@1agh/maude 2.2.1 → 2.3.1

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 (74) 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/client/panels/ChatPanel.jsx +19 -4
  33. package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
  34. package/apps/studio/client/panels/acp-runtime.js +95 -7
  35. package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
  36. package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
  37. package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
  38. package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
  39. package/apps/studio/client/v2/ai/Composer.jsx +4 -0
  40. package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
  41. package/apps/studio/client/v2/ai/Feed.jsx +8 -0
  42. package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
  43. package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
  44. package/apps/studio/client/v2/ai/advanced-model.js +17 -6
  45. package/apps/studio/client/v2/ai/agents-model.js +333 -0
  46. package/apps/studio/client/v2/ai/agents-store.js +223 -0
  47. package/apps/studio/client/v2/ai/ai.css +63 -0
  48. package/apps/studio/client/v2/ai/needs-you.js +1 -1
  49. package/apps/studio/client/v2/fold/fold-store.js +1 -0
  50. package/apps/studio/client/v2/settings/agent-keys.js +88 -0
  51. package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
  52. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  53. package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
  54. package/apps/studio/client/v2/settings/settings-cards.js +2 -1
  55. package/apps/studio/client/v2/settings/settings-model.js +1 -0
  56. package/apps/studio/client/v2/settings/settings.css +7 -0
  57. package/apps/studio/client/v2/shell/served-routes.js +1 -0
  58. package/apps/studio/cloud-build.ts +5 -0
  59. package/apps/studio/dist/client.bundle.js +604 -604
  60. package/apps/studio/dist/styles.css +1 -1
  61. package/apps/studio/generation/keys.ts +197 -11
  62. package/apps/studio/outbox/policy.ts +8 -2
  63. package/apps/studio/outbox/types.ts +5 -0
  64. package/apps/studio/routes/agents.ts +479 -0
  65. package/apps/studio/routes/index.ts +3 -0
  66. package/apps/studio/scripts/acp-conformance-local.ts +95 -0
  67. package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
  68. package/apps/studio/server.ts +9 -0
  69. package/apps/studio/sync/writer-registry.ts +12 -0
  70. package/apps/studio/whats-new.json +10 -0
  71. package/apps/studio/ws.ts +3 -0
  72. package/cli/commands/codex.mjs +36 -2
  73. package/cli/lib/harness/codex-runtime.mjs +98 -11
  74. package/package.json +9 -8
@@ -181,6 +181,13 @@ export interface WriteScopeVerdict {
181
181
  * runs only executable hooks there, and `Write` creates 0644.
182
182
  * • `.ai/workflows.config.json` (root only — a PREFIX rule below) — flow
183
183
  * `eval`s its `quality` gates on the next /flow:validate or commit gate.
184
+ * • Other agents' project config (security review 2026-11-12, defender M1 /
185
+ * attacker C2) — `.codex`, `.agents`, `.opencode`, `opencode.json(c)`,
186
+ * `.gemini`, `AGENTS.md`, `GEMINI.md` (and the already-listed `.claude`,
187
+ * `CLAUDE.md`, `.mcp.json`). The person's terminal Codex / opencode / Gemini
188
+ * loads them from the project on its next run: MCP servers and plugins start
189
+ * unsandboxed, and the instruction files steer that agent. This narrows the
190
+ * Claude chat too: those writes now reach the person's card.
184
191
  *
185
192
  * THE PREDICATE, recorded so this list is extended by RE-DERIVATION rather than
186
193
  * by pattern-matching the entries above: **an in-project path that reaches
