@mwillbanks/ast-mcp 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +71 -22
  2. package/dist/ast-mcp.js +301 -101
  3. package/dist/ast-mcp.js.map +107 -27
  4. package/package.json +3 -1
  5. package/src/ast-bro/capability.ts +3 -8
  6. package/src/ast-bro/client.ts +18 -2
  7. package/src/ast-bro/result.ts +5 -12
  8. package/src/cli.ts +112 -13
  9. package/src/config-cli.ts +54 -0
  10. package/src/config.ts +886 -0
  11. package/src/helpers/aider.ts +252 -0
  12. package/src/helpers/ast-bro.ts +64 -0
  13. package/src/helpers/config.ts +149 -0
  14. package/src/helpers/hook.ts +60 -0
  15. package/src/helpers/installer.ts +249 -0
  16. package/src/helpers/json.ts +19 -0
  17. package/src/helpers/mcp-schema.ts +31 -0
  18. package/src/helpers/process.ts +31 -0
  19. package/src/helpers/string.ts +97 -0
  20. package/src/hook.ts +135 -40
  21. package/src/http-entry.ts +1 -1
  22. package/src/http.ts +118 -103
  23. package/src/installer-transport.ts +190 -0
  24. package/src/installer.ts +596 -235
  25. package/src/mcp-cli.ts +104 -0
  26. package/src/patch/aider.ts +6 -199
  27. package/src/patch/engine.ts +271 -197
  28. package/src/runtime/dependencies.ts +161 -8
  29. package/src/runtime/file-delete.ts +13 -9
  30. package/src/runtime/file-read.ts +91 -57
  31. package/src/runtime/file-rename.ts +158 -0
  32. package/src/runtime/format.ts +57 -34
  33. package/src/runtime/paths.ts +30 -16
  34. package/src/runtime/policy.ts +21 -0
  35. package/src/runtime/process-input.ts +14 -4
  36. package/src/service.ts +219 -0
  37. package/src/shell-policy.ts +331 -0
  38. package/src/stdio.ts +47 -35
  39. package/src/tools/ast-bro.ts +12 -6
  40. package/src/tools/configured.ts +28 -0
  41. package/src/tools/files.ts +24 -27
  42. package/src/tools/index.ts +5 -3
  43. package/src/tools/lifecycle.ts +69 -55
  44. package/templates/skills/ast-mcp/SKILL.md +7 -6
  45. package/templates/skills/ast-mcp/evals/batch.evals.json +48 -0
  46. package/templates/skills/ast-mcp/evals/evals.json +1 -0
  47. package/templates/skills/ast-mcp/evals/score.test.ts +175 -0
  48. package/templates/skills/ast-mcp/evals/score.ts +304 -267
  49. package/templates/skills/ast-mcp/evals/semantic.test.ts +322 -0
  50. package/templates/skills/ast-mcp/evals/semantic.ts +390 -135
  51. package/templates/skills/ast-mcp/evals/shell-policy.ts +252 -0
  52. package/templates/skills/ast-mcp/evals/source.test.ts +46 -0
  53. package/templates/skills/ast-mcp/evals/source.ts +164 -0
  54. package/templates/skills/ast-mcp/evals/trigger-queries.json +1 -1
  55. package/templates/skills/ast-mcp/references/installation.md +24 -11
  56. package/templates/skills/ast-mcp/references/patch-state-machine.md +5 -5
  57. package/templates/skills/ast-mcp/references/tool-catalog.md +4 -2
  58. package/templates/skills/ast-mcp/scripts/check-install.ts +312 -110
package/src/stdio.ts CHANGED
@@ -68,43 +68,55 @@ export class BatchingStdioServerTransport implements Transport {
68
68
  });
69
69
  }
70
70
 
