@beatos/bridge-runner 0.8.1 → 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.
package/dist/safety.js CHANGED
@@ -296,6 +296,85 @@ export function claudeArgs(i) {
296
296
  argv.push("--", i.prompt); // --add-dir and --mcp-config take many values and would eat the prompt
297
297
  return argv;
298
298
  }
299
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
300
+ const CHAT_MODEL_RE = /^[A-Za-z0-9._-]{1,64}$/;
301
+ /** The only tools of a read-only chat session (BEA-107). */
302
+ export const READ_TOOLS = "Read,Grep,Glob";
303
+ /**
304
+ * On Windows a file or folder also opens by its 8.3 short name
305
+ * (C:/Users/me/DOCUME~1 for Documents, ENV~1 for .env). A deny rule sees the
306
+ * path as it was written, so every rule by long name could be passed that
307
+ * way. Checked on Claude Code 2.1.319 with a real read session: it read a
308
+ * walled folder by BEATOS~2/SPIKE-~3 and its own .env as ENV~1; with these
309
+ * rules both are denied. A short name always has "~" and a digit, so every
310
+ * such name is denied on the drives given (one rule set per drive letter). A
311
+ * real long name with "~1" in it is refused too: the safe side.
312
+ */
313
+ export function shortNameRules(paths) {
314
+ const rules = [];
315
+ const seen = new Set();
316
+ for (const p of paths) {
317
+ const d = /^([A-Za-z]):/.exec(p);
318
+ if (!d)
319
+ continue;
320
+ const letter = d[1].toUpperCase();
321
+ if (seen.has(letter))
322
+ continue;
323
+ seen.add(letter);
324
+ for (const glob of ["**/*~[0-9]*", "**/*~[0-9]*/**"]) {
325
+ rules.push(`Read(${letter}:/${glob})`, `Read(//${letter.toLowerCase()}/${glob})`);
326
+ }
327
+ }
328
+ return rules;
329
+ }
330
+ /**
331
+ * More deny rules for every chat turn (read and work; task runs do not
332
+ * change): key and .env files anywhere under the session's root (the cwd can
333
+ * be below it, and the root can be outside ~/projects), other sessions'
334
+ * transcripts and the live registry, and every Windows short name on the
335
+ * root's drive and the home drive (shortNameRules). Work also gets Bash
336
+ * patterns for the transcripts and the registry.
337
+ */
338
+ export function chatDenyRules(root, access, home = homedir()) {
339
+ const rules = [];
340
+ for (const f of PROJECT_SECRET_FILES)
341
+ rules.push(...pathForms("Read", root, `**/${f}`));
342
+ for (const rel of [".claude/projects/**", ".claude/sessions/**"])
343
+ rules.push(...homeForms("Read", rel, home));
344
+ rules.push(...shortNameRules([root, home]));
345
+ if (access === "work")
346
+ rules.push("Bash(*.claude/projects*)", "Bash(*.claude\\projects*)", "Bash(*.claude/sessions*)", "Bash(*.claude\\sessions*)");
347
+ return rules;
348
+ }
349
+ /**
350
+ * argv for one chat turn of a Bridge session (BEA-107). The user's text goes
351
+ * by stdin, never argv. read: Read, Grep and Glob are the only tools there
352
+ * are, anything else is denied without asking. work: the same auto mode and
353
+ * deny rules as a task run. Never --dangerously-skip-permissions.
354
+ */
355
+ export function chatArgs(i) {
356
+ if (i.access !== "read" && i.access !== "work")
357
+ throw new Error("sessions are off");
358
+ if (!CHAT_MODEL_RE.test(i.model))
359
+ throw new Error("bad model name");
360
+ if (i.resumeSessionId !== undefined && !UUID_RE.test(i.resumeSessionId))
361
+ throw new Error("bad session id");
362
+ if (i.fork && !i.resumeSessionId)
363
+ throw new Error("a copy needs the session it copies");
364
+ const argv = ["-p", "--output-format", "stream-json", "--verbose", "--model", i.model];
365
+ if (i.resumeSessionId)
366
+ argv.push("--resume", i.resumeSessionId);
367
+ if (i.fork)
368
+ argv.push("--fork-session");
369
+ if (i.access === "read")
370
+ argv.push("--tools", READ_TOOLS, "--allowedTools", READ_TOOLS, "--permission-mode", "dontAsk");
371
+ else
372
+ argv.push("--permission-mode", "auto");
373
+ if (!i.settingsFile || i.settingsFile.trim().startsWith("{"))
374
+ throw new Error("chat settings go in a file");
375
+ argv.push("--settings", i.settingsFile, "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--no-chrome", "--append-system-prompt-file", i.rulesFile);
376
+ return argv;
377
+ }
299
378
  /**
300
379
  * argv for the short "comprension" session of a processed video (BEA-96
301
380
  * slice 8): the same CLI and login as a run, but Read is the only tool there