@@ -203,6 +210,15 @@ export const PROTECTED_IN_PROJECT: readonly string[] = [
203
210
  '.claude',
204
211
  'CLAUDE.md',
205
212
  '.mcp.json',
213
+ // security review 2026-11-12 M1/C2 — other agents' project config (see the bullet above).
214
+ '.codex',
215
+ '.agents',
216
+ '.opencode',
217
+ 'opencode.json',
218
+ 'opencode.jsonc',
219
+ '.gemini',
220
+ 'AGENTS.md',
221
+ 'GEMINI.md',
206
222
  '.envrc',
207
223
  '.vscode',
208
224
  'node_modules',
@@ -544,6 +560,50 @@ export function resolveWriteTargets(
544
560
  }
545
561
 
546
562
  const resolved = [...new Set([...resolvedLocations, ...resolvedRawInput])];
563
+ return judgeResolvedWrites(resolved, odd, [scopeRoot], readOnlyRoots, onlyPaths, designRoots);
564
+ }
565
+
566
+ /**
567
+ * Universal ACP (B3/F5, contract rule 5) — the write gate keyed on a normalised request's paths
568
+ * instead of a Claude tool call: each path spelled from `cwd` through agent-path.ts and realpath'd,
569
+ * then the same rules as `resolveWriteTargets` (read-only grants, every target inside one of
570
+ * `writeRoots`, protected paths, runtime state, a run's own scope). No path, or one with a NUL →
571
+ * `no-target`. `writeRoots` are compared as they resolve on disk.
572
+ */
573
+ export function writeVerdictForPaths(
574
+ paths: readonly string[],
575
+ cwd: string,
576
+ writeRoots: readonly string[],
577
+ readOnlyRoots: readonly string[] = [],
578
+ onlyPaths: readonly string[] | null = null,
579
+ designRoots: readonly string[] = []
580
+ ): WriteScopeVerdict {
581
+ const roots = writeRoots.filter((r) => isAbsolute(r)).map((r) => resolveRealPath(r, r));
582
+ const spelled = paths.map((p) => agentPath(p, cwd));
583
+ if (!spelled.length || !roots.length || spelled.some((a) => a === null))
584
+ return { inside: false, reason: 'no-target', resolved: [] };
585
+ const odd = spelled.some((a) => a?.odd);
586
+ const resolved = [
587
+ ...new Set(spelled.map((a) => resolveRealPath((a as { abs: string }).abs, cwd))),
588
+ ];
589
+ return judgeResolvedWrites(resolved, odd, roots, readOnlyRoots, onlyPaths, designRoots);
590
+ }
591
+
592
+ /**
593
+ * The rules after resolution, shared by both entry points. `roots[0]` (the pinned scope root) is
594
+ * what relative grants and run paths resolve against; a target must lie inside ONE of `roots`, and
595
+ * the protected-path test runs against that root.
596
+ */
597
+ function judgeResolvedWrites(
598
+ resolved: string[],
599
+ odd: boolean,
600
+ roots: readonly string[],
601
+ readOnlyRoots: readonly string[],
602
+ onlyPaths: readonly string[] | null,
603
+ designRoots: readonly string[]
604
+ ): WriteScopeVerdict {
605
+ const scopeRoot = roots[0] as string;
606
+ const rootOf = (p: string) => roots.find((r) => isInsideRoot(p, r));
547
607
  // S5.10 — a folder the person allowed AI to READ stays read-only, inside the project or not.
548
608
  // Judged on the resolved target (symlinks followed by resolveRealPath) against each grant's real
549
609
  // path, and the root itself counts: a grant never turns into a write path.
@@ -559,12 +619,12 @@ export function resolveWriteTargets(
559
619
  return { inside: false, reason: 'read-only-grant', resolved };
560
620
  }
561
621
  // EVERY target must pass — a multi-location write with one escape is an escape.
562
- const inside = !odd && resolved.every((p) => isInsideRoot(p, scopeRoot));
622
+ const inside = !odd && resolved.every((p) => rootOf(p) !== undefined);
563
623
  if (!inside) return { inside: false, reason: 'outside', resolved };
564
624
  // Inside is NECESSARY but not SUFFICIENT. A write under `.git/` or `.claude/`
565
625
  // is in-project and still reaches execution, so it goes to the prompt like any
566
626
  // out-of-project write would. See PROTECTED_IN_PROJECT.
567
- if (resolved.some((p) => isProtectedInProject(p, scopeRoot))) {
627
+ if (resolved.some((p) => isProtectedInProject(p, rootOf(p) as string))) {
568
628
  return { inside: false, reason: 'in-project-denied', resolved };
569
629
  }
570
630
  // V2-8.9 B1 — the app's runtime state under the design root is not the agent's to write.
@@ -192,6 +192,8 @@ function ChatThread({
192
192
  suggestOn,
193
193
  onSetSuggestOn,
194
194
  unavailable = false,
195
+ claudeReady = false,
196
+ aiRunning = false,
195
197
  viewer = false,
196
198
  onConnected,
197
199
  projectName = '',
@@ -311,6 +313,9 @@ function ChatThread({
311
313
  // ThreadPrimitive.Messages' component registry, which doesn't pass custom
312
314
  // props through, so this context is the only way it reaches the filter.
313
315
  const [lightboxSrc, setLightboxSrc] = useState(null);
316
+ // Universal ACP B6 — the agent this chat runs on, as the server reports it (null: Claude, or not said yet)
317
+ const [chatAgent, setChatAgent] = useState(null);
318
+ useEffect(() => conn.onAgent?.(setChatAgent), [conn]);
314
319
  // P8 c10 (03 `ai-long`): the chat's runs, so an earlier reply can draw its own result card (v2/ai/TurnResult.jsx)
315
320
  const { runs: chatRunList } = useChatRuns(conn, chatId);
316
321
  const chatRuns = useMemo(() => ({ runs: chatRunList }), [chatRunList]);
@@ -321,8 +326,9 @@ function ChatThread({
321
326
  designRel,
322
327
  transcriptView,
323
328
  chatRuns,
329
+ agent: chatAgent, // B6: the vendor badge on a reply from an agent other than Claude
324
330
  }),
325
- [designRel, transcriptView, chatRuns]
331
+ [designRel, transcriptView, chatRuns, chatAgent]
326
332
  );
327
333
  const [activeTools, setActiveTools] = useState([]);
328
334
  useEffect(() => conn.onActivity(setActiveTools), [conn]);
@@ -451,7 +457,7 @@ function ChatThread({
451
457
  <DropOverlay attach={attach} />
452
458
  {/* DDR-184 #3 — said up front when the current mode can't edit (plan / dontAsk),
453
459
  so a user typing "change X" isn't silently ignored. Above the feed. */}
454
- <SuggestOnlyBanner modes={caps.modes} onSetMode={onSetMode} />
460
+ <SuggestOnlyBanner modes={caps.modes} onSetMode={onSetMode} agent={chatAgent} />
455
461
  <ThreadPrimitive.Root className="chat-thread">
456
462
  {/* gate-b-a11y: the feed scrolls, so it is a tab stop with a name (axe scrollable-region-focusable) */}
457
463
  <ThreadPrimitive.Viewport
@@ -461,7 +467,7 @@ function ChatThread({
461
467
  aria-label="Conversation"
462
468
  >
463
469
  <ThreadPrimitive.Empty>
464
- <ChatEmpty />
470
+ <ChatEmpty claudeConnected={claudeReady} running={aiRunning} />
465
471
  </ThreadPrimitive.Empty>
466
472
  <ThreadPrimitive.Messages components={{ UserMessage, AssistantMessage }} />
467
473
  {/* Background work that outlived the turn — streamed here so it's not
@@ -541,7 +547,12 @@ function ChatThread({
541
547
  chatId={chatId}
542
548
  chatTitle={chatTitle}
543
549
  active={!hidden && !panelHidden}
544
- caps={{ modes: caps.modes, parsedOptions }}
550
+ caps={{
551
+ modes: caps.modes,
552
+ parsedOptions,
553
+ agent: chatAgent ?? caps.agent ?? null,
554
+ allowedModes: caps.allowedModes,
555
+ }}
545
556
  onSetMode={onSetMode}
546
557
  onSetConfig={onSetConfig}
547
558
  transcriptView={transcriptView}
@@ -916,6 +927,8 @@ export default function ChatPanel({
916
927
  }, [chats, openChatIds, sessionTitles, runsView]);
917
928
 
918
929
  const connected = status.available !== false;
930
+ // B6: the offer line waits while any chat runs (Claude busy is not idle)
931
+ const aiRunning = Object.values(busyChats).some(Boolean);
919
932
 
920
933
  return (
921
934
  <AiChatIsland hidden={hidden} resizing={resizing} width={width}>
@@ -1031,6 +1044,8 @@ export default function ChatPanel({
1031
1044
  suggestOn={suggestOn}
1032
1045
  onSetSuggestOn={onSetSuggestOn}
1033
1046
  unavailable={status.available === false}
1047
+ claudeReady={status.available === true}
1048
+ aiRunning={aiRunning}
1034
1049
  viewer={readOnly}
1035
1050
  onConnected={recheck}
1036
1051
  />
@@ -95,16 +95,21 @@ export function sanitizePathForDisplay(p) {
95
95
  return String(p).replace(UNSAFE_DISPLAY, '�');
96
96
  }
97
97
 
98
- export function describeOutOfProject(scope) {
98
+ export function describeOutOfProject(scope, agent = null) {
99
99
  if (!scope || scope.outOfProjectWrite !== true) return null;
100
+ // Universal ACP (Design Decision 5) — the agent that asks; Claude when the frame names none
101
+ const who =
102
+ typeof agent?.label === 'string' && agent.label.trim()
103
+ ? sanitizePathForDisplay(agent.label.trim())
104
+ : 'Claude';
100
105
  const paths = Array.isArray(scope.resolvedPaths)
101
106
  ? scope.resolvedPaths.filter(Boolean).map(sanitizePathForDisplay)
102
107
  : [];
103
108
  const lead =
104
109
  scope.reason === 'no-target'
105
- ? 'Claude asked to write a file but did not say which one.'
110
+ ? `${who} asked to write a file but did not say which one.`
106
111
  : scope.reason === 'disagreement'
107
- ? 'Claude named two different files for one write.'
112
+ ? `${who} named two different files for one write.`
108
113
  : // `in-project-denied` is INSIDE the project — saying "outside" would be
109
114
  // a plain lie, and the reason it's being asked about is different in
110
115
  // kind: not "where is this going" but "this file runs".
@@ -126,8 +131,8 @@ export function describeOutOfProject(scope) {
126
131
  : scope.reason === 'audience-unknown'
127
132
  ? 'Maude couldn’t check who can see this canvas, and AI read other files in this chat.'
128
133
  : paths.length > 1
129
- ? 'Claude wants to write files outside this project.'
130
- : 'Claude wants to write a file outside this project.';
134
+ ? `${who} wants to write files outside this project.`
135
+ : `${who} wants to write a file outside this project.`;
131
136
  return {
132
137
  lead,
133
138
  paths,
@@ -193,7 +198,7 @@ export default function PermissionPrompt({ request, onRespond, queueLength = 1 }
193
198
  const cardRef = useRef(null);
194
199
  const { toolCall } = request;
195
200
  const target = toolTarget(toolCall);
196
- const outOfProject = describeOutOfProject(request.scope);
201
+ const outOfProject = describeOutOfProject(request.scope, request.agent);
197
202
  const options = visibleOptions(request.options, !!outOfProject);
198
203
  // See the header comment in the JSX below for why an out-of-project write
199
204
  // gets a substituted headline + target instead of the adapter's own.
@@ -11,6 +11,7 @@ import { readMay } from '../v2/ai/ai-may.js';
11
11
  import { mayField, mergeOutbox, newAskId, promptFrame, reduceQueued } from '../v2/ai/ask-frame.js';
12
12
  import { noteAskedAnnotations } from '../v2/ai/ai-offer.js';
13
13
  import { cleanTasks } from '../v2/ai/background-model.js';
14
+ import { frameAgent, refusedNotice } from '../v2/ai/agents-model.js';
14
15
 
15
16
  const WS_PATH = '/_ws/acp';
16
17
 
@@ -271,15 +272,50 @@ export function createAcpConnection() {
271
272
  // it as its own channel too so the panel can render a proper retry card
272
273
  // instead — same "chrome, not turn content" treatment as commands/caps.
273
274
  const errorListeners = new Set();
274
- let lastError = null; // { message, code? } | null — `code` is the server's (S5.6: read-only | not-queued)
275
+ // { message, code?, agent? } | null — `code` is the server's (S5.6: read-only | not-queued; B6:
276
+ // agent-needs-consent | agent-policy-violated), `agent` the `{ id, label, vendor }` that said it (B6).
277
+ let lastError = null;
275
278
  function emitError() {
276
279
  for (const fn of errorListeners) fn(lastError);
277
280
  }
278
- function setError(message, code) {
279
- lastError = message ? (code ? { message, code } : { message }) : null;
281
+ function setError(message, code, agent) {
282
+ const who = frameAgent(agent);
283
+ lastError = message
284
+ ? { message, ...(code ? { code } : {}), ...(who ? { agent: who } : {}) }
285
+ : null;
280
286
  emitError();
281
287
  }
282
288
 
289
+ // Universal ACP B6 — the agent this chat runs on (`agent` on the `ready` / `caps` frames: `{ id, label,
290
+ // vendor }`; null until the server says, and from an older server that never does), the agent a NEW chat
291
+ // asks for on `attach`, and a refused turn's one quiet line (`turn-end` `reason: 'refused'`).
292
+ let chatAgent = null;
293
+ const agentListeners = new Set();
294
+ function setChatAgent(v) {
295
+ const next = frameAgent(v);
296
+ if (!next || (chatAgent && chatAgent.id === next.id && chatAgent.label === next.label)) return;
297
+ chatAgent = next;
298
+ for (const fn of agentListeners) fn(chatAgent);
299
+ }
300
+ let attachAgent; // the id the `attach` frame carries (undefined = the server's default, Claude)
301
+ let attachConsent = false;
302
+ let notice = null;
303
+ const noticeListeners = new Set();
304
+ function setNotice(v) {
305
+ if (notice === v) return;
306
+ notice = v;
307
+ for (const fn of noticeListeners) fn(notice);
308
+ }
309
+ function attachFrame() {
310
+ return {
311
+ t: 'attach',
312
+ chat: attachedChatId,
313
+ seq: hydratedSeq,
314
+ ...(attachAgent ? { agent: attachAgent } : {}),
315
+ ...(attachAgent && attachConsent ? { consent: true } : {}),
316
+ };
317
+ }
318
+
283
319
  // S5.13 — the chat's waiting prompts (`{t:'queued'}`, S5.6) and the runs it has (`{t:'run'}`). Neither is
284
320
  // turn content: a queued prompt did not start a turn, a run frame is bookkeeping. Chrome, like caps.
285
321
  const queuedListeners = new Set();
@@ -327,6 +363,7 @@ export function createAcpConnection() {
327
363
  status.ready = true;
328
364
  status.available = frame.available;
329
365
  status.reason = frame.reason;
366
+ if (frame.agent) setChatAgent(frame.agent);
330
367
  emitStatus();
331
368
  return;
332
369
  }
@@ -340,7 +377,14 @@ export function createAcpConnection() {
340
377
  // Same treatment for the capability channel — chrome, not turn content,
341
378
  // arrives on establish + on every live mode/config-option change.
342
379
  if (frame.t === 'caps') {
343
- caps = { modes: frame.modes ?? null, configOptions: frame.configOptions ?? [] };
380
+ if (frame.agent) setChatAgent(frame.agent);
381
+ caps = {
382
+ modes: frame.modes ?? null,
383
+ configOptions: frame.configOptions ?? [],
384
+ // B6: the modes the server lets this agent use (the bridge refuses the rest); absent = all offered
385
+ ...(Array.isArray(frame.allowedModes) ? { allowedModes: frame.allowedModes } : {}),
386
+ ...(frameAgent(frame.agent) ? { agent: frameAgent(frame.agent) } : {}),
387
+ };
344
388
  for (const fn of capsListeners) fn(caps);
345
389
  return;
346
390
  }
@@ -375,9 +419,14 @@ export function createAcpConnection() {
375
419
  // A refusal with a code (S5.6: `read-only`, `not-queued`) can arrive with no turn in flight (a
376
420
  // continuation, or a role that dropped mid-socket). It is a card, not a thrown turn.
377
421
  if (frame.t === 'error' && frame.code && !turnHandler) {
378
- setError(frame.message || 'AI could not do that.', frame.code);
422
+ setError(frame.message || 'AI could not do that.', frame.code, frame.agent);
379
423
  return;
380
424
  }
425
+ // B6: a refused turn says so in one quiet line (the turn itself ends below, as any turn-end does)
426
+ if (frame.t === 'turn-end') {
427
+ const said = refusedNotice(frame);
428
+ if (said) setNotice(said);
429
+ }
381
430
  if (frame.t === 'permission-request') {
382
431
  pendingPermissions = [
383
432
  ...pendingPermissions,
@@ -391,6 +440,8 @@ export function createAcpConnection() {
391
440
  // permission request, so PermissionPrompt's "outside the project"
392
441
  // copy can't fire on one.
393
442
  scope: frame.scope ?? null,
443
+ // Universal ACP (Design Decision 5) — the agent that asks (absent: Claude)
444
+ agent: frame.agent ?? null,
394
445
  },
395
446
  ];
396
447
  emitPermissions();
@@ -460,7 +511,7 @@ export function createAcpConnection() {
460
511
  // prompt.
461
512
  if (attachedChatId) {
462
513
  try {
463
- sock.send(JSON.stringify({ t: 'attach', chat: attachedChatId, seq: hydratedSeq }));
514
+ sock.send(JSON.stringify(attachFrame()));
464
515
  } catch {
465
516
  /* the frame handlers below surface a dead socket */
466
517
  }
@@ -616,6 +667,42 @@ export function createAcpConnection() {
616
667
  hydratedSeq = Number.isFinite(seq) && seq > 0 ? Math.floor(seq) : 0;
617
668
  },
618
669
 
670
+ /**
671
+ * B6 — the agent this chat asks for on `attach` (`agent: <id>`; Claude or none = the server's default, so
672
+ * a Claude chat's frame is unchanged). `consent` answers `agent-needs-consent` for an unrestricted agent.
673
+ * With the socket already open the attach is sent again at once; otherwise it rides the next open.
674
+ */
675
+ setAgent(agentId, { consent = false } = {}) {
676
+ const next = agentId && agentId !== 'claude' ? agentId : undefined;
677
+ const changed = next !== attachAgent || (consent && !attachConsent);
678
+ attachAgent = next;
679
+ attachConsent = !!(next && consent);
680
+ if (!changed || !attachedChatId || ws?.readyState !== WebSocket.OPEN) return;
681
+ try {
682
+ ws.send(JSON.stringify(attachFrame()));
683
+ } catch {
684
+ /* the next open sends it */
685
+ }
686
+ },
687
+ /** The id the next `attach` carries (undefined = Claude, the server's default). */
688
+ get attachAgent() {
689
+ return attachAgent;
690
+ },
691
+
692
+ /** Subscribe to the agent this chat runs on (`{ id, label, vendor }` or null); replays the current one. */
693
+ onAgent(fn) {
694
+ agentListeners.add(fn);
695
+ fn(chatAgent);
696
+ return () => agentListeners.delete(fn);
697
+ },
698
+
699
+ /** Subscribe to the refused turn's quiet line (string or null); replays the current one. */
700
+ onNotice(fn) {
701
+ noticeListeners.add(fn);
702
+ fn(notice);
703
+ return () => noticeListeners.delete(fn);
704
+ },
705
+
619
706
  /** Subscribe to `{ chat, running }` — fires once per successful attach.
620
707
  * `running: true` means this socket re-joined a LIVE turn. */
621
708
  onAttached(fn) {
@@ -733,7 +820,7 @@ export function createAcpConnection() {
733
820
  if (!sawTurn) ended = true;
734
821
  } else if (frame.t === 'error') {
735
822
  failure = frame.message || 'The Claude bridge errored.';
736
- setError(failure, frame.code); // Task C3: the styled retry card's source
823
+ setError(failure, frame.code, frame.agent); // Task C3: the styled retry card's source
737
824
  } else {
738
825
  sawTurn = true;
739
826
  queue.push(frame); // update / connected / permission
@@ -760,6 +847,7 @@ export function createAcpConnection() {
760
847
  // busy before these empty emits.
761
848
  resetBackground();
762
849
  setError(null); // a fresh turn clears any stale card from a prior failure
850
+ setNotice(null); // …and a refused turn's line (B6)
763
851
  if (activeTools.size) {
764
852
  activeTools.clear();
765
853
  emitActivity();
@@ -175,8 +175,8 @@ function MaySwitch({ row, label, on, onChange }) {
175
175
  }
176
176
 
177
177
  /** The one-line "AI is set to suggest only. The canvas won't change. [Allow changes]" above the thread. */
178
- export function SuggestOnlyBanner({ modes, onSetMode }) {
179
- const b = modeBanner(modes);
178
+ export function SuggestOnlyBanner({ modes, onSetMode, agent = null }) {
179
+ const b = modeBanner(modes, agent);
180
180
  if (!b) return null;
181
181
  return (
182
182
  <div className="ai-modebar" role="alert" data-testid="chat-mode-banner">
@@ -261,7 +261,8 @@ export function ChatAdvanced({
261
261
 
262
262
  const parsed = caps?.parsedOptions ?? { model: null, effort: null, fast: null, others: [] };
263
263
  const modes = caps?.modes ?? null;
264
- const modeList = modeOptions(modes);
264
+ // B6: the chat's agent's own modes; Claude's ids keep their plain words, the server's allowed list wins
265
+ const modeList = modeOptions(modes, { agent: caps?.agent, allowed: caps?.allowedModes });
265
266
  const currentMode = modeList.find((m) => m.id === modes?.currentModeId);
266
267
  // "Change canvases" is the ask-before mode seen as a switch: the "AI changes nothing" modes are off.
267
268
  const changesNothing = modeList.find((m) => m.id === modes?.currentModeId)?.group === 'nochange';
@@ -0,0 +1,138 @@
1
+ // client/v2/ai/AgentNotice.jsx — universal ACP B6, Design Decision 5: what an agent other than Claude said,
2
+ // said as ITS words, never as Maude's "AI broke".
3
+ //
4
+ // • an error frame carrying `agent` → "Codex reported: …" + the vendor's status page
5
+ // • `agent-policy-violated` → "Codex was stopped: it did not stay inside Maude's limits."
6
+ // • `agent-needs-consent` → the consent card (an unrestricted agent): Allow · Not now
7
+ // • `turn-end` with `reason: 'refused'` → one quiet line (AgentRefusedLine), not an error card
8
+ //
9
+ // Claude's own errors never come here (agents-model.js `agentErrorModel` answers null for them).
10
+
11
+ import { useEffect, useState } from 'react';
12
+ import { StIcon } from '../../shell/icons.jsx';
13
+ import { agentErrorModel } from './agents-model.js';
14
+
15
+ /** The desktop app (Tauri), where the webview has no general browser opener (DDR-054). */
16
+ const isDesktop = () => typeof window !== 'undefined' && !!window.__TAURI__;
17
+
18
+ /**
19
+ * A vendor status page. The URL is a catalog constant the server sent, never canvas or agent text.
20
+ * Browser: a new tab. Desktop: copied to the clipboard. The webview's openers are zone-locked
21
+ * (`open_cloud_url`) or confirm-sheet-only (`open_link_external`, S3.10b), and DDR-054 forbids a
22
+ * general one, so this is the same named fallback the website sheet uses: Copy link.
23
+ */
24
+ export function openStatusPage(url, deps = {}) {
25
+ if (!url) return Promise.resolve('failed');
26
+ const desktop = deps.desktop ?? isDesktop();
27
+ if (desktop) {
28
+ const copy = deps.copy ?? ((t) => navigator.clipboard.writeText(t));
29
+ return Promise.resolve()
30
+ .then(() => copy(url))
31
+ .then(
32
+ () => 'copied',
33
+ () => 'failed'
34
+ );
35
+ }
36
+ try {
37
+ (deps.windowOpen ?? window.open)(url, '_blank', 'noopener,noreferrer');
38
+ return Promise.resolve('ok');
39
+ } catch {
40
+ return Promise.resolve('failed');
41
+ }
42
+ }
43
+
44
+ /** The card for an agent's own error, or null when the error is not an agent's. */
45
+ export function AgentErrorCard({ error, onRetry, onConsent, onDecline, open = openStatusPage }) {
46
+ const [copied, setCopied] = useState(false);
47
+ const m = agentErrorModel(error);
48
+ if (!m) return null;
49
+ if (m.kind === 'consent')
50
+ return (
51
+ <div className="ai-nc ai-nc-choice" role="alert" data-testid="ai-agent-consent">
52
+ <p className="ai-nc-t">
53
+ <span className="ai-nc-ic ai-nc-ic--prob" aria-hidden="true">
54
+ <StIcon name="problem" size={14} />
55
+ </span>
56
+ <span className="ai-nc-tt">{m.text}</span>
57
+ </p>
58
+ <span className="ai-nc-a">
59
+ <button
60
+ type="button"
61
+ className="btn btn--sm"
62
+ data-testid="ai-agent-consent-dismiss"
63
+ onClick={onDecline}
64
+ >
65
+ Not now
66
+ </button>
67
+ <button
68
+ type="button"
69
+ className="btn btn--sm btn--primary"
70
+ data-testid="ai-agent-consent-allow"
71
+ onClick={() => onConsent?.(m.agent)}
72
+ >
73
+ Allow
74
+ </button>
75
+ </span>
76
+ </div>
77
+ );
78
+ return (
79
+ <div
80
+ className="ai-nc ai-nc-prob"
81
+ role="alert"
82
+ data-testid="ai-agent-error"
83
+ data-kind={m.kind}
84
+ data-agent={m.agent.id}
85
+ >
86
+ <p className="ai-nc-t">
87
+ <span className="ai-nc-ic ai-nc-ic--prob" aria-hidden="true">
88
+ <StIcon name="problem" size={14} />
89
+ </span>
90
+ <span className="ai-nc-tt" data-testid="ai-agent-error-text">
91
+ {m.text}
92
+ </span>
93
+ </p>
94
+ {m.statusUrl || (m.kind === 'reported' && onRetry) ? (
95
+ <span className="ai-nc-a">
96
+ {m.statusUrl ? (
97
+ <button
98
+ type="button"
99
+ className="btn btn--sm btn--ghost"
100
+ data-testid="ai-agent-error-status"
101
+ onClick={() =>
102
+ Promise.resolve(open(m.statusUrl)).then((r) => r === 'copied' && setCopied(true))
103
+ }
104
+ >
105
+ {copied
106
+ ? 'Status page link copied'
107
+ : isDesktop()
108
+ ? `Copy ${m.agent.vendor || m.agent.label} status link`
109
+ : `${m.agent.vendor || m.agent.label} status ↗`}
110
+ </button>
111
+ ) : null}
112
+ {m.kind === 'reported' && onRetry ? (
113
+ <button
114
+ type="button"
115
+ className="btn btn--sm btn--primary"
116
+ data-testid="ai-agent-error-retry"
117
+ onClick={onRetry}
118
+ >
119
+ Try again
120
+ </button>
121
+ ) : null}
122
+ </span>
123
+ ) : null}
124
+ </div>
125
+ );
126
+ }
127
+
128
+ /** A refused turn's notice: one quiet line under the chat, cleared when the next turn starts. */
129
+ export function AgentRefusedLine({ conn }) {
130
+ const [notice, setNotice] = useState(null);
131
+ useEffect(() => conn?.onNotice?.(setNotice), [conn]);
132
+ if (!notice) return null;
133
+ return (
134
+ <p className="ai-agent-note" role="status" data-testid="ai-agent-refused">
135
+ {notice}
136
+ </p>
137
+ );
138
+ }
@@ -0,0 +1,110 @@
1
+ // client/v2/ai/AgentOffer.jsx — universal ACP B6, Design Decision 1: the one quiet line in the AI panel's EMPTY
2
+ // state when another agent is on this Mac:
3
+ //
4
+ // Codex is on this Mac. Use it in Maude too? Connect · Not now
5
+ //
6
+ // The shape of OfferCard.jsx (one sentence, one button, Not now), not the component. Shown only while Claude is
7
+ // connected and idle and the server offers an agent (agents-model.js `offerModel`). "Not now" is permanent for
8
+ // every agent the line names. Connect registers the agent and starts that vendor's own sign-in, right here; a
9
+ // line naming several agents, or one with a note to read first, opens Settings › Connections › AI agents.
10
+
11
+ import { menuRunner } from '../shell/menu-runner.js';
12
+ import { offerModel } from './agents-model.js';
13
+ import {
14
+ connectProgressWords,
15
+ dismissAgentOffers,
16
+ useAgentConnect,
17
+ useAgents,
18
+ } from './agents-store.js';
19
+
20
+ /** Settings › Connections, on the AI agents card. */
21
+ export function openAgentsSettings(run = (id, p) => menuRunner.run(id, p)) {
22
+ return run('settings.open', { tab: 'connections#agents' });
23
+ }
24
+
25
+ export function AgentOfferLine({
26
+ agents,
27
+ offerAgents,
28
+ claudeConnected,
29
+ running = false,
30
+ conn: c,
31
+ onDismiss = dismissAgentOffers,
32
+ onOpenSettings = openAgentsSettings,
33
+ }) {
34
+ const offer = offerModel({ agents, offerAgents, claudeConnected, running });
35
+ if (!offer) return null;
36
+ const one = offer.rows.length === 1 ? offer.rows[0] : null;
37
+ const inline = !!one && !one.connectNote;
38
+ const busy = c.busyId !== null && offer.ids.includes(c.busyId);
39
+ const progress = busy ? connectProgressWords(c.phase, one?.label ?? '') : null;
40
+ const failed = c.errorId && offer.ids.includes(c.errorId) ? c.error : null;
41
+ return (
42
+ // biome-ignore lint/a11y/useSemanticElements: one labelled line with two verbs, not a form fieldset
43
+ <div
44
+ className="ai-agent-offer"
45
+ data-testid="ai-agent-offer"
46
+ role="group"
47
+ aria-label="Another AI agent"
48
+ >
49
+ <p className="ai-agent-offer-t">
50
+ {progress ?? offer.text}{' '}
51
+ {busy ? (
52
+ <button
53
+ type="button"
54
+ className="ai-agent-link"
55
+ data-testid="ai-agent-offer-cancel"
56
+ onClick={c.cancel}
57
+ >
58
+ Cancel
59
+ </button>
60
+ ) : (
61
+ <>
62
+ <button
63
+ type="button"
64
+ className="ai-agent-link"
65
+ data-testid="ai-agent-offer-connect"
66
+ onClick={() => (inline ? c.connect(one) : onOpenSettings())}
67
+ >
68
+ Connect
69
+ </button>
70
+ <span className="ai-agent-sep" aria-hidden="true">
71
+ ·
72
+ </span>
73
+ <button
74
+ type="button"
75
+ className="ai-agent-link ai-agent-link--quiet"
76
+ data-testid="ai-agent-offer-dismiss"
77
+ onClick={() => onDismiss(offer.ids)}
78
+ >
79
+ Not now
80
+ </button>
81
+ </>
82
+ )}
83
+ </p>
84
+ {failed ? (
85
+ <p
86
+ className="ai-agent-note ai-agent-note--err"
87
+ role="alert"
88
+ data-testid="ai-agent-offer-error"
89
+ >
90
+ {failed}
91
+ </p>
92
+ ) : null}
93
+ </div>
94
+ );
95
+ }
96
+
97
+ /** The line, wired: the shared agent list, one connect at a time. `running`: any chat of the panel runs. */
98
+ export function AgentOffer({ claudeConnected = false, running = false }) {
99
+ const { agents, offerAgents } = useAgents();
100
+ const c = useAgentConnect();
101
+ return (
102
+ <AgentOfferLine
103
+ agents={agents}
104
+ offerAgents={offerAgents}
105
+ claudeConnected={claudeConnected}
106
+ running={running}
107
+ conn={c}
108
+ />
109
+ );
110
+ }