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,629 @@
1
+ ---
2
+ name: codesnipe
3
+ description:
4
+ Dual-codebase precision comparison via ast-grep. Builds a symbol registry for YOUR (HOME) codebase first, then surgically snipes a TARGET codebase to find what is relevant, inspiring, addable, or comparable — scored and ranked before a single implementation line is read. Companion to codemunch; where codemunch holistically maps one codebase, codesnipe triangulates two.
5
+ ---
6
+
7
+ # CodeSnipe — Dual-Codebase Precision Intelligence
8
+
9
+ **IMPORTANT**: CodeSnipe is NOT a code reader. It is a code comparator. Before reading
10
+ a single implementation line from the TARGET, you MUST first build a symbol registry
11
+ of the HOME codebase. Every TARGET symbol you retrieve must first earn a relevance score
12
+ against the HOME registry. Low-scoring symbols are DISCARDED — not read, not summarised,
13
+ not discussed. The sniper does not spray. The sniper fires once, and only at verified targets.
14
+
15
+ **The Two-Question Contract** (borrowed from jcodemunch-mcp's dual-server philosophy):
16
+ 1. "What does TARGET *do* relative to HOME?" — answered by OUTLINE phase only.
17
+ 2. "How does TARGET *do it*?" — answered only for symbols that scored ≥ 8 in relevance.
18
+
19
+ Reading a symbol that scored < 8 is a token waste and a protocol violation.
20
+
21
+ ---
22
+
23
+ ## 0. ACE Role Declaration
24
+
25
+ CodeSnipe operates as a `capability-research` module with a **comparative output contract**.
26
+
27
+ - **Emits** `SOURCE_VALIDATED` events per symbol snipe (with relevance score attached).
28
+ - **Emits** `GATE_FAILED` if the HOME registry is empty when TARGET sniping begins.
29
+ - **Writes** to `./agent-state/snipe/` (separate namespace from codemunch artifacts).
30
+ - **Blocks** downstream modules from acting on TARGET patterns that lack HOME context.
31
+ - **Hands off** via `HANDOFF.json` once `SNIPE_COMPARISON.md` is locked and scored.
32
+
33
+ ACE Clarity Protocol headers must be used at each phase boundary.
34
+
35
+ ---
36
+
37
+ ## 1. The Dual-Context Model
38
+
39
+ Every CodeSnipe session operates with two explicit roles:
40
+
41
+ ```
42
+ HOME = the codebase you OWN, MAINTAIN, or are WORKING ON.
43
+ Source of truth for "what we already do."
44
+
45
+ TARGET = the codebase you are STUDYING, COMPARING AGAINST, or DRAWING FROM.
46
+ Source of potential patterns, ideas, missing features, or alternative
47
+ implementations.
48
+ ```
49
+
50
+ **The Relevance Score** gates all TARGET reads:
51
+
52
+ | Score | Signal | Action |
53
+ |---|---|---|
54
+ | 20 | Exact symbol name match in HOME | Read TARGET implementation; direct comparison possible |
55
+ | 12–19 | Structural/semantic overlap with HOME | Read TARGET implementation; likely inspiration or divergence |
56
+ | 8–11 | Partial name or pattern overlap | Read signature only; decide before reading body |
57
+ | 4–7 | Weak thematic connection | Log to KNOWN_UNKNOWNS; do not read |
58
+ | 0–3 | No meaningful connection to HOME | Discard |
59
+
60
+ The scoring formula (adapted from jcodemunch-mcp's weighted search):
61
+ ```
62
+ score = 0
63
+ score += 20 if exact name match (HOME symbol name == TARGET symbol name)
64
+ score += 10 if name substring match
65
+ score += 5 per shared word in name
66
+ score += 8 if full signature pattern match (same function shape)
67
+ score += 4 if return type matches a HOME type
68
+ score += 3 if parameter types overlap with HOME types
69
+ score += 5 if TARGET docstring mentions a concept present in HOME
70
+ score += 2 per shared decorator/attribute
71
+ ```
72
+
73
+ Compute this BEFORE running any `ast-grep` pattern to read an implementation.
74
+
75
+ ---
76
+
77
+ ## 2. The Snipe Socratic Stack
78
+
79
+ Run this stack in order. **The first question you cannot answer from the HOME registry
80
+ is your first ast-grep snipe into the TARGET.**
81
+
82
+ **Tier 0 — Establish HOME Baseline**
83
+ 1. What symbols does HOME export publicly? (functions, types, classes, constants)
84
+ 2. What are HOME's primary design patterns? (builder, registry, pipeline, actor, etc.)
85
+ 3. What problems does HOME solve? (one sentence per module)
86
+ 4. Where are HOME's extension/plugin points?
87
+ 5. What does HOME conspicuously NOT do? (known gaps, TODOs, deferred features)
88
+
89
+ **Tier 1 — Profile TARGET at Outline Level**
90
+ 6. What languages and structure does TARGET use?
91
+ 7. What is TARGET's stated purpose? Does it overlap with HOME's domain?
92
+ 8. What public symbols does TARGET expose? (names only — no implementations yet)
93
+ 9. Which TARGET symbol names appear verbatim or approximately in HOME?
94
+ 10. Which TARGET module names map to HOME module names?
95
+
96
+ **Tier 2 — Score and Rank**
97
+ 11. Which TARGET symbols scored ≥ 12 against HOME? (prime snipe candidates)
98
+ 12. Which TARGET symbols represent concepts HOME has TODOs for?
99
+ 13. Which TARGET patterns appear 3+ times but are absent from HOME?
100
+ 14. Does TARGET solve any HOME Tier-5 Socratic question (known gaps)?
101
+
102
+ **Tier 3 — Precision Extraction (only for score ≥ 8 symbols)**
103
+ 15. How does TARGET implement the high-score symbol? (read body now)
104
+ 16. What does TARGET do that HOME does differently? (divergence analysis)
105
+ 17. Is TARGET's approach adoptable in HOME's architecture without breaking changes?
106
+ 18. What would adoption cost? (new dependencies, refactors, interface changes)
107
+
108
+ > **Rule**: Write every scored symbol into `SNIPE_RELEVANCE_MAP.md` immediately.
109
+ > A symbol discussed without a recorded score is a protocol violation.
110
+
111
+ ---
112
+
113
+ ## 3. Execution Protocol
114
+
115
+ ### Phase 0 — HOME Registry Build `[STATE_ANALYSIS]`
116
+
117
+ **Never skip this phase.** No TARGET sniping without a complete HOME registry.
118
+
119
+ **Step 1 — HOME public API surface**
120
+ ```bash
121
+ # Rust
122
+ ast-grep --pattern 'pub fn $NAME($$$)' --lang rust --json | \
123
+ jq '.[] | {name: .metaVariables.NAME, file: .file, line: .range.start.line}' \
124
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
125
+
126
+ ast-grep --pattern 'pub struct $NAME' --lang rust --json | \
127
+ jq '.[] | {name: .metaVariables.NAME, kind: "struct", file: .file}' \
128
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
129
+
130
+ ast-grep --pattern 'pub trait $NAME' --lang rust --json | \
131
+ jq '.[] | {name: .metaVariables.NAME, kind: "trait", file: .file}' \
132
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
133
+
134
+ # Python
135
+ ast-grep --pattern 'def $NAME($$$):' --lang python --json | \
136
+ jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
137
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
138
+
139
+ ast-grep --pattern 'class $NAME:' --lang python --json | \
140
+ jq '.[] | {name: .metaVariables.NAME, kind: "class", file: .file}' \
141
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
142
+
143
+ # TypeScript / JavaScript
144
+ ast-grep --pattern 'export function $NAME($$$)' --lang ts --json | \
145
+ jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
146
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
147
+
148
+ ast-grep --pattern 'export class $NAME' --lang ts --json | \
149
+ jq '.[] | {name: .metaVariables.NAME, kind: "class", file: .file}' \
150
+ >> ./agent-state/snipe/HOME_REGISTRY.jsonl
151
+ ```
152
+
153
+ **Step 2 — HOME gap map (known unknowns)**
154
+ ```bash
155
+ # Extract TODOs, FIXMEs, unimplemented stubs — these are prime adoption targets
156
+ grep -rn "TODO\|FIXME\|HACK\|unimplemented!\|todo!()" \
157
+ --include="*.rs" --include="*.py" --include="*.ts" \
158
+ | grep -v ".git" | head -50 \
159
+ >> ./agent-state/snipe/HOME_GAP_MAP.txt
160
+
161
+ # Rust: unimplemented/todo macros (structural, not comment)
162
+ ast-grep --pattern 'unimplemented!()' --lang rust
163
+ ast-grep --pattern 'todo!()' --lang rust
164
+ ```
165
+
166
+ **Step 3 — HOME pattern fingerprint**
167
+ ```bash
168
+ # What recurring structural patterns define HOME's style?
169
+ # Rust: error enum pattern
170
+ ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust | grep -i "err\|Error\|Fail"
171
+
172
+ # Rust: Result-returning public functions (count as percentage of all pub fns)
173
+ ast-grep --pattern 'pub fn $NAME($$$) -> Result<$$$>' --lang rust
174
+
175
+ # Python: decorator usage (marks framework patterns)
176
+ ast-grep --pattern '@$DECORATOR' --lang python --json | \
177
+ jq -r '.[] | .metaVariables.DECORATOR' | sort | uniq -c | sort -rn | head -15
178
+ ```
179
+
180
+ **Output**: Write `SNIPE_HOME_REGISTRY.md`:
181
+ ```markdown
182
+ # SNIPE_HOME_REGISTRY.md
183
+ Generated: <timestamp>
184
+ HOME Path: <path>
185
+ Language(s): <langs>
186
+
187
+ ## Public Symbol Inventory
188
+ | Symbol | Kind | File | Notes |
189
+ |--------|------|------|-------|
190
+ | <name> | fn/class/trait/type | <file> | |
191
+
192
+ ## Pattern Fingerprint
193
+ - Primary error handling: <Result/Exception/Either>
194
+ - Primary concurrency: <async/sync/threaded>
195
+ - Decorator/attribute patterns: <list>
196
+ - Extension points: <list>
197
+
198
+ ## Known Gaps (from TODOs/unimplemented)
199
+ - <file:line>: <todo text>
200
+ ```
201
+
202
+ **Gate**: HOME registry must contain ≥ 1 symbol before proceeding to Phase 1.
203
+ If HOME is empty or inaccessible, emit `GATE_FAILED` and halt.
204
+
205
+ ---
206
+
207
+ ### Phase 1 — TARGET Outline (No Reads Yet) `[STRATEGY_SELECTOR]`
208
+
209
+ Extract TARGET structure at the symbol-name level only. Zero implementations read.
210
+
211
+ **Step 4 — TARGET skeleton**
212
+ ```bash
213
+ # Run from TARGET directory. Mirror HOME's Phase 0 queries exactly.
214
+ cd <TARGET_PATH>
215
+
216
+ # Rust
217
+ ast-grep --pattern 'pub fn $NAME($$$)' --lang rust --json | \
218
+ jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
219
+ >> ./agent-state/snipe/TARGET_OUTLINE.jsonl
220
+
221
+ # Python
222
+ ast-grep --pattern 'def $NAME($$$):' --lang python --json | \
223
+ jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
224
+ >> ./agent-state/snipe/TARGET_OUTLINE.jsonl
225
+
226
+ # TypeScript
227
+ ast-grep --pattern 'export function $NAME($$$)' --lang ts --json | \
228
+ jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
229
+ >> ./agent-state/snipe/TARGET_OUTLINE.jsonl
230
+ ```
231
+
232
+ **Step 5 — TARGET structural shape (without reading bodies)**
233
+ ```bash
234
+ # Module/file structure
235
+ find . -type f \( -name "*.rs" -o -name "*.py" -o -name "*.ts" \) \
236
+ | grep -v ".git" | sort
237
+
238
+ # Public type surface
239
+ ast-grep --pattern 'pub struct $NAME { $$$ }' --lang rust # Rust types
240
+ ast-grep --pattern 'class $NAME:' --lang python # Python classes
241
+ ast-grep --pattern 'interface $NAME' --lang ts # TS interfaces
242
+ ```
243
+
244
+ **Step 6 — TARGET dependency profile**
245
+ ```bash
246
+ # What external deps does TARGET use that HOME does not?
247
+ # (Compare against HOME's Cargo.toml / pyproject.toml / package.json)
248
+ cat Cargo.toml | grep -A50 "\[dependencies\]" # Rust
249
+ cat pyproject.toml | grep -A30 "dependencies" # Python
250
+ cat package.json | python3 -c "import sys,json; d=json.load(sys.stdin); [print(k) for k in d.get('dependencies',{}).keys()]" # Node
251
+
252
+ # New deps in TARGET but not HOME = potential new capabilities
253
+ ```
254
+
255
+ **Output**: Write `SNIPE_TARGET_OUTLINE.md`:
256
+ ```markdown
257
+ # SNIPE_TARGET_OUTLINE.md
258
+ TARGET Path/URL: <path>
259
+ Language(s): <langs>
260
+ Symbol Count: <n>
261
+
262
+ ## Symbol Names (outline only)
263
+ | Symbol | Kind | File |
264
+ |--------|------|------|
265
+ | <name> | fn/class/type | <file> |
266
+
267
+ ## Dependencies Not in HOME
268
+ - <dep>: <apparent purpose>
269
+ ```
270
+
271
+ ---
272
+
273
+ ### Phase 2 — Relevance Scoring `[EXECUTION_LOG]`
274
+
275
+ This is the **core of CodeSnipe**. No TARGET implementation is read until every symbol
276
+ has a score. Score computation is done against the HOME registry in memory.
277
+
278
+ **Step 7 — Name-match pass**
279
+ ```bash
280
+ # For each TARGET symbol name, check if it exists in HOME registry
281
+ # (Run this as a shell one-liner using the JSONL registries)
282
+
283
+ # Exact matches (score += 20)
284
+ comm -12 \
285
+ <(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort) \
286
+ <(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort) \
287
+ > ./agent-state/snipe/EXACT_MATCHES.txt
288
+
289
+ # Substring matches (score += 10 each)
290
+ while IFS= read -r target_name; do
291
+ grep -i "$target_name" ./agent-state/snipe/HOME_REGISTRY.jsonl && echo "SUBSTR_MATCH: $target_name"
292
+ done < <(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl) \
293
+ >> ./agent-state/snipe/SUBSTR_MATCHES.txt
294
+ ```
295
+
296
+ **Step 8 — Structural pattern match (signature shape)**
297
+ ```bash
298
+ # For each TARGET symbol, check if HOME has similar signatures
299
+ # Use ast-grep on TARGET to find signatures matching HOME patterns
300
+
301
+ # Example: if HOME uses Result<T, E> returns extensively,
302
+ # check if TARGET also returns Result-like types
303
+ ast-grep --pattern 'fn $NAME($$$) -> Result<$T, $E>' --lang rust # (run in TARGET)
304
+ ast-grep --pattern 'def $NAME($$$) -> $RETURN:' --lang python # (run in TARGET)
305
+
306
+ # Cross-reference: which TARGET fns return types that exist in HOME?
307
+ ast-grep --pattern 'fn $NAME($$$) -> $RET' --lang rust --json | \
308
+ jq -r '.[] | .metaVariables.RET' \
309
+ | grep -Ff <(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl)
310
+ ```
311
+
312
+ **Step 9 — Gap alignment pass**
313
+ ```bash
314
+ # Does TARGET have implementations for HOME's known gaps?
315
+ # For each TODO in HOME_GAP_MAP.txt, search TARGET for related symbols
316
+
317
+ while IFS= read -r gap; do
318
+ keyword=$(echo "$gap" | grep -oP '(?<=TODO|FIXME)[^$]+' | tr -cs 'a-zA-Z' ' ' | head -c50)
319
+ echo "=== Gap: $keyword ===" >> ./agent-state/snipe/GAP_COVERAGE.txt
320
+ grep -i "$keyword" ./agent-state/snipe/TARGET_OUTLINE.jsonl \
321
+ >> ./agent-state/snipe/GAP_COVERAGE.txt
322
+ done < ./agent-state/snipe/HOME_GAP_MAP.txt
323
+ ```
324
+
325
+ **Output**: Write `SNIPE_RELEVANCE_MAP.md`:
326
+ ```markdown
327
+ # SNIPE_RELEVANCE_MAP.md
328
+
329
+ ## Tier A — Prime Snipe Targets (score ≥ 12)
330
+ | TARGET Symbol | Score | Reason | HOME Counterpart | File |
331
+ |---|---|---|---|---|
332
+ | `parse_file` | 20 | Exact name match | `parse_file` | extractor.py |
333
+ | `LanguageSpec` | 15 | Name+type overlap | `LangConfig` | languages.py |
334
+
335
+ ## Tier B — Worth Reading Signature (score 8–11)
336
+ | TARGET Symbol | Score | Reason | File |
337
+ |---|---|---|---|
338
+
339
+ ## Tier C — Gap Coverage (HOME TODO resolved by TARGET)
340
+ | HOME Gap | TARGET Symbol | File |
341
+ |---|---|---|
342
+
343
+ ## Discarded (score < 8)
344
+ Count: <n> symbols discarded. Not read. Not discussed.
345
+ ```
346
+
347
+ ---
348
+
349
+ ### Phase 3 — Precision Extraction `[EXECUTION_LOG]`
350
+
351
+ **Only Tier A and Tier B symbols reach this phase.**
352
+
353
+ **Step 10 — Snipe Tier A implementations**
354
+ ```bash
355
+ # For each Tier A symbol, extract full implementation via ast-grep
356
+ # Replace SYMBOL_NAME with actual name from SNIPE_RELEVANCE_MAP.md
357
+
358
+ # Rust function body
359
+ ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust
360
+
361
+ # Rust with impl context (method)
362
+ ast-grep --pattern 'impl $TYPE { $$$ fn SYMBOL_NAME($$$) { $$$ } $$$ }' --lang rust
363
+
364
+ # Python function body
365
+ ast-grep --pattern 'def SYMBOL_NAME($$$): $$$' --lang python
366
+
367
+ # TypeScript
368
+ ast-grep --pattern 'function SYMBOL_NAME($$$): $RET { $$$ }' --lang ts
369
+ ast-grep --pattern 'SYMBOL_NAME($$$): $RET { $$$ }' --lang ts # method
370
+ ```
371
+
372
+ **Step 11 — Divergence extraction (how HOME and TARGET differ)**
373
+ ```bash
374
+ # For exact-match symbols (score == 20), extract both HOME and TARGET implementations
375
+ # to compare approaches
376
+
377
+ # HOME implementation
378
+ cd <HOME_PATH>
379
+ ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust > /tmp/home_impl.txt
380
+
381
+ # TARGET implementation
382
+ cd <TARGET_PATH>
383
+ ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust > /tmp/target_impl.txt
384
+
385
+ # Structural diff: how many lines? How many patterns differ?
386
+ wc -l /tmp/home_impl.txt /tmp/target_impl.txt
387
+ diff /tmp/home_impl.txt /tmp/target_impl.txt | head -40
388
+ ```
389
+
390
+ **Step 12 — Pattern sniping (recurring TARGET idioms absent from HOME)**
391
+ ```bash
392
+ # Idioms seen 3+ times in TARGET but absent from HOME
393
+
394
+ # Example: if TARGET uses a registry pattern
395
+ ast-grep --pattern '$REGISTRY.insert($KEY, $VAL)' --lang rust # (run in TARGET)
396
+ ast-grep --pattern '$REGISTRY[$KEY] = $VAL' --lang python # (run in TARGET)
397
+
398
+ # Check if HOME has equivalent
399
+ ast-grep --pattern '$REGISTRY.insert($KEY, $VAL)' --lang rust # (run in HOME)
400
+ # If 0 results → this is a pattern gap
401
+
402
+ # Extract TARGET's registry pattern instances
403
+ ast-grep --pattern 'PATTERN' --lang rust --json | \
404
+ jq '.[] | {file: .file, line: .range.start.line, text: .text}' \
405
+ >> ./agent-state/snipe/SNIPE_EXTRACTS.jsonl
406
+ ```
407
+
408
+ ---
409
+
410
+ ### Phase 4 — Artifact Generation `[ARTIFACT_UPDATE]`
411
+
412
+ All snipe findings are crystallised into locked artifacts.
413
+
414
+ **Required artifacts:**
415
+
416
+ | Artifact | Contents |
417
+ |---|---|
418
+ | `SNIPE_HOME_REGISTRY.md` | HOME symbol inventory, pattern fingerprint, gap map |
419
+ | `SNIPE_TARGET_OUTLINE.md` | TARGET symbol names, module structure (no implementations) |
420
+ | `SNIPE_RELEVANCE_MAP.md` | Scored symbol table, Tier A/B/C/Discarded |
421
+ | `SNIPE_EXTRACTS.jsonl` | Raw ast-grep output for Tier A/B symbols |
422
+ | `SNIPE_COMPARISON.md` | Final comparison: divergence, adoption cost, inspiration |
423
+ | `EVIDENCE_LOG.md` | All ast-grep command outputs (append-only, shared with codemunch) |
424
+
425
+ **Artifact write protocol:**
426
+ ```bash
427
+ # Every snipe command appends to EVIDENCE_LOG
428
+ echo "## Snipe: fn parse_file (TARGET extractor.py)" >> ./agent-state/snipe/EVIDENCE_LOG.md
429
+ ast-grep --pattern 'def parse_file($$$):' --lang python --json \
430
+ >> ./agent-state/snipe/EVIDENCE_LOG.md
431
+ ```
432
+
433
+ **Optional artifacts by intent:**
434
+
435
+ | Intent | Extra Artifact |
436
+ |---|---|
437
+ | `steal` | `ADOPTION_PLAN.md` — step-by-step integration into HOME |
438
+ | `compare` | `DIVERGENCE_ANALYSIS.md` — side-by-side of same-named symbols |
439
+ | `debug` | `BUG_TRIANGULATION.md` — TARGET's solution to HOME's bug |
440
+ | `integrate` | `INTERFACE_BRIDGE.md` — data schema + API contract between HOME and TARGET |
441
+
442
+ ---
443
+
444
+ ### Phase 5 — Synthesis `[VERIFICATION]`
445
+
446
+ Read ONLY the artifacts. Final reasoning pass over structured data, not raw code.
447
+
448
+ **Step 13 — Snipe self-verification checklist**
449
+ - [ ] `SNIPE_HOME_REGISTRY.md` contains ≥ 5 symbols (HOME is meaningfully mapped)
450
+ - [ ] `SNIPE_RELEVANCE_MAP.md` has at least 1 Tier A symbol
451
+ - [ ] Every Tier A symbol in `SNIPE_EXTRACTS.jsonl` has an evidence entry
452
+ - [ ] Tier C gap coverage attempted for all HOME TODO items
453
+ - [ ] Discarded symbol count is documented (proof that low-signal symbols were filtered)
454
+ - [ ] `SNIPE_COMPARISON.md` exists and contains a recommendation
455
+
456
+ **Step 14 — SNIPE_COMPARISON.md structure**
457
+
458
+ ```markdown
459
+ # SNIPE_COMPARISON.md
460
+
461
+ ## Executive Summary
462
+ HOME: <one sentence>
463
+ TARGET: <one sentence>
464
+ Overlap: <n> exact matches, <n> structural matches
465
+ Key Finding: <one sentence — what's the most important thing TARGET has?>
466
+
467
+ ## Tier A Analysis (Direct Comparisons)
468
+ ### `symbol_name`
469
+ - **HOME approach**: <2-3 sentences from HOME impl>
470
+ - **TARGET approach**: <2-3 sentences from TARGET impl>
471
+ - **Divergence**: <where/why they differ>
472
+ - **Recommendation**: adopt / adapt / ignore
473
+
474
+ ## Tier C Gap Coverage (TARGET solves HOME TODOs)
475
+ | HOME Gap | TARGET Solution | Adoption Complexity |
476
+ |---|---|---|
477
+
478
+ ## Pattern Gaps (TARGET idioms absent from HOME)
479
+ | Pattern | Frequency in TARGET | Adoption Note |
480
+ |---|---|---|
481
+
482
+ ## Inspiration Extracts
483
+ <curated list of TARGET patterns worth considering, with ast-grep evidence refs>
484
+ ```
485
+
486
+ **Step 15 — HANDOFF**
487
+ ```json
488
+ {
489
+ "meta": { "timestamp": "<ISO8601>", "skill": "codesnipe", "session_id": "<uuid>" },
490
+ "transition": {
491
+ "from": "capability-research",
492
+ "to": "capability-spec",
493
+ "status": "READY_FOR_HANDOFF",
494
+ "reason": "Dual-codebase comparison complete. Adoption candidates identified."
495
+ },
496
+ "payload": {
497
+ "primary_artifact": "./agent-state/snipe/SNIPE_COMPARISON.md",
498
+ "home_registry": "./agent-state/snipe/SNIPE_HOME_REGISTRY.md",
499
+ "target_outline": "./agent-state/snipe/SNIPE_TARGET_OUTLINE.md",
500
+ "relevance_map": "./agent-state/snipe/SNIPE_RELEVANCE_MAP.md",
501
+ "evidence_pointer": "./agent-state/snipe/EVIDENCE_LOG.md",
502
+ "tier_a_count": "<n>",
503
+ "adoption_candidates": ["<symbol1>", "<symbol2>"]
504
+ }
505
+ }
506
+ ```
507
+
508
+ ---
509
+
510
+ ## 4. Intent-Specific Modes
511
+
512
+ ### `--intent steal`
513
+ Focus: Extract and integrate a specific TARGET pattern into HOME.
514
+ - Phase 0–1 run as normal.
515
+ - Phase 2: Restrict scoring to symbols related to the stated feature.
516
+ - Phase 3: Extract full implementation + dependencies.
517
+ - Phase 4+: Generate `ADOPTION_PLAN.md` with interface changes needed in HOME.
518
+
519
+ ### `--intent compare`
520
+ Focus: Understand how TARGET solves a problem HOME also solves.
521
+ - Run Phase 0–3 fully.
522
+ - Phase 4: Generate `DIVERGENCE_ANALYSIS.md` for every Tier A symbol.
523
+ - Emphasis: WHY do they differ, not just HOW.
524
+
525
+ ### `--intent debug`
526
+ Focus: HOME has a bug; TARGET may have fixed it.
527
+ - Phase 0: Map HOME bug site via ast-grep (find the failing pattern).
528
+ - Phase 1: Search TARGET for same pattern, look for fixes.
529
+ - Phase 2: Score TARGET fixes by structural similarity to HOME's bug site.
530
+ - Phase 4: Generate `BUG_TRIANGULATION.md`.
531
+
532
+ ```bash
533
+ # Snipe a specific bug pattern in TARGET
534
+ # Example: HOME has panics on unwrap(), does TARGET handle this better?
535
+ ast-grep --pattern '$EXPR.unwrap()' --lang rust # (HOME: find all panic sites)
536
+ ast-grep --pattern '$EXPR.unwrap()' --lang rust # (TARGET: compare frequency)
537
+ ast-grep --pattern '$EXPR.unwrap_or($DEFAULT)' --lang rust # (TARGET: safer pattern?)
538
+ ast-grep --pattern 'match $EXPR { Ok($V) => $OK, Err($E) => $ERR }' --lang rust
539
+ ```
540
+
541
+ ### `--intent integrate`
542
+ Focus: HOME needs to consume or extend TARGET as a library/module.
543
+ - Phase 0: Map HOME's consumption points (where would TARGET connect?).
544
+ - Phase 1: Map TARGET's public API surface (exports, entry points only).
545
+ - Phase 2: Score TARGET exports against HOME consumption points.
546
+ - Phase 4: Generate `INTERFACE_BRIDGE.md` with schema + integration plan.
547
+
548
+ ---
549
+
550
+ ## 5. ast-grep Snipe Commands Reference
551
+
552
+ ### Surgical Symbol Extraction (Tier A reads)
553
+ ```bash
554
+ # Named function (any language variant)
555
+ ast-grep --pattern 'fn TARGET_FN($$$) { $$$ }' --lang rust
556
+ ast-grep --pattern 'def TARGET_FN($$$): $$$' --lang python
557
+ ast-grep --pattern 'function TARGET_FN($$$) { $$$ }' --lang ts
558
+ ast-grep --pattern 'TARGET_FN($$$): $RET { $$$ }' --lang ts # method
559
+
560
+ # Named type/class
561
+ ast-grep --pattern 'struct TARGET_TYPE { $$$ }' --lang rust
562
+ ast-grep --pattern 'class TARGET_CLASS: $$$' --lang python
563
+ ast-grep --pattern 'interface TARGET_IFACE { $$$ }' --lang ts
564
+ ```
565
+
566
+ ### Cross-Codebase Pattern Search
567
+ ```bash
568
+ # Run identical patterns in both HOME and TARGET; compare match counts
569
+ # HOME:
570
+ cd <HOME_PATH> && ast-grep --pattern '$EXPR?' --lang rust --json | jq length
571
+ # TARGET:
572
+ cd <TARGET_PATH> && ast-grep --pattern '$EXPR?' --lang rust --json | jq length
573
+ # If TARGET has 5× more ? usage → different error philosophy
574
+ ```
575
+
576
+ ### Relevance Scoring Helpers
577
+ ```bash
578
+ # Count shared symbol names between HOME and TARGET registries
579
+ comm -12 \
580
+ <(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort -u) \
581
+ <(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort -u) \
582
+ | wc -l
583
+
584
+ # List all shared names
585
+ comm -12 \
586
+ <(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort -u) \
587
+ <(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort -u)
588
+ ```
589
+
590
+ ---
591
+
592
+ ## 6. Failure Modes & Circuit Breakers
593
+
594
+ | Failure | Signal | Recovery |
595
+ |---|---|---|
596
+ | HOME registry empty | Gate blocks Phase 1 | Re-run Phase 0 with correct HOME path |
597
+ | All TARGET symbols score < 8 | Zero Tier A/B symbols | Log to DECISIONS.md: "TARGET unrelated to HOME"; abort |
598
+ | TARGET language ≠ HOME language | Phase 2 scoring can't use signatures | Score by name and pattern concept only; flag in SNIPE_COMPARISON.md |
599
+ | Target is too large (>500 files) | Outline phase takes too long | Restrict to top-level modules only; flag as `PARTIAL_SNIPE` |
600
+ | Intent changes mid-session | New focus discovered | Re-enter Phase 2 with updated scoring weights; do NOT re-run Phase 0 |
601
+
602
+ ---
603
+
604
+ ## 7. Activation
605
+
606
+ ```
607
+ snipe --home <path> --target <path|repo> --intent <steal|compare|debug|integrate> [--lang <lang>]
608
+ ```
609
+
610
+ **Example invocations:**
611
+ ```bash
612
+ # Study how fastapi handles dependency injection vs our framework
613
+ snipe --home ./myapi --target fastapi/fastapi --intent compare
614
+
615
+ # Steal incremental indexing pattern from jcodemunch into our build tool
616
+ snipe --home ./build-tool --target ./jcodemunch-mcp --intent steal
617
+
618
+ # Find how TARGET fixed the panic we have in our parser
619
+ snipe --home ./myparser --target nom-rs/nom --intent debug
620
+
621
+ # Understand how to consume TARGET as a library in HOME
622
+ snipe --home ./myapp --target ./some-sdk --intent integrate
623
+ ```
624
+
625
+ CodeSnipe will automatically build the HOME registry, profile TARGET at outline level,
626
+ score all symbols, extract only what earned it, and produce `SNIPE_COMPARISON.md`
627
+ with concrete adoption recommendations.
628
+
629
+ **No raw file reads. No unscored symbol access. Precision only.**
@@ -0,0 +1,7 @@
1
+ # DECISIONS
2
+
3
+ Append-only tradeoff ledger.
4
+
5
+ ## Entries
6
+
7
+ - 2026-03-03T00:00:00Z — Initialized ACE artifact scaffolding.
@@ -0,0 +1,7 @@
1
+ # EVIDENCE LOG
2
+
3
+ Append-only validation evidence.
4
+
5
+ ## Entries
6
+
7
+ - 2026-03-03T00:00:00Z — bootstrap initialized.
@@ -0,0 +1,24 @@
1
+ {
2
+ "meta": {
3
+ "timestamp": "2026-03-03T00:00:00Z",
4
+ "iteration": 1,
5
+ "session_id": "00000000-0000-0000-0000-000000000000"
6
+ },
7
+ "transition": {
8
+ "from": "capability-skeptic",
9
+ "to": "capability-research",
10
+ "status": "READY",
11
+ "reason": "Bootstrap complete"
12
+ },
13
+ "payload": {
14
+ "primary_artifact": "TASK.md",
15
+ "spec_version": "0.1.0",
16
+ "evidence_pointer": "EVIDENCE_LOG.md#entries",
17
+ "known_issues": [],
18
+ "interface_contract": "SPEC_CONTRACT.json#v0.1.0"
19
+ },
20
+ "integrity": {
21
+ "checksum": "sha256:pending",
22
+ "file_count": 0
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "gate-completeness",
3
+ "type": "artifact_scan",
4
+ "invariant": "All required artifacts exist and are non-empty",
5
+ "command": "",
6
+ "evidence_requirement": "File presence and section completeness evidence"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "gate-correctness",
3
+ "type": "executable",
4
+ "invariant": "All required tests pass",
5
+ "command": "npm test --silent",
6
+ "evidence_requirement": "Command output snippet with exit code 0"
7
+ }