@commonlyai/cli 0.1.325 → 0.1.327
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
|
@@ -96,6 +96,8 @@ import {
|
|
|
96
96
|
withDefaultSandbox,
|
|
97
97
|
} from '../lib/default-environment.js';
|
|
98
98
|
import { mergeGrantBrokers, withholdGrantBroker } from '../lib/grant-broker-guard.js';
|
|
99
|
+
import { withPublicSeatMcpFlag } from '../lib/public-seat-mcp-flag.js';
|
|
100
|
+
import { UNCONFINED_TURN_REFUSAL, seatRunsUnconfined, unconfinedPodRefusalReason } from '../lib/unconfined-seat-guard.js';
|
|
99
101
|
import {
|
|
100
102
|
OUTSIDER_GRANT_MCP_UNCONFINED, outsiderGrantMcpRefusal, seatIsConfined, unshippedMcpEntries,
|
|
101
103
|
} from '../lib/outsider-grant-mcp.js';
|
|
@@ -1095,10 +1097,10 @@ export const buildDefaultEnvironment = (adapterName) => {
|
|
|
1095
1097
|
* work while the OS-level sandbox never engaged at all.
|
|
1096
1098
|
*
|
|
1097
1099
|
* Deny-by-default only means something if ABSENT is refused, so this is a hard
|
|
1098
|
-
* error rather than a warning.
|
|
1099
|
-
* (
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1100
|
+
* error rather than a warning. A seat the adapters do not confine
|
|
1101
|
+
* (lib/unconfined-seat-guard.js `seatRunsUnconfined`) attaches only to a pod
|
|
1102
|
+
* confirmed private and invite-only; a pod whose visibility cannot be read
|
|
1103
|
+
* fails closed, and each turn checks again.
|
|
1102
1104
|
* dsh is private-only, so it requires a successful visibility read and rejects
|
|
1103
1105
|
* a public pod even without a sandbox declaration.
|
|
1104
1106
|
*/
|
|
@@ -1107,7 +1109,8 @@ export const assertSandboxDeclaredForPublicPod = async ({
|
|
|
1107
1109
|
podId,
|
|
1108
1110
|
environment,
|
|
1109
1111
|
adapterName,
|
|
1110
|
-
|
|
1112
|
+
// Kept for callers; every outcome here is now a return or a refusal.
|
|
1113
|
+
log: _log = () => {},
|
|
1111
1114
|
}) => {
|
|
1112
1115
|
if (!podId || !client) return;
|
|
1113
1116
|
|
|
@@ -1124,7 +1127,9 @@ export const assertSandboxDeclaredForPublicPod = async ({
|
|
|
1124
1127
|
if (pod?.publicRead || pod?.communityListed) {
|
|
1125
1128
|
throw new Error('dsh supports private pods only; this pod is publicly readable');
|
|
1126
1129
|
}
|
|
1127
|
-
|
|
1130
|
+
// dsh's confined shape stops here; an unconfined dsh runs as its owner and
|
|
1131
|
+
// meets the invite-only requirement below.
|
|
1132
|
+
if (!seatRunsUnconfined({ environment, adapterName })) return;
|
|
1128
1133
|
}
|
|
1129
1134
|
|
|
1130
1135
|
// A `workspace` seat lets the room read its start directory (TASK-294), so it
|
|
@@ -1152,41 +1157,45 @@ export const assertSandboxDeclaredForPublicPod = async ({
|
|
|
1152
1157
|
);
|
|
1153
1158
|
}
|
|
1154
1159
|
|
|
1155
|
-
//
|
|
1156
|
-
// legacy `internal`
|
|
1157
|
-
//
|
|
1158
|
-
//
|
|
1159
|
-
|
|
1160
|
-
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
1161
|
-
const mode = sandbox?.mode;
|
|
1162
|
-
const trust = sandbox?.trust;
|
|
1163
|
-
// An ENFORCED declaration is one the adapters act on: a public trust (whose
|
|
1164
|
-
// mode they resolve per host at spawn) or an explicit non-'none' mode. This
|
|
1165
|
-
// mirrors the daemon's predicate in lib/default-environment.js, so the shape
|
|
1166
|
-
// the daemon writes for an unconfigured seat is one attach also accepts.
|
|
1167
|
-
const declared = mode !== 'none'
|
|
1168
|
-
&& (trust === 'public' || typeof mode === 'string');
|
|
1169
|
-
if (declared) return;
|
|
1160
|
+
// Confined means what the adapters enforce: a public trust (normalized, so a
|
|
1161
|
+
// legacy `internal` counts), or dsh's own confined shape. A `sandbox.mode`
|
|
1162
|
+
// with no trust is spawned bare by claude and codex, so it is unconfined here
|
|
1163
|
+
// and per turn alike (lib/unconfined-seat-guard.js).
|
|
1164
|
+
if (!seatRunsUnconfined({ environment, adapterName })) return;
|
|
1170
1165
|
|
|
1166
|
+
// No enforced sandbox: the agent runs as its owner, so the pod has to be
|
|
1167
|
+
// confirmed private, not merely not known to be public. A pod anyone can join
|
|
1168
|
+
// is refused as a public one is, and one whose visibility cannot be read
|
|
1169
|
+
// fails closed (lib/unconfined-seat-guard.js; each turn checks again).
|
|
1171
1170
|
let pod = null;
|
|
1172
1171
|
try {
|
|
1173
1172
|
pod = await client.get(`/api/pods/${podId}`);
|
|
1174
1173
|
} catch {
|
|
1175
|
-
|
|
1176
|
-
'
|
|
1177
|
-
+ '
|
|
1174
|
+
throw new Error(
|
|
1175
|
+
'This agent runs without a sandbox, so it would run with your own access, and this pod\'s '
|
|
1176
|
+
+ 'visibility could not be read. An agent without a sandbox attaches only to a pod confirmed '
|
|
1177
|
+
+ 'private and invite-only. Try again, or add "sandbox": { "trust": "public" } to its environment file.',
|
|
1178
1178
|
);
|
|
1179
|
-
return;
|
|
1180
1179
|
}
|
|
1180
|
+
if (podIsConfirmedPrivate(pod)) return;
|
|
1181
1181
|
|
|
1182
1182
|
const isPublic = Boolean(pod?.publicRead) || Boolean(pod?.communityListed);
|
|
1183
|
-
if (!isPublic)
|
|
1183
|
+
if (!isPublic) {
|
|
1184
|
+
const label = pod?.name ? `"${pod.name}"` : podId;
|
|
1185
|
+
const why = pod?.joinPolicy === 'invite-only' ? 'did not report whether it is publicly readable' : 'is open to join';
|
|
1186
|
+
throw new Error(
|
|
1187
|
+
`${label} ${why}, and this agent runs without a sandbox, so anyone who joins could direct it with your `
|
|
1188
|
+
+ 'own access to files, commands and logins. Make the pod invite-only (its owner sets "Who can join" '
|
|
1189
|
+
+ 'to Invite-only in the pod\'s side panel in Commonly) and try again, or add '
|
|
1190
|
+
+ '"sandbox": { "trust": "public" } to its environment file.',
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1184
1193
|
|
|
1185
1194
|
const label = pod?.name ? `"${pod.name}"` : podId;
|
|
1186
1195
|
throw new Error(
|
|
1187
1196
|
`${label} is publicly readable, so this agent would take instructions from `
|
|
1188
|
-
+ 'people you do not control — but its environment declares no sandbox, and '
|
|
1189
|
-
+ '
|
|
1197
|
+
+ 'people you do not control — but its environment declares no sandbox trust, and '
|
|
1198
|
+
+ 'without one this agent runs with NO sandbox.\n\n'
|
|
1190
1199
|
+ 'Add a sandbox block to the environment file and retry:\n\n'
|
|
1191
1200
|
+ ' "sandbox": { "trust": "public" }\n\n'
|
|
1192
1201
|
+ 'That is the whole declaration: the adapters pick the enforced mode for '
|
|
@@ -2360,22 +2369,35 @@ export const performRun = ({
|
|
|
2360
2369
|
&& effortRefusedByDevice(inventory, desiredEnvironment.effort)
|
|
2361
2370
|
? { ...desiredEnvironment, effort: undefined } : desiredEnvironment;
|
|
2362
2371
|
};
|
|
2363
|
-
const
|
|
2364
|
-
await refreshSeatEnvironment();
|
|
2365
|
-
if (seatEnvironment?.sandbox?.trust !== 'workspace' && !codexUnconfined) {
|
|
2366
|
-
return { environment: seatEnvironment, cwd: agentCwd, binding: sessionBinding };
|
|
2367
|
-
}
|
|
2368
|
-
let installations = null;
|
|
2369
|
-
let readError = null;
|
|
2372
|
+
const readSeatPods = async () => {
|
|
2370
2373
|
try {
|
|
2371
2374
|
const identity = await client.get('/api/agents/runtime/installations', {}, {
|
|
2372
2375
|
signal: AbortSignal.timeout(5000),
|
|
2373
2376
|
});
|
|
2374
|
-
installations
|
|
2377
|
+
return { installations: Array.isArray(identity?.installations) ? identity.installations : [], readError: null };
|
|
2375
2378
|
} catch (err) {
|
|
2376
|
-
installations
|
|
2377
|
-
readError = err;
|
|
2379
|
+
return { installations: null, readError: err };
|
|
2378
2380
|
}
|
|
2381
|
+
};
|
|
2382
|
+
const placeTurn = async () => {
|
|
2383
|
+
await refreshSeatEnvironment();
|
|
2384
|
+
if (seatEnvironment?.sandbox?.trust !== 'workspace' && !codexUnconfined) {
|
|
2385
|
+
const unchecked = { environment: seatEnvironment, cwd: agentCwd, binding: sessionBinding };
|
|
2386
|
+
if (!seatRunsUnconfined({ environment: seatEnvironment, adapterName: adapter.name })) return unchecked;
|
|
2387
|
+
// A seat with no sandbox runs as its owner, so each turn re-reads its
|
|
2388
|
+
// pods and runs only while all are confirmed private
|
|
2389
|
+
// (lib/unconfined-seat-guard.js). There is no confined fallback.
|
|
2390
|
+
const { installations, readError } = await readSeatPods();
|
|
2391
|
+
const reason = unconfinedPodRefusalReason(installations);
|
|
2392
|
+
if (reason !== lastPlacementReason) {
|
|
2393
|
+
log(reason
|
|
2394
|
+
? `turns are refused, because ${reason}: ${UNCONFINED_TURN_REFUSAL}`
|
|
2395
|
+
: 'every pod is confirmed private again; turns run');
|
|
2396
|
+
lastPlacementReason = reason;
|
|
2397
|
+
}
|
|
2398
|
+
return reason ? { ...unchecked, reason, readError, unconfinedRefused: true } : unchecked;
|
|
2399
|
+
}
|
|
2400
|
+
const { installations, readError } = await readSeatPods();
|
|
2379
2401
|
const placement = codexUnconfined
|
|
2380
2402
|
? unconfinedTurnPlacement({ environment: seatEnvironment, installations, cwd: agentCwd })
|
|
2381
2403
|
: workspaceTurnPlacement({
|
|
@@ -2835,7 +2857,7 @@ export const performRun = ({
|
|
|
2835
2857
|
// failed read is not: it throws, so the event stays unacked and comes back
|
|
2836
2858
|
// through the spawn-retry backoff instead of being refused for good.
|
|
2837
2859
|
if (placement.reason) {
|
|
2838
|
-
const turnRefusal = hostSandboxRefusal({
|
|
2860
|
+
const turnRefusal = placement.unconfinedRefused ? UNCONFINED_TURN_REFUSAL : hostSandboxRefusal({
|
|
2839
2861
|
environment: placement.environment,
|
|
2840
2862
|
adapterName: adapter.name,
|
|
2841
2863
|
hostUnconfined,
|
|
@@ -2858,7 +2880,7 @@ export const performRun = ({
|
|
|
2858
2880
|
try {
|
|
2859
2881
|
await client.post(
|
|
2860
2882
|
`/api/agents/runtime/asks/${encodeURIComponent(event.payload.requestId)}/respond`,
|
|
2861
|
-
{ content: 'I can’t take this ask:
|
|
2883
|
+
{ content: 'I can’t take this ask: a pod I’m in isn’t private and invite-only, so I can’t run on my owner’s computer right now.' },
|
|
2862
2884
|
);
|
|
2863
2885
|
} catch (err) {
|
|
2864
2886
|
if (err?.status !== 409 || err?.body?.code !== 'already_responded') throw err;
|
|
@@ -2867,7 +2889,7 @@ export const performRun = ({
|
|
|
2867
2889
|
return {
|
|
2868
2890
|
outcome: 'no_action',
|
|
2869
2891
|
refused: { reason: 'delivery-refused' },
|
|
2870
|
-
reason: 'host-cannot-confine-turn',
|
|
2892
|
+
reason: placement.unconfinedRefused ? 'unconfined-pod-not-private' : 'host-cannot-confine-turn',
|
|
2871
2893
|
};
|
|
2872
2894
|
}
|
|
2873
2895
|
}
|
|
@@ -3137,7 +3159,9 @@ export const performRun = ({
|
|
|
3137
3159
|
commitAttributionEnv: commitAttribution?.sandboxEnv || null,
|
|
3138
3160
|
memoryLongTerm,
|
|
3139
3161
|
memoryWithheld,
|
|
3140
|
-
|
|
3162
|
+
// A public seat's Commonly server writes nothing once Commonly is
|
|
3163
|
+
// unreachable in its process (lib/public-seat-mcp-flag.js).
|
|
3164
|
+
environment: publicSeat ? withPublicSeatMcpFlag(placement.environment) : placement.environment,
|
|
3141
3165
|
// Only when set, so every other spawn context stays as it was.
|
|
3142
3166
|
...(hostUnconfined === true ? { hostUnconfined: true } : {}),
|
|
3143
3167
|
...(publicSeat && !memoryWithheld && opened.ownerWoken === true ? { ownerWoken: true } : {}),
|
|
@@ -189,7 +189,9 @@ export const extensionArgs = (servers, ctx) => {
|
|
|
189
189
|
}
|
|
190
190
|
const env = Object.entries(delivery.env).map(([name, value]) => {
|
|
191
191
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error('goose adapter: invalid MCP environment key');
|
|
192
|
-
|
|
192
|
+
// COMMONLY_MCP_PUBLIC_SEAT is the constant '1' (public-seat-mcp-flag.js),
|
|
193
|
+
// never a secret, so it may ride either path.
|
|
194
|
+
if (!['COMMONLY_TOKEN_FILE', 'COMMONLY_API_URL', 'COMMONLY_INSTANCE_URL', 'COMMONLY_MCP_PUBLIC_SEAT'].includes(name)) {
|
|
193
195
|
throw new Error(`goose adapter: MCP server ${server.name} has ${name}, which cannot safely ride a CLI flag`);
|
|
194
196
|
}
|
|
195
197
|
const resolved = substitute(value, ctx);
|
|
@@ -166,27 +166,32 @@ export const withDefaultMcpServer = (environment, adapterName) => {
|
|
|
166
166
|
* are the same thing to the adapter, and this is the path that decides what an
|
|
167
167
|
* undeclared sandbox means.
|
|
168
168
|
*/
|
|
169
|
+
/**
|
|
170
|
+
* Whether an environment declares a sandbox the adapters ENFORCE: a public or
|
|
171
|
+
* workspace trust (whose mode they resolve, and refuse to spawn without, every
|
|
172
|
+
* adapter but claude refusing `workspace` outright, TASK-294) or an explicit
|
|
173
|
+
* non-'none' mode. `mode: 'none'`, an empty block and a missing one are all the
|
|
174
|
+
* same thing to a spawn: no confinement.
|
|
175
|
+
*
|
|
176
|
+
* Normalized first (Wren 71719): a legacy `internal` means `public` here as it
|
|
177
|
+
* does to the attach gate and the adapters.
|
|
178
|
+
*/
|
|
179
|
+
export const declaresEnforcedSandbox = (environment) => {
|
|
180
|
+
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
181
|
+
return sandbox !== null && typeof sandbox === 'object'
|
|
182
|
+
&& sandbox.mode !== 'none'
|
|
183
|
+
&& (sandbox.trust === 'public' || sandbox.trust === 'workspace'
|
|
184
|
+
|| typeof sandbox.mode === 'string');
|
|
185
|
+
};
|
|
186
|
+
|
|
169
187
|
export const withDefaultSandbox = (environment) => {
|
|
170
188
|
if (environment !== null && environment !== undefined
|
|
171
189
|
&& (typeof environment !== 'object' || Array.isArray(environment))) {
|
|
172
190
|
return environment;
|
|
173
191
|
}
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
// gate accepts — benign (same effective trust) but not a mirror, and the
|
|
178
|
-
// comment would be false. The ORIGINAL block is what gets returned below.
|
|
179
|
-
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
180
|
-
// An ENFORCED declaration is one the adapters act on: a public or workspace
|
|
181
|
-
// trust (whose mode they resolve, and refuse to spawn without — every adapter
|
|
182
|
-
// but claude refuses `workspace` outright, TASK-294) or an explicit non-'none'
|
|
183
|
-
// mode. `mode: 'none'`, an empty block and a missing one are all the same
|
|
184
|
-
// thing to a spawn — no confinement — so all three are replaced here.
|
|
185
|
-
const enforced = sandbox !== null && typeof sandbox === 'object'
|
|
186
|
-
&& sandbox.mode !== 'none'
|
|
187
|
-
&& (sandbox.trust === 'public' || sandbox.trust === 'workspace'
|
|
188
|
-
|| typeof sandbox.mode === 'string');
|
|
189
|
-
if (enforced) return environment;
|
|
192
|
+
// `mode: 'none'`, an empty block and a missing one are replaced; the ORIGINAL
|
|
193
|
+
// block is what is returned when it is enforced.
|
|
194
|
+
if (declaresEnforcedSandbox(environment)) return environment;
|
|
190
195
|
return { ...(environment || {}), sandbox: defaultSeatSandbox() };
|
|
191
196
|
};
|
|
192
197
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tell a public seat's Commonly MCP server that it serves a public seat.
|
|
3
|
+
*
|
|
4
|
+
* The server then writes nothing once Commonly has been unreachable in that
|
|
5
|
+
* process (commonly-mcp/src/public-seat-gate.js), which closes the post a model
|
|
6
|
+
* makes through the tool before the CLI's own witness withholds the reply
|
|
7
|
+
* (public-tool-error.js, TASK-256). Only the shipped Commonly server is
|
|
8
|
+
* flagged. Every adapter carries a declared literal env key through to the
|
|
9
|
+
* server's process (`deliverSeatCredential` copies the declaration's env), so
|
|
10
|
+
* one copy here reaches all of them. A server that predates the gate ignores
|
|
11
|
+
* the key.
|
|
12
|
+
*
|
|
13
|
+
* Set at spawn, on a copy: the record and the guards (`auditDeclaredMcp`,
|
|
14
|
+
* `isShippedCommonlyMcpEntry`) still see the declaration as written.
|
|
15
|
+
*/
|
|
16
|
+
import { isShippedCommonlyMcpCommand } from './declared-mcp-guard.js';
|
|
17
|
+
import { describeMcpCommand } from './mcp-server-version.js';
|
|
18
|
+
|
|
19
|
+
export const PUBLIC_SEAT_MCP_ENV = 'COMMONLY_MCP_PUBLIC_SEAT';
|
|
20
|
+
|
|
21
|
+
// The npx form, or a recorded local checkout of the same package (the form
|
|
22
|
+
// goose's public check and `auditDeclaredMcp` also admit).
|
|
23
|
+
const isCommonlyServer = (server, describe) => isShippedCommonlyMcpCommand(server?.command)
|
|
24
|
+
|| Boolean(describe(server?.command)?.isCommonly);
|
|
25
|
+
|
|
26
|
+
export const withPublicSeatMcpFlag = (environment, { describe = describeMcpCommand } = {}) => {
|
|
27
|
+
const servers = Array.isArray(environment?.mcp) ? environment.mcp : null;
|
|
28
|
+
const flagged = servers ? servers.map((server) => isCommonlyServer(server, describe)) : [];
|
|
29
|
+
if (!flagged.some(Boolean)) return environment;
|
|
30
|
+
return {
|
|
31
|
+
...environment,
|
|
32
|
+
mcp: servers.map((server, i) => (flagged[i]
|
|
33
|
+
? { ...server, env: { ...(server.env || {}), [PUBLIC_SEAT_MCP_ENV]: '1' } }
|
|
34
|
+
: server)),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A seat with no sandbox answers only in pods confirmed private.
|
|
3
|
+
*
|
|
4
|
+
* An agent the adapters do not confine runs as its owner: their files, their
|
|
5
|
+
* git and GitHub login, their shell. Anyone who can post in its pod can direct
|
|
6
|
+
* it. Attach already refused a publicly readable pod, but not one anyone can
|
|
7
|
+
* join, and nothing looked again once it ran, so a pod made joinable later
|
|
8
|
+
* handed that access to whoever joined.
|
|
9
|
+
*
|
|
10
|
+
* So attach requires such a seat's pod to be confirmed private (publicRead and
|
|
11
|
+
* communityListed reported false, joinPolicy invite-only:
|
|
12
|
+
* workspace-trust.js `podIsConfirmedPrivate`), and before every turn the seat
|
|
13
|
+
* re-reads its pods (GET /installations) and refuses the turn unless all of
|
|
14
|
+
* them still are. There is no confined fallback: the seat's record was never
|
|
15
|
+
* written for one, so a pod that is not private is a refused turn, and a read
|
|
16
|
+
* that fails defers it. The Windows Codex opt-in keeps its own placement
|
|
17
|
+
* (`unconfinedTurnPlacement`); this covers every other unconfined seat.
|
|
18
|
+
*
|
|
19
|
+
* "Confined" is what the adapters enforce, not what the file declares: a public
|
|
20
|
+
* or workspace trust, or a shape one adapter enforces with no trust (claude's
|
|
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.
|
|
24
|
+
*
|
|
25
|
+
* A legacy pod with no joinPolicy is reported 'open', and that is not only a
|
|
26
|
+
* default: an agent may self-install into a pod an agent created unless it is
|
|
27
|
+
* invite-only, so a missing value is not confirmed private.
|
|
28
|
+
*
|
|
29
|
+
* The test-only `stub` adapter runs nothing and is not checked.
|
|
30
|
+
*/
|
|
31
|
+
import { normalizeSandboxTrust } from './environment.js';
|
|
32
|
+
import { podIsConfirmedPrivate } from './workspace-trust.js';
|
|
33
|
+
|
|
34
|
+
export const UNCONFINED_UNCHECKED_ADAPTERS = new Set(['stub']);
|
|
35
|
+
|
|
36
|
+
// adapters/dsh.js isConfinedDsh's accepted shape, copied so this module stays
|
|
37
|
+
// free of adapter imports; a test holds the two equal.
|
|
38
|
+
const isConfinedDshShape = (sandbox) => {
|
|
39
|
+
if (!sandbox || typeof sandbox !== 'object' || sandbox.trust !== undefined) return false;
|
|
40
|
+
const { mode, network, ...rest } = sandbox;
|
|
41
|
+
return mode === 'workspace' && network?.policy === 'restricted'
|
|
42
|
+
&& Object.keys(network).length === 1 && Object.keys(rest).length === 0;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Confinement an adapter applies with no trust: claude wraps any `bwrap` mode
|
|
46
|
+
// (adapters/claude.js), and dsh enforces its one shape. codex, opencode and the
|
|
47
|
+
// rest apply a mode only under a public or workspace trust.
|
|
48
|
+
const ADAPTER_OWN_CONFINEMENT = {
|
|
49
|
+
claude: (sandbox) => sandbox?.mode === 'bwrap',
|
|
50
|
+
dsh: isConfinedDshShape,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const seatRunsUnconfined = ({ environment, adapterName }) => {
|
|
54
|
+
if (UNCONFINED_UNCHECKED_ADAPTERS.has(adapterName)) return false;
|
|
55
|
+
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
56
|
+
// An explicit 'none' is no sandbox whatever the trust says.
|
|
57
|
+
if (sandbox?.mode === 'none') return true;
|
|
58
|
+
if (sandbox?.trust === 'public' || sandbox?.trust === 'workspace') return false;
|
|
59
|
+
return !ADAPTER_OWN_CONFINEMENT[adapterName]?.(sandbox);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const UNCONFINED_TURN_REFUSAL = 'This agent runs without a sandbox, with your own access to files, '
|
|
63
|
+
+ 'commands and logins, so it answers only while every pod it is in is private and invite-only. '
|
|
64
|
+
+ 'To fix it, the pod\'s owner opens it in Commonly and sets "Who can join" to Invite-only in its side '
|
|
65
|
+
+ 'panel (and makes it private if it is public or listed in Community), or you remove this agent from that pod.';
|
|
66
|
+
|
|
67
|
+
const MAX_PODS_NAMED = 3;
|
|
68
|
+
|
|
69
|
+
const describePod = (pod) => {
|
|
70
|
+
const label = pod?.podName ? `"${pod.podName}" (${pod.podId})` : `pod ${pod?.podId || '(no id)'}`;
|
|
71
|
+
if (typeof pod?.publicRead !== 'boolean' || typeof pod?.communityListed !== 'boolean') {
|
|
72
|
+
return `${label} did not report whether it is private`;
|
|
73
|
+
}
|
|
74
|
+
if (pod.publicRead || pod.communityListed) return `${label} is public or listed in Community`;
|
|
75
|
+
return `${label} is open to join`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** Null when every pod is confirmed private, otherwise why the turn is refused, naming the pods. */
|
|
79
|
+
export const unconfinedPodRefusalReason = (installations) => {
|
|
80
|
+
if (installations === null) return 'its pods could not be read';
|
|
81
|
+
if (!Array.isArray(installations) || installations.length === 0) return 'the server listed no pods for it';
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const notPrivate = installations.filter((pod) => {
|
|
84
|
+
if (podIsConfirmedPrivate(pod)) return false;
|
|
85
|
+
const key = String(pod?.podId || '');
|
|
86
|
+
if (seen.has(key)) return false;
|
|
87
|
+
seen.add(key);
|
|
88
|
+
return true;
|
|
89
|
+
});
|
|
90
|
+
if (!notPrivate.length) return null;
|
|
91
|
+
const named = notPrivate.slice(0, MAX_PODS_NAMED).map(describePod).join('; ');
|
|
92
|
+
const more = notPrivate.length - MAX_PODS_NAMED;
|
|
93
|
+
return more > 0 ? `${named}; and ${more} more` : named;
|
|
94
|
+
};
|