planflow-ai 1.3.4 → 1.4.1

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 (90) hide show
  1. package/.claude/commands/create-plan.md +11 -0
  2. package/.claude/commands/discovery-plan.md +12 -0
  3. package/.claude/commands/execute-plan.md +114 -23
  4. package/.claude/commands/flow.md +30 -5
  5. package/.claude/commands/resume-work.md +261 -0
  6. package/.claude/commands/review-code.md +11 -0
  7. package/.claude/commands/review-pr.md +11 -0
  8. package/.claude/resources/core/_index.md +45 -2
  9. package/.claude/resources/core/atomic-commits.md +380 -0
  10. package/.claude/resources/core/autopilot-mode.md +3 -2
  11. package/.claude/resources/core/compaction-guide.md +15 -1
  12. package/.claude/resources/core/heartbeat.md +129 -1
  13. package/.claude/resources/core/model-routing.md +6 -2
  14. package/.claude/resources/core/per-task-verification.md +362 -0
  15. package/.claude/resources/core/phase-isolation.md +192 -4
  16. package/.claude/resources/core/session-scratchpad.md +1 -0
  17. package/.claude/resources/core/wave-execution.md +329 -0
  18. package/.claude/resources/patterns/plans-patterns.md +56 -0
  19. package/.claude/resources/patterns/plans-templates.md +152 -0
  20. package/.claude/resources/skills/_index.md +8 -6
  21. package/.claude/resources/skills/create-plan-skill.md +71 -5
  22. package/.claude/resources/skills/execute-plan-skill.md +357 -12
  23. package/.claude/resources/skills/resume-work-skill.md +159 -0
  24. package/.claude/rules/core/forbidden-patterns.md +38 -0
  25. package/dist/cli/commands/init.js +1 -1
  26. package/dist/cli/commands/init.js.map +1 -1
  27. package/dist/cli/commands/state.d.ts +12 -0
  28. package/dist/cli/commands/state.d.ts.map +1 -0
  29. package/dist/cli/commands/state.js +47 -0
  30. package/dist/cli/commands/state.js.map +1 -0
  31. package/dist/cli/daemon/desktop-notifier.d.ts +16 -0
  32. package/dist/cli/daemon/desktop-notifier.d.ts.map +1 -0
  33. package/dist/cli/daemon/desktop-notifier.js +53 -0
  34. package/dist/cli/daemon/desktop-notifier.js.map +1 -0
  35. package/dist/cli/daemon/event-writer.d.ts +22 -0
  36. package/dist/cli/daemon/event-writer.d.ts.map +1 -0
  37. package/dist/cli/daemon/event-writer.js +76 -0
  38. package/dist/cli/daemon/event-writer.js.map +1 -0
  39. package/dist/cli/daemon/heartbeat-daemon.js +81 -1
  40. package/dist/cli/daemon/heartbeat-daemon.js.map +1 -1
  41. package/dist/cli/daemon/log-writer.d.ts +17 -0
  42. package/dist/cli/daemon/log-writer.d.ts.map +1 -0
  43. package/dist/cli/daemon/log-writer.js +62 -0
  44. package/dist/cli/daemon/log-writer.js.map +1 -0
  45. package/dist/cli/daemon/notification-router.d.ts +17 -0
  46. package/dist/cli/daemon/notification-router.d.ts.map +1 -0
  47. package/dist/cli/daemon/notification-router.js +35 -0
  48. package/dist/cli/daemon/notification-router.js.map +1 -0
  49. package/dist/cli/daemon/prompt-manager.d.ts +27 -0
  50. package/dist/cli/daemon/prompt-manager.d.ts.map +1 -0
  51. package/dist/cli/daemon/prompt-manager.js +107 -0
  52. package/dist/cli/daemon/prompt-manager.js.map +1 -0
  53. package/dist/cli/index.js +9 -0
  54. package/dist/cli/index.js.map +1 -1
  55. package/dist/cli/state/flowconfig-parser.d.ts +16 -0
  56. package/dist/cli/state/flowconfig-parser.d.ts.map +1 -0
  57. package/dist/cli/state/flowconfig-parser.js +166 -0
  58. package/dist/cli/state/flowconfig-parser.js.map +1 -0
  59. package/dist/cli/state/heartbeat-state.d.ts +16 -0
  60. package/dist/cli/state/heartbeat-state.d.ts.map +1 -0
  61. package/dist/cli/state/heartbeat-state.js +97 -0
  62. package/dist/cli/state/heartbeat-state.js.map +1 -0
  63. package/dist/cli/state/model-router.d.ts +8 -0
  64. package/dist/cli/state/model-router.d.ts.map +1 -0
  65. package/dist/cli/state/model-router.js +36 -0
  66. package/dist/cli/state/model-router.js.map +1 -0
  67. package/dist/cli/state/plan-parser.d.ts +16 -0
  68. package/dist/cli/state/plan-parser.d.ts.map +1 -0
  69. package/dist/cli/state/plan-parser.js +124 -0
  70. package/dist/cli/state/plan-parser.js.map +1 -0
  71. package/dist/cli/state/session-state.d.ts +21 -0
  72. package/dist/cli/state/session-state.d.ts.map +1 -0
  73. package/dist/cli/state/session-state.js +36 -0
  74. package/dist/cli/state/session-state.js.map +1 -0
  75. package/dist/cli/state/state-md-parser.d.ts +18 -0
  76. package/dist/cli/state/state-md-parser.d.ts.map +1 -0
  77. package/dist/cli/state/state-md-parser.js +222 -0
  78. package/dist/cli/state/state-md-parser.js.map +1 -0
  79. package/dist/cli/state/types.d.ts +106 -0
  80. package/dist/cli/state/types.d.ts.map +1 -0
  81. package/dist/cli/state/types.js +8 -0
  82. package/dist/cli/state/types.js.map +1 -0
  83. package/dist/cli/state/wave-calculator.d.ts +18 -0
  84. package/dist/cli/state/wave-calculator.d.ts.map +1 -0
  85. package/dist/cli/state/wave-calculator.js +134 -0
  86. package/dist/cli/state/wave-calculator.js.map +1 -0
  87. package/dist/cli/types.d.ts +15 -0
  88. package/dist/cli/types.d.ts.map +1 -1
  89. package/package.json +4 -2
  90. package/templates/shared/CLAUDE.md.template +4 -0
