@commonlyai/cli 0.1.328 → 0.1.330
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 +47 -46
- package/src/commands/daemon.js +24 -23
- package/src/commands/dev.js +10 -9
- package/src/commands/doctor.js +3 -2
- package/src/commands/inbox.js +16 -15
- package/src/commands/login.js +7 -6
- package/src/commands/mcp.js +3 -2
- package/src/commands/pod.js +8 -7
- package/src/commands/task.js +9 -8
- package/src/index.js +14 -13
- package/src/lib/adapters/claude.js +2 -1
- package/src/lib/adapters/opencode.js +50 -3
- package/src/lib/api.js +2 -1
- package/src/lib/cli-hint.js +33 -0
- package/src/lib/daemon-hint.js +15 -3
- package/src/lib/daemon-service.js +5 -4
- package/src/lib/doctor.js +10 -9
- package/src/lib/mcp-home.js +24 -0
- package/src/lib/model-unavailable.js +2 -1
- package/src/lib/poller.js +2 -1
- package/src/lib/sandbox/host-check.js +3 -2
- package/src/lib/stable-install.js +2 -1
- package/src/lib/task.js +3 -2
- package/src/lib/turn-failure-notice.js +11 -1
- package/src/lib/update-check.js +2 -1
package/src/commands/inbox.js
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
INBOX_KINDS,
|
|
31
31
|
TOKEN_FILE_ENV,
|
|
32
32
|
} from '../lib/inbox.js';
|
|
33
|
+
import { CLI } from '../lib/cli-hint.js';
|
|
33
34
|
|
|
34
35
|
export const INBOX_TOKEN_HELP = `Account token file (or ${TOKEN_FILE_ENV})`;
|
|
35
36
|
|
|
@@ -165,7 +166,7 @@ export const runInboxAck = async (itemId, opts = {}, deps = {}) => {
|
|
|
165
166
|
env = process.env, fetchImpl = fetch, log = console.log, error = console.error, sleep = undefined,
|
|
166
167
|
} = deps;
|
|
167
168
|
try {
|
|
168
|
-
if (!itemId) throw new InboxRefusal(
|
|
169
|
+
if (!itemId) throw new InboxRefusal(`an item id is required: ${CLI} inbox ack <attentionItemId>`);
|
|
169
170
|
const {
|
|
170
171
|
baseUrl, request, account,
|
|
171
172
|
} = await connect(opts, { env, fetchImpl, sleep });
|
|
@@ -180,8 +181,8 @@ export const runInboxAck = async (itemId, opts = {}, deps = {}) => {
|
|
|
180
181
|
if (err instanceof InboxRefusal) return reportRefusal(err, error);
|
|
181
182
|
if (err?.status === 400) {
|
|
182
183
|
error(`Failed: ${err.message}`);
|
|
183
|
-
error(
|
|
184
|
-
+
|
|
184
|
+
error(`Acknowledge takes the item's attentionItemId — the id printed as \`item=…\` by \`${CLI} inbox list\``
|
|
185
|
+
+ ` (the unlabelled source id is what \`${CLI} inbox choose\` takes).`);
|
|
185
186
|
return 1;
|
|
186
187
|
}
|
|
187
188
|
return reportFailure(err, error);
|
|
@@ -221,8 +222,8 @@ export const runInboxChoose = async (decisionId, value, opts = {}, deps = {}) =>
|
|
|
221
222
|
env = process.env, fetchImpl = fetch, log = console.log, error = console.error, sleep = undefined,
|
|
222
223
|
} = deps;
|
|
223
224
|
try {
|
|
224
|
-
if (!decisionId) throw new InboxRefusal(
|
|
225
|
-
if (value === undefined) throw new InboxRefusal(
|
|
225
|
+
if (!decisionId) throw new InboxRefusal(`a decision id is required: ${CLI} inbox choose <decisionId> <n|label>`);
|
|
226
|
+
if (value === undefined) throw new InboxRefusal(`a value is required: ${CLI} inbox choose <decisionId> <n|label>`);
|
|
226
227
|
const {
|
|
227
228
|
baseUrl, request, account,
|
|
228
229
|
} = await connect(opts, { env, fetchImpl, sleep });
|
|
@@ -256,10 +257,10 @@ export const registerInbox = (program) => {
|
|
|
256
257
|
inbox.addHelpText('after', `
|
|
257
258
|
The account is read from a token file and from nowhere else:
|
|
258
259
|
|
|
259
|
-
$
|
|
260
|
-
$ COMMONLY_TOKEN_FILE=~/.commonly/bin/lily-token
|
|
260
|
+
$ ${CLI} inbox list --token-file ~/.commonly/bin/connector-ops-token
|
|
261
|
+
$ COMMONLY_TOKEN_FILE=~/.commonly/bin/lily-token ${CLI} inbox list
|
|
261
262
|
|
|
262
|
-
There is no fallback to the saved login. On a host where
|
|
263
|
+
There is no fallback to the saved login. On a host where \`${CLI} login\` was
|
|
263
264
|
run once as somebody else, a fallback would print that person's queue while the
|
|
264
265
|
operator believed they were reading their own. Every run therefore names the
|
|
265
266
|
account it resolved on its first line.
|
|
@@ -268,13 +269,13 @@ With neither --token-file nor COMMONLY_TOKEN_FILE set, the command refuses
|
|
|
268
269
|
before it makes a request.
|
|
269
270
|
|
|
270
271
|
Examples:
|
|
271
|
-
$
|
|
272
|
-
$
|
|
273
|
-
$
|
|
274
|
-
$
|
|
275
|
-
$
|
|
276
|
-
$
|
|
277
|
-
$
|
|
272
|
+
$ ${CLI} inbox list --json | jq '.items[].title'
|
|
273
|
+
$ ${CLI} inbox list --kind decision --pod <podId>
|
|
274
|
+
$ ${CLI} inbox list --cursor-file ~/.commonly/inbox/connector-ops.cursor # only what is new
|
|
275
|
+
$ ${CLI} inbox list --cursor-file ~/.commonly/inbox/c.cursor --window 300 # widen the re-read to 5m
|
|
276
|
+
$ ${CLI} inbox ack <attentionItemId>
|
|
277
|
+
$ ${CLI} inbox choose <decisionId> 2 # second option of the card, by position
|
|
278
|
+
$ ${CLI} inbox choose <decisionId> "Ship it" # or by its label
|
|
278
279
|
|
|
279
280
|
Cost: with no cursor, \`list\` reads the WHOLE queue, one request per 50 items —
|
|
280
281
|
550 open items is 11 requests. /api/activity is limited to 60 a minute **keyed on
|
package/src/commands/login.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
DeviceLoginExpiredError,
|
|
16
16
|
waitForDeviceAuthorization,
|
|
17
17
|
} from '../lib/device-login.js';
|
|
18
|
+
import { CLI } from '../lib/cli-hint.js';
|
|
18
19
|
|
|
19
20
|
const prompt = (rl, question) => new Promise((resolve) => rl.question(question, resolve));
|
|
20
21
|
|
|
@@ -75,9 +76,9 @@ export const registerLogin = (program) => {
|
|
|
75
76
|
.option('--password', 'Use the legacy email/password prompt instead of device authorization')
|
|
76
77
|
.addHelpText('after', `
|
|
77
78
|
Examples:
|
|
78
|
-
$
|
|
79
|
-
$
|
|
80
|
-
$
|
|
79
|
+
$ ${CLI} login # active profile (production on first run)
|
|
80
|
+
$ ${CLI} login --instance https://api.commonly.me --key dev # named profile
|
|
81
|
+
$ ${CLI} login --instance http://localhost:5000 # saved as "local"
|
|
81
82
|
|
|
82
83
|
Tokens are stored in ~/.commonly/config.json. Other commands take
|
|
83
84
|
--instance <url-or-key> to target the right profile.
|
|
@@ -141,7 +142,7 @@ Tokens are stored in ~/.commonly/config.json. Other commands take
|
|
|
141
142
|
console.log(`Token saved to ~/.commonly/config.json`);
|
|
142
143
|
} catch (err) {
|
|
143
144
|
const message = err instanceof DeviceLoginExpiredError
|
|
144
|
-
? `Code expired after 10 minutes. Run
|
|
145
|
+
? `Code expired after 10 minutes. Run ${CLI} login --instance ${configKey} for a new code.`
|
|
145
146
|
: err instanceof DeviceLoginCancelledError || err instanceof DeviceLoginDeniedError
|
|
146
147
|
? err.message
|
|
147
148
|
: `Login failed: ${err.message}`;
|
|
@@ -161,7 +162,7 @@ export const registerWhoami = (program) => {
|
|
|
161
162
|
const instances = listInstances();
|
|
162
163
|
|
|
163
164
|
if (instances.length === 0) {
|
|
164
|
-
console.log(
|
|
165
|
+
console.log(`Not logged in. Run: ${CLI} login`);
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -187,7 +188,7 @@ export const formatTokenStatus = (token, tokenType, now = Date.now(), instanceKe
|
|
|
187
188
|
const expiresAt = decodeJwtExpiry(token);
|
|
188
189
|
if (!expiresAt) return 'session token · expiry unknown';
|
|
189
190
|
const diff = expiresAt - now;
|
|
190
|
-
if (diff <= 0) return `expired —
|
|
191
|
+
if (diff <= 0) return `expired — ${CLI} login --instance ${instanceKey}`;
|
|
191
192
|
const hours = Math.max(1, Math.ceil(diff / (60 * 60 * 1000)));
|
|
192
193
|
return `expires in ${hours}h`;
|
|
193
194
|
};
|
package/src/commands/mcp.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { listLocalAgents, loadAgentToken } from './agent.js';
|
|
7
7
|
import { validMcpTokenName, writeMcpTokenCopy } from '../lib/mcp-token.js';
|
|
8
|
+
import { CLI } from '../lib/cli-hint.js';
|
|
8
9
|
|
|
9
|
-
const NO_AGENT_HINT =
|
|
10
|
+
const NO_AGENT_HINT = `Attach one first: ${CLI} agent attach <adapter> --pod <podId> --name <name>`;
|
|
10
11
|
|
|
11
12
|
export const buildMcpConfig = ({ agent } = {}) => {
|
|
12
13
|
let name = agent;
|
|
@@ -22,7 +23,7 @@ export const buildMcpConfig = ({ agent } = {}) => {
|
|
|
22
23
|
const record = loadAgentToken(name);
|
|
23
24
|
const token = String(record?.runtimeToken || '').trim();
|
|
24
25
|
if (!token) throw new Error(`No runtime token saved for agent '${name}'. ${NO_AGENT_HINT}`);
|
|
25
|
-
if (!token.startsWith('cm_agent_')) throw new Error(`The saved token for '${name}' is not a cm_agent_* runtime token. Re-attach it:
|
|
26
|
+
if (!token.startsWith('cm_agent_')) throw new Error(`The saved token for '${name}' is not a cm_agent_* runtime token. Re-attach it: ${CLI} agent attach`);
|
|
26
27
|
if (!record.instanceUrl) throw new Error(`Agent '${name}' has no saved instance URL. Re-attach it.`);
|
|
27
28
|
|
|
28
29
|
const tokenPath = writeMcpTokenCopy(name, token);
|
package/src/commands/pod.js
CHANGED
|
@@ -9,18 +9,19 @@
|
|
|
9
9
|
import { createClient } from '../lib/api.js';
|
|
10
10
|
import { getToken, resolveInstanceUrl } from '../lib/config.js';
|
|
11
11
|
import { createTailPoller } from '../lib/pod-tail.js';
|
|
12
|
+
import { CLI } from '../lib/cli-hint.js';
|
|
12
13
|
|
|
13
14
|
export const registerPod = (program) => {
|
|
14
15
|
const pod = program.command('pod').description('Manage pods');
|
|
15
16
|
|
|
16
17
|
pod.addHelpText('after', `
|
|
17
18
|
Examples:
|
|
18
|
-
$
|
|
19
|
-
$
|
|
20
|
-
$
|
|
19
|
+
$ ${CLI} pod list
|
|
20
|
+
$ ${CLI} pod send <podId> "hello from the CLI"
|
|
21
|
+
$ ${CLI} pod tail <podId>
|
|
21
22
|
|
|
22
23
|
Each command accepts --instance <url-or-key> to target a non-default
|
|
23
|
-
Commonly instance (see:
|
|
24
|
+
Commonly instance (see: ${CLI} login --help).
|
|
24
25
|
`);
|
|
25
26
|
|
|
26
27
|
// ── list ──────────────────────────────────────────────────────────────────
|
|
@@ -30,7 +31,7 @@ Commonly instance (see: commonly login --help).
|
|
|
30
31
|
.option('--instance <url>', 'Target Commonly instance')
|
|
31
32
|
.action(async (opts) => {
|
|
32
33
|
const token = getToken(opts.instance);
|
|
33
|
-
if (!token) { console.error(
|
|
34
|
+
if (!token) { console.error(`Not logged in. Run: ${CLI} login`); process.exit(1); }
|
|
34
35
|
|
|
35
36
|
const client = createClient({ instance: resolveInstanceUrl(opts.instance), token });
|
|
36
37
|
|
|
@@ -60,7 +61,7 @@ Commonly instance (see: commonly login --help).
|
|
|
60
61
|
.option('--instance <url>', 'Target Commonly instance')
|
|
61
62
|
.action(async (podId, message, opts) => {
|
|
62
63
|
const token = getToken(opts.instance);
|
|
63
|
-
if (!token) { console.error(
|
|
64
|
+
if (!token) { console.error(`Not logged in. Run: ${CLI} login`); process.exit(1); }
|
|
64
65
|
|
|
65
66
|
const client = createClient({ instance: resolveInstanceUrl(opts.instance), token });
|
|
66
67
|
|
|
@@ -93,7 +94,7 @@ Commonly instance (see: commonly login --help).
|
|
|
93
94
|
.option('--instance <url>', 'Target Commonly instance')
|
|
94
95
|
.action(async (podId, opts) => {
|
|
95
96
|
const token = getToken(opts.instance);
|
|
96
|
-
if (!token) { console.error(
|
|
97
|
+
if (!token) { console.error(`Not logged in. Run: ${CLI} login`); process.exit(1); }
|
|
97
98
|
|
|
98
99
|
const client = createClient({ instance: resolveInstanceUrl(opts.instance), token });
|
|
99
100
|
|
package/src/commands/task.js
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
resolveTaskToken,
|
|
32
32
|
taskPath,
|
|
33
33
|
} from '../lib/task.js';
|
|
34
|
+
import { CLI } from '../lib/cli-hint.js';
|
|
34
35
|
|
|
35
36
|
export const TASK_TOKEN_HELP = `Agent token file (or ${TOKEN_FILE_ENV}, or ${TASK_TOKEN_ENV})`;
|
|
36
37
|
|
|
@@ -191,8 +192,8 @@ export const registerTask = (program) => {
|
|
|
191
192
|
task.addHelpText('after', `
|
|
192
193
|
The board is read and written as the identity in a token file, and nowhere else:
|
|
193
194
|
|
|
194
|
-
$
|
|
195
|
-
$ COMMONLY_AGENT_TOKEN=<token>
|
|
195
|
+
$ ${CLI} task list --pod <podId> --token-file <path>
|
|
196
|
+
$ COMMONLY_AGENT_TOKEN=<token> ${CLI} task claim TASK-123 --pod <podId>
|
|
196
197
|
|
|
197
198
|
The identity is --token-file, then COMMONLY_TOKEN_FILE, then COMMONLY_AGENT_TOKEN.
|
|
198
199
|
The saved login and COMMONLY_TOKEN are never read: a write made under an
|
|
@@ -207,12 +208,12 @@ A claim or a note can refuse with unseen messages in the pod. Read them and retr
|
|
|
207
208
|
or pass --continue-anyway to go ahead without reading them.
|
|
208
209
|
|
|
209
210
|
Examples:
|
|
210
|
-
$
|
|
211
|
-
$
|
|
212
|
-
$
|
|
213
|
-
$
|
|
214
|
-
$
|
|
215
|
-
$
|
|
211
|
+
$ ${CLI} task list --pod <podId> --status pending,claimed
|
|
212
|
+
$ ${CLI} task list --pod <podId> --mine --json
|
|
213
|
+
$ ${CLI} task create --pod <podId> --title "Fix the board" --priority P1 --notes "Repro in staging"
|
|
214
|
+
$ ${CLI} task claim TASK-123 --pod <podId>
|
|
215
|
+
$ ${CLI} task update TASK-123 --pod <podId> --note "PR is up"
|
|
216
|
+
$ ${CLI} task close TASK-123 --pod <podId> --pr https://github.com/Team-Commonly/commonly/pull/<n>
|
|
216
217
|
`);
|
|
217
218
|
|
|
218
219
|
task
|
package/src/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { registerVerify } from './commands/verify.js';
|
|
|
24
24
|
import { registerDoctor } from './commands/doctor.js';
|
|
25
25
|
import { registerMcp } from './commands/mcp.js';
|
|
26
26
|
import { registerTask } from './commands/task.js';
|
|
27
|
+
import { CLI } from './lib/cli-hint.js';
|
|
27
28
|
|
|
28
29
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
29
30
|
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
|
|
@@ -70,24 +71,24 @@ registerTask(program);
|
|
|
70
71
|
|
|
71
72
|
program.addHelpText('after', `
|
|
72
73
|
Quick start:
|
|
73
|
-
$
|
|
74
|
-
$
|
|
75
|
-
$
|
|
76
|
-
$
|
|
77
|
-
$
|
|
78
|
-
$
|
|
79
|
-
$
|
|
80
|
-
$
|
|
74
|
+
$ ${CLI} login --instance https://api.commonly.me --key dev
|
|
75
|
+
$ ${CLI} agent attach claude --pod <podId> --name my-claude
|
|
76
|
+
$ ${CLI} agent run my-claude # Ctrl+C to stop
|
|
77
|
+
$ ${CLI} agent detach my-claude # clean uninstall
|
|
78
|
+
$ ${CLI} daemon register --name "My MacBook"
|
|
79
|
+
$ ${CLI} daemon status
|
|
80
|
+
$ ${CLI} doctor # check Node, install, login, daemon, adapters
|
|
81
|
+
$ ${CLI} inbox list --token-file ~/.commonly/bin/ops-token # an operator's own queue
|
|
81
82
|
|
|
82
83
|
Custom Python agent:
|
|
83
|
-
$
|
|
84
|
+
$ ${CLI} agent init --language python --name research-bot --pod <podId>
|
|
84
85
|
$ python3 research-bot.py
|
|
85
86
|
|
|
86
87
|
Subcommand help:
|
|
87
|
-
$
|
|
88
|
-
$
|
|
89
|
-
$
|
|
90
|
-
$
|
|
88
|
+
$ ${CLI} login --help
|
|
89
|
+
$ ${CLI} agent attach --help
|
|
90
|
+
$ ${CLI} agent run --help
|
|
91
|
+
$ ${CLI} pod tail --help
|
|
91
92
|
|
|
92
93
|
Note: --instance is a subcommand option, not a program option. It accepts
|
|
93
94
|
either a saved key name ("dev", "local", "default") or a full URL.
|
|
@@ -108,6 +108,7 @@ import { isShippedCommonlyMcpCommand } from '../declared-mcp-guard.js';
|
|
|
108
108
|
import { isAnswerableToolError, PUBLIC_MCP_NOT_READY_CODE, PUBLIC_TOOL_FAILED_CODE } from '../public-tool-error.js';
|
|
109
109
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
110
110
|
import { startProviderProxy } from '../provider-proxy.js';
|
|
111
|
+
import { CLI } from '../cli-hint.js';
|
|
111
112
|
|
|
112
113
|
// See codex.js for the rationale on bumping the default + env override.
|
|
113
114
|
// Keeping both adapters in lockstep so any wrapper agent runtime has the
|
|
@@ -1411,7 +1412,7 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1411
1412
|
throw new Error(
|
|
1412
1413
|
`${sandboxTrust} Claude agents run inside a sandbox, and Commonly has no sandbox it can enforce on Windows `
|
|
1413
1414
|
+ `(got sandbox.mode=${JSON.stringify(sandboxMode)}). To run this agent without one, which is your choice, `
|
|
1414
|
-
+ `run
|
|
1415
|
+
+ `run ${CLI} agent run <name> ${UNSANDBOXED_FLAG} (or ${CLI} daemon install ${UNSANDBOXED_FLAG} for the agents `
|
|
1415
1416
|
+ 'this computer\'s daemon runs), or choose "Run it here" on the Connect page for a hosted agent.',
|
|
1416
1417
|
);
|
|
1417
1418
|
}
|
|
@@ -23,7 +23,7 @@ import { observeSpawn, controlsFromArguments } from '../runtime-observation.js';
|
|
|
23
23
|
import { requireSeatModel, seatModelRequired } from './seat-model.js';
|
|
24
24
|
import { isPatchAfterNewestTested } from './tested-version.js';
|
|
25
25
|
import { spawn as childSpawn, spawnSync } from 'child_process';
|
|
26
|
-
import { createHash } from 'crypto';
|
|
26
|
+
import { createHash, randomUUID } from 'crypto';
|
|
27
27
|
import { existsSync, readdirSync, realpathSync, rmSync } from 'fs';
|
|
28
28
|
import {
|
|
29
29
|
chmod,
|
|
@@ -43,7 +43,9 @@ import {
|
|
|
43
43
|
} from 'path';
|
|
44
44
|
import { writeCredentialFile } from '../credential-file.js';
|
|
45
45
|
import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir, selectedMcpWritesReadyFile,
|
|
48
|
+
} from '../mcp-home.js';
|
|
47
49
|
import { buildMemoryPreamble } from '../memory-bridge.js';
|
|
48
50
|
import {
|
|
49
51
|
isLegacySandboxTrust,
|
|
@@ -57,7 +59,7 @@ import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
|
57
59
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
58
60
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
59
61
|
import { isShippedCommonlyMcpCommand } from '../declared-mcp-guard.js';
|
|
60
|
-
import { isAnswerableToolError, PUBLIC_TOOL_FAILED_CODE } from '../public-tool-error.js';
|
|
62
|
+
import { isAnswerableToolError, PUBLIC_MCP_NOT_READY_CODE, PUBLIC_TOOL_FAILED_CODE } from '../public-tool-error.js';
|
|
61
63
|
import { startInstanceProxy } from '../instance-proxy.js';
|
|
62
64
|
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
63
65
|
|
|
@@ -567,6 +569,14 @@ const buildMcpConfig = (servers, ctx = {}) => {
|
|
|
567
569
|
console.warn(`[opencode] skipping MCP server ${server.name}: its credential declaration has no file-backed delivery`);
|
|
568
570
|
continue;
|
|
569
571
|
}
|
|
572
|
+
// F421: the shipped Commonly server of a public seat names its ready file,
|
|
573
|
+
// when the warm build it runs writes one (selectedMcpWritesReadyFile).
|
|
574
|
+
if (ctx.readyFileDir && isShippedCommonlyMcpCommand(server.command)
|
|
575
|
+
&& (ctx.mcpWritesReadyFile || selectedMcpWritesReadyFile)(command)) {
|
|
576
|
+
const readyPath = join(ctx.readyFileDir, randomUUID());
|
|
577
|
+
env[MCP_READY_FILE_ENV] = readyPath;
|
|
578
|
+
ctx.readyFiles?.push({ name: server.name, path: readyPath });
|
|
579
|
+
}
|
|
570
580
|
mcp[server.name] = {
|
|
571
581
|
type: 'local',
|
|
572
582
|
command: command.map((part) => substitutePublicPlaceholders(part, ctx)),
|
|
@@ -807,6 +817,31 @@ const makeEventParser = () => {
|
|
|
807
817
|
// started, so each catches what the other cannot.
|
|
808
818
|
export { PUBLIC_TOOL_FAILED_CODE };
|
|
809
819
|
|
|
820
|
+
// F421. OpenCode's stream says nothing about its MCP servers. When the Commonly
|
|
821
|
+
// server fails to start, OpenCode 1.19.0 logs one WARN line ("server
|
|
822
|
+
// unavailable … status=failed"), runs the model without the Commonly tools, and
|
|
823
|
+
// exits 0, so the reply would be an answer written without reading the pod
|
|
824
|
+
// (measured with a stub provider on 2026-11-11). The server creates the file
|
|
825
|
+
// this adapter names in COMMONLY_MCP_READY_FILE once OpenCode asks for its
|
|
826
|
+
// tools (tools/list, sent only after initialize succeeded), inside the folder the sandbox lets the seat write (OpenCode's own
|
|
827
|
+
// data home: Seatbelt's statePath, bwrap's write-outside). A turn whose file is
|
|
828
|
+
// missing never had the server, so its reply is withheld and the run loop tells
|
|
829
|
+
// the waiting pod why (turn-failure-notice.js) and retries.
|
|
830
|
+
export const MCP_READY_FILE_ENV = 'COMMONLY_MCP_READY_FILE';
|
|
831
|
+
|
|
832
|
+
export const missingReadyFile = (readyFiles, exists = existsSync) => (
|
|
833
|
+
(readyFiles || []).find(({ path }) => !exists(path)) || null
|
|
834
|
+
);
|
|
835
|
+
|
|
836
|
+
const publicMcpNotReadyError = (name) => {
|
|
837
|
+
const failure = new Error(
|
|
838
|
+
`public seat withheld this turn's reply: Commonly MCP server ${name} never reported ready (no ready file), `
|
|
839
|
+
+ 'so the model ran without its Commonly tools; the CLI posted no reply for it and does not ack the event',
|
|
840
|
+
);
|
|
841
|
+
failure.code = PUBLIC_MCP_NOT_READY_CODE;
|
|
842
|
+
return failure;
|
|
843
|
+
};
|
|
844
|
+
|
|
810
845
|
export const publicToolFailure = (toolErrors, mcpServers) => {
|
|
811
846
|
const prefixes = (Array.isArray(mcpServers) ? mcpServers : [])
|
|
812
847
|
.filter((server) => server?.name && isShippedCommonlyMcpCommand(server.command))
|
|
@@ -1217,6 +1252,8 @@ export default {
|
|
|
1217
1252
|
root: tempDir,
|
|
1218
1253
|
});
|
|
1219
1254
|
let openCodeHome = null;
|
|
1255
|
+
let readyFileDir = null;
|
|
1256
|
+
const readyFiles = [];
|
|
1220
1257
|
let providerProxy = null;
|
|
1221
1258
|
let instanceProxy = null;
|
|
1222
1259
|
try {
|
|
@@ -1242,6 +1279,7 @@ export default {
|
|
|
1242
1279
|
});
|
|
1243
1280
|
}
|
|
1244
1281
|
const stateHome = isPublic ? join(openCodeHome.root, 'state') : null;
|
|
1282
|
+
readyFileDir = isPublic ? join(openCodeHome.root, 'mcp-ready') : null;
|
|
1245
1283
|
const cacheHome = isPublic ? join(openCodeHome.root, 'cache') : null;
|
|
1246
1284
|
const tempWork = isPublic ? join(openCodeHome.root, 'tmp') : join(tempDir, 'tmp');
|
|
1247
1285
|
await Promise.all([
|
|
@@ -1252,7 +1290,11 @@ export default {
|
|
|
1252
1290
|
const unavailableMcp = [];
|
|
1253
1291
|
const mcpReadDirectories = [];
|
|
1254
1292
|
const bearerFileServers = [];
|
|
1293
|
+
if (readyFileDir) await mkdir(readyFileDir, { recursive: true, mode: 0o700 });
|
|
1255
1294
|
const mcp = buildMcpConfig(ctx.environment?.mcp, {
|
|
1295
|
+
readyFileDir,
|
|
1296
|
+
readyFiles,
|
|
1297
|
+
mcpWritesReadyFile: ctx._mcpWritesReadyFile,
|
|
1256
1298
|
runtimeToken: ctx.runtimeToken,
|
|
1257
1299
|
instanceUrl: instanceProxy
|
|
1258
1300
|
? `http://127.0.0.1:${ISOLATED_INSTANCE_PORT}` : ctx.instanceUrl,
|
|
@@ -1419,6 +1461,8 @@ export default {
|
|
|
1419
1461
|
: undefined,
|
|
1420
1462
|
});
|
|
1421
1463
|
if (isPublic) {
|
|
1464
|
+
const notReady = missingReadyFile(readyFiles, ctx._existsSync);
|
|
1465
|
+
if (notReady) throw publicMcpNotReadyError(notReady.name);
|
|
1422
1466
|
const failure = publicToolFailure(result.toolErrors, ctx.environment?.mcp);
|
|
1423
1467
|
if (failure) throw publicToolFailedError(failure);
|
|
1424
1468
|
}
|
|
@@ -1431,6 +1475,9 @@ export default {
|
|
|
1431
1475
|
try { await instanceProxy?.close(); } catch { /* ignore */ }
|
|
1432
1476
|
try { await providerProxy?.close(); } catch { /* ignore */ }
|
|
1433
1477
|
try { await rm(tempDir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
1478
|
+
for (const { path } of readyFiles) {
|
|
1479
|
+
try { await rm(path, { force: true }); } catch { /* ignore */ }
|
|
1480
|
+
}
|
|
1434
1481
|
}
|
|
1435
1482
|
},
|
|
1436
1483
|
};
|
package/src/lib/api.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { resolveInstanceUrl, getToken, resolveInstance } from './config.js';
|
|
9
|
+
import { CLI } from './cli-hint.js';
|
|
9
10
|
|
|
10
11
|
const headers = (token, extra = {}) => ({
|
|
11
12
|
'Content-Type': 'application/json',
|
|
@@ -17,7 +18,7 @@ const knownSessionFailure = (body) => [body?.msg, body?.error, body?.message]
|
|
|
17
18
|
.some((value) => ['Token is not valid', 'Invalid API token', 'Account no longer exists'].includes(value));
|
|
18
19
|
|
|
19
20
|
export const sessionExpiredMessage = ({ instanceKey, baseUrl }) => (
|
|
20
|
-
`Session for ${instanceKey} (${baseUrl}) has expired.\nRun:
|
|
21
|
+
`Session for ${instanceKey} (${baseUrl}) has expired.\nRun: ${CLI} login --instance ${instanceKey}`
|
|
21
22
|
);
|
|
22
23
|
|
|
23
24
|
// A non-JSON error body is usually an edge proxy's HTML page; a Cloudflare
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The commands this CLI prints for a person to type (F435).
|
|
2
|
+
//
|
|
3
|
+
// npm installs `commonly` and `npx` on Windows as three shims: a `.ps1`, a
|
|
4
|
+
// `.cmd` and a bare sh script. PowerShell picks the `.ps1` first, and its
|
|
5
|
+
// default execution policy (Restricted on a Windows client) refuses to run
|
|
6
|
+
// it, so a printed `commonly daemon install` fails there before it starts.
|
|
7
|
+
// The `.cmd` shim is not a script to PowerShell and runs under any policy, and
|
|
8
|
+
// it runs the same in cmd.exe. So on win32 every hint names `commonly.cmd`,
|
|
9
|
+
// `npx.cmd` or `npm.cmd`; elsewhere the bare name.
|
|
10
|
+
//
|
|
11
|
+
// Windows PowerShell 5.1 has no `&&`, and `;` would run the second step even
|
|
12
|
+
// when the first failed, so steps that depend on each other print one per line
|
|
13
|
+
// on win32 (`cliSteps`).
|
|
14
|
+
//
|
|
15
|
+
// The guard in __tests__/cli-hint.test.mjs fails on a `commonly <subcommand>`
|
|
16
|
+
// written into a string anywhere else in cli/src: use `${CLI} <subcommand>`.
|
|
17
|
+
|
|
18
|
+
export const cliName = (platform = process.platform) => (platform === 'win32' ? 'commonly.cmd' : 'commonly');
|
|
19
|
+
export const npxName = (platform = process.platform) => (platform === 'win32' ? 'npx.cmd' : 'npx');
|
|
20
|
+
export const npmName = (platform = process.platform) => (platform === 'win32' ? 'npm.cmd' : 'npm');
|
|
21
|
+
|
|
22
|
+
export const CLI = cliName();
|
|
23
|
+
export const NPX = npxName();
|
|
24
|
+
export const NPM = npmName();
|
|
25
|
+
|
|
26
|
+
// Commands that run one after another, each only if the one before succeeded.
|
|
27
|
+
// Joined with ` && ` on POSIX shells; on win32, one command per line, each
|
|
28
|
+
// indented by `indent`, so the reader runs them in order.
|
|
29
|
+
export const cliSteps = (steps, { platform = process.platform, indent = ' ' } = {}) => (
|
|
30
|
+
platform === 'win32'
|
|
31
|
+
? steps.map((step) => `\n${indent}${step}`).join('')
|
|
32
|
+
: steps.join(' && ')
|
|
33
|
+
);
|
package/src/lib/daemon-hint.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// The hint a foreground `commonly agent run` prints for keeping the agent
|
|
2
2
|
// running. The daemon supervises only the agents placed on this computer, so
|
|
3
3
|
// the hint depends on whether a daemon is registered here at all.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
//
|
|
5
|
+
// The two daemon steps depend on each other, so on Windows they print one per
|
|
6
|
+
// line instead of joined with `&&`, which Windows PowerShell 5.1 lacks (F435).
|
|
7
|
+
import { cliName, cliSteps } from './cli-hint.js';
|
|
8
|
+
|
|
9
|
+
export const foregroundDaemonHint = ({ daemonRegistered, platform = process.platform }) => {
|
|
10
|
+
const lead = 'foreground mode; this stops when the terminal closes. To keep it running, ';
|
|
11
|
+
const inWebApp = 'the web app: Agents → Bring your own → On my computer';
|
|
12
|
+
if (daemonRegistered) return `${lead}add the agent to this computer in ${inWebApp}`;
|
|
13
|
+
const cli = cliName(platform);
|
|
14
|
+
const steps = cliSteps([`${cli} daemon register`, `${cli} daemon install`], { platform, indent: ' ' });
|
|
15
|
+
return platform === 'win32'
|
|
16
|
+
? `${lead}add this computer by running these two commands, one after the other:${steps}\n then add the agent to it in ${inWebApp}`
|
|
17
|
+
: `${lead}add this computer with: ${steps}, then add the agent to it in ${inWebApp}`;
|
|
18
|
+
};
|
|
@@ -18,6 +18,7 @@ import { basename, join, dirname, resolve } from 'path';
|
|
|
18
18
|
import {
|
|
19
19
|
WINDOWS_TASK_NAME, installWindowsService, uninstallWindowsService, windowsServiceAction, windowsServicePaths,
|
|
20
20
|
} from './daemon-service-windows.js';
|
|
21
|
+
import { CLI } from './cli-hint.js';
|
|
21
22
|
|
|
22
23
|
export const LAUNCHD_LABEL = 'me.commonly.daemon';
|
|
23
24
|
export const SYSTEMD_UNIT = 'commonly-daemon.service';
|
|
@@ -310,7 +311,7 @@ export const foreignServiceRefusal = ({ target, loadedFile, platform = process.p
|
|
|
310
311
|
const own = target.kind === 'schtasks' ? target.launcher : target.file;
|
|
311
312
|
if (canonicalPath(loadedFile, platform) === canonicalPath(own, platform)) return null;
|
|
312
313
|
const head = `This computer already runs a Commonly daemon for another account (its service file is ${loadedFile}), `
|
|
313
|
-
+
|
|
314
|
+
+ `and installing here would stop it. To see it, run \`${CLI} daemon status\` as that account. `;
|
|
314
315
|
// The systemd user manager reads units only from its own account's folder,
|
|
315
316
|
// so a unit written under another HOME is never loaded: --replace can't help,
|
|
316
317
|
// and neither would uninstalling the other one first.
|
|
@@ -322,8 +323,8 @@ export const foreignServiceRefusal = ({ target, loadedFile, platform = process.p
|
|
|
322
323
|
};
|
|
323
324
|
|
|
324
325
|
export const installSummary = ({ startsAtBoot }) => (startsAtBoot
|
|
325
|
-
?
|
|
326
|
-
:
|
|
326
|
+
? `The daemon now starts at boot and is kept alive, so it survives reboots. Uninstall with: ${CLI} daemon uninstall`
|
|
327
|
+
: `The daemon now starts at login and is kept alive. Uninstall with: ${CLI} daemon uninstall`);
|
|
327
328
|
|
|
328
329
|
export const installDaemonService = async ({
|
|
329
330
|
platform = process.platform,
|
|
@@ -419,7 +420,7 @@ export const installDaemonService = async ({
|
|
|
419
420
|
if (lingerUser) startsAtBoot = await ensureLinger({ username: lingerUser, existsFile, execCmd, warn });
|
|
420
421
|
}
|
|
421
422
|
for (const name of missing) {
|
|
422
|
-
warn(`${name} is not set in this shell, so it is NOT in the service file. A seat that relies on it will fail to start (one with its own provider.keyFile won't); export it and re-run:
|
|
423
|
+
warn(`${name} is not set in this shell, so it is NOT in the service file. A seat that relies on it will fail to start (one with its own provider.keyFile won't); export it and re-run: ${CLI} daemon install (docs/agents/daemon-service-environment.md)`);
|
|
423
424
|
}
|
|
424
425
|
log(`Installed ${target.kind} service (${target.file}). Logs: ${daemonLogPath(home)}`);
|
|
425
426
|
return { ...target, startsAtBoot };
|
package/src/lib/doctor.js
CHANGED
|
@@ -16,6 +16,7 @@ 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
18
|
import { signedOutHint } from './adapter-login.js';
|
|
19
|
+
import { CLI, NPM } from './cli-hint.js';
|
|
19
20
|
|
|
20
21
|
export const PASS = 'pass';
|
|
21
22
|
export const FAIL = 'fail';
|
|
@@ -62,7 +63,7 @@ export const checkInstall = ({
|
|
|
62
63
|
pathValue, platform, isExecutable, runVersion, runningVersion, fromSetup = runsFromStableInstall(),
|
|
63
64
|
}) => {
|
|
64
65
|
// A `daemon setup` copy is updated by running setup again, never a global install.
|
|
65
|
-
const fix = fromSetup ? DAEMON_SETUP_LINE :
|
|
66
|
+
const fix = fromSetup ? DAEMON_SETUP_LINE : `${NPM} install -g @commonlyai/cli`;
|
|
66
67
|
const found = findOnPath({ command: 'commonly', pathValue, platform, isExecutable });
|
|
67
68
|
if (!found.length) return result('install', FAIL, 'no `commonly` on PATH', fix);
|
|
68
69
|
const [binary] = found;
|
|
@@ -94,7 +95,7 @@ export const checkLogin = async ({ target, fetchUser }) => {
|
|
|
94
95
|
if ([401, 403].includes(error?.status)) {
|
|
95
96
|
return result('login', FAIL, `${where} rejected ${tokenName}`, refix);
|
|
96
97
|
}
|
|
97
|
-
return result('login', FAIL, `could not reach ${target.url}: ${error?.message || error}`,
|
|
98
|
+
return result('login', FAIL, `could not reach ${target.url}: ${error?.message || error}`, `check the network, then re-run ${CLI} doctor`);
|
|
98
99
|
}
|
|
99
100
|
const who = user?.username || user?.email || user?._id;
|
|
100
101
|
if (!who) return result('login', FAIL, `${where} answered without a user`, refix);
|
|
@@ -125,17 +126,17 @@ export const checkDaemon = async ({
|
|
|
125
126
|
}
|
|
126
127
|
const name = record.machineName || 'this computer';
|
|
127
128
|
if (!fileExists(serviceFile)) {
|
|
128
|
-
return result('daemon', FAIL, `${name} is registered but its login service is not installed (${serviceFile})`,
|
|
129
|
+
return result('daemon', FAIL, `${name} is registered but its login service is not installed (${serviceFile})`, `${CLI} daemon install`);
|
|
129
130
|
}
|
|
130
131
|
let machine;
|
|
131
132
|
try {
|
|
132
133
|
machine = await fetchMachine(record);
|
|
133
134
|
} catch (error) {
|
|
134
|
-
return result('daemon', FAIL, describeError(error),
|
|
135
|
+
return result('daemon', FAIL, describeError(error), `${CLI} daemon status`);
|
|
135
136
|
}
|
|
136
137
|
const heard = `last heartbeat ${ago(machine?.lastSeenAt, now)}`;
|
|
137
138
|
if (machine?.status !== 'online') {
|
|
138
|
-
return result('daemon', FAIL, `${machine?.name || name} is ${machine?.status || 'unknown'}, ${heard}`,
|
|
139
|
+
return result('daemon', FAIL, `${machine?.name || name} is ${machine?.status || 'unknown'}, ${heard}`, `${CLI} daemon restart, then ${CLI} daemon logs`);
|
|
139
140
|
}
|
|
140
141
|
return result('daemon', PASS, `${machine.name || name} online, service installed, ${heard}`);
|
|
141
142
|
};
|
|
@@ -159,7 +160,7 @@ export const checkAdapters = async ({ agents, getAdapter, unreadable = [] }) =>
|
|
|
159
160
|
byAdapter.get(adapter).push(agent.name);
|
|
160
161
|
}
|
|
161
162
|
const unreadableLine = unreadable.length
|
|
162
|
-
? [result('adapters', FAIL, `the token file of ${nameList(unreadable)} is not readable JSON (~/.commonly/tokens)`,
|
|
163
|
+
? [result('adapters', FAIL, `the token file of ${nameList(unreadable)} is not readable JSON (~/.commonly/tokens)`, `${CLI} agent detach <name> --force, then attach it again`)]
|
|
163
164
|
: [];
|
|
164
165
|
if (!byAdapter.size) {
|
|
165
166
|
return unreadableLine.length ? unreadableLine : [result('adapters', SKIP, 'no agents are attached on this computer')];
|
|
@@ -169,12 +170,12 @@ export const checkAdapters = async ({ agents, getAdapter, unreadable = [] }) =>
|
|
|
169
170
|
const id = `adapter:${name}`;
|
|
170
171
|
const used = `used by ${nameList(agentNames)}`;
|
|
171
172
|
if (name === '?') {
|
|
172
|
-
results.push(result(id, FAIL, `no adapter recorded in the token file, ${used}`,
|
|
173
|
+
results.push(result(id, FAIL, `no adapter recorded in the token file, ${used}`, `${CLI} agent detach <name> --force, then attach it again`));
|
|
173
174
|
continue;
|
|
174
175
|
}
|
|
175
176
|
const adapter = getAdapter(name);
|
|
176
177
|
if (!adapter) {
|
|
177
|
-
results.push(result(id, FAIL, `unknown adapter '${name}', ${used}`,
|
|
178
|
+
results.push(result(id, FAIL, `unknown adapter '${name}', ${used}`, `${CLI} agent detach <name> --force, then attach it again`));
|
|
178
179
|
continue;
|
|
179
180
|
}
|
|
180
181
|
if (typeof adapter.detect !== 'function') {
|
|
@@ -225,7 +226,7 @@ export const checkMacClaude = ({
|
|
|
225
226
|
// A failed preflight most often means doctor itself is inside a sandbox
|
|
226
227
|
// (an agent's turn), where a nested sandbox-exec is refused.
|
|
227
228
|
const fixes = [];
|
|
228
|
-
if (!seatbelt?.available) fixes.push(
|
|
229
|
+
if (!seatbelt?.available) fixes.push(`run ${CLI} doctor from a normal Terminal, not from inside an agent's sandbox`);
|
|
229
230
|
if (missing.length > (seatbelt?.available ? 0 : 1)) {
|
|
230
231
|
fixes.push('sign in to this Mac as the user the agent runs as, and run claude once to log in');
|
|
231
232
|
}
|
package/src/lib/mcp-home.js
CHANGED
|
@@ -350,6 +350,30 @@ export const selectedMcpVersionDir = (command, home = mcpHomeDir()) => {
|
|
|
350
350
|
return versionDirFor(home, version);
|
|
351
351
|
};
|
|
352
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Whether the warm build this spawn runs writes the ready file (F421).
|
|
355
|
+
*
|
|
356
|
+
* A public OpenCode seat's stream reports nothing about its MCP servers, so the
|
|
357
|
+
* adapter names a file the Commonly server creates once its host reaches it
|
|
358
|
+
* (commonly-mcp/src/ready-file.js) and withholds a turn that ends without it.
|
|
359
|
+
* Only a release that says so in its package.json (`commonly.readyFile`) is
|
|
360
|
+
* asked: a build from before the file existed would leave every turn withheld.
|
|
361
|
+
* Anything this cannot read or verify answers false, which keeps the turn as it
|
|
362
|
+
* was before F421.
|
|
363
|
+
*/
|
|
364
|
+
export const selectedMcpWritesReadyFile = (command, home = mcpHomeDir(), { readFile = defaultRead } = {}) => {
|
|
365
|
+
if (!selectedMcpVersionDir(command, home)) return false;
|
|
366
|
+
const version = relative(home, command[1]).split(sep)[0];
|
|
367
|
+
const raw = readFile(join(packageDirFor(home, version), 'package.json'));
|
|
368
|
+
if (typeof raw !== 'string') return false;
|
|
369
|
+
try {
|
|
370
|
+
const pkg = JSON.parse(raw);
|
|
371
|
+
return pkg?.name === MCP_PACKAGE && pkg?.commonly?.readyFile === true;
|
|
372
|
+
} catch {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
353
377
|
/**
|
|
354
378
|
* The bin of an npm PREFIX dir, which is the shape the warm installs into:
|
|
355
379
|
* `npm install --prefix <dir>` leaves `<dir>/node_modules/...`, with no version
|