@commonlyai/cli 0.1.379 → 0.1.381
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/node_modules/@commonlyai/seats/src/adapters/hermes.js +8 -0
- package/package.json +1 -1
- package/src/commands/agent.js +24 -12
- package/src/lib/adapters/opencode.js +4 -0
- package/src/lib/adapters/qwen.js +4 -0
- package/src/lib/sandbox-option-refusal.js +92 -0
- package/src/lib/unconfined-seat-guard.js +6 -2
|
@@ -228,6 +228,14 @@ export const createHermesAdapter = ({
|
|
|
228
228
|
throw new Error('Commonly can\'t give Hermes extra MCP servers yet, so this environment file can\'t '
|
|
229
229
|
+ 'list any. Remove the mcp block to run Hermes.');
|
|
230
230
|
}
|
|
231
|
+
// Workspace trust is claude's tier. Any other adapter that ran it would
|
|
232
|
+
// run bare while the unconfined-seat guard reads it as confined.
|
|
233
|
+
if (environment?.sandbox?.trust === 'workspace') {
|
|
234
|
+
throw new Error('hermes adapter: sandbox.trust=workspace is claude-only for now. '
|
|
235
|
+
+ "Attach this agent with the claude adapter, or remove sandbox.trust 'workspace' from its environment file, "
|
|
236
|
+
+ "along with sandbox.allow (it applies only to trust 'workspace') and any sandbox.mode other than 'none'. "
|
|
237
|
+
+ 'Hermes has no sandbox yet, so it runs with no sandbox settings at all.');
|
|
238
|
+
}
|
|
231
239
|
if (effectiveTrust(environment?.sandbox?.trust) === 'public') {
|
|
232
240
|
throw new Error('Commonly has no sandbox for Hermes yet, so Hermes can\'t run as a public seat. '
|
|
233
241
|
+ 'Pick another harness for a public seat.');
|
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -102,6 +102,7 @@ import {
|
|
|
102
102
|
import { mergeGrantBrokers, withholdGrantBroker } from '../lib/grant-broker-guard.js';
|
|
103
103
|
import { withPublicSeatMcpFlag } from '../lib/public-seat-mcp-flag.js';
|
|
104
104
|
import { UNCONFINED_TURN_REFUSAL, seatRunsUnconfined, unconfinedPodRefusalReason } from '../lib/unconfined-seat-guard.js';
|
|
105
|
+
import { sandboxOptionRefusal } from '../lib/sandbox-option-refusal.js';
|
|
105
106
|
import {
|
|
106
107
|
OUTSIDER_GRANT_MCP_UNCONFINED, outsiderGrantMcpRefusal, seatIsConfined, unshippedMcpEntries,
|
|
107
108
|
} from '../lib/outsider-grant-mcp.js';
|
|
@@ -294,6 +295,21 @@ export const deleteAgentToken = (name) => {
|
|
|
294
295
|
export const BOOTSTRAP_ADAPTER_DETECT_ORDER = ['claude', 'codex', 'pi'];
|
|
295
296
|
export const NO_AGENT_CLI_CODE = 'no_agent_cli';
|
|
296
297
|
|
|
298
|
+
/**
|
|
299
|
+
* What `agent run` says when no token is set. On Windows the page's lines are
|
|
300
|
+
* PowerShell: pasted into Command Prompt, the `$env:` lines set nothing and the
|
|
301
|
+
* run ends here before it reaches the server (F548), so name the shell and its
|
|
302
|
+
* form rather than `export`.
|
|
303
|
+
*/
|
|
304
|
+
export const noRunTokenMessage = ({ name, agentArg = name, platform = process.platform }) => {
|
|
305
|
+
const set = platform === 'win32'
|
|
306
|
+
? 'In PowerShell, not Command Prompt, run the $env:COMMONLY_API_URL="…" and $env:COMMONLY_AGENT_TOKEN="…" lines'
|
|
307
|
+
: 'Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN';
|
|
308
|
+
return `No token for '${name}'. ${set}`
|
|
309
|
+
+ ` (shown on the Connect your own agent page) and re-run, or:`
|
|
310
|
+
+ ` ${CLI} agent attach <adapter> --pod <podId> --name ${agentArg}`;
|
|
311
|
+
};
|
|
312
|
+
|
|
297
313
|
/**
|
|
298
314
|
* A saved seat with no enforced sandbox: an adapter that takes one, no
|
|
299
315
|
* workspace, and an environment that is absent or enforces nothing (a record
|
|
@@ -1372,8 +1388,9 @@ export const updateAgentConfiguration = async ({
|
|
|
1372
1388
|
environment = { ...environmentRuntime };
|
|
1373
1389
|
}
|
|
1374
1390
|
{
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1391
|
+
const configAdapter = String(runtime.adapter || record.adapter || '').trim().toLowerCase();
|
|
1392
|
+
const refusal = providerRefusal(environment, adapterRegistry.getAdapter(configAdapter))
|
|
1393
|
+
|| sandboxOptionRefusal(environment, configAdapter);
|
|
1377
1394
|
if (refusal) throw new Error(refusal);
|
|
1378
1395
|
}
|
|
1379
1396
|
if (environment) config.environment = environmentForServer(environment);
|
|
@@ -1544,7 +1561,7 @@ export const performAttach = async ({
|
|
|
1544
1561
|
// kernel server. The daemon applies this same baseline before every spawn.
|
|
1545
1562
|
environment = withDefaultMcpServer(await parseEnvironmentFile(envPath), adapterName);
|
|
1546
1563
|
{
|
|
1547
|
-
const refusal = providerRefusal(environment, adapter);
|
|
1564
|
+
const refusal = providerRefusal(environment, adapter) || sandboxOptionRefusal(environment, adapterName, platform);
|
|
1548
1565
|
if (refusal) throw new Error(refusal);
|
|
1549
1566
|
}
|
|
1550
1567
|
workspace = await resolveWorkspace(environment, agentName, dirname(envPath));
|
|
@@ -2215,7 +2232,7 @@ export const performRun = ({
|
|
|
2215
2232
|
const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
|
|
2216
2233
|
reportRuntime = reportRuntime && WALKED_HARNESSES.includes(adapter?.name);
|
|
2217
2234
|
{
|
|
2218
|
-
const refusal = providerRefusal(environment, adapter);
|
|
2235
|
+
const refusal = providerRefusal(environment, adapter) || sandboxOptionRefusal(environment, adapter?.name);
|
|
2219
2236
|
if (refusal) throw new Error(refusal);
|
|
2220
2237
|
}
|
|
2221
2238
|
const requestedTurnTimeout = Number(turnTimeoutMs ?? process.env.COMMONLY_AGENT_RUN_TIMEOUT_MS);
|
|
@@ -5944,14 +5961,9 @@ Docs:
|
|
|
5944
5961
|
process.exit(1);
|
|
5945
5962
|
}
|
|
5946
5963
|
if (!record) {
|
|
5947
|
-
//
|
|
5948
|
-
//
|
|
5949
|
-
console.error(
|
|
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}`);
|
|
5964
|
+
// On Windows the page's lines are PowerShell's ($env:…), and in Command
|
|
5965
|
+
// Prompt they set nothing, so this is where that run lands.
|
|
5966
|
+
console.error(noRunTokenMessage({ name, agentArg }));
|
|
5955
5967
|
process.exit(1);
|
|
5956
5968
|
}
|
|
5957
5969
|
const instanceRefusal = named ? runInstanceRefusal({ record, instanceId }) : null;
|
|
@@ -1471,6 +1471,10 @@ export default {
|
|
|
1471
1471
|
if (isPublic && !['workspace', 'read-only', 'bwrap'].includes(sandboxMode)) {
|
|
1472
1472
|
throw new Error(`public OpenCode agents require an enforced sandbox mode, got ${sandboxMode || 'unset'}`);
|
|
1473
1473
|
}
|
|
1474
|
+
// F535: a public seat reads only its workspace (sandbox-option-refusal.js).
|
|
1475
|
+
if (isPublic && sandbox.filesystem?.['read-outside']?.length) {
|
|
1476
|
+
throw new Error('opencode adapter: public seats do not allow sandbox.filesystem.read-outside');
|
|
1477
|
+
}
|
|
1474
1478
|
|
|
1475
1479
|
const provider = ctx.environment?.provider;
|
|
1476
1480
|
// Attach and config refuse these first; a turn refuses them too, for a
|
package/src/lib/adapters/qwen.js
CHANGED
|
@@ -332,6 +332,10 @@ export default {
|
|
|
332
332
|
if (isPublic && !['workspace', 'read-only', 'bwrap'].includes(mode)) {
|
|
333
333
|
throw new Error('public Qwen seats require an enforced sandbox');
|
|
334
334
|
}
|
|
335
|
+
// F535: a public seat reads only its workspace (sandbox-option-refusal.js).
|
|
336
|
+
if (isPublic && sandbox.filesystem?.['read-outside']?.length) {
|
|
337
|
+
throw new Error('qwen adapter: public seats do not allow sandbox.filesystem.read-outside');
|
|
338
|
+
}
|
|
335
339
|
const provider = ctx.environment?.provider;
|
|
336
340
|
if (!provider || !ctx.environment?.model) {
|
|
337
341
|
throw new Error('Qwen seats require environment.provider and environment.model');
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refuse before open (F535): a sandbox option the seat's adapter can't
|
|
3
|
+
* enforce fails the seat at start, never drops silently. One check for config,
|
|
4
|
+
* attach and run (the daemon starts seats through run), beside providerRefusal.
|
|
5
|
+
*
|
|
6
|
+
* Each rule below is a shape that was accepted and then not enforced (the
|
|
7
|
+
* 11-15 audit on main 10364a0c):
|
|
8
|
+
* - network.allow-hosts on an open network: the schema reads it and no
|
|
9
|
+
* adapter does, so every host stays reachable. Beside a restricted network
|
|
10
|
+
* it only asks for less than it gets, and the rules below decide.
|
|
11
|
+
* - network.policy=restricted under macOS Seatbelt on claude, opencode or
|
|
12
|
+
* qwen: the profile keeps the network on for the model and MCP. Under bwrap
|
|
13
|
+
* claude and qwen refuse it already, and opencode restricts it.
|
|
14
|
+
* - sandbox.mode on a seat with no public or workspace trust: claude (any mode
|
|
15
|
+
* but bwrap), opencode and qwen spawn bare. codex runs every such seat in
|
|
16
|
+
* its one private profile (workspace writable, network on), so it keeps
|
|
17
|
+
* mode workspace and refuses read-only. dsh enforces its one shape.
|
|
18
|
+
* - network or filesystem rules on a seat with no trust: nothing reads them
|
|
19
|
+
* when there is no mode, and codex's private profile never does.
|
|
20
|
+
* An open network policy and empty lists ask for nothing, so they pass.
|
|
21
|
+
* The test-only `stub` adapter runs nothing and is not checked.
|
|
22
|
+
*/
|
|
23
|
+
import { normalizeSandboxTrust } from './environment.js';
|
|
24
|
+
import { resolvePublicSandboxMode } from './sandbox/mode.js';
|
|
25
|
+
import { adapterConfinesItself } from './unconfined-seat-guard.js';
|
|
26
|
+
|
|
27
|
+
const SEATBELT_MODES = new Set(['workspace', 'read-only']);
|
|
28
|
+
const SEATBELT_NETWORK_KEPT = new Set(['claude', 'opencode', 'qwen']);
|
|
29
|
+
// The modes an adapter honours on a seat with no confined trust (dsh's one
|
|
30
|
+
// shape returns earlier, through adapterConfinesItself).
|
|
31
|
+
const MODES_WITHOUT_TRUST = { codex: new Set(['workspace']) };
|
|
32
|
+
const UNCHECKED = new Set(['stub']);
|
|
33
|
+
|
|
34
|
+
const declares = (value) => value !== undefined && value !== null && value !== ''
|
|
35
|
+
&& !(Array.isArray(value) && value.length === 0)
|
|
36
|
+
&& !(typeof value === 'object' && !Array.isArray(value) && Object.values(value).every((v) => !declares(v)));
|
|
37
|
+
// A rule asks for something unless it is an open network or an empty list.
|
|
38
|
+
const asksFor = (key, rules) => {
|
|
39
|
+
if (!rules || typeof rules !== 'object') return declares(rules);
|
|
40
|
+
return Object.entries(rules).some(([name, value]) => declares(value)
|
|
41
|
+
&& !(key === 'network' && name === 'policy' && value === 'unrestricted'));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Null when every sandbox option the seat declares is enforced, otherwise why not. */
|
|
45
|
+
export const sandboxOptionRefusal = (environment, adapterName, platform = process.platform) => {
|
|
46
|
+
if (!environment?.sandbox || UNCHECKED.has(adapterName)) return null;
|
|
47
|
+
const sandbox = normalizeSandboxTrust(environment.sandbox);
|
|
48
|
+
const adapter = adapterName || 'this';
|
|
49
|
+
const network = sandbox.network || {};
|
|
50
|
+
if (declares(network['allow-hosts']) && network.policy !== 'restricted') {
|
|
51
|
+
return `sandbox.network.allow-hosts is not enforced by any adapter yet, so the ${adapter} seat would reach every host. `
|
|
52
|
+
+ 'Remove it, or use sandbox.network.policy.';
|
|
53
|
+
}
|
|
54
|
+
// A public seat answers strangers, so it reads only its workspace: a path
|
|
55
|
+
// outside it is what an injected agent would use to reach tokens
|
|
56
|
+
// (F535). bwrap opencode and qwen used to bind it in.
|
|
57
|
+
if (sandbox.trust === 'public' && declares(sandbox.filesystem?.['read-outside'])) {
|
|
58
|
+
return `A public seat reads only its workspace, so sandbox.filesystem.read-outside is refused on the ${adapter} adapter. `
|
|
59
|
+
+ 'Remove it, or copy what the agent needs into the workspace.';
|
|
60
|
+
}
|
|
61
|
+
if (adapterConfinesItself(adapterName, sandbox)) return null;
|
|
62
|
+
const confined = sandbox.trust === 'public' || sandbox.trust === 'workspace';
|
|
63
|
+
if (confined) {
|
|
64
|
+
const mode = resolvePublicSandboxMode(sandbox, platform);
|
|
65
|
+
if (network.policy === 'restricted' && SEATBELT_MODES.has(mode) && SEATBELT_NETWORK_KEPT.has(adapterName)) {
|
|
66
|
+
return `The ${adapter} adapter can't restrict the network under macOS Seatbelt (sandbox.mode=${mode}): `
|
|
67
|
+
+ 'the sandbox keeps it on for the model and MCP. Remove sandbox.network.policy, or run the seat under bwrap on Linux.';
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const hasMode = declares(sandbox.mode) && sandbox.mode !== 'none';
|
|
72
|
+
const ownModes = MODES_WITHOUT_TRUST[adapterName];
|
|
73
|
+
if (hasMode && !ownModes?.has(sandbox.mode)) {
|
|
74
|
+
return ownModes
|
|
75
|
+
? `The ${adapter} adapter runs a seat with no sandbox.trust in one private profile (workspace writable, network on), `
|
|
76
|
+
+ `so sandbox.mode=${sandbox.mode} would not apply. Add sandbox.trust=public, or remove sandbox.mode.`
|
|
77
|
+
: `The ${adapter} adapter applies sandbox.mode=${sandbox.mode} only with sandbox.trust=public, so this seat would run `
|
|
78
|
+
+ 'without a sandbox. Add sandbox.trust=public, or remove sandbox.mode.';
|
|
79
|
+
}
|
|
80
|
+
const rules = ['network', 'filesystem'].filter((key) => asksFor(key, sandbox[key]));
|
|
81
|
+
if (rules.length) {
|
|
82
|
+
const they = rules.length > 1;
|
|
83
|
+
return hasMode
|
|
84
|
+
? `sandbox.${rules.join(' and sandbox.')} ${they ? 'are' : 'is'} not applied by the ${adapter} adapter's private profile. `
|
|
85
|
+
+ `Add sandbox.trust=public, or remove ${they ? 'them' : 'it'}.`
|
|
86
|
+
: `sandbox.${rules.join(' and sandbox.')} ${they ? 'are' : 'is'} enforced only inside a sandbox, and this `
|
|
87
|
+
+ `${adapter} seat has none. Add sandbox.trust=public, or remove ${they ? 'them' : 'it'}.`;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default sandboxOptionRefusal;
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
* "Confined" is what the adapters enforce, not what the file declares: a public
|
|
20
20
|
* or workspace trust, or a shape one adapter enforces with no trust (claude's
|
|
21
21
|
* `bwrap` mode, dsh's `isConfinedDsh` shape). Any other `sandbox.mode` with no
|
|
22
|
-
* trust is
|
|
23
|
-
*
|
|
22
|
+
* trust is unconfined here: claude, opencode and qwen spawn it bare, codex
|
|
23
|
+
* runs its private profile (workspace writable, network on), and the rest
|
|
24
|
+
* refuse it. `mode: 'none'` always is.
|
|
24
25
|
*
|
|
25
26
|
* A legacy pod with no joinPolicy is reported 'open', and that is not only a
|
|
26
27
|
* default: an agent may self-install into a pod an agent created unless it is
|
|
@@ -50,6 +51,9 @@ const ADAPTER_OWN_CONFINEMENT = {
|
|
|
50
51
|
dsh: isConfinedDshShape,
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
/** True when the adapter enforces this sandbox shape with no trust (claude bwrap, dsh's one shape). */
|
|
55
|
+
export const adapterConfinesItself = (adapterName, sandbox) => Boolean(ADAPTER_OWN_CONFINEMENT[adapterName]?.(sandbox));
|
|
56
|
+
|
|
53
57
|
export const seatRunsUnconfined = ({ environment, adapterName }) => {
|
|
54
58
|
if (UNCONFINED_UNCHECKED_ADAPTERS.has(adapterName)) return false;
|
|
55
59
|
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|