pi-maestro-flow 0.2.0 → 0.3.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 (235) hide show
  1. package/README.md +44 -72
  2. package/agents/cross-role-reviewer.md +1 -1
  3. package/agents/impeccable-agent.md +1 -1
  4. package/agents/ralph-executor.md +1 -1
  5. package/agents/team-worker.md +1 -1
  6. package/agents/workflow-analyzer.md +1 -1
  7. package/agents/workflow-codebase-mapper.md +1 -1
  8. package/agents/workflow-collab-planner.md +1 -1
  9. package/agents/workflow-debugger.md +1 -1
  10. package/agents/workflow-executor.md +1 -1
  11. package/agents/workflow-integration-checker.md +1 -1
  12. package/agents/workflow-nyquist-auditor.md +1 -1
  13. package/agents/workflow-phase-researcher.md +1 -1
  14. package/agents/workflow-planner.md +1 -1
  15. package/agents/workflow-project-researcher.md +1 -1
  16. package/agents/workflow-reviewer.md +1 -1
  17. package/agents/workflow-verifier.md +1 -1
  18. package/package.json +13 -4
  19. package/skills/codify-to-knowhow/SKILL.md +1 -1
  20. package/skills/delegation-check/SKILL.md +1 -1
  21. package/skills/domain-add/SKILL.md +5 -7
  22. package/skills/insight-challenge/SKILL.md +1 -1
  23. package/skills/learn-decompose/SKILL.md +4 -4
  24. package/skills/learn-follow/SKILL.md +5 -5
  25. package/skills/learn-investigate/SKILL.md +5 -5
  26. package/skills/learn-second-opinion/SKILL.md +5 -5
  27. package/skills/maestro/SKILL.md +9 -10
  28. package/skills/maestro-amend/SKILL.md +3 -3
  29. package/skills/maestro-analyze/SKILL.md +10 -13
  30. package/skills/maestro-blueprint/SKILL.md +8 -11
  31. package/skills/maestro-brainstorm/SKILL.md +11 -14
  32. package/skills/maestro-collab/SKILL.md +4 -4
  33. package/skills/maestro-companion/SKILL.md +3 -3
  34. package/skills/maestro-composer/SKILL.md +11 -12
  35. package/skills/maestro-execute/SKILL.md +9 -12
  36. package/skills/maestro-fork/SKILL.md +8 -11
  37. package/skills/maestro-grill/SKILL.md +13 -16
  38. package/skills/maestro-guard/SKILL.md +5 -5
  39. package/skills/maestro-help/SKILL.md +3 -3
  40. package/skills/maestro-impeccable/SKILL.md +7 -7
  41. package/skills/maestro-init/SKILL.md +9 -12
  42. package/skills/maestro-merge/SKILL.md +6 -8
  43. package/skills/maestro-milestone-audit/SKILL.md +3 -5
  44. package/skills/maestro-milestone-complete/SKILL.md +9 -12
  45. package/skills/maestro-milestone-release/SKILL.md +9 -11
  46. package/skills/maestro-next/SKILL.md +5 -5
  47. package/skills/maestro-overlay/SKILL.md +16 -16
  48. package/skills/maestro-plan/SKILL.md +9 -12
  49. package/skills/maestro-player/SKILL.md +5 -5
  50. package/skills/maestro-quick/SKILL.md +5 -7
  51. package/skills/maestro-ralph/SKILL.md +16 -17
  52. package/skills/maestro-ralph-cli/SKILL.md +6 -6
  53. package/skills/maestro-ralph-cli-execute/SKILL.md +2 -2
  54. package/skills/maestro-ralph-execute/SKILL.md +4 -4
  55. package/skills/maestro-ralph-v2/SKILL.md +18 -19
  56. package/skills/maestro-roadmap/SKILL.md +8 -9
  57. package/skills/maestro-swarm-workflow/SKILL.md +9 -9
  58. package/skills/maestro-tools-execute/SKILL.md +5 -7
  59. package/skills/maestro-tools-register/SKILL.md +7 -9
  60. package/skills/maestro-ui-codify/SKILL.md +9 -10
  61. package/skills/maestro-universal-workflow/SKILL.md +15 -15
  62. package/skills/maestro-update/SKILL.md +10 -10
  63. package/skills/manage-codebase-rebuild/SKILL.md +4 -6
  64. package/skills/manage-drift-realign/SKILL.md +8 -11
  65. package/skills/manage-harvest/SKILL.md +6 -9
  66. package/skills/manage-issue/SKILL.md +5 -8
  67. package/skills/manage-issue-discover/SKILL.md +8 -11
  68. package/skills/manage-kg-extractors/SKILL.md +3 -3
  69. package/skills/manage-knowhow/SKILL.md +3 -5
  70. package/skills/manage-knowhow-capture/SKILL.md +4 -6
  71. package/skills/manage-knowledge-audit/SKILL.md +6 -9
  72. package/skills/manage-status/SKILL.md +3 -5
  73. package/skills/manage-wiki/SKILL.md +5 -7
  74. package/skills/odyssey-debug/SKILL.md +13 -13
  75. package/skills/odyssey-improve/SKILL.md +15 -15
  76. package/skills/odyssey-planex/SKILL.md +16 -16
  77. package/skills/odyssey-review-test-fix/SKILL.md +11 -11
  78. package/skills/odyssey-ui/SKILL.md +10 -10
  79. package/skills/prompt-generator/SKILL.md +5 -5
  80. package/skills/quality-auto-test/SKILL.md +3 -5
  81. package/skills/quality-debug/SKILL.md +3 -5
  82. package/skills/quality-refactor/SKILL.md +3 -5
  83. package/skills/quality-retrospective/SKILL.md +10 -13
  84. package/skills/quality-review/SKILL.md +5 -8
  85. package/skills/quality-sync/SKILL.md +3 -5
  86. package/skills/quality-test/SKILL.md +4 -6
  87. package/skills/scholar-anti-ai-writing/SKILL.md +1 -1
  88. package/skills/scholar-citation-verify/SKILL.md +1 -1
  89. package/skills/scholar-experiment/SKILL.md +2 -2
  90. package/skills/scholar-ideation/SKILL.md +7 -7
  91. package/skills/scholar-latex-organizer/SKILL.md +1 -1
  92. package/skills/scholar-publish/SKILL.md +3 -3
  93. package/skills/scholar-rebuttal-pro/SKILL.md +3 -3
  94. package/skills/scholar-review/SKILL.md +1 -1
  95. package/skills/scholar-writing/SKILL.md +1 -1
  96. package/skills/security-audit/SKILL.md +2 -4
  97. package/skills/skill-generator/SKILL.md +3 -3
  98. package/skills/skill-iter-tune/SKILL.md +3 -3
  99. package/skills/skill-simplify/SKILL.md +1 -1
  100. package/skills/skill-tuning/SKILL.md +1 -1
  101. package/skills/spec-add/SKILL.md +5 -7
  102. package/skills/spec-load/SKILL.md +3 -5
  103. package/skills/spec-remove/SKILL.md +4 -6
  104. package/skills/spec-setup/SKILL.md +6 -8
  105. package/skills/team-adversarial-swarm/SKILL.md +5 -5
  106. package/skills/team-arch-opt/SKILL.md +2 -2
  107. package/skills/team-brainstorm/SKILL.md +3 -3
  108. package/skills/team-coordinate/SKILL.md +4 -4
  109. package/skills/team-designer/SKILL.md +1 -1
  110. package/skills/team-executor/SKILL.md +3 -3
  111. package/skills/team-frontend/SKILL.md +2 -2
  112. package/skills/team-frontend-debug/SKILL.md +3 -3
  113. package/skills/team-interactive-craft/SKILL.md +2 -2
  114. package/skills/team-issue/SKILL.md +3 -3
  115. package/skills/team-lifecycle-v4/SKILL.md +4 -4
  116. package/skills/team-motion-design/SKILL.md +2 -2
  117. package/skills/team-perf-opt/SKILL.md +3 -3
  118. package/skills/team-planex/SKILL.md +2 -2
  119. package/skills/team-quality-assurance/SKILL.md +3 -3
  120. package/skills/team-review/SKILL.md +3 -3
  121. package/skills/team-roadmap-dev/SKILL.md +3 -3
  122. package/skills/team-swarm/SKILL.md +4 -4
  123. package/skills/team-tech-debt/SKILL.md +2 -2
  124. package/skills/team-testing/SKILL.md +3 -3
  125. package/skills/team-ui-polish/SKILL.md +2 -2
  126. package/skills/team-uidesign/SKILL.md +2 -2
  127. package/skills/team-ultra-analyze/SKILL.md +4 -4
  128. package/skills/team-ux-improve/SKILL.md +3 -3
  129. package/skills/team-visual-a11y/SKILL.md +2 -2
  130. package/skills/workflow-skill-designer/SKILL.md +8 -8
  131. package/templates/business-test-report.json +68 -0
  132. package/templates/config.json +48 -0
  133. package/templates/context.md +16 -0
  134. package/templates/doc-index.json +11 -0
  135. package/templates/index.json +68 -0
  136. package/templates/issue.json +36 -0
  137. package/templates/plan.json +38 -0
  138. package/templates/project.md +60 -0
  139. package/templates/reflection-log.md +20 -0
  140. package/templates/roadmap.md +45 -0
  141. package/templates/scratch-index.json +19 -0
  142. package/templates/search-tool.json +1 -0
  143. package/templates/search-tools.md +47 -0
  144. package/templates/state.json +18 -0
  145. package/templates/task-summary.md +21 -0
  146. package/templates/task.json +89 -0
  147. package/templates/terminology-template.json +22 -0
  148. package/templates/uat.md +21 -0
  149. package/templates/validation.json +31 -0
  150. package/templates/verification.json +37 -0
  151. package/templates/workflow.md +14 -0
  152. package/templates/worktree-scope.json +9 -0
  153. package/templates/worktrees.json +26 -0
  154. package/workflows/agy-instructions.md +156 -0
  155. package/workflows/analyze.md +768 -0
  156. package/workflows/auto-test.md +705 -0
  157. package/workflows/blueprint.md +406 -0
  158. package/workflows/boundary-grill.md +50 -0
  159. package/workflows/brainstorm.md +508 -0
  160. package/workflows/business-test.md +574 -0
  161. package/workflows/chinese-response.md +25 -0
  162. package/workflows/claude-instructions.md +167 -0
  163. package/workflows/codebase-rebuild.md +267 -0
  164. package/workflows/codebase-refresh.md +168 -0
  165. package/workflows/codex-instructions.md +156 -0
  166. package/workflows/coding-philosophy.md +70 -0
  167. package/workflows/command-authoring.md +823 -0
  168. package/workflows/debug.md +409 -0
  169. package/workflows/delegate-usage.md +99 -0
  170. package/workflows/domain-add.md +121 -0
  171. package/workflows/drift-realign.md +396 -0
  172. package/workflows/execute.md +631 -0
  173. package/workflows/explore-usage.md +93 -0
  174. package/workflows/finish-work.md +124 -0
  175. package/workflows/fork.md +162 -0
  176. package/workflows/grill.md +494 -0
  177. package/workflows/harvest.md +478 -0
  178. package/workflows/impeccable.md +168 -0
  179. package/workflows/init.md +157 -0
  180. package/workflows/instruction-authoring-guide.md +97 -0
  181. package/workflows/integration-test.md +186 -0
  182. package/workflows/interview-mechanics.md +8 -0
  183. package/workflows/issue-analyze.md +20 -0
  184. package/workflows/issue-discover.md +238 -0
  185. package/workflows/issue-execute.md +110 -0
  186. package/workflows/issue-gaps-analyze.codex.md +256 -0
  187. package/workflows/issue-gaps-analyze.md +215 -0
  188. package/workflows/issue-plan.md +110 -0
  189. package/workflows/issue.md +338 -0
  190. package/workflows/knowhow.md +429 -0
  191. package/workflows/knowledge-audit.md +355 -0
  192. package/workflows/learn.md +271 -0
  193. package/workflows/maestro-chain-execute.md +20 -0
  194. package/workflows/maestro-link-coordinate.md +114 -0
  195. package/workflows/maestro-super.md +120 -0
  196. package/workflows/maestro.md +501 -0
  197. package/workflows/map.md +74 -0
  198. package/workflows/merge.md +122 -0
  199. package/workflows/milestone-audit.md +155 -0
  200. package/workflows/milestone-complete.md +167 -0
  201. package/workflows/milestone-release.md +82 -0
  202. package/workflows/odyssey-base-codex.md +305 -0
  203. package/workflows/odyssey-base.md +256 -0
  204. package/workflows/overlays.md +109 -0
  205. package/workflows/plan.md +520 -0
  206. package/workflows/quick.md +350 -0
  207. package/workflows/ralph-amend-goal.md +177 -0
  208. package/workflows/refactor.md +87 -0
  209. package/workflows/retrospective.md +471 -0
  210. package/workflows/review.md +448 -0
  211. package/workflows/roadmap-common.md +193 -0
  212. package/workflows/roadmap.md +106 -0
  213. package/workflows/shell-exec-protocol.md +30 -0
  214. package/workflows/skill-authoring.md +265 -0
  215. package/workflows/spec-generate.md +475 -0
  216. package/workflows/specs-add.md +123 -0
  217. package/workflows/specs-load.md +76 -0
  218. package/workflows/specs-remove.md +104 -0
  219. package/workflows/specs-setup.md +316 -0
  220. package/workflows/status.md +149 -0
  221. package/workflows/sync.md +116 -0
  222. package/workflows/tdd.md +255 -0
  223. package/workflows/test-gen.md +226 -0
  224. package/workflows/test.md +385 -0
  225. package/workflows/tools-spec.md +70 -0
  226. package/workflows/ui-codify-extract.md +372 -0
  227. package/workflows/ui-codify-knowhow.md +258 -0
  228. package/workflows/ui-codify-package.md +159 -0
  229. package/workflows/ui-codify.md +227 -0
  230. package/workflows/ui-design.md +393 -0
  231. package/workflows/ui-style.md +201 -0
  232. package/workflows/verify.md +557 -0
  233. package/workflows/wiki-connect.md +153 -0
  234. package/workflows/wiki-digest.md +180 -0
  235. package/workflows/wiki-manage.md +113 -0
