planflow-ai 1.3.5 → 1.4.3

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 (123) hide show
  1. package/.claude/commands/brainstorm.md +6 -14
  2. package/.claude/commands/create-contract.md +6 -38
  3. package/.claude/commands/create-plan.md +18 -38
  4. package/.claude/commands/discovery-plan.md +19 -49
  5. package/.claude/commands/execute-plan.md +116 -77
  6. package/.claude/commands/flow.md +27 -2
  7. package/.claude/commands/heartbeat.md +12 -14
  8. package/.claude/commands/learn.md +20 -80
  9. package/.claude/commands/note.md +6 -23
  10. package/.claude/commands/resume-work.md +261 -0
  11. package/.claude/commands/review-code.md +19 -51
  12. package/.claude/commands/review-pr.md +21 -57
  13. package/.claude/commands/setup.md +8 -56
  14. package/.claude/commands/write-tests.md +7 -41
  15. package/.claude/resources/core/atomic-commits.md +380 -0
  16. package/.claude/resources/core/autopilot-mode.md +3 -2
  17. package/.claude/resources/core/compaction-guide.md +15 -1
  18. package/.claude/resources/core/heartbeat.md +129 -1
  19. package/.claude/resources/core/per-task-verification.md +362 -0
  20. package/.claude/resources/core/phase-isolation.md +237 -4
  21. package/.claude/resources/core/session-scratchpad.md +1 -0
  22. package/.claude/resources/core/shared-context.md +110 -0
  23. package/.claude/resources/core/wave-execution.md +407 -0
  24. package/.claude/resources/patterns/plans-patterns.md +56 -0
  25. package/.claude/resources/patterns/plans-templates.md +152 -0
  26. package/.claude/resources/skills/create-plan-skill.md +71 -5
  27. package/.claude/resources/skills/execute-plan-skill.md +420 -14
  28. package/.claude/resources/skills/resume-work-skill.md +159 -0
  29. package/README.md +154 -96
  30. package/dist/cli/commands/brain.d.ts +20 -0
  31. package/dist/cli/commands/brain.d.ts.map +1 -0
  32. package/dist/cli/commands/brain.js +127 -0
  33. package/dist/cli/commands/brain.js.map +1 -0
  34. package/dist/cli/commands/init.d.ts.map +1 -1
  35. package/dist/cli/commands/init.js +10 -1
  36. package/dist/cli/commands/init.js.map +1 -1
  37. package/dist/cli/commands/state-query.d.ts +13 -0
  38. package/dist/cli/commands/state-query.d.ts.map +1 -0
  39. package/dist/cli/commands/state-query.js +32 -0
  40. package/dist/cli/commands/state-query.js.map +1 -0
  41. package/dist/cli/commands/state.d.ts +12 -0
  42. package/dist/cli/commands/state.d.ts.map +1 -0
  43. package/dist/cli/commands/state.js +47 -0
  44. package/dist/cli/commands/state.js.map +1 -0
  45. package/dist/cli/daemon/desktop-notifier.d.ts +16 -0
  46. package/dist/cli/daemon/desktop-notifier.d.ts.map +1 -0
  47. package/dist/cli/daemon/desktop-notifier.js +53 -0
  48. package/dist/cli/daemon/desktop-notifier.js.map +1 -0
  49. package/dist/cli/daemon/event-writer.d.ts +22 -0
  50. package/dist/cli/daemon/event-writer.d.ts.map +1 -0
  51. package/dist/cli/daemon/event-writer.js +76 -0
  52. package/dist/cli/daemon/event-writer.js.map +1 -0
  53. package/dist/cli/daemon/heartbeat-daemon.js +81 -1
  54. package/dist/cli/daemon/heartbeat-daemon.js.map +1 -1
  55. package/dist/cli/daemon/log-writer.d.ts +17 -0
  56. package/dist/cli/daemon/log-writer.d.ts.map +1 -0
  57. package/dist/cli/daemon/log-writer.js +62 -0
  58. package/dist/cli/daemon/log-writer.js.map +1 -0
  59. package/dist/cli/daemon/notification-router.d.ts +17 -0
  60. package/dist/cli/daemon/notification-router.d.ts.map +1 -0
  61. package/dist/cli/daemon/notification-router.js +35 -0
  62. package/dist/cli/daemon/notification-router.js.map +1 -0
  63. package/dist/cli/daemon/prompt-manager.d.ts +27 -0
  64. package/dist/cli/daemon/prompt-manager.d.ts.map +1 -0
  65. package/dist/cli/daemon/prompt-manager.js +107 -0
  66. package/dist/cli/daemon/prompt-manager.js.map +1 -0
  67. package/dist/cli/daemon/shared-context.d.ts +38 -0
  68. package/dist/cli/daemon/shared-context.d.ts.map +1 -0
  69. package/dist/cli/daemon/shared-context.js +129 -0
  70. package/dist/cli/daemon/shared-context.js.map +1 -0
  71. package/dist/cli/handlers/claude.d.ts.map +1 -1
  72. package/dist/cli/handlers/claude.js +18 -0
  73. package/dist/cli/handlers/claude.js.map +1 -1
  74. package/dist/cli/handlers/shared.js +1 -1
  75. package/dist/cli/handlers/shared.js.map +1 -1
  76. package/dist/cli/index.js +30 -0
  77. package/dist/cli/index.js.map +1 -1
  78. package/dist/cli/state/brain-query.d.ts +48 -0
  79. package/dist/cli/state/brain-query.d.ts.map +1 -0
  80. package/dist/cli/state/brain-query.js +113 -0
  81. package/dist/cli/state/brain-query.js.map +1 -0
  82. package/dist/cli/state/flowconfig-parser.d.ts +16 -0
  83. package/dist/cli/state/flowconfig-parser.d.ts.map +1 -0
  84. package/dist/cli/state/flowconfig-parser.js +166 -0
  85. package/dist/cli/state/flowconfig-parser.js.map +1 -0
  86. package/dist/cli/state/heartbeat-state.d.ts +16 -0
  87. package/dist/cli/state/heartbeat-state.d.ts.map +1 -0
  88. package/dist/cli/state/heartbeat-state.js +97 -0
  89. package/dist/cli/state/heartbeat-state.js.map +1 -0
  90. package/dist/cli/state/model-router.d.ts +8 -0
  91. package/dist/cli/state/model-router.d.ts.map +1 -0
  92. package/dist/cli/state/model-router.js +36 -0
  93. package/dist/cli/state/model-router.js.map +1 -0
  94. package/dist/cli/state/plan-parser.d.ts +16 -0
  95. package/dist/cli/state/plan-parser.d.ts.map +1 -0
  96. package/dist/cli/state/plan-parser.js +124 -0
  97. package/dist/cli/state/plan-parser.js.map +1 -0
  98. package/dist/cli/state/session-state.d.ts +21 -0
  99. package/dist/cli/state/session-state.d.ts.map +1 -0
  100. package/dist/cli/state/session-state.js +36 -0
  101. package/dist/cli/state/session-state.js.map +1 -0
  102. package/dist/cli/state/state-md-parser.d.ts +18 -0
  103. package/dist/cli/state/state-md-parser.d.ts.map +1 -0
  104. package/dist/cli/state/state-md-parser.js +222 -0
  105. package/dist/cli/state/state-md-parser.js.map +1 -0
  106. package/dist/cli/state/types.d.ts +137 -0
  107. package/dist/cli/state/types.d.ts.map +1 -0
  108. package/dist/cli/state/types.js +8 -0
  109. package/dist/cli/state/types.js.map +1 -0
  110. package/dist/cli/state/wave-calculator.d.ts +18 -0
  111. package/dist/cli/state/wave-calculator.d.ts.map +1 -0
  112. package/dist/cli/state/wave-calculator.js +134 -0
  113. package/dist/cli/state/wave-calculator.js.map +1 -0
  114. package/dist/cli/types.d.ts +15 -0
  115. package/dist/cli/types.d.ts.map +1 -1
  116. package/package.json +7 -2
  117. package/templates/shared/CLAUDE.md.template +4 -0
  118. package/.claude/resources/core/_index.md +0 -304
  119. package/.claude/resources/languages/_index.md +0 -76
  120. package/.claude/resources/patterns/_index.md +0 -200
  121. package/.claude/resources/skills/_index.md +0 -285
  122. package/.claude/resources/tools/_index.md +0 -110
  123. package/.claude/resources/tools/reference-expansion-tool.md +0 -326