71
+ private takeLine() {
72
+ const newline = this.buffer.indexOf(10);
73
+ if (newline === -1) return;
74
+ const line = this.buffer
75
+ .subarray(0, newline)
76
+ .toString("utf8")
77
+ .replace(/\r$/, "");
78
+ this.buffer = this.buffer.subarray(newline + 1);
79
+ return line;
80
+ }
81
+
82
+ private deserializeItem(message: unknown) {
83
+ try {
84
+ return deserializeMessage(JSON.stringify(message));
85
+ } catch (error) {
86
+ this.reportInvalidRequest(
87
+ error instanceof Error ? error : new Error(String(error)),
88
+ );
89
+ }
90
+ }
91
+
92
+ private deserializeBatch(parsed: unknown) {
93
+ if (Array.isArray(parsed) && parsed.length === 0) {
94
+ this.reportInvalidRequest(
95
+ new Error("JSON-RPC batches must not be empty"),
96
+ );
97
+ return [];
98
+ }
99
+ return (Array.isArray(parsed) ? parsed : [parsed])
100
+ .map((message) => this.deserializeItem(message))
101
+ .filter((message): message is JSONRPCMessage => message !== undefined);
102
+ }
103
+
104
+ private processLine(line: string) {
105
+ try {
106
+ const messages = this.deserializeBatch(JSON.parse(line));
107
+ for (const message of messages) this.onmessage?.(message);
108
+ } catch (error) {
109
+ this.reportInvalidRequest(
110
+ error instanceof Error ? error : new Error(String(error)),
111
+ );
112
+ }
113
+ }
114
+
71
115
  private processReadBuffer() {
72
116
  while (true) {
73
- const newline = this.buffer.indexOf(10);
74
- if (newline === -1) return;
75
-
76
- const line = this.buffer
77
- .subarray(0, newline)
78
- .toString("utf8")
79
- .replace(/\r$/, "");
80
- this.buffer = this.buffer.subarray(newline + 1);
81
-
82
- try {
83
- const parsed: unknown = JSON.parse(line);
84
- if (Array.isArray(parsed) && parsed.length === 0) {
85
- this.reportInvalidRequest(
86
- new Error("JSON-RPC batches must not be empty"),
87
- );
88
- continue;
89
- }
90
- const messages = (Array.isArray(parsed) ? parsed : [parsed]).flatMap(
91
- (message) => {
92
- try {
93
- return [deserializeMessage(JSON.stringify(message))];
94
- } catch (error) {
95
- this.reportInvalidRequest(
96
- error instanceof Error ? error : new Error(String(error)),
97
- );
98
- return [];
99
- }
100
- },
101
- );
102
- for (const message of messages) this.onmessage?.(message);
103
- } catch (error) {
104
- this.reportInvalidRequest(
105
- error instanceof Error ? error : new Error(String(error)),
106
- );
107
- }
117
+ const line = this.takeLine();
118
+ if (line === undefined) return;
119
+ this.processLine(line);
108
120
  }
109
121
  }
110
122
 
@@ -15,6 +15,7 @@ import { replaceFileAtomically } from "../runtime/atomic";
15
15
  import { assertFormattable, formatFileAtomically } from "../runtime/format";
16
16
  import { withFileLocks } from "../runtime/locks";
17
17
  import { primaryRoot, resolveWritablePath } from "../runtime/paths";
18
+ import { type ConfiguredExecution, localExecution } from "./configured";
18
19
 
19
20
  function upstreamSchema(
20
21
  jsonSchema: Record<string, unknown>,
@@ -135,7 +136,10 @@ async function callAstBroWithFormatting(
135
136
  });
136
137
  }
137
138
 
