@raytrace-cli/cli 0.16.0 → 0.17.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/bin/raytrace.mjs CHANGED
@@ -48,6 +48,11 @@ Local sandboxes (your project stays on this machine):
48
48
  raytrace sandbox destroy <name> [--delete-logs | --keep-logs]
49
49
  asks whether to delete its captured logs too;
50
50
  kept logs move to ~/.raytrace/archive
51
+ raytrace sandbox files <name> show the files the agent may not change (Restrict)
52
+ and the files whose every read is recorded (Report)
53
+ raytrace sandbox files <name> --restrict <path> | --report <path> | --clear <path>
54
+ change them; paths are from the project's root,
55
+ and each option can be repeated
51
56
  Recorded commands, files and connections: raytrace open, then Sandbox evidence.
52
57
  macOS and Linux; Windows is experimental. raytrace doctor shows what is missing.
53
58
 
@@ -170,6 +175,9 @@ if (command === 'sandbox') {
170
175
  'delete-logs': { type: 'boolean' },
171
176
  'keep-logs': { type: 'boolean' },
172
177
  'keep-traces': { type: 'boolean' },
178
+ restrict: { type: 'string', multiple: true },
179
+ report: { type: 'string', multiple: true },
180
+ clear: { type: 'string', multiple: true },
173
181
  } });
174
182
  } catch (error) { console.error(`${error.message}\n\nRun \`raytrace help\` for usage.`); process.exit(2); }
175
183
  const [sub, id] = parsed.positionals;
@@ -180,6 +188,7 @@ if (command === 'sandbox') {
180
188
  start: () => sandbox.start(id, parsed.values),
181
189
  stop: () => sandbox.stop(id, parsed.values),
182
190
  destroy: () => sandbox.destroy(id, parsed.values),
191
+ files: () => sandbox.files(id, parsed.values),
183
192
  }[sub];
184
193
  if (!action) { console.error(`Unknown sandbox command: ${sub ?? '(none)'}\n\n${HELP}`); process.exit(2); }
185
194
  try { await action(); process.exit(0); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytrace-cli/cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.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
  "repository": {
@@ -460,7 +460,8 @@ const server = createServer(async (req, res) => {
460
460
  return json(200, { id: box.id, name: box.name, ...(await sandboxes.activity(box.id, window)) });
461
461
  } catch { return json(503, { error: NO_VM }); }
462
462
  }
463
- // The initial scan, restricted files and alerts are not kept for local sandboxes yet.
463
+ // The initial scan and alerts are not kept for local sandboxes yet. Their restricted and
464
+ // reported files are set from the CLI: raytrace sandbox files <name> (src/local-sandbox.mjs).
464
465
  if (/^\/raytace\/(sandboxes\/rtp-[a-f0-9]{32}(\/files)?|alerts(\?sandbox=rtp-[a-f0-9]{32})?|alerts\/seen)$/.test(req.url ?? '')) {
465
466
  if (req.method === 'GET' && req.url.startsWith('/raytace/alerts')) return json(200, { alerts: [] });
466
467
  return json(404, { error: 'Not available for local sandboxes yet. Destroy one with: raytrace sandbox destroy <name>' });
@@ -260,6 +260,51 @@ export async function start(id) {
260
260
  say(`${registry()[id].name} running`);
261
261
  }
262
262
 
263
+ /** A path as the lists keep it: from the project's root, with no ./ or trailing slash. */
264
+ const listPath = (path) => String(path).trim().replace(/^(\.\/)+/, '').replace(/\/+$/, '');
265
+
266
+ /**
267
+ * The two lists after a change. A file is on one list at most: restricting a
268
+ * reported file moves it, and the other way round. `clear` takes it off both.
269
+ */
270
+ export function changedLists(current, { restrict = [], report = [], clear = [] } = {}) {
271
+ const [toRestrict, toReport, toClear] = [restrict, report, clear].map((paths) => paths.map(listPath).filter(Boolean));
272
+ const both = toRestrict.filter((path) => toReport.includes(path));
273
+ if (both.length) throw new Error(`${both[0]} is given to both --restrict and --report; pick one.`);
274
+ const gone = new Set([...toClear, ...toRestrict, ...toReport]);
275
+ const keep = (list) => (list ?? []).filter((path) => !gone.has(path));
276
+ const unique = (list) => [...new Set(list)].sort();
277
+ return { restricted: unique([...keep(current.restricted), ...toRestrict]), watched: unique([...keep(current.watched), ...toReport]) };
278
+ }
279
+
280
+ /**
281
+ * Shows or changes a local sandbox's two file lists.
282
+ * Restrict: the agent's file tools are refused at once, and the file is locked
283
+ * read-only for every program from the sandbox's next start.
284
+ * Report: every read and change of the file is recorded as its own line.
285
+ */
286
+ export async function files(ref, change = {}) {
287
+ const id = pickId(ref);
288
+ ensureVm();
289
+ const { name } = registry()[id];
290
+ const read = (args, options) => JSON.parse(projects(args, options).stdout);
291
+ let lists = read(['guardrails', id]);
292
+ const changing = ['restrict', 'report', 'clear'].some((key) => change[key]?.length);
293
+ if (changing) {
294
+ const wanted = changedLists(lists, change);
295
+ lists = read(['set-guardrails', id], { input: JSON.stringify(wanted) });
296
+ }
297
+ const show = (title, list, none) => say(`${title}\n${list.length ? list.map((path) => ` ${path}${lists.missing.includes(path) ? ' (no such file in the sandbox yet)' : ''}`).join('\n') : ` ${none}`}`);
298
+ say(`${name}${changing ? ': lists updated' : ''}\n`);
299
+ show('Restrict (the agent cannot change these):', lists.restricted, 'none');
300
+ show('\nReport (every read and change is recorded):', lists.watched, 'none');
301
+ const unlocked = lists.restricted.filter((path) => !lists.read_only.includes(path) && !lists.missing.includes(path));
302
+ if (unlocked.length) {
303
+ say(`\nNot locked yet: ${unlocked.join(', ')}\nThe agent's file tools are refused now. To lock ${unlocked.length === 1 ? 'it' : 'them'} against every program: raytrace sandbox stop ${name} && raytrace sandbox start ${name}`);
304
+ }
305
+ if (!changing) say(`\nChange them: raytrace sandbox files ${name} --restrict <path> | --report <path> | --clear <path>`);
306
+ }
307
+
263
308
  export async function stop(id) {
264
309
  id = pickId(id);
265
310
  if (vmStatus() === 'Running') projects(['stop', id]);
package/src/sandbox.mjs CHANGED
@@ -221,6 +221,13 @@ export async function stop(id, flags = {}) {
221
221
  const box = await call('POST', `/v1/sandboxes/${await pickId(id)}/stop`); say(`${box.id} stopped; its files are kept`);
222
222
  }
223
223
 
224
+ export async function files(id, flags = {}) {
225
+ if (id && !flags.local && !local.isLocal(id)) {
226
+ throw new Error('File lists are set here for local sandboxes only. For a cloud sandbox, use Initial scan in the dashboard.');
227
+ }
228
+ return local.files(id, flags);
229
+ }
230
+
224
231
  export async function destroy(id, flags) {
225
232
  if (flags.local || local.isLocal(id)) return local.destroy(id, flags, { ask, interactive });
226
233
  id = await pickId(id);
@@ -138,7 +138,8 @@ if (input.hook_event_name === 'PreToolUse') {
138
138
  queue({ kind: 'blocked', path });
139
139
  process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny',
140
140
  permissionDecisionReason: `RayTrace: ${path} is restricted by this project's owner and cannot be changed. `
141
- + 'Do not try another way to write it; tell the user it has to be unlocked under Initial scan in the RayTrace dashboard.' } }));
141
+ + 'Do not try another way to write it; tell the user it has to be unlocked: under Initial scan in the RayTrace dashboard, '
142
+ + `or for a local sandbox with \`raytrace sandbox files <name> --clear ${path}\`.` } }));
142
143
  }