@@ -0,0 +1,407 @@
1
+
2
+ # Wave-Based Parallel Execution
3
+
4
+ ## Purpose
5
+
6
+ When `wave_execution: true` in `flow/.flowconfig` (default), `/execute-plan` analyzes phase dependencies, groups independent phases into **waves**, and executes phases within each wave **in parallel** using Agent sub-agents. Waves are sequenced — Wave N+1 starts only after all Wave N phases complete. This reduces total execution time by 40-60% for plans with independent phases.
7
+
8
+ **Core principle**: Dependency analysis in, parallel waves out, sequential commits after.
9
+
10
+ ---
11
+
12
+ ## Architecture
13
+
14
+ ```
15
+ Coordinator (main session)
16
+
17
+ ├─ Step 2b: Wave Analysis
18
+ │ ├─ Parse Dependencies from each phase
19
+ │ ├─ Build dependency graph
20
+ │ ├─ Topological sort → group into waves
21
+ │ └─ Present wave summary to user
22
+
23
+ ├─ For each Wave:
24
+ │ │
25
+ │ ├─ Sequential: Approve each phase in Plan Mode
26
+ │ │
27
+ │ ├─ Create shared context file (flow/.wave-context.jsonl)
28
+ │ │
29
+ │ ├─ Parallel: Spawn Agent sub-agents for all wave phases
30
+ │ │ ├─► Agent: Phase A (model: [tier from model routing])
31
+ │ │ ├─► Agent: Phase B (model: [tier from model routing])
32
+ │ │ └─► Agent: Phase C (model: [tier from model routing])
33
+ │ │ (agents read/append to .wave-context.jsonl during execution)
34
+ │ │
35
+ │ ├─ Collect JSON returns from all sub-agents
36
+ │ │
37
+ │ ├─ Post-wave processing:
38
+ │ │ ├─ Detect file conflicts (files_modified overlap)
39
+ │ │ ├─ Detect contract conflicts (same name, different signatures)
40
+ │ │ ├─ Accumulate files_modified list
41
+ │ │ ├─ Buffer patterns from all phases
42
+ │ │ ├─ Git commit per-task (iterate tasks within each phase, in phase order)
43
+ │ │ ├─ Handle failures (present to user)
44
+ │ │ └─ Delete .wave-context.jsonl (clean slate for next wave)
45
+ │ │
46
+ │ └─ Next Wave...
47
+
48
+ └─ Completion summary with wave execution stats
49
+ ```
50
+
51
+ Planning and user approval always happen **sequentially** in the main session. Only **implementation** is parallelized within waves.
52
+
53
+ ---
54
+
55
+ ## Shared Context
56
+
57
+ ### Overview
58
+
59
+ During wave execution, parallel phases share a context file (`flow/.wave-context.jsonl`) that enables real-time coordination. Agents share API contracts, architectural decisions, and progress status via append-only JSONL entries. Before each task, sub-agents receive shared context from sibling phases, preventing broken contracts and duplicate decisions.
60
+
61
+ ### Lifecycle
62
+
63
+ 1. **Wave start**: Coordinator creates `flow/.wave-context.jsonl` (empty file) before spawning sub-agents
64
+ 2. **During execution**: Sub-agents append entries as they make decisions, define contracts, or complete tasks
65
+ 3. **Before each task**: Sub-agents read the shared context file to pick up entries from sibling phases
66
+ 4. **Wave end**: Coordinator reads the final context file for post-wave conflict detection
67
+ 5. **Cleanup**: Context file is deleted after the wave completes (each wave gets a fresh file)
68
+
69
+ ### Entry Format
70
+
71
+ Each line in `.wave-context.jsonl` is a JSON object with one of three types:
72
+
73
+ ```jsonl
74
+ {"type":"contract","phase":2,"task":1,"name":"UserAPI","signature":{"endpoint":"/api/users","method":"GET","response":"User[]"},"timestamp":"2024-01-15T10:30:00Z"}
75
+ {"type":"decision","phase":1,"task":2,"name":"auth-strategy","value":"JWT with refresh tokens","reason":"Aligns with existing session management","timestamp":"2024-01-15T10:31:00Z"}
76
+ {"type":"progress","phase":3,"task":1,"status":"complete","files_modified":["src/utils/helpers.ts"],"timestamp":"2024-01-15T10:32:00Z"}
77
+ ```
78
+
79
+ | Type | Purpose | Key Fields |
80
+ |------|---------|------------|
81
+ | `contract` | API shapes, interfaces, shared types | `name`, `signature` |
82
+ | `decision` | Architecture choices, technology selections | `name`, `value`, `reason` |
83
+ | `progress` | Task completion status, files touched | `status`, `files_modified` |
84
+
85
+ ### Sub-Agent Context Injection
86
+
87
+ When spawning each sub-agent, the coordinator includes in the context template:
88
+
89
+ ```
90
+ ## Shared Context (from sibling phases)
91
+
92
+ [Contents of flow/.wave-context.jsonl, if any entries exist]
93
+
94
+ RULES:
95
+ - Read shared context before starting each task
96
+ - Append contract/decision/progress entries as you work
97
+ - If a sibling defined a contract, use that exact signature
98
+ - If a sibling made an architecture decision, follow it
99
+ ```
100
+
101
+ For the first task in a wave, the context file may be empty. As phases progress, entries accumulate and inform subsequent tasks.
102
+
103
+ ---
104
+
105
+ ## Dependency Analysis
106
+
107
+ ### Dependency Declaration Syntax
108
+
109
+ Each plan phase may include an optional `**Dependencies**` field after `**Complexity**`:
110
+
111
+ ```markdown
112
+ ### Phase 3: API Integration
113
+
114
+ **Scope**: ...
115
+ **Complexity**: 5/10
116
+ **Dependencies**: Phase 1, Phase 2
117
+
118
+ - [ ] Task 1
119
+ - [ ] Task 2
120
+ ```
121
+
122
+ ### Dependency Rules
123
+
124
+ | Declaration | Meaning |
125
+ |-------------|---------|
126
+ | `**Dependencies**: Phase 1, Phase 3` | Phase depends on Phase 1 and Phase 3 completing first |
127
+ | `**Dependencies**: None` | Phase has no dependencies — can run in parallel with others |
128
+ | No `Dependencies` field | **Default**: depends on previous phase (backward-compatible sequential) |
129
+
130
+ **Parsing rules**:
131
+ 1. Look for `**Dependencies**:` line in each phase section
132
+ 2. Extract phase numbers: parse `Phase N` references (case-insensitive)
133
+ 3. `None` (case-insensitive) means explicitly independent
134
+ 4. Missing field = implicit dependency on Phase N-1 (Phase 1 has no implicit dependency)
135
+ 5. Self-references are ignored
136
+ 6. References to non-existent phases are ignored with a warning
137
+
138
+ ### Special Rules
139
+
140
+ - **Tests phase**: NEVER parallelized, regardless of dependency declaration. Always runs alone in the final wave.
141
+ - **Phase 1**: Always in Wave 1 (no possible predecessors)
142
+
143
+ ---
144
+
145
+ ## Wave Grouping Algorithm
146
+
147
+ ### Topological Sort
148
+
149
+ 1. **Build graph**: For each phase, record its dependencies (explicit or implicit)
150
+ 2. **Assign wave numbers**:
151
+ - Phases with no dependencies → Wave 1
152
+ - For each remaining phase: wave = max(wave of each dependency) + 1
153
+ 3. **Tests phase exception**: Move to its own final wave regardless of computed wave number
154
+ 4. **Validate**: Check for circular dependencies — if found, warn user and fall back to sequential
155
+
156
+ ### Example
157
+
158
+ Given a plan with 5 phases:
159
+ ```
160
+ Phase 1: Types and interfaces Dependencies: None
161
+ Phase 2: Utility functions Dependencies: None
162
+ Phase 3: API integration Dependencies: Phase 1, Phase 2
163
+ Phase 4: Configuration updates Dependencies: Phase 1, Phase 3
164
+ Phase 5: Tests Dependencies: Phase 1, Phase 2, Phase 3, Phase 4
165
+ ```
166
+
167
+ Wave grouping result:
168
+ ```
169
+ Wave 1: Phase 1, Phase 2 (both independent)
170
+ Wave 2: Phase 3 (depends on Wave 1 phases)
171
+ Wave 3: Phase 4 (depends on Phase 3 in Wave 2)
172
+ Wave 4: Phase 5 (tests — always last, alone)
173
+ ```
174
+
175
+ Sequential execution: 5 phases in sequence
176
+ Wave execution: 4 waves (Wave 1 runs 2 phases in parallel)
177
+ Estimated speedup: ~20% (1 fewer sequential step)
178
+
179
+ ### Backward Compatibility
180
+
181
+ Plans without any `Dependencies` fields produce a fully sequential wave plan:
182
+ ```
183
+ Wave 1: Phase 1
184
+ Wave 2: Phase 2
185
+ Wave 3: Phase 3
186
+ ...
187
+ ```
188
+
189
+ This matches existing behavior exactly — no regression.
190
+
191
+ ---
192
+
193
+ ## Wave Execution Summary
194
+
195
+ Before execution begins, the coordinator presents the wave plan to the user:
196
+
197
+ ```markdown
198
+ ## Wave Execution Plan
199
+
200
+ | Wave | Phases | Parallel |
201
+ |------|--------|----------|
202
+ | 1 | Phase 1: Types, Phase 2: Utilities | Yes (2 parallel) |
203
+ | 2 | Phase 3: API Integration | No (1 phase) |
204
+ | 3 | Phase 4: Config Updates | No (1 phase) |
205
+ | 4 | Phase 5: Tests | No (always sequential) |
206
+
207
+ **Sequential phases**: 5 → **Waves**: 4 → **Estimated speedup**: ~20%
208
+
209
+ Proceed with wave execution? (yes/no/sequential)
210
+ ```
211
+
212
+ User options:
213
+ - **yes**: Execute with wave parallelism
214
+ - **no**: Stop execution
215
+ - **sequential**: Fall back to sequential execution (ignore waves)
216
+
217
+ ---
218
+
219
+ ## Parallel Spawning Rules
220
+
221
+ ### Sub-Agent Setup
222
+
223
+ Each phase within a wave is spawned as an **independent Agent sub-agent** following the phase-isolation context template (see `phase-isolation.md` COR-PI-2). Key additions for wave execution:
224
+
225
+ 1. **Files Modified context**: For Wave N, include files_modified from ALL completed waves (1 through N-1), not just the previous phase
226
+ 2. **No cross-phase awareness**: Sub-agents within the same wave do NOT know about each other. They receive no information about sibling phases.
227
+ 3. **Model routing**: Each sub-agent uses the model tier from its own phase complexity score (same as phase isolation)
228
+
229
+ ### Spawning Pattern
230
+
231
+ ```
232
+ For Wave N (phases A, B, C):
233
+ Launch in parallel:
234
+ - Agent(model: [tier_A], prompt: phase_A_context)
235
+ - Agent(model: [tier_B], prompt: phase_B_context)
236
+ - Agent(model: [tier_C], prompt: phase_C_context)
237
+
238
+ Wait for all to complete.
239
+ Process results sequentially.
240
+ ```
241
+
242
+ This mirrors the discovery-sub-agents pattern (see `discovery-sub-agents.md` COR-DSA-3) but with phase-isolation context templates instead of exploration prompts.
243
+
244
+ ### Return Format
245
+
246
+ Each sub-agent returns the **same JSON format** as phase isolation (see `phase-isolation.md`), including the `tasks_completed` array for per-task file tracking. The `tasks_completed` field enables the wave coordinator to create atomic per-task commits after the wave completes. See `.claude/resources/core/atomic-commits.md` for the full `tasks_completed` schema.
247
+
248
+ ---
249
+
250
+ ## Wave Coordinator Behavior
251
+
252
+ ### Per-Wave Processing
253
+
254
+ After all sub-agents in a wave return, the coordinator processes results **sequentially in phase order**:
255
+
256
+ 1. **Collect returns**: Gather JSON from all sub-agents
257
+ 2. **Validate JSON**: Parse each return, check for required fields
258
+ 3. **Detect file conflicts**: Check for files_modified overlap between phases in this wave
259
+ 4. **Process each phase** (in phase number order):
260
+ - Update plan file (mark tasks `[x]`)
261
+ - Accumulate files_modified into running list
262
+ - Buffer patterns_captured entries
263
+ - Git commit per-task if enabled: iterate `tasks_completed` array and create one commit per task (`feat(phase-N.task-M): <desc> — <feature>`). See `.claude/resources/core/atomic-commits.md` for format.
264
+ - Log decisions and deviations
265
+ 5. **Report wave completion**: Summary of all phases in this wave, including `task_verifications` results from each phase return (display pass/fail counts and any repairs applied per phase)
266
+
267
+ ### File Conflict Detection
268
+
269
+ After collecting all wave results, check for **files_modified overlap**:
270
+
271
+ ```
272
+ For each pair of phases (A, B) in the wave:
273
+ overlap = A.files_modified ∩ B.files_modified
274
+ if overlap is not empty:
275
+ → File conflict detected
276
+ ```
277
+
278
+ **On conflict**:
279
+ 1. Present the conflicting files and which phases modified them
280
+ 2. Offer options:
281
+ - **(1) Accept as-is**: Last writer wins (the phase with the higher number committed last)
282
+ - **(2) Re-run conflicting phases sequentially**: Re-execute only the conflicting phases in order
283
+ - **(3) Stop execution**: Halt for manual resolution
284
+
285
+ File conflict does NOT affect non-conflicting phases — their results are preserved.
286
+
287
+ ### Contract Conflict Detection
288
+
289
+ After collecting all wave results, parse `flow/.wave-context.jsonl` and check for **contract conflicts**:
290
+
291
+ ```
292
+ For each pair of "contract" entries with the same name:
293
+ if entry_A.signature != entry_B.signature:
294
+ → Contract conflict detected
295
+ ```
296
+
297
+ **On contract conflict**:
298
+ 1. Present the conflicting contract definitions — show the name, the two signatures, and which phases defined them
299
+ 2. Offer options:
300
+ - **(1) Pick one**: User selects which phase's contract to use; the other phase must be re-run with the chosen contract injected
301
+ - **(2) Re-run conflicting phases sequentially**: Re-execute only the conflicting phases in order, so the second phase sees the first's contract
302
+ - **(3) Stop execution**: Halt for manual resolution
303
+
304
+ Contract conflicts are checked **after** file conflicts. Both may exist simultaneously — present all conflicts before asking for resolution.
305
+
306
+ ### Failure Handling
307
+
308
+ | Scenario | Behavior |
309
+ |----------|----------|
310
+ | One phase fails, others succeed | Process successful phases normally. Present failure to user. Offer: retry failed phase, skip it, or stop. |
311
+ | Multiple phases fail | Process any successful phases. Present all failures. Offer same options per failed phase. |
312
+ | All phases in wave fail | Present all failures. Offer: retry wave, skip wave, or stop. |
313
+ | Sub-agent timeout | Treat as failure for that phase. Other phases unaffected. |
314
+ | Invalid JSON return | Treat as failure for that phase. |
315
+
316
+ **Key rule**: A failed phase in a wave does NOT cancel other phases in the same wave. Parallel phases are independent — let them all complete.
317
+
318
+ ### Git Commit Ordering
319
+
320
+ When `commit: true` in `.flowconfig`, git commits happen **after** the wave completes, **per-task in phase order then task order**:
321
+
322
+ ```
323
+ Wave 1 complete:
324
+ Phase 1, Task 1: git add -A && git commit -m "feat(phase-1.task-1): Define user and session types — feature-name"
325
+ Phase 1, Task 2: git add -A && git commit -m "feat(phase-1.task-2): Create user schema with Prisma — feature-name"
326
+ Phase 2, Task 1: git add -A && git commit -m "feat(phase-2.task-1): Implement utility helpers — feature-name"
327
+ Phase 2, Task 2: git add -A && git commit -m "feat(phase-2.task-2): Add string formatting utils — feature-name"
328
+ ```
329
+
330
+ The coordinator iterates each phase's `tasks_completed` array (from the JSON return) in task_number order. This ensures **deterministic, fine-grained commit history** regardless of which sub-agent finished first. See `.claude/resources/core/atomic-commits.md` for the full commit format spec.
331
+
332
+ ---
333
+
334
+ ## Configuration
335
+
336
+ ### `.flowconfig` Setting
337
+
338
+ ```yaml
339
+ wave_execution: true # Enable wave-based parallel execution (default: true)
340
+ ```
341
+
342
+ - `true` (default): Analyze dependencies and execute in parallel waves
343
+ - `false`: Sequential execution (ignore Dependencies, legacy behavior)
344
+
345
+ ### Toggle via `/flow`
346
+
347
+ ```
348
+ /flow wave_execution=true
349
+ /flow wave_execution=false
350
+ ```
351
+
352
+ ### Interaction Matrix
353
+
354
+ | wave_execution | phase_isolation | model_routing | Behavior |
355
+ |---------------|-----------------|---------------|----------|
356
+ | `true` | `true` | `true` | Full parallel: waves + isolated sub-agents + correct tier models |
357
+ | `true` | `true` | `false` | Parallel waves + isolated sub-agents + session model |
358
+ | `true` | `false` | `true` | Parallel waves + inline execution per phase + correct tier models |
359
+ | `true` | `false` | `false` | Parallel waves + inline execution + session model |
360
+ | `false` | `true` | `true` | Sequential + isolated sub-agents + correct tier models (existing behavior) |
361
+ | `false` | `true` | `false` | Sequential + isolated sub-agents + session model |
362
+ | `false` | `false` | `true` | Sequential + inline + correct tier models |
363
+ | `false` | `false` | `false` | Sequential + inline + session model (original behavior) |
364
+
365
+ **Note**: `wave_execution: true` requires `phase_isolation: true` for best results. Without phase isolation, parallel execution still works but sub-agents share the session context, which may cause interference.
366
+
367
+ ### Interaction with Aggregation
368
+
369
+ When phases are aggregated (combined complexity ≤ 6), aggregated phases are treated as a **single unit** for wave analysis:
370
+ - They share one dependency set (union of all aggregated phases' dependencies)
371
+ - They produce one wave slot
372
+ - They run as one sub-agent call (same as current aggregation behavior)
373
+
374
+ ---
375
+
376
+ ## Rules
377
+
378
+ 1. **Planning stays sequential** — approve each phase before wave execution begins
379
+ 2. **Tests never parallel** — tests phase always runs alone in the final wave
380
+ 3. **No cross-phase awareness** — sub-agents in the same wave know nothing about each other
381
+ 4. **Deterministic commits** — git commits happen sequentially in phase order after wave completes
382
+ 5. **Failures are isolated** — one failed phase does not cancel sibling phases in the same wave
383
+ 6. **Backward compatible** — plans without Dependencies fields execute sequentially (no behavior change)
384
+ 7. **User controls** — user can always choose sequential execution at the wave summary prompt
385
+ 8. **File conflicts are presented** — never silently resolve file conflicts, always ask the user
386
+ 9. **Reuse phase-isolation format** — sub-agent prompts and JSON returns follow phase-isolation.md exactly
387
+ 10. **Wave analysis is fast** — dependency parsing and topological sort add negligible overhead
388
+ 11. **Verification is internal to sub-agents** — per-task verification loops run entirely inside each phase sub-agent. The wave coordinator does not interact with verification; it only processes the final `task_verifications` field from the JSON return. See `.claude/resources/core/per-task-verification.md` for the complete verification system.
389
+ 12. **Shared context per wave** — each wave creates a fresh `.wave-context.jsonl` file, deleted after post-wave processing
390
+ 13. **Contract conflicts require user intervention** — never silently resolve conflicting contract signatures between parallel phases
391
+ 14. **Append-only context** — sub-agents only append to `.wave-context.jsonl`, never edit or delete existing entries
392
+
393
+ ---
394
+
395
+ ## Related Files
396
+
397
+ | File | Purpose |
398
+ |------|---------|
399
+ | `.claude/resources/core/phase-isolation.md` | Sub-agent context template, JSON return format, coordinator processing |
400
+ | `.claude/resources/core/discovery-sub-agents.md` | Parallel spawning pattern (3 agents → collect → merge) |
401
+ | `.claude/resources/core/review-multi-agent.md` | Parallel agents with deduplication |
402
+ | `.claude/resources/core/model-routing.md` | Model tier selection per phase complexity |
403
+ | `.claude/resources/core/shared-context.md` | Shared context file format, entry types, and coordination rules |
404
+ | `.claude/resources/core/complexity-scoring.md` | Complexity scores and aggregation rules |
405
+ | `.claude/resources/core/per-task-verification.md` | Per-task verification system, debug sub-agent, and repair loops |
406
+ | `.claude/resources/skills/execute-plan-skill.md` | Execute-plan skill (Steps 2b, 3, 4 modified for waves) |
407
+ | `.claude/resources/patterns/plans-templates.md` | Plan template with Dependencies field |
@@ -74,6 +74,7 @@ Every plan must be divided into implementation phases with clear scope boundarie
74
74
 
75
75
  - **Scope**: What this phase covers
76
76
  - **Complexity**: Score from 0-10
77
+ - **Dependencies**: (Optional) Which phases must complete first
77
78
  - **Tasks**: Checkboxes for tracking
78
79
  - **Build Verification**: Command to verify
79
80
 
@@ -130,6 +131,48 @@ When executing a plan, each phase must trigger **Plan mode** before implementati
130
131
 
131
132
  ---
132
133
 
134
+ ### 13. Declare Phase Dependencies for Parallel Execution
135
+
136
+ Phases may include an optional `**Dependencies**` field to declare which prior phases must complete before execution can begin. This enables wave-based parallel execution where independent phases run simultaneously.
137
+
138
+ **Syntax**:
139
+
140
+ - `**Dependencies**: None` — No dependencies; can run in the first wave
141
+ - `**Dependencies**: Phase 1, Phase 3` — Depends on specific phases completing first
142
+ - **Omitting the field** — Defaults to depending on the immediately previous phase (sequential)
143
+
144
+ **Rules**:
145
+
146
+ 1. Mark phases as `Dependencies: None` when they have no data or code dependency on other phases
147
+ 2. When two or more phases share the same dependency set, they form a wave and can execute in parallel
148
+ 3. The Tests phase always depends on ALL prior phases — never mark it as `Dependencies: None`
149
+ 4. Dependencies must only reference phases with lower numbers (no forward or circular dependencies)
150
+ 5. When uncertain whether phases are independent, default to sequential (omit the field)
151
+ 6. The dependency declaration is metadata for the execution engine — it does not change the phase content
152
+
153
+ **Example** — independent phases forming a parallel wave:
154
+
155
+ ```markdown
156
+ ### Phase 1: Types and Schemas
157
+ **Dependencies**: None
158
+
159
+ ### Phase 2: API Routes
160
+ **Dependencies**: Phase 1
161
+
162
+ ### Phase 3: CLI Commands
163
+ **Dependencies**: Phase 1
164
+
165
+ ### Phase 4: Integration
166
+ **Dependencies**: Phase 2, Phase 3
167
+
168
+ ### Phase 5: Tests (Final)
169
+ **Dependencies**: Phase 1, Phase 2, Phase 3, Phase 4
170
+ ```
171
+
172
+ Phases 2 and 3 can run in parallel (Wave 2). Phase 4 waits for both. Phase 5 waits for all.
173
+
174
+ ---
175
+
133
176
  ## Forbidden Patterns
134
177
 
135
178
  ### 1. DON'T Read or Reference Archived Plans
@@ -210,6 +253,18 @@ Keep discovery documents in `flow/discovery/` and plans in `flow/plans/`.
210
253
 
211
254
  ---
212
255
 
256
+ ### 14. DON'T Mark the Tests Phase as Independent
257
+
258
+ The Tests phase must always depend on ALL prior phases. Never assign `Dependencies: None` to the Tests phase.
259
+
260
+ ---
261
+
262
+ ### 15. DON'T Create Circular or Forward Dependencies
263
+
264
+ Dependencies must only reference phases with lower numbers. A phase cannot depend on itself or on any phase that comes after it.
265
+
266
+ ---
267
+
213
268
  ## Summary
214
269
 
215
270
  Following these planning patterns ensures:
@@ -223,3 +278,4 @@ Following these planning patterns ensures:
223
278
  - **Clarity**: Archived plans are ignored, only active plans are referenced
224
279
  - **Intelligent Pacing**: Complexity scores guide execution strategy
225
280
  - **Collaborative Execution**: Plan mode ensures user approval before each phase
281
+ - **Parallel Execution**: Dependency declarations enable wave-based parallel phase execution