138
- export default function registerAstBroTools(server: McpServer) {
139
+ export default function registerAstBroTools(
140
+ server: McpServer,
141
+ execute: ConfiguredExecution = localExecution,
142
+ ) {
139
143
  for (const toolName of AST_BRO_TOOLS) {
140
144
  const definition = metadata[toolName];
141
145
  server.registerTool(
@@ -150,11 +154,13 @@ export default function registerAstBroTools(server: McpServer) {
150
154
  },
151
155
  async (args) => {
152
156
  try {
153
- const root = await primaryRoot();
154
- await validateAstBroPaths(args, root);
155
- return toolName === "run"
156
- ? await callAstBroWithFormatting(args, root)
157
- : await callAstBro(toolName, args, root);
157
+ return await execute(args, async () => {
158
+ const root = await primaryRoot();
159
+ await validateAstBroPaths(args, root);
160
+ return toolName === "run"
161
+ ? await callAstBroWithFormatting(args, root)
162
+ : await callAstBro(toolName, args, root);
163
+ });
158
164
  } catch (error) {
159
165
  return {
160
166
  content: [
@@ -0,0 +1,28 @@
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
+ import { configRequestPaths, withConfig } from "../config";
3
+
4
+ export type ConfiguredExecution = <T>(
5
+ args: unknown,
6
+ operation: () => Promise<T>,
7
+ ) => Promise<T>;
8
+
9
+ export const localExecution: ConfiguredExecution = (args, operation) =>
10
+ withConfig({ requestPaths: configRequestPaths(args) }, operation);
11
+
12
+ export function configuredExecution(server: McpServer): ConfiguredExecution {
13
+ return async (args, operation) => {
14
+ const capabilities = server.server.getClientCapabilities();
15
+ const clientRoots = capabilities?.roots
16
+ ? await server.server
17
+ .listRoots()
18
+ .then(({ roots }) => roots.map((root) => root.uri))
19
+ : [];
20
+ return withConfig(
21
+ {
22
+ clientRoots,
23
+ requestPaths: configRequestPaths(args),
24
+ },
25
+ operation,
26
+ );
27
+ };
28
+ }
@@ -1,7 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import * as z from "zod/v4";
3
+ import { chattrSchema, toolFailure } from "../helpers/mcp-schema";
3
4
  import { patchFiles, writeFilesSafely } from "../patch/engine";
4
-
5
5
  import {
6
6
  FILE_READ_MAX_BATCH,
7
7
  FILE_READ_MAX_BYTES,
@@ -9,17 +9,13 @@ import {
9
9
  hashFilesSafely,
10
10
  readFilesSafely,
11
11
  } from "../runtime/file-read";
12
+ import { type ConfiguredExecution, localExecution } from "./configured";
12
13
 
13
- const failure = (error: unknown) => ({
14
- content: [
15
- {
16
- text: error instanceof Error ? error.message : String(error),
17
- type: "text" as const,
18
- },
19
- ],
20
- isError: true,
21
- });
22
- export default function registerFileTools(server: McpServer) {
14
+ const failure = toolFailure;
15
+ export default function registerFileTools(
16
+ server: McpServer,
17
+ execute: ConfiguredExecution = localExecution,
18
+ ) {
23
19
  const lineRange = z
24
20
  .tuple([z.number().int().nonnegative(), z.number().int().positive()])
25
21
  .describe("Zero-based, end-exclusive [start, end] line range");
@@ -37,15 +33,7 @@ export default function registerFileTools(server: McpServer) {
37
33
  fix: z.string(),
38
34
  pattern: z.string().min(1),
39
35
  });
40
- const chattr = z.object({
41
- chmod: z.number().int().min(0).max(0o777).optional(),
42
- chown: z
43
- .object({
44
- gid: z.number().int().nonnegative(),
45
- uid: z.number().int().nonnegative(),
46
- })
47
- .optional(),
48
- });
36
+ const chattr = chattrSchema;
49
37
  const writeTarget = z.object({
50
38
  chattr: chattr.optional(),
51
39
  content: z.string(),
@@ -75,7 +63,9 @@ export default function registerFileTools(server: McpServer) {
75
63
  return {
76
64
  content: [
77
65
  {
78
- text: JSON.stringify({ files: await readFilesSafely(files) }),
66
+ text: JSON.stringify({
67
+ files: await execute({ files }, () => readFilesSafely(files)),
68
+ }),
79
69
  type: "text",
80
70
  },
81
71
  ],
@@ -101,7 +91,9 @@ export default function registerFileTools(server: McpServer) {
101
91
  content: [
102
92
  {
103
93
  text: JSON.stringify({
104
- files: await hashFilesSafely(filePaths),
94
+ files: await execute({ filePaths }, () =>
95
+ hashFilesSafely(filePaths),
96
+ ),
105
97
  }),
106
98
  type: "text",
107
99
  },
@@ -117,7 +109,7 @@ export default function registerFileTools(server: McpServer) {
117
109
  "file_write",
118
110
  {
119
111
  description:
120
- "Creates or replaces multiple files in one keyed batch. Each key is a file path and each value contains content plus an optional fresh expectedSha256 for existing non-structurally-rewritable files.",
112
+ "Creates or replaces multiple files in one keyed batch. Existing files require a fresh expectedSha256 by default; safety.require_hash=false makes it optional, but any supplied hash is still verified.",
121
113
  inputSchema: boundedBatch(
122
114
  writeTarget,
123
115
  "file_write requires between 1 and 50 files",
@@ -129,7 +121,9 @@ export default function registerFileTools(server: McpServer) {
129
121
  return {
130
122
  content: [
131
123
  {
132
- text: JSON.stringify(await writeFilesSafely(args)),
124
+ text: JSON.stringify(
125
+ await execute(args, () => writeFilesSafely(args)),
126
+ ),
133
127
  type: "text",
134
128
  },
135
129
  ],
@@ -144,13 +138,13 @@ export default function registerFileTools(server: McpServer) {
144
138
  "file_patch",
145
139
  {
146
140
  description:
147
- "Patches multiple files in one keyed batch. Each key is a file path and each value contains one expectedSha256, a patchStrategy, ordered aiderBlocks or astRules, and optional preview mode. Preview runs the complete guarded operation and returns a bounded diff without committing.",
141
+ "Patches multiple files in one keyed 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.",
148
142
  inputSchema: boundedBatch(
149
143
  z.object({
150
144
  aiderBlocks: z.array(aiderBlock).max(FILE_READ_MAX_BATCH).optional(),
151
145
  astRules: z.array(astRule).max(FILE_READ_MAX_BATCH).optional(),
152
146
  chattr: chattr.optional(),
153
- expectedSha256: z.string().length(64),
147
+ expectedSha256: z.string().length(64).optional(),
154
148
  patchStrategy: z.enum(["ast", "aider_block"]),
155
149
  preview: z.boolean().optional(),
156
150
  }),
@@ -162,7 +156,10 @@ export default function registerFileTools(server: McpServer) {
162
156
  try {
163
157
  return {
164
158
  content: [
165
- { text: JSON.stringify(await patchFiles(args)), type: "text" },
159
+ {
160
+ text: JSON.stringify(await execute(args, () => patchFiles(args))),
161
+ type: "text",
162
+ },
166
163
  ],
167
164
  };
168
165
  } catch (error) {
@@ -1,11 +1,13 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/server";
2
2
 
3
3
  import registerAstBroTools from "./ast-bro";
4
+ import { configuredExecution } from "./configured";
4
5
  import registerFileTools from "./files";
5
6
  import registerLifecycleTools from "./lifecycle";
6
7
 
7
8
  export default function (server: McpServer) {
8
- registerFileTools(server);
9
- registerLifecycleTools(server);
10
- registerAstBroTools(server);
9
+ const execute = configuredExecution(server);
10
+ registerFileTools(server, execute);
11
+ registerLifecycleTools(server, execute);
12
+ registerAstBroTools(server, execute);
11
13
  }
@@ -1,61 +1,49 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import * as z from "zod/v4";
3
+ import {
4
+ boundedRecord,
5
+ chattrSchema,
6
+ toolFailure,
7
+ } from "../helpers/mcp-schema";
3
8
  import { applyFileChattr, type FileChattr } from "../runtime/attributes";
4
9
  import { deleteFilesSafely } from "../runtime/file-delete";
5
- import { FILE_READ_MAX_BATCH } from "../runtime/file-read";
10
+ import { renameFilesSafely } from "../runtime/file-rename";
6
11
  import { sha256 } from "../runtime/hash";
7
12
  import { withFileLocks } from "../runtime/locks";
8
13
  import { resolveWritablePath } from "../runtime/paths";
14
+ import { type ConfiguredExecution, localExecution } from "./configured";
9
15
 
10
- const chattr = z.object({
11
- chmod: z.number().int().min(0).max(0o777).optional(),
12
- chown: z
13
- .object({
14
- gid: z.number().int().nonnegative(),
15
- uid: z.number().int().nonnegative(),
16
- })
17
- .optional(),
18
- });
16
+ const chattr = chattrSchema;
19
17
 
20
- const failure = (error: unknown) => ({
21
- content: [
22
- {
23
- text: error instanceof Error ? error.message : String(error),
24
- type: "text" as const,
25
- },
26
- ],
27
- isError: true,
28
- });
18
+ const failure = toolFailure;
29
19
 
30
- export default function registerLifecycleTools(server: McpServer) {
20
+ export default function registerLifecycleTools(
21
+ server: McpServer,
22
+ execute: ConfiguredExecution = localExecution,
23
+ ) {
31
24
  server.registerTool(
32
25
  "file_chattr",
33
26
  {
34
27
  description:
35
28
  "Applies the shared chattr contract to multiple root-bounded files under deterministic locks.",
36
- inputSchema: z
37
- .record(
38
- z.string().min(1),
39
- z.object({
40
- chattr,
41
- expectedSha256: z.string().length(64).optional(),
42
- }),
43
- )
44
- .refine(
45
- (value) =>
46
- Object.keys(value).length > 0 &&
47
- Object.keys(value).length <= FILE_READ_MAX_BATCH,
48
- "file_chattr requires between 1 and 50 files",
49
- ),
29
+ inputSchema: boundedRecord(
30
+ z.object({
31
+ chattr,
32
+ expectedSha256: z.string().length(64).optional(),
33
+ }),
34
+ "file_chattr requires between 1 and 50 files",
35
+ ),
50
36
  title: "Change File Attributes Safely",
51
37
  },
52
38
  async (requests) => {
53
39
  try {
54
- const entries = await Promise.all(
55
- Object.entries(requests).map(async ([inputPath, request]) => ({
56
- filePath: await resolveWritablePath(inputPath),
57
- request,
58
- })),
40
+ const entries = await execute(requests, () =>
41
+ Promise.all(
42
+ Object.entries(requests).map(async ([inputPath, request]) => ({
43
+ filePath: await resolveWritablePath(inputPath),
44
+ request,
45
+ })),
46
+ ),
59
47
  );
60
48
  const files: Record<string, unknown> = {};
61
49
  await withFileLocks(
@@ -89,21 +77,14 @@ export default function registerLifecycleTools(server: McpServer) {
89
77
  "file_delete",
90
78
  {
91
79
  description:
92
- "Deletes hash-guarded files in one reference-preflighted batch and removes empty ancestor directories within configured roots.",
93
- inputSchema: z
94
- .record(
95
- z.string().min(1),
96
- z.object({
97
- expectedSha256: z.string().length(64),
98
- forceReferences: z.boolean().optional(),
99
- }),
100
- )
101
- .refine(
102
- (value) =>
103
- Object.keys(value).length > 0 &&
104
- Object.keys(value).length <= FILE_READ_MAX_BATCH,
105
- "file_delete requires between 1 and 50 files",
106
- ),
80
+ "Deletes files in one reference-preflighted batch 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
+ inputSchema: boundedRecord(
82
+ z.object({
83
+ expectedSha256: z.string().length(64).optional(),
84
+ forceReferences: z.boolean().optional(),
85
+ }),
86
+ "file_delete requires between 1 and 50 files",
87
+ ),
107
88
  title: "Delete Files Safely",
108
89
  },
109
90
  async (requests) => {
@@ -111,7 +92,40 @@ export default function registerLifecycleTools(server: McpServer) {
111
92
  return {
112
93
  content: [
113
94
  {
114
- text: JSON.stringify(await deleteFilesSafely(requests)),
95
+ text: JSON.stringify(
96
+ await execute(requests, () => deleteFilesSafely(requests)),
97
+ ),
98
+ type: "text",
99
+ },
100
+ ],
101
+ };
102
+ } catch (error) {
103
+ return failure(error);
104
+ }
105
+ },
106
+ );
107
+ server.registerTool(
108
+ "file_rename",
109
+ {
110
+ description:
111
+ "Renames files in one root-bounded batch without overwriting destinations. A fresh expectedSha256 is required by default; safety.require_hash=false makes it optional, but supplied hashes remain enforced.",
112
+ inputSchema: boundedRecord(
113
+ z.object({
114
+ destination: z.string().min(1),
115
+ expectedSha256: z.string().length(64).optional(),
116
+ }),
117
+ "file_rename requires between 1 and 50 files",
118
+ ),
119
+ title: "Rename Files Safely",
120
+ },
121
+ async (requests) => {
122
+ try {
123
+ return {
124
+ content: [
125
+ {
126
+ text: JSON.stringify(
127
+ await execute(requests, () => renameFilesSafely(requests)),
128
+ ),
115
129
  type: "text",
116
130
  },
117
131
  ],
@@ -30,15 +30,16 @@ Read [tool-catalog.md](references/tool-catalog.md) for exact arguments and combi
30
30
 
31
31
  1. Inspect AST-capable targets with `map`, `show`, `context`, or a bounded `run` search. For unsupported content, use one batched `file_read({ files: [...] })` call with narrow line ranges.
32
32
  2. Preview every AST rule with `run({ pattern, paths: [filePath], lang?, json: true })`; inspect all matches and reject capped output before mutation. For a contract-level dry run, send the same keyed `file_patch` entry with `preview: true`; it returns the formatted bounded diff and never commits.
33
- 3. Call one batched `file_hash({ filePaths: [...] })` immediately before guarded edits. Keep one returned hash per keyed path.
33
+ 3. Call one batched `file_hash({ filePaths: [...] })` immediately before guarded edits. Keep one returned hash per keyed path. The runtime can make hashes optional through `safety.require_hash = false`, but the normal agent workflow should still supply them whenever current-state protection matters.
34
34
  4. Use one path-keyed `file_patch` batch for one or more files:
35
35
  - AST targets: `{ expectedSha256, patchStrategy: "ast", astRules: [{ pattern, fix, expectedMatches: 1 }], preview?: boolean }`
36
36
  - Unsupported targets: `{ expectedSha256, patchStrategy: "aider_block", aiderBlocks: [{ search, replace }], preview?: boolean }`
37
37
  Operations in each array run in order under one file lock; preview returns without committing and normal mode commits atomically.
38
38
  5. Use one path-keyed `file_write` batch for new files or SHA-guarded replacement of existing non-structurally-rewritable files. Supply the shared `chattr` object when chmod/chown metadata is required; missing parents are created only after a guarded `ENOENT` write and path revalidation.
39
- 6. Use `file_chattr` for metadata-only changes. Use hash-guarded `file_delete` for deletion; it preflights all targets and AST import references before any deletion, requires an explicit `forceReferences` override for referenced source, and removes empty ancestor directories after lock release.
40
- 7. Use direct `run` with `rewrite` and `write: true` only for an intentionally bounded lower-level rewrite; it is not the normal agent patch route and still rewrites only the first match per file.
41
- 8. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation.
39
+ 6. Use one path-keyed `file_rename` batch for hash-guarded, root-bounded file moves; validate every source and destination, reject existing destinations, and use no-replace moves. Ordinary failures roll back completed entries when possible; the operation is not crash-atomic.
40
+ 7. Use `file_chattr` for metadata-only changes. Use hash-guarded `file_delete` for deletion; it preflights all targets and AST import references before any deletion, requires an explicit `forceReferences` override for referenced source, and removes empty ancestor directories after lock release.
41
+ 8. Use direct `run` with `rewrite` and `write: true` only for an intentionally bounded lower-level rewrite; it is not the normal agent patch route and still rewrites only the first match per file.
42
+ 9. Verify keyed results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation.
42
43
 
43
44
  Example batched AST patch:
44
45
 
@@ -86,11 +87,11 @@ Read [patch-state-machine.md](references/patch-state-machine.md) for routing and
86
87
  - Zero or excess matches: narrow each AST rule; every astRules item must match exactly one node because ast-bro rewrites the first match per file, while ordered arrays let one keyed file_patch apply multiple reviewed operations.
87
88
  - Capped direct preview: narrow paths, glob, or pattern before writing.
88
89
  - Aider ambiguity: request a larger bounded slice and expand the search block with unique surrounding context.
89
- - Dprint preflight failure: do not write that file until a configured formatter supports it.
90
+ - Formatter preflight failure: inspect the active `[formatting]` policy. Do not write until the matching external formatter or dprint fallback succeeds; `enabled = false` deliberately skips formatting.
90
91
  - MCP loss mid-task: stop writing, restore the server, then re-inspect touched and pending files through their correct AST or non-AST routes.
91
92
 
92
93
  ## Completion check
93
94
 
94
- Confirm the old structure is absent through AST search, callers are correct, touched files were verified through their proper route, dprint-backed writes succeeded, repository validation passes, and no direct-write or whole-file-read bypass was used.
95
+ Confirm the old structure is absent through AST search, callers are correct, touched files were verified through their proper route, configured formatter-backed writes succeeded (or formatting is explicitly disabled), repository validation passes, and no direct-write or whole-file-read bypass was used.
95
96
 
96
97
  Use `evals:check` for fixture-matrix integrity. `evals:measure` inventories direct MCP transcript 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 the following direct MCP records with that case. An outer `exec` result cannot prove each nested call, so marked nested calls and multi-marker evidence fail closed. Scoring validates schema-relevant inputs, transcript workspace roots, required order, expected output evidence, assertions, and successful per-call outputs. Use `evals:score --strict` only for a complete marked matrix; transcript scoring is matched task-execution evidence, not a blanket agent-quality claim.
@@ -270,5 +270,53 @@
270
270
  "required_tools": ["file_delete"],
271
271
  "surface": "file_delete",
272
272
  "variant": "directory"
273
+ },
274
+ {
275
+ "assertions": [
276
+ "Uses one path-keyed file_rename batch.",
277
+ "Obtains a fresh source hash before renaming.",
278
+ "Reports each source and destination result."
279
+ ],
280
+ "category": "positive",
281
+ "expected_output": "Uses the guarded file_rename contract for multiple files.",
282
+ "files": [],
283
+ "forbidden_tools": [],
284
+ "id": 91,
285
+ "prompt": "Rename two hash-guarded files in one file_rename operation.",
286
+ "required_tools": ["file_rename"],
287
+ "surface": "file_rename",
288
+ "variant": "batch"
289
+ },
290
+ {
291
+ "assertions": [
292
+ "Preserves source hash and root-boundary safeguards.",
293
+ "Does not overwrite an existing destination.",
294
+ "Reports the per-file operation result."
295
+ ],
296
+ "category": "variant",
297
+ "expected_output": "Uses the guarded file_rename contract and rejects an existing destination.",
298
+ "files": [],
299
+ "forbidden_tools": [],
300
+ "id": 92,
301
+ "prompt": "Reject a file_rename request whose destination already exists.",
302
+ "required_tools": ["file_rename"],
303
+ "surface": "file_rename",
304
+ "variant": "existing-destination"
305
+ },
306
+ {
307
+ "assertions": [
308
+ "Does not use shell mv or a direct editor for renaming.",
309
+ "Uses the registered file_rename MCP surface.",
310
+ "Preserves the root and hash safeguards."
311
+ ],
312
+ "category": "negative",
313
+ "expected_output": "Uses file_rename and does not call shell mutation or direct editor tools.",
314
+ "files": [],
315
+ "forbidden_tools": ["file_write", "file_delete"],
316
+ "id": 93,
317
+ "prompt": "Move a source file to a new name using the filesystem shell.",
318
+ "required_tools": ["file_rename"],
319
+ "surface": "file_rename",
320
+ "variant": "shell-near-miss"
273
321
  }
274
322
  ]
@@ -1180,6 +1180,7 @@
1180
1180
  "mcp_tools": [
1181
1181
  "file_chattr",
1182
1182
  "file_delete",
1183
+ "file_rename",
1183
1184
  "file_hash",
1184
1185
  "file_patch",
1185
1186
  "file_read",