@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,230 @@
|
|
|
1
|
+
// S3 (universal-ACP security review, defender H1) — no agent whose READS are judged by its own
|
|
2
|
+
// permission engine starts in a folder that holds a link out of it.
|
|
3
|
+
//
|
|
4
|
+
// Measured (S1, contract note "Security fixes S1"): opencode 1.18.30's `read` tool follows an
|
|
5
|
+
// in-project symlink, committed or not, to a file outside every root and returns it with no card.
|
|
6
|
+
// Its permission engine judges the path it is GIVEN, never the real one. Gemini and Copilot judge
|
|
7
|
+
// reads the same way (`readGate: 'agent-permission-engine'`). Codex is unaffected: its OS sandbox
|
|
8
|
+
// (Seatbelt) resolves the link before it judges (`readGate: 'os-sandbox'`).
|
|
9
|
+
//
|
|
10
|
+
// Decision (lead, fail closed): such an agent does not start while any root it is given (every
|
|
11
|
+
// write root and read root) holds a symlink whose real target lies outside the read roots or inside
|
|
12
|
+
// a credential path. The walk never follows a link and skips nothing; what it cannot finish (too
|
|
13
|
+
// many entries, too slow, a folder it cannot read, a link loop) also refuses, each with its own
|
|
14
|
+
// words. A dangling link is ignored: it leads nowhere today.
|
|
15
|
+
//
|
|
16
|
+
// Residual (named): a link that appears mid-session (the person's own `ln -s`, an approved shell
|
|
17
|
+
// command, a `git pull` they ran) is not seen until the next spawn; a HARD link is the file itself
|
|
18
|
+
// and cannot be told from one (a clone never carries one; making one needs the shell card).
|
|
19
|
+
|
|
20
|
+
import { type Dirent, readdirSync, realpathSync } from 'node:fs';
|
|
21
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
22
|
+
|
|
23
|
+
import type { CredentialPaths } from '../may-scope.ts';
|
|
24
|
+
import { isInsideRoot } from '../write-scope.ts';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Default caps: a project past them is refused as "too large to check" (fail closed). Measured
|
|
28
|
+
* 2026-11-12 (M-series, warm cache): ≈1.8 µs per entry (42k entries in 77 ms), so 250k entries is
|
|
29
|
+
* ≈0.5 s and the time cap only bites on a slow or cold disk. The read roots include Maude's own
|
|
30
|
+
* studio folder (≈42k entries in a source checkout, few in the app), so the cap is shared with it.
|
|
31
|
+
*/
|
|
32
|
+
export const LINK_SCAN_MAX_ENTRIES = 250_000;
|
|
33
|
+
export const LINK_SCAN_MAX_MS = 2_000;
|
|
34
|
+
|
|
35
|
+
export type LinkScanReason = 'escape' | 'credential' | 'loop' | 'unreadable' | 'too-large';
|
|
36
|
+
|
|
37
|
+
export type LinkScanResult =
|
|
38
|
+
| { ok: true; entries: number }
|
|
39
|
+
| {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: LinkScanReason;
|
|
42
|
+
/** The link (escape / credential / loop) or the folder (unreadable) it stopped at. */
|
|
43
|
+
path?: string;
|
|
44
|
+
/** Where an escaping link leads (its real path). */
|
|
45
|
+
target?: string;
|
|
46
|
+
entries: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface LinkScanInput {
|
|
50
|
+
/** Every root the agent is given: write roots and read roots (duplicates and nesting are fine). */
|
|
51
|
+
roots: readonly string[];
|
|
52
|
+
/** What a link may lead into. */
|
|
53
|
+
readRoots: readonly string[];
|
|
54
|
+
credentialPaths: CredentialPaths;
|
|
55
|
+
maxEntries?: number;
|
|
56
|
+
maxMs?: number;
|
|
57
|
+
/** Monotonic clock in ms (tests). */
|
|
58
|
+
now?: () => number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const errCode = (e: unknown) => (e as NodeJS.ErrnoException | null)?.code ?? '';
|
|
62
|
+
|
|
63
|
+
function realOrNull(p: string): string | null {
|
|
64
|
+
try {
|
|
65
|
+
return realpathSync.native(p);
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Inside or equal — a link to a root itself stays inside it. */
|
|
72
|
+
const within = (target: string, root: string) => target === root || isInsideRoot(target, root);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Each credential path as given AND as its real path (`/var` → `/private/var`), case-folded like
|
|
76
|
+
* `isProtectedInProject`: macOS's default disk is case-insensitive, so `~/.SSH` is `~/.ssh`. The
|
|
77
|
+
* fold only ever ADDS a refusal.
|
|
78
|
+
*/
|
|
79
|
+
function foldedCredentials(cred: CredentialPaths): { dirs: string[]; files: string[] } {
|
|
80
|
+
const both = (list: readonly string[]) => {
|
|
81
|
+
const out = new Set<string>();
|
|
82
|
+
for (const p of list) {
|
|
83
|
+
if (!isAbsolute(p)) continue;
|
|
84
|
+
out.add(resolve(p).toLowerCase());
|
|
85
|
+
const real = realOrNull(p);
|
|
86
|
+
if (real) out.add(real.toLowerCase());
|
|
87
|
+
}
|
|
88
|
+
return [...out];
|
|
89
|
+
};
|
|
90
|
+
return { dirs: both(cred.dirs), files: both(cred.files) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function inCredentials(target: string, cred: { dirs: string[]; files: string[] }): boolean {
|
|
94
|
+
const t = target.toLowerCase();
|
|
95
|
+
return cred.dirs.some((d) => within(t, d)) || cred.files.includes(t);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Walk every root without following a link; the first unsafe link (or an unfinished walk) wins. */
|
|
99
|
+
export function scanLinks(input: LinkScanInput): LinkScanResult {
|
|
100
|
+
const maxEntries = input.maxEntries ?? LINK_SCAN_MAX_ENTRIES;
|
|
101
|
+
const maxMs = input.maxMs ?? LINK_SCAN_MAX_MS;
|
|
102
|
+
const now = input.now ?? (() => performance.now());
|
|
103
|
+
const started = now();
|
|
104
|
+
let entries = 0;
|
|
105
|
+
const credentials = foldedCredentials(input.credentialPaths);
|
|
106
|
+
|
|
107
|
+
// What a link may lead into: each read root as given AND as its real path (`/var` → `/private/var`).
|
|
108
|
+
const allowed = new Set<string>();
|
|
109
|
+
for (const r of input.readRoots) {
|
|
110
|
+
if (!isAbsolute(r)) continue;
|
|
111
|
+
allowed.add(resolve(r));
|
|
112
|
+
const real = realOrNull(r);
|
|
113
|
+
if (real) allowed.add(real);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// The folders to walk: each root's real path once, a root nested in another walked as part of it.
|
|
117
|
+
const real: string[] = [];
|
|
118
|
+
for (const r of input.roots) {
|
|
119
|
+
if (!isAbsolute(r)) continue;
|
|
120
|
+
let p: string;
|
|
121
|
+
try {
|
|
122
|
+
p = realpathSync.native(r);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
// A root that does not exist holds no link; one we cannot resolve cannot be checked.
|
|
125
|
+
if (errCode(e) === 'ENOENT' || errCode(e) === 'ENOTDIR') continue;
|
|
126
|
+
return { ok: false, reason: 'unreadable', path: resolve(r), entries };
|
|
127
|
+
}
|
|
128
|
+
if (!real.includes(p)) real.push(p);
|
|
129
|
+
}
|
|
130
|
+
real.sort((a, b) => a.length - b.length);
|
|
131
|
+
const walk = real.filter((p, i) => !real.slice(0, i).some((q) => isInsideRoot(p, q)));
|
|
132
|
+
|
|
133
|
+
for (const root of walk) {
|
|
134
|
+
const stack = [root];
|
|
135
|
+
while (stack.length) {
|
|
136
|
+
const dir = stack.pop() as string;
|
|
137
|
+
let list: Dirent[];
|
|
138
|
+
try {
|
|
139
|
+
list = readdirSync(dir, { withFileTypes: true });
|
|
140
|
+
} catch (e) {
|
|
141
|
+
// A root that is a plain file holds no link below it.
|
|
142
|
+
if (dir === root && errCode(e) === 'ENOTDIR') break;
|
|
143
|
+
// Removed while we walked: nothing there to follow.
|
|
144
|
+
if (errCode(e) === 'ENOENT') continue;
|
|
145
|
+
return { ok: false, reason: 'unreadable', path: dir, entries };
|
|
146
|
+
}
|
|
147
|
+
for (const ent of list) {
|
|
148
|
+
entries++;
|
|
149
|
+
if (entries > maxEntries) return { ok: false, reason: 'too-large', entries };
|
|
150
|
+
if ((entries & 511) === 0 && now() - started > maxMs) {
|
|
151
|
+
return { ok: false, reason: 'too-large', entries };
|
|
152
|
+
}
|
|
153
|
+
const p = join(dir, ent.name);
|
|
154
|
+
if (ent.isSymbolicLink()) {
|
|
155
|
+
let target: string;
|
|
156
|
+
try {
|
|
157
|
+
target = realpathSync.native(p);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
const code = errCode(e);
|
|
160
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') continue; // dangling: leads nowhere today
|
|
161
|
+
if (code === 'ELOOP') return { ok: false, reason: 'loop', path: p, entries };
|
|
162
|
+
return { ok: false, reason: 'unreadable', path: p, entries };
|
|
163
|
+
}
|
|
164
|
+
if (inCredentials(target, credentials)) {
|
|
165
|
+
return { ok: false, reason: 'credential', path: p, target, entries };
|
|
166
|
+
}
|
|
167
|
+
if (![...allowed].some((r) => within(target, r))) {
|
|
168
|
+
return { ok: false, reason: 'escape', path: p, target, entries };
|
|
169
|
+
}
|
|
170
|
+
} else if (ent.isDirectory()) {
|
|
171
|
+
stack.push(p);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (now() - started > maxMs) return { ok: false, reason: 'too-large', entries };
|
|
176
|
+
}
|
|
177
|
+
return { ok: true, entries };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The refusal an agent's spawn throws; index.ts sends it as an `agent-unsafe-link` error frame. */
|
|
181
|
+
export class UnsafeLinkError extends Error {
|
|
182
|
+
readonly code = 'agent-unsafe-link';
|
|
183
|
+
constructor(
|
|
184
|
+
message: string,
|
|
185
|
+
readonly reason: LinkScanReason,
|
|
186
|
+
/** The link (or folder) it stopped at, relative to the project when inside it. */
|
|
187
|
+
readonly link: string | null
|
|
188
|
+
) {
|
|
189
|
+
super(message);
|
|
190
|
+
this.name = 'UnsafeLinkError';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Plain words for a refusal (CONTRACT §4 voice: what happened · what to do). */
|
|
195
|
+
export function unsafeLinkWords(
|
|
196
|
+
r: Extract<LinkScanResult, { ok: false }>,
|
|
197
|
+
label: string,
|
|
198
|
+
link: string | null
|
|
199
|
+
): string {
|
|
200
|
+
const head = `Maude did not start ${label} in this project:`;
|
|
201
|
+
switch (r.reason) {
|
|
202
|
+
case 'escape':
|
|
203
|
+
return `${head} the link ${link} leads outside the folders AI may read, and ${label} would read through it without asking. Remove the link, or use Claude or Codex here.`;
|
|
204
|
+
case 'credential':
|
|
205
|
+
return `${head} the link ${link} leads to a place where sign-ins and keys are kept. Remove the link, or use Claude or Codex here.`;
|
|
206
|
+
case 'loop':
|
|
207
|
+
return `${head} the link ${link} points back at itself, so Maude cannot check where it leads. Remove the link, or use Claude or Codex here.`;
|
|
208
|
+
case 'unreadable':
|
|
209
|
+
return `${head} Maude cannot read ${link ?? 'a folder'} to check it for links that lead outside the project. Use Claude or Codex here.`;
|
|
210
|
+
case 'too-large':
|
|
211
|
+
return `${head} the project is too large for Maude to check for links that lead outside it. Use Claude or Codex here.`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Throws `UnsafeLinkError` when the scan fails. `projectRoot` only shortens the link in the words
|
|
217
|
+
* (a path outside it is shown in full).
|
|
218
|
+
*/
|
|
219
|
+
export function assertNoUnsafeLinks(
|
|
220
|
+
input: LinkScanInput & { label: string; projectRoot: string }
|
|
221
|
+
): void {
|
|
222
|
+
const r = scanLinks(input);
|
|
223
|
+
if (r.ok) return;
|
|
224
|
+
let link: string | null = r.path ?? null;
|
|
225
|
+
if (link) {
|
|
226
|
+
const base = realOrNull(input.projectRoot) ?? resolve(input.projectRoot);
|
|
227
|
+
if (isInsideRoot(link, base)) link = relative(base, link);
|
|
228
|
+
}
|
|
229
|
+
throw new UnsafeLinkError(unsafeLinkWords(r, input.label, link), r.reason, link);
|
|
230
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// How the bridge starts one ACP agent from its descriptor (F3 / plan Task B2, contract rule 14).
|
|
2
|
+
// Pure: the bridge resolves the binaries, the scope and the prefs, then asks this ONE function for
|
|
3
|
+
// the argv and the whole child env, so a test can assert exactly what an agent is handed.
|
|
4
|
+
//
|
|
5
|
+
// Claude (policy 'claude-meta') comes out exactly as before the descriptor existed
|
|
6
|
+
// (test/acp-agent-spawn.test.ts pins it): its least-privilege policy rides `_meta.claudeCode`,
|
|
7
|
+
// not the env. Every other agent gets its launch policy's env (and argv for native ACP) plus
|
|
8
|
+
// MAUDE_NO_EGRESS when web is off — it has no `_meta` channel for either.
|
|
9
|
+
//
|
|
10
|
+
// B7 (DDR-252) — the agent's own stored chat key (acp/agents/chat-key.ts) is added AFTER the scrub
|
|
11
|
+
// and the launch policy, for this descriptor only. The one read outside the inputs: when the caller
|
|
12
|
+
// passes no `chatKeyEnv`, it comes from the 0600 key store (generation/keys.ts) at spawn time. A
|
|
13
|
+
// Claude spawn without the Advanced opt-in adds nothing.
|
|
14
|
+
//
|
|
15
|
+
// S3 (defender H1) — the other read outside the inputs: an agent whose reads are judged by its own
|
|
16
|
+
// permission engine (`readGate: 'agent-permission-engine'`: opencode, Gemini, Copilot) is refused
|
|
17
|
+
// (`UnsafeLinkError`, code `agent-unsafe-link`) while any root it is given holds a link out of the
|
|
18
|
+
// read roots (acp/agents/link-scan.ts). A root that does not exist holds no link.
|
|
19
|
+
|
|
20
|
+
import { realpathSync } from 'node:fs';
|
|
21
|
+
import { resolve, sep } from 'node:path';
|
|
22
|
+
|
|
23
|
+
import { DEV_SERVER_ROOT } from '../../paths.ts';
|
|
24
|
+
import { chatSpawnEnv, scrubAgentEnv, teamsSpawnEnv } from '../env.ts';
|
|
25
|
+
import { mayEnv } from '../may-scope.ts';
|
|
26
|
+
import { upToGitRoot } from '../policy/agent-home.ts';
|
|
27
|
+
import { chatKeyEnvFor } from './chat-key.ts';
|
|
28
|
+
import type { AgentDescriptor, PolicyCtx } from './descriptor.ts';
|
|
29
|
+
import { assertNoUnsafeLinks } from './link-scan.ts';
|
|
30
|
+
|
|
31
|
+
/** realpath when it exists (a link must not pass for Maude's own folder), else the resolved path. */
|
|
32
|
+
function realOr(p: string): string {
|
|
33
|
+
try {
|
|
34
|
+
return realpathSync(resolve(p));
|
|
35
|
+
} catch {
|
|
36
|
+
return resolve(p);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The git repository root above `scopeRoot` when it differs from it (none → []). */
|
|
41
|
+
function gitRootAbove(scopeRoot: string): string[] {
|
|
42
|
+
const chain = upToGitRoot(scopeRoot);
|
|
43
|
+
const top = chain[chain.length - 1];
|
|
44
|
+
return top && top !== resolve(scopeRoot) ? [top] : [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Maude's own studio folder (DEV_SERVER_ROOT) or inside it. */
|
|
48
|
+
function isMaudeOwnRoot(r: string): boolean {
|
|
49
|
+
const own = realOr(DEV_SERVER_ROOT);
|
|
50
|
+
const abs = realOr(r);
|
|
51
|
+
return abs === own || abs.startsWith(own.endsWith(sep) ? own : own + sep);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AgentSpawnInput {
|
|
55
|
+
descriptor: AgentDescriptor;
|
|
56
|
+
/**
|
|
57
|
+
* `scrubAgentEnv(process.env, descriptor.envAllow)`. The caller scrubs, so every spawn site
|
|
58
|
+
* visibly goes through the one scrub (acp-env.test.ts pins that).
|
|
59
|
+
*/
|
|
60
|
+
scrubbed: Record<string, string>;
|
|
61
|
+
/** The agent's real binary: `launch.agentBinEnv` for an adapter, argv[0] for native ACP. */
|
|
62
|
+
agentBin: string;
|
|
63
|
+
/** adapter-js only — the bundled adapter's entry script. */
|
|
64
|
+
adapterEntry?: string;
|
|
65
|
+
/** adapter-js only — the JS runtime that runs it (probe.ts `resolveAgentRuntime`). */
|
|
66
|
+
runtime?: { bin: string; bunBeBun: boolean };
|
|
67
|
+
/** The session scope the launch policy is built from. */
|
|
68
|
+
policyCtx: PolicyCtx;
|
|
69
|
+
/** What the chat's `maude design` verbs are held to (the actor env). */
|
|
70
|
+
actor: {
|
|
71
|
+
sessionRoot: string;
|
|
72
|
+
readRoots: readonly string[];
|
|
73
|
+
ownPorts?: readonly number[];
|
|
74
|
+
/** This chat's scratch, when it could be made safely; absent → TMPDIR left as it was. */
|
|
75
|
+
tmpdir?: string | null;
|
|
76
|
+
grantsFile?: string;
|
|
77
|
+
};
|
|
78
|
+
/** Settings › Advanced › teams (Claude only). */
|
|
79
|
+
teams: boolean;
|
|
80
|
+
chatId?: string;
|
|
81
|
+
/** path.delimiter (':' on POSIX) — a parameter so the function stays pure. */
|
|
82
|
+
delimiter: string;
|
|
83
|
+
/**
|
|
84
|
+
* B7 — the env this agent's stored chat key becomes (`chatKeyEnvFor`). Absent → read from the key
|
|
85
|
+
* store now; `{}` → none (tests, and any caller that must not read the store).
|
|
86
|
+
*/
|
|
87
|
+
chatKeyEnv?: Record<string, string>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface AgentSpawn {
|
|
91
|
+
cmd: string[];
|
|
92
|
+
env: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function agentSpawn(input: AgentSpawnInput): AgentSpawn {
|
|
96
|
+
const d = input.descriptor;
|
|
97
|
+
const env: Record<string, string> = { ...input.scrubbed };
|
|
98
|
+
let cmd: string[];
|
|
99
|
+
// S3 — before the launch policy (which reads the person's config): a refused spawn touches nothing.
|
|
100
|
+
if (d.enforcement?.readGate === 'agent-permission-engine') {
|
|
101
|
+
const c = input.policyCtx;
|
|
102
|
+
assertNoUnsafeLinks({
|
|
103
|
+
// Maude's own install folder (a read root for canvas-lib & co.) is app-owned, not the
|
|
104
|
+
// project's: its package-manager links (pnpm in a source checkout) are not an attacker's.
|
|
105
|
+
// Review N1 — these agents treat the whole git repository as the project (opencode's
|
|
106
|
+
// boundary is the git root), so a link in a sibling folder of a subfolder project counts.
|
|
107
|
+
roots: [...c.writeRoots, ...c.readRoots, ...gitRootAbove(c.scopeRoot)].filter(
|
|
108
|
+
(r) => !isMaudeOwnRoot(r)
|
|
109
|
+
),
|
|
110
|
+
readRoots: c.readRoots,
|
|
111
|
+
credentialPaths: c.credentialPaths,
|
|
112
|
+
label: d.label,
|
|
113
|
+
projectRoot: c.scopeRoot,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const policy = d.enforcement?.launchPolicy(input.policyCtx);
|
|
117
|
+
|
|
118
|
+
if (d.launch.kind === 'adapter-js') {
|
|
119
|
+
if (!input.adapterEntry || !input.runtime) {
|
|
120
|
+
throw new Error(`agent ${d.id}: an adapter-js launch needs its adapter entry and runtime`);
|
|
121
|
+
}
|
|
122
|
+
// DDR-123 guardrail #2 (Claude) and its analog for every adapter: pin it to the person's OWN
|
|
123
|
+
// agent binary (CODEX_PATH, CLAUDE_CODE_EXECUTABLE), never a bundled one.
|
|
124
|
+
if (d.launch.agentBinEnv) env[d.launch.agentBinEnv] = input.agentBin;
|
|
125
|
+
// RCA-G1 — our own compiled self behaves as `bun` only with BUN_BE_BUN=1.
|
|
126
|
+
if (input.runtime.bunBeBun) env.BUN_BE_BUN = '1';
|
|
127
|
+
cmd = [input.runtime.bin, input.adapterEntry];
|
|
128
|
+
} else {
|
|
129
|
+
cmd = [input.agentBin, ...d.launch.args, ...(policy?.args ?? [])];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (policy) {
|
|
133
|
+
// The launch policy is Maude's own code, but it never gets to hand the agent a secret the
|
|
134
|
+
// scrub drops (ANTHROPIC_*, MAUDE_SHELL_*, …): its keys go through the same scrub.
|
|
135
|
+
Object.assign(env, scrubAgentEnv(policy.env, Object.keys(policy.env)));
|
|
136
|
+
}
|
|
137
|
+
// B7 — this agent's own key, after the scrub and the policy (neither can drop or forge it), and
|
|
138
|
+
// only the names chatKeyEnvFor allows for THIS descriptor.
|
|
139
|
+
Object.assign(env, input.chatKeyEnv ?? chatKeyEnvFor(d));
|
|
140
|
+
// Claude carries the egress switch in `_meta.claudeCode.options.env` (newSessionParams); an
|
|
141
|
+
// agent without that channel carries it from spawn.
|
|
142
|
+
if (d.policy !== 'claude-meta') Object.assign(env, mayEnv(input.policyCtx.may));
|
|
143
|
+
|
|
144
|
+
// The actor env, last, so nothing above can name another chat's root or ports.
|
|
145
|
+
// V2-2.4b — `maude design hook` tells a Maude chat run from a terminal one by this.
|
|
146
|
+
env.MAUDE_AGENT_ACTOR = 'maude-chat';
|
|
147
|
+
// gate-b-sec2 — the project this chat's maude verbs are held to.
|
|
148
|
+
env.MAUDE_SESSION_ROOT = input.actor.sessionRoot;
|
|
149
|
+
// V2-8.9 H2 — the read boundary for the verbs that read a path they are given.
|
|
150
|
+
env.MAUDE_READ_ROOTS = input.actor.readRoots.join(input.delimiter);
|
|
151
|
+
// V2-8.9 re-check 2 H-a — this session's own server ports; none → unset (helpers refuse all).
|
|
152
|
+
const ports = (input.actor.ownPorts ?? []).filter(
|
|
153
|
+
(p) => Number.isInteger(p) && p > 0 && p < 65536
|
|
154
|
+
);
|
|
155
|
+
if (ports.length) env.MAUDE_OWN_PORTS = [...new Set(ports)].join(',');
|
|
156
|
+
// V2-8.9 M2 — the agent's temp folder is this chat's own scratch.
|
|
157
|
+
if (input.actor.tmpdir) env.TMPDIR = `${input.actor.tmpdir}/`;
|
|
158
|
+
if (input.actor.grantsFile) env.MAUDE_GRANTS_FILE = input.actor.grantsFile;
|
|
159
|
+
|
|
160
|
+
// S11.13 — agent teams are a Claude Code switch; V2-1.15 §5.4 — this chat's id and no other's.
|
|
161
|
+
const withTeams =
|
|
162
|
+
d.policy === 'claude-meta' ? teamsSpawnEnv(env, { experimentalTeams: input.teams }) : env;
|
|
163
|
+
return { cmd, env: chatSpawnEnv(withTeams, input.chatId) };
|
|
164
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// The "connect another agent" state (universal ACP, plan B5/B6, DDR-252): which agents this person
|
|
2
|
+
// has connected to the Studio chat, and which proactive offers they have answered "Not now".
|
|
3
|
+
//
|
|
4
|
+
// { connected: { [id]: { at, version } }, offerDismissed: { [id]: true } }
|
|
5
|
+
//
|
|
6
|
+
// PER PROFILE, OUTSIDE ANY PROJECT. The file lives in the profile's own config folder, next to its
|
|
7
|
+
// cloud.json / hubs.json (`~/.config/maude/agents.json`, or `…/profiles/<id>/agents.json`): the
|
|
8
|
+
// folder `credentialPathsFor` (acp/may-scope.ts) already puts on every chat session's Read deny
|
|
9
|
+
// list, so the agent that is being connected cannot read or rewrite its own consent record, and a
|
|
10
|
+
// project (which a clone or a teammate can plant) cannot pre-connect anything. Mode 0600 in a 0700
|
|
11
|
+
// folder, written atomically (temp file in the same folder → rename).
|
|
12
|
+
//
|
|
13
|
+
// The location is derived from the profile id and HOME/XDG alone, never from `MAUDE_CLOUD_CONFIG`
|
|
14
|
+
// or `HUBS_CONFIG_PATH` (an env pointer could name a folder the deny rules do not cover).
|
|
15
|
+
|
|
16
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { homedir } from 'node:os';
|
|
18
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
19
|
+
|
|
20
|
+
import { PROFILE_ID_RE } from '../../shell/profile.ts';
|
|
21
|
+
|
|
22
|
+
export interface ConnectedRecord {
|
|
23
|
+
/** ms since the epoch the agent passed the connect check. */
|
|
24
|
+
at: number;
|
|
25
|
+
/** The agent version that passed it. */
|
|
26
|
+
version: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AgentState {
|
|
30
|
+
connected: Record<string, ConnectedRecord>;
|
|
31
|
+
offerDismissed: Record<string, true>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Env = Record<string, string | undefined>;
|
|
35
|
+
|
|
36
|
+
const ID_RE = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
|
|
37
|
+
|
|
38
|
+
export const emptyState = (): AgentState => ({ connected: {}, offerDismissed: {} });
|
|
39
|
+
|
|
40
|
+
/** The folder of the profile this process runs as (a sibling of its cloud.json / hubs.json). */
|
|
41
|
+
export function agentStateDir(
|
|
42
|
+
env: Env = process.env,
|
|
43
|
+
home: string = env.HOME || homedir()
|
|
44
|
+
): string {
|
|
45
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
46
|
+
const base = xdg && xdg.length > 0 && isAbsolute(xdg) ? xdg : join(home, '.config');
|
|
47
|
+
const id = env.MAUDE_PROFILE_ID;
|
|
48
|
+
if (id && id !== 'default' && PROFILE_ID_RE.test(id)) return join(base, 'maude', 'profiles', id);
|
|
49
|
+
return join(base, 'maude');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function agentStatePath(env: Env = process.env, home?: string): string {
|
|
53
|
+
return join(agentStateDir(env, home), 'agents.json');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Read a parsed document into the shape; anything else (a hand edit, a future shape) is dropped. */
|
|
57
|
+
function normalise(raw: unknown): AgentState {
|
|
58
|
+
const out = emptyState();
|
|
59
|
+
if (!raw || typeof raw !== 'object') return out;
|
|
60
|
+
const { connected, offerDismissed } = raw as Record<string, unknown>;
|
|
61
|
+
if (connected && typeof connected === 'object') {
|
|
62
|
+
for (const [id, rec] of Object.entries(connected as Record<string, unknown>)) {
|
|
63
|
+
if (!ID_RE.test(id) || !rec || typeof rec !== 'object') continue;
|
|
64
|
+
const { at, version } = rec as { at?: unknown; version?: unknown };
|
|
65
|
+
if (typeof at !== 'number' || !Number.isFinite(at)) continue;
|
|
66
|
+
out.connected[id] = {
|
|
67
|
+
at,
|
|
68
|
+
version: typeof version === 'string' ? version.slice(0, 64) : null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (offerDismissed && typeof offerDismissed === 'object') {
|
|
73
|
+
for (const [id, v] of Object.entries(offerDismissed as Record<string, unknown>)) {
|
|
74
|
+
if (ID_RE.test(id) && v === true) out.offerDismissed[id] = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AgentStateStore {
|
|
81
|
+
readonly path: string;
|
|
82
|
+
/** Always re-reads the file: another tab's server (same profile) may have written it. */
|
|
83
|
+
read(): AgentState;
|
|
84
|
+
markConnected(id: string, version: string | null, at?: number): void;
|
|
85
|
+
disconnect(id: string): void;
|
|
86
|
+
dismissOffer(id: string): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A store over one file. Writes are read-modify-write of the whole document, then atomic. */
|
|
90
|
+
export function createAgentStateStore(path: string = agentStatePath()): AgentStateStore {
|
|
91
|
+
const read = (): AgentState => {
|
|
92
|
+
try {
|
|
93
|
+
if (!existsSync(path)) return emptyState();
|
|
94
|
+
return normalise(JSON.parse(readFileSync(path, 'utf8')));
|
|
95
|
+
} catch {
|
|
96
|
+
return emptyState(); // an unreadable file reads as nothing connected: fail closed
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const write = (state: AgentState): void => {
|
|
100
|
+
const dir = dirname(path);
|
|
101
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
102
|
+
const tmp = join(dir, `.agents.json.${process.pid}.${Date.now()}.tmp`);
|
|
103
|
+
writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
104
|
+
chmodSync(tmp, 0o600);
|
|
105
|
+
renameSync(tmp, path);
|
|
106
|
+
};
|
|
107
|
+
const change = (fn: (s: AgentState) => void): void => {
|
|
108
|
+
const s = read();
|
|
109
|
+
fn(s);
|
|
110
|
+
write(s);
|
|
111
|
+
};
|
|
112
|
+
const checked = (id: string): string => {
|
|
113
|
+
if (!ID_RE.test(id)) throw new Error('invalid agent id');
|
|
114
|
+
return id;
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
path,
|
|
118
|
+
read,
|
|
119
|
+
markConnected: (id, version, at = Date.now()) =>
|
|
120
|
+
change((s) => {
|
|
121
|
+
s.connected[checked(id)] = { at, version };
|
|
122
|
+
}),
|
|
123
|
+
disconnect: (id) =>
|
|
124
|
+
change((s) => {
|
|
125
|
+
delete s.connected[checked(id)];
|
|
126
|
+
}),
|
|
127
|
+
dismissOffer: (id) =>
|
|
128
|
+
change((s) => {
|
|
129
|
+
s.offerDismissed[checked(id)] = true;
|
|
130
|
+
}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -84,11 +84,16 @@ export function createAskQueue(deps: AskQueueDeps) {
|
|
|
84
84
|
const now = deps.now ?? Date.now;
|
|
85
85
|
const project = () => deps.project?.() ?? { id: null, hub: null };
|
|
86
86
|
|
|
87
|
-
/** The gates closed for a chat prompt right now. */
|
|
88
|
-
function closed(): Gate[] {
|
|
87
|
+
/** The gates closed for a chat prompt right now (`agent`: the chat's agent when not Claude). */
|
|
88
|
+
function closed(agent?: string): Gate[] {
|
|
89
89
|
try {
|
|
90
90
|
return closedGates(
|
|
91
|
-
{
|
|
91
|
+
{
|
|
92
|
+
kind: 'ai.prompt',
|
|
93
|
+
project: project(),
|
|
94
|
+
watermark: null,
|
|
95
|
+
payload: { kind: 'ai.prompt', agent },
|
|
96
|
+
},
|
|
92
97
|
deps.gates(),
|
|
93
98
|
[],
|
|
94
99
|
now()
|
|
@@ -117,8 +122,11 @@ export function createAskQueue(deps: AskQueueDeps) {
|
|
|
117
122
|
chatId: string;
|
|
118
123
|
text: string;
|
|
119
124
|
scope: RunScope | null;
|
|
125
|
+
/** the chat's agent id (B3); a non-Claude agent is not held by Claude's sign-in gate */
|
|
126
|
+
agent?: string;
|
|
120
127
|
}): Queued | { refused: string } | null {
|
|
121
|
-
const
|
|
128
|
+
const agent = p.agent && p.agent !== 'claude' ? p.agent : undefined;
|
|
129
|
+
const gates = closed(agent);
|
|
122
130
|
if (!gates.length && !chatHasQueued(p.chatId)) return null;
|
|
123
131
|
const words = gateWords(gates, 'ai.prompt', allowanceTime());
|
|
124
132
|
const r = deps.outbox.enqueue({
|
|
@@ -134,6 +142,7 @@ export function createAskQueue(deps: AskQueueDeps) {
|
|
|
134
142
|
scope: p.scope,
|
|
135
143
|
attachments: [],
|
|
136
144
|
presentation: words?.presentation === 'field' ? 'field' : 'sent',
|
|
145
|
+
...(agent ? { agent } : {}),
|
|
137
146
|
},
|
|
138
147
|
gates,
|
|
139
148
|
allowanceResetsAt: safeFacts()?.allowanceResetsAt ?? null,
|
|
@@ -34,6 +34,12 @@ export interface StudioBriefFacts {
|
|
|
34
34
|
* only. (`/flow:*` is intentionally excluded from the chat for now — 2026-07-03.)
|
|
35
35
|
*/
|
|
36
36
|
commandsAvailable?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* B4 (universal ACP) — the session runs an agent that is not Claude (Codex, opencode …). It has
|
|
39
|
+
* no `/design:*` slash commands; the brief tells it where Maude's commands come from instead.
|
|
40
|
+
* Implies `commandsAvailable: false`.
|
|
41
|
+
*/
|
|
42
|
+
agentCli?: boolean;
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -75,11 +81,12 @@ function safeFact(value: string, max: number): string {
|
|
|
75
81
|
export function buildStudioBrief(facts: StudioBriefFacts): string {
|
|
76
82
|
const dr = safeFact((facts.designRel || '.design').replace(/\/+$/, ''), 80) || '.design';
|
|
77
83
|
const label = safeFact(facts.projectLabel || '', 80) || 'this project';
|
|
84
|
+
const commandsAvailable = facts.commandsAvailable === true && !facts.agentCli;
|
|
78
85
|
// DDR-143 — on the native/desktop path the `/design:*` command family is loaded
|
|
79
86
|
// in this session (auto-injected or already installed), so state that plainly
|
|
80
87
|
// instead of leaving the agent to guess. On the web path stay with the plain
|
|
81
88
|
// line. (`/flow:*` is intentionally left out of the chat for now — 2026-07-03.)
|
|
82
|
-
const slashCommands =
|
|
89
|
+
const slashCommands = commandsAvailable
|
|
83
90
|
? `For small, targeted changes edit the canvas file directly — the live canvas hot-reloads on save. The \`/design:*\` slash commands (edit, new, critic, screenshot, draw) are available in this session — no install needed; they run full multi-step workflows (dev-server checks, screenshots, critic passes), so reach for them only when the user explicitly asks for that depth. Runtime helpers: \`maude design <verb>\`.`
|
|
84
91
|
: `For small, targeted changes edit the canvas file directly — the live canvas hot-reloads on save. The \`/design:*\` slash commands (edit, new, critic, screenshot, draw) run full multi-step workflows (dev-server checks, screenshots, critic passes); reach for them only when the user explicitly asks for that depth. Runtime helpers: \`maude design <verb>\`.`;
|
|
85
92
|
// S12.3 — the studio's own verbs, named so the agent drives the product through
|
|
@@ -91,7 +98,7 @@ export function buildStudioBrief(facts: StudioBriefFacts): string {
|
|
|
91
98
|
// "annotations"; `/design:board` is only the command's name (S12-slices D4).
|
|
92
99
|
// The command claim rides only when it is in this session's catalogue
|
|
93
100
|
// (commandsAvailable, DDR-143 plugin auto-load).
|
|
94
|
-
const annotationsFact =
|
|
101
|
+
const annotationsFact = commandsAvailable
|
|
95
102
|
? `Each canvas also has annotations — sticky notes, shapes, arrows, sections and Stickers drawn over the artboards. \`/design:board\` reads them, answers or adds to them, or lays a whole template out on the canvas (retro, kanban, content calendar, roadmap, brainstorm, checklist, user flow) from a plain request like "make me a sprint retro" or "vytvoř mi kanban".`
|
|
96
103
|
: `Each canvas also has annotations — sticky notes, shapes, arrows, sections and Stickers drawn over the artboards.`;
|
|
97
104
|
// S12.3 — capability facts the studio enforces (CONTRACT §7 One AI per
|
|
@@ -101,7 +108,7 @@ export function buildStudioBrief(facts: StudioBriefFacts): string {
|
|
|
101
108
|
// S12.3 — the two skills that carry the studio's map and its voice (D13:
|
|
102
109
|
// contract-voice is for the AI's own messages and Maude's own fields, not the
|
|
103
110
|
// user's canvases). Only claimed where the plugin is loaded.
|
|
104
|
-
const skillsFact =
|
|
111
|
+
const skillsFact = commandsAvailable
|
|
105
112
|
? `The \`studio-actions\` skill maps every studio capability to its file or \`maude design\` verb. The \`contract-voice\` skill sets the words for your replies in the AI chat panel and for text written into Maude's own fields (comments, version names, chat titles) — not for the user's canvases.`
|
|
106
113
|
: null;
|
|
107
114
|
return [
|
|
@@ -112,6 +119,12 @@ export function buildStudioBrief(facts: StudioBriefFacts): string {
|
|
|
112
119
|
annotationsFact,
|
|
113
120
|
runFacts,
|
|
114
121
|
...(skillsFact ? [skillsFact] : []),
|
|
122
|
+
// B4 — a non-Claude agent has no slash commands and no plugin: its Maude commands are the CLI.
|
|
123
|
+
...(facts.agentCli
|
|
124
|
+
? [
|
|
125
|
+
`Maude commands come from the \`maude design <verb>\` CLI, run in your shell (\`maude design help\` lists them); the \`/design:*\` slash commands are not available to you.`,
|
|
126
|
+
]
|
|
127
|
+
: []),
|
|
115
128
|
// DDR-185 — a raw `curl` still pauses for approval every time. Since V2-2.8
|
|
116
129
|
// S4, `curl-local` does too (only auto-tier `maude design <verb>` calls run
|
|
117
130
|
// immediately — actions/verbs.ts); it still refuses non-loopback hosts. This
|