specdacular 0.10.0 → 0.11.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 (60) hide show
  1. package/README.md +3 -3
  2. package/bin/install.js +3 -1
  3. package/bin/specd.js +135 -0
  4. package/commands/specd.best-practices.md +75 -0
  5. package/commands/specd.docs.md +81 -0
  6. package/commands/specd.docs.review.md +80 -0
  7. package/commands/specd.generate-skills.learn.md +65 -0
  8. package/commands/specd.new-project.md +58 -0
  9. package/commands/specd.new-runner-task.md +52 -0
  10. package/commands/specd.new.md +6 -6
  11. package/commands/specd.runner-status.md +27 -0
  12. package/package.json +6 -2
  13. package/runner/main/agent/parser.js +39 -0
  14. package/runner/main/agent/runner.js +137 -0
  15. package/runner/main/agent/template.js +16 -0
  16. package/runner/main/bootstrap.js +69 -0
  17. package/runner/main/db.js +45 -0
  18. package/runner/main/index.js +103 -0
  19. package/runner/main/ipc.js +72 -0
  20. package/runner/main/notifications/telegram.js +45 -0
  21. package/runner/main/orchestrator.js +193 -0
  22. package/runner/main/paths.js +36 -0
  23. package/runner/main/pipeline/resolver.js +20 -0
  24. package/runner/main/pipeline/sequencer.js +42 -0
  25. package/runner/main/server/api.js +125 -0
  26. package/runner/main/server/index.js +33 -0
  27. package/runner/main/server/websocket.js +24 -0
  28. package/runner/main/state/manager.js +83 -0
  29. package/runner/main/template-manager.js +41 -0
  30. package/runner/main/test/agent-parser.test.js +44 -0
  31. package/runner/main/test/bootstrap.test.js +58 -0
  32. package/runner/main/test/db.test.js +72 -0
  33. package/runner/main/test/paths.test.js +29 -0
  34. package/runner/main/test/state-manager.test.js +72 -0
  35. package/runner/main/test/template-manager.test.js +66 -0
  36. package/runner/main/worktree/manager.js +95 -0
  37. package/runner/package.json +22 -0
  38. package/runner/preload.js +19 -0
  39. package/specdacular/HELP.md +20 -11
  40. package/specdacular/agents/best-practices-researcher.md +271 -0
  41. package/specdacular/agents/project-researcher.md +409 -0
  42. package/specdacular/references/load-context.md +4 -7
  43. package/specdacular/templates/orchestrator/CONCERNS.md +1 -1
  44. package/specdacular/templates/orchestrator/PROJECTS.md +3 -4
  45. package/specdacular/templates/tasks/PLAN.md +2 -2
  46. package/specdacular/templates/tasks/PROJECT.md +52 -0
  47. package/specdacular/templates/tasks/REQUIREMENTS.md +75 -0
  48. package/specdacular/workflows/best-practices.md +472 -0
  49. package/specdacular/workflows/context-add.md +16 -30
  50. package/specdacular/workflows/context-manual-review.md +7 -7
  51. package/specdacular/workflows/docs-review.md +273 -0
  52. package/specdacular/workflows/docs.md +420 -0
  53. package/specdacular/workflows/generate-learn-skill.md +214 -0
  54. package/specdacular/workflows/new-project.md +799 -0
  55. package/specdacular/workflows/new.md +5 -4
  56. package/specdacular/workflows/orchestrator/new.md +4 -4
  57. package/specdacular/workflows/orchestrator/plan.md +6 -6
  58. package/commands/specd.codebase.map.md +0 -72
  59. package/commands/specd.codebase.review.md +0 -39
  60. package/specdacular/workflows/map-codebase.md +0 -715
@@ -29,10 +29,9 @@
29
29
 
30
30
  ### Codebase Docs
31
31
 