@@ -0,0 +1,501 @@
1
+ # Workflow: maestro
2
+
3
+ Intelligent coordinator that routes user intent to optimal command chain based on project state.
4
+ Builds a `ralph_protocol_version: "2"` session: every executable step carries `skill,args,stage,scope,command_scope,command_path`; every cross-step gate is a `step.decision` node. All execution dispatched to unified executor (`maestro-ralph-execute`); the command body (`.claude/commands/maestro.md`) owns session build + dispatch. `--exec` is legacy input only — recorded to `legacy_options.exec_mode`, never changes execution. This brain is consumed for **classification only** (intent → task_type → chain); it does NOT prescribe execution semantics.
5
+
6
+ **Prerequisites:**
7
+ - None for initial invocation (can bootstrap)
8
+ - `continue`/`next`: `.workflow/state.json` must exist
9
+ - `-c` (resume): handled by command file before this workflow loads — not applicable here
10
+
11
+ ## Step 1: Parse & Initialize
12
+
13
+ ### 1a: Parse arguments
14
+
15
+ ```
16
+ Parse $ARGUMENTS → extract flags, remainder is intent text.
17
+ Flags: autoYes (-y/--yes), dryRun (--dry-run)
18
+ Valued: execMode (--exec auto|cli|internal, default 'auto'), cliTool (--tool X, default 'claude')
19
+ intent = arguments with all flags/valued options stripped, trimmed
20
+ ```
21
+
22
+ ### 1b: Read project state
23
+
24
+ Check `.workflow/state.json` existence.
25
+
26
+ **If exists:** Read state.json + roadmap.md. Derive progress by grouping artifacts by phase, determining furthest artifact type per phase (analyze→plan→execute), and identifying pending plans. Build `$PROJECT_STATE`:
27
+ ```json
28
+ {
29
+ "initialized": true,
30
+ "current_milestone": "M1",
31
+ "milestone_name": "MVP Auth",
32
+ "milestone_progress": {
33
+ "phases_total": 3,
34
+ "phases_with_execute": 1,
35
+ "phases_with_plan": 2,
36
+ "adhoc_count": 0
37
+ },
38
+ "latest_artifact": { "id": "PLN-002", "type": "plan", "phase": 2 },
39
+ "pending_actions": ["execute phase 2", "analyze phase 3"],
40
+ "has_blockers": false,
41
+ "suggested_next": null
42
+ }
43
+ ```
44
+
45
+ **If missing:** `$PROJECT_STATE = { initialized: false }`. If intent also empty → **Error E001** (suggest `maestro-init`).
46
+
47
+ ### 1c: Display banner
48
+
49
+ ```
50
+ ============================================================
51
+ MAESTRO COORDINATOR
52
+ ============================================================
53
+ Mode: {intent-based | state-based}
54
+ Auto: {yes | no}
55
+ Exec: {auto | cli | internal}
56
+ Input: {intent or "continue"}
57
+ ```
58
+
59
+ ## Step 2: Analyze Intent
60
+
61
+ ### 2a: Fast path — forced chain or exact match
62
+
63
+ **Exact-match keywords:**
64
+ ```
65
+ Keyword → taskType (skip to Step 3):
66
+ continue/next/go/继续/下一步 → 'state_continue'
67
+
68
+ Short-circuit (execute immediately, no chain):
69
+ status/状态/dashboard → Skill({ skill: "manage-status" }). **End.**
70
+ ```
71
+
72
+ ### 2b: Semantic intent matching
73
+
74
+ Directly match user intent to the best `task_type` (maps to chain in chainMap). Use LLM semantic understanding — no rigid keyword lookup.
75
+
76
+ **Output:**
77
+ ```json
78
+ {
79
+ "task_type": "<from chain catalog below>",
80
+ "scope": "<module/file/area or null>",
81
+ "issue_id": "<ISS-XXXXXXXX-NNN if mentioned, else null>",
82
+ "phase_ref": "<integer if mentioned, else null>",
83
+ "urgency": "<low | normal | high>"
84
+ }
85
+ ```
86
+
87
+ **Chain catalog — select by best semantic fit:**
88
+
89
+ | task_type | When user intent is about... |
90
+ |-----------|---------------------------|
91
+ | `quick` | Simple/small task, add a feature, quick change |
92
+ | `plan` | Plan, design, architect a phase |
93
+ | `execute` | Implement, develop, code a phase (includes built-in verification gate) |
94
+ | `analyze` | Understand, investigate, evaluate code |
95
+ | `review` | Code quality review |
96
+ | `test` | Run or create tests, UAT |
97
+ | `test_gen` | Generate tests for coverage gaps |
98
+ | `debug` | Diagnose, troubleshoot, fix broken behavior |
99
+ | `refactor` | Restructure, clean up, reduce tech debt |
100
+ | `init` | Initialize project |
101
+ | `sync` | Update/sync documentation |
102
+ | `retrospective` | Phase review, post-mortem, 复盘 |
103
+ | `learn` | Capture insights, record learnings |
104
+ | `release` | Publish, ship, tag version |
105
+ | `fork` | Create worktree for parallel dev |
106
+ | `merge` | Merge worktree back |
107
+ | `amend` | Revise workflow commands |
108
+ | `compose` | Design/compose reusable workflows |
109
+ | `overlay` | Create/edit command overlays |
110
+ | `update` | Update maestro itself |
111
+ | `harvest` | Extract knowledge from artifacts |
112
+ | `domain_add` | Register a domain term into glossary |
113
+ | `domain_list` | List registered domain terms |
114
+ | `domain_discover` | Discover domain term candidates from codebase |
115
+ | `wiki` | Manage wiki graph |
116
+ | `knowhow` | Manage knowhow entries |
117
+ | `impeccable_chain` | UI design — explore, general |
118
+ | `impeccable_build` | Build new UI from scratch |
119
+ | `impeccable_improve` | Improve/fix existing UI |
120
+ | `issue` | Issue CRUD — create, list, close, query |
121
+ | `issue_discover` | Discover/find issues in codebase |
122
+ | `issue_analyze` | Analyze a specific issue |
123
+ | `issue_plan` | Plan fix for an issue |
124
+ | `issue_execute` | Fix issue end-to-end (auto-upgrades to issue-full) |
125
+ | `team_coordinate` | Team multi-agent coordination (general) |
126
+ | `team_review` | Team code review |
127
+ | `team_test` | Team testing |
128
+ | `team_qa` | Team QA, debugging |
129
+ | `team_tech_debt` | Team tech debt remediation |
130
+ | `team_lifecycle` | Team full lifecycle (plan+dev+test+review) |
131
+ | `full-lifecycle` | Complete phase: plan→execute→review→test→audit |
132
+ | `grill` | Stress-test a plan/idea against codebase reality (Socratic; `-y` → Auto mode code-answers, stage NOT skipped) |
133
+ | `blueprint` | Formal spec package — 7-phase spec-generate |
134
+ | `analyze-macro` | Broad/medium intent, no numeric phase — produces scope_verdict for ralph `post-analyze-scope` |
135
+ | `brainstorm-driven` | Start from exploration/brainstorm |
136
+ | `spec-driven` | From spec/requirements (heavy, with init) |
137
+ | `roadmap-driven` | From requirements (light, with init) |
138
+ | `analyze-plan-execute` | Fast track: analyze→plan→execute |
139
+ | `review-fix` | Fix review-blocked issues |
140
+ | `quality-loop` | Full quality improvement cycle |
141
+ | `quality-loop-partial` | Partial quality fix |
142
+ | `milestone-close` | Close/transition milestone |
143
+ | `milestone-release` | Release milestone with version tag |
144
+ | `next-milestone` | Advance to next milestone |
145
+ | `state_continue` | Continue from current project state |
146
+
147
+ **Selection priorities:**
148
+ 1. `issue_id` present → prefer issue chains
149
+ 2. "team" context → prefer team chains
150
+ 3. UI/design/界面/页面/原型 → prefer impeccable chains
151
+ 4. Multiple lifecycle steps implied → prefer multi-step chains
152
+ 5. Single specific action → prefer single-step chains
153
+ 6. "问题" describing broken behavior → `debug`; tracked item with ISS-ID → `issue`; ambiguous → `debug`
154
+ 7. Simple task, no lifecycle context → `quick`
155
+ 8. Global fallback → `quick`
156
+
157
+ ### 2c: Chain upgrade & clarity
158
+
159
+ **State-aware chain upgrade:**
160
+ - `issue_execute` → auto-upgrade to `issue-full` (appends review gate)
161
+ - `debug` during `executing` phase → keep single-step (state validation handles prepend/append)
162
+
163
+ **Clarity score** (from extracted intent tuple): 3 = action+object+scope, 2 = action+object, 1 = action only, 0 = neither
164
+
165
+ Display intent analysis: action, object, scope, issue_id, phase_ref, task_type, clarity score.
166
+
167
+ **Clarification** (skip if `autoYes` or clarity >= 2, max 2 rounds):
168
+ - 0 → offer: "Start new project" / "Continue working" / "Quick task" / "Check status" / "Rephrase"
169
+ - 1 → confirm inferred action with alternatives
170
+ - Still unclear after 2 rounds → **Error E002**
171
+
172
+ ## Step 3: Select Chain & Prepare
173
+
174
+ ### 3a: Map task_type → chain
175
+
176
+ **Resolution order:**
177
+ 1. `state_continue` → `detectNextAction(projectState)` → `{ chain, argsOverride? }`. Apply argsOverride before template substitution.
178
+ 2. Task-type aliases → named chain: `spec_generate`→`spec-driven`, `brainstorm`→`brainstorm-driven`, `grill`→`grill-driven`, `blueprint`→`blueprint-driven`, `analyze_macro`→`analyze-plan-execute`, `issue_execute`→`issue-full`
179
+ 3. `chainMap[taskType]` → direct lookup
180
+
181
+ Full `chainMap` and `detectNextAction` are in the [Reference Data](#reference-data) section.
182
+
183
+ ### 3b: Validate against state (W003)
184
+
185
+ Cross-validate intent against project state:
186
+ - `execute` but no plan → warn, prepend `maestro-plan`
187
+ - `test` but not executed → warn, prepend `maestro-execute`
188
+ - `milestone_close` but not all phases executed → warn, suggest completing first
189
+
190
+ Display warning but let user override.
191
+
192
+ ### 3c: Resolve phase number and issue ID
193
+
194
+ ```
195
+ resolvePhase — priority order:
196
+ 1. intent_analysis.phase_ref (from structured extraction)
197
+ 2. Regex match "phase N" or bare number from raw intent
198
+ 3. From project state artifacts: in-progress execute → first incomplete phase → latest artifact phase
199
+ 4. null if chain is 'analyze-plan-execute' (uses {scratch_dir} instead)
200
+ 5. null if all chain commands are phase-independent:
201
+ manage-status, manage-issue, manage-issue-discover, maestro-init,
202
+ maestro-fork, maestro-merge, maestro-roadmap, spec-setup, manage-knowhow, manage-knowhow-capture,
203
+ manage-learn, manage-codebase-rebuild, manage-codebase-refresh, maestro-milestone-audit,
204
+ maestro-milestone-complete
205
+ 6. Ask user
206
+
207
+ resolveIssueId — priority: intent_analysis.issue_id → regex match ISS-*-NNN from raw intent → null
208
+ ```
209
+
210
+ When executing issue chains, replace `{issue_id}` in step args with resolved ID. If missing and required, prompt user.
211
+
212
+ ### 3d: Confirm chain
213
+
214
+ **If `dryRun`:** Display chain visualization and exit.
215
+ **If not `autoYes`:** Confirm with user — show numbered steps, offer: Execute / Execute from step N / Cancel.
216
+ If user chooses "Execute from step N": set `$START_STEP = N` (used in 3f to set `current_step`).
217
+
218
+ ### 3e: Step-level command resolution (v1)
219
+
220
+ > **Superseded by `ralph_protocol_version: "2"`.** The command body resolves `command_scope`/`command_path` per execution step via `maestro ralph skills --platform claude --json --quiet`; cross-step gates carry `step.decision`. Do NOT write a per-step `type` field (legacy skill/cli). `--exec` is recorded to `legacy_options.exec_mode` only — it never changes execution. FSM owns step ordering + decision evaluation (control-plane precedence, see command-body invariant 15).
221
+
222
+ ```
223
+ If execMode is 'cli' or 'internal' → force that type for all steps ("cli" or "skill").
224
+ In 'auto' mode, select per step:
225
+ CLI steps (heavy, context-isolated): maestro-plan, maestro-execute, maestro-analyze, maestro-brainstorm, maestro-roadmap, maestro-impeccable, quality-refactor → type: "cli"
226
+ Skill steps (everything else): current-session Skill() call — review, test, debug, milestone-*, manage-*, spec-*, quick, etc. → type: "skill"
227
+ ```
228
+
229
+ **Trade-off:** CLI = context isolation + template prompts. Skill = current-session Skill() call, direct visibility + synchronous + user can intervene.
230
+
231
+ ### 3f: Low-complexity fast path (before session creation)
232
+
233
+ If ALL conditions met:
234
+ - clarity >= 2
235
+ - task_type == `'quick'` or (action == `'create'` && object == `'feature'`)
236
+ - NOT `state_continue`
237
+
238
+ Then: `Skill({ skill: "maestro-quick", args: '"{description}"' })`. **End.** (no session created, no status.json)
239
+
240
+ ### 3g: Setup session
241
+
242
+ Create session directory `.workflow/.maestro/maestro-{YYYYMMDD-HHMMSS}/` and write `status.json`:
243
+ ```json
244
+ {
245
+ "session_id": "{SESSION_ID}",
246
+ "created_at": "{ISO timestamp}",
247
+ "intent": "{original_intent}",
248
+ "task_type": "{task_type}",
249
+ "chain_name": "{chain_name}",
250
+ "phase": "{resolved_phase}",
251
+ "auto_mode": "{autoYes}",
252
+ "exec_mode": "{execMode}",
253
+ "cli_tool": "{cliTool}",
254
+ "context": {
255
+ "issue_id": "{resolved_issue_id or null}",
256
+ "milestone_num": "{current_milestone_num or null}",
257
+ "spec_session_id": null,
258
+ "scratch_dir": null,
259
+ "plan_dir": null,
260
+ "analysis_dir": null,
261
+ "brainstorm_dir": null
262
+ },
263
+ "source": "maestro",
264
+ "updated_at": "{ISO timestamp}",
265
+ "milestone": null,
266
+ "lifecycle_position": null,
267
+ "target": null,
268
+ "waves": [],
269
+ "steps": [{ "index": 0, "skill": "{chainMap[].cmd}", "args": "{chainMap[].args}", "type": "{cli|skill from 3e}", "status": "pending", "started_at": null, "completed_at": null, "error": null }],
270
+ "current_step": "{$START_STEP or 0}",
271
+ "status": "running"
272
+ }
273
+ ```
274
+
275
+ ### 3h: Initialize TodoWrite tracking
276
+
277
+ Create TodoWrite entries with `MAESTRO:{chain_name}:` prefix for UI-visible progress tracking. TodoWrite and status.json form dual-track system — TodoWrite for user visibility, status.json for persistence and resume.
278
+
279
+ ```javascript
280
+ const todos = steps.map((step, i) => ({
281
+ content: `MAESTRO:${chain_name}: [${i + 1}/${steps.length}] ${step.skill}`,
282
+ status: i === 0 ? 'in_progress' : 'pending'
283
+ }));
284
+ TodoWrite({ todos });
285
+ ```
286
+
287
+ ## Step 4: Dispatch to unified executor
288
+
289
+ status.json already created in Step 3g, TodoWrite initialized in Step 3h.
290
+
291
+ ```
292
+ Skill({ skill: "maestro-ralph-execute" })
293
+ ```
294
+
295
+ The unified executor discovers the latest running session from `.workflow/.maestro/*/status.json` and executes steps in order. maestro sessions (source: "maestro") are `ralph_protocol_version: "2"`: execution steps load via `maestro ralph next`; any `step.decision` node hands off to `Skill("maestro-ralph")` for evaluation (same mechanism as ralph sessions). Decision nodes ARE supported in maestro sessions.
296
+
297
+ ---
298
+
299
+ ## Reference Data
300
+
301
+ ### Chain Map
302
+
303
+ ```javascript
304
+ const chainMap = {
305
+ // ── Single-step ──
306
+ 'status': [{ cmd: 'manage-status' }],
307
+ 'init': [{ cmd: 'maestro-init' }],
308
+ 'grill': [{ cmd: 'maestro-grill', args: '"{description}"' }],
309
+ 'blueprint': [{ cmd: 'maestro-blueprint', args: '"{description}"' }],
310
+ 'analyze-macro': [{ cmd: 'maestro-analyze', args: '"{description}"' }],
311
+ 'analyze': [{ cmd: 'maestro-analyze', args: '{phase}' }],
312
+ 'analyze-quick': [{ cmd: 'maestro-analyze', args: '{phase} -q' }],
313
+ 'ui_design': [{ cmd: 'maestro-impeccable', args: '"{description}" --chain build' }],
314
+ 'impeccable_chain': [{ cmd: 'maestro-impeccable', args: '"{description}"' }],
315
+ 'impeccable_build': [{ cmd: 'maestro-impeccable', args: '"{description}" --chain build' }],
316
+ 'impeccable_improve': [{ cmd: 'maestro-impeccable', args: '"{description}" --chain improve' }],
317
+ 'plan': [{ cmd: 'maestro-plan', args: '{phase}' }],
318
+ 'execute': [{ cmd: 'maestro-execute', args: '{phase}' }],
319
+ 'test_gen': [{ cmd: 'quality-auto-test', args: '{phase}' }],
320
+ 'auto_test': [{ cmd: 'quality-auto-test', args: '{phase}' }],
321
+ 'test': [{ cmd: 'quality-test', args: '{phase}' }],
322
+ 'debug': [{ cmd: 'quality-debug', args: '"{description}"' }],
323
+ 'integration_test': [{ cmd: 'quality-auto-test', args: '{phase}' }],
324
+ 'refactor': [{ cmd: 'quality-refactor', args: '"{description}"' }],
325
+ 'review': [{ cmd: 'quality-review', args: '{phase}' }],
326
+ 'retrospective': [{ cmd: 'quality-retrospective', args: '{phase}' }],
327
+ 'learn': [{ cmd: 'manage-learn', args: '"{description}"' }],
328
+ 'sync': [{ cmd: 'quality-sync' }],
329
+ 'milestone_close': [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }],
330
+ 'milestone_audit': [{ cmd: 'maestro-milestone-audit' }],
331
+ 'milestone_complete': [{ cmd: 'maestro-milestone-complete' }],
332
+ 'codebase_rebuild': [{ cmd: 'manage-codebase-rebuild' }],
333
+ 'codebase_refresh': [{ cmd: 'manage-codebase-refresh' }],
334
+ 'spec_setup': [{ cmd: 'spec-setup' }],
335
+ 'spec_add': [{ cmd: 'spec-add', args: '"{description}"' }],
336
+ 'spec_load': [{ cmd: 'spec-load' }],
337
+ 'spec_map': [{ cmd: 'manage-codebase-rebuild' }],
338
+ 'domain_add': [{ cmd: 'domain-add', args: '"{description}"' }],
339
+ 'domain_list': [{ cmd: 'domain-list' }],
340
+ 'domain_discover': [{ cmd: 'domain-discover' }],
341
+ 'knowhow_capture': [{ cmd: 'manage-knowhow-capture', args: '"{description}"' }],
342
+ 'issue': [{ cmd: 'manage-issue', args: '"{description}"' }],
343
+ 'issue_discover': [{ cmd: 'manage-issue-discover', args: '"{description}"' }],
344
+ 'issue_analyze': [{ cmd: 'maestro-analyze', args: '--gaps "{description}"' }],
345
+ 'issue_plan': [{ cmd: 'maestro-plan', args: '--gaps' }],
346
+ 'issue_execute': [{ cmd: 'maestro-execute', args: '' }],
347
+ 'knowhow': [{ cmd: 'manage-knowhow', args: '"{description}"' }],
348
+ 'quick': [{ cmd: 'maestro-quick', args: '"{description}"' }],
349
+ 'fork': [{ cmd: 'maestro-fork', args: '-m {milestone_num}' }],
350
+ 'merge': [{ cmd: 'maestro-merge', args: '-m {milestone_num}' }],
351
+
352
+ // ── Team skills ──
353
+ 'team_lifecycle': [{ cmd: 'team-lifecycle-v4', args: '"{description}"' }],
354
+ 'team_coordinate': [{ cmd: 'team-coordinate', args: '"{description}"' }],
355
+ 'team_design': [{ cmd: 'team-coordinate', args: '"{description}"' }],
356
+ 'team_execute': [{ cmd: 'team-executor', args: '"{description}"' }],
357
+ 'team_qa': [{ cmd: 'team-quality-assurance', args: '"{description}"' }],
358
+ 'team_test': [{ cmd: 'team-testing', args: '"{description}"' }],
359
+ 'team_review': [{ cmd: 'team-review', args: '"{description}"' }],
360
+ 'team_tech_debt': [{ cmd: 'team-tech-debt', args: '"{description}"' }],
361
+
362
+ // ── Multi-step chains ──
363
+ 'full-lifecycle': [{ cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'quality-review', args: '{phase}' }, { cmd: 'quality-test', args: '{phase}' }, { cmd: 'maestro-milestone-audit' }, { cmd: 'manage-harvest', args: '--auto' }],
364
+ 'spec-driven': [{ cmd: 'maestro-init' }, { cmd: 'maestro-roadmap', args: '--mode full "{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'manage-harvest', args: '--auto' }],
365
+ 'roadmap-driven': [{ cmd: 'maestro-init' }, { cmd: 'maestro-roadmap', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'manage-harvest', args: '--auto' }],
366
+ 'grill-driven': [{ cmd: 'maestro-grill', args: '"{description}"' }, { cmd: 'maestro-brainstorm', args: '"{description}" --from grill:{grill_id}' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'manage-harvest', args: '--auto' }],
367
+ 'blueprint-driven': [{ cmd: 'maestro-init' }, { cmd: 'maestro-blueprint', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'manage-harvest', args: '--auto' }],
368
+ 'brainstorm-driven': [{ cmd: 'maestro-brainstorm', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'manage-harvest', args: '--auto' }],
369
+ 'brainstorm_visualize': [{ cmd: 'brainstorm-visualize', args: '"{description}"' }],
370
+ 'impeccable-build': [{ cmd: 'maestro-impeccable', args: '"{description}" --chain build' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }],
371
+ 'impeccable-driven': [{ cmd: 'maestro-impeccable', args: '"{description}" --chain build' }, { cmd: 'maestro-execute', args: '{phase}' }],
372
+ 'analyze-plan-execute': [{ cmd: 'maestro-analyze', args: '"{description}" -q' }, { cmd: 'maestro-plan', args: '--dir {scratch_dir}' }, { cmd: 'maestro-execute', args: '--dir {scratch_dir}' }, { cmd: 'manage-harvest', args: '--auto' }],
373
+ 'quality-loop': [{ cmd: 'quality-review', args: '{phase}' }, { cmd: 'quality-auto-test', args: '{phase}' }, { cmd: 'quality-test', args: '{phase}' }, { cmd: 'quality-debug', args: '--from-uat {phase}' }, { cmd: 'maestro-plan', args: '{phase} --gaps' }, { cmd: 'maestro-execute', args: '{phase}' }],
374
+ 'milestone-close': [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }],
375
+ 'next-milestone': [{ cmd: 'maestro-roadmap', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }],
376
+ 'review-fix': [{ cmd: 'maestro-plan', args: '{phase} --gaps' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'quality-review', args: '{phase}' }],
377
+ 'quality-loop-partial': [{ cmd: 'maestro-plan', args: '{phase} --gaps' }, { cmd: 'maestro-execute', args: '{phase}' }],
378
+ 'issue-full': [{ cmd: 'maestro-analyze', args: '--gaps {issue_id}' }, { cmd: 'maestro-plan', args: '--gaps' }, { cmd: 'maestro-execute', args: '' }, { cmd: 'quality-review', args: '{phase}' }, { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }, { cmd: 'manage-harvest', args: '--auto' }],
379
+ 'issue-quick': [{ cmd: 'maestro-plan', args: '--gaps' }, { cmd: 'maestro-execute', args: '' }, { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }],
380
+ 'milestone-release': [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-release' }],
381
+
382
+ 'learn': [{ cmd: 'maestro-learn', args: '"{description}"' }],
383
+ 'harvest': [{ cmd: 'manage-harvest', args: '"{description}"' }],
384
+ 'wiki': [{ cmd: 'manage-wiki' }],
385
+ 'wiki_connect': [{ cmd: 'wiki-connect' }],
386
+ 'wiki_digest': [{ cmd: 'wiki-digest' }],
387
+ 'business_test': [{ cmd: 'quality-auto-test', args: '{phase}' }],
388
+ 'spec_remove': [{ cmd: 'spec-remove', args: '"{description}"' }],
389
+ 'amend': [{ cmd: 'maestro-amend', args: '"{description}"' }],
390
+ 'release': [{ cmd: 'maestro-milestone-release' }],
391
+ 'compose': [{ cmd: 'maestro-composer', args: '"{description}"' }],
392
+ 'play': [{ cmd: 'maestro-player', args: '"{description}"' }],
393
+ 'update': [{ cmd: 'maestro-update' }],
394
+ 'overlay': [{ cmd: 'maestro-overlay', args: '"{description}"' }],
395
+ 'link_coordinate': [{ cmd: 'maestro-link-coordinate', args: '"{description}"' }],
396
+ };
397
+ ```
398
+
399
+ ### State Detection (detectNextAction)
400
+
401
+ Used when `task_type == state_continue`. Routes based on `phase_status` and artifact presence:
402
+
403
+ ```
404
+ Returns { chain, argsOverride? }. Steps resolved from chainMap[chain].
405
+
406
+ detectNextAction(state):
407
+ not initialized → 'init'
408
+
409
+ phases_total == 0:
410
+ no roadmap + has accumulated_context → 'next-milestone' with argsOverride containing deferred items and key decisions
411
+ otherwise → 'brainstorm-driven'
412
+
413
+ Route by phase_status (ps):
414
+ pending: has context artifact → 'plan'; has analysis → 'analyze-quick'; else → 'analyze'
415
+ exploring/planning: has plan → 'execute'; else → 'plan'
416
+ executing: all tasks done → 'review'; has blockers → 'debug'; else → 'execute'
417
+ exec completed (verification is built-in):
418
+ no review → 'review'
419
+ review BLOCK → 'review-fix'
420
+ uat pending → 'test'; uat passed → 'milestone-close'; uat failed → 'debug'
421
+ default → 'test'
422
+ testing: uat passed → 'milestone-close'; else → 'debug'
423
+ completed: → 'milestone-close'
424
+ forked: worktrees.json exists → 'merge'; else → 'status'
425
+ blocked: → 'debug'
426
+ default: → 'status'
427
+ ```
428
+
429
+ ### Chain Reference
430
+
431
+ | Chain | Steps | Use Case |
432
+ |-------|-------|----------|
433
+ | `full-lifecycle` | plan → execute → review → test → audit → harvest | Full milestone completion |
434
+ | `blueprint-driven` | init → blueprint → plan → execute → harvest | From idea/requirements (heavy) |
435
+ | `roadmap-driven` | init → roadmap → plan → execute → harvest | From requirements (light) |
436
+ | `brainstorm-driven` | brainstorm → plan → execute → harvest | From exploration |
437
+ | `impeccable-build` | impeccable --chain build → plan → execute | From design system generation |
438
+ | `analyze-plan-execute` | analyze -q → plan --dir → execute --dir → harvest | Fast track (scratch mode) |
439
+ | `review-fix` | plan --gaps → execute → review | Fix review-blocked issues |
440
+ | `quality-loop` | review → test-gen → test → debug → plan --gaps → execute | Fix quality issues |
441
+ | `quality-loop-partial` | plan --gaps → execute | Partial quality fix cycle |
442
+ | `milestone-close` | audit → complete | Close a milestone |
443
+ | `milestone-release` | audit → release | Release with version tag |
444
+ | `next-milestone` | roadmap → plan → execute | Next milestone (auto-loads deferred) |
445
+ | `issue-full` | analyze → plan → execute → review → close → harvest | Issue with quality gate |
446
+ | `issue-quick` | plan → execute → close | Issue fast path |
447
+
448
+ ### Pipeline Examples
449
+
450
+ | Input | task_type | Chain |
451
+ |-------|-----------|-------|
452
+ | `"continue"` | *(2a exact)* state_continue | (from state) |
453
+ | `"status"` | *(2a exact)* status | manage-status |
454
+ | `"plan phase 2"` | plan | maestro-plan 2 |
455
+ | `"execute"` | execute | maestro-execute |
456
+ | `"Add API endpoint"` | quick | maestro-quick |
457
+ | `"run tests"` | test | quality-test |
458
+ | `"debug auth crash"` | debug | quality-debug "auth crash" |
459
+ | `"修复登录问题"` | debug | quality-debug "登录" |
460
+ | `"fix issue ISS-abc-001"` | issue_execute | issue-full |
461
+ | `"这个问题需要看看"` | analyze | maestro-analyze |
462
+ | `"创建一个 issue 跟踪"` | issue | manage-issue |
463
+ | `"discover issues"` | issue_discover | manage-issue-discover |
464
+ | `"brainstorm notifications"` | brainstorm-driven | brainstorm→plan→execute |
465
+ | `"spec generate auth"` | spec-driven | init→spec→plan→execute |
466
+ | `"ui design landing"` | impeccable_build | maestro-impeccable --chain build |
467
+ | `"优化界面交互"` | impeccable_improve | maestro-impeccable --chain improve |
468
+ | `"refactor auth module"` | refactor | quality-refactor "auth module" |
469
+ | `"复盘 phase 2"` | retrospective | quality-retrospective 2 |
470
+ | `"team review code"` | team_review | team-review |
471
+ | `"next phase"` | milestone-close | audit→complete |
472
+ | `-y "implement X"` | execute | maestro-execute (auto) |
473
+ | `"release v1.2"` | release | maestro-milestone-release |
474
+ | `"从需求开始做完整个项目"` | spec-driven | init→spec→plan→execute |
475
+ | `"分析完直接改"` | analyze-plan-execute | analyze→plan→execute |
476
+ | `"review 有问题需要修"` | review-fix | plan --gaps→execute→review |
477
+ | `"全面质量检查"` | quality-loop | review→test→debug→plan→execute |
478
+
479
+ ### Error Codes
480
+
481
+ | Code | Description | Recovery |
482
+ |------|-------------|----------|
483
+ | E001 | No intent + project not initialized | Suggest maestro-init |
484
+ | E002 | Clarity too low after 2 rounds | Ask to rephrase |
485
+ | E003 | Chain step failed + abort | Suggest resume with -c |
486
+ | E004 | Resume session not found | Show available sessions |
487
+ | W001 | Ambiguous intent, multiple chains | Present options |
488
+ | W002 | Step completed with warnings | Log and continue |
489
+ | W003 | State suggests different chain | Show discrepancy, let user decide |
490
+
491
+ ### Design Principles
492
+
493
+ 1. **Semantic Routing** — LLM-native `action × object` extraction; disambiguates "问题" by context
494
+ 2. **State-Aware** — Reads `.workflow/state.json` before routing
495
+ 3. **Quality Gates** — Issue chains auto-include review; `issue-full` is default for issue execution
496
+ 4. **Per-Step Type** — Each step independently typed as `"skill"` or `"cli"`. Heavy steps (plan, execute, analyze, brainstorm) → CLI for context isolation. Observable steps (review, test, debug, manage-*) → Skill (current-session) for direct visibility. `--exec cli|internal` forces all steps.
497
+ 5. **Unified Executor** — All execution dispatched to `maestro-ralph-execute`, which handles both maestro (static chain) and ralph (adaptive chain with decision nodes) sessions.
498
+ 6. **Phase Propagation** — Auto-detects and passes phase numbers to downstream commands
499
+ 7. **Auto Mode** — `-y` propagates through chain, skipping all confirmations
500
+ 8. **Resumable** — Session state in `.workflow/.maestro/` enables `-c` resume
501
+ 9. **Error Resilience** — Retry/skip/abort per step; auto-skip in `-y` mode
@@ -0,0 +1,74 @@
1
+ # Workflow: map
2
+
3
+ Codebase scanning with parallel mapper agents.
4
+
5
+ ---
6
+
7
+ ## Step 1: Pre-check
8
+
9
+ 1. Check if `.workflow/research/` already exists with documents:
10
+ - If documents exist and are recent (< 7 days):
11
+ - Ask user: "Codebase map exists. Refresh or skip?"
12
+ - "refresh" → continue to Step 2 (overwrite)
13
+ - "skip" → exit with route suggestions
14
+ - If documents are stale or missing → continue to Step 2
15
+
16
+ 2. Create `.workflow/research/` directory if it does not exist.
17
+
18
+ ---
19
+
20
+ ## Step 2: Spawn Parallel Mapper Agents
21
+
22
+ MANDATORY, NOT SUBSTITUTABLE by manual Read/Grep: Spawn 4 parallel `workflow-codebase-mapper` agents, each writing to `.workflow/research/`:
23
+
24
+ | Agent | Focus | Output | Content |
25
+ |-------|-------|--------|---------|
26
+ | 1 | tech | STACK.md | languages, frameworks, build tools, dependencies, versions |
27
+ | 2 | arch | ARCHITECTURE.md | architecture style, layers, module graph, key abstractions |
28
+ | 3 | features | FEATURES.md | feature inventory, feature-to-file mapping, completeness |
29
+ | 4 | concerns | PITFALLS.md | tech debt, missing tests, security gaps, performance issues |
30
+
31
+ If `$ARGUMENTS` provided, pass as focus filter to each agent.
32
+
33
+ Load project specs: `maestro spec load --category arch`
34
+
35
+ Each agent spawned in parallel as `workflow-codebase-mapper` subagent with specs context.
36
+
37
+ ---
38
+
39
+ ## Step 3: Verification
40
+
41
+ After all 4 agents complete:
42
+
43
+ 1. Verify all 4 documents exist with >10 lines each.
44
+ 2. If any missing/empty → log failure, re-spawn that agent (max 1 retry); after retry exhausted, flag SUMMARY as [LOW CONFIDENCE] (incomplete) and list missing docs.
45
+
46
+ ---
47
+
48
+ ## Step 4: Summary
49
+
50
+ 1. Create `.workflow/research/SUMMARY.md`:
51
+ - Read all 4 documents
52
+ - Write a consolidated executive summary covering:
53
+ - Tech stack overview (from STACK.md)
54
+ - Architecture highlights (from ARCHITECTURE.md)
55
+ - Feature inventory count (from FEATURES.md)
56
+ - Top 3 concerns (from PITFALLS.md)
57
+ - Recommendations for next steps
58
+
59
+ ---
60
+
61
+ ## Step 5: Commit and Route
62
+
63
+ 1. If git repo: commit `.workflow/research/` with message `"chore: map codebase"`
64
+
65
+ 2. Display summary:
66
+ ```
67
+ Codebase mapped successfully.
68
+ Documents: 5 files in .workflow/research/
69
+ ```
70
+
71
+ 3. Route next steps based on project state:
72
+ - No `.workflow/state.json` → "Run `/workflow:init` to initialize project"
73
+ - Has state, no roadmap → "Run `/workflow:init` to create roadmap"
74
+ - Has roadmap → "Run `/workflow:plan {next_phase}` to start planning"