@@ -21,7 +21,9 @@ This skill is **strictly for creating plan documents**. The process:
21
21
  1. **Reads** the discovery document or gathers requirements
22
22
  2. **Analyzes** complexity and scope
23
23
  3. **Structures** phases with complexity scores
24
- 4. **Generates** a plan markdown file
24
+ 4. **Analyzes** phase independence for parallel execution
25
+ 5. **Generates** verify sections for applicable tasks
26
+ 6. **Generates** a plan markdown file
25
27
 
26
28
  **No code, no implementation, no source file modifications.**
27
29
 
@@ -96,8 +98,10 @@ Create phases following these guidelines:
96
98
 
97
99
  **Scope**: [What this phase covers]
98
100
  **Complexity**: X/10
101
+ **Dependencies**: [None | Phase N, Phase M | omit for sequential default]
99
102
 
100
103
  - [ ] Task 1
104
+ <verify>npx tsc --noEmit src/path/to/file.ts</verify>
101
105
  - [ ] Task 2
102
106
 
103
107
  **Build Verification**: Run `npm run build`
@@ -122,9 +126,64 @@ Create phases following these guidelines:
122
126
  | 7-8 | High | Complex, multiple considerations |
123
127
  | 9-10 | Very High | Significant complexity/risk |
124
128
 
129
+ #### Auto-Generating Verify Sections
130
+
131
+ When creating tasks within phases, auto-generate `<verify>` tags based on the task type using these heuristics:
132
+
133
+ | Task Type | Verify Command | When to Apply |
134
+ |-----------|---------------|---------------|
135
+ | File creation (`.ts`, `.tsx`) | `npx tsc --noEmit <file>` | Task creates or modifies a TypeScript source file |
136
+ | Test writing | `npx jest <test-file> --no-coverage` | Task creates or modifies a test file |
137
+ | Schema/type definition | `npx tsc --noEmit <type-file>` | Task creates or modifies type definitions or schemas |
138
+ | Config file changes | No verify | Task modifies `.flowconfig`, `tsconfig.json`, or similar config files |
139
+ | Documentation/markdown | No verify | Task creates or updates `.md` files |
140
+ | Generic/ambiguous tasks | No verify | Task description does not clearly indicate a verifiable output file |
141
+
142
+ **Rules for auto-generation:**
143
+
144
+ 1. Only generate `<verify>` when the task clearly references a specific file path
145
+ 2. Use the file path from the task description in the verify command
146
+ 3. Prefer `npx tsc --noEmit` for source files and `npx jest --no-coverage` for test files
147
+ 4. When in doubt, omit the `<verify>` tag — false verification commands are worse than no verification
148
+ 5. Never generate full-build commands (`npm run build`) as verify tags — those belong in Build Verification
149
+
150
+ ---
151
+
152
+ ### Step 4: Analyze Phase Dependencies
153
+
154
+ After structuring phases, analyze which phases are independent and can run in parallel:
155
+
156
+ 1. **For each phase**, determine its data and code dependencies on other phases:
157
+ - Does this phase use types/interfaces defined in another phase?
158
+ - Does this phase call functions or APIs created in another phase?
159
+ - Does this phase modify files that another phase also modifies?
160
+
161
+ 2. **Mark independent phases** with `**Dependencies**: None` when they:
162
+ - Only depend on pre-existing code (not created in this plan)
163
+ - Have no shared file modifications with other phases in the same wave
164
+ - Can be implemented and verified independently
165
+
166
+ 3. **Mark dependent phases** with explicit dependency lists:
167
+ - `**Dependencies**: Phase 1` — depends on one phase
168
+ - `**Dependencies**: Phase 1, Phase 3` — depends on multiple phases
169
+ - List only **direct** dependencies (not transitive ones)
170
+
171
+ 4. **Default to sequential** (omit the field) when:
172
+ - Unsure whether phases are truly independent
173
+ - Phases touch overlapping files
174
+ - The dependency relationship is ambiguous
175
+
176
+ 5. **Tests phase**: Always list ALL prior phases as dependencies. The Tests phase is never parallelized.
177
+
178
+ **Common independence patterns**:
179
+ - Types/schemas phase is often `Dependencies: None` (foundational, no prior phases needed)
180
+ - Backend API and CLI commands may be independent if they don't share code
181
+ - Store and UI phases often depend on types but may be independent of each other
182
+ - Integration phases typically depend on multiple prior phases
183
+
125
184
  ---
126
185
 
127
- ### Step 4: Add Key Changes Summary
186
+ ### Step 5: Add Key Changes Summary
128
187
 
129
188
  Document the most important modifications:
130
189
 
@@ -137,7 +196,7 @@ Document the most important modifications:
137
196
 
138
197
  ---
