@commonlyai/cli 0.1.404 → 0.1.406

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.404",
3
+ "version": "0.1.406",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1,3 +1,4 @@
1
+ import { Option } from 'commander';
1
2
  import { createOwnKeyResolver, createMachineReportClient } from '../lib/own-key-launch.js';
2
3
  import { foregroundDaemonHint } from '../lib/daemon-hint.js';
3
4
  import { loadDaemonRecord } from '../lib/daemon-store.js';
@@ -116,7 +117,9 @@ import {
116
117
  import { formatPodConventionsFrame } from '../lib/pod-conventions.js';
117
118
  import { claimReleaseFor, ackResultFor, EMPTY_OUTPUT } from '../lib/claim-outcome.js';
118
119
  import { createClaimedWorkGate } from '../lib/claimed-work-gate.js';
119
- import { prepareCommitAttribution } from '../lib/commit-attribution.js';
120
+ import {
121
+ commitAttributionEnabled, prepareCommitAttribution, withCommitAttributionChoice,
122
+ } from '../lib/commit-attribution.js';
120
123
  import { detectBwrap } from '../lib/sandbox/bwrap.js';
121
124
  import { resolveCodexSandboxMode, resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
122
125
  import {
@@ -2312,6 +2315,9 @@ export const performRun = ({
2312
2315
  // (lib/long-poll.js). Undefined derives it from the read timeout; 0 turns
2313
2316
  // the long-poll off. Tests pin a small value.
2314
2317
  longPollWaitMs: longPollWaitOverride,
2318
+ // F656: false when the person turned commit attribution off for this agent
2319
+ // (the record's `commitAttribution`). Unset is on, as it always was.
2320
+ commitAttribution: commitAttributionOn = true,
2315
2321
  }) => {
2316
2322
  const stateKey = localKey || agentName;
2317
2323
  const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
@@ -3379,7 +3385,9 @@ export const performRun = ({
3379
3385
  // The local CLI is a wrapper for a Commonly seat, so its Git commits
3380
3386
  // carry the seat and the adapter's selected model/effort. `stub` exists
3381
3387
  // only for tests and has no commit-making child process.
3382
- if (adapter?.name !== 'stub') {
3388
+ // F656: the person turned attribution off for this agent, so nothing is
3389
+ // prepared and the child gets the plain environment.
3390
+ if (adapter?.name !== 'stub' && commitAttributionOn !== false) {
3383
3391
  commitAttribution = prepareCommitAttribution({
3384
3392
  cwd: placement.cwd,
3385
3393
  env: process.env,
@@ -5997,6 +6005,10 @@ Docs:
5997
6005
  .option('--refusal-handoff <agent>', 'Agent to @mention when the model provider refuses a request\'s content; the request is acked as refused, never retried')
5998
6006
  .option('--allow <grants>', 'On first run of an agent that works in its folder, also let it edit files and run commands (write) and/or fetch web pages (web), comma-separated. Commands reach the network.')
5999
6007
  .option('--unsandboxed', 'Native Windows, or a private Codex agent on Linux: run this agent without a sandbox, with your own access to files and commands. It gets no connector grants. Codex can run commands in invite-only pods, where anyone in the pod, including people invited later, can direct it.')
6008
+ // The positive form first, so no flag leaves opts.commitAttribution
6009
+ // undefined (the saved choice) rather than commander's implied true.
6010
+ .addOption(new Option('--commit-attribution').hideHelp())
6011
+ .option('--no-commit-attribution', "Don't add Co-authored-by and Agent-Model trailers to this agent's commits; saved for its later runs, and --commit-attribution turns them back on")
6000
6012
  .option('--api-url <url>', 'The Commonly instance this agent joins (the Connect your own agent page fills it in; same as COMMONLY_API_URL)')
6001
6013
  .option('--connect <code>', "The connect code from the Connect your own agent page's line, traded once for this agent's key; it stops working once the agent has listened, or after 30 minutes")
6002
6014
  .action(async (typedName, opts) => {
@@ -6176,6 +6188,7 @@ Docs:
6176
6188
  adapterName: record.adapter,
6177
6189
  adapter: getAdapter(record.adapter),
6178
6190
  environment: record.environment,
6191
+ agentName: record.agentName,
6179
6192
  checkInstalled: !bootstrapped,
6180
6193
  });
6181
6194
  const harnessOutcome = preflightOutcome(harnessProblems, { firstRun: bootstrapped });
@@ -6282,6 +6295,9 @@ Docs:
6282
6295
  ? 'this agent is set to workspace trust'
6283
6296
  : "a pod this agent answers in isn't confirmed private and invite-only"}, so it runs in Codex's own sandbox.`);
6284
6297
  }
6298
+ // F656: --[no-]commit-attribution is saved on the record, so a later run
6299
+ // and a daemon-started seat (which passes no flag) keep the choice.
6300
+ record = withCommitAttributionChoice(record, opts.commitAttribution);
6285
6301
  if (saved && record !== saved) saveAgentToken(name, record);
6286
6302
  if (bootstrapped) {
6287
6303
  // A named instance is saved under its seat key; an unnamed run keeps
@@ -6357,6 +6373,10 @@ Docs:
6357
6373
  });
6358
6374
 
6359
6375
  console.log(`${stamp()} [${name}] polling ${record.instanceUrl} for events (ctrl+c to stop)`);
6376
+ if (!commitAttributionEnabled(record)) {
6377
+ console.log(`${stamp()} [${name}] commit attribution is off: this agent's commits get no Co-authored-by `
6378
+ + `or Agent-Model trailers. To turn it back on: ${CLI} agent run ${name} --commit-attribution`);
6379
+ }
6360
6380
  console.log(`${stamp()} [${name}] ${foregroundDaemonHint({ daemonRegistered: hasDaemonRecord(), instanceUrl: record.instanceUrl })}`);
6361
6381
  // TASK-660: one line when this CLI is stale. Fired, not awaited, so a
6362
6382
  // slow registry never delays the first poll.
@@ -6398,6 +6418,7 @@ Docs:
6398
6418
  readGrantBrokers: !record.machineId && process.env.COMMONLY_MANAGED_RUNNER !== '1',
6399
6419
  spawnCredentialTtlSeconds: resolveSpawnTtlSeconds(process.env),
6400
6420
  refusalHandoff: opts.refusalHandoff || null,
6421
+ commitAttribution: commitAttributionEnabled(record),
6401
6422
  log: (line) => console.log(`${stamp()} [${name}] ${line}`),
6402
6423
  // Both sinks are stamped, and both must be — but not for the reason
6403
6424
  // this comment gave until now, which its own PR falsified.
@@ -1512,6 +1512,41 @@ const resolveClaudeInstall = (env) => {
1512
1512
  }
1513
1513
  };
1514
1514
 
1515
+ /**
1516
+ * F647: how the sign-in probe (`claude auth status`) runs for a seat, so it
1517
+ * reads the login the way the seat's turn does. A seat confined by Seatbelt
1518
+ * (public or workspace trust on macOS) gets its turn's state folder as HOME,
1519
+ * its turn's stripped environment and its turn's Seatbelt profile; a login the
1520
+ * jail can't read then reports signed out at setup, not at the first mention.
1521
+ * null for every other seat, which keeps the plain probe. `_prepareState` is a
1522
+ * test seam for the state folder.
1523
+ */
1524
+ export const claudeLoginProbeLaunch = async (args, {
1525
+ environment = null,
1526
+ agentName = null,
1527
+ env = process.env,
1528
+ platform = process.platform,
1529
+ _prepareState = preparePublicClaudeState,
1530
+ } = {}) => {
1531
+ // Normalized as `spawn` does: a saved `internal` seat's turn runs as `public`,
1532
+ // so its probe must too, or it reports signed in without the jail's view.
1533
+ const sandbox = normalizeSandboxTrust(environment?.sandbox);
1534
+ if (platform !== 'darwin' || !isConfinedTrust(sandbox?.trust)
1535
+ || !PUBLIC_SANDBOX_MODES.has(resolvePublicSandboxMode(sandbox, platform))) return null;
1536
+ // The turn's own state folder, keyed on the same name, with its keychain link.
1537
+ const state = await _prepareState({ agentName });
1538
+ const claudeEnv = withClaudePath(buildClaudeEnv(env, state, {}, null, true, platform));
1539
+ const claudeBin = resolveClaudePath(claudeEnv);
1540
+ const wrapped = wrapArgvWithSeatbelt([claudeBin, ...args], {
1541
+ workspacePath: state.tmpPath,
1542
+ workspaceAccess: 'read',
1543
+ executablePath: claudeBin,
1544
+ statePath: state.statePath,
1545
+ allowClaudeRuntimeAccess: true,
1546
+ });
1547
+ return { command: wrapped[0], args: wrapped.slice(1), env: claudeEnv, cwd: state.tmpPath };
1548
+ };
1549
+
1515
1550
  // A jail that cannot carry claude would fail inside at every spawn.
1516
1551
  const claudeInstallRefusal = (claudeBin) => new Error(
1517
1552
  'Claude agents on Linux need Claude Code on PATH, so the sandbox can carry its install; '
@@ -389,3 +389,25 @@ export const prepareCommitAttribution = ({
389
389
  };
390
390
 
391
391
  export const supportedGitHooks = () => [...GIT_HOOKS];
392
+
393
+ // F656: the person can turn the trailers off for one agent. The choice lives
394
+ // on the agent's local record as `commitAttribution: false`; any other value,
395
+ // or none, is on. Off means prepareCommitAttribution is never called, so no
396
+ // hooks directory, core.hooksPath overlay or COMMONLY_AGENT_* metadata exists.
397
+ export const commitAttributionEnabled = (record) => record?.commitAttribution !== false;
398
+
399
+ /**
400
+ * The record after `agent run`'s flag: false saves off, true removes the field
401
+ * (the default again), undefined (no flag, as a daemon-started seat runs)
402
+ * keeps the saved choice. The same object comes back when nothing changes.
403
+ */
404
+ export const withCommitAttributionChoice = (record, flag) => {
405
+ if (flag === false) {
406
+ return record.commitAttribution === false ? record : { ...record, commitAttribution: false };
407
+ }
408
+ if (flag === true && Object.hasOwn(record, 'commitAttribution')) {
409
+ const { commitAttribution: _cleared, ...rest } = record;
410
+ return rest;
411
+ }
412
+ return record;
413
+ };
@@ -15,7 +15,7 @@ import { readFileSync } from 'fs';
15
15
  import { checkNode, FAIL } from './doctor.js';
16
16
  import { loginState } from './adapter-login.js';
17
17
  import { missingHarnessHint } from './missing-harness.js';
18
- import { withClaudePath } from './adapters/claude.js';
18
+ import { claudeLoginProbeLaunch, withClaudePath } from './adapters/claude.js';
19
19
  import { resolveWindowsCommandWithReason } from './windows-command.js';
20
20
 
21
21
  // The reason codes the instance accepts (POST /api/agents/runtime/listen-blocked).
@@ -66,33 +66,57 @@ export const nodeFinding = ({ nodeVersion = process.versions.node, enginesRange
66
66
  * on Windows a name cmd can't find exits 1, which is the signed-out code, and
67
67
  * would stop a run that is signed in. null when the command can't be resolved
68
68
  * or the probe can't run or times out (no verdict).
69
+ *
70
+ * F647: given the seat's `environment` and name, a Claude seat confined by
71
+ * Seatbelt is probed inside its own sandbox (the turn's profile, HOME and
72
+ * environment), so a login the jail can't read is not reported signed in. A
73
+ * sandboxed probe that can't be prepared is no verdict, as any other.
69
74
  */
70
- export const runHarnessLoginStatus = (name, args, {
75
+ const plainProbeLaunch = (name, args, { env, platform, resolve }) => {
76
+ const childEnv = name === 'claude' ? withClaudePath(env) : env;
77
+ const located = resolve(name, { env: childEnv, platform });
78
+ if (!located?.command) return null;
79
+ return { command: located.command, args: [...(located.args || []), ...args], env: childEnv };
80
+ };
81
+
82
+ export const runHarnessLoginStatus = async (name, args, {
71
83
  env = process.env,
72
84
  platform = process.platform,
73
85
  resolve = resolveWindowsCommandWithReason,
74
86
  spawnFn = spawn,
75
87
  timeoutMs = 10_000,
76
- } = {}) => new Promise((done) => {
77
- const childEnv = name === 'claude' ? withClaudePath(env) : env;
78
- const located = resolve(name, { env: childEnv, platform });
79
- if (!located?.command) {
80
- done(null);
81
- return;
82
- }
83
- let child;
88
+ environment = null,
89
+ agentName = null,
90
+ _prepareClaudeState,
91
+ } = {}) => {
92
+ let launch = null;
84
93
  try {
85
- child = spawnFn(located.command, [...(located.args || []), ...args], {
86
- stdio: 'ignore', windowsHide: true, env: childEnv, shell: false,
87
- });
94
+ if (name === 'claude' && environment) {
95
+ launch = await claudeLoginProbeLaunch(args, {
96
+ environment, agentName, env, platform,
97
+ ...(_prepareClaudeState ? { _prepareState: _prepareClaudeState } : {}),
98
+ });
99
+ }
88
100
  } catch {
89
- done(null);
90
- return;
101
+ return null;
91
102
  }
92
- const timer = setTimeout(() => { child.kill(); done(null); }, timeoutMs);
93
- child.on('error', () => { clearTimeout(timer); done(null); });
94
- child.on('exit', (code) => { clearTimeout(timer); done(typeof code === 'number' ? code : null); });
95
- });
103
+ launch = launch || plainProbeLaunch(name, args, { env, platform, resolve });
104
+ if (!launch) return null;
105
+ return new Promise((done) => {
106
+ let child;
107
+ try {
108
+ child = spawnFn(launch.command, launch.args, {
109
+ stdio: 'ignore', windowsHide: true, env: launch.env, shell: false, ...(launch.cwd ? { cwd: launch.cwd } : {}),
110
+ });
111
+ } catch {
112
+ done(null);
113
+ return;
114
+ }
115
+ const timer = setTimeout(() => { child.kill(); done(null); }, timeoutMs);
116
+ child.on('error', () => { clearTimeout(timer); done(null); });
117
+ child.on('exit', (code) => { clearTimeout(timer); done(typeof code === 'number' ? code : null); });
118
+ });
119
+ };
96
120
 
97
121
  /**
98
122
  * The harness findings for one adapter: not installed, or installed and not
@@ -105,9 +129,11 @@ export const harnessFindings = async ({
105
129
  adapterName,
106
130
  adapter,
107
131
  environment = null,
132
+ // The seat's name, which keys its sandbox state folder (F647).
133
+ agentName = null,
108
134
  checkInstalled = true,
109
135
  env = process.env,
110
- runStatus = (name, args) => runHarnessLoginStatus(name, args, { env }),
136
+ runStatus = (name, args) => runHarnessLoginStatus(name, args, { env, environment, agentName }),
111
137
  }) => {
112
138
  if (!adapter || !adapterName) return [];
113
139
  if (checkInstalled) {
@@ -431,6 +431,30 @@ const isSymlink = (path) => {
431
431
  }
432
432
  };
433
433
 
434
+ // F647: a confined Claude seat's HOME is its own state folder, whose
435
+ // Library/Keychains is a link to the person's real one (preparePublicClaudeState
436
+ // in adapters/claude.js). Seatbelt checks the path a link resolves to, so the
437
+ // login keychain is admitted at that resolved path too, resolved once here. It
438
+ // is admitted only when it is the login keychain directly inside the person's
439
+ // own Library/Keychains: a link the seat's folder holds to anywhere else adds
440
+ // nothing, and never a folder.
441
+ const LOGIN_KEYCHAIN = 'login.keychain-db';
442
+ const linkedLoginKeychain = (seatHome, personHome) => {
443
+ const seatKeychains = join(seatHome, 'Library', 'Keychains');
444
+ const seatLogin = join(seatKeychains, LOGIN_KEYCHAIN);
445
+ if (!isSymlink(seatKeychains) && !isSymlink(seatLogin)) return null;
446
+ let resolved;
447
+ try {
448
+ resolved = realpathSync(seatLogin);
449
+ } catch {
450
+ return null;
451
+ }
452
+ const personKeychains = join(personHome, 'Library', 'Keychains');
453
+ const allowedFolders = new Set([personKeychains, realpathOrSelf(personKeychains)]);
454
+ if (basename(resolved) !== LOGIN_KEYCHAIN || !allowedFolders.has(dirname(resolved))) return null;
455
+ return resolved;
456
+ };
457
+
434
458
  // The two xcode-select links. The xcrun shim reads developer_dir; both name
435
459
  // the same folder on a normal install, and a turn admits each target.
436
460
  const XCODE_SELECT_LINKS = Object.freeze(['/private/var/select/developer_dir', '/private/var/db/xcode_select_link']);
@@ -664,6 +688,9 @@ export const buildSeatbeltProfile = ({
664
688
  hostReadDirectories = [],
665
689
  // The home folder those rules are judged against. Tests pass a temp one.
666
690
  hostReadHome = homedir(),
691
+ // The person whose login keychain a Claude seat reads (F647). Tests pass a
692
+ // temp one.
693
+ keychainHome = homedir(),
667
694
  loopbackNetworkPorts = [],
668
695
  allowClaudeRuntimeAccess = false,
669
696
  // 'open' (the default) or 'loopback': only the listed loopback ports.
@@ -826,11 +853,16 @@ export const buildSeatbeltProfile = ({
826
853
  // temp files on the machine, so it is not admitted.
827
854
  // Claude's security helper needs the encrypted login-keychain database and
828
855
  // this non-secret locale file: that one file, not the Keychains folder.
829
- const loginKeychain = join(homedir(), 'Library', 'Keychains', 'login.keychain-db');
830
- const textEncoding = join(homedir(), '.CFUserTextEncoding');
856
+ const loginKeychain = join(keychainHome, 'Library', 'Keychains', LOGIN_KEYCHAIN);
857
+ const textEncoding = join(keychainHome, '.CFUserTextEncoding');
858
+ const linked = linkedLoginKeychain(resolvedState, keychainHome);
831
859
  return [
832
860
  `(allow file-read* file-test-existence ${literal(loginKeychain)} ${literal(textEncoding)})`,
833
861
  `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(loginKeychain)}"))`,
862
+ ...(linked && linked !== loginKeychain ? [
863
+ `(allow file-read* file-test-existence ${literal(linked)})`,
864
+ `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(linked)}"))`,
865
+ ] : []),
834
866
  ];
835
867
  })() : [];
836
868