@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.
- package/apps/studio/acp/agents/auth.ts +241 -0
- package/apps/studio/acp/agents/catalog.ts +308 -0
- package/apps/studio/acp/agents/chat-key.ts +64 -0
- package/apps/studio/acp/agents/conformance.ts +1853 -0
- package/apps/studio/acp/agents/consent.ts +92 -0
- package/apps/studio/acp/agents/descriptor.ts +188 -0
- package/apps/studio/acp/agents/discover.ts +491 -0
- package/apps/studio/acp/agents/e2e-model.ts +58 -0
- package/apps/studio/acp/agents/health.ts +46 -0
- package/apps/studio/acp/agents/link-scan.ts +230 -0
- package/apps/studio/acp/agents/spawn.ts +164 -0
- package/apps/studio/acp/agents/state.ts +132 -0
- package/apps/studio/acp/ask-queue.ts +13 -4
- package/apps/studio/acp/bootstrap-brief.ts +16 -3
- package/apps/studio/acp/bridge.ts +709 -99
- package/apps/studio/acp/env.ts +43 -1
- package/apps/studio/acp/index.ts +428 -43
- package/apps/studio/acp/may-scope.ts +244 -21
- package/apps/studio/acp/policy/agent-home.ts +202 -0
- package/apps/studio/acp/policy/bridge-gate.ts +68 -0
- package/apps/studio/acp/policy/codex-home.ts +228 -0
- package/apps/studio/acp/policy/enforce.ts +620 -0
- package/apps/studio/acp/policy/gate-types.ts +41 -0
- package/apps/studio/acp/policy/launch-codex.ts +351 -0
- package/apps/studio/acp/policy/launch-copilot.ts +119 -0
- package/apps/studio/acp/policy/launch-gemini.ts +120 -0
- package/apps/studio/acp/policy/launch-opencode.ts +131 -0
- package/apps/studio/acp/policy/opencode-user-config.ts +240 -0
- package/apps/studio/acp/probe.ts +78 -14
- package/apps/studio/acp/transcript.ts +14 -0
- package/apps/studio/acp/write-scope.ts +62 -2
- package/apps/studio/client/panels/ChatPanel.jsx +19 -4
- package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
- package/apps/studio/client/panels/acp-runtime.js +95 -7
- package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
- package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
- package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
- package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
- package/apps/studio/client/v2/ai/Composer.jsx +4 -0
- package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
- package/apps/studio/client/v2/ai/Feed.jsx +8 -0
- package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
- package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
- package/apps/studio/client/v2/ai/advanced-model.js +17 -6
- package/apps/studio/client/v2/ai/agents-model.js +333 -0
- package/apps/studio/client/v2/ai/agents-store.js +223 -0
- package/apps/studio/client/v2/ai/ai.css +63 -0
- package/apps/studio/client/v2/ai/needs-you.js +1 -1
- package/apps/studio/client/v2/fold/fold-store.js +1 -0
- package/apps/studio/client/v2/settings/agent-keys.js +88 -0
- package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
- package/apps/studio/client/v2/settings/connections-model.js +1 -1
- package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
- package/apps/studio/client/v2/settings/settings-cards.js +2 -1
- package/apps/studio/client/v2/settings/settings-model.js +1 -0
- package/apps/studio/client/v2/settings/settings.css +7 -0
- package/apps/studio/client/v2/shell/served-routes.js +1 -0
- package/apps/studio/cloud-build.ts +5 -0
- package/apps/studio/dist/client.bundle.js +604 -604
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/generation/keys.ts +197 -11
- package/apps/studio/outbox/policy.ts +8 -2
- package/apps/studio/outbox/types.ts +5 -0
- package/apps/studio/routes/agents.ts +479 -0
- package/apps/studio/routes/index.ts +3 -0
- package/apps/studio/scripts/acp-conformance-local.ts +95 -0
- package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
- package/apps/studio/server.ts +9 -0
- package/apps/studio/sync/writer-registry.ts +12 -0
- package/apps/studio/whats-new.json +10 -0
- package/apps/studio/ws.ts +3 -0
- package/cli/commands/codex.mjs +36 -2
- package/cli/lib/harness/codex-runtime.mjs +98 -11
- package/package.json +9 -8
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// client/v2/ai/AgentPicker.jsx — universal ACP B6, Design Decision 4: which agent a chat runs on.
|
|
2
|
+
//
|
|
3
|
+
// • The chip sits in the composer, beside the scope chip, and shows only when two or more agents are
|
|
4
|
+
// connected (Claude counts when it is connected). Claude-only: nothing is drawn.
|
|
5
|
+
// • A NEW chat (nothing sent yet) starts on the last agent used in this profile (or Claude, or the one
|
|
6
|
+
// connected agent) and the person may pick another. The pick rides the WS `attach` frame (`agent`).
|
|
7
|
+
// • A chat that has started keeps its agent: the chip turns read-only. No switching mid-chat.
|
|
8
|
+
//
|
|
9
|
+
// The binding runs even while the chip is hidden: someone with only Codex connected gets Codex.
|
|
10
|
+
|
|
11
|
+
import { useThread } from '@assistant-ui/react';
|
|
12
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import {
|
|
14
|
+
CLAUDE_ID,
|
|
15
|
+
connectedAgents,
|
|
16
|
+
pickerVisible,
|
|
17
|
+
readChatAgent,
|
|
18
|
+
readLastAgent,
|
|
19
|
+
resolveNewChatAgent,
|
|
20
|
+
writeChatAgent,
|
|
21
|
+
writeLastAgent,
|
|
22
|
+
} from './agents-model.js';
|
|
23
|
+
import { currentProfileId, loadProfileId, useAgents } from './agents-store.js';
|
|
24
|
+
|
|
25
|
+
/** The chip itself (controlled). `locked` = the chat has started: its agent, read-only. */
|
|
26
|
+
export function AgentPickerChip({ agents, value, locked = false, lockedLabel = null, onPick }) {
|
|
27
|
+
if (!pickerVisible(agents)) return null;
|
|
28
|
+
const on = connectedAgents(agents);
|
|
29
|
+
const current = on.find((a) => a.id === value);
|
|
30
|
+
if (locked) {
|
|
31
|
+
const label = lockedLabel ?? current?.label ?? 'Claude';
|
|
32
|
+
return (
|
|
33
|
+
<span
|
|
34
|
+
className="chip ai-agent-chip ai-agent-chip--locked"
|
|
35
|
+
data-testid="ai-agent-picker"
|
|
36
|
+
data-agent={value ?? CLAUDE_ID}
|
|
37
|
+
title={`This chat runs on ${label}. Start a new chat to use another agent.`}
|
|
38
|
+
>
|
|
39
|
+
{label}
|
|
40
|
+
</span>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
<select
|
|
45
|
+
className="chip ai-agent-chip"
|
|
46
|
+
data-testid="ai-agent-picker"
|
|
47
|
+
data-agent={value ?? ''}
|
|
48
|
+
aria-label="Agent for this chat"
|
|
49
|
+
value={value ?? ''}
|
|
50
|
+
onChange={(e) => onPick?.(e.target.value)}
|
|
51
|
+
>
|
|
52
|
+
{on.map((a) => (
|
|
53
|
+
<option key={a.id} value={a.id}>
|
|
54
|
+
{a.label}
|
|
55
|
+
</option>
|
|
56
|
+
))}
|
|
57
|
+
</select>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The composer's picker, wired to this chat's connection. Mount it inside the thread (it reads whether the
|
|
63
|
+
* chat has started from it).
|
|
64
|
+
*/
|
|
65
|
+
export function AgentPicker({ conn, chatId }) {
|
|
66
|
+
const { agents, loaded } = useAgents();
|
|
67
|
+
const started = useThread((t) => t.messages.length > 0);
|
|
68
|
+
const others = useMemo(() => connectedAgents(agents).some((a) => a.id !== CLAUDE_ID), [agents]);
|
|
69
|
+
// the chat's agent as the server reports it (`ready` / `caps`), else what this Mac recorded
|
|
70
|
+
const [live, setLive] = useState(null);
|
|
71
|
+
useEffect(() => conn?.onAgent?.(setLive), [conn]);
|
|
72
|
+
const recorded = useMemo(() => readChatAgent(chatId), [chatId]);
|
|
73
|
+
const [picked, setPicked] = useState(null);
|
|
74
|
+
const [profile, setProfile] = useState(currentProfileId);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!others) return undefined;
|
|
77
|
+
let alive = true;
|
|
78
|
+
void loadProfileId().then((id) => alive && setProfile(id));
|
|
79
|
+
return () => {
|
|
80
|
+
alive = false;
|
|
81
|
+
};
|
|
82
|
+
}, [others]);
|
|
83
|
+
|
|
84
|
+
// what a new chat is set to; kept when the first send starts it (the server's word follows)
|
|
85
|
+
const chosen = useRef(null);
|
|
86
|
+
if (!started) chosen.current = picked ?? resolveNewChatAgent(agents, readLastAgent(profile));
|
|
87
|
+
const value = started
|
|
88
|
+
? (live?.id ?? recorded ?? chosen.current ?? CLAUDE_ID)
|
|
89
|
+
: (chosen.current ?? CLAUDE_ID);
|
|
90
|
+
|
|
91
|
+
// a new chat asks for its agent on attach; Claude (or none) leaves the frame as it always was
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (started || !loaded || !conn?.setAgent) return;
|
|
94
|
+
conn.setAgent(value);
|
|
95
|
+
}, [started, loaded, conn, value]);
|
|
96
|
+
// a started chat this Mac recorded on another agent re-attaches to that agent (a reload, a reopened chat)
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (recorded && recorded !== CLAUDE_ID && conn?.setAgent && !conn.attachAgent)
|
|
99
|
+
conn.setAgent(recorded);
|
|
100
|
+
}, [recorded, conn]);
|
|
101
|
+
|
|
102
|
+
// the first send fixes the chat's agent, and makes it the profile's last-used one
|
|
103
|
+
const wasStarted = useRef(started);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const first = started && !wasStarted.current;
|
|
106
|
+
wasStarted.current = started;
|
|
107
|
+
if (!first || !loaded || !others || !chosen.current) return;
|
|
108
|
+
writeChatAgent(chatId, chosen.current);
|
|
109
|
+
writeLastAgent(profile, chosen.current);
|
|
110
|
+
}, [started, loaded, others, chatId, profile]);
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<AgentPickerChip
|
|
114
|
+
agents={agents}
|
|
115
|
+
value={value}
|
|
116
|
+
locked={started}
|
|
117
|
+
lockedLabel={started ? (live?.label ?? null) : null}
|
|
118
|
+
onPick={setPicked}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
uploadChatImage,
|
|
28
28
|
} from './paste-chips.jsx';
|
|
29
29
|
import { AttachChips } from './AChip.jsx';
|
|
30
|
+
import { AgentPicker } from './AgentPicker.jsx';
|
|
30
31
|
import { AttachMenu } from './AttachMenu.jsx';
|
|
31
32
|
import { Consent } from './Consent.jsx';
|
|
32
33
|
import { ScopeChip } from './ScopeChip.jsx';
|
|
@@ -621,6 +622,9 @@ export function Composer({
|
|
|
621
622
|
onRemove={onCtxDismiss}
|
|
622
623
|
/>
|
|
623
624
|
) : null}
|
|
625
|
+
{/* Universal ACP B6 — which agent this chat runs on; drawn only with two or more connected */}
|
|
626
|
+
<AgentPicker conn={conn} chatId={chatId} />
|
|
627
|
+
|
|
624
628
|
<HighlightedInput
|
|
625
629
|
existsSet={existsSet}
|
|
626
630
|
attachmentsRef={attachmentsRef}
|
|
@@ -92,6 +92,9 @@ export function ConnectSheet({
|
|
|
92
92
|
fine = "Your prompt waits here and runs as soon as it's connected.",
|
|
93
93
|
// 09 ex-handoff-edges draws the card without the "Claude Pro or Max" row: just the words and the two buttons
|
|
94
94
|
option = true,
|
|
95
|
+
// Universal ACP B6 (Design Decision 3): the sheet stays Claude-only; when another agent is on this Mac it
|
|
96
|
+
// gains one quiet link to Settings › Connections › AI agents. null = no link (always, for Claude-only).
|
|
97
|
+
onOtherAgent = null,
|
|
95
98
|
children,
|
|
96
99
|
}) {
|
|
97
100
|
const titleId = useId();
|
|
@@ -143,6 +146,16 @@ export function ConnectSheet({
|
|
|
143
146
|
</p>
|
|
144
147
|
) : null}
|
|
145
148
|
{fine ? <p className="ai-conn-fine">{fine}</p> : null}
|
|
149
|
+
{onOtherAgent ? (
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
className="ai-agent-link ai-conn-other"
|
|
153
|
+
data-testid="connect-other-agent-link"
|
|
154
|
+
onClick={onOtherAgent}
|
|
155
|
+
>
|
|
156
|
+
Use another agent…
|
|
157
|
+
</button>
|
|
158
|
+
) : null}
|
|
146
159
|
</div>
|
|
147
160
|
<div className="ai-conn-a">
|
|
148
161
|
<button
|
|
@@ -25,6 +25,7 @@ import { StIcon } from '../../shell/icons.jsx';
|
|
|
25
25
|
import { Copy, Retry, Spark } from './icons.jsx';
|
|
26
26
|
import { OPEN_ASSETS_EVENT } from './AttachMenu.jsx';
|
|
27
27
|
import { failureModel } from './needs-you.js';
|
|
28
|
+
import { agentBadge } from './agents-model.js';
|
|
28
29
|
|
|
29
30
|
// ── message-part renderers ──
|
|
30
31
|
// Assistant text: markdown, plus a thumbnail strip for any designRoot image
|
|
@@ -364,10 +365,17 @@ export function AssistantMessage() {
|
|
|
364
365
|
const turnChanged = !!turnRun && changedSomething(turnRun);
|
|
365
366
|
// A turn that has only called tools so far says nothing yet: no empty bubble, no empty gap.
|
|
366
367
|
const bare = grouped.length === 0;
|
|
368
|
+
const badge = bare ? null : agentBadge(media?.agent);
|
|
367
369
|
return (
|
|
368
370
|
<div
|
|
369
371
|
className={`chat-msg chat-msg--assistant${bare ? ' chat-msg--bare' : ''}${status === 'running' ? ' chat-msg--live' : ''}`}
|
|
370
372
|
>
|
|
373
|
+
{/* Universal ACP B6 (Design Decision 5): a reply from an agent other than Claude says whose it is */}
|
|
374
|
+
{badge ? (
|
|
375
|
+
<span className="ai-agent-badge" data-testid="ai-agent-badge" title={badge.title}>
|
|
376
|
+
{badge.label}
|
|
377
|
+
</span>
|
|
378
|
+
) : null}
|
|
371
379
|
{grouped.map((g, i) =>
|
|
372
380
|
g.type === 'tool-group' ? (
|
|
373
381
|
<ToolGroup
|
|
@@ -12,6 +12,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
|
12
12
|
import { dismissNotice, notify } from '../../../notifications.tsx';
|
|
13
13
|
import ElicitationPrompt from '../../panels/ElicitationPrompt.jsx';
|
|
14
14
|
import ChoiceCard from './ChoiceCard.jsx';
|
|
15
|
+
import { AgentErrorCard, AgentRefusedLine } from './AgentNotice.jsx';
|
|
16
|
+
import { agentErrorModel, otherAgentLinkVisible } from './agents-model.js';
|
|
17
|
+
import { useAgents } from './agents-store.js';
|
|
18
|
+
import { openAgentsSettings } from './AgentOffer.jsx';
|
|
15
19
|
import { ConnectModal } from './ConnectSheet.jsx';
|
|
16
20
|
import { connectClaude } from './connect-flow.js';
|
|
17
21
|
import { ErrorCard } from './Feed.jsx';
|
|
@@ -217,6 +221,11 @@ export default function NeedsYouSlot({
|
|
|
217
221
|
refresh();
|
|
218
222
|
}, [queued, refresh]);
|
|
219
223
|
|
|
224
|
+
// B6: an error an agent other than Claude reported (agents-model.js); Not now on a consent card hides it
|
|
225
|
+
const agentSaid = !!agentErrorModel(turnError);
|
|
226
|
+
const agentList = useAgents();
|
|
227
|
+
const [declined, setDeclined] = useState(null);
|
|
228
|
+
|
|
220
229
|
const activePermission = pendingPermissions[0] ?? null;
|
|
221
230
|
const activeElicitation = activePermission ? null : (pendingElicitations[0] ?? null);
|
|
222
231
|
const choice = activeElicitation ? choiceModel(activeElicitation) : null;
|
|
@@ -262,7 +271,18 @@ export default function NeedsYouSlot({
|
|
|
262
271
|
)
|
|
263
272
|
) : settled ? (
|
|
264
273
|
<ChoiceCard settled model={settled.model} picked={settled.picked} />
|
|
265
|
-
) : turnError
|
|
274
|
+
) : agentSaid && turnError !== declined ? (
|
|
275
|
+
// B6 (Design Decision 5): an agent other than Claude said it — its words, its status page
|
|
276
|
+
<AgentErrorCard
|
|
277
|
+
error={turnError}
|
|
278
|
+
onRetry={onRetry}
|
|
279
|
+
onConsent={(agent) => {
|
|
280
|
+
conn.setAgent?.(agent.id, { consent: true });
|
|
281
|
+
onRetry?.();
|
|
282
|
+
}}
|
|
283
|
+
onDecline={() => setDeclined(turnError)}
|
|
284
|
+
/>
|
|
285
|
+
) : agentSaid ? null : turnError?.code ? (
|
|
266
286
|
// A refusal the server coded (S5.6: view only, prompt not kept) says plainly what happened.
|
|
267
287
|
<ProblemCard error={turnError} />
|
|
268
288
|
) : (
|
|
@@ -276,9 +296,12 @@ export default function NeedsYouSlot({
|
|
|
276
296
|
error={connectError}
|
|
277
297
|
onConnect={connect}
|
|
278
298
|
onCancel={cancelConnect}
|
|
299
|
+
// B6 (Design Decision 3): Claude-only, with one quiet way to another agent when one is here
|
|
300
|
+
onOtherAgent={otherAgentLinkVisible(agentList) ? () => openAgentsSettings() : null}
|
|
279
301
|
/>
|
|
280
302
|
</QueuedState>
|
|
281
303
|
) : null}
|
|
304
|
+
<AgentRefusedLine conn={conn} />
|
|
282
305
|
</div>
|
|
283
306
|
);
|
|
284
307
|
}
|
|
@@ -8,6 +8,7 @@ import { deriveSuggestions } from './suggest-why.js';
|
|
|
8
8
|
import { useAnswered, useResultShown } from './result-shown.js';
|
|
9
9
|
import { useEffect, useState, useSyncExternalStore } from 'react';
|
|
10
10
|
import { repairOfferFor, subscribeRepairOffer } from '../create/repair-offer.js';
|
|
11
|
+
import { AgentOffer } from './AgentOffer.jsx';
|
|
11
12
|
|
|
12
13
|
// Persistent quick-action verbs (prefill the composer; never fire blind). The
|
|
13
14
|
// one-time `/design:setup-ds` is offered contextually in the empty state, not here.
|
|
@@ -18,7 +19,7 @@ export const QUICK_ACTIONS = [
|
|
|
18
19
|
{ label: '/design:screenshot', prompt: '/design:screenshot' },
|
|
19
20
|
];
|
|
20
21
|
|
|
21
|
-
export function ChatEmpty() {
|
|
22
|
+
export function ChatEmpty({ claudeConnected = false, running = false }) {
|
|
22
23
|
return (
|
|
23
24
|
<>
|
|
24
25
|
{/* P8-C6 (03 `.ai-hint`): one quiet paragraph, left-aligned, type-sm fg-2 — it sits right above the
|
|
@@ -26,6 +27,9 @@ export function ChatEmpty() {
|
|
|
26
27
|
<p className="ai-hint" data-testid="ai-hint">
|
|
27
28
|
Ask for a change, a few variants, or an answer. AI works on what the chip says.
|
|
28
29
|
</p>
|
|
30
|
+
{/* Universal ACP B6 (Design Decision 1): another agent on this Mac, offered once, in one quiet line.
|
|
31
|
+
Nothing at all when only Claude is here. */}
|
|
32
|
+
<AgentOffer claudeConnected={claudeConnected} running={running} />
|
|
29
33
|
{/* S5.17 G4 — 03 `ai-open` draws only this hint and the one suggestion strip above the field
|
|
30
34
|
(SuggestStrip). The v1 "Create new design system" CTA, the four /design:* verb buttons and the
|
|
31
35
|
three slash suggestions are gone from the EMPTY state only: every /design:* verb (setup-ds
|
|
@@ -101,22 +101,31 @@ export const MODE_GROUP_LABEL = Object.freeze({
|
|
|
101
101
|
free: 'No safety net',
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
/** Universal ACP B6: the words above are Claude Code's mode ids, so they are Claude's labels only. */
|
|
105
|
+
const isClaude = (agent) => !agent || agent === 'claude' || agent?.id === 'claude';
|
|
106
|
+
|
|
104
107
|
/**
|
|
105
108
|
* The modes the SESSION offers, in plain words. The agent decides which it offers; the rest stay hidden
|
|
106
109
|
* ("Skip every check" shows only where the agent allows it). An id Maude has no words for keeps the agent's
|
|
107
110
|
* own name (and its own description as the hint) rather than vanishing.
|
|
111
|
+
*
|
|
112
|
+
* B6 — `agent` is the chat's agent (`{ id }`, an id, or none for Claude). The plain words above are Claude's;
|
|
113
|
+
* any other agent's modes keep their own names and descriptions, in the agent's own order. `allowed` is the
|
|
114
|
+
* list the server sends in `caps` (`allowedModes`): a mode the bridge refuses is never listed.
|
|
108
115
|
*/
|
|
109
|
-
export function modeOptions(modes) {
|
|
110
|
-
const
|
|
116
|
+
export function modeOptions(modes, { agent = null, allowed = null } = {}) {
|
|
117
|
+
const claude = isClaude(agent);
|
|
118
|
+
const ok = Array.isArray(allowed) ? new Set(allowed) : null;
|
|
119
|
+
const list = (modes?.availableModes ?? []).filter((m) => !ok || ok.has(m.id));
|
|
111
120
|
return list
|
|
112
|
-
.map((m) => {
|
|
113
|
-
const w = WORDS.get(m.id);
|
|
121
|
+
.map((m, i) => {
|
|
122
|
+
const w = claude ? WORDS.get(m.id) : undefined;
|
|
114
123
|
return {
|
|
115
124
|
id: m.id,
|
|
116
125
|
label: w?.label ?? m.name ?? m.id,
|
|
117
126
|
note: m.id,
|
|
118
127
|
group: w?.group ?? 'asks',
|
|
119
|
-
order: w?.order ?? 100,
|
|
128
|
+
order: w?.order ?? (claude ? 100 : i),
|
|
120
129
|
description: m.description ?? '',
|
|
121
130
|
hint: w?.hint ?? m.description ?? '',
|
|
122
131
|
risky: w?.risky ?? false,
|
|
@@ -135,8 +144,10 @@ export function currentModeNote(modes) {
|
|
|
135
144
|
* ONE verb to undo it — "Allow changes". The target is the least-privilege mode that can edit (v1 DDR-184
|
|
136
145
|
* #3: Accept edits if offered, else the asking default). `null` when the mode can edit.
|
|
137
146
|
*/
|
|
138
|
-
export function modeBanner(modes) {
|
|
147
|
+
export function modeBanner(modes, agent = null) {
|
|
139
148
|
const id = modes?.currentModeId;
|
|
149
|
+
// B6: `plan` / `dontAsk` are Claude Code's ids; another agent's mode of the same name means something else
|
|
150
|
+
if (!isClaude(agent)) return null;
|
|
140
151
|
if (!id || !NO_EDIT_MODE_IDS.has(id)) return null;
|
|
141
152
|
const ids = new Set((modes.availableModes ?? []).map((m) => m.id));
|
|
142
153
|
const target = ids.has('acceptEdits') ? 'acceptEdits' : ids.has('default') ? 'default' : null;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// client/v2/ai/agents-model.js — universal ACP B6 (plan feature-universal-acp-and-codex, Design Decisions 1–6):
|
|
2
|
+
// the other AI agents as data. PURE (no DOM, no React, no fetch) so every visibility rule is tested alone.
|
|
3
|
+
//
|
|
4
|
+
// The rows come from `GET /_api/agents` (routes/agents.ts): `{ agents: [Row], offerAgents: [id] }`, Row =
|
|
5
|
+
// `{ id, label, vendor, installed, policy, offerable, connected, auth, offer, connectNote, state, … }`.
|
|
6
|
+
// Claude is a row too; it keeps its own Settings card and its own Connect sheet, so it is never a row here.
|
|
7
|
+
//
|
|
8
|
+
// The principle: awareness only from local evidence. With only Claude (nothing else installed) every
|
|
9
|
+
// function below answers "nothing to show": no offer line, no picker, no link, no Settings card.
|
|
10
|
+
|
|
11
|
+
export const CLAUDE_ID = 'claude';
|
|
12
|
+
|
|
13
|
+
/** The last agent a NEW chat used, per profile (localStorage, JSON `{ [profileId]: agentId }`). */
|
|
14
|
+
export const LAST_AGENT_KEY = 'maude-ai-last-agent-v1';
|
|
15
|
+
/** The agent each chat started with (localStorage, JSON `{ [chatId]: agentId }`). */
|
|
16
|
+
export const CHAT_AGENT_KEY = 'maude-ai-chat-agent-v1';
|
|
17
|
+
/** How many chats the map above remembers (oldest dropped first). */
|
|
18
|
+
export const CHAT_AGENT_CAP = 300;
|
|
19
|
+
|
|
20
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
21
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
22
|
+
|
|
23
|
+
/** A `/_api/agents` answer, made safe to read: anything malformed reads as "no agents". */
|
|
24
|
+
export function normalizeAgents(body) {
|
|
25
|
+
const agents = (Array.isArray(body?.agents) ? body.agents : [])
|
|
26
|
+
.filter((a) => isObj(a) && typeof a.id === 'string' && a.id)
|
|
27
|
+
.map((a) => ({
|
|
28
|
+
...a,
|
|
29
|
+
label: str(a.label) || a.id,
|
|
30
|
+
vendor: str(a.vendor),
|
|
31
|
+
installed: a.installed === true,
|
|
32
|
+
connected: a.connected === true,
|
|
33
|
+
}));
|
|
34
|
+
const known = new Set(agents.map((a) => a.id));
|
|
35
|
+
const offerAgents = (Array.isArray(body?.offerAgents) ? body.offerAgents : []).filter(
|
|
36
|
+
(id) => typeof id === 'string' && id !== CLAUDE_ID && known.has(id)
|
|
37
|
+
);
|
|
38
|
+
return { agents, offerAgents };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** "Codex" · "Codex and opencode" · "Codex, Gemini and opencode". */
|
|
42
|
+
export function andList(words) {
|
|
43
|
+
const w = (words ?? []).filter(Boolean);
|
|
44
|
+
if (w.length <= 1) return w.join('');
|
|
45
|
+
return `${w.slice(0, -1).join(', ')} and ${w[w.length - 1]}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Design Decision 1: the one shared offer line in the AI panel's EMPTY state, or null.
|
|
50
|
+
* Shown only when Claude is connected and idle and the server named agents it may offer (installed,
|
|
51
|
+
* bridge-enforced, tested version, not connected, never dismissed). Unrestricted agents are never offered.
|
|
52
|
+
* @returns {{ ids: string[], rows: object[], text: string } | null}
|
|
53
|
+
*/
|
|
54
|
+
export function offerModel({
|
|
55
|
+
agents = [],
|
|
56
|
+
offerAgents = [],
|
|
57
|
+
claudeConnected = false,
|
|
58
|
+
running = false,
|
|
59
|
+
}) {
|
|
60
|
+
if (!claudeConnected || running) return null;
|
|
61
|
+
const byId = new Map(agents.map((a) => [a.id, a]));
|
|
62
|
+
const rows = offerAgents
|
|
63
|
+
.map((id) => byId.get(id))
|
|
64
|
+
.filter((a) => a && a.id !== CLAUDE_ID && !a.connected && a.policy !== 'unrestricted');
|
|
65
|
+
if (!rows.length) return null;
|
|
66
|
+
const one = rows.length === 1;
|
|
67
|
+
return {
|
|
68
|
+
ids: rows.map((a) => a.id),
|
|
69
|
+
rows,
|
|
70
|
+
text: `${andList(rows.map((a) => a.label))} ${one ? 'is' : 'are'} on this Mac. Use ${one ? 'it' : 'them'} in Maude too?`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Every connected agent, Claude included when it is connected. */
|
|
75
|
+
export function connectedAgents(agents = []) {
|
|
76
|
+
return agents.filter((a) => a.connected);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Design Decision 4: the composer's agent chip shows only with two or more connected agents. */
|
|
80
|
+
export function pickerVisible(agents = []) {
|
|
81
|
+
return connectedAgents(agents).length >= 2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Design Decision 3: the Connect sheet's "Use another agent…" link — only when an offer is waiting, or a
|
|
86
|
+
* non-Claude agent that Maude can hold to its limits (bridge-enforced) is installed.
|
|
87
|
+
*/
|
|
88
|
+
export function otherAgentLinkVisible({ agents = [], offerAgents = [] } = {}) {
|
|
89
|
+
if (offerAgents.length > 0) return true;
|
|
90
|
+
return agents.some((a) => a.id !== CLAUDE_ID && a.installed && a.policy === 'bridge-enforced');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The agent a NEW chat starts with: the last one used (when it is still connected), else Claude when it is
|
|
95
|
+
* connected, else the first connected agent, else null (the server's default, Claude).
|
|
96
|
+
*/
|
|
97
|
+
export function resolveNewChatAgent(agents = [], lastUsed = null) {
|
|
98
|
+
const on = connectedAgents(agents);
|
|
99
|
+
if (lastUsed && on.some((a) => a.id === lastUsed)) return lastUsed;
|
|
100
|
+
if (on.some((a) => a.id === CLAUDE_ID)) return CLAUDE_ID;
|
|
101
|
+
return on[0]?.id ?? null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What the `attach` frame carries as `agent`: nothing for Claude (the server's default), else the id. */
|
|
105
|
+
export function attachAgentOf(agentId) {
|
|
106
|
+
return agentId && agentId !== CLAUDE_ID ? agentId : undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── Settings › Connections › AI agents (Design Decision 2) ─────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
const STATE_WORDS = {
|
|
112
|
+
connected: 'Connected',
|
|
113
|
+
'sign-in': 'Sign in',
|
|
114
|
+
untested: 'Untested version',
|
|
115
|
+
available: 'Available',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** The status word of a row: Connected · Sign in · Untested version · Unavailable — check <label> · Available. */
|
|
119
|
+
export function agentStateLabel(row) {
|
|
120
|
+
if (row?.state === 'unavailable') return `Unavailable — check ${row.label}`;
|
|
121
|
+
return STATE_WORDS[row?.state] ?? 'Available';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The dot beside the word: ok for connected, warn for what needs the person, off for the rest. */
|
|
125
|
+
export function agentStateSw(state) {
|
|
126
|
+
if (state === 'connected') return 'ok';
|
|
127
|
+
if (state === 'sign-in' || state === 'untested') return 'warn';
|
|
128
|
+
return 'off';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The one action of a row: connect · signin · disconnect · null (nothing Maude can do from here). */
|
|
132
|
+
export function agentRowAction(row) {
|
|
133
|
+
if (!row) return null;
|
|
134
|
+
if (row.state === 'sign-in') return 'signin';
|
|
135
|
+
if (row.connected) return 'disconnect';
|
|
136
|
+
if (row.state === 'available') return 'connect';
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The card's rows: installed agents only, Claude left out (it has its own card). `main` are the agents
|
|
142
|
+
* Maude holds to its limits; `advanced` are the unrestricted ones, behind the folded Advanced part.
|
|
143
|
+
* @returns {{ main: object[], advanced: object[] }}
|
|
144
|
+
*/
|
|
145
|
+
export function agentRows(agents = []) {
|
|
146
|
+
const rows = agents
|
|
147
|
+
.filter((a) => a.id !== CLAUDE_ID && a.installed)
|
|
148
|
+
.map((a) => ({
|
|
149
|
+
id: a.id,
|
|
150
|
+
label: a.label,
|
|
151
|
+
vendor: a.vendor,
|
|
152
|
+
state: a.state,
|
|
153
|
+
connected: a.connected,
|
|
154
|
+
unrestricted: a.policy === 'unrestricted',
|
|
155
|
+
connectNote: typeof a.connectNote === 'string' && a.connectNote ? a.connectNote : null,
|
|
156
|
+
word: agentStateLabel(a),
|
|
157
|
+
sw: agentStateSw(a.state),
|
|
158
|
+
action: agentRowAction(a),
|
|
159
|
+
}));
|
|
160
|
+
return {
|
|
161
|
+
main: rows.filter((r) => !r.unrestricted),
|
|
162
|
+
advanced: rows.filter((r) => r.unrestricted),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Is the AI agents card drawn at all? Settings' reference list is always there once the list has
|
|
168
|
+
* loaded (plan Design Decision 2), so a Mac with only Claude still reaches the Advanced fold (an
|
|
169
|
+
* own API key for Claude). Only the AI panel stays unchanged for Claude-only users.
|
|
170
|
+
*/
|
|
171
|
+
export function agentsCardVisible(agents = []) {
|
|
172
|
+
return agents.length > 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The closed card's line: "Codex connected" · "Codex and opencode on this Mac". */
|
|
176
|
+
export function agentsCardSummary(agents = []) {
|
|
177
|
+
const { main, advanced } = agentRows(agents);
|
|
178
|
+
const all = [...main, ...advanced];
|
|
179
|
+
const on = all.filter((r) => r.connected).map((r) => r.label);
|
|
180
|
+
if (on.length) return `${andList(on)} connected`;
|
|
181
|
+
if (!all.length) return 'No other AI agents on this Mac';
|
|
182
|
+
return `${andList(all.map((r) => r.label))} on this Mac`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The consent card's words for an unrestricted agent. */
|
|
186
|
+
export function consentWords(label) {
|
|
187
|
+
return `${label} runs without Maude’s file and network limits. Allow it for this project?`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A connect that did not go through, in words. */
|
|
191
|
+
export function connectFailWords(r, label = 'This agent') {
|
|
192
|
+
switch (r?.reason) {
|
|
193
|
+
case 'not-installed':
|
|
194
|
+
return `${label} is not on this Mac any more.`;
|
|
195
|
+
case 'version-too-old':
|
|
196
|
+
return `This version of ${label} is too old. Update it, then try again.`;
|
|
197
|
+
case 'untested-version':
|
|
198
|
+
return `Maude has not tested this version of ${label} yet.`;
|
|
199
|
+
case 'consent-required':
|
|
200
|
+
return `${label} needs your yes before it can run.`;
|
|
201
|
+
case 'conformance-failed':
|
|
202
|
+
return r.detail || `${label} did not stay inside Maude’s limits, so it was not connected.`;
|
|
203
|
+
case 'timeout':
|
|
204
|
+
return `The sign-in to ${label} did not finish. Try again.`;
|
|
205
|
+
case 'signin-failed':
|
|
206
|
+
return r.detail || `Could not start the sign-in to ${label}.`;
|
|
207
|
+
default:
|
|
208
|
+
return r?.detail || `Could not connect ${label}. Try again.`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ── which agent a chat is on ────────────────────────────────────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
function storage(store) {
|
|
215
|
+
if (store !== undefined) return store;
|
|
216
|
+
try {
|
|
217
|
+
return typeof localStorage !== 'undefined' ? localStorage : null;
|
|
218
|
+
} catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function readMap(key, store) {
|
|
223
|
+
try {
|
|
224
|
+
const v = JSON.parse(storage(store)?.getItem(key) ?? 'null');
|
|
225
|
+
return isObj(v) ? v : {};
|
|
226
|
+
} catch {
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function writeMap(key, map, store) {
|
|
231
|
+
try {
|
|
232
|
+
storage(store)?.setItem(key, JSON.stringify(map));
|
|
233
|
+
} catch {
|
|
234
|
+
/* private mode, storage full: not remembered, nothing breaks */
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function readLastAgent(profileId = 'default', store) {
|
|
239
|
+
const v = readMap(LAST_AGENT_KEY, store)[profileId || 'default'];
|
|
240
|
+
return typeof v === 'string' && v ? v : null;
|
|
241
|
+
}
|
|
242
|
+
export function writeLastAgent(profileId = 'default', agentId, store) {
|
|
243
|
+
if (!agentId) return;
|
|
244
|
+
writeMap(
|
|
245
|
+
LAST_AGENT_KEY,
|
|
246
|
+
{ ...readMap(LAST_AGENT_KEY, store), [profileId || 'default']: agentId },
|
|
247
|
+
store
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The agent a chat started with; a chat Maude never recorded is Claude's (every chat before B6 is). */
|
|
252
|
+
export function readChatAgent(chatId, store) {
|
|
253
|
+
if (!chatId) return null;
|
|
254
|
+
const v = readMap(CHAT_AGENT_KEY, store)[chatId];
|
|
255
|
+
return typeof v === 'string' && v ? v : null;
|
|
256
|
+
}
|
|
257
|
+
export function writeChatAgent(chatId, agentId, store) {
|
|
258
|
+
if (!chatId || !agentId) return;
|
|
259
|
+
const map = readMap(CHAT_AGENT_KEY, store);
|
|
260
|
+
delete map[chatId];
|
|
261
|
+
map[chatId] = agentId;
|
|
262
|
+
const keys = Object.keys(map);
|
|
263
|
+
for (const k of keys.slice(0, Math.max(0, keys.length - CHAT_AGENT_CAP))) delete map[k];
|
|
264
|
+
writeMap(CHAT_AGENT_KEY, map, store);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ── attribution (Design Decision 5) ─────────────────────────────────────────────────────────────────
|
|
268
|
+
|
|
269
|
+
/** The `{ id, label, vendor, statusUrl? }` a frame carries, or null. */
|
|
270
|
+
export function frameAgent(v) {
|
|
271
|
+
if (!isObj(v) || typeof v.id !== 'string' || !v.id) return null;
|
|
272
|
+
return {
|
|
273
|
+
id: v.id,
|
|
274
|
+
label: str(v.label) || v.id,
|
|
275
|
+
vendor: str(v.vendor),
|
|
276
|
+
...(typeof v.statusUrl === 'string' && /^https:\/\//.test(v.statusUrl)
|
|
277
|
+
? { statusUrl: v.statusUrl }
|
|
278
|
+
: {}),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The small vendor badge on a reply: only for an agent other than Claude. */
|
|
283
|
+
export function agentBadge(agent) {
|
|
284
|
+
const a = frameAgent(agent);
|
|
285
|
+
if (!a || a.id === CLAUDE_ID) return null;
|
|
286
|
+
return {
|
|
287
|
+
label: a.label,
|
|
288
|
+
vendor: a.vendor,
|
|
289
|
+
title: a.vendor ? `${a.label} by ${a.vendor}` : a.label,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* A turn error that came from an agent other than Claude, in words (`error` = `{ message, code?, agent? }`).
|
|
295
|
+
* null: not an agent's (the ordinary error card shows it).
|
|
296
|
+
* @returns {{ kind: 'stopped'|'consent'|'reported', text: string, agent: object, statusUrl?: string } | null}
|
|
297
|
+
*/
|
|
298
|
+
export function agentErrorModel(error) {
|
|
299
|
+
const agent = frameAgent(error?.agent);
|
|
300
|
+
if (!agent) return null;
|
|
301
|
+
if (error.code === 'agent-policy-violated')
|
|
302
|
+
return {
|
|
303
|
+
kind: 'stopped',
|
|
304
|
+
agent,
|
|
305
|
+
text: `${agent.label} was stopped: it did not stay inside Maude’s limits.`,
|
|
306
|
+
};
|
|
307
|
+
if (error.code === 'agent-needs-consent')
|
|
308
|
+
return { kind: 'consent', agent, text: consentWords(agent.label) };
|
|
309
|
+
// security review 2026-11-12 (M4) — Maude refused to start it: its own words, never "reported"
|
|
310
|
+
if (error.code === 'agent-not-connected')
|
|
311
|
+
return {
|
|
312
|
+
kind: 'not-connected',
|
|
313
|
+
agent,
|
|
314
|
+
text: `${agent.label} isn’t connected at the version on this Mac. Connect it in Settings › Connections › AI agents.`,
|
|
315
|
+
};
|
|
316
|
+
if (agent.id === CLAUDE_ID) return null;
|
|
317
|
+
const said = str(error.message).trim() || 'something went wrong.';
|
|
318
|
+
return {
|
|
319
|
+
kind: 'reported',
|
|
320
|
+
agent,
|
|
321
|
+
text: `${agent.label} reported: ${said}`,
|
|
322
|
+
...(agent.statusUrl ? { statusUrl: agent.statusUrl } : {}),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A turn that ended `reason: 'refused'`: its notice as one quiet line (never an error card). */
|
|
327
|
+
export function refusedNotice(frame) {
|
|
328
|
+
if (frame?.t !== 'turn-end' || frame.reason !== 'refused') return null;
|
|
329
|
+
const agent = frameAgent(frame.agent);
|
|
330
|
+
const notice = str(frame.notice).trim();
|
|
331
|
+
if (notice) return notice;
|
|
332
|
+
return agent ? `${agent.label} stopped: Maude refused what it asked to do.` : null;
|
|
333
|
+
}
|