@commonlyai/cli 0.1.376 → 0.1.378
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 +20 -0
- package/src/lib/sandbox/bwrap.js +69 -4
- package/src/lib/sandbox/host-check.js +36 -5
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -1867,6 +1867,24 @@ const FINAL_TEXT_IS_POSTED = 'Your final text is posted to the pod unless it is
|
|
|
1867
1867
|
// predicate, so the line and the drop can't disagree.
|
|
1868
1868
|
const seatPostsForItself = (environment) => (environment?.mcp || [])
|
|
1869
1869
|
.some((server) => server?.name === COMMONLY_MCP_SERVER_NAME);
|
|
1870
|
+
// F483: a reaction is the third way to close a wake, beside a post and
|
|
1871
|
+
// NO_REPLY, for the turn whose whole answer would be "thanks" or "got it". It is
|
|
1872
|
+
// offered only where the spawn carries the commonly tools: the seat declares the
|
|
1873
|
+
// server AND its adapter wires the declared servers into the spawn. The CLI's
|
|
1874
|
+
// Hermes adapter passes no MCP server to Hermes (the Hermes plugin is a separate,
|
|
1875
|
+
// standalone install), so a Hermes seat is never told about a tool it lacks
|
|
1876
|
+
// (CodeRabbit on #2816). Add an adapter here only once its spawn wires `mcp`.
|
|
1877
|
+
const ADAPTERS_THAT_WIRE_MCP = new Set(['claude', 'codex', 'opencode', 'goose', 'pi', 'qwen', 'dsh']);
|
|
1878
|
+
export const seatCanReact = (adapterName, environment) => (
|
|
1879
|
+
ADAPTERS_THAT_WIRE_MCP.has(String(adapterName || '')) && seatPostsForItself(environment)
|
|
1880
|
+
);
|
|
1881
|
+
const REACTION_CLOSES_A_WAKE = 'If an acknowledgement is all you would post, react to the message you would acknowledge '
|
|
1882
|
+
+ '(commonly_react_to_message with its message id) instead, then end with NO_REPLY.';
|
|
1883
|
+
// Only a shown item the seat may act on gives the reaction a target: a peer's
|
|
1884
|
+
// read-only item is not one, an item already settled this batch (a duplicate)
|
|
1885
|
+
// is only context, and an ask response or a ruling carries no id.
|
|
1886
|
+
export const reactableEntry = (entry) => !entry.readOnly && !entry.result
|
|
1887
|
+
&& Boolean(entry.event?.payload?.messageId);
|
|
1870
1888
|
const HEARTBEAT_TEXT_IS_NOT_POSTED = 'This turn is only a heartbeat: nobody asked you anything, and your final text is not posted. '
|
|
1871
1889
|
+ 'If something needs saying, post it with commonly_post_message, then end with NO_REPLY. '
|
|
1872
1890
|
+ 'Otherwise end with NO_REPLY alone, with no summary.';
|
|
@@ -3765,6 +3783,8 @@ export const performRun = ({
|
|
|
3765
3783
|
? `Do not narrate the inbox. ${HEARTBEAT_TEXT_IS_NOT_POSTED}`
|
|
3766
3784
|
: 'Do not narrate the inbox. Post only an action or a materially useful response; otherwise return NO_REPLY. '
|
|
3767
3785
|
+ FINAL_TEXT_IS_POSTED
|
|
3786
|
+
+ (seatCanReact(adapter?.name, seatEnvironment) && shownEntries.some(reactableEntry)
|
|
3787
|
+
? ` ${REACTION_CLOSES_A_WAKE}` : '')
|
|
3768
3788
|
+ roomQuestionLine(pod, shownEntries)),
|
|
3769
3789
|
].join('\n\n');
|
|
3770
3790
|
};
|
package/src/lib/sandbox/bwrap.js
CHANGED
|
@@ -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)
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|