143
144
  process.exit(0);
144
145
  }
@@ -187,6 +187,24 @@ def lock(root, path, on):
187
187
  finally:
188
188
  os.close(at)
189
189
 
190
+ def present(root, path):
191
+ """Whether a project path is a regular file, without following a link at any step."""
192
+ try:
193
+ at = os.open(root, os.O_RDONLY | os.O_DIRECTORY)
194
+ except OSError:
195
+ return False
196
+ try:
197
+ parts = PurePosixPath(path).parts
198
+ for part in parts[:-1]:
199
+ below = os.open(part, os.O_RDONLY | os.O_NOFOLLOW | os.O_DIRECTORY, dir_fd=at)
200
+ os.close(at)
201
+ at = below
202
+ return bool(parts) and stat.S_ISREG(os.stat(parts[-1], dir_fd=at, follow_symlinks=False).st_mode)
203
+ except OSError:
204
+ return False
205
+ finally:
206
+ os.close(at)
207
+
190
208
  def guardrails(sid, state, restricted=None, watched=None, blocked=None):
191
209
  """Applies a sandbox's restricted files: the new list, or the stored one
192
210
  again. The Claude Code hook gets the list at once and refuses the edit
@@ -197,7 +215,8 @@ def guardrails(sid, state, restricted=None, watched=None, blocked=None):
197
215
  owner wants to hear of a read or a change: the hook reports an attempt on
198
216
  them and nothing is locked. `blocked` are the programs the hook refuses
199
217
  to start (None keeps the stored list). Returns {hook: the hook has the
200
- list, read_only: the files locked}."""
218
+ list, read_only: the files locked, restricted and watched: the lists as
219
+ they now are, missing: listed paths that are not a file in the project}."""
201
220
  GUARDRAILS.mkdir(parents=True, exist_ok=True, mode=0o700)
202
221
  stored = GUARDRAILS / (sid+'.json')
203
222
  kept = json.loads(stored.read_text()) if stored.exists() else {}
@@ -217,7 +236,8 @@ def guardrails(sid, state, restricted=None, watched=None, blocked=None):
217
236
  stored.write_text(lists)
218
237
  if running and (restricted or before or watched or kept.get('watched') or blocked or kept.get('blocked')):
219
238
  write_as_root(sid, GUARDRAILS_IN_SANDBOX, lists.encode())
220
- return {'hook': bool(running), 'read_only': read_only}
239
+ return {'hook': bool(running), 'read_only': read_only, 'restricted': restricted, 'watched': watched,
240
+ 'missing': [path for path in [*restricted, *watched] if not present(root, path)]}
221
241
 
222
242
  def as_node(container, *command, data=None, check=True):
223
243
  """Runs a command in a sandbox as its agent user, never root."""