@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
|
@@ -4,14 +4,15 @@ The server distinguishes AST inspection from structural rewrite support. AST-cap
|
|
|
4
4
|
|
|
5
5
|
## Route selection
|
|
6
6
|
|
|
7
|
-
1.
|
|
8
|
-
2.
|
|
9
|
-
3.
|
|
10
|
-
4.
|
|
11
|
-
5. Use `
|
|
12
|
-
6.
|
|
13
|
-
7. Use
|
|
14
|
-
8.
|
|
7
|
+
1. Call `file_capabilities` when the route is uncertain. It is the authoritative contract shared by `file_read`, `run`, and `file_patch`, and reports intrinsic support separately from configuration-filtered methods.
|
|
8
|
+
2. Choose `file_read.mode` explicitly when intent matters: `ast` returns a source map/requested symbols or RFC 6901-selected structured-document values, `text` returns a bounded slice, and `auto` prefers AST when available. Text remains selectable for AST-capable files.
|
|
9
|
+
3. Choose `file_patch.patchStrategy` per target. `ast` and `aider_block` are both valid for parseable source when reported by `file_capabilities`; prefer AST for semantic or repeated structural changes and Aider for a small, exact, uniquely anchored text replacement. Configuration may narrow either method but never silently changes the agent's selection.
|
|
10
|
+
4. Preview every ordered AST rule with `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. Aider patches also support the guarded preview receipt workflow.
|
|
11
|
+
5. Use one `file_patch({ files: { ... } })` object for one or more files. Each path value declares exactly one `patchStrategy`, the corresponding ordered `astRules` or `aiderBlocks`, optional `preview`, and normally one fresh `expectedSha256`.
|
|
12
|
+
6. Use one `file_write({ files: { ... } })` object for new files or explicit whole-file replacement where permitted. Use the shared `chattr` object for chmod/chown metadata. The complete batch policy preflight finishes before filesystem preparation.
|
|
13
|
+
7. Use `file_rename`, `file_chattr`, and `file_delete` for their dedicated operations. Rename requires source `delete` and destination `write`; guarded mutations honor `safety.require_hash` and supplied hashes are always enforced.
|
|
14
|
+
8. 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.
|
|
15
|
+
9. Use direct `run` with `rewrite` and `write: true` only for an intentionally bounded lower-level rewrite; normal agent mutations belong to `file_patch`.
|
|
15
16
|
|
|
16
17
|
MCP transport requests may contain a JSON-RPC array of requests and notifications. Preserve request IDs and expect one response per request, with notifications omitted.
|
|
17
18
|
|
|
@@ -21,19 +22,19 @@ MCP transport requests may contain a JSON-RPC array of requests and notification
|
|
|
21
22
|
- Use `$NODE` for one node and `$$NODES` for zero or more nodes.
|
|
22
23
|
- Preview with the same language, explicit paths, and optional glob.
|
|
23
24
|
- Inspect search matches, then use `file_patch` with `preview: true` for the full guarded diff; keep direct `run.write` for exceptional lower-level rewrites only.
|
|
24
|
-
- ast-bro
|
|
25
|
+
- ast-bro 4.0.0 changes only the first match in each file; narrow ambiguous patterns rather than assuming replace-all behavior.
|
|
25
26
|
- Split declarations, calls, and type references into separate rules.
|
|
26
27
|
|
|
27
28
|
## Aider block discipline
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
Version 2 enables exact, whitespace-normalized, relative-indentation, and diff-match-patch matching by default. Repositories may narrow `[files.patch].aider_matchers` when they intentionally want a stricter matching policy. Use `file_read` with `mode: "text"` to identify the smallest unique surrounding block, expand the slice and block on ambiguity, and select Aider only when the capability result permits it. Matcher ambiguity or a disabled fallback is a safe stop, never a reason to broaden the patch silently.
|
|
30
31
|
|
|
31
32
|
## Rejections
|
|
32
33
|
|
|
33
34
|
- `Stale file context`: refresh `file_hash`, re-inspect through the correct AST or bounded non-AST route, and rebuild the patch.
|
|
34
|
-
-
|
|
35
|
-
- `matched N nodes; expected M`: inspect and narrow the rule.
|
|
36
|
-
- `first match per file`:
|
|
35
|
+
- `read_mode_unavailable` or `patch_strategy_unavailable`: call `file_capabilities`, then make a supported explicit selection; do not retry a different method blindly.
|
|
36
|
+
- `matched N nodes; expected M`: inspect the returned bounded locations and narrow the rule.
|
|
37
|
+
- `first match per file`: narrow `file_patch` to one structural node or use a bounded direct run only when the lower-level rewrite is intentional.
|
|
37
38
|
- capped preview or read: narrow paths, glob, pattern, line ranges, or byte caps.
|
|
38
39
|
- 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
|
|
40
|
+
- path or symlink rejection: use a real path permitted by the effective host baseline and top-level `[[paths]]` rules. Version 2 grants no implicit OS-temporary access; add a narrow explicit path rule when it is required. Legacy `safety.allow_temp_directory`, `safety.allow_any_path`, and `safety.follow_symlinks` apply only to version 1. In version 2, both a link and its resolved target must be authorized and the winning rule must set `follow_symlinks = true`.
|
|
@@ -5,14 +5,18 @@ All tools are exposed directly by ast-mcp. Do not wrap ast-bro calls in a proxy
|
|
|
5
5
|
## File boundary
|
|
6
6
|
|
|
7
7
|
- `file_hash({ filePaths })`: batch up to 50 AST or non-AST paths and stream each whole file into SHA-256 without returning source content.
|
|
8
|
-
- `
|
|
8
|
+
- `file_capabilities({ filePaths })`: batch up to 50 paths and return file kind, language, parse health, configuration generation, intrinsic read/patch/search support, and effective methods after configuration filtering.
|
|
9
|
+
- `file_read({ files })`: batch up to 50 files. Each request accepts `mode: "auto" | "ast" | "text"`, optional source `symbols`, structured-document RFC 6901 `selectors`, and `language`, plus `range: { start, end }`; the numeric zero-based, end-exclusive `lines: [start, end]` tuple remains a permanent compatibility alias. AST mode returns a source map/requested symbols or selected JSON, JSONC, TOML, or YAML values; text mode returns a bounded slice, and auto prefers AST when available.
|
|
9
10
|
- `file_chattr({ files: { "/repo/a.txt": { chattr, expectedSha256? } } })`: applies the shared `chattr` contract (`chmod?`, same-owner `chown?`) under deterministic locks and reports the effective attributes.
|
|
10
|
-
- `file_write({ files: { "/repo/a.txt": { content, chattr? }, "/repo/b.txt": { content, expectedSha256?, chattr? } } })`: create or replace multiple files in one declared batch; existing replacements remain limited to non-AST-rewritable files.
|
|
11
|
-
- `file_patch({ files: { "/repo/src/a.ts": { expectedSha256?, patchStrategy: "ast", astRules
|
|
11
|
+
- `file_write({ files: { "/repo/a.txt": { content, chattr? }, "/repo/b.txt": { content, expectedSha256?, chattr? } } })`: create or replace multiple files in one declared batch; existing replacements remain limited to non-AST-rewritable files. The complete batch policy preflight runs first. For a new nested target, in-place formatter staging may transiently create, revalidate, and remove missing parents before the guarded commit recreates them; the live target is not written before commit.
|
|
12
|
+
- `file_patch({ files: { "/repo/src/a.ts": { expectedSha256?, patchStrategy: "ast" | "aider_block", astRules?: [...], aiderBlocks?: [...], chattr?, preview? } } })`: patch one or more files in one declared batch with an explicit agent-selected strategy supported by `file_capabilities`. A preview returns an opaque one-use `previewReceipt`; commit with `{ previewReceipt }` to reuse the reviewed formatted candidate after session, policy, generation, and source-hash rechecks.
|
|
12
13
|
- `file_rename({ files: { "/repo/a.txt": { destination, expectedSha256? } } })`: renames multiple regular files in one file-operation-root-bounded batch, locks every source and destination, rejects cross-root and duplicate/existing destinations, uses no-replace moves, rolls back prior moves when a later move fails, and reports a per-file result. Crash-atomic recovery is not guaranteed.
|
|
13
14
|
- `file_delete({ files: { "/repo/a.txt": { expectedSha256?, forceReferences? } } })`: preflights all targets and AST import references before any deletion, rejects referenced source unless explicitly overridden, and removes empty ancestor directories within the allowed operation root.
|
|
14
15
|
- `expectedSha256` is required by the secure default for patch, existing-file write, rename, and delete. `safety.require_hash = false` makes it optional; supplied hashes are always verified.
|
|
15
|
-
- Mutation tools use a declared `files` input object and return a `files` result map.
|
|
16
|
+
- Mutation tools use a declared `files` input object, preflight the complete batch, and return a `files` result map. Version 2 grants no implicit temporary access; use explicit top-level `[[paths]]` rules and approval policies. MCP transport also accepts JSON-RPC request/notification arrays and returns one response per request ID.
|
|
17
|
+
- `config_status({})` returns redacted effective configuration, source provenance, generation, health, and formatter selection.
|
|
18
|
+
- `policy_check({ checks })` explains batched read/write/delete decisions without side effects.
|
|
19
|
+
- `document_query({ filePath, selectors })` returns bounded RFC 6901-selected JSON, JSONC, TOML, or YAML values plus the whole-file hash.
|
|
16
20
|
|
|
17
21
|
## Shape and source
|
|
18
22
|
|
|
@@ -36,13 +40,15 @@ All tools are exposed directly by ast-mcp. Do not wrap ast-bro calls in a proxy
|
|
|
36
40
|
- dry-run per-file diffs when `rewrite` is present and `write` is false or omitted;
|
|
37
41
|
- disk rewrite when both `rewrite` and `write: true` are present.
|
|
38
42
|
|
|
39
|
-
For pinned ast-bro
|
|
43
|
+
For pinned ast-bro 4.0.0, write mode changes the first match per file, caps a call at 50 files, and reports rewritten files rather than node counts. Through ast-mcp, paths are root-checked, search is repeated as a non-capped safety preview, each candidate is checked against dprint, and each rewritten file is atomically formatted. Narrow rules to one intended match per file.
|
|
40
44
|
|
|
41
45
|
- `squeeze({ path, start?, end?, raw?, json? })`: compression for repetitive logs/text, not source code.
|
|
42
46
|
|
|
43
47
|
## Common sequences
|
|
44
48
|
|
|
45
49
|
- Rename: `impact` → `show`/`context` → `run` search → `run` dry diff → bounded `run.write` → AST absence check.
|
|
46
|
-
- Atomic single-file edit:
|
|
47
|
-
-
|
|
50
|
+
- Atomic single-file edit: `file_capabilities` when uncertain → select AST or Aider → preview → `file_hash` → `file_patch` → matching AST or text verification.
|
|
51
|
+
- Exact text edit: batched `file_read` with `mode: "text"` → `file_hash` → unique Aider block → bounded text verification.
|
|
52
|
+
- Structured manifest: `document_query` with multiple selectors → targeted edit workflow; do not request the whole manifest.
|
|
53
|
+
- Uncertain mutation policy: `config_status` → batched `policy_check` → preview → hash → mutation.
|
|
48
54
|
- Refactor module: `surface` → `deps` + `reverse_deps` → `impact` → edits → `cycles`.
|
|
@@ -96,13 +96,8 @@ const instructionsBegin = "<!-- ast-mcp:begin -->";
|
|
|
96
96
|
const instructionsEnd = "<!-- ast-mcp:end -->";
|
|
97
97
|
|
|
98
98
|
async function astMcpEntry(entry: unknown): Promise<boolean> {
|
|
99
|
-
if (entry
|
|
100
|
-
|
|
101
|
-
return false;
|
|
102
|
-
const bin = path.dirname(entry);
|
|
103
|
-
return (
|
|
104
|
-
path.basename(bin) === "bin" && path.basename(path.dirname(bin)) === ".bun"
|
|
105
|
-
);
|
|
99
|
+
if (typeof entry !== "string") return false;
|
|
100
|
+
return ["ast-mcp", "ast-mcp.js", "ast-mcp.ts"].includes(path.basename(entry));
|
|
106
101
|
}
|
|
107
102
|
|
|
108
103
|
async function expectedReference(
|
|
@@ -209,10 +204,8 @@ function entryTypeCurrent(
|
|
|
209
204
|
return type !== "local" || Array.isArray(entry.tools);
|
|
210
205
|
}
|
|
211
206
|
|
|
212
|
-
function entryRootCurrent(entry: McpEntry,
|
|
213
|
-
return
|
|
214
|
-
? entry.env?.AST_MCP_PROJECT_ROOT === root
|
|
215
|
-
: Object.keys(entry.env ?? {}).length === 0;
|
|
207
|
+
function entryRootCurrent(entry: McpEntry, _root: string | undefined) {
|
|
208
|
+
return Object.keys(entry.env ?? {}).length === 0;
|
|
216
209
|
}
|
|
217
210
|
|
|
218
211
|
function stdioMetadataCurrent(
|
|
@@ -255,7 +248,7 @@ function codexHttpMcpCurrent(block: string, url: string | undefined) {
|
|
|
255
248
|
!block.includes("command =")
|
|
256
249
|
);
|
|
257
250
|
}
|
|
258
|
-
async function codexStdioMcpCurrent(block: string,
|
|
251
|
+
async function codexStdioMcpCurrent(block: string, _root: string | undefined) {
|
|
259
252
|
const command = block.match(/command = (".*")/);
|
|
260
253
|
if (
|
|
261
254
|
!block.includes("[mcp_servers.ast-mcp]") ||
|
|
@@ -264,9 +257,7 @@ async function codexStdioMcpCurrent(block: string, root: string | undefined) {
|
|
|
264
257
|
!(await astMcpEntry(JSON.parse(command[1])))
|
|
265
258
|
)
|
|
266
259
|
return false;
|
|
267
|
-
return
|
|
268
|
-
? block.includes(`AST_MCP_PROJECT_ROOT = ${JSON.stringify(root)}`)
|
|
269
|
-
: !block.includes("AST_MCP_PROJECT_ROOT");
|
|
260
|
+
return !block.includes("AST_MCP_PROJECT_ROOT") && !block.includes("env =");
|
|
270
261
|
}
|
|
271
262
|
async function codexMcpCurrent(
|
|
272
263
|
file: string,
|
|
@@ -428,8 +419,8 @@ function installOperation(checks: InstallChecks) {
|
|
|
428
419
|
? ("update" as const)
|
|
429
420
|
: ("install" as const);
|
|
430
421
|
}
|
|
431
|
-
function commandSuffix(options: CheckOptions,
|
|
432
|
-
return `--scope ${options.scope} --target ${options.target}${
|
|
422
|
+
function commandSuffix(options: CheckOptions, _global: boolean) {
|
|
423
|
+
return `--scope ${options.scope} --target ${options.target}${options.transport === "http" ? ` --transport http --host ${JSON.stringify(options.host)} --port ${options.port}` : ""}${options.service ? " --service" : ""}`;
|
|
433
424
|
}
|
|
434
425
|
function installCommands(options: CheckOptions, global: boolean) {
|
|
435
426
|
const suffix = commandSuffix(options, global);
|