refactor(mcp): simplify tool inputs and inline results
This commit is contained in:
@@ -44,10 +44,6 @@ const comparisonDimensionSchema = z.enum([
|
||||
export const artifactComparisonInputSchema = z.strictObject({
|
||||
left_evidence_id: evidenceIdSchema,
|
||||
right_evidence_id: evidenceIdSchema,
|
||||
unknown_registry_approved: z
|
||||
.literal(true)
|
||||
.optional()
|
||||
.describe("Explicit approval to record incomplete or differing evidence"),
|
||||
});
|
||||
|
||||
/** One path-classified artifact change with citations to both observations. */
|
||||
|
||||
@@ -2,10 +2,10 @@ import { z } from "zod";
|
||||
|
||||
import {
|
||||
BROWSER_SCENARIO_LIMITS,
|
||||
BROWSER_SCENARIO_CAPTURE_LIMITS,
|
||||
browserScenarioActionSchema,
|
||||
browserScenarioAllowedOriginsSchema,
|
||||
browserScenarioBrowserSchema,
|
||||
browserScenarioCaptureLimitsSchema,
|
||||
browserScenarioCaptureSchema,
|
||||
browserScenarioEnvironmentSchema,
|
||||
browserScenarioRedactionSchema,
|
||||
@@ -28,26 +28,42 @@ export {
|
||||
type BrowserScenarioValue,
|
||||
} from "./browserScenarioValues.js";
|
||||
|
||||
const scenarioShapeSchema = z.strictObject({
|
||||
browser: browserScenarioBrowserSchema,
|
||||
start_url: browserScenarioUrlSchema,
|
||||
allowed_origins: browserScenarioAllowedOriginsSchema,
|
||||
export const browserScenarioInputSchema = z.strictObject({
|
||||
browser: browserScenarioBrowserSchema.describe(
|
||||
"Required launch/connect authority. Launch uses the approved executable and an owned temporary profile; connect uses one approved loopback CDP endpoint and target.",
|
||||
),
|
||||
start_url: browserScenarioUrlSchema.describe(
|
||||
"Required initial HTTP(S) URL. Query values must be declared separately as public literals or secret references.",
|
||||
),
|
||||
allowed_origins: browserScenarioAllowedOriginsSchema.describe(
|
||||
"Required exact HTTP(S) origins for the start URL and every later navigation, storage seed, and replay route.",
|
||||
),
|
||||
environment: browserScenarioEnvironmentSchema,
|
||||
actions: z
|
||||
.array(browserScenarioActionSchema)
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.actions),
|
||||
.max(BROWSER_SCENARIO_LIMITS.actions)
|
||||
.describe("Required bounded sequence of explicit browser actions."),
|
||||
storage: browserScenarioStorageSchema,
|
||||
request_replay: browserScenarioRequestReplaySchema,
|
||||
secrets: z
|
||||
.array(browserScenarioSecretSchema)
|
||||
.max(BROWSER_SCENARIO_LIMITS.secrets)
|
||||
.default([]),
|
||||
.default([])
|
||||
.describe(
|
||||
"Optional references to approved environment variables. Secret values are never supplied inline; declarations are required only when an action, URL, storage value, or replay route references a secret.",
|
||||
),
|
||||
redaction: browserScenarioRedactionSchema,
|
||||
capture: browserScenarioCaptureSchema,
|
||||
limits: browserScenarioCaptureLimitsSchema,
|
||||
});
|
||||
|
||||
const scenarioShapeSchema = browserScenarioInputSchema.transform(
|
||||
(scenario) => ({
|
||||
...scenario,
|
||||
limits: BROWSER_SCENARIO_CAPTURE_LIMITS,
|
||||
}),
|
||||
);
|
||||
|
||||
type ScenarioShape = z.infer<typeof scenarioShapeSchema>;
|
||||
|
||||
const addIssue = (
|
||||
|
||||
+161
-123
@@ -15,6 +15,42 @@ export const BROWSER_SCENARIO_LIMITS = {
|
||||
actionTimeoutMs: 60_000,
|
||||
} as const;
|
||||
|
||||
/** Fixed internal budgets for provider-owned scenario capture. */
|
||||
export interface BrowserScenarioCaptureLimits {
|
||||
readonly max_duration_ms: number;
|
||||
readonly action_timeout_ms: number;
|
||||
readonly navigation_timeout_ms: number;
|
||||
readonly max_events: number;
|
||||
readonly max_frames: number;
|
||||
readonly max_workers: number;
|
||||
readonly max_popups: number;
|
||||
readonly max_websockets: number;
|
||||
readonly max_dom_nodes: number;
|
||||
readonly max_accessibility_nodes: number;
|
||||
readonly max_screenshots: number;
|
||||
readonly max_screenshot_bytes: number;
|
||||
readonly max_storage_entries: number;
|
||||
readonly max_total_metadata_bytes: number;
|
||||
}
|
||||
|
||||
export const BROWSER_SCENARIO_CAPTURE_LIMITS: BrowserScenarioCaptureLimits =
|
||||
Object.freeze({
|
||||
max_duration_ms: 60_000,
|
||||
action_timeout_ms: 5_000,
|
||||
navigation_timeout_ms: 10_000,
|
||||
max_events: 2_000,
|
||||
max_frames: 100,
|
||||
max_workers: 20,
|
||||
max_popups: 10,
|
||||
max_websockets: 100,
|
||||
max_dom_nodes: 10_000,
|
||||
max_accessibility_nodes: 10_000,
|
||||
max_screenshots: 16,
|
||||
max_screenshot_bytes: 4 * 1_024 * 1_024,
|
||||
max_storage_entries: 256,
|
||||
max_total_metadata_bytes: 4 * 1_024 * 1_024,
|
||||
});
|
||||
|
||||
export const scenarioIdentifierSchema = z
|
||||
.string()
|
||||
.regex(/^[A-Za-z][A-Za-z0-9._-]{0,63}$/u);
|
||||
@@ -102,26 +138,42 @@ export const browserScenarioBrowserSchema = z.discriminatedUnion("mode", [
|
||||
}),
|
||||
]);
|
||||
|
||||
export const browserScenarioEnvironmentSchema = z.strictObject({
|
||||
viewport: z.strictObject({
|
||||
width: z.number().int().min(320).max(7_680),
|
||||
height: z.number().int().min(240).max(4_320),
|
||||
device_scale_factor: z.number().min(0.5).max(4).default(1),
|
||||
}),
|
||||
locale: z
|
||||
.string()
|
||||
.min(2)
|
||||
.max(64)
|
||||
.regex(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/u),
|
||||
timezone: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(128)
|
||||
.regex(/^[A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)*$/u),
|
||||
color_scheme: z.enum(["light", "dark", "no-preference"]),
|
||||
reduced_motion: z.enum(["reduce", "no-preference"]),
|
||||
service_workers: z.literal("block"),
|
||||
});
|
||||
export const browserScenarioEnvironmentSchema = z
|
||||
.strictObject({
|
||||
viewport: z
|
||||
.strictObject({
|
||||
width: z.number().int().min(320).max(7_680).default(1_280),
|
||||
height: z.number().int().min(240).max(4_320).default(720),
|
||||
device_scale_factor: z.number().min(0.5).max(4).default(1),
|
||||
})
|
||||
.default({ width: 1_280, height: 720, device_scale_factor: 1 }),
|
||||
locale: z
|
||||
.string()
|
||||
.min(2)
|
||||
.max(64)
|
||||
.regex(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/u)
|
||||
.default("en-US"),
|
||||
timezone: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(128)
|
||||
.regex(/^[A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)*$/u)
|
||||
.default("UTC"),
|
||||
color_scheme: z.enum(["light", "dark", "no-preference"]).default("light"),
|
||||
reduced_motion: z.enum(["reduce", "no-preference"]).default("reduce"),
|
||||
service_workers: z.literal("block").default("block"),
|
||||
})
|
||||
.default({
|
||||
viewport: { width: 1_280, height: 720, device_scale_factor: 1 },
|
||||
locale: "en-US",
|
||||
timezone: "UTC",
|
||||
color_scheme: "light",
|
||||
reduced_motion: "reduce",
|
||||
service_workers: "block",
|
||||
})
|
||||
.describe(
|
||||
"Optional deterministic browser settings. Defaults to 1280x720, en-US, UTC, light mode, reduced motion, and blocked service workers.",
|
||||
);
|
||||
|
||||
const locatorSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
@@ -225,39 +277,44 @@ const storageEntrySchema = z.strictObject({
|
||||
value: browserScenarioValueSchema,
|
||||
});
|
||||
|
||||
export const browserScenarioStorageSchema = z.strictObject({
|
||||
cookies: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
name: z.string().min(1).max(1_024),
|
||||
value: browserScenarioValueSchema,
|
||||
destination: browserScenarioUrlSchema,
|
||||
http_only: z.boolean(),
|
||||
secure: z.boolean(),
|
||||
same_site: z.enum(["Strict", "Lax", "None"]),
|
||||
}),
|
||||
)
|
||||
.max(128)
|
||||
.default([]),
|
||||
local_storage: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
origin: browserOriginSchema,
|
||||
entries: z.array(storageEntrySchema).max(128),
|
||||
}),
|
||||
)
|
||||
.max(32)
|
||||
.default([]),
|
||||
session_storage: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
origin: browserOriginSchema,
|
||||
entries: z.array(storageEntrySchema).max(128),
|
||||
}),
|
||||
)
|
||||
.max(32)
|
||||
.default([]),
|
||||
});
|
||||
export const browserScenarioStorageSchema = z
|
||||
.strictObject({
|
||||
cookies: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
name: z.string().min(1).max(1_024),
|
||||
value: browserScenarioValueSchema,
|
||||
destination: browserScenarioUrlSchema,
|
||||
http_only: z.boolean(),
|
||||
secure: z.boolean(),
|
||||
same_site: z.enum(["Strict", "Lax", "None"]),
|
||||
}),
|
||||
)
|
||||
.max(128)
|
||||
.default([]),
|
||||
local_storage: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
origin: browserOriginSchema,
|
||||
entries: z.array(storageEntrySchema).max(128),
|
||||
}),
|
||||
)
|
||||
.max(32)
|
||||
.default([]),
|
||||
session_storage: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
origin: browserOriginSchema,
|
||||
entries: z.array(storageEntrySchema).max(128),
|
||||
}),
|
||||
)
|
||||
.max(32)
|
||||
.default([]),
|
||||
})
|
||||
.default({ cookies: [], local_storage: [], session_storage: [] })
|
||||
.describe(
|
||||
"Optional initial cookies, local storage, or session storage. Defaults to empty; every supplied value and origin must be explicitly declared and approved.",
|
||||
);
|
||||
|
||||
const headerNameSchema = z
|
||||
.string()
|
||||
@@ -298,17 +355,22 @@ const replayRouteSchema = z.strictObject({
|
||||
response: replayResponseSchema,
|
||||
});
|
||||
|
||||
export const browserScenarioRequestReplaySchema = z.discriminatedUnion("mode", [
|
||||
z.strictObject({ mode: z.literal("disabled") }),
|
||||
z.strictObject({
|
||||
mode: z.literal("exact"),
|
||||
unmatched: z.enum(["abort", "passthrough-approved-origins"]),
|
||||
routes: z
|
||||
.array(replayRouteSchema)
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.replayRoutes),
|
||||
}),
|
||||
]);
|
||||
export const browserScenarioRequestReplaySchema = z
|
||||
.discriminatedUnion("mode", [
|
||||
z.strictObject({ mode: z.literal("disabled") }),
|
||||
z.strictObject({
|
||||
mode: z.literal("exact"),
|
||||
unmatched: z.enum(["abort", "passthrough-approved-origins"]),
|
||||
routes: z
|
||||
.array(replayRouteSchema)
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.replayRoutes),
|
||||
}),
|
||||
])
|
||||
.default({ mode: "disabled" })
|
||||
.describe(
|
||||
"Optional exact request replay. Defaults to disabled; replay routes and unmatched-request behavior must be explicitly declared when enabled.",
|
||||
);
|
||||
|
||||
export const browserScenarioSecretSchema = z.strictObject({
|
||||
secret_id: scenarioIdentifierSchema,
|
||||
@@ -339,7 +401,9 @@ const normalizedNames = (maximum: number) =>
|
||||
|
||||
export const browserScenarioRedactionSchema = z
|
||||
.strictObject({
|
||||
secret_values: z.literal("replace-with-secret-reference"),
|
||||
secret_values: z
|
||||
.literal("replace-with-secret-reference")
|
||||
.default("replace-with-secret-reference"),
|
||||
query_parameter_names: normalizedNames(128).default([]),
|
||||
header_names: normalizedNames(128).default([...REQUIRED_REDACTED_HEADERS]),
|
||||
})
|
||||
@@ -351,7 +415,15 @@ export const browserScenarioRedactionSchema = z
|
||||
path: ["header_names"],
|
||||
message: `Required credential header ${required} must be redacted`,
|
||||
});
|
||||
});
|
||||
})
|
||||
.default({
|
||||
secret_values: "replace-with-secret-reference",
|
||||
query_parameter_names: [],
|
||||
header_names: [...REQUIRED_REDACTED_HEADERS],
|
||||
})
|
||||
.describe(
|
||||
"Redaction policy. Secret values and credential headers are always redacted; list query parameter names when a secret is used in a URL.",
|
||||
);
|
||||
|
||||
const snapshotKindSchema = z.enum([
|
||||
"screenshot",
|
||||
@@ -362,62 +434,28 @@ const snapshotKindSchema = z.enum([
|
||||
"storage",
|
||||
]);
|
||||
|
||||
export const browserScenarioCaptureSchema = z.strictObject({
|
||||
after_each_step: z.array(snapshotKindSchema).max(6),
|
||||
at_end: z.array(snapshotKindSchema).max(6),
|
||||
events: z.array(
|
||||
z.enum([
|
||||
"console",
|
||||
"page-errors",
|
||||
"network",
|
||||
"websockets",
|
||||
"frames",
|
||||
"workers",
|
||||
"popups",
|
||||
"downloads",
|
||||
]),
|
||||
),
|
||||
});
|
||||
|
||||
export const browserScenarioCaptureLimitsSchema = z.strictObject({
|
||||
max_duration_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.min(100)
|
||||
.max(BROWSER_SCENARIO_LIMITS.durationMs),
|
||||
action_timeout_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.actionTimeoutMs),
|
||||
navigation_timeout_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.actionTimeoutMs),
|
||||
max_events: z.number().int().min(1).max(100_000),
|
||||
max_frames: z.number().int().min(1).max(1_000),
|
||||
max_workers: z.number().int().min(0).max(1_000),
|
||||
max_popups: z.number().int().min(0).max(100),
|
||||
max_websockets: z.number().int().min(0).max(10_000),
|
||||
max_dom_nodes: z.number().int().min(1).max(100_000),
|
||||
max_accessibility_nodes: z.number().int().min(1).max(100_000),
|
||||
max_screenshots: z.number().int().min(0).max(256),
|
||||
max_screenshot_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(8 * 1_024 * 1_024),
|
||||
max_storage_entries: z
|
||||
.number()
|
||||
.int()
|
||||
.min(0)
|
||||
.max(BROWSER_SCENARIO_LIMITS.storageEntries),
|
||||
max_total_metadata_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1_024)
|
||||
.max(64 * 1_024 * 1_024),
|
||||
});
|
||||
export const browserScenarioCaptureSchema = z
|
||||
.strictObject({
|
||||
after_each_step: z.array(snapshotKindSchema).max(6).default([]),
|
||||
at_end: z.array(snapshotKindSchema).max(6).default(["url"]),
|
||||
events: z
|
||||
.array(
|
||||
z.enum([
|
||||
"console",
|
||||
"page-errors",
|
||||
"network",
|
||||
"websockets",
|
||||
"frames",
|
||||
"workers",
|
||||
"popups",
|
||||
"downloads",
|
||||
]),
|
||||
)
|
||||
.default([]),
|
||||
})
|
||||
.default({ after_each_step: [], at_end: ["url"], events: [] })
|
||||
.describe(
|
||||
"Optional retained artifacts and event families. Defaults to only a final sanitized URL; request screenshots, DOM, accessibility, history, storage, and event capture explicitly.",
|
||||
);
|
||||
|
||||
export const browserScenarioAllowedOriginsSchema = browserAllowedOriginsSchema;
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
import type { AddressedName } from "./hopperValues.js";
|
||||
|
||||
/** Select Swift class symbols using the legacy `_TtC` convention. */
|
||||
export const discoverSwiftClasses = (
|
||||
procedures: readonly AddressedName[],
|
||||
pattern: string,
|
||||
): JsonValue => {
|
||||
const classes = procedures
|
||||
.filter(({ name }) => name.includes("_TtC"))
|
||||
.filter(({ name }) => pattern.length === 0 || name.includes(pattern));
|
||||
return {
|
||||
count: classes.length,
|
||||
classes: classes.map(toJsonEntry),
|
||||
};
|
||||
};
|
||||
|
||||
/** Select and deduplicate Objective-C class labels. */
|
||||
export const discoverObjcClasses = (
|
||||
names: readonly AddressedName[],
|
||||
@@ -55,10 +41,15 @@ const SWIFT_CATEGORIES = [
|
||||
["protocols", "_TtP"],
|
||||
["extensions", "_TtE"],
|
||||
] as const;
|
||||
type SwiftTypeCategory = (typeof SWIFT_CATEGORIES)[number][0] | "other";
|
||||
|
||||
/** Categorize deduplicated Swift mangled symbols. */
|
||||
export const categorizeSwiftTypes = (
|
||||
procedures: readonly AddressedName[],
|
||||
filter: {
|
||||
readonly category?: SwiftTypeCategory | undefined;
|
||||
readonly pattern?: string | undefined;
|
||||
} = {},
|
||||
): JsonValue => {
|
||||
const groups: Record<string, AddressedName[]> = Object.fromEntries(
|
||||
[...SWIFT_CATEGORIES.map(([category]) => category), "other"].map(
|
||||
@@ -69,11 +60,14 @@ export const categorizeSwiftTypes = (
|
||||
|
||||
for (const entry of procedures) {
|
||||
if (!entry.name.includes("_Tt") || seen.has(entry.name)) continue;
|
||||
seen.add(entry.name);
|
||||
const category =
|
||||
SWIFT_CATEGORIES.find(([, prefix]) =>
|
||||
entry.name.startsWith(prefix),
|
||||
)?.[0] ?? "other";
|
||||
if (filter.category !== undefined && filter.category !== category) continue;
|
||||
if (filter.pattern !== undefined && !entry.name.includes(filter.pattern))
|
||||
continue;
|
||||
seen.add(entry.name);
|
||||
groups[category]?.push(entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import { z } from "zod";
|
||||
/** Self-verifying text artifact used by web-source analysis boundaries. */
|
||||
export const webTextArtifactSchema = z
|
||||
.object({
|
||||
uri: z.string().regex(/^rea:\/\/web-content\/sha256\/[a-f0-9]{64}$/u),
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(0),
|
||||
media_type: z.string().min(1).max(256),
|
||||
@@ -27,12 +26,6 @@ export const webTextArtifactSchema = z
|
||||
path: ["sha256"],
|
||||
message: "Digest mismatch",
|
||||
});
|
||||
if (artifact.uri !== webContentUri(digest))
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["uri"],
|
||||
message: "Content URI mismatch",
|
||||
});
|
||||
});
|
||||
export type WebTextArtifact = z.infer<typeof webTextArtifactSchema>;
|
||||
|
||||
@@ -43,7 +36,6 @@ export const createWebTextArtifact = (
|
||||
): WebTextArtifact => {
|
||||
const sha256 = createHash("sha256").update(text).digest("hex");
|
||||
return {
|
||||
uri: webContentUri(sha256),
|
||||
sha256,
|
||||
bytes: Buffer.byteLength(text),
|
||||
media_type: mediaType,
|
||||
@@ -51,6 +43,3 @@ export const createWebTextArtifact = (
|
||||
text,
|
||||
};
|
||||
};
|
||||
|
||||
const webContentUri = (sha256: string): string =>
|
||||
`rea://web-content/sha256/${sha256}`;
|
||||
|
||||
@@ -13,7 +13,6 @@ const MAX_SCREENSHOT_BYTES = 8 * 1_024 * 1_024;
|
||||
/** Self-verifying inline PNG artifact for CLI/MCP parity. */
|
||||
export const webScreenshotArtifactSchema = z
|
||||
.object({
|
||||
uri: z.string().regex(/^rea:\/\/web-screenshot\/sha256\/[a-f0-9]{64}$/u),
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(1).max(MAX_SCREENSHOT_BYTES),
|
||||
media_type: z.literal("image/png"),
|
||||
@@ -26,11 +25,7 @@ export const webScreenshotArtifactSchema = z
|
||||
return;
|
||||
}
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
if (
|
||||
bytes.byteLength !== artifact.bytes ||
|
||||
sha256 !== artifact.sha256 ||
|
||||
artifact.uri !== `rea://web-screenshot/sha256/${sha256}`
|
||||
)
|
||||
if (bytes.byteLength !== artifact.bytes || sha256 !== artifact.sha256)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "Screenshot artifact digest or size mismatch",
|
||||
@@ -164,7 +159,6 @@ export const createWebScreenshotArtifact = (
|
||||
): WebScreenshotArtifact => {
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
return webScreenshotArtifactSchema.parse({
|
||||
uri: `rea://web-screenshot/sha256/${sha256}`,
|
||||
sha256,
|
||||
bytes: bytes.byteLength,
|
||||
media_type: "image/png",
|
||||
|
||||
Reference in New Issue
Block a user