raytrace-cli 0.11.1__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. raytrace/__init__.py +1 -0
  2. raytrace/__main__.py +33 -0
  3. raytrace/app/LICENSE +21 -0
  4. raytrace/app/README.md +599 -0
  5. raytrace/app/bin/raytrace.mjs +297 -0
  6. raytrace/app/dist/dashboard/assets/dm-sans-latin-400-normal-BwCSEQnW.woff +0 -0
  7. raytrace/app/dist/dashboard/assets/dm-sans-latin-400-normal-CW0RaeGs.woff2 +0 -0
  8. raytrace/app/dist/dashboard/assets/dm-sans-latin-500-normal-B9HHJjqV.woff2 +0 -0
  9. raytrace/app/dist/dashboard/assets/dm-sans-latin-500-normal-Dr3UlScf.woff +0 -0
  10. raytrace/app/dist/dashboard/assets/dm-sans-latin-600-normal-Aqo67rzb.woff2 +0 -0
  11. raytrace/app/dist/dashboard/assets/dm-sans-latin-600-normal-BmdmIIQ2.woff +0 -0
  12. raytrace/app/dist/dashboard/assets/dm-sans-latin-700-normal-CUSSCpQX.woff +0 -0
  13. raytrace/app/dist/dashboard/assets/dm-sans-latin-700-normal-DvUfVpUG.woff2 +0 -0
  14. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BjWJ59Pq.woff +0 -0
  15. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BtiwyxMk.woff2 +0 -0
  16. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-500-normal-BJfUCQsA.woff2 +0 -0
  17. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-500-normal-DR84L5F-.woff +0 -0
  18. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-600-normal-4vooXBpG.woff2 +0 -0
  19. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-600-normal-DRtaDpgU.woff +0 -0
  20. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-700-normal-BLI3TTWz.woff +0 -0
  21. raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-700-normal-CJIcxD6K.woff2 +0 -0
  22. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  23. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  24. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  25. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  26. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-CTOM6hUh.woff2 +0 -0
  27. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-fLZuRloM.woff +0 -0
  28. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  29. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  30. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  31. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  32. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-9HEixskS.woff +0 -0
  33. raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-V-xxqcpd.woff2 +0 -0
  34. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  35. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  36. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  37. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  38. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
  39. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
  40. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  41. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  42. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  43. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  44. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-D38SheWl.woff2 +0 -0
  45. raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-DmB0ttJJ.woff +0 -0
  46. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  47. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  48. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  49. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  50. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-D2EvbN8M.woff2 +0 -0
  51. raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-iLQfcSjf.woff +0 -0
  52. raytrace/app/dist/dashboard/assets/index-DepcI8Fi.js +38 -0
  53. raytrace/app/dist/dashboard/assets/index-H97VLD5l.css +1 -0
  54. raytrace/app/dist/dashboard/favicon.svg +6 -0
  55. raytrace/app/dist/dashboard/index.html +15 -0
  56. raytrace/app/package.json +48 -0
  57. raytrace/app/proxy/agent-intent-schema.test.mjs +142 -0
  58. raytrace/app/proxy/call-assessment.mjs +385 -0
  59. raytrace/app/proxy/call-assessment.test.mjs +167 -0
  60. raytrace/app/proxy/call-category.mjs +461 -0
  61. raytrace/app/proxy/capture-health.mjs +30 -0
  62. raytrace/app/proxy/capture-health.test.mjs +44 -0
  63. raytrace/app/proxy/capture.mjs +38 -0
  64. raytrace/app/proxy/capture.test.mjs +49 -0
  65. raytrace/app/proxy/claude-code-adapter.mjs +301 -0
  66. raytrace/app/proxy/claude-code-hook.mjs +22 -0
  67. raytrace/app/proxy/codex-config.mjs +36 -0
  68. raytrace/app/proxy/codex.mjs +14 -0
  69. raytrace/app/proxy/evidence-schema.test.mjs +240 -0
  70. raytrace/app/proxy/evidence-store.mjs +993 -0
  71. raytrace/app/proxy/evidence-store.test.mjs +301 -0
  72. raytrace/app/proxy/exec-narrative.mjs +625 -0
  73. raytrace/app/proxy/exec-narrative.test.mjs +262 -0
  74. raytrace/app/proxy/execution-correlation.mjs +185 -0
  75. raytrace/app/proxy/execution-correlation.test.mjs +146 -0
  76. raytrace/app/proxy/execution-runner.mjs +89 -0
  77. raytrace/app/proxy/execution-runner.test.mjs +38 -0
  78. raytrace/app/proxy/experiment-engine.mjs +195 -0
  79. raytrace/app/proxy/experiment-engine.test.mjs +93 -0
  80. raytrace/app/proxy/explanations.mjs +36 -0
  81. raytrace/app/proxy/explanations.test.mjs +20 -0
  82. raytrace/app/proxy/failure-signature.mjs +56 -0
  83. raytrace/app/proxy/gvisor-forwarder.mjs +493 -0
  84. raytrace/app/proxy/gvisor-forwarder.test.mjs +433 -0
  85. raytrace/app/proxy/init-evidence-db.mjs +227 -0
  86. raytrace/app/proxy/local-sandboxes.mjs +94 -0
  87. raytrace/app/proxy/local-token.mjs +30 -0
  88. raytrace/app/proxy/playground-recovery.test.mjs +130 -0
  89. raytrace/app/proxy/playground.mjs +439 -0
  90. raytrace/app/proxy/prompt-context.mjs +278 -0
  91. raytrace/app/proxy/prompt-traces.mjs +40 -0
  92. raytrace/app/proxy/prompt-traces.test.mjs +32 -0
  93. raytrace/app/proxy/providers.mjs +65 -0
  94. raytrace/app/proxy/providers.test.mjs +76 -0
  95. raytrace/app/proxy/proxy.integration.test.mjs +135 -0
  96. raytrace/app/proxy/raytace-proxy.mjs +941 -0
  97. raytrace/app/proxy/request-metrics.mjs +13 -0
  98. raytrace/app/proxy/request-metrics.test.mjs +19 -0
  99. raytrace/app/proxy/request-policy.mjs +45 -0
  100. raytrace/app/proxy/request-policy.test.mjs +47 -0
  101. raytrace/app/proxy/run-recap.mjs +139 -0
  102. raytrace/app/proxy/runtime-attribution.mjs +110 -0
  103. raytrace/app/proxy/sandbox-bridge.mjs +49 -0
  104. raytrace/app/proxy/schema/EVIDENCE_DATABASE.md +276 -0
  105. raytrace/app/proxy/schema/agent_intent.sql +101 -0
  106. raytrace/app/proxy/schema/auxiliary.sql +90 -0
  107. raytrace/app/proxy/schema/capture_health.sql +14 -0
  108. raytrace/app/proxy/schema/classification.sql +89 -0
  109. raytrace/app/proxy/schema/file_context.sql +53 -0
  110. raytrace/app/proxy/schema/runtime_evidence.sql +201 -0
  111. raytrace/app/proxy/schema/search.sql +66 -0
  112. raytrace/app/proxy/schema/shared_storage.sql +21 -0
  113. raytrace/app/proxy/search.mjs +418 -0
  114. raytrace/app/proxy/search.test.mjs +161 -0
  115. raytrace/app/proxy/smoke.test.mjs +93 -0
  116. raytrace/app/proxy/step-attribution.mjs +380 -0
  117. raytrace/app/proxy/step-lab.mjs +78 -0
  118. raytrace/app/proxy/step-lab.test.mjs +38 -0
  119. raytrace/app/proxy/summaries.mjs +151 -0
  120. raytrace/app/proxy/summaries.test.mjs +69 -0
  121. raytrace/app/proxy/tool-metadata.mjs +111 -0
  122. raytrace/app/proxy/tool-metadata.test.mjs +38 -0
  123. raytrace/app/proxy/trace-view.mjs +324 -0
  124. raytrace/app/proxy/trace-view.test.mjs +92 -0
  125. raytrace/app/proxy/typesafe.mjs +63 -0
  126. raytrace/app/proxy/typesafe.test.mjs +39 -0
  127. raytrace/app/src/agents.mjs +7 -0
  128. raytrace/app/src/api.mjs +57 -0
  129. raytrace/app/src/auth.mjs +205 -0
  130. raytrace/app/src/beta.mjs +96 -0
  131. raytrace/app/src/claude-code.mjs +93 -0
  132. raytrace/app/src/commands.mjs +285 -0
  133. raytrace/app/src/config.mjs +49 -0
  134. raytrace/app/src/export.mjs +200 -0
  135. raytrace/app/src/lima.mjs +176 -0
  136. raytrace/app/src/local-sandbox.mjs +358 -0
  137. raytrace/app/src/mcp.mjs +688 -0
  138. raytrace/app/src/paths.mjs +33 -0
  139. raytrace/app/src/prompt.mjs +42 -0
  140. raytrace/app/src/proxy-process.mjs +143 -0
  141. raytrace/app/src/sandbox.mjs +306 -0
  142. raytrace/app/src/share.mjs +86 -0
  143. raytrace/app/src/terminal.mjs +68 -0
  144. raytrace/app/src/upload.mjs +198 -0
  145. raytrace/app/worker/sandbox/Dockerfile +8 -0
  146. raytrace/app/worker/sandbox/SYSCALL_CATALOG.md +197 -0
  147. raytrace/app/worker/sandbox/claude-hook.mjs +364 -0
  148. raytrace/app/worker/sandbox/collector.py +405 -0
  149. raytrace/app/worker/sandbox/dns_forwarder.py +255 -0
  150. raytrace/app/worker/sandbox/engine.py +940 -0
  151. raytrace/app/worker/sandbox/file_scan.py +491 -0
  152. raytrace/app/worker/sandbox/lima.yaml +29 -0
  153. raytrace/app/worker/sandbox/network.py +90 -0
  154. raytrace/app/worker/sandbox/projects.py +702 -0
  155. raytrace/app/worker/sandbox/setup.py +159 -0
  156. raytrace/app/worker/sandbox/syscall_catalog.sql +985 -0
  157. raytrace/app/worker/sandbox/transcript-delivery.test.mjs +153 -0
  158. raytrace/app/worker/sandbox/viewer.py +195 -0
  159. raytrace/node/LICENSE +2946 -0
  160. raytrace/node/node.exe +4 -0
  161. raytrace_cli-0.11.1.dist-info/LICENSE +21 -0
  162. raytrace_cli-0.11.1.dist-info/METADATA +42 -0
  163. raytrace_cli-0.11.1.dist-info/RECORD +165 -0
  164. raytrace_cli-0.11.1.dist-info/WHEEL +4 -0
  165. raytrace_cli-0.11.1.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,301 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtemp, rm } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { openEvidenceStore } from './evidence-store.mjs';
