@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.
@@ -16,7 +16,7 @@ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync,
16
16
  import { basename, join } from 'node:path';
17
17
  import { paths } from './paths.mjs';
18
18
  import { portInUse, runningPid, start as startProxy, stop as stopProxy } from './proxy-process.mjs';
19
- import { readConfig } from './config.mjs';
19
+ import { portOf, readConfig } from './config.mjs';
20
20
  import { ensureToken } from '../proxy/local-token.mjs';
21
21
  import { viewerTokenFor } from '../proxy/request-policy.mjs';
22
22
  import { LIMA_VERSION, canDownload, checks, downloadLima, findLima } from './lima.mjs';
@@ -216,15 +216,27 @@ export async function create(name, { root, files, skipped, total, archive }) {
216
216
  say(`Open it: raytrace connect ${name}`);
217
217
  }
218
218
 
219
- export async function list() {
219
+ /** This machine's local sandboxes with their state: running, stopped, or
220
+ * missing (in the registry, gone from the VM). `vmRunning` says whether the
221
+ * states were read from the VM; when it is not running, all are stopped. */
222
+ export function localSandboxes() {
220
223
  const boxes = registry();
221
- if (!Object.keys(boxes).length) { say('No local sandboxes. Create one from a Git repository: raytrace sandbox create --local'); return; }
222
- const running = vmStatus() === 'Running';
224
+ if (!Object.keys(boxes).length) return { vmRunning: false, sandboxes: [] };
225
+ let running = false;
226
+ try { running = vmStatus() === 'Running'; } catch { /* no Lima: nothing can be running */ }
223
227
  const states = running ? Object.fromEntries(JSON.parse(projects(['list']).stdout || '[]').map((box) => [box.id, box.status])) : {};
224
- for (const [id, box] of Object.entries(boxes)) {
228
+ const sandboxes = Object.entries(boxes).map(([id, { token, ...box }]) => ({
229
+ id, ...box, status: running ? (states[id] === 'running' ? 'running' : states[id] ? 'stopped' : 'missing') : 'stopped',
230
+ }));
231
+ return { vmRunning: running, sandboxes };
232
+ }
233
+
234
+ export async function list() {
235
+ const { vmRunning: running, sandboxes } = localSandboxes();
236
+ if (!sandboxes.length) { say('No local sandboxes. Create one from a Git repository: raytrace sandbox create --local'); return; }
237
+ for (const box of sandboxes) {
225
238
  const age = Math.round((Date.now() - Date.parse(box.created)) / 60000);
226
- const status = running ? (states[id] === 'running' ? 'running' : states[id] ? 'stopped' : 'missing') : 'stopped';
227
- say(`${box.name.padEnd(20)} ${status.padEnd(8)} ${id} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old, local)`);
239
+ say(`${box.name.padEnd(20)} ${box.status.padEnd(8)} ${box.id} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old, local)`);
228
240
  }
229
241
  if (!running) say(`\nThe RayTrace VM is stopped; \`raytrace sandbox start <name>\` starts it.`);
230
242
  }
@@ -326,14 +338,20 @@ export async function destroy(ref, flags, { ask, interactive }) {
326
338
  if (deleteLogs && forks.length && runningPid()) { await stopProxy(); await startProxy(); }
327
339
  }
328
340
 
329
- /** A terminal in the sandbox, through the VM. Leaving it keeps the sandbox running. */
330
- export async function shell(id) {
341
+ /** A terminal in the sandbox, through the VM; with `claude`, Claude Code
342
+ * starts in it first. Leaving it keeps the sandbox running. */
343
+ /** The local dashboard's Prompts, only those that ran in this sandbox. */
344
+ export const promptsLink = (id) => `http://127.0.0.1:${portOf(readConfig())}/?box=${encodeURIComponent(id)}`;
345
+
346
+ export async function shell(id, { claude = false } = {}) {
331
347
  id = pickId(id);
332
348
  ensureVm();
333
349
  await ensureBridge();
334
350
  const { name } = registry()[id];
335
- say(`Connected to ${name}. Run \`claude\` (or codex) here; exit to leave. The sandbox keeps running.`);
351
+ say(claude ? `Connected to ${name}, 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.`
352
+ : `Connected to ${name}. Run \`claude\` (or codex) here; exit to leave. The sandbox keeps running.`);
353
+ say(`Its prompts, and only its: ${promptsLink(id)}`);
336
354
  say('Recorded commands, files and connections: raytrace open, then Sandbox evidence\n');
337
- projects(['shell', id], { inherit: true, check: false });
355
+ projects(['shell', id, ...(claude ? ['--claude'] : [])], { inherit: true, check: false });
338
356
  say(`\nLeft ${name}. It is still running. Back in: raytrace connect ${name} Stop it: raytrace sandbox stop ${name}`);
339
357
  }