rea-agents 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -18
- package/dist/application/AndroidApplicationService.js +17 -0
- package/dist/application/AppleApplicationService.js +17 -0
- package/dist/application/ApplicationWorkflowEvidenceResolver.js +162 -0
- package/dist/application/BinarySession.js +9 -2
- package/dist/application/BinarySessionStatus.js +39 -1
- package/dist/application/CapabilityInventory.js +15 -0
- package/dist/application/ClientRegistrationStatus.js +11 -4
- package/dist/application/CommandShimReplay.js +6 -3
- package/dist/application/CompositeProvider.js +5 -2
- package/dist/application/DirectAnalysis.js +1 -20
- package/dist/application/DirectAnalysisStatus.js +83 -0
- package/dist/application/Doctor.js +34 -25
- package/dist/application/DoctorDiagnostics.js +1 -4
- package/dist/application/DoctorProjection.js +43 -0
- package/dist/application/DoctorScope.js +102 -0
- package/dist/application/EvidenceReferenceResolver.js +26 -0
- package/dist/application/InventoryProjectionEvidence.js +41 -0
- package/dist/application/InvestigationProviders.js +12 -0
- package/dist/application/JavaScriptApplicationEvidence.js +1 -1
- package/dist/application/JavaScriptApplicationEvidenceGraph.js +10 -1
- package/dist/application/JavaScriptApplicationService.js +3 -2
- package/dist/application/JavaScriptApplicationWorkflowEvidence.js +26 -0
- package/dist/application/JavaScriptApplicationWorkflowService.js +49 -1
- package/dist/application/JavaScriptArtifactReconstruction.js +7 -0
- package/dist/application/JavaScriptModuleRelationships.js +25 -1
- package/dist/application/JavaScriptReturnShapeProjection.js +111 -0
- package/dist/application/JavaScriptSemanticGraphBuilder.js +294 -0
- package/dist/application/JavaScriptSemanticGraphConstruction.js +144 -0
- package/dist/application/JavaScriptSemanticGraphEvidence.js +86 -0
- package/dist/application/JavaScriptSemanticGraphFlowProjection.js +72 -0
- package/dist/application/JavaScriptSemanticGraphProjection.js +33 -0
- package/dist/application/JavaScriptSemanticTraceService.js +45 -0
- package/dist/application/LoopbackReplay.js +277 -133
- package/dist/application/LoopbackReplayRecorder.js +101 -0
- package/dist/application/PermissionAuthority.js +7 -3
- package/dist/application/ProcessCaptureJournal.js +95 -0
- package/dist/application/ProcessCaptureLifecycle.js +24 -13
- package/dist/application/ProcessCheckpoints.js +30 -4
- package/dist/application/ProcessCli.js +26 -4
- package/dist/application/ProcessHarness.js +20 -50
- package/dist/application/ProcessNormalization.js +3 -2
- package/dist/application/ProcessPairedExperiment.js +72 -0
- package/dist/application/ProcessReactiveCoordinator.js +218 -0
- package/dist/application/ProcessReactiveEffects.js +133 -0
- package/dist/application/ProcessReactiveObservations.js +20 -0
- package/dist/application/ProcessSampling.js +2 -0
- package/dist/application/SessionProviderRouter.js +7 -6
- package/dist/application/Setup.js +14 -13
- package/dist/application/SetupClientConfiguration.js +10 -6
- package/dist/application/SetupPlan.js +4 -3
- package/dist/application/SetupRegistrationEnvironment.js +12 -0
- package/dist/application/SetupSkill.js +44 -40
- package/dist/application/TerminalRenderer.js +3 -1
- package/dist/application/Uninstall.js +7 -1
- package/dist/application/Upgrade.js +16 -1
- package/dist/browser/CdpEndpoint.js +37 -4
- package/dist/catalogIdentity.js +16 -7
- package/dist/cli/coreAnalysisCommands.js +34 -2
- package/dist/cli/javascriptApplicationAnalysis.js +19 -0
- package/dist/cli/setupCommands.js +84 -30
- package/dist/cli/utilityCommands.js +10 -2
- package/dist/cliApplicationCommands.js +79 -16
- package/dist/cliCommandNames.js +3 -0
- package/dist/cliElectronCommands.js +23 -33
- package/dist/cliObservationOptions.js +1 -1
- package/dist/cliOutput.js +56 -0
- package/dist/cliProcessCommands.js +32 -1
- package/dist/cliSetup.js +55 -29
- package/dist/contracts/applicationToolContracts.js +54 -7
- package/dist/contracts/applicationWorkflowInputContracts.js +119 -0
- package/dist/contracts/electronToolContracts.js +73 -4
- package/dist/contracts/javascriptApplicationWorkflowExamples.js +32 -9
- package/dist/contracts/managedToolContracts.js +7 -2
- package/dist/contracts/processCaptureExample.js +1 -0
- package/dist/contracts/replayMachineExample.js +37 -0
- package/dist/contracts/sessionStatusContract.js +26 -0
- package/dist/contracts/toolContractExamples.js +2 -0
- package/dist/contracts/toolContractTypes.js +12 -1
- package/dist/contracts/toolContracts.js +8 -11
- package/dist/contracts/toolEffects.js +3 -0
- package/dist/contracts/toolOutputSchemaGroups.js +53 -9
- package/dist/contracts/toolOutputSchemaPrimitives.js +73 -32
- package/dist/doctorRuntime.js +41 -0
- package/dist/domain/analysisErrorPresentation.js +5 -3
- package/dist/domain/analysisErrorProjection.js +7 -1
- package/dist/domain/androidApplication.js +206 -0
- package/dist/domain/appleApplication.js +221 -0
- package/dist/domain/boundedCartesianProjection.js +15 -0
- package/dist/domain/changedBehavior.js +5 -4
- package/dist/domain/completionLedgerGeneration.js +190 -0
- package/dist/domain/errors.js +4 -2
- package/dist/domain/evidenceCompletionLedger.js +113 -0
- package/dist/domain/hopperStartupFailure.js +9 -0
- package/dist/domain/javascriptApplicationAnalysis.js +44 -2
- package/dist/domain/javascriptExportShapeComparison.js +145 -0
- package/dist/domain/javascriptExportShapeComparisonIdentity.js +11 -0
- package/dist/domain/javascriptExportShapeComparisonSchemas.js +277 -0
- package/dist/domain/javascriptExportShapeSelection.js +132 -0
- package/dist/domain/javascriptExportShapeVariants.js +272 -0
- package/dist/domain/javascriptRuntimeReconciliationParsing.js +2 -2
- package/dist/domain/javascriptSemanticAnalysis.js +17 -36
- package/dist/domain/javascriptSemanticCallResolution.js +129 -0
- package/dist/domain/javascriptSemanticCalls.js +269 -0
- package/dist/domain/javascriptSemanticGraph.js +356 -0
- package/dist/domain/javascriptSemanticGraphSchemas.js +329 -0
- package/dist/domain/javascriptSemanticGraphSerialization.js +23 -0
- package/dist/domain/javascriptSemanticIr.js +14 -1
- package/dist/domain/javascriptSemanticPrimitives.js +36 -0
- package/dist/domain/javascriptSemanticProjection.js +36 -4
- package/dist/domain/javascriptSemanticProvenance.js +29 -0
- package/dist/domain/javascriptSemanticQuery.js +294 -0
- package/dist/domain/javascriptSemanticQueryAssessment.js +74 -0
- package/dist/domain/javascriptSemanticQueryIdentity.js +86 -0
- package/dist/domain/javascriptSemanticQueryRelations.js +15 -0
- package/dist/domain/javascriptSemanticQuerySchemas.js +188 -0
- package/dist/domain/javascriptSemanticReturns.js +187 -0
- package/dist/domain/javascriptSemanticState.js +32 -0
- package/dist/domain/javascriptSemanticTraceSchemas.js +14 -0
- package/dist/domain/javascriptSemanticValues.js +54 -70
- package/dist/domain/processCapture.js +36 -0
- package/dist/domain/processCaptureValidation.js +101 -12
- package/dist/domain/processComparison.js +96 -24
- package/dist/domain/processObservation.js +153 -0
- package/dist/domain/processPairedExperiment.js +128 -0
- package/dist/domain/processReactiveCheckpointDataflow.js +32 -0
- package/dist/domain/processReactiveMatching.js +210 -0
- package/dist/domain/processReactiveRuntime.js +109 -0
- package/dist/domain/processReactiveScenario.js +361 -0
- package/dist/domain/processReactiveScenarioPreflight.js +120 -0
- package/dist/domain/processReactiveTransition.js +159 -0
- package/dist/domain/processScenario.js +12 -0
- package/dist/domain/processTraceComparison.js +43 -0
- package/dist/domain/processTraceDimensionProjection.js +50 -0
- package/dist/domain/processTraceEvaluation.js +312 -0
- package/dist/domain/processTraceSpecification.js +373 -0
- package/dist/domain/reconstructionVerification.js +5 -4
- package/dist/domain/replayMachine.js +332 -0
- package/dist/domain/replayMachineRun.js +216 -0
- package/dist/domain/replayMachineRuntime.js +294 -0
- package/dist/domain/runtimeIdentification.js +210 -0
- package/dist/domain/staticRuntimeCorrelation.js +4 -2
- package/dist/evaluation/CodexAgentEval.js +156 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraClient.js +13 -2
- package/dist/ghidra/GhidraDiagnostics.js +1 -0
- package/dist/ghidra/GhidraLauncher.js +7 -3
- package/dist/ghidra/GhidraProvider.js +8 -1
- package/dist/hopper/BridgeLauncher.js +56 -14
- package/dist/hopper/HopperClient.js +23 -10
- package/dist/hopper/HopperDiagnostics.js +14 -0
- package/dist/hopper/HopperProcessDiagnostic.js +14 -0
- package/dist/hopper/HopperProvider.js +8 -1
- package/dist/hopper/LinuxPrivateDisplayDiagnostic.js +72 -0
- package/dist/hopper/LinuxPrivateDisplayProbe.js +217 -0
- package/dist/identity.js +2 -1
- package/dist/main/transport.js +2 -0
- package/dist/mcpDoctor.js +310 -0
- package/dist/process/ProcessOwnership.js +200 -53
- package/dist/process/ProviderRunLineage.js +21 -0
- package/dist/server/createServer.js +8 -2
- package/dist/server/javascriptApplicationResult.js +106 -0
- package/dist/server/registerApplicationTools/characterization.js +3 -3
- package/dist/server/registerApplicationTools/compareExportShapes.js +37 -0
- package/dist/server/registerApplicationTools/compareVersions.js +12 -6
- package/dist/server/registerApplicationTools/controlledReplay.js +2 -2
- package/dist/server/registerApplicationTools/coverage.js +3 -3
- package/dist/server/registerApplicationTools/helpers.js +37 -25
- package/dist/server/registerApplicationTools/traceFeature.js +9 -5
- package/dist/server/registerApplicationTools/traceSemantics.js +30 -0
- package/dist/server/registerApplicationTools.js +4 -0
- package/dist/server/registerElectronTools.js +19 -5
- package/dist/server/registerEvidenceResources.js +7 -1
- package/dist/server/registerJavaScriptApplicationGraphResource.js +69 -0
- package/dist/server/registerManagedTools.js +18 -1
- package/dist/server/registerProcessComparisonTool.js +17 -7
- package/dist/server/registerReplayMachineTool.js +20 -0
- package/dist/server/registerSessionStatusTool.js +95 -25
- package/dist/server/registerSessionTools.js +12 -7
- package/dist/server/sessionAvailabilityPolicy.js +2 -1
- package/dist/server/toolResult.js +10 -4
- package/dist/serverIdentity.js +19 -0
- package/package.json +62 -29
- package/scripts/hopper-demo-x11.py +459 -61
- package/scripts/prepack.mjs +55 -0
- package/scripts/prepare.mjs +28 -0
- package/scripts/rea.mjs +26 -5
- package/skills/reverse-engineer-anything/SKILL.md +69 -228
- package/skills/reverse-engineer-anything/references/controlled-replay.md +12 -0
- package/skills/reverse-engineer-anything/references/evidence-workflows.md +33 -0
- package/skills/reverse-engineer-anything/references/javascript-applications.md +35 -0
- package/skills/reverse-engineer-anything/references/native-and-artifacts.md +36 -0
- package/skills/reverse-engineer-anything/references/runtime-observation.md +24 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const INFERENCE_LIMITATION = "This relationship is a bounded static candidate; it does not prove runtime execution or causal flow.";
|
|
2
|
+
/** Exact artifact-backed syntax evidence for one semantic graph node. */
|
|
3
|
+
export const observedSemanticEvidence = (file, location) => ({
|
|
4
|
+
authority: "ast-static-analysis",
|
|
5
|
+
state: "observed",
|
|
6
|
+
confidence: "exact",
|
|
7
|
+
artifact: {
|
|
8
|
+
available: true,
|
|
9
|
+
artifact_id: `art_${file.sha256}`,
|
|
10
|
+
sha256: file.sha256,
|
|
11
|
+
},
|
|
12
|
+
location: location === null
|
|
13
|
+
? { available: true, value: { kind: "artifact-path", path: file.path } }
|
|
14
|
+
: {
|
|
15
|
+
available: true,
|
|
16
|
+
value: { kind: "source-range", source: file.path, ...location },
|
|
17
|
+
},
|
|
18
|
+
extractor: {
|
|
19
|
+
name: "rea-javascript-semantic-analysis",
|
|
20
|
+
version: "1",
|
|
21
|
+
operation: "analyze_javascript_application",
|
|
22
|
+
executable_sha256: null,
|
|
23
|
+
},
|
|
24
|
+
coverage: {
|
|
25
|
+
status: "complete",
|
|
26
|
+
truncated: false,
|
|
27
|
+
omitted_count: 0,
|
|
28
|
+
limits: [],
|
|
29
|
+
},
|
|
30
|
+
limitations: [],
|
|
31
|
+
evidence_ids: [],
|
|
32
|
+
});
|
|
33
|
+
/** Conservative static relationship evidence derived from one syntax node. */
|
|
34
|
+
export const inferredSemanticEvidence = (source) => ({
|
|
35
|
+
...source.evidence,
|
|
36
|
+
authority: "static-relationship-inference",
|
|
37
|
+
state: "inferred",
|
|
38
|
+
confidence: "high",
|
|
39
|
+
limitations: [INFERENCE_LIMITATION],
|
|
40
|
+
});
|
|
41
|
+
/** Static relationship evidence anchored at the syntax that proves the link. */
|
|
42
|
+
export const inferredSemanticEvidenceAt = (file, location) => ({
|
|
43
|
+
...observedSemanticEvidence(file, location),
|
|
44
|
+
authority: "static-relationship-inference",
|
|
45
|
+
state: "inferred",
|
|
46
|
+
confidence: "high",
|
|
47
|
+
limitations: [INFERENCE_LIMITATION],
|
|
48
|
+
});
|
|
49
|
+
/** Explicit absence of semantic syntax for an artifact-level fallback root. */
|
|
50
|
+
export const unavailableSemanticRootEvidence = (rootArtifactSha256) => ({
|
|
51
|
+
authority: "unknown",
|
|
52
|
+
state: "unavailable",
|
|
53
|
+
confidence: "unknown",
|
|
54
|
+
artifact: {
|
|
55
|
+
available: true,
|
|
56
|
+
artifact_id: `art_${rootArtifactSha256}`,
|
|
57
|
+
sha256: rootArtifactSha256,
|
|
58
|
+
},
|
|
59
|
+
location: {
|
|
60
|
+
available: false,
|
|
61
|
+
reason: "not-observed",
|
|
62
|
+
detail: "No admitted JavaScript source produced semantic IR.",
|
|
63
|
+
},
|
|
64
|
+
extractor: {
|
|
65
|
+
name: "rea-javascript-semantic-analysis",
|
|
66
|
+
version: "1",
|
|
67
|
+
operation: "analyze_javascript_application",
|
|
68
|
+
executable_sha256: null,
|
|
69
|
+
},
|
|
70
|
+
coverage: {
|
|
71
|
+
status: "unavailable",
|
|
72
|
+
truncated: false,
|
|
73
|
+
omitted_count: null,
|
|
74
|
+
limits: [],
|
|
75
|
+
},
|
|
76
|
+
limitations: ["This synthetic graph root does not claim a source location."],
|
|
77
|
+
evidence_ids: [],
|
|
78
|
+
});
|
|
79
|
+
/** Explicit unknown evidence at one unresolved dynamic syntax location. */
|
|
80
|
+
export const unknownSemanticEvidence = (file, location) => ({
|
|
81
|
+
...observedSemanticEvidence(file, location),
|
|
82
|
+
authority: "unknown",
|
|
83
|
+
state: "unknown",
|
|
84
|
+
confidence: "unknown",
|
|
85
|
+
limitations: ["Dynamic syntax prevents an exact static relationship."],
|
|
86
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createJavaScriptSemanticGraphUnknown } from "../domain/javascriptSemanticGraph.js";
|
|
2
|
+
import { addSemanticGraphRelation, addSemanticGraphUnknown, } from "./JavaScriptSemanticGraphConstruction.js";
|
|
3
|
+
import { inferredSemanticEvidenceAt, unknownSemanticEvidence, } from "./JavaScriptSemanticGraphEvidence.js";
|
|
4
|
+
import { semanticNodesWithinRange } from "./JavaScriptSemanticGraphProjection.js";
|
|
5
|
+
/** Link direct return expressions to their retained semantic references. */
|
|
6
|
+
export const projectSemanticReturnValues = (context) => {
|
|
7
|
+
for (const callable of context.ir.callables)
|
|
8
|
+
for (const site of callable.returnSites) {
|
|
9
|
+
const returnNode = context.returnSiteNodes.get(site.returnSiteId);
|
|
10
|
+
const references = semanticNodesWithinRange(context.referenceNodes, site.location);
|
|
11
|
+
for (const reference of references)
|
|
12
|
+
addSemanticGraphRelation(context.state, {
|
|
13
|
+
source: reference,
|
|
14
|
+
target: returnNode,
|
|
15
|
+
relation: "aliases",
|
|
16
|
+
resolution: site.identityReferenceLocation !== null &&
|
|
17
|
+
rangesEqual(reference.identity.source_range, site.identityReferenceLocation)
|
|
18
|
+
? "resolved"
|
|
19
|
+
: "candidate",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const rangesEqual = (left, right) => left !== null &&
|
|
24
|
+
right !== null &&
|
|
25
|
+
left.start.line === right.start.line &&
|
|
26
|
+
left.start.column === right.start.column &&
|
|
27
|
+
left.end.line === right.end.line &&
|
|
28
|
+
left.end.column === right.end.column;
|
|
29
|
+
/** Link each captured binding to the callable at the exact reference site. */
|
|
30
|
+
export const projectSemanticClosureCaptures = (context) => {
|
|
31
|
+
for (const capture of context.ir.closureCaptures)
|
|
32
|
+
addSemanticGraphRelation(context.state, {
|
|
33
|
+
source: context.bindingNodes.get(capture.bindingId),
|
|
34
|
+
target: context.callableNodes.get(capture.callableId),
|
|
35
|
+
relation: "captures",
|
|
36
|
+
resolution: "resolved",
|
|
37
|
+
evidence: inferredSemanticEvidenceAt(context.file, capture.referenceLocation),
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/** Retain bounded unresolved dynamic-call and dynamic-property frontiers. */
|
|
41
|
+
export const projectSemanticFrontiers = (context) => {
|
|
42
|
+
for (const frontier of context.ir.frontiers) {
|
|
43
|
+
const unknown = createJavaScriptSemanticGraphUnknown({
|
|
44
|
+
node_id: frontier.callableId === null
|
|
45
|
+
? context.moduleNode.node_id
|
|
46
|
+
: (context.callableNodes.get(frontier.callableId)?.node_id ??
|
|
47
|
+
context.moduleNode.node_id),
|
|
48
|
+
family: frontier.kind === "dynamic-call" ? "call-flow" : "object-flow",
|
|
49
|
+
relation_kinds: frontier.kind === "dynamic-call"
|
|
50
|
+
? ["calls"]
|
|
51
|
+
: ["reads-property", "writes-property"],
|
|
52
|
+
reason: frontier.kind,
|
|
53
|
+
detail: frontier.reason,
|
|
54
|
+
candidate_node_ids: [],
|
|
55
|
+
evidence: unknownSemanticEvidence(context.file, frontier.location),
|
|
56
|
+
});
|
|
57
|
+
addSemanticGraphUnknown(context.state, unknown);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/** Publish exact semantic analyzer limits reached by any admitted source file. */
|
|
61
|
+
export const semanticRecoveryLimits = (analysis) => {
|
|
62
|
+
const limits = new Map();
|
|
63
|
+
for (const { semantic } of analysis.files) {
|
|
64
|
+
if (semantic === null)
|
|
65
|
+
continue;
|
|
66
|
+
for (const name of semantic.ir.coverage.limitsReached)
|
|
67
|
+
limits.set(`semantic.${name}`, semantic.limits[name]);
|
|
68
|
+
}
|
|
69
|
+
return [...limits]
|
|
70
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
71
|
+
.map(([name, value]) => ({ name, value, unit: "items" }));
|
|
72
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { compareCodePoints } from "../domain/javascriptApplicationGraph.js";
|
|
2
|
+
import { JAVASCRIPT_SEMANTIC_RELATION_FAMILIES } from "../domain/javascriptSemanticGraphSchemas.js";
|
|
3
|
+
/** Find the innermost callable that contains one exact source range. */
|
|
4
|
+
export const owningSemanticCallableNode = (location, ir, nodes) => {
|
|
5
|
+
if (location === null)
|
|
6
|
+
return undefined;
|
|
7
|
+
return ir.callables
|
|
8
|
+
.filter((callable) => contains(callable.location, location))
|
|
9
|
+
.sort((left, right) => compareCodePoints(positionKey(right.location), positionKey(left.location)))
|
|
10
|
+
.map(({ callableId }) => nodes.get(callableId))
|
|
11
|
+
.find((node) => node !== undefined);
|
|
12
|
+
};
|
|
13
|
+
/** Find retained semantic nodes whose exact ranges are within one expression. */
|
|
14
|
+
export const semanticNodesWithinRange = (nodes, range) => nodes.filter((node) => node.identity.source_range !== null &&
|
|
15
|
+
contains(range, node.identity.source_range));
|
|
16
|
+
/** Report extractor support without treating missing families as absence. */
|
|
17
|
+
export const semanticFamilyStatus = (family, analysis, truncated) => {
|
|
18
|
+
if (!["call-flow", "closure", "data-flow", "object-flow"].includes(family))
|
|
19
|
+
return "unsupported";
|
|
20
|
+
if (truncated)
|
|
21
|
+
return "unknown";
|
|
22
|
+
return analysis.truncated_scopes === 0 ? "partial" : "unknown";
|
|
23
|
+
};
|
|
24
|
+
/** Compare two exact semantic source ranges. */
|
|
25
|
+
export const semanticRangesEqual = (left, right) => left !== null &&
|
|
26
|
+
left.start.line === right.start.line &&
|
|
27
|
+
left.start.column === right.start.column &&
|
|
28
|
+
left.end.line === right.end.line &&
|
|
29
|
+
left.end.column === right.end.column;
|
|
30
|
+
const contains = (outer, inner) => pointCompare(outer.start, inner.start) <= 0 &&
|
|
31
|
+
pointCompare(outer.end, inner.end) >= 0;
|
|
32
|
+
const pointCompare = (left, right) => left.line - right.line || left.column - right.column;
|
|
33
|
+
const positionKey = (range) => `${String(range.start.line).padStart(12, "0")}:${String(range.start.column).padStart(12, "0")}`;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AnalysisInputError, AnalysisProtocolError, } from "../domain/errors.js";
|
|
3
|
+
import { jsonValueSchema } from "../domain/jsonValue.js";
|
|
4
|
+
import { queryJavaScriptSemanticGraph } from "../domain/javascriptSemanticQuery.js";
|
|
5
|
+
import { JavaScriptSemanticQueryCursorError } from "../domain/javascriptSemanticQueryIdentity.js";
|
|
6
|
+
import { javaScriptSemanticTraceResultSchema, traceJavaScriptSemanticsInputSchema, } from "../domain/javascriptSemanticTraceSchemas.js";
|
|
7
|
+
import { err, ok } from "../domain/result.js";
|
|
8
|
+
import { parseApplicationGraphEvidence } from "./JavaScriptApplicationEvidenceGraph.js";
|
|
9
|
+
import { createJavaScriptSemanticTraceEvidence } from "./JavaScriptApplicationWorkflowEvidence.js";
|
|
10
|
+
const OPERATION = "trace_javascript_semantics";
|
|
11
|
+
/** Trace semantic relations from input already parsed by a trusted adapter. */
|
|
12
|
+
export const traceJavaScriptSemanticsEvidenceValidated = (input) => {
|
|
13
|
+
try {
|
|
14
|
+
const source = parseApplicationGraphEvidence(input.application);
|
|
15
|
+
if (source.semanticGraph === null)
|
|
16
|
+
return err(new AnalysisInputError(OPERATION, undefined, [
|
|
17
|
+
{
|
|
18
|
+
path: ["application"],
|
|
19
|
+
reason: "invalid_value",
|
|
20
|
+
expected: "analyze_javascript_application v2 Evidence; reanalyze the artifact with the current REA version",
|
|
21
|
+
},
|
|
22
|
+
]));
|
|
23
|
+
const query = queryJavaScriptSemanticGraph(source.semanticGraph, input.query);
|
|
24
|
+
const result = javaScriptSemanticTraceResultSchema.parse({
|
|
25
|
+
...query,
|
|
26
|
+
source_evidence_id: source.evidence.evidence_id,
|
|
27
|
+
evidence_links: [source.evidence.evidence_id],
|
|
28
|
+
});
|
|
29
|
+
return ok(createJavaScriptSemanticTraceEvidence({
|
|
30
|
+
application_evidence_id: source.evidence.evidence_id,
|
|
31
|
+
query: jsonValueSchema.parse(input.query),
|
|
32
|
+
}, result));
|
|
33
|
+
}
|
|
34
|
+
catch (cause) {
|
|
35
|
+
if (cause instanceof JavaScriptSemanticQueryCursorError)
|
|
36
|
+
return err(new AnalysisInputError(OPERATION, undefined, [
|
|
37
|
+
{
|
|
38
|
+
path: ["query", "cursor"],
|
|
39
|
+
reason: "invalid_value",
|
|
40
|
+
expected: "a cursor returned by the same graph, query, and limits",
|
|
41
|
+
},
|
|
42
|
+
]));
|
|
43
|
+
return err(new AnalysisProtocolError("JavaScript semantic trace failed", { cause }));
|
|
44
|
+
}
|
|
45
|
+
};
|