@raytrace-cli/cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,18 +112,25 @@ recorded for your organization.
112
112
  raytrace auth login # sign in once; a code opens in your browser
113
113
  cd your-project # any Git repository
114
114
  raytrace sandbox create # upload it to a new sandbox
115
- raytrace sandbox shell # a terminal in the sandbox: run claude or codex there
115
+ raytrace connect # a terminal in the sandbox: run claude or codex there
116
116
  ```
117
117
 
118
118
  Then open **[app.raytracer.si](https://app.raytracer.si)** and sign in with the
119
- same account to see your organization's prompts, sandboxes and tool calls.
119
+ same account to see your organization's prompts, sandboxes and tool calls. You
120
+ can also create a sandbox there by dropping a project folder on the Sandboxes
121
+ page; it shows the command to open it, `raytrace connect <sandbox-id>`, which
122
+ signs you in first if you are not. Sandboxes belong to the account that made
123
+ them: `raytrace auth status` says which one the CLI is using.
120
124
 
121
125
  - **What is uploaded:** the files Git would track in the repository (including
122
126
  new files it does not ignore), without `.git`, dependencies such as
123
127
  `node_modules`, build output, `.env*` files, private keys (`.pem`, `.key`,
124
128
  `.p12`, `.pfx`) and common credential files (`.npmrc`, `.netrc`, `id_rsa`, …).
125
- The upload is limited to 256 MiB. Review your project for secrets inside other
126
- files before you upload.
129
+ Review your project for secrets inside other files before you upload.
130
+ - **Limits:** a project may be up to 200 MiB and 20,000 files, each file up to
131
+ 25 MiB (100 MiB once packed). A project over a limit is refused, with the
132
+ files named, and nothing is uploaded; add them to `.gitignore`. You can have
133
+ three sandboxes at a time.
127
134
  - **Signing in to your agent:** sign in to Claude Code inside the sandbox as
128
135
  you would on your machine. That sign-in stays in the sandbox until you
129
136
  destroy it.
@@ -149,7 +156,7 @@ Cloud sandboxes are a preview and may change; please
149
156
  | `raytrace auth login` | sign in to RayTrace (needed for cloud sandboxes); `status`, `logout` |
150
157
  | `raytrace sandbox create` | upload this Git repository to a new cloud sandbox; `--name <name>` |
151
158
  | `raytrace sandbox list` | your cloud sandboxes |
152
- | `raytrace sandbox shell [id]` | open a terminal in a sandbox |
159
+ | `raytrace connect [id]` | open a terminal in a sandbox, signing in first if needed (also `raytrace sandbox shell [id]`) |
153
160
  | `raytrace sandbox start\|stop [id]` | start or stop a sandbox; stopping keeps its files |
154
161
  | `raytrace sandbox destroy [id]` | delete a sandbox; its recorded sessions are kept |
155
162
 
package/bin/raytrace.mjs CHANGED
@@ -16,15 +16,18 @@ Usage: raytrace <command>
16
16
  codex [...] run Codex through RayTrace (needs an OpenRouter key)
17
17
  uninstall remove the Claude Code hook, optionally all recorded data
18
18
  auth ... sign in to RayTrace: login, status, logout
19
+ connect <id> open a terminal in a cloud sandbox (signs you in if needed)
19
20
  sandbox ... cloud sandboxes: create, list, shell, start, stop, destroy
20
21
 
21
22
  Options for setup: --yes --no-claude-code --no-start --openrouter-key <key>
22
23
  Options for uninstall: --yes --purge (also delete ~/.raytrace)
23
24
 
24
- Sandboxes (preview; sign in first with raytrace auth login):
25
+ Sandboxes (preview):
25
26
  raytrace sandbox create [--name <name>] upload this Git repository to a new sandbox
27
+ (up to 200 MiB, 25 MiB a file, 20,000 files)
26
28
  raytrace sandbox list
27
- raytrace sandbox shell [id] a terminal in it; run claude or codex there
29
+ raytrace connect [id] a terminal in it; run claude or codex there
30
+ (same as: raytrace sandbox shell [id])
28
31
  raytrace sandbox start|stop [id]
29
32
  raytrace sandbox destroy [id] [--yes] delete it; recorded evidence is kept
30
33
 
@@ -66,6 +69,14 @@ if (command === 'auth') {
66
69
  catch (error) { console.error(`raytrace auth ${sub}: ${error.message}`); process.exit(1); }
67
70
  }
68
71
 
72
+ // `raytrace connect <id>`: the sandbox's terminal, by the id the dashboard shows.
73
+ if (command === 'connect') {
74
+ if (rest.length > 1 || rest[0]?.startsWith('-')) { console.error('Usage: raytrace connect [sandbox-id]'); process.exit(2); }
75
+ const sandbox = await import('../src/sandbox.mjs');
76
+ try { await sandbox.shell(rest[0]); process.exit(0); }
77
+ catch (error) { console.error(`raytrace connect: ${error.message}`); process.exit(1); }
78
+ }
79
+
69
80
  if (command === 'sandbox') {
70
81
  const sandbox = await import('../src/sandbox.mjs');
71
82
  let parsed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytrace-cli/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/auth.mjs CHANGED
@@ -136,6 +136,9 @@ export async function login() {
136
136
  throw new Error('The code expired before it was approved. Run raytrace auth login again.');
137
137
  }
138
138
 
139
+ /** The signed-in account's email, for messages that need to say whose workspace this is; null when signed out. */
140
+ export function account() { return load()?.user?.email || null; }
141
+
139
142
  export async function status() {
140
143
  const session = load();
141
144
  if (!session) { say('Not signed in. Run: raytrace auth login'); return; }
package/src/sandbox.mjs CHANGED
@@ -11,12 +11,18 @@ import { lstatSync } from 'node:fs';
11
11
  import { request as httpRequest } from 'node:http';
12
12
  import { request as httpsRequest } from 'node:https';
13
13
  import { basename, join } from 'node:path';
14
- import { accessToken } from './auth.mjs';
14
+ import { accessToken, account, login } from './auth.mjs';
15
15
  import { readConfig } from './config.mjs';
16
16
  import { ask, interactive } from './prompt.mjs';
17
17
 
18
18
  const say = (line = '') => console.log(line);
19
- const MAX_BYTES = 256 * 1024 * 1024;
19
+ // What one project upload may be. RayTrace's API holds the dashboard's folder
20
+ // upload to the same numbers and checks them again; saying so here saves the upload.
21
+ const MIB = 1024 * 1024;
22
+ const MAX_FILE = 25 * MIB; // any one file
23
+ const MAX_BYTES = 200 * MIB; // all files, before compression
24
+ const MAX_FILES = 20_000;
25
+ const MAX_ARCHIVE = 100 * MIB; // the packed upload
20
26
  const ID = /^rtp-[a-f0-9]{32}$/;
21
27
  const API = 'https://api.raytracer.si';
22
28
  const unreachable = (url) => new Error(`Cannot reach RayTrace at ${url.origin}. Check your connection; `
@@ -39,8 +45,15 @@ export function packable(path) {
39
45
  async function api() {
40
46
  const config = readConfig();
41
47
  const url = process.env.RAYTRACE_API_URL || config.RAYTRACE_API_URL || API;
42
- const key = process.env.RAYTRACE_API_KEY || config.RAYTRACE_API_KEY || await accessToken();
43
- if (!key) throw new Error('Not signed in. Run: raytrace auth login');
48
+ let key = process.env.RAYTRACE_API_KEY || config.RAYTRACE_API_KEY || await accessToken();
49
+ if (!key) {
50
+ if (!interactive()) throw new Error('Not signed in. Run: raytrace auth login');
51
+ say('You are not signed in to RayTrace yet.');
52
+ await login();
53
+ key = await accessToken();
54
+ if (!key) throw new Error('Not signed in. Run: raytrace auth login');
55
+ say();
56
+ }
44
57
  return { url: new URL(url), key };
45
58
  }
46
59
 
@@ -61,15 +74,22 @@ async function call(method, path, { body, headers = {} } = {}) {
61
74
  function projectFiles(root) {
62
75
  const listed = spawnSync('git', ['-C', root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], { maxBuffer: 256 * 1024 * 1024 });
63
76
  if (listed.status !== 0) throw new Error(`${root} is not a Git repository. Run this from inside one.`);
64
- const files = []; const skipped = []; let total = 0;
77
+ const files = []; const skipped = []; const large = []; let total = 0;
65
78
  for (const name of [...new Set(listed.stdout.toString().split('\0').filter(Boolean))].sort()) {
66
79
  let stat;
67
80
  try { stat = lstatSync(join(root, name)); } catch { continue; } // deleted, still in the index
68
81
  if (!packable(name) || !stat.isFile()) { skipped.push(name); continue; } // symlinks too
82
+ if (stat.size > MAX_FILE) { large.push(`${name} (${Math.round(stat.size / MIB)} MiB)`); continue; }
69
83
  total += stat.size;
70
- if (total > MAX_BYTES) throw new Error('The project is over 256 MiB; add large generated files to .gitignore first.');
71
84
  files.push(name);
72
85
  }
86
+ // Refused, never trimmed: a project missing its large files would not be the project.
87
+ if (large.length) {
88
+ throw new Error(`${large.length === 1 ? 'This file is' : 'These files are'} over ${MAX_FILE / MIB} MiB, the most one file may be:\n `
89
+ + `${large.slice(0, 10).join('\n ')}${large.length > 10 ? `\n ... and ${large.length - 10} more` : ''}\nAdd ${large.length === 1 ? 'it' : 'them'} to .gitignore (or remove ${large.length === 1 ? 'it' : 'them'}), then try again.`);
90
+ }
91
+ if (files.length > MAX_FILES) throw new Error(`The project has ${files.length.toLocaleString()} files; the most is ${MAX_FILES.toLocaleString()}. Add generated files to .gitignore first.`);
92
+ if (total > MAX_BYTES) throw new Error(`The project is ${Math.round(total / MIB)} MiB; the most is ${MAX_BYTES / MIB} MiB. Add large generated files to .gitignore first.`);
73
93
  return { files, skipped, total };
74
94
  }
75
95
 
@@ -96,7 +116,8 @@ async function pickId(id) {
96
116
  }
97
117
  const live = (await call('GET', '/v1/sandboxes')).filter((box) => box.status !== 'deleted');
98
118
  if (live.length === 1) return live[0].id;
99
- throw new Error(live.length ? 'More than one sandbox; name one (raytrace sandbox list).' : 'No sandboxes yet: raytrace sandbox create');
119
+ throw new Error(live.length ? 'More than one sandbox; name one (raytrace sandbox list).'
120
+ : `No sandboxes${account() ? ` in ${account()}'s workspace` : ''} yet: raytrace sandbox create`);
100
121
  }
101
122
 
102
123
  export async function create(flags) {
@@ -109,6 +130,7 @@ export async function create(flags) {
109
130
  say(`Packing ${files.length} files (${(total / 1048576).toFixed(1)} MiB) from ${root}`);
110
131
  if (skipped.length) say(`Not uploaded (${skipped.length}): ${skipped.slice(0, 8).join(', ')}${skipped.length > 8 ? ', ...' : ''}`);
111
132
  const archive = await pack(root, files);
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.`);
112
134
  say('Creating the sandbox (the first one on a host takes a little longer)...');
