@commonlyai/cli 0.1.309 → 0.1.310

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.309",
3
+ "version": "0.1.310",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -77,7 +77,6 @@ import { homedir, tmpdir } from 'os';
77
77
  import {
78
78
  delimiter, dirname, isAbsolute, join,
79
79
  } from 'path';
80
- import { fileURLToPath } from 'url';
81
80
 
82
81
  import {
83
82
  isLegacySandboxTrust,
@@ -95,6 +94,7 @@ import {
95
94
  } from '../sandbox/seatbelt.js';
96
95
  import { CREDENTIAL_FILE_VAR, CREDENTIAL_KEY, writeCredentialFile } from '../credential-file.js';
97
96
  import { supportedGitHooks } from '../commit-attribution.js';
97
+ import { workspaceGitAttachment } from '../workspace-git.js';
98
98
  import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
99
99
  import {
100
100
  prepareMcpSpawn, PUBLIC_MCP_UNAVAILABLE_CODE, publicMcpUnavailableError, selectedMcpVersionDir,
@@ -180,44 +180,23 @@ const workspaceGrants = (sandbox) => (
180
180
  sandbox?.trust === 'workspace' && Array.isArray(sandbox.allow) ? sandbox.allow : []
181
181
  );
182
182
  // A workspace seat reads its project's history through one read-only git tool
183
- // (git-readonly-server.js). The server runs inside the jail, so the jail must
184
- // admit its code (cli/src/lib, plus package.json for the module type) and the
185
- // git binary it runs.
186
- const WORKSPACE_GIT_SERVER = fileURLToPath(new URL('../git-readonly-server.js', import.meta.url));
187
- const WORKSPACE_GIT_PACKAGE_JSON = fileURLToPath(new URL('../../../package.json', import.meta.url));
188
- // macOS's /usr/bin/git is an xcrun shim, and it fails inside Seatbelt ("No
189
- // developer tools were found"). So the jail gets the binary git itself runs:
190
- // `git --exec-path`, resolved here on the host, holds a `git` that links to it.
191
- const resolveRealGit = () => {
192
- const result = spawnSync('git', ['--exec-path'], { encoding: 'utf8', timeout: 5000 });
193
- const execDir = result?.status === 0 ? String(result.stdout || '').trim() : '';
194
- if (!execDir) return null;
195
- try {
196
- return realpathSync(join(execDir, 'git'));
197
- } catch {
198
- return null;
199
- }
200
- };
183
+ // (git-readonly-server.js, attached by workspace-git.js). The server runs
184
+ // inside the jail, so the jail admits its code and the real git binary.
201
185
  const withWorkspaceGit = (ctx) => {
202
186
  if (ctx.environment?.sandbox?.trust !== 'workspace' || !ctx.cwd) return ctx;
203
- const git = resolveRealGit();
204
- if (!git) {
187
+ const attachment = workspaceGitAttachment(ctx.cwd);
188
+ if (!attachment) {
205
189
  // eslint-disable-next-line no-console
206
190
  console.warn('[claude] git was not found on this machine, so this workspace seat has no git tool');
207
191
  return ctx;
208
192
  }
209
- const server = {
210
- name: 'workspace_git',
211
- transport: 'stdio',
212
- command: [process.execPath, WORKSPACE_GIT_SERVER, '--root', ctx.cwd, '--git', git],
213
- };
214
193
  return {
215
194
  ...ctx,
216
- environment: { ...ctx.environment, mcp: [...(ctx.environment.mcp || []), server] },
195
+ environment: { ...ctx.environment, mcp: [...(ctx.environment.mcp || []), attachment.server] },
217
196
  workspaceGit: {
218
- executable: git,
219
- readDirectories: [dirname(WORKSPACE_GIT_SERVER)],
220
- readPaths: [WORKSPACE_GIT_PACKAGE_JSON],
197
+ executable: attachment.executable,
198
+ readDirectories: attachment.readDirectories,
199
+ readPaths: attachment.readPaths,
221
200
  },
222
201
  };
223
202
  };
@@ -75,6 +75,7 @@ import { isOurGrantBroker } from '../grant-broker-guard.js';
75
75
  import { BRIDGE_PATH } from './codex-broker-bridge.mjs';
76
76
  import { brokerBridgeEntry } from './broker-bridge-entry.js';
77
77
  import { supportedGitHooks } from '../commit-attribution.js';
78
+ import { WORKSPACE_GIT_SERVER_NAME, confinedWorkspaceGitServer } from '../workspace-git.js';
78
79
  import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
79
80
  import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } from '../mcp-home.js';
80
81
  import { BACKGROUND_PROCESS_CUE, buildMemoryPreamble, ROW_SLICING_CUE } from '../memory-bridge.js';
@@ -1114,7 +1115,38 @@ export default {
1114
1115
 
1115
1116
  let providerProxy = null;
1116
1117
  try {
1117
- const mcp = buildMcpOverrideArgs(ctx.environment?.mcp, {
1118
+ // A public seat can't run git from its shell on macOS: Homebrew's git is
1119
+ // outside the profile and /usr/bin/git is an xcrun shim that fails there.
1120
+ // So it reads its workspace's history through the read-only git tool a
1121
+ // Claude workspace seat has. Codex starts MCP servers outside the seat's
1122
+ // profile, so this one runs under a Seatbelt of its own
1123
+ // (confinedWorkspaceGitServer). An entry the environment declares under
1124
+ // the same name would run unconfined, so on a public seat it is replaced.
1125
+ const declaredMcp = ctx.environment?.mcp || [];
1126
+ let seatMcp = declaredMcp;
1127
+ if (workspacePath) {
1128
+ const declaresGit = declaredMcp.some((server) => server?.name === WORKSPACE_GIT_SERVER_NAME);
1129
+ if (declaresGit) {
1130
+ // eslint-disable-next-line no-console
1131
+ console.warn(`[codex] this public seat's environment declares ${WORKSPACE_GIT_SERVER_NAME}; `
1132
+ + 'Codex would run it outside the sandbox, so the confined one replaces it');
1133
+ }
1134
+ const stateDir = join(dir, 'git-tool');
1135
+ await mkdir(stateDir, { mode: 0o700 });
1136
+ const workspaceGit = (ctx._workspaceGitServer || confinedWorkspaceGitServer)(workspacePath, {
1137
+ stateDir,
1138
+ platform: ctx._platform || process.platform,
1139
+ });
1140
+ if (!workspaceGit) {
1141
+ // eslint-disable-next-line no-console
1142
+ console.warn('[codex] the read-only git tool needs macOS and git on this machine, so this public seat has none');
1143
+ }
1144
+ seatMcp = [
1145
+ ...declaredMcp.filter((server) => server?.name !== WORKSPACE_GIT_SERVER_NAME),
1146
+ ...(workspaceGit ? [workspaceGit] : []),
1147
+ ];
1148
+ }
1149
+ const mcp = buildMcpOverrideArgs(seatMcp, {
1118
1150
  runtimeToken: ctx.runtimeToken,
1119
1151
  instanceUrl: ctx.instanceUrl,
1120
1152
  credentialFile: credential?.path || null,
@@ -1186,6 +1218,9 @@ export default {
1186
1218
  prompt: fullPrompt,
1187
1219
  outputFile,
1188
1220
  mcpFlags: mcp.flags,
1221
+ // Nothing is added for the git tool, which has a Seatbelt of its own:
1222
+ // admitting the git binary here would let the shell run git directly,
1223
+ // around the read-only server.
1189
1224
  mcpReadDirectories: mcp.mcpReadDirectories,
1190
1225
  publicSandboxMode,
1191
1226
  model: seatModel,
@@ -42,9 +42,12 @@
42
42
  * no transport is allowed, which covers git older than 2.44, where
43
43
  * GIT_NO_LAZY_FETCH does nothing.
44
44
  * 5. Outside this module, the seat's sandbox (Seatbelt or bwrap) mounts the
45
- * workspace read-only.
45
+ * workspace read-only. A public Codex seat starts its MCP servers outside
46
+ * its own profile, so the codex adapter runs this server under a Seatbelt
47
+ * of its own (workspace-git.js): workspace read-only, no network.
46
48
  * 6. A committed `.env` or `.env.*` stays as far out of reach as the file
47
- * itself, which the sandbox denies at any depth. An argument naming one
49
+ * itself, which the sandbox denies at any depth. So do `.npmrc`,
50
+ * `.yarnrc*`, `.commonly` and `.codex`, which a sandbox also denies. An argument naming one
48
51
  * (`.env`, `HEAD:.env`, `:0:sub/.env.local`, `-L1,5:.env`) is refused, and
49
52
  * status, log, diff and show run with pathspecs excluding them, so no patch,
50
53
  * pickaxe match or blob id comes from one whatever path or glob the caller
@@ -154,13 +157,27 @@ const checkFormat = (arg) => {
154
157
  return `${arg} is refused: name a built-in format (${BUILTIN_FORMATS.join(', ')}) or give format:<placeholders>`;
155
158
  };
156
159
 
157
- // Mirrors the names sandbox/seatbelt.js denies at any depth.
160
+ // The names a seat's sandbox denies at any depth: sandbox/seatbelt.js denies
161
+ // .env files, .commonly and .codex, and a public Codex seat's profile
162
+ // (adapters/codex.js) also denies .npmrc and .yarnrc*. They are kept out of
163
+ // git's results too, since the objects git reads hold them whatever the
164
+ // sandbox says about the file.
158
165
  const ENV_FILE_SEGMENT = /^\.env(\..*)?$/;
159
- const namesEnvFile = (arg) => arg.split(':')
160
- .some((part) => part.split('/').some((segment) => ENV_FILE_SEGMENT.test(segment)));
166
+ const OTHER_PROTECTED_SEGMENT = /^(?:\.npmrc|\.yarnrc.*|\.commonly|\.codex)$/;
167
+ const segmentsOf = (arg) => arg.split(':').flatMap((part) => part.split('/'));
168
+ const namesEnvFile = (arg) => segmentsOf(arg).some((segment) => ENV_FILE_SEGMENT.test(segment));
169
+ const namesOtherProtected = (arg) => segmentsOf(arg).some((segment) => OTHER_PROTECTED_SEGMENT.test(segment));
161
170
  const NAMES_ENV_FILE = 'it names a .env file, which the workspace keeps out of reach';
171
+ const NAMES_OTHER_PROTECTED = 'it names a file the workspace keeps out of reach (.npmrc, .yarnrc, .commonly or .codex)';
172
+ const protectedNameReason = (arg) => {
173
+ if (namesEnvFile(arg)) return NAMES_ENV_FILE;
174
+ if (namesOtherProtected(arg)) return NAMES_OTHER_PROTECTED;
175
+ return null;
176
+ };
162
177
  const ENV_EXCLUDES = Object.freeze([
163
178
  ':(exclude,glob)**/.env', ':(exclude,glob)**/.env.*', ':(exclude,glob)**/.env/**', ':(exclude,glob)**/.env.*/**',
179
+ ':(exclude,glob)**/.npmrc', ':(exclude,glob)**/.npmrc/**', ':(exclude,glob)**/.yarnrc*', ':(exclude,glob)**/.yarnrc*/**',
180
+ ':(exclude,glob)**/.commonly', ':(exclude,glob)**/.commonly/**', ':(exclude,glob)**/.codex', ':(exclude,glob)**/.codex/**',
164
181
  ]);
165
182
  // blame takes one literal file, so the name check above covers it. A
166
183
  // blob-to-blob diff (`diff A:f B:f`) takes no pathspec and is refused by git
@@ -254,14 +271,16 @@ export const readonlyGitArgv = ({ subcommand, args = [], root }) => {
254
271
  if (arg.length > MAX_ARG_LENGTH || arg.includes('\0')) return refuse('an argument is too long or contains NUL');
255
272
  if (pathsOnly || arg === '-' || !arg.startsWith('-')) {
256
273
  if (escapesRoot(root, arg)) return refuse(`${arg} is refused: it is outside the workspace`);
257
- if (namesEnvFile(arg)) return refuse(`${arg} is refused: ${NAMES_ENV_FILE}`);
274
+ const protectedReason = protectedNameReason(arg);
275
+ if (protectedReason) return refuse(`${arg} is refused: ${protectedReason}`);
258
276
  } else if (arg === '--') {
259
277
  pathsOnly = true;
260
278
  } else {
261
279
  const reason = arg.startsWith('--') ? checkLongOption(arg) || checkFormat(arg) : checkShortOption(arg, subcommand);
262
280
  if (reason) return refuse(reason);
263
281
  if (arg.startsWith('-L')) {
264
- if (namesEnvFile(arg.slice(2))) return refuse(`${arg} is refused: ${NAMES_ENV_FILE}`);
282
+ const rangeReason = protectedNameReason(arg.slice(2));
283
+ if (rangeReason) return refuse(`${arg} is refused: ${rangeReason}`);
265
284
  if (PATHSPEC_SUBCOMMANDS.has(subcommand)) {
266
285
  const lineRangeReason = checkLineRange(arg, index, subcommand);
267
286
  if (lineRangeReason) return refuse(lineRangeReason);
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The read-only `workspace_git` MCP server (git-readonly-server.js), as an
3
+ * adapter attaches it to a sandboxed seat. Shared by the claude adapter (for a
4
+ * workspace-trust seat) and the codex adapter (for a public seat), so both
5
+ * give the model the same one git tool, run against the same real binary.
6
+ */
7
+ import { spawnSync } from 'child_process';
8
+ import { realpathSync } from 'fs';
9
+ import { dirname, join } from 'path';
10
+ import { fileURLToPath } from 'url';
11
+ import { wrapArgvWithSeatbelt } from './sandbox/seatbelt.js';
12
+
13
+ // The name git-readonly-server.js serves under. Kept here, not imported: the
14
+ // server module pulls in git-readonly.js and its execFile, which an adapter has
15
+ // no use for (git-readonly-server.test.mjs checks the two names agree).
16
+ export const WORKSPACE_GIT_SERVER_NAME = 'workspace_git';
17
+
18
+ // The server runs inside the sandbox, so the sandbox must admit its code
19
+ // (cli/src/lib, plus package.json for the module type) and the git binary it runs.
20
+ export const WORKSPACE_GIT_SERVER = fileURLToPath(new URL('./git-readonly-server.js', import.meta.url));
21
+ export const WORKSPACE_GIT_PACKAGE_JSON = fileURLToPath(new URL('../../package.json', import.meta.url));
22
+
23
+ // macOS's /usr/bin/git is an xcrun shim, and it fails inside a sandbox ("No
24
+ // developer tools were found"). So the sandbox gets the binary git itself runs:
25
+ // `git --exec-path`, resolved here on the host, holds a `git` that links to it.
26
+ export const resolveRealGit = ({ run = spawnSync } = {}) => {
27
+ const result = run('git', ['--exec-path'], { encoding: 'utf8', timeout: 5000 });
28
+ const execDir = result?.status === 0 ? String(result.stdout || '').trim() : '';
29
+ if (!execDir) return null;
30
+ try {
31
+ return realpathSync(join(execDir, 'git'));
32
+ } catch {
33
+ return null;
34
+ }
35
+ };
36
+
37
+ // The MCP server entry and the paths the sandbox has to let it read, for a
38
+ // seat whose workspace is `root`. Null when this machine has no git.
39
+ export const workspaceGitAttachment = (root, { git = resolveRealGit() } = {}) => {
40
+ if (!root || !git) return null;
41
+ return {
42
+ server: {
43
+ name: WORKSPACE_GIT_SERVER_NAME,
44
+ transport: 'stdio',
45
+ command: [process.execPath, WORKSPACE_GIT_SERVER, '--root', root, '--git', git],
46
+ },
47
+ executable: git,
48
+ readDirectories: [dirname(WORKSPACE_GIT_SERVER)],
49
+ readPaths: [WORKSPACE_GIT_PACKAGE_JSON],
50
+ };
51
+ };
52
+
53
+ // For a public Codex seat. Codex starts its MCP servers outside the seat's
54
+ // permission profile, so a bare server would run git as the operator, with the
55
+ // network on and every file the profile denies in reach. This one runs under a
56
+ // Seatbelt of its own: the workspace read-only, no network, its code and git
57
+ // readable, and nothing writable but `stateDir`, an empty folder of its own (not
58
+ // the folder that holds the seat's credential). macOS only: elsewhere there is
59
+ // no wrapper here yet, so the seat gets no tool rather than an unconfined one.
60
+ export const confinedWorkspaceGitServer = (root, {
61
+ stateDir,
62
+ platform = process.platform,
63
+ git = platform === 'darwin' ? resolveRealGit() : null,
64
+ wrap = wrapArgvWithSeatbelt,
65
+ } = {}) => {
66
+ if (platform !== 'darwin' || !root || !stateDir || !git) return null;
67
+ const attachment = workspaceGitAttachment(root, { git });
68
+ const command = wrap(attachment.server.command, {
69
+ workspacePath: root,
70
+ workspaceAccess: 'read',
71
+ executablePath: git,
72
+ statePath: stateDir,
73
+ readOnlyDirectories: attachment.readDirectories,
74
+ readOnlyPaths: attachment.readPaths,
75
+ network: 'loopback',
76
+ processInfo: 'self',
77
+ });
78
+ return { ...attachment.server, command };
79
+ };