feat(javascript): add semantic_analysis structure-only mode to analyze_javascript_application (#14117)

* feat(javascript): add semantic_analysis structure-only mode to analyze_javascript_application

On large Electron apps the default analysis runs full semantic analysis per file (364 s measured in #14100) although first questions are application-graph facts. semantic_analysis: structure-only returns static and application-graph facts without semantic IR, graph content or traces: the worker purpose protocol gains structure-only (full static checkpoint, semantic phase skipped, no semantic result budget consumed), adoption records the mode once as a limitation, and Evidence parameters record the selection. Default complete behavior is unchanged.

Closes #14116. Verified: javascriptArtifactReconstruction, electronApplicationAnalysis and javascriptApplicationService suites (75 tests incl. new structure-only e2e), worker server/schema tests, check:fast, docs:check, advertised schema summary regenerated.

* test(javascript): assert semantic relations in the structure-only test

* fix(javascript): record structure-only semantic coverage as incomplete and retain refusal facts

Structure-only files now record a semantic unavailable reason so graph coverage cannot claim complete examination (comparisons will not report skipped bindings as removed), member-mutation refusal checkpoints cross for structure-only as they do for complete analysis, and the e2e control asserts real semantic content under the default.

* docs(javascript): document semantic_analysis and expose --semantic-analysis

The owning reconstruction guide now describes the complete default, what structure-only returns and skips, and how to follow up with complete analysis of selected sources. The CLI projection declares the field so --semantic-analysis <complete|structure-only> is accepted with the contract enum.

* fix(javascript): record structure-only application coverage as partial

Structure-only omits source-module and export-binding nodes. The
application graph now reports partial coverage with a null omission
count, so a comparison of an unchanged application treats those
bindings as unknown rather than removed.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morlutoandCursor Agent authored and GitHub committed 2026-11-23 17:56:32 +00:00
1 parent fba6b6f9ae
commit eccd18a2cc
15 files changed
+212 -16

No files matched your search

@@ -48,7 +48,9 @@ const analyze: JavaScriptSourceWorkerAnalyzer = async (
precision,
memberMutationAllowance,
);
if (static_ === null) return null;
// Structure-only keeps the full static facts and skips semantic analysis;
// no semantic result budget is consumed.
if (static_ === null || purpose === "structure-only") return null;
const { resultBudgetBytes, callPaths } = static_;
if (resultBudgetBytes === 0)
throw new AnalysisResourceConstraintError(
@@ -95,7 +97,9 @@ const analyze: JavaScriptSourceWorkerAnalyzer = async (
/**
* Checkpoint static facts, reusing the ones preload discovery retained for
* this exact request. Null ends the job: discovery returns only declarations,
* and a failed parse has no semantic phase.
* and a failed parse has no semantic phase. The caller stops after this
* checkpoint for structure-only, so that pass reuses the same facts and
* still does not start semantic analysis.
*/
const staticCheckpoint = async (
source: string,
@@ -108,7 +112,8 @@ const staticCheckpoint = async (
readonly resultBudgetBytes: number;
readonly callPaths: JavaScriptStaticAnalysis["electron"]["call_paths"];
} | null> => {
const reused = purpose === "analysis" ? callbacks.reusedStatic() : undefined;
const reused =
purpose === "preload-discovery" ? undefined : callbacks.reusedStatic();
if (reused !== undefined) {
const resultBudgetBytes = await callbacks.checkpointReused(reused);
return reused.parse_status === "failed"
@@ -128,7 +133,13 @@ const staticCheckpoint = async (
} catch (cause: unknown) {
// The semantic phase indexes the same mutations under the same
// allowance, so it is not started; the syntax facts cross first.
if (purpose === "analysis" && isJavaScriptMemberMutationRefusal(cause))
// Structure-only has no later semantic phase, so the same refusal must
// still cross the syntax facts. Discovery leaves that report to the
// normal pass, which recomputes this source.
if (
purpose !== "preload-discovery" &&
isJavaScriptMemberMutationRefusal(cause)
)
await callbacks.checkpoint(
memberMutationRefusedJavaScriptStaticAnalysis(source, parsed, cause),
);