refactor(javascript): group domain semantics and contracts (#907)
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { evidenceInputSchema } from "../evidenceInputContracts.js";
|
||||
import { compareApplicationVersionsInputSchema } from "../../domain/javascript/javascriptApplicationVersionComparisonSchemas.js";
|
||||
import { compareJavaScriptExportShapesInputSchema } from "../../domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../../domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import { javaScriptSemanticQueryInputSchema } from "../../domain/javascript/javascriptSemanticQuerySchemas.js";
|
||||
import { compareSourceToBundleInputSchema } from "../../domain/javascript/sourceToBundleComparisonSchemas.js";
|
||||
|
||||
const traceApplicationFeatureFacts = {
|
||||
native_observations:
|
||||
traceApplicationFeatureInputSchema.shape.native_observations,
|
||||
seed: traceApplicationFeatureInputSchema.shape.seed,
|
||||
direction: traceApplicationFeatureInputSchema.shape.direction,
|
||||
} as const;
|
||||
|
||||
/** Application trace request accepting inline or same-session application Evidence. */
|
||||
export const traceApplicationFeatureRequestSchema = z.strictObject({
|
||||
...traceApplicationFeatureFacts,
|
||||
application: evidenceInputSchema,
|
||||
});
|
||||
|
||||
/** Semantic trace request accepting inline or same-session application Evidence. */
|
||||
export const traceJavaScriptSemanticsRequestSchema = z.strictObject({
|
||||
application: evidenceInputSchema,
|
||||
query: javaScriptSemanticQueryInputSchema,
|
||||
});
|
||||
|
||||
const compareApplicationVersionsFacts = {
|
||||
left_native_observations:
|
||||
compareApplicationVersionsInputSchema.shape.left_native_observations,
|
||||
right_native_observations:
|
||||
compareApplicationVersionsInputSchema.shape.right_native_observations,
|
||||
} as const;
|
||||
|
||||
/** Application comparison request accepting inline or same-session application Evidence. */
|
||||
export const compareApplicationVersionsRequestSchema = z.strictObject({
|
||||
...compareApplicationVersionsFacts,
|
||||
left: evidenceInputSchema,
|
||||
right: evidenceInputSchema,
|
||||
});
|
||||
|
||||
const compareSourceToBundleFacts = {
|
||||
reference: compareSourceToBundleInputSchema.shape.reference,
|
||||
} as const;
|
||||
|
||||
/** Historical-source comparison accepting inline or same-session application Evidence. */
|
||||
export const compareSourceToBundleRequestSchema = z.strictObject({
|
||||
...compareSourceToBundleFacts,
|
||||
application: evidenceInputSchema,
|
||||
});
|
||||
|
||||
const compareJavaScriptExportShapesFacts = {
|
||||
left_module_path:
|
||||
compareJavaScriptExportShapesInputSchema.shape.left_module_path,
|
||||
left_export_name:
|
||||
compareJavaScriptExportShapesInputSchema.shape.left_export_name,
|
||||
right_module_path:
|
||||
compareJavaScriptExportShapesInputSchema.shape.right_module_path,
|
||||
right_export_name:
|
||||
compareJavaScriptExportShapesInputSchema.shape.right_export_name,
|
||||
} as const;
|
||||
|
||||
/** Export-shape request accepting inline or same-session application Evidence. */
|
||||
export const compareJavaScriptExportShapesRequestSchema = z.strictObject({
|
||||
...compareJavaScriptExportShapesFacts,
|
||||
left: evidenceInputSchema,
|
||||
right: evidenceInputSchema,
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
import type { ToolContract } from "../toolContracts.js";
|
||||
import { toolContractMetadata } from "../toolEffects.js";
|
||||
import { evidenceResultOf } from "../toolOutputSchemas.js";
|
||||
import {
|
||||
electronPageInspectionSchema,
|
||||
electronTargetListSchema,
|
||||
inspectElectronPageInputSchema,
|
||||
listElectronTargetsInputSchema,
|
||||
} from "../../domain/javascript/electronObservation.js";
|
||||
import {
|
||||
electronActiveObservationInputSchema,
|
||||
electronActiveObservationResultSchema,
|
||||
} from "../../domain/javascript/electronActiveObservation.js";
|
||||
import {
|
||||
analyzeJavaScriptApplicationInputSchema,
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
} from "../../domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import {
|
||||
javascriptRuntimeReconciliationResultSchema,
|
||||
reconcileJavaScriptRuntimeInputSchema,
|
||||
} from "../../domain/javascript/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 activeExample = {
|
||||
executable_path: "/Applications/Electron.app/Contents/MacOS/Electron",
|
||||
application_path: "/Applications/Example.app/Contents/Resources/main.js",
|
||||
args: [],
|
||||
actions: [{ step_id: "exercise-ipc", kind: "click", selector: "#run" }],
|
||||
};
|
||||
|
||||
/** Endpoint-scoped 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 a selected loopback CDP endpoint. Local file paths are canonicalized after symlink resolution. Selecting an endpoint exposes every eligible target and its local path metadata.",
|
||||
kind: "electron-provider",
|
||||
inputSchema: listElectronTargetsInputSchema,
|
||||
outputSchema: listOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
title: "List Electron file pages",
|
||||
input: {
|
||||
cdp_endpoint: endpoint,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "inspect_electron_page",
|
||||
...toolContractMetadata("inspect_electron_page"),
|
||||
description:
|
||||
"Passively inspect one Electron file page by supplying its loopback CDP endpoint and target ID. The provider rechecks that the target currently exists at that endpoint and is a local file page. Returns frames, DOM structure, resource paths, and scripts without evaluating renderer JavaScript or invoking Electron APIs. The selected endpoint exposes every local file page and its metadata to this tool.",
|
||||
kind: "electron-provider",
|
||||
inputSchema: inspectElectronPageInputSchema,
|
||||
outputSchema: inspectionOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
title: "Inspect an Electron page",
|
||||
input: {
|
||||
cdp_endpoint: endpoint,
|
||||
target_id: "TARGET_ID_FROM_LIST_ELECTRON_TARGETS",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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 a provider-owned Electron run when passive CDP or Inspector observation cannot exercise application behavior. REA owns startup and teardown, accepts caller-defined 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[];
|
||||
@@ -0,0 +1,126 @@
|
||||
import { createEvidence } from "../../domain/evidence.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../domain/javascript/javascriptRuntimeReconciliation.js";
|
||||
import {
|
||||
JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE,
|
||||
} from "./javascriptRuntimeReconciliationExample.js";
|
||||
import { createHistoricalSourceGraph } from "../../domain/referenceSourceGraph.js";
|
||||
|
||||
const reconciliation = reconcileJavaScriptRuntime(
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE,
|
||||
);
|
||||
const reconciliationEvidence = createEvidence(
|
||||
undefined,
|
||||
{
|
||||
id: "rea-javascript-runtime-reconciliation",
|
||||
name: "REA JavaScript runtime reconciliation",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
predicateType: "rea.javascript-runtime-reconciliation",
|
||||
operation: "reconcile_javascript_runtime",
|
||||
parameters: {
|
||||
static_layers:
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE.static_layers.map(
|
||||
({ analysis }) => ({
|
||||
role: "application",
|
||||
evidence_id: analysis.evidence_id,
|
||||
runtime_mappings: [],
|
||||
}),
|
||||
),
|
||||
runtime_evidence_ids:
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE.runtime_observations.map(
|
||||
({ evidence_id: id }) => id,
|
||||
),
|
||||
},
|
||||
result: reconciliation,
|
||||
confidence: "inferred",
|
||||
authority: "analyst-inference",
|
||||
limitations: reconciliation.limitations,
|
||||
evidenceLinks: reconciliation.evidence_links,
|
||||
},
|
||||
);
|
||||
const TRACE_SEED = {
|
||||
kind: "module" as const,
|
||||
value: "renderer.js",
|
||||
match: "exact" as const,
|
||||
case_sensitive: false,
|
||||
};
|
||||
|
||||
/** Natural trace request with the producer's complete Evidence inline. */
|
||||
export const JAVASCRIPT_FEATURE_TRACE_EXAMPLE = {
|
||||
application: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
seed: TRACE_SEED,
|
||||
direction: "both" as const,
|
||||
};
|
||||
|
||||
/** Natural version comparison with both Evidence records inline. */
|
||||
export const JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE = {
|
||||
left: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
right: reconciliationEvidence,
|
||||
};
|
||||
|
||||
/** Historical source inventory compared with inline application Evidence. */
|
||||
export const SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE = {
|
||||
reference: createHistoricalSourceGraph({
|
||||
schema: "HistoricalSourceGraph",
|
||||
authority: "historical-reference",
|
||||
root_alias: "$REFERENCE_ROOT",
|
||||
inventory_state: "complete",
|
||||
entries: [
|
||||
{
|
||||
path: "src",
|
||||
kind: "directory",
|
||||
classifications: ["source"],
|
||||
tree_state: "enumerated",
|
||||
limitations: [],
|
||||
},
|
||||
{
|
||||
path: "src/main.ts",
|
||||
kind: "file",
|
||||
sha256: "2".repeat(64),
|
||||
size: 128,
|
||||
language: "TypeScript",
|
||||
classifications: ["source"],
|
||||
content_state: "hashed",
|
||||
limitations: [],
|
||||
},
|
||||
],
|
||||
relationships: [],
|
||||
parse_failures: [],
|
||||
exclusions: [],
|
||||
languages: ["TypeScript"],
|
||||
manifests: [],
|
||||
vcs: { kind: "none", head: null, dirty: null },
|
||||
provenance: {
|
||||
importer: "rea",
|
||||
importer_version: "1",
|
||||
caller: "contract-example",
|
||||
},
|
||||
limitations: [],
|
||||
}),
|
||||
application: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
};
|
||||
|
||||
/** Exact static return-shape comparison with both Evidence records inline. */
|
||||
export const JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE = {
|
||||
left: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
right: reconciliationEvidence,
|
||||
left_module_path: "parser.mjs",
|
||||
left_export_name: "default",
|
||||
right_module_path: "parser.mjs",
|
||||
right_export_name: "default",
|
||||
};
|
||||
|
||||
/** Full-Evidence compatibility fixture used by pure domain and adapter tests. */
|
||||
export const JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE = {
|
||||
application: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
seed: TRACE_SEED,
|
||||
direction: "both" as const,
|
||||
};
|
||||
|
||||
/** Full-Evidence compatibility comparison fixture. */
|
||||
export const JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE = {
|
||||
left: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
|
||||
right: reconciliationEvidence,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
javascriptRecoveryInputSchema,
|
||||
javascriptRecoveryResultSchema,
|
||||
} from "../../domain/javascript/javascriptRecovery.js";
|
||||
import { toolContractMetadata } from "../toolEffects.js";
|
||||
import { evidenceResultOf } from "../toolOutputSchemaPrimitives.js";
|
||||
import type { ToolContract } from "../toolContractTypes.js";
|
||||
|
||||
/** Derived script artifacts from optional upstream recovery adapters. */
|
||||
export const JAVASCRIPT_RECOVERY_TOOL_CONTRACTS = [
|
||||
{
|
||||
name: "recover_javascript_sources",
|
||||
...toolContractMetadata("recover_javascript_sources"),
|
||||
kind: "application",
|
||||
description:
|
||||
"Recover readable modules from one local UTF-8 JavaScript script/bundle into an absent directory, using caller-supplied Wakaru 1.13.0 on Linux x64. Returns original/derived digests, extraction byte ranges, emitted source maps, warnings and analysis_input inline. Structural splitting may fall back to one module; original names and runtime equivalence remain unknown. No application code execution. Requires util-linux prlimit; one worker, 1 GiB address-space ceiling, 120-second deadline, 64 MiB input, 128 MiB output, 10000 entries and 8 MiB per diagnostic/report stream.",
|
||||
inputSchema: javascriptRecoveryInputSchema,
|
||||
outputSchema: evidenceResultOf(javascriptRecoveryResultSchema),
|
||||
examples: [
|
||||
{
|
||||
title: "Recover a captured production bundle",
|
||||
input: {
|
||||
path: "/tmp/web-scripts/app.js",
|
||||
output_directory: "/tmp/recovered-app",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly ToolContract[];
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { ToolContract } from "../toolContracts.js";
|
||||
import { toolContractMetadata } from "../toolEffects.js";
|
||||
import { evidenceResultOf } from "../toolOutputSchemas.js";
|
||||
import {
|
||||
javascriptRuntimeObservationSchema,
|
||||
javascriptRuntimeTargetListSchema,
|
||||
listJavaScriptRuntimeTargetsInputSchema,
|
||||
observeJavaScriptRuntimeInputSchema,
|
||||
} from "../../domain/javascript/javascriptRuntimeObservation.js";
|
||||
|
||||
const endpoint = "http://127.0.0.1:9229";
|
||||
|
||||
/** Passive Node/Electron V8 Inspector discovery and observation contracts. */
|
||||
export const JAVASCRIPT_RUNTIME_OBSERVATION_TOOL_CONTRACTS = [
|
||||
{
|
||||
name: "list_javascript_runtime_targets",
|
||||
...toolContractMetadata("list_javascript_runtime_targets"),
|
||||
description:
|
||||
"List every eligible Node/Electron V8 Inspector target from an explicit literal-loopback endpoint. Node discovery file locations that cannot be verified are preserved as unresolved reported URLs; they do not prove filesystem identity. Listing does not attach to targets.",
|
||||
kind: "runtime-provider",
|
||||
inputSchema: listJavaScriptRuntimeTargetsInputSchema,
|
||||
outputSchema: evidenceResultOf(javascriptRuntimeTargetListSchema),
|
||||
examples: [
|
||||
{
|
||||
title: "List Node Inspector targets",
|
||||
input: {
|
||||
inspector_endpoint: endpoint,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "observe_javascript_runtime",
|
||||
...toolContractMetadata("observe_javascript_runtime"),
|
||||
description:
|
||||
"Attach passively to one Node/Electron V8 Inspector target by supplying its loopback Inspector endpoint and target ID. The provider rechecks target presence and attachability; a Node discovery file location may remain unresolved. Loaded script locations are validated independently from Debugger.scriptParsed. Captures script and Runtime execution-context metadata. REA never evaluates, pauses, resumes, reads source, or instruments the target; require/import edges, EventEmitter activity, and Electron IPC remain explicit unknowns. Reconcile the result with static Application Graph Evidence using reconcile_javascript_runtime. The selected endpoint exposes every target it serves to this tool.",
|
||||
kind: "runtime-provider",
|
||||
inputSchema: observeJavaScriptRuntimeInputSchema,
|
||||
outputSchema: evidenceResultOf(javascriptRuntimeObservationSchema),
|
||||
examples: [
|
||||
{
|
||||
title: "Observe one Node runtime",
|
||||
input: {
|
||||
inspector_endpoint: endpoint,
|
||||
target_id: "TARGET_ID_FROM_LIST_JAVASCRIPT_RUNTIME_TARGETS",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly ToolContract[];
|
||||
@@ -0,0 +1,265 @@
|
||||
import { createEvidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
createJavaScriptApplicationNode,
|
||||
} from "../../domain/javascript/javascriptApplicationGraph.js";
|
||||
import { createWebTextArtifact } from "../../domain/webContentArtifact.js";
|
||||
import {
|
||||
createJavaScriptSemanticGraph,
|
||||
createJavaScriptSemanticGraphNode,
|
||||
} from "../../domain/javascript/javascriptSemanticGraph.js";
|
||||
import { JAVASCRIPT_SEMANTIC_RELATION_FAMILIES } from "../../domain/javascript/javascriptSemanticGraphSchemas.js";
|
||||
|
||||
const applicationSha256 = "1".repeat(64);
|
||||
const script = createWebTextArtifact(
|
||||
"export const example = true;\n",
|
||||
"text/javascript",
|
||||
);
|
||||
const inputPath = "/Applications/Example.app/Contents/Resources/app";
|
||||
const scriptPath = `${inputPath}/renderer.js`;
|
||||
|
||||
const completeCoverage = {
|
||||
status: "complete" as const,
|
||||
truncated: false,
|
||||
omitted_count: 0,
|
||||
limits: [],
|
||||
};
|
||||
const graphEvidence = {
|
||||
authority: "artifact-bytes" as const,
|
||||
state: "observed" as const,
|
||||
confidence: "exact" as const,
|
||||
artifact: {
|
||||
available: true as const,
|
||||
artifact_id: `art_${script.sha256}`,
|
||||
sha256: script.sha256,
|
||||
},
|
||||
location: {
|
||||
available: true as const,
|
||||
value: { kind: "artifact-path" as const, path: "renderer.js" },
|
||||
},
|
||||
extractor: {
|
||||
name: "rea-javascript-application",
|
||||
version: "1",
|
||||
operation: "inventory-relevant-file",
|
||||
executable_sha256: null,
|
||||
},
|
||||
coverage: completeCoverage,
|
||||
limitations: [],
|
||||
evidence_ids: [],
|
||||
};
|
||||
const asset = createJavaScriptApplicationNode({
|
||||
kind: "javascript-asset",
|
||||
identity: {
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: script.sha256,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "renderer.js",
|
||||
properties: { path: "renderer.js", bytes: script.bytes },
|
||||
evidence: graphEvidence,
|
||||
},
|
||||
],
|
||||
});
|
||||
const graph = createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
root_node_ids: [asset.node_id],
|
||||
nodes: [asset],
|
||||
edges: [],
|
||||
coverage: completeCoverage,
|
||||
limitations: [],
|
||||
});
|
||||
const semanticNode = createJavaScriptSemanticGraphNode({
|
||||
kind: "module",
|
||||
identity: {
|
||||
artifact_sha256: applicationSha256,
|
||||
module_path: "renderer.js",
|
||||
source_range: null,
|
||||
role_key: "example-module",
|
||||
},
|
||||
function_node_id: null,
|
||||
application_node_ids: [asset.node_id],
|
||||
label: "renderer.js",
|
||||
properties: {},
|
||||
evidence: graphEvidence,
|
||||
});
|
||||
const semanticGraph = createJavaScriptSemanticGraph({
|
||||
schema: "JavaScriptSemanticRelationGraph",
|
||||
root_artifact_sha256: applicationSha256,
|
||||
application_graph_id: graph.graph_id,
|
||||
root_node_ids: [semanticNode.node_id],
|
||||
nodes: [semanticNode],
|
||||
relations: [],
|
||||
fingerprints: [],
|
||||
unknowns: [],
|
||||
coverage: {
|
||||
status: "unknown",
|
||||
truncated: false,
|
||||
omitted_nodes: 0,
|
||||
omitted_relations: 0,
|
||||
limits: [],
|
||||
families: JAVASCRIPT_SEMANTIC_RELATION_FAMILIES.map((family) => ({
|
||||
family,
|
||||
status: "unknown" as const,
|
||||
retained_relations: 0,
|
||||
omitted_relations: 0,
|
||||
unknown_ids: [],
|
||||
})),
|
||||
},
|
||||
limitations: ["Semantic relations are unavailable in this minimal example."],
|
||||
});
|
||||
|
||||
const staticEvidence = createEvidence(
|
||||
{ path: inputPath, sha256: applicationSha256, format: "directory" },
|
||||
{
|
||||
id: "rea-javascript-application",
|
||||
name: "REA JavaScript application analyzer",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
predicateType: "rea.javascript-application-analysis",
|
||||
operation: "analyze_javascript_application",
|
||||
parameters: {},
|
||||
result: {
|
||||
input_path: inputPath,
|
||||
format: "directory",
|
||||
root_artifact_sha256: applicationSha256,
|
||||
inventory_manifest_id: `agm_${"2".repeat(64)}`,
|
||||
inventory_graph_sha256: "3".repeat(64),
|
||||
graph,
|
||||
semantic_graph: semanticGraph,
|
||||
summary: {
|
||||
browser_windows: 0,
|
||||
explicit_web_preferences: 0,
|
||||
preload_entrypoints: 0,
|
||||
context_bridge_apis: 0,
|
||||
exposed_api_members: 0,
|
||||
ipc: {
|
||||
operations: 0,
|
||||
literal_channels: 0,
|
||||
dynamic_channel_operations: 0,
|
||||
renderer_transmissions: 0,
|
||||
renderer_listeners: 0,
|
||||
main_handlers: 0,
|
||||
paired_renderer_transmissions: 0,
|
||||
ambiguous_renderer_transmissions: 0,
|
||||
unpaired_literal_renderer_transmissions: 0,
|
||||
},
|
||||
sender_validation_observations: 0,
|
||||
utility_processes: 0,
|
||||
resolved_utility_entrypoints: 0,
|
||||
native_addon_bindings: 0,
|
||||
resolved_native_addon_bindings: 0,
|
||||
},
|
||||
statistics: {
|
||||
relevant_files: 1,
|
||||
nested_asar_containers: 0,
|
||||
text_bytes_read: script.bytes,
|
||||
invalid_utf8_files: 0,
|
||||
parsed_javascript_files: 1,
|
||||
visited_ast_nodes: 1,
|
||||
findings: 0,
|
||||
modules: 0,
|
||||
parse_failures: 0,
|
||||
truncated_scopes: 0,
|
||||
},
|
||||
limitations: [],
|
||||
},
|
||||
confidence: "derived",
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
);
|
||||
|
||||
/** Minimal valid static application Evidence for graph workflow examples. */
|
||||
export const JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE = staticEvidence;
|
||||
|
||||
const runtimeEvidence = createEvidence(
|
||||
undefined,
|
||||
{
|
||||
id: "rea-cdp-electron",
|
||||
name: "REA Electron file-page CDP observation provider",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
predicateType: "rea.electron-page-inspection",
|
||||
operation: "inspect_electron_page",
|
||||
parameters: {
|
||||
cdp_endpoint: "http://127.0.0.1:9223",
|
||||
target_id: "example-target",
|
||||
include_script_sources: true,
|
||||
},
|
||||
result: {
|
||||
browser: {
|
||||
product: "Electron/example",
|
||||
protocol_version: "1.3",
|
||||
revision: "example",
|
||||
user_agent: "Electron example",
|
||||
js_version: "1",
|
||||
},
|
||||
target: {
|
||||
target_id: "example-target",
|
||||
type: "page",
|
||||
title: "Example",
|
||||
file_path: `${inputPath}/index.html`,
|
||||
attached: false,
|
||||
},
|
||||
capture_window: {
|
||||
started_at: "2026-07-15T00:00:00.000Z",
|
||||
ended_at: "2026-07-15T00:00:00.100Z",
|
||||
observation_ms: 100,
|
||||
},
|
||||
completeness: browserCompleteness(),
|
||||
frames: [],
|
||||
dom: { total_nodes: 0, nodes: [] },
|
||||
scripts: {
|
||||
total: 1,
|
||||
items: [
|
||||
{
|
||||
script_key: `electron_script_${"4".repeat(64)}`,
|
||||
frame_id: null,
|
||||
file_path: scriptPath,
|
||||
cdp_hash: "example",
|
||||
length: script.bytes,
|
||||
is_module: true,
|
||||
language: "JavaScript",
|
||||
source: { included: true, artifact: script },
|
||||
},
|
||||
],
|
||||
},
|
||||
resources: [],
|
||||
workers: [],
|
||||
limitations: ["Example passive capture."],
|
||||
},
|
||||
confidence: "observed",
|
||||
authority: "external-service",
|
||||
},
|
||||
);
|
||||
|
||||
/** Compact valid Evidence pair used by the public reconciliation contract. */
|
||||
export const JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE = {
|
||||
static_layers: [{ analysis: staticEvidence }],
|
||||
runtime_observations: [runtimeEvidence],
|
||||
};
|
||||
|
||||
function browserCompleteness() {
|
||||
return {
|
||||
status: "complete_within_window" as const,
|
||||
conditions: ["complete_within_window" as const],
|
||||
policy_filtered_sections: [],
|
||||
attach_limited_sections: [],
|
||||
truncated_sections: [],
|
||||
unavailable_sections: [],
|
||||
excluded: [],
|
||||
dropped_events: {
|
||||
scripts: 0,
|
||||
network_requests: 0,
|
||||
console_events: 0,
|
||||
websocket_connections: 0,
|
||||
websocket_frames: 0,
|
||||
webmcp_tools: 0,
|
||||
timeline_events: 0,
|
||||
total: 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user