@mwillbanks/ast-mcp 0.2.0 → 0.2.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.
- package/README.md +3 -1
- package/dist/ast-mcp.js +76 -76
- package/dist/ast-mcp.js.map +13 -13
- package/package.json +1 -1
- package/src/config.ts +32 -4
- package/src/helpers/config.ts +5 -3
- package/src/helpers/mcp-schema.ts +7 -0
- package/src/installer.ts +37 -17
- package/src/runtime/file-delete.ts +33 -4
- package/src/runtime/file-rename.ts +2 -4
- package/src/runtime/paths.ts +85 -22
- package/src/service.ts +2 -4
- package/src/tools/ast-bro.ts +3 -3
- package/src/tools/files.ts +15 -18
- package/src/tools/lifecycle.ts +13 -13
- package/templates/AGENTS.md +5 -5
- package/templates/skills/ast-mcp/SKILL.md +31 -23
- package/templates/skills/ast-mcp/evals/batch.evals.json +9 -9
- package/templates/skills/ast-mcp/evals/measure.ts +27 -4
- package/templates/skills/ast-mcp/evals/score.test.ts +46 -3
- package/templates/skills/ast-mcp/evals/score.ts +7 -0
- package/templates/skills/ast-mcp/evals/semantic.test.ts +209 -28
- package/templates/skills/ast-mcp/evals/semantic.ts +148 -36
- package/templates/skills/ast-mcp/references/installation.md +1 -1
- package/templates/skills/ast-mcp/references/patch-state-machine.md +4 -4
- package/templates/skills/ast-mcp/references/tool-catalog.md +6 -6
- package/templates/skills/ast-mcp/scripts/check-install.ts +15 -25
|
@@ -1,6 +1,170 @@
|
|
|
1
1
|
import { expect, test } from "bun:test";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import { verifyEvaluation } from "./semantic";
|
|
3
5
|
|
|
6
|
+
test("semantic evaluator scopes declared batches and file-operation paths", () => {
|
|
7
|
+
const evaluation = {
|
|
8
|
+
assertions: ["Uses declared files property."],
|
|
9
|
+
expected_output: "verification output",
|
|
10
|
+
files: [],
|
|
11
|
+
forbidden_tools: [],
|
|
12
|
+
id: 97,
|
|
13
|
+
required_tools: ["file_write"],
|
|
14
|
+
};
|
|
15
|
+
const legacy = verifyEvaluation(
|
|
16
|
+
evaluation,
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
index: 0,
|
|
20
|
+
input: '{ files: {}, "/outside.ts": { content: "legacy" } }',
|
|
21
|
+
tool: "file_write",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
"verification output",
|
|
25
|
+
["/workspace"],
|
|
26
|
+
);
|
|
27
|
+
expect(legacy).toContain("file_write has empty or schema-incomplete input");
|
|
28
|
+
const nested = verifyEvaluation(
|
|
29
|
+
evaluation,
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
index: 0,
|
|
33
|
+
input:
|
|
34
|
+
'{ wrapper: { files: { "/outside.ts": { content: "nested" } } } }',
|
|
35
|
+
tool: "file_write",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
"verification output",
|
|
39
|
+
["/workspace"],
|
|
40
|
+
);
|
|
41
|
+
expect(nested).toContain("file_write has empty or schema-incomplete input");
|
|
42
|
+
|
|
43
|
+
for (const [tool, input] of [
|
|
44
|
+
[
|
|
45
|
+
"file_patch",
|
|
46
|
+
JSON.stringify({
|
|
47
|
+
files: {
|
|
48
|
+
"/workspace/file.ts": {
|
|
49
|
+
astRules: [{ fix: "new", pattern: "old" }],
|
|
50
|
+
expectedSha256: "a".repeat(64),
|
|
51
|
+
patchStrategy: "ast",
|
|
52
|
+
preview: true,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"file_delete",
|
|
59
|
+
JSON.stringify({
|
|
60
|
+
files: {
|
|
61
|
+
"/workspace/file.ts": {
|
|
62
|
+
expectedSha256: "a".repeat(64),
|
|
63
|
+
forceReferences: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
] as const) {
|
|
69
|
+
const ordered = verifyEvaluation(
|
|
70
|
+
{ ...evaluation, required_tools: [tool] },
|
|
71
|
+
[{ index: 0, input, tool }],
|
|
72
|
+
"verification output",
|
|
73
|
+
["/workspace"],
|
|
74
|
+
);
|
|
75
|
+
expect(ordered).not.toContain(
|
|
76
|
+
`${tool} has empty or schema-incomplete input`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const forceFirstBatch = `{"files":{"/outside-one.ts":{"forceReferences":true,"expectedSha256":"${"a".repeat(64)}"},"/outside-two.ts":{"forceReferences":true,"expectedSha256":"${"b".repeat(64)}"}}}`;
|
|
81
|
+
const batchErrors = verifyEvaluation(
|
|
82
|
+
{
|
|
83
|
+
...evaluation,
|
|
84
|
+
assertions: ["Uses one keyed batch."],
|
|
85
|
+
required_tools: ["file_delete"],
|
|
86
|
+
},
|
|
87
|
+
[{ index: 0, input: forceFirstBatch, tool: "file_delete" }],
|
|
88
|
+
"verification output",
|
|
89
|
+
["/workspace"],
|
|
90
|
+
);
|
|
91
|
+
expect(batchErrors).toContain(
|
|
92
|
+
"file_delete input escapes transcript file-operation roots: /outside-one.ts",
|
|
93
|
+
);
|
|
94
|
+
expect(batchErrors).toContain(
|
|
95
|
+
"file_delete input escapes transcript file-operation roots: /outside-two.ts",
|
|
96
|
+
);
|
|
97
|
+
expect(batchErrors).not.toContain(
|
|
98
|
+
"assertion not proven: Uses one keyed batch.",
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const previewFirstErrors = verifyEvaluation(
|
|
102
|
+
{ ...evaluation, required_tools: ["file_patch"] },
|
|
103
|
+
[
|
|
104
|
+
{
|
|
105
|
+
index: 0,
|
|
106
|
+
input: `{"files":{"/outside-preview.ts":{"preview":true,"expectedSha256":"${"a".repeat(64)}","patchStrategy":"ast","astRules":[{"pattern":"old","fix":"new"}]}}}`,
|
|
107
|
+
tool: "file_patch",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
"verification output",
|
|
111
|
+
["/workspace"],
|
|
112
|
+
);
|
|
113
|
+
expect(previewFirstErrors).toContain(
|
|
114
|
+
"file_patch input escapes transcript file-operation roots: /outside-preview.ts",
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const temporaryPath = path.join(os.tmpdir(), "ast-mcp-eval.ts");
|
|
118
|
+
expect(
|
|
119
|
+
verifyEvaluation(
|
|
120
|
+
evaluation,
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
index: 0,
|
|
124
|
+
input: JSON.stringify({
|
|
125
|
+
files: { [temporaryPath]: { content: "temporary" } },
|
|
126
|
+
}),
|
|
127
|
+
tool: "file_write",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
"verification output",
|
|
131
|
+
["/workspace"],
|
|
132
|
+
),
|
|
133
|
+
).toEqual([]);
|
|
134
|
+
expect(
|
|
135
|
+
verifyEvaluation(
|
|
136
|
+
evaluation,
|
|
137
|
+
[
|
|
138
|
+
{
|
|
139
|
+
index: 0,
|
|
140
|
+
input: JSON.stringify({
|
|
141
|
+
files: { "/etc/ast-mcp-eval.ts": { content: "unrestricted" } },
|
|
142
|
+
}),
|
|
143
|
+
tool: "file_write",
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
"verification output",
|
|
147
|
+
["/workspace"],
|
|
148
|
+
{ allowAnyPath: true },
|
|
149
|
+
),
|
|
150
|
+
).toEqual([]);
|
|
151
|
+
|
|
152
|
+
const astErrors = verifyEvaluation(
|
|
153
|
+
{
|
|
154
|
+
...evaluation,
|
|
155
|
+
assertions: [],
|
|
156
|
+
required_tools: ["map"],
|
|
157
|
+
},
|
|
158
|
+
[{ index: 0, input: '{ paths: ["/etc"] }', tool: "map" }],
|
|
159
|
+
"verification output",
|
|
160
|
+
["/workspace"],
|
|
161
|
+
{ allowAnyPath: true },
|
|
162
|
+
);
|
|
163
|
+
expect(astErrors).toContain(
|
|
164
|
+
"map input escapes transcript workspace roots: /etc",
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
4
168
|
const evaluation = {
|
|
5
169
|
assertions: ["Reports each source and destination result."],
|
|
6
170
|
expected_output: "reports each source and destination result",
|
|
@@ -17,7 +181,12 @@ test("rename evaluator accepts root-relative runtime results", () => {
|
|
|
17
181
|
{
|
|
18
182
|
index: 0,
|
|
19
183
|
input: JSON.stringify({
|
|
20
|
-
|
|
184
|
+
files: {
|
|
185
|
+
"source.txt": {
|
|
186
|
+
destination: "renamed.txt",
|
|
187
|
+
expectedSha256: "hash",
|
|
188
|
+
},
|
|
189
|
+
},
|
|
21
190
|
}),
|
|
22
191
|
tool: "file_rename",
|
|
23
192
|
},
|
|
@@ -42,13 +211,15 @@ test("rename evaluator rejects incomplete per-file results", () => {
|
|
|
42
211
|
{
|
|
43
212
|
index: 0,
|
|
44
213
|
input: JSON.stringify({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
214
|
+
files: {
|
|
215
|
+
"/tmp/ast-mcp-root/one.txt": {
|
|
216
|
+
destination: "/tmp/ast-mcp-root/one-new.txt",
|
|
217
|
+
expectedSha256: "hash",
|
|
218
|
+
},
|
|
219
|
+
"/tmp/ast-mcp-root/two.txt": {
|
|
220
|
+
destination: "/tmp/ast-mcp-root/two-new.txt",
|
|
221
|
+
expectedSha256: "hash",
|
|
222
|
+
},
|
|
52
223
|
},
|
|
53
224
|
}),
|
|
54
225
|
tool: "file_rename",
|
|
@@ -121,7 +292,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
121
292
|
),
|
|
122
293
|
).toEqual([]);
|
|
123
294
|
};
|
|
124
|
-
const patch = `{ "src/file.ts": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "ast", astRules: [{ pattern: "old", fix: "next", expectedMatches: 1 }], preview: true } }`;
|
|
295
|
+
const patch = `{ files: { "src/file.ts": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "ast", astRules: [{ pattern: "old", fix: "next", expectedMatches: 1 }], preview: true } } }`;
|
|
125
296
|
|
|
126
297
|
verify(
|
|
127
298
|
"Does not overwrite an existing destination.",
|
|
@@ -129,9 +300,11 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
129
300
|
invocation(
|
|
130
301
|
"file_rename",
|
|
131
302
|
JSON.stringify({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
303
|
+
files: {
|
|
304
|
+
"source.txt": {
|
|
305
|
+
destination: "destination.txt",
|
|
306
|
+
expectedSha256: "a".repeat(64),
|
|
307
|
+
},
|
|
135
308
|
},
|
|
136
309
|
}),
|
|
137
310
|
),
|
|
@@ -176,34 +349,42 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
176
349
|
[
|
|
177
350
|
"file_write",
|
|
178
351
|
JSON.stringify({
|
|
179
|
-
|
|
180
|
-
|
|
352
|
+
files: {
|
|
353
|
+
"src/a.ts": { content: "a" },
|
|
354
|
+
"src/b.ts": { content: "b" },
|
|
355
|
+
},
|
|
181
356
|
}),
|
|
182
357
|
],
|
|
183
358
|
[
|
|
184
359
|
"file_chattr",
|
|
185
360
|
JSON.stringify({
|
|
186
|
-
|
|
187
|
-
|
|
361
|
+
files: {
|
|
362
|
+
"src/a.ts": { chattr: { chmod: 384 } },
|
|
363
|
+
"src/b.ts": { chattr: { chmod: 384 } },
|
|
364
|
+
},
|
|
188
365
|
}),
|
|
189
366
|
],
|
|
190
367
|
[
|
|
191
368
|
"file_delete",
|
|
192
369
|
JSON.stringify({
|
|
193
|
-
|
|
194
|
-
|
|
370
|
+
files: {
|
|
371
|
+
"src/a.ts": { expectedSha256: "a".repeat(64) },
|
|
372
|
+
"src/b.ts": { expectedSha256: "b".repeat(64) },
|
|
373
|
+
},
|
|
195
374
|
}),
|
|
196
375
|
],
|
|
197
376
|
[
|
|
198
377
|
"file_rename",
|
|
199
378
|
JSON.stringify({
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
379
|
+
files: {
|
|
380
|
+
"src/a.ts": {
|
|
381
|
+
destination: "src/a-new.ts",
|
|
382
|
+
expectedSha256: "a".repeat(64),
|
|
383
|
+
},
|
|
384
|
+
"src/b.ts": {
|
|
385
|
+
destination: "src/b-new.ts",
|
|
386
|
+
expectedSha256: "b".repeat(64),
|
|
387
|
+
},
|
|
207
388
|
},
|
|
208
389
|
}),
|
|
209
390
|
],
|
|
@@ -214,7 +395,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
214
395
|
invocation("file_hash", '{ filePaths: ["src/a.ts"] }', 0),
|
|
215
396
|
invocation(
|
|
216
397
|
"file_write",
|
|
217
|
-
JSON.stringify({ "src/a.ts": { content: "next" } }),
|
|
398
|
+
JSON.stringify({ files: { "src/a.ts": { content: "next" } } }),
|
|
218
399
|
1,
|
|
219
400
|
),
|
|
220
401
|
]);
|
|
@@ -230,7 +411,7 @@ test("semantic evaluator proves every supported assertion shape", () => {
|
|
|
230
411
|
verify("Uses an Aider block.", [
|
|
231
412
|
invocation(
|
|
232
413
|
"file_patch",
|
|
233
|
-
`{ "README.md": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "aider_block", aiderBlocks: [{ search: "old", replace: "new" }] } }`,
|
|
414
|
+
`{ files: { "README.md": { expectedSha256: "${"a".repeat(64)}", patchStrategy: "aider_block", aiderBlocks: [{ search: "old", replace: "new" }] } } }`,
|
|
234
415
|
),
|
|
235
416
|
]);
|
|
236
417
|
verify("Reports verification output.", []);
|
|
@@ -275,7 +456,7 @@ test("semantic evaluator reports every validation failure class", () => {
|
|
|
275
456
|
"file_hash has empty or schema-incomplete input",
|
|
276
457
|
"required tool sequence is concurrent and cannot be proven",
|
|
277
458
|
"required tool sequence is not satisfied at: file_write",
|
|
278
|
-
"file_write input escapes transcript
|
|
459
|
+
"file_write input escapes transcript file-operation roots: /etc/out.txt",
|
|
279
460
|
"output does not prove file result: required.txt",
|
|
280
461
|
"expected output not proven: expected transport behavior",
|
|
281
462
|
"assertion not proven: Uses bounded lines.",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from "node:os";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { embeddedShellMutates, shellMutates } from "./shell-policy";
|
|
3
4
|
import { advanceQuote } from "./source";
|
|
@@ -114,20 +115,33 @@ function hasBoolean(input: string, key: string, value: boolean) {
|
|
|
114
115
|
|
|
115
116
|
type InputValidator = (input: string) => boolean;
|
|
116
117
|
|
|
117
|
-
const
|
|
118
|
+
const fileEntryKeyPattern =
|
|
119
|
+
"(?:aiderBlocks|astRules|chattr|content|destination|expectedSha256|forceReferences|patchStrategy|preview)";
|
|
120
|
+
const declaredFileBatchExpression = new RegExp(
|
|
121
|
+
`^\\s*(?:(?:await\\s+)?tools\\.mcp__ast_mcp__file_(?:chattr|delete|patch|rename|write)\\s*\\(\\s*)?\\{\\s*["']?files["']?\\s*:\\s*\\{\\s*["']([^"']+)["']\\s*:\\s*\\{\\s*["']?${fileEntryKeyPattern}["']?\\s*:`,
|
|
122
|
+
"s",
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const hasDeclaredFileBatch = (input: string) => {
|
|
126
|
+
declaredFileBatchExpression.lastIndex = 0;
|
|
127
|
+
return declaredFileBatchExpression.test(withoutComments(input));
|
|
128
|
+
};
|
|
118
129
|
const inputValidators: Record<string, InputValidator> = {
|
|
119
|
-
file_chattr: (input) =>
|
|
130
|
+
file_chattr: (input) =>
|
|
131
|
+
hasKey(input, "chattr") && hasDeclaredFileBatch(input),
|
|
120
132
|
file_delete: (input) =>
|
|
121
|
-
hasKey(input, "expectedSha256") &&
|
|
133
|
+
hasKey(input, "expectedSha256") && hasDeclaredFileBatch(input),
|
|
122
134
|
file_patch: (input) =>
|
|
123
135
|
hasKey(input, "expectedSha256") &&
|
|
124
136
|
hasKey(input, "patchStrategy") &&
|
|
137
|
+
hasDeclaredFileBatch(input) &&
|
|
125
138
|
(hasKey(input, "astRules") || hasKey(input, "aiderBlocks")),
|
|
126
139
|
file_rename: (input) =>
|
|
127
140
|
hasKey(input, "expectedSha256") &&
|
|
128
141
|
hasKey(input, "destination") &&
|
|
129
|
-
|
|
130
|
-
file_write: (input) =>
|
|
142
|
+
hasDeclaredFileBatch(input),
|
|
143
|
+
file_write: (input) =>
|
|
144
|
+
hasKey(input, "content") && hasDeclaredFileBatch(input),
|
|
131
145
|
};
|
|
132
146
|
|
|
133
147
|
function meaningfulInput(invocation: Invocation) {
|
|
@@ -154,8 +168,10 @@ const singlePathExpression =
|
|
|
154
168
|
/["']?(?:filePath|file|path|root|destination)["']?\s*:\s*["']([^"']+)["']/g;
|
|
155
169
|
const pathArrayExpression =
|
|
156
170
|
/["']?(?:filePaths|paths)["']?\s*:\s*\[([^\]]*)\]/gs;
|
|
157
|
-
const keyedPathExpression =
|
|
158
|
-
|
|
171
|
+
const keyedPathExpression = new RegExp(
|
|
172
|
+
`["']([^"']+)["']\\s*:\\s*\\{\\s*["']?${fileEntryKeyPattern}["']?\\s*:`,
|
|
173
|
+
"g",
|
|
174
|
+
);
|
|
159
175
|
|
|
160
176
|
function expressionValues(input: string, expression: RegExp) {
|
|
161
177
|
expression.lastIndex = 0;
|
|
@@ -184,18 +200,80 @@ function escapedPath(candidate: string, roots: string[]) {
|
|
|
184
200
|
return pathLike && !pathIsWithinRoot(candidate, roots);
|
|
185
201
|
}
|
|
186
202
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
203
|
+
const fileOperationTools = new Set([
|
|
204
|
+
"file_chattr",
|
|
205
|
+
"file_delete",
|
|
206
|
+
"file_hash",
|
|
207
|
+
"file_patch",
|
|
208
|
+
"file_read",
|
|
209
|
+
"file_rename",
|
|
210
|
+
"file_write",
|
|
211
|
+
]);
|
|
212
|
+
|
|
213
|
+
export interface FileOperationPolicy {
|
|
214
|
+
allowAnyPath?: boolean;
|
|
215
|
+
allowTempDirectory?: boolean;
|
|
216
|
+
roots?: string[];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface InvocationPathPolicy {
|
|
220
|
+
allowAnyPath: boolean;
|
|
221
|
+
boundary: string;
|
|
222
|
+
roots: string[];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function effectiveFileOperationRoots(
|
|
226
|
+
workspaceRoots: string[],
|
|
227
|
+
policy: FileOperationPolicy,
|
|
228
|
+
) {
|
|
229
|
+
if (policy.roots) return policy.roots;
|
|
230
|
+
return policy.allowTempDirectory === false
|
|
231
|
+
? workspaceRoots
|
|
232
|
+
: [...workspaceRoots, os.tmpdir()];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function invocationPathPolicy(
|
|
236
|
+
invocation: Invocation,
|
|
237
|
+
workspaceRoots: string[],
|
|
238
|
+
fileOperationPolicy: FileOperationPolicy,
|
|
239
|
+
): InvocationPathPolicy {
|
|
240
|
+
if (!fileOperationTools.has(invocation.tool))
|
|
241
|
+
return {
|
|
242
|
+
allowAnyPath: false,
|
|
243
|
+
boundary: "transcript workspace roots",
|
|
244
|
+
roots: workspaceRoots,
|
|
245
|
+
};
|
|
246
|
+
return {
|
|
247
|
+
allowAnyPath: fileOperationPolicy.allowAnyPath === true,
|
|
248
|
+
boundary: "transcript file-operation roots",
|
|
249
|
+
roots: effectiveFileOperationRoots(workspaceRoots, fileOperationPolicy),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function invocationPathErrors(
|
|
254
|
+
invocation: Invocation,
|
|
255
|
+
policy: InvocationPathPolicy,
|
|
256
|
+
) {
|
|
257
|
+
if (policy.allowAnyPath) return [];
|
|
258
|
+
return pathCandidates(withoutComments(invocation.input))
|
|
259
|
+
.filter((candidate) => escapedPath(candidate, policy.roots))
|
|
260
|
+
.map(
|
|
261
|
+
(candidate) =>
|
|
262
|
+
`${invocation.tool} input escapes ${policy.boundary}: ${candidate}`,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function pathErrors(
|
|
267
|
+
invocations: Invocation[],
|
|
268
|
+
workspaceRoots: string[],
|
|
269
|
+
fileOperationPolicy: FileOperationPolicy,
|
|
270
|
+
) {
|
|
271
|
+
return invocations.flatMap((invocation) =>
|
|
272
|
+
invocationPathErrors(
|
|
273
|
+
invocation,
|
|
274
|
+
invocationPathPolicy(invocation, workspaceRoots, fileOperationPolicy),
|
|
275
|
+
),
|
|
276
|
+
);
|
|
199
277
|
}
|
|
200
278
|
|
|
201
279
|
function isBatch(invocation: Invocation) {
|
|
@@ -208,8 +286,10 @@ function isBatch(invocation: Invocation) {
|
|
|
208
286
|
"file_delete",
|
|
209
287
|
"file_rename",
|
|
210
288
|
].includes(invocation.tool)
|
|
211
|
-
)
|
|
212
|
-
|
|
289
|
+
) {
|
|
290
|
+
keyedPathExpression.lastIndex = 0;
|
|
291
|
+
return expressionValues(input, keyedPathExpression).length > 1;
|
|
292
|
+
}
|
|
213
293
|
if (invocation.tool === "file_hash")
|
|
214
294
|
return /filePaths\s*:\s*\[[^\]]+,[^\]]+\]/s.test(input);
|
|
215
295
|
if (invocation.tool === "file_read")
|
|
@@ -247,11 +327,13 @@ function renameResultsCoverInputs(
|
|
|
247
327
|
roots: string[] = [],
|
|
248
328
|
) {
|
|
249
329
|
try {
|
|
250
|
-
const request = JSON.parse(call.input) as
|
|
330
|
+
const request = JSON.parse(call.input) as {
|
|
331
|
+
files?: Record<string, unknown>;
|
|
332
|
+
};
|
|
251
333
|
const result = JSON.parse(output) as { files?: RenameFiles };
|
|
252
|
-
if (!result.files) return false;
|
|
334
|
+
if (!request.files || !result.files) return false;
|
|
253
335
|
const workspaceRoot = roots[0] ?? process.cwd();
|
|
254
|
-
return Object.entries(request).every((entry) =>
|
|
336
|
+
return Object.entries(request.files).every((entry) =>
|
|
255
337
|
renameEntryMatches(result.files as RenameFiles, workspaceRoot, entry),
|
|
256
338
|
);
|
|
257
339
|
} catch {
|
|
@@ -393,23 +475,52 @@ function hashPrecedesMutation(context: AssertionContext) {
|
|
|
393
475
|
);
|
|
394
476
|
}
|
|
395
477
|
|
|
396
|
-
function
|
|
478
|
+
function declaredFileBatchAssertion(
|
|
479
|
+
context: AssertionContext,
|
|
480
|
+
): boolean | undefined {
|
|
397
481
|
const { invocations, normalized } = context;
|
|
482
|
+
if (!normalized.includes("declared") || !normalized.includes("files"))
|
|
483
|
+
return undefined;
|
|
484
|
+
const requireBatch = normalized.includes("batch");
|
|
485
|
+
return invocations.some(
|
|
486
|
+
(invocation) =>
|
|
487
|
+
[
|
|
488
|
+
"file_patch",
|
|
489
|
+
"file_write",
|
|
490
|
+
"file_chattr",
|
|
491
|
+
"file_delete",
|
|
492
|
+
"file_rename",
|
|
493
|
+
].includes(invocation.tool) &&
|
|
494
|
+
hasDeclaredFileBatch(invocation.input) &&
|
|
495
|
+
(!requireBatch || isBatch(invocation)),
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function previewAssertion(context: AssertionContext): boolean | undefined {
|
|
398
500
|
const patchCalls = calls(context, "file_patch");
|
|
501
|
+
if (context.normalized.includes("preview true"))
|
|
502
|
+
return patchCalls.some((call) => hasBoolean(call.input, "preview", true));
|
|
503
|
+
if (
|
|
504
|
+
!context.normalized.includes("preview") &&
|
|
505
|
+
!context.normalized.includes("dry run")
|
|
506
|
+
)
|
|
507
|
+
return undefined;
|
|
508
|
+
return (
|
|
509
|
+
calls(context, "run").some(
|
|
510
|
+
(call) => !hasBoolean(call.input, "write", true),
|
|
511
|
+
) || patchCalls.some((call) => hasBoolean(call.input, "preview", true))
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function workflowAssertion(context: AssertionContext): boolean | undefined {
|
|
516
|
+
const declaredBatch = declaredFileBatchAssertion(context);
|
|
517
|
+
if (declaredBatch !== undefined) return declaredBatch;
|
|
518
|
+
const { invocations, normalized } = context;
|
|
399
519
|
if (normalized.includes("batch") || normalized.includes("one keyed"))
|
|
400
520
|
return invocations.some(isBatch);
|
|
401
521
|
if (normalized.includes("fresh") && normalized.includes("hash"))
|
|
402
522
|
return hashPrecedesMutation(context);
|
|
403
|
-
|
|
404
|
-
return patchCalls.some((call) => hasBoolean(call.input, "preview", true));
|
|
405
|
-
if (normalized.includes("preview") || normalized.includes("dry run")) {
|
|
406
|
-
return (
|
|
407
|
-
calls(context, "run").some(
|
|
408
|
-
(call) => !hasBoolean(call.input, "write", true),
|
|
409
|
-
) || patchCalls.some((call) => hasBoolean(call.input, "preview", true))
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
return undefined;
|
|
523
|
+
return previewAssertion(context);
|
|
413
524
|
}
|
|
414
525
|
|
|
415
526
|
function strategyAssertion(context: AssertionContext): boolean | undefined {
|
|
@@ -561,11 +672,12 @@ export function verifyEvaluation(
|
|
|
561
672
|
invocations: Invocation[],
|
|
562
673
|
output: string,
|
|
563
674
|
roots: string[],
|
|
675
|
+
fileOperationPolicy: FileOperationPolicy = {},
|
|
564
676
|
) {
|
|
565
677
|
const errors = [
|
|
566
678
|
...toolContractErrors(evaluation, invocations),
|
|
567
679
|
...sequenceErrors(evaluation, invocations),
|
|
568
|
-
...pathErrors(invocations, roots),
|
|
680
|
+
...pathErrors(invocations, roots, fileOperationPolicy),
|
|
569
681
|
...fileEvidenceErrors(evaluation, invocations, output),
|
|
570
682
|
];
|
|
571
683
|
if (
|
|
@@ -56,6 +56,6 @@ The pinned `@ast-bro/cli@3.0.0` package has a precompiled binary only for macOS
|
|
|
56
56
|
2. Restart or reconnect MCP servers in the host; a skill file alone cannot make MCP tools callable. A supervised ast-mcp process may receive `SIGHUP`, which performs graceful cleanup and exits 0 so the host can restart it from refreshed code and configuration.
|
|
57
57
|
3. Confirm `file_hash`, `file_read`, `file_write`, and `file_patch` are present.
|
|
58
58
|
4. Confirm direct intelligence tools such as `digest`, `map`, `show`, `context`, and `impact` are present; there is no proxy tool.
|
|
59
|
-
5. Verify that `file_read` accepts batched `files`, `file_hash` accepts batched `filePaths`, and `
|
|
59
|
+
5. Verify that `file_read` accepts batched `files`, `file_hash` accepts batched `filePaths`, and every mutation tool accepts a declared `files` object containing path-keyed per-file operations; dictionary-only top-level mutation schemas and the legacy whole-file `file_read({ filePath })` schema are stale.
|
|
60
60
|
6. Rerun `check-install.ts` if the tool list remains incomplete.
|
|
61
61
|
7. If configuration is correct but startup fails, run the package's `bun run tools:check` from its checkout and report the missing dependency or startup error. Do not bypass the write boundary.
|
|
@@ -6,9 +6,9 @@ The server distinguishes AST inspection from structural rewrite support. AST-cap
|
|
|
6
6
|
|
|
7
7
|
1. Inspect AST-capable content with intelligence tools. Inspect unsupported content with batched, bounded `file_read` slices.
|
|
8
8
|
2. Preview every ordered structural rule with ast-bro `run`; for the full guarded and formatted dry run, use the same keyed `file_patch` entry with `preview: true`, then obtain one fresh `file_hash` per keyed path immediately before mutation.
|
|
9
|
-
3. Use one
|
|
10
|
-
4. Use one
|
|
11
|
-
5. Use `file_rename` with a fresh byte hash for root-bounded moves; preflight every source and destination, reject duplicate destinations, lock all endpoints, use no-replace moves, and roll back prior moves when a later move fails. The contract is recoverable on ordinary failures, not crash-atomic. Use `file_chattr` for metadata-only changes. Use `file_delete` with a fresh hash for deletion; it preflights all targets and AST import references before any deletion, rejects referenced source unless `forceReferences` is explicit, then removes empty ancestor directories after releasing locks. `safety.require_hash = false` makes hashes optional for patch, existing write, rename, and delete, but any supplied hash remains enforced.
|
|
9
|
+
3. Use one `file_patch({ files: { ... } })` object for one or more files. The declared `files` property contains path keys; each value has one `patchStrategy`, ordered `astRules` or `aiderBlocks` arrays, optional `preview`, and normally one fresh `expectedSha256`.
|
|
10
|
+
4. Use one `file_write({ files: { ... } })` object for new files or existing non-structurally-rewritable files; existing replacements normally receive their own fresh `expectedSha256`. Use the shared `chattr` object for chmod/chown metadata. Missing parents are created only after a guarded write returns `ENOENT`, followed by path revalidation.
|
|
11
|
+
5. Use `file_rename({ files: { ... } })` with a fresh byte hash for file-operation-root-bounded moves; preflight every source and destination, reject duplicate destinations, lock all endpoints, use no-replace moves, and roll back prior moves when a later move fails. The contract is recoverable on ordinary failures, not crash-atomic. Use `file_chattr` for metadata-only changes. Use `file_delete` with a fresh hash for deletion; it preflights all targets and AST import references before any deletion, rejects referenced source unless `forceReferences` is explicit, then removes empty ancestor directories after releasing locks. `safety.require_hash = false` makes hashes optional for patch, existing write, rename, and delete, but any supplied hash remains enforced.
|
|
12
12
|
6. Operations for one path are serialized under one lock and one atomic commit. A preview returns a bounded diff and leaves that path unchanged; a failed rule also leaves it unchanged.
|
|
13
13
|
7. Use direct `run` with `rewrite` and `write: true` only for an intentionally bounded lower-level rewrite; normal agent mutations belong to `file_patch`.
|
|
14
14
|
8. New files use `file_write`.
|
|
@@ -36,4 +36,4 @@ The native TypeScript matcher attempts exact, whitespace-normalized, relative-in
|
|
|
36
36
|
- `first match per file`: reduce file_patch to one match or use a bounded direct run across files.
|
|
37
37
|
- capped preview or read: narrow paths, glob, pattern, line ranges, or byte caps.
|
|
38
38
|
- formatter preflight failure: the selected external formatter or dprint fallback does not support the target; no write occurs. Formatting is skipped only when `[formatting].enabled = false`.
|
|
39
|
-
- path or symlink rejection: use a real path under an effective workspace root. Final symlinks are followed only when `safety.follow_symlinks = true`, and their resolved targets must remain root
|
|
39
|
+
- path or symlink rejection: use a real path under an effective workspace root or the OS temporary directory. Set `safety.allow_temp_directory = false` to remove the default temporary-directory allowance. `safety.allow_any_path = true` explicitly disables path protection for file tools. Final symlinks are followed only when `safety.follow_symlinks = true`, and their resolved targets must remain inside an allowed file-operation root unless unrestricted mode is enabled.
|
|
@@ -6,13 +6,13 @@ All tools are exposed directly by ast-mcp. Do not wrap ast-bro calls in a proxy
|
|
|
6
6
|
|
|
7
7
|
- `file_hash({ filePaths })`: batch up to 50 AST or non-AST paths and stream each whole file into SHA-256 without returning source content.
|
|
8
8
|
- `file_read({ files })`: batch up to 50 non-AST files. Each request accepts a zero-based, end-exclusive `lines` tuple and `maxBytes`; defaults are `[0, 100]` and 1 MiB, with hard caps of 1,000 lines and 1 MiB per slice. AST-capable files are rejected and routed to intelligence tools.
|
|
9
|
-
- `file_chattr({ "/repo/a.txt": { chattr, expectedSha256? } })`: applies the shared `chattr` contract (`chmod?`, same-owner `chown?`) under deterministic locks and reports the effective attributes.
|
|
10
|
-
- `file_write({ "/repo/a.txt": { content, chattr? }, "/repo/b.txt": { content, expectedSha256?, chattr? } })`: create or replace multiple files in one
|
|
11
|
-
- `file_patch({ "/repo/src/a.ts": { expectedSha256?, patchStrategy: "ast", astRules: [...], chattr? } })`: patch one or more files in one
|
|
12
|
-
- `file_rename({ "/repo/a.txt": { destination, expectedSha256? } })`: renames multiple regular files in one root-bounded batch, locks every source and destination, rejects cross-root and duplicate/existing destinations, uses no-replace moves, rolls back prior moves when a later move fails, and reports a per-file result. Crash-atomic recovery is not guaranteed.
|
|
13
|
-
- `file_delete({ "/repo/a.txt": { expectedSha256?, forceReferences? } })`: preflights all targets and AST import references before any deletion, rejects referenced source unless explicitly overridden, and removes empty ancestor directories within the
|
|
9
|
+
- `file_chattr({ files: { "/repo/a.txt": { chattr, expectedSha256? } } })`: applies the shared `chattr` contract (`chmod?`, same-owner `chown?`) under deterministic locks and reports the effective attributes.
|
|
10
|
+
- `file_write({ files: { "/repo/a.txt": { content, chattr? }, "/repo/b.txt": { content, expectedSha256?, chattr? } } })`: create or replace multiple files in one declared batch; existing replacements remain limited to non-AST-rewritable files. Missing parents are created only after the write attempt returns `ENOENT`, then the path is revalidated.
|
|
11
|
+
- `file_patch({ files: { "/repo/src/a.ts": { expectedSha256?, patchStrategy: "ast", astRules: [...], chattr? } } })`: patch one or more files in one declared batch. Use ordered `astRules` or `aiderBlocks`; every path has one atomic commit.
|
|
12
|
+
- `file_rename({ files: { "/repo/a.txt": { destination, expectedSha256? } } })`: renames multiple regular files in one file-operation-root-bounded batch, locks every source and destination, rejects cross-root and duplicate/existing destinations, uses no-replace moves, rolls back prior moves when a later move fails, and reports a per-file result. Crash-atomic recovery is not guaranteed.
|
|
13
|
+
- `file_delete({ files: { "/repo/a.txt": { expectedSha256?, forceReferences? } } })`: preflights all targets and AST import references before any deletion, rejects referenced source unless explicitly overridden, and removes empty ancestor directories within the allowed operation root.
|
|
14
14
|
- `expectedSha256` is required by the secure default for patch, existing-file write, rename, and delete. `safety.require_hash = false` makes it optional; supplied hashes are always verified.
|
|
15
|
-
-
|
|
15
|
+
- Mutation tools use a declared `files` input object and return a `files` result map. The OS temporary directory is allowed by default; configure `safety.allow_temp_directory = false` to disable it or `safety.allow_any_path = true` for explicit unrestricted file access. MCP transport also accepts JSON-RPC request/notification arrays and returns one response per request ID.
|
|
16
16
|
|
|
17
17
|
## Shape and source
|
|
18
18
|
|