@commonlyai/cli 0.1.324 → 0.1.326
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,10 @@ 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 {
|
|
101
|
+
OUTSIDER_GRANT_MCP_UNCONFINED, outsiderGrantMcpRefusal, seatIsConfined, unshippedMcpEntries,
|
|
102
|
+
} from '../lib/outsider-grant-mcp.js';
|
|
99
103
|
import {
|
|
100
104
|
FOCUS_FRAME_MAX_CODE_POINTS,
|
|
101
105
|
formatPodFocusFrame,
|
|
@@ -2868,6 +2872,44 @@ export const performRun = ({
|
|
|
2868
2872
|
};
|
|
2869
2873
|
}
|
|
2870
2874
|
}
|
|
2875
|
+
// §12 C: a confined seat that a connector grant may reach runs with only the
|
|
2876
|
+
// shipped MCP servers (lib/outsider-grant-mcp.js). The server is asked only
|
|
2877
|
+
// when this turn's set holds something else, so an ordinary seat makes no
|
|
2878
|
+
// extra read. A failed read defers the turn, as the placement read does.
|
|
2879
|
+
if (seatIsConfined(placement.environment) && unshippedMcpEntries(placement.environment, instanceUrl).length) {
|
|
2880
|
+
let identity;
|
|
2881
|
+
try {
|
|
2882
|
+
identity = await client.get('/api/agents/runtime/installations', {}, {
|
|
2883
|
+
signal: AbortSignal.timeout(5000),
|
|
2884
|
+
});
|
|
2885
|
+
} catch (err) {
|
|
2886
|
+
throw Object.assign(
|
|
2887
|
+
new Error(`turn deferred, because whether a connector grant reaches this seat could not be read: ${err.message}`, {
|
|
2888
|
+
cause: err,
|
|
2889
|
+
}),
|
|
2890
|
+
{ status: err.status },
|
|
2891
|
+
);
|
|
2892
|
+
}
|
|
2893
|
+
const mcpRefusal = outsiderGrantMcpRefusal({ environment: placement.environment, identity, instanceUrl });
|
|
2894
|
+
if (mcpRefusal) {
|
|
2895
|
+
log(`turn refused: ${mcpRefusal.message}`);
|
|
2896
|
+
if (event.type === 'agent.ask' && event.payload?.requestId) {
|
|
2897
|
+
try {
|
|
2898
|
+
await client.post(
|
|
2899
|
+
`/api/agents/runtime/asks/${encodeURIComponent(event.payload.requestId)}/respond`,
|
|
2900
|
+
{ content: 'I can’t take this ask: I’m set up with tools that can’t run next to this pod’s connector.' },
|
|
2901
|
+
);
|
|
2902
|
+
} catch (err) {
|
|
2903
|
+
if (err?.status !== 409 || err?.body?.code !== 'already_responded') throw err;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
return {
|
|
2907
|
+
outcome: 'no_action',
|
|
2908
|
+
refused: { reason: 'delivery-refused' },
|
|
2909
|
+
reason: OUTSIDER_GRANT_MCP_UNCONFINED,
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2871
2913
|
// TASK-440: a cold, large session starts fresh at wake instead of being
|
|
2872
2914
|
// resumed, and F392: so does one past the hard ceiling, however recently it
|
|
2873
2915
|
// ran. The restart note leads the prompt; memory still reaches the fresh
|
|
@@ -3096,7 +3138,9 @@ export const performRun = ({
|
|
|
3096
3138
|
commitAttributionEnv: commitAttribution?.sandboxEnv || null,
|
|
3097
3139
|
memoryLongTerm,
|
|
3098
3140
|
memoryWithheld,
|
|
3099
|
-
|
|
3141
|
+
// A public seat's Commonly server writes nothing once Commonly is
|
|
3142
|
+
// unreachable in its process (lib/public-seat-mcp-flag.js).
|
|
3143
|
+
environment: publicSeat ? withPublicSeatMcpFlag(placement.environment) : placement.environment,
|
|
3100
3144
|
// Only when set, so every other spawn context stays as it was.
|
|
3101
3145
|
...(hostUnconfined === true ? { hostUnconfined: true } : {}),
|
|
3102
3146
|
...(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);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A confined seat that an outsider-writable grant reaches runs with only the
|
|
3
|
+
* shipped MCP servers (docs/plans/hosted-mcp-connection-scope.md §12 C).
|
|
4
|
+
*
|
|
5
|
+
* While a grant whose source outsiders can write reaches one of a seat's pods,
|
|
6
|
+
* the server narrows what the seat's token can do (§12 A). It cannot see the
|
|
7
|
+
* MCP servers the seat loads on this machine, though. The daemon admits a
|
|
8
|
+
* declared stdio entry that equals one in the local token record
|
|
9
|
+
* (`auditDeclaredMcp`), so a server its owner installed locally can sit beside
|
|
10
|
+
* the grant's results, and content an outsider wrote can steer it. So before
|
|
11
|
+
* each turn, a confined seat that may be narrowed is refused while its MCP set
|
|
12
|
+
* holds anything but the shipped Commonly server or a shipped grant broker.
|
|
13
|
+
*
|
|
14
|
+
* The effective set is the declared one. A confined seat's adapter excludes
|
|
15
|
+
* user- and project-scope MCP config (claude `--strict-mcp-config`, codex
|
|
16
|
+
* `--ignore-user-config`, isolated homes for the others), and
|
|
17
|
+
* `outsider-grant-mcp.test.mjs` pins those flags, so a scope added to an
|
|
18
|
+
* adapter fails that test before it widens this set.
|
|
19
|
+
*
|
|
20
|
+
* Only confined seats (`sandbox.trust` public or workspace, with the legacy
|
|
21
|
+
* `internal` read as public) are checked. An
|
|
22
|
+
* unconfined seat named on a grant runs on its owner's machine with a shell,
|
|
23
|
+
* under the owner's consent that what it reads can leave, so a local MCP
|
|
24
|
+
* server adds nothing it lacks (§12, the F94 amendment).
|
|
25
|
+
*/
|
|
26
|
+
import { isShippedCommonlyMcpEntry, isShippedGrantBrokerEntry } from './declared-mcp-guard.js';
|
|
27
|
+
import { effectiveSandboxTrust } from './environment.js';
|
|
28
|
+
|
|
29
|
+
export const OUTSIDER_GRANT_MCP_UNCONFINED = 'outsider_grant_mcp_unconfined';
|
|
30
|
+
|
|
31
|
+
const CONFINED_TRUSTS = new Set(['public', 'workspace']);
|
|
32
|
+
|
|
33
|
+
// Read through the legacy table, as the broker guard and the adapters read it:
|
|
34
|
+
// a record still carrying `internal` is confined as `public`, and is handed
|
|
35
|
+
// the broker as a public seat, so it is checked as one.
|
|
36
|
+
export const seatIsConfined = (environment) => CONFINED_TRUSTS.has(
|
|
37
|
+
effectiveSandboxTrust(environment?.sandbox?.trust),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// The server flags a broker on a grant that names this seat (`byoNamed`). It is
|
|
41
|
+
// a marker for the guard, not something the client reads, so it is set aside
|
|
42
|
+
// before the whole-entry match, and only as exactly `true`.
|
|
43
|
+
const withoutByoNamedFlag = (server) => {
|
|
44
|
+
if (!server || typeof server !== 'object' || server.byoNamed !== true) return server;
|
|
45
|
+
const { byoNamed: _byoNamed, ...rest } = server;
|
|
46
|
+
return rest;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The entries of a turn's MCP set that are neither shipped server. */
|
|
50
|
+
export const unshippedMcpEntries = (environment, instanceUrl) => {
|
|
51
|
+
const servers = Array.isArray(environment?.mcp) ? environment.mcp : [];
|
|
52
|
+
return servers.filter((server) => !isShippedCommonlyMcpEntry(server)
|
|
53
|
+
&& !isShippedGrantBrokerEntry(withoutByoNamedFlag(server), instanceUrl));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether the server's answer leaves the seat possibly narrowed. Only an
|
|
58
|
+
* explicit `outsiderGrantNarrowed: false` clears it. A server from before the
|
|
59
|
+
* field, or an answer that lacks it, counts as narrowed, because the CLI
|
|
60
|
+
* publishes before the server change is deployed.
|
|
61
|
+
*/
|
|
62
|
+
export const mayBeNarrowed = (identity) => identity?.outsiderGrantNarrowed !== false;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @returns {null | { code: string, names: string[], message: string }}
|
|
66
|
+
*/
|
|
67
|
+
export const outsiderGrantMcpRefusal = ({ environment, identity, instanceUrl }) => {
|
|
68
|
+
if (!seatIsConfined(environment)) return null;
|
|
69
|
+
const extra = unshippedMcpEntries(environment, instanceUrl);
|
|
70
|
+
if (!extra.length || !mayBeNarrowed(identity)) return null;
|
|
71
|
+
const names = extra.map((server) => String(server?.name || '(unnamed)'));
|
|
72
|
+
const why = identity && 'outsiderGrantNarrowed' in identity
|
|
73
|
+
? 'a connector grant whose source outsiders can write reaches one of its pods'
|
|
74
|
+
: 'the server did not say whether a connector grant reaches its pods, so it is treated as if one does';
|
|
75
|
+
return {
|
|
76
|
+
code: OUTSIDER_GRANT_MCP_UNCONFINED,
|
|
77
|
+
names,
|
|
78
|
+
message: `${OUTSIDER_GRANT_MCP_UNCONFINED}: this seat loads MCP servers beyond the shipped Commonly server `
|
|
79
|
+
+ `and grant broker (${names.join(', ')}), and ${why}. Remove them from the seat's environment, `
|
|
80
|
+
+ 'or use a separate agent for the connector pod.',
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -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
|
+
};
|