@1agh/maude 0.56.0 → 0.58.0

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 (58) hide show
  1. package/README.md +5 -1
  2. package/apps/studio/acp/bridge.ts +385 -26
  3. package/apps/studio/acp/index.ts +498 -102
  4. package/apps/studio/acp/running.ts +97 -0
  5. package/apps/studio/acp/transcript.ts +64 -0
  6. package/apps/studio/acp/write-scope.ts +459 -0
  7. package/apps/studio/api.ts +69 -4
  8. package/apps/studio/build.ts +28 -1
  9. package/apps/studio/client/app.jsx +187 -39
  10. package/apps/studio/client/panels/ChatPanel.jsx +19 -1
  11. package/apps/studio/client/panels/CloudBar.jsx +72 -13
  12. package/apps/studio/client/panels/PermissionPrompt.jsx +146 -6
  13. package/apps/studio/client/panels/RepoBranchSwitcher.jsx +145 -6
  14. package/apps/studio/client/panels/acp-runtime.js +96 -5
  15. package/apps/studio/client/panels/chat-markdown.jsx +76 -5
  16. package/apps/studio/client/panels/file-preview.jsx +115 -0
  17. package/apps/studio/client/styles/3-shell-maude.css +56 -2
  18. package/apps/studio/client/styles/6-acp-chat.css +79 -0
  19. package/apps/studio/dist/client.bundle.js +1436 -1436
  20. package/apps/studio/dist/comment-mount.js +2 -2
  21. package/apps/studio/dist/styles.css +1 -1
  22. package/apps/studio/http.ts +59 -2
  23. package/apps/studio/input-router.tsx +39 -1
  24. package/apps/studio/server.ts +11 -0
  25. package/apps/studio/sync/connection-state.ts +116 -6
  26. package/apps/studio/sync/index.ts +50 -1
  27. package/apps/studio/sync/presentation.ts +273 -0
  28. package/apps/studio/sync/remote-docs.ts +191 -0
  29. package/apps/studio/sync/status.ts +4 -1
  30. package/apps/studio/test/acp-activity-endpoint.test.ts +183 -0
  31. package/apps/studio/test/acp-branch-guard.test.ts +123 -0
  32. package/apps/studio/test/acp-bridge-lifetime.test.ts +369 -0
  33. package/apps/studio/test/acp-caps-bridge.test.ts +5 -0
  34. package/apps/studio/test/acp-commands.test.ts +5 -0
  35. package/apps/studio/test/acp-elicitation-bridge.test.ts +5 -0
  36. package/apps/studio/test/acp-permission-prompt.test.ts +175 -1
  37. package/apps/studio/test/acp-permission.test.ts +18 -2
  38. package/apps/studio/test/acp-session-allowed-tools.test.ts +62 -14
  39. package/apps/studio/test/acp-usage-bridge.test.ts +5 -0
  40. package/apps/studio/test/acp-write-gate.test.ts +323 -0
  41. package/apps/studio/test/acp-write-scope.test.ts +533 -0
  42. package/apps/studio/test/bundle-smoke.test.ts +35 -18
  43. package/apps/studio/test/canvas-origin-gate.test.ts +7 -0
  44. package/apps/studio/test/cloud-connect-note.test.ts +135 -0
  45. package/apps/studio/test/cloud-endpoints.test.ts +11 -4
  46. package/apps/studio/test/cloud-shell-surfaces.test.ts +5 -2
  47. package/apps/studio/test/config-version.test.ts +88 -0
  48. package/apps/studio/test/fixtures/mock-acp-agent-slow.mjs +45 -0
  49. package/apps/studio/test/fixtures/mock-acp-agent-write.mjs +118 -0
  50. package/apps/studio/test/input-router.test.ts +56 -0
  51. package/apps/studio/test/sync-connect-honesty.test.ts +114 -0
  52. package/apps/studio/test/sync-connection-state.test.ts +45 -1
  53. package/apps/studio/test/sync-presentation.test.ts +185 -0
  54. package/apps/studio/test/sync-remote-docs.test.ts +171 -0
  55. package/apps/studio/test/whats-new.test.ts +13 -1
  56. package/apps/studio/whats-new.json +27 -0
  57. package/apps/studio/whats-new.ts +34 -10
  58. package/package.json +8 -8
