@mwillbanks/ast-mcp 0.1.3 → 0.2.1

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 +59 -20
  2. package/dist/ast-mcp.js +232 -130
  3. package/dist/ast-mcp.js.map +107 -27
  4. package/package.json +2 -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 +70 -95
  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 +604 -247
  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 +48 -29
  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 +217 -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 +9 -8
  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 +323 -131
@@ -0,0 +1,252 @@
1
+ import { type Command, parse } from "unbash";
2
+
3
+ const mutators = new Set([
4
+ "apply_patch",
5
+ "patch",
6
+ "truncate",
7
+ "touch",
8
+ "rm",
9
+ "unlink",
10
+ "mv",
11
+ "rename",
12
+ "ed",
13
+ "set-content",
14
+ "add-content",
15
+ "clear-content",
16
+ "out-file",
17
+ "remove-item",
18
+ "move-item",
19
+ "new-item",
20
+ ]);
21
+
22
+ const wrappers = new Set([
23
+ "env",
24
+ "command",
25
+ "builtin",
26
+ "exec",
27
+ "sudo",
28
+ "doas",
29
+ "nice",
30
+ "nohup",
31
+ "stdbuf",
32
+ "busybox",
33
+ "timeout",
34
+ "chrt",
35
+ ]);
36
+
37
+ function executable(command: Command) {
38
+ const values = [command.name, ...command.suffix].map(
39
+ (word) => word?.value ?? "",
40
+ );
41
+ let index = 0;
42
+ while (wrappers.has(values[index]?.split("/").at(-1)?.toLowerCase() ?? "")) {
43
+ const wrapper = values[index++].split("/").at(-1)?.toLowerCase();
44
+ while (values[index]?.startsWith("-")) {
45
+ const option = values[index++];
46
+ if (
47
+ (wrapper === "env" &&
48
+ ["-u", "-C", "--unset", "--chdir"].includes(option)) ||
49
+ ((wrapper === "sudo" || wrapper === "doas") &&
50
+ [
51
+ "-u",
52
+ "-g",
53
+ "-p",
54
+ "-r",
55
+ "-t",
56
+ "-C",
57
+ "-D",
58
+ "-R",
59
+ "-T",
60
+ "--user",
61
+ "--group",
62
+ "--prompt",
63
+ "--role",
64
+ "--type",
65
+ "--close-from",
66
+ "--chdir",
67
+ "--chroot",
68
+ "--command-timeout",
69
+ ].includes(option)) ||
70
+ (wrapper === "nice" && ["-n", "--adjustment"].includes(option))
71
+ )
72
+ index++;
73
+ }
74
+ if (wrapper === "env")
75
+ while (/^[A-Za-z_][A-Za-z0-9_]*=/.test(values[index] ?? "")) index++;
76
+ if ((wrapper === "timeout" || wrapper === "chrt") && index < values.length)
77
+ index++;
78
+ }
79
+ return {
80
+ args: values.slice(index + 1),
81
+ name: values[index]?.split("/").at(-1)?.toLowerCase() ?? "",
82
+ };
83
+ }
84
+
85
+ function inlineMutates(source: string) {
86
+ const value = source.toLowerCase();
87
+ if (
88
+ [
89
+ "writefile(",
90
+ "writefilesync(",
91
+ "appendfile(",
92
+ "appendfilesync(",
93
+ "bun.write(",
94
+ "deno.write",
95
+ ".write_text(",
96
+ ".write_bytes(",
97
+ "unlink(",
98
+ "unlinksync(",
99
+ "rmsync(",
100
+ "truncate(",
101
+ "truncatesync(",
102
+ "mkdir(",
103
+ "rename(",
104
+ "renamesync(",
105
+ ].some((marker) => value.includes(marker))
106
+ )
107
+ return true;
108
+ const opens = value.includes("open(") || value.includes("opensync(");
109
+ return (
110
+ opens &&
111
+ ([', "w', ", 'w", ', "a', ", 'a", ', "x', ", 'x", ', "r+', ", 'r+"].some(
112
+ (marker) => value.includes(marker),
113
+ ) ||
114
+ /\bmode\s*=\s*["'](?:[wax]|r\+)/.test(value))
115
+ );
116
+ }
117
+
118
+ function payloadAfter(args: string[], flags: string[]) {
119
+ const index = args.findIndex(
120
+ (arg) =>
121
+ flags.includes(arg) || flags.some((flag) => arg.startsWith(`${flag}=`)),
122
+ );
123
+ if (index < 0) return undefined;
124
+ const argument = args[index];
125
+ const separator = argument.indexOf("=");
126
+ return separator >= 0 ? argument.slice(separator + 1) : args[index + 1];
127
+ }
128
+
129
+ function commandMutates(command: Command) {
130
+ const original = command.name?.value.split("/").at(-1)?.toLowerCase() ?? "";
131
+ const originalArgs = command.suffix.map((word) => word.value);
132
+ if (
133
+ original === "command" &&
134
+ originalArgs.some((arg) => arg === "-v" || arg === "-V")
135
+ )
136
+ return false;
137
+ if (original === "env") {
138
+ const dispatched = payloadAfter(originalArgs, ["-S", "--split-string"]);
139
+ if (dispatched) return shellMutates(dispatched);
140
+ }
141
+ const { args, name } = executable(command);
142
+ if (name === "git") return false;
143
+ if (mutators.has(name)) return true;
144
+ if (name === "sed")
145
+ return args.some(
146
+ (arg) =>
147
+ arg === "--in-place" ||
148
+ arg.startsWith("--in-place=") ||
149
+ /^-[^-]*i/.test(arg),
150
+ );
151
+ if (name === "ast-grep")
152
+ return (
153
+ args.some((arg) => arg === "--rewrite" || arg.startsWith("--rewrite=")) &&
154
+ args.some((arg) => arg === "-U" || arg === "--update-all")
155
+ );
156
+ if (name === "find") {
157
+ if (args.includes("-delete")) return true;
158
+ const action = args.findIndex((arg) =>
159
+ ["-exec", "-execdir", "-ok", "-okdir"].includes(arg),
160
+ );
161
+ return action >= 0 && shellMutates(args.slice(action + 1).join(" "));
162
+ }
163
+ if (name === "xargs") return shellMutates(args.join(" "));
164
+ if (name === "eval") return shellMutates(args.join(" "));
165
+ if (
166
+ ["bash", "sh", "zsh", "dash", "ksh", "fish", "pwsh", "powershell"].includes(
167
+ name,
168
+ )
169
+ ) {
170
+ const grouped = args.findIndex((arg) => /^-[A-Za-z]*c[A-Za-z]*$/.test(arg));
171
+ const payload =
172
+ payloadAfter(args, ["-c", "--command", "-Command"]) ??
173
+ (grouped >= 0 ? args[grouped + 1] : undefined);
174
+ return payload ? shellMutates(payload) : false;
175
+ }
176
+ if (/^(?:node|python\d*(?:\.\d+)*|ruby|perl|php|bun|deno)$/.test(name)) {
177
+ const flags = name.startsWith("python") ? ["-c"] : ["-e", "--eval"];
178
+ const payload = payloadAfter(args, flags);
179
+ return payload ? inlineMutates(payload) : false;
180
+ }
181
+ return false;
182
+ }
183
+
184
+ function visit(value: unknown): boolean {
185
+ if (!value || typeof value !== "object") return false;
186
+ if (Array.isArray(value)) return value.some(visit);
187
+ const node = value as {
188
+ command?: unknown;
189
+ commands?: unknown[];
190
+ parts?: unknown[];
191
+ script?: unknown;
192
+ type?: string;
193
+ };
194
+ if (node.type === "Command" && commandMutates(node as Command)) return true;
195
+ if (node.script && visit(node.script)) return true;
196
+ if (node.command && visit(node.command)) return true;
197
+ if (node.commands?.some(visit)) return true;
198
+ if (node.parts?.some(visit)) return true;
199
+ return Object.values(value).some(visit);
200
+ }
201
+
202
+ export function shellMutates(source: string) {
203
+ if (source.length > 100_000) return false;
204
+ try {
205
+ const script = parse(source);
206
+ return script.errors?.length ? false : visit(script);
207
+ } catch {
208
+ return false;
209
+ }
210
+ }
211
+
212
+ const embeddedKeys = new Set(["cmd", "command", "script", "source", "code"]);
213
+
214
+ function stringLiteral(source: string, start: number) {
215
+ const quote = source[start];
216
+ if (quote !== '"' && quote !== "'" && quote !== "`") return undefined;
217
+ let value = "";
218
+ for (let index = start + 1; index < source.length; index++) {
219
+ const character = source[index];
220
+ if (character === "\\" && index + 1 < source.length) {
221
+ value += source[++index];
222
+ continue;
223
+ }
224
+ if (character === quote) return { end: index + 1, value };
225
+ value += character;
226
+ }
227
+ return undefined;
228
+ }
229
+
230
+ export function embeddedShellMutates(source: string) {
231
+ if (source.length > 100_000) return false;
232
+ for (let index = 0; index < source.length; index++) {
233
+ let key = "";
234
+ let end = index;
235
+ const literal = stringLiteral(source, index);
236
+ if (literal) {
237
+ key = literal.value;
238
+ end = literal.end;
239
+ } else if (/[A-Za-z_$]/.test(source[index] ?? "")) {
240
+ while (/[A-Za-z0-9_$]/.test(source[end] ?? "")) end++;
241
+ key = source.slice(index, end);
242
+ } else continue;
243
+ index = end - 1;
244
+ if (!embeddedKeys.has(key)) continue;
245
+ while (/\s/.test(source[end] ?? "")) end++;
246
+ if (source[end++] !== ":") continue;
247
+ while (/\s/.test(source[end] ?? "")) end++;
248
+ const payload = stringLiteral(source, end);
249
+ if (payload && shellMutates(payload.value)) return true;
250
+ }
251
+ return false;
252
+ }
@@ -0,0 +1,46 @@
1
+ import { expect, test } from "bun:test";
2
+ import {
3
+ executableSource,
4
+ extractExecInvocations,
5
+ isInsidePromiseAll,
6
+ } from "./source";
7
+
8
+ test("masks quoted and commented source without shifting offsets", () => {
9
+ const source = `const visible = true; // tools.mcp__ast_mcp__file_hash({})\nconst quoted = "tools.mcp__ast_mcp__file_read({})";\n/* hidden */ tools.mcp__ast_mcp__map({ paths: ["src"] });`;
10
+ const executable = executableSource(source);
11
+ expect(executable.length).toBe(source.length);
12
+ expect(executable).not.toContain("file_hash");
13
+ expect(executable).not.toContain("file_read");
14
+ expect(executable).toContain("tools.mcp__ast_mcp__map");
15
+ });
16
+
17
+ test("extracts nested inputs and identifies Promise.all concurrency", () => {
18
+ const source = `await Promise.all([\n tools.mcp__ast_mcp__file_hash({ filePaths: ["a.ts", call("b.ts")] }),\n tools.mcp__ast_mcp__map({ paths: ["src"] }),\n]);`;
19
+ const invocations = extractExecInvocations(source);
20
+ expect(invocations).toEqual([
21
+ {
22
+ concurrent: true,
23
+ input: `{ filePaths: ["a.ts", call("b.ts")] }`,
24
+ tool: "file_hash",
25
+ },
26
+ {
27
+ concurrent: true,
28
+ input: `{ paths: ["src"] }`,
29
+ tool: "map",
30
+ },
31
+ ]);
32
+ expect(
33
+ isInsidePromiseAll(source, source.indexOf("tools.mcp__ast_mcp__map")),
34
+ ).toBe(true);
35
+ });
36
+
37
+ test("ignores unterminated calls and preserves parentheses inside quotes", () => {
38
+ const source = `tools.mcp__ast_mcp__search({ query: "call())" });\ntools.mcp__ast_mcp__show({ path: "open"`;
39
+ expect(extractExecInvocations(source)).toEqual([
40
+ {
41
+ concurrent: false,
42
+ input: `{ query: "call())" }`,
43
+ tool: "search",
44
+ },
45
+ ]);
46
+ });
@@ -0,0 +1,164 @@
1
+ export interface QuoteState {
2
+ escaped: boolean;
3
+ quote: string;
4
+ }
5
+
6
+ export function advanceQuote(
7
+ character: string,
8
+ quote: string,
9
+ escaped: boolean,
10
+ ): QuoteState {
11
+ if (escaped) return { escaped: false, quote };
12
+ if (character === "\\") return { escaped: true, quote };
13
+ return { escaped: false, quote: character === quote ? "" : quote };
14
+ }
15
+
16
+ type SourceState = "block" | "code" | "line" | "quoted";
17
+
18
+ class ExecutableSourceScanner {
19
+ private escaped = false;
20
+ private index = 0;
21
+ private masked = "";
22
+ private quote = "";
23
+ private state: SourceState = "code";
24
+
25
+ constructor(private readonly source: string) {}
26
+
27
+ read() {
28
+ while (this.index < this.source.length) {
29
+ this.readCharacter();
30
+ this.index += 1;
31
+ }
32
+ return this.masked;
33
+ }
34
+
35
+ private readCharacter() {
36
+ const character = this.source[this.index] ?? "";
37
+ const next = this.source[this.index + 1] ?? "";
38
+ if (this.state === "code") return this.readCode(character, next);
39
+ if (this.state === "line") return this.readLine(character);
40
+ if (this.state === "block") return this.readBlock(character, next);
41
+ return this.readQuoted(character);
42
+ }
43
+
44
+ private readCode(character: string, next: string) {
45
+ if (character === "/" && next === "/") return this.beginComment("line");
46
+ if (character === "/" && next === "*") return this.beginComment("block");
47
+ if ("\"'`".includes(character)) return this.beginQuote(character);
48
+ this.masked += character;
49
+ }
50
+
51
+ private beginComment(state: "block" | "line") {
52
+ this.masked += " ";
53
+ this.index += 1;
54
+ this.state = state;
55
+ }
56
+
57
+ private beginQuote(quote: string) {
58
+ this.masked += " ";
59
+ this.quote = quote;
60
+ this.state = "quoted";
61
+ }
62
+
63
+ private readLine(character: string) {
64
+ this.masked += character === "\n" ? "\n" : " ";
65
+ if (character === "\n") this.state = "code";
66
+ }
67
+
68
+ private readBlock(character: string, next: string) {
69
+ this.masked += character === "\n" ? "\n" : " ";
70
+ if (character !== "*" || next !== "/") return;
71
+ this.masked += " ";
72
+ this.index += 1;
73
+ this.state = "code";
74
+ }
75
+
76
+ private readQuoted(character: string) {
77
+ this.masked += character === "\n" ? "\n" : " ";
78
+ const result = advanceQuote(character, this.quote, this.escaped);
79
+ this.escaped = result.escaped;
80
+ this.quote = result.quote;
81
+ if (!this.quote) this.state = "code";
82
+ }
83
+ }
84
+
85
+ export function executableSource(source: string) {
86
+ return new ExecutableSourceScanner(source).read();
87
+ }
88
+
89
+ export function isInsidePromiseAll(source: string, position: number) {
90
+ const executable = executableSource(source);
91
+ const promise = executable.lastIndexOf("Promise.all", position);
92
+ if (promise < 0) return false;
93
+ const open = executable.indexOf("(", promise);
94
+ if (open < 0 || open >= position) return false;
95
+ let depth = 1;
96
+ for (let index = open + 1; index < position; index += 1) {
97
+ if (executable[index] === "(") depth += 1;
98
+ else if (executable[index] === ")") depth -= 1;
99
+ }
100
+ return depth > 0;
101
+ }
102
+
103
+ class ParenthesisScanner {
104
+ private depth = 1;
105
+ private escaped = false;
106
+ private quote = "";
107
+
108
+ constructor(
109
+ private readonly source: string,
110
+ private index: number,
111
+ ) {}
112
+
113
+ read() {
114
+ for (; this.index < this.source.length; this.index += 1) {
115
+ if (this.readCharacter()) return this.index;
116
+ }
117
+ return -1;
118
+ }
119
+
120
+ private readCharacter() {
121
+ const character = this.source[this.index] ?? "";
122
+ if (this.quote) return this.readQuoted(character);
123
+ if ("\"'`".includes(character)) {
124
+ this.quote = character;
125
+ return false;
126
+ }
127
+ if (character === "(") this.depth += 1;
128
+ else if (character === ")") this.depth -= 1;
129
+ return this.depth === 0;
130
+ }
131
+
132
+ private readQuoted(character: string) {
133
+ const state = advanceQuote(character, this.quote, this.escaped);
134
+ this.quote = state.quote;
135
+ this.escaped = state.escaped;
136
+ return false;
137
+ }
138
+ }
139
+
140
+ function closingParenthesis(source: string, open: number) {
141
+ return new ParenthesisScanner(source, open + 1).read();
142
+ }
143
+
144
+ export interface SourceInvocation {
145
+ concurrent: boolean;
146
+ input: string;
147
+ tool: string;
148
+ }
149
+
150
+ export function extractExecInvocations(source: string): SourceInvocation[] {
151
+ const invocations: SourceInvocation[] = [];
152
+ const expression = /tools\.mcp__ast_mcp__(\w+)\s*\(/g;
153
+ for (const match of executableSource(source).matchAll(expression)) {
154
+ const open = (match.index ?? 0) + match[0].length - 1;
155
+ const close = closingParenthesis(source, open);
156
+ if (close < 0) continue;
157
+ invocations.push({
158
+ concurrent: isInsidePromiseAll(source, match.index ?? 0),
159
+ input: source.slice(open + 1, close).trim(),
160
+ tool: match[1] ?? "",
161
+ });
162
+ }
163
+ return invocations;
164
+ }
@@ -16,7 +16,7 @@
16
16
  "Patch this README paragraph through the AST-isolated environment.",
17
17
  "Show the blast radius of changing PaymentService.",
18
18
  "The ast-mcp tools disappeared; help me restore the local MCP.",
19
- "Install the code-intelligence and blocking hooks globally for Codex.",
19
+ "Install the code-intelligence and best-effort routing hooks globally for Codex.",
20
20
  "Trace how the request handler reaches the database call."
21
21
  ]
22
22
  }
@@ -8,7 +8,7 @@ From the installed skill directory, run the read-only checker:
8
8
 
9
9
  `bun run scripts/check-install.ts --scope local --target codex --root "$PWD"`
10
10
 
11
- Replace `codex` with `claude` or `copilot`. For a global installation, pass `--scope global`. The JSON result validates the marked guidance against the bundled template, checks the host-specific MCP, hook payload and registration, skill, and prints the appropriate install or update command.
11
+ Replace `codex` with `claude` or `copilot`. For a global installation, pass `--scope global`. For HTTP installations, also pass `--transport http --host <address> --port <number>` so the checker validates the generated URL. The JSON result validates the marked guidance against the bundled template, checks the host-specific MCP, hook payload and registration, skill, and prints the appropriate install or update command.
12
12
 
13
13
  ## Install from this package checkout
14
14
 
@@ -22,7 +22,7 @@ For one host globally:
22
22
 
23
23
  `bun run bin/ast-mcp.ts install --scope global --target codex`
24
24
 
25
- Targets are `codex`, `claude`, `copilot`, or `all`.
25
+ Targets are `codex`, `claude`, `copilot`, or `all`. Stdio is the default transport. Use `--transport http --host 127.0.0.1 --port 3768` for HTTP host entries and add `--service` only when a macOS LaunchAgent or Linux systemd user unit should be managed.
26
26
 
27
27
  ## Install from the published package
28
28
 
@@ -52,9 +52,10 @@ The pinned `@ast-bro/cli@3.0.0` package has a precompiled binary only for macOS
52
52
 
53
53
  ## Activate and verify
54
54
 
55
- 1. 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.
56
- 2. Confirm `file_hash`, `file_read`, `file_write`, and `file_patch` are present.
57
- 3. Confirm direct intelligence tools such as `digest`, `map`, `show`, `context`, and `impact` are present; there is no proxy tool.
58
- 4. Verify that `file_read` accepts batched `files`, `file_hash` accepts batched `filePaths`, and `file_write`/`file_patch` accept path-keyed batches with ordered per-file operations; the legacy whole-file `file_read({ filePath })` schema is stale.
59
- 5. Rerun `check-install.ts` if the tool list remains incomplete.
60
- 6. 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.
55
+ 1. Run `ast-mcp config validate --root "$PWD"` before reconnecting. Use `ast-mcp config show --root "$PWD"` when the effective project, global, environment, or default source is unclear.
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
+ 3. Confirm `file_hash`, `file_read`, `file_write`, and `file_patch` are present.
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 `file_write`/`file_patch` accept path-keyed batches with ordered per-file operations; the legacy whole-file `file_read({ filePath })` schema is stale.
60
+ 6. Rerun `check-install.ts` if the tool list remains incomplete.
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 path-keyed `file_patch` object for one or more files. Each value has one `expectedSha256`, one `patchStrategy`, ordered `astRules` or `aiderBlocks` arrays, and optional `preview`.
10
- 4. Use one path-keyed `file_write` object for new files or existing non-structurally-rewritable files; existing replacements still require 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_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.
9
+ 3. Use one path-keyed `file_patch` object for one or more files. Each value has one `patchStrategy`, ordered `astRules` or `aiderBlocks` arrays, optional `preview`, and normally one fresh `expectedSha256`.
10
+ 4. Use one path-keyed `file_write` 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` 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.
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`.
@@ -35,5 +35,5 @@ The native TypeScript matcher attempts exact, whitespace-normalized, relative-in
35
35
  - `matched N nodes; expected M`: inspect and narrow the rule.
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
- - dprint preflight failure: the formatter does not support the target under the active configuration; no direct run write occurs.
39
- - path or symlink rejection: use a real path under `AST_MCP_ROOTS`.
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-bounded.
@@ -8,8 +8,10 @@ All tools are exposed directly by ast-mcp. Do not wrap ast-bro calls in a proxy
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
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
10
  - `file_write({ "/repo/a.txt": { content, chattr? }, "/repo/b.txt": { content, expectedSha256?, chattr? } })`: create or replace multiple files in one keyed 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({ "/repo/src/a.ts": { expectedSha256, patchStrategy: "ast", astRules: [...], chattr? } })`: patch one or more files in one keyed batch. Use ordered `astRules` or `aiderBlocks`; every path has one fresh hash and one atomic commit.
12
- - `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 configured root.
11
+ - `file_patch({ "/repo/src/a.ts": { expectedSha256?, patchStrategy: "ast", astRules: [...], chattr? } })`: patch one or more files in one keyed batch. Use ordered `astRules` or `aiderBlocks`; every path has one atomic commit.
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 configured root.
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.
13
15
  - The keyed mutation tools return a `files` result map. MCP transport also accepts JSON-RPC request/notification arrays and returns one response per request ID.
14
16
 
15
17
  ## Shape and source