@commonlyai/cli 0.1.333 → 0.1.334

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.333",
3
+ "version": "0.1.334",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -112,7 +112,7 @@ import { prepareCommitAttribution } from '../lib/commit-attribution.js';
112
112
  import { detectBwrap } from '../lib/sandbox/bwrap.js';
113
113
  import { resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
114
114
  import {
115
- CODEX_PRIVATE_LINUX_OPTED_IN_MESSAGE, UNSANDBOXED_FLAG, bwrapRefusedMessage, hostSandboxRefusal, windowsSandboxMessage,
115
+ CODEX_OPTED_IN_PUBLIC_POD_MESSAGE, UNSANDBOXED_FLAG, bwrapRefusedMessage, hostSandboxRefusal, windowsSandboxMessage,
116
116
  } from '../lib/sandbox/host-check.js';
117
117
  import {
118
118
  UNSANDBOXED_NOTICE, codexUnconfinedForRun, codexUnsandboxedNotice, hostReportFailureMessage, hostUnconfinedForRun,
@@ -2878,7 +2878,7 @@ export const performRun = ({
2878
2878
  hostUnconfined,
2879
2879
  optedIn: codexUnconfined,
2880
2880
  ...(detectBwrapImpl ? { detectBwrap: detectBwrapImpl } : {}),
2881
- }) || (codexUnconfined ? CODEX_PRIVATE_LINUX_OPTED_IN_MESSAGE : null));
2881
+ }) || (codexUnconfined ? CODEX_OPTED_IN_PUBLIC_POD_MESSAGE : null));
2882
2882
  if (turnRefusal && placement.readError) {
2883
2883
  throw Object.assign(
2884
2884
  new Error(`turn deferred, because its pods could not be read: ${placement.readError.message}`, {
@@ -5653,6 +5653,14 @@ Docs:
5653
5653
  console.error(`${stamp()} [${name}] ${hostRefusal}`);
5654
5654
  process.exit(1);
5655
5655
  }
5656
+ // F444: on Linux a private Codex seat has a sandbox, so a flag its pods
5657
+ // rule out leaves it there; say so rather than let the flag look applied.
5658
+ if (optedIn && record.adapter === 'codex' && process.platform === 'linux' && !codexUnconfined) {
5659
+ console.warn(`${stamp()} [${name}] ${UNSANDBOXED_FLAG} was not applied: ${
5660
+ effectiveSandboxTrust(record.environment?.sandbox?.trust) === 'workspace'
5661
+ ? 'this agent is set to workspace trust'
5662
+ : "a pod this agent answers in isn't confirmed private and invite-only"}, so it runs in Codex's own sandbox.`);
5663
+ }
5656
5664
  if (saved && record !== saved) saveAgentToken(name, record);
5657
5665
  if (bootstrapped) {
5658
5666
  // A named instance is saved under its seat key; an unnamed run keeps
@@ -46,7 +46,7 @@ import { meetsMinimumVersion, probeVersion, publicCodexVersionError } from './te
46
46
  import { spawn as childSpawn, spawnSync } from 'child_process';
47
47
  import { createHash } from 'crypto';
48
48
  import {
49
- accessSync, constants, existsSync, readFileSync, realpathSync, statSync,
49
+ accessSync, constants, existsSync, readFileSync, readdirSync, realpathSync, statSync,
50
50
  } from 'fs';
51
51
  import {
52
52
  chmod,
@@ -388,6 +388,16 @@ const publicCodexHomesRoot = (ctx) => {
388
388
  return root;
389
389
  };
390
390
 
391
+ // An XDG_STATE_HOME under ~/.commonly throws above, and that tree is denied anyway.
392
+ const privatePublicHomesDeny = (ctx) => {
393
+ if ((ctx._platform || process.platform) !== 'linux') return [];
394
+ try {
395
+ return [publicCodexHomesRoot(ctx)];
396
+ } catch {
397
+ return [];
398
+ }
399
+ };
400
+
391
401
  const operatorCodexHome = (ctx) => ctx.env?.CODEX_HOME
392
402
  || process.env.CODEX_HOME
393
403
  || join(homedir(), '.codex');
@@ -745,10 +755,12 @@ const publicPermissionProfileFlags = (
745
755
 
746
756
  // Host secrets a private seat's shell never reads. ~/.commonly holds every
747
757
  // seat's tokens and state; the seat's own workspace sits under it and is
748
- // admitted by the more specific workspace rule. gh keeps working: on macOS its
758
+ // admitted by the more specific workspace rule (on Linux too: measured on
759
+ // codex-cli 0.164.0, a write key inside a denied folder works there). The
760
+ // Codex home is privateCodexHomeDenies'. gh keeps working: on macOS its
749
761
  // login is in the keychain, which a credential the seat itself uses has to be.
750
762
  const PRIVATE_SECRET_DENIES = Object.freeze([
751
- '~/.commonly', '~/.claude', '~/.codex', '~/.ssh', '~/.aws', '~/.gnupg',
763
+ '~/.commonly', '~/.claude', '~/.ssh', '~/.aws', '~/.gnupg',
752
764
  '~/.kube', '~/.docker', '~/.netrc', '~/.config/gcloud',
753
765
  ]);
754
766
 
@@ -760,6 +772,63 @@ const realOrSelf = (path) => {
760
772
  }
761
773
  };
762
774
 
775
+ // F444: what the private profile denies of the Codex home the seat runs with.
776
+ // On macOS the home is denied whole. On Linux Codex execs its sandbox helper
777
+ // from `<home>/tmp/arg0-linux` inside bwrap, and a denied home stops every turn
778
+ // at start ("bwrap: execvp codex-linux-sandbox: Permission denied"; a read key
779
+ // for `tmp` under the denied home does not lift it). Measured with `codex
780
+ // sandbox` and a real turn on codex-cli 0.164.0, ubuntu-22.04. So there the
781
+ // home itself stays readable and everything in it is denied except the helper
782
+ // folder: each entry present now, and the names Codex writes later even while
783
+ // they are absent (a key for a missing path is accepted there). Codex's SQLite
784
+ // databases write a `-wal` file during the turn that holds their newest rows,
785
+ // other sessions' included, and SQLite removes it when the last connection
786
+ // closes; so every database name, listed or known, takes its `-wal`, `-shm`
787
+ // and `-journal` too. A database under a new name is listed, with those, from
788
+ // the next turn. No globs: Codex's `*` crosses `/`, and a glob that matched a
789
+ // file inside a folder already denied stopped every turn at start ("bwrap:
790
+ // Can't create file at …: Read-only file system", run 43103991434).
791
+ // `~/.codex` is denied whole when it isn't that home.
792
+ const CODEX_HOME_SECRET_NAMES = Object.freeze([
793
+ 'auth.json', 'config.toml', 'sessions', 'archived_sessions', 'history.jsonl', 'log',
794
+ 'session_index.jsonl', 'shell_snapshots', 'memories',
795
+ 'logs_2.sqlite', 'state_5.sqlite', 'goals_1.sqlite', 'queue_1.sqlite',
796
+ ]);
797
+ const SQLITE_SIDECARS = Object.freeze(['-wal', '-shm', '-journal']);
798
+ const CODEX_HELPER_PATH = Object.freeze(['tmp', 'arg0-linux']);
799
+
800
+ const entriesOf = (dir) => {
801
+ try {
802
+ return readdirSync(dir);
803
+ } catch {
804
+ return [];
805
+ }
806
+ };
807
+
808
+ export const privateCodexHomeDenies = ({ codexHome = null, platform = process.platform, home = homedir() } = {}) => {
809
+ const defaultHome = join(home, '.codex');
810
+ const runHome = codexHome ? realOrSelf(codexHome) : null;
811
+ const runsFromDefault = !runHome || runHome === realOrSelf(defaultHome);
812
+ if (platform !== 'linux') return runsFromDefault ? ['~/.codex'] : ['~/.codex', runHome];
813
+ const helperHome = runHome || realOrSelf(defaultHome);
814
+ const denies = runsFromDefault ? [] : ['~/.codex'];
815
+ // Deny every sibling of the helper path at each level, so only the path
816
+ // itself stays reachable.
817
+ let dir = helperHome;
818
+ for (const [depth, keep] of CODEX_HELPER_PATH.entries()) {
819
+ const names = new Set(entriesOf(dir));
820
+ if (depth === 0) {
821
+ CODEX_HOME_SECRET_NAMES.forEach((name) => names.add(name));
822
+ [...names].filter((name) => /\.(sqlite|db)$/.test(name))
823
+ .forEach((name) => SQLITE_SIDECARS.forEach((suffix) => names.add(`${name}${suffix}`)));
824
+ }
825
+ names.delete(keep);
826
+ denies.push(...[...names].sort().map((name) => join(dir, name)));
827
+ dir = join(dir, keep);
828
+ }
829
+ return denies;
830
+ };
831
+
763
832
  // What a commit writes, and nothing that runs code. Codex keeps a workspace's
764
833
  // `.git` read-only even inside a writable root, and only an explicit absolute
765
834
  // key opens it (measured with `codex sandbox` on 0.162.1: the same key inside
@@ -828,6 +897,9 @@ const privatePermissionProfileFlags = ({
828
897
  workspace = null,
829
898
  tempRoots = [],
830
899
  shellTempDir = null,
900
+ codexHome = null,
901
+ home = homedir(),
902
+ otherCodexHomes = [],
831
903
  } = {}) => {
832
904
  const { commitHooksPath, originalHookPaths } = commitHookReadPaths(commitAttributionEnv);
833
905
  const posix = platform !== 'win32';
@@ -845,7 +917,8 @@ const privatePermissionProfileFlags = ({
845
917
  // no drive and Codex would refuse the whole profile (as with /private/tmp
846
918
  // in publicPermissionProfileFlags).
847
919
  posix ? '"/"="read"' : '":minimal"="read"',
848
- ...PRIVATE_SECRET_DENIES.map((path) => `${toml(path)}="deny"`),
920
+ ...[...PRIVATE_SECRET_DENIES, ...privateCodexHomeDenies({ codexHome, platform, home }), ...otherCodexHomes]
921
+ .map((path) => `${toml(path)}="deny"`),
849
922
  ...deniedTemp.map((path) => `${toml(path)}="deny"`),
850
923
  ...(shellTemp ? [`${toml(shellTemp)}="write"`] : []),
851
924
  '":workspace_roots"={"."="write",".commonly/**"="deny",".codex/**"="deny"}',
@@ -994,6 +1067,9 @@ const buildArgs = ({
994
1067
  privateWorkspace = null,
995
1068
  tempRoots = [],
996
1069
  shellTempDir = null,
1070
+ privateCodexHome = null,
1071
+ privateHome = homedir(),
1072
+ privateOtherCodexHomes = [],
997
1073
  }) => {
998
1074
  const publicSandbox = publicSandboxMode !== null;
999
1075
  // F387: a private seat keeps the flag below only in a cloud-codex pod, or
@@ -1049,6 +1125,9 @@ const buildArgs = ({
1049
1125
  workspace: privateWorkspace,
1050
1126
  tempRoots,
1051
1127
  shellTempDir,
1128
+ codexHome: privateCodexHome,
1129
+ home: privateHome,
1130
+ otherCodexHomes: privateOtherCodexHomes,
1052
1131
  });
1053
1132
  const common = [
1054
1133
  '--json',
@@ -1455,6 +1534,15 @@ export default {
1455
1534
  // lives, and the one the shell would inherit.
1456
1535
  tempRoots: privateProfile ? [tmpdir(), childEnv.TMPDIR] : [],
1457
1536
  shellTempDir: privateShellTemp,
1537
+ // The home Codex runs with, and the HOME its `~` keys expand against.
1538
+ // Codex reads a relative CODEX_HOME from its own folder, the turn's.
1539
+ privateCodexHome: privateProfile
1540
+ ? pathResolve(ctx.cwd || process.cwd(), childEnv.CODEX_HOME || join(childEnv.HOME || homedir(), '.codex'))
1541
+ : null,
1542
+ privateHome: childEnv.HOME || homedir(),
1543
+ // Public seats' Codex homes (their sessions and logs): under the denied
1544
+ // ~/.commonly on macOS, outside it on Linux.
1545
+ privateOtherCodexHomes: privateProfile ? privatePublicHomesDeny(ctx) : [],
1458
1546
  });
1459
1547
  // childEnv is derived from the process environment, so the bootstrap export has to be
1460
1548
  // taken back out: the declaration above moved our server onto the file,
@@ -122,28 +122,47 @@ export const bwrapRefusedMessage = (adapterName, { reason, apparmorRestricted, u
122
122
  ].join('\n');
123
123
  };
124
124
 
125
+ const CODEX_UNSANDBOXED_RUN_LINE = ` - In invite-only pods, run it without a sandbox: ${CLI} agent run <name> ${UNSANDBOXED_FLAG}`
126
+ + ' (in the foreground; the daemon takes this only on Windows).'
127
+ + ' Nothing confines it: it runs with your own access to files and commands, anyone in the pod,'
128
+ + ' people you invite later included, can direct it, and it gets no connector grants.';
129
+
125
130
  /**
126
- * F387: a private Codex seat on Linux is refused by default until a Linux
127
- * permission profile is walked (see hostSandboxRefusal). The person can run it
128
- * unconfined by their own choice, as on native Windows; it never falls back
129
- * to that without being asked.
131
+ * F387, F444: a private Codex seat on Linux runs under Codex's own sandbox,
132
+ * which uses bubblewrap there. Where bubblewrap can't start one, the seat is
133
+ * refused before its first poll, with the fix for this host. The person can
134
+ * run it unconfined by their own choice, as on native Windows; it never falls
135
+ * back to that without being asked.
130
136
  */
131
- export const CODEX_PRIVATE_LINUX_MESSAGE = [
132
- 'A private Codex agent runs inside a sandbox that keeps your other credentials out of its reach, and that sandbox is not ready on Linux yet,',
133
- 'so by default this agent cannot listen for @mentions here. You can:',
134
- ` - In invite-only pods, run it without a sandbox: ${CLI} agent run <name> ${UNSANDBOXED_FLAG}.`
135
- + ' Nothing confines it: it runs with your own access to files and commands, anyone in the pod,'
136
- + ' people you invite later included, can direct it, and it gets no connector grants.',
137
- ' - Run it on a Mac, where the sandbox is ready.',
138
- HOSTED_LINE,
139
- ].join('\n');
137
+ export const codexPrivateLinuxMessage = (bwrap = {}, { optedIn = false } = {}) => {
138
+ const refused = bwrap.namespaceRefused === true;
139
+ const offersProfile = refused && bwrap.apparmorRestricted === true && bwrap.ubuntuRelease === '24.04';
140
+ return [
141
+ 'A private Codex agent runs inside Codex\'s own sandbox, which keeps your other credentials out of its reach'
142
+ + ` and uses bubblewrap on Linux. ${refused
143
+ ? `This machine won't let bubblewrap start one (${bwrap.reason}).`
144
+ : (bwrap.error || 'bubblewrap was not found.')}`,
145
+ ...(refused && bwrap.apparmorRestricted === true
146
+ ? ['AppArmor on Ubuntu 24.04 and later restricts the user namespaces bubblewrap needs.']
147
+ : []),
148
+ ...(optedIn
149
+ ? ['A pod this agent answers in is publicly readable or open to join, or did not report whether it is,'
150
+ + ' so it cannot run without a sandbox either.']
151
+ : []),
152
+ 'So this agent cannot listen for @mentions here yet. You can:',
153
+ ...(refused ? [] : [' - Install bubblewrap (`sudo apt install bubblewrap`) and run the same command again.']),
154
+ ...(optedIn ? [] : [CODEX_UNSANDBOXED_RUN_LINE]),
155
+ HOSTED_LINE,
156
+ ...(offersProfile ? UBUNTU_BWRAP_PROFILE_LINES : []),
157
+ ].join('\n');
158
+ };
140
159
 
141
- // The person opted in, and a pod rules it out. Naming the flag again would
142
- // only send them round in a circle.
143
- export const CODEX_PRIVATE_LINUX_OPTED_IN_MESSAGE = [
160
+ // The person opted in, and a pod rules it out, so the turn has no sandbox to
161
+ // fall back to on any platform. Naming the flag again would only send them
162
+ // round in a circle.
163
+ export const CODEX_OPTED_IN_PUBLIC_POD_MESSAGE = [
144
164
  'A pod this agent answers in is publicly readable or open to join, or did not report whether it is,',
145
- 'so it cannot run without a sandbox, and the sandbox for a private Codex agent is not ready on Linux yet. You can:',
146
- ' - Run it on a Mac, where the sandbox is ready.',
165
+ 'so it cannot run without a sandbox. You can:',
147
166
  HOSTED_LINE,
148
167
  ].join('\n');
149
168
 
@@ -200,17 +219,18 @@ export const hostSandboxRefusal = ({
200
219
  const bwrap = detectBwrap();
201
220
  return bwrap.namespaceRefused === true ? bwrapRefusedMessage(adapterName, bwrap) : null;
202
221
  }
203
- // F387: a private seat outside a cloud-codex pod runs under the private
204
- // permission profile. On Linux, Codex runs its sandbox helper from
205
- // CODEX_HOME (~/.codex), and a denied ancestor always wins there (see the
206
- // public Codex home in adapters/codex.js), so the profile's denies would
207
- // fail every turn at bootstrap. Until a Linux key set is walked, the seat
208
- // is refused before its first poll, unless the person ran it unconfined
209
- // by their own --unsandboxed (D245, as on Windows: only with every pod
210
- // confirmed private). Never unconfined without being asked.
222
+ // F387, F444: a private seat outside a cloud-codex pod runs under the
223
+ // private permission profile, which Codex enforces with bubblewrap on Linux
224
+ // (walked on byo-linux.yml, walk=private-codex). Where bubblewrap can't
225
+ // start, every turn would fail at session start, so the seat is refused
226
+ // before its first poll, unless the person ran it unconfined by their own
227
+ // --unsandboxed (D245, as on Windows: only with every pod confirmed
228
+ // private). Never unconfined without being asked.
211
229
  if (platform === 'linux' && trust !== 'workspace' && !codexTrustedPerimeter(env)) {
212
230
  if (hostUnconfined === true) return null;
213
- return optedIn === true ? CODEX_PRIVATE_LINUX_OPTED_IN_MESSAGE : CODEX_PRIVATE_LINUX_MESSAGE;
231
+ const bwrap = detectBwrap();
232
+ if (bwrap.available) return null;
233
+ return codexPrivateLinuxMessage(bwrap, { optedIn: optedIn === true });
214
234
  }
215
235
  if (platform !== 'win32') return null;
216
236
  if (trust === 'workspace') return null;
@@ -55,8 +55,8 @@ export const unsandboxedMarkerPath = (home = homedir()) => join(home, '.commonly
55
55
 
56
56
  /**
57
57
  * The flag answers a gap in the sandbox: native Windows has none, and a private
58
- * Codex agent on Linux has none ready yet (F387). So on Linux it is accepted
59
- * only for `agent run` of a Codex agent: pass `adapterName` once it is known,
58
+ * Codex agent on Linux has none where bubblewrap can't start (F387, F444). So
59
+ * on Linux it is accepted only for `agent run` of a Codex agent: pass `adapterName` once it is known,
60
60
  * or `deferred` before the record is read (the run checks again after). The
61
61
  * daemon's marker stays Windows-only.
62
62
  */
@@ -123,9 +123,8 @@ export const hostUnconfinedForRun = ({
123
123
  };
124
124
 
125
125
  /**
126
- * Does this Codex run go unconfined? Only on win32, or on Linux where a private
127
- * Codex agent has no sandbox ready yet (F387), only by the user's own
128
- * opt-in, and only when every pod the seat answers in is confirmed private:
126
+ * Does this Codex run go unconfined? Only on win32, or on Linux (F387, F444),
127
+ * only by the user's own opt-in, and only when every pod the seat answers in is confirmed private:
129
128
  * `installations` is the server's read of them, and an empty or failed read is
130
129
  * a no. Workspace trust stays with Codex's own refusal. The caller removes the
131
130
  * sandbox block for this run only, so the saved record keeps its public trust
@@ -152,7 +151,7 @@ export const UNSANDBOXED_NOTICE = 'unsandboxed (opted in): Windows has no sandbo
152
151
  /** Codex has no restricted tool settings to keep, so its line says what it costs instead. */
153
152
  export const CODEX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in): Windows has no sandbox Codex can use here, so nothing confines this agent. It runs with your own access to files and commands, and anyone in its pods, people invited later included, can direct it. It gets no connector grants, and a turn is refused if a pod stops being invite-only.';
154
153
 
155
- export const CODEX_LINUX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in): the sandbox for a private Codex agent is not ready on Linux yet, so nothing confines this agent. It runs with your own access to files and commands, and anyone in its pods, people invited later included, can direct it. It gets no connector grants, and a turn is refused if a pod stops being invite-only.';
154
+ export const CODEX_LINUX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in): you ran this Codex agent without its sandbox, so nothing confines this agent. It runs with your own access to files and commands, and anyone in its pods, people invited later included, can direct it. It gets no connector grants, and a turn is refused if a pod stops being invite-only.';
156
155
 
157
156
  export const codexUnsandboxedNotice = (platform = process.platform) => (platform === 'linux'
158
157
  ? CODEX_LINUX_UNSANDBOXED_NOTICE