@@ -0,0 +1,323 @@
1
+ // feature-acp-write-path-scope — the gate proven END TO END through a real ACP
2
+ // round-trip (fixtures/mock-acp-agent-write.mjs replays the adapter's measured
3
+ // wire shape; see that file's header for where each field came from).
4
+ //
5
+ // acp-write-scope.test.ts covers the pure path logic. THIS file covers the part
6
+ // that logic cannot see:
7
+ // • the tool NAME arriving only on a prior `tool_call` notification, and the
8
+ // gate failing closed when it doesn't;
9
+ // • the in-project write producing NO client frame at all (the DDR-184
10
+ // regression guard — a prompt here is the user-visible bug this whole
11
+ // feature promised not to introduce);
12
+ // • Decision D — `allow_always` stripped from an out-of-project write, AND
13
+ // rejected if a crafted response names it anyway;
14
+ // • Task 11 — a session pinned to project A prompting for a write into
15
+ // project B while B is the "open" project.
16
+
17
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
18
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
19
+ import { tmpdir } from 'node:os';
20
+ import { join } from 'node:path';
21
+
22
+ import type { RequestPermissionRequest } from '@agentclientprotocol/sdk';
23
+
24
+ import { AcpBridge, type PermissionScopeInfo } from '../acp/bridge.ts';
25
+
26
+ const FIXTURE = join(import.meta.dir, 'fixtures', 'mock-acp-agent-write.mjs');
27
+ const TEST_ENV_KEYS = [
28
+ 'MAUDE_ACP_ADAPTER_ENTRY',
29
+ 'MAUDE_ACP_RUNTIME',
30
+ 'MAUDE_CLAUDE_BIN',
31
+ 'MAUDE_TEST_WRITE_PATH',
32
+ 'MAUDE_TEST_WRITE_TOOL',
33
+ 'MAUDE_TEST_OMIT_TOOL_CALL',
34
+ ];
35
+
36
+ let tmp: string;
37
+ let projectA: string;
38
+ let projectB: string;
39
+
40
+ beforeAll(() => {
41
+ // realpath the base — on macOS `/var` symlinks to `/private/var`, which would
42
+ // otherwise make every in-project case look like an escape.
43
+ tmp = realpathSync(mkdtempSync(join(tmpdir(), 'maude-write-gate-')));
44
+ projectA = join(tmp, 'project-a');
45
+ projectB = join(tmp, 'project-b');
46
+ mkdirSync(join(projectA, '.design', 'ui'), { recursive: true });
47
+ mkdirSync(projectB, { recursive: true });
48
+ writeFileSync(join(projectA, '.design', 'ui', 'home.tsx'), '// canvas\n');
49
+ });
50
+
51
+ afterAll(() => rmSync(tmp, { recursive: true, force: true }));
52
+
53
+ afterEach(() => {
54
+ for (const key of TEST_ENV_KEYS) delete process.env[key];
55
+ });
56
+
57
+ function useWriteAgent(opts: { path: string; tool?: string; omitToolCall?: boolean }) {
58
+ process.env.MAUDE_ACP_ADAPTER_ENTRY = FIXTURE;
59
+ process.env.MAUDE_ACP_RUNTIME = process.execPath;
60
+ process.env.MAUDE_CLAUDE_BIN = process.execPath;
61
+ process.env.MAUDE_TEST_WRITE_PATH = opts.path;
62
+ process.env.MAUDE_TEST_WRITE_TOOL = opts.tool ?? 'Write';
63
+ if (opts.omitToolCall) process.env.MAUDE_TEST_OMIT_TOOL_CALL = '1';
64
+ }
65
+
66
+ interface Captured {
67
+ id: string;
68
+ req: RequestPermissionRequest;
69
+ scope?: PermissionScopeInfo;
70
+ }
71
+
72
+ /** Run one turn against the fixture and report what the client SAW. `text` is
73
+ * the mock's echo of the outcome it received, which is the only proof of what
74
+ * the bridge actually answered the adapter. */
75
+ async function runTurn(repoRoot: string, autoRespond?: (c: Captured) => string) {
76
+ const prompts: Captured[] = [];
77
+ const transparency: RequestPermissionRequest[] = [];
78
+ const updates: Array<{ content?: { text?: string } }> = [];
79
+ const bridge = new AcpBridge({
80
+ repoRoot,
81
+ permissionTimeoutMs: 4000,
82
+ onUpdate: (u) => updates.push(u as { content?: { text?: string } }),
83
+ onPermission: (req) => transparency.push(req),
84
+ onPermissionRequest: (id, req, scope) => {
85
+ const c = { id, req, scope };
86
+ prompts.push(c);
87
+ if (autoRespond) bridge.resolvePermission(id, autoRespond(c));
88
+ },
89
+ });
90
+ try {
91
+ await bridge.prompt('go', 'c1');
92
+ return {
93
+ prompts,
94
+ transparency,
95
+ outcome: updates.map((u) => u?.content?.text ?? '').join(''),
96
+ scopeRoot: bridge.writeScopeRoot,
97
+ };
98
+ } finally {
99
+ await bridge.stop();
100
+ }
101
+ }
102
+
103
+ describe('write gate — in-project writes never prompt (DDR-184 regression guard)', () => {
104
+ test('Write to an existing in-project file is auto-approved with NO client frame', async () => {
105
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'home.tsx') });
106
+ const r = await runTurn(projectA);
107
+ // The load-bearing assertion of this entire feature's "no friction" half:
108
+ // zero prompts forwarded to the UI.
109
+ expect(r.prompts).toHaveLength(0);
110
+ expect(r.outcome).toContain('"outcome":"selected"');
111
+ // Auto-approval uses the ONCE-only option, never `allow_always` — the
112
+ // latter makes the adapter install a session-wide standing rule for the
113
+ // tool NAME, which would silently restore the unscoped Write grant this
114
+ // change removes, from inside the code that removed it.
115
+ expect(r.outcome).toContain('"optionId":"allow"');
116
+ expect(r.outcome).not.toContain('allow_always');
117
+ // Transparency still fires for EVERY request regardless of how it resolves
118
+ // — auto-approving must not make a write invisible to an audit consumer.
119
+ expect(r.transparency).toHaveLength(1);
120
+ }, 20000);
121
+
122
+ test('Write to a NEW in-project file is auto-approved', async () => {
123
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'brand-new.tsx') });
124
+ const r = await runTurn(projectA);
125
+ expect(r.prompts).toHaveLength(0);
126
+ expect(r.outcome).toContain('"outcome":"selected"');
127
+ }, 20000);
128
+
129
+ test('Edit is gated the same way as Write', async () => {
130
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'home.tsx'), tool: 'Edit' });
131
+ const r = await runTurn(projectA);
132
+ expect(r.prompts).toHaveLength(0);
133
+ }, 20000);
134
+
135
+ test('NotebookEdit — no `locations` at all — is judged via rawInput.notebook_path', async () => {
136
+ useWriteAgent({ path: join(projectA, 'nb.ipynb'), tool: 'NotebookEdit' });
137
+ const r = await runTurn(projectA);
138
+ expect(r.prompts).toHaveLength(0);
139
+ }, 20000);
140
+ });
141
+
142
+ describe('write gate — out-of-project writes prompt', () => {
143
+ test('an absolute escape prompts and names the RESOLVED path', async () => {
144
+ useWriteAgent({ path: join(projectB, 'stolen.conf') });
145
+ const r = await runTurn(projectA, () => 'reject');
146
+ expect(r.prompts).toHaveLength(1);
147
+ const { scope } = r.prompts[0];
148
+ expect(scope?.outOfProjectWrite).toBe(true);
149
+ expect(scope?.reason).toBe('outside');
150
+ expect(scope?.resolvedPaths).toEqual([join(projectB, 'stolen.conf')]);
151
+ expect(scope?.scopeRoot).toBe(projectA);
152
+ }, 20000);
153
+
154
+ test('a `../` escape prompts with the path RESOLVED, not as the model wrote it', async () => {
155
+ // `<projectA>/.design/../../project-b/stolen.conf` reads like a `.design`
156
+ // edit. Rendering the model's string is what makes the prompt useless.
157
+ const sneaky = join(projectA, '.design', '..', '..', 'project-b', 'stolen.conf');
158
+ useWriteAgent({ path: sneaky });
159
+ const r = await runTurn(projectA, () => 'reject');
160
+ expect(r.prompts).toHaveLength(1);
161
+ expect(r.prompts[0].scope?.resolvedPaths).toEqual([join(projectB, 'stolen.conf')]);
162
+ }, 20000);
163
+
164
+ test('DECISION D — `allow_always` is stripped from the offered options', async () => {
165
+ useWriteAgent({ path: join(projectB, 'stolen.conf') });
166
+ const r = await runTurn(projectA, () => 'reject');
167
+ const kinds = r.prompts[0].req.options.map((o) => o.kind);
168
+ expect(kinds).not.toContain('allow_always');
169
+ // The reject path must survive the filter, or the card would have no way out.
170
+ expect(kinds).toContain('reject_once');
171
+ expect(kinds).toContain('allow_once');
172
+ }, 20000);
173
+
174
+ test('DECISION D — a crafted response naming `allow_always` FAILS CLOSED', async () => {
175
+ // Filtering the option out of the UI is cosmetic on its own; the control is
176
+ // that `resolvePermission` validates against the same filtered set, so a
177
+ // hand-written WS frame can't pin the option that was never offered.
178
+ useWriteAgent({ path: join(projectB, 'stolen.conf') });
179
+ const r = await runTurn(projectA, () => 'allow_always');
180
+ expect(r.outcome).toContain('"outcome":"cancelled"');
181
+ expect(r.outcome).not.toContain('allow_always');
182
+ }, 20000);
183
+
184
+ test('an out-of-project write CAN still be approved per-call', async () => {
185
+ // The gate is a consent boundary, not a prohibition — proving the allow
186
+ // path works matters as much as proving the deny path does.
187
+ useWriteAgent({ path: join(projectB, 'stolen.conf') });
188
+ const r = await runTurn(projectA, () => 'allow');
189
+ expect(r.outcome).toContain('"optionId":"allow"');
190
+ }, 20000);
191
+ });
192
+
193
+ describe('write gate — fail-closed shapes', () => {
194
+ test('a MISSING `tool_call` notification (no tool name) prompts instead of auto-approving', async () => {
195
+ // The tool name has exactly one carrier. If a future adapter reorders or
196
+ // drops that notification, the gate must degrade to "the user is asked" —
197
+ // never to a silent allow. An in-project path is used deliberately: this
198
+ // proves the miss itself is what forces the prompt.
199
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'home.tsx'), omitToolCall: true });
200
+ const r = await runTurn(projectA, () => 'reject');
201
+ expect(r.prompts).toHaveLength(1);
202
+ // No `scope` — the gate never judged it as a write, so the client must NOT
203
+ // claim "outside this project" (it isn't; the name was simply unknown).
204
+ expect(r.prompts[0].scope).toBeUndefined();
205
+ }, 20000);
206
+
207
+ test('a READ tool with an out-of-project path is NOT treated as a write', async () => {
208
+ // Reads are deliberately unscoped (this change closes write egress, not
209
+ // read). Read isn't on the allow-list in this test's bridge either, so it
210
+ // prompts — but as an ORDINARY prompt, with no out-of-project write copy
211
+ // and no option filtering.
212
+ useWriteAgent({ path: join(projectB, 'secret.txt'), tool: 'Read' });
213
+ const r = await runTurn(projectA, () => 'reject');
214
+ expect(r.prompts).toHaveLength(1);
215
+ expect(r.prompts[0].scope).toBeUndefined();
216
+ expect(r.prompts[0].req.options.map((o) => o.kind)).toContain('allow_always');
217
+ }, 20000);
218
+ });
219
+
220
+ describe('write gate — Task 11: the scope is the session origin project', () => {
221
+ test('a session created under project A prompts for a write into project B', async () => {
222
+ // Today a bridge's lifetime IS one project's lifetime, so this reads as
223
+ // belt-and-braces. It is the Addendum's load-bearing invariant: once a
224
+ // session survives a project switch, a gate that re-reads "the open
225
+ // project" would hand A's session write access to B silently.
226
+ useWriteAgent({ path: join(projectB, 'canvas.tsx') });
227
+ const r = await runTurn(projectA, () => 'reject');
228
+ expect(r.prompts).toHaveLength(1);
229
+ expect(r.prompts[0].scope?.scopeRoot).toBe(projectA);
230
+ expect(r.scopeRoot).toBe(projectA);
231
+ }, 20000);
232
+
233
+ test('the pinned root is resolved once and exposed read-only', async () => {
234
+ useWriteAgent({ path: join(projectA, 'x.tsx') });
235
+ const bridge = new AcpBridge({ repoRoot: projectA, onUpdate: () => {} });
236
+ try {
237
+ expect(bridge.writeScopeRoot).toBe(projectA);
238
+ // No setter exists — the pin cannot be re-pointed at runtime, which is
239
+ // the whole mechanism behind Solution E.
240
+ expect(Object.getOwnPropertyDescriptor(bridge, 'writeScopeRoot')?.set).toBeUndefined();
241
+ } finally {
242
+ await bridge.stop();
243
+ }
244
+ });
245
+ });
246
+
247
+ describe('write gate — F2: granting is strict, warning is generous', () => {
248
+ test('an UNKNOWN-name out-of-project write still strips allow_always and names the path', async () => {
249
+ // SECURITY (security-auditor F2). The first cut coupled BOTH the grant and
250
+ // the hardening to the strict `WRITE_TOOL_NAMES` check, so a missed/evicted/
251
+ // reordered `tool_call` notification failed closed for the grant but OPEN
252
+ // for the hardening: no `scope` ⇒ `allow_always` was NOT stripped (one click
253
+ // installs a session-wide standing rule for Write — Decision D defeated) and
254
+ // the card fell back to the model's own `Write docs/../../../.zshenv`
255
+ // headline. The fixture omits the notification, so the name is genuinely
256
+ // unknown — exactly that state.
257
+ useWriteAgent({ path: join(projectB, 'stolen.conf'), omitToolCall: true });
258
+ const r = await runTurn(projectA, () => 'reject');
259
+ expect(r.prompts).toHaveLength(1);
260
+ const { scope, req } = r.prompts[0];
261
+ // Warned about, despite the unknown name …
262
+ expect(scope?.outOfProjectWrite).toBe(true);
263
+ expect(scope?.resolvedPaths).toEqual([join(projectB, 'stolen.conf')]);
264
+ // … and Decision D still enforced.
265
+ expect(req.options.map((o) => o.kind)).not.toContain('allow_always');
266
+ }, 20000);
267
+
268
+ test('an unknown name is still NEVER granted, even in-project', async () => {
269
+ // The other half of the asymmetry: generosity applies only to warning.
270
+ // Auto-approval still requires a confirmed write tool.
271
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'home.tsx'), omitToolCall: true });
272
+ const r = await runTurn(projectA, () => 'reject');
273
+ expect(r.prompts).toHaveLength(1);
274
+ // …and it must NOT claim "outside this project" — the file is inside; the
275
+ // NAME was the unknown. A false scope claim would be its own bug.
276
+ expect(r.prompts[0].scope).toBeUndefined();
277
+ }, 20000);
278
+
279
+ test('a READ of an out-of-project file is still NOT treated as a write', async () => {
280
+ // The heuristic is `kind:'edit'` / `notebook_path`, deliberately NOT "has a
281
+ // file_path" — Read carries one too, and would otherwise get the write copy
282
+ // plus a pointlessly stripped allow_always.
283
+ useWriteAgent({ path: join(projectB, 'secret.txt'), tool: 'Read', omitToolCall: true });
284
+ const r = await runTurn(projectA, () => 'reject');
285
+ expect(r.prompts[0].scope).toBeUndefined();
286
+ expect(r.prompts[0].req.options.map((o) => o.kind)).toContain('allow_always');
287
+ }, 20000);
288
+ });
289
+
290
+ describe('write gate — F6: `allow_always` is stripped from EVERY write-shaped card', () => {
291
+ test('an IN-PROJECT write-shaped card still offers no `allow_always`', async () => {
292
+ // SECURITY (security-auditor F6). The first cut tied the option filter to
293
+ // `info`, which is only set when the target is OUTSIDE the project. So an
294
+ // in-project write-shaped card that reached the prompt still offered
295
+ // `allow_always` — and selecting it makes the adapter install a
296
+ // `{type:'addRules', rules:[{toolName}]}` standing rule keyed by the tool
297
+ // NAME, carrying no path scope whatsoever. One click on an inside-the-
298
+ // project card therefore permanently permits every subsequent write by that
299
+ // tool, INCLUDING out-of-project ones: the whole gate, undone from the safe-
300
+ // looking side of it.
301
+ //
302
+ // `info` (copy — only truthful when outside) and `stripAlways` (control —
303
+ // needed whenever the call is write-shaped) are now separate.
304
+ //
305
+ // Reached via an unknown tool name so the call is write-SHAPED but not
306
+ // grantable, which is what puts an in-project write on a card at all.
307
+ useWriteAgent({ path: join(projectA, '.design', 'ui', 'home.tsx'), omitToolCall: true });
308
+ const r = await runTurn(projectA, () => 'reject');
309
+ expect(r.prompts).toHaveLength(1);
310
+ // No false "outside this project" claim — the file IS inside …
311
+ expect(r.prompts[0].scope).toBeUndefined();
312
+ // … and yet no standing-exemption option either.
313
+ expect(r.prompts[0].req.options.map((o) => o.kind)).not.toContain('allow_always');
314
+ }, 20000);
315
+
316
+ test('a NON-write tool keeps its `allow_always` — the strip is scoped to writes', async () => {
317
+ // Guard against over-correcting: stripping everywhere would quietly remove a
318
+ // legitimate affordance from every ordinary tool card.
319
+ useWriteAgent({ path: join(projectA, 'x.txt'), tool: 'Read', omitToolCall: true });
320
+ const r = await runTurn(projectA, () => 'reject');
321
+ expect(r.prompts[0].req.options.map((o) => o.kind)).toContain('allow_always');
322
+ }, 20000);
323
+ });