feat(javascript): retain queryable static route inventories (#6019)

This commit is contained in:
gensokyo-dev authored and GitHub committed 2026-10-22 16:54:14 +08:00
1 parent 933af60eba
commit 7d0efef62d
67 files changed
+74345 -231

No files matched your search

+5 -2
View File
@@ -104,7 +104,7 @@ export const deliverCliAnalysisEvidence = async (
export const publishCliAnalysisEvidence = async (
value: JsonValue,
input: CliEvidenceDelivery,
) => {
): Promise<JsonValue> => {
const { operation, signal, detail, evidenceOutput } = input;
if (!isEvidence(value)) return value;
const complete = parseEvidence(value);
@@ -146,7 +146,10 @@ export const publishCliAnalysisEvidence = async (
return detail === "summary"
? {
summary: published.value.delivered,
evidence_bundle: published.value.evidenceBundle,
evidence_bundle: {
path: published.value.evidenceBundle.path,
bytes: published.value.evidenceBundle.bytes,
},
}
: published.value.delivered;
};
+20 -6
View File
@@ -1,3 +1,9 @@
import {
parseJavaScriptRouteDelivery,
javascriptRouteDeliveryOptions,
} from "./javascriptRouteDelivery.js";
import { deliverCliAnalysisEvidence } from "./analysisEvidenceDelivery.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { Cli, z } from "incur";
import { browserContext, browserCliError } from "../cliBrowserContext.js";
@@ -157,6 +163,7 @@ const registerBundleAnalysis = (
}),
options: z.object({
...browserScopeOptions,
...javascriptRouteDeliveryOptions,
observationMs: observationDuration(500),
fetchSourceMaps: z
.boolean()
@@ -172,6 +179,11 @@ const registerBundleAnalysis = (
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, "analyze-web-bundle", async () => {
const delivery = parseJavaScriptRouteDelivery(
"analyze_web_bundle",
options,
);
if (!delivery.ok) return projectAnalysisError(delivery.error);
const context = browserContext();
const input = {
cdp_endpoint: args.endpoint,
@@ -205,17 +217,19 @@ const registerBundleAnalysis = (
input,
),
);
return await finishAnalysisCommand(
() => analyzeWebBundle(context.provider, parsed.data, { signal }),
{
return deliverCliAnalysisEvidence({
...delivery.value,
run: () =>
analyzeWebBundle(context.provider, parsed.data, { signal }),
service: {
close: async () => {
await context.provider.close?.();
},
},
context.provider.identity().id,
"analyze_web_bundle",
providerId: context.provider.identity().id,
operation: "analyze_web_bundle",
signal,
);
});
}),
),
});
+50 -39
View File
@@ -1,3 +1,4 @@
import { parseJavaScriptRouteDelivery } from "./javascriptRouteDelivery.js";
import { isAbsolute, resolve, sep } from "node:path";
import { Cli, z } from "incur";
@@ -312,45 +313,55 @@ const registerJavaScriptApplicationCommand = (
options: javascriptApplicationOptions,
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () =>
runCliJavaScriptApplicationAnalysis(
{
// An empty path names no file; leave it for input validation.
input_path:
args.path === "" ? args.path : absoluteCallerPath(args.path),
format: options.artifactFormat,
integrity_policy: options.integrityPolicy,
...(options.maxSemanticNodes === undefined
? {}
: { max_semantic_nodes: options.maxSemanticNodes }),
...(options.maxSemanticNodesPerFile === undefined
? {}
: {
max_semantic_nodes_per_file:
options.maxSemanticNodesPerFile,
}),
...(options.maxSemanticUnknowns === undefined
? {}
: { max_semantic_unknowns: options.maxSemanticUnknowns }),
...(options.maxSemanticUnknownsPerFile === undefined
? {}
: {
max_semantic_unknowns_per_file:
options.maxSemanticUnknownsPerFile,
}),
...(options.sourcePath === undefined
? {}
: { source_paths: options.sourcePath }),
...(options.maxHeapMb === undefined
? {}
: { max_heap_mb: options.maxHeapMb }),
...(options.analysisTimeoutMs === undefined
? {}
: { analysis_timeout_ms: options.analysisTimeoutMs }),
},
environment,
signal,
),
logCliCommand(
logger,
CLI_COMMANDS.analyzeJavaScriptApplication,
async () => {
const delivery = parseJavaScriptRouteDelivery(
"analyze_javascript_application",
options,
);
if (!delivery.ok) return projectAnalysisError(delivery.error);
return runCliJavaScriptApplicationAnalysis(
{
// An empty path names no file; leave it for input validation.
input_path:
args.path === "" ? args.path : absoluteCallerPath(args.path),
format: options.artifactFormat,
integrity_policy: options.integrityPolicy,
...(options.maxSemanticNodes === undefined
? {}
: { max_semantic_nodes: options.maxSemanticNodes }),
...(options.maxSemanticNodesPerFile === undefined
? {}
: {
max_semantic_nodes_per_file:
options.maxSemanticNodesPerFile,
}),
...(options.maxSemanticUnknowns === undefined
? {}
: { max_semantic_unknowns: options.maxSemanticUnknowns }),
...(options.maxSemanticUnknownsPerFile === undefined
? {}
: {
max_semantic_unknowns_per_file:
options.maxSemanticUnknownsPerFile,
}),
...(options.sourcePath === undefined
? {}
: { source_paths: options.sourcePath }),
...(options.maxHeapMb === undefined
? {}
: { max_heap_mb: options.maxHeapMb }),
...(options.analysisTimeoutMs === undefined
? {}
: { analysis_timeout_ms: options.analysisTimeoutMs }),
},
environment,
signal,
delivery.value,
);
},
),
),
});
+16 -1
View File
@@ -1,3 +1,5 @@
import type { AnalysisViewRequest } from "../domain/analysisView/analysisView.js";
import { publishCliAnalysisEvidence } from "./analysisEvidenceDelivery.js";
import { JAVASCRIPT_APPLICATION_PROVIDER } from "../application/InvestigationProviders.js";
import { createProgressReporter } from "../application/ProgressReporter.js";
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
@@ -48,6 +50,11 @@ export const runCliJavaScriptApplicationAnalysis = async (
input: unknown,
environment: Readonly<Record<string, string | undefined>>,
signal?: AbortSignal,
delivery?: {
readonly detail: "complete" | "summary";
readonly evidenceOutput: string | undefined;
readonly view?: AnalysisViewRequest;
},
): Promise<JsonValue> => {
const { analyzeJavaScriptApplication } =
await import("../application/javascript/JavaScriptApplicationService.js");
@@ -87,7 +94,15 @@ export const runCliJavaScriptApplicationAnalysis = async (
),
);
}
return result.ok ? result.value : cliError(result.error);
const value = result.ok ? result.value : cliError(result.error);
return delivery === undefined
? value
: publishCliAnalysisEvidence(value, {
...delivery,
providerId: JAVASCRIPT_APPLICATION_PROVIDER.id,
operation: "analyze_javascript_application",
signal: signal ?? new AbortController().signal,
});
};
const cliError = (
+63
View File
@@ -0,0 +1,63 @@
import { z } from "incur";
import {
javaScriptRoutesDeliverySchema,
webRoutesDeliverySchema,
} from "../domain/analysisView/javascriptRoutesView.js";
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
import { err, ok } from "../domain/result.js";
import {
analysisEvidenceDeliveryOptions,
cliEvidenceDeliveryInputError,
} from "./analysisEvidenceDelivery.js";
export const javascriptRouteDeliveryOptions = {
...analysisEvidenceDeliveryOptions,
view: z
.string()
.optional()
.describe(
"JSON javascript-routes view; requires --detail summary and --evidence_output",
),
};
/** Validate delivery before opening artifacts or attaching a browser. */
export const parseJavaScriptRouteDelivery = (
operation: string,
options: {
detail: "complete" | "summary";
evidence_output?: string | undefined;
view?: string | undefined;
},
) => {
let view: unknown;
try {
view = options.view === undefined ? undefined : JSON.parse(options.view);
} catch (cause) {
return err(
new AnalysisInputError(operation, { cause }, [
{
path: ["view"],
reason: "invalid_format",
message: "view must be valid JSON",
},
]),
);
}
const raw = {
detail: options.detail,
...(view === undefined ? {} : { view }),
};
const schema =
operation === "analyze_web_bundle"
? webRoutesDeliverySchema
: javaScriptRoutesDeliverySchema;
const parsed = schema.safeParse(raw);
if (!parsed.success)
return err(
analysisInputErrorFromIssues(operation, parsed.error.issues, raw),
);
const value = { ...parsed.data, evidenceOutput: options.evidence_output };
const invalid = cliEvidenceDeliveryInputError({ ...value, operation });
return invalid === undefined ? ok(value) : err(invalid);
};