@commonlyai/cli 0.1.321 → 0.1.322

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.321",
3
+ "version": "0.1.322",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -25,7 +25,8 @@ import {
25
25
  } from '../lib/daemon-supervisor.js';
26
26
  import { loadAgentToken, saveAgentToken } from './agent.js';
27
27
  import { getLastTurn } from '../lib/session-store.js';
28
- import { getAdapter, providerKeyEnvNames } from '../lib/adapters/index.js';
28
+ import { getAdapter, providerKeyEnvNames, seatProviderKeyEnv } from '../lib/adapters/index.js';
29
+ import { runLoginStatus, signedOutAdapters, signedOutHint } from '../lib/adapter-login.js';
29
30
  import {
30
31
  installDaemonService,
31
32
  installSummary,
@@ -34,7 +35,6 @@ import {
34
35
  stopDaemonService,
35
36
  restartDaemonService,
36
37
  daemonLogPath,
37
- missingProviderKeys,
38
38
  servicePaths,
39
39
  } from '../lib/daemon-service.js';
40
40
  import { daemonLogsDir, daemonSeatLogPath, readLogTail } from '../lib/daemon-logs.js';
@@ -397,6 +397,13 @@ Examples:
397
397
  : reject(new Error(`\`commonly ${args.join(' ')}\` exited with code ${code}`))));
398
398
  }),
399
399
  });
