mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
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:
1 parent
fba6b6f9ae
commit
eccd18a2cc
15 files changed
+212
-16
No files matched your search
@@ -93,6 +93,9 @@ const parameters = (
|
||||
...(input.semantic_precision === undefined
|
||||
? {}
|
||||
: { semantic_precision: input.semantic_precision }),
|
||||
...(input.semantic_analysis === undefined
|
||||
? {}
|
||||
: { semantic_analysis: input.semantic_analysis }),
|
||||
format: input.format,
|
||||
integrity_policy: input.integrity_policy,
|
||||
...(input.max_semantic_nodes === undefined
|
||||
|
||||
@@ -84,6 +84,8 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
|
||||
preloadPaths: ReadonlySet<string> = new Set(),
|
||||
/** Discovery gaps that may leave a declared preload in its package scope. */
|
||||
preloadLimitations: readonly string[] = [],
|
||||
/** Return static and application facts without semantic analysis. */
|
||||
structureOnly: boolean = false,
|
||||
): Promise<{
|
||||
readonly analysis: JavaScriptArtifactAnalysis;
|
||||
readonly interruption: AnalysisError | null;
|
||||
@@ -130,6 +132,7 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
|
||||
posix.extname(file.path) === ".js"
|
||||
? "commonjs"
|
||||
: packageTypeFor(file),
|
||||
structureOnly ? "structure-only" : "analysis",
|
||||
);
|
||||
const facts = result.ok ? result.value : result.error;
|
||||
for (const revoked of facts.revokedStaticProjections ?? []) {
|
||||
@@ -186,10 +189,12 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
|
||||
});
|
||||
const semanticUnavailableReason =
|
||||
failure?.reason ??
|
||||
javaScriptSemanticSourceExclusion(
|
||||
file,
|
||||
facts.javascript?.parse_status ?? null,
|
||||
);
|
||||
(structureOnly && file.kind === "javascript" && file.text.included
|
||||
? "Semantic analysis was not requested (structure-only)"
|
||||
: javaScriptSemanticSourceExclusion(
|
||||
file,
|
||||
facts.javascript?.parse_status ?? null,
|
||||
));
|
||||
if (facts.projection === null && semanticUnavailableReason !== null)
|
||||
projection.recordUnavailableFile(
|
||||
file,
|
||||
@@ -308,7 +313,11 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
|
||||
}
|
||||
restoreInventoryOrder(fileSet.files, state.files);
|
||||
return {
|
||||
analysis: finalizeArtifactAnalysis(state, preloadLimitations),
|
||||
analysis: finalizeArtifactAnalysis(
|
||||
state,
|
||||
preloadLimitations,
|
||||
structureOnly,
|
||||
),
|
||||
interruption,
|
||||
};
|
||||
};
|
||||
@@ -352,6 +361,7 @@ const restoreInventoryOrder = (
|
||||
const finalizeArtifactAnalysis = (
|
||||
state: MutableArtifactAnalysis,
|
||||
preloadLimitations: readonly string[],
|
||||
structureOnly: boolean = false,
|
||||
): JavaScriptArtifactAnalysis => {
|
||||
return {
|
||||
jsonDocuments: state.jsonDocuments,
|
||||
@@ -371,9 +381,15 @@ const finalizeArtifactAnalysis = (
|
||||
),
|
||||
modules: state.modules,
|
||||
parse_failures: state.parseFailures,
|
||||
...(structureOnly ? { semantic_analysis: "structure-only" as const } : {}),
|
||||
limitations: [
|
||||
"JavaScript and HTML were parsed as inert text; bundle bootstrap code was never executed.",
|
||||
"Static paths and relationships may remain unresolved when expressions are dynamic or obfuscated.",
|
||||
...(structureOnly
|
||||
? [
|
||||
"Semantic analysis was not requested (semantic_analysis: structure-only): no semantic IR, semantic graph or semantic traces were produced. Request semantic_analysis: complete for selected sources to obtain them.",
|
||||
]
|
||||
: []),
|
||||
...state.htmlInlineScripts.map(htmlInlineScriptLimitation),
|
||||
...state.files.flatMap(
|
||||
({ analysis_failure, application_projection_failure }) =>
|
||||
|
||||
@@ -225,4 +225,11 @@ export interface JavaScriptArtifactAnalysis {
|
||||
readonly modules: number;
|
||||
readonly parse_failures: number;
|
||||
readonly limitations: readonly string[];
|
||||
/**
|
||||
* Set when the caller skipped semantic analysis. Omitted for a complete
|
||||
* pass. Application-graph coverage reads this rather than guessing from
|
||||
* absent module IR: source-module and export-binding nodes are not built,
|
||||
* so the graph cannot claim those facts were examined.
|
||||
*/
|
||||
readonly semantic_analysis?: "structure-only";
|
||||
}
|
||||
@@ -371,6 +371,12 @@ const graphCoverage = (context: JavaScriptArtifactGraphContext) => {
|
||||
);
|
||||
return partialApplicationCoverage([], nestedArchiveWasOpaque ? null : 0);
|
||||
}
|
||||
// Structure-only keeps static and Electron facts and does not build
|
||||
// source-module or export-binding nodes. The omitted node count is unknown
|
||||
// without semantic analysis. Complete coverage would let a comparison treat
|
||||
// those unchanged bindings as removed.
|
||||
if (context.analysis.semantic_analysis === "structure-only")
|
||||
return partialApplicationCoverage([], null);
|
||||
return completeApplicationCoverage();
|
||||
};
|
||||
|
||||
|
||||
@@ -262,6 +262,7 @@ export const reconstructJavaScriptArtifact = async (
|
||||
},
|
||||
preloads.paths,
|
||||
preloads.limitations,
|
||||
input.semantic_analysis === "structure-only",
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
analysisFailure = { cause };
|
||||
|
||||
Reference in new issue
Block a user