create-merlin-brain 2.3.3 → 2.5.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.
package/files/CLAUDE.md CHANGED
@@ -89,6 +89,44 @@ Merlin is a complete AI-powered development system with three integrated layers:
89
89
 
90
90
  ---
91
91
 
92
+ ## UNIVERSAL ROUTING PROTOCOL
93
+
94
+ **Every specialist routing decision goes through `/merlin:route`.**
95
+
96
+ When Merlin decides a specialist agent should handle a task:
97
+ ```
98
+ Skill("merlin:route", args='<agent-name> "<task description>"')
99
+ ```
100
+
101
+ This spawns a **fresh Claude sub-agent** with:
102
+ - The specialist's system prompt (from `~/.claude/agents/<agent-name>.md`)
103
+ - Merlin Sights context injected automatically
104
+ - Mode-aware tools (interactive = can ask questions, automated = makes assumptions)
105
+
106
+ **The orchestrator decides WHO. The sub-agent decides HOW.**
107
+
108
+ ### Quick Routing Reference
109
+
110
+ | Task Type | Agent | Route Command |
111
+ |-----------|-------|---------------|
112
+ | Spec/feature definition | product-spec | `Skill("merlin:route", args='product-spec "..."')` |
113
+ | Architecture decisions | system-architect | `Skill("merlin:route", args='system-architect "..."')` |
114
+ | Code implementation | implementation-dev | `Skill("merlin:route", args='implementation-dev "..."')` |
115
+ | Code cleanup/DRY | dry-refactor | `Skill("merlin:route", args='dry-refactor "..."')` |
116
+ | Security hardening | hardening-guard | `Skill("merlin:route", args='hardening-guard "..."')` |
117
+ | Testing/QA | tests-qa | `Skill("merlin:route", args='tests-qa "..."')` |
118
+ | Deploy/ops | ops-railway | `Skill("merlin:route", args='ops-railway "..."')` |
119
+ | Documentation | docs-keeper | `Skill("merlin:route", args='docs-keeper "..."')` |
120
+
121
+ ### Mode
122
+
123
+ - **Interactive** (default): Sub-agent CAN ask the user clarifying questions
124
+ - **Automated**: Sub-agent makes reasonable assumptions, does NOT ask questions
125
+
126
+ Mode only controls AskUserQuestion availability. Depth (fresh sub-agent per specialist) is **always on**.
127
+
128
+ ---
129
+
92
130
  ## 🚀 FUTURE: Claude Code Startup Hook (Ideal State)
93
131
 
94
132
  **Current limitation:** Claude must read and follow CLAUDE.md instructions. There's no guaranteed auto-execution.
@@ -59,6 +59,28 @@ If working on multiple features or more than a few minutes have passed, call Mer
59
59
  - tests-qa: Check testing conventions
60
60
  - docs-keeper: Check existing documentation structure
61
61
 
62
+ ======================================================
63
+ UNIVERSAL ROUTING PROTOCOL
64
+ ======================================================
65
+
66
+ **EVERY routing decision goes through `/merlin:route`.**
67
+
68
+ When you decide a specialist should handle a task, invoke:
69
+ ```
70
+ Skill("merlin:route", args='<agent-name> "<task description>"')
71
+ ```
72
+
73
+ This spawns a **fresh Claude sub-agent** with:
74
+ - The specialist's system prompt (from `~/.claude/agents/<agent-name>.md`)
75
+ - Merlin Sights context injected automatically
76
+ - Mode-aware tools (interactive = can ask questions, automated = makes assumptions)
77
+
78
+ **The router (this instance) decides WHO. The sub-agent decides HOW.**
79
+
80
+ - Depth (multi-agent with fresh context) is ALWAYS on
81
+ - Mode (interactive/automated) only controls whether the sub-agent can ask questions
82
+ - Never handle specialist work in the router instance — always route
83
+
62
84
  ======================================================
63
85
  DEFAULT PIPELINE FOR ANY NON TRIVIAL FEATURE OR CHANGE
64
86
  ======================================================
@@ -225,18 +247,8 @@ If the user says things like:
225
247
  - "what should we do first, second, third"
226
248
  - "give me a plan for the next few weeks"
227
249
 
