@commonlyai/cli 0.1.312 → 0.1.314

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.312",
3
+ "version": "0.1.314",
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
  }
@@ -56,8 +56,12 @@
56
56
  * file each one changed. A line range (log and show `-L<range>:<file>`)
57
57
  * takes no pathspec, so it is taken only as the first argument, in one
58
58
  * piece, where git cannot read it as another option's value, and its file
59
- * is name-checked. What this cannot stop is `show <blob id>` with an id
60
- * learned somewhere else.
59
+ * is name-checked. A blob has no name of its own, so `show` refuses any
60
+ * revision that names a blob (or a tag that peels to one) other than as
61
+ * `<rev>:<path>`, whose path is name-checked: git is asked each one's type
62
+ * before the call runs (blobNamedById). `show` also refuses the options
63
+ * that make git pick objects itself (SHOW_DENIED_OPTIONS), since it prints
64
+ * every blob they reach whatever the pathspec says.
61
65
  */
62
66
  import { execFile } from 'child_process';
63
67
  import { realpathSync } from 'fs';
@@ -83,8 +87,40 @@ export const DENIED_LONG_OPTIONS = Object.freeze({
83
87
  '--show-signature': 'runs gpg to check a signature',
84
88
  '--follow': 'needs exactly one path, and every log here also carries the .env excludes',
85
89
  '--full-diff': 'shows every file a picked commit changed, .env files included',
90
+ '--end-of-options': 'makes git read every later argument as a revision, so an option-shaped one skips the checks a revision gets',
86
91
  });
87
92
 
93
+ // Options refused for `show` only. Each makes git pick objects itself (every
94
+ // ref, every tag, the index), and `show` prints every blob it is handed in
95
+ // full: a pathspec doesn't filter it, so `show --indexed-objects` would print
96
+ // every file in the index, and `show --tags` a tag that points at a blob.
97
+ // log reads the same options, but prints only the commits they reach.
98
+ export const SHOW_DENIED_OPTIONS = Object.freeze({
99
+ '--all': 'shows every object the refs point at, blobs included',
100
+ '--branches': 'shows every object the branches point at',
101
+ '--tags': 'shows every object the tags point at, blobs included',
102
+ '--remotes': 'shows every object the remote refs point at',
103
+ '--glob': 'shows every object the matching refs point at, blobs included',
104
+ '--exclude': 'only qualifies a ref-selecting option, which show refuses',
105
+ '--exclude-hidden': 'only qualifies a ref-selecting option, which show refuses',
106
+ '--reflog': 'shows every object a reflog names',
107
+ '--indexed-objects': 'shows every file in the index, whatever its name',
108
+ '--alternate-refs': 'shows objects another repository\'s refs point at',
109
+ '--bisect': 'shows the objects the bisect refs point at',
110
+ '--stdin': 'reads revisions the name check never sees',
111
+ });
112
+ const checkShowOption = (arg) => {
113
+ const [name] = arg.split('=', 1);
114
+ if (Object.prototype.hasOwnProperty.call(SHOW_DENIED_OPTIONS, name)) {
115
+ return `${name} is refused for show: it ${SHOW_DENIED_OPTIONS[name]}; name the commit, tree or <rev>:<path> to show`;
116
+ }
117
+ if (name.length >= 4) {
118
+ const denied = Object.keys(SHOW_DENIED_OPTIONS).find((option) => option.startsWith(name));
119
+ if (denied) return `${name} is refused for show: git may read it as ${denied}, which ${SHOW_DENIED_OPTIONS[denied]}`;
120
+ }
121
+ return null;
122
+ };
123
+
88
124
  // Real options that are also prefixes of a denied one. Git takes an exact name
89
125
  // over an abbreviation, so these never mean the denied option.
90
126
  const EXACT_NAMES_THAT_PREFIX_A_DENIED_ONE = new Set(['--text', '--ignore-rev']);
