maestro-flow-one 0.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 (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +173 -0
  3. package/bin/maestro-flow.js +730 -0
  4. package/claude/maestro-flow/SKILL.md +239 -0
  5. package/claude/maestro-flow/chains/templates.json +256 -0
  6. package/claude/maestro-flow/commands/learn/decompose.md +176 -0
  7. package/claude/maestro-flow/commands/learn/follow.md +167 -0
  8. package/claude/maestro-flow/commands/learn/investigate.md +221 -0
  9. package/claude/maestro-flow/commands/learn/retro.md +303 -0
  10. package/claude/maestro-flow/commands/learn/second-opinion.md +167 -0
  11. package/claude/maestro-flow/commands/lifecycle/amend.md +300 -0
  12. package/claude/maestro-flow/commands/lifecycle/analyze.md +126 -0
  13. package/claude/maestro-flow/commands/lifecycle/brainstorm.md +100 -0
  14. package/claude/maestro-flow/commands/lifecycle/composer.md +354 -0
  15. package/claude/maestro-flow/commands/lifecycle/execute.md +114 -0
  16. package/claude/maestro-flow/commands/lifecycle/fork.md +86 -0
  17. package/claude/maestro-flow/commands/lifecycle/init.md +78 -0
  18. package/claude/maestro-flow/commands/lifecycle/learn.md +140 -0
  19. package/claude/maestro-flow/commands/lifecycle/link-coordinate.md +71 -0
  20. package/claude/maestro-flow/commands/lifecycle/merge.md +61 -0
  21. package/claude/maestro-flow/commands/lifecycle/overlay.md +178 -0
  22. package/claude/maestro-flow/commands/lifecycle/plan.md +138 -0
  23. package/claude/maestro-flow/commands/lifecycle/player.md +404 -0
  24. package/claude/maestro-flow/commands/lifecycle/quick.md +56 -0
  25. package/claude/maestro-flow/commands/lifecycle/roadmap.md +164 -0
  26. package/claude/maestro-flow/commands/lifecycle/ui-design.md +93 -0
  27. package/claude/maestro-flow/commands/lifecycle/update.md +176 -0
  28. package/claude/maestro-flow/commands/lifecycle/verify.md +90 -0
  29. package/claude/maestro-flow/commands/manage/codebase-rebuild.md +75 -0
  30. package/claude/maestro-flow/commands/manage/codebase-refresh.md +57 -0
  31. package/claude/maestro-flow/commands/manage/harvest.md +94 -0
  32. package/claude/maestro-flow/commands/manage/issue-discover.md +77 -0
  33. package/claude/maestro-flow/commands/manage/issue.md +73 -0
  34. package/claude/maestro-flow/commands/manage/knowhow-capture.md +193 -0
  35. package/claude/maestro-flow/commands/manage/knowhow.md +77 -0
  36. package/claude/maestro-flow/commands/manage/learn.md +67 -0
  37. package/claude/maestro-flow/commands/manage/status.md +51 -0
  38. package/claude/maestro-flow/commands/manage/wiki.md +62 -0
  39. package/claude/maestro-flow/commands/milestone/audit.md +68 -0
  40. package/claude/maestro-flow/commands/milestone/complete.md +75 -0
  41. package/claude/maestro-flow/commands/milestone/release.md +96 -0
  42. package/claude/maestro-flow/commands/quality/auto-test.md +124 -0
  43. package/claude/maestro-flow/commands/quality/debug.md +115 -0
  44. package/claude/maestro-flow/commands/quality/refactor.md +55 -0
  45. package/claude/maestro-flow/commands/quality/retrospective.md +78 -0
  46. package/claude/maestro-flow/commands/quality/review.md +108 -0
  47. package/claude/maestro-flow/commands/quality/sync.md +51 -0
  48. package/claude/maestro-flow/commands/quality/test.md +103 -0
  49. package/claude/maestro-flow/commands/spec/add.md +49 -0
  50. package/claude/maestro-flow/commands/spec/load.md +51 -0
  51. package/claude/maestro-flow/commands/spec/remove.md +51 -0
  52. package/claude/maestro-flow/commands/spec/setup.md +51 -0
  53. package/claude/maestro-flow/commands/wiki/connect.md +62 -0
  54. package/claude/maestro-flow/commands/wiki/digest.md +69 -0
  55. package/codex/maestro-flow/SKILL.md +505 -0
  56. package/codex/maestro-flow/chains/templates.json +256 -0
  57. package/codex/maestro-flow/commands/learn/decompose.md +113 -0
  58. package/codex/maestro-flow/commands/learn/follow.md +83 -0
  59. package/codex/maestro-flow/commands/learn/investigate.md +83 -0
  60. package/codex/maestro-flow/commands/learn/retro.md +83 -0
  61. package/codex/maestro-flow/commands/learn/second-opinion.md +86 -0
  62. package/codex/maestro-flow/commands/lifecycle/amend.md +300 -0
  63. package/codex/maestro-flow/commands/lifecycle/analyze.md +483 -0
  64. package/codex/maestro-flow/commands/lifecycle/brainstorm.md +397 -0
  65. package/codex/maestro-flow/commands/lifecycle/composer.md +213 -0
  66. package/codex/maestro-flow/commands/lifecycle/execute.md +318 -0
  67. package/codex/maestro-flow/commands/lifecycle/fork.md +98 -0
  68. package/codex/maestro-flow/commands/lifecycle/init.md +134 -0
  69. package/codex/maestro-flow/commands/lifecycle/learn.md +80 -0
  70. package/codex/maestro-flow/commands/lifecycle/link-coordinate.md +257 -0
  71. package/codex/maestro-flow/commands/lifecycle/merge.md +69 -0
  72. package/codex/maestro-flow/commands/lifecycle/overlay.md +119 -0
  73. package/codex/maestro-flow/commands/lifecycle/plan.md +460 -0
  74. package/codex/maestro-flow/commands/lifecycle/player.md +323 -0
  75. package/codex/maestro-flow/commands/lifecycle/quick.md +124 -0
  76. package/codex/maestro-flow/commands/lifecycle/roadmap.md +468 -0
  77. package/codex/maestro-flow/commands/lifecycle/ui-design.md +135 -0
  78. package/codex/maestro-flow/commands/lifecycle/update.md +176 -0
  79. package/codex/maestro-flow/commands/lifecycle/verify.md +468 -0
  80. package/codex/maestro-flow/commands/manage/codebase-rebuild.md +347 -0
  81. package/codex/maestro-flow/commands/manage/codebase-refresh.md +66 -0
  82. package/codex/maestro-flow/commands/manage/harvest.md +91 -0
  83. package/codex/maestro-flow/commands/manage/issue-discover.md +431 -0
  84. package/codex/maestro-flow/commands/manage/issue.md +75 -0
  85. package/codex/maestro-flow/commands/manage/knowhow-capture.md +110 -0
  86. package/codex/maestro-flow/commands/manage/knowhow.md +95 -0
  87. package/codex/maestro-flow/commands/manage/learn.md +137 -0
  88. package/codex/maestro-flow/commands/manage/status.md +76 -0
  89. package/codex/maestro-flow/commands/manage/wiki.md +55 -0
  90. package/codex/maestro-flow/commands/milestone/audit.md +87 -0
  91. package/codex/maestro-flow/commands/milestone/complete.md +91 -0
  92. package/codex/maestro-flow/commands/milestone/release.md +70 -0
  93. package/codex/maestro-flow/commands/quality/auto-test.md +547 -0
  94. package/codex/maestro-flow/commands/quality/debug.md +334 -0
  95. package/codex/maestro-flow/commands/quality/refactor.md +151 -0
  96. package/codex/maestro-flow/commands/quality/retrospective.md +292 -0
  97. package/codex/maestro-flow/commands/quality/review.md +364 -0
  98. package/codex/maestro-flow/commands/quality/sync.md +111 -0
  99. package/codex/maestro-flow/commands/quality/test.md +498 -0
  100. package/codex/maestro-flow/commands/spec/add.md +101 -0
  101. package/codex/maestro-flow/commands/spec/load.md +77 -0
  102. package/codex/maestro-flow/commands/spec/remove.md +69 -0
  103. package/codex/maestro-flow/commands/spec/setup.md +75 -0
  104. package/codex/maestro-flow/commands/wiki/connect.md +73 -0
  105. package/codex/maestro-flow/commands/wiki/digest.md +87 -0
  106. package/package.json +24 -0
@@ -0,0 +1,460 @@
1
+ ---
2
+ name: maestro-plan
3
+ description: Exploration-driven planning via CSV wave pipeline. Wave 1 runs parallel codebase exploration agents, Wave 2 synthesizes explorations into plan.json + TASK-*.json. Replaces maestro-plan command.
4
+ argument-hint: "[-y|--yes] [-c|--concurrency N] [--continue] \"<phase> [--dir <path>] [--gaps] [--spec SPEC-xxx] [--collab]\""
5
+ allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
+ ---
7
+
8
+ <purpose>
9
+ Wave-based planning using `spawn_agents_on_csv`. Wave 1 explores codebase context in parallel across multiple angles, Wave 2 consumes all exploration findings to generate a verified execution plan.
10
+
11
+ **Core workflow**: Resolve Phase -> Determine Explorations -> Parallel Exploration -> Sequential Planning -> Check + Confirm
12
+
13
+ ```
14
+ +---------------------------------------------------------------------------+
15
+ | PLAN CSV WAVE WORKFLOW |
16
+ +---------------------------------------------------------------------------+
17
+ | |
18
+ | Phase 1: Phase Resolution -> CSV |
19
+ | +-- Resolve phase directory from arguments (or --dir) |
20
+ | +-- Load context.md, index.json, spec-ref, codebase docs |
21
+ | +-- Check for upstream analysis (conclusions.json) |
22
+ | +-- If --gaps: load gaps from issues/verification/uat |
23
+ | +-- Determine exploration angles (architecture, implementation, etc.) |
24
+ | +-- Generate tasks.csv with one row per exploration + planning row |
25
+ | +-- User validates exploration breakdown (skip if -y) |
26
+ | |
27
+ | Phase 2: Wave Execution Engine |
28
+ | +-- Wave 1: Codebase Exploration (parallel) |
29
+ | | +-- Each agent explores one angle of the codebase |
30
+ | | +-- Agent reads files, discovers patterns, maps dependencies |
31
+ | | +-- Discoveries shared via board (patterns, conventions, risks) |
32
+ | | +-- Results: findings per exploration angle |
33
+ | +-- Wave 2: Plan Generation (sequential) |
34
+ | | +-- Single planning agent consumes all exploration findings |
35
+ | | +-- Generates plan.json with waves, dependencies, estimates |
36
+ | | +-- Generates .task/TASK-*.json for each task |
37
+ | | +-- Applies Deep Work Rules (read_first, convergence.criteria) |
38
+ | | +-- Results: plan.json path + task count |
39
+ | +-- discoveries.ndjson shared across all waves (append-only) |
40
+ | |
41
+ | Phase 3: Plan Checking + Confirmation |
42
+ | +-- Validate plan quality (coverage, feasibility, deps, criteria) |
43
+ | +-- Revision loop (max 3 rounds) if critical issues found |
44
+ | +-- Update index.json with plan metadata |
45
+ | +-- Display plan summary + options (execute/modify/view) |
46
+ | |
47
+ +---------------------------------------------------------------------------+
48
+ ```
49
+ </purpose>
50
+
51
+ <context>
52
+ ```bash
53
+ $maestro-plan "3"
54
+ $maestro-plan -y "3"
55
+ $maestro-plan -c 4 "3 --spec SPEC-001"
56
+ $maestro-plan "3 --gaps"
57
+ $maestro-plan "3 --dir .workflow/scratch/quick-nav-fix"
58
+ $maestro-plan --continue "20260318-plan-P3-auth"
59
+ ```
60
+
61
+ **Flags**:
62
+ - `-y, --yes`: Skip all confirmations (auto mode)
63
+ - `-c, --concurrency N`: Max concurrent agents within each wave (default: 4)
64
+ - `--continue`: Resume existing session
65
+
66
+ When `--yes` or `-y`: Auto-confirm exploration angles, skip interactive clarification (P2), use defaults for complexity detection.
67
+
68
+ **Output Directory**: `.workflow/.csv-wave/{session-id}/`
69
+ **Core Output**: `tasks.csv` (master state) + `results.csv` (final) + `discoveries.ndjson` (shared exploration) + `context.md` (human-readable report) + `plan.json` + `.task/TASK-*.json`
70
+ </context>
71
+
72
+ <csv_schema>
73
+
74
+ ### tasks.csv (Master State)
75
+
76
+ ```csv
77
+ id,title,description,exploration_focus,deps,context_from,wave,status,findings,error
78
+ "E1","Architecture Exploration","Explore how the target feature fits into existing architecture. Map module boundaries, dependency graph, and integration points. Identify existing patterns that should be followed.","architecture","","","1","","",""
79
+ "E2","Implementation Exploration","Explore implementation patterns: libraries in use, coding conventions, error handling patterns, type definitions. Find 3+ similar features as reference.","implementation","","","1","","",""
80
+ "E3","Integration Exploration","Explore integration points: what existing code needs modification, API contracts, shared state, event flows. Map all touch points.","integration","","","1","","",""
81
+ "E4","Risk Exploration","Explore risks: what could go wrong, backward compatibility concerns, performance implications, security surface changes, test coverage gaps.","risk","","","1","","",""
82
+ "P1","Plan Generation","Consume all exploration findings. Decompose phase goal into concrete tasks with waves, dependencies, convergence criteria. Generate plan.json + TASK-*.json files following Deep Work Rules.","planning","E1;E2;E3;E4","E1;E2;E3;E4","2","","",""
83
+ ```
84
+
85
+ **Columns**:
86
+
87
+ | Column | Phase | Description |
88
+ |--------|-------|-------------|
89
+ | `id` | Input | Unique task identifier: `E{N}` for explorations (wave 1), `P1` for planning (wave 2) |
90
+ | `title` | Input | Short exploration or planning title |
91
+ | `description` | Input | Detailed exploration/planning instructions |
92
+ | `exploration_focus` | Input | Focus area: architecture/implementation/integration/risk/planning |
93
+ | `deps` | Input | Semicolon-separated dependency task IDs |
94
+ | `context_from` | Input | Semicolon-separated task IDs whose findings this task needs |
95
+ | `wave` | Computed | Wave number (1 = exploration, 2 = plan generation) |
96
+ | `status` | Output | `pending` -> `completed` / `failed` / `skipped` |
97
+ | `findings` | Output | Key findings summary (max 500 chars) |
98
+ | `error` | Output | Error message if failed |
99
+
100
+ ### Per-Wave CSV (Temporary)
101
+
102
+ Each wave generates `wave-{N}.csv` with extra `prev_context` column.
103
+
104
+ ### Output Artifacts
105
+
106
+ | File | Purpose | Lifecycle |
107
+ |------|---------|-----------|
108
+ | `tasks.csv` | Master state -- all tasks with status/findings | Updated after each wave |
109
+ | `wave-{N}.csv` | Per-wave input (temporary) | Created before wave, deleted after |
110
+ | `results.csv` | Final export of all task results | Created in Phase 3 |
111
+ | `discoveries.ndjson` | Shared exploration board | Append-only, carries across waves |
112
+ | `context.md` | Human-readable planning report | Created in Phase 3 |
113
+ | `plan.json` | Execution plan (in phase directory) | Created by wave 2 agent |
114
+ | `.task/TASK-*.json` | Individual task definitions (in phase directory) | Created by wave 2 agent |
115
+
116
+ ### Session Structure
117
+
118
+ ```
119
+ .workflow/.csv-wave/{YYYYMMDD}-plan-P{N}-{slug}/
120
+ +-- tasks.csv
121
+ +-- results.csv
122
+ +-- discoveries.ndjson
123
+ +-- context.md
124
+ +-- wave-{N}.csv (temporary)
125
+ ```
126
+ </csv_schema>
127
+
128
+ <invariants>
129
+ 1. **Start Immediately**: First action is session initialization, then Phase 1
130
+ 2. **Wave Order is Sacred**: Never execute wave 2 before wave 1 completes and results are merged
131
+ 3. **CSV is Source of Truth**: Master tasks.csv holds all state
132
+ 4. **Context Propagation**: prev_context built from master CSV, not from memory
133
+ 5. **Discovery Board is Append-Only**: Never clear, modify, or recreate discoveries.ndjson
134
+ 6. **Skip on Failure**: If all exploration agents failed, planning agent proceeds with available context
135
+ 7. **Cleanup Temp Files**: Remove wave-{N}.csv after results are merged
136
+ 8. **DO NOT STOP**: Continuous execution until all waves complete
137
+ </invariants>
138
+
139
+ <execution>
140
+
141
+ ### Session Initialization
142
+
143
+ ```javascript
144
+ // Parse from $ARGUMENTS:
145
+ // AUTO_YES <- --yes | -y
146
+ // continueMode <- --continue
147
+ // maxConcurrency <- --concurrency N | -c N (default: 4)
148
+ // autoMode <- --auto
149
+ // gapsMode <- --gaps
150
+ // dirMatch <- --dir <path>
151
+ // specMatch <- --spec SPEC-xxx
152
+ // collabMode <- --collab
153
+ // phaseArg <- remaining text after stripping all flags
154
+
155
+ // Auto-bootstrap .workflow/state.json if missing
156
+
157
+ // Scope determination from state.json (priority order):
158
+ // --dir given → scope from parent artifact or 'standalone'
159
+ // phaseArg empty → 'milestone' (requires current_milestone + roadmap.md) or ERROR E001
160
+ // phaseArg is digit → 'phase', resolve slug from roadmap, find latest completed analyze artifact
161
+ // phaseArg is text → 'adhoc' (if milestone active) or 'standalone', slugify phaseArg
162
+
163
+ // Session IDs (UTC+8):
164
+ // sessionId = {YYYYMMDD}-plan-P{phaseArg}-{phaseSlug}
165
+ // sessionFolder = .workflow/.csv-wave/{sessionId}
166
+ // scratchDir = .workflow/scratch/{sessionId}
167
+
168
+ // Create: sessionFolder, scratchDir/.task/
169
+ ```
170
+
171
+ ### Phase 1: Phase Resolution -> CSV
172
+
173
+ **Objective**: Resolve phase, load context, determine exploration angles, generate tasks.csv.
174
+
175
+ **Decomposition Rules**:
176
+
177
+ 1. **Scope resolution**: Already determined in Session Initialization (milestone/phase/adhoc/standalone)
178
+
179
+ 2. **Context loading** (from upstream analyze artifact or --dir):
180
+ - Read `{contextDir}/context.md` (user decisions from analyze) — if contextDir resolved
181
+ - Read `.workflow/project.md` — project vision and constraints
182
+ - Read `.workflow/roadmap.md` — phase structure and dependencies
183
+ - Read spec-ref if `--spec` flag
184
+ - Read `.workflow/codebase/doc-index.json` if exists
185
+ - Find design artifacts from `state.json.artifacts[]` (type=brainstorm with ui-designer) for MASTER.md
186
+ - Load project specs via `maestro spec load --category arch`
187
+
188
+ 3. **Upstream analysis check**:
189
+ - If `{contextDir}/conclusions.json` exists and has content: reuse as exploration context, skip wave 1
190
+ - If `{contextDir}/explorations.json` exists: load as additional context
191
+
192
+ 4. **Gap mode** (if `--gaps`):
193
+ - Load gaps from `.workflow/issues/issues.jsonl` (primary), `verification.json` (fallback), `uat.md` (additional)
194
+ - Enrich with debug diagnosis from `{PHASE_DIR}/.debug/*/understanding.md`
195
+ - Skip wave 1 exploration, generate gap-fix tasks directly in wave 2
196
+
197
+ 5. **Exploration angle determination** (skip if --gaps or upstream analysis loaded):
198
+
199
+ | Angle | Focus | When Included |
200
+ |-------|-------|---------------|
201
+ | architecture | Module boundaries, dependency graph, integration points | Always |
202
+ | implementation | Coding patterns, libraries, conventions, similar features | Always |
203
+ | integration | Existing code modifications, API contracts, shared state | When phase touches existing modules |
204
+ | risk | Backward compatibility, performance, security, test gaps | When phase is complex or critical |
205
+
206
+ 6. **CSV generation**: Exploration rows (wave 1) + one planning row (wave 2).
207
+
208
+ **Wave computation**: Simple 2-wave -- all exploration tasks = wave 1, planning task = wave 2.
209
+
210
+ **User validation**: Display exploration breakdown (skip if AUTO_YES or `--auto`).
211
+
212
+ ### Pre-flight: Team Conflict Check
213
+
214
+ Before starting the plan pipeline:
215
+ ```
216
+ Bash("maestro collab preflight --phase <phase-number>")
217
+ ```
218
+ If exit code is 1, present warnings and ask whether to proceed.
219
+
220
+ ### Wiki Knowledge Search
221
+
222
+ During context collection, after loading files and before exploration (Wave 1):
223
+ ```
224
+ phase_keywords = extract key terms from goal/title (2-5 terms)
225
+ wiki_result = Bash("maestro wiki search ${phase_keywords} --json 2>/dev/null")
226
+
227
+ IF wiki_result exit code != 0 OR empty:
228
+ W003: Wiki search unavailable, continue without prior knowledge
229
+ ELSE:
230
+ entries = JSON.parse(wiki_result).entries (limit to first 10)
231
+ Pass wiki_context to Wave 2 planning agent
232
+ ```
233
+
234
+ ### Mode Routing
235
+
236
+ | Mode | Trigger | Behavior |
237
+ |------|---------|----------|
238
+ | Create | Default (no --revise/--check) | Full pipeline: Phase 1 → Wave 1 → Wave 2 → Phase 3 |
239
+ | Revise | `--revise [instructions]` | Load existing plan, apply incremental edits, re-check |
240
+ | Check | `--check <plan-dir>` | Skip exploration/planning, run plan-checker only on existing plan |
241
+
242
+ **Revise mode**: Load plan.json from target dir, apply user instructions (add/remove/edit tasks, adjust waves), re-run plan-checker, update index.json.
243
+
244
+ **Check mode**: Read plan.json + .task/TASK-*.json from `--check` path, validate quality, report issues. No exploration, no generation.
245
+
246
+ ### Phase 2: Wave Execution Engine
247
+
248
+ **Objective**: Explore codebase then generate plan via spawn_agents_on_csv.
249
+
250
+ #### Wave 1: Codebase Exploration (Parallel)
251
+
252
+ 1. Read master `tasks.csv`
253
+ 2. Filter rows where `wave == 1` AND `status == pending`
254
+ 3. No prev_context needed (wave 1 has no predecessors)
255
+ 4. Write `wave-1.csv`
256
+ 5. Execute:
257
+
258
+ ```javascript
259
+ spawn_agents_on_csv({
260
+ csv_path: `${sessionFolder}/wave-1.csv`,
261
+ id_column: "id",
262
+ instruction: buildExplorationInstruction(sessionFolder, phaseDir),
263
+ max_concurrency: maxConcurrency,
264
+ max_runtime_seconds: 3600,
265
+ output_csv_path: `${sessionFolder}/wave-1-results.csv`,
266
+ output_schema: { // required: id, status, findings
267
+ id: "string", status: "completed|failed", findings: "string", error: "string"
268
+ }
269
+ })
270
+ ```
271
+
272
+ 6. Merge `wave-1-results.csv` into master `tasks.csv`, delete `wave-1.csv`
273
+
274
+ #### Task Count Guard (before Wave 2)
275
+
276
+ Before generating the planning instruction, assess scope complexity and embed expected task count ceiling:
277
+ - Single feature / simple change → expect **1-2 tasks** max
278
+ - Medium feature (multiple files, one module) → expect **2-4 tasks** max
279
+ - Large feature (cross-module) → expect **4-8 tasks** max
280
+
281
+ Include this ceiling in `buildPlanningInstruction`. If the planning agent outputs more tasks than the threshold, re-prompt with explicit instruction to merge.
282
+
283
+ #### Wave 2: Plan Generation (Sequential)
284
+
285
+ 1. Read master `tasks.csv`
286
+ 2. Filter rows where `wave == 2` AND `status == pending`
287
+ 3. Build `prev_context` from wave 1 findings:
288
+ ```
289
+ [E1: Architecture Exploration] Module boundaries: auth/ is self-contained, shared/ has...
290
+ [E2: Implementation Exploration] Patterns found: Result type for errors, zod for validation...
291
+ [E3: Integration Exploration] Touch points: routes/index.ts needs new route, middleware/auth.ts...
292
+ [E4: Risk Exploration] Risks: No test coverage for auth refresh flow, potential breaking change...
293
+ ```
294
+ 4. Write `wave-2.csv` with `prev_context` column
295
+ 5. Execute:
296
+
297
+ ```javascript
298
+ spawn_agents_on_csv({
299
+ csv_path: `${sessionFolder}/wave-2.csv`,
300
+ id_column: "id",
301
+ instruction: buildPlanningInstruction(sessionFolder, phaseDir, {
302
+ contextMd, indexJson, specRef, docIndex, designRef, gapsContext
303
+ }),
304
+ max_concurrency: 1, // Single planning agent
305
+ max_runtime_seconds: 3600,
306
+ output_csv_path: `${sessionFolder}/wave-2-results.csv`,
307
+ output_schema: { // required: id, status, findings
308
+ id: "string", status: "completed|failed", findings: "string", error: "string"
309
+ }
310
+ })
311
+ ```
312
+
313
+ 6. Merge `wave-2-results.csv` into master `tasks.csv`, delete `wave-2.csv`
314
+
315
+ **Planning agent responsibilities** (embedded in instruction):
316
+ - Group work into feature-level tasks. One feature = one task (even if it touches 3-5 files). Do NOT split a single feature into multiple file-level tasks.
317
+ - Apply Deep Work Rules: `read_first[]` includes modified file + source of truth; `convergence.criteria[]` are grep-verifiable; all actions/steps have concrete values
318
+ - Write `plan.json` to `{PHASE_DIR}/plan.json` and `.task/TASK-{NNN}.json` to `{PHASE_DIR}/.task/`
319
+ - `--gaps`: create fix tasks from gap context, link to issues; `--collab`: pre-allocate ID ranges
320
+
321
+ **Task Grouping Rules (MANDATORY)** — pass to planning agent, re-prompt if violated:
322
+
323
+ 1. **Group by feature** — All changes for one feature = one task (even if 3-5 files). Never create separate tasks per file.
324
+ 2. **Group by context** — Related functional changes belong together. Don't split just because changes touch different files.
325
+ 3. **Minimize agent count** — Group simple unrelated changes into a single "batch" task to reduce overhead. Each agent spawn costs significant tokens.
326
+ 4. **Substantial tasks only** — Each task should represent 15-60 minutes of real work. If a task takes <5 minutes, merge it into another.
327
+ 5. **True dependencies only** — `depends_on` only when Task B genuinely needs Task A's output (e.g., "Task A defines the interface that Task B implements"). Sequential execution wastes time.
328
+ 6. **Prefer parallel** — Most tasks should be independent (no depends_on). Default to parallel waves.
329
+ 7. **Complexity-based sizing**:
330
+ - **Low** (single file, single concern, zero cross-module): **1 task**
331
+ - **Medium** (multiple files OR integration point): **1-4 tasks**
332
+ - **High** (cross-module, architectural, new subsystem): **4-10 tasks**
333
+
334
+ **Anti-splitting rules** (re-prompt if violated):
335
+ - One feature = one task (even if 3-5 files); never split a feature into per-file tasks
336
+ - Group simple unrelated changes into a batch task to minimize agent spawns
337
+ - `depends_on` only for genuine output dependencies; most tasks should be parallel
338
+ - Each task must be substantial (15-60 min); sub-5-min changes must be merged
339
+
340
+ ### Phase 3: Plan Checking + Confirmation
341
+
342
+ **Objective**: Validate plan quality, revise if needed, present to user.
343
+
344
+ 1. **Plan checking** (inline, not a separate wave):
345
+ Read `plan.json` + all `.task/TASK-*.json`. Validate: requirements coverage, file feasibility, dependency correctness (no cycles, valid wave order), grep-verifiable convergence criteria, read_first completeness, action concreteness, no parallel file conflicts, **task count within complexity threshold** (reject over-split plans), **no per-file splitting** (each task must be feature-level).
346
+
347
+ 2. **Revision loop** (max 3 rounds): If critical issues found, regenerate affected tasks.
348
+
349
+ 2b. **Spec Enrichment**: Persist cross-task reusable design decisions:
350
+ - `maestro spec add coding|arch "<decision.title>" "<rationale>" --keywords ... --source plan:{sessionId}`
351
+ - Test strategy decisions → `maestro spec add test ...`
352
+ - Typical: 0-3 entries per plan session
353
+
354
+ 3. **Export results**:
355
+ - Export `results.csv` from master `tasks.csv`
356
+ - Generate `context.md`: summary (phase, task count, wave count, complexity, exploration count), exploration findings per angle, plan overview (approach, task IDs, waves), next steps
357
+
358
+ 4. **Collision detection**: Scan same-milestone plans for overlapping file targets:
359
+ ```
360
+ other_plans = state.json.artifacts.filter(a => a.milestone == current && a.type == "plan" && a.id != this)
361
+ For each other_plan: read .task/TASK-*.json, collect files[].path
362
+ collisions = intersection(this_plan_files, other_plan_files)
363
+ If collisions.length > 0: emit W004, display collision table (non-blocking)
364
+ ```
365
+
366
+ 5. **Update index.json**: set `status: "planning"`, `plan: { task_ids, task_count, complexity, waves }`, `updated_at`
367
+
368
+ 6. **Register PLN artifact** in state.json:
369
+ ```json
370
+ { "id": "PLN-NNN", "type": "plan", "milestone": "current", "phase": "target_phase",
371
+ "scope": "phase", "path": "scratch/{YYYYMMDD}-plan-P{N}-{slug}",
372
+ "status": "completed", "depends_on": "anl_art.id || exec_art.id" }
373
+ ```
374
+
375
+ 7. **Issue linking** (if --gaps):
376
+ For each TASK with `issue_id`: update issue in `issues.jsonl` (`task_refs` += TASK-NNN, `task_plan_dir`, `status: "planned"`, `updated_at`) + append history entry. Ensures bidirectional issue-TASK traceability.
377
+
378
+ 8. **Display summary + options** (skip options if AUTO_YES):
379
+ ```
380
+ === PLAN READY ===
381
+ Phase: {phase_name}
382
+ Tasks: {task_count} tasks in {wave_count} waves
383
+ Check: {checker_status} (iteration {check_count}/{max_checks})
384
+ Collision: {collision_status}
385
+
386
+ Next steps:
387
+ $maestro-execute "{phase}" -- Execute the plan
388
+ $maestro-plan "{phase}" -- Re-plan with modifications
389
+ ```
390
+
391
+ ### Shared Discovery Board Protocol
392
+
393
+ #### Standard Discovery Types
394
+
395
+ | Type | Dedup Key | Data Schema | Description |
396
+ |------|-----------|-------------|-------------|
397
+ | `code_pattern` | `data.name` | `{name, file, description}` | Reusable code pattern found |
398
+ | `integration_point` | `data.file` | `{file, description, exports[]}` | Module connection point |
399
+ | `convention` | singleton | `{naming, imports, formatting}` | Project code conventions |
400
+ | `blocker` | `data.issue` | `{issue, severity, impact}` | Blocking issue found |
401
+ | `tech_stack` | singleton | `{framework, language, tools[]}` | Technology stack info |
402
+
403
+ #### Domain Discovery Types
404
+
405
+ | Type | Dedup Key | Data Schema | Description |
406
+ |------|-----------|-------------|-------------|
407
+ | `existing_pattern` | `data.name` | `{name, file, description, usage}` | Existing feature pattern to follow |
408
+ | `dependency_map` | `data.module` | `{module, imports[], exports[], dependents[]}` | Module dependency mapping |
409
+ | `risk_factor` | `data.risk` | `{risk, severity, mitigation, affected_files[]}` | Identified risk |
410
+ | `test_command` | `data.command` | `{command, scope, framework}` | Test execution command |
411
+
412
+ #### Protocol
413
+
414
+ 1. **Read** `{session_folder}/discoveries.ndjson` before own exploration
415
+ 2. **Skip covered**: If discovery of same type + dedup key exists, skip
416
+ 3. **Write immediately**: Append findings as found
417
+ 4. **Append-only**: Never modify or delete
418
+ 5. **Deduplicate**: Check before writing
419
+
420
+ ```bash
421
+ echo '{"ts":"<ISO>","worker":"{id}","type":"existing_pattern","data":{"name":"Result error handling","file":"src/utils/result.ts","description":"All functions return Result<T,E> instead of throwing","usage":"Used in auth, payments, validation modules"}}' >> {session_folder}/discoveries.ndjson
422
+ ```
423
+ </execution>
424
+
425
+ <error_codes>
426
+
427
+ | Error | Resolution |
428
+ |-------|------------|
429
+ | Phase argument required | Abort with error: "Phase argument required" |
430
+ | Phase directory not found | Abort with error: "Phase {N} not found. Run init first." |
431
+ | --gaps requires gaps source | Abort with error: "--gaps requires issues.jsonl, verification.json, or uat.md" |
432
+ | No plan found to revise (--revise) | Use --dir to specify plan, or create plan first |
433
+ | Plan directory not found (--check) | Check path, use --dir |
434
+ | No context.md found | Warn, proceed with exploration only |
435
+ | Wiki search unavailable (W003) | Continue without prior knowledge context |
436
+ | Collision detected (W004) | Review colliding files, confirm or adjust scope |
437
+ | Exploration agent timeout | Mark as failed, continue with available explorations |
438
+ | Planning agent fails | Retry once with simplified context, then abort |
439
+ | Plan produces invalid JSON | Retry once, then abort with error details |
440
+ | Plan-checker exceeds 3 rounds | Accept plan with warnings, note in index.json |
441
+ | CSV parse error | Validate format, show line number |
442
+ | discoveries.ndjson corrupt | Ignore malformed lines |
443
+ | Continue mode: no session found | List available sessions |
444
+ </error_codes>
445
+
446
+ <success_criteria>
447
+ - [ ] Session folder created with valid tasks.csv
448
+ - [ ] All waves executed in order
449
+ - [ ] plan.json produced in phase directory
450
+ - [ ] .task/TASK-*.json files produced for all tasks
451
+ - [ ] Plan passes quality checks (coverage, deps, criteria)
452
+ - [ ] Collision detection executed against same-milestone plans
453
+ - [ ] PLN artifact registered in state.json
454
+ - [ ] context.md produced with exploration findings + plan overview
455
+ - [ ] index.json updated with plan metadata
456
+ - [ ] Issues linked bidirectionally (if --gaps mode)
457
+ - [ ] Wiki knowledge integrated (if available)
458
+ - [ ] Team conflict preflight checked
459
+ - [ ] discoveries.ndjson append-only throughout
460
+ </success_criteria>