@mwillbanks/ast-mcp 0.2.2 → 0.4.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 (62) hide show
  1. package/CONTRIBUTING.md +13 -0
  2. package/README.md +18 -16
  3. package/dist/ast-mcp.js +209 -147
  4. package/dist/ast-mcp.js.map +70 -50
  5. package/package.json +21 -15
  6. package/src/ast-bro/capability.ts +20 -10
  7. package/src/ast-bro/client.ts +12 -6
  8. package/src/ast-bro/result.ts +79 -0
  9. package/src/ast-bro/tools.json +29 -4
  10. package/src/cli.ts +10 -7
  11. package/src/config-cli.ts +166 -19
  12. package/src/config-edit.ts +236 -0
  13. package/src/config-migrate.ts +206 -0
  14. package/src/config-registry.ts +329 -0
  15. package/src/config-schema-common.ts +88 -0
  16. package/src/config-v2-schema.ts +109 -0
  17. package/src/config.ts +523 -170
  18. package/src/helpers/ast-bro.ts +1 -7
  19. package/src/helpers/config.ts +16 -3
  20. package/src/helpers/installer.ts +8 -0
  21. package/src/helpers/mcp-schema.ts +98 -4
  22. package/src/host-smoke.ts +182 -0
  23. package/src/http.ts +8 -3
  24. package/src/installer-transport.ts +6 -4
  25. package/src/installer.ts +242 -54
  26. package/src/patch/engine.ts +575 -280
  27. package/src/patch/languages.ts +9 -0
  28. package/src/patch/strategy/aiderBlock.ts +110 -0
  29. package/src/patch/strategy/ast.ts +170 -0
  30. package/src/patch/strategy.ts +61 -0
  31. package/src/runtime/approval.ts +438 -0
  32. package/src/runtime/config-write.ts +327 -0
  33. package/src/runtime/dependencies.ts +14 -78
  34. package/src/runtime/document-inspection.ts +78 -0
  35. package/src/runtime/file-capabilities.ts +250 -0
  36. package/src/runtime/file-delete.ts +110 -37
  37. package/src/runtime/file-read.ts +134 -15
  38. package/src/runtime/file-rename.ts +5 -2
  39. package/src/runtime/format.ts +90 -30
  40. package/src/runtime/git-worktrees.ts +179 -0
  41. package/src/runtime/path-policy.ts +643 -0
  42. package/src/runtime/path-utils.ts +80 -0
  43. package/src/runtime/paths.ts +171 -47
  44. package/src/server.ts +2 -1
  45. package/src/tools/ast-bro.ts +294 -75
  46. package/src/tools/configuration.ts +668 -0
  47. package/src/tools/configured.ts +49 -21
  48. package/src/tools/files.ts +169 -62
  49. package/src/tools/index.ts +2 -0
  50. package/src/tools/lifecycle.ts +82 -38
  51. package/templates/AGENTS.md +17 -15
  52. package/templates/skills/ast-mcp/SKILL.md +57 -20
  53. package/templates/skills/ast-mcp/evals/evals.json +319 -9
  54. package/templates/skills/ast-mcp/evals/score.ts +80 -0
  55. package/templates/skills/ast-mcp/evals/semantic.ts +3 -1
  56. package/templates/skills/ast-mcp/references/installation.md +12 -12
  57. package/templates/skills/ast-mcp/references/patch-state-machine.md +15 -14
  58. package/templates/skills/ast-mcp/references/tool-catalog.md +18 -8
  59. package/templates/skills/ast-mcp/scripts/binary-resolution.ts +112 -0
  60. package/templates/skills/ast-mcp/scripts/check-install.ts +165 -51
  61. package/templates/skills/ast-mcp/scripts/managed-hook.ts +34 -2
  62. package/src/ast-bro/rewrite-capability.ts +0 -9
@@ -15,33 +15,43 @@ Treat ast-mcp as the only code-intelligence and filesystem boundary. Do not call
15
15
 
16
16
  ## Explore before editing
17
17
 
18
- - AST-capable files must be inspected with AST intelligence, never `file_read`: start unfamiliar work with `digest`, use `map` for one file's shape, and use `show` for exact symbols.
18
+ - Start unfamiliar work with `digest`, use `map` for one file's shape, and use `show` for exact symbols. When a file workflow is uncertain, call `file_capabilities` once for all relevant paths; `file_read`, `run`, and `file_patch` enforce that same result.
19
19
  - Use `search` when names are unknown and `find_related` for code similar to a known location.
