@commonlyai/cli 0.1.344 → 0.1.345
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 +1 -1
- package/src/commands/daemon.js +19 -8
- package/src/lib/adapter-login.js +13 -0
- package/src/lib/runtime-inventory.js +11 -4
package/package.json
CHANGED
package/src/commands/daemon.js
CHANGED
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
import { loadAgentToken, saveAgentToken } from './agent.js';
|
|
27
27
|
import { getLastTurn } from '../lib/session-store.js';
|
|
28
28
|
import { getAdapter, providerKeyEnvNames, seatProviderKeyEnv } from '../lib/adapters/index.js';
|
|
29
|
-
import { runLoginStatus, signedOutAdapters, signedOutHint } from '../lib/adapter-login.js';
|
|
29
|
+
import { loginState, runLoginStatus, signedOutAdapters, signedOutHint } from '../lib/adapter-login.js';
|
|
30
|
+
|
|
30
31
|
import {
|
|
31
32
|
installDaemonService,
|
|
32
33
|
installSummary,
|
|
@@ -59,6 +60,9 @@ import { machineHostReport } from '../lib/machine-host.js';
|
|
|
59
60
|
import { orchestrateDaemonSetup } from '../lib/stable-install.js';
|
|
60
61
|
import { CLI } from '../lib/cli-hint.js';
|
|
61
62
|
|
|
63
|
+
// Set on the steps `daemon setup` runs, so a step can leave a line to setup.
|
|
64
|
+
const SETUP_CHILD_ENV = 'COMMONLY_DAEMON_SETUP_STEP';
|
|
65
|
+
|
|
62
66
|
// launchd, systemd and Task Scheduler hold one Commonly daemon per computer
|
|
63
67
|
// account. Install refuses to stop another HOME's; this flag takes it over.
|
|
64
68
|
const REPLACE_FLAG = '--replace';
|
|
@@ -371,6 +375,10 @@ export const firstSupervisionPass = async ({
|
|
|
371
375
|
|
|
372
376
|
export const registerDaemon = (program) => {
|
|
373
377
|
const daemon = program.command('daemon').description('Manage the local Commonly daemon');
|
|
378
|
+
const signedOutNotes = async () => (await signedOutAdapters({
|
|
379
|
+
detect: (name) => getAdapter(name)?.detect(),
|
|
380
|
+
runStatus: runLoginStatus,
|
|
381
|
+
})).map((name) => `Note: ${signedOutHint(name)}.`);
|
|
374
382
|
|
|
375
383
|
daemon.addHelpText('after', `
|
|
376
384
|
The daemon token is scoped to this machine and stored in a 0600 file under
|
|
@@ -411,7 +419,8 @@ Examples:
|
|
|
411
419
|
// device-auth and any prompts work; reject on a non-zero exit so a
|
|
412
420
|
// failed step stops the chain before the next one.
|
|
413
421
|
runCli: (entry, args) => new Promise((resolve, reject) => {
|
|
414
|
-
|
|
422
|
+
// SETUP_CHILD_ENV: register leaves the signed-out note to setup's last line.
|
|
423
|
+
const child = spawn(process.execPath, [entry, ...args], { stdio: 'inherit', env: { ...process.env, [SETUP_CHILD_ENV]: '1' } });
|
|
415
424
|
child.on('error', reject);
|
|
416
425
|
child.on('close', (code) => (code === 0
|
|
417
426
|
? resolve()
|
|
@@ -420,11 +429,7 @@ Examples:
|
|
|
420
429
|
});
|
|
421
430
|
// Growth's F370 walk: setup said all was well, and the first @mention
|
|
422
431
|
// then failed with "claude exited 1: Not logged in".
|
|
423
|
-
const
|
|
424
|
-
detect: (name) => getAdapter(name)?.detect(),
|
|
425
|
-
runStatus: runLoginStatus,
|
|
426
|
-
});
|
|
427
|
-
for (const name of signedOut) console.log(`Note: ${signedOutHint(name)}.`);
|
|
432
|
+
for (const line of await signedOutNotes()) console.log(line);
|
|
428
433
|
} catch (error) {
|
|
429
434
|
console.error(`Daemon setup failed: ${error.message}`);
|
|
430
435
|
process.exitCode = 1;
|
|
@@ -472,6 +477,12 @@ Examples:
|
|
|
472
477
|
if (existing && existsSync(servicePaths(process.platform, homedir()).file)) {
|
|
473
478
|
console.log(`Restart the installed daemon to use the new key: ${CLI} daemon restart`);
|
|
474
479
|
}
|
|
480
|
+
// F458: register run by hand (the F454 walk) said nothing, and the
|
|
481
|
+
// agent looked healthy until its first message failed. Setup prints
|
|
482
|
+
// this itself, after the install step, so its own register doesn't.
|
|
483
|
+
if (!process.env[SETUP_CHILD_ENV]) {
|
|
484
|
+
for (const line of await signedOutNotes()) console.log(line);
|
|
485
|
+
}
|
|
475
486
|
} catch (error) {
|
|
476
487
|
console.error(`Daemon registration failed: ${error.message}`);
|
|
477
488
|
process.exitCode = 1;
|
|
@@ -740,7 +751,7 @@ Examples:
|
|
|
740
751
|
// exit parks it on macOS; systemd honors 77 directly.
|
|
741
752
|
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
742
753
|
};
|
|
743
|
-
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses));
|
|
754
|
+
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses, { loginState }));
|
|
744
755
|
supervisor = createDaemonSupervisor({
|
|
745
756
|
record,
|
|
746
757
|
client,
|
package/src/lib/adapter-login.js
CHANGED
|
@@ -47,6 +47,19 @@ export const signedOutAdapters = async ({ detect, runStatus, env = process.env,
|
|
|
47
47
|
return out;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* One harness's login, for the daemon's inventory (F458): true signed in (exit
|
|
52
|
+
* 0), false signed out (exit 1), null when there is no verdict: no checked
|
|
53
|
+
* probe for it, a key in the environment it runs on instead, or a probe that
|
|
54
|
+
* couldn't run. Only the exit code is read, as above.
|
|
55
|
+
*/
|
|
56
|
+
export const loginState = async (name, { runStatus = runLoginStatus, env = process.env } = {}) => {
|
|
57
|
+
if (!LOGIN_STATUS_ARGS[name] || (KEY_ENV[name] || []).some((key) => envSet(env, key))) return null;
|
|
58
|
+
const code = await runStatus(name, LOGIN_STATUS_ARGS[name]).catch(() => null);
|
|
59
|
+
if (code === 0) return true;
|
|
60
|
+
return code === SIGNED_OUT_EXIT ? false : null;
|
|
61
|
+
};
|
|
62
|
+
|
|
50
63
|
// The exit code of `<name> <args>`, with every stream discarded. null when it
|
|
51
64
|
// cannot run or takes longer than `timeoutMs` (a CLI that opens a prompt).
|
|
52
65
|
export const runLoginStatus = (name, args, { timeoutMs = 10_000, spawnFn = spawn } = {}) => new Promise((done) => {
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
// Probe only the walked adapter's version command. Never enumerate workspace
|
|
2
2
|
// extensions to discover models: a model picker must not execute project code.
|
|
3
3
|
export const WALKED_HARNESSES = ['claude', 'codex', 'opencode', 'hermes', 'dsh'];
|
|
4
|
-
|
|
4
|
+
// `loginState` (F458), when given, adds `signedIn` to an installed harness it
|
|
5
|
+
// has a verdict for, so the page can say "not signed in" before the first
|
|
6
|
+
// message fails instead of after.
|
|
7
|
+
export const collectRuntimeInventory = async (getAdapter, capabilities, harnesses = WALKED_HARNESSES, { loginState } = {}) => Promise.all(harnesses.map(async (harness) => {
|
|
5
8
|
const adapter = getAdapter(harness);
|
|
6
9
|
let detected = null;
|
|
7
10
|
try { detected = await adapter?.detect(); } catch { /* unavailable */ }
|
|
8
11
|
let choices = { models: null, efforts: [] };
|
|
9
12
|
if (detected) { try { choices = (await (capabilities ? capabilities(harness) : adapter?.inventory?.())) || choices; } catch { /* unavailable */ } }
|
|
13
|
+
let signedIn = null;
|
|
14
|
+
if (detected && loginState) { try { signedIn = await loginState(harness); } catch { /* no verdict */ } }
|
|
10
15
|
return { harness, installed: Boolean(detected), version: detected?.version || null,
|
|
11
|
-
models: choices.models, efforts: choices.efforts };
|
|
16
|
+
models: choices.models, efforts: choices.efforts, ...(typeof signedIn === 'boolean' ? { signedIn } : {}) };
|
|
12
17
|
}));
|
|
13
18
|
|
|
14
19
|
// The daemon's inventory, refreshed in full every five minutes. A harness it
|
|
15
20
|
// didn't find is probed again sooner, so one installed while the BYO page is
|
|
16
|
-
// open shows up within a heartbeat or two, without a reload (F370 #8).
|
|
21
|
+
// open shows up within a heartbeat or two, without a reload (F370 #8). One
|
|
22
|
+
// that reported signed out is rechecked the same way, so a sign-in does too (F458).
|
|
17
23
|
// Probes are synchronous: a binary that isn't there fails at once, but one
|
|
18
24
|
// that's there and hangs on --version blocks the daemon for its timeout. A
|
|
19
25
|
// re-probe slower than INVENTORY_SLOW_MS waits for the full refresh instead.
|
|
@@ -34,7 +40,8 @@ export const createInventoryCache = (collect, { now = Date.now } = {}) => {
|
|
|
34
40
|
slow = new Set();
|
|
35
41
|
return cached;
|
|
36
42
|
}
|
|
37
|
-
const missing = cached.filter((row) => !row.installed && !slow.has(row.harness))
|
|
43
|
+
const missing = cached.filter((row) => (!row.installed || row.signedIn === false) && !slow.has(row.harness))
|
|
44
|
+
.map((row) => row.harness);
|
|
38
45
|
if (missing.length && at - missingAt > INVENTORY_MISSING_MS) {
|
|
39
46
|
missingAt = at;
|
|
40
47
|
for (const harness of missing) {
|