rea-agents 1.2.0 → 1.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 (79) hide show
  1. package/README.md +74 -27
  2. package/bridge/hopper_bridge.py +161 -12
  3. package/dist/application/AnalysisSnapshotCache.js +131 -0
  4. package/dist/application/AnalysisSnapshotFiles.js +31 -0
  5. package/dist/application/ArtifactInventory.js +4 -0
  6. package/dist/application/AuthorizedArtifactInventory.js +16 -0
  7. package/dist/application/BinarySession.js +66 -36
  8. package/dist/application/BinarySessionPort.js +1 -0
  9. package/dist/application/BoundedJsonFiles.js +109 -0
  10. package/dist/application/CrossVersionInventory.js +98 -0
  11. package/dist/application/CrossVersionInvestigation.js +295 -0
  12. package/dist/application/DirectAnalysis.js +115 -22
  13. package/dist/application/Doctor.js +30 -1
  14. package/dist/application/EvidenceBundleFiles.js +15 -108
  15. package/dist/application/EvidenceLedger.js +3 -2
  16. package/dist/application/InvestigationProviders.js +48 -0
  17. package/dist/application/InvestigationWorkspaceStore.js +214 -0
  18. package/dist/application/LinuxHopper.js +72 -48
  19. package/dist/application/ProcessCaptureAuthority.js +2 -2
  20. package/dist/application/ProcessCaptureError.js +12 -0
  21. package/dist/application/ProcessCaptureLifecycle.js +19 -1
  22. package/dist/application/ProcessCli.js +98 -31
  23. package/dist/application/ProcessHarness.js +2 -2
  24. package/dist/application/ReferenceSourceImportEntries.js +18 -3
  25. package/dist/application/ReferenceSourceImportTypes.js +32 -0
  26. package/dist/application/Setup.js +33 -60
  27. package/dist/application/SetupClients.js +19 -0
  28. package/dist/application/SetupInstallFailure.js +53 -0
  29. package/dist/application/SetupPlan.js +31 -0
  30. package/dist/application/Uninstall.js +33 -23
  31. package/dist/application/UnknownEvidence.js +33 -0
  32. package/dist/application/Upgrade.js +1 -1
  33. package/dist/application/runtime.js +1 -1
  34. package/dist/artifacts/ArtifactProvider.js +2 -5
  35. package/dist/cli.js +31 -11
  36. package/dist/cliEvidenceCommands.js +11 -12
  37. package/dist/cliInvestigationCommands.js +86 -0
  38. package/dist/cliOutput.js +41 -0
  39. package/dist/cliProcessCommands.js +14 -4
  40. package/dist/config.js +39 -24
  41. package/dist/contracts/promptContracts.js +256 -0
  42. package/dist/contracts/sessionLifecycleInputs.js +11 -0
  43. package/dist/contracts/toolContractTypes.js +1 -0
  44. package/dist/contracts/toolContracts.js +10 -6
  45. package/dist/contracts/toolOutputSchemas.js +33 -4
  46. package/dist/domain/analysisSnapshot.js +149 -0
  47. package/dist/domain/changedBehavior.js +30 -7
  48. package/dist/domain/errors.js +180 -41
  49. package/dist/domain/evidence.js +4 -2
  50. package/dist/domain/evidenceBundle.js +28 -0
  51. package/dist/domain/hopperStartupFailure.js +55 -0
  52. package/dist/domain/investigationWorkspace.js +214 -0
  53. package/dist/domain/jsonValue.js +2 -0
  54. package/dist/domain/nativeInspection.js +3 -2
  55. package/dist/domain/processCapture.js +5 -4
  56. package/dist/domain/processComparison.js +5 -4
  57. package/dist/hopper/BridgeLauncher.js +47 -20
  58. package/dist/hopper/HopperClient.js +17 -2
  59. package/dist/hopper/HopperProvider.js +1 -0
  60. package/dist/main.js +47 -24
  61. package/dist/server/createServer.js +2 -0
  62. package/dist/server/promptCompletion.js +144 -0
  63. package/dist/server/registerEnhancedTools.js +2 -6
  64. package/dist/server/registerEvidenceTools.js +2 -8
  65. package/dist/server/registerFunctionComparisonTool.js +1 -1
  66. package/dist/server/registerInvestigationTools.js +31 -11
  67. package/dist/server/registerOfficialTools.js +6 -13
  68. package/dist/server/registerProcessComparisonTool.js +1 -7
  69. package/dist/server/registerPrompts.js +67 -0
  70. package/dist/server/registerSessionStatusTool.js +11 -0
  71. package/dist/server/registerSessionTools.js +52 -18
  72. package/dist/server/sessionEvidence.js +2 -8
  73. package/dist/server/sessionToolPolicies.js +1 -42
  74. package/dist/server/toolResult.js +7 -3
  75. package/install.sh +11 -11
  76. package/package.json +5 -3
  77. package/scripts/hopper-demo-x11.py +349 -0
  78. package/scripts/rea.mjs +6 -3
  79. package/skills/rea-analysis/SKILL.md +9 -2
