@commonlyai/cli 0.1.379 → 0.1.380

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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.379",
3
+ "version": "0.1.380",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -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';
@@ -1372,8 +1373,9 @@ export const updateAgentConfiguration = async ({
1372
1373
  environment = { ...environmentRuntime };
1373
1374
  }
1374
1375
  {
1375
- const refusal = providerRefusal(environment,
1376
- adapterRegistry.getAdapter(String(runtime.adapter || record.adapter || '').trim().toLowerCase()));
1376
+ const configAdapter = String(runtime.adapter || record.adapter || '').trim().toLowerCase();
1377
+ const refusal = providerRefusal(environment, adapterRegistry.getAdapter(configAdapter))
1378
+ || sandboxOptionRefusal(environment, configAdapter);
1377
1379
  if (refusal) throw new Error(refusal);
1378
1380
  }
1379
1381
  if (environment) config.environment = environmentForServer(environment);
@@ -1544,7 +1546,7 @@ export const performAttach = async ({
1544
1546
  // kernel server. The daemon applies this same baseline before every spawn.
1545
1547
  environment = withDefaultMcpServer(await parseEnvironmentFile(envPath), adapterName);
1546
1548
  {
1547
- const refusal = providerRefusal(environment, adapter);
1549
+ const refusal = providerRefusal(environment, adapter) || sandboxOptionRefusal(environment, adapterName, platform);
1548
1550
  if (refusal) throw new Error(refusal);
1549
1551
  }
1550
1552
  workspace = await resolveWorkspace(environment, agentName, dirname(envPath));
@@ -2215,7 +2217,7 @@ export const performRun = ({
2215
2217
  const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
2216
2218
  reportRuntime = reportRuntime && WALKED_HARNESSES.includes(adapter?.name);
2217
2219
  {
2218
- const refusal = providerRefusal(environment, adapter);
2220
+ const refusal = providerRefusal(environment, adapter) || sandboxOptionRefusal(environment, adapter?.name);
2219
2221
  if (refusal) throw new Error(refusal);
2220
2222
  }
2221
2223
  const requestedTurnTimeout = Number(turnTimeoutMs ?? process.env.COMMONLY_AGENT_RUN_TIMEOUT_MS);
@@ -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
@@ -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 spawned bare (claude, codex) or refused at spawn, so it is
23
- * unconfined here, and `mode: 'none'` always is.
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);