feat: add evidence-backed process investigations

This commit is contained in:
morluto
2026-07-12 20:36:00 +08:00
parent 9f60348d1b
commit cc8681a856
53 changed files with 2774 additions and 290 deletions
+23
View File
@@ -28,6 +28,29 @@ export const enhancedInputSchemas = {
limit: z.number().int().min(1).max(500).default(100),
max_pseudocode_chars: z.number().int().min(1).max(100_000).default(20_000),
max_instructions: z.number().int().min(1).max(5_000).default(500),
pseudocode_offset: z.number().int().min(0).default(0),
assembly_offset: z.number().int().min(0).default(0),
collection_offset: z
.object({
comments: z.number().int().min(0).default(0),
callers: z.number().int().min(0).default(0),
callees: z.number().int().min(0).default(0),
incoming_references: z.number().int().min(0).default(0),
outgoing_references: z.number().int().min(0).default(0),
referenced_strings: z.number().int().min(0).default(0),
referenced_names: z.number().int().min(0).default(0),
basic_blocks: z.number().int().min(0).default(0),
})
.default({
comments: 0,
callers: 0,
callees: 0,
incoming_references: 0,
outgoing_references: 0,
referenced_strings: 0,
referenced_names: 0,
basic_blocks: 0,
}),
}),
trace_feature: z.object({
query: z.string().min(1),
+32 -1
View File
@@ -1,4 +1,9 @@
import { z } from "zod";
import { evidenceBundleSchema } from "../domain/evidenceBundle.js";
import {
processCaptureSchema,
processScenarioSchema,
} from "../domain/processCapture.js";
import { enhancedInputSchemas } from "./enhancedInputs.js";
import {
@@ -44,6 +49,7 @@ export interface ToolContract {
const annotations = (name: string, kind: ToolKind): ToolAnnotations => ({
readOnlyHint:
kind === "enhanced" ||
name === "export_evidence_bundle" ||
(!name.startsWith("set_") &&
name !== "unset_bookmark" &&
name !== "goto_address" &&
@@ -354,11 +360,36 @@ export const SESSION_TOOL_CONTRACTS = [
"Report whether a target is open and, when open, its canonical path, format, and kind. Use before analysis calls or target switches; this performs no analysis.",
z.object({}),
),
session(
"export_evidence_bundle",
"Return the session's deterministic Evidence v2 bundle without clearing it. Records are sorted by evidence ID, and array order carries no investigative meaning.",
z.object({}),
),
session(
"import_evidence_bundle",
"Validate and atomically merge a local Evidence v2 bundle supplied as data. Semantic IDs are recomputed; tampering, unsupported versions, conflicts, and ledger overflow reject the entire import.",
z.object({ bundle: evidenceBundleSchema }),
),
session(
"capture_process_scenario",
"Run one bounded process under a PTY using operator-approved executable and working roots. Requires approved: true on every call. Captures normalized terminal frames, sampled descendants, filesystem snapshots, and loopback HTTP/WebSocket replay. This launches a process and is disabled unless operator policy enables it; it is not a security sandbox.",
processScenarioSchema,
),
session(
"compare_process_captures",
"Compare two bounded process captures across terminal, exit, sampled process, filesystem, HTTP, and WebSocket evidence. Missing or truncated observations are never treated as equivalent.",
z.object({
left_evidence_id: z.string().regex(/^ev_[a-f0-9]{64}$/u),
left: processCaptureSchema,
right_evidence_id: z.string().regex(/^ev_[a-f0-9]{64}$/u),
right: processCaptureSchema,
}),
),
] as const satisfies readonly ToolContract[];
/**
* Complete ordered public inventory used by registration and verification.
* Keep this collection at 46 tools unless a deliberate contract change updates
* Keep this collection at 50 tools unless a deliberate contract change updates
* snapshots, package verification, and real-Hopper verification together.
*/
export const TOOL_CONTRACTS = [
+60 -24
View File
@@ -1,24 +1,19 @@
import { z } from "zod";
import { evidenceSchema } from "../domain/evidence.js";
import { processCaptureSchema } from "../domain/processCapture.js";
import { evidenceBundleSchema } from "../domain/evidenceBundle.js";
const evidenceMetadata = {
schema_version: z.literal(1),
artifact: z
.object({
path: z.string(),
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
format: z.enum(["hopper", "mach-o", "elf", "pe"]),
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]).nullable(),
})
.nullable(),
provider: z.object({ id: z.literal("hopper"), version: z.null() }),
operation: z.string().min(1),
parameters: z.record(z.string(), z.json()),
confidence: z.literal("observed"),
limitations: z.array(z.string()),
};
const resultOf = (schema: z.ZodType) =>
z.object({ ...evidenceMetadata, result: schema });
evidenceSchema.omit({ result: true }).extend({ result: schema });
const lifecycleResultOf = (schema: z.ZodType) => z.object({ result: schema });
const comparisonStatus = z.enum([
"unchanged",
"added",
"removed",
"changed",
"truncated",
"unknown",
]);
const nullableText = z.string().nullable();
const addressList = z.array(z.string());
const addressedEntry = z.object({ address: z.string(), name: z.string() });
@@ -92,7 +87,18 @@ const graphNode = z.union([
z.object({ address: z.string(), calls: z.array(z.string()) }),
z.object({ address: z.string(), error: z.string() }),
]);
const unavailableOrBoundedStrings = z.union([unavailable, bounded(z.string())]);
const referenceEdge = z.object({
source_address: z.string(),
target_address: z.string(),
source_procedure: procedureIdentity.nullable(),
target_procedure: procedureIdentity.nullable(),
kind: unavailable,
});
const referencedValue = z.object({
address: z.string(),
value: z.string(),
source_address: z.string(),
});
const functionDossierOutput = resultOf(
z.object({
procedure: z.object({
@@ -116,18 +122,23 @@ const functionDossierOutput = resultOf(
text: z.string(),
}),
),
callers: bounded(z.string()),
callees: bounded(z.string()),
incoming_references: bounded(z.string()),
referenced_strings: unavailableOrBoundedStrings,
referenced_names: unavailableOrBoundedStrings,
callers: bounded(procedureIdentity),
callees: bounded(procedureIdentity),
incoming_references: bounded(referenceEdge),
outgoing_references: bounded(referenceEdge),
referenced_strings: bounded(referencedValue),
referenced_names: bounded(referencedValue),
basic_blocks: bounded(
z.object({
start: z.string(),
end: z.string(),
successors: z.union([unavailable, z.array(z.string())]),
successors: z.array(z.string()),
}),
),
instruction_scan: z.object({
scanned: z.number().int().min(0),
truncated: z.boolean(),
}),
}),
);
@@ -284,4 +295,29 @@ export const sessionOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
}),
]),
),
export_evidence_bundle: lifecycleResultOf(evidenceBundleSchema),
import_evidence_bundle: lifecycleResultOf(
z.object({
imported: z.number().int().min(0),
total: z.number().int().min(0),
}),
),
capture_process_scenario: lifecycleResultOf(
evidenceSchema
.omit({ result: true })
.extend({ result: processCaptureSchema }),
),
compare_process_captures: lifecycleResultOf(
evidenceSchema.omit({ result: true }).extend({
result: z.object({
status: comparisonStatus,
terminal: comparisonStatus,
exit: comparisonStatus,
filesystem: comparisonStatus,
protocol: comparisonStatus,
process: comparisonStatus,
limitations: z.array(z.string()),
}),
}),
),
};