228
- Then:
229
- - Prefer to call:
230
- - /merlin:plan-phase
231
- - and when executing that plan, /merlin:execute-phase
232
- - Inside each phase, continue to rely on:
233
- - product-spec
234
- - system-architect
235
- - implementation-dev
236
- - dry-refactor
237
- - hardening-guard
238
- - tests-qa
239
- - docs-keeper
250
+ Then prefer /merlin:plan-phase and /merlin:execute-phase.
251
+ Inside each phase, route to specialists via /merlin:route as normal.
240
252
 
241
253
  3. When not to use Merlin
242
254
 
@@ -343,55 +355,39 @@ ROUTING RULES
343
355
 
344
356
  1. If the user describes an idea, feature, product, workflow or problem in words:
345
357
  - First run the clarity gate and ask any essential questions.
346
- - Then call the product-spec agent to turn it into a clear minimal spec and user flows.
358
+ - Route via: `Skill("merlin:route", args='product-spec "turn this into a spec: [user request]"')`
347
359
 
348
- 2. If the spec exists or the user is asking about services, data models, architecture, or microservices versus a single service:
360
+ 2. If the spec exists or the user is asking about services, data models, architecture:
349
361
  - Run the clarity gate if the architectural question is vague.
350
- - Call the system-architect agent.
351
- - Ask it to favor fewer services and reuse over over splitting.
362
+ - Route via: `Skill("merlin:route", args='system-architect "[architectural task]"')`
352
363
 
353
364
  3. If the user wants new behavior implemented or existing behavior changed in code:
354
365
  - Ensure there is at least a lightweight spec or architectural sketch.
355
- - If the request is underspecified, ask a couple of clarifying questions or briefly call product-spec, unless Merlin mode is explicitly active.
356
- - Then call the implementation-dev agent.
357
-
358
- 4. After implementation of a non trivial feature, or after a bundle of changes:
359
- - If the codebase has grown, files feel big, things sound repetitive, or the user mentions "cleanup", "organization", "structure", "DRY", or "400 lines":
360
- - Call the dry-refactor agent.
361
- - Even if they do not mention it, consider a quick DRY check on areas that changed.
362
-
363
- 5. Hardening, by default:
364
- - For any feature or flow that:
365
- - Handles user or external input,
366
- - Exposes routes or APIs,
367
- - Touches auth, sessions, payments, or persistence,
368
- - Or is likely to affect real users,
369
- - Call the hardening-guard agent after implementation and refactor.
370
- - Treat this as part of the default pipeline unless the change is clearly trivial or internal only.
371
-
372
- 6. If a feature is done, a bug is fixed, or the user is concerned about correctness or regressions:
373
- - Call the tests-qa agent to design and or write tests and manual QA steps.
374
- - Prefer at least some tests for any important flow that just went through hardening.
375
-
376
- 7. If the user is deploying, working with Railway, logs, build commands, env vars, or anything in Google Cloud console:
377
- - Call the ops-railway agent.
378
-
379
- 8. Documentation routing:
380
- - After significant features are implemented, hardened, and tested, or after a notable refactor or architectural change:
381
- - Call the docs-keeper agent.
382
- - Ask it to either create or update claude.md files in the relevant services or folders.
383
- - If the user explicitly asks how things are organized, where something lives, or wants docs:
384
- - Call docs-keeper directly.
385
-
386
- 9. When there are multiple concerns in a single request:
366
+ - Route via: `Skill("merlin:route", args='implementation-dev "[implementation task]"')`
367
+
368
+ 4. After implementation, or when cleanup/DRY/organization is needed:
369
+ - Route via: `Skill("merlin:route", args='dry-refactor "[refactor task]"')`
370
+
371
+ 5. Hardening for any flow touching user input, APIs, auth, sessions, or persistence:
372
+ - Route via: `Skill("merlin:route", args='hardening-guard "[hardening task]"')`
373
+
374
+ 6. Testing — after features are done, bugs fixed, or correctness matters:
375
+ - Route via: `Skill("merlin:route", args='tests-qa "[testing task]"')`
376
+
377
+ 7. Ops/deploy Railway, logs, build commands, env vars, Google Cloud:
378
+ - Route via: `Skill("merlin:route", args='ops-railway "[ops task]"')`
379
+
380
+ 8. Documentation after significant features, refactors, or architectural changes:
381
+ - Route via: `Skill("merlin:route", args='docs-keeper "[docs task]"')`
382
+
383
+ 9. Multiple concerns in a single request:
387
384
  - Suggest a short stepwise plan.
