rea-agents 5.0.0 → 6.0.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 (275) hide show
  1. package/README.md +157 -650
  2. package/bridge/mitmproxy/capture.py +210 -0
  3. package/bridge/native/rea_lldb_tracer.py +303 -0
  4. package/bridge/process/ProcessRunTokenReader.swift +263 -0
  5. package/bridge/process/ProcessRunTokenReaderMain.swift +35 -0
  6. package/bridge/pwndbg/core_context.py +101 -0
  7. package/bridge/pwndbg/launch.py +39 -0
  8. package/bridge/pwndbg/launch_impl.py +34 -0
  9. package/bridge/pwntools/decoder_runtime.py +59 -0
  10. package/bridge/pwntools/layout.py +39 -0
  11. package/bridge/pwntools/layout_impl.py +309 -0
  12. package/bridge/pwntools/recorded_crash.py +39 -0
  13. package/bridge/pwntools/recorded_crash_impl.py +143 -0
  14. package/dist/android/JadxProvider.js +1 -0
  15. package/dist/application/CapabilityInventory.js +21 -0
  16. package/dist/application/DirectAnalysis.js +97 -23
  17. package/dist/application/EvidenceBundleFiles.js +1 -1
  18. package/dist/application/ReconstructionObligationCandidates.js +5 -1
  19. package/dist/application/WebNetworkCapturePort.js +1 -0
  20. package/dist/application/WebNetworkCaptureService.js +132 -0
  21. package/dist/application/WindowsCapabilities.js +1 -1
  22. package/dist/application/binary/AnalysisSnapshotCache.js +49 -6
  23. package/dist/application/binary/BinarySession.js +38 -10
  24. package/dist/application/binary/BinarySessionOpen.js +16 -3
  25. package/dist/application/binary/BinarySessionRecords.js +20 -0
  26. package/dist/application/binaryDiagnostics/BinaryLayoutPort.js +1 -0
  27. package/dist/application/binaryDiagnostics/BinaryLayoutService.js +57 -0
  28. package/dist/application/binaryDiagnostics/RecordedCrashPort.js +1 -0
  29. package/dist/application/binaryDiagnostics/RecordedCrashService.js +60 -0
  30. package/dist/application/evm/EvmInterfacePort.js +1 -0
  31. package/dist/application/evm/EvmInterfaceService.js +62 -0
  32. package/dist/application/javascript/JavaScriptApplicationEvidence.js +1 -2
  33. package/dist/application/javascript/JavaScriptApplicationService.js +15 -2
  34. package/dist/application/javascript/JavaScriptArtifactAnalysis.js +42 -23
  35. package/dist/application/javascript/JavaScriptArtifactGraphDocuments.js +26 -2
  36. package/dist/application/javascript/JavaScriptArtifactPathResolution.js +74 -24
  37. package/dist/application/javascript/JavaScriptArtifactReconstruction.js +23 -10
  38. package/dist/application/javascript/JavaScriptSemanticGraphAsyncProjection.js +7 -7
  39. package/dist/application/javascript/JavaScriptSemanticGraphBuilder.js +145 -70
  40. package/dist/application/javascript/JavaScriptSemanticGraphChildProcessProjection.js +14 -15
  41. package/dist/application/javascript/JavaScriptSemanticGraphConstruction.js +41 -1
  42. package/dist/application/javascript/JavaScriptSemanticGraphDataProjection.js +7 -7
  43. package/dist/application/javascript/JavaScriptSemanticGraphFlowProjection.js +5 -9
  44. package/dist/application/javascript/JavaScriptSemanticGraphObjectProjection.js +3 -3
  45. package/dist/application/javascript/JavaScriptSemanticGraphProjection.js +118 -12
  46. package/dist/application/javascript/JavaScriptSemanticGraphResourceProjection.js +3 -3
  47. package/dist/application/javascript/JavaScriptSemanticGraphValueProjection.js +5 -5
  48. package/dist/application/{ProcessCli.js → process/ProcessCli.js} +10 -10
  49. package/dist/application/{ProcessEvidence.js → process/ProcessEvidence.js} +4 -4
  50. package/dist/artifacts/ArtifactProvider.js +30 -3
  51. package/dist/artifacts/ArtifactProviderMetadata.js +2 -1
  52. package/dist/artifacts/ZipArtifactReader.js +3 -0
  53. package/dist/artifacts/apple/DylibResolutionReader.js +259 -0
  54. package/dist/artifacts/apple/MachoLoadCommandReader.js +294 -0
  55. package/dist/{application → artifacts/extraction}/ArtifactExtraction.js +10 -10
  56. package/dist/{application → artifacts/inventory}/ArtifactGraphConstruction.js +3 -3
  57. package/dist/{application → artifacts/inventory}/ArtifactInventory.js +4 -4
  58. package/dist/{application/ArtifactInventory → artifacts/inventory}/classify.js +2 -2
  59. package/dist/{application/ArtifactInventory → artifacts/inventory}/reader.js +5 -5
  60. package/dist/{application/ArtifactInventory → artifacts/inventory}/scanCanonical.js +3 -3
  61. package/dist/{application/ArtifactInventory → artifacts/inventory}/scanReader.js +5 -5
  62. package/dist/artifacts/readStableArtifact.js +20 -4
  63. package/dist/browser/CdpCaptureEventHandlers.js +90 -2
  64. package/dist/browser/CdpCaptureEvents.js +9 -0
  65. package/dist/browser/PlaywrightElectronActiveProvider.js +12 -3
  66. package/dist/browser/history/CaptureFailures.js +101 -0
  67. package/dist/browser/history/CaptureFormatError.js +10 -0
  68. package/dist/browser/history/CaptureRedaction.js +65 -0
  69. package/dist/browser/history/CaptureRelease.js +12 -0
  70. package/dist/browser/history/HarCapture.js +165 -0
  71. package/dist/browser/history/HarCaptureAdapter.js +20 -0
  72. package/dist/browser/history/HarCaptureProcess.js +57 -0
  73. package/dist/browser/history/HarJson.js +91 -0
  74. package/dist/browser/history/HarSchema.js +72 -0
  75. package/dist/browser/history/HistoricalCaptureDecoder.js +186 -0
  76. package/dist/browser/history/HistoricalCaptureFormatAdapter.js +1 -0
  77. package/dist/browser/history/MitmproxyCaptureAdapter.js +42 -0
  78. package/dist/cli/artifactCommands.js +26 -1
  79. package/dist/cli/binaryDiagnosticsCommands.js +39 -0
  80. package/dist/cli/coreAnalysisCommands.js +2 -2
  81. package/dist/cli/coreBinaryCommands.js +8 -8
  82. package/dist/cli/electronCommands.js +16 -9
  83. package/dist/cli/evmCommands.js +24 -0
  84. package/dist/cli/firmwareCommands.js +6 -3
  85. package/dist/cli/javascriptApplicationAnalysis.js +16 -3
  86. package/dist/cli/jsonOutput.js +133 -0
  87. package/dist/cli/nativeCallCommands.js +35 -0
  88. package/dist/cli/processCommands.js +1 -1
  89. package/dist/cli/streamedJsonOutput.js +56 -0
  90. package/dist/cli/utilityCommands.js +2 -0
  91. package/dist/cli/webNetworkCaptureCommands.js +40 -0
  92. package/dist/cli.js +9 -3
  93. package/dist/cliBrowserScenarioCommands.js +2 -2
  94. package/dist/cliCommandNames.js +6 -0
  95. package/dist/cliJsonInput.js +30 -1
  96. package/dist/cliOutput.js +21 -6
  97. package/dist/composition/binaryDiagnostics.js +8 -0
  98. package/dist/composition/evm.js +4 -0
  99. package/dist/composition/webNetworkCaptures.js +6 -0
  100. package/dist/contracts/artifactToolContracts.js +6 -0
  101. package/dist/contracts/browserCaptureToolInputSchema.js +43 -0
  102. package/dist/contracts/browserToolContracts.js +4 -3
  103. package/dist/contracts/errorSchemas.js +8 -1
  104. package/dist/contracts/evm/evmToolContracts.js +20 -0
  105. package/dist/contracts/investigationExamples.js +2 -2
  106. package/dist/contracts/managed/managedToolContracts.js +7 -3
  107. package/dist/contracts/native/binaryDiagnosticsToolContracts.js +42 -0
  108. package/dist/contracts/native/nativeToolContracts.js +17 -1
  109. package/dist/contracts/officialToolContracts.js +12 -9
  110. package/dist/contracts/process/processCaptureExample.js +2 -0
  111. package/dist/contracts/sessionLifecycleInputs.js +22 -5
  112. package/dist/contracts/sessionStatusContract.js +10 -2
  113. package/dist/contracts/sessionToolContracts.js +8 -1
  114. package/dist/contracts/sessionToolSchemas.js +10 -3
  115. package/dist/contracts/toolContractExamples.js +1 -1
  116. package/dist/contracts/toolContracts.js +6 -0
  117. package/dist/contracts/toolEffects.js +30 -0
  118. package/dist/contracts/toolOutputSchemaGroups.js +5 -1
  119. package/dist/contracts/toolOutputSchemaPrimitives.js +1 -1
  120. package/dist/contracts/webNetworkCaptureToolContracts.js +24 -0
  121. package/dist/domain/analysisErrorBase.js +15 -0
  122. package/dist/domain/analysisErrorCore.js +59 -5
  123. package/dist/domain/analysisErrorPresentation.js +29 -1
  124. package/dist/domain/analysisErrorProjection.js +52 -2
  125. package/dist/domain/analysisSnapshot.js +166 -2
  126. package/dist/domain/apple/dyldPaths.js +81 -0
  127. package/dist/domain/apple/dylibResolution.js +367 -0
  128. package/dist/domain/apple/dylibResolutionFindings.js +75 -0
  129. package/dist/domain/artifactPathSyntax.js +1 -1
  130. package/dist/domain/browserObservation.js +1 -1
  131. package/dist/domain/browserObservationSchemas.js +13 -0
  132. package/dist/domain/browserScenarioValues.js +9 -2
  133. package/dist/domain/callPathSchemas.js +1 -1
  134. package/dist/domain/canonicalDigest.js +13 -1
  135. package/dist/domain/changedBehavior.js +3 -3
  136. package/dist/domain/comparisonStatus.js +2 -30
  137. package/dist/domain/conformanceTrustGate.js +0 -16
  138. package/dist/domain/evidence.js +17 -5
  139. package/dist/domain/evm/evmInterface.js +63 -0
  140. package/dist/domain/explicitSensitiveFailure.js +92 -0
  141. package/dist/domain/explicitSensitiveValues.js +10 -0
  142. package/dist/domain/firmware/firmwareAnalysis.js +8 -1
  143. package/dist/domain/javascript/electronActiveObservation.js +9 -4
  144. package/dist/domain/javascript/htmlArtifactReferences.js +40 -0
  145. package/dist/domain/javascript/javascriptExportShapeComparison.js +21 -5
  146. package/dist/domain/javascript/javascriptExportShapeVariants.js +0 -10
  147. package/dist/domain/javascript/javascriptSemanticGraph.js +21 -5
  148. package/dist/domain/jsonValue.js +4 -0
  149. package/dist/domain/localPath.js +2 -0
  150. package/dist/domain/native/binaryLayout.js +357 -0
  151. package/dist/domain/native/nativeCallObservation.js +164 -0
  152. package/dist/domain/native/objcSwiftMetadata.js +0 -39
  153. package/dist/domain/native/recordedCrash.js +266 -0
  154. package/dist/domain/native/recordedCrashNoteCoverage.js +73 -0
  155. package/dist/domain/{processCapture.js → process/processCapture.js} +139 -2
  156. package/dist/domain/{processCaptureExample.js → process/processCaptureExample.js} +5 -0
  157. package/dist/domain/process/processCaptureParsing.js +54 -0
  158. package/dist/domain/{processCaptureValidation.js → process/processCaptureValidation.js} +18 -2
  159. package/dist/domain/{processComparison.js → process/processComparison.js} +1 -1
  160. package/dist/domain/{processObservation.js → process/processObservation.js} +1 -1
  161. package/dist/domain/{processTraceSpecification.js → process/processTraceSpecification.js} +1 -1
  162. package/dist/domain/providerSelectionError.js +4 -2
  163. package/dist/domain/reconstructionVerification.js +3 -3
  164. package/dist/domain/reconstructionVerificationSchemas.js +1 -1
  165. package/dist/domain/residualUnknown.js +3 -2
  166. package/dist/domain/staticRuntimeCorrelation.js +3 -3
  167. package/dist/domain/webCaptureDiff.js +1 -0
  168. package/dist/domain/webNetworkCapture.js +118 -0
  169. package/dist/domain/webNetworkCaptureCoordinates.js +58 -0
  170. package/dist/dotnet/ManagedExceptionRegionValidation.js +41 -0
  171. package/dist/dotnet/ManagedMemberInspector.js +4 -2
  172. package/dist/dotnet/ManagedMemberInspectorCore.js +38 -32
  173. package/dist/dotnet/ManagedMemberInstructionDecoder.js +23 -7
  174. package/dist/dotnet/ManagedMemberRows.js +14 -3
  175. package/dist/dotnet/ManagedMetadataHeaps.js +20 -2
  176. package/dist/dotnet/ManagedMetadataInventory.js +38 -28
  177. package/dist/dotnet/ManagedMetadataInventoryRows.js +24 -10
  178. package/dist/dotnet/ManagedMethodBodyReader.js +7 -1
  179. package/dist/dotnet/ManagedNativeBoundaryHelpers.js +15 -3
  180. package/dist/dotnet/ManagedNativeBoundaryInspector.js +3 -1
  181. package/dist/dotnet/ManagedPeReader.js +11 -0
  182. package/dist/evm/EvmBytecodeCarrier.js +21 -0
  183. package/dist/evm/EvmWorkerLimits.js +40 -0
  184. package/dist/evm/EvmoleFailures.js +126 -0
  185. package/dist/evm/EvmoleInterfaceAdapter.js +53 -0
  186. package/dist/evm/EvmoleInterfaceProvider.js +273 -0
  187. package/dist/evm/EvmoleInterfaceWorker.js +87 -0
  188. package/dist/evm/EvmoleRelease.js +16 -0
  189. package/dist/firmware/FirmwareCommand.js +1 -0
  190. package/dist/generatedPackageMetadata.js +2 -2
  191. package/dist/ghidra/GhidraLauncher.js +1 -0
  192. package/dist/ghidra/GhidraProvider.js +2 -2
  193. package/dist/ghidra/GhidraProviderCapabilities.js +1 -1
  194. package/dist/hopper/BridgeLauncher.js +2 -0
  195. package/dist/hopper/LinuxPrivateDisplayProbe.js +4 -2
  196. package/dist/javascript/recovery/WakaruCommand.js +3 -0
  197. package/dist/javascript/sourceMaps/SourceMapCommand.js +1 -0
  198. package/dist/native/CommandRunner.js +2 -1
  199. package/dist/native/LldbCallTracer.js +278 -0
  200. package/dist/native/NativeCallObservation.js +135 -0
  201. package/dist/native/NativeMacOSProvider.js +19 -3
  202. package/dist/native/NativeMacOSProviderMetadata.js +8 -3
  203. package/dist/native/pwndbg/PwndbgCoreContext.js +160 -0
  204. package/dist/native/pwntools/PwntoolsDecoder.js +203 -0
  205. package/dist/native/pwntools/PwntoolsFailures.js +180 -0
  206. package/dist/native/pwntools/PwntoolsLayoutProvider.js +36 -0
  207. package/dist/native/pwntools/PwntoolsRecordedCrashProvider.js +75 -0
  208. package/dist/native/pwntools/PwntoolsRelease.js +19 -0
  209. package/dist/native/pwntools/PwntoolsResourceLimits.js +76 -0
  210. package/dist/native/pwntools/RecordedCrashSourceBindings.js +46 -0
  211. package/dist/native/pwntools/RecordedCrashStructureBindings.js +101 -0
  212. package/dist/process/DarwinProcessRunTokenReader.js +294 -0
  213. package/dist/process/OwnedCommand.js +113 -0
  214. package/dist/process/ProcessOwnership.js +263 -33
  215. package/dist/process/ProcessOwnershipObservation.js +161 -24
  216. package/dist/process/ProviderProcess.js +30 -3
  217. package/dist/{application → process/capture}/ProcessCaptureCapability.js +15 -0
  218. package/dist/{application → process/capture}/ProcessCaptureError.js +17 -1
  219. package/dist/process/capture/ProcessCaptureLifecycle.js +615 -0
  220. package/dist/{application → process/capture}/ProcessHarness.js +195 -29
  221. package/dist/{application → process/capture}/ProcessSampling.js +2 -2
  222. package/dist/server/createServer.js +22 -0
  223. package/dist/server/promptCompletion.js +10 -3
  224. package/dist/server/registerBinaryDiagnosticsTools.js +17 -0
  225. package/dist/server/registerEvidenceTools.js +1 -1
  226. package/dist/server/registerEvmTools.js +17 -0
  227. package/dist/server/registerProcessComparisonTool.js +1 -1
  228. package/dist/server/registerRecordedCrashTools.js +17 -0
  229. package/dist/server/registerSessionTools.js +2 -2
  230. package/dist/server/registerWebNetworkCaptureTool.js +28 -0
  231. package/dist/server/sessionAvailabilityPolicy.js +3 -0
  232. package/dist/server/sessionToolPolicies.js +1 -1
  233. package/dist/server/toolResult.js +1 -1
  234. package/native/windows/build/manifest.json +2 -2
  235. package/native/windows/build/rea-windows-x64.node +0 -0
  236. package/package.json +37 -9
  237. package/scripts/rea.mjs +11 -3
  238. package/skills/reverse-engineer-anything/SKILL.md +23 -3
  239. package/skills/reverse-engineer-anything/references/native-and-artifacts.md +29 -0
  240. package/third_party/README.md +60 -0
  241. package/third_party/evmole/LICENSE +21 -0
  242. package/third_party/evmole/README.md +22 -0
  243. package/third_party/pwndbg/LICENSE.md +21 -0
  244. package/third_party/pwndbg/README.md +23 -0
  245. package/third_party/pwntools/README.md +40 -0
  246. package/dist/application/AuthorizedArtifactInventory.js +0 -7
  247. package/dist/application/ProcessCaptureLifecycle.js +0 -299
  248. package/dist/application/StoreFileLock.js +0 -124
  249. package/dist/contracts/processCaptureExample.js +0 -2
  250. package/dist/domain/bytecodeProvider.js +0 -178
  251. package/dist/domain/customProtocolCapture.js +0 -137
  252. package/dist/domain/eventProcessTree.js +0 -225
  253. package/dist/domain/mobileApplicationInvestigation.js +0 -159
  254. package/dist/domain/packageAnalysis.js +0 -123
  255. package/dist/domain/peInspection.js +0 -197
  256. package/dist/domain/processCaptureParsing.js +0 -21
  257. package/dist/domain/protocolCapture.js +0 -217
  258. package/dist/domain/runtimeIdentification.js +0 -212
  259. package/dist/generatedMcpToolCatalog.js +0 -37
  260. /package/dist/application/{ArtifactExtractionDestination.js → artifacts/ArtifactExtractionDestination.js} +0 -0
  261. /package/dist/{application/ArtifactInventory → artifacts/inventory}/policy.js +0 -0
  262. /package/dist/{application/ArtifactInventory → artifacts/inventory}/types.js +0 -0
  263. /package/dist/domain/{processEvidenceProvider.js → process/processEvidenceProvider.js} +0 -0
  264. /package/dist/domain/{processScenario.js → process/processScenario.js} +0 -0
  265. /package/dist/domain/{processTraceComparison.js → process/processTraceComparison.js} +0 -0
  266. /package/dist/domain/{processTraceDimensionProjection.js → process/processTraceDimensionProjection.js} +0 -0
  267. /package/dist/domain/{processTraceEvaluation.js → process/processTraceEvaluation.js} +0 -0
  268. /package/dist/{application → process/capture}/FilesystemSnapshot.js +0 -0
  269. /package/dist/{application → process/capture}/ProcessCaptureEnvironment.js +0 -0
  270. /package/dist/{application → process/capture}/ProcessCaptureJournal.js +0 -0
  271. /package/dist/{application → process/capture}/ProcessFilesystemEffects.js +0 -0
  272. /package/dist/{application → process/capture}/ProcessNormalization.js +0 -0
  273. /package/dist/{application → process/capture}/ProcessScenarioRuntimeValidation.js +0 -0
  274. /package/dist/{application → process/capture}/ProcessTimer.js +0 -0
  275. /package/dist/{application → process/capture}/TerminalRenderer.js +0 -0
