@commonlyai/cli 0.1.376 → 0.1.377

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.376",
3
+ "version": "0.1.377",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -156,6 +156,74 @@ export const detectBwrap = ({
156
156
  }
157
157
  };
158
158
 
159
+ // OpenCode's private network: inside its own network namespace the loopback
160
+ // bridge (opencode-loopback.mjs) raises `lo` with CAP_NET_ADMIN, then drops
161
+ // both capabilities before the model process starts. wrapArgvWithBwrap and
162
+ // detectBwrapLoopback share these flags so the probe asks for what the
163
+ // sandbox will.
164
+ export const LOOPBACK_ISOLATION_FLAGS = Object.freeze([
165
+ '--uid', '0', '--gid', '0',
166
+ '--cap-add', 'CAP_NET_ADMIN', '--cap-add', 'CAP_SETPCAP',
167
+ ]);
168
+
169
+ // Where the bridge looks for iproute2's `ip`. The bridge keeps its own copy
170
+ // (only its file is bound into the sandbox); a test holds the two equal.
171
+ export const IP_CANDIDATES = Object.freeze(['/usr/sbin/ip', '/sbin/ip', '/usr/bin/ip', '/bin/ip']);
172
+
173
+ /**
174
+ * F540: can this host give OpenCode's sandbox its private network? detectBwrap
175
+ * proves bubblewrap can start a namespace; a host can do that and still refuse
176
+ * the capability the loopback needs. Ubuntu 26.04 does ("RTNETLINK answers:
177
+ * Operation not permitted", GitHub run 43770297952), and so does Ubuntu's
178
+ * bwrap-userns-restrict AppArmor profile, under which what bubblewrap starts
179
+ * gets no capabilities. So this starts the same namespace with the same flags
180
+ * and raises its loopback. Call it only once detectBwrap reports available.
181
+ */
182
+ export const detectBwrapLoopback = ({
183
+ spawn = spawnSync,
184
+ platform = process.platform,
185
+ exists = existsSync,
186
+ readRestriction = readApparmorRestriction,
187
+ readRelease = readUbuntuRelease,
188
+ } = {}) => {
189
+ if (platform !== 'linux') {
190
+ return { available: false, error: nonLinuxMessage(platform) };
191
+ }
192
+ const ip = IP_CANDIDATES.find((candidate) => exists(candidate));
193
+ if (!ip) {
194
+ return {
195
+ available: false,
196
+ missingIp: true,
197
+ error: 'It needs the ip command, which is not installed here. Install iproute2: '
198
+ + '`sudo apt install iproute2` (Debian/Ubuntu, WSL), `sudo dnf install iproute` (Fedora) '
199
+ + 'or `sudo pacman -S iproute2` (Arch).',
200
+ };
201
+ }
202
+ try {
203
+ const probe = spawn('bwrap', [
204
+ '--unshare-all', '--unshare-net', ...LOOPBACK_ISOLATION_FLAGS,
205
+ '--ro-bind', '/', '/', '--die-with-parent',
206
+ ip, 'link', 'set', 'lo', 'up',
207
+ ], { encoding: 'utf8', timeout: 10_000 });
208
+ if (probe.error || probe.status !== 0) {
209
+ const reason = (probe.stderr || probe.error?.message || `exit ${probe.status}`).trim().split('\n').pop();
210
+ return {
211
+ available: false,
212
+ // As with the namespace probe: only a bwrap that ran and exited
213
+ // refusing says something about this host.
214
+ loopbackRefused: !probe.error && typeof probe.status === 'number',
215
+ reason,
216
+ apparmorRestricted: readRestriction(),
217
+ ubuntuRelease: readRelease(),
218
+ error: `bubblewrap starts a sandbox here, but not the private network OpenCode needs inside it (${reason}).`,
219
+ };
220
+ }
221
+ return { available: true };
222
+ } catch (err) {
223
+ return { available: false, error: `bwrap loopback detection failed: ${err.message}` };
224
+ }
225
+ };
226
+
159
227
  /**
160
228
  * Build the bwrap-wrapped argv. Caller spawns argv[0] with argv.slice(1).
161
229
  *
@@ -193,10 +261,7 @@ export const wrapArgvWithBwrap = (innerArgv, env, opts = {}) => {
193
261
  const flags = [
194
262
  '--unshare-all',
195
263
  ...networkFlags,
196
- ...(opts.enableLoopback ? [
197
- '--uid', '0', '--gid', '0',
198
- '--cap-add', 'CAP_NET_ADMIN', '--cap-add', 'CAP_SETPCAP',
199
- ] : []),
264
+ ...(opts.enableLoopback ? LOOPBACK_ISOLATION_FLAGS : []),
200
265
  '--die-with-parent',
201
266
  '--new-session',
202
267
  '--proc', '/proc',
@@ -19,7 +19,7 @@
19
19
 
20
20
  import { normalizeSandboxTrust } from '../environment.js';
21
21
  import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from './mode.js';
22
- import { detectBwrap as defaultDetectBwrap } from './bwrap.js';
22
+ import { detectBwrap as defaultDetectBwrap, detectBwrapLoopback as defaultDetectBwrapLoopback } from './bwrap.js';
23
23
  import { detectSeatbelt as defaultDetectSeatbelt } from './seatbelt.js';
24
24
  import { codexTrustedPerimeter } from './codex-perimeter.js';
25
25
  import { CLI } from '../cli-hint.js';
@@ -122,6 +122,26 @@ export const bwrapRefusedMessage = (adapterName, { reason, apparmorRestricted, u
122
122
  ].join('\n');
123
123
  };
124
124
 
125
+ /**
126
+ * F540: bubblewrap starts here, but this host won't give a public OpenCode's
127
+ * sandbox the private network it raises inside it. Ubuntu's bubblewrap profile
128
+ * is what takes that capability away, so it is never offered as the way out.
129
+ */
130
+ export const opencodeLoopbackMessage = ({
131
+ loopbackRefused, missingIp, reason, apparmorRestricted, error,
132
+ } = {}) => [
133
+ 'A connected OpenCode runs inside a bubblewrap sandbox with a private network of its own, '
134
+ + (loopbackRefused === true
135
+ ? `and this machine lets bubblewrap start the sandbox but not set up that network (${reason}).`
136
+ : `which can't be set up here. ${error || ''}`.trim()),
137
+ ...(loopbackRefused === true && apparmorRestricted === true
138
+ ? ['AppArmor on recent Ubuntu releases takes away the network setup that sandbox needs.']
139
+ : []),
140
+ 'So this agent cannot listen for @mentions here yet. You can:',
141
+ ...(missingIp === true ? [' - Install iproute2 as above and run the same command again.'] : []),
142
+ HOSTED_LINE,
143
+ ].join('\n');
144
+
125
145
  const CODEX_UNSANDBOXED_RUN_LINE = ` - In invite-only pods, run it without a sandbox: ${CLI} agent run <name> ${UNSANDBOXED_FLAG}`
