@mwillbanks/ast-mcp 0.2.1 → 0.3.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/CONTRIBUTING.md +13 -0
- package/README.md +18 -14
- package/dist/ast-mcp.js +183 -137
- package/dist/ast-mcp.js.map +58 -42
- package/package.json +17 -11
- package/src/ast-bro/capability.ts +20 -10
- package/src/ast-bro/tools.json +22 -2
- package/src/cli.ts +10 -7
- package/src/config-cli.ts +166 -19
- package/src/config-migrate.ts +223 -0
- package/src/config-registry.ts +321 -0
- package/src/config-schema-common.ts +81 -0
- package/src/config-v2-schema.ts +97 -0
- package/src/config.ts +375 -149
- package/src/helpers/ast-bro.ts +1 -7
- package/src/helpers/config.ts +12 -3
- package/src/helpers/installer.ts +8 -0
- package/src/helpers/mcp-schema.ts +105 -4
- package/src/host-smoke.ts +182 -0
- package/src/http.ts +8 -3
- package/src/installer-transport.ts +6 -4
- package/src/installer.ts +192 -51
- package/src/patch/engine.ts +555 -279
- package/src/patch/languages.ts +9 -0
- package/src/patch/strategy/aiderBlock.ts +110 -0
- package/src/patch/strategy/ast.ts +170 -0
- package/src/patch/strategy.ts +61 -0
- package/src/runtime/approval.ts +438 -0
- package/src/runtime/dependencies.ts +1 -1
- package/src/runtime/document-inspection.ts +78 -0
- package/src/runtime/file-capabilities.ts +250 -0
- package/src/runtime/file-delete.ts +122 -20
- package/src/runtime/file-read.ts +142 -14
- package/src/runtime/file-rename.ts +7 -6
- package/src/runtime/format.ts +65 -27
- package/src/runtime/path-policy.ts +557 -0
- package/src/runtime/path-utils.ts +40 -0
- package/src/runtime/paths.ts +204 -43
- package/src/server.ts +2 -1
- package/src/tools/ast-bro.ts +197 -76
- package/src/tools/configuration.ts +450 -0
- package/src/tools/configured.ts +49 -21
- package/src/tools/files.ts +177 -73
- package/src/tools/index.ts +2 -0
- package/src/tools/lifecycle.ts +89 -45
- package/templates/AGENTS.md +15 -17
- package/templates/skills/ast-mcp/SKILL.md +50 -34
- package/templates/skills/ast-mcp/evals/batch.evals.json +9 -9
- package/templates/skills/ast-mcp/evals/evals.json +221 -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 +87 -0
- package/templates/skills/ast-mcp/evals/semantic.test.ts +209 -28
- package/templates/skills/ast-mcp/evals/semantic.ts +151 -37
- package/templates/skills/ast-mcp/references/installation.md +12 -12
- package/templates/skills/ast-mcp/references/patch-state-machine.md +15 -14
- package/templates/skills/ast-mcp/references/tool-catalog.md +16 -10
- package/templates/skills/ast-mcp/scripts/check-install.ts +8 -17
- package/src/ast-bro/rewrite-capability.ts +0 -9
package/src/tools/files.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
boundedFileBatch,
|
|
5
|
+
chattrSchema,
|
|
6
|
+
toolFailure,
|
|
7
|
+
toolOutputSchema,
|
|
8
|
+
toolSuccess,
|
|
9
|
+
} from "../helpers/mcp-schema";
|
|
4
10
|
import { patchFiles, writeFilesSafely } from "../patch/engine";
|
|
11
|
+
import { inspectFileCapabilitiesSafely } from "../runtime/file-capabilities";
|
|
5
12
|
import {
|
|
6
13
|
FILE_READ_MAX_BATCH,
|
|
7
14
|
FILE_READ_MAX_BYTES,
|
|
@@ -19,11 +26,38 @@ export default function registerFileTools(
|
|
|
19
26
|
const lineRange = z
|
|
20
27
|
.tuple([z.number().int().nonnegative(), z.number().int().positive()])
|
|
21
28
|
.describe("Zero-based, end-exclusive [start, end] line range");
|
|
22
|
-
const readTarget = z
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const readTarget = z
|
|
30
|
+
.object({
|
|
31
|
+
filePath: z.string(),
|
|
32
|
+
language: z.string().min(1).optional(),
|
|
33
|
+
lines: lineRange.optional(),
|
|
34
|
+
maxBytes: z.number().int().positive().max(FILE_READ_MAX_BYTES).optional(),
|
|
35
|
+
mode: z.enum(["auto", "ast", "text"]).optional(),
|
|
36
|
+
range: z
|
|
37
|
+
.object({
|
|
38
|
+
end: z.number().int().positive(),
|
|
39
|
+
start: z.number().int().nonnegative(),
|
|
40
|
+
})
|
|
41
|
+
.strict()
|
|
42
|
+
.optional(),
|
|
43
|
+
selectors: z.array(z.string()).min(1).max(100).optional(),
|
|
44
|
+
symbols: z.array(z.string().min(1)).max(100).optional(),
|
|
45
|
+
})
|
|
46
|
+
.strict()
|
|
47
|
+
.refine(
|
|
48
|
+
(value) => !(value.lines && value.range),
|
|
49
|
+
"Use either range or lines, not both",
|
|
50
|
+
)
|
|
51
|
+
.refine(
|
|
52
|
+
(value) => !(value.selectors && value.symbols),
|
|
53
|
+
"Use selectors for structured documents or symbols for source files, not both",
|
|
54
|
+
)
|
|
55
|
+
.transform(({ range, ...value }) => ({
|
|
56
|
+
...value,
|
|
57
|
+
lines:
|
|
58
|
+
value.lines ??
|
|
59
|
+
(range ? ([range.start, range.end] as [number, number]) : undefined),
|
|
60
|
+
}));
|
|
27
61
|
const aiderBlock = z.object({
|
|
28
62
|
replace: z.string(),
|
|
29
63
|
search: z.string(),
|
|
@@ -39,37 +73,66 @@ export default function registerFileTools(
|
|
|
39
73
|
content: z.string(),
|
|
40
74
|
expectedSha256: z.string().length(64).optional(),
|
|
41
75
|
});
|
|
42
|
-
const boundedBatch = <T extends z.ZodType>(schema: T, label: string) =>
|
|
43
|
-
z
|
|
44
|
-
.record(z.string().min(1), schema)
|
|
45
|
-
.refine(
|
|
46
|
-
(value) =>
|
|
47
|
-
Object.keys(value).length > 0 &&
|
|
48
|
-
Object.keys(value).length <= FILE_READ_MAX_BATCH,
|
|
49
|
-
label,
|
|
50
|
-
);
|
|
51
76
|
|
|
52
77
|
server.registerTool(
|
|
53
78
|
"file_read",
|
|
54
79
|
{
|
|
55
|
-
|
|
80
|
+
annotations: {
|
|
81
|
+
destructiveHint: false,
|
|
82
|
+
idempotentHint: true,
|
|
83
|
+
openWorldHint: false,
|
|
84
|
+
readOnlyHint: true,
|
|
85
|
+
},
|
|
86
|
+
description: `Reads files using an agent-selected auto, ast, or text mode. AST mode returns a source map/requested symbols or RFC 6901-selected structured-document values; text mode returns a bounded slice. Each result includes capabilities and a streaming whole-file SHA-256. Text slices default to lines [0, 100] and are capped at ${FILE_READ_MAX_LINES} lines and ${FILE_READ_MAX_BYTES} bytes.`,
|
|
56
87
|
inputSchema: z.object({
|
|
57
88
|
files: z.array(readTarget).min(1).max(FILE_READ_MAX_BATCH),
|
|
58
89
|
}),
|
|
59
|
-
|
|
90
|
+
outputSchema: toolOutputSchema,
|
|
91
|
+
title: "Read Files as AST or Text",
|
|
92
|
+
},
|
|
93
|
+
async ({ files }, context) => {
|
|
94
|
+
try {
|
|
95
|
+
return toolSuccess({
|
|
96
|
+
files: await execute(
|
|
97
|
+
{ files },
|
|
98
|
+
() => readFilesSafely(files),
|
|
99
|
+
context,
|
|
100
|
+
"file_read",
|
|
101
|
+
),
|
|
102
|
+
});
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return failure(error);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
server.registerTool(
|
|
110
|
+
"file_capabilities",
|
|
111
|
+
{
|
|
112
|
+
annotations: {
|
|
113
|
+
destructiveHint: false,
|
|
114
|
+
idempotentHint: true,
|
|
115
|
+
openWorldHint: false,
|
|
116
|
+
readOnlyHint: true,
|
|
117
|
+
},
|
|
118
|
+
description:
|
|
119
|
+
"Reports the intrinsic and effective AST/text read, AST/Aider patch, and AST search capabilities for each file.",
|
|
120
|
+
inputSchema: z.object({
|
|
121
|
+
filePaths: z.array(z.string()).min(1).max(FILE_READ_MAX_BATCH),
|
|
122
|
+
}),
|
|
123
|
+
outputSchema: toolOutputSchema,
|
|
124
|
+
title: "Inspect File Capabilities",
|
|
60
125
|
},
|
|
61
|
-
async ({
|
|
126
|
+
async ({ filePaths }, context) => {
|
|
62
127
|
try {
|
|
63
|
-
return {
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
],
|
|
72
|
-
};
|
|
128
|
+
return toolSuccess({
|
|
129
|
+
files: await execute(
|
|
130
|
+
{ filePaths },
|
|
131
|
+
() => inspectFileCapabilitiesSafely(filePaths),
|
|
132
|
+
context,
|
|
133
|
+
"file_capabilities",
|
|
134
|
+
),
|
|
135
|
+
});
|
|
73
136
|
} catch (error) {
|
|
74
137
|
return failure(error);
|
|
75
138
|
}
|
|
@@ -79,26 +142,29 @@ export default function registerFileTools(
|
|
|
79
142
|
server.registerTool(
|
|
80
143
|
"file_hash",
|
|
81
144
|
{
|
|
145
|
+
annotations: {
|
|
146
|
+
destructiveHint: false,
|
|
147
|
+
idempotentHint: true,
|
|
148
|
+
openWorldHint: false,
|
|
149
|
+
readOnlyHint: true,
|
|
150
|
+
},
|
|
82
151
|
description: `Batches streaming whole-file SHA-256 calculations without loading file contents into memory. Use this for fresh patch hashes, including AST-capable files. Accepts up to ${FILE_READ_MAX_BATCH} paths.`,
|
|
83
152
|
inputSchema: z.object({
|
|
84
153
|
filePaths: z.array(z.string()).min(1).max(FILE_READ_MAX_BATCH),
|
|
85
154
|
}),
|
|
155
|
+
outputSchema: toolOutputSchema,
|
|
86
156
|
title: "Hash Files Without Reading Content",
|
|
87
157
|
},
|
|
88
|
-
async ({ filePaths }) => {
|
|
158
|
+
async ({ filePaths }, context) => {
|
|
89
159
|
try {
|
|
90
|
-
return {
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
type: "text",
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
};
|
|
160
|
+
return toolSuccess({
|
|
161
|
+
files: await execute(
|
|
162
|
+
{ filePaths },
|
|
163
|
+
() => hashFilesSafely(filePaths),
|
|
164
|
+
context,
|
|
165
|
+
"file_hash",
|
|
166
|
+
),
|
|
167
|
+
});
|
|
102
168
|
} catch (error) {
|
|
103
169
|
return failure(error);
|
|
104
170
|
}
|
|
@@ -108,26 +174,31 @@ export default function registerFileTools(
|
|
|
108
174
|
server.registerTool(
|
|
109
175
|
"file_write",
|
|
110
176
|
{
|
|
177
|
+
annotations: {
|
|
178
|
+
destructiveHint: true,
|
|
179
|
+
idempotentHint: true,
|
|
180
|
+
openWorldHint: false,
|
|
181
|
+
readOnlyHint: false,
|
|
182
|
+
},
|
|
111
183
|
description:
|
|
112
|
-
"Creates or replaces multiple files in one
|
|
113
|
-
inputSchema:
|
|
184
|
+
"Creates or replaces multiple files in one declared files batch. Existing files require a fresh expectedSha256 by default; safety.require_hash=false makes it optional, but any supplied hash is still verified.",
|
|
185
|
+
inputSchema: boundedFileBatch(
|
|
114
186
|
writeTarget,
|
|
115
187
|
"file_write requires between 1 and 50 files",
|
|
116
188
|
),
|
|
189
|
+
outputSchema: toolOutputSchema,
|
|
117
190
|
title: "Write Files Safely",
|
|
118
191
|
},
|
|
119
|
-
async (
|
|
192
|
+
async ({ files }, context) => {
|
|
120
193
|
try {
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
{
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
],
|
|
130
|
-
};
|
|
194
|
+
return toolSuccess(
|
|
195
|
+
await execute(
|
|
196
|
+
{ files },
|
|
197
|
+
() => writeFilesSafely(files),
|
|
198
|
+
context,
|
|
199
|
+
"file_write",
|
|
200
|
+
),
|
|
201
|
+
);
|
|
131
202
|
} catch (error) {
|
|
132
203
|
return failure(error);
|
|
133
204
|
}
|
|
@@ -137,31 +208,64 @@ export default function registerFileTools(
|
|
|
137
208
|
server.registerTool(
|
|
138
209
|
"file_patch",
|
|
139
210
|
{
|
|
211
|
+
annotations: {
|
|
212
|
+
destructiveHint: true,
|
|
213
|
+
idempotentHint: false,
|
|
214
|
+
openWorldHint: false,
|
|
215
|
+
readOnlyHint: false,
|
|
216
|
+
},
|
|
140
217
|
description:
|
|
141
|
-
"Patches multiple files in one
|
|
142
|
-
inputSchema:
|
|
143
|
-
z
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
218
|
+
"Patches multiple files in one declared files batch. Each value contains a patchStrategy, ordered aiderBlocks or astRules, and optional preview mode. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced. Preview runs the complete formatted operation without committing.",
|
|
219
|
+
inputSchema: boundedFileBatch(
|
|
220
|
+
z
|
|
221
|
+
.object({
|
|
222
|
+
aiderBlocks: z
|
|
223
|
+
.array(aiderBlock)
|
|
224
|
+
.max(FILE_READ_MAX_BATCH)
|
|
225
|
+
.optional(),
|
|
226
|
+
astRules: z.array(astRule).max(FILE_READ_MAX_BATCH).optional(),
|
|
227
|
+
chattr: chattr.optional(),
|
|
228
|
+
expectedSha256: z.string().length(64).optional(),
|
|
229
|
+
patchStrategy: z.enum(["ast", "aider_block"]).optional(),
|
|
230
|
+
preview: z.boolean().optional(),
|
|
231
|
+
previewReceipt: z.string().uuid().optional(),
|
|
232
|
+
})
|
|
233
|
+
.strict()
|
|
234
|
+
.superRefine((value, context) => {
|
|
235
|
+
if (
|
|
236
|
+
value.previewReceipt &&
|
|
237
|
+
(value.patchStrategy ||
|
|
238
|
+
value.aiderBlocks ||
|
|
239
|
+
value.astRules ||
|
|
240
|
+
value.preview)
|
|
241
|
+
)
|
|
242
|
+
context.addIssue({
|
|
243
|
+
code: "custom",
|
|
244
|
+
message:
|
|
245
|
+
"previewReceipt commit cannot include patch operations",
|
|
246
|
+
});
|
|
247
|
+
if (!value.previewReceipt && !value.patchStrategy)
|
|
248
|
+
context.addIssue({
|
|
249
|
+
code: "custom",
|
|
250
|
+
message:
|
|
251
|
+
"patchStrategy is required unless previewReceipt is supplied",
|
|
252
|
+
});
|
|
253
|
+
}),
|
|
151
254
|
"file_patch requires between 1 and 50 files",
|
|
152
255
|
),
|
|
256
|
+
outputSchema: toolOutputSchema,
|
|
153
257
|
title: "Patch Files Through the Enforced State Machine",
|
|
154
258
|
},
|
|
155
|
-
async (
|
|
259
|
+
async ({ files }, context) => {
|
|
156
260
|
try {
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
261
|
+
return toolSuccess(
|
|
262
|
+
await execute(
|
|
263
|
+
{ files },
|
|
264
|
+
() => patchFiles(files),
|
|
265
|
+
context,
|
|
266
|
+
"file_patch",
|
|
267
|
+
),
|
|
268
|
+
);
|
|
165
269
|
} catch (error) {
|
|
166
270
|
return failure(error);
|
|
167
271
|
}
|
package/src/tools/index.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
|
|
3
3
|
import registerAstBroTools from "./ast-bro";
|
|
4
|
+
import registerConfigurationTools from "./configuration";
|
|
4
5
|
import { configuredExecution } from "./configured";
|
|
5
6
|
import registerFileTools from "./files";
|
|
6
7
|
import registerLifecycleTools from "./lifecycle";
|
|
7
8
|
|
|
8
9
|
export default function (server: McpServer) {
|
|
9
10
|
const execute = configuredExecution(server);
|
|
11
|
+
registerConfigurationTools(server, execute);
|
|
10
12
|
registerFileTools(server, execute);
|
|
11
13
|
registerLifecycleTools(server, execute);
|
|
12
14
|
registerAstBroTools(server, execute);
|
package/src/tools/lifecycle.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
boundedFileBatch,
|
|
5
5
|
chattrSchema,
|
|
6
6
|
toolFailure,
|
|
7
|
+
toolOutputSchema,
|
|
8
|
+
toolSuccess,
|
|
7
9
|
} from "../helpers/mcp-schema";
|
|
8
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
applyFileChattr,
|
|
12
|
+
type FileChattr,
|
|
13
|
+
resultingFileChattr,
|
|
14
|
+
} from "../runtime/attributes";
|
|
9
15
|
import { deleteFilesSafely } from "../runtime/file-delete";
|
|
10
16
|
import { renameFilesSafely } from "../runtime/file-rename";
|
|
11
17
|
import { sha256 } from "../runtime/hash";
|
|
@@ -24,31 +30,46 @@ export default function registerLifecycleTools(
|
|
|
24
30
|
server.registerTool(
|
|
25
31
|
"file_chattr",
|
|
26
32
|
{
|
|
33
|
+
annotations: {
|
|
34
|
+
destructiveHint: true,
|
|
35
|
+
idempotentHint: true,
|
|
36
|
+
openWorldHint: false,
|
|
37
|
+
readOnlyHint: false,
|
|
38
|
+
},
|
|
27
39
|
description:
|
|
28
|
-
"Applies the shared chattr contract to multiple
|
|
29
|
-
inputSchema:
|
|
40
|
+
"Applies the shared chattr contract to multiple files in one declared files batch under deterministic locks.",
|
|
41
|
+
inputSchema: boundedFileBatch(
|
|
30
42
|
z.object({
|
|
31
43
|
chattr,
|
|
32
44
|
expectedSha256: z.string().length(64).optional(),
|
|
33
45
|
}),
|
|
34
46
|
"file_chattr requires between 1 and 50 files",
|
|
35
47
|
),
|
|
48
|
+
outputSchema: toolOutputSchema,
|
|
36
49
|
title: "Change File Attributes Safely",
|
|
37
50
|
},
|
|
38
|
-
async (requests) => {
|
|
51
|
+
async ({ files: requests }, context) => {
|
|
39
52
|
try {
|
|
40
|
-
const entries = await execute(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
request
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
const entries = await execute(
|
|
54
|
+
{ files: requests },
|
|
55
|
+
() =>
|
|
56
|
+
Promise.all(
|
|
57
|
+
Object.entries(requests).map(async ([inputPath, request]) => ({
|
|
58
|
+
filePath: await resolveWritablePath(inputPath),
|
|
59
|
+
request,
|
|
60
|
+
})),
|
|
61
|
+
),
|
|
62
|
+
context,
|
|
63
|
+
"file_chattr",
|
|
47
64
|
);
|
|
48
65
|
const files: Record<string, unknown> = {};
|
|
49
66
|
await withFileLocks(
|
|
50
67
|
entries.map(({ filePath }) => filePath),
|
|
51
68
|
async () => {
|
|
69
|
+
const previous = new Map<
|
|
70
|
+
string,
|
|
71
|
+
Awaited<ReturnType<typeof resultingFileChattr>>
|
|
72
|
+
>();
|
|
52
73
|
for (const { filePath, request } of entries) {
|
|
53
74
|
if (request.expectedSha256) {
|
|
54
75
|
const actual = sha256(await Bun.file(filePath).text());
|
|
@@ -57,16 +78,29 @@ export default function registerLifecycleTools(
|
|
|
57
78
|
`Stale file context: expected ${request.expectedSha256}, found ${actual}`,
|
|
58
79
|
);
|
|
59
80
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
81
|
+
previous.set(filePath, await resultingFileChattr(filePath));
|
|
82
|
+
}
|
|
83
|
+
const applied: string[] = [];
|
|
84
|
+
try {
|
|
85
|
+
for (const { filePath, request } of entries) {
|
|
86
|
+
files[filePath] = {
|
|
87
|
+
chattr: await applyFileChattr(
|
|
88
|
+
filePath,
|
|
89
|
+
request.chattr as FileChattr,
|
|
90
|
+
),
|
|
91
|
+
};
|
|
92
|
+
applied.push(filePath);
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
for (const filePath of applied.reverse())
|
|
96
|
+
try {
|
|
97
|
+
await applyFileChattr(filePath, previous.get(filePath));
|
|
98
|
+
} catch {}
|
|
99
|
+
throw error;
|
|
66
100
|
}
|
|
67
101
|
},
|
|
68
102
|
);
|
|
69
|
-
return
|
|
103
|
+
return toolSuccess({ files });
|
|
70
104
|
} catch (error) {
|
|
71
105
|
return failure(error);
|
|
72
106
|
}
|
|
@@ -76,29 +110,34 @@ export default function registerLifecycleTools(
|
|
|
76
110
|
server.registerTool(
|
|
77
111
|
"file_delete",
|
|
78
112
|
{
|
|
113
|
+
annotations: {
|
|
114
|
+
destructiveHint: true,
|
|
115
|
+
idempotentHint: false,
|
|
116
|
+
openWorldHint: false,
|
|
117
|
+
readOnlyHint: false,
|
|
118
|
+
},
|
|
79
119
|
description:
|
|
80
|
-
"Deletes files in one
|
|
81
|
-
inputSchema:
|
|
120
|
+
"Deletes files in one declared files batch after reference preflight and removes empty ancestor directories. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
121
|
+
inputSchema: boundedFileBatch(
|
|
82
122
|
z.object({
|
|
83
123
|
expectedSha256: z.string().length(64).optional(),
|
|
84
124
|
forceReferences: z.boolean().optional(),
|
|
85
125
|
}),
|
|
86
126
|
"file_delete requires between 1 and 50 files",
|
|
87
127
|
),
|
|
128
|
+
outputSchema: toolOutputSchema,
|
|
88
129
|
title: "Delete Files Safely",
|
|
89
130
|
},
|
|
90
|
-
async (
|
|
131
|
+
async ({ files }, context) => {
|
|
91
132
|
try {
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
],
|
|
101
|
-
};
|
|
133
|
+
return toolSuccess(
|
|
134
|
+
await execute(
|
|
135
|
+
{ files },
|
|
136
|
+
() => deleteFilesSafely(files),
|
|
137
|
+
context,
|
|
138
|
+
"file_delete",
|
|
139
|
+
),
|
|
140
|
+
);
|
|
102
141
|
} catch (error) {
|
|
103
142
|
return failure(error);
|
|
104
143
|
}
|
|
@@ -107,29 +146,34 @@ export default function registerLifecycleTools(
|
|
|
107
146
|
server.registerTool(
|
|
108
147
|
"file_rename",
|
|
109
148
|
{
|
|
149
|
+
annotations: {
|
|
150
|
+
destructiveHint: true,
|
|
151
|
+
idempotentHint: false,
|
|
152
|
+
openWorldHint: false,
|
|
153
|
+
readOnlyHint: false,
|
|
154
|
+
},
|
|
110
155
|
description:
|
|
111
|
-
"Renames files in one
|
|
112
|
-
inputSchema:
|
|
156
|
+
"Renames files in one declared files batch without overwriting destinations. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
|
|
157
|
+
inputSchema: boundedFileBatch(
|
|
113
158
|
z.object({
|
|
114
159
|
destination: z.string().min(1),
|
|
115
160
|
expectedSha256: z.string().length(64).optional(),
|
|
116
161
|
}),
|
|
117
162
|
"file_rename requires between 1 and 50 files",
|
|
118
163
|
),
|
|
164
|
+
outputSchema: toolOutputSchema,
|
|
119
165
|
title: "Rename Files Safely",
|
|
120
166
|
},
|
|
121
|
-
async (
|
|
167
|
+
async ({ files }, context) => {
|
|
122
168
|
try {
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
],
|
|
132
|
-
};
|
|
169
|
+
return toolSuccess(
|
|
170
|
+
await execute(
|
|
171
|
+
{ files },
|
|
172
|
+
() => renameFilesSafely(files),
|
|
173
|
+
context,
|
|
174
|
+
"file_rename",
|
|
175
|
+
),
|
|
176
|
+
);
|
|
133
177
|
} catch (error) {
|
|
134
178
|
return failure(error);
|
|
135
179
|
}
|
package/templates/AGENTS.md
CHANGED
|
@@ -5,20 +5,20 @@ CRITICAL INSTRUCTION: You are operating in an AST-isolated environment.
|
|
|
5
5
|
- Load and follow the `$ast-mcp` skill before exploring or changing repository files.
|
|
6
6
|
- You have zero permission to create, overwrite, patch, move, or delete files through direct editor tools, `apply_patch`, unified patches, shell utilities, or interpreter scripts.
|
|
7
7
|
- For repository structure, source, dependencies, callers, and exact file content, use only ast-mcp tools.
|
|
8
|
-
-
|
|
9
|
-
-
|
|
8
|
+
- Use `file_capabilities` when the supported read or patch methods are uncertain; `file_read`, `run`, and `file_patch` enforce the same result.
|
|
9
|
+
- `file_read.mode` is agent-selectable: `ast` returns a source map/requested symbols or RFC 6901-selected structured-document values, `text` returns a bounded slice, and `auto` prefers AST. Batch multiple files in one call.
|
|
10
10
|
- Use `file_hash` for fresh whole-file SHA-256 values without retrieving content.
|
|
11
11
|
- For new files, use only `file_write`.
|
|
12
|
-
- For existing files, call `file_hash` immediately before a guarded `file_patch`;
|
|
13
|
-
-
|
|
12
|
+
- For existing files, call `file_hash` immediately before a guarded `file_patch`; mutation tools declare a `files` property containing the path-keyed batch.
|
|
13
|
+
- The agent selects `file_patch.patchStrategy` per target from the effective methods reported by `file_capabilities`. Prefer `ast` for structural changes and `aider_block` for small exact text changes; parseable source commonly supports both.
|
|
14
14
|
|
|
15
15
|
## Available ast-mcp tools
|
|
16
16
|
|
|
17
|
-
File boundary: `file_hash`, `file_read`, `file_write`, `file_patch`, `file_chattr`, `file_delete`.
|
|
17
|
+
File boundary: `file_capabilities`, `file_hash`, `file_read`, `file_write`, `file_patch`, `file_chattr`, `file_delete`.
|
|
18
18
|
|
|
19
19
|
Code intelligence: `digest`, `map`, `show`, `search`, `find_related`, `surface`, `deps`, `reverse_deps`, `cycles`, `graph`, `callers`, `callees`, `trace`, `impact`, `context`, `implements`, `index`, `run`, `squeeze`.
|
|
20
20
|
|
|
21
|
-
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All
|
|
21
|
+
Call every intelligence tool directly by name. There is no proxy tool. Use `run` for bounded AST searches and previews. Direct `run` rewrites with `write: true` are a lower-level escape hatch for intentionally bounded cases; they remain first-match-per-file and are not the normal agent patch route. All mutation tools accept a declared `files` object, are file-operation-root bounded, SHA-guarded where required, and preflight the complete batch before committing any entry. In version 2, access outside the host baseline—including the OS temporary directory—requires an explicit top-level `[[paths]]` rule; legacy `safety.allow_temp_directory` and `safety.allow_any_path` apply only to version 1 configuration. `file_write` and `file_patch` share the `file_chattr` contract rather than independent chmod/chown keys; `file_delete` is the only directory cleanup capability and only removes empty ancestors after a successful file deletion.
|
|
22
22
|
|
|
23
23
|
## Forbidden mutation paths
|
|
24
24
|
|
|
@@ -32,16 +32,14 @@ Use ast-mcp intelligence tools as the primary repository search surface: `digest
|
|
|
32
32
|
|
|
33
33
|
## Required write workflow
|
|
34
34
|
|
|
35
|
-
1. Explore
|
|
36
|
-
2.
|
|
37
|
-
3.
|
|
38
|
-
4. Call
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
6. Use direct `run` with `rewrite` and `write: true` only when an intentionally bounded lower-level rewrite is required; do not use it instead of `file_patch` for normal agent edits.
|
|
44
|
-
7. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation and review the final diff without mutating through Git.
|
|
35
|
+
1. Explore with the smallest direct intelligence or `file_read` call; use `impact` before shared API changes and `file_capabilities` when method support is uncertain.
|
|
36
|
+
2. Select `file_read.mode` explicitly when intent matters. Select `file_patch.patchStrategy` per file: AST for structural edits, Aider for small exact text edits, subject to the reported effective capabilities.
|
|
37
|
+
3. Preview structural matches with `run({ pattern, paths, lang?, json: true })`, bounded to explicit paths. Use `file_patch` with `preview: true` for the full guarded and formatted dry-run contract of either strategy.
|
|
38
|
+
4. Call `file_hash({ filePaths })` immediately before a SHA-guarded patch.
|
|
39
|
+
5. Call one `file_patch({ files: { ... } })` batch with one fresh hash and matching ordered `astRules` or `aiderBlocks` per path. Each keyed path is locked and atomically committed once.
|
|
40
|
+
6. Use one `file_write({ files: { ... } })` batch for new files or permitted SHA-guarded whole-file replacement.
|
|
41
|
+
7. Use direct `run` with `rewrite` and `write: true` only when an intentionally bounded lower-level rewrite is required; do not use it instead of `file_patch` for normal agent edits.
|
|
42
|
+
8. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation and review the final diff without mutating through Git.
|
|
45
43
|
|
|
46
44
|
A stale hash, ambiguous Aider block, unexpected match count, capped run preview, capped file slice, dprint preflight failure, missing MCP, or lost MCP connection is a safe stop. Refresh `file_hash`, re-inspect through the correct route, or restore ast-mcp and rebuild the operation; never switch to a forbidden writer.
|
|
47
45
|
|
|
@@ -49,7 +47,7 @@ A stale hash, ambiguous Aider block, unexpected match count, capped run preview,
|
|
|
49
47
|
|
|
50
48
|
A JSON-RPC transport batch may contain requests and notifications. Stdio emits one framed response per request; live streamable HTTP uses SSE by default and emits one event per request. Notifications never receive responses. Preserve every request ID and do not assume the live HTTP response is a JSON array unless `enableJsonResponse` is configured.
|
|
51
49
|
|
|
52
|
-
`evals:measure` inventories direct MCP records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call.
|
|
50
|
+
`evals:measure` inventories direct MCP records and statically visible `tools.mcp__ast_mcp__*` calls inside top-level Codex `exec` source. Put exactly one `ast-mcp-eval:<id>` marker in the user evaluation prompt, or in a direct record input supplied by an evaluation harness, to associate following direct MCP records with that case. Marked nested `exec` evidence and multi-marker evidence fail closed because an outer result cannot prove each nested call. Scoring requires schema-relevant inputs, workspace-root compliance from transcript context, required sequencing, expected output evidence, fixture assertions, and a successful output bound to each direct call. Pass `--allow-any-path` and/or `--no-temp-directory` when the measured run used non-default file safety; scorer options are validated rather than inferred from layered project configuration.
|
|
53
51
|
|
|
54
52
|
## Missing MCP
|
|
55
53
|
|