139
198
 
140
- ### Step 5: Generate Plan Document
199
+ ### Step 6: Generate Plan Document
141
200
 
142
201
  Create the plan markdown file:
143
202
 
@@ -152,7 +211,7 @@ Create the plan markdown file:
152
211
  3. Non-Goals
153
212
  4. Requirements Summary (FR, NFR, Constraints)
154
213
  5. Risks
155
- 6. Phases (with complexity scores)
214
+ 6. Phases (with complexity scores and optional dependency declarations)
156
215
  7. Key Changes
157
216
 
158
217
  ---
@@ -217,8 +276,10 @@ The plan document should follow the template in `.claude/resources/patterns/plan
217
276
 
218
277
  **Scope**: [What this phase covers]
219
278
  **Complexity**: X/10
279
+ **Dependencies**: None
220
280
 
221
281
  - [ ] Task 1
282
+ <verify>npx tsc --noEmit src/path/to/file.ts</verify>
222
283
  - [ ] Task 2
223
284
 
224
285
  **Build Verification**: Run `npm run build`
@@ -227,8 +288,10 @@ The plan document should follow the template in `.claude/resources/patterns/plan
227
288
 
228
289
  **Scope**: Write comprehensive tests
229
290
  **Complexity**: X/10
291
+ **Dependencies**: Phase 1, Phase 2, ..., Phase N-1
230
292
 
231
293
  - [ ] Unit tests
294
+ <verify>npx jest src/path/to/test.ts --no-coverage</verify>
232
295
  - [ ] Integration tests
233
296
 
234
297
  **Build Verification**: Run `npm run build && npm run test`
@@ -247,9 +310,12 @@ Before completing the plan, verify:
247
310
  - [ ] Plan is saved in `flow/plans/` folder
248
311
  - [ ] File uses snake_case naming: `plan_<feature>_v<version>.md`
249
312
  - [ ] All phases have complexity scores (X/10)
250
- - [ ] Tests are the LAST phase
313
+ - [ ] Phase dependencies are analyzed and declared where appropriate
314
+ - [ ] Tests are the LAST phase with dependencies on ALL prior phases
251
315
  - [ ] Key Changes section is populated
252
316
  - [ ] Discovery document is referenced (discovery is required, never skipped)
317
+ - [ ] Verify sections are generated for applicable tasks (file creation, test writing, schema/type tasks)
318
+ - [ ] Verify sections are omitted for config, documentation, and generic tasks
253
319
  - [ ] **NO implementation code is included**
254
320
  - [ ] **NO source files were created or modified**
255
321
 
@@ -9,6 +9,7 @@ This skill **implements the plan** by:
9
9
 
10
10
  - Reading and parsing the plan file
11
11
  - Grouping phases by complexity
12
+ - Analyzing dependencies and grouping into parallel waves (when enabled)
12
13
  - Switching to Plan mode for each phase
13
14
  - Implementing after user approval
14
15
  - Updating progress in the plan file
@@ -149,9 +150,41 @@ Execution Groups:
149
150
 
150
151
  ---
151
152
 
153
+ ### Step 2b: Wave Analysis (Wave Execution)
154
+
155
+ **Condition**: Only run this step when `wave_execution` is `true` in `flow/.flowconfig` (default: `true`). If `wave_execution` is `false` or the key is missing, skip entirely — proceed to Step 3 with sequential grouping only.
156
+
157
+ Read `.claude/resources/core/wave-execution.md` for the full system reference.
158
+
159
+ 1. **Parse Dependencies**: For each phase, look for a `**Dependencies**:` line:
160
+ - `Phase 1, Phase 3` → depends on those phases completing first
161
+ - `None` → explicitly independent, can run in Wave 1 (if no other constraints)
162
+ - Missing field → implicit dependency on Phase N-1 (Phase 1 has no implicit dependency)
163
+ - Self-references and references to non-existent phases are ignored (warn on non-existent)
164
+
165
+ 2. **Build dependency graph**: Map each phase to its dependency set (after applying defaults).
166
+
167
+ 3. **Topological sort → assign wave numbers**:
168
+ - Phases with no dependencies → Wave 1
169
+ - For each remaining phase: `wave = max(wave of each dependency) + 1`
170
+ - Tests phase exception: Move to its own final wave regardless of computed wave number
171
+ - On circular dependency: warn user and **fall back to sequential execution**
172
+
173
+ 4. **Apply aggregation to waves**: If phases within the same wave are adjacent and their combined complexity ≤ 6, aggregate them into a single sub-agent call (same aggregation rules as Step 2). Aggregated phases share one wave slot and one dependency set (union of all their dependencies).
174
+
175
+ 5. **Estimate speedup**: Compare number of sequential phases vs number of waves.
176
+
177
+ 6. **Store wave plan** for use in Steps 3 and 4.
178
+
179
+ **Backward compatibility**: Plans without any `Dependencies` fields produce a fully sequential wave plan (one phase per wave). This matches existing behavior exactly — no regression.
180
+
181
+ ---
182
+
152
183
  ### Step 3: Present Execution Plan Summary
153
184
 
154
- Before starting, present the execution plan to the user:
185
+ Before starting, present the execution plan to the user.
186
+
187
+ **When wave execution is disabled** (or wave plan is fully sequential), present the standard summary:
155
188
 
156
189
  ```markdown
157
190
  ## Execution Plan Summary
@@ -174,6 +207,36 @@ Before starting, present the execution plan to the user:
174
207
  Ready to begin execution?
175
208
  ```
176
209
 