32
- - `{project-path}/.specd/codebase/MAP.md` — System overview
33
- - `{project-path}/.specd/codebase/PATTERNS.md` — Code patterns
34
- - `{project-path}/.specd/codebase/STRUCTURE.md` — File structure
35
- - `{project-path}/.specd/codebase/CONCERNS.md` — Project-level concerns
32
+ - `{project-path}/CLAUDE.md` — Routing table for project docs
33
+ - `{project-path}/docs/rules.md` — Project-wide rules
34
+ - `{project-path}/docs/*.md` — Topic-specific patterns and guidance
36
35
 
37
36
  ---
38
37
 
@@ -17,8 +17,8 @@ modifies:
17
17
  ## Context
18
18
 
19
19
  **Reference these files:**
20
- - `@.specd/codebase/PATTERNS.md` — Code patterns to follow
21
- - `@.specd/codebase/STRUCTURE.md` — Where files go
20
+ - `@CLAUDE.md` — Routing table for project docs
21
+ - `@docs/rules.md` — Project-wide rules and conventions
22
22
  - `@{path/to/pattern/file}` — Pattern to follow for this task
23
23
 
24
24
  **Relevant Decisions:**
@@ -0,0 +1,52 @@
1
+ # Project: {project-name}
2
+
3
+ ## Vision
4
+
5
+ {One paragraph: what this project is and why it exists. Focus on the core value proposition.}
6
+
7
+ ## Problem Statement
8
+
9
+ {What problem does this solve? Who experiences this problem? Why do existing solutions fall short?}
10
+
11
+ ## Target Users
12
+
13
+ {Who uses this and how? Be specific about user roles and their primary workflows.}
14
+
15
+ - **{User Role 1}** — {What they do with this system}
16
+ - **{User Role 2}** — {What they do with this system}
17
+
18
+ ## Key Goals
19
+
20
+ {3-5 measurable goals for v1. Each should be testable/observable.}
21
+
22
+ 1. {Goal 1}
23
+ 2. {Goal 2}
24
+ 3. {Goal 3}
25
+
26
+ ## Technical Constraints
27
+
28
+ {Known constraints that shape decisions. Platform, language, integrations, timeline, team.}
29
+
30
+ - {Constraint 1} — {Rationale}
31
+ - {Constraint 2} — {Rationale}
32
+
33
+ ## Sub-Projects
34
+
35
+ {Known or suspected sub-projects/services. Can be empty if not yet identified. Will be refined during research and roadmap stages.}
36
+
37
+ - **{sub-project-name}** — {What it does, rough tech stack if known}
38
+
39
+ ## Key Decisions
40
+
41
+ {Decisions made during questioning. Reference DEC-IDs if recorded in DECISIONS.md.}
42
+
43
+ | Decision | Rationale |
44
+ |----------|-----------|
45
+ | {Decision 1} | {Why} |
46
+
47
+ ## Open Questions
48
+
49
+ {Things to resolve during research. These feed into the research agent prompts.}
50
+
51
+ - {Question 1}
52
+ - {Question 2}
@@ -0,0 +1,75 @@
1
+ # Requirements: {project-name}
2
+
3
+ **Scoped:** {date}
4
+ **Total v1:** {count}
5
+
6
+ ---
7
+
8
+ ## v1 Requirements
9
+
10
+ | REQ-ID | Category | Feature | Description | Complexity | Dependencies |
11
+ |--------|----------|---------|-------------|------------|--------------|
12
+ | REQ-001 | {table-stakes\|differentiator\|nice-to-have} | {Feature Name} | {Brief description} | {Low\|Med\|High} | {REQ-IDs or "None"} |
13
+
14
+ ---
15
+
16
+ ## v2+ (Deferred)
17
+
18
+ | Feature | Category | Rationale for Deferral |
19
+ |---------|----------|----------------------|
20
+ | {Feature Name} | {category} | {Why it can wait} |
21
+
22
+ ---
23
+
24
+ ## Out of Scope
25
+
26
+ | Feature | Rationale |
27
+ |---------|-----------|
28
+ | {Feature Name} | {Why explicitly excluded} |
29
+
30
+ ---
31
+
32
+ ## Requirement Details
33
+
34
+ ### REQ-001: {Feature Name}
35
+
36
+ **Category:** {table-stakes|differentiator|nice-to-have}
37
+ **Complexity:** {Low|Med|High}
38
+ **Dependencies:** {REQ-IDs or "None"}
39
+
40
+ **Description:**
41
+ {Expanded description of what this requirement entails.}
42
+
43
+ **Acceptance Criteria:**
44
+ - [ ] {Specific, testable criterion}
45
+ - [ ] {Specific, testable criterion}
46
+
47
+ ---
48
+
49
+ ## Dependencies
50
+
51
+ ```
52
+ {Dependency diagram showing which REQ-IDs depend on others}
53
+ REQ-001
54
+ ├── REQ-003
55
+ └── REQ-005
56
+ └── REQ-007
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Summary
62
+
63
+ | Metric | Count |
64
+ |--------|-------|
65
+ | v1 Requirements | {count} |
66
+ | Table Stakes | {count} |
67
+ | Differentiators | {count} |
68
+ | Nice-to-Have (included) | {count} |
69
+ | Deferred to v2+ | {count} |
70
+ | Out of Scope | {count} |
71
+
72
+ **Complexity Distribution:**
73
+ - Low: {count}
74
+ - Medium: {count}
75
+ - High: {count}
@@ -0,0 +1,472 @@
1
+ <purpose>
2
+ Detect a repo's tech stack, ask user for focus areas, spawn 3 research agents, merge findings into docs/best-practices.md.
3
+
4
+ **Output:** `docs/best-practices.md` in the target repo
5
+ </purpose>
6
+
7
+ <philosophy>
8
+
9
+ ## Detect, Don't Ask
10
+
11
+ Auto-detect the tech stack from marker files and dependencies. The user shouldn't have to tell us what they use.
12
+
13
+ ## Options, Not Opinions
14
+
15
+ Present what's available with context and tradeoffs. Light "recommended" tags are fine, but the user chooses. Research agents must capture multiple options per topic.
16
+
17
+ ## User Steers Research
18
+
19
+ Ask for focus areas before dispatching agents. Focused research is deeper and more useful than broad-but-shallow.
20
+
21
+ ## Verify Before Publishing
22
+
23
+ Web-sourced claims must be treated as untrusted. URLs may be stale, recommendations may be outdated. The merge step should flag low-confidence items.
24
+
25
+ </philosophy>
26
+
27
+ <process>
28
+
29
+ <step name="detect_stack">
30
+ Detect all tech stacks in the repo from marker files and dependency parsing.
31
+
32
+ ```bash
33
+ # Detect marker files at repo root
34
+ STACKS=""
35
+
36
+ # Node.js / TypeScript
37
+ if [ -f "package.json" ]; then
38
+ DEPS=$(cat package.json | grep -E '"(dependencies|devDependencies)"' -A 100 | grep -oE '"(next|react|vue|svelte|angular|express|fastify|nestjs|nuxt|remix|astro|hono|elysia|bun|deno)"' | tr -d '"' | sort -u | tr '\n' ', ' | sed 's/,$//')
39
+ if [ -f "tsconfig.json" ] || grep -q '"typescript"' package.json 2>/dev/null; then
40
+ STACKS="$STACKS\nTypeScript: $DEPS"
41
+ else
42
+ STACKS="$STACKS\nNode.js: $DEPS"
43
+ fi
44
+ fi
45
+
46
+ # Python
47
+ if [ -f "pyproject.toml" ]; then
48
+ DEPS=$(grep -E '(fastapi|django|flask|starlette|litestar|sanic|tornado|streamlit|gradio|celery|pytest)' pyproject.toml 2>/dev/null | grep -oE '(fastapi|django|flask|starlette|litestar|sanic|tornado|streamlit|gradio|celery|pytest)' | sort -u | tr '\n' ', ' | sed 's/,$//')
49
+ STACKS="$STACKS\nPython: $DEPS"
50
+ elif [ -f "requirements.txt" ]; then
51
+ DEPS=$(grep -oiE '(fastapi|django|flask|starlette|litestar|sanic|tornado|streamlit|gradio|celery|pytest)' requirements.txt 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
52
+ STACKS="$STACKS\nPython: $DEPS"
53
+ elif [ -f "setup.py" ] || [ -f "setup.cfg" ]; then
54
+ STACKS="$STACKS\nPython: (legacy setup)"
55
+ fi
56
+
57
+ # Go
58
+ if [ -f "go.mod" ]; then
59
+ DEPS=$(grep -oE '(gin-gonic|echo|fiber|chi|gorilla|gorm|sqlx|ent)' go.mod 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
60
+ STACKS="$STACKS\nGo: $DEPS"
61
+ fi
62
+
63
+ # Rust
64
+ if [ -f "Cargo.toml" ]; then
65
+ DEPS=$(grep -oE '(actix-web|axum|rocket|warp|tokio|serde|diesel|sqlx|sea-orm)' Cargo.toml 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
66
+ STACKS="$STACKS\nRust: $DEPS"
67
+ fi
68
+
69
+ # Java / Kotlin
70
+ if [ -f "pom.xml" ]; then
71
+ DEPS=$(grep -oE '(spring-boot|quarkus|micronaut|jakarta)' pom.xml 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
72
+ STACKS="$STACKS\nJava: $DEPS"
73
+ elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
74
+ DEPS=$(grep -oE '(spring-boot|quarkus|micronaut|ktor)' build.gradle* 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
75
+ STACKS="$STACKS\nJava/Kotlin: $DEPS"
76
+ fi
77
+
78
+ # Ruby
79
+ if [ -f "Gemfile" ]; then
80
+ DEPS=$(grep -oE "'(rails|sinatra|hanami|rspec|sidekiq)'" Gemfile 2>/dev/null | tr -d "'" | sort -u | tr '\n' ', ' | sed 's/,$//')
81
+ STACKS="$STACKS\nRuby: $DEPS"
82
+ fi
83
+
84
+ # PHP
85
+ if [ -f "composer.json" ]; then
86
+ DEPS=$(grep -oE '"(laravel|symfony|slim|phpunit)"' composer.json 2>/dev/null | tr -d '"' | sort -u | tr '\n' ', ' | sed 's/,$//')
87
+ STACKS="$STACKS\nPHP: $DEPS"
88
+ fi
89
+
90
+ # .NET / C#
91
+ if ls *.csproj 2>/dev/null | head -1 > /dev/null; then
92
+ DEPS=$(grep -oE '(AspNetCore|EntityFramework|Blazor|MAUI)' *.csproj 2>/dev/null | sort -u | tr '\n' ', ' | sed 's/,$//')
93
+ STACKS="$STACKS\n.NET: $DEPS"
94
+ fi
95
+
96
+ # Elixir
97
+ if [ -f "mix.exs" ]; then
98
+ DEPS=$(grep -oE ':(phoenix|ecto|absinthe|oban|live_view)' mix.exs 2>/dev/null | tr -d ':' | sort -u | tr '\n' ', ' | sed 's/,$//')
99
+ STACKS="$STACKS\nElixir: $DEPS"
100
+ fi
101
+
102
+ # Clean up and display
103
+ echo "$STACKS" | grep -v '^$'
104
+ ```
105
+
106
+ **Also detect project signals for calibrated recommendations:**
107
+ ```bash
108
+ # Project maturity signals
109
+ [ -f "Dockerfile" ] || [ -f "docker-compose.yml" ] && echo "SIGNAL: Docker"
110
+ [ -d ".github/workflows" ] || [ -f ".gitlab-ci.yml" ] || [ -f "Jenkinsfile" ] && echo "SIGNAL: CI/CD"
111
+ [ -d "tests" ] || [ -d "test" ] || [ -d "__tests__" ] || [ -d "spec" ] && echo "SIGNAL: Test directory"
112
+ [ -f ".eslintrc*" ] || [ -f "eslint.config.*" ] || [ -f ".prettierrc*" ] || [ -f "ruff.toml" ] || [ -f ".flake8" ] && echo "SIGNAL: Linting configured"
113
+ find . -maxdepth 3 -name "*.ts" -o -name "*.py" -o -name "*.go" -o -name "*.rs" -o -name "*.java" -o -name "*.rb" 2>/dev/null | head -200 | wc -l | xargs echo "SIGNAL: Source files:"
114
+ ```
115
+
116
+ Store detected stacks as `$DETECTED_STACKS` and signals as `$PROJECT_SIGNALS`.
117
+
118
+ Continue to present_stacks.
119
+ </step>
120
+
121
+ <step name="present_stacks">
122
+ Show detected stacks to the user.
123
+
124
+ ```
125
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
126
+ BEST PRACTICES RESEARCH
127
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
128
+
129
+ Detected stacks:
130
+ {$DETECTED_STACKS formatted as a list}
131
+
132
+ Project signals:
133
+ {$PROJECT_SIGNALS}
134
+ ```
135
+
136
+ **If no stacks detected:**
137
+ ```
138
+ No tech stacks detected from marker files. This might be an empty repo
139
+ or use an uncommon setup.
140
+
141
+ You can still run research — just tell me what stack you're using.
142
+ ```
143
+ Use AskUserQuestion to ask what stack to research.
144
+
145
+ **If 3+ stacks detected (monorepo risk per research pitfalls):**
146
+ Use AskUserQuestion:
147
+ - header: "Multiple Stacks Detected"
148
+ - question: "I found several tech stacks. Which should I research? (Multiple stacks in a repo can include build tool configs that aren't your main stack.)"
149
+ - options: Each detected stack as a separate option, plus "All of them"
150
+
151
+ Store selected stacks as `$SELECTED_STACKS`. If fewer than 3 stacks or user selects "All", use all detected stacks.
152
+
153
+ Continue to ask_focus.
154
+ </step>
155
+
156
+ <step name="ask_focus">
157
+ Ask user for research focus areas (DEC-003).
158
+
159
+ Use AskUserQuestion:
160
+ - header: "Research Focus"
161
+ - question: "What should I focus on? I'll research deeper in your chosen areas."
162
+ - options:
163
+ - "Everything — full breadth across all categories"
164
+ - "Project structure & patterns — architecture, file layout, common libraries"
165
+ - "Claude Code tools — MCP servers, skills, hooks, CLAUDE.md patterns"
166
+ - "Tooling & DX — linting, formatting, testing, CI/CD, pre-commit hooks"
167
+
168
+ Store response as `$FOCUS_AREAS`.
169
+
170
+ Continue to spawn_agents.
171
+ </step>
172
+
173
+ <step name="spawn_agents">
174
+ Spawn 3 parallel research agents with stack and focus context. All agents run in background simultaneously.
175
+
176
+ **Spawn all 3 agents in a single message using the Agent tool with `run_in_background: true`:**
177
+
178
+ ### Agent 1: Stack Patterns
179
+
180
+ ```
181
+ Agent(
182
+ subagent_type: "general-purpose"
183
+ model: "sonnet"
184
+ description: "Stack patterns research"
185
+ run_in_background: true
186
+ prompt: "First, read ~/.claude/specdacular/agents/best-practices-researcher.md for your role and output format.
187
+
188
+ <focus_area>stack-patterns</focus_area>
189
+
190
+ <detected_stacks>
191
+ $SELECTED_STACKS
192
+ </detected_stacks>
193
+
194
+ <user_focus>
195
+ $FOCUS_AREAS
196
+ </user_focus>
197
+
198
+ <project_signals>
199
+ $PROJECT_SIGNALS
200
+ </project_signals>
201
+
202
+ Research project structure options, architectural patterns, and common libraries for the detected stacks.
203
+
204
+ <search_targets>
205
+ 1. Search: '{primary_stack} project structure best practices 2026'
206
+ 2. Search: '{primary_stack} recommended libraries production 2026'
207
+ 3. Search: 'awesome-{primary_stack} github'
208
+ 4. Search: '{primary_framework} vs alternatives comparison 2026' (if framework detected)
209
+ 5. Fetch: Official docs or awesome-list for top finding (verify claims)
210
+ </search_targets>
211
+
212
+ <output_instructions>
213
+ Return structured markdown following the 'Stack Patterns Output' format from your role file.
214
+ Every recommendation must include: name, purpose, tradeoffs, when to use it.
215
+ Assign confidence levels. Cite sources.
216
+ Do NOT write files — just return the markdown.
217
+ </output_instructions>"
218
+ )
219
+ ```
220
+
221
+ ### Agent 2: Claude Code Ecosystem
222
+
223
+ ```
224
+ Agent(
225
+ subagent_type: "general-purpose"
226
+ model: "sonnet"
227
+ description: "Claude Code ecosystem research"
228
+ run_in_background: true
229
+ prompt: "First, read ~/.claude/specdacular/agents/best-practices-researcher.md for your role and output format.
230
+
231
+ <focus_area>claude-code-ecosystem</focus_area>
232
+
233
+ <detected_stacks>
234
+ $SELECTED_STACKS
235
+ </detected_stacks>
236
+
237
+ <user_focus>
238
+ $FOCUS_AREAS
239
+ </user_focus>
240
+
241
+ Research Claude Code MCP servers, skills, hooks, and CLAUDE.md patterns relevant to the detected stacks.
242
+
243
+ <search_targets>
244
+ 1. Search: 'Claude Code MCP servers {primary_stack} 2026'
245
+ 2. Search: 'awesome-mcp-servers github' — fetch the README for the full server list
246
+ 3. Search: 'awesome-claude-code github' — fetch for skills and hooks patterns
247
+ 4. Search: 'Claude Code CLAUDE.md best practices {primary_stack}'
248
+ 5. Fetch: punkpeye/awesome-mcp-servers README or mcpservers.org for current server list
249
+ </search_targets>
250
+
251
+ <security_note>
252
+ 43% of examined MCP servers had critical security flaws (2026 research).
253
+ For every MCP server you recommend, include a note about whether it's from an official/verified source.
254
+ Always link to the official registry page, not raw install commands from web results.
255
+ </security_note>
256
+
257
+ <output_instructions>
258
+ Return structured markdown following the 'Claude Code Ecosystem Output' format from your role file.
259
+ Include MCP servers with: name, purpose, install command (from official source only), stack relevance, confidence, security notes.
260
+ Include CLAUDE.md recommendations, skill patterns, and hook patterns.
261
+ Do NOT write files — just return the markdown.
262
+ </output_instructions>"
263
+ )
264
+ ```
265
+
266
+ ### Agent 3: Tooling & DX
267
+
268
+ ```
269
+ Agent(
270
+ subagent_type: "general-purpose"
271
+ model: "sonnet"
272
+ description: "Tooling and DX research"
273
+ run_in_background: true
274
+ prompt: "First, read ~/.claude/specdacular/agents/best-practices-researcher.md for your role and output format.
275
+
276
+ <focus_area>tooling-dx</focus_area>
277
+
278
+ <detected_stacks>
279
+ $SELECTED_STACKS
280
+ </detected_stacks>
281
+
282
+ <user_focus>
283
+ $FOCUS_AREAS
284
+ </user_focus>
285
+
286
+ <project_signals>
287
+ $PROJECT_SIGNALS
288
+ </project_signals>
289
+
290
+ Research linters, formatters, testing frameworks, CI patterns, and pre-commit hooks for the detected stacks.
291
+
292
+ <search_targets>
293
+ 1. Search: '{primary_stack} linter formatter comparison 2026'
294
+ 2. Search: '{primary_stack} testing framework comparison 2026'
295
+ 3. Search: '{primary_stack} CI/CD github actions best practices 2026'
296
+ 4. Search: '{primary_stack} pre-commit hooks developer experience'
297
+ 5. Fetch: Official docs for top linter/formatter to verify current config format
298
+ </search_targets>
299
+
300
+ <calibration>
301
+ Use project signals to calibrate recommendations:
302
+ - If CI/CD signal detected: focus on optimizing existing, not setting up from scratch
303
+ - If linting signal detected: compare existing tools to alternatives
304
+ - If no test directory: emphasize testing setup as priority
305
+ - Source file count indicates project scale: tailor recommendations accordingly
306
+ </calibration>
307
+
308
+ <output_instructions>
309
+ Return structured markdown following the 'Tooling & DX Output' format from your role file.
310
+ Present options as comparisons (tool A vs tool B) with tradeoffs.
311
+ Include pre-commit hook recommendations.
312
+ Do NOT write files — just return the markdown.
313
+ </output_instructions>"
314
+ )
315
+ ```
316
+
317
+ After spawning all 3, continue to collect_results.
318
+
319
+ Continue to collect_results.
320
+ </step>
321
+
322
+ <step name="collect_results">
323
+ Wait for all 3 background agents to complete and collect their outputs.
324
+
325
+ **The agents were spawned with `run_in_background: true`, so they will notify when done.** Wait for all 3 notifications before proceeding.
326
+
327
+ **For each agent, when it completes:**
328
+ - Read the returned output (structured markdown)
329
+ - Store as `$AGENT_1_OUTPUT`, `$AGENT_2_OUTPUT`, `$AGENT_3_OUTPUT`
330
+ - If an agent failed or returned empty output, note it but continue
331
+
332
+ **Display status:**
333
+ ```
334
+ Research agents complete:
335
+ - Stack Patterns: {✓ complete | ✗ failed}
336
+ - Claude Code Ecosystem: {✓ complete | ✗ failed}
337
+ - Tooling & DX: {✓ complete | ✗ failed}
338
+ ```
339
+
340
+ **If any agent failed:**
341
+ ```
342
+ Note: {agent name} research failed. The output doc will have reduced
343
+ coverage in that section. You can re-run /specd.best-practices to retry.
344
+ ```
345
+
346
+ **If all agents failed:**
347
+ ```
348
+ All research agents failed. This may be due to rate limiting or network
349
+ issues. Try again in a few minutes with /specd.best-practices.
350
+ ```
351
+ End workflow.
352
+
353
+ Continue to merge_and_write.
354
+ </step>
355
+
356
+ <step name="merge_and_write">
357
+ Merge agent outputs into `docs/best-practices.md`.
358
+
359
+ ```bash
360
+ mkdir -p docs
361
+ ```
362
+
363
+ **Get project name from current directory:**
364
+ ```bash
365
+ basename $(pwd)
366
+ ```
367
+ Store as `$PROJECT_NAME`.
368
+
369
+ **Build the output document** by assembling agent outputs into the category structure. Write using the Write tool to `docs/best-practices.md`:
370
+
371
+ ```markdown
372
+ # Best Practices: {$SELECTED_STACKS} ({$PROJECT_NAME})
373
+
374
+ > Generated: {today's date} by `/specd.best-practices`
375
+ > Re-run to refresh with latest recommendations.
376
+
377
+ ---
378
+
379
+ ## Detected Stack
380
+
381
+ {$SELECTED_STACKS with framework details from detect_stack step}
382
+
383
+ **Project signals:** {$PROJECT_SIGNALS summary — Docker, CI/CD, tests, linting, file count}
384
+
385
+ ---
386
+
387
+ ## Project Structure & Patterns
388
+
389
+ {Insert $AGENT_1_OUTPUT here — Stack Patterns agent findings}
390
+
391
+ {If agent 1 failed: "⚠️ Stack patterns research was unavailable. Re-run `/specd.best-practices` to retry."}
392
+
393
+ ---
394
+
395
+ ## Claude Code Configuration
396
+
397
+ {Insert $AGENT_2_OUTPUT here — Claude Code Ecosystem agent findings}
398
+
399
+ {If agent 2 failed: "⚠️ Claude Code ecosystem research was unavailable. Re-run `/specd.best-practices` to retry."}
400
+
401
+ ---
402
+
403
+ ## Tooling & DX
404
+
405
+ {Insert $AGENT_3_OUTPUT here — Tooling & DX agent findings}
406
+
407
+ {If agent 3 failed: "⚠️ Tooling & DX research was unavailable. Re-run `/specd.best-practices` to retry."}
408
+
409
+ ---
410
+
411
+ ## Sources
412
+
413
+ {Aggregate all source URLs from agent outputs into a single list.
414
+ Only include URLs that agents marked as verified.
415
+ Group by: Official Docs, Community Resources, Registries.}
416
+ ```
417
+
418
+ **Merge rules to follow:**
419
+
420
+ 1. **Organize by category, not by agent.** Each agent's output maps to one section, but if an agent's findings touch another section's topic, move that content to the appropriate section.
421
+
422
+ 2. **Contradiction detection:** Before writing, scan all 3 agent outputs for cases where the same technology or tool is mentioned with conflicting recommendations. If found, add a note:
423
+ ```
424
+ > **Note:** Different research sources have varying perspectives on {tool}.
425
+ > {Perspective 1} vs {Perspective 2}. Consider your specific needs.
426
+ ```
427
+
428
+ 3. **Confidence filtering:**
429
+ - HIGH confidence findings: include directly as recommendations
430
+ - MEDIUM confidence findings: include with source attribution
431
+ - LOW confidence findings: move to a "For Awareness (Unverified)" subsection at the bottom of each major section, or omit if section is already comprehensive
432
+
433
+ 4. **URL verification:** Only include URLs that agents reported as verified (fetched successfully). Drop broken or unverified URLs.
434
+
435
+ 5. **Do NOT modify CLAUDE.md** (DEC-002). The output file is `docs/best-practices.md` only.
436
+
437
+ Continue to completion.
438
+ </step>
439
+
440
+ <step name="completion">
441
+ Show summary to user.
442
+
443
+ ```
444
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
445
+ BEST PRACTICES GENERATED
446
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
447
+
448
+ **Stack:** {$SELECTED_STACKS}
449
+ **Output:** docs/best-practices.md
450
+
451
+ **Sections:**
452
+ - Project Structure & Patterns: {count} recommendations
453
+ - Claude Code Configuration: {count} MCP servers, {count} skills/hooks
454
+ - Tooling & DX: {count} recommendations
455
+
456
+ The doc is ready to review. It is NOT committed or added to CLAUDE.md.
457
+ You can commit it if you find it useful, or re-run to refresh.
458
+ ```
459
+
460
+ End workflow.
461
+ </step>
462
+
463
+ </process>
464
+
465
+ <success_criteria>
466
+ - Tech stack auto-detected from repo marker files and dependencies
467
+ - User asked for focus areas before agent dispatch
468
+ - 3 research agents spawned with stack-aware context
469
+ - Agent outputs merged into categorized docs/best-practices.md
470
+ - Each recommendation has: name, purpose, tradeoffs, when to use it
471
+ - Generation date stamped, CLAUDE.md not modified
472
+ </success_criteria>