@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.
- 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/annotations-layer.tsx +8 -0
- package/apps/studio/bin/_capture-init.js +5 -0
- package/apps/studio/bin/screenshot.sh +7 -1
- package/apps/studio/bridge/dgn-protocol.ts +3 -2
- package/apps/studio/canvas-shell.tsx +54 -0
- package/apps/studio/client/panels/ChatPanel.jsx +19 -4
- package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
- package/apps/studio/client/panels/SyncConsentDialog.jsx +4 -1
- 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/empty/empty-host.jsx +11 -2
- package/apps/studio/client/v2/empty/use-empty-canvas.js +22 -7
- package/apps/studio/client/v2/fold/fold-store.js +1 -0
- package/apps/studio/client/v2/preview/preview-chrome-host.jsx +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/client/v2/undo/zoom-undo.jsx +19 -2
- package/apps/studio/cloud-build.ts +5 -0
- package/apps/studio/comments/reveal.ts +13 -0
- package/apps/studio/comments-overlay.tsx +36 -0
- package/apps/studio/dist/client.bundle.js +535 -535
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/editing/annotation-count.ts +25 -0
- package/apps/studio/editing/empty-report.ts +8 -3
- package/apps/studio/editing/empty-reporter.tsx +10 -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/index.ts +9 -1
- package/apps/studio/sync/writer-registry.ts +12 -0
- package/apps/studio/whats-new.json +19 -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,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
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// client/v2/ai/agents-store.js — universal ACP B6: the one `/_api/agents` list every surface reads (the offer
|
|
2
|
+
// line, the composer's agent chip, the Connect sheet's link, Settings › Connections › AI agents), and the
|
|
3
|
+
// verbs that change it (connect · sign in · disconnect · Not now).
|
|
4
|
+
//
|
|
5
|
+
// One module-level snapshot, so the panel and Settings never disagree; each write reads the list again.
|
|
6
|
+
// `servedFetch` (#204): a cell, or an older server without the route (404), reads as "no agents", which is
|
|
7
|
+
// exactly the Claude-only picture: nothing new is drawn.
|
|
8
|
+
//
|
|
9
|
+
// connectAgentFlow({ id, consent, fetchImpl, sleep, now, signal, onPhase }) → { ok } | { ok:false, reason, detail? }
|
|
10
|
+
//
|
|
11
|
+
// Phases: 'connecting' · 'waiting' (for the vendor's own sign-in in the browser). Cancel = abort the signal
|
|
12
|
+
// (the sign-in is withdrawn). Pure of React so the tests drive it with a scripted fetch.
|
|
13
|
+
|
|
14
|
+
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
15
|
+
import { servedFetch } from '../shell/served-routes.js';
|
|
16
|
+
import { connectFailWords, normalizeAgents } from './agents-model.js';
|
|
17
|
+
|
|
18
|
+
const SIGNIN_POLL_MS = 2000;
|
|
19
|
+
const SIGNIN_MAX_MS = 180_000;
|
|
20
|
+
|
|
21
|
+
const EMPTY = Object.freeze({ agents: [], offerAgents: [], loaded: false });
|
|
22
|
+
let snap = EMPTY;
|
|
23
|
+
const subs = new Set();
|
|
24
|
+
let inflight = null;
|
|
25
|
+
|
|
26
|
+
function emit() {
|
|
27
|
+
for (const fn of subs) fn();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function subscribeAgents(fn) {
|
|
31
|
+
subs.add(fn);
|
|
32
|
+
return () => subs.delete(fn);
|
|
33
|
+
}
|
|
34
|
+
export const agentsSnapshot = () => snap;
|
|
35
|
+
|
|
36
|
+
/** Tests only: put a list in place (or reset with no argument). */
|
|
37
|
+
export function setAgentsForTest(body) {
|
|
38
|
+
snap = body ? { ...normalizeAgents(body), loaded: true } : EMPTY;
|
|
39
|
+
inflight = null;
|
|
40
|
+
emit();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Read the list (once at a time); `force` asks the server to look on disk again. */
|
|
44
|
+
export function loadAgents({ force = false, fetchImpl } = {}) {
|
|
45
|
+
if (inflight && !force) return inflight;
|
|
46
|
+
const url = force ? '/_api/agents?refresh=1' : '/_api/agents';
|
|
47
|
+
const run = servedFetch(url, { cache: 'no-store' }, fetchImpl ?? ((...a) => fetch(...a)))
|
|
48
|
+
.then(async (res) => (res?.ok ? res.json() : null))
|
|
49
|
+
.catch(() => null)
|
|
50
|
+
.then((body) => {
|
|
51
|
+
snap = { ...normalizeAgents(body), loaded: true };
|
|
52
|
+
emit();
|
|
53
|
+
return snap;
|
|
54
|
+
})
|
|
55
|
+
.finally(() => {
|
|
56
|
+
if (inflight === run) inflight = null;
|
|
57
|
+
});
|
|
58
|
+
inflight = run;
|
|
59
|
+
return run;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The profile this project talks as (`/_config.profile.id`): the last-used agent is remembered per profile.
|
|
63
|
+
let profileId = null;
|
|
64
|
+
let profileAsk = null;
|
|
65
|
+
export function loadProfileId(fetchImpl = (...a) => fetch(...a)) {
|
|
66
|
+
if (profileId) return Promise.resolve(profileId);
|
|
67
|
+
profileAsk ??= fetchImpl('/_config', { cache: 'no-store', credentials: 'same-origin' })
|
|
68
|
+
.then((r) => (r?.ok ? r.json() : null))
|
|
69
|
+
.catch(() => null)
|
|
70
|
+
.then((cfg) => {
|
|
71
|
+
const id = cfg?.profile?.id;
|
|
72
|
+
profileId = typeof id === 'string' && /^[a-z0-9-]{1,32}$/.test(id) ? id : 'default';
|
|
73
|
+
return profileId;
|
|
74
|
+
});
|
|
75
|
+
return profileAsk;
|
|
76
|
+
}
|
|
77
|
+
export const currentProfileId = () => profileId ?? 'default';
|
|
78
|
+
|
|
79
|
+
/** The list, read once on first use. */
|
|
80
|
+
export function useAgents() {
|
|
81
|
+
const s = useSyncExternalStore(subscribeAgents, agentsSnapshot, agentsSnapshot);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!snap.loaded) void loadAgents();
|
|
84
|
+
}, []);
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const enc = (id) => encodeURIComponent(id);
|
|
89
|
+
const json = (res) => (res?.json ? res.json().catch(() => null) : null);
|
|
90
|
+
|
|
91
|
+
function post(fetchImpl, url, body) {
|
|
92
|
+
return fetchImpl(url, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
...(body
|
|
95
|
+
? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }
|
|
96
|
+
: {}),
|
|
97
|
+
})
|
|
98
|
+
.then(json)
|
|
99
|
+
.catch(() => null);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** "Not now" on the offer: permanent, for every agent the line named. */
|
|
103
|
+
export async function dismissAgentOffers(ids, { fetchImpl = (...a) => fetch(...a) } = {}) {
|
|
104
|
+
await Promise.all(
|
|
105
|
+
(ids ?? []).map((id) => post(fetchImpl, `/_api/agents/${enc(id)}/dismiss-offer`))
|
|
106
|
+
);
|
|
107
|
+
await loadAgents({ fetchImpl });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function disconnectAgent(id, { fetchImpl = (...a) => fetch(...a) } = {}) {
|
|
111
|
+
const r = await post(fetchImpl, `/_api/agents/${enc(id)}/disconnect`);
|
|
112
|
+
await loadAgents({ fetchImpl });
|
|
113
|
+
return r ?? { ok: false };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Start the vendor's own sign-in, then wait for it (or for Cancel). */
|
|
117
|
+
async function signIn({ id, fetchImpl, sleep, now, signal, onPhase }) {
|
|
118
|
+
const started = await post(fetchImpl, `/_api/agents/${enc(id)}/signin`);
|
|
119
|
+
if (!started?.ok) return { ok: false, reason: 'signin-failed' };
|
|
120
|
+
onPhase('waiting');
|
|
121
|
+
const deadline = now() + SIGNIN_MAX_MS;
|
|
122
|
+
for (;;) {
|
|
123
|
+
if (signal?.aborted) {
|
|
124
|
+
await post(fetchImpl, `/_api/agents/${enc(id)}/signin-cancel`);
|
|
125
|
+
return { ok: false, reason: 'cancelled' };
|
|
126
|
+
}
|
|
127
|
+
if (now() > deadline) {
|
|
128
|
+
await post(fetchImpl, `/_api/agents/${enc(id)}/signin-cancel`);
|
|
129
|
+
return { ok: false, reason: 'timeout' };
|
|
130
|
+
}
|
|
131
|
+
const st = await fetchImpl(`/_api/agents/${enc(id)}/signin-status`)
|
|
132
|
+
.then(json)
|
|
133
|
+
.catch(() => null);
|
|
134
|
+
if (st?.auth === 'signed-in' || st?.auth === 'not-needed') return { ok: true };
|
|
135
|
+
// the vendor's login exited without signing in (a closed browser tab, a refused login)
|
|
136
|
+
if (st && st.inFlight === false && typeof st.lastExit === 'number' && st.lastExit !== 0)
|
|
137
|
+
return { ok: false, reason: 'signin-failed' };
|
|
138
|
+
await sleep(SIGNIN_POLL_MS);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Connect one agent: register it, and when its vendor needs a sign-in first, run that sign-in and connect
|
|
144
|
+
* again. It does not change the default agent, open a session or widen any permission (Design Decision 1).
|
|
145
|
+
*/
|
|
146
|
+
export async function connectAgentFlow({
|
|
147
|
+
id,
|
|
148
|
+
consent = false,
|
|
149
|
+
signinFirst = false,
|
|
150
|
+
fetchImpl = (...a) => fetch(...a),
|
|
151
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
152
|
+
now = () => Date.now(),
|
|
153
|
+
signal,
|
|
154
|
+
onPhase = () => {},
|
|
155
|
+
} = {}) {
|
|
156
|
+
const deps = { id, fetchImpl, sleep, now, signal, onPhase };
|
|
157
|
+
const connect = () =>
|
|
158
|
+
post(fetchImpl, `/_api/agents/${enc(id)}/connect`, consent ? { consent: true } : undefined);
|
|
159
|
+
let r;
|
|
160
|
+
if (signinFirst) {
|
|
161
|
+
const s = await signIn(deps);
|
|
162
|
+
if (!s.ok) return s;
|
|
163
|
+
}
|
|
164
|
+
onPhase('connecting');
|
|
165
|
+
r = await connect();
|
|
166
|
+
if (r?.needsSignin) {
|
|
167
|
+
const s = await signIn(deps);
|
|
168
|
+
if (!s.ok) {
|
|
169
|
+
await loadAgents({ fetchImpl });
|
|
170
|
+
return s;
|
|
171
|
+
}
|
|
172
|
+
onPhase('connecting');
|
|
173
|
+
r = await connect();
|
|
174
|
+
}
|
|
175
|
+
await loadAgents({ fetchImpl });
|
|
176
|
+
if (r?.ok) return { ok: true };
|
|
177
|
+
return { ok: false, reason: r?.reason ?? 'unknown', ...(r?.detail ? { detail: r.detail } : {}) };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* One connect at a time, with its progress and Cancel: what the offer line and the Settings card share.
|
|
182
|
+
* `phase` = 'idle' · 'connecting' · 'waiting'; `busyId` = the agent being connected; `error` = words.
|
|
183
|
+
* @param deps test seam: `fetchImpl`, `sleep`, `now`
|
|
184
|
+
*/
|
|
185
|
+
export function useAgentConnect(deps = {}) {
|
|
186
|
+
const [state, setState] = useState({ phase: 'idle', busyId: null, error: null, errorId: null });
|
|
187
|
+
const ctl = useRef(null);
|
|
188
|
+
const depsRef = useRef(deps);
|
|
189
|
+
depsRef.current = deps;
|
|
190
|
+
useEffect(() => () => ctl.current?.abort(), []);
|
|
191
|
+
const connect = useCallback(async (row, opts = {}) => {
|
|
192
|
+
if (!row?.id || ctl.current) return false;
|
|
193
|
+
const abort = new AbortController();
|
|
194
|
+
ctl.current = abort;
|
|
195
|
+
setState({ phase: 'connecting', busyId: row.id, error: null, errorId: null });
|
|
196
|
+
const r = await connectAgentFlow({
|
|
197
|
+
...depsRef.current,
|
|
198
|
+
id: row.id,
|
|
199
|
+
consent: opts.consent === true,
|
|
200
|
+
signinFirst: opts.signinFirst === true,
|
|
201
|
+
signal: abort.signal,
|
|
202
|
+
onPhase: (phase) => setState((s) => ({ ...s, phase })),
|
|
203
|
+
});
|
|
204
|
+
if (ctl.current === abort) ctl.current = null;
|
|
205
|
+
const failed = !r.ok && r.reason !== 'cancelled';
|
|
206
|
+
setState({
|
|
207
|
+
phase: 'idle',
|
|
208
|
+
busyId: null,
|
|
209
|
+
error: failed ? connectFailWords(r, row.label) : null,
|
|
210
|
+
errorId: failed ? row.id : null,
|
|
211
|
+
});
|
|
212
|
+
return r.ok;
|
|
213
|
+
}, []);
|
|
214
|
+
const cancel = useCallback(() => ctl.current?.abort(), []);
|
|
215
|
+
return { ...state, connect, cancel };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The progress words of a connect: "Connecting Codex…" · "Sign in to Codex in your browser…". */
|
|
219
|
+
export function connectProgressWords(phase, label) {
|
|
220
|
+
if (phase === 'waiting') return `Sign in to ${label} in your browser…`;
|
|
221
|
+
if (phase === 'connecting') return `Connecting ${label}…`;
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
@@ -246,6 +246,69 @@
|
|
|
246
246
|
line-height: var(--lh-xs);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/* ── Universal ACP B6: another agent on this Mac (agents-model.js). Quiet: the hint's ink, a text link. ── */
|
|
250
|
+
.ai-agent-offer {
|
|
251
|
+
padding: var(--space-1) var(--space-1) 0;
|
|
252
|
+
}
|
|
253
|
+
.ai-agent-offer-t {
|
|
254
|
+
margin: 0;
|
|
255
|
+
color: var(--fg-2);
|
|
256
|
+
font-size: var(--type-sm);
|
|
257
|
+
line-height: var(--lh-sm);
|
|
258
|
+
}
|
|
259
|
+
.maude .ai-agent-link {
|
|
260
|
+
display: inline;
|
|
261
|
+
padding: 0;
|
|
262
|
+
border: 0;
|
|
263
|
+
background: none;
|
|
264
|
+
color: var(--accent);
|
|
265
|
+
font: inherit;
|
|
266
|
+
cursor: pointer;
|
|
267
|
+
}
|
|
268
|
+
.maude .ai-agent-link:hover {
|
|
269
|
+
text-decoration: underline;
|
|
270
|
+
}
|
|
271
|
+
.maude .ai-agent-link:focus-visible {
|
|
272
|
+
outline: 2px solid var(--focus-ring);
|
|
273
|
+
outline-offset: 2px;
|
|
274
|
+
border-radius: var(--radius-sm);
|
|
275
|
+
}
|
|
276
|
+
.maude .ai-agent-link--quiet {
|
|
277
|
+
color: var(--fg-2);
|
|
278
|
+
}
|
|
279
|
+
.ai-agent-sep {
|
|
280
|
+
margin: 0 var(--space-1);
|
|
281
|
+
color: var(--fg-2);
|
|
282
|
+
}
|
|
283
|
+
.ai-agent-note {
|
|
284
|
+
margin: var(--space-1) 0 0;
|
|
285
|
+
color: var(--fg-2);
|
|
286
|
+
font-size: var(--type-xs);
|
|
287
|
+
}
|
|
288
|
+
.ai-agent-note--err {
|
|
289
|
+
color: var(--status-error);
|
|
290
|
+
}
|
|
291
|
+
.ai-agent-badge {
|
|
292
|
+
display: inline-block;
|
|
293
|
+
margin-bottom: var(--space-1);
|
|
294
|
+
color: var(--fg-2);
|
|
295
|
+
font-size: var(--type-xs);
|
|
296
|
+
line-height: var(--lh-xs);
|
|
297
|
+
}
|
|
298
|
+
.maude .ai-agent-chip {
|
|
299
|
+
flex: none;
|
|
300
|
+
max-width: 120px;
|
|
301
|
+
font-size: var(--type-xs);
|
|
302
|
+
line-height: var(--lh-xs);
|
|
303
|
+
}
|
|
304
|
+
.maude .ai-agent-chip--locked {
|
|
305
|
+
color: var(--fg-2);
|
|
306
|
+
}
|
|
307
|
+
.maude .ai-conn-other {
|
|
308
|
+
align-self: flex-start;
|
|
309
|
+
font-size: var(--type-xs);
|
|
310
|
+
}
|
|
311
|
+
|
|
249
312
|
/* ── An answer that touched nothing ── */
|
|
250
313
|
.ai-unchanged {
|
|
251
314
|
margin: var(--space-2) 0 0;
|
|
@@ -105,7 +105,7 @@ function canvasName(path) {
|
|
|
105
105
|
*/
|
|
106
106
|
export function permissionModel(request, work = null) {
|
|
107
107
|
const toolCall = request?.toolCall ?? {};
|
|
108
|
-
const outside = describeOutOfProject(request?.scope);
|
|
108
|
+
const outside = describeOutOfProject(request?.scope, request?.agent);
|
|
109
109
|
const all = Array.isArray(request?.options) ? request.options.filter(Boolean) : [];
|
|
110
110
|
// Decision D is enforced server-side; this second pass only keeps a stale frame from painting a
|
|
111
111
|
// button the server would refuse.
|
|
@@ -53,7 +53,7 @@ export function EmptyHost() {
|
|
|
53
53
|
const native = isNativeApp();
|
|
54
54
|
const canAsk = native && canEdit;
|
|
55
55
|
const [claude] = useClaudeState(canAsk && canvasOpen);
|
|
56
|
-
const { lane, count, hint } = useEmptyLane({
|
|
56
|
+
const { lane, count, annotations, hint } = useEmptyLane({
|
|
57
57
|
activePath,
|
|
58
58
|
iframesRef,
|
|
59
59
|
canvasOrigin: cfg?.canvasOrigin,
|
|
@@ -66,7 +66,16 @@ export function EmptyHost() {
|
|
|
66
66
|
if (loadingPath) lane.loadStarted(loadingPath);
|
|
67
67
|
}, [lane, loadingPath]);
|
|
68
68
|
const model = canvasOpen
|
|
69
|
-
? emptyCanvasModel({
|
|
69
|
+
? emptyCanvasModel({
|
|
70
|
+
count,
|
|
71
|
+
annotations,
|
|
72
|
+
mode,
|
|
73
|
+
canEdit,
|
|
74
|
+
online,
|
|
75
|
+
claude,
|
|
76
|
+
canAsk,
|
|
77
|
+
loading: canvasLoading,
|
|
78
|
+
})
|
|
70
79
|
: null;
|
|
71
80
|
// rc3-h (#182): a run of yours on this empty canvas — the ghost where the first artboard lands, not the invitation
|
|
72
81
|
const { view: runsView } = useAiRuns();
|