ace-swarm 1.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 (72) hide show
  1. package/README.md +113 -0
  2. package/assets/.agents/ACE/ACE-Init/AGENTS.md +275 -0
  3. package/assets/.agents/ACE/ACE-Init/instructions.md +177 -0
  4. package/assets/.agents/ACE/ACE_coders/AGENTS.md +97 -0
  5. package/assets/.agents/ACE/ACE_coders/INSTRUCTIONS.md +146 -0
  6. package/assets/.agents/ACE/UI/AGENTS.md +115 -0
  7. package/assets/.agents/ACE/UI/instructions.md +178 -0
  8. package/assets/.agents/ACE/VOS/AGENTS.md +72 -0
  9. package/assets/.agents/ACE/VOS/instructions.md +211 -0
  10. package/assets/.agents/skills/ace-orchestrator/SKILL.md +317 -0
  11. package/assets/.agents/skills/codemunch/SKILL.md +502 -0
  12. package/assets/.agents/skills/codesnipe/SKILL.md +629 -0
  13. package/assets/agent-state/DECISIONS.md +7 -0
  14. package/assets/agent-state/EVIDENCE_LOG.md +7 -0
  15. package/assets/agent-state/HANDOFF.json +24 -0
  16. package/assets/agent-state/MODULES/gates/gate-completeness.json +7 -0
  17. package/assets/agent-state/MODULES/gates/gate-correctness.json +7 -0
  18. package/assets/agent-state/MODULES/registry.json +15 -0
  19. package/assets/agent-state/MODULES/roles/capability-build.json +19 -0
  20. package/assets/agent-state/MODULES/roles/capability-docs.json +19 -0
  21. package/assets/agent-state/MODULES/roles/capability-ops.json +18 -0
  22. package/assets/agent-state/MODULES/roles/capability-qa.json +20 -0
  23. package/assets/agent-state/MODULES/roles/capability-research.json +19 -0
  24. package/assets/agent-state/MODULES/roles/capability-skeptic.json +20 -0
  25. package/assets/agent-state/MODULES/roles/capability-spec.json +18 -0
  26. package/assets/agent-state/RISKS.md +5 -0
  27. package/assets/agent-state/SCOPE.md +10 -0
  28. package/assets/agent-state/STATUS.md +6 -0
  29. package/assets/agent-state/TASK.md +16 -0
  30. package/assets/agent-state/TEAL_CONFIG.md +31 -0
  31. package/assets/instructions/ACE.instructions.md +177 -0
  32. package/assets/instructions/ACE_Coder.instructions.md +146 -0
  33. package/assets/instructions/ACE_UI.instructions.md +178 -0
  34. package/assets/instructions/ACE_VOS.instructions.md +211 -0
  35. package/assets/tasks/README.md +19 -0
  36. package/assets/tasks/SWARM_HANDOFF.example.json +53 -0
  37. package/assets/tasks/SWARM_HANDOFF.example_ui_to_coders.json +55 -0
  38. package/assets/tasks/SWARM_HANDOFF.example_vos_to_ui.json +55 -0
  39. package/assets/tasks/SWARM_HANDOFF.template.json +52 -0
  40. package/assets/tasks/cli_work_split.md +22 -0
  41. package/assets/tasks/lessons.md +17 -0
  42. package/assets/tasks/role_tasks.md +48 -0
  43. package/assets/tasks/todo.md +23 -0
  44. package/dist/cli.d.ts +3 -0
  45. package/dist/cli.d.ts.map +1 -0
  46. package/dist/cli.js +88 -0
  47. package/dist/cli.js.map +1 -0
  48. package/dist/helpers.d.ts +50 -0
  49. package/dist/helpers.d.ts.map +1 -0
  50. package/dist/helpers.js +379 -0
  51. package/dist/helpers.js.map +1 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +7 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/prompts.d.ts +7 -0
  57. package/dist/prompts.d.ts.map +1 -0
  58. package/dist/prompts.js +281 -0
  59. package/dist/prompts.js.map +1 -0
  60. package/dist/resources.d.ts +7 -0
  61. package/dist/resources.d.ts.map +1 -0
  62. package/dist/resources.js +140 -0
  63. package/dist/resources.js.map +1 -0
  64. package/dist/server.d.ts +6 -0
  65. package/dist/server.d.ts.map +1 -0
  66. package/dist/server.js +26 -0
  67. package/dist/server.js.map +1 -0
  68. package/dist/tools.d.ts +6 -0
  69. package/dist/tools.d.ts.map +1 -0
  70. package/dist/tools.js +601 -0
  71. package/dist/tools.js.map +1 -0
  72. package/package.json +46 -0
