@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
|
@@ -182,7 +182,9 @@ interface ToolCallLike {
|
|
|
182
182
|
const PATH_KEYS = ['file_path', 'notebook_path', 'path', 'abs_path', 'filePath'] as const;
|
|
183
183
|
const VERB_RE = /(?:^|[\s;&|()`$])(?:maude|mdcc)\s+design\s+([a-z][a-z0-9-]*)/g;
|
|
184
184
|
// A downloader as a COMMAND word: `curl-local` (loopback-only, its own verb) is not one.
|
|
185
|
-
|
|
185
|
+
// E2E finding (2026-11-12): also by its path (`/usr/bin/curl`, `./bin/aria2c`), quoted (`"curl"`)
|
|
186
|
+
// or escaped (`\curl`) — each slipped past "Search the web: off" (test/acp-may-abs-downloader).
|
|
187
|
+
const DOWNLOADER_RE = /(?:^|[\s;&|()`$'"\\])(?:[\w.~+-]*\/)*(?:curl|wget|aria2c)(?![\w-])/;
|
|
186
188
|
|
|
187
189
|
function insideAny(p: string, repoRoot: string, roots: readonly string[]): boolean {
|
|
188
190
|
const lexical = isAbsolute(p) ? resolve(p) : resolve(repoRoot, p);
|
|
@@ -207,6 +209,25 @@ function verbsIn(command: string): string[] {
|
|
|
207
209
|
return [...command.matchAll(VERB_RE)].map((m) => m[1] as string);
|
|
208
210
|
}
|
|
209
211
|
|
|
212
|
+
/** A shell command that reaches the web: a downloader as a command word, or a web `maude design` verb. */
|
|
213
|
+
function commandIsWeb(command: string): boolean {
|
|
214
|
+
return (
|
|
215
|
+
!!command &&
|
|
216
|
+
(DOWNLOADER_RE.test(command) || verbsIn(command).some((v) => WEB_VERBS.includes(v)))
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** A shell command that runs an asset/footage verb or names the assets folder (either spelling). */
|
|
221
|
+
function commandTouchesAssets(
|
|
222
|
+
command: string,
|
|
223
|
+
repoRoot: string,
|
|
224
|
+
assetsRoots: readonly string[]
|
|
225
|
+
): boolean {
|
|
226
|
+
if (!command) return false;
|
|
227
|
+
if (verbsIn(command).some((v) => ASSET_VERBS.includes(v))) return true;
|
|
228
|
+
return spellings(repoRoot, assetsRoots).some((s) => command.includes(s));
|
|
229
|
+
}
|
|
230
|
+
|
|
210
231
|
/**
|
|
211
232
|
* The live gate: which switch, if any, refuses this permission request. `toolName` is the name from the
|
|
212
233
|
* streamed `tool_call` (AcpBridge.toolNames) — unknown is fine here: refusing is the safe direction, so a
|
|
@@ -226,18 +247,11 @@ export function mayRefusal(
|
|
|
226
247
|
if (!may.web) {
|
|
227
248
|
if (toolName && WEB_TOOL_NAMES.includes(toolName)) return 'web';
|
|
228
249
|
if (!toolName && toolCall?.kind === 'fetch') return 'web';
|
|
229
|
-
if (
|
|
230
|
-
command &&
|
|
231
|
-
(DOWNLOADER_RE.test(command) || verbsIn(command).some((v) => WEB_VERBS.includes(v)))
|
|
232
|
-
)
|
|
233
|
-
return 'web';
|
|
250
|
+
if (commandIsWeb(command)) return 'web';
|
|
234
251
|
}
|
|
235
252
|
|
|
236
253
|
if (!may.assets) {
|
|
237
|
-
if (command)
|
|
238
|
-
if (verbsIn(command).some((v) => ASSET_VERBS.includes(v))) return 'assets';
|
|
239
|
-
if (spellings(repoRoot, assetsRoots).some((s) => command.includes(s))) return 'assets';
|
|
240
|
-
}
|
|
254
|
+
if (commandTouchesAssets(command, repoRoot, assetsRoots)) return 'assets';
|
|
241
255
|
const paths: string[] = [];
|
|
242
256
|
for (const k of PATH_KEYS)
|
|
243
257
|
if (typeof raw[k] === 'string' && raw[k]) paths.push(raw[k] as string);
|
|
@@ -261,6 +275,67 @@ export function mayRefusal(
|
|
|
261
275
|
return null;
|
|
262
276
|
}
|
|
263
277
|
|
|
278
|
+
// ---------------------------------------------------------------------------------------------------
|
|
279
|
+
// Kind-keyed entry points (universal ACP, B3/F5 — contract `.ai/plans/notes/universal-acp-contract.md`
|
|
280
|
+
// rules 3–4). A non-Claude agent has no `_meta.claudeCode.toolName`: its request is judged by ACP
|
|
281
|
+
// `kind` + the paths it names + its command, normalised by acp/policy/enforce.ts. Same checks as the
|
|
282
|
+
// Claude-name-keyed functions (shared helpers), plus the command's path words resolved against the
|
|
283
|
+
// request's cwd: these can only REFUSE, never approve.
|
|
284
|
+
|
|
285
|
+
/** A permission request reduced to what the gates judge, whatever agent sent it. */
|
|
286
|
+
export interface KindRequest {
|
|
287
|
+
/** ACP `kind` (read, edit, delete, move, search, execute, fetch, …); undefined when absent. */
|
|
288
|
+
kind: string | undefined;
|
|
289
|
+
/** Every path the request names, as spelled (locations, rawInput target keys, rawInput.cwd). */
|
|
290
|
+
paths: readonly string[];
|
|
291
|
+
/** The shell command (a string, or an argv joined with spaces); '' when none. */
|
|
292
|
+
command: string;
|
|
293
|
+
/** What relative paths resolve against: the request's own cwd, else the session's root. */
|
|
294
|
+
cwd: string;
|
|
295
|
+
/** The request names a web URL (rawInput.url) — web-shaped whatever its kind. */
|
|
296
|
+
webShaped?: boolean;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The path-like words of a shell command (`/x`, `~/x`, `$HOME/x`, `./x`, `../x`, `a/b`, `.env`), split
|
|
301
|
+
* at whitespace, operators, quotes and `=` (so `--file=~/.ssh/k` and `VAR=/x` count), a short option
|
|
302
|
+
* glued to its path (`-f/etc/x`) unglued. Generous on purpose: it feeds refusals only.
|
|
303
|
+
*/
|
|
304
|
+
export function commandPathTokens(command: string): string[] {
|
|
305
|
+
const out: string[] = [];
|
|
306
|
+
for (let w of command.split(/[\s;&|()<>`"'=]+/)) {
|
|
307
|
+
w = w.replace(/^-{1,2}[A-Za-z]+(?=[/~])/, '').replace(/^\$\{?HOME\}?(?=\/|$)/, '~');
|
|
308
|
+
if (!w || w.includes('://')) continue;
|
|
309
|
+
if (w.includes('/') || w.startsWith('~') || w.startsWith('.')) out.push(w);
|
|
310
|
+
}
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** A glob judged by its literal prefix (`~/.ssh/*` → `~/.ssh/`); a plain path as it is. */
|
|
315
|
+
const globPrefix = (p: string) => p.split(/[*?[{]/)[0] ?? '';
|
|
316
|
+
|
|
317
|
+
/** `mayRefusal` keyed on the request's ACP `kind` instead of a Claude tool name. */
|
|
318
|
+
export function mayRefusalByKind(
|
|
319
|
+
req: KindRequest,
|
|
320
|
+
may: AiMay,
|
|
321
|
+
repoRoot: string,
|
|
322
|
+
assetsRoots: readonly string[],
|
|
323
|
+
home: string = process.env.HOME || homedir()
|
|
324
|
+
): 'web' | 'assets' | null {
|
|
325
|
+
if (may.web && may.assets) return null;
|
|
326
|
+
if (!may.web && (req.kind === 'fetch' || req.webShaped || commandIsWeb(req.command)))
|
|
327
|
+
return 'web';
|
|
328
|
+
if (!may.assets) {
|
|
329
|
+
if (commandTouchesAssets(req.command, repoRoot, assetsRoots)) return 'assets';
|
|
330
|
+
for (const w of [...req.paths, ...commandPathTokens(req.command)]) {
|
|
331
|
+
const base = globPrefix(w);
|
|
332
|
+
const a = base ? agentPath(base, req.cwd, home) : null;
|
|
333
|
+
if (a && insideAny(a.abs, repoRoot, assetsRoots)) return 'assets';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
|
|
264
339
|
// ---------------------------------------------------------------------------------------------------
|
|
265
340
|
// V2-8.9 M2 (decision maude/v2-8.9-lead-m2-deny-credential-reads-only) — credential stores are never
|
|
266
341
|
// read by the agent: these folders get a deny rule, on EVERY session whatever the "AI may" switches
|
|
@@ -343,7 +418,27 @@ export function credentialPathsFor(
|
|
|
343
418
|
if (real !== abs) files.add(real);
|
|
344
419
|
}
|
|
345
420
|
}
|
|
346
|
-
|
|
421
|
+
// F6b — the person's Codex sign-in (`$CODEX_HOME/auth.json`, default ~/.codex). The Studio chat's
|
|
422
|
+
// Codex reads it through a link in Maude's own Codex home (acp/policy/codex-home.ts, itself under
|
|
423
|
+
// the `.config/maude` folder above), in its own process; no agent's tool call reads it.
|
|
424
|
+
const addFile = (abs: string) => {
|
|
425
|
+
files.add(abs);
|
|
426
|
+
const real = resolveRealPath(abs, abs);
|
|
427
|
+
if (real !== abs) files.add(real);
|
|
428
|
+
};
|
|
429
|
+
const codexHome =
|
|
430
|
+
env.CODEX_HOME && isAbsolute(env.CODEX_HOME) ? resolve(env.CODEX_HOME) : join(home, '.codex');
|
|
431
|
+
addFile(join(codexHome, 'auth.json'));
|
|
432
|
+
// Security review 2026-11-12 (defender M6) — opencode's sign-in (`$XDG_DATA_HOME/opencode/auth.json`,
|
|
433
|
+
// default ~/.local/share on every platform: opencode uses xdg-basedir) and the Gemini CLI's folder
|
|
434
|
+
// (~/.gemini: oauth_creds.json, settings with MCP env). Both XDG spellings, as for Maude's config.
|
|
435
|
+
addFile(join(home, '.local', 'share', 'opencode', 'auth.json'));
|
|
436
|
+
const xdgData = env.XDG_DATA_HOME;
|
|
437
|
+
if (xdgData && isAbsolute(xdgData)) addFile(resolve(xdgData, 'opencode', 'auth.json'));
|
|
438
|
+
addDir(join(home, '.gemini'));
|
|
439
|
+
// B7 — a custom key-store path (generation/keys.ts) holds media AND chat keys: denied like the
|
|
440
|
+
// profile's own credential files when it sits outside the folders above.
|
|
441
|
+
for (const k of ['MAUDE_CLOUD_CONFIG', 'HUBS_CONFIG_PATH', 'MAUDE_GEN_KEYS_PATH']) {
|
|
347
442
|
const f = env[k];
|
|
348
443
|
if (!f || !isAbsolute(f)) continue;
|
|
349
444
|
const abs = resolve(f);
|
|
@@ -389,12 +484,8 @@ export function credentialRefusal(
|
|
|
389
484
|
home: string = process.env.HOME || homedir()
|
|
390
485
|
): 'credentials' | null {
|
|
391
486
|
const raw = (toolCall?.rawInput ?? {}) as Record<string, unknown>;
|
|
392
|
-
|
|
393
|
-
// `~/.CONFIG/Maude/cloud.json` as the same file, and the deny rules are exact-case.
|
|
394
|
-
const command = typeof raw.command === 'string' ? raw.command.toLowerCase() : '';
|
|
395
|
-
if (command && credentialSpellings(paths, home).some((s) => command.includes(s.toLowerCase())))
|
|
487
|
+
if (commandNamesCredential(typeof raw.command === 'string' ? raw.command : '', paths, home))
|
|
396
488
|
return 'credentials';
|
|
397
|
-
const roots = [...paths.dirs, ...paths.files];
|
|
398
489
|
const candidates: string[] = [];
|
|
399
490
|
for (const k of PATH_KEYS)
|
|
400
491
|
if (typeof raw[k] === 'string' && raw[k]) candidates.push(raw[k] as string);
|
|
@@ -408,14 +499,45 @@ export function credentialRefusal(
|
|
|
408
499
|
const t = g.trim();
|
|
409
500
|
if (isAbsolute(t) || t.startsWith('~')) candidates.push(t.split(/[*?[{]/)[0] ?? '');
|
|
410
501
|
}
|
|
502
|
+
return pathsHitCredential(candidates, paths, repoRoot, home) ? 'credentials' : null;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** A shell command that spells a credential path (absolute, `~/…`, `$HOME/…`), case-folded. */
|
|
506
|
+
function commandNamesCredential(command: string, paths: CredentialPaths, home: string): boolean {
|
|
507
|
+
// V2-8.9 round 2 R2-L2 — case-folded: a case-insensitive volume (the macOS default) opens
|
|
508
|
+
// `~/.CONFIG/Maude/cloud.json` as the same file, and the deny rules are exact-case.
|
|
509
|
+
const c = command.toLowerCase();
|
|
510
|
+
return !!c && credentialSpellings(paths, home).some((s) => c.includes(s.toLowerCase()));
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** Does any candidate path, resolved from `cwd`, lie in a credential store (case-folded)? */
|
|
514
|
+
function pathsHitCredential(
|
|
515
|
+
candidates: readonly string[],
|
|
516
|
+
paths: CredentialPaths,
|
|
517
|
+
cwd: string,
|
|
518
|
+
home: string
|
|
519
|
+
): boolean {
|
|
520
|
+
const roots = [...paths.dirs, ...paths.files];
|
|
411
521
|
// V2-8.9 H1 — expanded exactly as Claude Code opens it (agent-path.ts: trimmed, `~` and `~/`), so
|
|
412
522
|
// `' ~/.SSH/id_rsa'` is the key it is. Odd spellings are judged too: here they can only refuse.
|
|
413
523
|
return candidates.some((p) => {
|
|
414
|
-
const a = p ? agentPath(p,
|
|
415
|
-
return !!a && insideAnyFolded(a.abs,
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
|
|
524
|
+
const a = p ? agentPath(p, cwd, home) : null;
|
|
525
|
+
return !!a && insideAnyFolded(a.abs, cwd, roots);
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* `credentialRefusal` keyed on a normalised request: its paths, every path word of its command
|
|
531
|
+
* (resolved from the request's cwd, so `cat ../../.ssh/id_rsa` counts), and the command's spellings.
|
|
532
|
+
*/
|
|
533
|
+
export function credentialRefusalByKind(
|
|
534
|
+
req: KindRequest,
|
|
535
|
+
paths: CredentialPaths,
|
|
536
|
+
home: string = process.env.HOME || homedir()
|
|
537
|
+
): 'credentials' | null {
|
|
538
|
+
if (commandNamesCredential(req.command, paths, home)) return 'credentials';
|
|
539
|
+
const candidates = [...req.paths, ...commandPathTokens(req.command)].map(globPrefix);
|
|
540
|
+
return pathsHitCredential(candidates, paths, req.cwd, home) ? 'credentials' : null;
|
|
419
541
|
}
|
|
420
542
|
|
|
421
543
|
/** `insideAny`, with the lexical and the real path compared case-folded (R2-L2). */
|
|
@@ -786,6 +908,107 @@ export function bashReadsOutside(
|
|
|
786
908
|
return false;
|
|
787
909
|
}
|
|
788
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Universal ACP (B3/F5, contract rule 7) — the readers a `shellGate:'command-text'` agent's shell
|
|
913
|
+
* request may be APPROVED once for. A strict subset of `READ_ONLY_BASH`: that list only ever takes
|
|
914
|
+
* "Always allow" off a card, so it carries writers (`cp`, `sed -i`, `tar`) and readers that run a
|
|
915
|
+
* program (`find -exec`, `rg --pre`) or write a file (`tree -o`, `sort -o`, `xxd in out`). None here
|
|
916
|
+
* does either, whatever its options.
|
|
917
|
+
*
|
|
918
|
+
* Security review 2026-11-12 (defender H2, attacker A1): no reader that RECURSES. The gate judges the
|
|
919
|
+
* words it sees, not the files a recursive reader opens on the way down, and BSD `grep -rS`, `diff -r`
|
|
920
|
+
* and `du -L` follow an in-repo symlink (a relative "ladder" lands on HOME at any clone depth) into
|
|
921
|
+
* the person's credentials. `grep`/`egrep`/`fgrep`/`diff`/`du` therefore go to the card;
|
|
922
|
+
* `RECURSE_OR_DEREF_FLAG` refuses a recursive or dereferencing option on what is left (`ls -R`).
|
|
923
|
+
*/
|
|
924
|
+
export const APPROVABLE_READ_BASH: ReadonlySet<string> = new Set([
|
|
925
|
+
'cat',
|
|
926
|
+
'head',
|
|
927
|
+
'tail',
|
|
928
|
+
'wc',
|
|
929
|
+
'ls',
|
|
930
|
+
'stat',
|
|
931
|
+
'nl',
|
|
932
|
+
'cmp',
|
|
933
|
+
'strings',
|
|
934
|
+
]);
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* An option word that recurses or follows symlinks: a long `--recursive` / `--dereference*`, or a
|
|
938
|
+
* short cluster (`-rn`, `-lR`) holding `r`, `R`, `S`, `L` or `H`. Over-broad on purpose — a harmless
|
|
939
|
+
* `tail -r` or `ls -S` only reaches the card.
|
|
940
|
+
*/
|
|
941
|
+
const RECURSE_OR_DEREF_FLAG = /^(?:--(?:recursive|dereference)|-[^-=]*[rRSLH])/;
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* The words of a ONE-command shell line with no expansion anywhere, or null. Anything a word test
|
|
945
|
+
* cannot follow — an operator, a redirect, a variable, a substitution, an escape, a glob, `~`, a
|
|
946
|
+
* brace, history, a newline, an unterminated quote — is null, and every caller reads null as "ask".
|
|
947
|
+
*/
|
|
948
|
+
export function plainWords(command: string): string[] | null {
|
|
949
|
+
if (!command || /[;&|<>$`()\\{}\n\r*?[\]~!]/.test(command)) return null;
|
|
950
|
+
const words: string[] = [];
|
|
951
|
+
let word = '';
|
|
952
|
+
let inWord = false;
|
|
953
|
+
for (let i = 0; i < command.length; i++) {
|
|
954
|
+
const c = command[i] as string;
|
|
955
|
+
if (c === "'" || c === '"') {
|
|
956
|
+
const j = command.indexOf(c, i + 1);
|
|
957
|
+
if (j === -1) return null;
|
|
958
|
+
word += command.slice(i + 1, j);
|
|
959
|
+
inWord = true;
|
|
960
|
+
i = j;
|
|
961
|
+
} else if (/\s/.test(c)) {
|
|
962
|
+
if (inWord) words.push(word);
|
|
963
|
+
word = '';
|
|
964
|
+
inWord = false;
|
|
965
|
+
} else {
|
|
966
|
+
word += c;
|
|
967
|
+
inWord = true;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (inWord) words.push(word);
|
|
971
|
+
return words;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* The command-text approval (contract rule 7): `command` is ONE plain call of an
|
|
976
|
+
* `APPROVABLE_READ_BASH` reader (by bare name), every argument that is not a flag — and every
|
|
977
|
+
* `--opt=value` — names a path that resolves, from `cwd`, inside `roots`, and `cwd` itself lies in
|
|
978
|
+
* them. A flag glued to a path (`-f/etc/x`) is not judged: it asks. Same word judgment as
|
|
979
|
+
* `bashReadsOutside` (agent-path.ts spelling, realpath against the roots), in the approve direction.
|
|
980
|
+
*/
|
|
981
|
+
export function bashReadOnlyInside(
|
|
982
|
+
command: string,
|
|
983
|
+
cwd: string,
|
|
984
|
+
roots: readonly string[],
|
|
985
|
+
home: string = homedir()
|
|
986
|
+
): boolean {
|
|
987
|
+
const words = plainWords(command);
|
|
988
|
+
const head = words?.[0];
|
|
989
|
+
if (!words || !head || !APPROVABLE_READ_BASH.has(head)) return false;
|
|
990
|
+
const inside = (abs: string) => {
|
|
991
|
+
const real = resolveRealPath(abs, cwd);
|
|
992
|
+
return roots.some((r) => r === real || isInsideRoot(real, r));
|
|
993
|
+
};
|
|
994
|
+
if (!isAbsolute(cwd) || !inside(resolve(cwd))) return false;
|
|
995
|
+
for (let w of words.slice(1)) {
|
|
996
|
+
if (w.startsWith('-')) {
|
|
997
|
+
if (RECURSE_OR_DEREF_FLAG.test(w)) return false;
|
|
998
|
+
const eq = w.indexOf('=');
|
|
999
|
+
if (eq < 0) {
|
|
1000
|
+
if (w.includes('/') || w.includes('.')) return false;
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
w = w.slice(eq + 1);
|
|
1004
|
+
}
|
|
1005
|
+
if (!w) continue;
|
|
1006
|
+
const a = agentPath(w, cwd, home);
|
|
1007
|
+
if (!a || a.odd || !inside(a.abs)) return false;
|
|
1008
|
+
}
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
789
1012
|
/**
|
|
790
1013
|
* The live gate's read half. `null` — not a read tool, nothing to say. `inside` — every path it names
|
|
791
1014
|
* lies, as RESOLVED on disk (a symlink is judged by where it points), in a boundary root or a folder
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// B8 — a Maude-owned config home for an ACP agent (Gemini CLI, GitHub Copilot CLI), the same shape
|
|
2
|
+
// as F6b's Codex home (codex-home.ts): the chat's agent never reads the person's own config folder,
|
|
3
|
+
// where their MCP servers, hooks, extensions, plugins and allow-lists live and start outside every
|
|
4
|
+
// Maude gate. Contract: .ai/plans/notes/universal-acp-contract.md § "B8 — Gemini and Copilot".
|
|
5
|
+
//
|
|
6
|
+
// ~/.config/maude/agents/<name>/ profile `default`
|
|
7
|
+
// ~/.config/maude/profiles/<id>/agents/<name>/ any other profile
|
|
8
|
+
//
|
|
9
|
+
// At every spawn (idempotent, safe while other chats use the folder):
|
|
10
|
+
// • the folder (and every missing parent) is made owner-only; a symlink, a non-folder or a folder
|
|
11
|
+
// another user owns throws: the chat does not start;
|
|
12
|
+
// • `links`: each name becomes a SYMLINK to the person's own file (their sign-in), replaced only
|
|
13
|
+
// when it points elsewhere; a missing target leaves it dangling until they sign in;
|
|
14
|
+
// • `files`: Maude's own config, rewritten by rename;
|
|
15
|
+
// • `foreign`: config surfaces the agent reads from its home but Maude never writes, removed.
|
|
16
|
+
//
|
|
17
|
+
// Credentials: the folder sits under `~/.config/maude`, which `credentialPathsFor` denies to every
|
|
18
|
+
// agent's tool calls; the agent reads it in its own process.
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
chmodSync,
|
|
22
|
+
lstatSync,
|
|
23
|
+
mkdirSync,
|
|
24
|
+
readlinkSync,
|
|
25
|
+
renameSync,
|
|
26
|
+
rmSync,
|
|
27
|
+
symlinkSync,
|
|
28
|
+
unlinkSync,
|
|
29
|
+
writeFileSync,
|
|
30
|
+
} from 'node:fs';
|
|
31
|
+
import { homedir } from 'node:os';
|
|
32
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
33
|
+
|
|
34
|
+
import { resolveProfile } from '../../shell/profile.ts';
|
|
35
|
+
|
|
36
|
+
export type HostEnv = Readonly<Record<string, string | undefined>>;
|
|
37
|
+
|
|
38
|
+
export const homeOf = (env: HostEnv) => (env.HOME && isAbsolute(env.HOME) ? env.HOME : homedir());
|
|
39
|
+
|
|
40
|
+
const NAME_RE = /^[a-z0-9][a-z0-9-]{0,40}$/;
|
|
41
|
+
/** A relative path inside the home: no `..`, no absolute, no empty segment. */
|
|
42
|
+
const REL_RE = /^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/;
|
|
43
|
+
|
|
44
|
+
/** The Maude-owned home `<name>` for the profile this process runs as. */
|
|
45
|
+
export function maudeAgentHomePath(name: string, env: HostEnv = process.env): string {
|
|
46
|
+
if (!NAME_RE.test(name)) throw new Error(`Maude's agent home: bad name ${JSON.stringify(name)}`);
|
|
47
|
+
const { id } = resolveProfile(env as Record<string, string | undefined>, () => {});
|
|
48
|
+
const maude = join(homeOf(env), '.config', 'maude');
|
|
49
|
+
return id === 'default'
|
|
50
|
+
? join(maude, 'agents', name)
|
|
51
|
+
: join(maude, 'profiles', id, 'agents', name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AgentHomeSpec {
|
|
55
|
+
/** Folder name under `agents/` (`gemini-home`, `copilot-home`). */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Relative path in the home → absolute path of the person's own file it links to. */
|
|
58
|
+
links?: Readonly<Record<string, string>>;
|
|
59
|
+
/** Relative path in the home → content Maude writes (0600). */
|
|
60
|
+
files?: Readonly<Record<string, string>>;
|
|
61
|
+
/** Relative paths removed at every spawn. */
|
|
62
|
+
foreign?: readonly string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function assertOwnedDir(p: string, what: string) {
|
|
66
|
+
const st = lstatSync(p);
|
|
67
|
+
if (st.isSymbolicLink() || !st.isDirectory()) {
|
|
68
|
+
throw new Error(`Maude's agent home: ${what} is not a plain folder (${p})`);
|
|
69
|
+
}
|
|
70
|
+
const uid = process.getuid?.();
|
|
71
|
+
if (uid !== undefined && st.uid !== uid) {
|
|
72
|
+
throw new Error(`Maude's agent home: ${what} is not owned by this user (${p})`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** mkdir -p, creating every missing level owner-only. */
|
|
77
|
+
function mkdirsPrivate(p: string) {
|
|
78
|
+
try {
|
|
79
|
+
lstatSync(p);
|
|
80
|
+
return;
|
|
81
|
+
} catch {
|
|
82
|
+
/* missing */
|
|
83
|
+
}
|
|
84
|
+
mkdirsPrivate(dirname(p));
|
|
85
|
+
try {
|
|
86
|
+
mkdirSync(p, { mode: 0o700 });
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if ((e as NodeJS.ErrnoException).code !== 'EEXIST') throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function relIn(home: string, rel: string): string {
|
|
93
|
+
if (!REL_RE.test(rel)) throw new Error(`Maude's agent home: bad entry ${JSON.stringify(rel)}`);
|
|
94
|
+
const abs = join(home, rel);
|
|
95
|
+
// Every parent level inside the home must itself be a plain folder we own.
|
|
96
|
+
const parent = dirname(abs);
|
|
97
|
+
if (parent !== home) {
|
|
98
|
+
mkdirsPrivate(parent);
|
|
99
|
+
let p = parent;
|
|
100
|
+
while (p !== home && p.startsWith(home + sep)) {
|
|
101
|
+
assertOwnedDir(p, `a folder in it`);
|
|
102
|
+
p = dirname(p);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return abs;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Make (or repair) a Maude-owned agent home and return its path. */
|
|
109
|
+
export function ensureMaudeAgentHome(spec: AgentHomeSpec, env: HostEnv = process.env): string {
|
|
110
|
+
const home = maudeAgentHomePath(spec.name, env);
|
|
111
|
+
mkdirsPrivate(home);
|
|
112
|
+
assertOwnedDir(home, 'the folder');
|
|
113
|
+
chmodSync(home, 0o700);
|
|
114
|
+
|
|
115
|
+
for (const rel of spec.foreign ?? []) {
|
|
116
|
+
rmSync(relIn(home, rel), { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const [rel, target] of Object.entries(spec.links ?? {})) {
|
|
120
|
+
if (!isAbsolute(target))
|
|
121
|
+
throw new Error(`Maude's agent home: link target not absolute (${target})`);
|
|
122
|
+
const link = relIn(home, rel);
|
|
123
|
+
if (resolve(target) === link || resolve(target).startsWith(home + sep)) {
|
|
124
|
+
throw new Error(`Maude's agent home: ${rel} would link into Maude's own folder`);
|
|
125
|
+
}
|
|
126
|
+
let current: string | null = null;
|
|
127
|
+
try {
|
|
128
|
+
const st = lstatSync(link);
|
|
129
|
+
if (st.isDirectory()) throw new Error(`Maude's agent home: ${rel} is a folder (${link})`);
|
|
130
|
+
current = st.isSymbolicLink() ? readlinkSync(link) : '';
|
|
131
|
+
} catch (e) {
|
|
132
|
+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e;
|
|
133
|
+
}
|
|
134
|
+
if (current !== target) {
|
|
135
|
+
if (current !== null) unlinkSync(link);
|
|
136
|
+
symlinkSync(target, link);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
for (const [rel, content] of Object.entries(spec.files ?? {})) {
|
|
141
|
+
const f = relIn(home, rel);
|
|
142
|
+
try {
|
|
143
|
+
if (lstatSync(f).isDirectory())
|
|
144
|
+
throw new Error(`Maude's agent home: ${rel} is a folder (${f})`);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e;
|
|
147
|
+
}
|
|
148
|
+
const tmp = join(dirname(f), `.${process.pid}.${Date.now()}.tmp`);
|
|
149
|
+
writeFileSync(tmp, content, { mode: 0o600 });
|
|
150
|
+
renameSync(tmp, f);
|
|
151
|
+
}
|
|
152
|
+
return home;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The session folder, then each parent up to and including the nearest one holding `.git` (the
|
|
157
|
+
* repository an agent resolves its "project" config from). With no `.git` above, the folder alone.
|
|
158
|
+
*/
|
|
159
|
+
export function upToGitRoot(projectRoot: string): string[] {
|
|
160
|
+
const chain: string[] = [];
|
|
161
|
+
let p = resolve(projectRoot);
|
|
162
|
+
for (;;) {
|
|
163
|
+
chain.push(p);
|
|
164
|
+
try {
|
|
165
|
+
lstatSync(join(p, '.git'));
|
|
166
|
+
return chain;
|
|
167
|
+
} catch {
|
|
168
|
+
/* not the root */
|
|
169
|
+
}
|
|
170
|
+
const up = dirname(p);
|
|
171
|
+
if (up === p) return [resolve(projectRoot)];
|
|
172
|
+
p = up;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Throws when any of `entries` exists under `projectRoot` (lstat: a dangling link counts). The
|
|
178
|
+
* served repo is untrusted (DDR-054): config the agent would load from it starts code outside the
|
|
179
|
+
* gates, so Maude does not start the agent while it is there.
|
|
180
|
+
*/
|
|
181
|
+
export function refuseProjectEntries(
|
|
182
|
+
projectRoot: string,
|
|
183
|
+
entries: readonly string[],
|
|
184
|
+
label: string
|
|
185
|
+
): void {
|
|
186
|
+
for (const rel of entries) {
|
|
187
|
+
const p = join(resolve(projectRoot), rel);
|
|
188
|
+
try {
|
|
189
|
+
lstatSync(p);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
if (
|
|
192
|
+
(e as NodeJS.ErrnoException).code === 'ENOENT' ||
|
|
193
|
+
(e as NodeJS.ErrnoException).code === 'ENOTDIR'
|
|
194
|
+
)
|
|
195
|
+
continue;
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
throw new Error(
|
|
199
|
+
`This project has ${label} configuration (${p}). ${label} would load it outside the limits Maude sets, so Maude does not start ${label} while it is there.`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The adapter between the bridge's permission-gate call site (acp/policy/gate-types.ts) and the
|
|
2
|
+
// bridge-enforced rule set (acp/policy/enforce.ts, contract rules 1–13). One per bridge: the
|
|
3
|
+
// tripwire's memory of what each tool call said, and which calls the person approved, lives here.
|
|
4
|
+
//
|
|
5
|
+
// Which rules an agent gets:
|
|
6
|
+
// • an agent with an `enforcement` block gets enforce.ts in full, whatever its `policy` says. An
|
|
7
|
+
// 'unrestricted' agent with a block (Codex and opencode until their conformance probe passes)
|
|
8
|
+
// still runs under its launch policy (spawn.ts applies it) — consent to run it waives the probe,
|
|
9
|
+
// not the second gate.
|
|
10
|
+
// • an 'unrestricted' agent without one gets the same rules over a conservative stand-in: no
|
|
11
|
+
// shell call is ever approved without the person (`shellGate:'os-sandbox'` = always the card),
|
|
12
|
+
// and the tripwire watches credential stores only (it has no launch policy to hold).
|
|
13
|
+
|
|
14
|
+
import type { AgentDescriptor, Enforcement, PolicyCtx } from '../agents/descriptor.ts';
|
|
15
|
+
import {
|
|
16
|
+
answerCard,
|
|
17
|
+
cardRefusalNotice,
|
|
18
|
+
type EnforcedDescriptor,
|
|
19
|
+
gatePermission,
|
|
20
|
+
isForbiddenClientMethod,
|
|
21
|
+
newTripwireMemory,
|
|
22
|
+
refusalNotice,
|
|
23
|
+
tripwire,
|
|
24
|
+
} from './enforce.ts';
|
|
25
|
+
import type { PermissionGate } from './gate-types.ts';
|
|
26
|
+
|
|
27
|
+
/** rawInput keys a request may carry a path in, for an agent that names none (the catalog's list). */
|
|
28
|
+
const FALLBACK_TARGET_KEYS = ['filePath', 'filepath', 'file_path', 'path', 'abs_path', 'paths'];
|
|
29
|
+
|
|
30
|
+
const FALLBACK_ENFORCEMENT: Enforcement = {
|
|
31
|
+
launchPolicy: () => ({ env: {} }),
|
|
32
|
+
readGate: 'agent-permission-engine',
|
|
33
|
+
shellGate: 'os-sandbox',
|
|
34
|
+
rejectEndsTurn: false,
|
|
35
|
+
targetKeys: FALLBACK_TARGET_KEYS,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The descriptor the rules judge with: always bridge-enforced, never Claude. */
|
|
39
|
+
export function enforcedFor(d: AgentDescriptor): EnforcedDescriptor {
|
|
40
|
+
if (d.policy === 'claude-meta') {
|
|
41
|
+
throw new Error(`agent ${d.id}: Claude is gated by its own _meta policy, not the bridge gate`);
|
|
42
|
+
}
|
|
43
|
+
return { ...d, policy: 'bridge-enforced', enforcement: d.enforcement ?? FALLBACK_ENFORCEMENT };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createBridgeGate(d: AgentDescriptor): PermissionGate {
|
|
47
|
+
const enforced = enforcedFor(d);
|
|
48
|
+
const memory = newTripwireMemory();
|
|
49
|
+
return {
|
|
50
|
+
decide: ({ req, ctx, state }) => gatePermission(req, enforced, ctx, state),
|
|
51
|
+
answer: (result, optionId) => {
|
|
52
|
+
const res = answerCard(result, optionId);
|
|
53
|
+
const picked =
|
|
54
|
+
res.outcome.outcome === 'selected'
|
|
55
|
+
? result.strippedOptions.find(
|
|
56
|
+
(o) => o.optionId === (res.outcome as { optionId: string }).optionId
|
|
57
|
+
)
|
|
58
|
+
: undefined;
|
|
59
|
+
if (result.toolCallId && picked?.kind === 'allow_once')
|
|
60
|
+
memory.approved.add(result.toolCallId);
|
|
61
|
+
return res;
|
|
62
|
+
},
|
|
63
|
+
observe: (update, ctx: PolicyCtx) => tripwire(update, enforced, ctx, memory),
|
|
64
|
+
isForbiddenClientMethod: (method) => isForbiddenClientMethod(enforced, method),
|
|
65
|
+
refusalNotice: (result) => refusalNotice(enforced, result),
|
|
66
|
+
cardRefusalNotice: () => cardRefusalNotice(enforced),
|
|
67
|
+
};
|
|
68
|
+
}
|