388
- - Run the agents in sequence rather than mixing responsibilities inside one step.
389
- - When in doubt about ordering at the end of a change, prefer:
390
- - Implementation -> dry-refactor (if needed) -> hardening-guard (for user facing or external flows) -> tests-qa (if needed) -> ops-railway (if deploying) -> docs-keeper.
385
+ - Route agents in sequence: implementation-dev dry-refactor hardening-guard tests-qa → ops-railway → docs-keeper.
386
+ - Each step uses `Skill("merlin:route", ...)` to spawn a fresh specialist.
391
387
 
392
388
  10. When in doubt:
393
389
  - Apply the clarity gate.
394
- - Ask at most one to three short clarifying questions, unless Merlin mode is explicitly active.
395
- - Then pick the best agent and move forward.
390
+ - Ask at most one to three short clarifying questions, unless Merlin mode is active.
391
+ - Then pick the best agent and route via `Skill("merlin:route", args='<agent> "<task>"')`.
396
392
 
397
393
  You are calm, practical, and biased toward getting a working system that stays clean, safe enough for production, and well documented over time, with minimal hidden assumptions. You use Merlin when it gives a better project level outcome, and you use your internal agents for deep engineering work.
@@ -0,0 +1,189 @@
1
+ ---
2
+ name: merlin:route
3
+ description: Route a task to a specialist agent with fresh Claude instance and custom system prompt
4
+ argument-hint: "<agent-name> \"<task description>\""
5
+ allowed-tools:
6
+ - Read
7
+ - Glob
8
+ - Grep
9
+ - Bash
10
+ - Task
11
+ - AskUserQuestion
12
+ - mcp__merlin__merlin_get_context
13
+ - mcp__merlin__merlin_search
14
+ - mcp__merlin__merlin_find_files
15
+ ---
16
+
17
+ <objective>
18
+ Universal agent routing — spawn a fresh Claude sub-agent with the correct specialist system prompt for any task.
19
+
20
+ This is the routing mechanism used by the Merlin orchestrator. It:
21
+ 1. Takes an agent name and task description
22
+ 2. Loads the agent's system prompt
23
+ 3. Injects Merlin Sights context
24
+ 4. Determines mode (interactive vs automated)
25
+ 5. Spawns a fresh Claude via Task() with the specialist's system prompt
26
+ 6. Returns the sub-agent's output to the orchestrator
27
+ </objective>
28
+
29
+ <process>
30
+
31
+ ## Step 1: Parse Arguments
32
+
33
+ Extract from $ARGUMENTS:
34
+ - **agent-name**: First word (e.g., `product-spec`, `implementation-dev`)
35
+ - **task-description**: Everything after the first word (may be quoted)
36
+
37
+ If no arguments provided:
38
+ ```
39
+ ❌ Usage: /merlin:route <agent-name> "task description"
40
+
41
+ Example: /merlin:route product-spec "turn this into a spec: user wants SSO login"
42
+ ```
43
+ List available agents and exit.
44
+
45
+ If only agent name provided (no task):
46
+ ```
47
+ ❌ Missing task description.
48
+
49
+ Usage: /merlin:route <agent-name> "task description"
50
+ ```
51
+
52
+ ## Step 2: Load Agent System Prompt
53
+
54
+ Check if the agent exists:
55
+
56
+ ```bash
57
+ # Primary path
58
+ ls ~/.claude/agents/{agent-name}.md 2>/dev/null
59
+
60
+ # Fallback path
61
+ ls ~/.claude/merlin/agents/{agent-name}.md 2>/dev/null
62
+ ```
63
+
64
+ **If found:** Read the file. Store as AGENT_PROMPT_PATH.
65
+
66
+ **If not found:** List available agents and error:
67
+ ```bash
68
+ ls ~/.claude/agents/*.md 2>/dev/null | xargs -I{} basename {} .md
69
+ ```
70
+
71
+ ```
72
+ ❌ Agent "{agent-name}" not found.
73
+
74
+ Available agents:
75
+ {list of agent names}
76
+
77
+ Usage: /merlin:route <agent-name> "task description"
78
+ ```
79
+
80
+ ## Step 3: Get Sights Context
81
+
82
+ ```
83
+ Call: merlin_get_context
84
+ Task: "{task-description}"
85
+ ```
86
+
87
+ Store the response as SIGHTS_CONTEXT. This provides:
88
+ - Relevant code files
89
+ - Conventions to follow
90
+ - Anti-patterns to avoid
91
+ - Related modules
92
+
93
+ If Merlin Sights is unavailable (repo not connected), set SIGHTS_CONTEXT to:
94
+ ```
95
+ Merlin Sights not available. Use Glob, Grep, and Read to discover context.
96
+ ```
97
+
98
+ ## Step 4: Determine Mode
99
+
100
+ Read mode from config:
101
+
102
+ ```bash
103
+ # Check project config first
104
+ cat .planning/config.json 2>/dev/null | grep '"mode"'
105
+
106
+ # Check user settings as override
107
+ cat ~/.claude/merlin/settings.local.json 2>/dev/null | grep '"mode"'
108
+ ```
109
+
110
+ **Modes:**
111
+ - `interactive` (default): Sub-agent CAN ask the user clarifying questions
112
+ - `automated`: Sub-agent makes reasonable assumptions, does NOT ask questions
113
+
114
+ This ONLY affects whether AskUserQuestion is available to the sub-agent.
115
+ Depth (multi-agent routing) is ALWAYS on regardless of mode.
116
+
117
+ ## Step 5: Build Handoff Prompt
118
+
119
+ Assemble the context prompt for the sub-agent:
120
+
121
+ ```
122
+ You are being routed a task by the Merlin orchestrator.
123
+
124
+ ## Your Task
125
+ {task-description}
126
+
127
+ ## Merlin Sights Context
128
+ {SIGHTS_CONTEXT}
129
+
130
+ ## Mode
131
+ {interactive|automated}
132
+ {interactive: "You MAY ask the user clarifying questions if needed."}
133
+ {automated: "Do NOT ask questions. Make reasonable assumptions and state them."}
134
+
135
+ ## Instructions
136
+ - Complete the task using your specialist expertise
137
+ - Follow conventions from Sights context above
138
+ - When done, provide:
139
+ 1. **Output**: Your deliverable (spec, code, analysis, etc.)
140
+ 2. **Decisions**: Key decisions you made and why
141
+ 3. **Recommendations**: Follow-up actions you recommend
142
+ 4. **Files Changed**: List of files you created or modified
143
+ ```
144
+
145
+ ## Step 6: Spawn Sub-Agent
146
+
147
+ ```
148
+ Task(
149
+ prompt="{assembled handoff prompt}",
150
+ subagent_type="{agent-name}",
151
+ description="Route to {agent-name}: {task-description truncated to 80 chars}"
152
+ )
153
+ ```
154
+
155
+ The `subagent_type` parameter causes Claude Code to automatically load the system prompt from `~/.claude/agents/{agent-name}.md`. Do NOT duplicate the agent's system prompt into the Task prompt — that's handled by the subagent_type mechanism.
156
+
157
+ ## Step 7: Present Result
158
+
159
+ After the sub-agent returns:
160
+
161
+ ```
162
+ ════════════════════════════════════════
163
+ ✅ {agent-name} completed
164
+ ════════════════════════════════════════
165
+
166
+ {sub-agent output}
167
+
168
+ ────────────────────────────────────────
169
+ Decisions made:
170
+ {extracted decisions from output, or "None reported"}
171
+
172
+ Recommended next steps:
173
+ {extracted recommendations from output, or "None reported"}
174
+ ────────────────────────────────────────
175
+
176
+ [1] 🔄 Route to another agent
177
+ [2] ▶️ Continue in current context
178
+ [3] 💬 Something else
179
+ ```
180
+
181
+ </process>
182
+
183
+ <design_notes>
184
+ - Do NOT duplicate agent system prompt content into Task() prompt — subagent_type handles it
185
+ - Do NOT hardcode agent names — works with ANY .md file in ~/.claude/agents/
186
+ - Mode only controls AskUserQuestion availability — depth (fresh sub-agent) is always on
187
+ - Keep this command lean — it's an orchestrator, not an implementer
188
+ - Follow the same frontmatter format as execute-plan.md and execute-phase.md
189
+ </design_notes>