20
20
  - Use `context` for a symbol plus nearby calls; use `impact` before changing a public or shared symbol.
21
21
  - Use `deps`, `reverse_deps`, `graph`, or `cycles` for module relationships.
22
22
  - Use `callers`, `callees`, or `trace` for execution flow; use `implements` for type hierarchies.
23
23
  - Use `surface` for exported API shape, `index` for search-index maintenance, and `squeeze` only for repetitive logs or text.
24
- - Use `file_read` only for unsupported non-AST content. Request explicit zero-based, end-exclusive line slices, accept the default `[0, 100]` only when sufficient, and batch multiple files in one call.
24
+ - `file_read` accepts an agent-selected `mode`: `ast` returns a source map/requested symbols or RFC 6901-selected structured-document values, `text` returns a bounded zero-based end-exclusive slice, and `auto` prefers AST when supported. Use `symbols` for source and `selectors` for JSON, JSONC, TOML, or YAML. Text mode remains available for AST-capable files when exact source text is necessary. Batch multiple files in one call.
25
25
  - Use ast-mcp intelligence as the primary repository search route. Never invoke `ast-grep` directly and never use `sed` for repository reads or edits. `rg` is permitted only as a discouraged fallback for exact literals, identifiers, non-AST formats, or discovery unavailable through ast-mcp; external transcript analysis, Git metadata, validation, and live-runtime reproduction are exceptions.
26
26
 
27
27
  Read [tool-catalog.md](references/tool-catalog.md) for exact arguments and combinations.
28
28
 
29
+ ## Batch and parallelize safely
30
+
31
+ - Batch paths, symbols, selectors, and keyed files into one call whenever the tool schema supports them. Prefer one bounded multi-target call over repeated single-target calls.
32
+ - Issue independent read-only calls in the same model turn or host executor, and return all parallel results together when the host protocol requires it.
33
+ - Keep each AST intelligence request within one project root. Split cross-root work into root-specific calls; independent read-only calls may run in parallel.
34
+ - Linked git worktrees of the config-bearing repository are authorized according to `workspace.worktrees` (`include` by default). Pass absolute paths into a worktree; if `PWD` is a linked worktree, relative paths resolve there. Do not treat a toml-less worktree as a different project root.
35
+ - Keep dependent and overlapping work sequential: inspect, preview, hash, then mutate. Never parallelize writes that can touch the same path, configuration generation, or dependency chain.
36
+ - Call `config_status` before the first mutation when formatter selection, path policy, configuration health, or generation is uncertain. Use `policy_check` to preflight read, write, and delete decisions without side effects.
37
+ - Change `ast-mcp.toml` only through grouped `config_core` and batched `config_paths`. Do not rewrite the whole file with `file_write` or `file_patch`. Host elicitation is required by default (`mcp.configuration.require_approval = true`). Changing `[mcp.configuration]` always requires approval, including disabling the surface. Successful writes invalidate the in-process registry so the new generation applies without restarting the MCP server.
38
+ - Use `document_query` for bounded JSON, JSONC, TOML, and YAML inspection instead of attempting whole-file reads of structured manifests.
39
+
29
40
  ## Mutate through declared file batches
