@mwillbanks/ast-mcp 0.1.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 (61) hide show
  1. package/CONTRIBUTING.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +109 -0
  4. package/dist/ast-mcp-hook.js +7 -0
  5. package/dist/ast-mcp-hook.js.map +11 -0
  6. package/dist/ast-mcp-install.js +22 -0
  7. package/dist/ast-mcp-install.js.map +12 -0
  8. package/dist/ast-mcp.js +115 -0
  9. package/dist/ast-mcp.js.map +89 -0
  10. package/dprint.json +37 -0
  11. package/logo.svg +1 -0
  12. package/package.json +89 -0
  13. package/src/ast-bro/capability.ts +21 -0
  14. package/src/ast-bro/client.ts +47 -0
  15. package/src/ast-bro/result.ts +42 -0
  16. package/src/ast-bro/rewrite-capability.ts +9 -0
  17. package/src/ast-bro/tools.json +603 -0
  18. package/src/hook.ts +79 -0
  19. package/src/http-entry.ts +3 -0
  20. package/src/http.ts +138 -0
  21. package/src/index.ts +8 -0
  22. package/src/installer.ts +501 -0
  23. package/src/lifecycle.ts +10 -0
  24. package/src/managed-hook.ts +4 -0
  25. package/src/patch/aider.ts +224 -0
  26. package/src/patch/engine.ts +446 -0
  27. package/src/patch/languages.ts +36 -0
  28. package/src/runtime/atomic.ts +26 -0
  29. package/src/runtime/attributes.ts +70 -0
  30. package/src/runtime/file-delete.ts +96 -0
  31. package/src/runtime/file-read.ts +178 -0
  32. package/src/runtime/format.ts +56 -0
  33. package/src/runtime/hash.ts +11 -0
  34. package/src/runtime/locks.ts +87 -0
  35. package/src/runtime/paths.ts +73 -0
  36. package/src/runtime/process-input.ts +25 -0
  37. package/src/runtime/signals.ts +47 -0
  38. package/src/server.ts +13 -0
  39. package/src/stdio.ts +154 -0
  40. package/src/tools/ast-bro.ts +172 -0
  41. package/src/tools/files.ts +173 -0
  42. package/src/tools/index.ts +11 -0
  43. package/src/tools/lifecycle.ts +124 -0
  44. package/templates/AGENTS.md +56 -0
  45. package/templates/skills/ast-mcp/SKILL.md +96 -0
  46. package/templates/skills/ast-mcp/agents/openai.yaml +4 -0
  47. package/templates/skills/ast-mcp/evals/batch.evals.json +274 -0
  48. package/templates/skills/ast-mcp/evals/evals.json +1209 -0
  49. package/templates/skills/ast-mcp/evals/file-hash.evals.json +50 -0
  50. package/templates/skills/ast-mcp/evals/measure.ts +18 -0
  51. package/templates/skills/ast-mcp/evals/results.md +17 -0
  52. package/templates/skills/ast-mcp/evals/score.ts +417 -0
  53. package/templates/skills/ast-mcp/evals/semantic.ts +332 -0
  54. package/templates/skills/ast-mcp/evals/trigger-queries.json +22 -0
  55. package/templates/skills/ast-mcp/evals/validate.ts +99 -0
  56. package/templates/skills/ast-mcp/references/installation.md +40 -0
  57. package/templates/skills/ast-mcp/references/managed-hook.ts +3 -0
  58. package/templates/skills/ast-mcp/references/patch-state-machine.md +39 -0
  59. package/templates/skills/ast-mcp/references/tool-catalog.md +46 -0
  60. package/templates/skills/ast-mcp/scripts/check-install.ts +269 -0
  61. package/templates/skills/ast-mcp/scripts/managed-hook.ts +22 -0
