refactor(javascript): own coverage facts and reuse block prefixes

Separate syntax, semantic uncertainty, examination limits and observed Electron applicability at the static producer, then preserve them through worker, graph and retained/inline summary views. Derive the established parse_status from the same facts and leave historical measurements unknown. Give semantic resource-limit classifications one schema owner.

Replace repeated block-prefix searches and copies with collector-scoped syntax indexes. Keep invocation environments separate, charge indexing/replay to the existing work budget and yield during prefix work. Remove the superseded synchronous collector entrypoint.

Validated producer, worker, CLI/MCP, historical and partial-coverage regressions, plus actual cancellation during indexing. Bounded authored 128/256-call controls preserved all prior facts while replacing repeated search/copy work with one index pass; this is not a throughput or agent-token benchmark.
This commit is contained in:
morluto
2026-10-25 09:45:48 +08:00
parent c8269ca497
commit f62a2baad8
21 changed files with 898 additions and 125 deletions
@@ -3,7 +3,7 @@ import * as t from "@babel/types";
import { JavaScriptRouteScan } from "./javascriptRouteScan.js";
import type { JavaScriptRouteSourceFacts } from "./javascriptRouteFacts.js";
import { RETURNED_REFERENCE_WIDENING_LIMITATION } from "./javascriptSemanticCoverage.js";
import { collectElectronWrappedCallPaths } from "./electronWrappedCallPaths.js";
import { collectElectronWrappedCallPathsSteps } from "./electronWrappedCallPaths.js";
import {
ELECTRON_IDENTITY_LIMITATION,
ELECTRON_MODULE,
@@ -76,6 +76,10 @@ import {
isTypeOnlyImportDeclaration,
semanticImportEqualsSpecifier,
} from "./javascriptModuleDeclaration.js";
import {
javaScriptStaticParseStatus,
type JavaScriptStaticCoverage,
} from "./javascriptStaticCoverage.js";
/** Parse one JavaScript artifact and recover static structure only. */
export const analyzeJavaScriptStaticSource = (
@@ -154,7 +158,7 @@ export function* analyzeParsedJavaScriptStaticSourceSteps(
finishPartialNetworkEndpoints(findings, bindings, index);
finishSqliteStorageCalls(findings, bindings, index);
}
accumulator.electronCallPaths = collectElectronWrappedCallPaths(
accumulator.electronCallPaths = yield* collectElectronWrappedCallPathsSteps(
file.program,
bindings,
source,
@@ -191,6 +195,43 @@ const finalizeStaticAnalysis = (
routes: JavaScriptRouteSourceFacts,
): JavaScriptStaticAnalysis => {
const parserErrors = file.errors.length;
const typeOnlySideEffect = hasUncertainTypeOnlyModuleSideEffect(file.program);
const electronObserved = accumulator.references.some(
({ value }) =>
value.specifier !== null && ELECTRON_MODULE.test(value.specifier),
);
const resourceLimits = [...bindings.valueResourceLimits].sort();
const coverage: JavaScriptStaticCoverage = {
syntax:
parserErrors === 0
? { status: "complete", error_count: 0 }
: { status: "recovered", error_count: parserErrors },
semantics: {
unknown_findings: accumulator.unknownFindings,
uncertainty: [
...(accumulator.unknownFindings > 0
? ["dynamic-findings" as const]
: []),
...(bindings.returnedReferenceWidenings.size > 0
? ["returned-reference-widening" as const]
: []),
...(typeOnlySideEffect
? ["type-only-module-side-effect" as const]
: []),
],
},
examination: {
status:
resourceLimits.length > 0 ||
accumulator.electronCallPathLimitReached === true
? "limited"
: "complete",
semantic_resource_limits: resourceLimits,
electron_call_paths_limited:
accumulator.electronCallPathLimitReached === true,
},
applicability: { electron: electronObserved ? "observed" : "unknown" },
};
const limitations = [
...(bindings.valueResourceLimits.has("alias-selections")
? [semanticResourceLimitReason("alias-selections")]
@@ -218,26 +259,17 @@ const finalizeStaticAnalysis = (
: [
"One or more static keys, expressions, or Electron boundary values were dynamic and remain unknown.",
]),
...(hasUncertainTypeOnlyModuleSideEffect(file.program)
...(typeOnlySideEffect
? [
"Compiler options are unavailable; inline type-only imports or re-exports may preserve a module side-effect dependency.",
]
: []),
...(accumulator.references.some(
({ value }) =>
value.specifier !== null && ELECTRON_MODULE.test(value.specifier),
)
? [ELECTRON_IDENTITY_LIMITATION]
: []),
...(electronObserved ? [ELECTRON_IDENTITY_LIMITATION] : []),
"JavaScript syntax was parsed as data and was never evaluated.",
];
return {
parse_status:
parserErrors > 0 ||
accumulator.unknownFindings > 0 ||
bindings.valueResourceLimits.has("alias-selections")
? "partial"
: "complete",
parse_status: javaScriptStaticParseStatus(coverage),
analysis_coverage: coverage,
parse_error_count: parserErrors,
visited_ast_nodes: accumulator.visitedNodes,
references: finalizeLocatedFindings(