@@ -162,8 +198,8 @@ const checkFormat = (arg) => {
162
198
  // (adapters/codex.js) also denies .npmrc and .yarnrc*. They are kept out of
163
199
  // git's results too, since the objects git reads hold them whatever the
164
200
  // sandbox says about the file.
165
- const ENV_FILE_SEGMENT = /^\.env(\..*)?$/;
166
- const OTHER_PROTECTED_SEGMENT = /^(?:\.npmrc|\.yarnrc.*|\.commonly|\.codex)$/;
201
+ const ENV_FILE_SEGMENT = /^\.env(\..*)?$/i;
202
+ const OTHER_PROTECTED_SEGMENT = /^(?:\.npmrc|\.yarnrc.*|\.commonly|\.codex)$/i;
167
203
  const segmentsOf = (arg) => arg.split(':').flatMap((part) => part.split('/'));
168
204
  const namesEnvFile = (arg) => segmentsOf(arg).some((segment) => ENV_FILE_SEGMENT.test(segment));
169
205
  const namesOtherProtected = (arg) => segmentsOf(arg).some((segment) => OTHER_PROTECTED_SEGMENT.test(segment));
@@ -175,9 +211,9 @@ const protectedNameReason = (arg) => {
175
211
  return null;
176
212
  };
177
213
  const ENV_EXCLUDES = Object.freeze([
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/**',
214
+ ':(exclude,glob,icase)**/.env', ':(exclude,glob,icase)**/.env.*', ':(exclude,glob,icase)**/.env/**', ':(exclude,glob,icase)**/.env.*/**',
215
+ ':(exclude,glob,icase)**/.npmrc', ':(exclude,glob,icase)**/.npmrc/**', ':(exclude,glob,icase)**/.yarnrc*', ':(exclude,glob,icase)**/.yarnrc*/**',
216
+ ':(exclude,glob,icase)**/.commonly', ':(exclude,glob,icase)**/.commonly/**', ':(exclude,glob,icase)**/.codex', ':(exclude,glob,icase)**/.codex/**',
181
217
  ]);
182
218
  // blame takes one literal file, so the name check above covers it. A
183
219
  // blob-to-blob diff (`diff A:f B:f`) takes no pathspec and is refused by git
@@ -276,7 +312,9 @@ export const readonlyGitArgv = ({ subcommand, args = [], root }) => {
276
312
  } else if (arg === '--') {
277
313
  pathsOnly = true;
278
314
  } else {
279
- const reason = arg.startsWith('--') ? checkLongOption(arg) || checkFormat(arg) : checkShortOption(arg, subcommand);
315
+ const reason = arg.startsWith('--')
316
+ ? checkLongOption(arg) || checkFormat(arg) || (subcommand === 'show' ? checkShowOption(arg) : null)
317
+ : checkShortOption(arg, subcommand);
280
318
  if (reason) return refuse(reason);
281
319
  if (arg.startsWith('-L')) {
282
320
  const rangeReason = protectedNameReason(arg.slice(2));
@@ -320,6 +358,72 @@ export const readonlyGitEnv = ({ root, baseEnv = process.env }) => {
320
358
  };
321
359
  };
322
360
 
361
+ const execGit = (git, argv, { root, baseEnv, timeoutMs }) => new Promise((done) => {
362
+ execFile(git, argv, {
363
+ cwd: root,
364
+ env: readonlyGitEnv({ root, baseEnv }),
365
+ timeout: timeoutMs,
366
+ maxBuffer: MAX_BUFFER_BYTES,
367
+ encoding: 'utf8',
368
+ windowsHide: true,
369
+ }, (error, stdout, stderr) => done({ error, stdout: String(stdout || ''), stderr: String(stderr || '') }));
370
+ });
371
+
372
+ // Whether git reads `arg` as `<rev>:<path>`. git splits at the first `:`
373
+ // outside any `{...}` (get_oid_with_context_1 in object-name.c counts brace
374
+ // depth), so a `:` inside `@{...}` or `^{...}` belongs to the revision: a
375
+ // reflog date such as `ref@{2026-11-09 11:41:50}` names no path at all.
376
+ const namesAPath = (arg) => {
377
+ let depth = 0;
378
+ for (const ch of arg) {
379
+ if (ch === '{') depth += 1;
380
+ else if (ch === '}' && depth > 0) depth -= 1;
381
+ else if (ch === ':' && depth === 0) return true;
382
+ }
383
+ return false;
384
+ };
385
+
386
+ // The arguments `show` would read as revisions: before `--`, not an option
387
+ // (`--end-of-options` is refused, so a `-` argument is never a revision). One
388
+ // that names a path does so through `<rev>:<path>`, and readonlyGitArgv has
389
+ // name-checked that path; every other one is probed.
390
+ const unnamedRevisions = (args) => {
391
+ const revisions = [];
392
+ for (const arg of args) {
393
+ if (arg === '--') break;
394
+ if (!arg.startsWith('-') && !namesAPath(arg)) revisions.push(arg);
395
+ }
396
+ return revisions;
397
+ };
398
+
399
+ /**
400
+ * The first of `show`'s revisions that is a blob, or a tag that peels to one,
401
+ * or null. git prints a blob given by id whatever path it was committed at, so
402
+ * a blob is only shown through `<rev>:<path>`. An argument git can't resolve
403
+ * to one object (a range, a typo) is left to `show` itself, which shows no
404
+ * blob for it.
405
+ */
406
+ export const blobNamedById = async ({
407
+ args, root, git = 'git', baseEnv = process.env, timeoutMs = DEFAULT_TIMEOUT_MS,
408
+ }) => {
409
+ // One budget for every check, so many arguments can't stretch the call.
410
+ const deadline = Date.now() + timeoutMs;
411
+ for (const revision of unnamedRevisions(args)) {
412
+ const left = deadline - Date.now();
413
+ if (left <= 0) return { revision, unchecked: true };
414
+ // A revision here never starts with `-`, so cat-file can't read it as an option.
415
+ const { error, stdout } = await execGit(
416
+ git,
417
+ [...TOP_LEVEL, 'cat-file', '-t', `${revision}^{}`],
418
+ { root, baseEnv, timeoutMs: left },
419
+ );
420
+ // A check that was stopped proves nothing, so the call is refused.
421
+ if (error?.killed || error?.signal) return { revision, unchecked: true };
422
+ if (!error && stdout.trim() === 'blob') return { revision };
423
+ }
424
+ return null;
425
+ };
426
+
323
427
  const truncate = (text) => (text.length <= MAX_OUTPUT_CHARS
324
428
  ? text
325
429
  : `${text.slice(0, MAX_OUTPUT_CHARS)}\n[output truncated at ${MAX_OUTPUT_CHARS} characters; narrow it with -n, a path, or a revision range]`);
@@ -328,32 +432,32 @@ const truncate = (text) => (text.length <= MAX_OUTPUT_CHARS
328
432
  * Run one read-only git call in `root`. Resolves `{ ok, text }`; never rejects.
329
433
  * `git` is the binary to run (the adapter resolves it outside the sandbox).
330
434
  */
331
- export const runReadonlyGit = ({
435
+ export const runReadonlyGit = async ({
332
436
  subcommand, args, root, git = 'git', baseEnv = process.env, timeoutMs = DEFAULT_TIMEOUT_MS,
333
- }) => new Promise((done) => {
437
+ }) => {
334
438
  const checked = readonlyGitArgv({ subcommand, args, root });
335
- if (!checked.ok) {
336
- done({ ok: false, text: checked.reason });
337
- return;
338
- }
339
- execFile(git, checked.argv, {
340
- cwd: root,
341
- env: readonlyGitEnv({ root, baseEnv }),
342
- timeout: timeoutMs,
343
- maxBuffer: MAX_BUFFER_BYTES,
344
- encoding: 'utf8',
345
- windowsHide: true,
346
- }, (error, stdout, stderr) => {
347
- const out = String(stdout || '');
348
- if (!error) {
349
- done({ ok: true, text: truncate(out || '(no output)') });
350
- return;
439
+ if (!checked.ok) return { ok: false, text: checked.reason };
440
+ if (subcommand === 'show') {
441
+ const blob = await blobNamedById({
442
+ args, root, git, baseEnv, timeoutMs,
443
+ });
444
+ if (blob?.unchecked) {
445
+ return { ok: false, text: `${blob.revision} is refused: git did not say in time whether it is a blob` };
351
446
  }
352
- const detail = String(stderr || '').trim() || error.message;
353
- done({ ok: false, text: truncate([out.trim(), detail].filter(Boolean).join('\n')) });
354
- });
355
- });
447
+ if (blob) {
448
+ return {
449
+ ok: false,
450
+ text: `${blob.revision} is refused: it is a blob, and a blob is shown only as <rev>:<path>, so the file it came from can be checked`,
451
+ };
452
+ }
453
+ }
454
+ const { error, stdout: out, stderr } = await execGit(git, checked.argv, { root, baseEnv, timeoutMs });
455
+ if (!error) return { ok: true, text: truncate(out || '(no output)') };
456
+ const detail = stderr.trim() || error.message;
457
+ return { ok: false, text: truncate([out.trim(), detail].filter(Boolean).join('\n')) };
458
+ };
356
459
 
357
460
  export default {
358
- READONLY_GIT_SUBCOMMANDS, DENIED_LONG_OPTIONS, DENIED_SHORT_OPTIONS, readonlyGitArgv, readonlyGitEnv, runReadonlyGit,
461
+ READONLY_GIT_SUBCOMMANDS, DENIED_LONG_OPTIONS, DENIED_SHORT_OPTIONS, blobNamedById, readonlyGitArgv, readonlyGitEnv,
462
+ runReadonlyGit,
359
463
  };
@@ -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));