@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.
Files changed (91) hide show
  1. package/apps/studio/acp/agents/auth.ts +241 -0
  2. package/apps/studio/acp/agents/catalog.ts +308 -0
  3. package/apps/studio/acp/agents/chat-key.ts +64 -0
  4. package/apps/studio/acp/agents/conformance.ts +1853 -0
  5. package/apps/studio/acp/agents/consent.ts +92 -0
  6. package/apps/studio/acp/agents/descriptor.ts +188 -0
  7. package/apps/studio/acp/agents/discover.ts +491 -0
  8. package/apps/studio/acp/agents/e2e-model.ts +58 -0
  9. package/apps/studio/acp/agents/health.ts +46 -0
  10. package/apps/studio/acp/agents/link-scan.ts +230 -0
  11. package/apps/studio/acp/agents/spawn.ts +164 -0
  12. package/apps/studio/acp/agents/state.ts +132 -0
  13. package/apps/studio/acp/ask-queue.ts +13 -4
  14. package/apps/studio/acp/bootstrap-brief.ts +16 -3
  15. package/apps/studio/acp/bridge.ts +709 -99
  16. package/apps/studio/acp/env.ts +43 -1
  17. package/apps/studio/acp/index.ts +428 -43
  18. package/apps/studio/acp/may-scope.ts +244 -21
  19. package/apps/studio/acp/policy/agent-home.ts +202 -0
  20. package/apps/studio/acp/policy/bridge-gate.ts +68 -0
  21. package/apps/studio/acp/policy/codex-home.ts +228 -0
  22. package/apps/studio/acp/policy/enforce.ts +620 -0
  23. package/apps/studio/acp/policy/gate-types.ts +41 -0
  24. package/apps/studio/acp/policy/launch-codex.ts +351 -0
  25. package/apps/studio/acp/policy/launch-copilot.ts +119 -0
  26. package/apps/studio/acp/policy/launch-gemini.ts +120 -0
  27. package/apps/studio/acp/policy/launch-opencode.ts +131 -0
  28. package/apps/studio/acp/policy/opencode-user-config.ts +240 -0
  29. package/apps/studio/acp/probe.ts +78 -14
  30. package/apps/studio/acp/transcript.ts +14 -0
  31. package/apps/studio/acp/write-scope.ts +62 -2
  32. package/apps/studio/annotations-layer.tsx +8 -0
  33. package/apps/studio/bin/_capture-init.js +5 -0
  34. package/apps/studio/bin/screenshot.sh +7 -1
  35. package/apps/studio/bridge/dgn-protocol.ts +3 -2
  36. package/apps/studio/canvas-shell.tsx +54 -0
  37. package/apps/studio/client/panels/ChatPanel.jsx +19 -4
  38. package/apps/studio/client/panels/PermissionPrompt.jsx +11 -6
  39. package/apps/studio/client/panels/SyncConsentDialog.jsx +4 -1
  40. package/apps/studio/client/panels/acp-runtime.js +95 -7
  41. package/apps/studio/client/v2/ai/Advanced.jsx +4 -3
  42. package/apps/studio/client/v2/ai/AgentNotice.jsx +138 -0
  43. package/apps/studio/client/v2/ai/AgentOffer.jsx +110 -0
  44. package/apps/studio/client/v2/ai/AgentPicker.jsx +121 -0
  45. package/apps/studio/client/v2/ai/Composer.jsx +4 -0
  46. package/apps/studio/client/v2/ai/ConnectSheet.jsx +13 -0
  47. package/apps/studio/client/v2/ai/Feed.jsx +8 -0
  48. package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +24 -1
  49. package/apps/studio/client/v2/ai/Suggest.jsx +5 -1
  50. package/apps/studio/client/v2/ai/advanced-model.js +17 -6
  51. package/apps/studio/client/v2/ai/agents-model.js +333 -0
  52. package/apps/studio/client/v2/ai/agents-store.js +223 -0
  53. package/apps/studio/client/v2/ai/ai.css +63 -0
  54. package/apps/studio/client/v2/ai/needs-you.js +1 -1
  55. package/apps/studio/client/v2/empty/empty-host.jsx +11 -2
  56. package/apps/studio/client/v2/empty/use-empty-canvas.js +22 -7
  57. package/apps/studio/client/v2/fold/fold-store.js +1 -0
  58. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +1 -0
  59. package/apps/studio/client/v2/settings/agent-keys.js +88 -0
  60. package/apps/studio/client/v2/settings/agents-card.jsx +408 -0
  61. package/apps/studio/client/v2/settings/connections-model.js +1 -1
  62. package/apps/studio/client/v2/settings/connections-section.jsx +4 -0
  63. package/apps/studio/client/v2/settings/settings-cards.js +2 -1
  64. package/apps/studio/client/v2/settings/settings-model.js +1 -0
  65. package/apps/studio/client/v2/settings/settings.css +7 -0
  66. package/apps/studio/client/v2/shell/served-routes.js +1 -0
  67. package/apps/studio/client/v2/undo/zoom-undo.jsx +19 -2
  68. package/apps/studio/cloud-build.ts +5 -0
  69. package/apps/studio/comments/reveal.ts +13 -0
  70. package/apps/studio/comments-overlay.tsx +36 -0
  71. package/apps/studio/dist/client.bundle.js +535 -535
  72. package/apps/studio/dist/comment-mount.js +2 -2
  73. package/apps/studio/dist/styles.css +1 -1
  74. package/apps/studio/editing/annotation-count.ts +25 -0
  75. package/apps/studio/editing/empty-report.ts +8 -3
  76. package/apps/studio/editing/empty-reporter.tsx +10 -1
  77. package/apps/studio/generation/keys.ts +197 -11
  78. package/apps/studio/outbox/policy.ts +8 -2
  79. package/apps/studio/outbox/types.ts +5 -0
  80. package/apps/studio/routes/agents.ts +479 -0
  81. package/apps/studio/routes/index.ts +3 -0
  82. package/apps/studio/scripts/acp-conformance-local.ts +95 -0
  83. package/apps/studio/scripts/acp-e2e-local.ts +1026 -0
  84. package/apps/studio/server.ts +9 -0
  85. package/apps/studio/sync/index.ts +9 -1
  86. package/apps/studio/sync/writer-registry.ts +12 -0
  87. package/apps/studio/whats-new.json +19 -0
  88. package/apps/studio/ws.ts +3 -0
  89. package/cli/commands/codex.mjs +36 -2
  90. package/cli/lib/harness/codex-runtime.mjs +98 -11
  91. package/package.json +9 -8
