@commonlyai/cli 0.1.311 → 0.1.313

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.311",
3
+ "version": "0.1.313",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -94,7 +94,7 @@ import {
94
94
  } from '../sandbox/seatbelt.js';
95
95
  import { CREDENTIAL_FILE_VAR, CREDENTIAL_KEY, writeCredentialFile } from '../credential-file.js';
96
96
  import { supportedGitHooks } from '../commit-attribution.js';
97
- import { workspaceGitAttachment } from '../workspace-git.js';
97
+ import { workspaceGitAttachment, workspaceGitEnabled } 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,
@@ -181,9 +181,11 @@ const workspaceGrants = (sandbox) => (
181
181
  );
182
182
  // A workspace seat reads its project's history through one read-only git tool
183
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.
184
+ // inside the jail, so the jail admits its code and the real git binary. The
185
+ // tool is opt-in (workspaceGitEnabled): without it the seat simply has none.
185
186
  const withWorkspaceGit = (ctx) => {
186
187
  if (ctx.environment?.sandbox?.trust !== 'workspace' || !ctx.cwd) return ctx;
188
+ if (!workspaceGitEnabled()) return ctx;
187
189
  const attachment = workspaceGitAttachment(ctx.cwd);
188
190
  if (!attachment) {
189
191
  // eslint-disable-next-line no-console
@@ -75,7 +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
+ import { WORKSPACE_GIT_SERVER_NAME, confinedWorkspaceGitServer, workspaceGitEnabled } from '../workspace-git.js';
79
79
  import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
80
80
  import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } from '../mcp-home.js';
81
81
  import { BACKGROUND_PROCESS_CUE, buildMemoryPreamble, ROW_SLICING_CUE } from '../memory-bridge.js';
@@ -1132,19 +1132,27 @@ export default {
1132
1132
  const declaredMcp = ctx.environment?.mcp || [];
1133
1133
  let seatMcp = declaredMcp;
1134
1134
  if (workspacePath) {
1135
+ // The confined tool is opt-in (workspaceGitEnabled). A declared one is
1136
+ // dropped either way: Codex would run it outside the sandbox.
1137
+ const gitEnabled = workspaceGitEnabled();
1135
1138
  const declaresGit = declaredMcp.some((server) => server?.name === WORKSPACE_GIT_SERVER_NAME);
1136
1139
  if (declaresGit) {
1137
1140
  // eslint-disable-next-line no-console
1138
1141
  console.warn(`[codex] this public seat's environment declares ${WORKSPACE_GIT_SERVER_NAME}; `
1139
- + 'Codex would run it outside the sandbox, so the confined one replaces it');
1142
+ + (gitEnabled
1143
+ ? 'Codex would run it outside the sandbox, so the confined one replaces it'
1144
+ : 'Codex would run it outside the sandbox, so it is dropped'));
1140
1145
  }
1141
- const stateDir = join(dir, 'git-tool');
1142
- await mkdir(stateDir, { mode: 0o700 });
1143
- const workspaceGit = (ctx._workspaceGitServer || confinedWorkspaceGitServer)(workspacePath, {
1144
- stateDir,
1145
- platform: ctx._platform || process.platform,
1146
- });
1147
- if (!workspaceGit) {
1146
+ let workspaceGit = null;
1147
+ if (gitEnabled) {
1148
+ const stateDir = join(dir, 'git-tool');
1149
+ await mkdir(stateDir, { mode: 0o700 });
1150
+ workspaceGit = (ctx._workspaceGitServer || confinedWorkspaceGitServer)(workspacePath, {
1151
+ stateDir,
1152
+ platform: ctx._platform || process.platform,
1153
+ });
1154
+ }
1155
+ if (gitEnabled && !workspaceGit) {
1148
1156
  // eslint-disable-next-line no-console
1149
1157
  console.warn('[codex] the read-only git tool needs macOS and git on this machine, so this public seat has none');
1150
1158
  }
@@ -323,13 +323,18 @@ const subpath = (path) => `(subpath "${escapeSbplString(path)}")`;
323
323
  // inside a directory of that name: a real project keeps one beside each
324
324
  // package, not only at its root (TASK-294). An SBPL regex literal takes no
325
325
  // escapes, so a path it cannot hold is refused.
326
- const envFilesUnder = (workspace) => {
326
+ const regexUnder = (workspace, tail) => {
327
327
  if (/["\r\n]/.test(workspace)) {
328
328
  throw new Error('Seatbelt workspacePath must not contain a quote or a line break');
329
329
  }
330
330
  const pattern = workspace.replace(/[\\^$.|?*+()[\]{}]/g, '\\$&');
331
- return `(regex #"^${pattern}/(.*/)?\\.env([./].*)?$")`;
331
+ return `(regex #"^${pattern}/(.*/)?${tail}")`;
332
332
  };
333
+ const envFilesUnder = (workspace) => regexUnder(workspace, '\\.env([./].*)?$');
334
+ // Every .npmrc and .yarnrc* (.yarnrc, .yarnrc.yml) under the workspace, at any
335
+ // depth, and everything inside a directory of that name: they hold registry
336
+ // tokens. Opt-in, since a seat that installs packages reads its project's.
337
+ const registryConfigUnder = (workspace) => regexUnder(workspace, '(\\.npmrc|\\.yarnrc[^/]*)(/.*)?$');
333
338
 
334
339
  const assertAbsolutePath = (path, label) => {
335
340
  if (!path || !isAbsolute(path)) {
@@ -459,6 +464,10 @@ export const buildSeatbeltProfile = ({
459
464
  // Folders no rule here may let the jail write, however a grant above is
460
465
  // shaped: a workspace seat's own record of its folder (F200).
461
466
  denyWritePaths = [],
467
+ // Deny .npmrc and .yarnrc* under the workspace, as .env files are: for a
468
+ // process that only reads the workspace and installs nothing, such as a
469
+ // public Codex seat's git tool.
470
+ denyRegistryConfig = false,
462
471
  }) => {
463
472
  for (const [path, label] of [
464
473
  [workspacePath, 'workspacePath'],
@@ -590,6 +599,7 @@ export const buildSeatbeltProfile = ({
590
599
  `(deny file-read* file-write* ${subpath(join(resolvedWorkspace, '.commonly'))})`,
591
600
  `(deny file-read* file-write* ${subpath(join(resolvedWorkspace, '.codex'))})`,
592
601
  `(deny file-read* file-write* ${envFilesUnder(resolvedWorkspace)})`,
602
+ denyRegistryConfig ? `(deny file-read* file-write* ${registryConfigUnder(resolvedWorkspace)})` : '',
593
603
  readOnlyWorkspaceRules,
594
604
  // After every allow above, so a workspace that contained one of these
595
605
  // folders still could not write it (later rules win).
@@ -15,6 +15,12 @@ import { wrapArgvWithSeatbelt } from './sandbox/seatbelt.js';
15
15
  // no use for (git-readonly-server.test.mjs checks the two names agree).
16
16
  export const WORKSPACE_GIT_SERVER_NAME = 'workspace_git';
17
17
 
18
+ // The tool is opt-in: an adapter attaches it only when the environment the
19
+ // daemon itself runs in sets COMMONLY_WORKSPACE_GIT=1. Read from the daemon's
20
+ // own environment, never from a seat's record, so a seat cannot turn it on.
21
+ export const WORKSPACE_GIT_ENV = 'COMMONLY_WORKSPACE_GIT';
22
+ export const workspaceGitEnabled = (env = process.env) => env?.[WORKSPACE_GIT_ENV] === '1';
23
+
18
24
  // The server runs inside the sandbox, so the sandbox must admit its code
19
25
  // (cli/src/lib, plus package.json for the module type) and the git binary it runs.
20
26
  export const WORKSPACE_GIT_SERVER = fileURLToPath(new URL('./git-readonly-server.js', import.meta.url));
@@ -53,8 +59,9 @@ export const workspaceGitAttachment = (root, { git = resolveRealGit() } = {}) =>
53
59
  // For a public Codex seat. Codex starts its MCP servers outside the seat's
54
60
  // permission profile, so a bare server would run git as the operator, with the
55
61
  // 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
62
+ // Seatbelt of its own: the workspace read-only with its .env, .npmrc and
63
+ // .yarnrc* files unreadable, as the profile has them, no network, its code and
64
+ // git readable, and nothing writable but `stateDir`, an empty folder of its own (not
58
65
  // the folder that holds the seat's credential). macOS only: elsewhere there is
59
66
  // no wrapper here yet, so the seat gets no tool rather than an unconfined one.
60
67
  export const confinedWorkspaceGitServer = (root, {
@@ -74,6 +81,7 @@ export const confinedWorkspaceGitServer = (root, {
74
81
  readOnlyPaths: attachment.readPaths,
75
82
  network: 'loopback',
76
83
  processInfo: 'self',
84
+ denyRegistryConfig: true,
77
85
  });
78
86
  return { ...attachment.server, command };
79
87
  };