30
41
 
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
- 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 `file_patch` file 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 file. 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
- 4. Mutation tools accept a declared `files` property whose value is a path-keyed object. Use one `file_patch({ files: { ... } })` call for one or more files:
35
- - AST targets: `{ expectedSha256, patchStrategy: "ast", astRules: [{ pattern, fix, expectedMatches: 1 }], preview?: boolean }`
36
- - Unsupported targets: `{ expectedSha256, patchStrategy: "aider_block", aiderBlocks: [{ search, replace }], preview?: boolean }`
37
- Operations in each array run in order under one file lock; preview returns without committing and normal mode commits atomically.
38
- 5. Use one `file_write({ files: { ... } })` 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 one `file_rename({ files: { ... } })` batch for hash-guarded 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({ files: { ... } })` for metadata-only changes. Use hash-guarded `file_delete({ files: { ... } })` 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 results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation.
43
-
44
- The OS temporary directory is an allowed file-operation root by default. Set `safety.allow_temp_directory = false` to disable it. `safety.allow_any_path = true` is an explicit unrestricted mode for file tools; do not enable it merely to avoid configuring a workspace root.
42
+ 1. Inspect with `map`, `show`, `context`, a bounded `run`, or `file_read`. Call `file_capabilities` before choosing a read or patch method when intrinsic support or effective configuration is uncertain.
43
+ 2. Select `file_read.mode` explicitly when intent matters. Use `ast` with `symbols` for source structure or with RFC 6901 `selectors` for structured documents; use `text` for a bounded exact slice. `auto` is suitable when AST-first behavior is desired.
44
+ 3. Select `file_patch.patchStrategy` per file. Prefer `ast` for semantic, repeated, or structurally anchored changes; prefer `aider_block` for a small exact text replacement with unique context. Both remain selectable for parseable source whenever `file_capabilities` reports them, and configuration may narrow the effective choices.
45
+ 4. 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 of either strategy, send the same `file_patch` file entry with `preview: true`. Preview returns the unformatted strategy candidate and does not run formatters; formatting occurs only at commit, including `previewReceipt` commit.
46
+ 5. Call one batched `file_hash({ filePaths: [...] })` immediately before guarded edits. Keep one returned hash per file. 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.
47
+ 6. Mutation tools accept a declared `files` property whose value is a path-keyed object. Use one `file_patch({ files: { ... } })` call for one or more files with exactly one explicit strategy and its matching ordered operations. Each path runs under one lock; preview never commits and normal mode commits atomically.
48
+ 7. Use one `file_write({ files: { ... } })` batch for new files or permitted SHA-guarded whole-file replacement. Supply the shared `chattr` object when chmod/chown metadata is required. The complete batch policy preflight finishes first; in-place formatter staging may transiently create, revalidate, and remove missing parents before the guarded commit recreates them, without writing the live target.
49
+ 8. Use one `file_rename({ files: { ... } })` batch for hash-guarded 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.
50
+ 9. Use `file_chattr({ files: { ... } })` for metadata-only changes. Use hash-guarded `file_delete({ files: { ... } })` 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.
51
+ 10. 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.
52
+ 11. Verify results with `show`, `map`, `run`, or bounded `file_read` slices, then run repository validation.
53
+
54
+ Version 2 grants no implicit OS-temporary access. Express every exception through the narrowest top-level `[[paths]]` rule; `request` access must be approved through the host and model arguments can never bypass policy. Legacy v1 booleans remain readable only for compatibility and should be migrated with `ast-mcp config migrate`.
45
55
 
46
56
  Example batched AST patch:
47
57
 
@@ -89,17 +99,44 @@ MCP transport requests may use a single JSON-RPC array containing requests and n
89
99
 
90
100
  Read [patch-state-machine.md](references/patch-state-machine.md) for routing and rejection recovery.
91
101
 
102
+ ## Update configuration through MCP
103
+
104
+ Use `config_core` for grouped core sections (`workspace`, `safety`, `files`, `formatting`, `http`, `dependencies`, `mcp.configuration`) and `config_paths` for batched `[[paths]]` add, update, or remove operations. Batch related keys in one group; do not send a whole-file rewrite or one call per individual key. `target` defaults to `project` and may be `global`. Version 1 files must be migrated first. When `mcp.configuration.enabled = false`, both tools fail closed.
105
+
106
+ ```json
107
+ config_core({
108
+ "safety": { "require_hash": false },
109
+ "workspace": { "worktrees": "request" }
110
+ })
111
+ ```
112
+
113
+ ```json
114
+ config_paths({
115
+ "operations": [
116
+ {
117
+ "op": "add",
118
+ "rule": {
119
+ "id": "docs",
120
+ "path": "./docs",
121
+ "policies": { "read": "allow", "write": "request" }
122
+ }
123
+ },
124
+ { "op": "update", "id": "workspace", "rule": { "excludes": [".git/**"] } }
125
+ ]
126
+ })
127
+ ```
128
+
92
129
  ## Recover safely
93
130
 
94
- - Stale SHA: refresh `file_hash`, re-inspect through AST or a bounded unsupported-content slice, and rebuild the patch.
131
+ - Stale SHA: refresh `file_hash`, re-inspect with the selected AST or text mode, and rebuild the patch.
95
132
  - 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 declared `file_patch.files` entry apply multiple reviewed operations.
96
133
  - Capped direct preview: narrow paths, glob, or pattern before writing.
97
- - Aider ambiguity: request a larger bounded slice and expand the search block with unique surrounding context.
98
- - 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.
134
+ - Unavailable method: call `file_capabilities` and select a reported read or patch method. Aider ambiguity or a disabled matcher is a safe stop; request a larger `mode: "text"` slice and expand the search block with unique surrounding context.
135
+ - Formatter preflight failure: call `config_status`, inspect the selected formatter and fallback, and do not write until stdout or staged in-place formatting succeeds. A v2 `preserve` fallback deliberately keeps unmatched content unchanged.
99
136
  - MCP loss mid-task: stop writing, restore the server, then re-inspect touched and pending files through their correct AST or non-AST routes.
100
137
 
101
138
  ## Completion check
102
139
 
103
140
  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.
104
141
 
105
- 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. When the measured run used non-default file safety, pass the validated scorer options `--allow-any-path` and/or `--no-temp-directory`; the scorer does not infer layered project configuration from a transcript. Use `evals:score --strict` only for a complete marked matrix; transcript scoring is matched task-execution evidence, not a blanket agent-quality claim.
142
+ Use `evals:check` for fixture-matrix integrity. `evals:measure` inventories batch density, parallel read-only execution, validation-error codes, calls per recorded model-tool turn, 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. When the measured run used non-default file safety, pass the validated scorer options `--allow-any-path` and/or `--no-temp-directory`; the scorer does not infer layered project configuration from a transcript. Use `evals:score --strict` only for a complete marked matrix; transcript scoring is matched task-execution evidence, not a blanket agent-quality claim.
@@ -34,19 +34,19 @@
34
34
  },
35
35
  {
36
36
  "assertions": [
37
- "Does not call file_read for AST-capable source.",
38
- "Uses map for shape and show for the named implementation.",
39
- "Avoids whole-file content reads."
37
+ "Uses file_read with mode ast for AST-capable source.",
38
+ "Requests the named symbol instead of retrieving whole-file text.",
39
+ "Reports resolved mode, capabilities, and whole-file hash."
40
40
  ],
41
- "category": "negative",
42
- "expected_output": "Uses AST intelligence for the TypeScript file and never calls file_read.",
41
+ "category": "variant",
42
+ "expected_output": "Uses file_read AST mode with the createServer symbol.",
43
43
  "files": [],
44
- "forbidden_tools": ["file_read"],
44
+ "forbidden_tools": [],
45
45
  "id": 3,
46
- "prompt": "Inspect the declarations and implementation of createServer in src/server.ts.",
47
- "required_tools": ["map", "show"],
46
+ "prompt": "Inspect the declarations and implementation of createServer in src/server.ts through file_read AST mode.",
47
+ "required_tools": ["file_read"],
48
48
  "surface": "file_read",
49
- "variant": "ast-capable-near-miss"
49
+ "variant": "ast-mode"
50
50
  },
51
51
  {
52
52
  "assertions": [
@@ -1175,9 +1175,319 @@
1175
1175
  "required_tools": [],
1176
1176
  "surface": "skill",
1177
1177
  "variant": "trigger-negative"
1178
+ },
1179
+ {
1180
+ "assertions": [
1181
+ "Uses one file_capabilities call for the target.",
1182
+ "Reports intrinsic and configuration-filtered read, patch, and search methods.",
1183
+ "Performs no mutation."
1184
+ ],
1185
+ "category": "positive",
1186
+ "expected_output": "Batches capability inspection and reports intrinsic and effective methods.",
1187
+ "files": [],
1188
+ "forbidden_tools": [],
1189
+ "id": 180,
1190
+ "prompt": "Report whether package.json supports AST or text reads and AST or Aider patches before editing it.",
1191
+ "required_tools": ["file_capabilities"],
1192
+ "surface": "file_capabilities",
1193
+ "variant": "primary"
1194
+ },
1195
+ {
1196
+ "assertions": [
1197
+ "Batches all three paths in one call.",
1198
+ "Distinguishes intrinsic support from effective configuration.",
1199
+ "Uses the result to recommend a valid agent-selected strategy."
1200
+ ],
1201
+ "category": "variant",
1202
+ "expected_output": "Uses one batched capability call and explains method differences.",
1203
+ "files": [],
1204
+ "forbidden_tools": [],
1205
+ "id": 181,
1206
+ "prompt": "Compare supported read and patch methods for a TypeScript file, Markdown file, and TOML file.",
1207
+ "required_tools": ["file_capabilities"],
1208
+ "surface": "file_capabilities",
1209
+ "variant": "batch"
1210
+ },
1211
+ {
1212
+ "assertions": [
1213
+ "Uses file_hash rather than file_capabilities.",
1214
+ "Does not retrieve content.",
1215
+ "Performs no mutation."
1216
+ ],
1217
+ "category": "negative",
1218
+ "expected_output": "Uses file_hash directly.",
1219
+ "files": [],
1220
+ "forbidden_tools": ["file_capabilities"],
1221
+ "id": 182,
1222
+ "prompt": "Return the SHA-256 for README.md without inspecting its contents.",
1223
+ "required_tools": ["file_hash"],
1224
+ "surface": "file_capabilities",
1225
+ "variant": "near-miss"
1226
+ },
1227
+ {
1228
+ "assertions": [
1229
+ "Uses config_status before mutation when policy or formatting is uncertain.",
1230
+ "Reports the effective generation, health, and configuration provenance.",
1231
+ "Does not mutate files or manually reread configuration sources."
1232
+ ],
1233
+ "category": "positive",
1234
+ "expected_output": "Inspects the effective configuration generation and provenance.",
1235
+ "files": [],
1236
+ "forbidden_tools": [],
1237
+ "id": 171,
1238
+ "prompt": "Check the effective AST MCP configuration before editing.",
1239
+ "required_tools": ["config_status"],
1240
+ "surface": "config_status",
1241
+ "variant": "primary"
1242
+ },
1243
+ {
1244
+ "assertions": [
1245
+ "Uses one read-only status call and reports formatter selection order.",
1246
+ "Reports the global formatting enabled value and explicit fallback.",
1247
+ "Preserves first-match ordering and per-formatter enabled overrides."
1248
+ ],
1249
+ "category": "variant",
1250
+ "expected_output": "Reports formatting fallback and formatter selection.",
1251
+ "files": [],
1252
+ "forbidden_tools": [],
1253
+ "id": 172,
1254
+ "prompt": "Which formatter would AST MCP use for this project?",
1255
+ "required_tools": ["config_status"],
1256
+ "surface": "config_status",
1257
+ "variant": "formatting"
1258
+ },
1259
+ {
1260
+ "assertions": [
1261
+ "Does not inspect repository configuration for an unrelated prose request.",
1262
+ "Makes no MCP or filesystem tool call.",
1263
+ "Answers only from the supplied prose."
1264
+ ],
1265
+ "category": "negative",
1266
+ "expected_output": "Answers without tool use.",
1267
+ "files": [],
1268
+ "forbidden_tools": ["config_status"],
1269
+ "id": 173,
1270
+ "prompt": "Rewrite this sentence more concisely.",
1271
+ "required_tools": [],
1272
+ "surface": "config_status",
1273
+ "variant": "unrelated"
1274
+ },
1275
+ {
1276
+ "assertions": [
1277
+ "Batches multiple path decisions in one policy_check call.",
1278
+ "Includes canonical path, operation, tool, and matched rule evidence.",
1279
+ "Performs no mutation while explaining each decision."
1280
+ ],
1281
+ "category": "positive",
1282
+ "expected_output": "Explains read, write, and delete decisions without mutation.",
1283
+ "files": [],
1284
+ "forbidden_tools": [],
1285
+ "id": 174,
1286
+ "prompt": "Preflight read, write, and delete policy for three paths.",
1287
+ "required_tools": ["policy_check"],
1288
+ "surface": "policy_check",
1289
+ "variant": "primary"
1290
+ },
1291
+ {
1292
+ "assertions": [
1293
+ "Checks all independent paths in one batch.",
1294
+ "Reports matched rule source and specificity for every destination.",
1295
+ "Distinguishes allow, request, and deny without granting approval."
1296
+ ],
1297
+ "category": "variant",
1298
+ "expected_output": "Returns matched rules and provenance for each path.",
1299
+ "files": [],
1300
+ "forbidden_tools": [],
1301
+ "id": 175,
1302
+ "prompt": "Explain which safety rules match two external destinations.",
1303
+ "required_tools": ["policy_check"],
1304
+ "surface": "policy_check",
1305
+ "variant": "external"
1306
+ },
1307
+ {
1308
+ "assertions": [
1309
+ "Uses file_hash rather than policy_check when only a digest is requested.",
1310
+ "Uses one bounded hash call for the requested path.",
1311
+ "Does not retrieve file contents or invoke policy_check."
1312
+ ],
1313
+ "category": "negative",
1314
+ "expected_output": "Hashes the file directly.",
1315
+ "files": [],
1316
+ "forbidden_tools": ["policy_check"],
1317
+ "id": 176,
1318
+ "prompt": "Return the SHA-256 for README.md.",
1319
+ "required_tools": ["file_hash"],
1320
+ "surface": "policy_check",
1321
+ "variant": "hash-near-miss"
1322
+ },
1323
+ {
1324
+ "assertions": [
1325
+ "Uses RFC 6901 selectors and returns a whole-file hash.",
1326
+ "Batches both selectors in one document_query call.",
1327
+ "Returns bounded values and source locations without whole-file content."
1328
+ ],
1329
+ "category": "positive",
1330
+ "expected_output": "Queries bounded values from a TOML manifest.",
1331
+ "files": [],
1332
+ "forbidden_tools": [],
1333
+ "id": 177,
1334
+ "prompt": "Read /version and /formatting/fallback from ast-mcp.toml.",
1335
+ "required_tools": ["document_query"],
1336
+ "surface": "document_query",
1337
+ "variant": "primary"
1338
+ },
1339
+ {
1340
+ "assertions": [
1341
+ "Batches multiple selectors in one document_query call.",
1342
+ "Uses RFC 6901 escaping and selector semantics.",
1343
+ "Reports selected values, source locations, and the whole-file hash."
1344
+ ],
1345
+ "category": "variant",
1346
+ "expected_output": "Returns selected JSONC values and locations.",
1347
+ "files": [],
1348
+ "forbidden_tools": [],
1349
+ "id": 178,
1350
+ "prompt": "Inspect three keys from a JSONC manifest without reading the entire file.",
1351
+ "required_tools": ["document_query"],
1352
+ "surface": "document_query",
1353
+ "variant": "jsonc-batch"
1354
+ },
1355
+ {
1356
+ "assertions": [
1357
+ "Uses AST intelligence rather than document_query for TypeScript source.",
1358
+ "Uses show for the requested createServer implementation.",
1359
+ "Does not read the whole source file or invoke document_query."
1360
+ ],
1361
+ "category": "negative",
1362
+ "expected_output": "Routes source inspection to show.",
1363
+ "files": [],
1364
+ "forbidden_tools": ["document_query"],
1365
+ "id": 179,
1366
+ "prompt": "Show the createServer implementation in src/server.ts.",
1367
+ "required_tools": ["show"],
1368
+ "surface": "document_query",
1369
+ "variant": "ast-near-miss"
1370
+ },
1371
+ {
1372
+ "assertions": [
1373
+ "Uses file_hash when only a whole-file digest is requested.",
1374
+ "Does not retrieve source, document values, or bounded text.",
1375
+ "Performs no mutation."
1376
+ ],
1377
+ "category": "negative",
1378
+ "expected_output": "Routes hash-only inspection directly to file_hash.",
1379
+ "files": [],
1380
+ "forbidden_tools": ["file_read"],
1381
+ "id": 183,
1382
+ "prompt": "Return the SHA-256 for src/server.ts without reading its contents.",
1383
+ "required_tools": ["file_hash"],
1384
+ "surface": "file_read",
1385
+ "variant": "hash-only-near-miss"
1386
+ },
1387
+ {
1388
+ "assertions": [
1389
+ "Uses config_core for a grouped core section instead of rewriting ast-mcp.toml.",
1390
+ "Does not call file_write or file_patch on the configuration file.",
1391
+ "Leaves [[paths]] unchanged."
1392
+ ],
1393
+ "category": "positive",
1394
+ "expected_output": "Updates a core ast-mcp.toml section through config_core.",
1395
+ "files": [],
1396
+ "forbidden_tools": ["file_write", "file_patch"],
1397
+ "id": 184,
1398
+ "prompt": "Turn off require_hash in the project ast-mcp.toml without rewriting the whole file.",
1399
+ "required_tools": ["config_core"],
1400
+ "surface": "config_core",
1401
+ "variant": "primary"
1402
+ },
1403
+ {
1404
+ "assertions": [
1405
+ "Batches workspace and formatting keys in one config_core call.",
1406
+ "Does not send one call per individual key.",
1407
+ "Does not change [[paths]]."
1408
+ ],
1409
+ "category": "variant",
1410
+ "expected_output": "Updates multiple core sections in one grouped config_core call.",
1411
+ "files": [],
1412
+ "forbidden_tools": ["config_paths"],
1413
+ "id": 185,
1414
+ "prompt": "Set workspace.worktrees to request and formatting.fallback to reject in one configuration change.",
1415
+ "required_tools": ["config_core"],
1416
+ "surface": "config_core",
1417
+ "variant": "grouped-sections"
1418
+ },
1419
+ {
1420
+ "assertions": [
1421
+ "Does not rewrite ast-mcp.toml through file_write.",
1422
+ "Selects config_core for a core section change.",
1423
+ "Avoids direct filesystem or shell mutation."
1424
+ ],
1425
+ "category": "negative",
1426
+ "expected_output": "Does not route this near-miss to file_write; selects config_core.",
1427
+ "files": [],
1428
+ "forbidden_tools": ["file_write"],
1429
+ "id": 186,
1430
+ "prompt": "Replace the entire ast-mcp.toml contents to change only the HTTP port.",
1431
+ "required_tools": ["config_core"],
1432
+ "surface": "config_core",
1433
+ "variant": "whole-file-near-miss"
1434
+ },
1435
+ {
1436
+ "assertions": [
1437
+ "Uses config_paths to add a [[paths]] rule by id.",
1438
+ "Does not call config_core for path rules.",
1439
+ "Does not rewrite the whole configuration file."
1440
+ ],
1441
+ "category": "positive",
1442
+ "expected_output": "Adds a path rule through config_paths.",
1443
+ "files": [],
1444
+ "forbidden_tools": ["config_core", "file_write"],
1445
+ "id": 187,
1446
+ "prompt": "Add a docs path rule that allows read and requests write.",
1447
+ "required_tools": ["config_paths"],
1448
+ "surface": "config_paths",
1449
+ "variant": "primary"
1450
+ },
1451
+ {
1452
+ "assertions": [
1453
+ "Batches add, update, and remove path operations in one config_paths call.",
1454
+ "Identifies existing rules by id.",
1455
+ "Does not change core sections."
1456
+ ],
1457
+ "category": "variant",
1458
+ "expected_output": "Applies a batched config_paths operations list.",
1459
+ "files": [],
1460
+ "forbidden_tools": ["config_core"],
1461
+ "id": 188,
1462
+ "prompt": "In one call, add a vendor path rule, update the workspace rule excludes, and remove the unused temp rule.",
1463
+ "required_tools": ["config_paths"],
1464
+ "surface": "config_paths",
1465
+ "variant": "batched-operations"
1466
+ },
1467
+ {
1468
+ "assertions": [
1469
+ "Does not use config_core to change [[paths]].",
1470
+ "Selects config_paths for path rule mutation.",
1471
+ "Avoids a whole-file rewrite."
1472
+ ],
1473
+ "category": "negative",
1474
+ "expected_output": "Does not route this near-miss to config_core; selects config_paths.",
1475
+ "files": [],
1476
+ "forbidden_tools": ["config_core"],
1477
+ "id": 189,
1478
+ "prompt": "Use config_core to add a new [[paths]] rule for ./vendor.",
1479
+ "required_tools": ["config_paths"],
1480
+ "surface": "config_paths",
1481
+ "variant": "core-near-miss"
1178
1482
  }
1179
1483
  ],
1180
1484
  "mcp_tools": [
1485
+ "config_status",
1486
+ "config_core",
1487
+ "config_paths",
1488
+ "document_query",
1489
+ "file_capabilities",
1490
+ "policy_check",
1181
1491
  "file_chattr",
1182
1492
  "file_delete",
1183
1493
  "file_rename",
@@ -40,14 +40,18 @@ type TranscriptCall = {
40
40
 
41
41
  export type TranscriptScore = {
42
42
  astMcpOutputChars: number;
43
+ batchDensity: number;
44
+ callsPerModelTurn: number;
43
45
  errors: string[];
44
46
  evaluatedCases: number;
45
47
  execBatches: number;
46
48
  mutationCalls: number;
49
+ parallelReadOnlyCalls: number;
47
50
  passed: boolean;
48
51
  session: string;
49
52
  toolCalls: Record<string, number>;
50
53
  unscoredBatches: number;
54
+ validationErrorCodes: Record<string, number>;
51
55
  verifiedAssertions: number;
52
56
  };
53
57
 
@@ -416,6 +420,50 @@ function validateStrictMatrix(
416
420
  }
417
421
  }
418
422
 
423
+ function targetCount(value: unknown, key = ""): number {
424
+ if (Array.isArray(value))
425
+ return [
426
+ "filePaths",
427
+ "paths",
428
+ "symbols",
429
+ "files",
430
+ "checks",
431
+ "selectors",
432
+ ].includes(key)
433
+ ? value.length
434
+ : Math.max(0, ...value.map((item) => targetCount(item)));
435
+ if (!value || typeof value !== "object") return 0;
436
+ const record = value as Record<string, unknown>;
437
+ const own = key === "files" ? Object.keys(record).length : 0;
438
+ return Math.max(
439
+ own,
440
+ ...Object.entries(record).map(([childKey, child]) =>
441
+ targetCount(child, childKey),
442
+ ),
443
+ );
444
+ }
445
+
446
+ function invocationTargetCount(invocation: Invocation): number {
447
+ try {
448
+ return targetCount(JSON.parse(invocation.input));
449
+ } catch {
450
+ const match = invocation.input.match(
451
+ /(?:filePaths|paths|symbols)\s*:\s*\[([^\]]*)\]/s,
452
+ );
453
+ return match?.[1]?.trim() ? match[1].split(",").filter(Boolean).length : 0;
454
+ }
455
+ }
456
+
457
+ function validationErrorCodes(calls: Map<string, TranscriptCall>) {
458
+ const codes: Record<string, number> = {};
459
+ for (const call of calls.values()) {
460
+ const text = outputText(call.output?.output);
461
+ for (const match of text.matchAll(/["']code["']\s*:\s*["']([^"']+)["']/g))
462
+ codes[match[1]] = (codes[match[1]] ?? 0) + 1;
463
+ }
464
+ return codes;
465
+ }
466
+
419
467
  export async function scoreTranscript(
420
468
  sessionPath: string,
421
469
  strict = false,
@@ -446,16 +494,48 @@ export async function scoreTranscript(
446
494
  (toolCalls.file_patch ?? 0) +
447
495
  (toolCalls.file_write ?? 0) +
448
496
  (toolCalls.file_rename ?? 0);
497
+ const invocations = [...collector.calls.values()].flatMap(
498
+ (call) => call.invocations,
499
+ );
500
+ const batched = invocations.filter(
501
+ (invocation) => invocationTargetCount(invocation) > 1,
502
+ ).length;
503
+ const statefulTools = new Set([
504
+ "file_chattr",
505
+ "file_delete",
506
+ "file_patch",
507
+ "file_rename",
508
+ "file_write",
509
+ "find_related",
510
+ "index",
511
+ "search",
512
+ ]);
513
+ const parallelReadOnlyCalls = invocations.filter(
514
+ (invocation) =>
515
+ invocation.concurrent &&
516
+ !statefulTools.has(invocation.tool) &&
517
+ !(
518
+ invocation.tool === "run" &&
519
+ /(?:["']write["']|\bwrite)\s*:\s*true/.test(invocation.input)
520
+ ),
521
+ ).length;
449
522
  return {
450
523
  astMcpOutputChars: outputChars,
524
+ batchDensity: invocations.length === 0 ? 0 : batched / invocations.length,
525
+ callsPerModelTurn:
526
+ collector.calls.size === 0
527
+ ? 0
528
+ : invocations.length / collector.calls.size,
451
529
  errors: collector.errors,
452
530
  evaluatedCases: result.evaluatedCases,
453
531
  execBatches: collector.calls.size,
454
532
  mutationCalls,
533
+ parallelReadOnlyCalls,
455
534
  passed: collector.errors.length === 0,
456
535
  session: sessionPath,
457
536
  toolCalls,
458
537
  unscoredBatches: grouped.unscoredBatches,
538
+ validationErrorCodes: validationErrorCodes(collector.calls),
459
539
  verifiedAssertions: result.verifiedAssertions,
460
540
  };
461
541
  }
@@ -25,12 +25,14 @@ const toolKeys: Record<string, string[]> = {
25
25
  context: ["target"],
26
26
  deps: ["file"],
27
27
  digest: ["paths"],
28
+ document_query: ["filePath", "selectors"],
28
29
  file_hash: ["filePaths"],
29
30
  file_read: ["files"],
30
31
  find_related: ["path", "line"],
31
32
  impact: ["target"],
32
33
  implements: ["paths", "target"],
33
34
  map: ["paths"],
35
+ policy_check: ["checks"],
34
36
  reverse_deps: ["file"],
35
37
  run: ["pattern"],
36
38
  search: ["query"],
@@ -146,7 +148,7 @@ const inputValidators: Record<string, InputValidator> = {
146
148
 
147
149
  function meaningfulInput(invocation: Invocation) {
148
150
  const input = withoutComments(invocation.input).trim();
149
- if (!input || input === "{}") return false;
151
+ if (!input || input === "{}") return invocation.tool === "config_status";
150
152
  const validator = inputValidators[invocation.tool];
151
153
  if (validator) return validator(input);
152
154
  return (toolKeys[invocation.tool] ?? []).every((key) => hasKey(input, key));