Files
reverse-engineering-anything/src/domain/webBundleScriptAnalysis.ts
T
morluto 2430b081c9 refactor(providers): bind provider refusals' per-call controls instead of naming CLI flags (#11455)
* refactor(native): bind producer_limits and max_input_bytes as the per-call controls of pwntools and Apple dispatch refusals

producerLimitControl in src/domain/producerResourceLimits.ts names one producer budget as producer_limits.<field>; the shared provider outcome classifier now carries a resource signal's limit. Pwntools file-size, CPU and output refusals and the Apple dispatch input refusal bind their control, and their remediation no longer names CLI flags.

* fix(native): report the selected output allowance as the omitted file_bytes default

* fix(native): bind producer_limits.diagnostic_bytes as the pwntools command output-limit control

* refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals (#11458)

* refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals

* test(rust): cover the complete-report refusal's producer_limits control

* refactor(browser): bind caller-selectable browser deadlines as per-call controls instead of naming CLI flags (#11466)

* refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals

* test(rust): cover the complete-report refusal's producer_limits control

* refactor(browser): bind caller-selectable browser deadlines as per-call controls instead of naming CLI flags

deadlineParameterLimit in src/domain/analysisResourceLimits.ts owns the millisecond deadline control that nativeDeadlineRecovery and the browser recoveries share. CDP command and discovery, web bundle per-script and total, network capture and source-map decode deadlines now carry it; browserDeadlineIncrease no longer takes CLI flag text.

* fix(browser): record a per-script deadline's parameter control in partial web bundle results

* refactor(providers): bind Wabt, SQLite, EVMole, Apktool and Go controls instead of naming CLI commands (#11472)

* refactor(providers): bind Wabt, SQLite, EVMole and Apktool deadline and byte controls instead of naming CLI commands

These remediation strings named rea commands and flags through template text the cli-option guard did not count. Wabt byte refusals and output limits bind max_input_bytes, max_tool_bytes or max_output_bytes while a larger value is selectable; SQLite worker_timeout_ms, EVMole timeout_ms and Apktool decode_timeout_ms bind through deadlineParameterLimit; the shared provider outcome classifier now carries an output limit's control.

* refactor(go): bind Go analysis budgets as per-call controls instead of naming CLI flags

* fix(providers): keep the typed primary when Wabt, EVMole or pwntools command cleanup fails

* ci(guards): count template-built CLI option and command text outside the CLI layer (#11478)

* refactor(providers): bind Wabt, SQLite, EVMole and Apktool deadline and byte controls instead of naming CLI commands

These remediation strings named rea commands and flags through template text the cli-option guard did not count. Wabt byte refusals and output limits bind max_input_bytes, max_tool_bytes or max_output_bytes while a larger value is selectable; SQLite worker_timeout_ms, EVMole timeout_ms and Apktool decode_timeout_ms bind through deadlineParameterLimit; the shared provider outcome classifier now carries an output limit's control.

* refactor(go): bind Go analysis budgets as per-call controls instead of naming CLI flags

* fix(providers): keep the typed primary when Wabt, EVMole or pwntools command cleanup fails

* ci(guards): count template-built CLI option and command text outside the CLI layer

The cli-option-text-outside-cli pattern now also matches "(CLI ...", "on the CLI", "or use rea ..." and backticked `rea <command>` references, so remediation built from a template such as --${name} or rea inspect-... <path> is counted. Doctor.ts is exempt: setup and doctor run only through the CLI. The baseline records the newly counted pre-existing sites (22 -> 45 across 21 files).

* ci(guards): extract the CLI text matcher, exempt host-only commands with written reasons, and test each spelling

* ci(guards): exempt a host-only command and its own arguments in any matched CLI phrase

* fix(native): bind producer_limits.output_bytes for oversized pwndbg debugger replies through one owner

* fix(cli): name an Evidence target source failure's control by the source option that sets it

* feat(cli): render the flags of result-recorded controls in the full-output envelope (#11507)

* feat(cli): render the flags of result-recorded controls in the full-output envelope

* fix(cli): collect result controls only for a full-output envelope, in its requested format, past undefined values

* ci(guards): end a host-only command's arguments before the next CLI command

* refactor(reverse): record the output budget that stopped a one-shot command as a parameter control (#11528)

* fix(cli): read result controls only at positions the output schema declares as recorded controls

* refactor(providers): record the controls that bounded Rust compiler paths and kernel module text instead of naming CLI options (#11532)

* refactor(rust): record the control that bounded compiler-path coverage instead of naming CLI options

* refactor(native): record the controls that omitted kernel module .modinfo text instead of naming CLI options (#11534)

* fix(rust): describe compiler coverage from the retained result after report trimming

* refactor(providers): record managed representation and JavaScript semantic ceiling controls instead of naming CLI options (#11537)

* refactor(managed): record the representation budget on a resource-limit issue instead of naming its CLI option

* refactor(javascript): record the semantic retention ceilings that stopped a graph instead of naming CLI options (#11540)

* fix(cli): name a composed command's source options for the controls its result records

* fix(cli): read result controls from the delivered Evidence when a summary wraps it

* fix(rust): keep the report-byte control recorded when trimming omits every compiler path

When the complete-report allowance left room for no compiler path, rustc_commit became null and its coverage.limit was lost, so --full-output could not name the option that raises the allowance. The report now records rustc_commit_omission { reason, limit } outside the dropped record, and the summary view carries it.

* refactor(flutter): record the string-pool budgets that left a projection partial instead of naming the CLI option (#11541)

* refactor(flutter): record the string-pool budgets that left a projection partial instead of naming the CLI option

* test(flutter): assert the complete set of recorded string-pool budgets

* feat(cli): name the options of controls a failure's partial Evidence records (#11557)

meta.cli_controls was collected only from a successful result. A failure whose partial observation is Evidence of the command's own operation is now read the same way, at the positions the output schema declares as recorded controls; Evidence of another operation or a retained reference is not read. When --evidence_output publishes the partial, the delivery records it before replacing it.

* refactor(javascript): record the evaluator budgets that limited sources instead of naming the CLI option (#11564)

Per-value unknown reasons and the Electron wrapper limitation named --semantic-precision. The static examination now records the semantic_precision controls that limited a source (examination.controls), and analyze_javascript_application's semantic_graph.coverage.controls records every evaluator budget that limited any source (examination and semantic IR coverage), beside the retention ceilings. The CLI renders --semantic-precision from those records in meta.cli_controls; the reason texts name only the contract field.
2026-11-16 07:12:16 +08:00

205 lines
6.7 KiB
TypeScript

import { z } from "zod";
import { webBundleAnalysisSchema } from "./webBundleAnalysis.js";
import { analysisResultLimitSchema } from "./analysisSettingDefinitions.js";
import { javaScriptRouteSourceFactsSchema } from "./javascript/javascriptRouteFacts.js";
import { javaScriptRefusedPhaseSchema } from "./javascript/javascriptSemanticWorkAllowance.js";
import type { AnalysisError } from "./analysisErrorBase.js";
import { AnalysisResourceConstraintError } from "./analysisErrorCore.js";
import { analysisErrorRemediationAction } from "./analysisErrorPresentation.js";
const observationsSchema = z.strictObject({
edges: webBundleAnalysisSchema.shape.observations.shape.chunks.shape.edges,
routes: webBundleAnalysisSchema.shape.observations.shape.routes,
endpoints: webBundleAnalysisSchema.shape.observations.shape.endpoints,
webmcp_declarations:
webBundleAnalysisSchema.shape.observations.shape.webmcp_declarations,
});
/**
* Syntax-level facts for a parsed script whose named phase was refused.
* Findings that read that phase's facts were not examined.
*/
const refusedScriptFactsSchema = z.strictObject({
refused_phase: javaScriptRefusedPhaseSchema,
parse_status: z.enum(["parsed", "recovered"]),
inferences: webBundleAnalysisSchema.shape.inferences,
});
/** Serializable result for one captured script, suitable for worker transport. */
export const webBundleScriptAnalysisSchema = z
.discriminatedUnion("status", [
z.strictObject({
status: z.literal("analyzed"),
script_key: z.string(),
parse_status: z.enum(["parsed", "recovered", "failed"]),
visited_ast_nodes: z.number().int().min(0),
widened_return_references: z.boolean(),
route_facts: javaScriptRouteSourceFactsSchema.nullable().optional(),
observations: observationsSchema,
inferences: webBundleAnalysisSchema.shape.inferences,
}),
z.strictObject({
status: z.literal("unavailable"),
script_key: z.string(),
reason: z.enum([
"worker_failure",
"deadline",
"resource_constraint",
"cancelled",
"not_started",
]),
detail: z.string().optional(),
/** The setting or request parameter that bounded this script. */
limit: analysisResultLimitSchema.exactOptional(),
remediation: z.string().exactOptional(),
/** Facts gathered before a work allowance refused a later phase. */
partial: refusedScriptFactsSchema.exactOptional(),
}),
])
.superRefine((result, context) => {
const checkScriptKey = (
scriptKey: string,
path: (string | number)[],
): void => {
if (scriptKey !== result.script_key)
context.addIssue({
code: "custom",
path,
message: "Per-script analysis evidence must name its owning script",
});
};
const checkInferences = (
inferences: z.output<typeof refusedScriptFactsSchema>["inferences"],
path: (string | number)[],
): void =>
inferences.forEach((inference, inferenceIndex) =>
inference.basis.forEach((basis, basisIndex) =>
checkScriptKey(basis.script_key, [
...path,
inferenceIndex,
"basis",
basisIndex,
"script_key",
]),
),
);
if (result.status === "unavailable") {
if (result.partial === undefined) return;
if (result.reason !== "resource_constraint")
context.addIssue({
code: "custom",
path: ["partial"],
message: "Only a refused script carries partial facts",
});
checkInferences(result.partial.inferences, ["partial", "inferences"]);
return;
}
result.observations.edges.forEach((edge, index) => {
checkScriptKey(edge.from_script_key, [
"observations",
"edges",
index,
"from_script_key",
]);
checkScriptKey(edge.location.script_key, [
"observations",
"edges",
index,
"location",
"script_key",
]);
});
for (const collection of ["routes", "endpoints"] as const)
result.observations[collection].forEach((finding, index) =>
checkScriptKey(finding.location.script_key, [
"observations",
collection,
index,
"location",
"script_key",
]),
);
result.observations.webmcp_declarations.forEach((declaration, index) =>
checkScriptKey(declaration.location.script_key, [
"observations",
"webmcp_declarations",
index,
"location",
"script_key",
]),
);
checkInferences(result.inferences, ["inferences"]);
if (result.parse_status === "failed") {
const hasFindings =
result.observations.edges.length > 0 ||
result.observations.routes.length > 0 ||
result.observations.endpoints.length > 0 ||
result.observations.webmcp_declarations.length > 0 ||
result.inferences.length > 0;
if (
result.visited_ast_nodes !== 0 ||
result.widened_return_references ||
hasFindings
)
context.addIssue({
code: "custom",
path: ["parse_status"],
message:
"A failed script parse cannot carry visited nodes or derived findings",
});
}
});
export type WebBundleScriptAnalysis = z.infer<
typeof webBundleScriptAnalysisSchema
>;
type UnavailableWebScriptAnalysis = Extract<
WebBundleScriptAnalysis,
{ readonly status: "unavailable" }
>;
/**
* The control a script result can record: a registered setting, or a request
* parameter named by its contract field. An environment control is not a
* result-side reference, so its error keeps only the detail.
*/
const recordedLimit = (
limit: AnalysisError["limit"],
): UnavailableWebScriptAnalysis["limit"] =>
limit === undefined
? undefined
: "setting" in limit
? limit
: limit.control_kind === "parameter"
? limit
: undefined;
/**
* The detail and structured recovery an unavailable script states for the
* error that stopped its analysis, such as a resource refusal or a per-script
* deadline.
*/
export const unavailableWebScriptRecovery = (
error: AnalysisError,
): Pick<UnavailableWebScriptAnalysis, "detail" | "limit" | "remediation"> => {
const limit = recordedLimit(error.limit);
return {
detail:
error instanceof AnalysisResourceConstraintError &&
error.reportedLimits !== null
? `${error.userMessage ?? error.reason} Reported limits: ${JSON.stringify(error.reportedLimits)}`
: (error.userMessage ?? error.message),
...(limit === undefined
? {}
: {
limit,
remediation: analysisErrorRemediationAction(error),
}),
};
};