raytrace-cli 0.11.1__py3-none-win_amd64.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.
- raytrace/__init__.py +1 -0
- raytrace/__main__.py +33 -0
- raytrace/app/LICENSE +21 -0
- raytrace/app/README.md +599 -0
- raytrace/app/bin/raytrace.mjs +297 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-400-normal-BwCSEQnW.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-400-normal-CW0RaeGs.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-500-normal-B9HHJjqV.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-500-normal-Dr3UlScf.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-600-normal-Aqo67rzb.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-600-normal-BmdmIIQ2.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-700-normal-CUSSCpQX.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-700-normal-DvUfVpUG.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BjWJ59Pq.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BtiwyxMk.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-500-normal-BJfUCQsA.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-500-normal-DR84L5F-.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-600-normal-4vooXBpG.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-600-normal-DRtaDpgU.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-700-normal-BLI3TTWz.woff +0 -0
- raytrace/app/dist/dashboard/assets/dm-sans-latin-ext-700-normal-CJIcxD6K.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-CTOM6hUh.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-fLZuRloM.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-9HEixskS.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-V-xxqcpd.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-D38SheWl.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-DmB0ttJJ.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-D2EvbN8M.woff2 +0 -0
- raytrace/app/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-iLQfcSjf.woff +0 -0
- raytrace/app/dist/dashboard/assets/index-DepcI8Fi.js +38 -0
- raytrace/app/dist/dashboard/assets/index-H97VLD5l.css +1 -0
- raytrace/app/dist/dashboard/favicon.svg +6 -0
- raytrace/app/dist/dashboard/index.html +15 -0
- raytrace/app/package.json +48 -0
- raytrace/app/proxy/agent-intent-schema.test.mjs +142 -0
- raytrace/app/proxy/call-assessment.mjs +385 -0
- raytrace/app/proxy/call-assessment.test.mjs +167 -0
- raytrace/app/proxy/call-category.mjs +461 -0
- raytrace/app/proxy/capture-health.mjs +30 -0
- raytrace/app/proxy/capture-health.test.mjs +44 -0
- raytrace/app/proxy/capture.mjs +38 -0
- raytrace/app/proxy/capture.test.mjs +49 -0
- raytrace/app/proxy/claude-code-adapter.mjs +301 -0
- raytrace/app/proxy/claude-code-hook.mjs +22 -0
- raytrace/app/proxy/codex-config.mjs +36 -0
- raytrace/app/proxy/codex.mjs +14 -0
- raytrace/app/proxy/evidence-schema.test.mjs +240 -0
- raytrace/app/proxy/evidence-store.mjs +993 -0
- raytrace/app/proxy/evidence-store.test.mjs +301 -0
- raytrace/app/proxy/exec-narrative.mjs +625 -0
- raytrace/app/proxy/exec-narrative.test.mjs +262 -0
- raytrace/app/proxy/execution-correlation.mjs +185 -0
- raytrace/app/proxy/execution-correlation.test.mjs +146 -0
- raytrace/app/proxy/execution-runner.mjs +89 -0
- raytrace/app/proxy/execution-runner.test.mjs +38 -0
- raytrace/app/proxy/experiment-engine.mjs +195 -0
- raytrace/app/proxy/experiment-engine.test.mjs +93 -0
- raytrace/app/proxy/explanations.mjs +36 -0
- raytrace/app/proxy/explanations.test.mjs +20 -0
- raytrace/app/proxy/failure-signature.mjs +56 -0
- raytrace/app/proxy/gvisor-forwarder.mjs +493 -0
- raytrace/app/proxy/gvisor-forwarder.test.mjs +433 -0
- raytrace/app/proxy/init-evidence-db.mjs +227 -0
- raytrace/app/proxy/local-sandboxes.mjs +94 -0
- raytrace/app/proxy/local-token.mjs +30 -0
- raytrace/app/proxy/playground-recovery.test.mjs +130 -0
- raytrace/app/proxy/playground.mjs +439 -0
- raytrace/app/proxy/prompt-context.mjs +278 -0
- raytrace/app/proxy/prompt-traces.mjs +40 -0
- raytrace/app/proxy/prompt-traces.test.mjs +32 -0
- raytrace/app/proxy/providers.mjs +65 -0
- raytrace/app/proxy/providers.test.mjs +76 -0
- raytrace/app/proxy/proxy.integration.test.mjs +135 -0
- raytrace/app/proxy/raytace-proxy.mjs +941 -0
- raytrace/app/proxy/request-metrics.mjs +13 -0
- raytrace/app/proxy/request-metrics.test.mjs +19 -0
- raytrace/app/proxy/request-policy.mjs +45 -0
- raytrace/app/proxy/request-policy.test.mjs +47 -0
- raytrace/app/proxy/run-recap.mjs +139 -0
- raytrace/app/proxy/runtime-attribution.mjs +110 -0
- raytrace/app/proxy/sandbox-bridge.mjs +49 -0
- raytrace/app/proxy/schema/EVIDENCE_DATABASE.md +276 -0
- raytrace/app/proxy/schema/agent_intent.sql +101 -0
- raytrace/app/proxy/schema/auxiliary.sql +90 -0
- raytrace/app/proxy/schema/capture_health.sql +14 -0
- raytrace/app/proxy/schema/classification.sql +89 -0
- raytrace/app/proxy/schema/file_context.sql +53 -0
- raytrace/app/proxy/schema/runtime_evidence.sql +201 -0
- raytrace/app/proxy/schema/search.sql +66 -0
- raytrace/app/proxy/schema/shared_storage.sql +21 -0
- raytrace/app/proxy/search.mjs +418 -0
- raytrace/app/proxy/search.test.mjs +161 -0
- raytrace/app/proxy/smoke.test.mjs +93 -0
- raytrace/app/proxy/step-attribution.mjs +380 -0
- raytrace/app/proxy/step-lab.mjs +78 -0
- raytrace/app/proxy/step-lab.test.mjs +38 -0
- raytrace/app/proxy/summaries.mjs +151 -0
- raytrace/app/proxy/summaries.test.mjs +69 -0
- raytrace/app/proxy/tool-metadata.mjs +111 -0
- raytrace/app/proxy/tool-metadata.test.mjs +38 -0
- raytrace/app/proxy/trace-view.mjs +324 -0
- raytrace/app/proxy/trace-view.test.mjs +92 -0
- raytrace/app/proxy/typesafe.mjs +63 -0
- raytrace/app/proxy/typesafe.test.mjs +39 -0
- raytrace/app/src/agents.mjs +7 -0
- raytrace/app/src/api.mjs +57 -0
- raytrace/app/src/auth.mjs +205 -0
- raytrace/app/src/beta.mjs +96 -0
- raytrace/app/src/claude-code.mjs +93 -0
- raytrace/app/src/commands.mjs +285 -0
- raytrace/app/src/config.mjs +49 -0
- raytrace/app/src/export.mjs +200 -0
- raytrace/app/src/lima.mjs +176 -0
- raytrace/app/src/local-sandbox.mjs +358 -0
- raytrace/app/src/mcp.mjs +688 -0
- raytrace/app/src/paths.mjs +33 -0
- raytrace/app/src/prompt.mjs +42 -0
- raytrace/app/src/proxy-process.mjs +143 -0
- raytrace/app/src/sandbox.mjs +306 -0
- raytrace/app/src/share.mjs +86 -0
- raytrace/app/src/terminal.mjs +68 -0
- raytrace/app/src/upload.mjs +198 -0
- raytrace/app/worker/sandbox/Dockerfile +8 -0
- raytrace/app/worker/sandbox/SYSCALL_CATALOG.md +197 -0
- raytrace/app/worker/sandbox/claude-hook.mjs +364 -0
- raytrace/app/worker/sandbox/collector.py +405 -0
- raytrace/app/worker/sandbox/dns_forwarder.py +255 -0
- raytrace/app/worker/sandbox/engine.py +940 -0
- raytrace/app/worker/sandbox/file_scan.py +491 -0
- raytrace/app/worker/sandbox/lima.yaml +29 -0
- raytrace/app/worker/sandbox/network.py +90 -0
- raytrace/app/worker/sandbox/projects.py +702 -0
- raytrace/app/worker/sandbox/setup.py +159 -0
- raytrace/app/worker/sandbox/syscall_catalog.sql +985 -0
- raytrace/app/worker/sandbox/transcript-delivery.test.mjs +153 -0
- raytrace/app/worker/sandbox/viewer.py +195 -0
- raytrace/node/LICENSE +2946 -0
- raytrace/node/node.exe +4 -0
- raytrace_cli-0.11.1.dist-info/LICENSE +21 -0
- raytrace_cli-0.11.1.dist-info/METADATA +42 -0
- raytrace_cli-0.11.1.dist-info/RECORD +165 -0
- raytrace_cli-0.11.1.dist-info/WHEEL +4 -0
- raytrace_cli-0.11.1.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import * as fsPromises from 'node:fs/promises';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
|
|
10
|
+
const root = resolve(fileURLToPath(new URL('../../', import.meta.url)));
|
|
11
|
+
const session = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
|
12
|
+
const setup = (repo) => {
|
|
13
|
+
const dir = mkdtempSync(join(tmpdir(), 'raytrace-delivery-'));
|
|
14
|
+
const home = join(dir, 'isolated-home');
|
|
15
|
+
const state = join(dir, 'offsets');
|
|
16
|
+
const transcript = join(home, '.claude', 'projects', 'test', `${session}.jsonl`);
|
|
17
|
+
mkdirSync(resolve(transcript, '..'), {recursive:true});
|
|
18
|
+
mkdirSync(join(home,'.raytace'), {recursive:true});
|
|
19
|
+
mkdirSync(join(home,'.raytace-codex'), {recursive:true});
|
|
20
|
+
writeFileSync(join(home,'.raytace','sandbox-token'), 'synthetic-token');
|
|
21
|
+
writeFileSync(join(home,'.raytace-codex','config.toml'), '"x-raytace-sandbox-token" = "synthetic-token"');
|
|
22
|
+
const hookPath = fileURLToPath(new URL('./claude-hook.mjs', import.meta.url));
|
|
23
|
+
const source = readFileSync(hookPath,'utf8')
|
|
24
|
+
.replace("const home = process.env.HOME || '/home/node';", `const home = ${JSON.stringify(home)};`)
|
|
25
|
+
.replace("const STATE_DIR = '/tmp/raytace-claude';", `const STATE_DIR = ${JSON.stringify(state)};`);
|
|
26
|
+
const hook = join(dir,'hook.mjs'); writeFileSync(hook,source);
|
|
27
|
+
const preloader = join(dir,'fake-transport.mjs');
|
|
28
|
+
const adapter = pathToFileURL(resolve(root,'proxy/claude-code-adapter.mjs')).href;
|
|
29
|
+
writeFileSync(preloader, `
|
|
30
|
+
import {existsSync,readFileSync,writeFileSync,appendFileSync} from 'node:fs';
|
|
31
|
+
import {join} from 'node:path';
|
|
32
|
+
import {parseTranscript,exchangesFromTranscript} from ${JSON.stringify(adapter)};
|
|
33
|
+
const dir=${JSON.stringify(dir)};
|
|
34
|
+
globalThis.fetch=async (url,init)=>{
|
|
35
|
+
const note=JSON.parse(init.body), calls=join(dir,'calls.jsonl'), server=join(dir,'received.txt');
|
|
36
|
+
appendFileSync(calls, JSON.stringify({note,bytes:Buffer.byteLength(init.body)})+'\\n');
|
|
37
|
+
const mode=JSON.parse(readFileSync(join(dir,'mode.json'),'utf8'));
|
|
38
|
+
if(mode.grow){appendFileSync(${JSON.stringify(transcript)},mode.grow);writeFileSync(join(dir,'mode.json'),'{}');}
|
|
39
|
+
let bytes=existsSync(server)?readFileSync(server):Buffer.alloc(0);
|
|
40
|
+
const answer=(status,body)=>({status,ok:status===200,json:async()=>body});
|
|
41
|
+
if(mode.fail) return answer(503,{});
|
|
42
|
+
if(mode.conflict) return answer(409,{size:bytes.length});
|
|
43
|
+
if(note.offset!==bytes.length) return answer(409,{size:bytes.length});
|
|
44
|
+
bytes=Buffer.concat([bytes,Buffer.from(note.text)]);writeFileSync(server,bytes);
|
|
45
|
+
if(mode.loseAck){writeFileSync(join(dir,'mode.json'),'{}');throw new Error('synthetic lost acknowledgement');}
|
|
46
|
+
const lines=parseTranscript(bytes.toString('utf8'));
|
|
47
|
+
const rows=exchangesFromTranscript(lines,{final:note.hook_event_name==='Stop'&¬e.more!==true});
|
|
48
|
+
for(const row of rows) appendFileSync(join(dir,'rows.jsonl'),JSON.stringify(row)+'\\n');
|
|
49
|
+
return answer(200,{size:bytes.length});
|
|
50
|
+
};`);
|
|
51
|
+
writeFileSync(join(dir,'mode.json'),'{}');
|
|
52
|
+
return {dir,state,transcript,run() {
|
|
53
|
+
const result=spawnSync(process.execPath,['--import',preloader,hook],{
|
|
54
|
+
input:JSON.stringify({session_id:session,transcript_path:transcript,hook_event_name:'Stop'}),
|
|
55
|
+
encoding:'utf8',timeout:15000,maxBuffer:1024*1024,
|
|
56
|
+
});
|
|
57
|
+
assert.equal(result.error,undefined);assert.equal(result.status,0,result.stderr);
|
|
58
|
+
}, calls(){return readFileSync(join(dir,'calls.jsonl'),'utf8').trim().split('\n').map(JSON.parse);},
|
|
59
|
+
mode(value){writeFileSync(join(dir,'mode.json'),JSON.stringify(value));},
|
|
60
|
+
offset(){return existsSync(join(state,`${session}.offset`))?Number(readFileSync(join(state,`${session}.offset`),'utf8')):0;},
|
|
61
|
+
received(){return existsSync(join(dir,'received.txt'))?readFileSync(join(dir,'received.txt'),'utf8'):'';},
|
|
62
|
+
close(){rmSync(dir,{recursive:true,force:true});}};
|
|
63
|
+
};
|
|
64
|
+
for (const repo of ['local']) {
|
|
65
|
+
test(`${repo}: actual hook drains escaped oversized lines across UTF-8 boundaries and finalizes only once`,()=>{
|
|
66
|
+
const fixture=setup(repo);
|
|
67
|
+
try {
|
|
68
|
+
const line=(type,message,extra={})=>JSON.stringify({type,sessionId:session,timestamp:'2026-10-28T00:00:00Z',message,...extra})+'\n';
|
|
69
|
+
const raw=line('user',{content:'synthetic prompt'})
|
|
70
|
+
+line('assistant',{id:'message',content:[{type:'text',text:'first part'}]},{requestId:'request'})
|
|
71
|
+
+line('user',{content:[{type:'tool_result',tool_use_id:'call',content:'\\'.repeat(2_500_000)+'😀'.repeat(300_000)}]})
|
|
72
|
+
+line('assistant',{id:'message',content:[{type:'text',text:'last part'}]},{requestId:'request'});
|
|
73
|
+
writeFileSync(fixture.transcript,raw);fixture.run();
|
|
74
|
+
assert.equal(fixture.received(),raw);assert.equal(fixture.offset(),Buffer.byteLength(raw));
|
|
75
|
+
const calls=fixture.calls();assert.ok(calls.length>8);
|
|
76
|
+
assert.ok(calls.every(c=>c.bytes<=4*1024*1024));
|
|
77
|
+
assert.ok(calls.slice(0,-1).every(c=>c.note.more===true));assert.equal(calls.at(-1).note.more,false);
|
|
78
|
+
const rows=readFileSync(join(fixture.dir,'rows.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
79
|
+
assert.equal(rows.length,1);assert.equal(rows[0].response.payload.output.length,2);
|
|
80
|
+
} finally {fixture.close();}
|
|
81
|
+
});
|
|
82
|
+
test(`${repo}: failed send retains offset and retry delivers exact bytes`,()=>{
|
|
83
|
+
const fixture=setup(repo);try {
|
|
84
|
+
const raw=JSON.stringify({type:'user',message:{content:'hello 😀'}})+'\n';
|
|
85
|
+
writeFileSync(fixture.transcript,raw);fixture.mode({fail:true});fixture.run();
|
|
86
|
+
assert.equal(fixture.offset(),0);assert.equal(fixture.received(),'');
|
|
87
|
+
fixture.mode({});fixture.run();assert.equal(fixture.received(),raw);assert.equal(fixture.offset(),Buffer.byteLength(raw));
|
|
88
|
+
} finally {fixture.close();}
|
|
89
|
+
});
|
|
90
|
+
test(`${repo}: lost acknowledgement resumes with 409 without duplicating bytes`,()=>{
|
|
91
|
+
const fixture=setup(repo);try {
|
|
92
|
+
const raw=JSON.stringify({type:'user',message:{content:'hello'}})+'\n';
|
|
93
|
+
writeFileSync(fixture.transcript,raw);fixture.mode({loseAck:true});fixture.run();
|
|
94
|
+
assert.equal(fixture.offset(),0);assert.equal(fixture.received(),raw);
|
|
95
|
+
fixture.run();assert.equal(fixture.received(),raw);assert.equal(fixture.offset(),Buffer.byteLength(raw));
|
|
96
|
+
} finally {fixture.close();}
|
|
97
|
+
});
|
|
98
|
+
test(`${repo}: drain stops at entry size and a later hook sends concurrently appended bytes`,()=>{
|
|
99
|
+
const fixture=setup(repo);try {
|
|
100
|
+
const raw=JSON.stringify({type:'user',message:{content:'initial'}})+'\n';
|
|
101
|
+
const added=JSON.stringify({type:'user',message:{content:'appended during send'}})+'\n';
|
|
102
|
+
writeFileSync(fixture.transcript,raw);fixture.mode({grow:added});fixture.run();
|
|
103
|
+
assert.equal(fixture.received(),raw);assert.equal(fixture.offset(),Buffer.byteLength(raw));
|
|
104
|
+
fixture.run();assert.equal(fixture.received(),raw+added);
|
|
105
|
+
} finally {fixture.close();}
|
|
106
|
+
});
|
|
107
|
+
test(`${repo}: repeated conflicts have a bounded retry budget`,()=>{
|
|
108
|
+
const fixture=setup(repo);try {
|
|
109
|
+
writeFileSync(fixture.transcript,'{}\n');fixture.mode({conflict:true});fixture.run();
|
|
110
|
+
assert.equal(fixture.calls().length,8);assert.equal(fixture.offset(),0);
|
|
111
|
+
} finally {fixture.close();}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const sessionPattern=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
116
|
+
for (const repo of ['local']) {
|
|
117
|
+
test(`${repo}: real receiver accepts partial lines, enforces byte offsets and validates fragment flags`,async()=>{
|
|
118
|
+
const dir=mkdtempSync(join(tmpdir(), 'raytrace-receiver-'));
|
|
119
|
+
try {
|
|
120
|
+
const source=readFileSync(resolve(root,'proxy/raytace-proxy.mjs'),'utf8');
|
|
121
|
+
const start=source.indexOf('async function appendSandboxTranscript(');
|
|
122
|
+
const end=source.indexOf('\n/**',start);
|
|
123
|
+
const fn=new Function('join','sandboxTranscripts','CLAUDE_SESSION_ID','serially','mkdir','stat','appendFile',
|
|
124
|
+
`${source.slice(start,end)};return appendSandboxTranscript;`)(join,dir,sessionPattern,(_path,job)=>job(),fsPromises.mkdir,fsPromises.stat,fsPromises.appendFile);
|
|
125
|
+
const initial={session_id:session,offset:0,text:'{"value":"😀',more:true};
|
|
126
|
+
const first=await fn('rtp-synthetic',initial);assert.equal(first.status,200);
|
|
127
|
+
assert.equal(first.body.size,Buffer.byteLength(initial.text));
|
|
128
|
+
const duplicate=await fn('rtp-synthetic',initial);assert.equal(duplicate.status,409);assert.equal(duplicate.body.size,first.body.size);
|
|
129
|
+
const tail={session_id:session,offset:first.body.size,text:'"}\n',more:false};
|
|
130
|
+
const final=await fn('rtp-synthetic',tail);assert.equal(final.status,200);
|
|
131
|
+
assert.equal(readFileSync(join(dir,'rtp-synthetic',`${session}.jsonl`),'utf8'),initial.text+tail.text);
|
|
132
|
+
assert.equal((await fn('rtp-synthetic',{...tail,offset:final.body.size,more:'false'})).status,400);
|
|
133
|
+
assert.equal((await fn('rtp-synthetic',{...tail,offset:-1})).status,400);
|
|
134
|
+
assert.equal((await fn('rtp-synthetic',{...tail,session_id:'../../bad'})).status,400);
|
|
135
|
+
// Existing whole-line senders remain accepted without the new flag.
|
|
136
|
+
assert.equal((await fn('rtp-synthetic',{session_id:session,offset:final.body.size,text:'{}\n'})).status,200);
|
|
137
|
+
} finally {rmSync(dir,{recursive:true,force:true});}
|
|
138
|
+
});
|
|
139
|
+
test(`${repo}: actual serialized envelope is bounded and queued metadata is retained`,()=>{
|
|
140
|
+
const fixture=setup(repo);try {
|
|
141
|
+
mkdirSync(fixture.state,{recursive:true});
|
|
142
|
+
const event={id:'synthetic-large-event',detail:'x'.repeat(3_700_000)};
|
|
143
|
+
const queue=join(fixture.state,`${session}.events.jsonl`);
|
|
144
|
+
writeFileSync(queue,JSON.stringify(event)+'\n');
|
|
145
|
+
const raw=JSON.stringify({type:'user',message:{content:'\\'.repeat(400_000)}})+'\n';
|
|
146
|
+
writeFileSync(fixture.transcript,raw);fixture.run();
|
|
147
|
+
assert.equal(fixture.received(),raw);
|
|
148
|
+
const calls=fixture.calls();assert.ok(calls.length>1);assert.ok(calls.every(c=>c.bytes<=4*1024*1024));
|
|
149
|
+
assert.deepEqual(calls[0].note.events,[event]);assert.equal(readFileSync(queue,'utf8'),'');
|
|
150
|
+
} finally {fixture.close();}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""Loopback-only, read-only evidence viewer, forwarded by Lima to the Mac and
|
|
2
|
+
tunnelled to the control plane. A forwarded port is open to every account on
|
|
3
|
+
the machine at its end, so each request carries the token in this file. No
|
|
4
|
+
token, no evidence.
|
|
5
|
+
"""
|
|
6
|
+
import hmac
|
|
7
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
import sqlite3
|
|
11
|
+
import time
|
|
12
|
+
from urllib.parse import urlparse, parse_qs
|
|
13
|
+
|
|
14
|
+
TOKEN = Path('/etc/raytace/viewer-token')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def allowed(header):
|
|
18
|
+
try:
|
|
19
|
+
token = TOKEN.read_text().strip()
|
|
20
|
+
except OSError:
|
|
21
|
+
return False
|
|
22
|
+
return bool(token) and hmac.compare_digest(header.encode(), f'Bearer {token}'.encode())
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def event_page(db, query):
|
|
26
|
+
container = query.get('container', [''])[0]
|
|
27
|
+
before = int(query.get('before', ['0'])[0])
|
|
28
|
+
# `after` is the tailing cursor used by the RayTrace proxy's gVisor
|
|
29
|
+
# forwarder: events with id > after, oldest first, so a poller can
|
|
30
|
+
# advance through the log without gaps. `before` (the UI's "older
|
|
31
|
+
# events" paging, newest first) still works on its own; `after` wins
|
|
32
|
+
# when both are given.
|
|
33
|
+
after = int(query.get('after', ['0'])[0])
|
|
34
|
+
limit = min(500, max(1, int(query.get('limit', ['100'])[0])))
|
|
35
|
+
# `since`/`until` (epoch ms, inclusive) scope a page to one agent turn --
|
|
36
|
+
# from the prompt to the answer -- so the UI is not showing every command
|
|
37
|
+
# ever run in this sandbox. Filtered on the collector's own `received_ms`
|
|
38
|
+
# column rather than the event's timestamp_ns, which lives inside the JSON
|
|
39
|
+
# body: the two differ by well under a millisecond, and a column is
|
|
40
|
+
# indexable where a json_extract is not.
|
|
41
|
+
since = int(query.get('since', ['0'])[0])
|
|
42
|
+
until = int(query.get('until', ['0'])[0])
|
|
43
|
+
clauses, params = [], []
|
|
44
|
+
if container:
|
|
45
|
+
clauses.append('container_id = ?'); params.append(container)
|
|
46
|
+
if since:
|
|
47
|
+
clauses.append('received_ms >= ?'); params.append(since)
|
|
48
|
+
if until:
|
|
49
|
+
clauses.append('received_ms <= ?'); params.append(until)
|
|
50
|
+
if 'after' in query:
|
|
51
|
+
clauses.append('id > ?'); params.append(after)
|
|
52
|
+
elif before:
|
|
53
|
+
clauses.append('id < ?'); params.append(before)
|
|
54
|
+
if query.get('processes', [''])[0] == '1':
|
|
55
|
+
clauses.append("kind IN ('exec_succeeded','exec_failed','process_exit','collection_gap','collection_error','collector_connected','collector_disconnected')")
|
|
56
|
+
where = ' WHERE ' + ' AND '.join(clauses) if clauses else ''
|
|
57
|
+
order = 'ASC' if 'after' in query else 'DESC'
|
|
58
|
+
rows = db.execute('SELECT id,body,container_id FROM runtime_events'+where+' ORDER BY id '+order+' LIMIT ?', (*params, limit+1)).fetchall()
|
|
59
|
+
events = []
|
|
60
|
+
for identifier, body, bound_container in rows[:limit]:
|
|
61
|
+
event=json.loads(body); event.pop('raw_packet_base64',None)
|
|
62
|
+
event['event_id']=identifier; event['container_id']=bound_container; events.append(event)
|
|
63
|
+
page = {'events':events,'next_before':None if 'after' in query else (rows[limit-1][0] if len(rows)>limit else None)}
|
|
64
|
+
if 'after' in query:
|
|
65
|
+
page['next_after'] = rows[limit-1][0] if len(rows) > limit else None
|
|
66
|
+
# Metadata comes from the same selected container and time interval,
|
|
67
|
+
# independently of pagination or the processes-only display filter.
|
|
68
|
+
page['coverage'] = coverage_page(db, query)
|
|
69
|
+
page['gaps'] = page['coverage']['gaps']
|
|
70
|
+
return page
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def coverage_page(db, query):
|
|
74
|
+
container = query.get('container', [''])[0]
|
|
75
|
+
since, until = (int(query.get(key, ['0'])[0]) for key in ('since', 'until'))
|
|
76
|
+
clauses, params = [], []
|
|
77
|
+
for sql, value in [('container_id=?', container), ('received_ms>=?', since), ('received_ms<=?', until)]:
|
|
78
|
+
if value:
|
|
79
|
+
clauses.append(sql); params.append(value)
|
|
80
|
+
where = ' WHERE ' + ' AND '.join(clauses) if clauses else ''
|
|
81
|
+
gap_clauses, gap_params = ["kind IN ('collection_gap','collection_error')"], []
|
|
82
|
+
if container:
|
|
83
|
+
gap_clauses.append('container_id=?'); gap_params.append(container)
|
|
84
|
+
if since:
|
|
85
|
+
gap_clauses.append('received_ms>=?'); gap_params.append(since)
|
|
86
|
+
if until:
|
|
87
|
+
gap_clauses.append("COALESCE(json_extract(body,'$.gap_from_ms'),received_ms)<=?"); gap_params.append(until)
|
|
88
|
+
gaps = db.execute('SELECT COUNT(*) FROM runtime_events WHERE ' + ' AND '.join(gap_clauses), gap_params).fetchone()[0]
|
|
89
|
+
latest = db.execute('SELECT COALESCE(MAX(id),0) FROM runtime_events' + (' WHERE container_id=?' if container else ''), (container,) if container else ()).fetchone()[0]
|
|
90
|
+
result = {'version': 1, 'container_id': container, 'gaps': gaps, 'latest': latest, 'streams': [], 'checked_at_ms': int(time.time()*1000)}
|
|
91
|
+
try:
|
|
92
|
+
state = db.execute('SELECT instance_id,heartbeat_ms FROM collector_state WHERE id=1').fetchone()
|
|
93
|
+
if state:
|
|
94
|
+
result.update(source_instance_id=state[0], heartbeat_ms=state[1])
|
|
95
|
+
rows = db.execute('SELECT id,collector_id,container_id,started_ms,ended_ms,heartbeat_ms,dropped,errors,capabilities_json FROM capture_streams WHERE container_id=? ORDER BY started_ms', (container,)).fetchall()
|
|
96
|
+
result['streams'] = [dict(zip(('id','collector_id','container_id','started_ms','ended_ms','heartbeat_ms','dropped','errors','capabilities'), row)) for row in rows]
|
|
97
|
+
for stream in result['streams']:
|
|
98
|
+
stream['capabilities'] = json.loads(stream['capabilities'])
|
|
99
|
+
except sqlite3.OperationalError:
|
|
100
|
+
pass # Old collectors remain readable, with unknown health.
|
|
101
|
+
return result
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def fact_page(db, query):
|
|
105
|
+
"""Facts the engine drew (engine.py), oldest first after `after`: the
|
|
106
|
+
control plane's cursor over every sandbox of this host, or with `container`
|
|
107
|
+
over one. A fact that grew since it was read comes again under a new id, so
|
|
108
|
+
the reader replaces its copy. `latest` is the highest id ever given: a
|
|
109
|
+
reader whose cursor is past it is looking at a new database."""
|
|
110
|
+
container = query.get('container', [''])[0]
|
|
111
|
+
after = int(query.get('after', ['0'])[0])
|
|
112
|
+
limit = min(1000, max(1, int(query.get('limit', ['500'])[0])))
|
|
113
|
+
clauses, params = ['id > ?'], [after]
|
|
114
|
+
if container:
|
|
115
|
+
clauses.append('container_id = ?'); params.append(container)
|
|
116
|
+
rows = db.execute('SELECT id, body FROM facts WHERE ' + ' AND '.join(clauses) + ' ORDER BY id LIMIT ?', (*params, limit + 1)).fetchall()
|
|
117
|
+
facts = [{**json.loads(body), 'id': identifier} for identifier, body in rows[:limit]]
|
|
118
|
+
latest = db.execute("SELECT seq FROM sqlite_sequence WHERE name = 'facts'").fetchone()
|
|
119
|
+
return {'facts': facts, 'next_after': facts[-1]['id'] if len(rows) > limit else None, 'latest': latest[0] if latest else 0}
|
|
120
|
+
|
|
121
|
+
PAGE = '''<!doctype html><meta charset="utf-8"><title>RayTrace runtime evidence</title>
|
|
122
|
+
<style>body{font:15px system-ui;background:#111827;color:#e5e7eb;margin:32px}table{width:100%;border-collapse:collapse}td,th{text-align:left;padding:10px;border-bottom:1px solid #374151}code{white-space:pre-wrap}select{padding:8px} .note{color:#fbbf24}</style>
|
|
123
|
+
<h1>Runtime evidence</h1><p>Independent gVisor process events. Select a sandbox to inspect its timeline.</p>
|
|
124
|
+
<p class="note">Coverage: selected process events only. Missing evidence is not proof of non-execution. Disconnects do not certify completeness.</p>
|
|
125
|
+
<select id="jobs"><option value="">All sandboxes and collector health</option></select><p id="status"></p>
|
|
126
|
+
<table><thead><tr><th>Event</th><th>PID / parent</th><th>Executable / arguments / result</th></tr></thead><tbody id="events"></tbody></table>
|
|
127
|
+
<script>
|
|
128
|
+
const select=document.getElementById('jobs');
|
|
129
|
+
async function refresh(){try{const response=await fetch('events'+(select.value?'?container='+encodeURIComponent(select.value):''));if(!response.ok)throw Error('Collector unavailable');const data=await response.json();
|
|
130
|
+
const chosen=select.value;select.replaceChildren(new Option('All sandboxes and collector health',''));for(const id of data.containers)select.add(new Option(id.slice(0,16),id));select.value=chosen;
|
|
131
|
+
const rows=data.events.filter(e=>!select.value||e.container_id===select.value);
|
|
132
|
+
document.getElementById('status').textContent='Latest '+rows.length+' events (up to 500). '+data.gaps+' recorded collection errors/gaps.';
|
|
133
|
+
const body=document.getElementById('events');body.replaceChildren();for(const e of rows){const {raw_packet_base64,...detail}=e;const tr=document.createElement('tr');for(const v of [e.kind,`${e.pid??'—'} / ${e.ppid??'—'}`,JSON.stringify(detail)]){const td=document.createElement('td');const code=document.createElement('code');code.textContent=v;td.append(code);tr.append(td);}body.append(tr);}
|
|
134
|
+
}catch(e){document.getElementById('status').textContent=e.message;}}
|
|
135
|
+
select.onchange=refresh;refresh();setInterval(refresh,1500);
|
|
136
|
+
</script>'''
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class Handler(BaseHTTPRequestHandler):
|
|
140
|
+
def do_GET(self):
|
|
141
|
+
if self.headers.get('Host', '').split(':')[0] not in ('localhost', '127.0.0.1'):
|
|
142
|
+
self.send_error(403)
|
|
143
|
+
return
|
|
144
|
+
if not allowed(self.headers.get('Authorization', '')):
|
|
145
|
+
self.send_error(401)
|
|
146
|
+
return
|
|
147
|
+
if self.path == '/':
|
|
148
|
+
body, mime = PAGE.encode(), 'text/html; charset=utf-8'
|
|
149
|
+
elif urlparse(self.path).path == '/time':
|
|
150
|
+
# The VM's realtime clock, which gVisor stamps events with. The
|
|
151
|
+
# proxy on the Mac samples this to map event times onto its own
|
|
152
|
+
# clock; the two drift apart, notably after the Mac sleeps.
|
|
153
|
+
body, mime = json.dumps({'realtime_ns': str(time.time_ns())}).encode(), 'application/json'
|
|
154
|
+
elif urlparse(self.path).path == '/facts':
|
|
155
|
+
try:
|
|
156
|
+
with sqlite3.connect('file:/var/lib/raytace/runtime.db?mode=ro', uri=True) as db:
|
|
157
|
+
body, mime = json.dumps(fact_page(db, parse_qs(urlparse(self.path).query))).encode(), 'application/json'
|
|
158
|
+
except sqlite3.OperationalError:
|
|
159
|
+
# A host whose engine has not run yet has no facts table: none, not an error.
|
|
160
|
+
body, mime = json.dumps({'facts': [], 'next_after': None, 'latest': 0}).encode(), 'application/json'
|
|
161
|
+
except (sqlite3.Error, ValueError):
|
|
162
|
+
self.send_error(503, 'Evidence database unavailable')
|
|
163
|
+
return
|
|
164
|
+
elif urlparse(self.path).path == '/coverage':
|
|
165
|
+
try:
|
|
166
|
+
with sqlite3.connect('file:/var/lib/raytace/runtime.db?mode=ro', uri=True) as db:
|
|
167
|
+
body = json.dumps(coverage_page(db, parse_qs(urlparse(self.path).query))).encode()
|
|
168
|
+
mime = 'application/json'
|
|
169
|
+
except (sqlite3.Error, ValueError):
|
|
170
|
+
self.send_error(503, 'Recording health unavailable')
|
|
171
|
+
return
|
|
172
|
+
elif urlparse(self.path).path == '/events':
|
|
173
|
+
try:
|
|
174
|
+
with sqlite3.connect('file:/var/lib/raytace/runtime.db?mode=ro', uri=True) as db:
|
|
175
|
+
page = event_page(db, parse_qs(urlparse(self.path).query))
|
|
176
|
+
containers = [r[0] for r in db.execute("SELECT DISTINCT container_id FROM runtime_events WHERE container_id != ''")]
|
|
177
|
+
gaps = page['gaps']
|
|
178
|
+
body = json.dumps({**page, 'containers': containers, 'gaps': gaps, 'coverage':page['coverage']}).encode()
|
|
179
|
+
mime = 'application/json'
|
|
180
|
+
except (sqlite3.Error, ValueError):
|
|
181
|
+
self.send_error(503, 'Evidence database unavailable')
|
|
182
|
+
return
|
|
183
|
+
else:
|
|
184
|
+
self.send_error(404)
|
|
185
|
+
return
|
|
186
|
+
self.send_response(200)
|
|
187
|
+
self.send_header('Content-Type', mime)
|
|
188
|
+
self.send_header('Cache-Control', 'no-store')
|
|
189
|
+
self.send_header('X-Content-Type-Options', 'nosniff')
|
|
190
|
+
self.end_headers()
|
|
191
|
+
self.wfile.write(body)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == '__main__':
|
|
195
|
+
ThreadingHTTPServer(('127.0.0.1', 8798), Handler).serve_forever()
|