@raytrace-cli/cli 0.17.17 → 0.19.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.
- package/bin/raytrace.mjs +9 -2
- package/package.json +5 -1
- package/src/auth.mjs +3 -3
- package/src/beta.mjs +12 -10
- package/src/local-sandbox.mjs +21 -5
- package/src/mcp.mjs +11 -12
- package/src/sandbox.mjs +19 -20
- package/src/update-check.mjs +113 -0
- package/worker/sandbox/CORE_API.md +167 -0
- package/worker/sandbox/Dockerfile +7 -1
- package/worker/sandbox/agents.json +4 -0
- package/worker/sandbox/catalog_numbers.py +144 -0
- package/worker/sandbox/core/__init__.py +36 -0
- package/worker/sandbox/core/mechanics.py +882 -0
- package/worker/sandbox/core/release.py +90 -0
- package/worker/sandbox/engine.py +20 -7
- package/worker/sandbox/network.py +36 -4
- package/worker/sandbox/projects.py +8 -726
- package/worker/sandbox/setup.py +149 -21
- package/worker/sandbox/test_capture.py +0 -439
- package/worker/sandbox/test_dns_asker.py +0 -102
- package/worker/sandbox/transcript-delivery.test.mjs +0 -153
package/bin/raytrace.mjs
CHANGED
|
@@ -19,7 +19,8 @@ On this machine:
|
|
|
19
19
|
raytrace doctor what this machine has and lacks
|
|
20
20
|
raytrace uninstall [--purge] [--yes] stop RayTrace and remove the Claude Code hook; --purge
|
|
21
21
|
also deletes the local sandbox VM and ~/.raytrace
|
|
22
|
-
raytrace --version | -v print the installed version
|
|
22
|
+
raytrace --version | -v print the installed version (a newer published one is
|
|
23
|
+
noted on each command; RAYTRACE_NO_UPDATE_CHECK=1: don't)
|
|
23
24
|
|
|
24
25
|
Get started in the cloud (preview):
|
|
25
26
|
1. raytrace auth login sign in, or create your account, in the browser
|
|
@@ -36,7 +37,7 @@ Cloud sandboxes:
|
|
|
36
37
|
--claude or --codex starts that agent in it at
|
|
37
38
|
once, without approval prompts
|
|
38
39
|
raytrace --code <code> beta invite: redeem a code RayTrace gave you for one
|
|
39
|
-
|
|
40
|
+
free 3-day sandbox (signed in first; also: raytrace code <code>)
|
|
40
41
|
raytrace sandbox list
|
|
41
42
|
raytrace sandbox start|stop [id]
|
|
42
43
|
raytrace sandbox destroy [id] [--yes] [--keep-traces]
|
|
@@ -146,6 +147,12 @@ if (command === 'mcp') {
|
|
|
146
147
|
process.exit(0);
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// A newer published version: one line on stderr, from what the registry last said (src/update-check.mjs).
|
|
151
|
+
{
|
|
152
|
+
const { checkForUpdate } = await import('../src/update-check.mjs');
|
|
153
|
+
checkForUpdate(command);
|
|
154
|
+
}
|
|
155
|
+
|
|
149
156
|
if (!command || command === 'help' || command === '--help' || command === '-h') { console.log(HELP); process.exit(0); }
|
|
150
157
|
|
|
151
158
|
// `raytrace --code <code>` (also `raytrace code <code>`): redeem a beta code.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytrace-cli/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"mcpName": "io.github.Godcreatebugs/raytrace",
|
|
5
5
|
"description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"src/",
|
|
18
18
|
"proxy/",
|
|
19
19
|
"worker/",
|
|
20
|
+
"!worker/**/test_*.py",
|
|
21
|
+
"!worker/**/*.test.mjs",
|
|
22
|
+
"!worker/**/__pycache__/",
|
|
23
|
+
"!worker/**/*.pyc",
|
|
20
24
|
"dist/dashboard/",
|
|
21
25
|
"THIRD_PARTY_NOTICES.md"
|
|
22
26
|
],
|
package/src/auth.mjs
CHANGED
|
@@ -191,10 +191,10 @@ export async function status() {
|
|
|
191
191
|
say(left > 0 ? `Access token valid for ${left} more min; renewed automatically.` : 'Access token expired; it is renewed on the next command.');
|
|
192
192
|
// Beta is a cloud entitlement, separate from any local licence tier.
|
|
193
193
|
try {
|
|
194
|
-
const { betaStatus, formatCreditDeadline } = await import('./beta.mjs');
|
|
194
|
+
const { betaEnds, betaStatus, formatCreditDeadline } = await import('./beta.mjs');
|
|
195
195
|
const beta = await betaStatus();
|
|
196
|
-
if (beta?.sandbox_consumed) say(`Beta:
|
|
197
|
-
else if (beta?.entitled) say(`Beta:
|
|
196
|
+
if (beta?.sandbox_consumed) say(`Beta: free sandbox created${beta.credited_sandbox_id ? ` (${beta.credited_sandbox_id})` : ''}${betaEnds(beta) ? `, until ${formatCreditDeadline(betaEnds(beta))}` : ''}.`);
|
|
197
|
+
else if (beta?.entitled) say(`Beta: one free sandbox available${betaEnds(beta) ? ` until ${formatCreditDeadline(betaEnds(beta))}` : ''} (raytrace sandbox create).`);
|
|
198
198
|
} catch { /* no beta entitlement, old backend, or offline: nothing to add */ }
|
|
199
199
|
}
|
|
200
200
|
|
package/src/beta.mjs
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
// RayTrace. Sign-in (`raytrace auth login`) is a prerequisite — this command
|
|
3
3
|
// never starts a sign-in flow and never sends the code anywhere until a
|
|
4
4
|
// signed-in account is known. The backend is the source of truth: on a
|
|
5
|
-
// successful redeem it deletes the code irreversibly and
|
|
6
|
-
//
|
|
5
|
+
// successful redeem it deletes the code irreversibly and grants the signed-in
|
|
6
|
+
// account one free cloud sandbox for 3 days. The agents in it run on the user's
|
|
7
|
+
// own Claude Code or Codex sign-in, made inside the sandbox. Nothing
|
|
7
8
|
// about the code or entitlement is stored on this machine.
|
|
8
9
|
import { accessToken, consumeIdleNotice } from './auth.mjs';
|
|
9
10
|
import { call, hasApiKeyOverride } from './api.mjs';
|
|
10
11
|
|
|
11
12
|
const say = (line = '') => console.log(line);
|
|
12
13
|
|
|
14
|
+
/** When a free beta sandbox ends: beta_ends_at, or credit_expires_at from a backend before it. */
|
|
15
|
+
export const betaEnds = (status) => status?.beta_ends_at ?? status?.credit_expires_at ?? null;
|
|
16
|
+
|
|
13
17
|
export const normalizeBetaCode = (code) => String(code ?? '').trim().toUpperCase().replace(/\s+/g, '');
|
|
14
18
|
|
|
15
19
|
// Codes are minted only in the backend repo (raytrace:
|
|
@@ -49,7 +53,7 @@ function redeemError(error) {
|
|
|
49
53
|
case 401: return new Error('Not signed in. Run: raytrace auth login, then re-run: raytrace --code <your-code>');
|
|
50
54
|
case 422: return new Error("That code isn't valid. Check it and try again, or ask RayTrace for a new one.");
|
|
51
55
|
case 410: return new Error('That code has expired (codes must be redeemed within 3 days). Ask RayTrace for a new one.');
|
|
52
|
-
case 409: return new Error('This account already has beta
|
|
56
|
+
case 409: return new Error('This account already has a free beta sandbox, so this code was not used. '
|
|
53
57
|
+ 'It can still be given to someone else until it expires.');
|
|
54
58
|
case 429: return new Error('Too many code attempts. Wait a while and try again.');
|
|
55
59
|
default: return null;
|
|
@@ -78,19 +82,17 @@ export async function redeemBetaCode(rawCode, { ensure = ensureSignedIn, apiCall
|
|
|
78
82
|
try {
|
|
79
83
|
const status = await betaStatus(apiCall);
|
|
80
84
|
if (status?.entitled) {
|
|
81
|
-
log("You're already good for beta testing: this account has its beta
|
|
82
|
-
if (status
|
|
85
|
+
log("You're already good for beta testing: this account has its free beta sandbox.");
|
|
86
|
+
if (betaEnds(status)) log(`Create it by ${formatCreditDeadline(betaEnds(status))}: raytrace sandbox create`);
|
|
83
87
|
return status;
|
|
84
88
|
}
|
|
85
89
|
} catch { /* fall through to the original error */ }
|
|
86
90
|
throw error;
|
|
87
91
|
}
|
|
88
|
-
|
|
89
|
-
log(
|
|
92
|
+
log("You're good for beta testing: one free cloud sandbox for 3 days is on this account.");
|
|
93
|
+
log('In it, sign in to Claude Code or Codex with your own account; RayTrace records the session.');
|
|
90
94
|
log('Your account now shows as Beta in the RayTrace dashboard.');
|
|
91
|
-
if (data
|
|
92
|
-
log(`Hard limit: create your sandbox and use the credit by ${formatCreditDeadline(data.credit_expires_at)}. Unused credit expires.`);
|
|
93
|
-
}
|
|
95
|
+
if (betaEnds(data)) log(`It ends ${formatCreditDeadline(betaEnds(data))}.`);
|
|
94
96
|
log('Next, from a Git repository: raytrace sandbox create');
|
|
95
97
|
return data;
|
|
96
98
|
}
|
package/src/local-sandbox.mjs
CHANGED
|
@@ -106,12 +106,25 @@ export function vmStatus() {
|
|
|
106
106
|
return line ? line.split(' ')[1] : null;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (const entry of readdirSync(
|
|
113
|
-
|
|
109
|
+
/** Every file setup.py installs from (the core/ package too), by path from SOURCE, sorted. */
|
|
110
|
+
export function setupFiles(folder = SOURCE, prefix = '') {
|
|
111
|
+
const found = [];
|
|
112
|
+
for (const entry of readdirSync(join(folder, prefix), { withFileTypes: true })) {
|
|
113
|
+
// A __pycache__ or cache left by running the tests there is no part of what is installed.
|
|
114
|
+
if (entry.name.startsWith('.') || entry.name === '__pycache__') continue;
|
|
115
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
116
|
+
if (entry.isDirectory()) found.push(...setupFiles(folder, path));
|
|
117
|
+
else if (entry.isFile()) found.push(path);
|
|
114
118
|
}
|
|
119
|
+
return found.sort();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** This CLI's package version, which is the sandbox core's. */
|
|
123
|
+
export const packageVersion = () => JSON.parse(readFileSync(join(paths.root, 'package.json'), 'utf8')).version;
|
|
124
|
+
|
|
125
|
+
export function setupVersion(folder = SOURCE) {
|
|
126
|
+
const hash = createHash('sha256');
|
|
127
|
+
for (const path of setupFiles(folder)) hash.update(path).update(readFileSync(join(folder, path)));
|
|
115
128
|
return hash.digest('hex').slice(0, 16);
|
|
116
129
|
}
|
|
117
130
|
|
|
@@ -138,6 +151,9 @@ function installInVm(version) {
|
|
|
138
151
|
inVm(['rm', '-rf', '/tmp/raytrace-sandbox-source']);
|
|
139
152
|
limactl(['shell', '--workdir', '/', VM, 'mkdir', '-p', '/tmp/raytrace-sandbox-source']);
|
|
140
153
|
limactl(['copy', '-r', `${SOURCE}/.`, `${VM}:/tmp/raytrace-sandbox-source/`]);
|
|
154
|
+
// Only worker/sandbox is copied, not package.json: the core learns its version from this
|
|
155
|
+
// (core.version()), which names the image it builds and what `projects.py version` reports.
|
|
156
|
+
inVm(['sh', '-c', 'cat > /tmp/raytrace-sandbox-source/VERSION'], { input: `${packageVersion()}\n` });
|
|
141
157
|
inVm(['python3', '/tmp/raytrace-sandbox-source/setup.py'], { log: true });
|
|
142
158
|
inVm(['sh', '-c', `echo ${version} > ${SETUP_MARK}`]);
|
|
143
159
|
}
|
package/src/mcp.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
20
20
|
import { createInterface } from 'node:readline';
|
|
21
21
|
import { accessToken, account, openUrl, startDeviceLogin } from './auth.mjs';
|
|
22
22
|
import { call, hasApiKeyOverride } from './api.mjs';
|
|
23
|
-
import { formatCreditDeadline } from './beta.mjs';
|
|
23
|
+
import { betaEnds, formatCreditDeadline } from './beta.mjs';
|
|
24
24
|
import { findLima, LIMA_VERSION } from './lima.mjs';
|
|
25
25
|
import { isLocal, localSandboxes, promptsLink, registry, sandboxName } from './local-sandbox.mjs';
|
|
26
26
|
import { install, paths } from './paths.mjs';
|
|
@@ -59,7 +59,7 @@ const TOOLS = [
|
|
|
59
59
|
{
|
|
60
60
|
name: 'list_sandboxes',
|
|
61
61
|
title: 'List sandboxes',
|
|
62
|
-
description: "This machine's local sandboxes, and the signed-in workspace's cloud sandboxes: id, name, status, age and beta
|
|
62
|
+
description: "This machine's local sandboxes, and the signed-in workspace's cloud sandboxes: id, name, status, age, and when a free beta sandbox ends.",
|
|
63
63
|
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
64
64
|
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
65
65
|
},
|
|
@@ -83,7 +83,7 @@ const TOOLS = [
|
|
|
83
83
|
install_lima: { type: 'boolean', description: `With local: download Lima ${LIMA_VERSION} (open source, about 25-40 MB, no admin rights) when it is not installed. Only after the user agrees.` },
|
|
84
84
|
connect: { type: 'boolean', description: 'Open a terminal connected to the new sandbox with a coding agent running in it, once it is ready. Defaults to true.' },
|
|
85
85
|
agent: agentSchema,
|
|
86
|
-
without_beta_credit: { type: 'boolean', description: "Create a
|
|
86
|
+
without_beta_credit: { type: 'boolean', description: "Create a regular sandbox, not the user's free beta sandbox. Only after the user agrees, when create_sandbox reported their free beta sandbox expired or already created." },
|
|
87
87
|
},
|
|
88
88
|
additionalProperties: false,
|
|
89
89
|
},
|
|
@@ -240,9 +240,7 @@ function describe(box) {
|
|
|
240
240
|
const created = typeof box.created === 'number' ? box.created * 1000 : Date.parse(box.created);
|
|
241
241
|
const minutes = Number.isFinite(created) ? Math.round((Date.now() - created) / 60000) : null;
|
|
242
242
|
const age = minutes === null ? '' : `, ${minutes < 120 ? `${minutes} min` : `${Math.round(minutes / 60)} h`} old`;
|
|
243
|
-
const beta = box.beta
|
|
244
|
-
? `, beta credit $${Math.max(0, box.credit_usd - (box.credit_spent_usd ?? 0)).toFixed(2)} of $${box.credit_usd} left${box.credit_expires_at ? ` (ends ${formatCreditDeadline(box.credit_expires_at)})` : ''}`
|
|
245
|
-
: '';
|
|
243
|
+
const beta = box.beta ? `, free beta sandbox${betaEnds(box) ? ` until ${formatCreditDeadline(betaEnds(box))}` : ''}` : '';
|
|
246
244
|
return `${box.id} ${box.status} ${box.name}${age}${beta}`;
|
|
247
245
|
}
|
|
248
246
|
|
|
@@ -332,10 +330,10 @@ async function createSandbox({ path, name, local = false, install_lima: installL
|
|
|
332
330
|
const root = await projectRoot(path);
|
|
333
331
|
if (local) return createLocal(root, name, installLima, connect && agent, step);
|
|
334
332
|
await requireSignIn();
|
|
335
|
-
const { plan
|
|
333
|
+
const { plan } = plain ? { plan: 'none' } : await creditPlan();
|
|
336
334
|
if (plan === 'expired') {
|
|
337
|
-
throw new ToolError('No sandbox was created: the user\'s
|
|
338
|
-
+ 'Ask the user whether to create a
|
|
335
|
+
throw new ToolError('No sandbox was created: the user\'s free beta sandbox expired (its 3 days ran out). '
|
|
336
|
+
+ 'Ask the user whether to create a regular sandbox instead; if they agree, call create_sandbox again with without_beta_credit: true.');
|
|
339
337
|
}
|
|
340
338
|
const useCredit = plan === 'use';
|
|
341
339
|
const { files, skipped, total } = listProject(root);
|
|
@@ -349,13 +347,14 @@ async function createSandbox({ path, name, local = false, install_lima: installL
|
|
|
349
347
|
box = await upload(archive, name || basename(root), useCredit);
|
|
350
348
|
} catch (error) {
|
|
351
349
|
if (!useCredit || !isCreditRefusal(error)) throw error;
|
|
352
|
-
throw new ToolError(`No sandbox was created: the user's beta
|
|
353
|
-
+ 'Ask the user whether to create a
|
|
350
|
+
throw new ToolError(`No sandbox was created: the user's free beta sandbox ${error.status === 410 ? 'expired before it was created' : 'was already created'}. `
|
|
351
|
+
+ 'Ask the user whether to create a regular sandbox instead; if they agree, call create_sandbox again with without_beta_credit: true.');
|
|
354
352
|
}
|
|
355
353
|
const lines = [
|
|
356
354
|
`Sandbox ${box.id} is running.`,
|
|
357
355
|
listed,
|
|
358
|
-
box.credit_applied ? `
|
|
356
|
+
box.credit_applied ? `This is the user's free beta sandbox${betaEnds(box) ? `, until ${formatCreditDeadline(betaEnds(box))}` : ''}.` : '',
|
|
357
|
+
'The first time, Claude Code (or Codex) asks the user to sign in inside the sandbox with their own account.',
|
|
359
358
|
box.transcripts ? 'Claude Code sessions in it are recorded.' : `Claude Code transcripts are off: ${box.transcripts_off}. Commands are still recorded.`,
|
|
360
359
|
connect ? openSandbox(box.id, { agent }).message : `To work in it: connect_sandbox, or in a terminal: raytrace connect ${box.id} --${agent}. To run commands in it from here: run_command.`,
|
|
361
360
|
`Recorded sessions: ${DASHBOARD}`,
|
package/src/sandbox.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { request as httpsRequest } from 'node:https';
|
|
|
15
15
|
import { basename, join } from 'node:path';
|
|
16
16
|
import { account } from './auth.mjs';
|
|
17
17
|
import { api, call, ApiError, unreachable } from './api.mjs';
|
|
18
|
-
import { betaStatus, formatCreditDeadline } from './beta.mjs';
|
|
18
|
+
import { betaEnds, betaStatus, formatCreditDeadline } from './beta.mjs';
|
|
19
19
|
import { ask, confirm, interactive } from './prompt.mjs';
|
|
20
20
|
import * as local from './local-sandbox.mjs';
|
|
21
21
|
import { AGENTS } from './agents.mjs';
|
|
@@ -136,7 +136,7 @@ export async function packArchive(root, files) {
|
|
|
136
136
|
export async function creditPlan() {
|
|
137
137
|
let beta;
|
|
138
138
|
try { beta = await betaStatus(); } catch { return { plan: 'none', beta: null }; }
|
|
139
|
-
const deadlinePassed = beta
|
|
139
|
+
const deadlinePassed = betaEnds(beta) && Date.parse(betaEnds(beta)) <= Date.now();
|
|
140
140
|
if (beta && !beta.sandbox_consumed && deadlinePassed && (beta.entitled || beta.credit_usd)) return { plan: 'expired', beta };
|
|
141
141
|
if (beta?.entitled && !beta.sandbox_consumed) return { plan: 'use', beta };
|
|
142
142
|
return { plan: 'none', beta };
|
|
@@ -163,15 +163,14 @@ export async function create(flags) {
|
|
|
163
163
|
// The same files, packed the same way, as a cloud sandbox gets: only the copy stays here.
|
|
164
164
|
if (flags.local) return local.create(localName, { root, files, skipped, total, archive: await pack(root, files) });
|
|
165
165
|
|
|
166
|
-
// A local sandbox never uses beta
|
|
166
|
+
// A local sandbox never uses the beta grant.
|
|
167
167
|
const { plan, beta } = await creditPlan();
|
|
168
168
|
if (plan === 'expired') {
|
|
169
|
-
say('Your
|
|
170
|
-
if (!interactive()) throw new Error('
|
|
171
|
-
if (!(await confirm('Create a
|
|
169
|
+
say('Your free beta sandbox has expired: its 3 days ran out.');
|
|
170
|
+
if (!interactive()) throw new Error('Free beta sandbox expired; no sandbox was created. Ask RayTrace for a new code to try again.');
|
|
171
|
+
if (!(await confirm('Create a regular sandbox instead?', false))) { say('Not created.'); return; }
|
|
172
172
|
} else if (plan === 'use') {
|
|
173
|
-
say(`
|
|
174
|
-
+ `${beta.credit_expires_at ? ` — credit ends ${formatCreditDeadline(beta.credit_expires_at)}` : ''}.`);
|
|
173
|
+
say(`This is your free beta sandbox${betaEnds(beta) ? `, until ${formatCreditDeadline(betaEnds(beta))}` : ''}.`);
|
|
175
174
|
}
|
|
176
175
|
const useCredit = plan === 'use';
|
|
177
176
|
say(`Packing ${files.length} files (${(total / 1048576).toFixed(1)} MiB) from ${root}`);
|
|
@@ -183,19 +182,20 @@ export async function create(flags) {
|
|
|
183
182
|
box = await upload(archive, name, useCredit);
|
|
184
183
|
} catch (error) {
|
|
185
184
|
if (!useCredit || !isCreditRefusal(error)) throw error;
|
|
186
|
-
say(error.status === 410 ? 'Your beta
|
|
187
|
-
: 'Your beta
|
|
188
|
-
if (!interactive() || !(await confirm('Create a
|
|
189
|
-
throw new Error('
|
|
185
|
+
say(error.status === 410 ? 'Your free beta sandbox expired before it was created.'
|
|
186
|
+
: 'Your free beta sandbox was already created.');
|
|
187
|
+
if (!interactive() || !(await confirm('Create a regular sandbox instead?', false))) {
|
|
188
|
+
throw new Error('Not created as your free beta sandbox; no sandbox was created.');
|
|
190
189
|
}
|
|
191
190
|
box = await upload(archive, name, false);
|
|
192
191
|
}
|
|
193
192
|
say(`\nSandbox ${box.id} is running.`);
|
|
194
193
|
if (box.credit_applied) {
|
|
195
|
-
say(`
|
|
194
|
+
say(`Your free beta sandbox${betaEnds(box) ? `, until ${formatCreditDeadline(betaEnds(box))}` : ''}. It shows as Beta in the dashboard.`);
|
|
196
195
|
}
|
|
197
196
|
say(box.transcripts ? 'Claude Code sessions in it are recorded.'
|
|
198
197
|
: `Claude Code transcripts are off: ${box.transcripts_off}. Commands are still recorded.`);
|
|
198
|
+
say('The first time, Claude Code (or Codex) asks you to sign in inside the sandbox: use your own account.');
|
|
199
199
|
say(`Open it: raytrace connect ${box.id}`);
|
|
200
200
|
}
|
|
201
201
|
|
|
@@ -207,7 +207,7 @@ export async function list(flags = {}) {
|
|
|
207
207
|
// The sandbox's creation time (seconds), or its container's once that is known.
|
|
208
208
|
const created = typeof box.created === 'number' ? box.created * 1000 : Date.parse(box.created);
|
|
209
209
|
const age = Math.round((Date.now() - created) / 60000);
|
|
210
|
-
const beta = box.beta ? ` Beta${
|
|
210
|
+
const beta = box.beta ? ` Beta${betaEnds(box) ? ` (until ${formatCreditDeadline(betaEnds(box))})` : ''}` : '';
|
|
211
211
|
say(`${box.id} ${String(box.status).padEnd(8)} ${box.name}${beta} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old)`);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -250,15 +250,14 @@ export async function destroy(id, flags) {
|
|
|
250
250
|
else if (result.traces_deleted === false) say('Note: its traces could not be deleted; they may still show on the dashboard.');
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
/** Exported for tests: the warning shown when connecting to a beta
|
|
254
|
-
* whose 3 days are up, or null.
|
|
255
|
-
* backend; the sandbox itself still opens. */
|
|
253
|
+
/** Exported for tests: the warning shown when connecting to a free beta
|
|
254
|
+
* sandbox whose 3 days are up, or null. The backend stops it; its files stay. */
|
|
256
255
|
export function betaExpiryWarning(beta, id, now = Date.now()) {
|
|
257
256
|
if (!beta || beta.credited_sandbox_id !== id) return null;
|
|
258
|
-
const deadline = beta
|
|
257
|
+
const deadline = betaEnds(beta) ? Date.parse(betaEnds(beta)) : NaN;
|
|
259
258
|
if (!beta.expired && !(deadline <= now)) return null;
|
|
260
|
-
return `Warning: your beta
|
|
261
|
-
+ '
|
|
259
|
+
return `Warning: your free beta sandbox expired${betaEnds(beta) ? ` (${formatCreditDeadline(betaEnds(beta), now)})` : ''}; `
|
|
260
|
+
+ 'RayTrace stops it. Its files are kept.';
|
|
262
261
|
}
|
|
263
262
|
|
|
264
263
|
/** An interactive terminal in the sandbox, carried over one upgraded HTTP request.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// A one-line notice, on every command run at a terminal, while a newer
|
|
2
|
+
// RayTrace is published than the one running:
|
|
3
|
+
//
|
|
4
|
+
// RayTrace 0.19.0 is available (you have 0.18.0). Update: npm install -g @raytrace-cli/cli@latest
|
|
5
|
+
//
|
|
6
|
+
// No command waits for it. What the registry last said is kept in the
|
|
7
|
+
// RayTrace home (update-check.json); when that is older than a day, a
|
|
8
|
+
// detached process asks the registry again for next time. The notice goes to
|
|
9
|
+
// stderr, so piped output is untouched, and never shows for the Claude Code
|
|
10
|
+
// hook, the MCP server, CI, a run that is not at a terminal, a checkout of the
|
|
11
|
+
// repository, or with RAYTRACE_NO_UPDATE_CHECK=1.
|
|
12
|
+
import { spawn } from 'node:child_process';
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { paths } from './paths.mjs';
|
|
17
|
+
|
|
18
|
+
export const PACKAGE = '@raytrace-cli/cli';
|
|
19
|
+
export const REGISTRY = `https://registry.npmjs.org/${PACKAGE}/latest`;
|
|
20
|
+
const CACHE = 'update-check.json';
|
|
21
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
22
|
+
|
|
23
|
+
const STABLE = /^(\d+)\.(\d+)\.(\d+)$/;
|
|
24
|
+
/** Whether stable version `a` is newer than `b`; false for anything that is not x.y.z. */
|
|
25
|
+
export function newer(a, b) {
|
|
26
|
+
const [x, y] = [STABLE.exec(String(a)), STABLE.exec(String(b))];
|
|
27
|
+
if (!x || !y) return false;
|
|
28
|
+
for (let i = 1; i <= 3; i++) if (Number(x[i]) !== Number(y[i])) return Number(x[i]) > Number(y[i]);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** How this copy was installed, by where it runs from: npm, pip, npx, or a source checkout. */
|
|
33
|
+
export function installKind(root) {
|
|
34
|
+
const where = String(root).replace(/\\/g, '/');
|
|
35
|
+
if (existsSync(join(root, '.git'))) return 'checkout';
|
|
36
|
+
if (where.includes('/_npx/')) return 'npx';
|
|
37
|
+
if (/\/(site|dist)-packages\/raytrace\/app\/?$/.test(where)) return 'pip';
|
|
38
|
+
return 'npm';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const updateCommand = (kind) => ({
|
|
42
|
+
npm: `npm install -g ${PACKAGE}@latest`,
|
|
43
|
+
pip: 'pip install --upgrade raytrace-cli',
|
|
44
|
+
npx: `npx ${PACKAGE}@latest`,
|
|
45
|
+
})[kind];
|
|
46
|
+
|
|
47
|
+
export const notice = (latest, current, kind) =>
|
|
48
|
+
`RayTrace ${latest} is available (you have ${current}). Update: ${updateCommand(kind)}`;
|
|
49
|
+
|
|
50
|
+
function readCache(home) {
|
|
51
|
+
try { return JSON.parse(readFileSync(join(home, CACHE), 'utf8')); } catch { return {}; }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether this run should say anything at all. */
|
|
55
|
+
export function quiet(command, env, stderr) {
|
|
56
|
+
const off = (value) => value === '1' || value === 'true';
|
|
57
|
+
return ['hook', 'mcp'].includes(command) || off(env.RAYTRACE_NO_UPDATE_CHECK)
|
|
58
|
+
|| (typeof env.CI === 'string' && env.CI !== '') || !stderr?.isTTY;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Prints the notice when the cached latest version is newer than this one,
|
|
63
|
+
* and starts a background refresh when the cache is a day old. Returns the
|
|
64
|
+
* line printed, or null. Never throws. `deps` is for tests.
|
|
65
|
+
*/
|
|
66
|
+
export function checkForUpdate(command, deps = {}) {
|
|
67
|
+
try {
|
|
68
|
+
const env = deps.env ?? process.env;
|
|
69
|
+
const stderr = deps.stderr ?? process.stderr;
|
|
70
|
+
const root = deps.root ?? paths.root;
|
|
71
|
+
const home = deps.home ?? paths.home;
|
|
72
|
+
const now = deps.now ?? Date.now();
|
|
73
|
+
if (quiet(command, env, stderr)) return null;
|
|
74
|
+
const kind = installKind(root);
|
|
75
|
+
if (kind === 'checkout') return null;
|
|
76
|
+
const current = deps.current ?? JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version;
|
|
77
|
+
const cache = readCache(home);
|
|
78
|
+
if (!(cache.checked_at > now - DAY_MS)) (deps.refresh ?? refreshInBackground)(home);
|
|
79
|
+
if (!newer(cache.latest, current)) return null;
|
|
80
|
+
const line = notice(cache.latest, current, kind);
|
|
81
|
+
(deps.log ?? ((text) => stderr.write(`${text}\n`)))(line);
|
|
82
|
+
return line;
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Asks the registry in a detached process, which outlives this command and writes the cache. */
|
|
89
|
+
function refreshInBackground(home) {
|
|
90
|
+
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), '--refresh', home], {
|
|
91
|
+
detached: true, stdio: 'ignore', env: { ...process.env, RAYTRACE_NO_UPDATE_CHECK: '1' },
|
|
92
|
+
});
|
|
93
|
+
child.unref();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The registry's latest version, written to the cache with the time asked; the time is written on failure too. */
|
|
97
|
+
export async function refresh(home, fetcher = fetch) {
|
|
98
|
+
let latest = readCache(home).latest ?? null;
|
|
99
|
+
try {
|
|
100
|
+
const response = await fetcher(REGISTRY, { signal: AbortSignal.timeout(5000), headers: { accept: 'application/json' } });
|
|
101
|
+
if (response.ok) {
|
|
102
|
+
const version = (await response.json())?.version;
|
|
103
|
+
if (STABLE.test(String(version))) latest = version;
|
|
104
|
+
}
|
|
105
|
+
} catch { /* offline: ask again tomorrow */ }
|
|
106
|
+
mkdirSync(home, { recursive: true });
|
|
107
|
+
writeFileSync(join(home, CACHE), `${JSON.stringify({ checked_at: Date.now(), latest })}\n`);
|
|
108
|
+
return latest;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (process.argv[2] === '--refresh' && process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
112
|
+
await refresh(process.argv[3]);
|
|
113
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Sandbox core API
|
|
2
|
+
|
|
3
|
+
`worker/sandbox/` is the sandbox core: everything that runs on a sandbox host to
|
|
4
|
+
run gVisor sandboxes and record them. The local adapter (`projects.py`, driven by
|
|
5
|
+
`raytrace sandbox ... --local` in a Lima VM) is one user. Other host layers can
|
|
6
|
+
import it as a library and add their own actions.
|
|
7
|
+
|
|
8
|
+
The core **applies** what it is given: limits, an image, hooks, files. It never
|
|
9
|
+
**decides** them. It knows nothing about accounts, plans, quotas or how a host is
|
|
10
|
+
reached.
|
|
11
|
+
|
|
12
|
+
## Versions
|
|
13
|
+
|
|
14
|
+
| Constant | Where | Covers |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `CORE_API` | `core/__init__.py` | The functions below: arguments, results, errors and side effects. |
|
|
17
|
+
| `EVIDENCE_SCHEMA` | `core/__init__.py` | What the recorder hands on: collector events, the fact engine's facts, `syscall_catalog.sql`. |
|
|
18
|
+
| `version()` | `core/__init__.py` | The package version: from `package.json`, or the `VERSION` file that `setup.py` writes beside an installed copy. |
|
|
19
|
+
|
|
20
|
+
Raise a constant when a consumer would notice the change. The two are separate:
|
|
21
|
+
compatible evidence does not mean compatible functions, and the reverse is also
|
|
22
|
+
true. **v1 is the behaviour as of this file's introduction, written down.**
|
|
23
|
+
|
|
24
|
+
## `core.mechanics` (`CORE_API` 1)
|
|
25
|
+
|
|
26
|
+
Sandbox ids are `rtp-<32 hex>` (project) and `rtf-<32 hex>` (Playground fork).
|
|
27
|
+
Unless noted, a function raises `ValueError` on bad input and
|
|
28
|
+
`subprocess.CalledProcessError` when Docker fails.
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
- `Limits(cpus='2', memory='2g', pids=256, tmp='512m')`: what a sandbox may use.
|
|
32
|
+
It validates strictly; `.args()` gives the `docker create` flags.
|
|
33
|
+
`DEFAULT_LIMITS` holds today's values.
|
|
34
|
+
- `image()`: the image used when the caller names none. In order:
|
|
35
|
+
1. the active release's `image`;
|
|
36
|
+
2. `/etc/raytace/image`;
|
|
37
|
+
3. `raytace-gvisor-agent`.
|
|
38
|
+
- `bridge()`: the bridge URL sandboxes are given, as `RAYTRACE_BROKER`.
|
|
39
|
+
- `container_args(name, labels, limits=None, image_name=None)`: the one container
|
|
40
|
+
configuration used for projects and forks. It sets:
|
|
41
|
+
- the `raytace-gvisor` runtime and the `raytace-egress` network;
|
|
42
|
+
- no capabilities, `no-new-privileges`, and user 1000;
|
|
43
|
+
- the two volumes and the host resolver;
|
|
44
|
+
- the session environment.
|
|
45
|
+
- `create_container(name, labels, limits=None, image_name=None)`: makes the
|
|
46
|
+
volumes and the container, without starting it. Returns the container id.
|
|
47
|
+
|
|
48
|
+
### Lifecycle
|
|
49
|
+
- `preflight()`: the collector and resolver must be running, otherwise
|
|
50
|
+
`SystemExit`. It then runs `network.py`.
|
|
51
|
+
- `create(sid, archive, limits=None, expect_release=None)`: creates a project
|
|
52
|
+
sandbox from a staged `/tmp/<sid>.tar.gz` and returns its container id.
|
|
53
|
+
- With `expect_release`, it holds `core.release.lock(shared=True)` from the
|
|
54
|
+
check until the container exists.
|
|
55
|
+
- It raises `SystemExit` if the active release is a different one, before
|
|
56
|
+
creating anything.
|
|
57
|
+
- The container is made from the release's image and labelled
|
|
58
|
+
`io.raytace.release=<id>`.
|
|
59
|
+
- `stage_archive(sid)`: writes the archive from stdin to `/tmp/<sid>.tar.gz`
|
|
60
|
+
(up to 300 MiB).
|
|
61
|
+
- `validate_archive(path)`: accepts only regular files with relative paths,
|
|
62
|
+
256 MiB in total.
|
|
63
|
+
- `start(sid)`: starts the sandbox so it is recorded, and is safe on a running
|
|
64
|
+
sandbox. In order:
|
|
65
|
+
1. `preflight()`.
|
|
66
|
+
2. If the sandbox started before the collector did, restart it.
|
|
67
|
+
3. Lock its restricted files while it is stopped.
|
|
68
|
+
4. Put back its hook and lists from the host's copies.
|
|
69
|
+
5. Call `remember()`.
|
|
70
|
+
- `shell(sid, agent=None)`: an interactive bash in a started sandbox, optionally
|
|
71
|
+
starting `claude` or `codex` first. Returns its exit code.
|
|
72
|
+
- `stop(sid)`.
|
|
73
|
+
- `delete(sid, forget_evidence=False)`: the sandbox must be stopped. Removes:
|
|
74
|
+
- the container;
|
|
75
|
+
- its two volumes, but only ones labelled as its own;
|
|
76
|
+
- the host's copies of its hook and guardrails;
|
|
77
|
+
- with `forget_evidence`, the collector's records of it.
|
|
78
|
+
|
|
79
|
+
It then calls every function registered with `register_delete_cleanup(fn)`,
|
|
80
|
+
as `fn(sid)`.
|
|
81
|
+
- `listing()`: every managed container, as
|
|
82
|
+
`{id, container_id, status, created, persistent_volumes, size_bytes, fork_of, release, image}`.
|
|
83
|
+
- `remember(name)`: tells the fact engine which container is which sandbox.
|
|
84
|
+
- `predates_collector(state)`.
|
|
85
|
+
|
|
86
|
+
### Inside the sandbox
|
|
87
|
+
- `install_claude_hooks(container, hook)`: installs, owned by root:
|
|
88
|
+
- the hook script;
|
|
89
|
+
- Claude Code's managed settings;
|
|
90
|
+
- Codex's managed config.
|
|
91
|
+
- `enable_claude(sid, hook)`: does the same, and keeps the host's copy that
|
|
92
|
+
`start()` puts back.
|
|
93
|
+
- `set_token(sid, token)`: writes `~/.raytace/sandbox-token`, the credential the
|
|
94
|
+
hook (`claude-hook.mjs`) sends transcripts with.
|
|
95
|
+
- `write_home_files(sid, [(folder, name, bytes)])`: writes files into
|
|
96
|
+
`/home/node/<folder>/<name>`, owned by the agent user (folders 0700, files 0600).
|
|
97
|
+
- `write_as_root(container, path, bytes)`, `as_node(container, *command, data=None, check=True)`.
|
|
98
|
+
|
|
99
|
+
### Files, forks, snapshots, evidence
|
|
100
|
+
- `guardrails(sid, state, restricted=None, watched=None, blocked=None)` and
|
|
101
|
+
`set_guardrails(sid, state, request)`: restricted, watched and blocked lists.
|
|
102
|
+
Returns `{hook, read_only, restricted, watched, missing}`.
|
|
103
|
+
- `fork_action(action, fork, forget=False, credentials=None)`: handles
|
|
104
|
+
`fork-create | fork-run | fork-check | fork-collect | fork-stop | fork-delete`.
|
|
105
|
+
- `credentials` is the caller's policy for copying the parent's sign-ins into
|
|
106
|
+
a fork: a function of the request.
|
|
107
|
+
- When it is `None`, sign-ins are copied unless the request says
|
|
108
|
+
`credentials: false`.
|
|
109
|
+
- `snapshot_read(project)` and `read_snapshot(project, running)`.
|
|
110
|
+
- `evidence(container, forget=False)` and
|
|
111
|
+
`activity(container, since_ms=0, until_ms=0)`.
|
|
112
|
+
|
|
113
|
+
### Command line
|
|
114
|
+
`main(extra_actions=None, fork_credentials=None, argv=None)` is
|
|
115
|
+
`projects.py <action> [id] [--archive] [--confirm] [--release] [--since] [--until] [--forget-evidence] [--agent]`.
|
|
116
|
+
|
|
117
|
+
- `extra_actions` maps a name to `fn(opts, state)`. `state` is the sandbox's
|
|
118
|
+
`docker inspect`, or `None` when the action has no id.
|
|
119
|
+
- `version` prints `{core, core_api, evidence_schema, release, image}`, read from
|
|
120
|
+
what is installed.
|
|
121
|
+
|
|
122
|
+
## `core.release` (`CORE_API` 1)
|
|
123
|
+
|
|
124
|
+
A release is the directory `/opt/raytace/releases/<id>/` holding an immutable
|
|
125
|
+
`release.json`, with at least `{"id": <id>, "image": <tag>}`. The symlink
|
|
126
|
+
`/opt/raytace/current` is the only record of which release is active. A host
|
|
127
|
+
without it, such as a local VM, has no releases.
|
|
128
|
+
|
|
129
|
+
- `lock(shared=False)`: an `flock` on `/run/raytace/release.lock`.
|
|
130
|
+
- `active()`: the active release's manifest, or `None`.
|
|
131
|
+
- `point(target)`: switches the symlink in one rename, and returns the release
|
|
132
|
+
that was active before.
|
|
133
|
+
- `activate(target, restart, check)`: holds the exclusive lock, switches, then
|
|
134
|
+
runs `restart()` and `check()`.
|
|
135
|
+
- If either fails, it switches back, runs `restart()` again and re-raises the
|
|
136
|
+
error.
|
|
137
|
+
- If there was no previous release, it removes the symlink instead.
|
|
138
|
+
|
|
139
|
+
## Host setup (`setup.py`)
|
|
140
|
+
|
|
141
|
+
The steps run in this order, and each can run on its own:
|
|
142
|
+
`install → network → services → image → activate`. Pass `--root` for where the
|
|
143
|
+
core runs from: `/opt/raytace` locally, `/opt/raytace/current` behind releases.
|
|
144
|
+
|
|
145
|
+
`image` builds with exact `CLAUDE_CODE_VERSION` and `CODEX_VERSION`. These are
|
|
146
|
+
either given, or the tested ones in `agents.json`. It then checks
|
|
147
|
+
`claude --version` and `codex --version` in the image.
|
|
148
|
+
|
|
149
|
+
`activate` restarts the services in this order: resolver, collector, viewer.
|
|
150
|
+
It then checks:
|
|
151
|
+
- the collector's socket exists;
|
|
152
|
+
- the resolver answers on the gateway.
|
|
153
|
+
|
|
154
|
+
## Files the core owns on a host
|
|
155
|
+
|
|
156
|
+
- **The core writes:**
|
|
157
|
+
- `/etc/raytace/gvisor.json`, `resolv.conf`, `upstream-dns`, `bridge`,
|
|
158
|
+
`bridge-upstream`, `image` and `viewer-token`;
|
|
159
|
+
- the `raytace-collector`, `raytace-viewer` and `raytace-dns` units;
|
|
160
|
+
- `/var/lib/raytace/*`;
|
|
161
|
+
- `--root`.
|
|
162
|
+
- **The core only reads** `/etc/raytace/bridge-front`. It holds the port of a
|
|
163
|
+
front before the bridge on the gateway, written by a host layer that runs
|
|
164
|
+
one. Sandboxes are then pointed at the front, and both addresses count as
|
|
165
|
+
RayTrace's own.
|
|
166
|
+
- **Anything else under `/etc/raytace/`** belongs to the layer that wrote it.
|
|
167
|
+
The core never overwrites it.
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
FROM node:22-bookworm-slim
|
|
2
|
+
# Exact agent versions, always given: setup.py passes this core's tested ones
|
|
3
|
+
# (agents.json) or a host layer's pinned ones, and checks the image has them.
|
|
4
|
+
ARG CLAUDE_CODE_VERSION
|
|
5
|
+
ARG CODEX_VERSION
|
|
6
|
+
RUN test -n "$CLAUDE_CODE_VERSION" && test -n "$CODEX_VERSION" \
|
|
7
|
+
|| { echo "CLAUDE_CODE_VERSION and CODEX_VERSION are required" >&2; exit 1; }
|
|
2
8
|
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates python3 curl ripgrep \
|
|
3
9
|
&& rm -rf /var/lib/apt/lists/*
|
|
4
|
-
RUN npm install -g @openai/codex @anthropic-ai/claude-code
|
|
10
|
+
RUN npm install -g "@openai/codex@${CODEX_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}"
|
|
5
11
|
RUN mkdir /workspace && chown node:node /workspace
|
|
6
12
|
USER node
|
|
7
13
|
WORKDIR /workspace
|