rea-agents 2.2.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.
Files changed (165) hide show
  1. package/README.md +56 -9
  2. package/dist/application/ApplicationWorkflowEvidenceResolver.js +162 -0
  3. package/dist/application/BinarySession.js +9 -2
  4. package/dist/application/BinarySessionStatus.js +39 -1
  5. package/dist/application/CapabilityInventory.js +15 -0
  6. package/dist/application/CommandShimReplay.js +6 -3
  7. package/dist/application/CompositeProvider.js +5 -2
  8. package/dist/application/DirectAnalysis.js +1 -20
  9. package/dist/application/DirectAnalysisStatus.js +83 -0
  10. package/dist/application/Doctor.js +34 -25
  11. package/dist/application/DoctorDiagnostics.js +1 -4
  12. package/dist/application/DoctorProjection.js +43 -0
  13. package/dist/application/DoctorScope.js +102 -0
  14. package/dist/application/EvidenceReferenceResolver.js +26 -0
  15. package/dist/application/JavaScriptApplicationEvidence.js +1 -1
  16. package/dist/application/JavaScriptApplicationEvidenceGraph.js +10 -1
  17. package/dist/application/JavaScriptApplicationService.js +3 -2
  18. package/dist/application/JavaScriptApplicationWorkflowEvidence.js +26 -0
  19. package/dist/application/JavaScriptApplicationWorkflowService.js +49 -1
  20. package/dist/application/JavaScriptArtifactReconstruction.js +7 -0
  21. package/dist/application/JavaScriptModuleRelationships.js +25 -1
  22. package/dist/application/JavaScriptReturnShapeProjection.js +111 -0
  23. package/dist/application/JavaScriptSemanticGraphBuilder.js +294 -0
  24. package/dist/application/JavaScriptSemanticGraphConstruction.js +144 -0
  25. package/dist/application/JavaScriptSemanticGraphEvidence.js +86 -0
  26. package/dist/application/JavaScriptSemanticGraphFlowProjection.js +72 -0
  27. package/dist/application/JavaScriptSemanticGraphProjection.js +33 -0
  28. package/dist/application/JavaScriptSemanticTraceService.js +45 -0
  29. package/dist/application/LoopbackReplay.js +277 -133
  30. package/dist/application/LoopbackReplayRecorder.js +101 -0
  31. package/dist/application/PermissionAuthority.js +7 -3
  32. package/dist/application/ProcessCaptureJournal.js +95 -0
  33. package/dist/application/ProcessCaptureLifecycle.js +24 -13
  34. package/dist/application/ProcessCheckpoints.js +30 -4
  35. package/dist/application/ProcessCli.js +26 -4
  36. package/dist/application/ProcessHarness.js +20 -50
  37. package/dist/application/ProcessNormalization.js +3 -2
  38. package/dist/application/ProcessReactiveCoordinator.js +218 -0
  39. package/dist/application/ProcessReactiveEffects.js +133 -0
  40. package/dist/application/ProcessReactiveObservations.js +20 -0
  41. package/dist/application/ProcessSampling.js +2 -0
  42. package/dist/application/SessionProviderRouter.js +7 -6
  43. package/dist/application/Setup.js +11 -10
  44. package/dist/application/SetupPlan.js +1 -1
  45. package/dist/application/SetupRegistrationEnvironment.js +12 -0
  46. package/dist/application/TerminalRenderer.js +3 -1
  47. package/dist/browser/CdpEndpoint.js +37 -4
  48. package/dist/catalogIdentity.js +16 -7
  49. package/dist/cli/coreAnalysisCommands.js +34 -2
  50. package/dist/cli/javascriptApplicationAnalysis.js +19 -0
  51. package/dist/cli/setupCommands.js +81 -32
  52. package/dist/cli/utilityCommands.js +10 -2
  53. package/dist/cliApplicationCommands.js +79 -16
  54. package/dist/cliCommandNames.js +3 -0
  55. package/dist/cliElectronCommands.js +23 -33
  56. package/dist/cliObservationOptions.js +1 -1
  57. package/dist/cliOutput.js +56 -0
  58. package/dist/cliProcessCommands.js +32 -1
  59. package/dist/cliSetup.js +30 -21
  60. package/dist/contracts/applicationToolContracts.js +54 -7
  61. package/dist/contracts/applicationWorkflowInputContracts.js +119 -0
  62. package/dist/contracts/electronToolContracts.js +53 -32
  63. package/dist/contracts/javascriptApplicationWorkflowExamples.js +32 -9
  64. package/dist/contracts/processCaptureExample.js +1 -0
  65. package/dist/contracts/replayMachineExample.js +37 -0
  66. package/dist/contracts/toolContractExamples.js +2 -0
  67. package/dist/contracts/toolContracts.js +5 -1
  68. package/dist/contracts/toolEffects.js +3 -0
  69. package/dist/contracts/toolOutputSchemaGroups.js +2 -0
  70. package/dist/contracts/toolOutputSchemaPrimitives.js +40 -0
  71. package/dist/doctorRuntime.js +41 -0
  72. package/dist/domain/analysisErrorPresentation.js +5 -3
  73. package/dist/domain/analysisErrorProjection.js +7 -1
  74. package/dist/domain/changedBehavior.js +5 -4
  75. package/dist/domain/completionLedgerGeneration.js +190 -0
  76. package/dist/domain/errors.js +4 -2
  77. package/dist/domain/evidenceCompletionLedger.js +113 -0
  78. package/dist/domain/hopperStartupFailure.js +9 -0
  79. package/dist/domain/javascriptApplicationAnalysis.js +44 -2
  80. package/dist/domain/javascriptExportShapeComparison.js +145 -0
  81. package/dist/domain/javascriptExportShapeComparisonIdentity.js +11 -0
  82. package/dist/domain/javascriptExportShapeComparisonSchemas.js +277 -0
  83. package/dist/domain/javascriptExportShapeSelection.js +132 -0
  84. package/dist/domain/javascriptExportShapeVariants.js +272 -0
  85. package/dist/domain/javascriptRuntimeReconciliationParsing.js +2 -2
  86. package/dist/domain/javascriptSemanticAnalysis.js +17 -36
  87. package/dist/domain/javascriptSemanticCallResolution.js +129 -0
  88. package/dist/domain/javascriptSemanticCalls.js +269 -0
  89. package/dist/domain/javascriptSemanticGraph.js +356 -0
  90. package/dist/domain/javascriptSemanticGraphSchemas.js +329 -0
  91. package/dist/domain/javascriptSemanticGraphSerialization.js +23 -0
  92. package/dist/domain/javascriptSemanticIr.js +14 -1
  93. package/dist/domain/javascriptSemanticPrimitives.js +36 -0
  94. package/dist/domain/javascriptSemanticProjection.js +36 -4
  95. package/dist/domain/javascriptSemanticProvenance.js +29 -0
  96. package/dist/domain/javascriptSemanticQuery.js +294 -0
  97. package/dist/domain/javascriptSemanticQueryAssessment.js +74 -0
  98. package/dist/domain/javascriptSemanticQueryIdentity.js +86 -0
  99. package/dist/domain/javascriptSemanticQueryRelations.js +15 -0
  100. package/dist/domain/javascriptSemanticQuerySchemas.js +188 -0
  101. package/dist/domain/javascriptSemanticReturns.js +187 -0
  102. package/dist/domain/javascriptSemanticState.js +32 -0
  103. package/dist/domain/javascriptSemanticTraceSchemas.js +14 -0
  104. package/dist/domain/javascriptSemanticValues.js +54 -70
  105. package/dist/domain/processCapture.js +36 -0
  106. package/dist/domain/processCaptureValidation.js +101 -12
  107. package/dist/domain/processComparison.js +78 -25
  108. package/dist/domain/processObservation.js +153 -0
  109. package/dist/domain/processReactiveCheckpointDataflow.js +32 -0
  110. package/dist/domain/processReactiveMatching.js +210 -0
  111. package/dist/domain/processReactiveRuntime.js +109 -0
  112. package/dist/domain/processReactiveScenario.js +361 -0
  113. package/dist/domain/processReactiveScenarioPreflight.js +120 -0
  114. package/dist/domain/processReactiveTransition.js +159 -0
  115. package/dist/domain/processScenario.js +12 -0
  116. package/dist/domain/processTraceComparison.js +43 -0
  117. package/dist/domain/processTraceDimensionProjection.js +50 -0
  118. package/dist/domain/processTraceEvaluation.js +312 -0
  119. package/dist/domain/processTraceSpecification.js +373 -0
  120. package/dist/domain/reconstructionVerification.js +5 -4
  121. package/dist/domain/replayMachine.js +18 -2
  122. package/dist/domain/replayMachineRun.js +216 -0
  123. package/dist/domain/replayMachineRuntime.js +88 -9
  124. package/dist/domain/staticRuntimeCorrelation.js +4 -2
  125. package/dist/evaluation/CodexAgentEval.js +24 -0
  126. package/dist/generatedPackageMetadata.js +1 -1
  127. package/dist/ghidra/GhidraClient.js +13 -2
  128. package/dist/ghidra/GhidraDiagnostics.js +1 -0
  129. package/dist/ghidra/GhidraLauncher.js +7 -3
  130. package/dist/ghidra/GhidraProvider.js +8 -1
  131. package/dist/hopper/BridgeLauncher.js +56 -14
  132. package/dist/hopper/HopperClient.js +23 -10
  133. package/dist/hopper/HopperDiagnostics.js +14 -0
  134. package/dist/hopper/HopperProcessDiagnostic.js +14 -0
  135. package/dist/hopper/HopperProvider.js +8 -1
  136. package/dist/hopper/LinuxPrivateDisplayDiagnostic.js +72 -0
  137. package/dist/hopper/LinuxPrivateDisplayProbe.js +217 -0
  138. package/dist/main/transport.js +2 -0
  139. package/dist/mcpDoctor.js +310 -0
  140. package/dist/process/ProcessOwnership.js +200 -53
  141. package/dist/process/ProviderRunLineage.js +21 -0
  142. package/dist/server/createServer.js +4 -1
  143. package/dist/server/javascriptApplicationResult.js +22 -1
  144. package/dist/server/registerApplicationTools/characterization.js +3 -3
  145. package/dist/server/registerApplicationTools/compareExportShapes.js +37 -0
  146. package/dist/server/registerApplicationTools/compareVersions.js +12 -6
  147. package/dist/server/registerApplicationTools/controlledReplay.js +2 -2
  148. package/dist/server/registerApplicationTools/coverage.js +3 -3
  149. package/dist/server/registerApplicationTools/helpers.js +37 -25
  150. package/dist/server/registerApplicationTools/traceFeature.js +9 -5
  151. package/dist/server/registerApplicationTools/traceSemantics.js +30 -0
  152. package/dist/server/registerApplicationTools.js +4 -0
  153. package/dist/server/registerEvidenceResources.js +5 -1
  154. package/dist/server/registerProcessComparisonTool.js +17 -7
  155. package/dist/server/registerReplayMachineTool.js +20 -0
  156. package/dist/server/registerSessionTools.js +12 -7
  157. package/dist/server/sessionAvailabilityPolicy.js +2 -1
  158. package/dist/serverIdentity.js +19 -0
  159. package/package.json +62 -30
  160. package/scripts/hopper-demo-x11.py +459 -61
  161. package/scripts/prepack.mjs +55 -0
  162. package/scripts/prepare.mjs +28 -0
  163. package/scripts/rea.mjs +26 -5
  164. package/skills/reverse-engineer-anything/SKILL.md +2 -2
  165. package/skills/reverse-engineer-anything/references/javascript-applications.md +10 -0
