@1agh/maude 2.2.1 → 2.3.2

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.
Files changed (91) hide show
  1. package/apps/studio/acp/agents/auth.ts +241 -0
  2. package/apps/studio/acp/agents/catalog.ts +308 -0
  3. package/apps/studio/acp/agents/chat-key.ts +64 -0
  4. package/apps/studio/acp/agents/conformance.ts +1853 -0
  5. package/apps/studio/acp/agents/consent.ts +92 -0
  6. package/apps/studio/acp/agents/descriptor.ts +188 -0
  7. package/apps/studio/acp/agents/discover.ts +491 -0
  8. package/apps/studio/acp/agents/e2e-model.ts +58 -0
  9. package/apps/studio/acp/agents/health.ts +46 -0
  10. package/apps/studio/acp/agents/link-scan.ts +230 -0
  11. package/apps/studio/acp/agents/spawn.ts +164 -0
  12. package/apps/studio/acp/agents/state.ts +132 -0
  13. package/apps/studio/acp/ask-queue.ts +13 -4
  14. package/apps/studio/acp/bootstrap-brief.ts +16 -3
  15. package/apps/studio/acp/bridge.ts +709 -99
  16. package/apps/studio/acp/env.ts +43 -1
  17. package/apps/studio/acp/index.ts +428 -43
  18. package/apps/studio/acp/may-scope.ts +244 -21
  19. package/apps/studio/acp/policy/agent-home.ts +202 -0
  20. package/apps/studio/acp/policy/bridge-gate.ts +68 -0
  21. package/apps/studio/acp/policy/codex-home.ts +228 -0
  22. package/apps/studio/acp/policy/enforce.ts +620 -0
  23. package/apps/studio/acp/policy/gate-types.ts +41 -0
  24. package/apps/studio/acp/policy/launch-codex.ts +351 -0
  25. package/apps/studio/acp/policy/launch-copilot.ts +119 -0
  26. package/apps/studio/acp/policy/launch-gemini.ts +120 -0
  27. package/apps/studio/acp/policy/launch-opencode.ts +131 -0
  28. package/apps/studio/acp/policy/opencode-user-config.ts +240 -0
  29. package/apps/studio/acp/probe.ts +78 -14
  30. package/apps/studio/acp/transcript.ts +14 -0
  31. package/apps/studio/acp/write-scope.ts +62 -2
  32. package/apps/studio/annotations-layer.tsx +8 -0
  33. package/apps/studio/bin/_capture-init.js +5 -0
  34. package/apps/studio/bin/screenshot.sh +7 -1
  35. package/apps/studio/bridge/dgn-protocol.ts +3 -2
  36. package/apps/studio/canvas-shell.tsx +54 -0
  37. package/apps/studio/client/panels/ChatPanel.jsx +19 -4
  38. package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
  39. package/apps/studio/client/panels/SyncConsentDialog.jsx +4 -1
  40. package/apps/studio/client/panels/acp-runtime.js +95 -7
  41. package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
  42. package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
  43. package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
  44. package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
  45. package/apps/studio/client/v2/ai/Composer.jsx +4 -0
  46. package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
  47. package/apps/studio/client/v2/ai/Feed.jsx +8 -0
  48. package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
  49. package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
  50. package/apps/studio/client/v2/ai/advanced-model.js +17 -6
  51. package/apps/studio/client/v2/ai/agents-model.js +333 -0
  52. package/apps/studio/client/v2/ai/agents-store.js +223 -0
  53. package/apps/studio/client/v2/ai/ai.css +63 -0
  54. package/apps/studio/client/v2/ai/needs-you.js +1 -1
  55. package/apps/studio/client/v2/empty/empty-host.jsx +11 -2
  56. package/apps/studio/client/v2/empty/use-empty-canvas.js +22 -7
  57. package/apps/studio/client/v2/fold/fold-store.js +1 -0
  58. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +1 -0
  59. package/apps/studio/client/v2/settings/agent-keys.js +88 -0
  60. package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
  61. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  62. package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
  63. package/apps/studio/client/v2/settings/settings-cards.js +2 -1
  64. package/apps/studio/client/v2/settings/settings-model.js +1 -0
  65. package/apps/studio/client/v2/settings/settings.css +7 -0
  66. package/apps/studio/client/v2/shell/served-routes.js +1 -0
  67. package/apps/studio/client/v2/undo/zoom-undo.jsx +19 -2
  68. package/apps/studio/cloud-build.ts +5 -0
  69. package/apps/studio/comments/reveal.ts +13 -0
  70. package/apps/studio/comments-overlay.tsx +36 -0
  71. package/apps/studio/dist/client.bundle.js +535 -535
  72. package/apps/studio/dist/comment-mount.js +2 -2
  73. package/apps/studio/dist/styles.css +1 -1
  74. package/apps/studio/editing/annotation-count.ts +25 -0
  75. package/apps/studio/editing/empty-report.ts +8 -3
  76. package/apps/studio/editing/empty-reporter.tsx +10 -1
  77. package/apps/studio/generation/keys.ts +197 -11
  78. package/apps/studio/outbox/policy.ts +8 -2
  79. package/apps/studio/outbox/types.ts +5 -0
  80. package/apps/studio/routes/agents.ts +479 -0
  81. package/apps/studio/routes/index.ts +3 -0
  82. package/apps/studio/scripts/acp-conformance-local.ts +95 -0
  83. package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
  84. package/apps/studio/server.ts +9 -0
  85. package/apps/studio/sync/index.ts +9 -1
  86. package/apps/studio/sync/writer-registry.ts +12 -0
  87. package/apps/studio/whats-new.json +19 -0
  88. package/apps/studio/ws.ts +3 -0
  89. package/cli/commands/codex.mjs +36 -2
  90. package/cli/lib/harness/codex-runtime.mjs +98 -11
  91. package/package.json +9 -8