400
+ // Growth's F370 walk: setup said all was well, and the first @mention
401
+ // then failed with "claude exited 1: Not logged in".
402
+ const signedOut = await signedOutAdapters({
403
+ detect: (name) => getAdapter(name)?.detect(),
404
+ runStatus: runLoginStatus,
405
+ });
406
+ for (const name of signedOut) console.log(`Note: ${signedOutHint(name)}.`);
400
407
  } catch (error) {
401
408
  console.error(`Daemon setup failed: ${error.message}`);
402
409
  process.exitCode = 1;
@@ -652,19 +659,25 @@ Examples:
652
659
  chmodSync(logsDir, 0o700);
653
660
  const stampLog = (line) => console.log(`${new Date().toISOString()} ${line}`);
654
661
 
655
- // TASK-049: fail loudly at BIND, once, naming the variable.
662
+ // TASK-049: fail loudly, once, naming the variable.
656
663
  //
657
664
  // A service-started daemon inherits a clean environment, so a provider
658
- // key that lives only in the operator's shell is absent here; every pi
659
- // seat then dies at adapter start with `COMMONLY_LITELLM_KEY is not set`
660
- // and the operator sees crash loops with no cause at daemon level. One
661
- // line at startup answers the question the log would otherwise take a
662
- // seat autopsy to answer. Not fatal: the daemon's other seats are
663
- // unaffected, and refusing to start would turn one missing key into a
664
- // whole-machine outage.
665
- for (const name of missingProviderKeys({ names: providerKeyEnvNames() })) {
666
- stampLog(`WARNING: ${name} is not set in this environment — a seat that relies on it will fail to start (one with its own provider.keyFile won't). Export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
667
- }
665
+ // key that lives only in the operator's shell is absent here; a pi seat
666
+ // then dies at adapter start with `COMMONLY_LITELLM_KEY is not set` and
667
+ // the operator sees crash loops with no cause at daemon level. The
668
+ // warning names the seat that needs the key, when that seat starts:
669
+ // at daemon start it went to every BYO user, who needs none of them
670
+ // (Growth's F370 walk). Not fatal: the daemon's other seats are
671
+ // unaffected.
672
+ const warnedKeys = new Set();
673
+ const warnMissingSeatKey = (agentName) => {
674
+ let saved = null;
675
+ try { saved = loadAgentToken(agentName); } catch { return; }
676
+ const name = seatProviderKeyEnv({ adapter: saved?.adapter, environment: saved?.environment });
677
+ if (!name || process.env[name] || warnedKeys.has(`${agentName}:${name}`)) return;
678
+ warnedKeys.add(`${agentName}:${name}`);
679
+ stampLog(`WARNING: [${agentName}] needs ${name}, which is not set in this environment, so it will fail to start (a provider.keyFile avoids this); export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
680
+ };
668
681
  // TASK-660: the daemon outlives many publishes, so say once at start-up
669
682
  // when it is stale. Not awaited: supervision never waits on the registry.
670
683
  startUpdateNotice({ installedVersion: installedCliVersion(), log: stampLog });
@@ -703,6 +716,7 @@ Examples:
703
716
  // ordinary `commonly agent run <name>` — the daemon is its
704
717
  // supervisor, never its replacement (D6).
705
718
  spawnChild: (agentName) => {
719
+ warnMissingSeatKey(agentName);
706
720
  const seatLog = daemonSeatLogPath(agentName);
707
721
  const out = openSync(seatLog, 'a', 0o600);
708
722
  chmodSync(seatLog, 0o600);
@@ -11,6 +11,7 @@ import { getToken, resolveInstance, resolveInstanceUrl } from '../lib/config.js'
11
11
  import { loadDaemonRecord } from '../lib/daemon-store.js';
12
12
  import { servicePaths } from '../lib/daemon-service.js';
13
13
  import { getAdapter } from '../lib/adapters/index.js';
14
+ import { runLoginStatus, signedOutAdapters } from '../lib/adapter-login.js';
14
15
  import { detectSeatbelt } from '../lib/sandbox/seatbelt.js';
15
16
  import { daemonStatusErrorMessage, getDaemonMachineStatus } from './daemon.js';
16
17
  import { listLocalAgents, listUnreadableAgentTokens } from './agent.js';
@@ -109,6 +110,10 @@ export const hostDoctorDeps = ({ instance: instanceArg = null } = {}) => ({
109
110
  describeError: daemonStatusErrorMessage,
110
111
  now: Date.now(),
111
112
  },
113
+ adapterLogin: () => signedOutAdapters({
114
+ detect: (name) => getAdapter(name)?.detect(),
115
+ runStatus: runLoginStatus,
116
+ }),
112
117
  macos: {
113
118
  platform: process.platform,
114
119
  detectSeatbelt,
@@ -0,0 +1,63 @@
1
+ import { spawn } from 'child_process';
2
+
3
+ // Whether each installed CLI adapter is signed in, by the exit code of its own
4
+ // status command. A stranger on a fresh computer otherwise learns it from a
5
+ // failed @mention ("claude exited 1: Not logged in"), after setup said all was
6
+ // well (Growth's F370 hand walk). Only the exit code is read: the commands'
7
+ // output, which names the account, is never captured or printed.
8
+ //
9
+ // Both commands exit 1 when signed out (checked 2026-11-10 under an empty HOME:
10
+ // `claude auth status --json`, `codex login status`). opencode is left out: its
11
+ // `auth list` was not checked, and a guessed probe would cry wolf.
12
+ export const LOGIN_STATUS_ARGS = {
13
+ claude: ['auth', 'status', '--json'],
14
+ codex: ['login', 'status'],
15
+ };
16
+
17
+ // Credentials a seat runs on without a CLI login, so the probe is skipped.
18
+ // codex's are the ones codexAuthKind and the proxy route accept (adapters/
19
+ // codex.js), even though `codex login status` exits 1 with only a key set.
20
+ const KEY_ENV = {
21
+ claude: ['ANTHROPIC_API_KEY'],
22
+ codex: ['OPENAI_API_KEY', 'CODEX_API_KEY', 'CODEX_ACCESS_TOKEN'],
23
+ };
24
+ const envSet = (env, name) => typeof env[name] === 'string' && env[name].trim() !== '';
25
+
26
+ // Both CLIs exit exactly 1 when signed out. Any other non-zero code (2 for an
27
+ // unknown subcommand on an old CLI) is no verdict, not "signed out".
28
+ const SIGNED_OUT_EXIT = 1;
29
+
30
+ export const signedOutHint = (name) => `${name} is installed but not signed in; run \`${name}\` once to log in before adding an agent`;
31
+
32
+ /**
33
+ * The installed adapters that report signed out. `detect(name)` resolves truthy
34
+ * when the CLI is installed; `runStatus(name, args)` resolves its exit code, or
35
+ * null when it could not be run (timeout, spawn error), which is not a verdict.
36
+ */
37
+ export const signedOutAdapters = async ({ detect, runStatus, env = process.env, names = Object.keys(LOGIN_STATUS_ARGS) }) => {
38
+ const out = [];
39
+ for (const name of names) {
40
+ if (!LOGIN_STATUS_ARGS[name] || (KEY_ENV[name] || []).some((key) => envSet(env, key))) continue;
41
+ let installed = false;
42
+ try { installed = Boolean(await detect(name)); } catch { /* not installed */ }
43
+ if (!installed) continue;
44
+ const code = await runStatus(name, LOGIN_STATUS_ARGS[name]).catch(() => null);
45
+ if (code === SIGNED_OUT_EXIT) out.push(name);
46
+ }
47
+ return out;
48
+ };
49
+
50
+ // The exit code of `<name> <args>`, with every stream discarded. null when it
51
+ // cannot run or takes longer than `timeoutMs` (a CLI that opens a prompt).
52
+ export const runLoginStatus = (name, args, { timeoutMs = 10_000, spawnFn = spawn } = {}) => new Promise((done) => {
53
+ let child;
54
+ try {
55
+ child = spawnFn(name, args, { stdio: 'ignore', windowsHide: true, shell: process.platform === 'win32' });
56
+ } catch {
57
+ done(null);
58
+ return;
59
+ }
60
+ const timer = setTimeout(() => { child.kill(); done(null); }, timeoutMs);
61
+ child.on('error', () => { clearTimeout(timer); done(null); });
62
+ child.on('exit', (code) => { clearTimeout(timer); done(typeof code === 'number' ? code : null); });
63
+ });
@@ -51,3 +51,18 @@ export const getAdapter = (name) => ADAPTERS[name] || null;
51
51
  export const providerKeyEnvNames = (adapters = ADAPTERS) => [...new Set(
52
52
  Object.values(adapters).map((adapter) => adapter.providerKeyEnv).filter(Boolean),
53
53
  )];
54
+
55
+ /**
56
+ * The provider key ONE seat reads from the environment, or null when it reads
57
+ * none: its adapter signs in through its own CLI (claude, codex), or its
58
+ * provider block names a keyFile. The daemon warns per seat with this, so a
59
+ * BYO computer running only claude never hears about keys it has no use for
60
+ * (Growth's F370 walk).
61
+ */
62
+ export const seatProviderKeyEnv = ({ adapter, environment, adapters = ADAPTERS } = {}) => {
63
+ const declared = adapters[adapter]?.providerKeyEnv;
64
+ if (!declared) return null;
65
+ const provider = environment?.provider;
66
+ if (provider?.keyFile) return null;
67
+ return provider?.apiKeyEnv || declared;
68
+ };
package/src/lib/doctor.js CHANGED
@@ -15,6 +15,7 @@
15
15
  import { delimiter, join } from 'node:path';
16
16
  import { DAEMON_SETUP_LINE, runsFromStableInstall } from './stable-install.js';
17
17
  import { parseVersion, versionOlderThan } from './mcp-server-version.js';
18
+ import { signedOutHint } from './adapter-login.js';
18
19
 
19
20
  export const PASS = 'pass';
20
21
  export const FAIL = 'fail';
@@ -234,6 +235,20 @@ export const checkMacClaude = ({
234
235
  return result('macos-claude', PASS, 'Seatbelt runs, the login keychain and /usr/bin/security are present');
235
236
  };
236
237
 
238
+ // (g) Each installed CLI adapter's own sign-in (adapter-login.js). A fail only
239
+ // when an agent here uses the signed-out one; otherwise the line still says it,
240
+ // since the next agent added may pick that adapter.
241
+ export const checkAdapterLogin = async ({ agents = [], probe }) => {
242
+ if (!probe) return result('adapter-login', SKIP, 'no login probe on this host');
243
+ const signedOut = await probe();
244
+ if (!signedOut.length) return result('adapter-login', PASS, 'every installed claude or codex is signed in');
245
+ const detail = signedOut.map(signedOutHint).join('; ');
246
+ const used = signedOut.filter((name) => agents.some((agent) => agent?.adapter === name));
247
+ return used.length
248
+ ? result('adapter-login', FAIL, detail, `run ${used.map((name) => `\`${name}\``).join(' and ')} once to log in`)
249
+ : result('adapter-login', PASS, detail);
250
+ };
251
+
237
252
  /** Every check, in the order the lines print. */
238
253
  export const runDoctor = async (deps) => {
239
254
  // An unreadable tokens dir is one fail line, not a doctor that prints nothing.
@@ -259,6 +274,7 @@ export const runDoctor = async (deps) => {
259
274
  : [
260
275
  ...(await checkAdapters({ agents, getAdapter: deps.getAdapter, unreadable })),
261
276
  checkMacClaude({ ...deps.macos, agents }),
277
+ await checkAdapterLogin({ agents, probe: deps.adapterLogin }),
262
278
  ]),
263
279
  ];
264
280
  };