126
146
  + ' (in the foreground; the daemon takes this only on Windows).'
127
147
  + ' Nothing confines it: it runs with your own access to files and commands, anyone in the pod,'
@@ -202,6 +222,8 @@ export const hostSandboxRefusal = ({
202
222
  // chooses Codex's words: it never lets a seat through.
203
223
  optedIn = false,
204
224
  detectBwrap = defaultDetectBwrap,
225
+ // F540: only a public OpenCode seat needs it (adapters/opencode.js enableLoopback).
226
+ detectBwrapLoopback = defaultDetectBwrapLoopback,
205
227
  detectSeatbelt = defaultDetectSeatbelt,
206
228
  // F387: a cloud-codex pod declares itself here (codex-perimeter.js).
207
229
  env = process.env,
@@ -254,10 +276,19 @@ export const hostSandboxRefusal = ({
254
276
  }
255
277
  if (mode === 'bwrap') {
256
278
  const bwrap = detectBwrap();
257
- if (bwrap.available) return null;
258
- return bwrap.namespaceRefused === true
259
- ? bwrapRefusedMessage(adapterName, bwrap)
260
- : `This seat runs in a bubblewrap sandbox, which is not available here. ${bwrap.error}`;
279
+ if (!bwrap.available) {
280
+ return bwrap.namespaceRefused === true
281
+ ? bwrapRefusedMessage(adapterName, bwrap)
282
+ : `This seat runs in a bubblewrap sandbox, which is not available here. ${bwrap.error}`;
283
+ }
284
+ // A public OpenCode seat also raises a private loopback inside the sandbox.
285
+ // A host can start the namespace and refuse that, and every turn would then
286
+ // die at its first step while the pod heard nothing (F540).
287
+ if (adapterName === 'opencode' && sandbox.trust === 'public') {
288
+ const loopback = detectBwrapLoopback();
289
+ if (!loopback.available) return opencodeLoopbackMessage(loopback);
290
+ }
291
+ return null;
261
292
  }
262
293
  const seatbelt = detectSeatbelt();
263
294
  return seatbelt.available