@@ -3,13 +3,24 @@ import { artifactComparisonResultSchema } from "./artifactComparison.js";
3
3
  import { evidenceSchema, parseEvidence } from "./evidence.js";
4
4
  import { functionComparisonResultSchema } from "./functionComparison.js";
5
5
  import { comparisonStatusSchema, processCaptureComparisonSchema, } from "./processCapture.js";
6
+ import { crossVersionInvestigationInputSchema, investigationRunSummarySchema, } from "./investigationWorkspace.js";
6
7
  const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
7
8
  /** Strict bounded input for aggregating existing comparison Evidence. */
8
- export const changedBehaviorInputSchema = z.object({
9
- comparisons: z.array(evidenceSchema).min(1).max(100),
9
+ export const changedBehaviorInputSchema = z
10
+ .object({
11
+ comparisons: z.array(evidenceSchema).max(100).default([]),
12
+ investigation_run: crossVersionInvestigationInputSchema.optional(),
10
13
  offset: z.number().int().min(0).default(0),
11
14
  limit: z.number().int().min(1).max(100).default(100),
12
15
  unknown_registry_approved: z.literal(true).optional(),
16
+ })
17
+ .superRefine((input, context) => {
18
+ if (input.comparisons.length > 0 ===
19
+ (input.investigation_run !== undefined))
20
+ context.addIssue({
21
+ code: "custom",
22
+ message: "Supply either existing comparisons or one investigation_run, but not both",
23
+ });
13
24
  });
14
25
  const findingSchema = z.object({
15
26
  scope: z.enum(["runtime", "protocol", "resource", "static_candidate"]),
@@ -48,6 +59,7 @@ export const changedBehaviorResultSchema = z.object({
48
59
  }),
49
60
  evidence_links: z.array(evidenceIdSchema).min(3).max(20_100),
50
61
  limitations: z.array(z.string()),
62
+ investigation_run: investigationRunSummarySchema.optional(),
51
63
  });
52
64
  const EXPECTED_PROVIDERS = {
53
65
  compare_process_captures: {
@@ -113,6 +125,7 @@ export const findChangedBehavior = (comparisonsInput, offset, limit) => {
113
125
  ...(runtimeStatuses.length === 0
114
126
  ? ["No process comparison Evidence was supplied."]
115
127
  : []),
128
+ ...evidence.flatMap(artifactPaginationLimitations),
116
129
  ]),
117
130
  });
118
131
  };
@@ -169,10 +182,8 @@ const parseResult = (evidence) => {
169
182
  return;
170
183
  }
171
184
  const result = artifactComparisonResultSchema.parse(evidence.normalized_result);
172
- if (result.changes.offset !== 0 ||
173
- result.changes.next_offset !== null ||
174
- result.changes.items.length !== result.changes.total)
175
- throw new TypeError("Changed-behavior analysis requires complete artifact comparison pagination");
185
+ if (result.changes.offset !== 0)
186
+ throw new TypeError("Changed-behavior analysis requires artifact comparison pagination from offset zero");
176
187
  assertNestedLinks(evidence, result.changes.items.flatMap(({ evidence_links: links }) => links));
177
188
  };
178
189
  const assertNestedLinks = (evidence, nestedLinks) => {
@@ -242,7 +253,9 @@ const artifactFindings = (evidence) => {
242
253
  limitations: result.limitations,
243
254
  links: change.evidence_links,
244
255
  }));