@@ -0,0 +1,603 @@
1
+ {
2
+ "callees": {
3
+ "description": "What does this symbol call? — AST-accurate forward call traversal. Suffix-matches the target like `callers`. Unresolved/external callees shown by default (tagged cyan/red). Returns text by default; set `json: true` for `ast-bro.callees.v1`.",
4
+ "inputSchema": {
5
+ "properties": {
6
+ "depth": {
7
+ "description": "Max BFS depth (default 1).",
8
+ "minimum": 1,
9
+ "type": "integer"
10
+ },
11
+ "hide_external": {
12
+ "description": "Drop unresolved/external callees. Default: false (shown with [unresolved]/[external] tags).",
13
+ "type": "boolean"
14
+ },
15
+ "json": {
16
+ "type": "boolean"
17
+ },
18
+ "path": {
19
+ "description": "Repo root (default \".\").",
20
+ "type": "string"
21
+ },
22
+ "rebuild": {
23
+ "type": "boolean"
24
+ },
25
+ "target": {
26
+ "description": "Symbol name to look up.",
27
+ "type": "string"
28
+ }
29
+ },
30
+ "required": ["target"],
31
+ "type": "object"
32
+ }
33
+ },
34
+ "callers": {
35
+ "description": "Find callers of a symbol — AST-accurate, no grep noise. Suffix-matches the target like `show`/`implements`: `TakeDamage`, or `Type.method` when ambiguous. Ambiguous matches shown by default (tagged red). Returns text by default; set `json: true` for `ast-bro.callers.v1`.",
36
+ "inputSchema": {
37
+ "properties": {
38
+ "depth": {
39
+ "description": "Max BFS depth (default 1).",
40
+ "minimum": 1,
41
+ "type": "integer"
42
+ },
43
+ "hide_ambiguous": {
44
+ "description": "Drop callers with multiple candidates. Default: false (shown with Ambiguous tag).",
45
+ "type": "boolean"
46
+ },
47
+ "json": {
48
+ "type": "boolean"
49
+ },
50
+ "limit": {
51
+ "description": "Cap result count (default 200).",
52
+ "minimum": 1,
53
+ "type": "integer"
54
+ },
55
+ "path": {
56
+ "description": "Repo root (default \".\").",
57
+ "type": "string"
58
+ },
59
+ "rebuild": {
60
+ "type": "boolean"
61
+ },
62
+ "target": {
63
+ "description": "Symbol name to look up.",
64
+ "type": "string"
65
+ }
66
+ },
67
+ "required": ["target"],
68
+ "type": "object"
69
+ }
70
+ },
71
+ "context": {
72
+ "description": "Token-budgeted context for a symbol — target body + direct callees (bodies) + callers/transitive (signatures), greedily packed into a caller-supplied token budget. Replaces chains of 4–5 `show`/`callers`/`callees` calls with ONE context-aware payload. Budget degrades gracefully from full bodies to signatures only. Returns text by default; set `json: true` for `ast-bro.context.v1`.",
73
+ "inputSchema": {
74
+ "properties": {
75
+ "budget": {
76
+ "description": "Token budget (default 8000). ~4 bytes per token rough.",
77
+ "minimum": 100,
78
+ "type": "integer"
79
+ },
80
+ "json": {
81
+ "type": "boolean"
82
+ },
83
+ "path": {
84
+ "description": "Repo root (default \".\").",
85
+ "type": "string"
86
+ },
87
+ "target": {
88
+ "description": "Symbol to build context for (same form as callers).",
89
+ "type": "string"
90
+ }
91
+ },
92
+ "required": ["target"],
93
+ "type": "object"
94
+ }
95
+ },
96
+ "cycles": {
97
+ "description": "Find import cycles via Tarjan SCC. Returns the list of strongly-connected components with `len > 1` (or singletons with self-edges). Returns text by default; set `json: true` for `ast-bro.cycles.v1`. Exits non-zero when cycles exist (useful for CI gates).",
98
+ "inputSchema": {
99
+ "properties": {
100
+ "json": {
101
+ "type": "boolean"
102
+ },
103
+ "min_size": {
104
+ "description": "Drop SCCs smaller than this (default 2).",
105
+ "minimum": 1,
106
+ "type": "integer"
107
+ },
108
+ "path": {
109
+ "description": "Repo root (default \".\").",
110
+ "type": "string"
111
+ },
112
+ "rebuild": {
113
+ "type": "boolean"
114
+ }
115
+ },
116
+ "type": "object"
117
+ }
118
+ },
119
+ "deps": {
120
+ "description": "Forward import-graph traversal: what does this file import (transitively)? Builds a per-repo dep graph at `.ast-bro/deps/graph.bin` on first call, then reuses it. Returns text by default; set `json: true` for `ast-bro.deps.v1`.",
121
+ "inputSchema": {
122
+ "properties": {
123
+ "depth": {
124
+ "description": "Max BFS depth (default 3).",
125
+ "minimum": 1,
126
+ "type": "integer"
127
+ },
128
+ "file": {
129
+ "description": "Path to the file whose imports to follow.",
130
+ "type": "string"
131
+ },
132
+ "hide_external": {
133
+ "description": "Drop unresolved imports. Default: false (shown with [external] tag).",
134
+ "type": "boolean"
135
+ },
136
+ "json": {
137
+ "type": "boolean"
138
+ },
139
+ "rebuild": {
140
+ "description": "Drop the cached graph and rebuild.",
141
+ "type": "boolean"
142
+ }
143
+ },
144
+ "required": ["file"],
145
+ "type": "object"
146
+ }
147
+ },
148
+ "digest": {
149
+ "description": "One-page module map for an unfamiliar directory: every file's types and public methods. Returns text by default; set `json: true` for `ast-bro.map.v1`.",
150
+ "inputSchema": {
151
+ "properties": {
152
+ "include_fields": {
153
+ "type": "boolean"
154
+ },
155
+ "include_private": {
156
+ "type": "boolean"
157
+ },
158
+ "json": {
159
+ "type": "boolean"
160
+ },
161
+ "max_members": {
162
+ "description": "Cap members per type (default 50).",
163
+ "type": "integer"
164
+ },
165
+ "paths": {
166
+ "description": "Files or directories to digest.",
167
+ "items": {
168
+ "type": "string"
169
+ },
170
+ "minItems": 1,
171
+ "type": "array"
172
+ }
173
+ },
174
+ "required": ["paths"],
175
+ "type": "object"
176
+ }
177
+ },
178
+ "find_related": {
179
+ "description": "Find chunks semantically similar to a given file:line. Useful for navigating to related code. Returns text by default; set `json: true` for `ast-bro.related.v1`.",
180
+ "inputSchema": {
181
+ "properties": {
182
+ "json": {
183
+ "type": "boolean"
184
+ },
185
+ "line": {
186
+ "description": "1-indexed line within `path`.",
187
+ "minimum": 1,
188
+ "type": "integer"
189
+ },
190
+ "path": {
191
+ "description": "Repo-relative path of the source chunk.",
192
+ "type": "string"
193
+ },
194
+ "root": {
195
+ "description": "Repo root containing the index (default \".\").",
196
+ "type": "string"
197
+ },
198
+ "top_k": {
199
+ "description": "Max results (default 10).",
200
+ "minimum": 1,
201
+ "type": "integer"
202
+ }
203
+ },
204
+ "required": ["path", "line"],
205
+ "type": "object"
206
+ }
207
+ },
208
+ "graph": {
209
+ "description": "Emit the file-level dependency graph. Unresolved external imports shown by default (tagged `[external]`). Returns text by default; set `json: true` for `ast-bro.graph.v1`.",
210
+ "inputSchema": {
211
+ "properties": {
212
+ "hide_external": {
213
+ "description": "Drop unresolved imports. Default: false (shown with [external] tag).",
214
+ "type": "boolean"
215
+ },
216
+ "json": {
217
+ "description": "Return JSON (schema `ast-bro.graph.v1`) instead of text.",
218
+ "type": "boolean"
219
+ },
220
+ "path": {
221
+ "description": "Repo root (default \".\").",
222
+ "type": "string"
223
+ },
224
+ "rebuild": {
225
+ "type": "boolean"
226
+ }
227
+ },
228
+ "type": "object"
229
+ }
230
+ },
231
+ "impact": {
232
+ "description": "Cross-file impact analysis: callers + callees + file reverse-deps + test detection in one call. Answers 'what would break if I change X?' and 'how wide is the blast radius?' in one shot. Four modes: `deps` (what it calls/imports), `dependents` (who calls/imports it), `tests` (affected tests only), `all` (default). Returns text by default; set `json: true` for `ast-bro.impact.v1`.",
233
+ "inputSchema": {
234
+ "properties": {
235
+ "depth": {
236
+ "description": "Transitive depth (default 2).",
237
+ "minimum": 1,
238
+ "type": "integer"
239
+ },
240
+ "exclude_tests": {
241
+ "description": "Exclude test files from output.",
242
+ "type": "boolean"
243
+ },
244
+ "hide_ambiguous": {
245
+ "description": "Drop ambiguous call-edge matches. Default: false (shown with Ambiguous tag).",
246
+ "type": "boolean"
247
+ },
248
+ "json": {
249
+ "type": "boolean"
250
+ },
251
+ "limit": {
252
+ "description": "Result cap per section (default 200).",
253
+ "minimum": 1,
254
+ "type": "integer"
255
+ },
256
+ "mode": {
257
+ "description": "Section: 'deps', 'dependents', 'tests', or 'all' (default).",
258
+ "enum": ["deps", "dependents", "tests", "all"],
259
+ "type": "string"
260
+ },
261
+ "path": {
262
+ "description": "Repo root (default \".\").",
263
+ "type": "string"
264
+ },
265
+ "target": {
266
+ "description": "Symbol to analyse (e.g. 'handleRequest', 'Player.TakeDamage', 'src/Player.cs:TakeDamage').",
267
+ "type": "string"
268
+ },
269
+ "tests": {
270
+ "description": "Show only test files.",
271
+ "type": "boolean"
272
+ }
273
+ },
274
+ "required": ["target"],
275
+ "type": "object"
276
+ }
277
+ },
278
+ "implements": {
279
+ "description": "Find subclasses / implementations of a type using AST matching. Transitive by default — set `direct: true` for level-1 only. Returns text by default; set `json: true` for `ast-bro.implements.v1`.",
280
+ "inputSchema": {
281
+ "properties": {
282
+ "direct": {
283
+ "description": "Direct subtypes only (skip transitive).",
284
+ "type": "boolean"
285
+ },
286
+ "json": {
287
+ "type": "boolean"
288
+ },
289
+ "paths": {
290
+ "description": "Files or directories to search.",
291
+ "items": {
292
+ "type": "string"
293
+ },
294
+ "minItems": 1,
295
+ "type": "array"
296
+ },
297
+ "target": {
298
+ "description": "Type name to look up.",
299
+ "type": "string"
300
+ }
301
+ },
302
+ "required": ["target", "paths"],
303
+ "type": "object"
304
+ }
305
+ },
306
+ "index": {
307
+ "description": "Build, refresh, or inspect the per-repo search index. With `stats: true` returns index stats. With `rebuild: true` drops the cache and rebuilds. Otherwise just opens (and incrementally refreshes if files changed). Returns text by default; set `json: true` for `ast-bro.index-stats.v1`.",
308
+ "inputSchema": {
309
+ "properties": {
310
+ "json": {
311
+ "type": "boolean"
312
+ },
313
+ "path": {
314
+ "description": "Repo root (default \".\").",
315
+ "type": "string"
316
+ },
317
+ "rebuild": {
318
+ "description": "Drop existing cache and rebuild.",
319
+ "type": "boolean"
320
+ },
321
+ "stats": {
322
+ "description": "Print index stats and return.",
323
+ "type": "boolean"
324
+ }
325
+ },
326
+ "type": "object"
327
+ }
328
+ },
329
+ "map": {
330
+ "description": "AST-based structural map of source files — signatures with line ranges, no method bodies. Returns text by default (5–10× smaller than reading the file). Set `json: true` for the machine-readable schema `ast-bro.map.v1`.",
331
+ "inputSchema": {
332
+ "properties": {
333
+ "glob": {
334
+ "description": "Glob filter applied during directory walk.",
335
+ "type": "string"
336
+ },
337
+ "json": {
338
+ "description": "Return JSON (schema `ast-bro.map.v1`) instead of text.",
339
+ "type": "boolean"
340
+ },
341
+ "no_attrs": {
342
+ "description": "Hide attributes / decorators.",
343
+ "type": "boolean"
344
+ },
345
+ "no_docs": {
346
+ "description": "Hide doc comments.",
347
+ "type": "boolean"
348
+ },
349
+ "no_fields": {
350
+ "description": "Hide field declarations.",
351
+ "type": "boolean"
352
+ },
353
+ "no_lines": {
354
+ "description": "Hide line-range suffixes.",
355
+ "type": "boolean"
356
+ },
357
+ "no_private": {
358
+ "description": "Hide private declarations.",
359
+ "type": "boolean"
360
+ },
361
+ "paths": {
362
+ "description": "Files or directories to map.",
363
+ "items": {
364
+ "type": "string"
365
+ },
366
+ "minItems": 1,
367
+ "type": "array"
368
+ }
369
+ },
370
+ "required": ["paths"],
371
+ "type": "object"
372
+ }
373
+ },
374
+ "reverse_deps": {
375
+ "description": "Reverse import-graph: who imports this file (transitively)? Useful for refactor blast-radius assessment. Returns text by default; set `json: true` for `ast-bro.reverse-deps.v1`.",
376
+ "inputSchema": {
377
+ "properties": {
378
+ "depth": {
379
+ "description": "Max BFS depth (default 3).",
380
+ "minimum": 1,
381
+ "type": "integer"
382
+ },
383
+ "file": {
384
+ "description": "Path to the file whose importers to find.",
385
+ "type": "string"
386
+ },
387
+ "json": {
388
+ "type": "boolean"
389
+ },
390
+ "limit": {
391
+ "description": "Cap result count (default 200).",
392
+ "minimum": 1,
393
+ "type": "integer"
394
+ },
395
+ "rebuild": {
396
+ "type": "boolean"
397
+ }
398
+ },
399
+ "required": ["file"],
400
+ "type": "object"
401
+ }
402
+ },
403
+ "run": {
404
+ "description": "AST-aware pattern search and rewrite. Use metavariables like $FUNC, $ARG, $$$BODY for structural matching. Search-only without rewrite; transform code with rewrite and write. WARNING: `write: true` mutates files on disk — a broad pattern can touch many files at once (capped at 50 per call). Always preview with the default dry-run first and confirm the diff before re-running with `write: true`. Returns text by default; set `json: true` for `ast-bro.run.v1`.",
405
+ "inputSchema": {
406
+ "properties": {
407
+ "glob": {
408
+ "description": "Glob pattern to filter files, e.g. '**/*.rs'.",
409
+ "type": "string"
410
+ },
411
+ "json": {
412
+ "description": "Return results as JSON instead of text.",
413
+ "type": "boolean"
414
+ },
415
+ "lang": {
416
+ "description": "Language (auto-detected from file paths if omitted).",
417
+ "type": "string"
418
+ },
419
+ "paths": {
420
+ "description": "Files or directories to search.",
421
+ "items": {
422
+ "type": "string"
423
+ },
424
+ "minItems": 1,
425
+ "type": "array"
426
+ },
427
+ "pattern": {
428
+ "description": "AST pattern with metavariables (e.g. '$FUNC($$$)').",
429
+ "type": "string"
430
+ },
431
+ "rewrite": {
432
+ "description": "Replacement template (e.g. 'bar($A)'). Omit for search-only.",
433
+ "type": "string"
434
+ },
435
+ "write": {
436
+ "description": "Write changes to disk. Default: false (dry-run). DANGEROUS: mutates files; preview the dry-run diff first and confirm before flipping to true.",
437
+ "type": "boolean"
438
+ }
439
+ },
440
+ "required": ["pattern"],
441
+ "type": "object"
442
+ }
443
+ },
444
+ "search": {
445
+ "description": "Hybrid BM25 + dense semantic search over the repo. First call builds a per-repo index at `.ast-bro/index/` (one-time, ~seconds for typical repos). Returns text by default; set `json: true` for `ast-bro.search.v1`.",
446
+ "inputSchema": {
447
+ "properties": {
448
+ "alpha": {
449
+ "description": "Override semantic-vs-BM25 weight (0.0=pure BM25, 1.0=pure semantic). Default auto-detects from query type.",
450
+ "type": "number"
451
+ },
452
+ "json": {
453
+ "description": "Return JSON (schema `ast-bro.search.v1`) instead of text.",
454
+ "type": "boolean"
455
+ },
456
+ "languages": {
457
+ "description": "Restrict to chunks of these languages (e.g. [\"rust\", \"python\"]).",
458
+ "items": {
459
+ "type": "string"
460
+ },
461
+ "type": "array"
462
+ },
463
+ "path": {
464
+ "description": "Repo root to search in (default \".\").",
465
+ "type": "string"
466
+ },
467
+ "query": {
468
+ "description": "Search query (free-form text or symbol name).",
469
+ "type": "string"
470
+ },
471
+ "top_k": {
472
+ "description": "Max results to return (default 10).",
473
+ "minimum": 1,
474
+ "type": "integer"
475
+ }
476
+ },
477
+ "required": ["query"],
478
+ "type": "object"
479
+ }
480
+ },
481
+ "show": {
482
+ "description": "Extract source of one or more symbols from a single file. Suffix matching: `TakeDamage`, or `Player.TakeDamage` when ambiguous. For markdown the symbol is a heading. Returns text by default; set `json: true` for `ast-bro.show.v1`.",
483
+ "inputSchema": {
484
+ "properties": {
485
+ "json": {
486
+ "type": "boolean"
487
+ },
488
+ "path": {
489
+ "description": "File to search.",
490
+ "type": "string"
491
+ },
492
+ "symbols": {
493
+ "description": "One or more symbol names to extract.",
494
+ "items": {
495
+ "type": "string"
496
+ },
497
+ "minItems": 1,
498
+ "type": "array"
499
+ }
500
+ },
501
+ "required": ["path", "symbols"],
502
+ "type": "object"
503
+ }
504
+ },
505
+ "squeeze": {
506
+ "description": "Compress repetitive log/text with a reversible legend (logs, not code).",
507
+ "inputSchema": {
508
+ "properties": {
509
+ "end": {
510
+ "description": "1-indexed inclusive end line of the slice.",
511
+ "minimum": 1,
512
+ "type": "integer"
513
+ },
514
+ "json": {
515
+ "description": "Return JSON (schema `ast-bro.squeeze.v1`) instead of text.",
516
+ "type": "boolean"
517
+ },
518
+ "path": {
519
+ "description": "Path to the log/text file to read.",
520
+ "type": "string"
521
+ },
522
+ "raw": {
523
+ "description": "Skip compression and emit the raw text.",
524
+ "type": "boolean"
525
+ },
526
+ "start": {
527
+ "description": "1-indexed inclusive start line of the slice.",
528
+ "minimum": 1,
529
+ "type": "integer"
530
+ }
531
+ },
532
+ "required": ["path"],
533
+ "type": "object"
534
+ }
535
+ },
536
+ "surface": {
537
+ "description": "True public API surface — resolves `pub use` re-exports (Rust) and `__all__` (Python) to compute exactly what a downstream user sees, not just every `pub`/non-underscore item per file. Falls back to visibility-filtered output for Java/C#/Go/Kotlin (no real re-export concept). Returns text by default; set `json: true` for `ast-bro.surface.v1`.",
538
+ "inputSchema": {
539
+ "properties": {
540
+ "include_chain": {
541
+ "description": "Append the via-chain on each entry (text mode only).",
542
+ "type": "boolean"
543
+ },
544
+ "include_private": {
545
+ "description": "Include private items — only meaningful for the fallback resolver.",
546
+ "type": "boolean"
547
+ },
548
+ "json": {
549
+ "type": "boolean"
550
+ },
551
+ "lang": {
552
+ "description": "Force a resolver: `rust`, `python`, or `fallback`.",
553
+ "type": "string"
554
+ },
555
+ "max_depth": {
556
+ "description": "Recursion guard for re-export chains (default 16).",
557
+ "type": "integer"
558
+ },
559
+ "path": {
560
+ "description": "Crate root file, package init, or directory to auto-detect (default \".\").",
561
+ "type": "string"
562
+ },
563
+ "tree": {
564
+ "description": "Render as a hierarchical tree grouped by module.",
565
+ "type": "boolean"
566
+ }
567
+ },
568
+ "type": "object"
569
+ }
570
+ },
571
+ "trace": {
572
+ "description": "Trace the static call path between two symbols — \"how does <from> reach <to>?\". Shortest-path BFS over the call graph with each hop's source body inlined, so a flow question (e.g. request→handler, update→render) is answered in ONE call instead of chaining `callers`/`callees`. If no static path exists the chain broke at dynamic dispatch — the response inlines both endpoints plus the target file's sibling callables. Targets are suffix-matched like `callers`. Returns text by default; set `json: true` for `ast-bro.trace.v1`.",
573
+ "inputSchema": {
574
+ "properties": {
575
+ "depth": {
576
+ "description": "Max path length in hops (default 12).",
577
+ "minimum": 1,
578
+ "type": "integer"
579
+ },
580
+ "from": {
581
+ "description": "Source symbol — where the path starts.",
582
+ "type": "string"
583
+ },
584
+ "json": {
585
+ "type": "boolean"
586
+ },
587
+ "path": {
588
+ "description": "Repo root (default \".\").",
589
+ "type": "string"
590
+ },
591
+ "rebuild": {
592
+ "type": "boolean"
593
+ },
594
+ "to": {
595
+ "description": "Destination symbol — where the path should reach.",
596
+ "type": "string"
597
+ }
598
+ },
599
+ "required": ["from", "to"],
600
+ "type": "object"
601
+ }
602
+ }
603
+ }
package/src/hook.ts ADDED
@@ -0,0 +1,79 @@
1
+ const direct =
2
+ /^(?:apply_patch|edit|editFiles|create|createFile|write|writeFile|replace|str_replace|MultiEdit|Edit|Write|NotebookEdit)$/;
3
+ const nestedDirect =
4
+ /tools(?:\.(?:apply_patch|edit|editFiles|create|createFile|write|writeFile|replace|str_replace|MultiEdit|Edit|Write|NotebookEdit)|\s*\[\s*["'](?:apply_patch|edit|editFiles|create|createFile|write|writeFile|replace|str_replace|MultiEdit|Edit|Write|NotebookEdit)["']\s*\])\s*\(/;
5
+ const shell =
6
+ /^(?:bash|shell|terminal|exec|functions\.exec|mcp__functions__exec|codex\.exec|exec_command|functions\.exec_command|Bash|powershell|PowerShell)$/;
7
+ const mutation =
8
+ /(?:^|[;&|]\s*|["'`]\s*|:\s*["'`]\s*)(?:(?:env(?:\s+(?:--?[^\s"'`]+|[A-Za-z_][A-Za-z0-9_]*=[^\s"'`]+))*|command|sudo(?:\s+--?[^\s"'`]+)*|nice(?:\s+--?[^\s"'`]+)*|nohup|busybox)\s+)*(?:(?:\/[^\s/"'`]+)*\/)?(?:apply_patch|patch|tee|truncate|touch|rm|mv|cp|install|dd|ed|awk|mkdir|rmdir|chmod|chown|python\d*|node|ruby|perl|php|sed|ast-grep)(?=\s|["'`]|$)|(?:^|[;&|]\s*|["'`]\s*|:\s*["'`]\s*)(?:find\b[^\n]*\s-delete\b|xargs\s+(?:[^\n]*\s)?rm\b|git(?:\s+(?:-[A-Za-z]\s+[^\s"'`]+|--?[^\s"'`]+))*\s+(?:apply|checkout|restore|reset|clean)|dprint\s+fmt|bun\s+(?:-e|--eval)|(?:Set|Add)-Content|Out-File|Remove-Item|Move-Item|Copy-Item|New-Item)(?=\s|["'`]|$)|(?:^|[^<\d>])>{1,2}(?!=)|<<[-~]?\s*\w/i;
9
+
10
+ const nestedInterpreter =
11
+ /(?:bash|sh|zsh|dash|ksh|fish|pwsh|powershell|node|python\d*|ruby|perl|php)(?:["']|\s)+(?:--?[A-Za-z][A-Za-z0-9-]*(?:=[^\s"']+)?(?:["']|\s)+)*(?:-c|--command|-Command|-e|--eval)(?=\s|["']|$)/i;
12
+ export interface HookDecision {
13
+ denied: boolean;
14
+ reason?: string;
15
+ }
16
+ export function evaluateHook(event: Record<string, unknown>): HookDecision {
17
+ const name = String(event.tool_name ?? event.toolName ?? event.name ?? "");
18
+ if (direct.test(name))
19
+ return {
20
+ denied: true,
21
+ reason: "Direct file editing is blocked. Use ast-mcp.",
22
+ };
23
+ if (!shell.test(name)) return { denied: false };
24
+ const raw =
25
+ event.tool_input ??
26
+ event.toolInput ??
27
+ event.toolArgs ??
28
+ event.input ??
29
+ event.args;
30
+ const input =
31
+ raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};
32
+ const command =
33
+ typeof raw === "string"
34
+ ? raw
35
+ : String(
36
+ input.cmd ??
37
+ input.command ??
38
+ input.script ??
39
+ input.source ??
40
+ input.code ??
41
+ "",
42
+ );
43
+ return command &&
44
+ (nestedDirect.test(command) ||
45
+ mutation.test(command) ||
46
+ nestedInterpreter.test(command))
47
+ ? { denied: true, reason: "Direct file mutation is blocked. Use ast-mcp." }
48
+ : { denied: false };
49
+ }
50
+ export function decisionPayload(
51
+ decision: HookDecision,
52
+ ): Record<string, unknown> {
53
+ if (!decision.denied) return {};
54
+ return {
55
+ hookSpecificOutput: {
56
+ hookEventName: "PreToolUse",
57
+ permissionDecision: "deny",
58
+ permissionDecisionReason: decision.reason,
59
+ },
60
+ permissionDecision: "deny",
61
+ permissionDecisionReason: decision.reason,
62
+ };
63
+ }
64
+ export async function runHook(
65
+ input: Promise<Record<string, unknown>> = Bun.stdin.json(),
66
+ ): Promise<number> {
67
+ try {
68
+ process.stdout.write(
69
+ `${JSON.stringify(decisionPayload(evaluateHook(await input)))}\n`,
70
+ );
71
+ return 0;
72
+ } catch (error) {
73
+ process.stdout.write(
74
+ `${JSON.stringify(decisionPayload({ denied: true, reason: `Invalid hook input: ${String(error)}` }))}\n`,
75
+ );
76
+ return 2;
77
+ }
78
+ }
79
+ if (import.meta.main) process.exit(await runHook());
@@ -0,0 +1,3 @@
1
+ import { startHttpServer } from "./http";
2
+
3
+ startHttpServer();