@commonlyai/cli 0.1.324 → 0.1.325
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 +41 -0
- package/src/lib/outsider-grant-mcp.js +82 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -96,6 +96,9 @@ import {
|
|
|
96
96
|
withDefaultSandbox,
|
|
97
97
|
} from '../lib/default-environment.js';
|
|
98
98
|
import { mergeGrantBrokers, withholdGrantBroker } from '../lib/grant-broker-guard.js';
|
|
99
|
+
import {
|
|
100
|
+
OUTSIDER_GRANT_MCP_UNCONFINED, outsiderGrantMcpRefusal, seatIsConfined, unshippedMcpEntries,
|
|
101
|
+
} from '../lib/outsider-grant-mcp.js';
|
|
99
102
|
import {
|
|
100
103
|
FOCUS_FRAME_MAX_CODE_POINTS,
|
|
101
104
|
formatPodFocusFrame,
|
|
@@ -2868,6 +2871,44 @@ export const performRun = ({
|
|
|
2868
2871
|
};
|
|
2869
2872
|
}
|
|
2870
2873
|
}
|
|
2874
|
+
// §12 C: a confined seat that a connector grant may reach runs with only the
|
|
2875
|
+
// shipped MCP servers (lib/outsider-grant-mcp.js). The server is asked only
|
|
2876
|
+
// when this turn's set holds something else, so an ordinary seat makes no
|
|
2877
|
+
// extra read. A failed read defers the turn, as the placement read does.
|
|
2878
|
+
if (seatIsConfined(placement.environment) && unshippedMcpEntries(placement.environment, instanceUrl).length) {
|
|
2879
|
+
let identity;
|
|
2880
|
+
try {
|
|
2881
|
+
identity = await client.get('/api/agents/runtime/installations', {}, {
|
|
2882
|
+
signal: AbortSignal.timeout(5000),
|
|
2883
|
+
});
|
|
2884
|
+
} catch (err) {
|
|
2885
|
+
throw Object.assign(
|
|
2886
|
+
new Error(`turn deferred, because whether a connector grant reaches this seat could not be read: ${err.message}`, {
|
|
2887
|
+
cause: err,
|
|
2888
|
+
}),
|
|
2889
|
+
{ status: err.status },
|
|
2890
|
+
);
|
|
2891
|
+
}
|
|
2892
|
+
const mcpRefusal = outsiderGrantMcpRefusal({ environment: placement.environment, identity, instanceUrl });
|
|
2893
|
+
if (mcpRefusal) {
|
|
2894
|
+
log(`turn refused: ${mcpRefusal.message}`);
|
|
2895
|
+
if (event.type === 'agent.ask' && event.payload?.requestId) {
|
|
2896
|
+
try {
|
|
2897
|
+
await client.post(
|
|
2898
|
+
`/api/agents/runtime/asks/${encodeURIComponent(event.payload.requestId)}/respond`,
|
|
2899
|
+
{ content: 'I can’t take this ask: I’m set up with tools that can’t run next to this pod’s connector.' },
|
|
2900
|
+
);
|
|
2901
|
+
} catch (err) {
|
|
2902
|
+
if (err?.status !== 409 || err?.body?.code !== 'already_responded') throw err;
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
return {
|
|
2906
|
+
outcome: 'no_action',
|
|
2907
|
+
refused: { reason: 'delivery-refused' },
|
|
2908
|
+
reason: OUTSIDER_GRANT_MCP_UNCONFINED,
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2871
2912
|
// TASK-440: a cold, large session starts fresh at wake instead of being
|
|
2872
2913
|
// resumed, and F392: so does one past the hard ceiling, however recently it
|
|
2873
2914
|
// ran. The restart note leads the prompt; memory still reaches the fresh
|
|
@@ -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
|
+
};
|