@@ -155,7 +155,7 @@ export const createEvidence = (target, provider, observation) => {
155
155
  const subject = target === undefined
156
156
  ? null
157
157
  : {
158
- name: target.path.split("/").at(-1) ?? target.path,
158
+ name: target.path.split("/").at(-1) || "artifact",
159
159
  digest: { sha256: target.sha256 },
160
160
  format: target.format,
161
161
  architecture: target.architecture ?? null,
@@ -187,20 +187,32 @@ export const createEvidence = (target, provider, observation) => {
187
187
  environment: observation.environment ?? null,
188
188
  limitations: [
189
189
  ...(target === undefined
190
- ? ["Artifact identity is unavailable for this observation."]
190
+ ? [
191
+ observation.subjectUnavailableReason ??
192
+ "Artifact identity is unavailable for this observation.",
193
+ ]
191
194
  : []),
192
195
  ...(observation.limitations ?? []),
193
196
  ],
194
197
  locations: [...(observation.locations ?? [])],
195
198
  evidence_links: [...(observation.evidenceLinks ?? [])],
196
199
  };
197
- const normalized = evidenceRecordSchema.parse({
200
+ // Select the known envelope before parsing. A union otherwise traverses and
201
+ // clones a legacy result for the profiled branch before rejecting its absent
202
+ // profile and trying the legacy branch.
203
+ const schema = observation.analysisProfile === undefined
204
+ ? evidenceBaseSchema
205
+ : profiledEvidenceSchema;
206
+ const normalized = schema.parse({
198
207
  ...semantic,
199
208
  evidence_id: `ev_${"0".repeat(64)}`,
200
209
  subject,
201
210
  });
202
- return parseEvidence({
211
+ // The envelope has already been parsed into an independent snapshot. Only
212
+ // its derived identifier changes here; parsing again clones the full payload
213
+ // and recomputes the same digest while the previous snapshot is still live.
214
+ return {
203
215
  ...normalized,
204
216
  evidence_id: computeEvidenceId(normalized),
205
- });
217
+ };
206
218
  };
@@ -0,0 +1,63 @@
1
+ import { z } from "zod";
2
+ const byteOffset = z.number().int().nonnegative();
3
+ const sha256 = z.string().regex(/^[a-f0-9]{64}$/);
4
+ /** Select the carrier representation explicitly; no RPC or deployed-contract lookup is implied. */
5
+ export const inspectEvmInterfaceInputSchema = z.strictObject({
6
+ path: z
7
+ .string()
8
+ .min(1)
9
+ .describe("Absolute path to caller-selected local bytecode carrier"),
10
+ encoding: z
11
+ .enum(["raw", "hex"])
12
+ .describe("Raw bytes or UTF-8 hex with optional 0x prefix and outer ASCII whitespace"),
13
+ });
14
+ /** Recovered interface candidates are inferences, independently of observed byte identity. */
15
+ export const evmInterfaceSchema = z
16
+ .strictObject({
17
+ artifact: z.strictObject({
18
+ path: z.string().min(1),
19
+ sha256,
20
+ bytes: byteOffset,
21
+ encoding: z.enum(["raw", "hex"]),
22
+ }),
23
+ bytecode: z.strictObject({
24
+ sha256,
25
+ bytes: byteOffset,
26
+ hex: z.string().regex(/^(?:[0-9a-f]{2})*$/),
27
+ digest_algorithm: z.literal("sha256"),
28
+ kind: z.literal("unknown"),
29
+ deployment_authenticity: z.literal("unknown"),
30
+ hardfork: z.literal("unknown"),
31
+ }),
32
+ evidence_kind: z.literal("inferred"),
33
+ functions: z.array(z.strictObject({
34
+ selector: z.string().regex(/^0x[0-9a-f]{8}$/),
35
+ bytecode_offset: byteOffset,
36
+ dispatch: z.enum(["abi", "fallback"]),
37
+ inferred_arguments: z.string().nullable(),
38
+ inferred_state_mutability: z.string().nullable(),
39
+ })),
40
+ discovery_completeness: z.literal("unknown"),
41
+ runtime_execution: z.literal("not-performed"),
42
+ diagnostics: z.strictObject({
43
+ stdout: z.string(),
44
+ stderr: z.string(),
45
+ truncated: z.boolean(),
46
+ }),
47
+ limitations: z.array(z.string()),
48
+ })
49
+ .superRefine((value, context) => {
50
+ if (value.bytecode.hex.length !== value.bytecode.bytes * 2)
51
+ context.addIssue({
52
+ code: "custom",
53
+ path: ["bytecode"],
54
+ message: "Selected byte count does not match the bytecode hex representation.",
55
+ });
56
+ for (const [index, fn] of value.functions.entries())
57
+ if (fn.bytecode_offset >= value.bytecode.bytes)
58
+ context.addIssue({
59
+ code: "custom",
60
+ path: ["functions", index, "bytecode_offset"],
61
+ message: "Inferred body offset lies outside the selected bytecode.",
62
+ });
63
+ });
@@ -0,0 +1,92 @@
1
+ import { AnalysisAccessDeniedError, AnalysisArtifactChangedError, AnalysisInputError, AnalysisOutputError, AnalysisCapabilityUnavailableError, } from "./analysisErrorCore.js";
2
+ import { redactExplicitText } from "./explicitSensitiveValues.js";
3
+ import { ProviderAdapterError } from "./providerAdapterError.js";
4
+ import { ProviderCleanupError } from "./providerCleanupError.js";
5
+ /** Keep a real JSON-pointer ancestor when a property identity is explicitly excluded. */
6
+ export const redactExplicitPointer = (pointer, values) => {
7
+ let parent = "";
8
+ for (const segment of pointer.split("/").slice(1)) {
9
+ const decoded = segment.replaceAll("~1", "/").replaceAll("~0", "~");
10
+ const child = `${parent}/${segment}`;
11
+ if (values.some((literal) => decoded.includes(literal) || child.includes(literal)))
12
+ return parent;
13
+ parent = child;
14
+ }
15
+ return parent;
16
+ };
17
+ /** Exclude explicit literals from common acquisition/decoder failures, preserving typed diagnostics. */
18
+ export const redactExplicitFailure = (error, values) => {
19
+ if (values.length === 0)
20
+ return error;
21
+ const text = (value) => redactExplicitText(value, values);
22
+ const path = (parts, ordinaryNames) => {
23
+ const retained = [];
24
+ for (const part of parts) {
25
+ if (typeof part !== "string") {
26
+ retained.push(part);
27
+ }
28
+ else if (!ordinaryNames && part.startsWith("/")) {
29
+ const pointer = redactExplicitPointer(part, values);
30
+ retained.push(pointer);
31
+ if (pointer !== part)
32
+ break;
33
+ }
34
+ else {
35
+ if (values.some((literal) => part.includes(literal)))
36
+ break;
37
+ retained.push(part);
38
+ }
39
+ }
40
+ return retained;
41
+ };
42
+ const diagnostics = (value) => Object.fromEntries(Object.entries(value)
43
+ .filter(([key]) => !values.some((literal) => key.includes(literal)))
44
+ .map(([key, item]) => [key, visit(item)]));
45
+ const visit = (value) => {
46
+ if (typeof value === "string")
47
+ return text(value);
48
+ if (Array.isArray(value))
49
+ return value.map(visit);
50
+ if (typeof value === "object" && value !== null)
51
+ return diagnostics(value);
52
+ return value;
53
+ };
54
+ if (error instanceof AnalysisAccessDeniedError)
55
+ return new AnalysisAccessDeniedError(error.operation, text(error.path), error.systemCode, { cause: error });
56
+ if (error instanceof AnalysisArtifactChangedError)
57
+ return new AnalysisArtifactChangedError(error.operation, text(error.path), text(error.reason), { cause: error });
58
+ if (error instanceof AnalysisInputError)
59
+ return new AnalysisInputError(error.operation, { cause: error }, error.issues.map((issue) => ({
60
+ ...issue,
61
+ // Unknown-argument paths contain literal field names, including names
62
+ // beginning with '/'; they are not producer JSON-pointer coordinates.
63
+ path: path(issue.path, issue.reason === "unknown_argument"),
64
+ ...(issue.message === undefined
65
+ ? {}
66
+ : { message: text(issue.message) }),
67
+ ...(issue.expected === undefined
68
+ ? {}
69
+ : { expected: visit(issue.expected) }),
70
+ })));
71
+ if (error instanceof AnalysisOutputError)
72
+ return new AnalysisOutputError(error.operation, text(error.reason), {
73
+ cause: error,
74
+ });
75
+ if (error instanceof AnalysisCapabilityUnavailableError)
76
+ return new AnalysisCapabilityUnavailableError(error.providerId, error.operation, text(error.reason), {
77
+ cause: error,
78
+ ...(error.userMessage === undefined
79
+ ? {}
80
+ : { userMessage: text(error.userMessage) }),
81
+ });
82
+ if (error instanceof ProviderCleanupError)
83
+ return new ProviderCleanupError(error.providerId, error.cleanupResources.map(text), diagnostics(error.diagnostics ?? {}), { operation: error.operation, cause: error });
84
+ if (error instanceof ProviderAdapterError)
85
+ return new ProviderAdapterError(error.providerId, error.operation, {
86
+ cause: error,
87
+ ...(error.diagnostics === undefined
88
+ ? {}
89
+ : { diagnostics: diagnostics(error.diagnostics) }),
90
+ });
91
+ return error;
92
+ };
@@ -0,0 +1,10 @@
1
+ /** Replace caller-declared literal text values without guessing sensitivity from names. */
2
+ export const redactExplicitText = (value, sensitiveValues) => {
3
+ const literals = [...new Set(sensitiveValues)].filter((literal) => literal !== "");
4
+ const replacement = ["[REDACTED]", "…", ""].find((candidate) => literals.every((literal) => !candidate.includes(literal))) ?? "";
5
+ let result = value;
6
+ for (const literal of literals.sort((left, right) => right.length - left.length))
7
+ result = result.replaceAll(literal, replacement);
8
+ // Replacement boundaries can form another declaration; exclude that text.
9
+ return literals.some((literal) => result.includes(literal)) ? "" : result;
10
+ };
@@ -1,10 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import { digestSchema } from "../digests.js";
3
3
  import { jsonValueSchema } from "../jsonValue.js";
4
+ import { isAbsoluteLocalPath } from "../localPath.js";
4
5
  const bytes = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
5
6
  const range = z.strictObject({ offset: bytes, length: bytes.positive() });
6
7
  const target = {
7
- path: z.string().min(1).describe("Local firmware file; never executed"),
8
+ path: z
9
+ .string()
10
+ .min(1)
11
+ .refine(isAbsoluteLocalPath, {
12
+ message: "path must be an absolute local filesystem path (for example /tmp/firmware.bin or C:\\firmware\\firmware.bin)",
13
+ })
14
+ .describe("Absolute local firmware file; never executed. Relative paths are rejected."),
8
15
  };
9
16
  /** Explicit firmware inspection and extraction intent, independent of engines. */
10
17
  export const firmwareInputSchemas = {
@@ -1,5 +1,8 @@
1
1
  import { z } from "zod";
2
- const pathInputSchema = z.string().trim().min(1);
2
+ import { isAbsoluteLocalPath } from "../localPath.js";
3
+ const pathInputSchema = z.string().trim().min(1).refine(isAbsoluteLocalPath, {
4
+ message: "Electron executable, application, and root paths must be absolute local filesystem paths (for example /Applications/Electron.app/Contents/MacOS/Electron)",
5
+ });
3
6
  const absolutePathSchema = z
4
7
  .string()
5
8
  .min(1)
@@ -52,9 +55,11 @@ const actionSchema = z.discriminatedUnion("kind", [
52
55
  ]);
53
56
  /** Input for one explicit, provider-owned Electron runtime experiment. */
54
57
  export const electronActiveObservationInputSchema = z.strictObject({
55
- executable_path: pathInputSchema,
56
- application_path: pathInputSchema,
57
- application_root: pathInputSchema.optional(),
58
+ executable_path: pathInputSchema.describe("Absolute local filesystem path for the Electron executable; relative paths are rejected."),
59
+ application_path: pathInputSchema.describe("Absolute local filesystem path for the Electron application; relative paths are rejected."),
60
+ application_root: pathInputSchema
61
+ .optional()
62
+ .describe("Absolute local filesystem root for application-relative paths; omit to derive it from the application path. Relative paths are rejected."),
58
63
  args: z.array(z.string()).default([]),
59
64
  actions: z.array(actionSchema).default([]),
60
65
  });
@@ -0,0 +1,40 @@
1
+ import { defaultTreeAdapter, parse, } from "parse5";
2
+ /** Extract inert HTML script references and the first document base href. */
3
+ export const htmlArtifactReferences = (text) => {
4
+ const pending = [
5
+ parse(text, { sourceCodeLocationInfo: true }),
6
+ ];
7
+ const scripts = [];
8
+ let baseHref = null;
9
+ while (pending.length > 0) {
10
+ const node = pending.pop();
11
+ if (node === undefined)
12
+ continue;
13
+ if (defaultTreeAdapter.isElementNode(node) &&
14
+ node.namespaceURI === "http://www.w3.org/1999/xhtml") {
15
+ if (node.tagName === "base" && baseHref === null) {
16
+ const href = node.attrs.find(({ name }) => name === "href");
17
+ if (href !== undefined)
18
+ baseHref = href.value;
19
+ }
20
+ if (node.tagName === "script") {
21
+ const src = node.attrs.find(({ name }) => name === "src");
22
+ const location = node.sourceCodeLocation?.startTag;
23
+ if (src !== undefined && src.value !== "" && location !== undefined) {
24
+ scripts.push({
25
+ scriptPath: src.value,
26
+ startOffset: location.startOffset,
27
+ endOffset: location.endOffset,
28
+ });
29
+ }
30
+ }
31
+ }
32
+ // Template content belongs to a separate inert document fragment. Only
33
+ // traverse the actual document children, without recursion on deep input.
34
+ if ("childNodes" in node) {
35
+ for (const child of node.childNodes.toReversed())
36
+ pending.push(child);
37
+ }
38
+ }
39
+ return { baseHref, scripts };
40
+ };
@@ -1,8 +1,8 @@
1
- import { uniqueSorted } from "../canonicalOrdering.js";
2
- import { digestExportShapeValue } from "./javascriptExportShapeComparisonIdentity.js";
1
+ import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
2
+ import { canonicalExportShapeValue, digestExportShapeValue, } from "./javascriptExportShapeComparisonIdentity.js";
3
3
  import { javaScriptExportShapeComparisonResultSchema, } from "./javascriptExportShapeComparisonSchemas.js";
4
4
  import { retainJavaScriptExportShapes, selectJavaScriptExport, } from "./javascriptExportShapeSelection.js";
5
- import { buildJavaScriptExportShapeChanges, compareJavaScriptExportShapeChanges, hasPartialJavaScriptExportPropertyCoverage, pairJavaScriptExportShapeVariants, } from "./javascriptExportShapeVariants.js";
5
+ import { buildJavaScriptExportShapeChanges, hasPartialJavaScriptExportPropertyCoverage, pairJavaScriptExportShapeVariants, } from "./javascriptExportShapeVariants.js";
6
6
  /** Compare exact selected export return shapes without executing JavaScript. */
7
7
  export const compareJavaScriptExportShapes = (input) => {
8
8
  const left = selectJavaScriptExport(input.left);
@@ -11,14 +11,14 @@ export const compareJavaScriptExportShapes = (input) => {
11
11
  const rightRetained = retainJavaScriptExportShapes(right);
12
12
  const pairing = pairJavaScriptExportShapeVariants(leftRetained.shapes, rightRetained.shapes);
13
13
  const evidenceLinks = evidencePair(input.left.evidenceId, input.right.evidenceId);
14
- const allChanges = buildJavaScriptExportShapeChanges({
14
+ const allChanges = sortChanges(buildJavaScriptExportShapeChanges({
15
15
  leftSelection: left,
16
16
  rightSelection: right,
17
17
  pairing,
18
18
  leftShapes: leftRetained.shapes,
19
19
  rightShapes: rightRetained.shapes,
20
20
  evidenceLinks,
21
- }).sort(compareJavaScriptExportShapeChanges);
21
+ }));
22
22
  const changes = allChanges;
23
23
  const omittedChanges = 0;
24
24
  const coverage = comparisonCoverage({
@@ -46,6 +46,22 @@ export const compareJavaScriptExportShapes = (input) => {
46
46
  comparison_id: `jesc_${digestExportShapeValue(semantic)}`,
47
47
  });
48
48
  };
49
+ const sortChanges = (changes) => changes
50
+ .map((change, index) => ({
51
+ change,
52
+ index,
53
+ sortKey: canonicalExportShapeValue({
54
+ discriminant: change.discriminant,
55
+ path: change.path,
56
+ status: change.status,
57
+ left_source_range: change.left_source_range,
58
+ right_source_range: change.right_source_range,
59
+ change_id: change.change_id,
60
+ }),
61
+ }))
62
+ .sort((left, right) => compareCodePoints(left.sortKey, right.sortKey) ||
63
+ left.index - right.index)
64
+ .map(({ change }) => change);
49
65
  const comparisonCoverage = (context) => {
50
66
  const leftSource = context.left.projection?.return_shape_coverage;
51
67
  const rightSource = context.right.projection?.return_shape_coverage;
@@ -61,8 +61,6 @@ export const buildJavaScriptExportShapeChanges = (input) => {
61
61
  });
62
62
  return [...paired, ...unpairedLeft, ...unpairedRight];
63
63
  };
64
- /** Sort changes by semantic content rather than traversal order. */
65
- export const compareJavaScriptExportShapeChanges = (left, right) => compareCodePoints(canonicalExportShapeValue(changeSortKey(left)), canonicalExportShapeValue(changeSortKey(right)));
66
64
  /** Report whether any retained shape lacks complete property coverage. */
67
65
  export const hasPartialJavaScriptExportPropertyCoverage = (shapes) => shapes.some((shape) => shape.property_coverage.some(({ status }) => status === "partial"));
68
66
  const discriminantOccurrences = (shapes) => {
@@ -270,14 +268,6 @@ const changeWithId = (semantic) => ({
270
268
  ...semantic,
271
269
  change_id: `jesc_change_${digestExportShapeValue(semantic)}`,
272
270
  });
273
- const changeSortKey = (change) => ({
274
- discriminant: change.discriminant,
275
- path: change.path,
276
- status: change.status,
277
- left_source_range: change.left_source_range,
278
- right_source_range: change.right_source_range,
279
- change_id: change.change_id,
280
- });
281
271
  const literalValue = (field) => field.state === "literal" && isPrimitive(field.value)
282
272
  ? { found: true, value: field.value }
283
273
  : { found: false };
@@ -11,7 +11,8 @@ const normalizeEvidence = (evidence) => ({
11
11
  limitations: uniqueSorted(evidence.limitations),
12
12
  evidence_ids: uniqueSorted(evidence.evidence_ids),
13
13
  });
14
- const nodeId = (node) => `jsrg_node_${canonicalDigest({ kind: node.kind, identity: node.identity }, "JavaScript semantic graph")}`;
14
+ /** Derive a semantic node ID from its kind and exact artifact identity. */
15
+ export const javaScriptSemanticNodeId = (node) => `jsrg_node_${canonicalDigest({ kind: node.kind, identity: node.identity }, "JavaScript semantic graph")}`;
15
16
  /** Normalize one semantic entity and derive its artifact-version identifier. */
16
17
  export const createJavaScriptSemanticGraphNode = (input) => {
17
18
  const parsed = javaScriptSemanticNodeInputSchema.parse(input);
@@ -26,7 +27,7 @@ export const createJavaScriptSemanticGraphNode = (input) => {
26
27
  };
27
28
  return javaScriptSemanticNodeSchema.parse({
28
29
  ...semantic,
29
- node_id: nodeId(semantic),
30
+ node_id: javaScriptSemanticNodeId(semantic),
30
31
  });
31
32
  };
32
33
  /** Normalize one semantic relationship and derive its exact identifier. */
@@ -157,7 +158,7 @@ const checkCanonicalOrder = (graph, context) => {
157
158
  };
158
159
  const checkNodes = (graph, nodes, context) => {
159
160
  for (const [index, node] of graph.nodes.entries()) {
160
- if (node.node_id !== nodeId(node))
161
+ if (node.node_id !== javaScriptSemanticNodeId(node))
161
162
  context.addIssue({
162
163
  code: "custom",
163
164
  path: ["nodes", index, "node_id"],
@@ -295,7 +296,7 @@ const checkFingerprints = (graph, nodes, context) => {
295
296
  });
296
297
  }
297
298
  };
298
- const checkGraph = (graph, context) => {
299
+ const checkGraphContent = (graph, context) => {
299
300
  checkCanonicalOrder(graph, context);
300
301
  const nodes = new Map(graph.nodes.map((node) => [node.node_id, node]));
301
302
  checkNodes(graph, nodes, context);
@@ -311,6 +312,9 @@ const checkGraph = (graph, context) => {
311
312
  path: ["limitations"],
312
313
  message: "Non-complete graph coverage requires a limitation",
313
314
  });
315
+ };
316
+ const checkGraph = (graph, context) => {
317
+ checkGraphContent(graph, context);
314
318
  const { graph_id: identifier, ...semantic } = graph;
315
319
  if (identifier !==
316
320
  "jsrg_" + canonicalDigest(semantic, "JavaScript semantic graph"))
@@ -344,8 +348,20 @@ export const createJavaScriptSemanticGraph = (input) => {
344
348
  },
345
349
  limitations: uniqueSorted(parsed.limitations),
346
350
  };
347
- return javaScriptSemanticGraphSchema.parse({
351
+ // The input schema already cloned and validated every field. Validate the
352
+ // normalized relationships in place, then derive the only added field. The
353
+ // public schema still verifies arbitrary records and their commitments.
354
+ const record = {
348
355
  ...semantic,
349
356
  graph_id: `jsrg_${canonicalDigest(semantic, "JavaScript semantic graph")}`,
357
+ };
358
+ const issues = [];
359
+ checkGraphContent(record, {
360
+ addIssue: (issue) => {
361
+ issues.push(issue);
362
+ },
350
363
  });
364
+ if (issues.length > 0)
365
+ throw new z.ZodError(issues);
366
+ return record;
351
367
  };
@@ -1,5 +1,9 @@
1
1
  import { z } from "zod";
2
2
  /** JSON-safe value shared by domain, application, and adapter boundaries. */
3
3
  export const jsonValueSchema = z.json();
4
+ // Every JSON value satisfies `{}`. Advertise that instead of Zod's
5
+ // self-referential `$defs` projection, which MCP clients and model APIs that
6
+ // reject recursive JSON Schemas refuse. Runtime parsing still admits only JSON.
7
+ jsonValueSchema._zod.toJSONSchema = () => ({});
4
8
  /** JSON object boundary for caller-visible parameter maps. */
5
9
  export const jsonObjectSchema = z.record(z.string(), jsonValueSchema);
@@ -1,4 +1,6 @@
1
1
  import { isAbsolute, relative, sep } from "node:path";
2
+ /** True when the value is an absolute filesystem path on the host platform. */
3
+ export const isAbsoluteLocalPath = (value) => isAbsolute(value);
2
4
  /** Test lexical containment on the host platform; callers must resolve symlinks first. */
3
5
  export const isPathWithinRoot = (root, path) => {
4
6
  const value = relative(root, path);