Files
reverse-engineering-anything/src/browser/WebBundleAnalysisWorkerProtocol.ts
T
morluto cb4e5cfbff feat(analysis): make resource budgets recoverable across CLI and MCP (#9706)
* refactor(analysis): centralize resource budgets and recovery facts

* feat(analysis): expose ASAR and Ghidra runtime admission controls

* feat(artifacts): expose reader admission and preserve limited recognition

* feat(javascript): expose recoverable semantic precision budgets

* feat(web): add recoverable source-map budgets and compact retained views

* feat(web): make historical capture decoding budgets recoverable

* fix(desktop): enforce selected view policies across capture and export

* feat(runtime): make Frida and LLDB retention budgets selectable

* feat(native): expose diagnostic budgets and preserve exhaustion causes

* feat(managed): expose recoverable snapshot and representation budgets

* feat(metadata): make Go and Rust inspection budgets recoverable

* feat(wasm): expose representation and producer admissions

* feat(evm): expose per-call worker resource budgets

* feat(android): make resource and string-pool omissions recoverable

* feat(producers): expose command and recorded-capture budgets

* docs(analysis): record recovery contracts and integrated validation

* fix(docs): link calibration oracle from published verification pages

* fix(docs): restore desktop task anchors and receipt links

* test(analysis): align fixtures with selectable budget contracts

* fix(analysis): remove source-location projector dependency cycle

* test(analysis): refresh budget recovery and verifier regressions

* test(analysis): preserve format and publication recovery expectations

* test(windows): align conformance with owned runtime admission

* fix(desktop): preserve selected alias kinds in exported state

* test(analysis): align provider fixtures with recoverable budgets

* test(desktop): validate emitted alias metadata structurally

* fix(ghidra): classify bounded Windows endpoint refusals

* test(cli): assert selectable artifact admission recovery

* fix(cli): preserve capture provenance in environment builds
2026-11-10 05:11:20 -05:00

84 lines
2.7 KiB
TypeScript

import { javaScriptSemanticPrecisionSchema } from "../domain/javascript/javascriptSemanticPrecision.js";
import { z } from "zod";
import { JAVASCRIPT_STATIC_FACT_BYTES } from "../domain/javascript/javascriptAnalysisResourceControls.js";
import { digestSchema } from "../domain/digests.js";
import { WEB_RUNTIME_LIMITS } from "../domain/webRuntime.js";
import { webPageInspectionSchema } from "../domain/browserObservationSchemas.js";
import { webTextArtifactSchema } from "../domain/webContentArtifact.js";
import {
DEFAULT_WEB_BUNDLE_HEAP_MB,
DEFAULT_WEB_BUNDLE_SCRIPT_TIMEOUT_MS,
DEFAULT_WEB_BUNDLE_TOTAL_TIMEOUT_MS,
} from "../domain/webBundleAnalysis.js";
/** Independent per-script worker limits for source records and control frames. */
export const WEB_BUNDLE_WORKER_LIMITS = {
heapMb: DEFAULT_WEB_BUNDLE_HEAP_MB,
scriptTimeoutMs: DEFAULT_WEB_BUNDLE_SCRIPT_TIMEOUT_MS,
totalTimeoutMs: DEFAULT_WEB_BUNDLE_TOTAL_TIMEOUT_MS,
protocolBytes: 64 * 1024,
sourceBytes: 8 * WEB_RUNTIME_LIMITS.sourceBytes,
resultBytes: JAVASCRIPT_STATIC_FACT_BYTES,
} as const;
const includedSourceSchema = z.strictObject({
included: z.literal(true),
artifact: webTextArtifactSchema.strict(),
});
const browserScriptSchema =
webPageInspectionSchema.shape.scripts.shape.items.element;
/** Derive producer metadata rules; the worker requires captured source text. */
export const includedWebScriptSchema = browserScriptSchema
.extend({ source: includedSourceSchema })
.strict();
export const webBundleWorkerRequestSchema = z.strictObject({
kind: z.literal("analyze"),
semantic_precision: javaScriptSemanticPrecisionSchema.exactOptional(),
id: z.uuid(),
source: z.strictObject({
bytes: z.number().int().min(0).max(WEB_BUNDLE_WORKER_LIMITS.sourceBytes),
sha256: digestSchema,
}),
result_budget_bytes: z
.number()
.int()
.min(0)
.max(WEB_BUNDLE_WORKER_LIMITS.resultBytes),
});
const identity = { id: z.uuid() };
/** Control frames contain descriptors and progress only, never source or findings. */
export const webBundleWorkerMessageSchema = z.discriminatedUnion("kind", [
z.strictObject({
kind: z.literal("ready"),
heap_limit_bytes: z.number().int().positive().nullable(),
}),
z.strictObject({
kind: z.literal("phase"),
...identity,
phase: z.literal("analyze"),
}),
z.strictObject({
kind: z.literal("complete"),
...identity,
result: z.strictObject({
bytes: z.number().int().nonnegative(),
sha256: digestSchema,
}),
}),
z.strictObject({
kind: z.literal("failure"),
...identity,
reason: z.enum(["input", "resource", "output", "io"]),
message: z.string(),
}),
]);
export type WebBundleWorkerMessage = z.output<
typeof webBundleWorkerMessageSchema
>;