245
- return (result.status === "unknown" || result.status === "truncated") &&
256
+ return (result.status === "unknown" ||
257
+ result.status === "truncated" ||
258
+ result.changes.next_offset !== null) &&
246
259
  !changes.some(({ classification }) => classification === "unresolved_branch")
247
260
  ? [
248
261
  ...changes,
@@ -257,6 +270,16 @@ const artifactFindings = (evidence) => {
257
270
  ]
258
271
  : changes;
259
272
  };
273
+ const artifactPaginationLimitations = (evidence) => {
274
+ if (evidence.operation !== "compare_artifacts")
275
+ return [];
276
+ const result = artifactComparisonResultSchema.parse(evidence.normalized_result);
277
+ return result.changes.next_offset === null
278
+ ? []
279
+ : [
280
+ `Artifact comparison reports ${String(result.changes.items.length)} of ${String(result.changes.total)} changes.`,
281
+ ];
282
+ };
260
283
  const makeFinding = (input) => findingSchema.parse({
261
284
  scope: input.scope,
262
285
  dimension: input.dimension,
@@ -1,5 +1,7 @@
1
+ import { hopperStartupFailure, } from "./hopperStartupFailure.js";
2
+ export { hopperStartupFailure } from "./hopperStartupFailure.js";
1
3
  /** Stable tags exposed by safe analysis-error projections. */
2
- export const ANALYSIS_ERROR_TAGS = [
4
+ const ANALYSIS_ERROR_TAGS = [
3
5
  "AnalysisProtocolError",
4
6
  "AnalysisInputError",
5
7
  "AnalysisOutputError",
@@ -13,6 +15,7 @@ export const ANALYSIS_ERROR_TAGS = [
13
15
  "EvidenceIntegrityError",
14
16
  "EvidenceLimitError",
15
17
  "EvidenceFileError",
18
+ "InvestigationWorkspaceError",
16
19
  "UnknownRegistryError",
17
20
  "HopperTimeoutError",
18
21
  "HopperCancelledError",
@@ -26,6 +29,8 @@ export const ANALYSIS_ERROR_TAGS = [
26
29
  ];
27
30
  /** Base class for expected analysis, provider, and session failures. */
28
31
  export class AnalysisError extends Error {
32
+ userMessage = undefined;
33
+ userCategory = undefined;
29
34
  }
30
35
  /** Base class for failures produced specifically by the Hopper provider. */
31
36
  export class HopperError extends AnalysisError {
@@ -148,6 +153,17 @@ export class EvidenceFileError extends AnalysisError {
148
153
  this.reason = reason;
149
154
  }
150
155
  }
156
+ /** Persistent investigation workspace access or CAS validation failed. */
157
+ export class InvestigationWorkspaceError extends AnalysisError {
158
+ operation;
159
+ reason;
160
+ _tag = "InvestigationWorkspaceError";
161
+ constructor(operation, reason, options) {
162
+ super(`Investigation workspace ${operation} failed: ${reason}`, options);
163
+ this.operation = operation;
164
+ this.reason = reason;
165
+ }
166
+ }
151
167
  /** Residual-unknown mutation failed a lifecycle, reference, or CAS invariant. */
152
168
  export class UnknownRegistryError extends AnalysisError {
153
169
  reason;
@@ -194,9 +210,14 @@ export class HopperRemoteError extends HopperError {
194
210
  export class HopperProcessError extends HopperError {
195
211
  exitCode;
196
212
  _tag = "HopperProcessError";
213
+ failureCode;
214
+ userMessage;
197
215
  constructor(exitCode) {
198
216
  super(`Hopper bridge stopped unexpectedly with code ${String(exitCode)}`);
199
217
  this.exitCode = exitCode;
218
+ const failure = hopperStartupFailure(exitCode);
219
+ this.failureCode = failure?.code;
220
+ this.userMessage = failure?.message;
200
221
  }
201
222
  }
202
223
  /** Hopper or the repository bridge could not be started. */
@@ -229,54 +250,171 @@ export class BinaryTargetError extends AnalysisError {
229
250
  /** Project expected failures into exhaustive, secret-safe caller fields. */
230
251
  export const projectAnalysisError = (error) => {
231
252
  assertKnownTag(error._tag);
253
+ const code = error instanceof HopperProcessError ? error.failureCode : undefined;
232
254
  return {
233
- tag: error._tag,
234
- message: error.message,
235
- details: safeDetails(error),
255
+ category: errorCategory(error),
256
+ message: userMessage(error),
257
+ ...(code === undefined ? {} : { code }),
236
258
  };
237
259
  };
238
- const safeDetails = (error) => {
260
+ const errorCategory = (error) => {
261
+ if (error._tag === "ProcessCaptureError")
262
+ return error.userCategory ?? "execution_failure";
263
+ if (error instanceof HopperRemoteError &&
264
+ error.diagnosticType === "authorization")
265
+ return "permission_required";
266
+ if (error instanceof ArtifactOperationError)
267
+ return artifactErrorCategory(error.reason);
268
+ if (error instanceof EvidenceFileError && error.reason === "disabled")
269
+ return "unavailable";
270
+ if (error instanceof InvestigationWorkspaceError)
271
+ return investigationWorkspaceCategory(error.reason);
272
+ return STATIC_ERROR_CATEGORIES[error._tag] ?? "execution_failure";
273
+ };
274
+ const investigationWorkspaceCategory = (reason) => {
275
+ if (reason === "disabled" ||
276
+ reason === "outside-root" ||
277
+ reason === "not-file")
278
+ return "unavailable";
279
+ if (reason === "too-large")
280
+ return "truncated";
281
+ if (reason === "invalid-json" || reason === "integrity")
282
+ return "integrity_mismatch";
283
+ return "execution_failure";
284
+ };
285
+ const artifactErrorCategory = (reason) => {
286
+ if (reason === "integrity")
287
+ return "integrity_mismatch";
288
+ if (reason === "limit")
289
+ return "truncated";
290
+ if (reason === "cancelled")
291
+ return "cancelled";
292
+ if (reason === "unavailable")
293
+ return "unavailable";
294
+ return "execution_failure";
295
+ };
296
+ const STATIC_ERROR_CATEGORIES = {
297
+ AnalysisInputError: "invalid_input",
298
+ AnalysisCapabilityUnavailableError: "unsupported_provider",
299
+ ProviderSelectionError: "unsupported_provider",
300
+ EvidenceIntegrityError: "integrity_mismatch",
301
+ EvidenceLimitError: "truncated",
302
+ AnalysisCancelledError: "cancelled",
303
+ HopperCancelledError: "cancelled",
304
+ AnalysisTimeoutError: "timeout",
305
+ HopperTimeoutError: "timeout",
306
+ NoBinaryOpenError: "unavailable",
307
+ BinaryTargetError: "unavailable",
308
+ };
309
+ const userMessage = (error) => {
239
310
  if (error instanceof AnalysisInputError)
240
- return { operation: error.operation };
241
- if (error instanceof AnalysisOutputError)
242
- return { operation: error.operation, reason: error.reason };
243
- if (error instanceof AnalysisCapabilityUnavailableError)
244
- return {
245
- providerId: error.providerId,
246
- operation: error.operation,
247
- reason: error.reason,
248
- };
249
- if (error instanceof AnalysisCancelledError)
250
- return { operation: error.operation };
251
- if (error instanceof AnalysisTimeoutError)
252
- return { operation: error.operation, timeoutMs: error.timeoutMs };
253
- if (error instanceof ProviderSelectionError)
254
- return { operation: error.operation };
255
- if (error instanceof ProviderAdapterError)
256
- return { providerId: error.providerId, operation: error.operation };
311
+ return "Analysis input is invalid. Check the arguments and try again.";
312
+ if (error.userMessage !== undefined)
313
+ return error.userMessage;
314
+ if (UNREADABLE_OUTPUT_TAGS.has(error._tag))
315
+ return "Analysis returned an unreadable result. Retry once; if it continues, run `rea doctor`.";
316
+ if (UNSUPPORTED_PROVIDER_TAGS.has(error._tag))
317
+ return "This analysis is unavailable for the current target. Choose another analysis or target.";
318
+ if (CANCELLED_TAGS.has(error._tag))
319
+ return "Analysis was cancelled. Start it again when ready.";
320
+ if (TIMEOUT_TAGS.has(error._tag))
321
+ return "Analysis took too long. Try a smaller request, then run `rea doctor` if it continues.";
322
+ if (ADAPTER_FAILURE_TAGS.has(error._tag))
323
+ return "Analysis could not complete. Retry once; if it continues, run `rea doctor`.";
324
+ if (START_FAILURE_TAGS.has(error._tag))
325
+ return "Analysis could not start or stopped unexpectedly. Run `rea doctor`, then try again.";
257
326
  if (error instanceof ArtifactOperationError)
258
- return {
259
- operation: error.operation,
260
- reason: error.reason,
261
- ...error.artifactDetails,
262
- };
327
+ return artifactMessage(error.reason);
328
+ if (error instanceof EvidenceIntegrityError)
329
+ return "Evidence is invalid or has changed. Recreate or re-import it, then try again.";
263
330
  if (error instanceof EvidenceLimitError)
264
- return { limit: error.limit, maximum: error.maximum };
331
+ return "Evidence is too large for this session. Reduce the evidence set and try again.";
265
332
  if (error instanceof EvidenceFileError)
266
- return { operation: error.operation, reason: error.reason };
333
+ return evidenceFileMessage(error.reason);
334
+ if (error instanceof InvestigationWorkspaceError)
335
+ return investigationWorkspaceMessage(error.reason);
267
336
  if (error instanceof UnknownRegistryError)
268
- return { reason: error.reason };
269
- if (error instanceof HopperTimeoutError)
270
- return { timeoutMs: error.timeoutMs };
271
- if (error instanceof HopperRemoteError)
272
- return {
273
- code: error.code,
274
- safeMessage: error.safeMessage,
275
- diagnosticType: error.diagnosticType,
276
- };
277
- if (error instanceof HopperProcessError)
278
- return { exitCode: error.exitCode };
279
- return {};
337
+ return "Evidence state changed before the update completed. Refresh the current state and try again.";
338
+ if (error instanceof ConfigurationError)
339
+ return "REA configuration is invalid. Run `rea doctor` and fix the reported setting.";
340
+ if (error instanceof NoBinaryOpenError)
341
+ return error.message;
342
+ if (error instanceof BinaryTargetError)
343
+ return "REA could not open that app or binary. Check that the path exists, is readable, and points to a supported file.";
344
+ if (error._tag === "ProcessCaptureError")
345
+ return (error.userMessage ??
346
+ "Process capture could not complete. Run `rea doctor`, then review capture policy and try again.");
347
+ return "Analysis could not complete. Run `rea doctor`, then try again.";
348
+ };
349
+ const UNREADABLE_OUTPUT_TAGS = new Set([
350
+ "AnalysisProtocolError",
351
+ "AnalysisOutputError",
352
+ "HopperProtocolError",
353
+ ]);
354
+ const UNSUPPORTED_PROVIDER_TAGS = new Set([
355
+ "AnalysisCapabilityUnavailableError",
356
+ "ProviderSelectionError",
357
+ ]);
358
+ const CANCELLED_TAGS = new Set([
359
+ "AnalysisCancelledError",
360
+ "HopperCancelledError",
361
+ ]);
362
+ const TIMEOUT_TAGS = new Set([
363
+ "AnalysisTimeoutError",
364
+ "HopperTimeoutError",
365
+ ]);
366
+ const ADAPTER_FAILURE_TAGS = new Set([
367
+ "ProviderAdapterError",
368
+ "HopperRemoteError",
369
+ ]);
370
+ const START_FAILURE_TAGS = new Set([
371
+ "HopperProcessError",
372
+ "HopperStartError",
373
+ ]);
374
+ const artifactMessage = (reason) => {
375
+ if (reason === "cancelled")
376
+ return "Artifact operation was cancelled. Start it again when ready.";
377
+ if (reason === "limit")
378
+ return "Artifact is too large to process safely. Narrow the requested path or use a smaller artifact.";
379
+ if (reason === "path")
380
+ return "Artifact path is not allowed. Choose a path inside the artifact and try again.";
381
+ if (reason === "unavailable")
382
+ return "Artifact format is not available on this system. Choose another artifact or supported environment.";
383
+ if (reason === "format" || reason === "integrity")
384
+ return "Artifact is invalid or has changed. Get a fresh copy and try again.";
385
+ return "Artifact could not be read or written. Check file access and try again.";
386
+ };
387
+ const evidenceFileMessage = (reason) => {
388
+ if (reason === "disabled")
389
+ return "Evidence file access is disabled. Enable an evidence directory or use inline evidence.";
390
+ if (reason === "outside-root")
391
+ return "Evidence path is outside the allowed directory. Choose a path inside the configured evidence directory.";
392
+ if (reason === "not-file")
393
+ return "Evidence path does not point to a file. Choose an evidence file and try again.";
394
+ if (reason === "too-large")
395
+ return "Evidence file is too large. Reduce its size and try again.";
396
+ if (reason === "exists")
397
+ return "Evidence file already exists. Choose another path or allow overwrite.";
398
+ if (reason === "invalid-json")
399
+ return "Evidence file is not valid JSON. Repair or recreate the file and try again.";
400
+ return "Evidence file could not be accessed. Check file permissions and try again.";
401
+ };
402
+ const investigationWorkspaceMessage = (reason) => {
403
+ if (reason === "disabled")
404
+ return "Investigation workspace access is disabled. Configure a workspace directory and try again.";
405
+ if (reason === "outside-root")
406
+ return "Investigation workspace is outside the allowed directory. Choose a configured workspace directory and try again.";
407
+ if (reason === "not-file")
408
+ return "Investigation workspace path is not a file. Choose a workspace file and try again.";
409
+ if (reason === "too-large")
410
+ return "Investigation workspace is too large. Reduce its size and try again.";
411
+ if (reason === "invalid-json" || reason === "integrity")
412
+ return "Investigation workspace is invalid or has changed. Recreate or repair it, then try again.";
413
+ if (reason === "locked")
414
+ return "Another investigation update is in progress. Try again when it finishes.";
415
+ if (reason === "revision-conflict" || reason === "name-conflict")
416
+ return "Investigation workspace state changed. Refresh the current state and try again.";
417
+ return "Investigation workspace could not be accessed. Check file permissions and try again.";
280
418
  };
281
419
  const KNOWN_ERROR_TAGS = {
282
420
  AnalysisProtocolError: true,
@@ -292,6 +430,7 @@ const KNOWN_ERROR_TAGS = {
292
430
  EvidenceIntegrityError: true,
293
431
  EvidenceLimitError: true,
294
432
  EvidenceFileError: true,
433
+ InvestigationWorkspaceError: true,
295
434
  UnknownRegistryError: true,
296
435
  HopperTimeoutError: true,
297
436
  HopperCancelledError: true,
@@ -3,7 +3,8 @@ import canonicalize from "canonicalize";
3
3
  import { z } from "zod";
4
4
  import { jsonValueSchema } from "./jsonValue.js";
5
5
  const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
6
- const providerSchema = z.object({
6
+ /** Provider identity schema shared by evidence-bearing persistence formats. */
7
+ export const providerSchema = z.object({
7
8
  id: z.string().min(1),
8
9
  name: z.string().min(1),
9
10
  version: z.string().nullable(),
@@ -36,7 +37,8 @@ const subjectSchema = z.object({
36
37
  local_path: z.string(),
37
38
  });
38
39
  /** Source location attached to an evidence observation. */
39
- const evidenceLocationSchema = z.discriminatedUnion("kind", [
40
+ /** Source-location schema shared by evidence-bearing persistence formats. */
41
+ export const evidenceLocationSchema = z.discriminatedUnion("kind", [
40
42
  z.object({ kind: z.literal("address"), address: z.string().min(1) }),
41
43
  z.object({
42
44
  kind: z.literal("address-range"),
@@ -66,6 +66,34 @@ export const createEvidenceBundle = (records, unknowns = []) => {
66
66
  records: sortedRecords,
67
67
  };
68
68
  };
69
+ /** Restrict a bundle to records and complete unknown histories for one artifact. */
70
+ export const evidenceBundleForTarget = (bundle, sha256) => {
71
+ const recordsById = new Map(bundle.records.map((record) => [record.evidence_id, record]));
72
+ let unknowns = bundle.unknowns.filter(({ scope_digest: scopeDigest }) => scopeDigest === sha256);
73
+ let changed = true;
74
+ while (changed) {
75
+ const ids = new Set(unknowns.map(({ unknown_id: id }) => id));
76
+ const retained = unknowns.filter((unknown) => unknown.relationships.every(({ unknown_id: id }) => ids.has(id)) &&
77
+ referencedEvidenceIds(unknown).every((id) => {
78
+ const record = recordsById.get(id);
79
+ return (record?.subject?.digest.sha256 === sha256 ||
80
+ (unknown.mutation_evidence_ids.includes(id) &&
81
+ record?.subject === null &&
82
+ record.predicate_type === "rea.residual-unknown-mutation/v1"));
83
+ }));
84
+ changed = retained.length !== unknowns.length;
85
+ unknowns = retained;
86
+ }
87
+ const mutationIds = new Set(unknowns.flatMap(({ mutation_evidence_ids: ids }) => ids));
88
+ return createEvidenceBundle(bundle.records.filter((record) => record.subject?.digest.sha256 === sha256 ||
89
+ mutationIds.has(record.evidence_id)), unknowns);
90
+ };
91
+ const referencedEvidenceIds = (unknown) => [
92
+ ...unknown.supporting_evidence_ids,
93
+ ...unknown.contradicting_evidence_ids,
94
+ ...unknown.mutation_evidence_ids,
95
+ ...(unknown.resolution?.evidence_ids ?? []),
96
+ ];
69
97
  /** Parse records, verify semantic IDs, and reject inconsistent manifests. */
70
98
  export const parseEvidenceBundle = (input) => {
71
99
  const parsed = evidenceBundleSchema.parse(input);
@@ -0,0 +1,55 @@
1
+ const failures = [
2
+ [
3
+ 70,
4
+ "private_display_unavailable",
5
+ "REA could not start its private Linux display. Install Xvfb, then rerun rea doctor.",
6
+ ],
7
+ [
8
+ 71,
9
+ "x11_authorization_failed",
10
+ "REA could not authorize its private Linux display. Install xauth, then rerun rea doctor.",
11
+ ],
12
+ [
13
+ 72,
14
+ "unsupported_hopper_build",
15
+ "This Hopper build is not supported for unattended Linux analysis. Unset HOPPER_LAUNCHER_PATH and rerun rea setup --yes --install-hopper, or update REA.",
16
+ ],
17
+ [
18
+ 73,
19
+ "invalid_launch_command",
20
+ "REA refused an unexpected Hopper launch command. Check HOPPER_LAUNCHER_PATH and rerun rea doctor.",
21
+ ],
22
+ [
23
+ 74,
24
+ "process_ownership_mismatch",
25
+ "REA could not verify ownership of the launched Hopper process and stopped safely. Close other Hopper sessions and retry.",
26
+ ],
27
+ [
28
+ 75,
29
+ "hopper_exited_during_startup",
30
+ "Hopper exited before the REA bridge was ready. Run rea doctor and retry the analysis.",
31
+ ],
32
+ [
33
+ 76,
34
+ "unsupported_demo_dialog",
35
+ "This Hopper demo dialog is not supported for unattended Linux analysis. Update REA or use a supported Hopper build.",
36
+ ],
37
+ [
38
+ 77,
39
+ "unexpected_display_geometry",
40
+ "REA's private Linux display did not match the validated layout. Close custom display overrides and retry.",
41
+ ],
42
+ [
43
+ 78,
44
+ "x11_input_failed",
45
+ "REA could not activate Hopper's validated demo control. Install the XTEST runtime, then rerun rea doctor.",
46
+ ],
47
+ [
48
+ 79,
49
+ "runtime_dependency_unavailable",
50
+ "A Linux demo-session dependency is unavailable. Rerun rea setup --yes --install-hopper, then rea doctor.",
51
+ ],
52
+ ];
53
+ const HOPPER_STARTUP_FAILURES = new Map(failures.map(([exitCode, code, message]) => [exitCode, { code, message }]));
54
+ /** Return the stable public failure associated with a Linux demo adapter exit. */
55
+ export const hopperStartupFailure = (exitCode) => exitCode === null ? undefined : HOPPER_STARTUP_FAILURES.get(exitCode);