From fa2b6c5a61adcb75c4c2773ed1c9f7dba83fc1d3 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 29 Sep 2026 12:42:08 +0800 Subject: [PATCH] refactor(observation): retain complete tool results --- docs/browser-observation.md | 2 +- src/application/BrowserEvidence.ts | 25 +-- .../InventoryProjectionEvidence.ts | 6 +- src/browser/CdpCaptureDocuments.test.ts | 22 +- src/browser/CdpCaptureDocuments.ts | 66 ++---- src/browser/CdpCaptureEventBodyShapes.ts | 5 +- src/browser/CdpCaptureEventHandlers.ts | 66 +----- src/browser/CdpCaptureEventState.ts | 3 - src/browser/CdpCaptureEvents.ts | 8 +- src/browser/CdpCaptureStorage.ts | 34 +-- src/browser/CdpCaptureStorageFingerprints.ts | 199 +++++++++--------- src/browser/CdpPageCapture.ts | 38 +--- src/browser/CdpPageCaptureScripts.ts | 18 +- src/browser/CdpPageCaptureWorkers.ts | 10 +- src/browser/CdpWebMcpDiscovery.ts | 30 +-- src/cliBrowserAdvancedCommands.ts | 41 ---- src/contracts/browserToolContracts.ts | 9 +- src/contracts/contractSnapshot.test.ts | 1 - src/domain/androidApplication.ts | 77 ++----- src/domain/artifactInventoryEvidence.ts | 8 +- src/domain/browserCaptureComparison.ts | 17 +- src/domain/browserObservation.ts | 19 +- src/domain/browserScenarioDiff.test.ts | 17 +- src/domain/browserScenarioDiff.ts | 17 +- src/domain/browserScenarioDiffValues.ts | 10 - src/domain/runtimeIdentification.ts | 35 +-- src/domain/webCaptureDiff.ts | 75 +++---- src/domain/webCaptureDiffSchemas.ts | 13 +- src/domain/webMcpDiscovery.ts | 11 +- ...cdpBrowserProvider.document_script.test.ts | 121 ++++++----- .../cdpBrowserProvider.sensitive_data.test.ts | 14 +- tests/boundary/browser/webCaptureDiff.test.ts | 10 + .../filesystem/runtimeIdentification.test.ts | 25 ++- .../androidApplication.test.ts | 33 ++- tests/fixtures/fakeCdpBrowserEvents.ts | 30 ++- tests/fixtures/fakeCdpBrowserResults.ts | 10 + tests/fixtures/fakeCdpBrowserTypes.ts | 1 + 37 files changed, 425 insertions(+), 701 deletions(-) diff --git a/docs/browser-observation.md b/docs/browser-observation.md index 44e24501b..a1bd15a74 100644 --- a/docs/browser-observation.md +++ b/docs/browser-observation.md @@ -8,7 +8,7 @@ REA can attach to a user-owned Chrome-family browser through the Chrome DevTools - `inspect_web_page` / `rea inspect-web-page` captures bounded DOM structure, accessibility nodes, scripts, resources, safe response/DOM metadata, attach-window network and console metadata, WebSocket frame sizes, workers, quota, and optionally storage key names, redacted storage-content fingerprints, or script sources. - `analyze_web_bundle` / `rea analyze-web-bundle` parses approved script artifacts without execution and derives chunk edges, route and endpoint candidates, vendor fingerprints, static WebMCP declarations, and optionally approved source-map/original-source evidence. - `observe_web_session` / `rea observe-web-session` arms a bounded window for an external user action and records ordered reload, SPA navigation, redirect, failure, lifecycle, and target-termination metadata. -- `discover_webmcp_tools` / `rea discover-webmcp-tools` uses the experimental CDP WebMCP domain to inventory page registrations. REA never exposes `WebMCP.invokeTool`. +- `discover_webmcp_tools` / `rea discover-webmcp-tools` uses the experimental CDP WebMCP domain to return every in-scope registration and its complete structural input-schema summary inline. REA never exposes `WebMCP.invokeTool`; malformed or over-limit protocol payloads fail explicitly instead of returning truncated tool metadata. - `compare_web_captures` / `rea compare-web-captures` compares passive captures or exact-step-aligned browser scenarios. Scenario results commit reproducible literal normalization and expose alignment failures plus artifact-level action, screenshot, DOM, accessibility, URL, history, storage, and event differences. Missing or truncated evidence is never treated as equivalence. - `capture_web_screenshot` / `rea capture-web-screenshot` returns an explicitly approved, bounded, content-addressed visible-viewport PNG. - `compare_web_screenshots` / `rea compare-web-screenshots` performs bounded local PNG pixel comparison without OCR or external services. diff --git a/src/application/BrowserEvidence.ts b/src/application/BrowserEvidence.ts index c9728fcec..c59b6f772 100644 --- a/src/application/BrowserEvidence.ts +++ b/src/application/BrowserEvidence.ts @@ -104,15 +104,15 @@ const browserParameters = ( after_browser: input.after_scenario.browser, before_start_origin: input.before_scenario.scenario.start_origin, after_start_origin: input.after_scenario.scenario.start_origin, - max_changes: input.max_changes, normalization_sha256: commitBrowserScenarioNormalization( input.normalization ?? { rules: [] }, ).sha256, }; if ( - "max_changes" in input && input.before !== undefined && - input.after !== undefined + input.after !== undefined && + "inspection" in input.before && + "inspection" in input.after ) return { before_target_id: input.before.inspection.target.target_id, @@ -120,7 +120,6 @@ const browserParameters = ( input.before.inspection.capture_window.ended_at, after_target_id: input.after.inspection.target.target_id, after_capture_ended_at: input.after.inspection.capture_window.ended_at, - max_changes: input.max_changes, }; if (isScreenshotComparison(input)) return { @@ -142,23 +141,19 @@ const browserParameters = ( target_id: input.target_id, maximum_image_bytes: input.maximum_image_bytes, }; - if ("max_tools" in input) - return { - ...scope, - target_id: input.target_id, - observation_ms: input.observation_ms, - max_tools: input.max_tools, - max_schema_bytes: input.max_schema_bytes, - max_schema_nodes: input.max_schema_nodes, - max_schema_depth: input.max_schema_depth, - }; - if (!("include_accessibility_text" in input)) + if ("max_timeline_events" in input) return { ...scope, target_id: input.target_id, observation_ms: input.observation_ms, max_timeline_events: input.max_timeline_events, }; + if (!("limits" in input)) + return { + ...scope, + target_id: input.target_id, + observation_ms: input.observation_ms, + }; return { ...scope, target_id: input.target_id, diff --git a/src/application/InventoryProjectionEvidence.ts b/src/application/InventoryProjectionEvidence.ts index 50b5db9b6..a51d3fdde 100644 --- a/src/application/InventoryProjectionEvidence.ts +++ b/src/application/InventoryProjectionEvidence.ts @@ -16,7 +16,7 @@ import { err, ok, type Result } from "../domain/result.js"; interface InventoryProjectionInput { readonly inventory_evidence: readonly Evidence[]; - readonly limits: unknown; + readonly limits?: unknown; } interface InventoryProjectionResult { @@ -69,7 +69,9 @@ export const projectInventoryEvidence = < operation: options.operation, parameters: { inventory_evidence_ids: [...result.source_evidence_ids], - limits: jsonValueSchema.parse(parsed.data.limits), + ...("limits" in parsed.data && parsed.data.limits !== undefined + ? { limits: jsonValueSchema.parse(parsed.data.limits) } + : {}), }, result: jsonValueSchema.parse(result), rawResult: null, diff --git a/src/browser/CdpCaptureDocuments.test.ts b/src/browser/CdpCaptureDocuments.test.ts index 730a0e5c6..452d4440b 100644 --- a/src/browser/CdpCaptureDocuments.test.ts +++ b/src/browser/CdpCaptureDocuments.test.ts @@ -11,7 +11,7 @@ import { inspectWebPageInputSchema } from "../domain/browserObservation.js"; const origin = "https://app.example.test"; describe("CDP document capture", () => { - it("walks deeply nested frame trees iteratively and retains a bounded prefix", () => { + it("walks deeply nested frame trees and returns every frame and resource", () => { let frameTree: Record = { frame: { id: "frame-0", url: `${origin}/0` }, resources: [{ url: `${origin}/0.js`, type: "Script" }], @@ -27,12 +27,10 @@ describe("CDP document capture", () => { }; } const result = { frameTree }; - const frames = captureFrames(result, new Set([origin]), 3); - const resources = captureResources(result, new Set([origin]), 2); - expect(frames).toMatchObject({ total: 2_000 }); - expect(frames.items).toHaveLength(3); - expect(resources).toMatchObject({ total: 2_000 }); - expect(resources.items).toHaveLength(2); + const frames = captureFrames(result, new Set([origin])); + const resources = captureResources(result, new Set([origin])); + expect(frames.items).toHaveLength(2_000); + expect(resources.items).toHaveLength(2_000); }); it("rebases parent indexes when allowed DOM documents are combined", () => { @@ -91,25 +89,23 @@ describe("CDP document capture", () => { ], }, ], - 10, { includeText: true, maximumFieldBytes: 4, - maximumTotalBytes: 7, }, ); expect(capture.nodes[0]).toMatchObject({ name: "😀", - description: "é", + description: "éé", states: [{ name: "disabled", value: true }], }); expect(capture.treeIncomplete).toBe(true); expect(capture.textCapture).toEqual({ status: "truncated", - retained_bytes: 6, + retained_bytes: 8, excluded_fields: 0, - truncated_fields: 2, + truncated_fields: 1, }); }); @@ -126,11 +122,9 @@ describe("CDP document capture", () => { ], }, ], - 10, { includeText: false, maximumFieldBytes: 1_024, - maximumTotalBytes: 64 * 1_024, }, ); diff --git a/src/browser/CdpCaptureDocuments.ts b/src/browser/CdpCaptureDocuments.ts index ea0e4bc48..e7c056051 100644 --- a/src/browser/CdpCaptureDocuments.ts +++ b/src/browser/CdpCaptureDocuments.ts @@ -20,20 +20,18 @@ export type CapturedResource = Omit< "resource_key" > & { readonly rawUrl: string }; -/** Normalize allowed frames while retaining a bounded prefix and total count. */ +/** Normalize every allowed frame, optionally selecting a leading frame. */ export const captureFrames = ( result: unknown, allowedOrigins: ReadonlySet, - maximum: number, + maximum?: number, completeness?: CdpCaptureCompleteness, ): { - readonly total: number; readonly items: WebPageInspection["frames"]; } => { const root = recordValue(requiredRecord(result).frameTree); - if (root === undefined) return { total: 0, items: [] }; + if (root === undefined) return { items: [] }; const items: WebPageInspection["frames"] = []; - let total = 0; for (const tree of walkFrameTrees(root)) { const frame = recordValue(tree.frame); const frameId = stringValue(frame?.id); @@ -49,8 +47,7 @@ export const captureFrames = ( ); continue; } - total += 1; - if (items.length >= maximum) continue; + if (maximum !== undefined && items.length >= maximum) continue; items.push({ frame_id: frameId, parent_frame_id: @@ -59,7 +56,7 @@ export const captureFrames = ( origin: sanitized.origin, }); } - return { total, items }; + return { items }; }; /** Read the current main-frame URL from an untrusted Page.getFrameTree result. */ @@ -68,20 +65,17 @@ export const mainFrameUrl = (result: unknown): string | undefined => recordValue(recordValue(requiredRecord(result).frameTree)?.frame)?.url, ); -/** Normalize allowed resources while retaining a bounded prefix and total count. */ +/** Normalize every allowed resource. */ export const captureResources = ( result: unknown, allowedOrigins: ReadonlySet, - maximum: number, completeness?: CdpCaptureCompleteness, ): { - readonly total: number; readonly items: readonly CapturedResource[]; } => { const root = recordValue(requiredRecord(result).frameTree); - if (root === undefined) return { total: 0, items: [] }; + if (root === undefined) return { items: [] }; const items: CapturedResource[] = []; - let total = 0; for (const tree of walkFrameTrees(root)) { for (const resource of recordsValue(tree.resources)) { const url = allowedSanitizedUrl(resource.url, allowedOrigins); @@ -92,8 +86,6 @@ export const captureResources = ( ); continue; } - total += 1; - if (items.length >= maximum) continue; const contentSize = numberValue(resource.contentSize); items.push({ rawUrl: stringValue(resource.url) ?? "", @@ -106,7 +98,7 @@ export const captureResources = ( }); } } - return { total, items }; + return { items }; }; const walkFrameTrees = function* ( @@ -163,11 +155,7 @@ export const captureDom = ( : []; const baseIndex = nodes.length; total += nodeTypes.length; - for ( - let index = 0; - index < nodeTypes.length && nodes.length < input.limits.max_dom_nodes; - index += 1 - ) { + for (let index = 0; index < nodeTypes.length; index += 1) { const attributeIndexes = numberArray(attributes[index]); const parent = Math.trunc(parents[index] ?? -1); const nodeIndex = nodes.length; @@ -180,8 +168,7 @@ export const captureDom = ( node_value_length: indexedString(strings, nodeValues[index]).length, attribute_names: attributeIndexes .filter((_value, attributeIndex) => attributeIndex % 2 === 0) - .map((value) => indexedString(strings, value).slice(0, 256)) - .slice(0, 200), + .map((value) => indexedString(strings, value).slice(0, 256)), }); const metadata = domMetadata({ strings, @@ -192,10 +179,6 @@ export const captureDom = ( allowedOrigins, }); for (const url of metadata.urls) { - if (urls.length >= input.limits.max_resources) { - completeness?.truncate("metadata"); - continue; - } urls.push(url); if (url.destination_scope !== "approved") { excludedUrls += 1; @@ -214,18 +197,16 @@ export const captureDom = ( total, nodes, urls, - agentHints: agentHints.slice(0, input.limits.max_resources), + agentHints, excludedUrls, }; }; export const captureAccessibility = ( results: readonly unknown[], - maximum: number, options: { readonly includeText: boolean; readonly maximumFieldBytes: number; - readonly maximumTotalBytes: number; readonly unavailable?: boolean; }, ): { @@ -243,10 +224,9 @@ export const captureAccessibility = ( return nodeId === undefined ? [] : [nodeId]; }), ); - let retainedBytes = 0; let excludedFields = 0; let truncatedFields = 0; - const nodes = all.slice(0, maximum).map((node) => { + const nodes = all.map((node) => { const captureText = (value: unknown): string | null => { const raw = stringValue(recordValue(value)?.value); if (raw === undefined) return null; @@ -254,12 +234,7 @@ export const captureAccessibility = ( excludedFields += 1; return null; } - const available = Math.max(0, options.maximumTotalBytes - retainedBytes); - const captured = boundedUtf8( - raw, - Math.min(options.maximumFieldBytes, available), - ); - retainedBytes += captured.bytes; + const captured = boundedUtf8(raw, options.maximumFieldBytes); if (captured.truncated) { truncatedFields += 1; if (captured.text === "" && raw !== "") { @@ -279,13 +254,6 @@ export const captureAccessibility = ( states: accessibilityStates(node.properties), }; }); - for (const node of all.slice(maximum)) { - for (const value of [node.name, node.description]) { - if (stringValue(recordValue(value)?.value) === undefined) continue; - excludedFields += 1; - if (options.includeText) truncatedFields += 1; - } - } return { total: all.length, nodes, @@ -305,7 +273,13 @@ export const captureAccessibility = ( : truncatedFields > 0 ? "truncated" : "included", - retained_bytes: retainedBytes, + retained_bytes: nodes.reduce( + (total, node) => + total + + Buffer.byteLength(node.name ?? "") + + Buffer.byteLength(node.description ?? ""), + 0, + ), excluded_fields: excludedFields, truncated_fields: truncatedFields, }, diff --git a/src/browser/CdpCaptureEventBodyShapes.ts b/src/browser/CdpCaptureEventBodyShapes.ts index 622de1b49..c3c0ec34a 100644 --- a/src/browser/CdpCaptureEventBodyShapes.ts +++ b/src/browser/CdpCaptureEventBodyShapes.ts @@ -80,13 +80,10 @@ const inferBodyShape = ( text: string, ): { readonly shape: JsonShape | null; readonly truncated: boolean } => { const bytes = Buffer.byteLength(text); - const remaining = - state.input.limits.max_total_json_body_bytes - state.jsonBodyBytes; - if (bytes > state.input.limits.max_json_body_bytes || bytes > remaining) { + if (bytes > state.input.limits.max_json_body_bytes) { state.completeness.truncate("json_body_shapes"); return { shape: null, truncated: true }; } - state.jsonBodyBytes += bytes; const shape = inferJsonShape(text, { maximumBytes: state.input.limits.max_json_body_bytes, maximumNodes: state.input.limits.max_json_shape_nodes, diff --git a/src/browser/CdpCaptureEventHandlers.ts b/src/browser/CdpCaptureEventHandlers.ts index 33ee45e2f..dd42c7aba 100644 --- a/src/browser/CdpCaptureEventHandlers.ts +++ b/src/browser/CdpCaptureEventHandlers.ts @@ -40,13 +40,6 @@ export const handleExecutionContextCreated = ( ) return; const key = String(identifier); - if ( - state.executionContextFrames.size >= state.input.limits.max_scripts && - !state.executionContextFrames.has(key) - ) { - state.completeness.truncate("scripts"); - return; - } state.executionContextFrames.set(key, frameId); }; @@ -73,13 +66,6 @@ export const handleScriptParsed = ( state.completeness.exclude("scripts", exclusionReasonForUrl(rawUrl)); return; } - if ( - state.scripts.size >= state.input.limits.max_scripts && - !state.scripts.has(scriptId) - ) { - state.completeness.drop("scripts"); - return; - } const sourceMap = sourceMapForScript(params.sourceMapURL, rawUrl, state); const script: CapturedScript = { scriptId, @@ -148,13 +134,6 @@ export const handleRequestWillBeSent = ( state.network.delete(requestId); return; } - if ( - state.network.size >= state.input.limits.max_network_events && - !state.network.has(requestId) - ) { - state.completeness.drop("network_requests"); - return; - } const initiator = recordValue(params.initiator); const initiatorFrame = initiatorLocation(initiator); const rawInitiatorUrl = stringValue(initiatorFrame?.url); @@ -214,10 +193,6 @@ export const handleResponseReceived = ( status: numberValue(response.status) ?? null, mime_type: boundedText(response.mimeType, 256), }); - if (state.responseMetadata.length >= state.input.limits.max_network_events) { - state.completeness.truncate("metadata"); - return; - } const metadata = safeResponseMetadata( requestId, sanitized.url, @@ -262,19 +237,13 @@ export const handleConsoleAPICalled = ( ); return; } - if (state.console.length >= state.input.limits.max_console_events) { - state.completeness.drop("console_events"); - return; - } const arguments_ = recordsValue(params.args); state.console.push({ type: (stringValue(params.type) ?? "unknown").slice(0, 100), timestamp: numberValue(params.timestamp) ?? 0, - argument_types: arguments_ - .map((argument) => - (stringValue(argument.type) ?? "unknown").slice(0, 100), - ) - .slice(0, 100), + argument_types: arguments_.map((argument) => + (stringValue(argument.type) ?? "unknown").slice(0, 100), + ), url: source.url, line: integerOrNull(frame.lineNumber), column: integerOrNull(frame.columnNumber), @@ -300,15 +269,9 @@ const captureConsoleText = ( for (const [argumentIndex, argument] of arguments_.entries()) { const primitive = consolePrimitive(argument); if (primitive === undefined) continue; - const remaining = - state.input.limits.max_total_console_text_bytes - state.consoleTextBytes; - if (remaining <= 0) { - truncatedValues += 1; - continue; - } const bounded = boundedSensitiveText( primitive.text, - Math.min(state.input.limits.max_console_text_field_bytes, remaining), + state.input.limits.max_console_text_field_bytes, ); values.push({ argument_index: argumentIndex, @@ -316,7 +279,6 @@ const captureConsoleText = ( text: bounded.text, }); retainedBytes += bounded.bytes; - state.consoleTextBytes += bounded.bytes; if (bounded.truncated) truncatedValues += 1; } if (truncatedValues > 0) state.completeness.truncate("console_text"); @@ -340,10 +302,6 @@ export const handleWebSocketFrame = ( (!state.network.has(requestId) && !state.allowedWebSockets.has(requestId)) ) return; - if (state.websockets.length >= state.input.limits.max_websocket_events) { - state.completeness.drop("websocket_frames"); - return; - } const response = recordValue(params.response); const payload = stringValue(response?.payloadData) ?? ""; const opcode = Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0)); @@ -369,17 +327,10 @@ const captureWebSocketShape = ( if (opcode !== 1) return { format: "binary", json_shape: null, truncated: false }; const bytes = Buffer.byteLength(payload); - const remaining = - state.input.limits.max_total_websocket_shape_bytes - - state.websocketShapeBytes; - if ( - bytes > state.input.limits.max_websocket_shape_bytes || - bytes > remaining - ) { + if (bytes > state.input.limits.max_websocket_shape_bytes) { state.completeness.truncate("websocket_shapes"); return { format: "text", json_shape: null, truncated: true }; } - state.websocketShapeBytes += bytes; const shape = inferJsonShape(payload, { maximumBytes: state.input.limits.max_websocket_shape_bytes, maximumNodes: state.input.limits.max_json_shape_nodes, @@ -431,13 +382,6 @@ export const handleWebSocketCreated = ( state.completeness.exclude("websocket_connections", "disallowed_origin"); return; } - if ( - !state.allowedWebSockets.has(requestId) && - state.allowedWebSockets.size >= state.input.limits.max_websocket_events - ) { - state.completeness.drop("websocket_connections"); - return; - } state.allowedWebSockets.add(requestId); }; diff --git a/src/browser/CdpCaptureEventState.ts b/src/browser/CdpCaptureEventState.ts index fdb433bc3..324881c28 100644 --- a/src/browser/CdpCaptureEventState.ts +++ b/src/browser/CdpCaptureEventState.ts @@ -20,7 +20,4 @@ export interface CdpCaptureEventsState { originViolation: boolean; navigationDuringCapture: boolean; mainFrameId: string | undefined; - consoleTextBytes: number; - jsonBodyBytes: number; - websocketShapeBytes: number; } diff --git a/src/browser/CdpCaptureEvents.ts b/src/browser/CdpCaptureEvents.ts index ba967c791..2d8d35e93 100644 --- a/src/browser/CdpCaptureEvents.ts +++ b/src/browser/CdpCaptureEvents.ts @@ -13,7 +13,7 @@ import { recordValue } from "./CdpCaptureValues.js"; export { type CapturedScript } from "./CdpCaptureEventTypes.js"; -/** Bounded event accumulator that drops payload values at ingestion time. */ +/** Event accumulator that validates and normalizes payloads at ingestion. */ export class CdpCaptureEvents implements CdpCaptureEventsState { readonly scripts = new Map(); readonly executionContextFrames = new Map(); @@ -33,9 +33,6 @@ export class CdpCaptureEvents implements CdpCaptureEventsState { originViolation = false; navigationDuringCapture = false; mainFrameId: string | undefined = undefined; - consoleTextBytes = 0; - jsonBodyBytes = 0; - websocketShapeBytes = 0; readonly input: InspectWebPageInput; readonly allowedOrigins: ReadonlySet; @@ -57,9 +54,6 @@ export class CdpCaptureEvents implements CdpCaptureEventsState { this.websockets.length = 0; this.responseMetadata.length = 0; this.agentHints.length = 0; - this.consoleTextBytes = 0; - this.jsonBodyBytes = 0; - this.websocketShapeBytes = 0; this.completeness.reset(); if (!this.input.include_console_text) this.completeness.exclude("console_text", "not_approved", null); diff --git a/src/browser/CdpCaptureStorage.ts b/src/browser/CdpCaptureStorage.ts index a3bbc2083..bd6bf0ab7 100644 --- a/src/browser/CdpCaptureStorage.ts +++ b/src/browser/CdpCaptureStorage.ts @@ -16,7 +16,7 @@ import { stringValue, } from "./CdpCaptureValues.js"; -/** Capture redacted, bounded storage metadata for one authorized origin. */ +/** Capture redacted storage metadata for one authorized origin. */ export const captureStorage = async ( context: { readonly connection: CdpConnection; @@ -28,7 +28,6 @@ export const captureStorage = async ( limitations: string[], ): Promise<{ readonly value: WebPageInspection["storage"]; - readonly truncated: boolean; }> => { const quota = recordValue( await optionalCdpCommand( @@ -64,22 +63,17 @@ export const captureStorage = async ( : undefined; const cacheValues = recordsValue(recordValue(cacheRaw)?.caches); const caches = capturedCaches(cacheValues); - const maximum = context.input.limits.max_storage_keys; const fingerprints = context.input.include_storage_fingerprints ? await captureStorageFingerprints({ context, origin, local, session, - indexedDbNames: indexed.slice(0, maximum), - caches: caches.slice(0, maximum), + indexedDbNames: indexed, + caches, limitations, }) - : { items: [], complete: false as const, truncated: false }; - const truncated = - [local.items, session.items, indexed, caches].some( - (items) => items.length > maximum, - ) || fingerprints.truncated; + : { items: [], complete: false }; const structuredStorageComplete = indexedRaw !== undefined && Array.isArray(indexedValues) && @@ -91,25 +85,15 @@ export const captureStorage = async ( origin, usage_bytes: numberValue(quota?.usage) ?? null, quota_bytes: numberValue(quota?.quota) ?? null, - local_storage_keys: local.items - .map(({ key }) => key.slice(0, 1_024)) - .slice(0, maximum), - session_storage_keys: session.items - .map(({ key }) => key.slice(0, 1_024)) - .slice(0, maximum), - indexed_db_names: indexed - .map((name) => name.slice(0, 1_024)) - .slice(0, maximum), - cache_names: caches - .map(({ name }) => name.slice(0, 1_024)) - .slice(0, maximum), + local_storage_keys: local.items.map(({ key }) => key.slice(0, 1_024)), + session_storage_keys: session.items.map(({ key }) => key.slice(0, 1_024)), + indexed_db_names: indexed.map((name) => name.slice(0, 1_024)), + cache_names: caches.map(({ name }) => name.slice(0, 1_024)), content_fingerprints: [...fingerprints.items], fingerprint_algorithm: "sha256", - fingerprints_complete: - fingerprints.complete && structuredStorageComplete && !truncated, + fingerprints_complete: fingerprints.complete && structuredStorageComplete, values_redacted: true, }, - truncated, }; }; diff --git a/src/browser/CdpCaptureStorageFingerprints.ts b/src/browser/CdpCaptureStorageFingerprints.ts index c6ff03bd5..cfa0ef79a 100644 --- a/src/browser/CdpCaptureStorageFingerprints.ts +++ b/src/browser/CdpCaptureStorageFingerprints.ts @@ -37,9 +37,7 @@ interface StorageFingerprintContext { interface FingerprintState { readonly items: StorageFingerprint[]; - readonly maximum: number; complete: boolean; - truncated: boolean; } interface FingerprintRun { @@ -60,10 +58,8 @@ interface CaptureStorageFingerprintInput { type StorageFingerprintCapture = { readonly items: readonly StorageFingerprint[]; -} & ( - | { readonly complete: true; readonly truncated: false } - | { readonly complete: false; readonly truncated: boolean } -); + readonly complete: boolean; +}; /** Capture stable hashes of approved storage content without returning values. */ export const captureStorageFingerprints = async ({ @@ -77,9 +73,7 @@ export const captureStorageFingerprints = async ({ }: CaptureStorageFingerprintInput): Promise => { const state: FingerprintState = { items: [], - maximum: context.input.limits.max_storage_keys, complete: local.complete && session.complete, - truncated: false, }; const run = { context, limitations, state }; addStorageItems(state, "local_storage", local.items); @@ -94,16 +88,8 @@ export const captureStorageFingerprints = async ({ ), ); const complete = - state.complete && - !state.truncated && - state.items.every(({ complete }) => complete); - return complete - ? { items: state.items, complete: true, truncated: false } - : { - items: state.items, - complete: false, - truncated: state.truncated, - }; + state.complete && state.items.every(({ complete }) => complete); + return { items: state.items, complete }; }; const addStorageItems = ( @@ -175,10 +161,6 @@ const addIndexedDb = async ( names: readonly string[], ): Promise => { for (const databaseName of names) { - if (run.state.items.length >= run.state.maximum) { - run.state.truncated = true; - return; - } const raw = await optionalCdpCommand( run.context, "IndexedDB.requestDatabase", @@ -261,57 +243,62 @@ const addIndexedDbRecords = async ( readonly objectStoreName: string; }, ): Promise => { - const remaining = run.state.maximum - run.state.items.length; - if (remaining <= 0) { - run.state.truncated = true; - return; - } - const raw = await optionalCdpCommand( - run.context, - "IndexedDB.requestData", - { - securityOrigin: input.origin, - databaseName: input.databaseName, - objectStoreName: input.objectStoreName, - indexName: "", - skipCount: 0, - pageSize: remaining, - }, - run.limitations, - ); - const result = recordValue(raw); - if (raw === undefined || result === undefined) { - run.state.complete = false; - return; - } - if ( - !Array.isArray(result.objectStoreDataEntries) || - typeof result.hasMore !== "boolean" - ) { - run.state.complete = false; - return; - } - const entries = recordsValue(result.objectStoreDataEntries); - if (entries.length !== result.objectStoreDataEntries.length) - run.state.complete = false; - for (const entry of entries) { - const key = stableValue(entry.key); - const primaryKey = stableValue(entry.primaryKey); - const value = stableValue(entry.value); - addFingerprint(run.state, { - scope: "indexed_db_record", - identity: { - database: input.databaseName, - store: input.objectStoreName, - key, - primaryKey, + let skipCount = 0; + while (true) { + const raw = await optionalCdpCommand( + run.context, + "IndexedDB.requestData", + { + securityOrigin: input.origin, + databaseName: input.databaseName, + objectStoreName: input.objectStoreName, + indexName: "", + skipCount, + pageSize: STORAGE_ENTRY_PAGE_SIZE, }, - value, - complete: remoteObjectComplete(entry.value), - }); + run.limitations, + ); + const result = recordValue(raw); + if (raw === undefined || result === undefined) { + run.state.complete = false; + return; + } + if ( + !Array.isArray(result.objectStoreDataEntries) || + typeof result.hasMore !== "boolean" + ) { + run.state.complete = false; + return; + } + const entries = recordsValue(result.objectStoreDataEntries); + if (entries.length !== result.objectStoreDataEntries.length) + run.state.complete = false; + for (const entry of entries) { + const key = stableValue(entry.key); + const primaryKey = stableValue(entry.primaryKey); + const value = stableValue(entry.value); + addFingerprint(run.state, { + scope: "indexed_db_record", + identity: { + database: input.databaseName, + store: input.objectStoreName, + key, + primaryKey, + }, + value, + complete: remoteObjectComplete(entry.value), + }); + } + if (result.hasMore !== true) return; + if ( + entries.length === 0 || + skipCount > Number.MAX_SAFE_INTEGER - entries.length + ) { + run.state.complete = false; + return; + } + skipCount += entries.length; } - if (result.hasMore === true || entries.length > remaining) - run.state.truncated = true; }; const addCaches = async ( @@ -319,34 +306,44 @@ const addCaches = async ( caches: readonly CapturedCache[], ): Promise => { for (const cache of caches) { - const remaining = run.state.maximum - run.state.items.length; - if (remaining <= 0) { - run.state.truncated = true; - return; + let skipCount = 0; + let returnCount: number | undefined; + while (returnCount === undefined || skipCount < returnCount) { + const raw = await optionalCdpCommand( + run.context, + "CacheStorage.requestEntries", + { cacheId: cache.id, skipCount, pageSize: STORAGE_ENTRY_PAGE_SIZE }, + run.limitations, + ); + const result = recordValue(raw); + if (raw === undefined || result === undefined) { + run.state.complete = false; + break; + } + if ( + !Array.isArray(result.cacheDataEntries) || + typeof result.returnCount !== "number" || + !Number.isSafeInteger(result.returnCount) || + result.returnCount < 0 + ) { + run.state.complete = false; + break; + } + const entries = recordsValue(result.cacheDataEntries); + if (entries.length !== result.cacheDataEntries.length) + run.state.complete = false; + for (const entry of entries) await addCacheEntry(run, cache, entry); + returnCount = result.returnCount; + if (skipCount + entries.length >= returnCount) break; + if ( + entries.length === 0 || + skipCount > Number.MAX_SAFE_INTEGER - entries.length + ) { + run.state.complete = false; + break; + } + skipCount += entries.length; } - const raw = await optionalCdpCommand( - run.context, - "CacheStorage.requestEntries", - { cacheId: cache.id, skipCount: 0, pageSize: remaining }, - run.limitations, - ); - const result = recordValue(raw); - if (raw === undefined || result === undefined) { - run.state.complete = false; - continue; - } - if ( - !Array.isArray(result.cacheDataEntries) || - typeof result.returnCount !== "number" - ) { - run.state.complete = false; - continue; - } - const entries = recordsValue(result.cacheDataEntries); - if (entries.length !== result.cacheDataEntries.length) - run.state.complete = false; - for (const entry of entries) await addCacheEntry(run, cache, entry); - if (result.returnCount > entries.length) run.state.truncated = true; } }; @@ -406,10 +403,6 @@ const addFingerprint = ( readonly complete: boolean; }, ): void => { - if (state.items.length >= state.maximum) { - state.truncated = true; - return; - } state.items.push({ scope: input.scope, identity_sha256: digest(input.identity), @@ -421,6 +414,8 @@ const addFingerprint = ( }); }; +const STORAGE_ENTRY_PAGE_SIZE = 1_000; + const digest = (value: unknown): string => createHash("sha256").update(encodedValue(value)).digest("hex"); diff --git a/src/browser/CdpPageCapture.ts b/src/browser/CdpPageCapture.ts index 9ded68c62..a32f54fb3 100644 --- a/src/browser/CdpPageCapture.ts +++ b/src/browser/CdpPageCapture.ts @@ -84,7 +84,7 @@ export const capturePage = async ( allowedOrigins, limitations: [ "Observation starts when REA attaches; prior network and console activity is unavailable.", - "Raw network headers, bodies, cookies, storage values, console objects, and WebSocket payloads are never retained; separately approved captures retain only bounded redacted text or value-free shapes.", + "Raw network headers, bodies, cookies, storage values, console objects, and WebSocket payloads are never retained; separately approved captures retain only redacted text or value-free shapes.", "Source maps are reported only as declarative URLs and are not fetched.", "URL-less scripts and console events without an allowed source URL are excluded because their origin cannot be proven.", ], @@ -109,12 +109,10 @@ const captureAuthorizedPage = async ( const frameCapture = captureFrames( frameResult, allowedOrigins, - input.limits.max_frames, + undefined, state.events.completeness, ); const frames = frameCapture.items; - if (frameCapture.total > frames.length) - state.events.completeness.truncate("frames"); const captureFrame = frames[0]; if (captureFrame === undefined) throw new BrowserObservationError("inspect_web_page", "target_not_allowed"); @@ -122,19 +120,13 @@ const captureAuthorizedPage = async ( const resourceCapture = captureResources( await connection.send("Page.getResourceTree", {}, sessionId, signal), allowedOrigins, - input.limits.max_resources, state.events.completeness, ); - if (resourceCapture.total > resourceCapture.items.length) - state.events.completeness.truncate("resources"); const resources = stableWebResources( resourceCapture.items.map(publicResource), ); const dom = await capturePageDom(state); - if (dom.total > dom.nodes.length) state.events.completeness.truncate("dom"); const accessibility = await accessibilityForFrames(state, frames); - if (accessibility.total > accessibility.nodes.length) - state.events.completeness.truncate("accessibility"); const scripts = await captureScripts({ context, events: state.events, @@ -142,19 +134,15 @@ const captureAuthorizedPage = async ( resources, frameIds: new Set(frames.map((frame) => frame.frame_id)), }); - const workerCapture = await captureWorkers( + const workers = await captureWorkers( { context, allowedOrigins, limitations, events: state.events }, new Set(frames.map((frame) => frame.frame_id)), ); - if (workerCapture.total > workerCapture.items.length) - state.events.completeness.truncate("workers"); const storageCapture = await captureStorage( context, frames[0]?.origin ?? new URL(attachedUrl).origin, limitations, ); - if (storageCapture.truncated) - state.events.completeness.truncate("storage_keys"); if (!input.include_storage_keys) state.events.completeness.exclude("storage_keys", "not_approved", null); const completedFrameResult = await authorizedFrameTree( @@ -175,7 +163,7 @@ const captureAuthorizedPage = async ( accessibility, scripts: scripts.inventory, resources, - workers: workerCapture.items, + workers, storage: storageCapture.value, }), sourceMapRequests: scripts.sourceMapRequests, @@ -213,8 +201,7 @@ const authorizeObservationWindow = async ( await report(context.progress, 1, "Enabling passive CDP domains"); await connection.send("Page.enable", {}, sessionId, signal); const initialFrameResult = await authorizedFrameTree(context, allowedOrigins); - const mainFrame = captureFrames(initialFrameResult, allowedOrigins, 1) - .items[0]; + const mainFrame = captureFrames(initialFrameResult, allowedOrigins).items[0]; if (mainFrame === undefined) throw new BrowserObservationError("inspect_web_page", "target_not_allowed"); events.beginAuthorizedFrame(mainFrame.frame_id); @@ -367,16 +354,11 @@ const accessibilityForFrames = async ( else results.push(result); } if (unavailable) events.completeness.unavailable("accessibility"); - const capture = captureAccessibility( - results, - context.input.limits.max_ax_nodes, - { - includeText: context.input.include_accessibility_text, - maximumFieldBytes: context.input.limits.max_ax_text_field_bytes, - maximumTotalBytes: context.input.limits.max_total_ax_text_bytes, - ...(results.length === 0 && unavailable ? { unavailable: true } : {}), - }, - ); + const capture = captureAccessibility(results, { + includeText: context.input.include_accessibility_text, + maximumFieldBytes: context.input.limits.max_ax_text_field_bytes, + ...(results.length === 0 && unavailable ? { unavailable: true } : {}), + }); if (!context.input.include_accessibility_text) events.completeness.exclude( "accessibility", diff --git a/src/browser/CdpPageCaptureScripts.ts b/src/browser/CdpPageCaptureScripts.ts index 4493b05df..85efaec63 100644 --- a/src/browser/CdpPageCaptureScripts.ts +++ b/src/browser/CdpPageCaptureScripts.ts @@ -34,7 +34,6 @@ interface ScriptDraftState { readonly frameIds: ReadonlySet; readonly rawResources: readonly CapturedResource[]; readonly resources: WebPageInspection["resources"]; - totalSourceBytes: number; } type ScriptDraftItem = Omit< @@ -52,7 +51,6 @@ export const captureScripts = async ( frameIds, rawResources, resources, - totalSourceBytes: 0, }; const drafts: { readonly item: ScriptDraftItem; @@ -113,13 +111,6 @@ const captureScriptSource = async ( events.completeness.truncate("script_sources"); return sourceExcluded("declared script length exceeds per-script limit"); } - if ( - state.totalSourceBytes + script.length > - context.input.limits.max_total_script_source_bytes - ) { - events.completeness.truncate("script_sources"); - return sourceExcluded("total script source limit reached"); - } const result = requiredRecord( await context.connection.send( "Debugger.getScriptSource", @@ -130,15 +121,10 @@ const captureScriptSource = async ( ); const content = stringValue(result.scriptSource) ?? ""; const bytes = Buffer.byteLength(content); - if ( - bytes > context.input.limits.max_script_source_bytes || - state.totalSourceBytes + bytes > - context.input.limits.max_total_script_source_bytes - ) { + if (bytes > context.input.limits.max_script_source_bytes) { events.completeness.truncate("script_sources"); - return sourceExcluded("actual source exceeds configured byte limits"); + return sourceExcluded("actual source exceeds the per-script byte limit"); } - state.totalSourceBytes += bytes; return sourceResult(content); }; diff --git a/src/browser/CdpPageCaptureWorkers.ts b/src/browser/CdpPageCaptureWorkers.ts index f4f05dc3b..088052d46 100644 --- a/src/browser/CdpPageCaptureWorkers.ts +++ b/src/browser/CdpPageCaptureWorkers.ts @@ -21,10 +21,7 @@ interface CaptureWorkersInput { export const captureWorkers = async ( input: CaptureWorkersInput, frameIds: ReadonlySet, -): Promise<{ - readonly total: number; - readonly items: WebPageInspection["workers"]; -}> => { +): Promise => { const { context, allowedOrigins, limitations, events } = input; const completeness = events.completeness; const result = await optionalCdpCommand( @@ -34,7 +31,6 @@ export const captureWorkers = async ( limitations, ); const items: WebPageInspection["workers"] = []; - let total = 0; if (result === undefined) completeness.unavailable("workers"); for (const target of recordsValue(recordValue(result)?.targetInfos)) { const type = stringValue(target.type) ?? ""; @@ -60,8 +56,6 @@ export const captureWorkers = async ( ); continue; } - total += 1; - if (items.length >= context.input.limits.max_workers) continue; items.push({ target_id: (stringValue(target.targetId) ?? "").slice(0, 256), type: type.slice(0, 100), @@ -72,5 +66,5 @@ export const captureWorkers = async ( parent_frame_id: boundedText(target.parentFrameId, 256) ?? null, }); } - return { total, items }; + return items; }; diff --git a/src/browser/CdpWebMcpDiscovery.ts b/src/browser/CdpWebMcpDiscovery.ts index 53626d4e5..913f431b0 100644 --- a/src/browser/CdpWebMcpDiscovery.ts +++ b/src/browser/CdpWebMcpDiscovery.ts @@ -58,7 +58,12 @@ export const discoverWebMcp = async ( const initialUrl = mainFrameUrl(frameTree); if (allowedSanitizedUrl(initialUrl, origins) === undefined) throw new BrowserObservationError("inspect_web_page", "target_not_allowed"); - const frames = captureFrames(frameTree, origins, 1_000, completeness).items; + const frames = captureFrames( + frameTree, + origins, + undefined, + completeness, + ).items; const frameUrls = new Map( frames.map((frame) => [ frame.frame_id, @@ -263,10 +268,6 @@ const ingestWebMcpEvent = (options: WebMcpIngestOptions): void => { for (const declared of recordsValue(params.tools)) { const normalized = normalizeTool(declared, input, frames, completeness); if (normalized === undefined) continue; - if (!tools.has(normalized.tool_key) && tools.size >= input.max_tools) { - completeness.drop("webmcp_tools"); - continue; - } tools.set(normalized.tool_key, normalized); } }; @@ -308,7 +309,7 @@ const normalizeTool = ( numberValue(value.backendNodeId) === undefined ? "imperative" : "declarative", - input_schema_shape: schemaShape(value.inputSchema, input, completeness), + input_schema_shape: schemaShape(value.inputSchema), annotations: { read_only: booleanOrNull(annotations?.readOnly), untrusted_content: booleanOrNull(annotations?.untrustedContent), @@ -322,19 +323,18 @@ const normalizeTool = ( }; }; -const schemaShape = ( - value: unknown, - input: DiscoverWebMcpToolsInput, - completeness: CdpCaptureCompleteness, -) => { +const schemaShape = (value: unknown) => { if (recordValue(value) === undefined) return null; const encoded = JSON.stringify(value); const shape = inferJsonShape(encoded, { - maximumBytes: input.max_schema_bytes, - maximumNodes: input.max_schema_nodes, - maximumDepth: input.max_schema_depth, + maximumBytes: 256 * 1_024, + maximumNodes: 5_000, + maximumDepth: 20, }); - if (shape === null || shape.truncated) completeness.truncate("webmcp_tools"); + if (shape === null) + throw new BrowserObservationError("inspect_web_page", "protocol_error"); + if (shape.truncated) + throw new BrowserObservationError("inspect_web_page", "payload_limit"); return shape; }; diff --git a/src/cliBrowserAdvancedCommands.ts b/src/cliBrowserAdvancedCommands.ts index 7375d5bbc..072dba27d 100644 --- a/src/cliBrowserAdvancedCommands.ts +++ b/src/cliBrowserAdvancedCommands.ts @@ -51,34 +51,6 @@ const registerWebMcp = ( .max(10_000) .default(100) .describe("Observation duration in milliseconds"), - maxTools: z - .number() - .int() - .min(1) - .max(5_000) - .default(500) - .describe("Maximum page-declared WebMCP tools to return"), - maxSchemaBytes: z - .number() - .int() - .min(1) - .max(1_024 * 1_024) - .default(256 * 1_024) - .describe("Maximum serialized size of one declared tool schema"), - maxSchemaNodes: z - .number() - .int() - .min(1) - .max(100_000) - .default(5_000) - .describe("Maximum nodes in one declared tool schema"), - maxSchemaDepth: z - .number() - .int() - .min(1) - .max(100) - .default(20) - .describe("Maximum nesting depth in one declared tool schema"), }), run: ({ args, options }) => logCliCommand(logger, "discover-webmcp-tools", async () => { @@ -90,10 +62,6 @@ const registerWebMcp = ( options.allowedOrigins ?? context.allowedBrowserOrigins, target_id: args.targetId, observation_ms: options.observationMs, - max_tools: options.maxTools, - max_schema_bytes: options.maxSchemaBytes, - max_schema_nodes: options.maxSchemaNodes, - max_schema_depth: options.maxSchemaDepth, }); if (!parsed.success) return inputError("discover_webmcp_tools"); const result = await discoverWebMcpTools( @@ -118,13 +86,6 @@ const registerCaptureDiff = ( afterJson: z.string().describe("Later normalized web capture JSON"), }), options: z.object({ - maxChanges: z - .number() - .int() - .min(1) - .max(20_000) - .default(2_000) - .describe("Maximum normalized changes to return"), normalizationJson: z .string() .default('{"rules":[]}') @@ -141,14 +102,12 @@ const registerCaptureDiff = ( before_scenario: before, after_scenario: after, normalization: parseJson(options.normalizationJson), - max_changes: options.maxChanges, }); const parsed = scenarioComparison.success ? scenarioComparison : browserCaptureComparisonInputSchema.safeParse({ before, after, - max_changes: options.maxChanges, }); if (!parsed.success) return inputError("compare_web_captures"); const result = await compareWebCaptureEvidence( diff --git a/src/contracts/browserToolContracts.ts b/src/contracts/browserToolContracts.ts index eb1a15b3b..76262bde4 100644 --- a/src/contracts/browserToolContracts.ts +++ b/src/contracts/browserToolContracts.ts @@ -202,7 +202,7 @@ export const BROWSER_TOOL_CONTRACTS = [ name: "discover_webmcp_tools", ...toolContractMetadata("discover_webmcp_tools"), description: - "Passively inventory page-registered WebMCP tools using the experimental CDP WebMCP domain. Metadata is bounded and page-declared-untrusted; REA never registers or invokes discovered tools.", + "Passively inventory every page-registered WebMCP tool and its complete structural input-schema summary using the experimental CDP WebMCP domain. Metadata is page-declared-untrusted; REA never registers or invokes discovered tools.", kind: "browser-provider", inputSchema: discoverWebMcpToolsInputSchema, outputSchema: webMcpOutputSchema, @@ -214,10 +214,6 @@ export const BROWSER_TOOL_CONTRACTS = [ allowed_origins: [origin], target_id: "TARGET_ID_FROM_LIST_BROWSER_TARGETS", observation_ms: 100, - max_tools: 500, - max_schema_bytes: 262_144, - max_schema_nodes: 5_000, - max_schema_depth: 20, }, }, ], @@ -226,7 +222,7 @@ export const BROWSER_TOOL_CONTRACTS = [ name: "compare_web_captures", ...toolContractMetadata("compare_web_captures"), description: - "Compare passive web captures by providing before and after, or compare recorded scenarios by providing 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 exposes bounded artifact-level changes plus alignment failures. Missing or truncated evidence never proves equality.", + "Compare passive web captures by providing before and after, or compare recorded scenarios by providing 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: browserCaptureComparisonInputSchema, outputSchema: captureDiffOutputSchema, @@ -246,7 +242,6 @@ export const BROWSER_TOOL_CONTRACTS = [ }, ], }, - max_changes: 2_000, }, }, ], diff --git a/src/contracts/contractSnapshot.test.ts b/src/contracts/contractSnapshot.test.ts index 25cb022ff..6a7d7f802 100644 --- a/src/contracts/contractSnapshot.test.ts +++ b/src/contracts/contractSnapshot.test.ts @@ -76,7 +76,6 @@ describe("tool contract surface", () => { "before_scenario", "after_scenario", "normalization", - "max_changes", ]), ); const example = contract.examples[0]; diff --git a/src/domain/androidApplication.ts b/src/domain/androidApplication.ts index 572dfebcd..44fb96434 100644 --- a/src/domain/androidApplication.ts +++ b/src/domain/androidApplication.ts @@ -4,7 +4,6 @@ import canonicalize from "canonicalize"; import { z } from "zod"; import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js"; -import { projectBoundedCartesian } from "./boundedCartesianProjection.js"; import { evidenceSchema } from "./evidence.js"; const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u); @@ -19,12 +18,7 @@ const componentSchema = z.strictObject({ /** Authenticated APK inventory pages projected as one Android application. */ export const androidApplicationProjectionInputSchema = z.strictObject({ - inventory_evidence: z.array(evidenceSchema).min(1).max(100), - limits: z - .strictObject({ - max_components: z.number().int().min(1).max(10_000).default(1_000), - }) - .default({ max_components: 1_000 }), + inventory_evidence: z.array(evidenceSchema).min(1), }); /** Deterministic, execution-free Android application inventory projection. */ @@ -32,7 +26,7 @@ export const androidApplicationProjectionResultSchema = z.strictObject({ projection_id: z.string().regex(/^adp_[a-f0-9]{64}$/u), root_sha256: digestSchema, root_format: z.literal("apk"), - source_evidence_ids: z.array(evidenceIdSchema).min(1).max(100), + source_evidence_ids: z.array(evidenceIdSchema).min(1), components: z.strictObject({ manifests: z.array(componentSchema), resources: z.array(componentSchema), @@ -67,10 +61,8 @@ export const androidApplicationProjectionResultSchema = z.strictObject({ }), ), coverage: z.strictObject({ - status: z.enum(["complete-within-inventory", "partial", "truncated"]), + status: z.enum(["complete-within-inventory", "partial"]), inventory_complete: z.boolean(), - omitted_components: z.number().int().min(0), - omitted_bridge_candidates: z.number().int().min(0), }), limitations: z.array(z.string().min(1).max(4_096)).max(100), }); @@ -115,27 +107,15 @@ export const projectAndroidApplication = ( } satisfies Component; }); const classified = classify(all); - const components = retain(classified, parsed.limits.max_components); - const omittedComponents = count(classified) - count(components); const bridgeProjection = bridgeCandidates( - [...components.dex, ...components.jvm_classes], - components.native_libraries, - parsed.limits.max_components, + [...classified.dex, ...classified.jvm_classes], + classified.native_libraries, ); + const components = classified; const limitations = [ ...(!inventory.complete ? ["Source inventory pages are incomplete; absence is unknown."] : []), - ...(omittedComponents > 0 - ? [ - `${String(omittedComponents)} component observations were omitted by the projection limit.`, - ] - : []), - ...(bridgeProjection.omitted > 0 - ? [ - `${String(bridgeProjection.omitted)} bridge hypotheses were omitted by the projection limit.`, - ] - : []), "Manifest, resource, signing, and bytecode semantics require a dedicated Android provider; this projection reports exact inventory paths and hashes only.", "Bridge candidates are path-based hypotheses, not decoded JNI declarations or observed runtime calls.", ]; @@ -149,15 +129,10 @@ export const projectAndroidApplication = ( runtime_families: runtimeFamilies(all), bridge_candidates: bridgeProjection.candidates, coverage: { - status: - omittedComponents > 0 || bridgeProjection.omitted > 0 - ? ("truncated" as const) - : inventory.complete - ? ("complete-within-inventory" as const) - : ("partial" as const), + status: inventory.complete + ? ("complete-within-inventory" as const) + : ("partial" as const), inventory_complete: inventory.complete, - omitted_components: omittedComponents, - omitted_bridge_candidates: bridgeProjection.omitted, }, limitations, }; @@ -195,27 +170,6 @@ const classify = (all: readonly Component[]) => ({ ), }); -const retain = >( - groups: Groups, - maximum: number, -): { [Key in keyof Groups]: Component[] } => { - let remaining = maximum; - // SAFETY: the projection preserves every key from Groups and replaces only - // each readonly Component array with a bounded mutable Component array. - return Object.fromEntries( - Object.entries(groups).map(([key, values]) => { - const selected = [...values] - .sort((left, right) => compare(left.path, right.path)) - .slice(0, remaining); - remaining -= selected.length; - return [key, selected]; - }), - ) as { [Key in keyof Groups]: Component[] }; -}; - -const count = (groups: Record): number => - Object.values(groups).reduce((total, values) => total + values.length, 0); - const runtimeFamilies = (all: readonly Component[]) => { const paths = all.map(({ path }) => path.toLowerCase()); const families = new Set< @@ -247,21 +201,16 @@ const runtimeFamilies = (all: readonly Component[]) => { const bridgeCandidates = ( managed: readonly Component[], native: readonly Component[], - maximum: number, ) => { - const projection = projectBoundedCartesian( - managed, - native, - maximum, - (source, target) => ({ + const candidates = managed.flatMap((source) => + native.map((target) => ({ managed_path: source.path, native_path: target.path, basis: bridgeBasis(target.path), - }), + })), ); return { - candidates: projection.values, - omitted: projection.omitted, + candidates, }; }; diff --git a/src/domain/artifactInventoryEvidence.ts b/src/domain/artifactInventoryEvidence.ts index 5766c3477..b85839cb8 100644 --- a/src/domain/artifactInventoryEvidence.ts +++ b/src/domain/artifactInventoryEvidence.ts @@ -28,7 +28,7 @@ interface ParsedInventorySet { readonly inventory: InventorySet; } -/** Parse, merge, and verify a bounded set of inventory Evidence pages. */ +/** Parse, merge, and verify inventory Evidence pages. */ export const parseArtifactInventoryEvidence = ( input: unknown, ): ParsedInventorySet => @@ -91,11 +91,11 @@ const assembleInventorySet = ( readonly inventory: ArtifactInventoryResult; }[], ): ParsedInventorySet => { - if (pages.length === 0 || pages.length > 100) - throw new TypeError("Artifact comparison requires 1 to 100 Evidence pages"); + if (pages.length === 0) + throw new TypeError("Artifact inventory requires Evidence pages"); const first = pages[0]; if (first === undefined) - throw new TypeError("Artifact comparison requires Evidence pages"); + throw new TypeError("Artifact inventory requires Evidence pages"); const manifestJson = canonicalJson(first.inventory.manifest); const nodes = new Map(); const occurrences = new Map(); diff --git a/src/domain/browserCaptureComparison.ts b/src/domain/browserCaptureComparison.ts index ca2a79745..006bdfefd 100644 --- a/src/domain/browserCaptureComparison.ts +++ b/src/domain/browserCaptureComparison.ts @@ -14,14 +14,6 @@ import { type WebCaptureDiff, } from "./webCaptureDiff.js"; -const maxChangesSchema = z - .number() - .int() - .min(1) - .max(20_000) - .default(2_000) - .describe("Maximum normalized change records to retain."); - /** Caller-visible object schema for passive and scenario capture comparisons. */ export const browserCaptureComparisonInputSchema = z .strictObject({ @@ -41,7 +33,6 @@ export const browserCaptureComparisonInputSchema = z .unwrap() .optional() .describe("Exact-literal normalization policy."), - max_changes: maxChangesSchema, }) .superRefine((input, context) => { const passive = input.before !== undefined && input.after !== undefined; @@ -70,7 +61,7 @@ export type BrowserCaptureComparisonInput = z.output< >; type ScenarioCapturePair = Pick< BrowserCaptureComparisonInput, - "before_scenario" | "after_scenario" | "normalization" | "max_changes" + "before_scenario" | "after_scenario" | "normalization" > & { before_scenario: NonNullable< BrowserCaptureComparisonInput["before_scenario"] @@ -107,9 +98,5 @@ const toPassiveComparison = ( ): CompareWebCapturesInput => { if (input.before === undefined || input.after === undefined) throw new Error("Validated passive comparison is missing a capture"); - return { - before: input.before, - after: input.after, - max_changes: input.max_changes, - }; + return { before: input.before, after: input.after }; }; diff --git a/src/domain/browserObservation.ts b/src/domain/browserObservation.ts index 7e985c86c..5b37826e2 100644 --- a/src/domain/browserObservation.ts +++ b/src/domain/browserObservation.ts @@ -102,30 +102,15 @@ export const listBrowserTargetsInputSchema = z.object({ ...browserInput, }); -/** Collection bounds for passive browser capture, applied internally. */ +/** Per-value limits for optional text and JSON-shape capture. */ export const DEFAULT_BROWSER_INSPECTION_LIMITS = { - max_frames: 200, - max_dom_nodes: 2_000, - max_ax_nodes: 2_000, max_ax_text_field_bytes: 1_024, - max_total_ax_text_bytes: 64 * 1_024, - max_scripts: 200, - max_resources: 2_000, - max_workers: 500, - max_storage_keys: 1_000, max_script_source_bytes: 1_024 * 1_024, - max_total_script_source_bytes: 4 * 1_024 * 1_024, - max_network_events: 1_000, - max_console_events: 200, max_console_text_field_bytes: 1_024, - max_total_console_text_bytes: 64 * 1_024, max_json_body_bytes: 1_024 * 1_024, - max_total_json_body_bytes: 4 * 1_024 * 1_024, max_json_shape_nodes: 5_000, max_json_shape_depth: 20, - max_websocket_events: 500, max_websocket_shape_bytes: 64 * 1_024, - max_total_websocket_shape_bytes: 1_024 * 1_024, }; const inspectWebPageInputFacts = { @@ -176,7 +161,7 @@ export const inspectWebPageToolInputSchema = z.union([ inspectWebPageWithSourceInputSchema, ]); -/** Internal parsed input with REA's fixed collection bounds applied. */ +/** Internal parsed input with per-value capture limits applied. */ export const inspectWebPageInputSchema = inspectWebPageToolInputSchema.transform((input) => ({ ...input, diff --git a/src/domain/browserScenarioDiff.test.ts b/src/domain/browserScenarioDiff.test.ts index d8563e31d..5d80108a5 100644 --- a/src/domain/browserScenarioDiff.test.ts +++ b/src/domain/browserScenarioDiff.test.ts @@ -109,15 +109,22 @@ describe("browser scenario comparison", () => { expect.objectContaining({ artifact: "dom", status: "changed" }), ], }); - expect(compared.artifact_diffs).toEqual({ - total: 2, - retained: 2, - omitted: 0, - }); + expect(compared.artifact_diffs).toEqual({ total: 2 }); }); }); describe("browser scenario comparison validation", () => { + it("does not accept caller limits that would omit difference records", () => { + const capture = scenarioCapture({}); + expect( + compareBrowserScenariosInputSchema.safeParse({ + before_scenario: capture, + after_scenario: capture, + max_changes: 1, + }).success, + ).toBe(false); + }); + it("reports missing aligned steps without claiming equality", () => { const before = scenarioCapture({}); const after = scenarioCapture({ stepId: "open-profile" }); diff --git a/src/domain/browserScenarioDiff.ts b/src/domain/browserScenarioDiff.ts index 2ec690ff8..c8f1f370d 100644 --- a/src/domain/browserScenarioDiff.ts +++ b/src/domain/browserScenarioDiff.ts @@ -76,7 +76,6 @@ export const compareBrowserScenarios = ( afterCapture: input.after_scenario, alignment, rules: normalization.rules, - maxChanges: input.max_changes, }); const failures = [...alignment.failures, ...compared.failures]; const alignmentStatus = @@ -110,21 +109,12 @@ export const compareBrowserScenarios = ( steps: compared.steps, artifact_diffs: { total: compared.totalArtifactDiffs, - retained: - compared.totalArtifactDiffs - - Math.max(0, compared.totalArtifactDiffs - input.max_changes), - omitted: Math.max(0, compared.totalArtifactDiffs - input.max_changes), }, limitations: [ "Steps align only by exact, unique step_id; missing, duplicate, or action-mismatched steps are reported and prevent an unchanged claim.", "Only declared literal normalization rules are applied, in canonical rule_id order, to already-redacted durable capture fields.", "Elapsed time and event sequence/index values are excluded as volatile; screenshot bytes are compared by content digest.", "A changed status proves an observed normalized difference. Missing or truncated evidence, incompatible capture context, or alignment failure prevents an unchanged claim.", - ...(compared.totalArtifactDiffs > input.max_changes - ? [ - `${String(compared.totalArtifactDiffs - input.max_changes)} artifact difference record(s) were omitted by max_changes.`, - ] - : []), ], }); }; @@ -178,13 +168,11 @@ interface CompareAlignedStepsInput { readonly afterCapture: BrowserScenarioCapture; readonly alignment: ScenarioAlignment; readonly rules: readonly BrowserScenarioNormalizationRule[]; - readonly maxChanges: number; } const compareAlignedSteps = ( input: CompareAlignedStepsInput, ): AlignedStepComparison => { - const remaining = { value: input.maxChanges }; let totalArtifactDiffs = 0; const steps: BrowserScenarioDiff["steps"] = []; const failures: BrowserScenarioAlignmentFailure[] = []; @@ -209,8 +197,6 @@ const compareAlignedSteps = ( diff === null ? [] : [diff], ); totalArtifactDiffs += reportable.length; - const retained = reportable.slice(0, remaining.value); - remaining.value -= retained.length; const statuses = artifacts.map(({ status }) => status); steps.push({ step_id: stepId, @@ -223,8 +209,7 @@ const compareAlignedSteps = ( : statuses.includes("unknown") ? "unknown" : "unchanged", - artifact_diffs: retained, - omitted_artifact_diffs: reportable.length - retained.length, + artifact_diffs: reportable, }); } return { steps, failures, totalArtifactDiffs }; diff --git a/src/domain/browserScenarioDiffValues.ts b/src/domain/browserScenarioDiffValues.ts index 2f035308a..8080b23ec 100644 --- a/src/domain/browserScenarioDiffValues.ts +++ b/src/domain/browserScenarioDiffValues.ts @@ -89,13 +89,6 @@ export const compareBrowserScenariosInputSchema = z.strictObject({ .describe( "Bounded exact-literal rules committed in the comparison result.", ), - max_changes: z - .number() - .int() - .min(1) - .max(20_000) - .default(2_000) - .describe("Maximum changed or unknown artifact records to retain."), }); /** Parsed browser scenario comparison input. */ export type CompareBrowserScenariosInput = z.infer< @@ -170,14 +163,11 @@ export const browserScenarioDiffSchema = z.strictObject({ after_action: z.string().min(1).max(64), status: z.enum(["changed", "unchanged", "unknown"]), artifact_diffs: z.array(artifactDiffSchema).max(8), - omitted_artifact_diffs: z.number().int().min(0).max(8), }), ) .max(129), artifact_diffs: z.strictObject({ total: z.number().int().min(0).max(1_032), - retained: z.number().int().min(0).max(1_032), - omitted: z.number().int().min(0).max(1_032), }), limitations: z.array(z.string().min(1).max(2_048)).max(64), }); diff --git a/src/domain/runtimeIdentification.ts b/src/domain/runtimeIdentification.ts index cd3433a4f..4481c44d7 100644 --- a/src/domain/runtimeIdentification.ts +++ b/src/domain/runtimeIdentification.ts @@ -25,7 +25,6 @@ const observationSchema = z.strictObject({ const runtimeObservationShape = { family: runtimeFamilySchema, observations: z.array(observationSchema), - omitted_observations: z.number().int().min(0), }; const identifiedRuntimeSchema = z.discriminatedUnion("inspection", [ z.strictObject({ @@ -50,12 +49,7 @@ const identifiedRuntimeSchema = z.discriminatedUnion("inspection", [ /** Authenticated artifact inventory pages to classify by runtime family. */ const runtimeIdentificationInputSchema = z.strictObject({ - inventory_evidence: z.array(evidenceSchema).min(1).max(100), - limits: z - .strictObject({ - max_observations: z.number().int().min(1).max(10_000).default(1_000), - }) - .default({ max_observations: 1_000 }), + inventory_evidence: z.array(evidenceSchema).min(1), }); /** Provider-neutral runtime identification with explicit tooling availability. */ @@ -63,12 +57,11 @@ export const runtimeIdentificationResultSchema = z.strictObject({ identification_id: z.string().regex(/^rid_[a-f0-9]{64}$/u), root_sha256: digestSchema, root_format: z.string().min(1).max(100), - source_evidence_ids: z.array(evidenceIdSchema).min(1).max(100), + source_evidence_ids: z.array(evidenceIdSchema).min(1), runtimes: z.array(identifiedRuntimeSchema), coverage: z.strictObject({ - status: z.enum(["complete-within-inventory", "partial", "truncated"]), + status: z.enum(["complete-within-inventory", "partial"]), inventory_complete: z.boolean(), - omitted_observations: z.number().int().min(0), }), limitations: z.array(z.string().min(1).max(4_096)).max(100), }); @@ -165,22 +158,15 @@ export const identifyRuntimes = ( sha256: rootObservation.sha256, format: rootObservation.format, }); - let remaining = parsed.limits.max_observations; - let omitted = 0; const runtimes = [...grouped.entries()] .sort(([left], [right]) => compare(left, right)) .map(([family, values]) => { const unique = deduplicate(values); - const observations = unique.slice(0, remaining); - remaining -= observations.length; - const omittedObservations = unique.length - observations.length; - omitted += omittedObservations; const provider = providerFor(family, inventory.manifest.root_format); return { family, ...runtimeInspection(provider), - observations, - omitted_observations: omittedObservations, + observations: unique, }; }); const limitations = [ @@ -189,9 +175,6 @@ export const identifyRuntimes = ( "Source inventory pages are incomplete; absent runtimes remain unknown.", ] : []), - ...(omitted > 0 - ? [`${String(omitted)} runtime observations were omitted by the limit.`] - : []), "Runtime families are identified from exact artifact formats and paths; semantic claims require the named provider.", ]; const withoutId = { @@ -202,14 +185,10 @@ export const identifyRuntimes = ( .sort(compare), runtimes, coverage: { - status: - omitted > 0 - ? ("truncated" as const) - : inventory.complete - ? ("complete-within-inventory" as const) - : ("partial" as const), + status: inventory.complete + ? ("complete-within-inventory" as const) + : ("partial" as const), inventory_complete: inventory.complete, - omitted_observations: omitted, }, limitations, }; diff --git a/src/domain/webCaptureDiff.ts b/src/domain/webCaptureDiff.ts index ac71b2c2f..08ac5af4f 100644 --- a/src/domain/webCaptureDiff.ts +++ b/src/domain/webCaptureDiff.ts @@ -26,10 +26,9 @@ type Change = WebCaptureChange; export const compareWebCaptures = ( input: CompareWebCapturesInput, ): WebCaptureDiff => { - const remaining = { value: input.max_changes }; const before = input.before.inspection; const after = input.after.inspection; - const dimensions = compareWebCaptureDimensions(input, remaining); + const dimensions = compareWebCaptureDimensions(input); const statuses = Object.values(dimensions).map(({ status }) => status); return webCaptureDiffSchema.parse({ overall_status: statuses.includes("changed") @@ -75,52 +74,44 @@ const compareIdentities = ( ); }; -const compareDimension = - (remaining: { value: number }) => - ( - before: ReadonlyMap, - after: ReadonlyMap, - complete: boolean, - reason: string, - ): Dimension => { - const all = compareIdentities(before, after); - const retained = all.slice(0, remaining.value); - remaining.value -= retained.length; - if (all.length > 0) - return { - status: "changed", - total_changes: all.length, - changes: retained, - omitted_changes: all.length - retained.length, +const compareDimension = ( + before: ReadonlyMap, + after: ReadonlyMap, + complete: boolean, + reason: string, +): Dimension => { + const all = compareIdentities(before, after); + if (all.length > 0) + return { + status: "changed", + total_changes: all.length, + changes: all, + reason: null, + }; + return complete + ? { + status: "unchanged", + total_changes: 0, + changes: [], reason: null, + } + : { + status: "unknown", + total_changes: 0, + changes: [], + reason, }; - return complete - ? { - status: "unchanged", - total_changes: 0, - changes: [], - omitted_changes: 0, - reason: null, - } - : { - status: "unknown", - total_changes: 0, - changes: [], - omitted_changes: 0, - reason, - }; - }; +}; const accessibilityDimension = ( before: WebPageInspection, after: WebPageInspection, - remaining: { value: number }, ): Dimension => { const beforeAccess = accessibilityComparable(before); const afterAccess = accessibilityComparable(after); const textComparable = beforeAccess.text && afterAccess.text; const nodesComparable = beforeAccess.nodes && afterAccess.nodes; - return compareDimension(remaining)( + return compareDimension( singleton( "accessibility_tree", digest( @@ -149,7 +140,6 @@ const accessibilityDimension = ( const storageDimension = ( before: WebPageInspection, after: WebPageInspection, - remaining: { value: number }, ): Dimension => { const keysComplete = storageKeysComparable(before) && storageKeysComparable(after); @@ -162,7 +152,7 @@ const storageDimension = ( before.storage, after.storage, ); - return compareDimension(remaining)( + return compareDimension( storageMap( before.storage, keysComplete, @@ -182,11 +172,10 @@ const storageDimension = ( const compareWebCaptureDimensions = ( input: CompareWebCapturesInput, - remaining: { value: number }, ): WebCaptureDiff["dimensions"] => { const before = input.before.inspection; const after = input.after.inspection; - const dimension = compareDimension(remaining); + const dimension = compareDimension; return { dom_structure: dimension( singleton("document", digest(domProjection(before))), @@ -235,8 +224,8 @@ const compareWebCaptureDimensions = ( webMcpComplete(input.before.webmcp) && webMcpComplete(input.after.webmcp), "WebMCP discovery was unavailable or incomplete in at least one capture.", ), - accessibility: accessibilityDimension(before, after, remaining), - storage: storageDimension(before, after, remaining), + accessibility: accessibilityDimension(before, after), + storage: storageDimension(before, after), }; }; diff --git a/src/domain/webCaptureDiffSchemas.ts b/src/domain/webCaptureDiffSchemas.ts index f233ac73a..0ea05a8d9 100644 --- a/src/domain/webCaptureDiffSchemas.ts +++ b/src/domain/webCaptureDiffSchemas.ts @@ -10,10 +10,9 @@ export const captureSnapshotSchema = z.object({ }); /** Input for deterministic comparison of two normalized web captures. */ -export const compareWebCapturesInputSchema = z.object({ +export const compareWebCapturesInputSchema = z.strictObject({ before: captureSnapshotSchema, after: captureSnapshotSchema, - max_changes: z.number().int().min(1).max(20_000).default(2_000), }); const changeSchema = z.object({ @@ -23,7 +22,6 @@ const changeSchema = z.object({ const emptyDimensionShape = { total_changes: z.literal(0), changes: z.tuple([]), - omitted_changes: z.literal(0), }; const dimensionSchema = z.union([ z @@ -31,17 +29,13 @@ const dimensionSchema = z.union([ status: z.literal("changed"), total_changes: z.number().int().min(1), changes: z.array(changeSchema), - omitted_changes: z.number().int().min(0), reason: z.null(), }) .superRefine((dimension, context) => { - if ( - dimension.changes.length + dimension.omitted_changes !== - dimension.total_changes - ) + if (dimension.changes.length !== dimension.total_changes) context.addIssue({ code: "custom", - message: "Retained and omitted changes must equal total changes", + message: "Inline changes must equal total changes", path: ["total_changes"], }); }), @@ -60,7 +54,6 @@ const legacyUnknownDimension: z.input = { status: "unknown", total_changes: 0, changes: [], - omitted_changes: 0, reason: "Dimension was not recorded by this version 1 capture diff.", }; diff --git a/src/domain/webMcpDiscovery.ts b/src/domain/webMcpDiscovery.ts index 32ea5d955..b6759d345 100644 --- a/src/domain/webMcpDiscovery.ts +++ b/src/domain/webMcpDiscovery.ts @@ -8,20 +8,11 @@ import { import { jsonShapeSchema } from "./jsonShape.js"; /** Input for passive discovery of page-registered WebMCP tools. */ -export const discoverWebMcpToolsInputSchema = z.object({ +export const discoverWebMcpToolsInputSchema = z.strictObject({ cdp_endpoint: browserEndpointSchema, allowed_origins: browserAllowedOriginsSchema, target_id: z.string().trim().min(1).max(256), observation_ms: z.number().int().min(0).max(10_000).default(100), - max_tools: z.number().int().min(1).max(5_000).default(500), - max_schema_bytes: z - .number() - .int() - .min(1) - .max(1_024 * 1_024) - .default(256 * 1_024), - max_schema_nodes: z.number().int().min(1).max(100_000).default(5_000), - max_schema_depth: z.number().int().min(1).max(100).default(20), }); export type DiscoverWebMcpToolsInput = z.infer< typeof discoverWebMcpToolsInputSchema diff --git a/tests/boundary/browser/cdpBrowserProvider.document_script.test.ts b/tests/boundary/browser/cdpBrowserProvider.document_script.test.ts index bdb3f4008..dc2a42643 100644 --- a/tests/boundary/browser/cdpBrowserProvider.document_script.test.ts +++ b/tests/boundary/browser/cdpBrowserProvider.document_script.test.ts @@ -9,6 +9,17 @@ import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js"; import { describeBrowser, trackBrowser } from "./cdpBrowserProvider.support.js"; describeBrowser("CdpBrowserProvider: document script 1", () => { + it("rejects removed caller-facing WebMCP item and schema limits", () => { + expect( + discoverWebMcpToolsInputSchema.safeParse({ + cdp_endpoint: "http://127.0.0.1:9222", + allowed_origins: ["https://example.test"], + target_id: "target", + max_tools: 1, + }).success, + ).toBe(false); + }); + it("captures bounded accessibility text only after independent approval", async () => { const browser = await startFakeCdpBrowser(); trackBrowser(browser); @@ -24,7 +35,6 @@ describeBrowser("CdpBrowserProvider: document script 1", () => { limits: { ...request.limits, max_ax_text_field_bytes: 6, - max_total_ax_text_bytes: 6, }, }); @@ -32,7 +42,7 @@ describeBrowser("CdpBrowserProvider: document script 1", () => { expect(result.value.accessibility).toMatchObject({ text_capture: { status: "truncated", - retained_bytes: 6, + retained_bytes: 12, truncated_fields: 2, }, nodes: [expect.objectContaining({ name: "Submit" })], @@ -223,7 +233,7 @@ describeBrowser("CdpBrowserProvider: document script 2", () => { ); }); - it("bounds WebMCP registration replay and reports dropped declarations", async () => { + it("returns every WebMCP registration in the replay", async () => { const browser = await startFakeCdpBrowser({ webMcpTools: true, extraCollections: true, @@ -235,19 +245,46 @@ describeBrowser("CdpBrowserProvider: document script 2", () => { allowed_origins: [browser.allowedOrigin], target_id: "allowed-page", observation_ms: 0, - max_tools: 1, }), ); if (!result.ok) throw result.error; expect(result.value.tools).toMatchObject({ total: 2, - items: [expect.any(Object)], + items: [expect.any(Object), expect.any(Object)], }); - expect(result.value.completeness).toMatchObject({ - status: "truncated", - dropped_events: { webmcp_tools: 1 }, + expect(result.value.completeness.truncated_sections).not.toContain( + "webmcp_tools", + ); + }); + + it("retains registrations from authorized frames beyond the former frame cap", async () => { + const browser = await startFakeCdpBrowser({ + webMcpTools: true, + webMcpFrameCount: 1_001, }); + trackBrowser(browser); + const result = await new CdpBrowserProvider().discoverWebMcpTools( + discoverWebMcpToolsInputSchema.parse({ + cdp_endpoint: browser.endpoint, + allowed_origins: [browser.allowedOrigin], + target_id: "allowed-page", + observation_ms: 0, + }), + ); + + if (!result.ok) throw result.error; + expect(result.value.tools.items).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: "beyond_frame_limit_tool", + frame_id: "webmcp-frame-1000", + }), + ]), + ); + expect(result.value.completeness.truncated_sections).not.toContain( + "webmcp_tools", + ); }); }); @@ -332,7 +369,7 @@ describeBrowser("CdpBrowserProvider: document script 3", () => { }); }); - it("reports configured truncation without over-reading DOM or script source", async () => { + it("returns every DOM node and applies the per-script source limit", async () => { const browser = await startFakeCdpBrowser(); trackBrowser(browser); const request = inspectWebPageInputSchema.parse({ @@ -346,27 +383,15 @@ describeBrowser("CdpBrowserProvider: document script 3", () => { ...request, limits: { ...request.limits, - max_frames: 1, - max_dom_nodes: 1, - max_ax_nodes: 1, - max_scripts: 1, - max_resources: 1, - max_workers: 1, - max_storage_keys: 1, max_script_source_bytes: 10, - max_total_script_source_bytes: 10, - max_network_events: 1, - max_console_events: 1, - max_websocket_events: 1, }, }); if (!result.ok) throw result.error; expect(result.value.completeness).toMatchObject({ - status: "truncated", - truncated_sections: ["dom", "script_sources"], + truncated_sections: ["script_sources"], }); expect(result.value.dom).toMatchObject({ total_nodes: 2 }); - expect(result.value.dom.nodes).toHaveLength(1); + expect(result.value.dom.nodes).toHaveLength(2); expect(result.value.scripts.items[0]?.source).toMatchObject({ included: false, reason: "declared script length exceeds per-script limit", @@ -378,7 +403,7 @@ describeBrowser("CdpBrowserProvider: document script 3", () => { }); describeBrowser("CdpBrowserProvider: document script 4", () => { - it("bounds frames, resources, workers, accessibility, and storage inventories", async () => { + it("returns every frame, resource, worker, accessibility, and storage inventory item", async () => { const browser = await startFakeCdpBrowser({ extraCollections: true }); trackBrowser(browser); const request = inspectWebPageInputSchema.parse({ @@ -388,44 +413,18 @@ describeBrowser("CdpBrowserProvider: document script 4", () => { observation_ms: 0, include_storage_keys: true, }); - const result = await new CdpBrowserProvider().inspectPage({ - ...request, - limits: { - ...request.limits, - max_frames: 1, - max_dom_nodes: 2, - max_ax_nodes: 1, - max_scripts: 1, - max_resources: 1, - max_workers: 1, - max_storage_keys: 1, - max_script_source_bytes: 10, - max_total_script_source_bytes: 10, - max_network_events: 1, - max_console_events: 1, - max_websocket_events: 1, - }, - }); + const result = await new CdpBrowserProvider().inspectPage(request); if (!result.ok) throw result.error; - expect(result.value.completeness).toMatchObject({ - status: "truncated", - truncated_sections: [ - "accessibility", - "frames", - "resources", - "storage_keys", - "workers", - ], - }); - expect(result.value.frames).toHaveLength(1); - expect(result.value.resources).toHaveLength(1); - expect(result.value.workers).toHaveLength(1); - expect(result.value.accessibility).toMatchObject({ total_nodes: 2 }); - expect(result.value.accessibility.nodes).toHaveLength(1); - expect(result.value.storage.local_storage_keys).toHaveLength(1); - expect(result.value.storage.session_storage_keys).toHaveLength(1); - expect(result.value.storage.indexed_db_names).toHaveLength(1); - expect(result.value.storage.cache_names).toHaveLength(1); + expect(result.value.completeness.truncated_sections).toEqual([]); + expect(result.value.frames.length).toBeGreaterThan(1); + expect(result.value.resources.length).toBeGreaterThan(1); + expect(result.value.workers.length).toBeGreaterThan(1); + expect(result.value.accessibility).toMatchObject({ total_nodes: 4 }); + expect(result.value.accessibility.nodes).toHaveLength(4); + expect(result.value.storage.local_storage_keys.length).toBeGreaterThan(1); + expect(result.value.storage.session_storage_keys.length).toBeGreaterThan(1); + expect(result.value.storage.indexed_db_names).toHaveLength(2); + expect(result.value.storage.cache_names).toHaveLength(2); expect(result.value.storage.content_fingerprints).toEqual([]); }); }); diff --git a/tests/boundary/browser/cdpBrowserProvider.sensitive_data.test.ts b/tests/boundary/browser/cdpBrowserProvider.sensitive_data.test.ts index 76b38a909..e41df6e6e 100644 --- a/tests/boundary/browser/cdpBrowserProvider.sensitive_data.test.ts +++ b/tests/boundary/browser/cdpBrowserProvider.sensitive_data.test.ts @@ -248,7 +248,7 @@ describeBrowser("CdpBrowserProvider: sensitive data 2", () => { }); describeBrowser("CdpBrowserProvider: sensitive data 3", () => { - it("reports independent sensitive-capture truncation at aggregate byte limits", async () => { + it("keeps per-value text, body, and WebSocket shape validation", async () => { const browser = await startFakeCdpBrowser({ sensitiveShapes: true }); trackBrowser(browser); const request = inspectWebPageInputSchema.parse({ @@ -265,20 +265,20 @@ describeBrowser("CdpBrowserProvider: sensitive data 3", () => { limits: { ...request.limits, max_console_text_field_bytes: 5, - max_total_console_text_bytes: 5, max_json_body_bytes: 10, - max_total_json_body_bytes: 10, max_websocket_shape_bytes: 5, - max_total_websocket_shape_bytes: 5, }, }); if (!result.ok) throw result.error; expect(result.value.console.events[0]?.text_capture).toEqual({ status: "truncated", - values: [{ argument_index: 0, type: "string", text: "autho" }], - retained_bytes: 5, - truncated_values: 2, + values: [ + { argument_index: 0, type: "string", text: "autho" }, + { argument_index: 1, type: "number", text: "42" }, + ], + retained_bytes: 7, + truncated_values: 1, }); expect(result.value.network.requests[0]?.body_shapes.status).toBe( "truncated", diff --git a/tests/boundary/browser/webCaptureDiff.test.ts b/tests/boundary/browser/webCaptureDiff.test.ts index 28b847501..7654aa280 100644 --- a/tests/boundary/browser/webCaptureDiff.test.ts +++ b/tests/boundary/browser/webCaptureDiff.test.ts @@ -22,6 +22,16 @@ afterEach(async () => { }); describe("web capture diff", () => { + it("rejects caller limits that would omit difference records", () => { + expect( + compareWebCapturesInputSchema.safeParse({ + before: {}, + after: {}, + max_changes: 1, + }).success, + ).toBe(false); + }); + it("reports stable observed changes while preserving unknown dimensions", async () => { const browser = await startFakeCdpBrowser(); browsers.push(browser); diff --git a/tests/boundary/filesystem/runtimeIdentification.test.ts b/tests/boundary/filesystem/runtimeIdentification.test.ts index d35d6cbb0..d7ac6009f 100644 --- a/tests/boundary/filesystem/runtimeIdentification.test.ts +++ b/tests/boundary/filesystem/runtimeIdentification.test.ts @@ -63,7 +63,6 @@ describe("runtime identification", () => { coverage: { status: "complete-within-inventory", inventory_complete: true, - omitted_observations: 0, }, }); expect(first.runtimes.map(({ family }) => family)).toEqual([ @@ -115,25 +114,29 @@ describe("runtime identification", () => { ).toBe(false); }); - it("reports bounded runtime-observation truncation", async () => { - const root = await createTestTempDirectory("rea-runtime-limit-"); + it("accepts more than 100 supplied inventory Evidence records", async () => { + const root = await createTestTempDirectory("rea-runtime-pages-"); const path = join(root, "Fixture.apk"); const writer = new ZipWriter(new Uint8ArrayWriter()); await writer.add("one.js", new TextReader("one")); - await writer.add("two.js", new TextReader("two")); await writeFile(path, await writer.close()); const inventory = parseEvidence( await runProviderAnalysis(path, "inventory_artifact", {}), ); const result = identifyRuntimes({ - inventory_evidence: [inventory], - limits: { max_observations: 1 }, + inventory_evidence: Array.from({ length: 101 }, () => inventory), }); - expect(result.coverage).toMatchObject({ - status: "truncated", - omitted_observations: expect.any(Number), - }); - expect(result.coverage.omitted_observations).toBeGreaterThan(0); + + expect(result.source_evidence_ids).toHaveLength(101); + expect(result.coverage.status).toBe("complete-within-inventory"); + expect(result.runtimes).toContainEqual( + expect.objectContaining({ + family: "javascript", + observations: expect.arrayContaining([ + expect.objectContaining({ path: "one.js" }), + ]), + }), + ); }); it("does not route nested DEX content to the APK-only provider", async () => { diff --git a/tests/composition/analysis-sessions/androidApplication.test.ts b/tests/composition/analysis-sessions/androidApplication.test.ts index 7f6453ee1..393037ad8 100644 --- a/tests/composition/analysis-sessions/androidApplication.test.ts +++ b/tests/composition/analysis-sessions/androidApplication.test.ts @@ -46,11 +46,9 @@ describe("Android application projection", () => { ); const first = projectAndroidApplicationEvidence({ inventory_evidence: [inventory], - limits: { max_components: 100 }, }); const second = projectAndroidApplicationEvidence({ inventory_evidence: [inventory], - limits: { max_components: 100 }, }); expect(first.ok).toBe(true); expect(second.ok).toBe(true); @@ -67,7 +65,6 @@ describe("Android application projection", () => { coverage: { status: "complete-within-inventory", inventory_complete: true, - omitted_components: 0, }, }); expect(left.components.manifests).toHaveLength(1); @@ -105,4 +102,34 @@ describe("Android application projection", () => { error: { _tag: "AnalysisInputError" }, }); }); + + it("returns every component and bridge candidate from the inventory", async () => { + const root = await createTestTempDirectory("rea-android-complete-"); + const path = join(root, "Fixture.apk"); + const writer = new ZipWriter(new Uint8ArrayWriter()); + const dex = Uint8Array.from([0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0]); + for (let index = 0; index < 1_001; index += 1) + await writer.add( + `classes${String(index).padStart(4, "0")}.dex`, + new Uint8ArrayReader(dex), + ); + await writer.add("lib/arm64-v8a/libnative.so", new TextReader("native")); + await writeFile(path, await writer.close()); + + const inventory = parseEvidence( + await runProviderAnalysis(path, "inventory_artifact", {}), + ); + const result = projectAndroidApplicationEvidence({ + inventory_evidence: [inventory], + }); + + expect(result.ok).toBe(true); + if (!result.ok) return; + const projection = androidApplicationProjectionResultSchema.parse( + result.value.normalized_result, + ); + expect(projection.components.dex).toHaveLength(1_001); + expect(projection.bridge_candidates).toHaveLength(1_001); + expect(projection.coverage.status).toBe("complete-within-inventory"); + }); }); diff --git a/tests/fixtures/fakeCdpBrowserEvents.ts b/tests/fixtures/fakeCdpBrowserEvents.ts index be0895fa1..a2aa3ca71 100644 --- a/tests/fixtures/fakeCdpBrowserEvents.ts +++ b/tests/fixtures/fakeCdpBrowserEvents.ts @@ -11,6 +11,17 @@ export const emitEvents = ( emitDebuggerEvents(socket, command, port, options); emitNetworkEvents(socket, command, port, options); emitRuntimeEvents(socket, command, port, options); + emitWebMcpEvents(socket, command, port, options); + emitSessionTimeline(socket, command, port, options); + emitCaptureNavigation(socket, command, options); +}; + +const emitWebMcpEvents = ( + socket: WebSocket, + command: FakeCdpCommand, + port: number, + options: FakeOptions, +): void => { if (command.method === "WebMCP.enable" && options.webMcpTools === true) { event(socket, "WebMCP.toolsAdded", command.sessionId, { tools: [ @@ -60,6 +71,16 @@ export const emitEvents = ( }, ] : []), + ...(options.webMcpFrameCount !== undefined && + options.webMcpFrameCount > 0 + ? [ + { + name: "beyond_frame_limit_tool", + description: "Registered in an in-scope frame after index 999", + frameId: `webmcp-frame-${String(options.webMcpFrameCount - 1)}`, + }, + ] + : []), ...(options.webMcpChildLeavesScope === true ? [ { @@ -90,7 +111,14 @@ export const emitEvents = ( }); } } - emitCaptureNavigation(socket, command, options); +}; + +const emitSessionTimeline = ( + socket: WebSocket, + command: FakeCdpCommand, + port: number, + options: FakeOptions, +): void => { if ( command.method === "Page.setLifecycleEventsEnabled" && options.sessionTimeline !== undefined diff --git a/tests/fixtures/fakeCdpBrowserResults.ts b/tests/fixtures/fakeCdpBrowserResults.ts index 0cc9ca8b5..f53642899 100644 --- a/tests/fixtures/fakeCdpBrowserResults.ts +++ b/tests/fixtures/fakeCdpBrowserResults.ts @@ -66,6 +66,7 @@ const frameTreeResult = ( ? ":" : (options.electronFileUrl ?? options.attachedFrameUrl), options.extraCollections === true, + options.webMcpFrameCount, ); const resourceTreeResult = (port: number, options: FakeOptions) => @@ -214,6 +215,7 @@ const frameTree = ( port: number, overrideUrl?: string, extraCollections = false, + webMcpFrameCount = 0, ): Readonly> => ({ frameTree: { frame: { @@ -236,6 +238,14 @@ const frameTree = ( }, ] : []), + ...Array.from({ length: webMcpFrameCount }, (_value, index) => ({ + frame: { + id: `webmcp-frame-${String(index)}`, + parentId: "frame-main", + loaderId: `loader-webmcp-${String(index)}`, + url: `http://127.0.0.1:${String(port)}/webmcp-frame/${String(index)}`, + }, + })), { frame: { id: "frame-private", diff --git a/tests/fixtures/fakeCdpBrowserTypes.ts b/tests/fixtures/fakeCdpBrowserTypes.ts index da1343bab..f01d3e77a 100644 --- a/tests/fixtures/fakeCdpBrowserTypes.ts +++ b/tests/fixtures/fakeCdpBrowserTypes.ts @@ -57,6 +57,7 @@ export interface FakeOptions { readonly sensitiveShapes?: boolean; readonly invalidResponseBodyBase64?: boolean; readonly webMcpTools?: boolean; + readonly webMcpFrameCount?: number; readonly webMcpChildLeavesScope?: boolean; readonly electronFileUrl?: string; readonly duplicateElectronInventory?: boolean;