mirror of
https://github.com/morluto/rea
synced 2026-10-26 22:28:27 -04:00
9aca543f46
Run inert captured-script analysis in owned children with per-script and aggregate deadlines, bounded source/result transfer and explicit per-script coverage. Preserve completed facts and exact cleanup authority across cancellation, mixed descriptor/process failures and cross-consumer retry. Share aggregate source admission across page and Electron capture, expose CLI/MCP resource controls and retain selected parameters in Evidence. Verified with controlled CDP public workflows, real owned Node failure controls and the reporter-matching ReactDOM UMD artifact; real Chrome/Electron and Windows/Bun remain unqualified.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { WEB_RUNTIME_LIMITS } from "../domain/webRuntime.js";
|
|
import { ProviderStartupDeadline } from "../process/ProviderDeadline.js";
|
|
|
|
const MIB = 1024 * 1024;
|
|
|
|
export const CDP_SCRIPT_SOURCE_BYTES_OMISSION_REASON = `script source was omitted because the aggregate ${String(WEB_RUNTIME_LIMITS.sourceBytes / MIB)} MiB source budget was exhausted`;
|
|
export const CDP_SCRIPT_SOURCE_DEADLINE_OMISSION_REASON = `script source was omitted because the ${String(WEB_RUNTIME_LIMITS.commandTimeoutMs / 1000)}-second source collection deadline elapsed`;
|
|
|
|
/** Shared admission for source text retained from passive CDP script reads. */
|
|
export class CdpScriptSourceBudget {
|
|
readonly #deadline: ProviderStartupDeadline;
|
|
#retainedBytes = 0;
|
|
|
|
constructor(signal?: AbortSignal) {
|
|
this.#deadline = new ProviderStartupDeadline(
|
|
WEB_RUNTIME_LIMITS.commandTimeoutMs,
|
|
signal,
|
|
);
|
|
}
|
|
|
|
get signal(): AbortSignal {
|
|
return this.#deadline.signal;
|
|
}
|
|
|
|
get timedOut(): boolean {
|
|
return this.#deadline.interruption === "timeout";
|
|
}
|
|
|
|
/** Admit exact UTF-8 source bytes before building or retaining its artifact. */
|
|
admit(text: string): boolean {
|
|
const bytes = Buffer.byteLength(text, "utf8");
|
|
if (bytes > WEB_RUNTIME_LIMITS.sourceBytes - this.#retainedBytes)
|
|
return false;
|
|
this.#retainedBytes += bytes;
|
|
return true;
|
|
}
|
|
|
|
dispose(): void {
|
|
this.#deadline.dispose();
|
|
}
|
|
}
|