@raytrace-cli/cli 0.7.0 → 0.9.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/README.md +71 -1
- package/bin/raytrace.mjs +65 -5
- package/dist/dashboard/assets/{index-DtV3UdEB.css → index-H97VLD5l.css} +1 -1
- package/dist/dashboard/assets/{index-Dc3LTk8b.js → index-TqrxOY-Y.js} +3 -3
- package/dist/dashboard/index.html +2 -2
- package/package.json +1 -1
- package/src/auth.mjs +28 -20
- package/src/local-sandbox.mjs +29 -11
- package/src/mcp.mjs +679 -0
- package/src/sandbox.mjs +89 -44
- package/src/share.mjs +86 -0
- package/src/terminal.mjs +68 -0
- package/worker/sandbox/projects.py +8 -3
package/src/sandbox.mjs
CHANGED
|
@@ -31,16 +31,23 @@ const ID = /^rtp-[a-f0-9]{32}$/;
|
|
|
31
31
|
|
|
32
32
|
// Never packed: version control, dependencies and build output (rebuilt in the
|
|
33
33
|
// sandbox), and files that usually hold credentials.
|
|
34
|
-
const EXCLUDED = new Set(['.git', '.raytace', '.raytrace', '.ssh', '.aws', '.azure', '.config', 'node_modules', '.venv',
|
|
34
|
+
const EXCLUDED = new Set(['.git', '.raytace', '.raytrace', '.ssh', '.aws', '.azure', '.config', '.claude', 'node_modules', '.venv',
|
|
35
35
|
'__pycache__', '.next', '.vinext', 'dist', 'coverage', '.wrangler', '.DS_Store']);
|
|
36
|
-
const SECRET_NAMES = new Set([
|
|
36
|
+
const SECRET_NAMES = new Set([
|
|
37
|
+
'.npmrc', '.netrc', '.pypirc', '.htpasswd', '.dockercfg', 'credentials', 'credentials.json', 'credentials.ini',
|
|
38
|
+
'auth.json', 'service-account.json', 'service_account.json', 'serviceAccountKey.json',
|
|
39
|
+
'client_secret.json', 'client_secrets.json', 'token.json', 'id_rsa', 'id_dsa', 'id_ecdsa',
|
|
40
|
+
'id_ed25519', 'id_ecdsa_sk', 'id_ed25519_sk', 'known_hosts',
|
|
41
|
+
]);
|
|
37
42
|
const SECRET_EXTENSIONS = /\.(pem|key|p12|pfx)$/i;
|
|
38
43
|
|
|
39
44
|
export function packable(path) {
|
|
40
45
|
const parts = path.split('/');
|
|
41
46
|
const name = parts.at(-1);
|
|
47
|
+
const lower = name.toLowerCase();
|
|
42
48
|
return !parts.some((part) => EXCLUDED.has(part) || part === '..') && !path.startsWith('/')
|
|
43
|
-
&& !
|
|
49
|
+
&& !lower.startsWith('.env') && !lower.startsWith('.secret')
|
|
50
|
+
&& !SECRET_EXTENSIONS.test(name) && !SECRET_NAMES.has(lower);
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
/** The project's files git would track, minus what must not leave this machine. */
|
|
@@ -82,70 +89,105 @@ function pack(root, files) {
|
|
|
82
89
|
});
|
|
83
90
|
}
|
|
84
91
|
|
|
92
|
+
/** The signed-in workspace's cloud sandboxes, minus deleted ones. */
|
|
93
|
+
export async function liveSandboxes() {
|
|
94
|
+
return (await call('GET', '/v1/sandboxes')).filter((box) => box.status !== 'deleted');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function checkId(id) {
|
|
98
|
+
if (!ID.test(id)) throw new Error(`Not a sandbox id: ${id}`);
|
|
99
|
+
return id;
|
|
100
|
+
}
|
|
101
|
+
|
|
85
102
|
async function pickId(id) {
|
|
86
|
-
if (id)
|
|
87
|
-
|
|
88
|
-
return id;
|
|
89
|
-
}
|
|
90
|
-
const live = (await call('GET', '/v1/sandboxes')).filter((box) => box.status !== 'deleted');
|
|
103
|
+
if (id) return checkId(id);
|
|
104
|
+
const live = await liveSandboxes();
|
|
91
105
|
if (live.length === 1) return live[0].id;
|
|
92
106
|
throw new Error(live.length ? 'More than one sandbox; name one (raytrace sandbox list).'
|
|
93
107
|
: `No sandboxes${account() ? ` in ${account()}'s workspace` : ''} yet: raytrace sandbox create`);
|
|
94
108
|
}
|
|
95
109
|
|
|
110
|
+
/** The top of the Git repository holding `dir`, or null. */
|
|
111
|
+
export function repoRoot(dir = process.cwd()) {
|
|
112
|
+
const top = spawnSync('git', ['-C', dir, 'rev-parse', '--show-toplevel'], { encoding: 'utf8' });
|
|
113
|
+
return top.status === 0 ? top.stdout.trim() : null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The files of the repository at `root` that may be uploaded, checked against the limits. */
|
|
117
|
+
export function listProject(root) {
|
|
118
|
+
const project = projectFiles(root);
|
|
119
|
+
if (!project.files.length) throw new Error('Nothing to upload.');
|
|
120
|
+
return project;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Pack listed files into the gzip archive a sandbox is created from. */
|
|
124
|
+
export async function packArchive(root, files) {
|
|
125
|
+
const archive = await pack(root, files);
|
|
126
|
+
if (archive.length > MAX_ARCHIVE) throw new Error(`The packed project is ${Math.round(archive.length / MIB)} MiB; the most is ${MAX_ARCHIVE / MIB} MiB.`);
|
|
127
|
+
return archive;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** What beta credit does for the next cloud sandbox: 'use' it, it has
|
|
131
|
+
* 'expired' (unused, past its hard 3 days), or 'none'. Credit is consumed by
|
|
132
|
+
* the first cloud sandbox created after redemption. An older backend (or no
|
|
133
|
+
* entitlement) never blocks a plain one, so no answer means 'none'; the
|
|
134
|
+
* create call surfaces any real auth/network failure. */
|
|
135
|
+
export async function creditPlan() {
|
|
136
|
+
let beta;
|
|
137
|
+
try { beta = await betaStatus(); } catch { return { plan: 'none', beta: null }; }
|
|
138
|
+
const deadlinePassed = beta?.credit_expires_at && Date.parse(beta.credit_expires_at) <= Date.now();
|
|
139
|
+
if (beta && !beta.sandbox_consumed && deadlinePassed && (beta.entitled || beta.credit_usd)) return { plan: 'expired', beta };
|
|
140
|
+
if (beta?.entitled && !beta.sandbox_consumed) return { plan: 'use', beta };
|
|
141
|
+
return { plan: 'none', beta };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Create a cloud sandbox from a packed project. A credit refusal comes back
|
|
145
|
+
* as an ApiError (see isCreditRefusal) for the caller to decide on. */
|
|
146
|
+
export function upload(archive, name, useCredit) {
|
|
147
|
+
const headers = { 'content-type': 'application/gzip', 'x-raytrace-name': name.replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100) };
|
|
148
|
+
return call('POST', '/v1/sandboxes', { body: archive, headers: useCredit ? { ...headers, 'x-raytrace-beta-credit': '1' } : headers });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The API refused the credit: 409 already used on another sandbox, 410 expired. */
|
|
152
|
+
export const isCreditRefusal = (error) => error instanceof ApiError && [409, 410].includes(error.status);
|
|
153
|
+
|
|
96
154
|
export async function create(flags) {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
const root = top.stdout.trim();
|
|
155
|
+
const root = repoRoot();
|
|
156
|
+
if (!root) throw new Error('Run this from inside a Git repository.');
|
|
100
157
|
const name = flags.name || basename(root);
|
|
101
158
|
// What the machine lacks is said before the project is read, and Lima fetched if agreed.
|
|
102
159
|
const localName = flags.local ? local.sandboxName(flags, root) : null;
|
|
103
160
|
if (flags.local) await local.preflight(flags, { confirm, interactive });
|
|
104
|
-
const { files, skipped, total } =
|
|
105
|
-
if (!files.length) throw new Error('Nothing to upload.');
|
|
161
|
+
const { files, skipped, total } = listProject(root);
|
|
106
162
|
// The same files, packed the same way, as a cloud sandbox gets: only the copy stays here.
|
|
107
163
|
if (flags.local) return local.create(localName, { root, files, skipped, total, archive: await pack(root, files) });
|
|
108
164
|
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!interactive()) throw new Error('Beta credit expired; no sandbox was created. Ask RayTrace for a new code to try again.');
|
|
119
|
-
if (!(await confirm('Create a plain sandbox without beta credit?', false))) { say('Not created.'); return; }
|
|
120
|
-
} else if (beta?.entitled && !beta.sandbox_consumed) {
|
|
121
|
-
useCredit = true;
|
|
122
|
-
say(`Using your $${beta.credit_usd ?? 10} beta credit (OpenRouter) on this sandbox`
|
|
123
|
-
+ `${beta.credit_expires_at ? ` — credit ends ${formatCreditDeadline(beta.credit_expires_at)}` : ''}.`);
|
|
124
|
-
}
|
|
125
|
-
} catch (error) {
|
|
126
|
-
if (/Beta credit expired/.test(error.message)) throw error;
|
|
127
|
-
// No beta answer (old backend, signed out, unreachable): proceed plain;
|
|
128
|
-
// the create call below surfaces any real auth/network failure.
|
|
165
|
+
// A local sandbox never uses beta credit.
|
|
166
|
+
const { plan, beta } = await creditPlan();
|
|
167
|
+
if (plan === 'expired') {
|
|
168
|
+
say('Your $10 beta credit has expired: the 3 days ran out, and unused credit does not carry over.');
|
|
169
|
+
if (!interactive()) throw new Error('Beta credit expired; no sandbox was created. Ask RayTrace for a new code to try again.');
|
|
170
|
+
if (!(await confirm('Create a plain sandbox without beta credit?', false))) { say('Not created.'); return; }
|
|
171
|
+
} else if (plan === 'use') {
|
|
172
|
+
say(`Using your $${beta.credit_usd ?? 10} beta credit (OpenRouter) on this sandbox`
|
|
173
|
+
+ `${beta.credit_expires_at ? ` — credit ends ${formatCreditDeadline(beta.credit_expires_at)}` : ''}.`);
|
|
129
174
|
}
|
|
175
|
+
const useCredit = plan === 'use';
|
|
130
176
|
say(`Packing ${files.length} files (${(total / 1048576).toFixed(1)} MiB) from ${root}`);
|
|
131
177
|
if (skipped.length) say(`Not uploaded (${skipped.length}): ${skipped.slice(0, 8).join(', ')}${skipped.length > 8 ? ', ...' : ''}`);
|
|
132
|
-
const archive = await
|
|
133
|
-
if (archive.length > MAX_ARCHIVE) throw new Error(`The packed project is ${Math.round(archive.length / MIB)} MiB; the most is ${MAX_ARCHIVE / MIB} MiB.`);
|
|
178
|
+
const archive = await packArchive(root, files);
|
|
134
179
|
say('Creating the sandbox (the first one on a host takes a little longer)...');
|
|
135
|
-
const headers = { 'content-type': 'application/gzip', 'x-raytrace-name': name.replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100) };
|
|
136
180
|
let box;
|
|
137
181
|
try {
|
|
138
|
-
box = await
|
|
139
|
-
body: archive, headers: useCredit ? { ...headers, 'x-raytrace-beta-credit': '1' } : headers,
|
|
140
|
-
});
|
|
182
|
+
box = await upload(archive, name, useCredit);
|
|
141
183
|
} catch (error) {
|
|
142
|
-
if (!useCredit || !(error
|
|
184
|
+
if (!useCredit || !isCreditRefusal(error)) throw error;
|
|
143
185
|
say(error.status === 410 ? 'Your beta credit expired before the sandbox was created.'
|
|
144
186
|
: 'Your beta credit was already used on another sandbox.');
|
|
145
187
|
if (!interactive() || !(await confirm('Create a plain sandbox without beta credit?', false))) {
|
|
146
188
|
throw new Error('Beta credit not applied; no sandbox was created.');
|
|
147
189
|
}
|
|
148
|
-
box = await
|
|
190
|
+
box = await upload(archive, name, false);
|
|
149
191
|
}
|
|
150
192
|
say(`\nSandbox ${box.id} is running.`);
|
|
151
193
|
if (box.credit_applied) {
|
|
@@ -158,7 +200,7 @@ export async function create(flags) {
|
|
|
158
200
|
|
|
159
201
|
export async function list(flags = {}) {
|
|
160
202
|
if (flags.local) return local.list();
|
|
161
|
-
const boxes =
|
|
203
|
+
const boxes = await liveSandboxes();
|
|
162
204
|
if (!boxes.length) { say('No sandboxes. Create one from a Git repository: raytrace sandbox create'); return; }
|
|
163
205
|
for (const box of boxes) {
|
|
164
206
|
// The sandbox's creation time (seconds), or its container's once that is known.
|
|
@@ -216,7 +258,7 @@ export function betaExpiryWarning(beta, id, now = Date.now()) {
|
|
|
216
258
|
export async function shell(id, flags = {}) {
|
|
217
259
|
if (!interactive()) throw new Error('Connecting to a sandbox needs a terminal.');
|
|
218
260
|
// With no id and no cloud sign-in, the one local sandbox is the likely one.
|
|
219
|
-
if (flags.local || local.isLocal(id) || (!id && Object.keys(local.registry()).length && !account())) return local.shell(id);
|
|
261
|
+
if (flags.local || local.isLocal(id) || (!id && Object.keys(local.registry()).length && !account())) return local.shell(id, { claude: flags.claude });
|
|
220
262
|
id = await pickId(id);
|
|
221
263
|
try {
|
|
222
264
|
const warning = betaExpiryWarning(await betaStatus(), id);
|
|
@@ -242,8 +284,11 @@ export async function shell(id, flags = {}) {
|
|
|
242
284
|
});
|
|
243
285
|
});
|
|
244
286
|
req.on('upgrade', (_response, socket, head) => {
|
|
245
|
-
say(`Connected to ${id}
|
|
287
|
+
say(flags.claude ? `Connected to ${id}, starting Claude Code without permission prompts (the sandbox is what contains it); when it exits you are in the sandbox's shell. The sandbox keeps running.\n`
|
|
288
|
+
: `Connected to ${id}. Run \`claude\` (or codex) here; exit to leave. The sandbox keeps running.\n`);
|
|
246
289
|
if (head.length) stdout.write(head);
|
|
290
|
+
// The API's shell takes no command: Claude Code is started by typing it, which the terminal holds until the shell reads it.
|
|
291
|
+
if (flags.claude) socket.write('claude --dangerously-skip-permissions\r');
|
|
247
292
|
stdin.setRawMode(true);
|
|
248
293
|
stdin.resume();
|
|
249
294
|
stdin.pipe(socket);
|
package/src/share.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// `raytrace share`: create, list, and revoke share links for recorded traces.
|
|
2
|
+
// Shares are time-limited links on https://app.raytracer.si/share/<token>.
|
|
3
|
+
import { call, ApiError } from './api.mjs';
|
|
4
|
+
import { liveSandboxes } from './sandbox.mjs';
|
|
5
|
+
|
|
6
|
+
const DASHBOARD = process.env.RAYTRACE_DASHBOARD_URL || 'https://app.raytracer.si';
|
|
7
|
+
const say = (line = '') => console.log(line);
|
|
8
|
+
|
|
9
|
+
export function formatTimeLeft(expiresEpoch) {
|
|
10
|
+
const leftSec = Math.round(expiresEpoch - Date.now() / 1000);
|
|
11
|
+
if (leftSec <= 0) return 'expired';
|
|
12
|
+
const min = Math.round(leftSec / 60);
|
|
13
|
+
if (min < 60) return `${min} min`;
|
|
14
|
+
const hr = Math.round(min / 60);
|
|
15
|
+
return `${hr} h`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function sharePrompt(traceId, { sandboxId, allowFork = false } = {}) {
|
|
19
|
+
if (!traceId || !traceId.trim()) {
|
|
20
|
+
throw new Error('Trace ID is required. Usage: raytrace share <trace-id> [--sandbox <id>] [--fork]');
|
|
21
|
+
}
|
|
22
|
+
const cleanTrace = traceId.trim();
|
|
23
|
+
|
|
24
|
+
let targetSandbox = sandboxId?.trim();
|
|
25
|
+
if (!targetSandbox) {
|
|
26
|
+
const sandboxes = await liveSandboxes();
|
|
27
|
+
if (sandboxes.length === 1) {
|
|
28
|
+
targetSandbox = sandboxes[0].id;
|
|
29
|
+
} else if (sandboxes.length === 0) {
|
|
30
|
+
throw new Error('No live cloud sandboxes found. Create one first with: raytrace sandbox create');
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error(`More than one cloud sandbox found. Specify which one with --sandbox <id>:\n ${sandboxes.map((s) => `${s.id} (${s.name})`).join('\n ')}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const result = await call('POST', '/v1/shares', {
|
|
37
|
+
body: {
|
|
38
|
+
trace_id: cleanTrace,
|
|
39
|
+
sandbox_id: targetSandbox,
|
|
40
|
+
allow_fork: Boolean(allowFork),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const fullUrl = `${DASHBOARD}${result.url}`;
|
|
45
|
+
const share = result.share;
|
|
46
|
+
say('Share link created:');
|
|
47
|
+
say(` ${fullUrl}`);
|
|
48
|
+
say();
|
|
49
|
+
say(`- Prompt: ${share.trace_id}`);
|
|
50
|
+
say(`- Sandbox: ${share.sandbox_id}`);
|
|
51
|
+
say(`- Forking: ${share.allow_fork ? 'allowed' : 'view only'}`);
|
|
52
|
+
say(`- Expires in: ${formatTimeLeft(share.expires)}`);
|
|
53
|
+
return { ...result, fullUrl };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function listShares() {
|
|
57
|
+
const result = await call('GET', '/v1/shares');
|
|
58
|
+
const shares = result.shares ?? [];
|
|
59
|
+
const tier = result.tier === 'enterprise' ? 'Team & Enterprise' : 'Individual';
|
|
60
|
+
say(`Active share links (${shares.length} of ${result.limit} on ${tier}):`);
|
|
61
|
+
if (!shares.length) {
|
|
62
|
+
say(' No active share links. Share a prompt with: raytrace share <trace-id>');
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
say();
|
|
66
|
+
for (const s of shares) {
|
|
67
|
+
const views = s.views?.length ?? 0;
|
|
68
|
+
const viewStr = views === 1 ? '1 view' : `${views} views`;
|
|
69
|
+
say(`- ${s.trace_id}: ${formatTimeLeft(s.expires)} remaining · ${s.allow_fork ? 'fork allowed' : 'view only'} · ${viewStr}`);
|
|
70
|
+
say(` Link: ${DASHBOARD}/share/${s.id}`);
|
|
71
|
+
say(` ID: ${s.id}`);
|
|
72
|
+
}
|
|
73
|
+
say();
|
|
74
|
+
say('Revoke a link at any time: raytrace share --revoke <id>');
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function revokeShare(shareId) {
|
|
79
|
+
if (!shareId || !shareId.trim()) {
|
|
80
|
+
throw new Error('Share ID is required. Usage: raytrace share --revoke <id>');
|
|
81
|
+
}
|
|
82
|
+
const cleanId = shareId.trim();
|
|
83
|
+
await call('POST', `/v1/shares/${cleanId}/revoke`);
|
|
84
|
+
say(`Revoked share link ${cleanId}.`);
|
|
85
|
+
return { revoked: cleanId };
|
|
86
|
+
}
|
package/src/terminal.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// A new terminal running one command, for `raytrace mcp` to open a sandbox's
|
|
2
|
+
// terminal next to the editor. The environment says where the agent itself
|
|
3
|
+
// runs (an MCP server inherits it from its client), and the new terminal goes
|
|
4
|
+
// there when that can be driven from outside: a tmux window beside it, an iTerm
|
|
5
|
+
// or WezTerm window or tab. Otherwise the system's own terminal. VS Code's
|
|
6
|
+
// built-in terminal cannot be opened from outside VS Code, so there it is a
|
|
7
|
+
// separate Terminal window.
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
/** One argument, quoted for sh. */
|
|
11
|
+
export const shellQuote = (arg) => (/^[A-Za-z0-9_./:=@%+-]+$/.test(arg) ? arg : `'${String(arg).replace(/'/g, `'\\''`)}'`);
|
|
12
|
+
const appleString = (text) => `"${text.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
13
|
+
const has = (program) => spawnSync('sh', ['-c', `command -v ${shellQuote(program)}`], { stdio: 'ignore' }).status === 0;
|
|
14
|
+
|
|
15
|
+
function attempt(how, program, args) {
|
|
16
|
+
const result = spawnSync(program, args, { stdio: ['ignore', 'ignore', 'pipe'], encoding: 'utf8', timeout: 15_000 });
|
|
17
|
+
if (result.error || result.status !== 0) {
|
|
18
|
+
return { opened: false, how, error: (result.error?.message || result.stderr || `exit ${result.status}`).trim().split('\n').slice(-2).join(' ') };
|
|
19
|
+
}
|
|
20
|
+
return { opened: true, how };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Where to open it, best first: [label, program, args]. */
|
|
24
|
+
function candidates(args, title, env) {
|
|
25
|
+
const command = args.map(shellQuote).join(' ');
|
|
26
|
+
const found = [];
|
|
27
|
+
if (env.TMUX && has('tmux')) found.push(['a new tmux window', 'tmux', ['new-window', '-n', title, command]]);
|
|
28
|
+
if (process.platform === 'darwin') {
|
|
29
|
+
if (env.TERM_PROGRAM === 'iTerm.app') {
|
|
30
|
+
found.push(['a new iTerm window', 'osascript', ['-e', `tell application "iTerm"
|
|
31
|
+
activate
|
|
32
|
+
set w to (create window with default profile)
|
|
33
|
+
tell current session of w to write text ${appleString(command)}
|
|
34
|
+
end tell`]]);
|
|
35
|
+
}
|
|
36
|
+
if (env.TERM_PROGRAM === 'WezTerm' && has('wezterm')) found.push(['a new WezTerm tab', 'wezterm', ['cli', 'spawn', '--', '/bin/sh', '-c', command]]);
|
|
37
|
+
found.push(['a new Terminal window', 'osascript', ['-e', `tell application "Terminal"
|
|
38
|
+
activate
|
|
39
|
+
do script ${appleString(command)}
|
|
40
|
+
end tell`]]);
|
|
41
|
+
} else if (process.platform === 'win32') {
|
|
42
|
+
const line = args.map((arg) => (/[\s"]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg)).join(' ');
|
|
43
|
+
if (spawnSync('where', ['wt'], { stdio: 'ignore' }).status === 0) found.push(['a new Windows Terminal tab', 'wt', ['new-tab', '--title', title, 'cmd', '/k', line]]);
|
|
44
|
+
found.push(['a new Command Prompt window', 'cmd', ['/c', 'start', `"${title}"`, 'cmd', '/k', line]]);
|
|
45
|
+
} else if (env.DISPLAY || env.WAYLAND_DISPLAY) {
|
|
46
|
+
for (const [program, flag] of [['x-terminal-emulator', '-e'], ['gnome-terminal', '--'], ['konsole', '-e'], ['xfce4-terminal', '-x'],
|
|
47
|
+
['kitty', null], ['alacritty', '-e'], ['wezterm', 'start'], ['xterm', '-e']]) {
|
|
48
|
+
if (has(program)) found.push([`a new ${program} window`, program, [...(flag ? [flag] : []), '/bin/sh', '-c', command]]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return found;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Open a new terminal running `args` (a program and its arguments). Answers
|
|
56
|
+
* { opened, how, command }: how it was opened, or why not, and the command as
|
|
57
|
+
* the user would type it, for when it could not be.
|
|
58
|
+
*/
|
|
59
|
+
export function openTerminal(args, { title = 'RayTrace', env = process.env } = {}) {
|
|
60
|
+
const command = args.map(shellQuote).join(' ');
|
|
61
|
+
const errors = [];
|
|
62
|
+
for (const [how, program, programArgs] of candidates(args, title, env)) {
|
|
63
|
+
const result = attempt(how, program, programArgs);
|
|
64
|
+
if (result.opened) return { opened: true, how, command };
|
|
65
|
+
errors.push(`${how}: ${result.error}`);
|
|
66
|
+
}
|
|
67
|
+
return { opened: false, how: errors.length ? errors.join('; ') : 'no terminal found to open', command };
|
|
68
|
+
}
|
|
@@ -116,7 +116,9 @@ def install_claude_hooks(container, hook):
|
|
|
116
116
|
if not 0 < len(hook) <= 262144:
|
|
117
117
|
raise ValueError('Expected the hook script')
|
|
118
118
|
command = 'node /opt/raytace-claude/hook.mjs'
|
|
119
|
-
|
|
119
|
+
# No permission prompts for any Claude Code session here: the sandbox is
|
|
120
|
+
# what contains the agent, and the hook still refuses restricted files.
|
|
121
|
+
settings = json.dumps({'permissions': {'defaultMode': 'bypassPermissions'}, 'skipDangerousModePermissionPrompt': True, 'hooks': {
|
|
120
122
|
# Bash for the call id; the file tools so an edit to a restricted file is refused (see guardrails()).
|
|
121
123
|
'PreToolUse': [{'matcher': 'Bash|Write|Edit|MultiEdit|NotebookEdit', 'hooks': [{'type': 'command', 'command': command, 'timeout': 5}]}],
|
|
122
124
|
**{event: [{**({'matcher': '*'} if event == 'PostToolUse' else {}),
|
|
@@ -548,6 +550,7 @@ def main():
|
|
|
548
550
|
parser.add_argument('--since', type=int, default=0, help='activity: from this epoch ms')
|
|
549
551
|
parser.add_argument('--until', type=int, default=0, help='activity: up to this epoch ms')
|
|
550
552
|
parser.add_argument('--forget-evidence', action='store_true', help='delete: also delete what the collector recorded for it')
|
|
553
|
+
parser.add_argument('--claude', action='store_true', help='shell: start Claude Code first; its exit leaves the shell')
|
|
551
554
|
opts = parser.parse_args()
|
|
552
555
|
if opts.action == 'list':
|
|
553
556
|
ids = subprocess.check_output(['docker', 'ps', '-aq', '--filter', 'label='+LABEL], text=True).split()
|
|
@@ -645,8 +648,10 @@ def main():
|
|
|
645
648
|
if opts.action == 'start':
|
|
646
649
|
return
|
|
647
650
|
# Exiting this shell or Codex never stops/removes the persistent container.
|
|
648
|
-
|
|
649
|
-
|
|
651
|
+
start = 'if [ -f /home/node/.raytace-codex/config.toml ]; then export CODEX_HOME=/home/node/.raytace-codex; fi; '
|
|
652
|
+
if opts.claude:
|
|
653
|
+
start += 'cd /workspace 2>/dev/null; if command -v claude >/dev/null; then claude --dangerously-skip-permissions; else echo "Claude Code is not installed in this sandbox."; fi; '
|
|
654
|
+
proc = subprocess.run(['docker', 'exec', '-it', opts.id, '/bin/bash', '-c', start+'exec /bin/bash'], check=False)
|
|
650
655
|
sys.exit(proc.returncode)
|
|
651
656
|
elif opts.action == 'stop':
|
|
652
657
|
run('docker', 'stop', '-t', '10', opts.id)
|