@raytrace-cli/cli 0.17.15 → 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/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.15",
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
+ }