@@ -0,0 +1,228 @@
1
+ // F6b — the Maude-owned CODEX_HOME the Studio chat's Codex runs with.
2
+ // Contract: .ai/plans/notes/universal-acp-contract.md § "F6b — MCP/hooks isolation and flip".
3
+ //
4
+ // Why: the person's MCP servers and hooks in `$CODEX_HOME/config.toml` (+ `hooks.json`) start
5
+ // OUTSIDE the sandbox, and an override in CODEX_CONFIG merges with them instead of replacing them
6
+ // (measured, F6: the session config reaches app-server after it started its MCP servers). So the
7
+ // chat's Codex never reads the person's Codex home at all. It gets one Maude owns, per profile:
8
+ //
9
+ // ~/.config/maude/agents/codex-home/ profile `default`
10
+ // ~/.config/maude/profiles/<id>/agents/codex-home/ any other profile
11
+ //
12
+ // That folder holds:
13
+ // • auth.json → a SYMLINK to the person's own `$CODEX_HOME/auth.json` (default ~/.codex), so the
14
+ // sign-in from Settings (which runs `codex login` against the person's own CODEX_HOME,
15
+ // auth.ts) carries over, and a token refresh writes THROUGH the link into the person's file
16
+ // (measured on 0.154: `codex login --with-api-key` under the Maude home kept the link and
17
+ // rewrote the target). A missing target is fine: the link dangles until the person signs in.
18
+ // NOT when the person stored an API key for the chat (S1, defender M2): codex-acp then logs in
19
+ // with that key (`DEFAULT_AUTH_REQUEST`, chat-key.ts) and Codex writes the login to
20
+ // `$CODEX_HOME/auth.json`, which through the link would be the person's own `~/.codex/auth.json`
21
+ // (the key would leave Maude's 0600 store, and removing it in Settings would not sign Codex out).
22
+ // With a key, auth.json is Codex's own plain file inside this 0700 folder, made 0600 at every
23
+ // spawn, and deleted when the key is removed (`forgetCodexApiLogin`) or the next spawn has none.
24
+ // • config.toml — Maude's, rewritten at every spawn (no MCP servers, no hooks, no plugins,
25
+ // no profiles, no project trust).
26
+ // • whatever Codex itself writes there at runtime (sessions, logs, its own skills cache).
27
+ // What is removed at every spawn: the config surfaces Codex reads from its home but never writes
28
+ // itself — `hooks.json`, `AGENTS.md`, `AGENTS.override.md` — and `rules/` (exec-policy amendments:
29
+ // an `allow` rule there would run a matching command OUTSIDE the sandbox without a card; the
30
+ // bridge never picks the "always" option that writes one, so a rule there was planted).
31
+ //
32
+ // Credentials: the folder sits under `~/.config/maude`, which `credentialPathsFor` denies to every
33
+ // agent (Codex's Seatbelt profile `none`, the bridge's live refusal); the person's real auth.json is
34
+ // on that list too (may-scope.ts). Codex reads both in its own process, outside the sandbox that
35
+ // confines its tool calls.
36
+ //
37
+ // The served repo's own `.codex/` (measured, F6b, 0.154): codex-acp marks the session folder
38
+ // `trust_level = "trusted"` in the session config it sends (its value wins over ours), so Codex loads
39
+ // the PROJECT layer `<cwd>/.codex/config.toml`, and an MCP server named there started outside the
40
+ // sandbox. A `.codex` above the session folder did not load (untrusted). So a project with a
41
+ // `.codex` entry is refused (`refuseProjectCodexConfig`): the repo is untrusted (DDR-054), and
42
+ // `.codex/` can also carry hooks, rules and agent roles.
43
+ //
44
+ // Fail closed: anything unexpected (the folder is a symlink, not ours, not a folder; auth.json is a
45
+ // folder) throws, and the chat does not start.
46
+
47
+ import {
48
+ chmodSync,
49
+ existsSync,
50
+ lstatSync,
51
+ mkdirSync,
52
+ readlinkSync,
53
+ renameSync,
54
+ rmSync,
55
+ symlinkSync,
56
+ unlinkSync,
57
+ writeFileSync,
58
+ } from 'node:fs';
59
+ import { homedir } from 'node:os';
60
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
61
+
62
+ import { resolveProfile } from '../../shell/profile.ts';
63
+
64
+ export type HostEnv = Readonly<Record<string, string | undefined>>;
65
+
66
+ const homeOf = (env: HostEnv) => (env.HOME && isAbsolute(env.HOME) ? env.HOME : homedir());
67
+
68
+ /** The person's own Codex home: `$CODEX_HOME` when absolute, else `~/.codex`. */
69
+ export function personCodexHome(env: HostEnv = process.env): string {
70
+ const c = env.CODEX_HOME;
71
+ return c && isAbsolute(c) ? resolve(c) : join(homeOf(env), '.codex');
72
+ }
73
+
74
+ /** The person's own Codex sign-in file (what Settings' Sign in writes). */
75
+ export function personCodexAuthFile(env: HostEnv = process.env): string {
76
+ return join(personCodexHome(env), 'auth.json');
77
+ }
78
+
79
+ /** The Maude-owned Codex home for the profile this process runs as. */
80
+ export function maudeCodexHomePath(env: HostEnv = process.env): string {
81
+ const { id } = resolveProfile(env as Record<string, string | undefined>, () => {});
82
+ const maude = join(homeOf(env), '.config', 'maude');
83
+ return id === 'default'
84
+ ? join(maude, 'agents', 'codex-home')
85
+ : join(maude, 'profiles', id, 'agents', 'codex-home');
86
+ }
87
+
88
+ /** Throws when the session folder has a `.codex` entry Codex would load as a trusted project layer. */
89
+ export function refuseProjectCodexConfig(projectRoot: string): void {
90
+ const p = join(resolve(projectRoot), '.codex');
91
+ let found = false;
92
+ try {
93
+ lstatSync(p);
94
+ found = true;
95
+ } catch (e) {
96
+ if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e;
97
+ }
98
+ if (found) {
99
+ throw new Error(
100
+ `This project has a Codex folder (${p}). Codex would load its MCP servers and settings outside the limits Maude sets, so Maude does not start Codex while it is there.`
101
+ );
102
+ }
103
+ }
104
+
105
+ /** Maude's config.toml for the chat's Codex. Deliberately empty of settings. */
106
+ export const MAUDE_CODEX_CONFIG_TOML = [
107
+ '# Written by Maude at every Studio chat start; edits here are replaced.',
108
+ "# The chat's Codex runs with this CODEX_HOME so that none of your own MCP servers, hooks,",
109
+ '# plugins or profiles from your Codex config start outside the sandbox. Your sign-in is shared',
110
+ '# through auth.json, a link to your own Codex home.',
111
+ '',
112
+ ].join('\n');
113
+
114
+ /** Config surfaces Codex reads from its home but never writes itself; removed at every spawn. */
115
+ export const CODEX_HOME_FOREIGN = ['hooks.json', 'AGENTS.md', 'AGENTS.override.md', 'rules'];
116
+
117
+ function assertOwnedDir(p: string, what: string) {
118
+ const st = lstatSync(p);
119
+ if (st.isSymbolicLink() || !st.isDirectory()) {
120
+ throw new Error(`Maude's Codex home: ${what} is not a plain folder (${p})`);
121
+ }
122
+ const uid = process.getuid?.();
123
+ if (uid !== undefined && st.uid !== uid) {
124
+ throw new Error(`Maude's Codex home: ${what} is not owned by this user (${p})`);
125
+ }
126
+ }
127
+
128
+ /** mkdir -p, creating every missing level owner-only. */
129
+ function mkdirsPrivate(p: string) {
130
+ try {
131
+ lstatSync(p);
132
+ return;
133
+ } catch {
134
+ /* missing */
135
+ }
136
+ mkdirsPrivate(dirname(p));
137
+ try {
138
+ mkdirSync(p, { mode: 0o700 });
139
+ } catch (e) {
140
+ if ((e as NodeJS.ErrnoException).code !== 'EEXIST') throw e;
141
+ }
142
+ }
143
+
144
+ export interface CodexHomeOptions {
145
+ /**
146
+ * S1 (M2) — a chat API key will be injected for this spawn: no auth.json link (Codex keeps the
147
+ * key login in its own 0600 file here). Default false.
148
+ */
149
+ apiKey?: boolean;
150
+ }
151
+
152
+ /** auth.json in Maude's Codex home when it is Codex's own plain file (an API-key login), else null. */
153
+ function ownLoginFile(home: string): string | null {
154
+ const f = join(home, 'auth.json');
155
+ try {
156
+ const st = lstatSync(f);
157
+ if (st.isDirectory()) throw new Error(`Maude's Codex home: auth.json is a folder (${f})`);
158
+ return st.isSymbolicLink() ? null : f;
159
+ } catch (e) {
160
+ if ((e as NodeJS.ErrnoException).code === 'ENOENT') return null;
161
+ throw e;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * S1 (M2) — the person removed the chat's Codex API key: delete the login Codex kept for it in
167
+ * Maude's Codex home (a plain auth.json). A link to the person's own sign-in is never touched, and
168
+ * nothing outside Maude's folder is. Best effort: the next spawn without a key removes it as well.
169
+ */
170
+ export function forgetCodexApiLogin(env: HostEnv = process.env): boolean {
171
+ try {
172
+ const home = maudeCodexHomePath(env);
173
+ if (!existsSync(home)) return false;
174
+ assertOwnedDir(home, 'the folder');
175
+ const f = ownLoginFile(home);
176
+ if (!f) return false;
177
+ unlinkSync(f);
178
+ return true;
179
+ } catch {
180
+ return false;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Make (or repair) the Maude-owned Codex home and return its path. Idempotent; safe to run for
186
+ * every spawn while other chats' Codex processes use the same folder (config.toml is replaced by
187
+ * rename, the link only when it is wrong).
188
+ */
189
+ export function ensureMaudeCodexHome(
190
+ env: HostEnv = process.env,
191
+ opts: CodexHomeOptions = {}
192
+ ): string {
193
+ const home = maudeCodexHomePath(env);
194
+ const target = personCodexAuthFile(env);
195
+ if (home === personCodexHome(env) || resolve(target) === resolve(home, 'auth.json')) {
196
+ throw new Error("Maude's Codex home: CODEX_HOME already points at Maude's own folder");
197
+ }
198
+ mkdirsPrivate(home);
199
+ assertOwnedDir(home, 'the folder');
200
+ chmodSync(home, 0o700);
201
+
202
+ const link = join(home, 'auth.json');
203
+ let current: string | null = null;
204
+ try {
205
+ const st = lstatSync(link);
206
+ if (st.isDirectory()) throw new Error(`Maude's Codex home: auth.json is a folder (${link})`);
207
+ current = st.isSymbolicLink() ? readlinkSync(link) : '';
208
+ } catch (e) {
209
+ if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e;
210
+ }
211
+ if (opts.apiKey) {
212
+ // S1 (M2) — never a link while a key is stored: Codex's key login must not write through it.
213
+ if (current !== null && current !== '') unlinkSync(link);
214
+ if (current === '') chmodSync(link, 0o600);
215
+ } else if (current !== target) {
216
+ // A plain file here is a key login left from a key that is gone: removed, then the link.
217
+ if (current !== null) unlinkSync(link);
218
+ symlinkSync(target, link);
219
+ }
220
+
221
+ for (const name of CODEX_HOME_FOREIGN) rmSync(join(home, name), { recursive: true, force: true });
222
+
223
+ const cfg = join(home, 'config.toml');
224
+ const tmp = join(home, `.config.toml.${process.pid}.${Date.now()}.tmp`);
225
+ writeFileSync(tmp, MAUDE_CODEX_CONFIG_TOML, { mode: 0o600 });
226
+ renameSync(tmp, cfg);
227
+ return home;
228
+ }