210
+ **When wave execution is enabled** and the wave plan contains at least one wave with multiple phases, present the wave execution summary:
211
+
212
+ ```markdown
213
+ ## Execution Plan Summary
214
+
215
+ **Plan**: [Plan Name]
216
+ **Total Phases**: X
217
+ **Total Complexity**: XX/XX
218
+ **Execution Mode**: Wave-based parallel
219
+
220
+ ### Wave Execution Plan:
221
+
222
+ | Wave | Phases | Parallel |
223
+ |------|--------|----------|
224
+ | 1 | Phase 1: Types, Phase 2: Utilities | Yes (2 parallel) |
225
+ | 2 | Phase 3: API Integration | No (1 phase) |
226
+ | 3 | Phase 4: Config Updates | No (1 phase) |
227
+ | 4 | Phase 5: Tests | No (always sequential) |
228
+
229
+ **Sequential phases**: 5 → **Waves**: 4 → **Estimated speedup**: ~20%
230
+ **Build Verification**: Only at the end, after ALL phases complete
231
+
232
+ Proceed with wave execution? (yes/no/sequential)
233
+ ```
234
+
235
+ User response options for wave execution:
236
+ - **yes**: Execute with wave parallelism
237
+ - **no**: Stop execution
238
+ - **sequential**: Fall back to sequential execution (ignore waves, use standard Step 4)
239
+
177
240
  Wait for user confirmation before proceeding.
178
241
 
179
242
  ---
@@ -184,16 +247,18 @@ Wait for user confirmation before proceeding.
184
247
 
185
248
  **REMINDER**: Do NOT run `npm run build` between phases.
186
249
 
250
+ #### Step 4 — Sequential Mode (default, or when wave_execution is disabled)
251
+
187
252
  **For Each Phase**:
188
253
 
189
254
  1. **Auto-switch to Plan mode** - Call `SwitchMode` tool
190
255
  2. **Present phase details** - Show scope, tasks, and approach
191
256
  3. **Wait for approval** - Get user confirmation
192
- 4. **Select model tier** - If `model_routing` is enabled in `flow/.flowconfig` (default: `true`):
257
+ 4. **Select model tier** - If `model_routing` is enabled in `flow/.flowconfig` (default: `false` — uses the most capable session model):
193
258
  - Read the phase's complexity score
194
259
  - Look up model tier: **0-3 → Fast (haiku)**, **4-5 → Standard (sonnet)**, **6-10 → Powerful (opus)**
195
260
  - For aggregated phases, use the **highest individual phase complexity** to determine the tier
196
- - If `model_routing` is `false` or key is missing, skip routing (use session model)
261
+ - If `model_routing` is `false` or key is missing, skip routing (use the most capable model from the active provider — e.g., opus for Anthropic, o3 for OpenAI)
197
262
  - See `.claude/resources/core/model-routing.md` for full tier table, platform mappings, and rules
