refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
+2 -2
View File
@@ -9,13 +9,11 @@ const inventory = (digit: string) => {
const nodes = [
{
artifact_id: artifactId,
kind: "resource",
format: "file",
sha256: sha,
size: 1,
media_type: null,
architecture: null,
executable: false,
content_state: "materialized",
limitations: [],
},
@@ -27,6 +25,8 @@ const inventory = (digit: string) => {
parent_occurrence_id: null,
logical_path: ".",
entry_kind: "file",
artifact_kind: "resource",
artifact_format: "file",
declared_size: 1,
compressed_size: null,
executable: false,
@@ -1,62 +0,0 @@
import { browserCaptureComparisonInputSchema } from "../domain/browserCaptureComparison.js";
import { browserScenarioCaptureSchema } from "../domain/browserScenarioCapture.js";
import { captureSnapshotSchema } from "../domain/webCaptureDiffSchemas.js";
// Captures are complete producer results to pass back unchanged, rather than
// analyst-authored options. Describe that boundary without embedding the entire
// inspection result schema in every comparison input. The cloned parser still
// validates every nested field using the canonical domain schemas.
const passiveCaptureInputSchema = captureSnapshotSchema.clone(
captureSnapshotSchema.def,
);
passiveCaptureInputSchema._zod.toJSONSchema = () => ({
type: "object",
properties: {
inspection: {
type: "object",
description:
"Complete result object returned by inspect_web_page. Pass the entire result unchanged, including capture identity, observations, completeness, and limitations. Every nested field is validated by REA.",
},
webmcp: {
anyOf: [{ type: "object" }, { type: "null" }],
default: null,
description:
"Complete result object returned by discover_webmcp_tools for this capture, or null when it was not recorded. Pass the entire result unchanged. Every nested field is validated by REA.",
},
},
required: ["inspection"],
});
const scenarioCaptureInputSchema = browserScenarioCaptureSchema.clone(
browserScenarioCaptureSchema.def,
);
scenarioCaptureInputSchema._zod.toJSONSchema = () => ({
type: "object",
description:
"Complete result object returned by capture_browser_scenario. Pass the entire result unchanged, including browser and scenario identity, steps, events, artifact contents and digests, completeness, and limitations. Every nested field is validated by REA.",
});
/** Advertise capture round trips while retaining full runtime validation. */
export const browserCaptureToolInputSchema =
browserCaptureComparisonInputSchema.safeExtend({
before: passiveCaptureInputSchema
.optional()
.describe(
"Earlier passive web-page capture with complete producer results.",
),
after: passiveCaptureInputSchema
.optional()
.describe(
"Later passive web-page capture with complete producer results.",
),
before_scenario: scenarioCaptureInputSchema
.optional()
.describe(
"Earlier complete result object returned by capture_browser_scenario.",
),
after_scenario: scenarioCaptureInputSchema
.optional()
.describe(
"Later complete result object returned by capture_browser_scenario.",
),
});
+11 -4
View File
@@ -17,7 +17,10 @@ import {
discoverWebMcpToolsInputSchema,
webMcpDiscoverySchema,
} from "../domain/webMcpDiscovery.js";
import { browserCaptureComparisonSchema } from "../domain/browserCaptureComparison.js";
import {
browserCaptureComparisonInputSchema,
browserCaptureComparisonSchema,
} from "../domain/browserCaptureComparison.js";
import {
captureWebScreenshotInputSchema,
compareWebScreenshotsInputSchema,
@@ -26,7 +29,6 @@ import {
} from "../domain/webScreenshot.js";
import { toolContractMetadata } from "./toolEffects.js";
import { evidenceResultOf } from "./toolOutputSchemas.js";
import { browserCaptureToolInputSchema } from "./browserCaptureToolInputSchema.js";
const evidenceResult = evidenceResultOf;
const listOutputSchema = evidenceResult(browserTargetListSchema);
@@ -74,6 +76,11 @@ const exampleScenarioCapture = () => ({
start_origin: origin,
action_count: 1,
secret_references: [],
network_content: {
request_body: false,
response_body: false,
header_values: false,
},
},
duration_ms: 10,
steps: [
@@ -213,9 +220,9 @@ export const BROWSER_TOOL_CONTRACTS = [
name: "compare_web_captures",
...toolContractMetadata("compare_web_captures"),
description:
"Compare passive web captures by providing before and after, each with the complete inspect_web_page result in inspection and an optional complete discover_webmcp_tools result in webmcp; or compare recorded scenarios by passing complete capture_browser_scenario results in before_scenario and after_scenario with an optional normalization policy. Use exactly one input group. Scenario comparison aligns exact step IDs, records deterministic literal normalization, and returns every artifact-level difference plus alignment failures inline. Missing or truncated evidence never proves equality.",
"Compare passive web captures by providing before and after, each with the complete inspect_web_page normalized_result in inspection and an optional complete discover_webmcp_tools normalized_result in webmcp; or compare recorded scenarios by passing complete capture_browser_scenario normalized_result objects in before_scenario and after_scenario with an optional normalization policy. Use exactly one input group. Scenario comparison aligns exact step IDs, records deterministic literal normalization, and returns every artifact-level difference plus alignment failures inline. Missing or truncated evidence never proves equality.",
kind: "browser-provider",
inputSchema: browserCaptureToolInputSchema,
inputSchema: browserCaptureComparisonInputSchema,
outputSchema: captureDiffOutputSchema,
examples: [
{
+2 -53
View File
@@ -102,62 +102,11 @@ const describeSchema = (
);
};
const flattenRootUnion = (
value: Record<string, unknown>,
describeProperty: (property: string) => string,
): Record<string, unknown> => {
if (!Array.isArray(value.anyOf)) return value;
const branches = value.anyOf;
const objects = branches.filter(isObject);
if (objects.length === 0 || objects.length !== branches.length) return value;
const properties = new Map<string, unknown>();
for (const branch of objects) {
if (!isObject(branch.properties)) return value;
for (const [name, schema] of Object.entries(branch.properties)) {
const previous = properties.get(name);
if (!properties.has(name)) properties.set(name, schema);
else if (JSON.stringify(previous) !== JSON.stringify(schema))
properties.set(name, {
anyOf: [previous, schema],
description: describeProperty(name),
});
}
}
// Invocation still uses the exact canonical union, including branch rules.
const { anyOf: _anyOf, required: _required, ...root } = value;
const requiredByBranch = objects.map((branch) =>
Array.isArray(branch.required)
? branch.required.filter(
(item): item is string => typeof item === "string",
)
: [],
);
const required = requiredByBranch.reduce((common, current) =>
common.filter((name) => current.includes(name)),
);
const minProperties = Math.max(
typeof root.minProperties === "number" ? root.minProperties : 0,
Math.min(...requiredByBranch.map((names) => names.length)),
);
return {
...root,
type: "object",
properties: Object.fromEntries(properties),
...(minProperties > 0 ? { minProperties } : {}),
...(required.length > 0 ? { required } : {}),
...(objects.every((branch) => branch.additionalProperties === false)
? { additionalProperties: false }
: {}),
};
};
/** Preserve property guidance and literal data while advertising object roots. */
/** Describe canonical input fields without changing structural constraints. */
export const presentInputJsonSchema = (
root: Record<string, unknown>,
describeProperty: (property: string) => string,
): Record<string, unknown> => {
const described = describeSchema(root, root, describeProperty);
return isObject(described)
? flattenRootUnion(described, describeProperty)
: root;
return isObject(described) ? described : root;
};
@@ -12,13 +12,11 @@ const inventory = (format: "apk" | "ipa" | "directory", digit: string) => {
const nodes = [
{
artifact_id: artifactId,
kind: "resource",
format,
format: format === "directory" ? "directory" : "zip",
sha256: sha,
size: 1,
media_type: null,
architecture: null,
executable: false,
content_state: "materialized",
limitations: [],
},
@@ -30,6 +28,8 @@ const inventory = (format: "apk" | "ipa" | "directory", digit: string) => {
parent_occurrence_id: null,
logical_path: ".",
entry_kind: "file",
artifact_kind: "resource",
artifact_format: format,
declared_size: 1,
compressed_size: null,
executable: false,
-6
View File
@@ -414,7 +414,6 @@ export const sessionOutputSchemas = {
path: z.string(),
format: targetFormatSchema,
kind: targetKindSchema,
loaderArgs: z.array(z.string()),
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]).nullable(),
}),
@@ -425,11 +424,6 @@ export const sessionOutputSchemas = {
z.object({
path: z.string(),
bytes: z.number().int().min(0),
entries: z
.number()
.int()
.min(0)
.describe("Legacy primitive query count."),
primitive_entries: z
.number()
.int()
+8 -13
View File
@@ -8,7 +8,10 @@ import {
functionBodySchema,
} from "../domain/hopperValues.js";
import { analysisProfileSchema } from "../domain/analysisProfile.js";
import { evidenceEnvelopeSchema } from "../domain/evidence.js";
import {
evidenceSchema,
validateAnalysisProfileProvider,
} from "../domain/evidence.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import {
PROVIDER_REJECTION_CODES,
@@ -20,18 +23,12 @@ import {
PROVIDER_RETRY_ACTIONS,
} from "../domain/providerOperationHealth.js";
import { analysisErrorProjectionSchema } from "./errorSchemas.js";
import { prefixedDigestSchema } from "./../domain/digests.js";
/** Inline result with its complete Evidence record. */
export const inlineEvidenceRecordSchema = evidenceEnvelopeSchema;
/** Wrap a result and its Evidence while preserving the result schema type. */
/** Specialize the single normalized result inside a complete Evidence record. */
export const evidenceResultOf = <Schema extends z.ZodType>(schema: Schema) =>
z.strictObject({
result: schema,
evidence_id: prefixedDigestSchema("ev"),
evidence: inlineEvidenceRecordSchema,
});
z
.strictObject({ ...evidenceSchema.shape, normalized_result: schema })
.superRefine(validateAnalysisProfileProvider);
const resultOf = evidenceResultOf;
/** Wrap a lifecycle result while preserving its exact schema type. */
@@ -336,8 +333,6 @@ export type ToolUnavailabilityReason = z.output<
export const sessionProvider = z
.object({
provider: providerIdentity,
providers: z.array(providerIdentity),
capabilities: z.array(providerCapability),
analysis_run: analysisRun,
analysis_activity: analysisActivity,
+1 -10
View File
@@ -62,17 +62,8 @@ export const toolInputSchemaWithMetadata = <Contract extends ToolContract>(
...options,
libraryOptions: { reused: "ref", ...options.libraryOptions },
});
// Root-union flattening compares branch properties before widening them.
// Keep its inline representation: distinct references can name equal
// schemas and otherwise introduce redundant, deeper anyOf properties.
const compatible = Array.isArray(shared.anyOf)
? project({
...options,
libraryOptions: { ...options.libraryOptions, reused: "inline" },
})
: shared;
return {
...presentInputJsonSchema(compatible, fallbackPropertyDescription),
...presentInputJsonSchema(shared, fallbackPropertyDescription),
examples: contract.examples.map(({ input }) => input),
};
},