113
135
  const box = await call('POST', '/v1/sandboxes', {
114
136
  body: archive, headers: { 'content-type': 'application/gzip', 'x-raytrace-name': name.replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100) },
@@ -116,7 +138,7 @@ export async function create(flags) {
116
138
  say(`\nSandbox ${box.id} is running.`);
117
139
  say(box.transcripts ? 'Claude Code sessions in it are recorded.'
118
140
  : `Claude Code transcripts are off: ${box.transcripts_off}. Commands are still recorded.`);
119
- say(`Open it: raytrace sandbox shell ${box.id}`);
141
+ say(`Open it: raytrace connect ${box.id}`);
120
142
  }
121
143
 
122
144
  export async function list() {
@@ -144,10 +166,11 @@ export async function destroy(id, flags) {
144
166
  say(`${id} destroyed.`);
145
167
  }
146
168
 
147
- /** An interactive terminal in the sandbox, carried over one upgraded HTTP request. */
169
+ /** An interactive terminal in the sandbox, carried over one upgraded HTTP request.
170
+ * `raytrace connect <id>` and `raytrace sandbox shell [id]` are the same thing. */
148
171
  export async function shell(id) {
172
+ if (!interactive()) throw new Error('Connecting to a sandbox needs a terminal.');
149
173
  id = await pickId(id);
150
- if (!interactive()) throw new Error('raytrace sandbox shell needs a terminal.');
151
174
  const { url, key } = await api();
152
175
  const { stdin, stdout } = process;
153
176
  const path = `/v1/sandboxes/${id}/shell?rows=${stdout.rows || 24}&cols=${stdout.columns || 80}`;
@@ -158,7 +181,14 @@ export async function shell(id) {
158
181
  req.on('response', (response) => {
159
182
  let text = '';
160
183
  response.on('data', (chunk) => { text += chunk; });
161
- response.on('end', () => { try { reject(new Error(JSON.parse(text).error)); } catch { reject(new Error(`HTTP ${response.statusCode}`)); } });
184
+ response.on('end', () => {
185
+ // The API does not say whether another account has this sandbox; the likely mix-up is worth naming.
186
+ if (response.statusCode === 404 && account()) {
187
+ return reject(new Error(`No sandbox ${id} in ${account()}'s workspace. If it was made under another account `
188
+ + '(for example in the dashboard), sign in as that one: raytrace auth login'));
189
+ }
190
+ try { reject(new Error(JSON.parse(text).error)); } catch { reject(new Error(`HTTP ${response.statusCode}`)); }
191
+ });
162
192
  });
163
193
  req.on('upgrade', (_response, socket, head) => {
164
194
  say(`Connected to ${id}. Run \`claude\` (or codex) here; exit to leave. The sandbox keeps running.\n`);
@@ -174,5 +204,5 @@ export async function shell(id) {
174
204
  req.on('error', () => reject(unreachable(url)));
175
205
  req.end();
176
206
  });
177
- say(`\nLeft ${id}. It is still running: raytrace sandbox stop ${id}`);
207
+ say(`\nLeft ${id}. It is still running. Back in: raytrace connect ${id} Stop it: raytrace sandbox stop ${id}`);
178
208
  }