Files
rea/src/cliObservationOptions.ts
T
KAI-CHIEH YANG e5965adb29 feat(cli): accept JavaScript source selections from a JSON array or file (#5029)
* feat(cli): accept JavaScript source selections from a JSON array or file

Add --source-paths-json to analyze and analyze-javascript-application.
It takes an inline JSON array or a JSON file path of exact inventoried
paths and appends them after any --source-path values, so a long
selection no longer has to fit on one command line (cmd.exe through npx
on Windows stops at 8,191 characters). Entries stay artifact-relative and
go through the existing source_paths validation; the native lane rejects
the option like --source-path.

Refs #4987

* fix(cli): cancel --source-paths-json file reads with the command

Pass the command's abort signal through parseCliJsonInput to
readJsonInputFile, so SIGINT/SIGTERM stop a selection-file read instead
of waiting for it to finish. A cancelled read now propagates its abort
rather than being reported as a file read failure.

* test(cli): preserve ASAR identity for JSON file selections

* docs(cli): record source-selection task costs and identity verification

---------

Co-authored-by: KJLavender <KJLavender@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-10-24 12:32:41 +08:00

110 lines
3.9 KiB
TypeScript

import { javascriptRouteDeliveryOptions } from "./cli/javascriptRouteDelivery.js";
import { z } from "incur";
import { webRuntimeCommandTimeoutSchema } from "./domain/browserDeadline.js";
import { javaScriptAnalysisResourceControlsSchema } from "./domain/javascript/javascriptAnalysisResourceControls.js";
import { javaScriptSourcePathsSchema } from "./domain/javascript/javascriptSourceSelection.js";
/** Accept an agent-selected browser observation duration without an artificial ceiling. */
export const observationDuration = (fallback: number, minimum = 0) =>
z
.number()
.int()
.min(minimum)
.default(fallback)
.describe("Observation duration in milliseconds");
/** Shared passive browser origin options. */
export const browserScopeOptions = {
allowedOrigins: z
.array(z.string().min(1))
.optional()
.describe("Optional exact-origin filter"),
commandTimeoutMs: webRuntimeCommandTimeoutSchema,
};
/** Keep an omitted command deadline absent so Evidence records the caller selection only. */
export const selectedCommandTimeout = (
commandTimeoutMs: number | undefined,
): { readonly command_timeout_ms?: number } =>
commandTimeoutMs === undefined
? {}
: { command_timeout_ms: commandTimeoutMs };
export const browserPageInspectionOptions = z.object({
...browserScopeOptions,
observationMs: observationDuration(500),
includeAccessibilityText: z
.boolean()
.default(false)
.describe("Include accessibility text"),
includeConsoleText: z
.boolean()
.default(false)
.describe("Include console message text"),
includeJsonBodyShapes: z
.boolean()
.default(false)
.describe("Include structural shapes of JSON response bodies"),
includeWebsocketShapes: z
.boolean()
.default(false)
.describe("Include structural shapes of WebSocket payloads"),
includeScriptSources: z
.boolean()
.default(false)
.describe("Include JavaScript source text"),
includeStorageKeys: z
.boolean()
.default(false)
.describe("Include storage key names without values"),
includeStorageFingerprints: z
.boolean()
.default(false)
.describe("Include content-derived storage fingerprints"),
});
export const electronPageInspectionOptions = z.object({
observationMs: observationDuration(100),
includeScriptSources: z
.boolean()
.default(false)
.describe("Include JavaScript source text"),
commandTimeoutMs: webRuntimeCommandTimeoutSchema,
});
export const javascriptApplicationOptions = z.object({
...javascriptRouteDeliveryOptions,
maxSemanticNodes:
javaScriptAnalysisResourceControlsSchema.shape.max_semantic_nodes,
maxSemanticNodesPerFile:
javaScriptAnalysisResourceControlsSchema.shape.max_semantic_nodes_per_file,
maxSemanticUnknowns:
javaScriptAnalysisResourceControlsSchema.shape.max_semantic_unknowns,
maxSemanticUnknownsPerFile:
javaScriptAnalysisResourceControlsSchema.shape
.max_semantic_unknowns_per_file,
sourcePath: javaScriptSourcePathsSchema
.optional()
.describe(
"Exact inventoried file path relative to the application root; repeat to select several. No implicit dependencies.",
),
sourcePathsJson: z
.string()
.min(1)
.optional()
.describe(
"Inline JSON array or JSON file path of exact inventoried file paths relative to the application root, selected after any --source-path values. Use a file for selections that exceed the host command-line limit.",
),
maxHeapMb: javaScriptAnalysisResourceControlsSchema.shape.max_heap_mb,
analysisTimeoutMs:
javaScriptAnalysisResourceControlsSchema.shape.analysis_timeout_ms,
artifactFormat: z
.enum(["auto", "asar", "directory"])
.default("auto")
.describe("Application artifact format"),
integrityPolicy: z
.enum(["fail", "record-and-continue"])
.default("fail")
.describe("Behavior when declared application integrity does not match"),
});