198
263
  5. **Inject design context** - Before implementing, check if the discovery doc (from plan's "Based on Discovery" field) has a `## Design Context` section. If present and the phase involves UI work (see UI Phase Detection Heuristics in `.claude/resources/core/design-awareness.md`), include the Design Context in the implementation prompt. If no Design Context or phase is not UI-related, skip this step.
199
264
  6. **Implement (with phase isolation)** - Check `phase_isolation` in `flow/.flowconfig` (default: `true`):
@@ -206,10 +271,106 @@ Wait for user confirmation before proceeding.
206
271
  - Append `patterns_captured` entries to `flow/resources/pending-patterns.md`
207
272
  - Log `decisions` in phase completion message
208
273
  - If inline mode (no isolation), capture patterns directly per `.claude/resources/core/pattern-capture.md`
274
+ - **Process task verifications** (if `task_verifications` array is present in the return):
275
+ - Count pass/fail totals and sum repairs applied
276
+ - Display a brief verification summary after the phase completion message:
277
+ ```
278
+ Task Verification: X/Y passed | Z repairs applied
279
+ ```
280
+ - If any task verification has `status: "fail"`, present each failed task with its last diagnosis and offer options:
281
+ ```
282
+ ⚠️ Task verification failed after N retries:
283
+ **Task**: <task description>
284
+ **Command**: <verify command>
285
+ **Last diagnosis**: <root_cause from last_diagnosis>
286
+ **Category**: <category from last_diagnosis>
287
+
288
+ Options:
289
+ 1. Continue with remaining phases (issue noted)
290
+ 2. Stop and fix manually
291
+ ```
209
292
  8. **Update progress** - Mark tasks complete in plan file
293
+ - **Note**: Sub-agent creates per-task commits directly (if `commit: true`). Coordinator does NOT create a phase-level commit. See `.claude/resources/core/atomic-commits.md` for commit format: `feat(phase-N.task-M): <desc> — <feature>`
210
294
  9. **Record model used** - Track which model tier was used for this phase (for the completion summary)
211
295
  10. **Continue to next phase** - NO BUILD between phases
212
296
 
297
+ #### Step 4 — Wave Mode (when wave_execution is enabled and user chose "yes")
298
+
299
+ Execute phases **wave by wave**. Within each wave, approve phases sequentially in Plan Mode, then spawn all wave phases as parallel Agent sub-agents.
300
+
301
+ **For Each Wave**:
302
+
303
+ ##### 4a. Sequential Approval (Plan Mode)
304
+
305
+ For each phase in the current wave (in phase number order):
306
+
307
+ 1. **Auto-switch to Plan mode** - Call `SwitchMode` tool
308
+ 2. **Present phase details** - Show scope, tasks, approach, and wave context (e.g., "Wave 2 of 4, running in parallel with Phase 5")
309
+ 3. **Wait for approval** - Get user confirmation
310
+ 4. **Select model tier** - Same rules as sequential mode (step 4.4 above)
311
+ 5. **Inject design context** - Same rules as sequential mode (step 4.5 above)
312
+
313
+ After ALL phases in the wave are approved, proceed to parallel spawning.
314
+
315
+ ##### 4b. Parallel Spawning
316
+
317
+ Launch all approved wave phases simultaneously as independent Agent sub-agents:
318
+
319
+ 1. **Prepare context for each phase**: Use the phase-isolation context template (see `.claude/resources/core/phase-isolation.md`). Key addition for wave execution: the `Files Modified in Previous Phases` section includes files from ALL completed waves (1 through N-1), not just the immediately preceding phase.
320
+ 2. **No cross-phase awareness**: Sub-agents within the same wave do NOT know about each other. They receive no information about sibling phases.
321
+ 3. **Spawn all in parallel**: Launch all wave phases simultaneously using Agent sub-agents with their respective model tiers.
322
+ 4. **Wait for all to complete**: All sub-agents must return before post-wave processing.
323
+
324
+ ##### 4c. Wave Coordinator — Post-Wave Processing
325
+
326
+ After all sub-agents in the wave return, process results **sequentially in phase number order**:
327
+
328
+ 1. **Collect JSON returns**: Gather the structured JSON summary from each sub-agent
329
+ 2. **Validate JSON**: Parse each return, check for required fields (status, phase, summary, files_created, files_modified)
330
+ 3. **Detect file conflicts**: Check for `files_modified` overlap between phases in this wave:
331
+ - For each pair of phases (A, B) in the wave: compute `overlap = A.files_modified ∩ B.files_modified`
332
+ - If overlap is not empty → file conflict detected
333
+ 4. **Handle file conflicts** (if any):
334
+ - Present the conflicting files and which phases modified them
335
+ - Offer options:
336
+ - **(1) Accept as-is**: Last writer wins (the phase with the higher number committed last)
337
+ - **(2) Re-run conflicting phases sequentially**: Re-execute only the conflicting phases in order
338
+ - **(3) Stop execution**: Halt for manual resolution
339
+ - File conflicts do NOT affect non-conflicting phases — their results are preserved
340
+ 5. **Process each phase** (in phase number order):
341
+ - Check `status` field: `success` → continue; `failure` → present errors, ask retry/skip/stop; `partial` → present deviations, ask user
342
+ - Update plan file (mark tasks `[x]`)
343
+ - Accumulate `files_created` and `files_modified` into running list
344
+ - Buffer `patterns_captured` entries to `flow/resources/pending-patterns.md`
345
+ - Git commit if enabled (sequential, one commit **per task** in phase/task order — see `.claude/resources/core/atomic-commits.md`). For each phase (in phase number order), iterate `tasks_completed` and commit: `git add -A && git commit -m "feat(phase-N.task-M): <desc> — <feature>"`
346
+ - Log `decisions` in phase completion message
347
+ 6. **Report wave completion**: Present summary of all phases in this wave, including task verification stats:
348
+ - For each phase in the wave that returned `task_verifications`, include pass/fail counts and repairs applied
349
+ - Wave completion report template:
350
+ ```
351
+ Wave N complete: X phases finished
352
+ - Phase A: success (Task Verification: 3/3 passed | 1 repair applied)
353
+ - Phase B: success (no verifications)
354
+ - Phase C: partial (Task Verification: 2/3 passed, 1 failed | 0 repairs applied)
355
+ ```
356
+ - If any task verification failed, display the failed task details (same format as sequential mode step 7)
357
+
358
+ ##### 4d. Wave Failure Handling
359
+
360
+ | Scenario | Behavior |
361
+ |----------|----------|
362
+ | One phase fails, others succeed | Process successful phases normally. Present failure to user. Offer: retry failed phase, skip it, or stop. |
363
+ | Multiple phases fail | Process any successful phases. Present all failures. Offer same options per failed phase. |
364
+ | All phases in wave fail | Present all failures. Offer: retry wave, skip wave, or stop. |
365
+ | Sub-agent timeout | Treat as failure for that phase. Other phases unaffected. |
366
+ | Invalid JSON return | Treat as failure for that phase. |
367
+
368
+ **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.
369
+
370
+ ##### 4e. Continue to Next Wave
371
+
372
+ After post-wave processing is complete (all commits done, failures handled), proceed to the next wave. Repeat from Step 4a.
373
+
213
374
  **Phase Presentation Template**:
214
375
 
215
376
  ```markdown
@@ -218,6 +379,8 @@ Wait for user confirmation before proceeding.
218
379
  **Complexity**: X/10
219
380
  **Scope**: [Phase scope description]
220
381
  **Design Context**: Available / Not applicable
382
+ **Wave**: [Wave N of M] / [Sequential]
383
+ **Parallel with**: [Phase Y, Phase Z] / [None]
221
384
 
222
385
  ### Tasks to Complete:
223
386
  - [ ] Task 1
@@ -240,6 +403,20 @@ Wait for user confirmation before proceeding.
240
403
 
241
404
  ---
242
405
 
406
+ ### Step 4f: STATE.md Phase Lifecycle Updates
407
+
408
+ Update `flow/STATE.md` at each phase transition to enable session resumability:
409
+
410
+ 1. **Before phase starts**: Update `Current Phase: {N} — {Phase Name}`, `Current Task: first task`, `Next Action: Implement phase {N}`
411
+ 2. **During phase** (inline mode only): Update `Current Task` as tasks progress; append decisions/blockers as they occur
412
+ 3. **After phase completes**: Append to `Completed Phases`: `Phase N: Name — {outcome}`. Set `Current Phase: none`, `Current Task: none`. Append new files to `Files Modified`. Set `Next Action: Begin phase {N+1}` (or `Run build verification` if last phase)
413
+ 4. **On phase failure**: Append to `Blockers`: `Phase {N} failed: {error} (status: open, tried: {attempts})`
414
+ 5. **Wave mode**: Update STATE.md once before each wave (set current wave phases) and once after each wave completes (batch-update completed phases)
415
+
416
+ **Important**: In isolation mode, the coordinator (main session) handles STATE.md updates — sub-agents do not write to STATE.md.
417
+
418
+ ---
419
+
243
420
  ### Step 5: Update Progress After Each Phase
244
421
 
245
422
  Mark completed tasks in the plan file:
@@ -251,6 +428,8 @@ Mark completed tasks in the plan file:
251
428
 
252
429
  Then continue to the next phase (NO BUILD HERE).
253
430
 
431
+ **Note**: In wave mode, progress updates happen during post-wave processing (Step 4c.5) rather than after each individual phase spawn. The coordinator handles updates sequentially in phase order after all wave sub-agents return.
432
+
254
433
  ---
255
434
 
256
435
  ### Step 5b: Phase-Boundary Context Check
@@ -262,16 +441,19 @@ Then continue to the next phase (NO BUILD HERE).
262
441
  - Multiple phases completed and more remain
263
442
  - You're about to start a complex phase (complexity >= 6)
264
443
 
444
+ **In wave mode**: Compact at **wave boundaries** (between waves), not between phases within a wave. Include wave progress in the compact summary.
445
+
265
446
  **How to compact at a phase boundary**:
266
447
 
267
448
  Run `/compact` with instructions that preserve execution state:
268
449
 
269
450
  ```
270
- /compact Executing plan: [plan file path]. Completed phases: [list]. Next phase: [name and scope]. Key files modified: [list]. Active tasklist items: [list from flow/tasklist.md]. Resume execution from phase [N].
451
+ /compact Executing plan: [plan file path]. Completed phases: [list]. Completed waves: [N of M]. Next wave: [wave N, phases: list]. Key files modified: [list]. Active tasklist items: [list from flow/tasklist.md]. Resume execution from wave [N] / phase [N].
271
452
  ```
272
453
 
273
454
  **Rules**:
274
455
  - NEVER compact mid-phase — only at phase boundaries (between phases)
456
+ - In wave mode, NEVER compact mid-wave — only at wave boundaries (between waves)
275
457
  - Always include enough context in the compact instructions to resume
276
458
  - After compaction, re-read the plan file and continue from the next phase
277
459
  - In autopilot mode, compact automatically without asking — this is a maintenance action, not a user decision
@@ -291,6 +473,8 @@ The Tests phase is **always executed separately**, regardless of complexity scor
291
473
  5. Implement tests
292
474
  6. **DO NOT run tests yet** - Continue to Step 7
293
475
 
476
+ **Wave mode note**: The tests phase always runs alone in its own final wave. This is enforced during wave analysis (Step 2b.3) — the tests phase is moved to a dedicated final wave regardless of its computed wave number.
477
+
294
478
  ---
295
479
 
296
480
  ### Step 7b: Pattern Review
@@ -304,6 +488,82 @@ After all phases are complete but **before** build/test verification, run the pa
304
488
 
305
489
  See `.claude/resources/core/pattern-capture.md` for the full end-of-skill review protocol.
306
490
 
491
+ ### Step 7c: Auto-PR Creation
492
+
493
+ After pattern review completes, optionally create and push a Pull Request if enabled:
494
+
495
+ 1. **Check if PR creation is enabled**: Read `flow/.flowconfig` and look for `pr: true`
496
+ - If `pr` is not set or is `false`, skip this entire step
497
+ - If `pr: true`, proceed to branch creation
498
+
499
+ 2. **Create and push feature branch**:
500
+ - Sanitize feature name: Convert plan name to lowercase, replace spaces and special characters (except hyphens) with hyphens, trim leading/trailing hyphens
501
+ - Example: "Add User Authentication" → `add-user-authentication`, "Feature (WIP)" → `feature-wip`
502
+ - Create branch: `git checkout -b feat/<sanitized-feature-name>`
503
+ - Check for pre-existing branch: If the branch already exists, warn the user and skip branch creation — proceed with PR creation using the existing branch
504
+ - Push branch: `git push -u origin feat/<sanitized-feature-name>`
505
+
506
+ 3. **Determine base branch**:
507
+ - Read `flow/.flowconfig` and check for `branch` setting
508
+ - If `branch` is set, use that as the base branch
509
+ - If `branch` is not set, detect the repository's default branch:
510
+ ```bash
511
+ gh repo view --json defaultBranchRef -q '.defaultBranchRef.name'
512
+ ```
513
+ - If `gh` CLI is not found or the command fails, default to `main`
514
+
515
+ 4. **Create Pull Request**:
516
+ - Title format: `feat: <plan-name>` (use the plan's name from the plan file)
517
+ - Body format: Include plan overview and list of completed phases:
518
+ ```markdown
519
+ ## Overview
520
+ <Summary of the plan>
521
+
522
+ ## Completed Phases
523
+ - Phase 1: <Phase Name>
524
+ - Phase 2: <Phase Name>
525
+ - Phase 3: <Phase Name>
526
+ ```
527
+ - Command:
528
+ ```bash
529
+ gh pr create --base <base-branch> --head feat/<sanitized-feature-name> --title "feat: <plan-name>" --body "<body>"
530
+ ```
531
+ - Capture the PR URL from the command output (format: `https://github.com/<owner>/<repo>/pull/<number>`)
532
+
533
+ 5. **Handle PR creation errors gracefully**:
534
+ - If `gh` CLI is not found or not installed, warn the user: `⚠️ GitHub CLI (gh) not found. Please create a PR manually: git push -u origin feat/<branch-name>`
535
+ - If `gh pr create` fails with any error, warn the user with the error message and continue: `⚠️ Failed to create PR: <error message>. You can create it manually on GitHub.`
536
+ - This is a best-effort feature — do not block execution if PR creation fails
537
+
538
+ 6. **Store PR URL**: If PR is created successfully, store the URL for use in Step 7 completion summary
539
+
540
+ **Branch Naming Convention**:
541
+
542
+ Feature branches follow the pattern: `feat/<sanitized-feature-name>`
543
+
544
+ Sanitization rules:
545
+ - Convert to lowercase
546
+ - Replace spaces with hyphens
547
+ - Replace special characters (`/`, `\`, `.`, `@`, etc.) with hyphens (except leading/trailing)
548
+ - Collapse consecutive hyphens into a single hyphen
549
+ - Trim leading and trailing hyphens
550
+ - Result must be a valid git branch name
551
+
552
+ **PR Metadata**:
553
+
554
+ - **Title**: `feat: <plan-name>` — descriptive, follows conventional commits
555
+ - **Body**: Structured markdown with Overview and Completed Phases sections
556
+ - **Base branch**: Either from `.flowconfig` `branch` setting or detected default
557
+ - **Head branch**: `feat/<sanitized-feature-name>`
558
+
559
+ **Notification Enrichment**:
560
+
561
+ When a PR is successfully created, the completion notification event message should be enriched with the PR URL:
562
+ - Without PR: `"All done — plan execution complete"`
563
+ - With PR: `"All done — PR: https://github.com/owner/repo/pull/123"`
564
+
565
+ This allows users to quickly jump to the PR from notifications without needing to search for it.
566
+
307
567
  ---
308
568
 
309
569
  ### Step 7: Completion - Build and Test Verification
@@ -323,17 +583,46 @@ npm run build && npm run test
323
583
  - If tests fail: Fix the issue, re-run verification
324
584
  - Only proceed after everything passes
325
585
 
326
- 3. **Present summary** of completed work, including model routing info if enabled:
586
+ 3. **Present summary** of completed work, including model routing and wave execution info if enabled:
587
+
588
+ **Sequential mode summary**:
327
589
 
328
590
  ```markdown
329
- | Phase | Complexity | Model | Status |
330
- |-------|-----------|-------|--------|
331
- | 1. Setup types | 2/10 | haiku | Done |
332
- | 2. Core logic | 5/10 | sonnet | Done |
333
- | 3. Integration | 7/10 | opus | Done |
334
- | 4. Tests | 4/10 | sonnet | Done |
591
+ | Phase | Complexity | Model | Verification | Status |
592
+ |-------|-----------|-------|--------------|--------|
593
+ | 1. Setup types | 2/10 | haiku | 2/2 passed | Done |
594
+ | 2. Core logic | 5/10 | sonnet | 3/3 passed (1 repair) | Done |
595
+ | 3. Integration | 7/10 | opus | 1/2 passed (1 failed) | Partial |
596
+ | 4. Tests | 4/10 | sonnet | — | Done |
597
+
598
+ **Task verification totals**: 8 verified, 7 passed, 1 failed, 1 repair applied
599
+ **Commits**: 8 atomic commits (per-task)
600
+ **Model routing**: Saved ~X% vs all-opus execution
601
+ **PR**: https://github.com/owner/repo/pull/123
602
+ ```
603
+
604
+ **Wave mode summary** (when wave execution was used):
335
605
 
606
+ ```markdown
607
+ | Wave | Phases | Parallel | Status |
608
+ |------|--------|----------|--------|
609
+ | 1 | Phase 1: Types (haiku), Phase 2: Utilities (haiku) | Yes (2 parallel) | Done |
610
+ | 2 | Phase 3: API Integration (opus) | No | Done |
611
+ | 3 | Phase 4: Config Updates (sonnet) | No | Done |
612
+ | 4 | Phase 5: Tests (sonnet) | No | Done |
613
+
614
+ **Wave execution stats**:
615
+ - Sequential phases: 5
616
+ - Waves executed: 4
617
+ - Parallel phases: 2 (in Wave 1)
618
+ - File conflicts: 0
619
+ - Failed phases: 0
620
+ - Estimated speedup: ~20%
621
+
622
+ **Task verification totals**: 8 verified, 7 passed, 1 failed, 1 repair applied
623
+ **Commits**: 8 atomic commits (per-task)
336
624
  **Model routing**: Saved ~X% vs all-opus execution
625
+ **PR**: https://github.com/owner/repo/pull/123
337
626
  ```
338
627
 
339
628
  4. **List all key changes** made
@@ -348,6 +637,8 @@ mv flow/plans/plan_feature_name_v1.md flow/archive/
348
637
 
349
638
  ## Execution Flow Within a Group
350
639
 
640
+ ### Sequential Mode
641
+
351
642
  ```
352
643
  Group 1: Phase 1 + Phase 2 (combined complexity: 5)
353
644
  |
@@ -366,6 +657,35 @@ Group 1: Phase 1 + Phase 2 (combined complexity: 5)
366
657
  +-- Continue to next group (NO BUILD HERE)
367
658
  ```
368
659
 
660
+ ### Wave Mode
661
+
662
+ ```
663
+ Wave 1: Phase 1 + Phase 2 (parallel, no dependencies)
664
+ |
665
+ +-- APPROVAL PHASE (sequential):
666
+ | +-- AUTO-SWITCH to Plan Mode for Phase 1
667
+ | +-- Present Phase 1 details (Wave 1 of 4, parallel with Phase 2)
668
+ | +-- Get user approval
669
+ | |
670
+ | +-- AUTO-SWITCH to Plan Mode for Phase 2
671
+ | +-- Present Phase 2 details (Wave 1 of 4, parallel with Phase 1)
672
+ | +-- Get user approval
673
+ |
674
+ +-- EXECUTION PHASE (parallel):
675
+ | +-- Spawn Agent: Phase 1 (model: haiku) ──┐
676
+ | +-- Spawn Agent: Phase 2 (model: haiku) ──┤ (running simultaneously)
677
+ | +-- Wait for all to return ──┘
678
+ |
679
+ +-- POST-WAVE PROCESSING (sequential):
680
+ | +-- Collect JSON returns
681
+ | +-- Check for file conflicts
682
+ | +-- Process Phase 1 result → update plan → git commit per task
683
+ | +-- Process Phase 2 result → update plan → git commit per task
684
+ | +-- Report wave completion
685
+ |
686
+ +-- Continue to Wave 2 (NO BUILD HERE)
687
+ ```
688
+
369
689
  ---
370
690
 
371
691
  ## Complexity-Based Behavior
@@ -398,6 +718,21 @@ Group 1: Phase 1 + Phase 2 (combined complexity: 5)
398
718
 
399
719
  ---
400
720
 
721
+ ## Per-Task Verification
722
+
723
+ When plans include tasks with `<verify>` tags, phase sub-agents run targeted verification after each task. If verification fails, a debug sub-agent (haiku) diagnoses the issue and the implementation sub-agent applies repairs automatically (up to `max_verify_retries` attempts, default: 2).
724
+
725
+ The execute-plan skill processes verification results at two levels:
726
+
727
+ 1. **Phase level** (Steps 4/4c): After each sub-agent returns, display per-phase verification summaries and present failed tasks to the user
728
+ 2. **Completion level** (Step 7): Aggregate verification stats across all phases in the final summary
729
+
730
+ Verification is internal to phase sub-agents — the coordinator and main session see only the `task_verifications` array in the JSON return. Plans without `<verify>` tags work unchanged (backward compatible).
731
+
732
+ See `.claude/resources/core/per-task-verification.md` for the full system reference: verify tag syntax, debug sub-agent prompt template, verification loop flow, JSON schemas, and configuration.
733
+
734
+ ---
735
+
401
736
  ## Error Handling
402
737
 
403
738
  ### Build Failures (at Completion)
@@ -429,6 +764,8 @@ If the user wants to stop execution:
429
764
  3. The plan can be resumed later from the last completed phase
430
765
  4. When resuming, run build verification first
431
766
 
767
+ **Wave mode cancellation**: If cancelled mid-wave, all running sub-agents complete (cannot be interrupted), but their results are discarded. Progress is saved up to the last fully completed wave.
768
+
432
769
  ---
433
770
 
434
771
  ## Summary of Key Rules
@@ -438,8 +775,13 @@ If the user wants to stop execution:
438
775
  | **Auto-switch to Plan mode** | Switch immediately for each phase, no asking |
439
776
  | **Build ONLY at end** | `npm run build && npm run test` runs once, after ALL phases |
440
777
  | **No intermediate builds** | Never run build between phases or groups |
441
- | **Tests phase separate** | Always execute Tests phase individually |
778
+ | **Tests phase separate** | Always execute Tests phase individually, in its own final wave |
442
779
  | **Update progress** | Mark tasks complete in plan file after each phase |
780
+ | **Wave fallback** | When wave_execution disabled or all phases dependent, execute sequentially (no behavior change) |
781
+ | **Approve then spawn** | In wave mode, approve ALL wave phases before spawning any |
782
+ | **Deterministic commits** | Git commits happen per-task in phase/task order after wave completes: `feat(phase-N.task-M): <desc> — <feature>` |
783
+ | **Failures are isolated** | One failed phase does not cancel sibling phases in the same wave |
784
+ | **File conflicts presented** | Never silently resolve file conflicts, always ask the user |
443
785
 
444
786
  ---
445
787
 
@@ -449,6 +791,9 @@ If the user wants to stop execution:
449
791
  | ------------------------------------------- | -------------------------------- |
450
792
  | `.claude/resources/patterns/plans-patterns.md` | Plan patterns and rules |
451
793
  | `.claude/resources/core/complexity-scoring.md` | Complexity scoring system |
794
+ | `.claude/resources/core/wave-execution.md` | Wave-based parallel execution system |
795
+ | `.claude/resources/core/phase-isolation.md` | Phase isolation and sub-agent spawning |
796
+ | `.claude/resources/core/per-task-verification.md` | Per-task verification system and debug sub-agents |
452
797
  | `.claude/resources/tools/plan-mode-tool.md` | Plan mode switching instructions |
453
798
  | `flow/plans/` | Input plan documents |
454
799
  | `flow/archive/` | Completed plans destination |