rea-agents 2.0.0 → 2.2.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 (273) hide show
  1. package/README.md +103 -38
  2. package/bridge/ghidra/ReaGhidraBridge.java +96 -11
  3. package/dist/application/AndroidApplicationService.js +17 -0
  4. package/dist/application/AppleApplicationService.js +17 -0
  5. package/dist/application/ArtifactExtraction.js +1 -1
  6. package/dist/application/ArtifactInventory/classify.js +42 -0
  7. package/dist/application/ArtifactInventory/hash.js +43 -0
  8. package/dist/application/ArtifactInventory/reader.js +41 -0
  9. package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
  10. package/dist/application/ArtifactInventory/scanReader.js +124 -0
  11. package/dist/application/ArtifactInventory/types.js +10 -0
  12. package/dist/application/ArtifactInventory.js +9 -351
  13. package/dist/application/AuthorizedArtifactInventory.js +2 -2
  14. package/dist/application/BinarySession.js +47 -270
  15. package/dist/application/BinarySessionExecution.js +28 -0
  16. package/dist/application/BinarySessionOpen.js +39 -0
  17. package/dist/application/BinarySessionRecords.js +149 -0
  18. package/dist/application/BinarySessionStatus.js +75 -0
  19. package/dist/application/CapabilityInventory.js +24 -2
  20. package/dist/application/ClientRegistrationStatus.js +11 -4
  21. package/dist/application/CrossVersionInventory.js +8 -2
  22. package/dist/application/CrossVersionInvestigation.js +1 -23
  23. package/dist/application/CrossVersionInvestigationCollections.js +23 -0
  24. package/dist/application/DirectAnalysis.js +47 -44
  25. package/dist/application/Doctor.js +156 -238
  26. package/dist/application/DoctorDiagnostics.js +180 -0
  27. package/dist/application/ElectronBoundaryAnalysis.js +23 -7
  28. package/dist/application/ElectronBoundaryGraphWindows.js +32 -8
  29. package/dist/application/EnhancedToolPagination.js +22 -0
  30. package/dist/application/EnhancedToolTypes.js +4 -0
  31. package/dist/application/EnhancedTools.js +20 -37
  32. package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
  33. package/dist/application/InventoryProjectionEvidence.js +41 -0
  34. package/dist/application/InvestigationProviders.js +12 -0
  35. package/dist/application/InvestigationWorkspaceStore.js +24 -10
  36. package/dist/application/JavaScriptArtifactAnalysis.js +45 -6
  37. package/dist/application/JavaScriptArtifactFiles.js +6 -2
  38. package/dist/application/JavaScriptArtifactGraphBuilder.js +23 -1
  39. package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
  40. package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
  41. package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
  42. package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
  43. package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
  44. package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
  45. package/dist/application/JavaScriptArtifactReconstruction.js +1 -1
  46. package/dist/application/JavaScriptJsonModules.js +39 -0
  47. package/dist/application/JavaScriptModuleRelationships.js +262 -0
  48. package/dist/application/JavaScriptReplayPermission.js +16 -0
  49. package/dist/application/JavaScriptReplayService.js +182 -156
  50. package/dist/application/LinuxHopper.js +10 -0
  51. package/dist/application/MacHopper.js +22 -11
  52. package/dist/application/NodeRuntimeCharacterizationService.js +196 -0
  53. package/dist/application/PermissionAuthority.js +106 -63
  54. package/dist/application/ProcessCaptureCapability.js +1 -1
  55. package/dist/application/ProcessCapturePermission.js +13 -0
  56. package/dist/application/ProcessCli.js +2 -12
  57. package/dist/application/ProcessHarness.js +1 -1
  58. package/dist/application/ProcessPairedExperiment.js +72 -0
  59. package/dist/application/ProjectPermissionStore.js +48 -9
  60. package/dist/application/RealHopperAssertions.js +76 -0
  61. package/dist/application/ReconstructionCoverageService.js +69 -0
  62. package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
  63. package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
  64. package/dist/application/Setup.js +148 -260
  65. package/dist/application/SetupClientConfiguration.js +224 -0
  66. package/dist/application/SetupClients.js +24 -2
  67. package/dist/application/SetupPlan.js +124 -12
  68. package/dist/application/SetupSkill.js +54 -36
  69. package/dist/application/SupportedClients.js +1 -0
  70. package/dist/application/Uninstall.js +12 -3
  71. package/dist/application/Upgrade.js +16 -1
  72. package/dist/application/WindowsCapabilities.js +86 -0
  73. package/dist/artifacts/AsarArtifactReader.js +11 -0
  74. package/dist/browser/BrowserProcessStartup.js +88 -0
  75. package/dist/browser/CdpCaptureDocuments.js +12 -8
  76. package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
  77. package/dist/browser/CdpCaptureEventHandlers.js +336 -0
  78. package/dist/browser/CdpCaptureEventHelpers.js +71 -0
  79. package/dist/browser/CdpCaptureEventState.js +1 -0
  80. package/dist/browser/CdpCaptureEventTypes.js +1 -0
  81. package/dist/browser/CdpCaptureEvents.js +29 -496
  82. package/dist/browser/CdpObservationSession.js +51 -8
  83. package/dist/browser/CdpPageCapture.js +12 -133
  84. package/dist/browser/CdpPageCaptureScripts.js +97 -0
  85. package/dist/browser/CdpPageCaptureWorkers.js +46 -0
  86. package/dist/browser/CdpWebMcpDiscovery.js +38 -14
  87. package/dist/browser/PngVisualDiff.js +9 -2
  88. package/dist/catalogIdentity.js +4 -0
  89. package/dist/cli/artifactCommands.js +82 -0
  90. package/dist/cli/coreAnalysisCommands.js +232 -0
  91. package/dist/cli/managedCommands.js +397 -0
  92. package/dist/cli/managedProjectGraphCommand.js +24 -0
  93. package/dist/cli/options.js +9 -0
  94. package/dist/cli/setupCommands.js +113 -0
  95. package/dist/cli/types.js +1 -0
  96. package/dist/cli/utilityCommands.js +122 -0
  97. package/dist/cli.js +10 -768
  98. package/dist/cliApplicationCommands.js +118 -4
  99. package/dist/cliBrowserAdvancedCommands.js +73 -16
  100. package/dist/cliBrowserCommands.js +39 -115
  101. package/dist/cliCommandNames.js +4 -0
  102. package/dist/cliElectronCommands.js +33 -62
  103. package/dist/cliEvidenceCommands.js +13 -2
  104. package/dist/cliInvestigationCommands.js +53 -10
  105. package/dist/cliObservationOptions.js +137 -0
  106. package/dist/cliPolicyCommands.js +80 -46
  107. package/dist/cliSetup.js +306 -0
  108. package/dist/config/environment.js +107 -0
  109. package/dist/config/parseConfig.js +228 -0
  110. package/dist/config/parsers.js +68 -0
  111. package/dist/config/permissions.js +30 -0
  112. package/dist/config/types.js +1 -0
  113. package/dist/config.js +1 -375
  114. package/dist/contracts/applicationToolContracts.js +134 -0
  115. package/dist/contracts/electronToolContracts.js +51 -3
  116. package/dist/contracts/managedToolContracts.js +8 -3
  117. package/dist/contracts/managedWorkflowToolContracts.js +3 -3
  118. package/dist/contracts/providerSelection.js +2 -0
  119. package/dist/contracts/sessionStatusContract.js +26 -0
  120. package/dist/contracts/toolContractTypes.js +12 -1
  121. package/dist/contracts/toolContracts.js +5 -12
  122. package/dist/contracts/toolEffects.js +14 -0
  123. package/dist/contracts/toolOutputSchemaGroups.js +274 -0
  124. package/dist/contracts/toolOutputSchemaPrimitives.js +328 -0
  125. package/dist/contracts/toolOutputSchemas.js +2 -550
  126. package/dist/domain/analysisErrorPresentation.js +234 -0
  127. package/dist/domain/analysisErrorProjection.js +284 -0
  128. package/dist/domain/androidApplication.js +206 -0
  129. package/dist/domain/appleApplication.js +221 -0
  130. package/dist/domain/artifactComparison.js +34 -15
  131. package/dist/domain/binaryTarget.js +87 -37
  132. package/dist/domain/boundedCartesianProjection.js +15 -0
  133. package/dist/domain/browserObservation.js +1 -285
  134. package/dist/domain/browserObservationSchemas.js +286 -0
  135. package/dist/domain/electronStaticAnalysisBrowser.js +14 -2
  136. package/dist/domain/errors.js +4 -486
  137. package/dist/domain/functionComparison.js +4 -165
  138. package/dist/domain/functionComparisonDimensions.js +164 -0
  139. package/dist/domain/javascriptApplicationVersionItems.js +18 -6
  140. package/dist/domain/javascriptApplicationVersionKeys.js +8 -8
  141. package/dist/domain/javascriptExportInstrumentation.js +97 -0
  142. package/dist/domain/javascriptFeatureTraversal.js +19 -7
  143. package/dist/domain/javascriptRuntimeStaticCandidates.js +3 -1
  144. package/dist/domain/javascriptSemanticAnalysis.js +386 -0
  145. package/dist/domain/javascriptSemanticIr.js +30 -0
  146. package/dist/domain/javascriptSemanticProjection.js +366 -0
  147. package/dist/domain/javascriptSemanticState.js +40 -0
  148. package/dist/domain/javascriptSemanticTraversal.js +22 -0
  149. package/dist/domain/javascriptSemanticValues.js +352 -0
  150. package/dist/domain/javascriptStaticAnalysis.js +5 -221
  151. package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
  152. package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
  153. package/dist/domain/javascriptStaticAnalysisHelpers.js +71 -2
  154. package/dist/domain/knownPageCoverage.js +21 -0
  155. package/dist/domain/managedApplicationGraph.js +14 -364
  156. package/dist/domain/managedApplicationGraphCoverage.js +170 -0
  157. package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
  158. package/dist/domain/managedApplicationGraphNodes.js +336 -0
  159. package/dist/domain/managedArtifact.js +16 -8
  160. package/dist/domain/managedMemberComparison.js +37 -391
  161. package/dist/domain/managedMemberComparisonCoverage.js +72 -0
  162. package/dist/domain/managedMemberComparisonMatch.js +356 -0
  163. package/dist/domain/managedNativeVerification.js +27 -389
  164. package/dist/domain/managedNativeVerificationMatch.js +272 -0
  165. package/dist/domain/managedNativeVerificationSchemas.js +141 -0
  166. package/dist/domain/managedReconstruction.js +82 -69
  167. package/dist/domain/managedRuntimeCorrelation.js +12 -3
  168. package/dist/domain/nodeRuntimeCharacterization.js +66 -0
  169. package/dist/domain/permissionPolicy.js +2 -0
  170. package/dist/domain/processComparison.js +19 -0
  171. package/dist/domain/processPairedExperiment.js +128 -0
  172. package/dist/domain/reconstructionCoverage.js +387 -0
  173. package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
  174. package/dist/domain/reconstructionVerificationSchemas.js +8 -0
  175. package/dist/domain/replayMachine.js +316 -0
  176. package/dist/domain/replayMachineRuntime.js +215 -0
  177. package/dist/domain/runtimeCharacterization.js +85 -0
  178. package/dist/domain/runtimeIdentification.js +210 -0
  179. package/dist/domain/webBundleAnalyzer.js +3 -409
  180. package/dist/domain/webBundleAnalyzerAst.js +77 -0
  181. package/dist/domain/webBundleAnalyzerInspection.js +307 -0
  182. package/dist/domain/webBundleAnalyzerResult.js +120 -0
  183. package/dist/dotnet/ManagedArtifactInspector.js +50 -29
  184. package/dist/dotnet/ManagedMemberInspector.js +51 -785
  185. package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
  186. package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
  187. package/dist/dotnet/ManagedMemberRows.js +120 -0
  188. package/dist/dotnet/ManagedMetadataInventory.js +42 -306
  189. package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
  190. package/dist/dotnet/ManagedMetadataLayout.js +48 -111
  191. package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
  192. package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
  193. package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
  194. package/dist/dotnet/ManagedNativeBoundaryInspector.js +102 -350
  195. package/dist/dotnet/ManagedPeReader.js +59 -28
  196. package/dist/evaluation/CodexAgentEval.js +132 -0
  197. package/dist/generatedPackageMetadata.js +2 -2
  198. package/dist/ghidra/GhidraClient.js +76 -91
  199. package/dist/ghidra/GhidraClientStartup.js +29 -0
  200. package/dist/ghidra/GhidraClientWire.js +34 -0
  201. package/dist/ghidra/GhidraDefaults.js +1 -1
  202. package/dist/ghidra/GhidraDiagnostics.js +6 -1
  203. package/dist/ghidra/GhidraInstallation.js +20 -15
  204. package/dist/ghidra/GhidraLauncher.js +93 -29
  205. package/dist/ghidra/GhidraProvider.js +61 -161
  206. package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
  207. package/dist/ghidra/GhidraSessionValues.js +2 -0
  208. package/dist/ghidra/GhidraSocketConnection.js +44 -7
  209. package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
  210. package/dist/ghidra/GhidraTransport.js +71 -0
  211. package/dist/identity.js +4 -2
  212. package/dist/main/messages.js +5 -0
  213. package/dist/main/reload.js +49 -0
  214. package/dist/main/shutdown.js +25 -0
  215. package/dist/main/startup.js +14 -0
  216. package/dist/main/state.js +26 -0
  217. package/dist/main/transport.js +61 -0
  218. package/dist/main/types.js +1 -0
  219. package/dist/main.js +35 -146
  220. package/dist/process/PrivateRuntimeRoot.js +3 -2
  221. package/dist/process/ProcessOwnership.js +35 -0
  222. package/dist/process/ProviderProcess.js +2 -0
  223. package/dist/replay/JavaScriptReplayWorker.js +64 -50
  224. package/dist/replay/LinuxJavaScriptReplayRunner.js +173 -390
  225. package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
  226. package/dist/replay/ReplayOutcome.js +95 -0
  227. package/dist/replay/ReplayProcessLifecycle.js +71 -0
  228. package/dist/server/ProcessCaptureElicitation.js +157 -0
  229. package/dist/server/createServer.js +124 -56
  230. package/dist/server/javascriptApplicationResult.js +85 -0
  231. package/dist/server/registerApplicationTools/characterization.js +57 -0
  232. package/dist/server/registerApplicationTools/compareVersions.js +34 -0
  233. package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
  234. package/dist/server/registerApplicationTools/coverage.js +84 -0
  235. package/dist/server/registerApplicationTools/helpers.js +42 -0
  236. package/dist/server/registerApplicationTools/traceFeature.js +26 -0
  237. package/dist/server/registerApplicationTools/types.js +1 -0
  238. package/dist/server/registerApplicationTools.js +10 -112
  239. package/dist/server/registerBrowserTools.js +59 -83
  240. package/dist/server/registerElectronTools.js +48 -49
  241. package/dist/server/registerEnhancedTools.js +34 -42
  242. package/dist/server/registerEvidenceResources.js +56 -0
  243. package/dist/server/registerInvestigationTools/helpers.js +74 -0
  244. package/dist/server/registerInvestigationTools/types.js +1 -0
  245. package/dist/server/registerInvestigationTools.js +83 -116
  246. package/dist/server/registerJavaScriptApplicationGraphResource.js +69 -0
  247. package/dist/server/registerManagedTools.js +18 -1
  248. package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
  249. package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
  250. package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
  251. package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
  252. package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
  253. package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
  254. package/dist/server/registerManagedWorkflowTools/types.js +1 -0
  255. package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
  256. package/dist/server/registerManagedWorkflowTools.js +10 -274
  257. package/dist/server/registerOfficialTools.js +73 -59
  258. package/dist/server/registerSessionRecordTools.js +137 -0
  259. package/dist/server/registerSessionStatusTool.js +97 -26
  260. package/dist/server/registerSessionTools.js +60 -164
  261. package/dist/server/sessionAvailabilityPolicy.js +10 -0
  262. package/dist/server/toolRegistrationOptions.js +101 -3
  263. package/dist/server/toolResult.js +15 -4
  264. package/package.json +11 -11
  265. package/skills/reverse-engineer-anything/SKILL.md +76 -0
  266. package/skills/reverse-engineer-anything/references/controlled-replay.md +12 -0
  267. package/skills/reverse-engineer-anything/references/evidence-workflows.md +33 -0
  268. package/skills/reverse-engineer-anything/references/javascript-applications.md +25 -0
  269. package/skills/reverse-engineer-anything/references/native-and-artifacts.md +36 -0
  270. package/skills/reverse-engineer-anything/references/runtime-observation.md +24 -0
  271. package/scripts/prepare-node-pty.mjs +0 -35
  272. package/scripts/rebuild-native.mjs +0 -22
  273. package/skills/rea-analysis/SKILL.md +0 -222
