147 lines
6.4 KiB
TypeScript
147 lines
6.4 KiB
TypeScript
import type { ToolContract } from "./toolContracts.js";
|
|
import { toolContractMetadata } from "./toolEffects.js";
|
|
import { evidenceResultOf } from "./toolOutputSchemas.js";
|
|
import {
|
|
electronPageInspectionSchema,
|
|
electronTargetListSchema,
|
|
inspectElectronPageInputSchema,
|
|
listElectronTargetsInputSchema,
|
|
} from "../domain/electronObservation.js";
|
|
import {
|
|
electronActiveObservationInputSchema,
|
|
electronActiveObservationResultSchema,
|
|
} from "../domain/electronActiveObservation.js";
|
|
import {
|
|
analyzeJavaScriptApplicationInputSchema,
|
|
javascriptApplicationAnalysisResultSchema,
|
|
} from "../domain/javascriptApplicationAnalysis.js";
|
|
import {
|
|
javascriptRuntimeReconciliationResultSchema,
|
|
reconcileJavaScriptRuntimeInputSchema,
|
|
} from "../domain/javascriptRuntimeReconciliationSchemas.js";
|
|
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "./javascriptRuntimeReconciliationExample.js";
|
|
|
|
const listOutputSchema = evidenceResultOf(electronTargetListSchema);
|
|
const inspectionOutputSchema = evidenceResultOf(electronPageInspectionSchema);
|
|
const applicationOutputSchema = evidenceResultOf(
|
|
javascriptApplicationAnalysisResultSchema,
|
|
);
|
|
const reconciliationOutputSchema = evidenceResultOf(
|
|
javascriptRuntimeReconciliationResultSchema,
|
|
);
|
|
|
|
const endpoint = "http://127.0.0.1:9223";
|
|
const root = "/Applications/Example.app/Contents/Resources";
|
|
const activeExample = {
|
|
executable_path: "/Applications/Electron.app/Contents/MacOS/Electron",
|
|
application_path: "/Applications/Example.app/Contents/Resources/main.js",
|
|
application_root: "/Applications/Example.app/Contents/Resources",
|
|
args: [],
|
|
actions: [{ step_id: "exercise-ipc", kind: "click", selector: "#run" }],
|
|
limits: {
|
|
max_duration_ms: 60_000,
|
|
action_timeout_ms: 5_000,
|
|
max_actions: 20,
|
|
max_ipc_events: 2_000,
|
|
max_processes: 32,
|
|
max_windows: 32,
|
|
},
|
|
};
|
|
|
|
/** Root-confined Electron file-page discovery and inspection contracts. */
|
|
export const ELECTRON_TOOL_CONTRACTS = [
|
|
{
|
|
name: "list_electron_targets",
|
|
...toolContractMetadata("list_electron_targets"),
|
|
description:
|
|
"List every Electron file:// page target from an approved user-owned loopback CDP endpoint. Every path is canonicalized and must remain contained by an approved filesystem root, including after symlink resolution.",
|
|
kind: "electron-provider",
|
|
inputSchema: listElectronTargetsInputSchema,
|
|
outputSchema: listOutputSchema,
|
|
examples: [
|
|
{
|
|
title: "List approved Electron file pages",
|
|
input: {
|
|
cdp_endpoint: endpoint,
|
|
allowed_file_roots: [root],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "inspect_electron_page",
|
|
...toolContractMetadata("inspect_electron_page"),
|
|
description:
|
|
"Passively inspect one approved Electron file page through CDP. Returns root-confined frames, DOM structure, resource paths, and scripts without evaluating renderer JavaScript or invoking Electron APIs; script contents require separate approval.",
|
|
kind: "electron-provider",
|
|
inputSchema: inspectElectronPageInputSchema,
|
|
outputSchema: inspectionOutputSchema,
|
|
examples: [
|
|
{
|
|
title: "Inspect an approved Electron page",
|
|
input: {
|
|
cdp_endpoint: endpoint,
|
|
allowed_file_roots: [root],
|
|
target_id: "TARGET_ID_FROM_LIST_ELECTRON_TARGETS",
|
|
observation_ms: 100,
|
|
include_script_sources: false,
|
|
limits: {
|
|
max_frames: 200,
|
|
max_dom_nodes: 2_000,
|
|
max_scripts: 500,
|
|
max_resources: 2_000,
|
|
max_workers: 500,
|
|
max_script_source_bytes: 1_048_576,
|
|
max_total_script_source_bytes: 4_194_304,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "analyze_javascript_application",
|
|
...toolContractMetadata("analyze_javascript_application"),
|
|
description:
|
|
"Reconstruct one local ASAR or extracted JavaScript application as an inline application graph without executing it. Returns all recovered graph nodes, edges, semantic relations, limitations, and coverage.",
|
|
kind: "electron-provider",
|
|
inputSchema: analyzeJavaScriptApplicationInputSchema,
|
|
outputSchema: applicationOutputSchema,
|
|
examples: [
|
|
{
|
|
title: "Analyze one local JavaScript application",
|
|
input: {
|
|
input_path: "/Applications/Example.app/Contents/Resources/app.asar",
|
|
format: "auto",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "reconcile_javascript_runtime",
|
|
...toolContractMetadata("reconcile_javascript_runtime"),
|
|
description:
|
|
"Reconcile verified static JavaScript application graphs with existing passive web/Electron CDP, passive V8 Inspector, or provider-owned active Electron Evidence. Active Electron captures contribute an explicitly partial target-only runtime record; they never invent renderer scripts, frames, workers, or execution claims. Exact captured-source digests take priority over caller-declared file/URL mappings; target, frame, script, and worker ambiguity remains explicit, and source-map authority stays separate.",
|
|
kind: "electron-provider",
|
|
inputSchema: reconcileJavaScriptRuntimeInputSchema,
|
|
outputSchema: reconciliationOutputSchema,
|
|
examples: [
|
|
{
|
|
title: "Reconcile one passive Electron capture",
|
|
input: JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "capture_electron_scenario",
|
|
...toolContractMetadata("capture_electron_scenario"),
|
|
description:
|
|
"Use this for an explicitly approved, provider-owned Electron run when passive CDP or Inspector observation cannot exercise application behavior. REA owns startup and teardown, accepts bounded click/wait actions plus window-targeted renderer reload/crash and synthetic open-url/second-instance delivery, and returns correlated window/WebContents/process/preload/session/navigation/shell/IPC evidence without retaining payload values. Results identify observed and unavailable event families, coverage status, action targets, and truncation. External shell, navigation, permission, download, popup, updater, and OS-integration effects are blocked and recorded. Use passive Electron tools for observation-only work.",
|
|
kind: "electron-provider",
|
|
inputSchema: electronActiveObservationInputSchema,
|
|
outputSchema: evidenceResultOf(electronActiveObservationResultSchema),
|
|
examples: [
|
|
{ title: "Exercise an owned Electron application", input: activeExample },
|
|
],
|
|
},
|
|
] as const satisfies readonly ToolContract[];
|