feat(electron): add autonomous Electron runtime analysis (#464)

* feat: add autonomous Electron runtime analysis

* feat(electron): add lifecycle and boundary telemetry

* feat(electron): capture runtime boundary evidence

* fix(electron): package boundary hook helper

* feat(electron): report active capture coverage

* fix(electron): account for bring-your-own runtime

* feat(electron): expand agent-owned runtime scenarios

* fix(ghidra): keep fixture credentials out of argv

* perf(test): serialize local test and docs workloads

* fix(electron): harden active runtime capture

* fix(inspector): require exact runtime target authorization

* fix(docs): make managed manifest host independent

* fix(ci): make generated catalog portable

* fix: unblock autonomous command and electron flows

* fix(electron): close popup and detached helper gaps
This commit is contained in:
morluto
2026-08-05 19:07:46 +08:00
committed by GitHub
parent 51559245d2
commit 8f229ede70
104 changed files with 5055 additions and 196 deletions
+7 -1
View File
@@ -12,7 +12,8 @@ export type BrowserObservationOperation =
| "inspect_electron_page"
| "list_javascript_runtime_targets"
| "observe_javascript_runtime"
| "capture_browser_scenario";
| "capture_browser_scenario"
| "capture_electron_scenario";
/** Stable failure reasons shared by browser-family provider adapters. */
export type BrowserObservationFailureReason =
@@ -24,5 +25,10 @@ export type BrowserObservationFailureReason =
| "protocol_error"
| "disconnected"
| "payload_limit"
| "window_not_found"
| "window_metadata_missing"
| "process_ownership_unavailable"
| "cleanup_failed"
| "cancelled"
| "timeout"
| "secret_unavailable";
+6 -4
View File
@@ -4,7 +4,10 @@ import {
conformancePackageSchema,
type ConformancePackage,
} from "./conformancePackage.js";
import { trustGateResultSchema } from "./conformanceTrustGate.js";
import {
evaluatePackageTrustGates,
trustGateResultSchema,
} from "./conformanceTrustGate.js";
/** Result of a single scenario replay. */
export const scenarioReplayResultSchema = z.strictObject({
@@ -31,6 +34,7 @@ export const packageReplayResultSchema = z.strictObject({
.strictObject({
scenario_id: z.string().min(1),
dimension: z.string().min(1),
evidence_id: z.string().min(1),
message: z.string(),
})
.nullable(),
@@ -116,6 +120,7 @@ export async function replayConformancePackage(
? {
scenario_id: first_drift_gate.scenario_id,
dimension: first_drift_gate.first_divergence.dimension,
evidence_id: first_drift_gate.first_divergence.evidence_id,
message: first_drift_gate.first_divergence.message,
}
: null;
@@ -133,6 +138,3 @@ export async function replayConformancePackage(
first_drift,
};
}
/** Import trust gate evaluator for replay. */
import { evaluatePackageTrustGates } from "./conformanceTrustGate.js";
+188 -30
View File
@@ -47,12 +47,158 @@ const SEMANTIC_DIMENSIONS = new Set([
"stdout",
"stderr",
"filesystem",
"process",
"process_tree",
"shim_events",
"protocol_events",
"event_journal",
]);
type IncompleteStatus = "unknown" | "truncated";
type EvidenceView = {
readonly values: Readonly<Record<string, unknown>>;
readonly evidence_ids: readonly string[];
readonly status: IncompleteStatus | null;
readonly unknown_scopes: readonly string[];
};
type CompareDimensionOptions = {
readonly truncated?: boolean;
readonly evidence_ids?: readonly string[];
readonly expected_status?: IncompleteStatus | null;
readonly actual_status?: IncompleteStatus | null;
};
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
typeof value === "object" && value !== null && !Array.isArray(value);
const uniqueStrings = (values: readonly string[]): string[] => [
...new Set(values.filter((value) => value.length > 0)),
];
const stringValues = (value: unknown): readonly string[] => {
if (typeof value === "string") return value.length > 0 ? [value] : [];
if (!Array.isArray(value)) return [];
return value.filter(
(item): item is string => typeof item === "string" && item.length > 0,
);
};
const evidenceIds = (record: Readonly<Record<string, unknown>>): string[] =>
uniqueStrings([
...stringValues(record["evidence_id"]),
...stringValues(record["evidence_ids"]),
...stringValues(record["evidence_links"]),
]);
const incompleteStatus = (value: unknown): IncompleteStatus | null => {
if (!isRecord(value)) return null;
const record = value;
if (record["truncated"] === true) return "truncated";
const status = record["status"];
if (status === "truncated") return "truncated";
if (
status === "unknown" ||
status === "unavailable" ||
status === "partial" ||
status === "incomplete" ||
status === "unverifiable" ||
status === "failed" ||
status === "not_approved"
)
return "unknown";
for (const key of ["coverage", "completeness"]) {
const nested = record[key];
if (!isRecord(nested)) continue;
const nestedStatus = incompleteStatus(nested);
if (nestedStatus !== null) return nestedStatus;
}
return null;
};
const hasResidualUnknowns = (value: unknown): boolean =>
isRecord(value) &&
Array.isArray(value["residual_unknowns"]) &&
value["residual_unknowns"].length > 0;
const unknownScopes = (record: Readonly<Record<string, unknown>>): string[] => {
const residualUnknowns = record["residual_unknowns"];
if (!Array.isArray(residualUnknowns)) return [];
return residualUnknowns.flatMap((item) => {
if (!isRecord(item) || typeof item["scope"] !== "string") return [];
return [item["scope"]];
});
};
const evidenceView = (input: unknown): EvidenceView => {
if (!isRecord(input))
return {
values: {},
evidence_ids: [],
status: null,
unknown_scopes: [],
};
const normalized = input["normalized_result"];
const values = isRecord(normalized) ? normalized : input;
const normalizedStatus = isRecord(normalized)
? incompleteStatus(normalized)
: null;
return {
values,
evidence_ids: evidenceIds(input),
status: incompleteStatus(input) ?? normalizedStatus,
unknown_scopes: uniqueStrings([
...unknownScopes(input),
...(isRecord(normalized) ? unknownScopes(normalized) : []),
]),
};
};
const dimensionScope = (dimensionName: string): string | null => {
if (dimensionName === "exit_code" || dimensionName === "exit") return "exit";
if (
dimensionName === "process" ||
dimensionName === "process_tree" ||
dimensionName === "event_journal"
)
return "process";
if (dimensionName === "stdout" || dimensionName === "stderr")
return "terminal";
if (dimensionName === "filesystem") return "filesystem";
if (dimensionName === "shim_events") return "shim";
if (dimensionName === "protocol_events") return "protocol";
return null;
};
const statusForDimension = (
view: EvidenceView,
dimensionName: string,
): IncompleteStatus | null => {
const valueStatus = incompleteStatus(view.values[dimensionName]);
if (valueStatus !== null) return valueStatus;
if (hasResidualUnknowns(view.values[dimensionName])) return "unknown";
const scope = dimensionScope(dimensionName);
return scope !== null && view.unknown_scopes.includes(scope)
? "unknown"
: view.status;
};
const comparisonIncompleteStatus = (
expected: unknown,
actual: unknown,
options: CompareDimensionOptions,
): IncompleteStatus | null => {
const expectedStatus = options.expected_status ?? incompleteStatus(expected);
const actualStatus = options.actual_status ?? incompleteStatus(actual);
if (options.truncated) return "truncated";
if (expectedStatus === "truncated" || actualStatus === "truncated")
return "truncated";
if (expectedStatus === "unknown" || actualStatus === "unknown")
return "unknown";
return null;
};
/** Check if a dimension name is volatile (timing/normalization noise). */
export function isVolatileDimension(name: string): boolean {
return VOLATILE_DIMENSIONS.has(name);
@@ -75,7 +221,7 @@ export function compareDimension(
dimensionName: string,
expected: unknown,
actual: unknown,
options: { truncated?: boolean } = {},
options: CompareDimensionOptions = {},
): DimensionResult {
// Volatile dimensions: always match regardless of values
if (isVolatileDimension(dimensionName)) {
@@ -83,16 +229,22 @@ export function compareDimension(
name: dimensionName,
status: "match",
message: "volatile dimension ignored",
evidence_ids: [],
evidence_ids: uniqueStrings(options.evidence_ids ?? []),
};
}
if (options.truncated) {
const status = comparisonIncompleteStatus(expected, actual, options);
const resultEvidenceIds = uniqueStrings(options.evidence_ids ?? []);
if (status !== null) {
return {
name: dimensionName,
status: "truncated",
message: "evidence was truncated",
evidence_ids: [],
status,
message:
status === "truncated"
? "evidence was truncated"
: "evidence completeness is unknown",
evidence_ids: resultEvidenceIds,
};
}
@@ -101,16 +253,16 @@ export function compareDimension(
name: dimensionName,
status: "unknown",
message: "both expected and actual are undefined",
evidence_ids: [],
evidence_ids: resultEvidenceIds,
};
}
if (expected === undefined || actual === undefined) {
return {
name: dimensionName,
status: "mismatch",
message: `expected ${expected === undefined ? "present" : "absent"}, actual ${actual === undefined ? "absent" : "present"}`,
evidence_ids: [],
status: "unknown",
message: "one side has no observed value",
evidence_ids: resultEvidenceIds,
};
}
@@ -123,14 +275,14 @@ export function compareDimension(
name: dimensionName,
status: "match",
message: "",
evidence_ids: [],
evidence_ids: resultEvidenceIds,
};
}
return {
name: dimensionName,
status: "mismatch",
message: "semantic content differs",
evidence_ids: [],
evidence_ids: resultEvidenceIds,
};
}
@@ -140,7 +292,7 @@ export function compareDimension(
name: dimensionName,
status: "match",
message: "",
evidence_ids: [],
evidence_ids: resultEvidenceIds,
};
}
@@ -148,7 +300,7 @@ export function compareDimension(
name: dimensionName,
status: "mismatch",
message: `expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`,
evidence_ids: [],
evidence_ids: resultEvidenceIds,
};
}
@@ -156,9 +308,10 @@ export function compareDimension(
function sortKeys(value: unknown): unknown {
if (value === null || typeof value !== "object") return value;
if (Array.isArray(value)) return value.map(sortKeys);
if (!isRecord(value)) return value;
const sorted: Record<string, unknown> = {};
for (const key of Object.keys(value as Record<string, unknown>).sort()) {
sorted[key] = sortKeys((value as Record<string, unknown>)[key]);
for (const key of Object.keys(value).sort()) {
sorted[key] = sortKeys(value[key]);
}
return sorted;
}
@@ -169,23 +322,28 @@ function sortKeys(value: unknown): unknown {
*/
export function evaluateTrustGate(
contract: VerifierContract,
expectedEvidence: Record<string, unknown>,
actualEvidence: Record<string, unknown>,
options: { truncated?: boolean } = {},
expectedEvidence: unknown,
actualEvidence: unknown,
options: { readonly truncated?: boolean } = {},
): TrustGateResult {
const dimensionResults: DimensionResult[] = [];
let firstDivergence: TrustGateResult["first_divergence"] = null;
const expectedView = evidenceView(expectedEvidence);
const actualView = evidenceView(actualEvidence);
for (const dim of contract.dimensions) {
if (!dim.required) continue;
const expectedValue = expectedEvidence[dim.name];
const actualValue = actualEvidence[dim.name];
const result = compareDimension(
dim.name,
expectedValue,
actualValue,
options,
);
const expectedValue = expectedView.values[dim.name];
const actualValue = actualView.values[dim.name];
const result = compareDimension(dim.name, expectedValue, actualValue, {
...options,
expected_status: statusForDimension(expectedView, dim.name),
actual_status: statusForDimension(actualView, dim.name),
evidence_ids: uniqueStrings([
...actualView.evidence_ids,
...expectedView.evidence_ids,
]),
});
dimensionResults.push(result);
if (result.status === "mismatch" && firstDivergence === null) {
@@ -223,8 +381,8 @@ export function evaluateTrustGate(
*/
export function evaluatePackageTrustGates(
pkg: ConformancePackage,
actualEvidence: Record<string, Record<string, unknown>>,
options: { truncated?: boolean } = {},
actualEvidence: Readonly<Record<string, Readonly<Record<string, unknown>>>>,
options: { readonly truncated?: boolean } = {},
): TrustGateResult[] {
const results: TrustGateResult[] = [];
for (const contract of pkg.verifier_contracts) {
@@ -236,7 +394,7 @@ export function evaluatePackageTrustGates(
const actual = actualEvidence[contract.scenario_id] ?? {};
const result = evaluateTrustGate(
contract,
expectedEvidence as Record<string, unknown>,
expectedEvidence,
actual,
options,
);
+296
View File
@@ -0,0 +1,296 @@
import { isAbsolute } from "node:path";
import { z } from "zod";
const absolutePathSchema = z
.string()
.min(1)
.max(16_384)
.refine(isAbsolute, "path must be absolute");
const windowIndexSchema = z.number().int().min(0).max(99);
const deepLinkUrlSchema = z
.string()
.min(1)
.max(4_096)
.refine((value) => {
try {
return new URL(value).protocol.length > 0;
} catch {
return false;
}
}, "deep-link url must be an absolute URL");
const actionSchema = z.discriminatedUnion("kind", [
z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.literal("click"),
selector: z.string().min(1).max(512),
window_index: windowIndexSchema.default(0),
}),
z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.literal("wait"),
duration_ms: z.number().int().min(0).max(10_000),
window_index: windowIndexSchema.optional(),
}),
z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.literal("renderer-reload"),
window_index: windowIndexSchema.default(0),
}),
z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.literal("renderer-crash"),
window_index: windowIndexSchema.default(0),
}),
z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.literal("deep-link"),
delivery: z.enum(["open-url", "second-instance"]),
url: deepLinkUrlSchema,
}),
]);
const limitsSchema = z.strictObject({
max_duration_ms: z.number().int().min(1).max(120_000).default(60_000),
action_timeout_ms: z.number().int().min(1).max(30_000).default(5_000),
max_actions: z.number().int().min(1).max(100).default(20),
max_ipc_events: z.number().int().min(1).max(10_000).default(2_000),
max_runtime_events: z.number().int().min(1).max(20_000).default(5_000),
max_processes: z.number().int().min(1).max(100).default(32),
max_windows: z.number().int().min(1).max(100).default(32),
});
/** Input for one explicit, provider-owned Electron runtime experiment. */
export const electronActiveObservationInputSchema = z
.strictObject({
schema_version: z.literal(1),
executable_path: absolutePathSchema,
application_path: absolutePathSchema,
application_root: absolutePathSchema,
args: z.array(z.string().max(4_096)).max(32).default([]),
actions: z.array(actionSchema).max(100).default([]),
limits: limitsSchema.default({
max_duration_ms: 60_000,
action_timeout_ms: 5_000,
max_actions: 20,
max_ipc_events: 2_000,
max_runtime_events: 5_000,
max_processes: 32,
max_windows: 32,
}),
approved: z.literal(true),
})
.superRefine((input, context) => {
if (input.actions.length > input.limits.max_actions)
context.addIssue({
code: "custom",
path: ["actions"],
message: "actions exceed the configured max_actions limit",
});
});
export type ElectronActiveObservationInput = z.infer<
typeof electronActiveObservationInputSchema
>;
const ipcEventSchema = z.strictObject({
sequence: z.number().int().min(1),
correlation_id: z.string().max(256).nullable().default(null),
kind: z.enum([
"main-handler-invocation",
"main-event-invocation",
"utility-process-fork",
"utility-process-message",
"ipc-main-to-renderer",
"ipc-utility-to-main",
"ipc-renderer-send",
"ipc-renderer-invoke",
"ipc-renderer-post-message",
]),
event: z.string().max(128).nullable().optional(),
phase: z
.enum(["attempted", "completed", "blocked", "failed", "observed"])
.nullable()
.optional(),
channel: z.string().max(1_024).nullable(),
channel_truncated: z.boolean().default(false),
direction: z
.enum([
"renderer-to-main",
"main-to-renderer",
"main-to-utility",
"utility-to-main",
])
.nullable()
.optional(),
sender: z.string().max(256).nullable().optional(),
receiver: z.string().max(256).nullable().optional(),
frame: z.string().max(256).nullable().default(null),
target: z.string().max(256).nullable().optional(),
argument_shapes: z.array(z.string().max(64)).max(32),
argument_shapes_truncated: z.boolean().default(false),
result_shape: z.string().max(64).nullable(),
process_type: z.string().max(128).nullable(),
source: z.string().max(64).default("electron-active-hook"),
capture_method: z
.enum(["api-wrapper", "event-emitter", "process-hook"])
.default("api-wrapper"),
artifact_path: z.string().max(16_384).nullable().default(null),
artifact_sha256: z
.string()
.regex(/^[a-f0-9]{64}$/u)
.nullable()
.default(null),
error: z.boolean(),
});
const timelineEventSchema = z.strictObject({
sequence: z.number().int().min(1),
correlation_id: z.string().max(256).nullable().default(null),
kind: z.enum([
"main-handler-invocation",
"main-event-invocation",
"utility-process-fork",
"utility-process-message",
"ipc-main-to-renderer",
"ipc-utility-to-main",
"ipc-renderer-send",
"ipc-renderer-invoke",
"ipc-renderer-post-message",
"app-lifecycle",
"window-lifecycle",
"web-contents-lifecycle",
"navigation",
"shell-attempt",
"process-lifecycle",
"permission",
"popup-attempt",
"download",
"protocol",
"preload",
"native-addon",
"updater",
"error",
]),
event: z.string().max(128).nullable(),
phase: z.enum(["attempted", "completed", "blocked", "failed", "observed"]),
channel: z.string().max(1_024).nullable(),
channel_truncated: z.boolean(),
direction: z
.enum([
"renderer-to-main",
"main-to-renderer",
"main-to-utility",
"utility-to-main",
])
.nullable(),
sender: z.string().max(256).nullable(),
receiver: z.string().max(256).nullable(),
frame: z.string().max(256).nullable(),
target: z.string().max(256).nullable(),
argument_shapes: z.array(z.string().max(64)).max(32),
argument_shapes_truncated: z.boolean(),
result_shape: z.string().max(64).nullable(),
process_type: z.string().max(128).nullable(),
source: z.string().max(64),
capture_method: z.enum(["api-wrapper", "event-emitter", "process-hook"]),
artifact_path: z.string().max(16_384).nullable(),
artifact_sha256: z
.string()
.regex(/^[a-f0-9]{64}$/u)
.nullable(),
error: z.boolean(),
});
const processMetricSchema = z.strictObject({
pid: z.number().int().min(1),
type: z.string().min(1).max(128),
name: z.string().max(256).nullable(),
service_name: z.string().max(256).nullable(),
});
const windowResultSchema = z.strictObject({
window_id: z.string().max(256),
web_contents_id: z.string().max(256),
url: z.string().max(65_536),
title: z.string().max(16_384),
visible: z.boolean().nullable(),
destroyed: z.boolean(),
});
const coverageSchema = z.strictObject({
status: z.enum([
"complete",
"partial_attach",
"capture_truncated",
"hook_conflict",
"target_exited",
"cleanup_failed",
]),
observed_event_families: z.array(z.string().max(128)).max(32),
unavailable_event_families: z.array(z.string().max(128)).max(32),
observed_roles: z.array(z.string().max(128)).max(16),
pre_capture_activity: z.literal("unavailable"),
});
const actionResultSchema = z.strictObject({
step_id: z.string().min(1).max(128),
kind: z.enum([
"click",
"wait",
"renderer-reload",
"renderer-crash",
"deep-link",
]),
window_index: windowIndexSchema.nullable(),
target: z.string().max(256).nullable(),
status: z.enum(["completed", "failed", "cancelled"]),
elapsed_ms: z.number().int().min(0),
error: z.string().nullable(),
});
/** Bounded result of a provider-owned Electron runtime experiment. */
export const electronActiveObservationResultSchema = z.strictObject({
schema_version: z.literal(1),
application: z.strictObject({
executable_path: absolutePathSchema,
application_path: absolutePathSchema,
electron_version: z.string().min(1).max(256),
process_ownership: z.literal("provider-owned"),
cleanup: z.literal("terminated-owned-process"),
}),
actions: z.array(actionResultSchema).max(100),
windows: z.array(windowResultSchema).max(100),
windows_truncated: z.boolean(),
processes: z.strictObject({
items: z.array(processMetricSchema).max(100),
truncated: z.boolean(),
}),
ipc: z.strictObject({
events: z.array(ipcEventSchema).max(10_000),
observed: z.number().int().min(0),
retained: z.number().int().min(0),
truncated: z.boolean(),
}),
timeline: z
.strictObject({
events: z.array(timelineEventSchema).max(20_000),
observed: z.number().int().min(0),
retained: z.number().int().min(0),
truncated: z.boolean(),
})
.default({ events: [], observed: 0, retained: 0, truncated: false }),
coverage: coverageSchema.default({
status: "partial_attach",
observed_event_families: [],
unavailable_event_families: [],
observed_roles: [],
pre_capture_activity: "unavailable",
}),
limitations: z.array(z.string().max(4_096)).max(100),
});
export type ElectronActiveObservationResult = z.infer<
typeof electronActiveObservationResultSchema
>;
@@ -115,6 +115,7 @@ export const javascriptRuntimeLocationSchema = z.discriminatedUnion("kind", [
z.strictObject({
kind: z.literal("file"),
file_path: z.string().min(1).max(16_384),
authority: z.literal("scope-fallback").optional(),
}),
z.strictObject({
kind: z.literal("url"),
@@ -0,0 +1,138 @@
import { createHash } from "node:crypto";
import { isAbsolute, relative } from "node:path";
import canonicalize from "canonicalize";
import { z } from "zod";
import {
classifyBrowserCompleteness,
type BrowserCompleteness,
} from "./browserCompleteness.js";
import {
electronActiveObservationResultSchema,
type ElectronActiveObservationResult,
} from "./electronActiveObservation.js";
import type { Evidence } from "./evidence.js";
import type { ParsedRuntimeCapture } from "./javascriptRuntimeReconciliationParsing.js";
/** Parse active Electron Evidence as a bounded, target-only runtime capture. */
export const parseActiveElectronCapture = (
evidence: Evidence,
): ParsedRuntimeCapture => {
assertIdentity(evidence);
const result = electronActiveObservationResultSchema.parse(
evidence.normalized_result,
);
const parameters = z
.object({
approved: z.literal(true),
application_path: absolutePathSchema,
application_root: absolutePathSchema,
})
.passthrough()
.parse(evidence.parameters);
if (
result.application.application_path !== parameters.application_path ||
!isWithinRoot(
parameters.application_root,
result.application.application_path,
)
)
throw new TypeError(
"Active Electron Evidence application path disagrees with its approved root",
);
return {
kind: "electron-active",
evidence,
inspection: normalizeInspection(result),
captureSha256: digestCanonical(result),
scriptsCompleteWithinScope: false,
};
};
const absolutePathSchema = z.string().min(1).max(16_384).refine(isAbsolute);
const assertIdentity = (evidence: Evidence): void => {
if (
evidence.operation !== "capture_electron_scenario" ||
evidence.predicate_type !== "rea.electron-active-scenario/v1" ||
evidence.provider.id !== "rea-playwright-electron-active" ||
evidence.provider.name !==
"REA Playwright active Electron observation provider" ||
evidence.provider.version !== "1" ||
evidence.authority !== "controlled-replay" ||
evidence.confidence !== "observed"
)
throw new TypeError(
"Evidence does not match the supported capture_electron_scenario contract",
);
};
const normalizeInspection = (
result: ElectronActiveObservationResult,
): {
readonly target: {
readonly target_id: string;
readonly type: string;
readonly title: string;
readonly attached: boolean;
readonly file_path: string;
};
readonly frames: readonly [];
readonly scripts: { readonly items: readonly [] };
readonly workers: readonly [];
readonly completeness: BrowserCompleteness;
} => ({
target: {
target_id: `electron-active:${digestCanonical(result.application.application_path).slice(0, 32)}`,
type: "electron-application",
title: result.application.application_path,
attached: true,
file_path: result.application.application_path,
},
frames: [],
scripts: { items: [] },
workers: [],
completeness: classifyBrowserCompleteness({
policyFilteredSections: new Set(),
attachLimitedSections: new Set(),
truncatedSections: new Set(
result.windows_truncated ||
result.processes.truncated ||
result.ipc.truncated ||
result.timeline.truncated
? ["timeline"]
: [],
),
unavailableSections: new Set([
"frames",
"scripts",
"script_sources",
"workers",
]),
excluded: [],
droppedEvents: {
scripts: 0,
network_requests: 0,
console_events: 0,
websocket_connections: 0,
websocket_frames: 0,
webmcp_tools: 0,
timeline_events: result.timeline.truncated ? result.timeline.observed : 0,
},
}),
});
const digestCanonical = (value: unknown): string => {
const encoded = canonicalize(value);
if (encoded === undefined)
throw new TypeError("Runtime reconciliation could not canonicalize input");
return createHash("sha256").update(encoded).digest("hex");
};
const isWithinRoot = (root: string, path: string): boolean => {
const remainder = relative(root, path);
return (
remainder === "" || (!remainder.startsWith("..") && !isAbsolute(remainder))
);
};
@@ -34,6 +34,7 @@ import {
compareCodePoints,
type JavaScriptApplicationGraph,
} from "./javascriptApplicationGraph.js";
import { parseActiveElectronCapture } from "./javascriptRuntimeReconciliationActive.js";
import type { ReconcileJavaScriptRuntimeInput } from "./javascriptRuntimeReconciliationSchemas.js";
type StaticLayerInput =
@@ -101,6 +102,22 @@ export type ParsedRuntimeCapture =
| (RuntimeCaptureBase & {
readonly kind: "v8-inspector";
readonly inspection: NormalizedV8Inspection;
})
| (RuntimeCaptureBase & {
readonly kind: "electron-active";
readonly inspection: {
readonly target: {
readonly target_id: string;
readonly type: string;
readonly title: string;
readonly attached: boolean;
readonly file_path: string;
};
readonly frames: readonly [];
readonly scripts: { readonly items: readonly [] };
readonly workers: readonly [];
readonly completeness: BrowserCompleteness;
};
});
/** Parse and semantically bind every static analysis Evidence layer. */
@@ -255,8 +272,11 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
scriptsCompleteWithinScope: false,
};
}
if (evidence.operation === "capture_electron_scenario") {
return parseActiveElectronCapture(evidence);
}
throw new TypeError(
"Runtime reconciliation requires inspect_web_page, inspect_electron_page, or observe_javascript_runtime Evidence",
"Runtime reconciliation requires inspect_web_page, inspect_electron_page, observe_javascript_runtime, or capture_electron_scenario Evidence",
);
};
@@ -170,7 +170,7 @@ const layerSummarySchema = z.strictObject({
const captureSummarySchema = z.strictObject({
evidence_id: evidenceIdSchema,
capture_sha256: digestSchema,
kind: z.enum(["browser", "electron", "v8-inspector"]),
kind: z.enum(["browser", "electron", "v8-inspector", "electron-active"]),
target_node_id: nodeIdSchema,
target_key: boundedTextSchema,
target_location: boundedTextSchema,
+1
View File
@@ -8,6 +8,7 @@ export type PermissionCapability =
| "browser_observe"
| "browser_automate"
| "electron_observe"
| "electron_automate"
| "v8_inspector_observe"
| "evidence_read"
| "evidence_write"