@@ -1,8 +1,11 @@
1
1
  import { z } from "incur";
2
+ import { stat } from "node:fs/promises";
3
+ import { resolve } from "node:path";
2
4
  import { runDirectAnalysis } from "../application/DirectAnalysis.js";
3
5
  import { CLI_COMMANDS } from "../cliCommandNames.js";
4
6
  import { logCliCommand } from "../cliLogging.js";
5
7
  import { directAnalysisOptions, providerSelectionOption } from "./options.js";
8
+ import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
6
9
  export const registerCoreAnalysisCommands = (cli, logger) => {
7
10
  registerCoreCommands(cli, logger);
8
11
  registerFunctionCommand(cli, logger);
@@ -30,13 +33,19 @@ const registerCoreCommands = (cli, logger) => {
30
33
  .describe("Load and update a local analysis snapshot"),
31
34
  provider: providerSelectionOption,
32
35
  });
36
+ const analyzeOptions = overviewOptions.extend({
37
+ approved: z
38
+ .boolean()
39
+ .default(false)
40
+ .describe("Approve static analysis when the path is a JavaScript directory or ASAR"),
41
+ });
33
42
  cli.command(CLI_COMMANDS.analyze, {
34
43
  description: "Get an overview of an app",
35
44
  args: z.object({
36
45
  path: z.string().describe("App, program, or analysis database path"),
37
46
  }),
38
- options: overviewOptions,
39
- run: ({ args, options }) => logCliCommand(logger, "analyze", () => runDirectAnalysis(args.path, "binary_overview", { detail: options.detail, limit: options.limit }, directAnalysisOptions(logger, options.snapshot, options.provider))),
47
+ options: analyzeOptions,
48
+ run: ({ args, options }) => logCliCommand(logger, "analyze", () => runRoutedOverview(args.path, options, logger)),
40
49
  });
