@1agh/maude 0.56.0 → 0.57.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.
- package/apps/studio/acp/bridge.ts +385 -26
- package/apps/studio/acp/index.ts +498 -102
- package/apps/studio/acp/running.ts +97 -0
- package/apps/studio/acp/transcript.ts +64 -0
- package/apps/studio/acp/write-scope.ts +459 -0
- package/apps/studio/build.ts +28 -1
- package/apps/studio/client/app.jsx +47 -30
- package/apps/studio/client/panels/ChatPanel.jsx +19 -1
- package/apps/studio/client/panels/CloudBar.jsx +72 -13
- package/apps/studio/client/panels/PermissionPrompt.jsx +146 -6
- package/apps/studio/client/panels/RepoBranchSwitcher.jsx +145 -6
- package/apps/studio/client/panels/acp-runtime.js +96 -5
- package/apps/studio/client/styles/3-shell-maude.css +11 -2
- package/apps/studio/client/styles/6-acp-chat.css +51 -0
- package/apps/studio/dist/client.bundle.js +1278 -1278
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/http.ts +51 -2
- package/apps/studio/server.ts +11 -0
- package/apps/studio/sync/connection-state.ts +116 -6
- package/apps/studio/sync/index.ts +50 -1
- package/apps/studio/sync/presentation.ts +273 -0
- package/apps/studio/sync/remote-docs.ts +191 -0
- package/apps/studio/sync/status.ts +4 -1
- package/apps/studio/test/acp-activity-endpoint.test.ts +183 -0
- package/apps/studio/test/acp-branch-guard.test.ts +123 -0
- package/apps/studio/test/acp-bridge-lifetime.test.ts +369 -0
- package/apps/studio/test/acp-caps-bridge.test.ts +5 -0
- package/apps/studio/test/acp-commands.test.ts +5 -0
- package/apps/studio/test/acp-elicitation-bridge.test.ts +5 -0
- package/apps/studio/test/acp-permission-prompt.test.ts +175 -1
- package/apps/studio/test/acp-permission.test.ts +18 -2
- package/apps/studio/test/acp-session-allowed-tools.test.ts +62 -14
- package/apps/studio/test/acp-usage-bridge.test.ts +5 -0
- package/apps/studio/test/acp-write-gate.test.ts +323 -0
- package/apps/studio/test/acp-write-scope.test.ts +533 -0
- package/apps/studio/test/bundle-smoke.test.ts +35 -18
- package/apps/studio/test/canvas-origin-gate.test.ts +7 -0
- package/apps/studio/test/cloud-connect-note.test.ts +135 -0
- package/apps/studio/test/cloud-endpoints.test.ts +11 -4
- package/apps/studio/test/cloud-shell-surfaces.test.ts +5 -2
- package/apps/studio/test/fixtures/mock-acp-agent-slow.mjs +45 -0
- package/apps/studio/test/fixtures/mock-acp-agent-write.mjs +118 -0
- package/apps/studio/test/sync-connect-honesty.test.ts +114 -0
- package/apps/studio/test/sync-connection-state.test.ts +45 -1
- package/apps/studio/test/sync-presentation.test.ts +185 -0
- package/apps/studio/test/sync-remote-docs.test.ts +171 -0
- package/apps/studio/whats-new.json +18 -0
- package/package.json +8 -8
|
@@ -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
|
|
77
|
-
for (const t of ['Read', '
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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);
|
|
@@ -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
|
+
});
|