@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
@@ -6,8 +6,15 @@
6
6
  // visually-primary button resolves to — a seam no backend test could see.
7
7
 
8
8
  import { describe, expect, test } from 'bun:test';
9
+ import { createElement } from 'react';
10
+ import { renderToStaticMarkup } from 'react-dom/server';
9
11
 
10
- import { pickDefaultAllow, pickDefaultReject } from '../client/panels/PermissionPrompt.jsx';
12
+ import PermissionPrompt, {
13
+ describeOutOfProject,
14
+ pickDefaultAllow,
15
+ pickDefaultReject,
16
+ sanitizePathForDisplay,
17
+ } from '../client/panels/PermissionPrompt.jsx';
11
18
 
12
19
  describe('pickDefaultAllow', () => {
13
20
  test('prefers allow_once over allow_always, regardless of array order', () => {
@@ -75,3 +82,170 @@ describe('pickDefaultReject', () => {
75
82
  expect(pickDefaultReject(null)).toBeNull();
76
83
  });
77
84
  });
85
+
86
+ // feature-acp-write-path-scope Task 4 — the out-of-project WRITE card.
87
+ //
88
+ // Same reasoning as the pickDefaultAllow suite above: the affordance IS the
89
+ // security control. A card that renders the model's own path string, or that
90
+ // still offers an "always allow", is a speed bump rather than a gate — and
91
+ // neither failure is visible to any bridge-side test.
92
+ const OUT_OF_PROJECT = {
93
+ outOfProjectWrite: true,
94
+ resolvedPaths: ['/Users/x/.zshenv'],
95
+ scopeRoot: '/Users/x/git/project',
96
+ reason: 'outside',
97
+ };
98
+
99
+ describe('describeOutOfProject', () => {
100
+ test('absent scope → null (an ordinary permission card is unchanged)', () => {
101
+ expect(describeOutOfProject(undefined)).toBeNull();
102
+ expect(describeOutOfProject(null)).toBeNull();
103
+ // A scope object that isn't explicitly flagged must NOT trigger the copy —
104
+ // the discriminator is checked, not merely the object's presence.
105
+ expect(describeOutOfProject({ resolvedPaths: ['/etc/passwd'] })).toBeNull();
106
+ });
107
+
108
+ test('carries the resolved paths + root verbatim', () => {
109
+ const d = describeOutOfProject(OUT_OF_PROJECT);
110
+ expect(d?.paths).toEqual(['/Users/x/.zshenv']);
111
+ expect(d?.scopeRoot).toBe('/Users/x/git/project');
112
+ expect(d?.lead).toContain('outside this project');
113
+ });
114
+
115
+ test('plural lead for a multi-target write', () => {
116
+ const d = describeOutOfProject({ ...OUT_OF_PROJECT, resolvedPaths: ['/a', '/b'] });
117
+ expect(d?.lead).toContain('files outside this project');
118
+ });
119
+
120
+ test('the fail-closed reasons get their own honest copy, not "outside"', () => {
121
+ // `no-target` and `disagreement` are NOT "the file is outside the project" —
122
+ // saying so would be a claim the server never made. They are "we could not
123
+ // tell what will be written", which is a different thing to ask a human about.
124
+ expect(describeOutOfProject({ ...OUT_OF_PROJECT, reason: 'no-target' })?.lead).toContain(
125
+ 'did not say which one'
126
+ );
127
+ expect(describeOutOfProject({ ...OUT_OF_PROJECT, reason: 'disagreement' })?.lead).toContain(
128
+ 'two different files'
129
+ );
130
+ });
131
+
132
+ test('tolerates a malformed resolvedPaths — never throws', () => {
133
+ expect(describeOutOfProject({ outOfProjectWrite: true })?.paths).toEqual([]);
134
+ expect(
135
+ describeOutOfProject({ outOfProjectWrite: true, resolvedPaths: [null, '', '/ok'] })?.paths
136
+ ).toEqual(['/ok']);
137
+ });
138
+ });
139
+
140
+ describe('PermissionPrompt — render', () => {
141
+ const OPTIONS = [
142
+ { optionId: 'allow_always', kind: 'allow_always', name: 'Always Allow' },
143
+ { optionId: 'allow', kind: 'allow_once', name: 'Allow' },
144
+ { optionId: 'reject', kind: 'reject_once', name: 'Reject' },
145
+ ];
146
+ const render = (request) =>
147
+ renderToStaticMarkup(createElement(PermissionPrompt, { request, onRespond: () => {} }));
148
+
149
+ test('an ORDINARY request renders the generic copy and every offered option', () => {
150
+ const out = render({ id: '1', toolCall: { title: 'Run command' }, options: OPTIONS });
151
+ expect(out).toContain('Claude wants permission to continue');
152
+ expect(out).not.toContain('chat-perm-outside');
153
+ expect(out).toContain('Always Allow');
154
+ });
155
+
156
+ test('an OUT-OF-PROJECT write renders the RESOLVED path, never the model string', () => {
157
+ const out = render({
158
+ id: '1',
159
+ // `rawInput.file_path` is the model-authored string. It reads like a docs
160
+ // edit; only the resolution tells the truth, so the card must show the
161
+ // latter. Same lesson as the deep-link modal's truncated project name.
162
+ toolCall: {
163
+ title: 'Write docs/../../../.zshenv',
164
+ rawInput: { file_path: 'docs/../../../.zshenv' },
165
+ },
166
+ options: OPTIONS,
167
+ scope: OUT_OF_PROJECT,
168
+ });
169
+ expect(out).toContain('/Users/x/.zshenv');
170
+ expect(out).not.toContain('docs/../../../.zshenv');
171
+ expect(out).toContain('outside this project');
172
+ expect(out).toContain('/Users/x/git/project');
173
+ });
174
+
175
+ test('DECISION D — the out-of-project card offers NO "always" option', () => {
176
+ const out = render({
177
+ id: '1',
178
+ toolCall: { title: 'Write' },
179
+ options: OPTIONS,
180
+ scope: OUT_OF_PROJECT,
181
+ });
182
+ expect(out).not.toContain('Always Allow');
183
+ expect(out).toContain('Allow');
184
+ expect(out).toContain('Reject');
185
+ expect(out).toContain('for this request only');
186
+ });
187
+
188
+ test('the out-of-project card is distinguishable, not just differently worded', () => {
189
+ // A card that LOOKS identical to the routine one gets clicked through at the
190
+ // same rate, which is the whole prompt-fatigue failure mode.
191
+ const out = render({
192
+ id: '1',
193
+ toolCall: { title: 'Write' },
194
+ options: OPTIONS,
195
+ scope: OUT_OF_PROJECT,
196
+ });
197
+ expect(out).toContain('chat-perm--outside');
198
+ expect(out).toContain('file outside this project'); // aria-label
199
+ });
200
+ });
201
+
202
+ // SECURITY (security-auditor F3) — the resolved path's non-existent tail is
203
+ // whatever the model asked to create, so it is attacker-influenced text in the
204
+ // one card whose entire job is to be read accurately. React escapes markup; it
205
+ // does NOT neutralize bidi overrides, so a path can be made to READ as harmless
206
+ // while resolving somewhere else. Written as \u escapes on purpose: a literal
207
+ // override in this source would reorder the test file itself in every editor.
208
+ const RLO = '\u202E';
209
+ const PDF = '\u202C';
210
+
211
+ describe('sanitizePathForDisplay (F3)', () => {
212
+ test('neutralizes bidi overrides — the visual-spoofing primitive', () => {
213
+ const out = sanitizePathForDisplay(`/Users/x/safe/${RLO}gnp.esriv${PDF}`);
214
+ expect(out).not.toContain(RLO);
215
+ expect(out).not.toContain(PDF);
216
+ // Replaced, not deleted — a tampered path should look ODD, not just shorter.
217
+ expect(out).toContain('\uFFFD');
218
+ });
219
+
220
+ test('neutralizes C0 controls (newline/CR can hide a whole path segment)', () => {
221
+ const out = sanitizePathForDisplay('/Users/x/a\nb\rc');
222
+ expect(out).not.toMatch(/[\n\r]/);
223
+ });
224
+
225
+ test('also covers zero-width, directional marks and soft hyphen (F3 nit)', () => {
226
+ // Zero-width joiners and directional marks are invisible, so they can split
227
+ // or re-order a path name without leaving any visible trace at all — the
228
+ // same class of trick as the overrides, just quieter.
229
+ const sneaky = '/Users/x/\u200Bzsh\u200Cenv\u061C\u00AD';
230
+ const out = sanitizePathForDisplay(sneaky);
231
+ for (const ch of ['\u200B', '\u200C', '\u061C', '\u00AD']) {
232
+ expect(out).not.toContain(ch);
233
+ }
234
+ });
235
+
236
+ test('leaves an ordinary path completely untouched', () => {
237
+ const p = '/Users/x/git/project/.design/ui/home.tsx';
238
+ expect(sanitizePathForDisplay(p)).toBe(p);
239
+ });
240
+
241
+ test('describeOutOfProject sanitizes BOTH the paths and the scope root', () => {
242
+ const d = describeOutOfProject({
243
+ outOfProjectWrite: true,
244
+ reason: 'outside',
245
+ resolvedPaths: [`/Users/x/${RLO}evil`],
246
+ scopeRoot: `/Users/x/${RLO}root`,
247
+ });
248
+ expect(d.paths[0]).not.toContain(RLO);
249
+ expect(d.scopeRoot).not.toContain(RLO);
250
+ });
251
+ });
@@ -75,7 +75,14 @@ describe('AcpBridge — permission approve/deny (Task B1)', () => {
75
75
  const promptPromise = bridge.prompt('hi', 'c1');
76
76
  const req = await until(() => (requests.length ? requests[0] : undefined));
77
77
  expect(req.toolCallTitle).toBe('Write file');
78
- expect(req.optionIds).toEqual(['allow-once', 'allow-always', 'reject-once']);
78
+ // `allow-always` is ABSENT, and that is the point (feature-acp-write-path-
79
+ // scope Decision D + security-auditor F2). This fixture's tool call is
80
+ // `kind:'edit'` targeting `/tmp/x` — a write-shaped call landing OUTSIDE
81
+ // the bridge's project root — so the bridge strips every `allow_always`
82
+ // option before offering it, and validates any response against that same
83
+ // filtered set. Consent for an out-of-project write is per-call; one click
84
+ // must not be able to install a session-wide standing rule.
85
+ expect(req.optionIds).toEqual(['allow-once', 'reject-once']);
79
86
  expect(transparency.length).toBe(1); // transparency fires unconditionally too
80
87
 
81
88
  bridge.resolvePermission(req.id, 'allow-once');
@@ -191,7 +198,11 @@ describe('Acp manager — permission-request/-response frames (Task B2)', () =>
191
198
  const reqFrame = await until(() => a.frames.find((f) => f.t === 'permission-request'));
192
199
  expect(reqFrame.toolCall).toMatchObject({ title: 'Write file' });
193
200
  const options = reqFrame.options as Array<{ optionId: string }>;
194
- expect(options.map((o) => o.optionId)).toEqual(['allow-once', 'allow-always', 'reject-once']);
201
+ // See the Task B1 test above — `allow-always` is stripped for this
202
+ // out-of-project write-shaped call, and the FRAME carries the filtered
203
+ // set, so the client is shown the real options rather than a cosmetic
204
+ // subset the server would then reject.
205
+ expect(options.map((o) => o.optionId)).toEqual(['allow-once', 'reject-once']);
195
206
 
196
207
  acp.onMessage(
197
208
  a.ws,
@@ -200,6 +211,11 @@ describe('Acp manager — permission-request/-response frames (Task B2)', () =>
200
211
  await until(() => a.frames.find((f) => f.t === 'turn-end'));
201
212
  } finally {
202
213
  acp.onClose(a.ws);
214
+ // Task 8 — `onClose` DETACHES now; it no longer stops the bridge (that is
215
+ // the point: a page reload must not kill a running turn). So a test that
216
+ // relied on socket-close for teardown leaks the adapter subprocess for the
217
+ // whole DETACHED_TTL_MS. Tear down explicitly.
218
+ acp.stopAll();
203
219
  await new Promise((r) => setTimeout(r, 50));
204
220
  }
205
221
  }, 20000);
@@ -22,6 +22,11 @@
22
22
  // (3) `WebSearch`/`WebFetch` (DDR-185) are present as bare native tool names
23
23
  // — no prefix-matching involved, so no source-of-truth guard needed the
24
24
  // way the Bash rules need one.
25
+ // (4) NO WRITE TOOL is on this list (feature-acp-write-path-scope). This
26
+ // file used to assert the exact opposite — that Edit/Write/NotebookEdit
27
+ // WERE present — so read the test's own comment before "restoring" it.
28
+ // Write auto-approval moved into the bridge's path gate, which is the
29
+ // only place a per-call target path exists; see acp-write-scope.test.ts.
25
30
 
26
31
  import { describe, expect, test } from 'bun:test';
27
32
  import { existsSync, readFileSync, realpathSync } from 'node:fs';
@@ -29,6 +34,7 @@ import { dirname, join } from 'node:path';
29
34
 
30
35
  import { MAUDE_DEFAULT_ALLOWED_TOOLS, newSessionParams } from '../acp/bridge.ts';
31
36
  import type { SdkPluginConfig } from '../acp/plugin-bootstrap.ts';
37
+ import { WRITE_TOOL_NAMES } from '../acp/write-scope.ts';
32
38
 
33
39
  type Meta = {
34
40
  systemPrompt?: { append?: string };
@@ -73,12 +79,38 @@ describe('newSessionParams — allowedTools carrier shape (DDR-184)', () => {
73
79
  describe('MAUDE_DEFAULT_ALLOWED_TOOLS — source-of-truth guard (DDR-184 / DDR-062)', () => {
74
80
  const bashRules = MAUDE_DEFAULT_ALLOWED_TOOLS.filter((t) => t.startsWith('Bash'));
75
81
 
76
- test('the canvas-editing file tools are all present', () => {
77
- for (const t of ['Read', 'Edit', 'Write', 'Glob', 'Grep', 'NotebookEdit']) {
82
+ test('the READ-ONLY file tools are present', () => {
83
+ for (const t of ['Read', 'Glob', 'Grep']) {
78
84
  expect(MAUDE_DEFAULT_ALLOWED_TOOLS).toContain(t);
79
85
  }
80
86
  });
81
87
 
88
+ test('NO write tool is name-allowed — they are path-gated instead (feature-acp-write-path-scope)', () => {
89
+ // This assertion is the whole point of the change, so it is worth being
90
+ // explicit about WHY it inverts what this file used to assert.
91
+ //
92
+ // A bare tool name on this list means the CLI approves the call itself and
93
+ // `requestPermission` is NEVER invoked — so a path condition cannot be
94
+ // attached to an entry here, at all. Auto-approving a write therefore had
95
+ // to be moved into the bridge's own gate (`classifyWrite` →
96
+ // `writeTargetsInsideProject`), where a per-call path exists. DDR-184's
97
+ // no-prompt-per-edit outcome is fully preserved for in-project writes; what
98
+ // changed is that a write to `~/.zshenv` now prompts instead of landing
99
+ // silently with no rollback.
100
+ //
101
+ // If someone "fixes" a re-prompting regression by putting Write back on this
102
+ // list, this test is what tells them they just reopened the hole.
103
+ for (const t of [...WRITE_TOOL_NAMES]) {
104
+ expect(MAUDE_DEFAULT_ALLOWED_TOOLS).not.toContain(t);
105
+ }
106
+ // Guard the shape too — an `Edit(...)`-style scoped entry would also bypass
107
+ // the bridge gate, and `not.toContain` on the bare name would miss it.
108
+ for (const t of MAUDE_DEFAULT_ALLOWED_TOOLS) {
109
+ const bare = t.replace(/\(.*$/, '');
110
+ expect(WRITE_TOOL_NAMES.has(bare)).toBe(false);
111
+ }
112
+ });
113
+
82
114
  test('WebSearch and WebFetch are present (DDR-185)', () => {
83
115
  for (const t of ['WebSearch', 'WebFetch']) {
84
116
  expect(MAUDE_DEFAULT_ALLOWED_TOOLS).toContain(t);
@@ -98,18 +130,34 @@ describe('MAUDE_DEFAULT_ALLOWED_TOOLS — source-of-truth guard (DDR-184 / DDR-0
98
130
  // - `Bash(find:*)` must NEVER appear — `find -exec` is unrestricted
99
131
  // command execution, not "mutation"; there is no verb substitute, it
100
132
  // is simply cut.
101
- expect(bashRules).toEqual([
102
- 'Bash(maude:*)',
103
- 'Bash(ls:*)',
104
- 'Bash(cat:*)',
105
- 'Bash(pwd:*)',
106
- 'Bash(head:*)',
107
- 'Bash(tail:*)',
108
- 'Bash(wc:*)',
109
- 'Bash(tree:*)',
110
- 'Bash(file:*)',
111
- 'Bash(stat:*)',
112
- ]);
133
+ // - the read-only fs verb group must NEVER appear — every one of them
134
+ // accepts `>`, making the rule an arbitrary-write grant. See the
135
+ // dedicated test below.
136
+ expect(bashRules).toEqual(['Bash(maude:*)']);
137
+ });
138
+
139
+ test('NO redirect-capable bare-command Bash rule — `cat > file` is an arbitrary write (F1)', () => {
140
+ // SECURITY (security-auditor F1, PoC'd live against claude 2.1.220). The
141
+ // read-only fs group (ls/cat/pwd/head/tail/wc/tree/file/stat) USED to be on
142
+ // this list, justified as adding no incremental READ capability. True, and
143
+ // beside the point: Claude Code's `Bash(<cmd>:*)` prefix rule does not
144
+ // reject shell redirection, so `cat > ~/.zshenv <<'EOF' … EOF` matched
145
+ // `Bash(cat:*)`, was self-approved by the CLI, never reached
146
+ // `requestPermission`, and wrote model-authored arbitrary content to an
147
+ // arbitrary path — with no write tool involved at all. That is the A2
148
+ // primitive the write-path gate exists to close, reachable by a CHEAPER
149
+ // route than the write tools themselves.
150
+ //
151
+ // Cut rather than patched (same call DDR-185 made for `find` and
152
+ // `agent-browser`): a prefix rule cannot inspect what follows the command
153
+ // name, so there is nothing to patch. If they come back, they must come
154
+ // back as a hardened `maude design` wrapper verb, which CAN reject `>`.
155
+ //
156
+ // This test is what makes re-adding any of them a loud failure rather than
157
+ // a silent reopening of the hole.
158
+ for (const verb of ['ls', 'cat', 'pwd', 'head', 'tail', 'wc', 'tree', 'file', 'stat']) {
159
+ expect(MAUDE_DEFAULT_ALLOWED_TOOLS).not.toContain(`Bash(${verb}:*)`);
160
+ }
113
161
  });
114
162
 
115
163
  test('the `maude` Bash rule is load-bearing on DDR-062: every design helper is a `maude design <verb>`', () => {
@@ -130,6 +130,11 @@ describe('Acp manager — usage frame is cached + replayed on a fresh socket (Ta
130
130
  acp.onClose(b.ws);
131
131
  } finally {
132
132
  acp.onClose(a.ws);
133
+ // Task 8 — `onClose` DETACHES now; it no longer stops the bridge (that is
134
+ // the point: a page reload must not kill a running turn). So a test that
135
+ // relied on socket-close for teardown leaks the adapter subprocess for the
136
+ // whole DETACHED_TTL_MS. Tear down explicitly.
137
+ acp.stopAll();
133
138
  await new Promise((r) => setTimeout(r, 50));
134
139
  }
135
140
  }, 20000);