@@ -1,5 +1,6 @@
1
1
  import { hopperStartupFailure, } from "./hopperStartupFailure.js";
2
2
  export { hopperStartupFailure };
3
+ export { projectAnalysisError } from "./analysisErrorProjection.js";
3
4
  /** Stable tags exposed by safe analysis-error projections. */
4
5
  const ANALYSIS_ERROR_TAGS = [
5
6
  "AnalysisProtocolError",
@@ -331,13 +332,14 @@ export class BinaryTargetError extends AnalysisError {
331
332
  }
332
333
  /** Exact denied authority used by both CLI and MCP remediation. */
333
334
  export class PermissionRequiredError extends AnalysisError {
335
+ _tag = "PermissionRequiredError";
334
336
  requested;
335
337
  missing;
336
338
  ceiling;
337
339
  elicitationSupported;
338
340
  restartRequired;
339
- _tag = "PermissionRequiredError";
340
- constructor(requested, missing, ceiling, elicitationSupported, restartRequired) {
341
+ constructor(...args) {
342
+ const [requested, missing, ceiling, elicitationSupported, restartRequired] = args;
341
343
  super(`Permission required for ${requested.capability}`);
342
344
  this.requested = requested;
343
345
  this.missing = missing;
@@ -357,487 +359,3 @@ export class ReplayPlanStaleError extends AnalysisError {
357
359
  this.actualDigest = actualDigest;
358
360
  }
359
361
  }
360
- /** Project expected failures into exhaustive, secret-safe caller fields. */
361
- export const projectAnalysisError = (error) => {
362
- assertKnownTag(error._tag);
363
- const code = errorCode(error);
364
- const details = errorDetails(error);
365
- return {
366
- code,
367
- category: errorCategory(error),
368
- message: userMessage(error),
369
- retryable: RETRYABLE_CODES.has(code),
370
- remediation: {
371
- action: remediationAction(error),
372
- restart_required: error instanceof PermissionRequiredError && error.restartRequired,
373
- ...(error instanceof PermissionRequiredError
374
- ? { elicitation_supported: error.elicitationSupported }
375
- : {}),
376
- },
377
- ...(details === undefined ? {} : { details }),
378
- };
379
- };
380
- const errorCode = (error) => {
381
- if (error instanceof ReplayPlanStaleError)
382
- return "plan_stale";
383
- if (error instanceof PermissionRequiredError)
384
- return "permission_required";
385
- if (error instanceof ProviderSelectionError &&
386
- error.reason === "provider_unavailable")
387
- return "provider_unavailable";
388
- if (error instanceof BrowserObservationError) {
389
- if (error.reason === "payload_limit")
390
- return "truncated";
391
- if (error.reason === "target_not_found" ||
392
- error.reason === "target_not_allowed" ||
393
- error.reason === "target_changed")
394
- return "target_unavailable";
395
- if (error.reason === "endpoint_unreachable" ||
396
- error.reason === "disconnected")
397
- return "provider_unavailable";
398
- return "unreadable_output";
399
- }
400
- if (error instanceof ArtifactOperationError)
401
- return error.reason === "integrity" && error.artifactDetails !== undefined
402
- ? "artifact_integrity_mismatch"
403
- : error.reason === "limit"
404
- ? "truncated"
405
- : error.reason === "cancelled"
406
- ? "cancelled"
407
- : "artifact_operation_failed";
408
- if (error instanceof EvidenceFileError)
409
- return error.reason === "outside-root"
410
- ? "outside_approved_root"
411
- : error.reason === "too-large"
412
- ? "truncated"
413
- : error.reason === "disabled"
414
- ? "capability_unavailable"
415
- : "execution_failure";
416
- if (error instanceof InvestigationWorkspaceError) {
417
- if (error.reason === "revision-conflict" ||
418
- error.reason === "name-conflict")
419
- return "revision_conflict";
420
- if (error.reason === "too-large")
421
- return "truncated";
422
- if (error.reason === "disabled")
423
- return "capability_unavailable";
424
- if (error.reason === "outside-root")
425
- return "outside_approved_root";
426
- if (error.reason === "integrity" || error.reason === "invalid-json")
427
- return "evidence_integrity_mismatch";
428
- return "execution_failure";
429
- }
430
- if (error instanceof UnknownRegistryError)
431
- return error.reason === "revision-conflict" ||
432
- error.reason === "already-exists"
433
- ? "revision_conflict"
434
- : error.reason === "limit"
435
- ? "truncated"
436
- : error.reason === "integrity"
437
- ? "evidence_integrity_mismatch"
438
- : "execution_failure";
439
- if (error._tag === "ProcessCaptureError")
440
- return error.cleanupIncomplete
441
- ? "cleanup_incomplete"
442
- : error.userCategory === "cancelled"
443
- ? "cancelled"
444
- : error.userCategory === "permission_required"
445
- ? "permission_required"
446
- : "process_capture_failed";
447
- switch (error._tag) {
448
- case "AnalysisProtocolError":
449
- case "AnalysisOutputError":
450
- case "HopperProtocolError":
451
- return "unreadable_output";
452
- case "AnalysisInputError":
453
- return "invalid_request";
454
- case "AnalysisCapabilityUnavailableError":
455
- case "ProviderSelectionError":
456
- return "capability_unavailable";
457
- case "AnalysisCancelledError":
458
- case "HopperCancelledError":
459
- return "cancelled";
460
- case "AnalysisTimeoutError":
461
- case "HopperTimeoutError":
462
- return "provider_timeout";
463
- case "HopperProcessError":
464
- case "HopperStartError":
465
- return "provider_unavailable";
466
- case "ConfigurationError":
467
- return "configuration_invalid";
468
- case "NoBinaryOpenError":
469
- case "BinaryTargetError":
470
- return "target_unavailable";
471
- case "EvidenceIntegrityError":
472
- return "evidence_integrity_mismatch";
473
- case "EvidenceLimitError":
474
- return "truncated";
475
- case "ProviderAdapterError":
476
- case "HopperRemoteError":
477
- return "execution_failure";
478
- case "BrowserObservationError":
479
- throw new TypeError("Unhandled specialized browser error");
480
- case "ArtifactOperationError":
481
- case "EvidenceFileError":
482
- case "InvestigationWorkspaceError":
483
- case "UnknownRegistryError":
484
- case "PermissionRequiredError":
485
- throw new TypeError("Unhandled specialized analysis error");
486
- case "ReplayPlanStaleError":
487
- throw new TypeError("Unhandled specialized replay error");
488
- }
489
- };
490
- const errorDetails = (error) => {
491
- if (error instanceof AnalysisInputError && error.issues.length > 0)
492
- return {
493
- operation: error.operation,
494
- issues: error.issues.map((issue) => ({
495
- path: [...issue.path],
496
- reason: issue.reason,
497
- ...(issue.expected === undefined ? {} : { expected: issue.expected }),
498
- ...(issue.minimum === undefined ? {} : { minimum: issue.minimum }),
499
- ...(issue.maximum === undefined ? {} : { maximum: issue.maximum }),
500
- })),
501
- };
502
- if (error instanceof EvidenceReferenceError)
503
- return {
504
- evidence_id: error.evidenceId,
505
- reason: error.reason,
506
- expected: error.expected,
507
- actual: error.actual,
508
- };
509
- if (error instanceof ReplayPlanStaleError)
510
- return {
511
- approved_plan_digest: error.approvedDigest,
512
- actual_plan_digest: error.actualDigest,
513
- application_code_admitted: false,
514
- };
515
- if (error instanceof PermissionRequiredError)
516
- return {
517
- capability: error.requested.capability,
518
- requested: scopeDetails(error.requested),
519
- missing: missingScopeDetails(error.missing),
520
- ceiling: error.ceiling === null ? null : scopeDetails(error.ceiling),
521
- };
522
- if (error instanceof ArtifactOperationError && error.artifactDetails)
523
- return {
524
- logical_path: error.artifactDetails.logicalPath,
525
- declared_sha256: error.artifactDetails.declaredSha256,
526
- calculated_sha256: error.artifactDetails.calculatedSha256,
527
- unpacked: error.artifactDetails.unpacked,
528
- };
529
- if (error instanceof ArtifactOperationError)
530
- return {
531
- operation: error.operation,
532
- reason: error.reason,
533
- ...(error.reason === "limit" ? { truncated: true } : {}),
534
- };
535
- if (error instanceof AnalysisCancelledError)
536
- return { operation: error.operation, cleanup: "complete" };
537
- if (error instanceof HopperCancelledError)
538
- return { operation: "hopper", cleanup: "complete" };
539
- if (error instanceof AnalysisTimeoutError)
540
- return { operation: error.operation, timeout_ms: error.timeoutMs };
541
- if (error instanceof HopperTimeoutError)
542
- return { operation: "hopper", timeout_ms: error.timeoutMs };
543
- if (error instanceof EvidenceLimitError)
544
- return { limit: error.limit, maximum: error.maximum, truncated: true };
545
- if (error instanceof InvestigationWorkspaceError)
546
- return { operation: error.operation, reason: error.reason };
547
- if (error instanceof UnknownRegistryError)
548
- return { reason: error.reason };
549
- if (error instanceof EvidenceFileError)
550
- return { operation: error.operation, reason: error.reason };
551
- if (error instanceof AnalysisCapabilityUnavailableError)
552
- return { provider_id: error.providerId, operation: error.operation };
553
- if (error instanceof ProviderSelectionError)
554
- return {
555
- operation: error.operation,
556
- selection_reason: error.reason,
557
- requested_provider_id: error.requestedProviderId,
558
- candidate_ids: [...error.candidateIds],
559
- rejections: error.rejections.map((rejection) => ({
560
- provider_id: rejection.providerId,
561
- code: rejection.code,
562
- reason: rejection.reason,
563
- diagnostics: rejection.diagnostics,
564
- })),
565
- };
566
- if (error instanceof ProviderAdapterError)
567
- return {
568
- provider_id: error.providerId,
569
- operation: error.operation,
570
- ...(error.diagnostics === undefined
571
- ? {}
572
- : { diagnostics: error.diagnostics }),
573
- };
574
- if (error instanceof BrowserObservationError)
575
- return { operation: error.operation, reason: error.reason };
576
- if (error instanceof HopperRemoteError)
577
- return { provider_code: error.code, diagnostic_type: error.diagnosticType };
578
- if (error instanceof HopperProcessError && error.failureCode !== undefined)
579
- return { failure_code: error.failureCode, exit_code: error.exitCode };
580
- if (error._tag === "ProcessCaptureError" && error.cleanupIncomplete)
581
- return {
582
- cleanup: "incomplete",
583
- resources: [...error.cleanupResources],
584
- };
585
- if (error._tag === "ProcessCaptureError" &&
586
- error.userCategory === "cancelled")
587
- return { operation: "process_capture", cleanup: "complete" };
588
- if (error instanceof BinaryTargetError)
589
- return { path: error.path };
590
- return undefined;
591
- };
592
- const scopeDetails = (scope) => ({
593
- capability: scope.capability,
594
- roots: [...scope.roots],
595
- executables: [...scope.executables],
596
- environment_names: [...scope.environment_names],
597
- ...(scope.origins === undefined ? {} : { origins: [...scope.origins] }),
598
- network: scope.network,
599
- mount: scope.mount,
600
- });
601
- const missingScopeDetails = (scope) => ({
602
- ...(scope.roots === undefined ? {} : { roots: [...scope.roots] }),
603
- ...(scope.executables === undefined
604
- ? {}
605
- : { executables: [...scope.executables] }),
606
- ...(scope.environment_names === undefined
607
- ? {}
608
- : { environment_names: [...scope.environment_names] }),
609
- ...(scope.origins === undefined ? {} : { origins: [...scope.origins] }),
610
- ...(scope.network === undefined ? {} : { network: scope.network }),
611
- ...(scope.mount === undefined ? {} : { mount: scope.mount }),
612
- });
613
- const RETRYABLE_CODES = new Set([
614
- "invalid_request",
615
- "provider_timeout",
616
- "cancelled",
617
- "revision_conflict",
618
- "provider_unavailable",
619
- ]);
620
- const remediationAction = (error) => {
621
- if (error instanceof AnalysisInputError)
622
- return "Correct the listed arguments and retry.";
623
- if (error instanceof ReplayPlanStaleError)
624
- return "Review the rebuilt replay plan and explicitly approve its new digest.";
625
- if (error instanceof PermissionRequiredError)
626
- return error.elicitationSupported
627
- ? "Approve the exact missing scope, then retry the operation."
628
- : "Add the exact missing scope beneath the administrator ceiling, then retry.";
629
- return userMessage(error);
630
- };
631
- const errorCategory = (error) => {
632
- if (error instanceof ReplayPlanStaleError)
633
- return "integrity_mismatch";
634
- if (error instanceof PermissionRequiredError)
635
- return "permission_required";
636
- if (error instanceof ProviderSelectionError &&
637
- error.reason === "provider_unavailable")
638
- return "unavailable";
639
- if (error._tag === "ProcessCaptureError")
640
- return error.userCategory ?? "execution_failure";
641
- if (error instanceof BrowserObservationError) {
642
- if (error.reason === "payload_limit")
643
- return "truncated";
644
- if (error.reason === "target_not_found" ||
645
- error.reason === "target_not_allowed" ||
646
- error.reason === "target_changed" ||
647
- error.reason === "endpoint_unreachable" ||
648
- error.reason === "disconnected")
649
- return "unavailable";
650
- }
651
- if (error instanceof HopperRemoteError &&
652
- error.diagnosticType === "authorization")
653
- return "permission_required";
654
- if (error instanceof ArtifactOperationError)
655
- return artifactErrorCategory(error.reason);
656
- if (error instanceof EvidenceFileError && error.reason === "disabled")
657
- return "unavailable";
658
- if (error instanceof InvestigationWorkspaceError)
659
- return investigationWorkspaceCategory(error.reason);
660
- return STATIC_ERROR_CATEGORIES[error._tag] ?? "execution_failure";
661
- };
662
- const investigationWorkspaceCategory = (reason) => {
663
- if (reason === "disabled" ||
664
- reason === "outside-root" ||
665
- reason === "not-file")
666
- return "unavailable";
667
- if (reason === "too-large")
668
- return "truncated";
669
- if (reason === "invalid-json" || reason === "integrity")
670
- return "integrity_mismatch";
671
- return "execution_failure";
672
- };
673
- const artifactErrorCategory = (reason) => {
674
- if (reason === "integrity")
675
- return "integrity_mismatch";
676
- if (reason === "limit")
677
- return "truncated";
678
- if (reason === "cancelled")
679
- return "cancelled";
680
- if (reason === "unavailable")
681
- return "unavailable";
682
- return "execution_failure";
683
- };
684
- const STATIC_ERROR_CATEGORIES = {
685
- AnalysisInputError: "invalid_input",
686
- AnalysisCapabilityUnavailableError: "unsupported_provider",
687
- ProviderSelectionError: "unsupported_provider",
688
- EvidenceIntegrityError: "integrity_mismatch",
689
- EvidenceLimitError: "truncated",
690
- AnalysisCancelledError: "cancelled",
691
- HopperCancelledError: "cancelled",
692
- AnalysisTimeoutError: "timeout",
693
- HopperTimeoutError: "timeout",
694
- NoBinaryOpenError: "unavailable",
695
- BinaryTargetError: "unavailable",
696
- };
697
- const userMessage = (error) => {
698
- if (error instanceof ReplayPlanStaleError)
699
- return "The controlled replay plan changed before execution. Refresh the current state and try again.";
700
- if (error instanceof PermissionRequiredError)
701
- return "This operation needs additional local permission. Review the requested scope and remediation.";
702
- if (error instanceof AnalysisInputError)
703
- return "Analysis input is invalid. Check the arguments and try again.";
704
- if (error.userMessage !== undefined)
705
- return error.userMessage;
706
- if (UNREADABLE_OUTPUT_TAGS.has(error._tag))
707
- return "Analysis returned an unreadable result. Retry once; if it continues, run `rea doctor`.";
708
- if (UNSUPPORTED_PROVIDER_TAGS.has(error._tag))
709
- return "This analysis is unavailable for the current target. Choose another analysis or target.";
710
- if (CANCELLED_TAGS.has(error._tag))
711
- return "Analysis was cancelled. Start it again when ready.";
712
- if (TIMEOUT_TAGS.has(error._tag))
713
- return "Analysis took too long. Try a smaller request, then run `rea doctor` if it continues.";
714
- if (ADAPTER_FAILURE_TAGS.has(error._tag))
715
- return "Analysis could not complete. Retry once; if it continues, run `rea doctor`.";
716
- if (START_FAILURE_TAGS.has(error._tag))
717
- return "Analysis could not start or stopped unexpectedly. Run `rea doctor`, then try again.";
718
- if (error instanceof ArtifactOperationError)
719
- return artifactMessage(error.reason);
720
- if (error instanceof EvidenceIntegrityError)
721
- return "Evidence is invalid or has changed. Recreate or re-import it, then try again.";
722
- if (error instanceof EvidenceLimitError)
723
- return "Evidence is too large for this session. Reduce the evidence set and try again.";
724
- if (error instanceof EvidenceFileError)
725
- return evidenceFileMessage(error.reason);
726
- if (error instanceof InvestigationWorkspaceError)
727
- return investigationWorkspaceMessage(error.reason);
728
- if (error instanceof UnknownRegistryError)
729
- return "Evidence state changed before the update completed. Refresh the current state and try again.";
730
- if (error instanceof ConfigurationError)
731
- return "REA configuration is invalid. Run `rea doctor` and fix the reported setting.";
732
- if (error instanceof NoBinaryOpenError)
733
- return error.message;
734
- if (error instanceof BinaryTargetError)
735
- return "REA could not open that app or binary. Check that the path exists, is readable, and points to a supported file.";
736
- if (error._tag === "ProcessCaptureError")
737
- return (error.userMessage ??
738
- "Process capture could not complete. Run `rea doctor`, then review capture policy and try again.");
739
- return "Analysis could not complete. Run `rea doctor`, then try again.";
740
- };
741
- const UNREADABLE_OUTPUT_TAGS = new Set([
742
- "AnalysisProtocolError",
743
- "AnalysisOutputError",
744
- "HopperProtocolError",
745
- ]);
746
- const UNSUPPORTED_PROVIDER_TAGS = new Set([
747
- "AnalysisCapabilityUnavailableError",
748
- "ProviderSelectionError",
749
- ]);
750
- const CANCELLED_TAGS = new Set([
751
- "AnalysisCancelledError",
752
- "HopperCancelledError",
753
- ]);
754
- const TIMEOUT_TAGS = new Set([
755
- "AnalysisTimeoutError",
756
- "HopperTimeoutError",
757
- ]);
758
- const ADAPTER_FAILURE_TAGS = new Set([
759
- "ProviderAdapterError",
760
- "HopperRemoteError",
761
- ]);
762
- const START_FAILURE_TAGS = new Set([
763
- "HopperProcessError",
764
- "HopperStartError",
765
- ]);
766
- const artifactMessage = (reason) => {
767
- if (reason === "cancelled")
768
- return "Artifact operation was cancelled. Start it again when ready.";
769
- if (reason === "limit")
770
- return "Artifact is too large to process safely. Narrow the requested path or use a smaller artifact.";
771
- if (reason === "path")
772
- return "Artifact path is not allowed. Choose a path inside the artifact and try again.";
773
- if (reason === "unavailable")
774
- return "Artifact format is not available on this system. Choose another artifact or supported environment.";
775
- if (reason === "format" || reason === "integrity")
776
- return "Artifact is invalid or has changed. Get a fresh copy and try again.";
777
- return "Artifact could not be read or written. Check file access and try again.";
778
- };
779
- const evidenceFileMessage = (reason) => {
780
- if (reason === "disabled")
781
- return "Evidence file access is disabled. Enable an evidence directory or use inline evidence.";
782
- if (reason === "outside-root")
783
- return "Evidence path is outside the allowed directory. Choose a path inside the configured evidence directory.";
784
- if (reason === "not-file")
785
- return "Evidence path does not point to a file. Choose an evidence file and try again.";
786
- if (reason === "too-large")
787
- return "Evidence file is too large. Reduce its size and try again.";
788
- if (reason === "exists")
789
- return "Evidence file already exists. Choose another path or allow overwrite.";
790
- if (reason === "invalid-json")
791
- return "Evidence file is not valid JSON. Repair or recreate the file and try again.";
792
- return "Evidence file could not be accessed. Check file permissions and try again.";
793
- };
794
- const investigationWorkspaceMessage = (reason) => {
795
- if (reason === "disabled")
796
- return "Investigation workspace access is disabled. Configure a workspace directory and try again.";
797
- if (reason === "outside-root")
798
- return "Investigation workspace is outside the allowed directory. Choose a configured workspace directory and try again.";
799
- if (reason === "not-file")
800
- return "Investigation workspace path is not a file. Choose a workspace file and try again.";
801
- if (reason === "too-large")
802
- return "Investigation workspace is too large. Reduce its size and try again.";
803
- if (reason === "invalid-json" || reason === "integrity")
804
- return "Investigation workspace is invalid or has changed. Recreate or repair it, then try again.";
805
- if (reason === "locked")
806
- return "Another investigation update is in progress. Try again when it finishes.";
807
- if (reason === "revision-conflict" || reason === "name-conflict")
808
- return "Investigation workspace state changed. Refresh the current state and try again.";
809
- return "Investigation workspace could not be accessed. Check file permissions and try again.";
810
- };
811
- const KNOWN_ERROR_TAGS = {
812
- AnalysisProtocolError: true,
813
- AnalysisInputError: true,
814
- AnalysisOutputError: true,
815
- AnalysisCapabilityUnavailableError: true,
816
- AnalysisCancelledError: true,
817
- AnalysisTimeoutError: true,
818
- ProviderSelectionError: true,
819
- ProviderAdapterError: true,
820
- BrowserObservationError: true,
821
- ArtifactOperationError: true,
822
- ProcessCaptureError: true,
823
- EvidenceIntegrityError: true,
824
- EvidenceLimitError: true,
825
- EvidenceFileError: true,
826
- InvestigationWorkspaceError: true,
827
- UnknownRegistryError: true,
828
- HopperTimeoutError: true,
829
- HopperCancelledError: true,
830
- HopperProtocolError: true,
831
- HopperRemoteError: true,
832
- HopperProcessError: true,
833
- HopperStartError: true,
834
- ConfigurationError: true,
835
- NoBinaryOpenError: true,
836
- BinaryTargetError: true,
837
- PermissionRequiredError: true,
838
- ReplayPlanStaleError: true,
839
- };
840
- const assertKnownTag = (tag) => {
841
- if (KNOWN_ERROR_TAGS[tag] !== true)
842
- throw new TypeError("Unknown analysis error tag");
843
- };