@commonlyai/cli 0.1.377 → 0.1.379
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/agent.js +69 -5
- package/src/lib/adapters/claude.js +1 -1
- package/src/lib/run-preflight.js +149 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -39,6 +39,9 @@ import { startPoller, terminalDeliveryAckError } from '../lib/poller.js';
|
|
|
39
39
|
import { formatDigestFrame, formatUnreadMessagesFrame } from '../lib/digest-frame.js';
|
|
40
40
|
import { startWebhookServer, forwardToLocalWebhook, logOnlyHandler } from '../lib/webhook-server.js';
|
|
41
41
|
import { getAdapter, listAdapterNames, listPublicAdapterNames } from '../lib/adapters/index.js';
|
|
42
|
+
import {
|
|
43
|
+
harnessFindings, nodeFinding, preflightOutcome, reportListenBlocked,
|
|
44
|
+
} from '../lib/run-preflight.js';
|
|
42
45
|
import {
|
|
43
46
|
getSession,
|
|
44
47
|
getSessionEntry,
|
|
@@ -1867,6 +1870,24 @@ const FINAL_TEXT_IS_POSTED = 'Your final text is posted to the pod unless it is
|
|
|
1867
1870
|
// predicate, so the line and the drop can't disagree.
|
|
1868
1871
|
const seatPostsForItself = (environment) => (environment?.mcp || [])
|
|
1869
1872
|
.some((server) => server?.name === COMMONLY_MCP_SERVER_NAME);
|
|
1873
|
+
// F483: a reaction is the third way to close a wake, beside a post and
|
|
1874
|
+
// NO_REPLY, for the turn whose whole answer would be "thanks" or "got it". It is
|
|
1875
|
+
// offered only where the spawn carries the commonly tools: the seat declares the
|
|
1876
|
+
// server AND its adapter wires the declared servers into the spawn. The CLI's
|
|
1877
|
+
// Hermes adapter passes no MCP server to Hermes (the Hermes plugin is a separate,
|
|
1878
|
+
// standalone install), so a Hermes seat is never told about a tool it lacks
|
|
1879
|
+
// (CodeRabbit on #2816). Add an adapter here only once its spawn wires `mcp`.
|
|
1880
|
+
const ADAPTERS_THAT_WIRE_MCP = new Set(['claude', 'codex', 'opencode', 'goose', 'pi', 'qwen', 'dsh']);
|
|
1881
|
+
export const seatCanReact = (adapterName, environment) => (
|
|
1882
|
+
ADAPTERS_THAT_WIRE_MCP.has(String(adapterName || '')) && seatPostsForItself(environment)
|
|
1883
|
+
);
|
|
1884
|
+
const REACTION_CLOSES_A_WAKE = 'If an acknowledgement is all you would post, react to the message you would acknowledge '
|
|
1885
|
+
+ '(commonly_react_to_message with its message id) instead, then end with NO_REPLY.';
|
|
1886
|
+
// Only a shown item the seat may act on gives the reaction a target: a peer's
|
|
1887
|
+
// read-only item is not one, an item already settled this batch (a duplicate)
|
|
1888
|
+
// is only context, and an ask response or a ruling carries no id.
|
|
1889
|
+
export const reactableEntry = (entry) => !entry.readOnly && !entry.result
|
|
1890
|
+
&& Boolean(entry.event?.payload?.messageId);
|
|
1870
1891
|
const HEARTBEAT_TEXT_IS_NOT_POSTED = 'This turn is only a heartbeat: nobody asked you anything, and your final text is not posted. '
|
|
1871
1892
|
+ 'If something needs saying, post it with commonly_post_message, then end with NO_REPLY. '
|
|
1872
1893
|
+ 'Otherwise end with NO_REPLY alone, with no summary.';
|
|
@@ -3765,6 +3786,8 @@ export const performRun = ({
|
|
|
3765
3786
|
? `Do not narrate the inbox. ${HEARTBEAT_TEXT_IS_NOT_POSTED}`
|
|
3766
3787
|
: 'Do not narrate the inbox. Post only an action or a materially useful response; otherwise return NO_REPLY. '
|
|
3767
3788
|
+ FINAL_TEXT_IS_POSTED
|
|
3789
|
+
+ (seatCanReact(adapter?.name, seatEnvironment) && shownEntries.some(reactableEntry)
|
|
3790
|
+
? ` ${REACTION_CLOSES_A_WAKE}` : '')
|
|
3768
3791
|
+ roomQuestionLine(pod, shownEntries)),
|
|
3769
3792
|
].join('\n\n');
|
|
3770
3793
|
};
|
|
@@ -5871,6 +5894,23 @@ Docs:
|
|
|
5871
5894
|
name = agentArg;
|
|
5872
5895
|
}
|
|
5873
5896
|
}
|
|
5897
|
+
// F515: Node first, before anything uses the token: on a Node without
|
|
5898
|
+
// fetch, the first call fails and reads as a bad token. A first run stops
|
|
5899
|
+
// here and says so, telling the instance when it can; a seat with a saved
|
|
5900
|
+
// record only warns.
|
|
5901
|
+
const oldNode = nodeFinding();
|
|
5902
|
+
const nodeOutcome = preflightOutcome(oldNode ? [oldNode] : [], { firstRun: !record });
|
|
5903
|
+
for (const line of nodeOutcome.lines) console.error(`${stamp()} [${name}] ${line}`);
|
|
5904
|
+
if (nodeOutcome.stop) {
|
|
5905
|
+
const envToken = (process.env.COMMONLY_AGENT_TOKEN || '').trim();
|
|
5906
|
+
if (envToken.startsWith('cm_agent_') && typeof fetch === 'function') {
|
|
5907
|
+
await reportListenBlocked(createClient({
|
|
5908
|
+
instance: (process.env.COMMONLY_API_URL || '').trim() || resolveInstanceUrl(undefined),
|
|
5909
|
+
token: envToken,
|
|
5910
|
+
}), nodeOutcome.report);
|
|
5911
|
+
}
|
|
5912
|
+
process.exit(1);
|
|
5913
|
+
}
|
|
5874
5914
|
let bootstrapped = false;
|
|
5875
5915
|
const saved = record;
|
|
5876
5916
|
const savedRefusal = record && named ? runInstanceRefusal({ record, instanceId }) : null;
|
|
@@ -5904,11 +5944,14 @@ Docs:
|
|
|
5904
5944
|
process.exit(1);
|
|
5905
5945
|
}
|
|
5906
5946
|
if (!record) {
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5947
|
+
// F515: on Windows the page's lines are PowerShell's ($env:…), and in
|
|
5948
|
+
// Command Prompt they set nothing, so this is where that run lands.
|
|
5949
|
+
console.error(process.platform === 'win32'
|
|
5950
|
+
? `No token for '${name}'. Run all the lines from the Connect your own agent page together, `
|
|
5951
|
+
+ 'in PowerShell (not Command Prompt): the $env: lines set the token for this window.'
|
|
5952
|
+
: `No token for '${name}'. Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN`
|
|
5953
|
+
+ ` (shown on the Connect your own agent page) and re-run, or:`
|
|
5954
|
+
+ ` ${CLI} agent attach <adapter> --pod <podId> --name ${agentArg}`);
|
|
5912
5955
|
process.exit(1);
|
|
5913
5956
|
}
|
|
5914
5957
|
const instanceRefusal = named ? runInstanceRefusal({ record, instanceId }) : null;
|
|
@@ -5919,6 +5962,27 @@ Docs:
|
|
|
5919
5962
|
bootstrapped = true;
|
|
5920
5963
|
}
|
|
5921
5964
|
|
|
5965
|
+
// F515: the harness this record names, installed and signed in, before
|
|
5966
|
+
// the run starts waiting. A first run has already looked for the harness
|
|
5967
|
+
// (and reported a missing one); it stops on a signed-out one too, and the
|
|
5968
|
+
// instance hears why, so the page and the pod can say it. A seat with a
|
|
5969
|
+
// saved record only warns: a probe that reads it wrong must not stop it.
|
|
5970
|
+
const harnessProblems = await harnessFindings({
|
|
5971
|
+
adapterName: record.adapter,
|
|
5972
|
+
adapter: getAdapter(record.adapter),
|
|
5973
|
+
environment: record.environment,
|
|
5974
|
+
checkInstalled: !bootstrapped,
|
|
5975
|
+
});
|
|
5976
|
+
const harnessOutcome = preflightOutcome(harnessProblems, { firstRun: bootstrapped });
|
|
5977
|
+
for (const line of harnessOutcome.lines) console.error(`${stamp()} [${name}] ${line}`);
|
|
5978
|
+
if (harnessOutcome.stop) {
|
|
5979
|
+
await reportListenBlocked(
|
|
5980
|
+
createClient({ instance: record.instanceUrl, token: record.runtimeToken }),
|
|
5981
|
+
harnessOutcome.report,
|
|
5982
|
+
);
|
|
5983
|
+
process.exit(1);
|
|
5984
|
+
}
|
|
5985
|
+
|
|
5922
5986
|
// On native Windows the user may choose to run without an OS
|
|
5923
5987
|
// sandbox, by typing the flag or by installing the daemon with it (the
|
|
5924
5988
|
// marker is read only by the seats that daemon spawns). Nothing from the
|
|
@@ -1370,7 +1370,7 @@ const createMcpConfig = async (mcpServers, ctx = {}) => {
|
|
|
1370
1370
|
// child environment and to every detection lookup so a daemon does not report
|
|
1371
1371
|
// a false "adapter unavailable" (or hit spawn ENOENT) merely because it was
|
|
1372
1372
|
// started outside an interactive shell.
|
|
1373
|
-
const withClaudePath = (input) => {
|
|
1373
|
+
export const withClaudePath = (input) => {
|
|
1374
1374
|
const output = { ...(input || process.env) };
|
|
1375
1375
|
const localBin = join(homedir(), '.local', 'bin');
|
|
1376
1376
|
// Windows keys are case-insensitive, and a child given both `Path` and a
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// F515: what `agent run` checks before it starts waiting. Both newcomers in the
|
|
2
|
+
// week of 11-09 created an agent and never got it listening: the page waited,
|
|
3
|
+
// and the terminal said nothing they could act on. So the run checks the three
|
|
4
|
+
// things the connect command needs (Node 22+, the harness installed, the
|
|
5
|
+
// harness signed in), and prints one plain line for each that fails.
|
|
6
|
+
//
|
|
7
|
+
// A first run (the pasted command, no saved record) stops on a failure, and
|
|
8
|
+
// tells the instance why, by reason code only, so the page and the pod can say
|
|
9
|
+
// it. A run with a saved record only warns: that is a seat that has run here
|
|
10
|
+
// before, and a login probe that reads it wrong must not take it down.
|
|
11
|
+
|
|
12
|
+
import { spawn } from 'child_process';
|
|
13
|
+
import { readFileSync } from 'fs';
|
|
14
|
+
|
|
15
|
+
import { checkNode, FAIL } from './doctor.js';
|
|
16
|
+
import { loginState } from './adapter-login.js';
|
|
17
|
+
import { missingHarnessHint } from './missing-harness.js';
|
|
18
|
+
import { withClaudePath } from './adapters/claude.js';
|
|
19
|
+
import { resolveWindowsCommandWithReason } from './windows-command.js';
|
|
20
|
+
|
|
21
|
+
// The reason codes the instance accepts (POST /api/agents/runtime/listen-blocked).
|
|
22
|
+
// A code, never text: nothing from this computer but the code is sent.
|
|
23
|
+
export const LISTEN_BLOCKED_REASONS = ['node-too-old', 'harness-signed-out'];
|
|
24
|
+
|
|
25
|
+
// The floor the CLI declares, read as `commonly doctor` reads it.
|
|
26
|
+
const CLI_ENGINES_NODE = (() => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).engines?.node;
|
|
29
|
+
} catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
const LABEL = { claude: 'Claude Code', codex: 'Codex' };
|
|
35
|
+
const SIGN_IN = { claude: 'claude', codex: 'codex login' };
|
|
36
|
+
|
|
37
|
+
/** The Node finding, or null when this Node meets the CLI's floor. */
|
|
38
|
+
export const nodeFinding = ({ nodeVersion = process.versions.node, enginesRange = CLI_ENGINES_NODE } = {}) => {
|
|
39
|
+
const check = checkNode({ nodeVersion, enginesRange });
|
|
40
|
+
if (check.status !== FAIL) return null;
|
|
41
|
+
const floor = /(\d+)/.exec(String(enginesRange || ''))?.[1] || '22';
|
|
42
|
+
return {
|
|
43
|
+
reason: 'node-too-old',
|
|
44
|
+
harness: null,
|
|
45
|
+
line: `This computer has Node ${nodeVersion}, and Commonly needs Node ${floor} or later. `
|
|
46
|
+
+ `Install Node ${floor} from nodejs.org, then run this line again.`,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The exit code of a harness's login status, run as its adapter runs it: the
|
|
52
|
+
* same command `detect()` found (Claude Code with its own ~/.local/bin on
|
|
53
|
+
* PATH, where the native installer puts it), without a shell. Through a shell
|
|
54
|
+
* on Windows a name cmd can't find exits 1, which is the signed-out code, and
|
|
55
|
+
* would stop a run that is signed in. null when the command can't be resolved
|
|
56
|
+
* or the probe can't run or times out (no verdict).
|
|
57
|
+
*/
|
|
58
|
+
export const runHarnessLoginStatus = (name, args, {
|
|
59
|
+
env = process.env,
|
|
60
|
+
platform = process.platform,
|
|
61
|
+
resolve = resolveWindowsCommandWithReason,
|
|
62
|
+
spawnFn = spawn,
|
|
63
|
+
timeoutMs = 10_000,
|
|
64
|
+
} = {}) => new Promise((done) => {
|
|
65
|
+
const childEnv = name === 'claude' ? withClaudePath(env) : env;
|
|
66
|
+
const located = resolve(name, { env: childEnv, platform });
|
|
67
|
+
if (!located?.command) {
|
|
68
|
+
done(null);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let child;
|
|
72
|
+
try {
|
|
73
|
+
child = spawnFn(located.command, [...(located.args || []), ...args], {
|
|
74
|
+
stdio: 'ignore', windowsHide: true, env: childEnv, shell: false,
|
|
75
|
+
});
|
|
76
|
+
} catch {
|
|
77
|
+
done(null);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const timer = setTimeout(() => { child.kill(); done(null); }, timeoutMs);
|
|
81
|
+
child.on('error', () => { clearTimeout(timer); done(null); });
|
|
82
|
+
child.on('exit', (code) => { clearTimeout(timer); done(typeof code === 'number' ? code : null); });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The harness findings for one adapter: not installed, or installed and not
|
|
87
|
+
* signed in. `checkInstalled` is false where the caller has already looked (a
|
|
88
|
+
* first run's bootstrap does, and reports it on its own route). A seat that
|
|
89
|
+
* runs on its own provider block needs no harness login, and a key in the
|
|
90
|
+
* environment is skipped by loginState itself.
|
|
91
|
+
*/
|
|
92
|
+
export const harnessFindings = async ({
|
|
93
|
+
adapterName,
|
|
94
|
+
adapter,
|
|
95
|
+
environment = null,
|
|
96
|
+
checkInstalled = true,
|
|
97
|
+
env = process.env,
|
|
98
|
+
runStatus = (name, args) => runHarnessLoginStatus(name, args, { env }),
|
|
99
|
+
}) => {
|
|
100
|
+
if (!adapter || !adapterName) return [];
|
|
101
|
+
if (checkInstalled) {
|
|
102
|
+
let installed = false;
|
|
103
|
+
try { installed = Boolean(await adapter.detect()); } catch { /* not installed */ }
|
|
104
|
+
if (!installed) {
|
|
105
|
+
return [{
|
|
106
|
+
reason: 'harness-missing',
|
|
107
|
+
harness: adapterName,
|
|
108
|
+
line: `${LABEL[adapterName] || adapterName} isn't installed on this computer. ${missingHarnessHint(adapterName)}`,
|
|
109
|
+
}];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (environment?.provider !== undefined || !LABEL[adapterName]) return [];
|
|
113
|
+
const signedIn = await loginState(adapterName, { runStatus, env });
|
|
114
|
+
if (signedIn !== false) return [];
|
|
115
|
+
return [{
|
|
116
|
+
reason: 'harness-signed-out',
|
|
117
|
+
harness: adapterName,
|
|
118
|
+
line: `${LABEL[adapterName]} is installed but not signed in on this computer. `
|
|
119
|
+
+ `Run ${SIGN_IN[adapterName]} once to sign in, then run this line again.`,
|
|
120
|
+
}];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* What the run does with its findings. A first run (the pasted command) stops,
|
|
125
|
+
* and the first finding is the one reported. A run from a saved record only
|
|
126
|
+
* warns and goes on: that seat has run here before, and a probe that misreads
|
|
127
|
+
* it must not take it down.
|
|
128
|
+
*/
|
|
129
|
+
export const preflightOutcome = (findings, { firstRun }) => {
|
|
130
|
+
if (!findings.length) return { stop: false, lines: [], report: null };
|
|
131
|
+
if (firstRun) return { stop: true, lines: findings.map((f) => f.line), report: findings[0] };
|
|
132
|
+
return { stop: false, lines: findings.map((f) => `warning: ${f.line}`), report: null };
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Tell the instance why this agent isn't listening yet. Best effort, as the
|
|
137
|
+
* harness-missing report: an older instance without the route, or a failed
|
|
138
|
+
* call, must not hide the line the person needs in the terminal (which is
|
|
139
|
+
* printed first). A missing harness has its own route, posted by bootstrap.
|
|
140
|
+
*/
|
|
141
|
+
export const reportListenBlocked = async (client, finding) => {
|
|
142
|
+
if (!finding) return;
|
|
143
|
+
try {
|
|
144
|
+
if (!LISTEN_BLOCKED_REASONS.includes(finding.reason)) return;
|
|
145
|
+
await client?.post?.('/api/agents/runtime/listen-blocked', { reason: finding.reason, harness: finding.harness });
|
|
146
|
+
} catch {
|
|
147
|
+
// The terminal line is the answer either way.
|
|
148
|
+
}
|
|
149
|
+
};
|