@commonlyai/cli 0.1.105 → 0.1.107
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
package/src/commands/agent.js
CHANGED
|
@@ -51,7 +51,9 @@ import {
|
|
|
51
51
|
ADAPTERS_WITH_GRANT_BROKER,
|
|
52
52
|
ADAPTERS_WITH_DEFAULT_SANDBOX,
|
|
53
53
|
defaultMcpServers,
|
|
54
|
+
seatBaseline,
|
|
54
55
|
withDefaultMcpServer,
|
|
56
|
+
withDefaultSandbox,
|
|
55
57
|
} from '../lib/default-environment.js';
|
|
56
58
|
import { withholdGrantBroker } from '../lib/grant-broker-guard.js';
|
|
57
59
|
import {
|
|
@@ -63,6 +65,8 @@ import { claimReleaseFor, ackResultFor } from '../lib/claim-outcome.js';
|
|
|
63
65
|
import { prepareCommitAttribution } from '../lib/commit-attribution.js';
|
|
64
66
|
import { detectBwrap } from '../lib/sandbox/bwrap.js';
|
|
65
67
|
import { resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
|
|
68
|
+
import { hostSandboxRefusal, windowsSandboxMessage } from '../lib/sandbox/host-check.js';
|
|
69
|
+
import { prepareMcpBeforeFirstPoll } from '../lib/mcp-first-run.js';
|
|
66
70
|
import { detectSeatbelt } from '../lib/sandbox/seatbelt.js';
|
|
67
71
|
import { describeUpstreamRefusal } from '../lib/upstream-refusal.js';
|
|
68
72
|
import {
|
|
@@ -148,6 +152,19 @@ export const deleteAgentToken = (name) => {
|
|
|
148
152
|
// OpenCode is opt-in: unlike the established wrappers it must not be selected
|
|
149
153
|
// just because its binary happens to be installed on the operator's machine.
|
|
150
154
|
export const BOOTSTRAP_ADAPTER_DETECT_ORDER = ['claude', 'codex', 'pi'];
|
|
155
|
+
export const NO_AGENT_CLI_CODE = 'no_agent_cli';
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A saved Connect-page seat from before bootstrap applied the default sandbox:
|
|
159
|
+
* an adapter that takes one, no workspace, and an environment with nothing
|
|
160
|
+
* enforced. Such a record is told how to pick the default up; it is not
|
|
161
|
+
* rewritten here (Cofounder, 2026-10-16: none were found outside our own tests).
|
|
162
|
+
*/
|
|
163
|
+
export const savedSeatLacksDefaultSandbox = (record) => Boolean(record)
|
|
164
|
+
&& ADAPTERS_WITH_DEFAULT_SANDBOX.has(record.adapter)
|
|
165
|
+
&& !record.workspacePath
|
|
166
|
+
&& record.environment !== null && typeof record.environment === 'object'
|
|
167
|
+
&& withDefaultSandbox(record.environment) !== record.environment;
|
|
151
168
|
|
|
152
169
|
/** Return the adapter binding resolved for this exact installation by the server. */
|
|
153
170
|
export const runtimeAdapterForInstallation = ({ installations, podId, instanceId } = {}) => {
|
|
@@ -319,16 +336,26 @@ export const bootstrapAgentRecordFromEnv = async ({
|
|
|
319
336
|
throw new Error(`Adapter '${adapterOverride}' not found on PATH.`);
|
|
320
337
|
}
|
|
321
338
|
} else {
|
|
339
|
+
const missing = [];
|
|
322
340
|
for (const candidate of BOOTSTRAP_ADAPTER_DETECT_ORDER) {
|
|
323
341
|
const adapter = adapterRegistry.getAdapter(candidate);
|
|
324
342
|
// eslint-disable-next-line no-await-in-loop
|
|
325
343
|
if (adapter && await adapter.detect()) { adapterName = candidate; break; }
|
|
344
|
+
missing.push(candidate);
|
|
326
345
|
}
|
|
327
346
|
if (!adapterName) {
|
|
328
|
-
|
|
347
|
+
const err = new Error(
|
|
329
348
|
`No supported agent CLI found on PATH (looked for: ${BOOTSTRAP_ADAPTER_DETECT_ORDER.join(', ')}). `
|
|
330
349
|
+ 'Install one, or pass --adapter <name>.',
|
|
331
350
|
);
|
|
351
|
+
err.code = NO_AGENT_CLI_CODE;
|
|
352
|
+
throw err;
|
|
353
|
+
}
|
|
354
|
+
// The page's command names the person's own CLI; running a different one
|
|
355
|
+
// without saying so is how a Claude Code user ended up with a Codex agent.
|
|
356
|
+
if (missing.length > 0) {
|
|
357
|
+
log(`${missing.join(', ')} not found on PATH, so this agent runs with ${adapterName}. `
|
|
358
|
+
+ 'To choose, pass --adapter <name>.');
|
|
332
359
|
}
|
|
333
360
|
}
|
|
334
361
|
|
|
@@ -356,7 +383,9 @@ export const bootstrapAgentRecordFromEnv = async ({
|
|
|
356
383
|
instanceUrl,
|
|
357
384
|
runtimeToken,
|
|
358
385
|
adapter: adapterName,
|
|
359
|
-
|
|
386
|
+
// The daemon's baseline for a seat nobody wrote a spec for, sandbox
|
|
387
|
+
// included: this record is derived from nothing the person declared.
|
|
388
|
+
environment: seatBaseline(buildDefaultEnvironment(adapterName), adapterName, { sandbox: true }),
|
|
360
389
|
workspacePath: null,
|
|
361
390
|
};
|
|
362
391
|
};
|
|
@@ -3046,6 +3075,7 @@ Docs:
|
|
|
3046
3075
|
.option('--refusal-handoff <agent>', 'Agent to @mention when the model provider refuses a request\'s content; the request is acked as refused, never retried')
|
|
3047
3076
|
.action(async (name, opts) => {
|
|
3048
3077
|
let record = loadAgentToken(name);
|
|
3078
|
+
let bootstrapped = false;
|
|
3049
3079
|
if (!record) {
|
|
3050
3080
|
// First run on this machine: the BYO connect page hands out env vars,
|
|
3051
3081
|
// not a token file — bootstrap the record from them (#913).
|
|
@@ -3057,12 +3087,14 @@ Docs:
|
|
|
3057
3087
|
});
|
|
3058
3088
|
} catch (err) {
|
|
3059
3089
|
console.error(`${stamp()} [${name}] ${err.message}`);
|
|
3090
|
+
// A Claude Code installed with npm is a .cmd shim Node cannot spawn,
|
|
3091
|
+
// so on Windows this is usually "installed but not runnable here".
|
|
3092
|
+
if (err.code === NO_AGENT_CLI_CODE && process.platform === 'win32') {
|
|
3093
|
+
console.error(windowsSandboxMessage('claude'));
|
|
3094
|
+
}
|
|
3060
3095
|
process.exit(1);
|
|
3061
3096
|
}
|
|
3062
|
-
if (record) {
|
|
3063
|
-
saveAgentToken(record.agentName, record);
|
|
3064
|
-
console.log(`${stamp()} [${name}] bootstrapped ${tokenFile(record.agentName)} from COMMONLY_AGENT_TOKEN (adapter: ${record.adapter})`);
|
|
3065
|
-
} else {
|
|
3097
|
+
if (!record) {
|
|
3066
3098
|
console.error(
|
|
3067
3099
|
`No token for '${name}'. Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN`
|
|
3068
3100
|
+ ` (shown on the Connect your own agent page) and re-run, or:`
|
|
@@ -3070,6 +3102,24 @@ Docs:
|
|
|
3070
3102
|
);
|
|
3071
3103
|
process.exit(1);
|
|
3072
3104
|
}
|
|
3105
|
+
bootstrapped = true;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
// Every turn of a seat this host cannot confine would fail, so say so
|
|
3109
|
+
// once, before a token file is written or a poll is made.
|
|
3110
|
+
const hostRefusal = hostSandboxRefusal({ environment: record.environment, adapterName: record.adapter });
|
|
3111
|
+
if (hostRefusal) {
|
|
3112
|
+
console.error(`${stamp()} [${name}] ${hostRefusal}`);
|
|
3113
|
+
process.exit(1);
|
|
3114
|
+
}
|
|
3115
|
+
if (bootstrapped) {
|
|
3116
|
+
saveAgentToken(record.agentName, record);
|
|
3117
|
+
console.log(`${stamp()} [${name}] bootstrapped ${tokenFile(record.agentName)} from COMMONLY_AGENT_TOKEN (adapter: ${record.adapter})`);
|
|
3118
|
+
} else if (savedSeatLacksDefaultSandbox(record)) {
|
|
3119
|
+
console.warn(
|
|
3120
|
+
`${stamp()} [${name}] this agent's saved settings predate the default sandbox. To pick it up, reconnect: `
|
|
3121
|
+
+ `commonly agent detach ${name} --force, then run a fresh command from the Connect page.`,
|
|
3122
|
+
);
|
|
3073
3123
|
}
|
|
3074
3124
|
|
|
3075
3125
|
const adapterRequest = checkRunAdapterRequest({
|
|
@@ -3117,6 +3167,11 @@ Docs:
|
|
|
3117
3167
|
// Unstamped, it took `ps -o lstart` to establish when nine seats came
|
|
3118
3168
|
// back on 2026-08-18, and that only worked because the processes were
|
|
3119
3169
|
// still alive — after the next restart that route is gone too.
|
|
3170
|
+
await prepareMcpBeforeFirstPoll({
|
|
3171
|
+
environment: record.environment,
|
|
3172
|
+
log: (line) => console.log(`${stamp()} [${name}] ${line}`),
|
|
3173
|
+
});
|
|
3174
|
+
|
|
3120
3175
|
console.log(`${stamp()} [${name}] polling ${record.instanceUrl} for events (ctrl+c to stop)`);
|
|
3121
3176
|
console.log(`${stamp()} [${name}] foreground mode; to background and keep it across logins, run: commonly daemon install`);
|
|
3122
3177
|
|
|
@@ -208,6 +208,9 @@ const buildClaudeEnv = (input, state, expansionEnv = {}, credentialFile = null)
|
|
|
208
208
|
}
|
|
209
209
|
output.HOME = state.statePath;
|
|
210
210
|
output.TMPDIR = state.tmpPath;
|
|
211
|
+
// Claude keeps its temp root at /private/tmp/claude-<uid> unless told
|
|
212
|
+
// otherwise; the seat's Seatbelt profile admits only its own tmp.
|
|
213
|
+
output.CLAUDE_CODE_TMPDIR = state.tmpPath;
|
|
211
214
|
output.XDG_CACHE_HOME = join(state.statePath, '.cache');
|
|
212
215
|
output.XDG_CONFIG_HOME = join(state.statePath, '.config');
|
|
213
216
|
output.XDG_DATA_HOME = join(state.statePath, '.local', 'share');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepare the commonly MCP build before a public seat's first poll.
|
|
3
|
+
*
|
|
4
|
+
* A public seat runs its MCP server only from a host-prepared build (TASK-273),
|
|
5
|
+
* and the first spawn on an empty home only STARTS preparing one, then refuses
|
|
6
|
+
* its turn. On a fresh machine that refused turn was the person's first
|
|
7
|
+
* @mention, and it waited out the kernel's requeue, about ten minutes (BYO
|
|
8
|
+
* walk, 2026-10-16). `agent run` prepares the build once, before it polls.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { normalizeSandboxTrust } from './environment.js';
|
|
12
|
+
import { COMMONLY_MCP_SERVER_NAME } from './default-environment.js';
|
|
13
|
+
import { WARM_RESULTS, planMcpSpawn, resolveHomeDir } from './mcp-home.js';
|
|
14
|
+
import { warmMcpHome } from './mcp-warm-child.mjs';
|
|
15
|
+
|
|
16
|
+
/** The warm's result when it ran, or null when this seat needed none. */
|
|
17
|
+
export const prepareMcpBeforeFirstPoll = async ({
|
|
18
|
+
environment,
|
|
19
|
+
home,
|
|
20
|
+
plan = planMcpSpawn,
|
|
21
|
+
warm = warmMcpHome,
|
|
22
|
+
log = () => {},
|
|
23
|
+
} = {}) => {
|
|
24
|
+
if (normalizeSandboxTrust(environment?.sandbox)?.trust !== 'public') return null;
|
|
25
|
+
const server = Array.isArray(environment?.mcp)
|
|
26
|
+
? environment.mcp.find((entry) => entry?.name === COMMONLY_MCP_SERVER_NAME)
|
|
27
|
+
: null;
|
|
28
|
+
if (!Array.isArray(server?.command)) return null;
|
|
29
|
+
if (plan(server.command, { home }).reason !== 'home-empty') return null;
|
|
30
|
+
|
|
31
|
+
log("preparing Commonly's tools on this machine (first run only)...");
|
|
32
|
+
const result = await warm(resolveHomeDir(home), { now: Date.now() });
|
|
33
|
+
if (result === WARM_RESULTS.ADVANCED || result === WARM_RESULTS.CURRENT) {
|
|
34
|
+
log("Commonly's tools are ready");
|
|
35
|
+
} else {
|
|
36
|
+
log(`could not prepare Commonly's tools yet (${result}); the first turn will try again`);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default { prepareMcpBeforeFirstPoll };
|
package/src/lib/sandbox/bwrap.js
CHANGED
|
@@ -31,7 +31,10 @@ const expandHome = (p) => {
|
|
|
31
31
|
return p;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
// Never advise `sandbox.mode: none` here: a public seat refuses it, and the
|
|
35
|
+
// mechanisms that do exist are named instead.
|
|
36
|
+
const MACOS_MESSAGE = 'bwrap is Linux-only. On macOS a public seat runs under Seatbelt '
|
|
37
|
+
+ '(sandbox.mode workspace or read-only); Windows has no supported sandbox yet, so use WSL 2.';
|
|
35
38
|
|
|
36
39
|
const DEFAULT_RO_BINDS = [
|
|
37
40
|
'/etc/ssl/certs',
|
|
@@ -53,7 +56,8 @@ export const detectBwrap = () => {
|
|
|
53
56
|
if (res.error || res.status !== 0) {
|
|
54
57
|
return {
|
|
55
58
|
available: false,
|
|
56
|
-
error: 'bwrap not found on PATH. Install bubblewrap: `apt install bubblewrap` (Debian/Ubuntu)
|
|
59
|
+
error: 'bwrap not found on PATH. Install bubblewrap: `sudo apt install bubblewrap` (Debian/Ubuntu, WSL), '
|
|
60
|
+
+ '`sudo dnf install bubblewrap` (Fedora) or `sudo pacman -S bubblewrap` (Arch).',
|
|
57
61
|
};
|
|
58
62
|
}
|
|
59
63
|
return { available: true, path: 'bwrap' };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Can THIS host confine the seat it is about to run? Asked once, before the
|
|
3
|
+
* first poll.
|
|
4
|
+
*
|
|
5
|
+
* A public seat's sandbox is resolved per host (mode.js): Seatbelt on macOS,
|
|
6
|
+
* bubblewrap elsewhere. `agent attach --env` checks that mechanism up front;
|
|
7
|
+
* `agent run` did not, so a public seat on a host without it (native Windows,
|
|
8
|
+
* or Linux without bubblewrap) would start, poll, and fail every turn while
|
|
9
|
+
* the pod saw nothing.
|
|
10
|
+
*
|
|
11
|
+
* Only the adapters that run inside these mechanisms are checked. Codex
|
|
12
|
+
* confines with its own permission profiles (mode.js), and pi refuses a
|
|
13
|
+
* declared sandbox itself (default-environment.js).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { normalizeSandboxTrust } from '../environment.js';
|
|
17
|
+
import { resolvePublicSandboxMode } from './mode.js';
|
|
18
|
+
import { detectBwrap as defaultDetectBwrap } from './bwrap.js';
|
|
19
|
+
import { detectSeatbelt as defaultDetectSeatbelt } from './seatbelt.js';
|
|
20
|
+
|
|
21
|
+
const SEATBELT_MODES = new Set(['workspace', 'read-only']);
|
|
22
|
+
|
|
23
|
+
const ADAPTER_LABELS = { claude: 'Claude Code', opencode: 'OpenCode', qwen: 'Qwen Code' };
|
|
24
|
+
|
|
25
|
+
const HOSTED_LINE = ' - A hosted agent: choose "Run it here" on the Connect page. Nothing runs on this machine.';
|
|
26
|
+
|
|
27
|
+
/** What a person on native Windows can do instead. */
|
|
28
|
+
export const windowsSandboxMessage = (adapterName) => {
|
|
29
|
+
const label = ADAPTER_LABELS[adapterName] || adapterName;
|
|
30
|
+
// WSL is offered only where the Linux sandbox can run the CLI: not Claude
|
|
31
|
+
// Code (see linuxClaudeMessage).
|
|
32
|
+
return [
|
|
33
|
+
`Commonly runs a connected ${label} inside a sandbox, and has no sandbox for Windows yet,`,
|
|
34
|
+
'so this agent cannot listen for @mentions from native Windows. Instead:',
|
|
35
|
+
...(adapterName === 'claude'
|
|
36
|
+
? [' - Use Commonly from your own Claude Code sessions: the Connect page shows a PowerShell `claude mcp add` command.']
|
|
37
|
+
: [` - WSL 2 (Ubuntu): install Node and ${label} inside WSL, run \`sudo apt install bubblewrap\`,`
|
|
38
|
+
+ ' then run these same commands there.']),
|
|
39
|
+
HOSTED_LINE,
|
|
40
|
+
].join('\n');
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Claude Code on Linux (WSL included). The bubblewrap namespace binds the
|
|
45
|
+
* system binary folders only, and Claude Code installs under the person's
|
|
46
|
+
* home or /usr/local, so a confined spawn could not even start it; its login
|
|
47
|
+
* and settings live under that home too (Ubuntu run, 2026-10-16). Until the
|
|
48
|
+
* namespace carries what Claude needs, the seat stops here with its options.
|
|
49
|
+
*/
|
|
50
|
+
export const linuxClaudeMessage = () => [
|
|
51
|
+
'Commonly runs a connected Claude Code inside a sandbox, and on Linux (WSL included) that sandbox',
|
|
52
|
+
'cannot run Claude Code yet, so this agent cannot listen for @mentions here. Instead:',
|
|
53
|
+
' - Use Commonly from your own Claude Code sessions: the Connect page shows a `claude mcp add` command.',
|
|
54
|
+
HOSTED_LINE,
|
|
55
|
+
].join('\n');
|
|
56
|
+
|
|
57
|
+
/** Why this host cannot confine the seat, or null when it can (or the seat declares no sandbox). */
|
|
58
|
+
export const hostSandboxRefusal = ({
|
|
59
|
+
environment,
|
|
60
|
+
adapterName,
|
|
61
|
+
platform = process.platform,
|
|
62
|
+
detectBwrap = defaultDetectBwrap,
|
|
63
|
+
detectSeatbelt = defaultDetectSeatbelt,
|
|
64
|
+
} = {}) => {
|
|
65
|
+
if (!Object.prototype.hasOwnProperty.call(ADAPTER_LABELS, adapterName)) return null;
|
|
66
|
+
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
67
|
+
if (!sandbox || typeof sandbox !== 'object') return null;
|
|
68
|
+
const mode = sandbox.mode ?? (sandbox.trust === 'public' ? resolvePublicSandboxMode(sandbox, platform) : undefined);
|
|
69
|
+
if (mode !== 'bwrap' && !SEATBELT_MODES.has(mode)) return null;
|
|
70
|
+
|
|
71
|
+
if (platform === 'win32') return windowsSandboxMessage(adapterName);
|
|
72
|
+
if (mode === 'bwrap' && adapterName === 'claude') return linuxClaudeMessage();
|
|
73
|
+
if (mode === 'bwrap') {
|
|
74
|
+
const bwrap = detectBwrap();
|
|
75
|
+
return bwrap.available ? null : `This seat runs in a bubblewrap sandbox, which is not available here. ${bwrap.error}`;
|
|
76
|
+
}
|
|
77
|
+
const seatbelt = detectSeatbelt();
|
|
78
|
+
return seatbelt.available
|
|
79
|
+
? null
|
|
80
|
+
: `This seat runs in a macOS Seatbelt sandbox (sandbox.mode=${mode}), which is not available here. ${seatbelt.error}`;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default { hostSandboxRefusal, linuxClaudeMessage, windowsSandboxMessage };
|
|
@@ -415,18 +415,17 @@ export const buildSeatbeltProfile = ({
|
|
|
415
415
|
`(allow network-outbound (remote tcp "localhost:${port}"))`
|
|
416
416
|
)).join('\n');
|
|
417
417
|
const claudeRuntimeRules = allowClaudeRuntimeAccess ? (() => {
|
|
418
|
-
|
|
419
|
-
|
|
418
|
+
// Claude's temp root is the seat's own: the adapter sets CLAUDE_CODE_TMPDIR
|
|
419
|
+
// under statePath, which the state rule above already admits. The
|
|
420
|
+
// uid-wide /private/tmp/claude-<uid> holds every other Claude session's
|
|
421
|
+
// temp files on the machine, so it is not admitted.
|
|
422
|
+
// Claude's security helper needs the encrypted login-keychain database and
|
|
423
|
+
// this non-secret locale file: that one file, not the Keychains folder.
|
|
424
|
+
const loginKeychain = join(homedir(), 'Library', 'Keychains', 'login.keychain-db');
|
|
420
425
|
const textEncoding = join(homedir(), '.CFUserTextEncoding');
|
|
421
426
|
return [
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(claudeTmp)}"))`,
|
|
425
|
-
`(allow file-read* file-test-existence file-write* ${literal(claudeTmp)} ${subpath(claudeTmp)})`,
|
|
426
|
-
// Claude's security helper needs the encrypted login-keychain database
|
|
427
|
-
// and this non-secret locale file. Other wrappers do not get this access.
|
|
428
|
-
`(allow file-read* file-test-existence ${subpath(userKeychains)} ${literal(textEncoding)})`,
|
|
429
|
-
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(userKeychains)}"))`,
|
|
427
|
+
`(allow file-read* file-test-existence ${literal(loginKeychain)} ${literal(textEncoding)})`,
|
|
428
|
+
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(loginKeychain)}"))`,
|
|
430
429
|
];
|
|
431
430
|
})() : [];
|
|
432
431
|
|