@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/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  <a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
16
16
  </p>
17
17
 
18
- `@mwillbanks/ast-mcp` combines native AST intelligence, deterministic file operations, state-machine-enforced edits, blocking hooks, and agent guidance. It gives Codex, Claude Code, GitHub Copilot, and VS Code Copilot a capable repository workflow without granting them an unbounded editor.
18
+ `@mwillbanks/ast-mcp` combines native AST intelligence, deterministic file operations, state-machine-enforced edits, best-effort routing hooks, and agent guidance. It gives Codex, Claude Code, GitHub Copilot, and VS Code Copilot a capable repository workflow without granting them an unbounded editor.
19
19
 
20
20
  **[Read the documentation](https://mwillbanks.github.io/ast-mcp/)**
21
21
 
@@ -29,7 +29,7 @@ Coding agents need more than a text editor. They need a way to understand code r
29
29
  | Guarded file operations | Batched hashing, bounded text reads, deterministic creation, exact patches, attributes, and reference-aware deletion |
30
30
  | Root isolation | One shared path policy for every file and ast-bro operation, with symlink rejection and explicit external-root opt-in |
31
31
  | Safe commits | Fresh SHA-256 checks, deterministic cross-process locks, candidate formatting, hash rechecks, and atomic replacement |
32
- | Host enforcement | Blocking hooks, a unified skill, and idempotent installers for Codex, Claude, Copilot, and VS Code |
32
+ | Agent routing | Best-effort hooks, a unified skill, and idempotent installers for Codex, Claude, Copilot, and VS Code |
33
33
 
34
34
  AST-capable files stay on the intelligence path instead of being retrieved as whole-file text. Unsupported formats use bounded reads and exact Aider search/replace blocks.
35
35
 
@@ -52,18 +52,44 @@ Runtime dependencies are pinned where binary compatibility matters. `@ast-bro/cl
52
52
 
53
53
  ## Install
54
54
 
55
- Install the MCP server, blocking hooks, unified skill, and managed instructions into the current repository:
55
+ Install the MCP server, best-effort routing hooks, unified skill, and managed instructions into the current repository:
56
+
57
+ The hooks nudge common direct editor and manual mutation attempts toward ast-mcp. They are not a security boundary and deliberately leave Git operations, output redirection, repository scripts, and arbitrary execution to the host framework and sandbox.
58
+
59
+ ```npm
60
+ npm install --save-dev @mwillbanks/ast-mcp
61
+ ```
62
+
63
+ When installing with Bun, allow the pinned native installers:
56
64
 
57
65
  ```bash
58
- bun add --dev @mwillbanks/ast-mcp
59
66
  bun pm trust @ast-bro/cli dprint
67
+ ```
68
+
69
+ ```bash
60
70
  ./node_modules/.bin/ast-mcp install \
61
71
  --scope local \
62
72
  --target all \
63
73
  --root "$PWD"
64
74
  ```
65
75
 
66
- Bun blocks transitive lifecycle scripts by default, so the explicit trust step runs the pinned ast-bro and dprint installers before the MCP starts. Targets are `codex`, `claude`, `copilot`, or `all`. Use `./node_modules/.bin/ast-mcp update` to reconcile every managed surface and `./node_modules/.bin/ast-mcp uninstall` to remove only ast-mcp-managed configuration.
76
+ Stdio remains the default. To generate Streamable HTTP entries instead, select HTTP and an endpoint:
77
+
78
+ ```bash
79
+ ./node_modules/.bin/ast-mcp install \
80
+ --scope local \
81
+ --target all \
82
+ --root "$PWD" \
83
+ --transport http \
84
+ --host 127.0.0.1 \
85
+ --port 3768
86
+ ```
87
+
88
+ Add `--service` to create and start a macOS LaunchAgent or Linux systemd user unit. Local services require an explicit port. Without `--service`, the installer prints the manual `ast-mcp mcp --transport http` startup command. Windows supports manual HTTP startup but not managed services.
89
+
90
+ Bun blocks transitive lifecycle scripts by default, so the explicit trust step runs the pinned ast-bro and dprint installers before the MCP starts. If another package manager blocks dependency build scripts, approve `@ast-bro/cli` and `dprint` through that manager before configuring a host. npm, pnpm, Yarn Classic, and Yarn 2+ project installations are supported. The runtime resolves binaries from ancestor package bins, package metadata, package-manager global bins, and then `PATH`.
91
+
92
+ Targets are `codex`, `claude`, `copilot`, or `all`. Use `./node_modules/.bin/ast-mcp update` to reconcile every managed surface and `./node_modules/.bin/ast-mcp uninstall` to remove only marked blocks, managed entries, and the owned `ast-mcp` skill directory.
67
93
 
68
94
  ### ast-bro platform support
69
95
 
@@ -93,26 +119,49 @@ bun run build
93
119
  bun run bin/ast-mcp.ts install --scope local --target all --root "$PWD"
94
120
  ```
95
121
 
96
- ## MCP configuration
122
+ ## Configuration
123
+
124
+ Create `ast-mcp.toml` in the project root to configure a local or globally installed server without rewriting host MCP definitions:
125
+
126
+ ```toml
127
+ version = 1
128
+
129
+ [workspace]
130
+ roots = ["."]
131
+
132
+ [safety]
133
+ allow_external_roots = false
134
+ follow_symlinks = false
135
+ require_hash = true
136
+
137
+ [safety.hook]
138
+ enabled = true
139
+
140
+ [formatting]
141
+ enabled = true
142
+ dprint_config = "./dprint.json"
97
143
 
98
- A minimal stdio configuration is:
99
-
100
- ```json
101
- {
102
- "mcpServers": {
103
- "ast-mcp": {
104
- "command": "bun",
105
- "args": [
106
- "/absolute/path/to/node_modules/@mwillbanks/ast-mcp/dist/ast-mcp.js",
107
- "mcp"
108
- ],
109
- "env": { "AST_MCP_ROOTS": "/absolute/project/root" }
110
- }
111
- }
112
- }
144
+ [[formatting.formatters]]
145
+ extensions = [".rs"]
146
+ command = "rustfmt"
147
+ args = ["--emit", "stdout"]
148
+
149
+ [http]
150
+ host = "127.0.0.1"
151
+ port = 3768
113
152
  ```
114
153
 
115
- The server also supports Streamable HTTP at `/mcp` with `bun run start:http`. It binds to `127.0.0.1` by default; set `AST_MCP_HTTP_HOST=0.0.0.0` only when deliberate network exposure is required. MCP session IDs correlate requests and are not authentication; stdio remains the trusted default transport. HTTP uses SSE by default and emits one event per request; JSON-array responses require `enableJsonResponse`.
154
+ Resolution is deterministic: environment overrides, project `ast-mcp.toml`, the platform global `ast-mcp/ast-mcp.toml`, then built-in defaults. The server uses MCP client workspace roots when available, so one global installation automatically selects the connected project. Existing environment variables remain supported as explicit overrides.
155
+
156
+ Formatting uses dprint by default, can be disabled, or can route the first matching extension/glob to a shell-free external formatter with dprint fallback. Safety remains strict by default; explicit settings can allow final symlinks inside configured roots, make mutation hashes optional, or tune the host hook allow/block policy.
157
+
158
+ Inspect the result with `ast-mcp config validate` and `ast-mcp config show`. See the [configuration reference](https://mwillbanks.github.io/ast-mcp/docs/reference/configuration/) for the full schema, discovery rules, cache behavior, formatter contract, safety semantics, and migration guidance.
159
+
160
+ ## MCP configuration
161
+
162
+ A minimal global stdio definition needs only the stable executable and `mcp` subcommand. Local installer definitions additionally carry `AST_MCP_PROJECT_ROOT` as a discovery selector; it does not override configuration values. Select `--transport http` during install to generate native URL entries for Codex, Claude Code, Copilot CLI, and VS Code.
163
+
164
+ Start HTTP manually with `ast-mcp mcp --transport http [--host <address>] [--port <number>]`, or install a user service with `--service`. CLI flags override environment variables, project TOML, global TOML, and built-in defaults. The endpoint is `/mcp`; wildcard bind addresses generate loopback client URLs, while explicit non-loopback addresses deliberately expose the server. MCP session IDs correlate requests and are not authentication; stdio remains the trusted default transport. HTTP uses SSE by default and emits one event per request; JSON-array responses require `enableJsonResponse`.
116
165
 
117
166
  `SIGTERM`, `SIGINT`, and `SIGHUP` all initiate graceful shutdown. The stdio process closes its MCP server; the HTTP process stops accepting requests, closes every active MCP session, then closes remaining connections. Successful cleanup exits 0, cleanup failure exits 1, and a second signal forces exit 1 while cleanup is pending. `SIGHUP` intentionally exits after cleanup so the host supervisor can restart ast-mcp from refreshed code and configuration.
118
167