@commonlyai/cli 0.1.387 → 0.1.389

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.387",
3
+ "version": "0.1.389",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -95,6 +95,7 @@ import { closeHeldPaths, openHeldPath } from '../sandbox/bind-fd.js';
95
95
  import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from '../sandbox/mode.js';
96
96
  import { UNSANDBOXED_FLAG } from '../sandbox/host-check.js';
97
97
  import {
98
+ HOST_READ_DOT_ALLOW,
98
99
  publicClaudeStateRoot,
99
100
  resolveHostReadDirectories,
100
101
  wrapArgvWithSeatbelt,
@@ -1722,7 +1723,17 @@ const prepareArgv = async (innerArgv, ctx) => {
1722
1723
  innerArgv = [
1723
1724
  ...innerArgv,
1724
1725
  ...buildPublicClaudePolicyArgs(allowedPatterns, workspaceBwrapSandbox
1725
- ? { trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }
1726
+ ? {
1727
+ trust: sandboxTrust,
1728
+ allow: grants,
1729
+ memoryWithheld: ctx.memoryWithheld === true,
1730
+ ownerWoken: ctx.ownerWoken,
1731
+ // F493: the folders bwrap binds for this seat, checked the same way
1732
+ // wrapArgvWithBwrap checks them, so its Read tool can reach them.
1733
+ hostReads: resolveHostReadDirectories(workspaceReadOutside(env), homedir(), {
1734
+ fold: false, only: HOST_READ_DOT_ALLOW,
1735
+ }),
1736
+ }
1726
1737
  : { memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }),
1727
1738
  ...(ctx.publicSkillArgs || []),
1728
1739
  ];
@@ -476,10 +476,8 @@ export default {
476
476
  const available = (ctx._detectBwrap || detectBwrap)();
477
477
  if (!available.available) throw new Error(`goose adapter: bwrap unavailable: ${available.error}`);
478
478
  [executable, ...spawnArgs] = (ctx._wrapArgvWithBwrap || wrapArgvWithBwrap)([binary, ...args], {
479
- ...ctx.environment, sandbox: { ...sandbox, filesystem: {
480
- ...(sandbox.filesystem || {}), 'write-outside': [home],
481
- } },
482
- }, { workspacePath: turnWorkspace, homePath: home,
479
+ ...ctx.environment, sandbox,
480
+ }, { workspacePath: turnWorkspace, homePath: home, homeWritablePaths: [home],
483
481
  readOnlyPaths: [tempDir, binary, process.execPath, ...mcpReadDirectories] });
484
482
  } else {
485
483
  if ((ctx._platform || process.platform) !== 'darwin') throw new Error('goose adapter: Seatbelt requires macOS');
@@ -1686,17 +1686,12 @@ export default {
1686
1686
  sandbox: {
1687
1687
  ...sandbox,
1688
1688
  network: { ...sandbox?.network, policy: 'restricted' },
1689
- filesystem: {
1690
- ...(sandbox?.filesystem || {}),
1691
- 'write-outside': [
1692
- ...(Array.isArray(sandbox?.filesystem?.['write-outside'])
1693
- ? sandbox.filesystem['write-outside'] : []),
1694
- openCodeHome.root,
1695
- ],
1696
- },
1697
1689
  },
1698
1690
  }, {
1699
1691
  workspacePath: ctx.cwd,
1692
+ // Its own home, bound writable through opts: the spec's lists are
1693
+ // the server's, and a public seat's are refused (F493).
1694
+ homeWritablePaths: [openCodeHome.root],
1700
1695
  readOnlyPaths: [
1701
1696
  tempDir,
1702
1697
  binary,
@@ -456,17 +456,11 @@ export default {
456
456
  if (!bwrap.available) throw new Error(`public Qwen seats require bwrap: ${bwrap.error}`);
457
457
  [cmd, ...spawnArgs] = (ctx._wrapArgvWithBwrap || wrapArgvWithBwrap)([bwrapEntry, ...args], {
458
458
  ...ctx.environment,
459
- sandbox: {
460
- ...sandbox,
461
- filesystem: {
462
- ...(sandbox?.filesystem || {}),
463
- 'write-outside': [
464
- ...(sandbox?.filesystem?.['write-outside'] || []), home,
465
- ],
466
- },
467
- },
459
+ sandbox,
468
460
  }, {
469
461
  workspacePath: ctx.cwd,
462
+ // Its own home, bound writable through opts (F493).
463
+ homeWritablePaths: [home],
470
464
  homePath: home,
471
465
  readOnlyPaths: [tempDir, bwrapEntry, packageDir, process.execPath, ...mcpReadDirectories].filter(Boolean),
472
466
  });
@@ -18,6 +18,9 @@ import { existsSync, readFileSync } from 'fs';
18
18
  import { isAbsolute, join } from 'path';
19
19
  import { homedir } from 'os';
20
20
 
21
+ import { effectiveSandboxTrust } from '../environment.js';
22
+ import { HOST_READ_DOT_ALLOW, resolveHostReadDirectories } from './seatbelt.js';
23
+
21
24
  // Tilde-expansion lives here (and not in environment.js's expandHome) because
22
25
  // bwrap reads OS-level paths verbatim — `~` is a shell construct, not a
23
26
  // kernel one, so any `~/foo` entry in `read-outside` / `write-outside` would
@@ -282,20 +285,51 @@ export const wrapArgvWithBwrap = (innerArgv, env, opts = {}) => {
282
285
  '--tmpfs', '/tmp',
283
286
  ];
284
287
 
285
- const userReadOutside = Array.isArray(env?.sandbox?.filesystem?.['read-outside'])
286
- ? env.sandbox.filesystem['read-outside'].map(expandHome)
287
- : [];
288
+ // F493: the spec's binds are the server's to write, so a confined seat's are
289
+ // held to what the jail can keep safe.
290
+ // - public: neither list. Strangers drive the seat; an adapter's own
291
+ // folders come through opts (writablePaths), never the spec.
292
+ // - workspace: read-outside only inside HOST_READ_DOT_ALLOW (bwrap cannot
293
+ // hide the .env files beneath a wider bind, as Seatbelt's denies do),
294
+ // resolved once and bound at the resolved path; write-outside refused, as
295
+ // on macOS (a writable project lets a seat plant a git hook the host runs).
296
+ // - none (a seat of your own): as declared. It is not confined, and names
297
+ // folders such as ~/.local/bin on purpose.
298
+ const trust = effectiveSandboxTrust(env?.sandbox?.trust);
299
+ const declaredBinds = (key) => (Array.isArray(env?.sandbox?.filesystem?.[key])
300
+ ? env.sandbox.filesystem[key].map(expandHome) : []);
301
+ for (const key of ['read-outside', 'write-outside']) {
302
+ if (trust === 'public' && declaredBinds(key).length) {
303
+ throw new Error(`refusing sandbox.filesystem.${key}: a public seat binds nothing outside its own folders`);
304
+ }
305
+ }
306
+ if (trust === 'workspace' && declaredBinds('write-outside').length) {
307
+ throw new Error('refusing sandbox.filesystem.write-outside: a workspace seat writes only its project, '
308
+ + 'as on macOS');
309
+ }
310
+ const userReadOutside = trust === 'workspace'
311
+ ? resolveHostReadDirectories(declaredBinds('read-outside'), opts.hostReadHome || homedir(), {
312
+ fold: false, only: HOST_READ_DOT_ALLOW,
313
+ })
314
+ : declaredBinds('read-outside');
288
315
  const roBinds = [...new Set([...DEFAULT_RO_BINDS, ...userReadOutside])];
289
316
  for (const p of roBinds) {
290
317
  flags.push('--ro-bind-try', p, p);
291
318
  }
292
319
 
293
- const userWriteOutside = Array.isArray(env?.sandbox?.filesystem?.['write-outside'])
294
- ? env.sandbox.filesystem['write-outside'].map(expandHome)
295
- : [];
320
+ const userWriteOutside = declaredBinds('write-outside');
296
321
  for (const p of userWriteOutside) {
297
322
  flags.push('--bind-try', p, p);
298
323
  }
324
+ // A public adapter's own home (F493: it used to ride in the spec's
325
+ // write-outside). bwrap stacks later binds on top, so it binds here, before
326
+ // the read-only inputs below: an input inside the home stays read-only.
327
+ for (const p of opts.homeWritablePaths || []) {
328
+ if (!p || !isAbsolute(p)) {
329
+ throw new Error('wrapArgvWithBwrap opts.homeWritablePaths entries must be absolute paths');
330
+ }
331
+ flags.push('--bind-try', p, p);
332
+ }
299
333
 
300
334
  // Adapter-owned transient inputs (for example Claude's per-spawn MCP
301
335
  // config) live outside the workspace so model-visible Read(./**) cannot
@@ -63,6 +63,12 @@ const PLATFORM_BASELINE = String.raw`
63
63
  (subpath "/private/var/db"))
64
64
  (allow file-read* file-test-existence
65
65
  (subpath "/System/Volumes/Preboot/Cryptexes/OS"))
66
+ ; The active developer tools, read-only. /usr/bin/git and the other /usr/bin
67
+ ; developer commands are xcrun shims: they read the xcode-select link, then run
68
+ ; the tool from the Command Line Tools, and git reads its own defaults there.
69
+ (allow file-read* file-test-existence
70
+ (literal "/private/var/select/developer_dir")
71
+ (subpath "/Library/Developer/CommandLineTools"))
66
72
 
67
73
  (allow file-map-executable
68
74
  (subpath "/Library/Apple/System/Library/Frameworks")
@@ -346,10 +352,24 @@ export const parseSeatbeltReadRoots = (profile) => {
346
352
  literals: Object.freeze([...literals]),
347
353
  });
348
354
  };
349
- let systemReadRoots = null;
350
- export const seatbeltSystemReadRoots = () => {
351
- if (!systemReadRoots) systemReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
352
- return systemReadRoots;
355
+ // Only the static baseline is cached. The developer folder is resolved on
356
+ // every call, as each profile resolves it, so a key-file check never trusts a
357
+ // selection the next profile no longer has (CodeRabbit on #4205). The same
358
+ // selection returns the same object.
359
+ let baselineReadRoots = null;
360
+ const rootsByDeveloperRules = new Map();
361
+ export const seatbeltSystemReadRoots = ({ developerDirs = resolveDeveloperDirs() } = {}) => {
362
+ if (!baselineReadRoots) baselineReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
363
+ const rules = developerDirsRules(developerDirs);
364
+ if (!rules) return baselineReadRoots;
365
+ if (!rootsByDeveloperRules.has(rules)) {
366
+ const extra = parseSeatbeltReadRoots(rules);
367
+ rootsByDeveloperRules.set(rules, Object.freeze({
368
+ subpaths: Object.freeze([...new Set([...baselineReadRoots.subpaths, ...extra.subpaths])]),
369
+ literals: Object.freeze([...new Set([...baselineReadRoots.literals, ...extra.literals])]),
370
+ }));
371
+ }
372
+ return rootsByDeveloperRules.get(rules);
353
373
  };
354
374
 
355
375
  // Both network modes. On macOS, c-ares (node's dns.Resolver and dns.resolve*)
@@ -411,6 +431,36 @@ const isSymlink = (path) => {
411
431
  }
412
432
  };
413
433
 
434
+ // The two xcode-select links. The xcrun shim reads developer_dir; both name
435
+ // the same folder on a normal install, and a turn admits each target.
436
+ const XCODE_SELECT_LINKS = Object.freeze(['/private/var/select/developer_dir', '/private/var/db/xcode_select_link']);
437
+ const COMMAND_LINE_TOOLS = '/Library/Developer/CommandLineTools';
438
+
439
+ /**
440
+ * The read-only rule for a developer folder xcode-select points at, when that
441
+ * isn't the Command Line Tools the baseline already admits. /usr/bin/git is an
442
+ * xcrun shim that runs git from that folder. Only a developer folder's shape
443
+ * is admitted: an Xcode bundle's Contents/Developer, or a folder under
444
+ * /Library/Developer. Anything else (/, a home folder, a link that did not
445
+ * resolve, a path holding a quote, backslash, `;` or line break) gets no
446
+ * rule, and git there fails closed. A `;` starts a comment to
447
+ * parseSeatbeltReadRoots, so such a path would drop out of the key-file roots.
448
+ */
449
+ export function developerDirRules(activeDeveloperDir) {
450
+ const dir = String(activeDeveloperDir || '');
451
+ if (!isAbsolute(dir) || XCODE_SELECT_LINKS.includes(dir) || /["\\;\r\n]/.test(dir)) return '';
452
+ if (dir === COMMAND_LINE_TOOLS || dir.startsWith(`${COMMAND_LINE_TOOLS}/`)) return '';
453
+ if (!dir.endsWith('.app/Contents/Developer') && !dir.startsWith('/Library/Developer/')) return '';
454
+ return [
455
+ `(allow file-read* file-test-existence ${subpath(dir)})`,
456
+ `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(dir)}"))`,
457
+ ].join('\n');
458
+ }
459
+
460
+ // What the links point at now; read once per profile and once per root check.
461
+ const resolveDeveloperDirs = () => [...new Set(XCODE_SELECT_LINKS.map(realpathOrSelf))];
462
+ const developerDirsRules = (dirs) => dirs.map(developerDirRules).filter(Boolean).join('\n');
463
+
414
464
  // A folder this profile lets the jail write is one the jail can also replace:
415
465
  // a write rule on a folder covers the folder's own name, so a process from an
416
466
  // earlier turn can move it aside and leave a link there. The profile grants
@@ -521,8 +571,11 @@ const canonicalPath = (path) => {
521
571
  }
522
572
  };
523
573
 
574
+ // Case is folded where the filesystem ignores it (macOS); on Linux the names
575
+ // are compared as they are, so `/VAR/LOG` is not taken for `/var/log`.
576
+ let foldCase = (p) => p.toLowerCase();
524
577
  const foldedWithin = (outer, inner) => {
525
- const rel = relative(outer.toLowerCase(), inner.toLowerCase());
578
+ const rel = relative(foldCase(outer), foldCase(inner));
526
579
  return rel === '' || (rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel));
527
580
  };
528
581
 
@@ -532,7 +585,7 @@ const foldedWithin = (outer, inner) => {
532
585
  const dotComponent = (canonical, home) => {
533
586
  if (HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
534
587
  const allowed = HOST_READ_DOT_ALLOW.find((a) => foldedWithin(join(home, a), canonical));
535
- const below = relative(join(home, allowed).toLowerCase(), canonical.toLowerCase());
588
+ const below = relative(foldCase(join(home, allowed)), foldCase(canonical));
536
589
  return below.split('/').find((name) => name.startsWith('.')) || null;
537
590
  }
538
591
  return canonical.split('/').find((name) => name.startsWith('.')) || null;
@@ -550,9 +603,9 @@ const hostReadRefusal = (canonical, home) => {
550
603
  ? null
551
604
  : `outside your home folder only ${HOST_READ_SYSTEM_ALLOW.join(', ')} are readable from a seat`;
552
605
  }
553
- const rel = relative(home.toLowerCase(), canonical.toLowerCase());
606
+ const rel = relative(foldCase(home), foldCase(canonical));
554
607
  const [first] = rel.split('/');
555
- if (first === 'library') return '~/Library holds keychains and app data';
608
+ if (foldCase(first) === 'library') return '~/Library holds keychains and app data';
556
609
  if (first.startsWith('.')
557
610
  && !HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
558
611
  return `the folders under ~/${first.split('/')[0]} are not readable from a seat `
@@ -562,18 +615,33 @@ const hostReadRefusal = (canonical, home) => {
562
615
  };
563
616
 
564
617
  // Each entry resolved once, refused on the first that fails, in the order given.
565
- export const resolveHostReadDirectories = (entries, home = homedir()) => {
566
- const canonicalHome = canonicalPath(home);
567
- return entries.map((entry) => {
568
- const canonical = canonicalPath(entry);
569
- const reason = hostReadRefusal(canonical, canonicalHome);
570
- if (reason) {
571
- throw new Error(`refusing sandbox.filesystem.read-outside ${entry}: ${reason}.`);
572
- }
573
- return canonical;
574
- });
618
+ // - fold: compare case-insensitively (macOS; default). Linux passes false.
619
+ // - only: folders under home the entry must also sit inside. bwrap cannot
620
+ // hide a credential file beneath a folder it binds, as Seatbelt's pattern
621
+ // denies do, so Linux admits only HOST_READ_DOT_ALLOW (F493 review).
622
+ export const resolveHostReadDirectories = (entries, home = homedir(), { fold = true, only = null } = {}) => {
623
+ const previousFold = foldCase;
624
+ foldCase = fold ? (p) => p.toLowerCase() : (p) => p;
625
+ try {
626
+ const canonicalHome = canonicalPath(home);
627
+ return entries.map((entry) => {
628
+ const canonical = canonicalPath(entry);
629
+ let reason = hostReadRefusal(canonical, canonicalHome);
630
+ if (!reason && only && !only.some((allowed) => foldedWithin(join(canonicalHome, allowed), canonical))) {
631
+ reason = `here only ${only.map((a) => `~/${a}`).join(', ')} can be named, because this sandbox `
632
+ + 'cannot hide the credential files beneath a folder it binds';
633
+ }
634
+ if (reason) {
635
+ throw new Error(`refusing sandbox.filesystem.read-outside ${entry}: ${reason}.`);
636
+ }
637
+ return canonical;
638
+ });
639
+ } finally {
640
+ foldCase = previousFold;
641
+ }
575
642
  };
576
643
 
644
+
577
645
  export const buildSeatbeltProfile = ({
578
646
  workspacePath,
579
647
  workspaceAccess = 'write',
@@ -605,6 +673,9 @@ export const buildSeatbeltProfile = ({
605
673
  // a seat credential in memory, as a public pi does. Signals are not narrowed:
606
674
  // a parent must still stop the children it started.
607
675
  processInfo = 'same-sandbox',
676
+ // The developer folders xcode-select points at. Resolved on each profile by
677
+ // default; tests pass their own.
678
+ developerDirs = resolveDeveloperDirs(),
608
679
  // Pin a writable workspace to its own name (see pinnedRealpath). Set it for
609
680
  // a public seat. Its workspace is usually the scratch folder the CLI made;
610
681
  // when it is an `environment.workspace.path` the operator gave and that path
@@ -758,6 +829,7 @@ export const buildSeatbeltProfile = ({
758
829
 
759
830
  return [
760
831
  `${PLATFORM_BASELINE}${RESOLVER_CONFIG}${network === 'open' ? OPEN_NETWORK : ''}`.trim(),
832
+ developerDirsRules(developerDirs),
761
833
  executableRules,
762
834
  executableSymlinkRules,
763
835
  `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(resolvedWorkspace)}"))`,