@mwillbanks/ast-mcp 0.2.2 → 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 -16
- 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 +346 -148
- package/src/helpers/ast-bro.ts +1 -7
- package/src/helpers/config.ts +7 -0
- package/src/helpers/installer.ts +8 -0
- package/src/helpers/mcp-schema.ts +98 -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 +110 -37
- package/src/runtime/file-read.ts +142 -14
- package/src/runtime/file-rename.ts +5 -2
- 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 +142 -44
- package/src/server.ts +2 -1
- package/src/tools/ast-bro.ts +196 -75
- package/src/tools/configuration.ts +450 -0
- package/src/tools/configured.ts +49 -21
- package/src/tools/files.ts +168 -61
- package/src/tools/index.ts +2 -0
- package/src/tools/lifecycle.ts +82 -38
- package/templates/AGENTS.md +13 -15
- package/templates/skills/ast-mcp/SKILL.md +28 -20
- package/templates/skills/ast-mcp/evals/evals.json +221 -9
- package/templates/skills/ast-mcp/evals/score.ts +80 -0
- package/templates/skills/ast-mcp/evals/semantic.ts +3 -1
- 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 +13 -7
- 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
|
@@ -4,8 +4,11 @@ import {
|
|
|
4
4
|
boundedFileBatch,
|
|
5
5
|
chattrSchema,
|
|
6
6
|
toolFailure,
|
|
7
|
+
toolOutputSchema,
|
|
8
|
+
toolSuccess,
|
|
7
9
|
} from "../helpers/mcp-schema";
|
|
8
10
|
import { patchFiles, writeFilesSafely } from "../patch/engine";
|
|
11
|
+
import { inspectFileCapabilitiesSafely } from "../runtime/file-capabilities";
|
|
9
12
|
import {
|
|
10
13
|
FILE_READ_MAX_BATCH,
|
|
11
14
|
FILE_READ_MAX_BYTES,
|
|
@@ -23,11 +26,38 @@ export default function registerFileTools(
|
|
|
23
26
|
const lineRange = z
|
|
24
27
|
.tuple([z.number().int().nonnegative(), z.number().int().positive()])
|
|
25
28
|
.describe("Zero-based, end-exclusive [start, end] line range");
|
|
26
|
-
const readTarget = z
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}));
|
|
31
61
|
const aiderBlock = z.object({
|
|
32
62
|
replace: z.string(),
|
|
33
63
|
search: z.string(),
|
|
@@ -47,24 +77,62 @@ export default function registerFileTools(
|
|
|
47
77
|
server.registerTool(
|
|
48
78
|
"file_read",
|
|
49
79
|
{
|
|
50
|
-
|
|
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.`,
|
|
51
87
|
inputSchema: z.object({
|
|
52
88
|
files: z.array(readTarget).min(1).max(FILE_READ_MAX_BATCH),
|
|
53
89
|
}),
|
|
54
|
-
|
|
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",
|
|
55
125
|
},
|
|
56
|
-
async ({
|
|
126
|
+
async ({ filePaths }, context) => {
|
|
57
127
|
try {
|
|
58
|
-
return {
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
],
|
|
67
|
-
};
|
|
128
|
+
return toolSuccess({
|
|
129
|
+
files: await execute(
|
|
130
|
+
{ filePaths },
|
|
131
|
+
() => inspectFileCapabilitiesSafely(filePaths),
|
|
132
|
+
context,
|
|
133
|
+
"file_capabilities",
|
|
134
|
+
),
|
|
135
|
+
});
|
|
68
136
|
} catch (error) {
|
|
69
137
|
return failure(error);
|
|
70
138
|
}
|
|
@@ -74,26 +142,29 @@ export default function registerFileTools(
|
|
|
74
142
|
server.registerTool(
|
|
75
143
|
"file_hash",
|
|
76
144
|
{
|
|
145
|
+
annotations: {
|
|
146
|
+
destructiveHint: false,
|
|
147
|
+
idempotentHint: true,
|
|
148
|
+
openWorldHint: false,
|
|
149
|
+
readOnlyHint: true,
|
|
150
|
+
},
|
|
77
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.`,
|
|
78
152
|
inputSchema: z.object({
|
|
79
153
|
filePaths: z.array(z.string()).min(1).max(FILE_READ_MAX_BATCH),
|
|
80
154
|
}),
|
|
155
|
+
outputSchema: toolOutputSchema,
|
|
81
156
|
title: "Hash Files Without Reading Content",
|
|
82
157
|
},
|
|
83
|
-
async ({ filePaths }) => {
|
|
158
|
+
async ({ filePaths }, context) => {
|
|
84
159
|
try {
|
|
85
|
-
return {
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
type: "text",
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
160
|
+
return toolSuccess({
|
|
161
|
+
files: await execute(
|
|
162
|
+
{ filePaths },
|
|
163
|
+
() => hashFilesSafely(filePaths),
|
|
164
|
+
context,
|
|
165
|
+
"file_hash",
|
|
166
|
+
),
|
|
167
|
+
});
|
|
97
168
|
} catch (error) {
|
|
98
169
|
return failure(error);
|
|
99
170
|
}
|
|
@@ -103,26 +174,31 @@ export default function registerFileTools(
|
|
|
103
174
|
server.registerTool(
|
|
104
175
|
"file_write",
|
|
105
176
|
{
|
|
177
|
+
annotations: {
|
|
178
|
+
destructiveHint: true,
|
|
179
|
+
idempotentHint: true,
|
|
180
|
+
openWorldHint: false,
|
|
181
|
+
readOnlyHint: false,
|
|
182
|
+
},
|
|
106
183
|
description:
|
|
107
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.",
|
|
108
185
|
inputSchema: boundedFileBatch(
|
|
109
186
|
writeTarget,
|
|
110
187
|
"file_write requires between 1 and 50 files",
|
|
111
188
|
),
|
|
189
|
+
outputSchema: toolOutputSchema,
|
|
112
190
|
title: "Write Files Safely",
|
|
113
191
|
},
|
|
114
|
-
async ({ files }) => {
|
|
192
|
+
async ({ files }, context) => {
|
|
115
193
|
try {
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
],
|
|
125
|
-
};
|
|
194
|
+
return toolSuccess(
|
|
195
|
+
await execute(
|
|
196
|
+
{ files },
|
|
197
|
+
() => writeFilesSafely(files),
|
|
198
|
+
context,
|
|
199
|
+
"file_write",
|
|
200
|
+
),
|
|
201
|
+
);
|
|
126
202
|
} catch (error) {
|
|
127
203
|
return failure(error);
|
|
128
204
|
}
|
|
@@ -132,33 +208,64 @@ export default function registerFileTools(
|
|
|
132
208
|
server.registerTool(
|
|
133
209
|
"file_patch",
|
|
134
210
|
{
|
|
211
|
+
annotations: {
|
|
212
|
+
destructiveHint: true,
|
|
213
|
+
idempotentHint: false,
|
|
214
|
+
openWorldHint: false,
|
|
215
|
+
readOnlyHint: false,
|
|
216
|
+
},
|
|
135
217
|
description:
|
|
136
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.",
|
|
137
219
|
inputSchema: boundedFileBatch(
|
|
138
|
-
z
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
+
}),
|
|
146
254
|
"file_patch requires between 1 and 50 files",
|
|
147
255
|
),
|
|
256
|
+
outputSchema: toolOutputSchema,
|
|
148
257
|
title: "Patch Files Through the Enforced State Machine",
|
|
149
258
|
},
|
|
150
|
-
async ({ files }) => {
|
|
259
|
+
async ({ files }, context) => {
|
|
151
260
|
try {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
{
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
],
|
|
161
|
-
};
|
|
261
|
+
return toolSuccess(
|
|
262
|
+
await execute(
|
|
263
|
+
{ files },
|
|
264
|
+
() => patchFiles(files),
|
|
265
|
+
context,
|
|
266
|
+
"file_patch",
|
|
267
|
+
),
|
|
268
|
+
);
|
|
162
269
|
} catch (error) {
|
|
163
270
|
return failure(error);
|
|
164
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
|
@@ -4,8 +4,14 @@ 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,6 +30,12 @@ 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
40
|
"Applies the shared chattr contract to multiple files in one declared files batch under deterministic locks.",
|
|
29
41
|
inputSchema: boundedFileBatch(
|
|
@@ -33,22 +45,31 @@ export default function registerLifecycleTools(
|
|
|
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 ({ files: 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,6 +110,12 @@ 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
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.",
|
|
81
121
|
inputSchema: boundedFileBatch(
|
|
@@ -85,20 +125,19 @@ export default function registerLifecycleTools(
|
|
|
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 ({ files }) => {
|
|
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,6 +146,12 @@ 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
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.",
|
|
112
157
|
inputSchema: boundedFileBatch(
|
|
@@ -116,20 +161,19 @@ export default function registerLifecycleTools(
|
|
|
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 ({ files }) => {
|
|
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
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
|
-
-
|
|
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 mutation tools accept a declared `files` object, are file-operation-root bounded, SHA-guarded where required, and
|
|
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
|
|