@raytrace-cli/cli 0.17.14 → 0.17.16

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
@@ -24,6 +24,7 @@
24
24
  <a href="https://pypi.org/project/raytrace-cli/">PyPI</a> ·
25
25
  <a href="docs/mcp.md">MCP</a> ·
26
26
  <a href="CONTRIBUTING.md">Contributing</a> ·
27
+ <a href="https://discord.gg/k7VWV5Gac9">Discord</a> ·
27
28
  <a href="https://github.com/Godcreatebugs/raytrace-cli/issues">Report an issue</a>
28
29
  </p>
29
30
 
@@ -32,6 +33,7 @@
32
33
  <a href="https://pypi.org/project/raytrace-cli/"><img src="https://img.shields.io/pypi/v/raytrace-cli?style=flat-square" alt="PyPI" /></a>
33
34
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="MIT license" /></a>
34
35
  <a href="https://www.raytracer.si/"><img src="https://img.shields.io/badge/website-raytracer.si-111315?style=flat-square" alt="raytracer.si" /></a>
36
+ <a href="https://discord.gg/k7VWV5Gac9"><img src="https://img.shields.io/badge/Discord-join-5865F2?style=flat-square&logo=discord&logoColor=white" alt="Discord" /></a>
35
37
  </p>
36
38
 
37
39
  ## Why sandboxing matters
package/bin/raytrace.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  // The `raytrace` command. Each subcommand lives in src/commands.mjs.
3
3
  import { readFileSync } from 'node:fs';
4
4
  import { parseArgs } from 'node:util';
5
+ import { closestCommand } from '../src/command-suggestion.mjs';
5
6
 
6
7
  const HELP = `RayTrace: see what your coding agent did.
7
8
 
@@ -103,6 +104,20 @@ AI features in the dashboard (summaries, recaps, Chain of thought), on your own
103
104
 
104
105
  Your sign-in stays on this machine; raytrace auth logout removes it.`;
105
106
 
107
+ const SANDBOX_HELP = [
108
+ 'Usage: raytrace sandbox <command>',
109
+ ...HELP.split('\n').filter((line) => line.startsWith(' raytrace sandbox ')),
110
+ ' raytrace sandbox shell [id]',
111
+ ].join('\n');
112
+
113
+ function unknownCommand(input, names, scope = '') {
114
+ const suggestion = closestCommand(input, names);
115
+ const prefix = scope ? `${scope} ` : '';
116
+ return `Unknown ${prefix}command: ${input}.`
117
+ + (suggestion ? ` Did you mean: raytrace ${prefix}${suggestion}?` : '')
118
+ + '\nRun raytrace help for all commands.';
119
+ }
120
+
106
121
  // node:sqlite, which the recorder stores everything in, needs 22.13.
107
122
  const [major, minor] = process.versions.node.split('.').map(Number);
108
123
  if (major < 22 || (major === 22 && minor < 13)) {
@@ -197,7 +212,7 @@ if (command === 'sandbox') {
197
212
  if (sub === 'destroy' && parsed.values['delete-logs'] && parsed.values['keep-logs']) {
198
213
  console.error('raytrace sandbox destroy: Pick one: --delete-logs or --keep-logs.'); process.exit(2);
199
214
  }
200
- const action = {
215
+ const actions = {
201
216
  create: () => sandbox.create(parsed.values),
202
217
  list: () => sandbox.list(parsed.values),
203
218
  shell: () => sandbox.shell(id, parsed.values),
@@ -205,8 +220,10 @@ if (command === 'sandbox') {
205
220
  stop: () => sandbox.stop(id, parsed.values),
206
221
  destroy: () => sandbox.destroy(id, parsed.values),
207
222
  files: () => sandbox.files(id, parsed.values),
208
- }[sub];
209
- if (!action) { console.error(`Unknown sandbox command: ${sub ?? '(none)'}\n\n${HELP}`); process.exit(2); }
223
+ };
224
+ const action = actions[sub];
225
+ if (!sub) { console.error(SANDBOX_HELP); process.exit(2); }
226
+ if (!action) { console.error(unknownCommand(sub, Object.keys(actions), 'sandbox')); process.exit(2); }
210
227
  try { await action(); process.exit(0); }
211
228
  catch (error) { console.error(`raytrace sandbox ${sub}: ${error.message}`); process.exit(1); }
212
229
  }
@@ -337,7 +354,7 @@ try {
337
354
  } }));