7
+ import { SCHEMA_VERSION } from './init-evidence-db.mjs';
8
+
9
+ const SESSION = 'rtp-' + 'f'.repeat(32);
10
+ const CONTAINER = 'c'.repeat(64);
11
+ const PROMPT = { role: 'user', type: 'message', content: 'In /workspace/demo-hook, run npm test.' };
12
+ const ENV = { role: 'user', type: 'message', content: '<environment_context>cwd=/workspace</environment_context>' };
13
+ const TOOLS = [{ type: 'function', name: 'exec_command', schema: 'x'.repeat(400) }];
14
+ const CALL = { type: 'function_call', call_id: 'call_1', name: 'exec_command', arguments: '{"cmd":"cd /workspace/demo-hook && npm test"}' };
15
+ const RESULT = (output) => ({ type: 'function_call_output', call_id: 'call_1', output });
16
+ const HEADER = (code, seconds) => `Wall time: ${seconds} seconds\nProcess exited with code ${code}\nOutput:\n1 passing`;
17
+
18
+ let clock = 0;
19
+ const exchange = (id, input, output, { at = (clock += 1000), session = SESSION, status = 200 } = {}) => ({
20
+ event_type: 'model.exchange', span_id: id, trace_id: 'header-trace', session_id: session, session_started_at: new Date(0).toISOString(),
21
+ provider: 'openrouter', route: '/v1/responses', method: 'POST',
22
+ timestamp: new Date(1_790_000_000_000 + at).toISOString(), completed_at: new Date(1_790_000_000_000 + at + 400).toISOString(),
23
+ metrics: { cost: 0.001 },
24
+ request: { headers: { 'content-type': 'application/json' }, bytes: 10, sha256: 'req', payload: { model: 'qwen', stream: true, tools: TOOLS, input } },
25
+ response: { status, headers: {}, bytes: 20, sha256: 'res', payload: { output } },
26
+ });
27
+
28
+ async function withStore(run) {
29
+ const dir = await mkdtemp(join(tmpdir(), 'raytace-evidence-store-'));
30
+ const store = openEvidenceStore(join(dir, 'evidence.db'));
31
+ try { await run(store, dir); } finally { store.close(); await rm(dir, { recursive: true, force: true }); }
32
+ }
33
+ const all = (store, sql, ...args) => store.db.prepare(sql).all(...args);
34
+ const one = (store, sql, ...args) => store.db.prepare(sql).get(...args);
35
+
36
+ /** The demo: the user asks, the model proposes npm test, the agent sends the
37
+ * result back and answers. Plus Codex's background title job in between. */
38
+ function captureDemo(store, { reported = HEADER(0, 0.3) } = {}) {
39
+ store.recordExchange(exchange('e1', [ENV, PROMPT], [CALL]));
40
+ store.recordExchange(exchange('bg', [{ role: 'user', type: 'message', content: 'Generate a concise, single-line task title for this. User prompt: run tests' }],
41
+ [{ type: 'message', content: [{ type: 'output_text', text: 'Run tests' }] }]));
42
+ store.recordExchange(exchange('e2', [ENV, PROMPT, CALL, RESULT(reported)], [{ type: 'message', content: [{ type: 'output_text', text: 'The tests pass.' }] }]));
43
+ }
44
+
45
+ const exec = (event_id, pid, ppid, argv, startNs, ms) => ({ event_id, kind: 'exec_succeeded', pid, ppid, argv, container_id: CONTAINER,
46
+ process_start_ns: startNs, timestamp_ns: String(BigInt(ms) * 1_000_000n) });
47
+ const exit = (event_id, pid, startNs, exit_code, ms) => ({ event_id, kind: 'process_exit', pid, container_id: CONTAINER,
48
+ process_start_ns: startNs, exit_code, timestamp_ns: String(BigInt(ms) * 1_000_000n) });
49
+
50
+ test('a fresh store is a current-version evidence database', () => withStore((store) => {
51
+ assert.equal(one(store, 'PRAGMA user_version').user_version, SCHEMA_VERSION);
52
+ assert.equal(one(store, "SELECT count(*) n FROM sqlite_schema WHERE type='table' AND name NOT LIKE 'sqlite_%'").n, 35);
53
+ }));
54
+
55
+ test('tool call contexts and Jev assessments round-trip through the store', () => withStore((store) => {
56
+ captureDemo(store);
57
+ const contexts = store.toolCallContexts(['call_1', 'missing', null]);
58
+ assert.deepEqual([...contexts.keys()], ['call_1']);
59
+ const context = contexts.get('call_1');
60
+ assert.equal(context.tool_name, 'exec_command');
61
+ assert.match(JSON.stringify(context.args), /npm test/);
62
+ assert.match(JSON.stringify(context.result), /Process exited with code 0/);
63
+ assert.equal(store.getCallAssessment('k'), null);
64
+ store.putCallAssessment('k', 'call_1', 'jev-1.13.0', { severities: [{ level: 1 }], labels: null });
65
+ assert.deepEqual(store.getCallAssessment('k'), { severities: [{ level: 1 }], labels: null });
66
+ assert.equal(one(store, "SELECT model FROM call_assessments WHERE key='k'").model, 'jev-1.13.0');
67
+ }));
68
+
69
+ test('capture fills session, turn, exchanges, context items and proposed calls', () => withStore((store) => {
70
+ captureDemo(store);
71
+ const [session] = all(store, 'SELECT * FROM agent_sessions');
72
+ assert.equal(session.external_session_id, SESSION);
73
+
74
+ const turns = all(store, 'SELECT * FROM agent_turns');
75
+ assert.equal(turns.length, 1, 'the continuation joins the turn; the title job opens none');
76
+ assert.equal(turns[0].sequence_number, 0);
77
+ assert.equal(turns[0].status, 'completed');
78
+ assert.equal(JSON.parse(one(store, 'SELECT content FROM agent_payloads WHERE sha = ?', turns[0].user_prompt_sha).content), PROMPT.content);
79
+ assert.ok(turns[0].final_response_sha);
80
+
81
+ const exchanges = all(store, 'SELECT id, turn_id, route, method, input_key FROM agent_exchanges ORDER BY started_at_ms');
82
+ assert.deepEqual(exchanges.map((e) => [e.id, e.turn_id === turns[0].id, e.turn_id === null]), [['e1', true, false], ['bg', false, true], ['e2', true, false]]);
83
+ assert.equal(exchanges[0].route, '/v1/responses');
84
+ assert.equal(exchanges[0].input_key, 'input');
85
+
86
+ const [call] = all(store, 'SELECT * FROM agent_tool_calls');
87
+ assert.equal(call.exchange_id, 'e1');
88
+ assert.equal(call.external_call_id, 'call_1');
89
+ assert.equal(call.tool_name, 'exec_command');
90
+ assert.ok(call.reported_result_sha, 'the result sent back is recorded on the call as its report');
91
+ assert.equal(one(store, "SELECT count(*) n FROM agent_context_items WHERE exchange_id = 'e2'").n, 4);
92
+ }));
93
+
94
+ test('a new user message in the same session opens the next turn', () => withStore((store) => {
95
+ captureDemo(store);
96
+ const next = { role: 'user', type: 'message', content: 'now delete notes.md' };
97
+ store.recordExchange(exchange('e3', [ENV, PROMPT, CALL, RESULT('ok'), { type: 'message', role: 'assistant', content: 'The tests pass.' }, next], []));
98
+ assert.deepEqual(all(store, 'SELECT sequence_number FROM agent_turns ORDER BY sequence_number').map((t) => t.sequence_number), [0, 1]);
99
+ }));
100
+
101
+ test('repeated history and tool lists are stored once, and exchanges hydrate back losslessly', () => withStore((store) => {
102
+ captureDemo(store);
103
+ assert.equal(one(store, 'SELECT count(*) n FROM agent_payloads WHERE content LIKE ?', `%${'x'.repeat(400)}%`).n, 1, 'one tools payload');
104
+ const rows = store.exchangeRows({});
105
+ assert.deepEqual(rows.map((r) => r.span_id), ['e1', 'e2'], 'background jobs are not part of any trace');
106
+ assert.equal(rows[0].trace_id, rows[1].trace_id, 'a trace is a turn');
107
+ assert.equal(rows[0].promptTitle, PROMPT.content);
108
+ assert.deepEqual(rows[1].request.payload, exchange('e2', [ENV, PROMPT, CALL, RESULT(HEADER(0, 0.3))], []).request.payload);
109
+ assert.equal(rows[0].request.headers['content-type'], 'application/json');
110
+ assert.deepEqual(store.findExchange('e1').response, { output: [CALL] });
111
+ assert.equal(store.findExchange('bg').route, '/v1/responses', 'background exchanges stay findable for the lab');
112
+ }));
113
+
114
+ test('causal candidates window each call from its proposal to the request that carried its result', () => withStore((store) => {
115
+ captureDemo(store);
116
+ const [candidate] = store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION });
117
+ const [e1, e2] = all(store, "SELECT started_at_ms FROM agent_exchanges WHERE id IN ('e1','e2') ORDER BY started_at_ms");
118
+ assert.equal(candidate.external_call_id, 'call_1');
119
+ assert.equal(candidate.window_start, e1.started_at_ms);
120
+ assert.equal(candidate.window_end, e2.started_at_ms);
121
+ assert.deepEqual(candidate.args, CALL.arguments);
122
+ assert.deepEqual(store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: 'rtp-other' }), []);
123
+ }));
124
+
125
+ /** The sandbox side of the demo: npm test (pid 108), its pretest hook and
126
+ * the rm it runs, and the test itself. */
127
+ function observeDemo(store, { exitCode = 0 } = {}) {
128
+ const [candidate] = store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION });
129
+ const t = candidate.window_start + 100;
130
+ const top = store.recordProcessStart({ containerId: CONTAINER, projectId: SESSION, raw: exec(1, 108, 10, ['/bin/bash', '-c', 'cd /workspace/demo-hook && npm test'], '1000', t), startedMs: t });
131
+ store.attribute({ toolCallId: candidate.call_id, eventId: top.eventId, method: 'window', score: 1, windowStartMs: candidate.window_start, windowEndMs: candidate.window_end });
132
+ for (const [id, pid, ppid, argv, start] of [[2, 119, 108, ['sh', '-c', 'node scripts/prepare.js'], '1100'], [3, 120, 119, ['node', 'scripts/prepare.js'], '1200'], [4, 127, 120, ['rm', '-f', 'notes/todo.md'], '1300']]) {
133
+ const child = store.recordProcessStart({ containerId: CONTAINER, raw: exec(id, pid, ppid, argv, start, t + id * 10), startedMs: t + id * 10 });
134
+ store.attribute({ toolCallId: candidate.call_id, eventId: child.eventId, method: 'inherited' });
135
+ }
136
+ store.recordProcessExit({ containerId: CONTAINER, raw: exit(5, 127, '1300', 0, t + 60), endedMs: t + 60, exit_code: 0 });
137
+ store.recordProcessExit({ containerId: CONTAINER, raw: exit(6, 108, '1000', exitCode, t + 300), endedMs: t + 300, exit_code: exitCode });
138
+ return candidate;
139
+ }
140
+
141
+ test('sandbox processes, their tree and their attributions land in the runtime tables', () => withStore((store) => {
142
+ captureDemo(store);
143
+ observeDemo(store);
144
+ const [sandbox] = all(store, 'SELECT * FROM runtime_sandboxes');
145
+ assert.equal(sandbox.project_id, SESSION, 'the sandbox joins its agent session by the rtp id');
146
+ const processes = all(store, 'SELECT pid, parent_process_id, exit_code, exited_at_ns FROM runtime_processes ORDER BY pid');
147
+ assert.deepEqual(processes.map((p) => p.pid), [108, 119, 120, 127]);
148
+ assert.equal(processes.find((p) => p.pid === 127).parent_process_id, `${CONTAINER}:120:1200`);
149
+ assert.equal(processes.find((p) => p.pid === 108).exit_code, 0);
150
+ assert.equal(processes.find((p) => p.pid === 119).exited_at_ns, null, 'no exit observed yet');
151
+ assert.deepEqual(all(store, 'SELECT method, count(*) n FROM runtime_attributions GROUP BY method ORDER BY method').map((r) => [r.method, r.n]), [['inherited', 3], ['window', 1]]);
152
+ assert.equal(one(store, 'SELECT count(*) n FROM runtime_events').n, 6);
153
+ // No longer a candidate once a process is tied to it.
154
+ assert.deepEqual(store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION }), []);
155
+ }));
156
+
157
+ test('divergence() and descendants() give the dashboard its proposed-vs-observed rows', () => withStore((store) => {
158
+ captureDemo(store);
159
+ const candidate = observeDemo(store);
160
+ const [row] = store.divergence(['e1']);
161
+ assert.equal(row.call_id, 'call_1');
162
+ assert.equal(row.outcome, 'as_proposed');
163
+ assert.equal(row.status, 'completed');
164
+ assert.equal(row.exit_code, 0);
165
+ assert.equal(row.pid, 108);
166
+ assert.equal(row.match_basis, 'window');
167
+ assert.equal(row.tier, 'corroborated');
168
+ assert.equal(row.window_start_ms, candidate.window_start);
169
+ assert.deepEqual(row.argv, ['/bin/bash', '-c', 'cd /workspace/demo-hook && npm test']);
170
+ assert.equal(row.descendant_count, 3);
171
+ assert.equal(row.reported_check, 'agrees', 'the agent reported exit 0 in 0.3 s; the sandbox saw exit 0 in 0.3 s');
172
+
173
+ const children = store.descendants(['e1']);
174
+ assert.deepEqual(children.map((c) => c.argv.join(' ')), ['sh -c node scripts/prepare.js', 'node scripts/prepare.js', 'rm -f notes/todo.md']);
175
+ assert.deepEqual(children.map((c) => c.status), ['running', 'running', 'completed']);
176
+ assert.ok(children.every((c) => c.parent_call_id === 'call_1'));
177
+ }));
178
+
179
+ test('an unobserved call reads as not executed, never as failed', () => withStore((store) => {
180
+ captureDemo(store);
181
+ const [row] = store.divergence(['e1']);
182
+ assert.equal(row.outcome, 'not_executed');
183
+ assert.equal(row.status, null);
184
+ assert.equal(row.pid, null);
185
+ }));
186
+
187
+ test('reported_check records disagreement whichever side arrives first', () => withStore((store) => {
188
+ // The agent claims exit 0; the sandbox saw exit 1.
189
+ captureDemo(store, { reported: HEADER(0, 0.3) });
190
+ observeDemo(store, { exitCode: 1 });
191
+ const [row] = store.divergence(['e1']);
192
+ assert.equal(row.status, 'failed');
193
+ assert.equal(row.error, 'exit 1');
194
+ assert.equal(row.reported_check, 'exit_code_differs');
195
+ }));
196
+
197
+ test('attributionsForProcesses marks own, inherited and unattributed processes by pid + start time', () => withStore((store) => {
198
+ captureDemo(store);
199
+ observeDemo(store);
200
+ store.recordProcessStart({ containerId: CONTAINER, raw: exec(9, 230, 1, ['git', 'status'], '5000', Date.now()), startedMs: Date.now() });
201
+ const byPid = Object.fromEntries(store.attributionsForProcesses({ containerId: CONTAINER, pids: [108, 127, 230, 999] }).map((r) => [r.pid, r]));
202
+ assert.equal(byPid[108].call_id, 'call_1');
203
+ assert.equal(byPid[108].match_basis, 'window');
204
+ assert.equal(byPid[127].parent_call_id, 'call_1');
205
+ assert.deepEqual([byPid[230].call_id, byPid[230].parent_call_id, byPid[230].tier], [null, null, 'unverified']);
206
+ assert.equal(byPid[999], undefined);
207
+ }));
208
+
209
+ test('replayed events are no-ops, and a reused pid is a different process', () => withStore((store) => {
210
+ const raw = exec(1, 50, 1, ['ls'], '100', 1000);
211
+ const first = store.recordProcessStart({ containerId: CONTAINER, raw, startedMs: 1000 });
212
+ const again = store.recordProcessStart({ containerId: CONTAINER, raw, startedMs: 1000 });
213
+ assert.deepEqual(first, again);
214
+ store.recordProcessStart({ containerId: CONTAINER, raw: exec(2, 50, 1, ['pwd'], '900', 2000), startedMs: 2000 });
215
+ assert.equal(one(store, 'SELECT count(*) n FROM runtime_processes WHERE pid = 50').n, 2);
216
+ assert.equal(one(store, 'SELECT count(*) n FROM runtime_events').n, 2);
217
+ // An exit for a process that never exec'd leaves no row.
218
+ assert.equal(store.recordProcessExit({ containerId: CONTAINER, raw: exit(3, 77, '1', 0, 3000), exit_code: 0 }), false);
219
+ }));
220
+
221
+ test('lost evidence marks open processes unknown, and a later real exit still closes them', () => withStore((store) => {
222
+ store.recordProcessStart({ containerId: CONTAINER, raw: exec(1, 50, 1, ['sleep', '300'], '100', 1000), startedMs: 1000 });
223
+ store.recordProcessStart({ containerId: CONTAINER, raw: exec(2, 51, 1, ['true'], '110', 1000), startedMs: 1000 });
224
+ store.recordProcessExit({ containerId: CONTAINER, raw: exit(3, 51, '110', 0, 1100), exit_code: 0 });
225
+ assert.equal(store.loseOpenProcesses({ containerId: CONTAINER, reason: 'collector disconnected', raw: { event_id: 4, kind: 'collector_disconnected', container_id: CONTAINER } }), 1);
226
+ assert.equal(one(store, 'SELECT evidence_lost FROM runtime_processes WHERE pid = 50').evidence_lost, 'collector disconnected');
227
+ assert.equal(one(store, 'SELECT evidence_lost FROM runtime_processes WHERE pid = 51').evidence_lost, null);
228
+ assert.equal(store.recordProcessExit({ containerId: CONTAINER, raw: exit(5, 50, '100', 0, 9000), exit_code: 0 }), true);
229
+ assert.equal(one(store, 'SELECT evidence_lost FROM runtime_processes WHERE pid = 50').evidence_lost, null);
230
+ }));
231
+
232
+ test('a failed execve reads as exec failed on its process', () => withStore((store) => {
233
+ const raw = { event_id: 1, kind: 'exec_failed', pid: 60, ppid: 1, argv: ['./script.sh'], errno: 13, container_id: CONTAINER, process_start_ns: '10', timestamp_ns: '20' };
234
+ store.recordProcessStart({ containerId: CONTAINER, raw, startedMs: 1 });
235
+ const [row] = store.db.prepare(`SELECT p.id FROM runtime_processes p`).all();
236
+ assert.ok(row);
237
+ // Surfaced through the descendant reader when attributed.
238
+ captureDemo(store);
239
+ const [candidate] = store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION });
240
+ store.attribute({ toolCallId: candidate.call_id, eventId: `gvisor:${CONTAINER}:1`, method: 'inherited' });
241
+ const [child] = store.descendants(['e1']);
242
+ assert.deepEqual([child.status, child.error], ['failed', 'exec failed: errno 13']);
243
+ }));
244
+
245
+ test('auxiliary features round trip', () => withStore((store) => {
246
+ store.saveExperiment({ id: 'x1', created_at: new Date().toISOString(), status: 'completed', exchange_id: 'e1', model: 'm' });
247
+ assert.equal(store.loadExperiments()[0].id, 'x1');
248
+ store.putExplanation('k', { a: 1 }); assert.deepEqual(store.getExplanation('k'), { a: 1 });
249
+ store.putSummary('s', 'e1', { text: 'hi' }); assert.deepEqual(store.getSummary('s'), { text: 'hi' }); assert.deepEqual(store.summaryForSpan('e1'), { text: 'hi' });
250
+ store.putCommandDescription('ls -la', 'listed files'); assert.equal(store.getCommandDescription('ls -la'), 'listed files');
251
+ store.recordProxyError({ trace_id: 't', timestamp: new Date().toISOString(), provider: 'p', route: '/r', error: 'boom', cause: { code: 'X' } });
252
+ assert.equal(one(store, 'SELECT count(*) n FROM proxy_errors').n, 1);
253
+ assert.equal(store.stats().exchanges, 0);
254
+ }));
255
+
256
+ test('reopening an existing evidence database keeps its rows; an old-format one is refused untouched', async () => {
257
+ const dir = await mkdtemp(join(tmpdir(), 'raytace-evidence-reopen-'));
258
+ try {
259
+ const file = join(dir, 'evidence.db');
260
+ let store = openEvidenceStore(file); captureDemo(store); store.close();
261
+ store = openEvidenceStore(file); assert.equal(store.stats().exchanges, 3); store.close();
262
+ const { DatabaseSync } = await import('node:sqlite');
263
+ const oldFile = join(dir, 'old.db');
264
+ const old = new DatabaseSync(oldFile); old.exec('CREATE TABLE exchanges (span_id TEXT); PRAGMA user_version = 8'); old.close();
265
+ assert.throws(() => openEvidenceStore(oldFile), /schema version|Incompatible/);
266
+ } finally { await rm(dir, { recursive: true, force: true }); }
267
+ });
268
+
269
+ test('five user turns stay five turns while tool continuations share their turn', () => withStore((store) => {
270
+ const history = [ENV];
271
+ for (let i = 0; i < 5; i++) {
272
+ history.push({ role: 'user', content: [{ type: 'input_text', text: 'same prompt' }] });
273
+ store.recordExchange(exchange(`turn-${i}`, structuredClone(history), [{ type: 'function_call', call_id: `c${i}`, name: 'read_file', arguments: '{}' }]));
274
+ history.push({ type: 'function_call', call_id: `c${i}`, name: 'read_file' }, { type: 'function_call_output', call_id: `c${i}`, output: 'file' });
275
+ store.recordExchange(exchange(`tool-${i}`, structuredClone(history), []));
276
+ }
277
+ const rows = store.exchangeRows({});
278
+ assert.equal(new Set(rows.map((r) => r.trace_id)).size, 5, 'the same words asked again are a new turn');
279
+ for (let i = 0; i < 5; i++) assert.equal(rows[i * 2].trace_id, rows[i * 2 + 1].trace_id);
280
+ assert.deepEqual(all(store, 'SELECT sequence_number FROM agent_turns ORDER BY sequence_number').map((t) => t.sequence_number), [0, 1, 2, 3, 4]);
281
+ }));
282
+
283
+ test('catch-up jobs open no turn, so they never become the visible session', () => withStore((store) => {
284
+ const recap = 'Write a brief catch-up for a user returning to this Codex task. In at most 40 words explain the objective. Recent conversation: User: Read package.json';
285
+ store.recordExchange(exchange('actual', [{ role: 'user', content: 'Read package.json' }], [], { session: 'rtp-' + 'a'.repeat(32) }));
286
+ store.recordExchange(exchange('recap', [{ role: 'user', content: recap }], [], { session: 'rtp-' + 'b'.repeat(32) }));
287
+ assert.deepEqual(store.exchangeRows({}).map((r) => r.promptTitle), ['Read package.json']);
288
+ assert.equal(one(store, "SELECT turn_id FROM agent_exchanges WHERE id = 'recap'").turn_id, null);
289
+ }));
290
+
291
+ test('a process that re-execs shows the command that was matched, not its setup exec', () => withStore((store) => {
292
+ captureDemo(store);
293
+ const [candidate] = store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION });
294
+ const t = candidate.window_start + 100;
295
+ // Codex's environment setup runs first in the same pid, then re-execs into the command.
296
+ store.recordProcessStart({ containerId: CONTAINER, raw: exec(1, 240, 151, ['/bin/bash', '-c', '__CODEX_SNAPSHOT_OVERRIDE_SET_0=…'], '7000', t), startedMs: t });
297
+ const matched = store.recordProcessStart({ containerId: CONTAINER, raw: exec(2, 240, 151, ['/bin/bash', '-c', 'cd /workspace/demo-hook && npm test'], '7000', t + 5), startedMs: t + 5 });
298
+ store.attribute({ toolCallId: candidate.call_id, eventId: matched.eventId, method: 'window', score: 1 });
299
+ assert.equal(one(store, 'SELECT count(*) n FROM runtime_processes WHERE pid = 240').n, 1, 'one process, two execs');
300
+ assert.deepEqual(store.divergence(['e1'])[0].argv, ['/bin/bash', '-c', 'cd /workspace/demo-hook && npm test']);
301
+ }));