@@ -0,0 +1,241 @@
1
+ // Per-agent sign-in (universal ACP, plan B5 auth half), generalising acp/login-state.ts (Claude's
2
+ // own flow, which stays exactly as it is) to any descriptor: the vendor's OWN CLI does the sign-in
3
+ // (`<realBin> <auth.loginArgs>` opens its browser flow), Maude only starts it, watches the vendor's
4
+ // own status command and can cancel. Maude never renders a login form, never sees a token, never
5
+ // touches the vendor's credential store.
6
+ //
7
+ // agentAuthStatus `<realBin> <auth.statusArgs>` under a 5 s kill, scrubbed env, nothing kept but
8
+ // an enum: 'signed-in' | 'signed-out' | 'not-needed' | 'unknown'
9
+ // startAgentSignin one sign-in child per agent; poll `agentSigninState`, `cancelAgentSignin`
10
+ //
11
+ // How a status command answers (observed, not guessed):
12
+ // codex 0.154 `codex login status` → "Logged in using ChatGPT" exit 0 · "Not logged in" exit 1
13
+ // (run against a scratch CODEX_HOME, 2026-11-12). Exit 1 is therefore "signed out";
14
+ // a timeout, a spawn failure or any OTHER exit code is `unknown`, never a claim.
15
+ // claude `auth status --json` always exits 0 and says `{"loggedIn":false}`: a JSON
16
+ // document with a boolean `loggedIn` outranks the exit code.
17
+
18
+ import { tmpdir } from 'node:os';
19
+
20
+ import { scrubAgentEnv } from '../env.ts';
21
+ import type { AgentDescriptor } from './descriptor.ts';
22
+
23
+ /**
24
+ * Security review 2026-11-12 (defender H3): every vendor-CLI child here runs in the temp folder,
25
+ * never the server's cwd (the served project). A CLI started in a project loads that project's own
26
+ * config and plugins (`opencode auth login` boots `.opencode/plugins/*`), which the spawn policy
27
+ * refuses for a chat. Same rule as discovery's version probe.
28
+ */
29
+ const vendorCwd = (): string => tmpdir();
30
+
31
+ /**
32
+ * The shared scrub drops every `CODEX_*` (defender M7), but the person's own sign-in lives in THEIR
33
+ * `CODEX_HOME`: the vendor's status and sign-in commands keep it (the chat's Codex finds it from the
34
+ * person's env too, codex-home.ts). Nothing else comes back.
35
+ */
36
+ const vendorEnvAllow = (d: AgentDescriptor): string[] =>
37
+ d.id === 'codex' ? [...d.envAllow, 'CODEX_HOME'] : [...d.envAllow];
38
+
39
+ export type AgentAuthState = 'signed-in' | 'signed-out' | 'not-needed' | 'unknown';
40
+
41
+ export const AUTH_STATUS_TIMEOUT_MS = 5000;
42
+ const MAX_STATUS_BYTES = 16 * 1024;
43
+
44
+ async function readCapped(stream: ReadableStream<Uint8Array> | null | undefined): Promise<string> {
45
+ if (!stream) return '';
46
+ const chunks: Uint8Array[] = [];
47
+ let total = 0;
48
+ const reader = stream.getReader();
49
+ try {
50
+ while (total < MAX_STATUS_BYTES) {
51
+ const { value, done } = await reader.read();
52
+ if (done) break;
53
+ chunks.push(value);
54
+ total += value.byteLength;
55
+ }
56
+ } catch {
57
+ /* a killed child closes its pipes abruptly */
58
+ } finally {
59
+ try {
60
+ await reader.cancel();
61
+ } catch {
62
+ /* already closed */
63
+ }
64
+ }
65
+ return Buffer.concat(chunks).toString('utf8');
66
+ }
67
+
68
+ /** `{"loggedIn": true|false}` somewhere in the output, else null. Strict booleans only. */
69
+ function jsonLoggedIn(text: string): boolean | null {
70
+ const start = text.indexOf('{');
71
+ const end = text.lastIndexOf('}');
72
+ if (start === -1 || end <= start) return null;
73
+ try {
74
+ const doc = JSON.parse(text.slice(start, end + 1)) as { loggedIn?: unknown };
75
+ return typeof doc.loggedIn === 'boolean' ? doc.loggedIn : null;
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+
81
+ export interface AuthStatusOptions {
82
+ timeoutMs?: number;
83
+ env?: Record<string, string | undefined>;
84
+ }
85
+
86
+ /** Where the person stands with this agent's own account. Never throws; never returns vendor text. */
87
+ export async function agentAuthStatus(
88
+ d: AgentDescriptor,
89
+ realBin: string,
90
+ opts: AuthStatusOptions = {}
91
+ ): Promise<AgentAuthState> {
92
+ if (d.auth.gate === 'none') return 'not-needed';
93
+ if (!d.auth.statusArgs) return 'unknown';
94
+ let proc: ReturnType<typeof Bun.spawn> | null = null;
95
+ let timer: ReturnType<typeof setTimeout> | null = null;
96
+ try {
97
+ proc = Bun.spawn([realBin, ...d.auth.statusArgs], {
98
+ cwd: vendorCwd(),
99
+ env: scrubAgentEnv(opts.env ?? process.env, vendorEnvAllow(d)),
100
+ windowsHide: true,
101
+ stdin: 'ignore',
102
+ stdout: 'pipe',
103
+ stderr: 'ignore',
104
+ });
105
+ const child = proc;
106
+ const limit = opts.timeoutMs ?? AUTH_STATUS_TIMEOUT_MS;
107
+ let timedOut = false;
108
+ // one deadline: it kills the child AND releases the read, so a wrapper whose descendants hold
109
+ // the pipe open cannot hold this promise open too
110
+ const deadline = new Promise<string>((res) => {
111
+ timer = setTimeout(() => {
112
+ timedOut = true;
113
+ try {
114
+ child.kill();
115
+ } catch {
116
+ /* already exited */
117
+ }
118
+ res('');
119
+ }, limit);
120
+ });
121
+ const stdout = await Promise.race([
122
+ readCapped(child.stdout as ReadableStream<Uint8Array>),
123
+ deadline,
124
+ ]);
125
+ let exitTimer: ReturnType<typeof setTimeout> | undefined;
126
+ const code = await Promise.race([
127
+ child.exited,
128
+ new Promise<number>((res) => {
129
+ exitTimer = setTimeout(() => res(-1), 500);
130
+ }),
131
+ ]);
132
+ clearTimeout(exitTimer);
133
+ if (timedOut) return 'unknown';
134
+ const flag = jsonLoggedIn(stdout);
135
+ if (flag !== null) return flag ? 'signed-in' : 'signed-out';
136
+ if (code === 0) return 'signed-in';
137
+ if (code === 1) return 'signed-out';
138
+ return 'unknown';
139
+ } catch {
140
+ return 'unknown';
141
+ } finally {
142
+ if (timer) clearTimeout(timer);
143
+ try {
144
+ proc?.kill();
145
+ } catch {
146
+ /* already exited */
147
+ }
148
+ }
149
+ }
150
+
151
+ // ---------------------------------------------------------------- sign-in children
152
+
153
+ interface Signin {
154
+ child: ReturnType<typeof Bun.spawn>;
155
+ startedAt: number;
156
+ exitCode: number | null;
157
+ done: boolean;
158
+ }
159
+
160
+ /** One per agent id. A finished entry is kept (for `lastExit`) until the next start. */
161
+ const signins = new Map<string, Signin>();
162
+
163
+ export interface SigninState {
164
+ inFlight: boolean;
165
+ startedAt: number | null;
166
+ /** Exit code of the last finished sign-in child (null while running / never run / cancelled). */
167
+ lastExit: number | null;
168
+ }
169
+
170
+ export function agentSigninState(id: string): SigninState {
171
+ const s = signins.get(id);
172
+ if (!s) return { inFlight: false, startedAt: null, lastExit: null };
173
+ return { inFlight: !s.done, startedAt: s.startedAt, lastExit: s.done ? s.exitCode : null };
174
+ }
175
+
176
+ export interface SigninOptions {
177
+ env?: Record<string, string | undefined>;
178
+ }
179
+
180
+ export type StartSignin =
181
+ | { ok: true }
182
+ | { ok: false; reason: 'no-signin' | 'in-progress' | 'spawn-failed' };
183
+
184
+ /** Start the vendor's own sign-in (browser flow). One at a time per agent; fire-and-forget. */
185
+ export function startAgentSignin(
186
+ d: AgentDescriptor,
187
+ realBin: string,
188
+ opts: SigninOptions = {}
189
+ ): StartSignin {
190
+ if (!d.auth.loginArgs) return { ok: false, reason: 'no-signin' };
191
+ const running = signins.get(d.id);
192
+ if (running && !running.done) return { ok: false, reason: 'in-progress' };
193
+ try {
194
+ const child = Bun.spawn([realBin, ...d.auth.loginArgs], {
195
+ cwd: vendorCwd(),
196
+ env: scrubAgentEnv(opts.env ?? process.env, vendorEnvAllow(d)),
197
+ windowsHide: true,
198
+ stdin: 'ignore',
199
+ // the vendor's progress text is not Maude's to read or keep
200
+ stdout: 'ignore',
201
+ stderr: 'ignore',
202
+ });
203
+ const entry: Signin = { child, startedAt: Date.now(), exitCode: null, done: false };
204
+ signins.set(d.id, entry);
205
+ child.exited.then(
206
+ (code) => {
207
+ entry.done = true;
208
+ entry.exitCode = code;
209
+ },
210
+ () => {
211
+ entry.done = true;
212
+ }
213
+ );
214
+ return { ok: true };
215
+ } catch {
216
+ return { ok: false, reason: 'spawn-failed' };
217
+ }
218
+ }
219
+
220
+ /** Kill the in-flight sign-in child of one agent, if any (cancel button + app quit). */
221
+ export function cancelAgentSignin(id: string): void {
222
+ const s = signins.get(id);
223
+ if (!s || s.done) return;
224
+ s.done = true;
225
+ s.exitCode = null;
226
+ try {
227
+ s.child.kill();
228
+ } catch {
229
+ /* already exited */
230
+ }
231
+ }
232
+
233
+ export function cancelAllAgentSignins(): void {
234
+ for (const id of [...signins.keys()]) cancelAgentSignin(id);
235
+ }
236
+
237
+ /** For tests. */
238
+ export function resetAgentSignins(): void {
239
+ cancelAllAgentSignins();
240
+ signins.clear();
241
+ }
@@ -0,0 +1,308 @@
1
+ // The curated, pinned agent catalog. Shaped after the public ACP registry
2
+ // (cdn.agentclientprotocol.com/registry/v1/latest/registry.json, snapshot read 2026-11-12) but
3
+ // never fetched or run from it: an agent appears only when its own CLI is already on this Mac.
4
+ //
5
+ // Policy status (DDR-252):
6
+ // claude claude-meta today's path, unchanged
7
+ // codex bridge-enforced probe passed in full on 0.154 / 0.165 / 0.166 (F6b)
8
+ // opencode bridge-enforced probe passed in full on 1.18.30 (F6b)
9
+ // gemini bridge-enforced probe passed in full on 0.66.0 (B8)
10
+ // copilot bridge-enforced probe passed in full on 1.0.105 (B8)
11
+ // goose, cursor: 'unrestricted' until their own probe passes
12
+
13
+ import { getChatKey } from '../../generation/keys.ts';
14
+ import { ensureMaudeCodexHome, refuseProjectCodexConfig } from '../policy/codex-home.ts';
15
+ import { codexLaunchPolicy, currentHost } from '../policy/launch-codex.ts';
16
+ import { copilotLaunchPolicyFor } from '../policy/launch-copilot.ts';
17
+ import { geminiLaunchPolicyFor } from '../policy/launch-gemini.ts';
18
+ import {
19
+ OPENCODE_EXTERNAL_DIRECTORY_MAP,
20
+ opencodeLaunchPolicy,
21
+ } from '../policy/launch-opencode.ts';
22
+ import { readPersonOpencodeConfig } from '../policy/opencode-user-config.ts';
23
+ import {
24
+ type AgentDescriptor,
25
+ type AgentId,
26
+ assertDescriptor,
27
+ type Enforcement,
28
+ } from './descriptor.ts';
29
+
30
+ const SEMVER = /(\d+\.\d+\.\d+)/;
31
+
32
+ /**
33
+ * S1 (M2) — whether this spawn injects a Codex chat key (chat-key.ts reads the same store): then
34
+ * Maude's Codex home gets no auth.json link. An unreadable store is "no key", as at the spawn.
35
+ */
36
+ function codexChatKeyStored(): boolean {
37
+ try {
38
+ return getChatKey('codex') !== null;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+
44
+ /** rawInput keys a request may carry a path in (B0 frames: opencode filePath/filepath/path). */
45
+ const TARGET_KEYS = ['filePath', 'filepath', 'file_path', 'path', 'abs_path', 'paths'];
46
+
47
+ export const CLAUDE: AgentDescriptor = assertDescriptor({
48
+ id: 'claude',
49
+ label: 'Claude',
50
+ vendor: 'Anthropic',
51
+ statusUrl: 'https://status.anthropic.com',
52
+ detect: {
53
+ bins: ['claude'],
54
+ versionArgs: ['--version'],
55
+ versionRe: SEMVER,
56
+ minVersion: '0.0.0',
57
+ testedMax: '999.0.0',
58
+ },
59
+ launch: {
60
+ kind: 'adapter-js',
61
+ adapterPkg: '@agentclientprotocol/claude-agent-acp',
62
+ adapterBin: 'claude-agent-acp',
63
+ agentBinEnv: 'CLAUDE_CODE_EXECUTABLE',
64
+ },
65
+ auth: {
66
+ gate: 'session-new',
67
+ statusArgs: ['auth', 'status', '--json'],
68
+ loginArgs: ['auth', 'login', '--claudeai'],
69
+ },
70
+ envAllow: [],
71
+ policy: 'claude-meta',
72
+ plugins: 'claude-meta',
73
+ });
74
+
75
+ export const CODEX: AgentDescriptor = assertDescriptor({
76
+ id: 'codex',
77
+ label: 'Codex',
78
+ vendor: 'OpenAI',
79
+ statusUrl: 'https://status.openai.com',
80
+ detect: {
81
+ bins: ['codex'],
82
+ versionArgs: ['--version'],
83
+ versionRe: /codex-cli (\d+\.\d+\.\d+)/,
84
+ // The bundled codex-acp 2.5.0 depends on @openai/codex ^0.165. The conformance probe passed every
85
+ // check on 0.154 (the person's, through codex-acp's app-server), 0.165 and 0.166 once runtime
86
+ // state was `none` in the permission profile (2026-11-12, contract note "F6b").
87
+ minVersion: '0.154.0',
88
+ testedMax: '0.166.99',
89
+ },
90
+ launch: {
91
+ kind: 'adapter-js',
92
+ adapterPkg: '@agentclientprotocol/codex-acp',
93
+ adapterBin: 'codex-acp',
94
+ agentBinEnv: 'CODEX_PATH',
95
+ },
96
+ auth: {
97
+ gate: 'session-new',
98
+ statusArgs: ['login', 'status'],
99
+ loginArgs: ['login'],
100
+ apiKeyEnv: ['OPENAI_API_KEY'],
101
+ },
102
+ envAllow: [],
103
+ // Bridge-enforced (DDR-252): every conformance check passes on 0.154 / 0.165 / 0.166. F6b fixed the
104
+ // person's MCP servers / hooks (a Maude-owned CODEX_HOME) and refuses a project `.codex/`; runtime
105
+ // state the agent does not own is `none` in the permission profile (a `read` inside the `write`
106
+ // scope does not stop writes under codex-acp's workspace-write mode; `none` does). Connect still
107
+ // runs the probe on this Mac's binary before the first chat.
108
+ policy: 'bridge-enforced',
109
+ enforcement: {
110
+ // F6b — a Maude-owned CODEX_HOME (made or repaired here, at every spawn; a failure stops the
111
+ // spawn): the person's config.toml / hooks.json never load, only their sign-in is shared. A
112
+ // project `.codex/` (which codex-acp makes a trusted layer) stops the spawn.
113
+ launchPolicy: (ctx) => {
114
+ refuseProjectCodexConfig(ctx.scopeRoot);
115
+ return codexLaunchPolicy(
116
+ ctx,
117
+ currentHost(),
118
+ ensureMaudeCodexHome(ctx.hostEnv ?? process.env, {
119
+ // A caller with its own host env (the probe, a test) is not the server whose key store
120
+ // this is: no key unless it says so.
121
+ apiKey: ctx.chatKeyStored ?? (ctx.hostEnv ? false : codexChatKeyStored()),
122
+ })
123
+ );
124
+ },
125
+ readGate: 'os-sandbox',
126
+ shellGate: 'os-sandbox',
127
+ // S1 (A6) — an allowlist: codex-acp 2.5.0's four modes are read-only, workspace-write, agent
128
+ // (Guardian auto-review) and agent-full-access; only the first two keep the person's card.
129
+ pinMode: { modeId: 'workspace-write', allow: ['read-only', 'workspace-write'] },
130
+ rejectEndsTurn: true,
131
+ targetKeys: TARGET_KEYS,
132
+ },
133
+ plugins: 'harness:codex',
134
+ });
135
+
136
+ export const OPENCODE: AgentDescriptor = assertDescriptor({
137
+ id: 'opencode',
138
+ label: 'opencode',
139
+ vendor: 'opencode',
140
+ detect: {
141
+ bins: ['opencode'],
142
+ versionArgs: ['--version'],
143
+ versionRe: SEMVER,
144
+ minVersion: '1.18.30',
145
+ testedMax: '1.18.99',
146
+ },
147
+ launch: { kind: 'native-acp', args: ['acp'] },
148
+ auth: { gate: 'none', loginArgs: ['auth', 'login'] },
149
+ envAllow: [],
150
+ // F6b (2026-11-12): the conformance probe passed every check on 1.18.30, project outside git and
151
+ // its own git repo, with the person's MCP servers named off and plugins / tools / a project
152
+ // `.opencode` refused at spawn (contract note, "F6b"). Re-run the probe before raising testedMax.
153
+ policy: 'bridge-enforced',
154
+ enforcement: {
155
+ // F6b — each of the person's MCP servers named off (read at every spawn); a config that cannot
156
+ // be read, a plugin or tool, or a `.opencode` folder in or above the project stops the spawn
157
+ // (opencode imports that code whatever its flags say).
158
+ launchPolicy: (ctx) =>
159
+ opencodeLaunchPolicy(
160
+ ctx,
161
+ OPENCODE_EXTERNAL_DIRECTORY_MAP,
162
+ readPersonOpencodeConfig(ctx.hostEnv ?? process.env, ctx.scopeRoot)
163
+ ),
164
+ readGate: 'agent-permission-engine',
165
+ shellGate: 'command-text',
166
+ rejectEndsTurn: false,
167
+ targetKeys: TARGET_KEYS,
168
+ },
169
+ plugins: 'harness:opencode',
170
+ connectNote:
171
+ 'Without a provider of your own, opencode sends prompts to its free hosted model. Pick a provider in opencode first if that is not what you want.',
172
+ });
173
+
174
+ function unprobed(
175
+ id: AgentId,
176
+ label: string,
177
+ vendor: string,
178
+ bin: string,
179
+ args: string[]
180
+ ): AgentDescriptor {
181
+ return assertDescriptor({
182
+ id,
183
+ label,
184
+ vendor,
185
+ detect: {
186
+ bins: [bin],
187
+ versionArgs: ['--version'],
188
+ versionRe: SEMVER,
189
+ minVersion: '0.0.0',
190
+ testedMax: '0.0.0',
191
+ },
192
+ launch: { kind: 'native-acp', args },
193
+ auth: { gate: 'session-new' },
194
+ envAllow: [],
195
+ policy: 'unrestricted',
196
+ plugins: 'none',
197
+ });
198
+ }
199
+
200
+ /**
201
+ * B8 — Gemini CLI under Maude's limits: a Maude-owned GEMINI_CLI_HOME + system settings (no MCP,
202
+ * extensions, skills, hooks or web tools), approval mode pinned to `default`, the project never
203
+ * trusted (acp/policy/launch-gemini.ts). Shell is judged by command text.
204
+ */
205
+ export const GEMINI_ENFORCEMENT: Enforcement = {
206
+ launchPolicy: geminiLaunchPolicyFor,
207
+ readGate: 'agent-permission-engine',
208
+ shellGate: 'command-text',
209
+ // S1 (A6) — an allowlist: `yolo` and `autoEdit` (and any mode a newer Gemini adds) are refused;
210
+ // `plan` is Gemini's read-only planning mode.
211
+ pinMode: { modeId: 'default', allow: ['default', 'plan'] },
212
+ rejectEndsTurn: false,
213
+ targetKeys: TARGET_KEYS,
214
+ };
215
+
216
+ /**
217
+ * B8 — Copilot CLI under Maude's limits: a Maude-owned COPILOT_HOME (no MCP, hooks, plugins or
218
+ * trusted folders), no web tool, every URL denied, project Copilot config refused
219
+ * (acp/policy/launch-copilot.ts). Shell is judged by command text.
220
+ */
221
+ export const COPILOT_ENFORCEMENT: Enforcement = {
222
+ launchPolicy: copilotLaunchPolicyFor,
223
+ readGate: 'agent-permission-engine',
224
+ shellGate: 'command-text',
225
+ // S1 (A6) — an allowlist: `#autopilot` (and any mode a newer Copilot adds) is refused.
226
+ pinMode: {
227
+ modeId: 'https://agentclientprotocol.com/protocol/session-modes#agent',
228
+ allow: [
229
+ 'https://agentclientprotocol.com/protocol/session-modes#agent',
230
+ 'https://agentclientprotocol.com/protocol/session-modes#plan',
231
+ ],
232
+ },
233
+ // S1 — `allow_all` (session/set_config_option) approves every tool call without a card, which the
234
+ // mode pin does not cover: only `off` may be set or listed.
235
+ pinConfig: { allow_all: { allow: ['off', 'false'] } },
236
+ rejectEndsTurn: false,
237
+ targetKeys: TARGET_KEYS,
238
+ };
239
+
240
+ // B8 (2026-11-12): the conformance probe passed every check on 0.66.0, project outside git and its
241
+ // own git repo, with a planted project `.gemini/` inert (contract note, "B8"). Shell: Gemini sends
242
+ // no rawInput, so the gate refuses every shell command (fail closed) until enforce.ts reads its
243
+ // title. Re-run the probe before raising testedMax.
244
+ export const GEMINI: AgentDescriptor = assertDescriptor({
245
+ id: 'gemini',
246
+ label: 'Gemini CLI',
247
+ vendor: 'Google',
248
+ statusUrl: 'https://status.cloud.google.com',
249
+ detect: {
250
+ bins: ['gemini'],
251
+ versionArgs: ['--version'],
252
+ versionRe: SEMVER,
253
+ minVersion: '0.66.0',
254
+ testedMax: '0.66.99',
255
+ },
256
+ launch: { kind: 'native-acp', args: ['--acp'] },
257
+ // Sign-in is Google's own (ACP authenticate / the CLI); an API key comes from the chat key store.
258
+ auth: { gate: 'session-new', apiKeyEnv: ['GEMINI_API_KEY'] },
259
+ envAllow: [],
260
+ policy: 'bridge-enforced',
261
+ enforcement: GEMINI_ENFORCEMENT,
262
+ plugins: 'none',
263
+ });
264
+
265
+ // B8 (2026-11-12): the conformance probe passed every check on 1.0.105, project outside git and its
266
+ // own git repo (contract note, "B8"). Copilot releases often and changes behaviour between patch
267
+ // releases, so testedMax is the measured release itself.
268
+ export const COPILOT: AgentDescriptor = assertDescriptor({
269
+ id: 'copilot',
270
+ label: 'GitHub Copilot CLI',
271
+ vendor: 'GitHub',
272
+ statusUrl: 'https://www.githubstatus.com',
273
+ detect: {
274
+ bins: ['copilot'],
275
+ versionArgs: ['--version'],
276
+ versionRe: SEMVER,
277
+ minVersion: '1.0.105',
278
+ testedMax: '1.0.105',
279
+ },
280
+ launch: { kind: 'native-acp', args: ['--acp'] },
281
+ auth: { gate: 'session-new', loginArgs: ['login'] },
282
+ envAllow: [],
283
+ policy: 'bridge-enforced',
284
+ enforcement: COPILOT_ENFORCEMENT,
285
+ plugins: 'none',
286
+ });
287
+ export const GOOSE = unprobed('goose', 'Goose', 'Block', 'goose', ['acp']);
288
+ export const CURSOR = unprobed('cursor', 'Cursor agent', 'Cursor', 'cursor-agent', ['acp']);
289
+
290
+ /** Order = order in Settings and in the offer line. Claude first, always. */
291
+ export const CATALOG: readonly AgentDescriptor[] = Object.freeze([
292
+ CLAUDE,
293
+ CODEX,
294
+ OPENCODE,
295
+ GEMINI,
296
+ COPILOT,
297
+ GOOSE,
298
+ CURSOR,
299
+ ]);
300
+
301
+ export function agentById(id: string): AgentDescriptor | undefined {
302
+ return CATALOG.find((d) => d.id === id);
303
+ }
304
+
305
+ /** Whether Studio may proactively offer this agent (Design Decision 1): bridge-enforced only. */
306
+ export function isOfferable(d: AgentDescriptor): boolean {
307
+ return d.id !== 'claude' && d.policy === 'bridge-enforced';
308
+ }
@@ -0,0 +1,64 @@
1
+ // B7 (plan feature-universal-acp-and-codex, DDR-252 § BYOK) — which env a stored chat key becomes,
2
+ // for ONE agent. spawn.ts applies it AFTER the shared scrub, so a key reaches only the agent it was
3
+ // stored for: a Codex key never lands in Claude's or opencode's env, and the inherited env never
4
+ // supplies one (the scrub drops OPENAI_* / GEMINI_* / ANTHROPIC_* first).
5
+ //
6
+ // codex OPENAI_API_KEY (its descriptor's auth.apiKeyEnv[0]) + DEFAULT_AUTH_REQUEST {methodId:
7
+ // "api-key"}: codex-acp 2.5 reads the key only when the api-key auth method runs, and runs
8
+ // the default request only when Codex has no sign-in of its own (a ChatGPT sign-in wins).
9
+ // Codex's launch policy keeps the var out of every command it runs (shell_environment_policy,
10
+ // acp/policy/launch-codex.ts).
11
+ // gemini GEMINI_API_KEY (catalog auth.apiKeyEnv).
12
+ // opencode none: opencode takes a key per provider (OPENAI_API_KEY, ANTHROPIC_API_KEY, …) with no
13
+ // one name to inject, so its keys stay with opencode's own `opencode auth login`.
14
+ // claude ANTHROPIC_API_KEY, ONLY when this profile turned on the Advanced opt-in (DDR-252 amends
15
+ // DDR-123), plus CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 so Claude Code strips it from the
16
+ // commands, hooks and MCP servers it starts. Off (the default) → nothing, and the Claude
17
+ // spawn stays byte-identical (test/acp-agent-spawn.test.ts).
18
+
19
+ import { getChatKey } from '../../generation/keys.ts';
20
+ import { isAgentSecretKey } from '../env.ts';
21
+ import type { AgentDescriptor } from './descriptor.ts';
22
+
23
+ /** The env name Claude's opted-in key rides in (Anthropic auth precedence #3). */
24
+ export const CLAUDE_API_KEY_ENV = 'ANTHROPIC_API_KEY';
25
+
26
+ /** codex-acp's "log in with the api-key method when Codex needs a login" switch. */
27
+ const CODEX_DEFAULT_AUTH = JSON.stringify({ methodId: 'api-key' });
28
+
29
+ /** The env name a chat key for `d` is injected as, or null when the agent takes none. */
30
+ export function chatKeyEnvName(d: AgentDescriptor): string | null {
31
+ if (d.id === 'claude') return d.policy === 'claude-meta' ? CLAUDE_API_KEY_ENV : null;
32
+ const name = d.auth.apiKeyEnv?.[0];
33
+ // Only a vendor credential name (the ones the shared scrub drops) — never ANTHROPIC_*, never one
34
+ // of Maude's own secrets, never PATH: a descriptor cannot turn a key into anything else.
35
+ return name && isAgentSecretKey(name) ? name : null;
36
+ }
37
+
38
+ /**
39
+ * The env to add for `d`'s stored chat key (empty when none). `lookup` defaults to the 0600 store
40
+ * (generation/keys.ts); tests hand it a fake. Read at each spawn, never cached — a key removed in
41
+ * Settings is gone from the next session.
42
+ */
43
+ export function chatKeyEnvFor(
44
+ d: AgentDescriptor,
45
+ lookup: (agentId: string) => string | null = getChatKey
46
+ ): Record<string, string> {
47
+ const name = chatKeyEnvName(d);
48
+ if (!name) return {};
49
+ let key: string | null = null;
50
+ try {
51
+ key = lookup(d.id);
52
+ } catch {
53
+ key = null; // an unreadable store is "no key", never a crash of the spawn
54
+ }
55
+ if (!key) return {};
56
+ if (d.id === 'claude') return { [name]: key, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB: '1' };
57
+ if (d.id === 'codex') return { [name]: key, DEFAULT_AUTH_REQUEST: CODEX_DEFAULT_AUTH };
58
+ return { [name]: key };
59
+ }
60
+
61
+ /** Whether `d` can take a chat key at all (Settings shows the "Use an API key" row only then). */
62
+ export function acceptsChatKey(d: AgentDescriptor): boolean {
63
+ return chatKeyEnvName(d) !== null;
64
+ }