338
355
  } catch (error) { console.error(`${error.message}\n\nRun \`raytrace help\` for usage.`); process.exit(2); }
339
356
 
340
- const run = {
357
+ const actions = {
341
358
  setup: () => commands.setup(flags),
342
359
  start: () => commands.startCommand(),
343
360
  stop: () => commands.stopCommand(),
@@ -345,8 +362,12 @@ const run = {
345
362
  open: () => commands.openCommand(),
346
363
  doctor: () => commands.doctor(),
347
364
  uninstall: () => commands.uninstall(flags),
348
- }[command];
365
+ };
366
+ const run = actions[command];
349
367
 
350
- if (!run) { console.error(`Unknown command: ${command}\n\n${HELP}`); process.exit(2); }
368
+ if (!run) {
369
+ const names = [...Object.keys(actions), 'auth', 'code', 'codex', 'connect', 'export', 'help', 'hook', 'key', 'mcp', 'report', 'sandbox', 'share', 'upload'];
370
+ console.error(unknownCommand(command, names)); process.exit(2);
371
+ }
351
372
  try { await run(); }
352
373
  catch (error) { console.error(`raytrace ${command}: ${error.message}`); process.exitCode = 1; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytrace-cli/cli",
3
- "version": "0.17.14",
3
+ "version": "0.17.16",
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",
@@ -0,0 +1,27 @@
1
+ /** Prefer a short completion, then the closest command within two edits. */
2
+ export function closestCommand(input, commands) {
3
+ if (!input) return undefined;
4
+ const completion = commands.filter((command) => command.startsWith(input) && command.length - input.length <= 2)
5
+ .sort((a, b) => a.length - b.length)[0];
6
+ if (completion) return completion;
7
+ let closest;
8
+ let bestDistance = 3;
9
+ for (const command of commands) {
10
+ if (Math.abs(command.length - input.length) > 2) continue;
11
+ const distance = editDistance(input, command);
12
+ if (distance < bestDistance) { closest = command; bestDistance = distance; }
13
+ }
14
+ return closest;
15
+ }
16
+
17
+ function editDistance(input, command) {
18
+ let previous = Array.from({ length: command.length + 1 }, (_, i) => i);
19
+ for (let i = 1; i <= input.length; i += 1) {
20
+ const current = [i];
21
+ for (let j = 1; j <= command.length; j += 1) {
22
+ current[j] = Math.min(current[j - 1] + 1, previous[j] + 1, previous[j - 1] + Number(input[i - 1] !== command[j - 1]));
23
+ }
24
+ previous = current;
25
+ }
26
+ return previous[command.length];
27
+ }
package/src/commands.mjs CHANGED
@@ -7,6 +7,7 @@ import { portOf, proxyEnv, readConfig, writeConfig } from './config.mjs';
7
7
  import { checkRunningPid, dashboardLink, healthy, portInUse, PROXY_API, proxyApi, runningPid, start, status, stop } from './proxy-process.mjs';
8
8
  import { HOOK_COMMAND, hookState, setHook } from './claude-code.mjs';
9
9
  import { askSecret, confirm, interactive } from './prompt.mjs';
10
+ import { maybeStarPrompt } from './star.mjs';
10
11
 
11
12
  const say = (line = '') => console.log(line);
12
13
  const CLOUD_URL = 'https://app.raytracer.si';
@@ -65,10 +66,11 @@ export async function setup(flags) {
65
66
 
66
67
  // A proxy this CLI started is restarted so the new settings apply.
67
68
  const port = portOf(readConfig());
68
- if (runningPid()) { await stop(); say('\nRestarting RayTrace with the new settings.'); await startCommand(); return; }
69
- if (await healthy(port)) { say(`\nA RayTrace proxy started outside this CLI is answering on :${port}; stop it to use these settings.`); return; }
70
- if (flags['no-start'] || (!yes && !(await confirm('\nStart RayTrace now?', true)))) { say('\nRun `raytrace start` when you are ready.'); return; }
71
- await startCommand({ open: !yes });
69
+ if (runningPid()) { await stop(); say('\nRestarting RayTrace with the new settings.'); await startCommand(); }
70
+ else if (await healthy(port)) say(`\nA RayTrace proxy started outside this CLI is answering on :${port}; stop it to use these settings.`);
71
+ else if (flags['no-start'] || (!yes && !(await confirm('\nStart RayTrace now?', true)))) say('\nRun `raytrace start` when you are ready.');
72
+ else await startCommand({ open: !yes });
73
+ maybeStarPrompt(flags);
72
74
  }
73
75
 
74
76
  // --------------------------------------------------------- start / stop / status
package/src/star.mjs ADDED
@@ -0,0 +1,61 @@
1
+ // One line after the first successful `raytrace setup`. It never asks a
2
+ // question or opens a browser. A file in the RayTrace home (next to
3
+ // config.env) remembers that this machine already saw it. A run that is not
4
+ // a person at a terminal does not print it and does not write that file, so
5
+ // the next real setup still can.
6
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { paths } from './paths.mjs';
9
+
10
+ export const STAR_URL = 'https://github.com/Godcreatebugs/raytrace-cli';
11
+ export const STAR_LINE = `If RayTrace is useful to you, a star on the repo helps other developers find it: ${STAR_URL}`;
12
+ const FLAG = 'star-prompted';
13
+
14
+ function optedOut(env) {
15
+ const value = env.RAYTRACE_NO_STAR_PROMPT;
16
+ return value === '1' || value === 'true';
17
+ }
18
+
19
+ // Any non-empty CI value counts, including "false": the variable being set is
20
+ // the signal that this run is not a person sitting at the setup output.
21
+ function ciSet(env) {
22
+ return typeof env.CI === 'string' && env.CI !== '';
23
+ }
24
+
25
+ function machineReadable(flags) {
26
+ if (!flags) return false;
27
+ if (flags.json || flags.quiet || flags.silent) return true;
28
+ return String(flags.format || '').toLowerCase() === 'json';
29
+ }
30
+
31
+ function suppressed(flags, env, stdout, stdin) {
32
+ if (optedOut(env)) return true;
33
+ if (ciSet(env)) return true;
34
+ if (!stdout?.isTTY || !stdin?.isTTY) return true;
35
+ return machineReadable(flags);
36
+ }
37
+
38
+ /**
39
+ * Print the star line when this machine has not seen it and this run is an
40
+ * interactive terminal. Returns whether it printed. `deps` is for tests.
41
+ */
42
+ export function maybeStarPrompt(flags = {}, deps = {}) {
43
+ const env = deps.env ?? process.env;
44
+ const stdout = deps.stdout ?? process.stdout;
45
+ const stdin = deps.stdin ?? process.stdin;
46
+ const log = deps.log ?? ((line) => console.log(line));
47
+ const home = deps.home ?? paths.home;
48
+ if (suppressed(flags, env, stdout, stdin)) return false;
49
+ const flag = join(home, FLAG);
50
+ if (existsSync(flag)) return false;
51
+ try {
52
+ mkdirSync(home, { recursive: true });
53
+ writeFileSync(flag, '1\n', { flag: 'wx' });
54
+ } catch {
55
+ // Setup must not fail, or ask again on every run, because the flag could
56
+ // not be saved. Skip the line instead.
57
+ return false;
58
+ }
59
+ log(STAR_LINE);
60
+ return true;
61
+ }