@@ -0,0 +1,502 @@
1
+ ---
2
+ name: codemunch
3
+ description:
4
+ Holistic AST-driven codebase comprehension. Uses ast-grep to surgically extract structural knowledge into lightweight artifacts, enabling deep understanding of any foreign codebase without reading raw files. Operates as a capability-research module inside the ACE Framework.
5
+ ---
6
+
7
+ # CodeMunch — AST-Driven Codebase Intelligence
8
+
9
+ **IMPORTANT**: NEVER read raw source files to understand a codebase. Every structural fact MUST
10
+ be extracted via an `ast-grep` query. Raw file reads burn 10–100× more tokens than equivalent
11
+ AST queries. The only exception is a single-file glance at an entry point to confirm language
12
+ and project purpose. The goal is to **produce artifacts, not chat**. If a CodeMunch session
13
+ ends without writing at least `CODEBASE_MAP.md`, it has failed.
14
+
15
+ ---
16
+
17
+ ## 0. ACE Role Declaration
18
+
19
+ CodeMunch is a `capability-research` module. In every session it:
20
+
21
+ - **Emits** a `SOURCE_VALIDATED` event when a structural claim is confirmed by ast-grep output.
22
+ - **Writes** findings to `./agent-state/` as append-only artifacts.
23
+ - **Blocks** downstream modules (`capability-spec`, `capability-build`) from acting on unverifiable structural assumptions.
24
+ - **Hands off** via `HANDOFF.json` once `CODEBASE_MAP.md` and `PATTERNS.md` are locked.
25
+
26
+ ACE Clarity Protocol headers (`[STATE_ANALYSIS]`, `[STRATEGY_SELECTOR]`, `[EXECUTION_LOG]`,
27
+ `[ARTIFACT_UPDATE]`, `[VERIFICATION]`) must be used at each phase boundary in your response.
28
+
29
+ ---
30
+
31
+ ## 1. Socratic Question Stack
32
+
33
+ Before running a single command, answer these questions in order. Stop at the first one you cannot answer — that is your first ast-grep target.
34
+
35
+ **Tier 0 — Orientation (answer from README or a 30-second scan)**
36
+ 1. What is the primary language and build system?
37
+ 2. What is the stated purpose of this codebase in one sentence?
38
+ 3. Where is the entry point (`main`, `__init__`, `index`, `lib.rs`, etc.)?
39
+
40
+ **Tier 1 — Skeleton (answer via ast-grep)**
41
+ 4. What are the top-level public types / classes / structs / enums?
42
+ 5. What are the primary exported functions or public API symbols?
43
+ 6. How many modules/crates/packages exist, and how are they named?
44
+ 7. What external dependencies are imported at the top level?
45
+
46
+ **Tier 2 — Relationships (answer via ast-grep)**
47
+ 8. Which modules call which other modules? (call-site mapping)
48
+ 9. Where does data enter the system and where does it leave?
49
+ 10. What trait / interface / protocol implementations exist?
50
+ 11. Where is error handling centralised? What error types exist?
51
+
52
+ **Tier 3 — Patterns (answer via ast-grep)**
53
+ 12. What repeated structural idioms appear 3+ times? (factory, builder, strategy, etc.)
54
+ 13. What test coverage patterns exist? (unit, integration, property-based?)
55
+ 14. Are there any TODO/FIXME/HACK/unsafe markers that signal risk areas?
56
+ 15. What configuration / deserialisation surface exists?
57
+
58
+ **Tier 4 — Goal Alignment (answer from the task)**
59
+ 16. What is the specific goal? (understand / debug / add feature / contribute / get inspired)
60
+ 17. Which modules are in the critical path for this goal?
61
+ 18. What is the simplest change that would advance this goal?
62
+
63
+ > **Rule**: Each unanswered question maps to exactly one ast-grep command in Phase 2.
64
+ > Write the question → answer pairs into `SOCRATIC_LOG.md` as you go.
65
+
66
+ ---
67
+
68
+ ## 2. Execution Protocol
69
+
70
+ ### Phase 0 — Bootstrap `[STATE_ANALYSIS]`
71
+
72
+ Detect the language, structure, and project skeleton without reading any source files.
73
+
74
+ **Step 1 — Language detection**
75
+ ```bash
76
+ # Count files by extension to confirm language mix
77
+ find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn | head -20
78
+
79
+ # Confirm primary language for ast-grep --lang flag
80
+ # Common values: rust, python, js, ts, tsx, go, java, cpp, c, cs, ruby
81
+ ```
82
+
83
+ **Step 2 — Entry point identification**
84
+ ```bash
85
+ # Rust
86
+ ast-grep --pattern 'fn main() { $$$ }' --lang rust --json
87
+
88
+ # Python
89
+ ast-grep --pattern 'if __name__ == "__main__": $$$' --lang python --json
90
+
91
+ # JS/TS
92
+ ast-grep --pattern 'export default $EXPR' --lang ts --json
93
+ ast-grep --pattern 'module.exports = $EXPR' --lang js --json
94
+ ```
95
+
96
+ **Step 3 — Top-level module map**
97
+ ```bash
98
+ # Count lines and files per directory (structural overview, no source reading)
99
+ find . -name "*.rs" | head -60
100
+ find . -name "*.py" | head -60
101
+ ```
102
+
103
+ **Output**: Write `CODEBASE_MAP.md` stub:
104
+ ```markdown
105
+ # CODEBASE_MAP.md
106
+ Language: <lang>
107
+ Entry Point: <path>
108
+ Build System: <cargo/pip/npm/make>
109
+ Module Count: <n>
110
+ Purpose: <one sentence from README>
111
+ ```
112
+
113
+ ---
114
+
115
+ ### Phase 1 — Skeleton Extraction `[STRATEGY_SELECTOR]`
116
+
117
+ Extract the full public API surface using targeted ast-grep patterns. Do NOT read
118
+ implementations — extract signatures only.
119
+
120
+ **Step 4 — Public types**
121
+ ```bash
122
+ # Rust: structs, enums, traits
123
+ ast-grep --pattern 'pub struct $NAME { $$$ }' --lang rust
124
+ ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust
125
+ ast-grep --pattern 'pub trait $NAME { $$$ }' --lang rust
126
+
127
+ # Python: classes
128
+ ast-grep --pattern 'class $NAME: $$$' --lang python
129
+
130
+ # TypeScript: interfaces, types, classes
131
+ ast-grep --pattern 'export interface $NAME { $$$ }' --lang ts
132
+ ast-grep --pattern 'export type $NAME = $TYPE' --lang ts
133
+ ast-grep --pattern 'export class $NAME { $$$ }' --lang ts
134
+ ```
135
+
136
+ **Step 5 — Public functions / methods**
137
+ ```bash
138
+ # Rust: public fns (with --json for machine-parseable output)
139
+ ast-grep --pattern 'pub fn $NAME($$$) -> $RET { $$$ }' --lang rust --json
140
+
141
+ # Rust: public fns (no return type)
142
+ ast-grep --pattern 'pub fn $NAME($$$) { $$$ }' --lang rust
143
+
144
+ # Python: top-level defs
145
+ ast-grep --pattern 'def $NAME($$$): $$$' --lang python
146
+
147
+ # TypeScript: exported functions
148
+ ast-grep --pattern 'export function $NAME($$$): $RET { $$$ }' --lang ts
149
+ ast-grep --pattern 'export const $NAME = ($$$) => $BODY' --lang ts
150
+ ```
151
+
152
+ **Step 6 — External dependencies**
153
+ ```bash
154
+ # Rust: use statements (top-level imports)
155
+ ast-grep --pattern 'use $PATH' --lang rust
156
+
157
+ # Python: imports
158
+ ast-grep --pattern 'import $MODULE' --lang python
159
+ ast-grep --pattern 'from $MODULE import $NAME' --lang python
160
+
161
+ # JS/TS: imports
162
+ ast-grep --pattern 'import $NAME from "$PATH"' --lang ts
163
+ ast-grep --pattern 'import { $$$ } from "$PATH"' --lang ts
164
+ ```
165
+
166
+ **Output**: Append to `CODEBASE_MAP.md`:
167
+ ```markdown
168
+ ## Public API Surface
169
+ ### Types
170
+ - `TypeName` — <kind: struct/enum/class> — <file:line>
171
+
172
+ ### Functions
173
+ - `fn_name(args) -> ret` — <file:line>
174
+
175
+ ### Key Dependencies
176
+ - <dep_name>: <apparent purpose>
177
+ ```
178
+
179
+ ---
180
+
181
+ ### Phase 2 — Relationship Mapping `[EXECUTION_LOG]`
182
+
183
+ Find how components connect. This answers Socratic questions 8–11.
184
+
185
+ **Step 7 — Trait/interface implementations**
186
+ ```bash
187
+ # Rust: impl blocks (what implements what)
188
+ ast-grep --pattern 'impl $TRAIT for $TYPE { $$$ }' --lang rust
189
+
190
+ # Rust: plain impl blocks
191
+ ast-grep --pattern 'impl $TYPE { $$$ }' --lang rust
192
+ ```
193
+
194
+ **Step 8 — Call-site mapping (who calls what)**
195
+ ```bash
196
+ # Find all calls to a specific function (replace TARGET with function name)
197
+ ast-grep --pattern '$OBJ.TARGET($$$)' --lang rust
198
+ ast-grep --pattern 'TARGET($$$)' --lang rust
199
+
200
+ # Find all method calls on a type
201
+ ast-grep --pattern '$VAR: $TYPE' --lang rust # find variable declarations of a type
202
+ ```
203
+
204
+ **Step 9 — Error handling topology**
205
+ ```bash
206
+ # Rust: Result types and ? operator usage
207
+ ast-grep --pattern 'Result<$T, $E>' --lang rust
208
+ ast-grep --pattern '$EXPR?' --lang rust
209
+
210
+ # Rust: custom error enums
211
+ ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust # filter for Error suffix
212
+
213
+ # Python: exception definitions
214
+ ast-grep --pattern 'class $NAME(Exception): $$$' --lang python
215
+ ast-grep --pattern 'except $EXC: $$$' --lang python
216
+ ```
217
+
218
+ **Step 10 — Configuration and deserialization surface**
219
+ ```bash
220
+ # Rust: serde derives (anything Deserialize is config/data entry)
221
+ ast-grep --pattern '#[derive($$$Deserialize$$$)] $STRUCT' --lang rust
222
+
223
+ # Python: dataclasses, pydantic models
224
+ ast-grep --pattern '@dataclass' --lang python
225
+ ast-grep --pattern 'class $NAME(BaseModel): $$$' --lang python
226
+
227
+ # TypeScript: zod schemas, JSON parse points
228
+ ast-grep --pattern 'z.object({ $$$ })' --lang ts
229
+ ```
230
+
231
+ **Output**: Write `DEPENDENCY_GRAPH.md`:
232
+ ```markdown
233
+ # DEPENDENCY_GRAPH.md
234
+ ## Module Relationships
235
+ - `module_a` → calls → `module_b` (via fn_name)
236
+
237
+ ## Trait Implementations
238
+ - `TypeX` implements `TraitY`
239
+
240
+ ## Error Taxonomy
241
+ - `ErrorVariant`: exits at <file:line>
242
+
243
+ ## Config / Data Entry Points
244
+ - `StructName` (Deserialize): loaded at <file>
245
+ ```
246
+
247
+ ---
248
+
249
+ ### Phase 3 — Pattern & Idiom Mining `[EXECUTION_LOG]`
250
+
251
+ Identify recurring structural decisions. These reveal the codebase's philosophy.
252
+
253
+ **Step 11 — Test patterns**
254
+ ```bash
255
+ # Rust: test functions
256
+ ast-grep --pattern '#[test] fn $NAME() { $$$ }' --lang rust
257
+ ast-grep --pattern '#[tokio::test] async fn $NAME() { $$$ }' --lang rust
258
+
259
+ # Python: pytest / unittest
260
+ ast-grep --pattern 'def test_$NAME($$$): $$$' --lang python
261
+ ast-grep --pattern 'class $NAME(TestCase): $$$' --lang python
262
+
263
+ # JS/TS: jest / vitest
264
+ ast-grep --pattern 'it("$DESC", $$$)' --lang ts
265
+ ast-grep --pattern 'describe("$DESC", $$$)' --lang ts
266
+ ```
267
+
268
+ **Step 12 — Unsafe / risk markers**
269
+ ```bash
270
+ # Rust: unsafe blocks (security/correctness hotspots)
271
+ ast-grep --pattern 'unsafe { $$$ }' --lang rust
272
+ ast-grep --pattern 'unsafe fn $NAME($$$)' --lang rust
273
+
274
+ # TODO/FIXME markers (language-agnostic comment scan)
275
+ grep -rn "TODO\|FIXME\|HACK\|SAFETY\|PANIC\|unwrap()" --include="*.rs" | head -40
276
+ grep -rn "TODO\|FIXME\|HACK\|BUG" --include="*.py" | head -40
277
+ ```
278
+
279
+ **Step 13 — Builder / factory / newtype patterns**
280
+ ```bash
281
+ # Rust: builder pattern (fn new / fn build)
282
+ ast-grep --pattern 'fn new($$$) -> Self { $$$ }' --lang rust
283
+ ast-grep --pattern 'fn build(self) -> $TYPE { $$$ }' --lang rust
284
+
285
+ # Rust: newtype wrappers
286
+ ast-grep --pattern 'pub struct $NAME($INNER);' --lang rust
287
+
288
+ # Python: class methods / factories
289
+ ast-grep --pattern '@classmethod' --lang python
290
+ ```
291
+
292
+ **Step 14 — Async / concurrency patterns**
293
+ ```bash
294
+ # Rust: async functions
295
+ ast-grep --pattern 'async fn $NAME($$$)' --lang rust
296
+ ast-grep --pattern 'tokio::spawn($$$)' --lang rust
297
+
298
+ # Python: async
299
+ ast-grep --pattern 'async def $NAME($$$): $$$' --lang python
300
+
301
+ # JS/TS
302
+ ast-grep --pattern 'await $EXPR' --lang ts
303
+ ```
304
+
305
+ **Output**: Append to `PATTERNS.md`:
306
+ ```markdown
307
+ # PATTERNS.md
308
+ ## Design Patterns Detected
309
+ - Builder: <count> usages, primary in <module>
310
+ - Newtype: <count> usages
311
+
312
+ ## Test Coverage Profile
313
+ - Unit tests: <count>
314
+ - Integration tests: <count>
315
+ - Async tests: <count>
316
+
317
+ ## Risk Markers
318
+ - unsafe blocks: <count> in <files>
319
+ - TODOs: <list of top ones>
320
+
321
+ ## Concurrency Model
322
+ - <async/sync/threaded/actor> — evidence: <fn names>
323
+ ```
324
+
325
+ ---
326
+
327
+ ### Phase 4 — Artifact Generation `[ARTIFACT_UPDATE]`
328
+
329
+ All findings are now crystallised into locked artifacts. No reasoning from memory — only
330
+ from the written artifacts below.
331
+
332
+ **Required artifacts** (write all before Phase 5):
333
+
334
+ | Artifact | Purpose |
335
+ |---|---|
336
+ | `CODEBASE_MAP.md` | Language, entry points, module list, public API surface |
337
+ | `DEPENDENCY_GRAPH.md` | Module relationships, trait impls, error taxonomy |
338
+ | `PATTERNS.md` | Design patterns, test profile, risk markers, concurrency model |
339
+ | `SOCRATIC_LOG.md` | Every question + its ast-grep-verified answer |
340
+ | `EVIDENCE_LOG.md` | Raw ast-grep output snippets used as evidence (append-only) |
341
+
342
+ **Artifact write protocol:**
343
+ ```bash
344
+ # Each ast-grep query output MUST be appended to EVIDENCE_LOG.md immediately
345
+ echo "## Query: pub fn signatures (rust)" >> ./agent-state/EVIDENCE_LOG.md
346
+ ast-grep --pattern 'pub fn $NAME($$$) -> $RET { $$$ }' --lang rust --json >> ./agent-state/EVIDENCE_LOG.md
347
+ ```
348
+
349
+ **Optional artifacts** (generate when goal demands it):
350
+
351
+ | Artifact | When to generate |
352
+ |---|---|
353
+ | `CALL_GRAPH.md` | Goal = debug / trace data flow |
354
+ | `CONTRIBUTION_GUIDE.md` | Goal = contribute / extend |
355
+ | `INSPIRATION_NOTES.md` | Goal = extract ideas for new project |
356
+ | `BUG_HYPOTHESIS.md` | Goal = debug specific issue |
357
+
358
+ ---
359
+
360
+ ### Phase 5 — Synthesis Pass `[VERIFICATION]`
361
+
362
+ **ONLY after all Phase 4 artifacts are written**, perform a final reasoning pass.
363
+ Read ONLY the artifacts — not any source files.
364
+
365
+ **Step 15 — Self-verification checklist**
366
+ - [ ] Can I describe the codebase architecture in 3 sentences from `CODEBASE_MAP.md` alone?
367
+ - [ ] Can I name the 5 most important types/functions without looking at source?
368
+ - [ ] Can I explain the data flow from entry to exit from `DEPENDENCY_GRAPH.md`?
369
+ - [ ] Have all Tier 2 Socratic questions been answered in `SOCRATIC_LOG.md`?
370
+ - [ ] Does `EVIDENCE_LOG.md` have at least one ast-grep snippet per structural claim?
371
+
372
+ **Step 16 — Goal-aligned synthesis**
373
+
374
+ *Mode: UNDERSTAND*
375
+ > Synthesise `CODEBASE_MAP.md` + `PATTERNS.md` into a plain-English architecture document.
376
+
377
+ *Mode: DEBUG*
378
+ > Trace the bug-relevant call path using `CALL_GRAPH.md`. Write `BUG_HYPOTHESIS.md`
379
+ > with: symptom → suspected module → ast-grep evidence → falsification criteria.
380
+
381
+ *Mode: CONTRIBUTE / ADD FEATURE*
382
+ > From `DEPENDENCY_GRAPH.md`, identify the minimum insertion point. Write
383
+ > `CONTRIBUTION_GUIDE.md` with: interface contract, which existing tests to extend,
384
+ > which patterns to follow (from `PATTERNS.md`).
385
+
386
+ *Mode: INSPIRE*
387
+ > Extract architectural decisions, naming conventions, idioms from `PATTERNS.md` into
388
+ > `INSPIRATION_NOTES.md` with annotations on what can be adapted.
389
+
390
+ **Step 17 — HANDOFF**
391
+
392
+ Emit `HANDOFF.json` when synthesis is complete:
393
+ ```json
394
+ {
395
+ "meta": { "timestamp": "<ISO8601>", "skill": "codemunch", "session_id": "<uuid>" },
396
+ "transition": {
397
+ "from": "capability-research",
398
+ "to": "capability-spec",
399
+ "status": "READY_FOR_HANDOFF",
400
+ "reason": "Codebase map and pattern artifacts are locked."
401
+ },
402
+ "payload": {
403
+ "primary_artifact": "./agent-state/CODEBASE_MAP.md",
404
+ "supporting_artifacts": [
405
+ "./agent-state/DEPENDENCY_GRAPH.md",
406
+ "./agent-state/PATTERNS.md",
407
+ "./agent-state/SOCRATIC_LOG.md"
408
+ ],
409
+ "evidence_pointer": "./agent-state/EVIDENCE_LOG.md",
410
+ "known_unknowns": ["<list any unanswered Tier 3/4 questions>"]
411
+ }
412
+ }
413
+ ```
414
+
415
+ ---
416
+
417
+ ## 3. ast-grep Quick Reference
418
+
419
+ ### Universal Flags
420
+ ```bash
421
+ --lang <lang> # rust | python | js | ts | tsx | go | java | cpp | c | html | css
422
+ --pattern / -p # inline pattern
423
+ --rule <file.yml> # YAML rule file for complex patterns
424
+ --json / -j # machine-readable JSON output (use for artifact writing)
425
+ --no-ignore # scan files ignored by .gitignore
426
+ --color never # disable ANSI in output (use when piping to artifact files)
427
+ ```
428
+
429
+ ### Meta-variable Syntax
430
+ ```
431
+ $NAME — single AST node (identifier, expression, etc.)
432
+ $$$ — zero or more AST nodes (variadic / body capture)
433
+ $$ARGS — named multi-match capture
434
+ $_ — anonymous wildcard (matches anything, not captured)
435
+ ```
436
+
437
+ ### YAML Rule Template (complex structural queries)
438
+ ```yaml
439
+ # Save as ./codemunch-rules/<rule-name>.yml
440
+ id: find-pattern-name
441
+ language: rust
442
+ rule:
443
+ pattern: pub fn $NAME($$$) -> Result<$T, $E> { $$$ }
444
+ # Optional filters:
445
+ inside:
446
+ pattern: impl $TRAIT for $TYPE { $$$ }
447
+ has:
448
+ pattern: $EXPR? # contains at least one ? operator
449
+ not:
450
+ pattern: todo!() # exclude unimplemented stubs
451
+ ```
452
+ Run: `ast-grep scan --rule ./codemunch-rules/<rule-name>.yml`
453
+
454
+ ### Language Cheat Sheet
455
+
456
+ **Rust**
457
+ ```bash
458
+ ast-grep -p 'pub fn $N($$$)' -l rust # public functions
459
+ ast-grep -p 'impl $T for $U { $$$ }' -l rust # trait impls
460
+ ast-grep -p '#[derive($$$)]' -l rust # all derives
461
+ ast-grep -p 'Err($E)' -l rust # error emission sites
462
+ ast-grep -p '$V.unwrap()' -l rust # panic hotspots
463
+ ```
464
+
465
+ **Python**
466
+ ```bash
467
+ ast-grep -p 'def $N($$$) -> $R: $$$' -l python # typed functions
468
+ ast-grep -p '@$DECORATOR' -l python # all decorators
469
+ ast-grep -p 'raise $E' -l python # exception sites
470
+ ast-grep -p '__all__ = [$$$]' -l python # public exports
471
+ ```
472
+
473
+ **TypeScript / JavaScript**
474
+ ```bash
475
+ ast-grep -p 'export { $$$ }' -l ts # barrel exports
476
+ ast-grep -p 'const $N = useCallback($$$)' -l tsx # React hooks
477
+ ast-grep -p 'throw new $E($$$)' -l ts # throw sites
478
+ ast-grep -p 'satisfies $TYPE' -l ts # type constraints
479
+ ```
480
+
481
+ ---
482
+
483
+ ## 4. Failure Modes & Circuit Breakers
484
+
485
+ | Failure | Signal | Recovery |
486
+ |---|---|---|
487
+ | `ast-grep` returns no matches | Pattern may be wrong for this dialect | Use `--json` + inspect one sample node kind first |
488
+ | Artifact file > 500 lines | Too much raw output captured | Summarise into bullet points; keep only exemplars in EVIDENCE_LOG |
489
+ | Socratic question unresolvable via AST | Deep runtime behaviour | Mark as `KNOWN_UNKNOWN` in SOCRATIC_LOG; do NOT guess |
490
+ | Goal changes mid-session | New task injected | Emit `GATE_FAILED`, re-enter Phase 0 with updated goal |
491
+
492
+ ---
493
+
494
+ ## 5. Activation
495
+
496
+ When you receive a codebase (path, repo, or CXML dump) with a goal, type:
497
+
498
+ **`munch <path> --goal <understand|debug|contribute|inspire> [--lang <lang>]`**
499
+
500
+ CodeMunch will automatically enter Phase 0, execute the Socratic Question Stack, run
501
+ ast-grep queries in order, and produce the Phase 4 artifacts before delivering the
502
+ Phase 5 synthesis. No raw file reading. No token waste. Only structure.