41
50
  cli.command(CLI_COMMANDS.inspect, {
42
51
  description: "Inspect an app overview with evidence",
@@ -63,6 +72,29 @@ const registerCoreCommands = (cli, logger) => {
63
72
  run: ({ args, options }) => logCliCommand(logger, "decompile", () => runDirectAnalysis(args.path, "procedure_pseudo_code", { procedure: args.address }, directAnalysisOptions(logger, options.snapshot, options.provider))),
64
73
  });
65
74
  };
75
+ const runRoutedOverview = async (path, options, logger) => {
76
+ if (options.provider === undefined &&
77
+ options.snapshot === undefined &&
78
+ (await isJavaScriptApplicationPath(path)))
79
+ return runCliJavaScriptApplicationAnalysis({
80
+ input_path: resolve(path),
81
+ approved: options.approved,
82
+ });
83
+ return runDirectAnalysis(path, "binary_overview", { detail: options.detail, limit: options.limit }, directAnalysisOptions(logger, options.snapshot, options.provider));
84
+ };
85
+ const isJavaScriptApplicationPath = async (path) => {
86
+ const lower = path.toLowerCase();
87
+ if (lower.endsWith(".asar"))
88
+ return true;
89
+ if (lower.endsWith(".app"))
90
+ return false;
91
+ try {
92
+ return (await stat(path)).isDirectory();
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ };
66
98
  const registerXrefsCommand = (cli, logger) => {
67
99
  cli.command(CLI_COMMANDS.xrefs, {
68
100
  description: "List bounded references to an analyzed address",
@@ -0,0 +1,19 @@
1
+ import { analyzeJavaScriptApplication } from "../application/JavaScriptApplicationService.js";
2
+ import { loadConfiguredPermissionAuthority } from "../application/PermissionConfiguration.js";
3
+ import { parseConfig } from "../config.js";
4
+ import { projectAnalysisError } from "../domain/errors.js";
5
+ /** Execute the shared one-shot CLI boundary for static JavaScript analysis. */
6
+ export const runCliJavaScriptApplicationAnalysis = async (input) => {
7
+ const config = parseConfig(process.env);
8
+ if (!config.ok)
9
+ return cliError(config.error);
10
+ const authority = await loadConfiguredPermissionAuthority(config.value);
11
+ if (!authority.ok)
12
+ return cliError(authority.error);
13
+ const result = await analyzeJavaScriptApplication(authority.value, input);
14
+ return result.ok ? result.value : cliError(result.error);
15
+ };
16
+ const cliError = (error) => ({
17
+ error: "JavaScript application analysis failed",
18
+ ...projectAnalysisError(error),
19
+ });
@@ -1,6 +1,6 @@
1
1
  import { z } from "incur";
2
- import { runDoctor } from "../application/Doctor.js";
3
- import { runSetup, systemSetupHost } from "../application/Setup.js";
2
+ import { DOCTOR_PROVIDER_IDS, runDoctor, } from "../application/Doctor.js";
3
+ import { runSetup, systemSetupHost, } from "../application/Setup.js";
4
4
  import { runUninstall } from "../application/Uninstall.js";
5
5
  import { runUpgrade, systemUpgradeHost } from "../application/Upgrade.js";
6
6
  import { conciseSetupResult, confirmInteractiveSetup, renderInteractiveSetupResult, renderSetupProgress, } from "../cliSetup.js";
@@ -8,7 +8,19 @@ import { PRODUCT_IDENTITY } from "../identity.js";
8
8
  import { logCliCommand } from "../cliLogging.js";
9
9
  import { createSystemDoctorHost } from "../doctorRuntime.js";
10
10
  import { CLI_COMMANDS } from "../cliCommandNames.js";
11
+ import { SUPPORTED_CLIENT_DEFINITIONS } from "../application/SupportedClients.js";
12
+ import { projectDoctorReport } from "../application/DoctorProjection.js";
13
+ const supportedClientIds = SUPPORTED_CLIENT_DEFINITIONS.map(({ name }) => name);
14
+ const supportedClientSchema = z
15
+ .string()
16
+ .refine((candidate) => supportedClientIds.some((name) => name === candidate), "Unsupported agent integration");
17
+ /** Register setup, doctor, uninstall, and upgrade CLI commands. */
11
18
  export const registerSetupCommands = (cli, logger) => {
19
+ registerSetupCommand(cli, logger);
20
+ registerDoctorCommand(cli, logger);
21
+ registerMaintenanceCommands(cli, logger);
22
+ };
23
+ const registerSetupCommand = (cli, logger) => {
12
24
  cli.command(CLI_COMMANDS.setup, {
13
25
  description: "Install requirements and configure agents",
14
26
  outputPolicy: "agent-only",
@@ -22,14 +34,7 @@ export const registerSetupCommands = (cli, logger) => {
22
34
  .default(false)
23
35
  .describe("Also approve Hopper installation with --yes"),
24
36
  client: z
25
- .array(z.enum([
26
- "claude_code",
27
- "claude_desktop",
28
- "codex",
29
- "cursor",
30
- "gemini_cli",
31
- "windsurf",
32
- ]))
37
+ .array(supportedClientSchema)
33
38
  .default([])
34
39
  .describe("Agent integration to configure; repeat for multiple agents"),
35
40
  allDetected: z
@@ -48,17 +53,41 @@ export const registerSetupCommands = (cli, logger) => {
48
53
  .boolean()
49
54
  .default(false)
50
55
  .describe("Use sequential accessible setup prompts"),
56
+ detail: z
57
+ .enum(["summary", "full"])
58
+ .default("summary")
59
+ .describe("Summary or complete setup and doctor diagnostics"),
51
60
  }),
52
61
  alias: { yes: "y" },
53
- run: ({ options, formatExplicit, agent }) => logCliCommand(logger, "setup", () => runSetupCommand({ options, formatExplicit, agent })),
62
+ run: ({ options, formatExplicit }) => logCliCommand(logger, "setup", () => runSetupCommand({ options, formatExplicit })),
54
63
  });
64
+ };
65
+ const registerDoctorCommand = (cli, logger) => {
55
66
  cli.command(CLI_COMMANDS.doctor, {
56
67
  description: "Check whether REA is ready",
57
68
  options: z.object({
58
69
  target: z.string().optional().describe("Optional app path to check"),
70
+ client: z
71
+ .array(supportedClientSchema)
72
+ .default([])
73
+ .describe("Agent registration whose readiness is required; repeatable"),
74
+ provider: z
75
+ .array(z.enum(DOCTOR_PROVIDER_IDS))
76
+ .default([])
77
+ .describe("Deep-analysis provider whose readiness is required"),
78
+ skill: z
79
+ .boolean()
80
+ .optional()
81
+ .describe("Require the installed REA skill identity to be aligned"),
82
+ detail: z
83
+ .enum(["summary", "full"])
84
+ .default("summary")
85
+ .describe("Summary or complete doctor diagnostics"),
59
86
  }),
60
- run: ({ options }) => logCliCommand(logger, "doctor", () => runDoctor(options.target, createSystemDoctorHost())),
87
+ run: ({ options }) => logCliCommand(logger, "doctor", () => runDoctor(options.target, createSystemDoctorHost(), doctorScope(options)).then((report) => projectDoctorReport(report, options.detail))),
61
88
  });
89
+ };
90
+ const registerMaintenanceCommands = (cli, logger) => {
62
91
  cli.command(CLI_COMMANDS.uninstall, {
63
92
  description: "Remove REA-owned agent configuration and skill files",
64
93
  options: z.object({
@@ -77,37 +106,57 @@ export const registerSetupCommands = (cli, logger) => {
77
106
  };
78
107
  const runSetupCommand = async (input) => {
79
108
  const { options } = input;
80
- const interactive = !options.yes &&
81
- !options.dryRun &&
82
- !input.formatExplicit &&
83
- process.stdin.isTTY === true &&
84
- process.stderr.isTTY === true;
109
+ const interactive = setupIsInteractive(options, input.formatExplicit);
85
110
  const hasExplicitScope = setupHasExplicitScope(options);
86
111
  if (options.yes && !hasExplicitScope)
87
112
  process.stderr.write("! Implicit `rea setup --yes` scope is deprecated; use `--all-detected` to retain it.\n");
113
+ const result = await runSetup(setupRunOptions(input, interactive, hasExplicitScope), systemSetupHost(createSystemDoctorHost()), interactive
114
+ ? (actions) => confirmInteractiveSetup(actions, options.accessible)
115
+ : undefined);
116
+ if (interactive)
117
+ renderInteractiveSetupResult(result);
118
+ return options.detail === "full" ? result : conciseSetupResult(result);
119
+ };
120
+ const setupRunOptions = (input, interactive, hasExplicitScope) => {
121
+ const { options } = input;
88
122
  const agentIntegrationSelected = options.allDetected || options.client.length > 0;
89
- const result = await runSetup({
123
+ const hasSelectedClients = hasExplicitScope && !options.allDetected;
124
+ return {
90
125
  approved: options.yes && !options.dryRun,
91
126
  installHopper: options.installHopper,
92
127
  structured: input.formatExplicit || options.dryRun,
93
128
  proposeHopper: !hasExplicitScope || options.installHopper,
94
- ...(!hasExplicitScope || options.allDetected
95
- ? {}
96
- : { clientIds: options.client }),
97
- ...(!hasExplicitScope
98
- ? {}
99
- : {
100
- installSkill: options.skill ?? agentIntegrationSelected,
101
- }),
129
+ ...(hasSelectedClients ? { clientIds: options.client } : {}),
130
+ ...(hasExplicitScope
131
+ ? { installSkill: options.skill ?? agentIntegrationSelected }
132
+ : {}),
102
133
  ...(interactive ? { onProgress: renderSetupProgress } : {}),
103
- }, systemSetupHost(createSystemDoctorHost()), interactive
104
- ? (actions) => confirmInteractiveSetup(actions, options.accessible)
105
- : undefined);
106
- if (interactive)
107
- renderInteractiveSetupResult(result);
108
- return input.formatExplicit ? result : conciseSetupResult(result);
134
+ ...(hasSelectedClients
135
+ ? {
136
+ readinessScope: {
137
+ clients: options.client,
138
+ providers: options.installHopper ? ["hopper"] : [],
139
+ skill: options.skill ?? agentIntegrationSelected,
140
+ },
141
+ }
142
+ : {}),
143
+ };
109
144
  };
145
+ const setupIsInteractive = (options, formatExplicit) => !options.yes &&
146
+ !options.dryRun &&
147
+ !formatExplicit &&
148
+ process.stdin.isTTY === true &&
149
+ process.stderr.isTTY === true;
110
150
  const setupHasExplicitScope = (options) => options.allDetected ||
111
151
  options.client.length > 0 ||
112
152
  options.skill !== undefined ||
113
153
  options.installHopper;
154
+ const doctorScope = (options) => options.client.length === 0 &&
155
+ options.provider.length === 0 &&
156
+ options.skill === undefined
157
+ ? undefined
158
+ : {
159
+ clients: options.client,
160
+ providers: options.provider,
161
+ skill: options.skill === true,
162
+ };
@@ -1,5 +1,5 @@
1
1
  import { z } from "incur";
2
- import { runProviderAnalysis, runSessionStatus, } from "../application/DirectAnalysis.js";
2
+ import { runCapabilityStatus, runProviderAnalysis, runProviderStatus, } from "../application/DirectAnalysis.js";
3
3
  import { importReferenceSource } from "../application/ReferenceSourceImport.js";
4
4
  import { projectReferenceSourceImportError } from "../application/ReferenceSourceImportTypes.js";
5
5
  import { loadConfiguredPermissionAuthority } from "../application/PermissionConfiguration.js";
@@ -22,7 +22,15 @@ const registerCapabilityCommands = (cli, logger) => {
22
22
  description: command === "capabilities"
23
23
  ? "List provider capabilities and side effects"
24
24
  : "List configured analysis providers",
25
- run: () => logCliCommand(logger, command, () => runSessionStatus(logger)),
25
+ options: z.object({
26
+ detail: z
27
+ .enum(["summary", "full"])
28
+ .default("summary")
29
+ .describe("Summary or complete provider descriptors"),
30
+ }),
31
+ run: ({ options }) => logCliCommand(logger, command, () => command === CLI_COMMANDS.providers
32
+ ? runProviderStatus(logger, options.detail)
33
+ : runCapabilityStatus(logger, options.detail)),
26
34
  });
27
35
  }
28
36
  };
@@ -1,5 +1,8 @@
1
1
  import { Cli, z } from "incur";
2
- import { compareApplicationVersionsEvidence, traceApplicationFeatureEvidence, } from "./application/JavaScriptApplicationWorkflowService.js";
2
+ import { compareApplicationVersionsEvidenceValidated, compareJavaScriptExportShapesEvidenceValidated, traceApplicationFeatureEvidenceValidated, } from "./application/JavaScriptApplicationWorkflowService.js";
3
+ import { traceJavaScriptSemanticsEvidenceValidated } from "./application/JavaScriptSemanticTraceService.js";
4
+ import { resolveCompareApplicationVersionsRequest, resolveCompareJavaScriptExportShapesRequest, resolveTraceApplicationFeatureRequest, resolveTraceJavaScriptSemanticsRequest, } from "./application/ApplicationWorkflowEvidenceResolver.js";
5
+ import { readEvidenceBundle } from "./application/EvidenceBundleFiles.js";
3
6
  import { runControlledReplay } from "./application/JavaScriptReplayService.js";
4
7
  import { executeNodeCharacterization, prepareNodeCharacterization, } from "./application/NodeRuntimeCharacterizationService.js";
5
8
  import { commitReconstructionCoverage, queryReconstructionCoverage, reconstructionCoverageCommitInputSchema, reconstructionCoverageQueryInputSchema, } from "./application/ReconstructionCoverageService.js";
@@ -19,14 +22,32 @@ export const registerApplicationCommands = (cli, logger) => {
19
22
  logger,
20
23
  name: CLI_COMMANDS.traceApplicationFeature,
21
24
  description: "Trace a typed seed through authenticated application Evidence JSON",
22
- workflow: traceApplicationFeatureEvidence,
25
+ resolveInput: resolveTraceApplicationFeatureRequest,
26
+ workflow: traceApplicationFeatureEvidenceValidated,
27
+ });
28
+ registerJsonCommand({
29
+ cli,
30
+ logger,
31
+ name: CLI_COMMANDS.traceJavaScriptSemantics,
32
+ description: "Trace bounded static semantic relations through authenticated application Evidence",
33
+ resolveInput: resolveTraceJavaScriptSemanticsRequest,
34
+ workflow: traceJavaScriptSemanticsEvidenceValidated,
23
35
  });
24
36
  registerJsonCommand({
25
37
  cli,
26
38
  logger,
27
39
  name: CLI_COMMANDS.compareApplicationVersions,
28
40
  description: "Compare two authenticated JavaScript Application Graph versions",
29
- workflow: compareApplicationVersionsEvidence,
41
+ resolveInput: resolveCompareApplicationVersionsRequest,
42
+ workflow: compareApplicationVersionsEvidenceValidated,
43
+ });
44
+ registerJsonCommand({
45
+ cli,
46
+ logger,
47
+ name: CLI_COMMANDS.compareJavaScriptExportShapes,
48
+ description: "Compare exact static JavaScript export return shapes without execution",
49
+ resolveInput: resolveCompareJavaScriptExportShapesRequest,
50
+ workflow: compareJavaScriptExportShapesEvidenceValidated,
30
51
  });
31
52
  cli.command(CLI_COMMANDS.runControlledReplay, {
32
53
  description: "Plan or execute an approved extracted-module replay in the Linux sandbox",
@@ -138,13 +159,10 @@ const registerCoverageCommands = (cli, logger) => {
138
159
  });
139
160
  };
140
161
  const configuredAuthority = async () => {
141
- const config = parseConfig(process.env);
142
- if (!config.ok)
143
- return { ok: false, error: projectAnalysisError(config.error) };
144
- const authority = await loadConfiguredPermissionAuthority(config.value);
145
- return authority.ok
146
- ? { ok: true, config: config.value, authority: authority.value }
147
- : { ok: false, error: projectAnalysisError(authority.error) };
162
+ const configured = await loadConfiguredAuthority();
163
+ return configured.ok
164
+ ? configured
165
+ : { ok: false, error: projectAnalysisError(configured.error) };
148
166
  };
149
167
  const replayDependencies = (config, authority) => ({
150
168
  policy: config.javascriptReplayPolicy,
@@ -152,25 +170,70 @@ const replayDependencies = (config, authority) => ({
152
170
  runner: new LinuxJavaScriptReplayRunner(),
153
171
  authority,
154
172
  });
155
- const registerJsonCommand = ({ cli, logger, name, description, workflow, }) => {
173
+ const registerJsonCommand = ({ cli, logger, name, description, resolveInput, workflow, }) => {
156
174
  cli.command(name, {
157
175
  description,
158
176
  args: z.object({
159
177
  inputJson: z.string().describe("Inline workflow JSON or JSON file path"),
160
178
  }),
161
- run: ({ args }) => logCliCommand(logger, name, async () => {
179
+ options: z.object({
180
+ evidenceBundle: z
181
+ .string()
182
+ .optional()
183
+ .describe("Authorized Evidence bundle used to resolve Evidence IDs"),
184
+ }),
185
+ run: ({ args, options }) => logCliCommand(logger, name, async () => {
162
186
  const input = await parseCliJsonInput(args.inputJson, name);
163
187
  if (!input.ok)
164
188
  return input.error;
165
- const result = workflow(input.value);
189
+ const lookup = await loadEvidenceLookup(options.evidenceBundle, name);
190
+ if (!lookup.ok)
191
+ return {
192
+ error: "Application workflow failed",
193
+ ...projectAnalysisError(lookup.error),
194
+ };
195
+ const resolved = resolveInput(input.value, lookup.value);
196
+ if (!resolved.ok)
197
+ return {
198
+ error: "Application workflow failed",
199
+ ...projectAnalysisError(resolved.error),
200
+ };
201
+ const result = workflow(resolved.value);
166
202
  return result.ok
167
203
  ? result.value
168
204
  : {
169
205
  error: "Application workflow failed",
170
- ...projectAnalysisError(result.error instanceof AnalysisInputError
171
- ? result.error
172
- : new AnalysisInputError(name)),
206
+ ...projectAnalysisError(result.error),
173
207
  };
174
208
  }),
175
209
  });
176
210
  };
211
+ const loadEvidenceLookup = async (bundlePath, operation) => {
212
+ if (bundlePath === undefined)
213
+ return { ok: true, value: undefined };
214
+ const configured = await loadConfiguredAuthority();
215
+ if (!configured.ok)
216
+ return configured;
217
+ const authorized = await authorizeRootPermission(configured.authority, {
218
+ capability: "evidence_read",
219
+ roots: [bundlePath],
220
+ access: "read",
221
+ operation,
222
+ });
223
+ if (!authorized.ok)
224
+ return authorized;
225
+ const loaded = await readEvidenceBundle(bundlePath, configured.config.evidenceFilePolicy);
226
+ if (!loaded.ok)
227
+ return loaded;
228
+ const records = new Map(loaded.value.records.map((record) => [record.evidence_id, record]));
229
+ return { ok: true, value: (evidenceId) => records.get(evidenceId) };
230
+ };
231
+ const loadConfiguredAuthority = async () => {
232
+ const config = parseConfig(process.env);
233
+ if (!config.ok)
234
+ return config;
235
+ const authority = await loadConfiguredPermissionAuthority(config.value);
236
+ return authority.ok
237
+ ? { ok: true, config: config.value, authority: authority.value }
238
+ : authority;
239
+ };
@@ -49,7 +49,10 @@ export const CLI_COMMANDS = Object.freeze({
49
49
  analyzeJavaScriptApplication: "analyze-javascript-application",
50
50
  reconcileJavaScriptRuntime: "reconcile-javascript-runtime",
51
51
  traceApplicationFeature: "trace-application-feature",
52
+ traceJavaScriptSemantics: "trace-javascript-semantics",
52
53
  compareApplicationVersions: "compare-application-versions",
54
+ compareJavaScriptExportShapes: "compare-javascript-export-shapes",
55
+ runReplayMachine: "run-replay-machine",
53
56
  runControlledReplay: "run-controlled-replay",
54
57
  prepareNodeCharacterization: "prepare-node-characterization",
55
58
  executeNodeCharacterization: "execute-node-characterization",
@@ -1,17 +1,16 @@
1
1
  import { Cli, z } from "incur";
2
2
  import { inspectElectronPage, listElectronTargets, } from "./application/ElectronObservationService.js";
3
- import { analyzeJavaScriptApplication } from "./application/JavaScriptApplicationService.js";
4
3
  import { reconcileJavaScriptRuntimeEvidence } from "./application/JavaScriptRuntimeReconciliationService.js";
5
4
  import { loadConfiguredPermissionAuthority } from "./application/PermissionConfiguration.js";
6
5
  import { CdpElectronProvider } from "./browser/CdpElectronProvider.js";
7
6
  import { logCliCommand } from "./cliLogging.js";
8
7
  import { parseConfig } from "./config.js";
9
8
  import { inspectElectronPageInputSchema, listElectronTargetsInputSchema, } from "./domain/electronObservation.js";
10
- import { analyzeJavaScriptApplicationInputSchema } from "./domain/javascriptApplicationAnalysis.js";
11
9
  import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
12
10
  import { CLI_COMMANDS } from "./cliCommandNames.js";
13
11
  import { parseCliJsonInput } from "./cliJsonInput.js";
14
12
  import { electronPageInspectionOptions, javascriptApplicationOptions, } from "./cliObservationOptions.js";
13
+ import { runCliJavaScriptApplicationAnalysis } from "./cli/javascriptApplicationAnalysis.js";
15
14
  const scopeOptions = {
16
15
  allowedFileRoots: z
17
16
  .array(z.string().min(1))
@@ -134,37 +133,28 @@ const registerJavaScriptApplicationCommand = (cli, logger) => {
134
133
  path: z.string().describe("Absolute ASAR or extracted application path"),
135
134
  }),
136
135
  options: javascriptApplicationOptions,
137
- run: ({ args, options }) => logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, async () => {
138
- const context = await electronContext();
139
- if (!context.ok)
140
- return context.error;
141
- const parsed = analyzeJavaScriptApplicationInputSchema.safeParse({
142
- input_path: args.path,
143
- approved: options.approved,
144
- format: options.format,
145
- source_map_read_approved: options.sourceMapReadApproved,
146
- limits: {
147
- max_entries: options.maxEntries,
148
- max_total_artifact_bytes: options.maxTotalArtifactBytes,
149
- max_artifact_entry_bytes: options.maxArtifactEntryBytes,
150
- max_compression_ratio: options.maxCompressionRatio,
151
- max_depth: options.maxDepth,
152
- max_path_bytes: options.maxPathBytes,
153
- max_text_files: options.maxTextFiles,
154
- max_total_text_bytes: options.maxTotalTextBytes,
155
- max_text_file_bytes: options.maxTextFileBytes,
156
- max_ast_nodes: options.maxAstNodes,
157
- max_findings: options.maxFindings,
158
- max_modules: options.maxModules,
159
- max_source_map_sources: options.maxSourceMapSources,
160
- max_parse_milliseconds: options.maxParseMilliseconds,
161
- },
162
- });
163
- if (!parsed.success)
164
- return inputError("analyze_javascript_application");
165
- const result = await analyzeJavaScriptApplication(context.authority, parsed.data);
166
- return result.ok ? result.value : cliError(result.error);
167
- }),
136
+ run: ({ args, options }) => logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () => runCliJavaScriptApplicationAnalysis({
137
+ input_path: args.path,
138
+ approved: options.approved,
139
+ format: options.artifactFormat,
140
+ source_map_read_approved: options.sourceMapReadApproved,
141
+ limits: {
142
+ max_entries: options.maxEntries,
143
+ max_total_artifact_bytes: options.maxTotalArtifactBytes,
144
+ max_artifact_entry_bytes: options.maxArtifactEntryBytes,
145
+ max_compression_ratio: options.maxCompressionRatio,
146
+ max_depth: options.maxDepth,
147
+ max_path_bytes: options.maxPathBytes,
148
+ max_text_files: options.maxTextFiles,
149
+ max_total_text_bytes: options.maxTotalTextBytes,
150
+ max_text_file_bytes: options.maxTextFileBytes,
151
+ max_ast_nodes: options.maxAstNodes,
152
+ max_findings: options.maxFindings,
153
+ max_modules: options.maxModules,
154
+ max_source_map_sources: options.maxSourceMapSources,
155
+ max_parse_milliseconds: options.maxParseMilliseconds,
156
+ },
157
+ })),
168
158
  });
169
159
  };
170
160
  const electronContext = async () => {
@@ -108,7 +108,7 @@ export const javascriptApplicationOptions = z.object({
108
108
  .boolean()
109
109
  .default(false)
110
110
  .describe("Approve reading the application artifact"),
111
- format: z
111
+ artifactFormat: z
112
112
  .enum(["auto", "asar", "directory"])
113
113
  .default("auto")
114
114
  .describe("Application artifact format"),
package/dist/cliOutput.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const SAFE_VALIDATION_MESSAGE = "REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again.";
2
+ const UNSUPPORTED_OUTPUT_COMBINATION_MESSAGE = "Token windows cannot preserve structured output. Remove --token-limit/--token-offset and use --filter-output or command pagination.";
2
3
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
4
  const validationError = (value) => {
4
5
  if (!isRecord(value))
@@ -9,6 +10,61 @@ const validationError = (value) => {
9
10
  return value.error.code === "VALIDATION_ERROR" ? value.error : undefined;
10
11
  return undefined;
11
12
  };
13
+ /** Reject text-window controls that would corrupt a structured document. */
14
+ export const validateCliOutputArguments = (arguments_) => {
15
+ let format = "toon";
16
+ let tokenWindow = false;
17
+ for (let index = 0; index < arguments_.length; index += 1) {
18
+ const argument = arguments_[index];
19
+ if (argument === "--")
20
+ break;
21
+ if (argument === "--json") {
22
+ format = "json";
23
+ continue;
24
+ }
25
+ if (argument === "--format") {
26
+ const value = arguments_[index + 1];
27
+ if (value !== undefined) {
28
+ format = value;
29
+ index += 1;
30
+ }
31
+ continue;
32
+ }
33
+ if (argument?.startsWith("--format=")) {
34
+ format = argument.slice("--format=".length);
35
+ continue;
36
+ }
37
+ if (argument === "--token-limit" || argument === "--token-offset") {
38
+ if (arguments_[index + 1] !== undefined) {
39
+ tokenWindow = true;
40
+ index += 1;
41
+ }
42
+ continue;
43
+ }
44
+ if (argument?.startsWith("--token-limit=") ||
45
+ argument?.startsWith("--token-offset="))
46
+ tokenWindow = true;
47
+ }
48
+ if (tokenWindow &&
49
+ (format === "json" || format === "jsonl" || format === "yaml"))
50
+ return {
51
+ ok: false,
52
+ format,
53
+ code: "UNSUPPORTED_OUTPUT_COMBINATION",
54
+ message: UNSUPPORTED_OUTPUT_COMBINATION_MESSAGE,
55
+ };
56
+ return { ok: true };
57
+ };
58
+ /** Render one complete structured error before command execution. */
59
+ export const renderCliOutputArgumentError = (error) => {
60
+ const value = {
61
+ ok: false,
62
+ error: { code: error.code, message: error.message },
63
+ };
64
+ if (error.format === "yaml")
65
+ return `ok: false\nerror:\n code: ${error.code}\n message: ${JSON.stringify(error.message)}\n`;
66
+ return `${JSON.stringify(value)}\n`;
67
+ };
12
68
  /** Remove validator internals from Incur's caller-visible CLI output. */
13
69
  export const sanitizeCliOutput = (output) => {
14
70
  const trimmed = output.trimStart();
@@ -2,8 +2,13 @@ import { Cli, z } from "incur";
2
2
  import { captureProcessScenarioFile, compareProcessEvidenceFiles, } from "./application/ProcessCli.js";
3
3
  import { logCliCommand } from "./cliLogging.js";
4
4
  import { CLI_COMMANDS } from "./cliCommandNames.js";
5
+ import { parseCliJsonInput } from "./cliJsonInput.js";
6
+ import { replayMachineRunInputSchema, runReplayMachine, } from "./domain/replayMachineRun.js";
7
+ import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
8
+ import { projectInputIssues } from "./domain/inputIssueProjection.js";
5
9
  /** Register Process Capture v4 one-shot commands through shared application services. */
6
10
  export const registerProcessCommands = (cli, logger) => {
11
+ registerReplayMachineCommand(cli, logger);
7
12
  cli.command(CLI_COMMANDS.captureProcess, {
8
13
  description: "Capture one approved Process Capture v4 JSON scenario",
9
14
  args: z.object({ scenario: z.string().describe("Scenario JSON path") }),
@@ -14,7 +19,33 @@ export const registerProcessCommands = (cli, logger) => {
14
19
  args: z.object({
15
20
  left: z.string().describe("Left capture Evidence JSON path"),
16
21
  right: z.string().describe("Right capture Evidence JSON path"),
22
+ traceSpec: z
23
+ .string()
24
+ .optional()
25
+ .describe("Optional partial-order or finite-trace specification path"),
26
+ }),
27
+ run: ({ args }) => logCliCommand(logger, "compare-process-captures", () => compareProcessEvidenceFiles(args.left, args.right, args.traceSpec)),
28
+ });
29
+ };
30
+ const registerReplayMachineCommand = (cli, logger) => {
31
+ cli.command(CLI_COMMANDS.runReplayMachine, {
32
+ description: "Run ordered protocol events directly through a finite replay machine",
33
+ args: z.object({
34
+ inputJson: z.string().describe("Inline replay JSON or JSON file path"),
35
+ }),
36
+ run: ({ args }) => logCliCommand(logger, CLI_COMMANDS.runReplayMachine, async () => {
37
+ const input = await parseCliJsonInput(args.inputJson, CLI_COMMANDS.runReplayMachine);
38
+ if (!input.ok)
39
+ return input.error;
40
+ const parsed = replayMachineRunInputSchema.safeParse(input.value);
41
+ return parsed.success
42
+ ? runReplayMachine(parsed.data)
43
+ : {
44
+ error: "Process command failed",
45
+ ...projectAnalysisError(new AnalysisInputError(CLI_COMMANDS.runReplayMachine, {
46
+ cause: parsed.error,
47
+ }, projectInputIssues(parsed.error.issues, input.value))),
48
+ };
17
49
  }),
18
- run: ({ args }) => logCliCommand(logger, "compare-process-captures", () => compareProcessEvidenceFiles(args.left, args.right)),
19
50
  });
20
51
  };