refactor(observation): internalize capture budgets
This commit is contained in:
@@ -95,31 +95,6 @@ const registerPageInspection = (
|
||||
include_script_sources: options.includeScriptSources,
|
||||
include_storage_keys: options.includeStorageKeys,
|
||||
include_storage_fingerprints: options.includeStorageFingerprints,
|
||||
limits: {
|
||||
max_frames: options.maxFrames,
|
||||
max_dom_nodes: options.maxDomNodes,
|
||||
max_ax_nodes: options.maxAxNodes,
|
||||
max_ax_text_field_bytes: options.maxAxTextFieldBytes,
|
||||
max_total_ax_text_bytes: options.maxTotalAxTextBytes,
|
||||
max_scripts: options.maxScripts,
|
||||
max_resources: options.maxResources,
|
||||
max_workers: options.maxWorkers,
|
||||
max_storage_keys: options.maxStorageKeys,
|
||||
max_script_source_bytes: options.maxScriptSourceBytes,
|
||||
max_total_script_source_bytes: options.maxTotalScriptSourceBytes,
|
||||
max_network_events: options.maxNetworkEvents,
|
||||
max_console_events: options.maxConsoleEvents,
|
||||
max_console_text_field_bytes: options.maxConsoleTextFieldBytes,
|
||||
max_total_console_text_bytes: options.maxTotalConsoleTextBytes,
|
||||
max_json_body_bytes: options.maxJsonBodyBytes,
|
||||
max_total_json_body_bytes: options.maxTotalJsonBodyBytes,
|
||||
max_json_shape_nodes: options.maxJsonShapeNodes,
|
||||
max_json_shape_depth: options.maxJsonShapeDepth,
|
||||
max_websocket_events: options.maxWebsocketEvents,
|
||||
max_websocket_shape_bytes: options.maxWebsocketShapeBytes,
|
||||
max_total_websocket_shape_bytes:
|
||||
options.maxTotalWebsocketShapeBytes,
|
||||
},
|
||||
});
|
||||
if (!parsed.success)
|
||||
return browserCliError(new AnalysisInputError("inspect_web_page"));
|
||||
|
||||
@@ -178,15 +178,6 @@ const registerElectronPageInspection = (
|
||||
target_id: args.targetId,
|
||||
observation_ms: options.observationMs,
|
||||
include_script_sources: options.includeScriptSources,
|
||||
limits: {
|
||||
max_frames: options.maxFrames,
|
||||
max_dom_nodes: options.maxDomNodes,
|
||||
max_scripts: options.maxScripts,
|
||||
max_resources: options.maxResources,
|
||||
max_workers: options.maxWorkers,
|
||||
max_script_source_bytes: options.maxScriptSourceBytes,
|
||||
max_total_script_source_bytes: options.maxTotalScriptSourceBytes,
|
||||
},
|
||||
});
|
||||
if (!parsed.success) return inputError("inspect_electron_page");
|
||||
const result = await inspectElectronPage(
|
||||
|
||||
@@ -52,41 +52,6 @@ const observeOptionsSchema = z.object({
|
||||
.max(10_000)
|
||||
.default(100)
|
||||
.describe("Bounded observation window in milliseconds"),
|
||||
maxEvents: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(50_000)
|
||||
.default(10_000)
|
||||
.describe("Maximum retained protocol events"),
|
||||
maxScripts: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(10_000)
|
||||
.default(2_000)
|
||||
.describe("Maximum retained scripts"),
|
||||
maxExecutionContexts: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(5_000)
|
||||
.default(1_000)
|
||||
.describe("Maximum retained execution contexts"),
|
||||
maxLocationBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(64)
|
||||
.max(65_536)
|
||||
.default(16_384)
|
||||
.describe("Maximum bytes in one protocol location"),
|
||||
maxTotalMetadataBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1_024)
|
||||
.max(32 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024)
|
||||
.describe("Maximum retained metadata bytes"),
|
||||
});
|
||||
|
||||
/** Register CLI equivalents of passive V8 Inspector tools. */
|
||||
@@ -148,13 +113,6 @@ export const registerJavaScriptRuntimeObservationCommands = (
|
||||
target_id: args.targetId,
|
||||
runtime_kind: options.runtimeKind,
|
||||
observation_ms: options.observationMs,
|
||||
limits: {
|
||||
max_events: options.maxEvents,
|
||||
max_scripts: options.maxScripts,
|
||||
max_execution_contexts: options.maxExecutionContexts,
|
||||
max_location_bytes: options.maxLocationBytes,
|
||||
max_total_metadata_bytes: options.maxTotalMetadataBytes,
|
||||
},
|
||||
});
|
||||
if (!parsed.success) return inputError("observe_javascript_runtime");
|
||||
const result = await observeJavaScriptRuntime(
|
||||
|
||||
@@ -15,13 +15,6 @@ export const boundedCount = (
|
||||
.default(fallback)
|
||||
.describe(`Maximum ${subject}`);
|
||||
|
||||
/** Bound a CLI observation byte budget. */
|
||||
export const boundedBytes = (
|
||||
subject: string,
|
||||
maximum: number,
|
||||
fallback: number,
|
||||
) => boundedCount(`${subject} in bytes`, maximum, fallback);
|
||||
|
||||
/** Shared passive browser origin options. */
|
||||
export const browserScopeOptions = {
|
||||
allowedOrigins: z
|
||||
@@ -68,68 +61,6 @@ export const browserPageInspectionOptions = z.object({
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include content-derived storage fingerprints"),
|
||||
maxFrames: boundedCount("page frames", 1_000, 200),
|
||||
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
|
||||
maxAxNodes: boundedCount("accessibility nodes", 10_000, 2_000),
|
||||
maxAxTextFieldBytes: boundedBytes(
|
||||
"one accessibility text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalAxTextBytes: boundedBytes(
|
||||
"total accessibility text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxScripts: boundedCount("scripts", 1_000, 200),
|
||||
maxResources: boundedCount("resources", 10_000, 2_000),
|
||||
maxWorkers: boundedCount("workers", 5_000, 500),
|
||||
maxStorageKeys: boundedCount("storage keys", 10_000, 1_000),
|
||||
maxScriptSourceBytes: boundedBytes(
|
||||
"one script source",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalScriptSourceBytes: boundedBytes(
|
||||
"total script source",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxNetworkEvents: boundedCount("network events", 10_000, 1_000),
|
||||
maxConsoleEvents: boundedCount("console events", 2_000, 200),
|
||||
maxConsoleTextFieldBytes: boundedBytes(
|
||||
"one console text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalConsoleTextBytes: boundedBytes(
|
||||
"total console text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxJsonBodyBytes: boundedBytes(
|
||||
"one JSON response body",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalJsonBodyBytes: boundedBytes(
|
||||
"total JSON response bodies",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxJsonShapeNodes: boundedCount("JSON shape nodes", 100_000, 5_000),
|
||||
maxJsonShapeDepth: boundedCount("JSON shape depth", 100, 20),
|
||||
maxWebsocketEvents: boundedCount("WebSocket events", 5_000, 500),
|
||||
maxWebsocketShapeBytes: boundedBytes(
|
||||
"one WebSocket shape",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxTotalWebsocketShapeBytes: boundedBytes(
|
||||
"total WebSocket shapes",
|
||||
16 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
});
|
||||
|
||||
/** Shared passive Electron root options. */
|
||||
@@ -152,21 +83,6 @@ export const electronPageInspectionOptions = z.object({
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded JavaScript source text"),
|
||||
maxFrames: boundedCount("page frames", 1_000, 200),
|
||||
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
|
||||
maxScripts: boundedCount("scripts", 2_000, 500),
|
||||
maxResources: boundedCount("resources", 10_000, 2_000),
|
||||
maxWorkers: boundedCount("workers", 5_000, 500),
|
||||
maxScriptSourceBytes: boundedBytes(
|
||||
"one captured script source",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalScriptSourceBytes: boundedBytes(
|
||||
"total captured script source",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
});
|
||||
|
||||
export const javascriptApplicationOptions = z.object({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ToolContract } from "./toolContracts.js";
|
||||
import {
|
||||
browserTargetListSchema,
|
||||
inspectWebPageInputSchema,
|
||||
inspectWebPageToolInputSchema,
|
||||
listBrowserTargetsInputSchema,
|
||||
webPageInspectionSchema,
|
||||
} from "../domain/browserObservation.js";
|
||||
@@ -140,7 +140,7 @@ export const BROWSER_TOOL_CONTRACTS = [
|
||||
description:
|
||||
"Passively inspect one approved page target through CDP without evaluating JavaScript, navigating, clicking, closing, or mutating the page. Returns bounded DOM structure, accessibility, scripts, resources, attach-window network and console metadata, workers, and redacted storage inventory as Evidence.",
|
||||
kind: "browser-provider",
|
||||
inputSchema: inspectWebPageInputSchema,
|
||||
inputSchema: inspectWebPageToolInputSchema,
|
||||
outputSchema: inspectionOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ import { evidenceResultOf } from "./toolOutputSchemas.js";
|
||||
import {
|
||||
electronPageInspectionSchema,
|
||||
electronTargetListSchema,
|
||||
inspectElectronPageInputSchema,
|
||||
inspectElectronPageToolInputSchema,
|
||||
listElectronTargetsInputSchema,
|
||||
} from "../domain/electronObservation.js";
|
||||
import {
|
||||
@@ -74,7 +74,7 @@ export const ELECTRON_TOOL_CONTRACTS = [
|
||||
description:
|
||||
"Passively inspect one approved Electron file page through CDP. Returns root-confined frames, DOM structure, resource paths, and scripts without evaluating renderer JavaScript or invoking Electron APIs; script contents require separate approval.",
|
||||
kind: "electron-provider",
|
||||
inputSchema: inspectElectronPageInputSchema,
|
||||
inputSchema: inspectElectronPageToolInputSchema,
|
||||
outputSchema: inspectionOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
javascriptRuntimeObservationSchema,
|
||||
javascriptRuntimeTargetListSchema,
|
||||
listJavaScriptRuntimeTargetsInputSchema,
|
||||
observeJavaScriptRuntimeInputSchema,
|
||||
observeJavaScriptRuntimeToolInputSchema,
|
||||
} from "../domain/javascriptRuntimeObservation.js";
|
||||
|
||||
const root = "/opt/example-app";
|
||||
@@ -38,7 +38,7 @@ export const JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS = [
|
||||
description:
|
||||
"Attach passively to one exact approved Node/Electron V8 Inspector target and capture bounded Debugger.scriptParsed plus Runtime execution-context events. REA sends only Runtime.enable and Debugger.enable: it never evaluates, pauses, resumes, reads source, or instruments the target. require/import edges, EventEmitter activity, and Electron IPC remain explicit unknowns; reconcile the returned Evidence with static Application Graph Evidence using reconcile_javascript_runtime.",
|
||||
kind: "runtime-provider",
|
||||
inputSchema: observeJavaScriptRuntimeInputSchema,
|
||||
inputSchema: observeJavaScriptRuntimeToolInputSchema,
|
||||
outputSchema: evidenceResultOf(javascriptRuntimeObservationSchema),
|
||||
examples: [
|
||||
{
|
||||
|
||||
@@ -101,6 +101,14 @@ describe("browser observation contracts", () => {
|
||||
max_total_websocket_shape_bytes: 1_048_576,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
inspectWebPageInputSchema.safeParse({
|
||||
cdp_endpoint: "http://127.0.0.1:9222",
|
||||
allowed_origins: ["https://app.example.test"],
|
||||
target_id: "page-1",
|
||||
limits: {},
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -102,82 +102,8 @@ export const listBrowserTargetsInputSchema = z.object({
|
||||
...browserInput,
|
||||
});
|
||||
|
||||
const browserInspectionLimitsSchema = z.object({
|
||||
max_frames: z.number().int().min(1).max(1_000).default(200),
|
||||
max_dom_nodes: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_ax_nodes: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_ax_text_field_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024)
|
||||
.default(1_024),
|
||||
max_total_ax_text_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(1_024 * 1_024)
|
||||
.default(64 * 1_024),
|
||||
max_scripts: z.number().int().min(1).max(1_000).default(200),
|
||||
max_resources: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_workers: z.number().int().min(1).max(5_000).default(500),
|
||||
max_storage_keys: z.number().int().min(1).max(10_000).default(1_000),
|
||||
max_script_source_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(4 * 1_024 * 1_024)
|
||||
.default(1_024 * 1_024),
|
||||
max_total_script_source_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024),
|
||||
max_network_events: z.number().int().min(1).max(10_000).default(1_000),
|
||||
max_console_events: z.number().int().min(1).max(2_000).default(200),
|
||||
max_console_text_field_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024)
|
||||
.default(1_024),
|
||||
max_total_console_text_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(1_024 * 1_024)
|
||||
.default(64 * 1_024),
|
||||
max_json_body_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(4 * 1_024 * 1_024)
|
||||
.default(1_024 * 1_024),
|
||||
max_total_json_body_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024),
|
||||
max_json_shape_nodes: z.number().int().min(1).max(100_000).default(5_000),
|
||||
max_json_shape_depth: z.number().int().min(1).max(100).default(20),
|
||||
max_websocket_events: z.number().int().min(1).max(5_000).default(500),
|
||||
max_websocket_shape_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(1_024 * 1_024)
|
||||
.default(64 * 1_024),
|
||||
max_total_websocket_shape_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024 * 1_024)
|
||||
.default(1_024 * 1_024),
|
||||
});
|
||||
|
||||
const DEFAULT_BROWSER_INSPECTION_LIMITS = {
|
||||
/** Collection bounds for passive browser capture, applied internally. */
|
||||
export const DEFAULT_BROWSER_INSPECTION_LIMITS = {
|
||||
max_frames: 200,
|
||||
max_dom_nodes: 2_000,
|
||||
max_ax_nodes: 2_000,
|
||||
@@ -200,7 +126,7 @@ const DEFAULT_BROWSER_INSPECTION_LIMITS = {
|
||||
max_websocket_events: 500,
|
||||
max_websocket_shape_bytes: 64 * 1_024,
|
||||
max_total_websocket_shape_bytes: 1_024 * 1_024,
|
||||
} as const;
|
||||
};
|
||||
|
||||
const inspectWebPageInputFacts = {
|
||||
...browserInput,
|
||||
@@ -212,9 +138,6 @@ const inspectWebPageInputFacts = {
|
||||
include_websocket_shapes: z.boolean().default(false),
|
||||
include_storage_keys: z.boolean().default(false),
|
||||
include_storage_fingerprints: z.boolean().default(false),
|
||||
limits: browserInspectionLimitsSchema.default(
|
||||
DEFAULT_BROWSER_INSPECTION_LIMITS,
|
||||
),
|
||||
} as const;
|
||||
|
||||
const inspectWebPageWithoutSourceSchema = z.strictObject({
|
||||
@@ -241,61 +164,25 @@ const refineInspectWebPageInput = (
|
||||
path: ["include_storage_fingerprints"],
|
||||
message: "Storage fingerprints require storage key capture",
|
||||
});
|
||||
if (
|
||||
input.limits.max_script_source_bytes >
|
||||
input.limits.max_total_script_source_bytes
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_script_source_bytes"],
|
||||
message: "Per-script source limit cannot exceed the total source limit",
|
||||
});
|
||||
if (
|
||||
input.limits.max_console_text_field_bytes >
|
||||
input.limits.max_total_console_text_bytes
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_console_text_field_bytes"],
|
||||
message:
|
||||
"Per-field console text limit cannot exceed the total text limit",
|
||||
});
|
||||
if (input.limits.max_json_body_bytes > input.limits.max_total_json_body_bytes)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_json_body_bytes"],
|
||||
message: "Per-body JSON limit cannot exceed the total body limit",
|
||||
});
|
||||
if (
|
||||
input.limits.max_websocket_shape_bytes >
|
||||
input.limits.max_total_websocket_shape_bytes
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_websocket_shape_bytes"],
|
||||
message: "Per-frame WebSocket limit cannot exceed the total frame limit",
|
||||
});
|
||||
if (
|
||||
input.limits.max_ax_text_field_bytes > input.limits.max_total_ax_text_bytes
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_ax_text_field_bytes"],
|
||||
message:
|
||||
"Per-field accessibility text limit cannot exceed the total text limit",
|
||||
});
|
||||
};
|
||||
|
||||
/** Source-capturing inspection input, reusable by static bundle analysis. */
|
||||
/** Caller schema for source-capturing inspection and bundle analysis. */
|
||||
export const inspectWebPageWithSourceInputSchema =
|
||||
inspectWebPageWithSourceShapeSchema.superRefine(refineInspectWebPageInput);
|
||||
|
||||
/** Public input for one passive, bounded inspection of an existing page. */
|
||||
export const inspectWebPageInputSchema = z.union([
|
||||
/** Caller-visible schema for one passive inspection. */
|
||||
export const inspectWebPageToolInputSchema = z.union([
|
||||
inspectWebPageWithoutSourceSchema.superRefine(refineInspectWebPageInput),
|
||||
inspectWebPageWithSourceInputSchema,
|
||||
]);
|
||||
|
||||
/** Internal parsed input with REA's fixed collection bounds applied. */
|
||||
export const inspectWebPageInputSchema =
|
||||
inspectWebPageToolInputSchema.transform((input) => ({
|
||||
...input,
|
||||
limits: DEFAULT_BROWSER_INSPECTION_LIMITS,
|
||||
}));
|
||||
|
||||
export type ListBrowserTargetsInput = z.infer<
|
||||
typeof listBrowserTargetsInputSchema
|
||||
>;
|
||||
|
||||
@@ -24,6 +24,17 @@ const approvedElectronInput = {
|
||||
allowed_file_roots: electronFileRootsSchema,
|
||||
};
|
||||
|
||||
/** Collection bounds for passive Electron capture, applied internally. */
|
||||
export const DEFAULT_ELECTRON_INSPECTION_LIMITS = {
|
||||
max_frames: 200,
|
||||
max_dom_nodes: 2_000,
|
||||
max_scripts: 500,
|
||||
max_resources: 2_000,
|
||||
max_workers: 500,
|
||||
max_script_source_bytes: 1_024 * 1_024,
|
||||
max_total_script_source_bytes: 4 * 1_024 * 1_024,
|
||||
};
|
||||
|
||||
/** Input for listing root-confined file:// page targets from Electron CDP. */
|
||||
export const listElectronTargetsInputSchema = z.strictObject({
|
||||
...approvedElectronInput,
|
||||
@@ -37,35 +48,6 @@ const inspectElectronPageFacts = {
|
||||
...approvedElectronInput,
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
observation_ms: z.number().int().min(0).max(10_000).default(100),
|
||||
limits: z
|
||||
.strictObject({
|
||||
max_frames: z.number().int().min(1).max(1_000).default(200),
|
||||
max_dom_nodes: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_scripts: z.number().int().min(1).max(2_000).default(500),
|
||||
max_resources: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_workers: z.number().int().min(1).max(5_000).default(500),
|
||||
max_script_source_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(4 * 1_024 * 1_024)
|
||||
.default(1_024 * 1_024),
|
||||
max_total_script_source_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024),
|
||||
})
|
||||
.default({
|
||||
max_frames: 200,
|
||||
max_dom_nodes: 2_000,
|
||||
max_scripts: 500,
|
||||
max_resources: 2_000,
|
||||
max_workers: 500,
|
||||
max_script_source_bytes: 1_024 * 1_024,
|
||||
max_total_script_source_bytes: 4 * 1_024 * 1_024,
|
||||
}),
|
||||
} as const;
|
||||
export const inspectElectronPageInputSchema = z
|
||||
.union([
|
||||
@@ -78,17 +60,20 @@ export const inspectElectronPageInputSchema = z
|
||||
include_script_sources: z.literal(true),
|
||||
}),
|
||||
])
|
||||
.superRefine((input, context) => {
|
||||
if (
|
||||
input.limits.max_script_source_bytes >
|
||||
input.limits.max_total_script_source_bytes
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["limits", "max_script_source_bytes"],
|
||||
message: "Per-script source limit cannot exceed the total source limit",
|
||||
});
|
||||
});
|
||||
.transform((input) => ({
|
||||
...input,
|
||||
limits: DEFAULT_ELECTRON_INSPECTION_LIMITS,
|
||||
}));
|
||||
export const inspectElectronPageToolInputSchema = z.union([
|
||||
z.strictObject({
|
||||
...inspectElectronPageFacts,
|
||||
include_script_sources: z.literal(false).default(false),
|
||||
}),
|
||||
z.strictObject({
|
||||
...inspectElectronPageFacts,
|
||||
include_script_sources: z.literal(true),
|
||||
}),
|
||||
]);
|
||||
export type InspectElectronPageInput = z.infer<
|
||||
typeof inspectElectronPageInputSchema
|
||||
>;
|
||||
|
||||
@@ -72,35 +72,31 @@ const observedJavaScriptRuntimeKindSchema = javascriptRuntimeKindSchema.or(
|
||||
z.literal("unknown"),
|
||||
);
|
||||
|
||||
export const javascriptRuntimeObservationLimitsSchema = z.strictObject({
|
||||
max_events: z.number().int().min(1).max(50_000).default(10_000),
|
||||
max_scripts: z.number().int().min(1).max(10_000).default(2_000),
|
||||
max_execution_contexts: z.number().int().min(1).max(5_000).default(1_000),
|
||||
max_location_bytes: z.number().int().min(64).max(65_536).default(16_384),
|
||||
max_total_metadata_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1_024)
|
||||
.max(32 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024),
|
||||
});
|
||||
/** Collection bounds for passive V8 Inspector capture, applied internally. */
|
||||
export const DEFAULT_JAVASCRIPT_RUNTIME_OBSERVATION_LIMITS = {
|
||||
max_events: 10_000,
|
||||
max_scripts: 2_000,
|
||||
max_execution_contexts: 1_000,
|
||||
max_location_bytes: 16_384,
|
||||
max_total_metadata_bytes: 4 * 1_024 * 1_024,
|
||||
};
|
||||
|
||||
/** Input for one bounded, attach-only V8 Inspector observation. */
|
||||
export const observeJavaScriptRuntimeInputSchema = z
|
||||
export const observeJavaScriptRuntimeToolInputSchema = z
|
||||
.strictObject({
|
||||
...runtimeScope,
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
runtime_kind: javascriptRuntimeKindSchema.optional(),
|
||||
observation_ms: z.number().int().min(0).max(10_000).default(100),
|
||||
limits: javascriptRuntimeObservationLimitsSchema.default({
|
||||
max_events: 10_000,
|
||||
max_scripts: 2_000,
|
||||
max_execution_contexts: 1_000,
|
||||
max_location_bytes: 16_384,
|
||||
max_total_metadata_bytes: 4 * 1_024 * 1_024,
|
||||
}),
|
||||
})
|
||||
.superRefine(requireRuntimeScope);
|
||||
|
||||
/** Internal parsed input with REA's fixed collection bounds applied. */
|
||||
export const observeJavaScriptRuntimeInputSchema =
|
||||
observeJavaScriptRuntimeToolInputSchema.transform((input) => ({
|
||||
...input,
|
||||
limits: DEFAULT_JAVASCRIPT_RUNTIME_OBSERVATION_LIMITS,
|
||||
}));
|
||||
export type ObserveJavaScriptRuntimeInput = z.infer<
|
||||
typeof observeJavaScriptRuntimeInputSchema
|
||||
>;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { inspectWebPageWithSourceInputSchema } from "./browserObservation.js";
|
||||
import {
|
||||
DEFAULT_BROWSER_INSPECTION_LIMITS,
|
||||
inspectWebPageWithSourceInputSchema,
|
||||
} from "./browserObservation.js";
|
||||
import { webTextArtifactSchema } from "./webContentArtifact.js";
|
||||
|
||||
/** Provider-owned parser and network safety bounds, never caller settings. */
|
||||
@@ -20,11 +23,13 @@ export const analyzeWebBundleToolInputSchema =
|
||||
export const analyzeWebBundleInputSchema =
|
||||
analyzeWebBundleToolInputSchema.transform((input) => ({
|
||||
...input,
|
||||
limits: DEFAULT_BROWSER_INSPECTION_LIMITS,
|
||||
analysis_limits: WEB_BUNDLE_ANALYSIS_LIMITS,
|
||||
})) as z.ZodType<AnalyzeWebBundleInput>;
|
||||
export type AnalyzeWebBundleInput = z.infer<
|
||||
typeof inspectWebPageWithSourceInputSchema
|
||||
> & {
|
||||
readonly limits: typeof DEFAULT_BROWSER_INSPECTION_LIMITS;
|
||||
readonly fetch_source_maps: boolean;
|
||||
readonly analysis_limits: typeof WEB_BUNDLE_ANALYSIS_LIMITS;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
inspectWebPageInputSchema,
|
||||
inspectWebPageToolInputSchema,
|
||||
webPageInspectionSchema,
|
||||
} from "./browserObservation.js";
|
||||
import { analyzeCapturedWebBundle } from "./webBundleAnalyzer.js";
|
||||
@@ -142,7 +142,7 @@ describe("web bundle analyzer", () => {
|
||||
|
||||
const input = (overrides: Record<string, unknown> = {}) =>
|
||||
analyzeWebBundleInputSchema.parse({
|
||||
...inspectWebPageInputSchema.parse({
|
||||
...inspectWebPageToolInputSchema.parse({
|
||||
cdp_endpoint: "http://127.0.0.1:9222",
|
||||
allowed_origins: [origin],
|
||||
target_id: "page-1",
|
||||
|
||||
@@ -19,6 +19,7 @@ import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import { analyzeWebBundleInputSchema } from "../domain/webBundleAnalysis.js";
|
||||
import { inspectWebPageInputSchema } from "../domain/browserObservation.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
@@ -83,10 +84,12 @@ export const registerBrowserTools = (
|
||||
inspectContract,
|
||||
{ input, context },
|
||||
(parsed, { signal, progress }) =>
|
||||
inspectWebPage(options.browser, options.permissionAuthority, parsed, {
|
||||
signal,
|
||||
progress,
|
||||
}),
|
||||
inspectWebPage(
|
||||
options.browser,
|
||||
options.permissionAuthority,
|
||||
inspectWebPageInputSchema.parse(parsed),
|
||||
{ signal, progress },
|
||||
),
|
||||
),
|
||||
);
|
||||
server.registerTool(
|
||||
|
||||
@@ -17,6 +17,7 @@ import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import { inspectElectronPageInputSchema } from "../domain/electronObservation.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
@@ -81,7 +82,7 @@ export const registerElectronTools = (
|
||||
inspectElectronPage(
|
||||
options.electron,
|
||||
options.permissionAuthority,
|
||||
parsed,
|
||||
inspectElectronPageInputSchema.parse(parsed),
|
||||
{
|
||||
signal,
|
||||
progress,
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../domain/javascriptRuntimeObservation.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
@@ -60,7 +61,7 @@ export const registerJavaScriptRuntimeObservationTools = (
|
||||
observeJavaScriptRuntime(
|
||||
options.runtime,
|
||||
options.permissionAuthority,
|
||||
parsed,
|
||||
observeJavaScriptRuntimeInputSchema.parse(parsed),
|
||||
{ signal },
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user