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
@@ -5,8 +5,8 @@
5
5
 
6
6
  Core rules define the foundational coding standards that apply across the entire project. These include best practices to follow (allowed patterns), anti-patterns to avoid (forbidden patterns), and complexity scoring for implementation planning.
7
7
 
8
- **Total Files**: 22 files, ~3580 lines
9
- **Reference Codes**: COR-AP-1 through COR-DSA-3
8
+ **Total Files**: 25 files, ~5550 lines
9
+ **Reference Codes**: COR-AP-1 through COR-AC-3
10
10
 
11
11
  ---
12
12
 
@@ -177,6 +177,16 @@ Core rules define the foundational coding standards that apply across the entire
177
177
  | COR-DSA-2 | Return format schema and Codebase Analysis section template | discovery-sub-agents.md | 132-190 |
178
178
  | COR-DSA-3 | Coordinator behavior (spawn, collect, merge, error handling) | discovery-sub-agents.md | 192-240 |
179
179
 
180
+ ### Wave Execution (`wave-execution.md`)
181
+
182
+ | Code | Description | Source | Lines |
183
+ |------|-------------|--------|---------|
184
+ | COR-WAVE-1 | Architecture, dependency analysis rules, and declaration syntax | wave-execution.md | 14-80 |
185
+ | COR-WAVE-2 | Wave grouping algorithm (topological sort, backward compatibility, example) | wave-execution.md | 82-140 |
186
+ | COR-WAVE-3 | Parallel spawning rules and wave execution summary format | wave-execution.md | 142-195 |
187
+ | COR-WAVE-4 | Wave coordinator behavior (per-wave processing, file conflict detection, failure handling, git commit ordering) | wave-execution.md | 197-270 |
188
+ | COR-WAVE-5 | Configuration (flowconfig, interaction matrix, aggregation, rules) | wave-execution.md | 272-340 |
189
+
180
190
  ### Review Adaptive Depth (`review-adaptive-depth.md`)
181
191
 
182
192
  | Code | Description | Source | Lines |
@@ -186,6 +196,24 @@ Core rules define the foundational coding standards that apply across the entire
186
196
  | COR-AD-3 | Deep review mode (500+ lines) — categorization, passes, executive summary | review-adaptive-depth.md | 103-187 |
187
197
  | COR-AD-4 | Insertion points for review-code and review-pr skills | review-adaptive-depth.md | 189-205 |
188
198
 
199
+ ### Per-Task Verification (`per-task-verification.md`)
200
+
201
+ | Code | Description | Source | Lines |
202
+ |------|-------------|--------|-------|
203
+ | COR-PTV-1 | Purpose, architecture, and verify-diagnose-repair loop flow | per-task-verification.md | 3-40 |
204
+ | COR-PTV-2 | Verify tag syntax, parsing rules, and debug sub-agent prompt/schema | per-task-verification.md | 42-130 |
205
+ | COR-PTV-3 | Verification loop, retry behavior, and task_verifications return field | per-task-verification.md | 132-200 |
206
+ | COR-PTV-4 | Configuration, error handling, wave mode interaction, and rules | per-task-verification.md | 202-260 |
207
+
208
+ ### Atomic Commits (`atomic-commits.md`)
209
+
210
+ | Code | Description | Source | Lines |
211
+ |------|-------------|--------|-------|
212
+ | COR-AC-1 | Purpose, commit format, and sequential mode behavior | atomic-commits.md | 3-80 |
213
+ | COR-AC-2 | Wave mode behavior, JSON schema extension, and coordinator processing | atomic-commits.md | 82-210 |
214
+ | COR-AC-3 | Interaction with phase isolation, wave execution, verification, and configuration | atomic-commits.md | 212-300 |
215
+
216
+ ---
189
217
  ---
190
218
 
191
219
  ## When to Expand
@@ -256,6 +284,18 @@ Core rules define the foundational coding standards that apply across the entire
256
284
  | COR-DSA-1 | Need discovery sub-agent definitions or prompt templates |
257
285
  | COR-DSA-2 | Need return format schema or Codebase Analysis section template |
258
286
  | COR-DSA-3 | Need coordinator spawn/collect/merge behavior or error handling |
287
+ | COR-WAVE-1 | Need wave execution architecture or dependency declaration syntax |
288
+ | COR-WAVE-2 | Need wave grouping algorithm or backward compatibility rules |
289
+ | COR-WAVE-3 | Need parallel spawning rules or wave execution summary format |
290
+ | COR-WAVE-4 | Need wave coordinator behavior, file conflict detection, or failure handling |
291
+ | COR-WAVE-5 | Need wave execution configuration, interaction matrix, or aggregation rules |
292
+ | COR-PTV-1 | Need per-task verification architecture or verify-diagnose-repair loop |
293
+ | COR-PTV-2 | Need verify tag syntax, parsing rules, or debug sub-agent schema |
294
+ | COR-PTV-3 | Need verification loop behavior, retry rules, or task_verifications return field |
295
+ | COR-PTV-4 | Need per-task verification configuration, error handling, or wave mode interaction |
296
+ | COR-AC-1 | Need atomic commits architecture, commit format, or sequential mode behavior |
297
+ | COR-AC-2 | Need wave mode commit behavior, JSON schema extension, or coordinator processing |
298
+ | COR-AC-3 | Need atomic commits interaction with phase isolation, wave execution, or config |
259
299
 
260
300
  ---
261
301
 
@@ -302,3 +342,6 @@ Core rules define the foundational coding standards that apply across the entire
302
342
  - `project-memory.md` is loaded on-demand - artifact tracking and 7-day session loading
303
343
  - `heartbeat.md` is loaded on-demand - scheduled task daemon configuration
304
344
  - `discovery-sub-agents.md` is loaded on-demand - parallel codebase exploration sub-agents during `/discovery-plan`
345
+ - `wave-execution.md` is loaded on-demand - wave-based parallel phase execution during `/execute-plan`
346
+ - `per-task-verification.md` is loaded on-demand - per-task verification with debug sub-agents during `/execute-plan`
347
+ - `atomic-commits.md` is loaded on-demand - per-task commit format and coordinator behavior during `/execute-plan`
@@ -0,0 +1,380 @@
1
+
2
+ # Atomic Commits Per Task
3
+
4
+ ## Purpose
5
+
6
+ When `commit: true` in `flow/.flowconfig`, `/execute-plan` creates a **git commit after each individual task** completes (and passes verification, if applicable), rather than one commit per phase. This enables `git bisect` to pinpoint task-level regressions, independent reverts of specific task changes, and clearer git history.
7
+
8
+ **Core principle**: Fine-grained commit history, tied to task completion.
9
+
10
+ ---
11
+
12
+ ## Commit Format
13
+
14
+ All per-task commits follow a consistent format:
15
+
16
+ ```
17
+ feat(phase-N.task-M): <description truncated to 50 chars> — <feature>
18
+ ```
19
+
20
+ ### Format Breakdown
21
+
22
+ | Part | Example | Description |
23
+ |------|---------|-------------|
24
+ | **Type** | `feat` | Always `feat` for feature implementation (per plan-flow convention) |
25
+ | **Scope** | `phase-1.task-2` | Phase number (N) and task number (M, 1-indexed within phase) |
26
+ | **Description** | `Create user auth middleware` | Short description of what the task did, truncated to 50 characters |
27
+ | **Feature** | `— user-auth-system` | Feature name from the plan, separated by ` — ` |
28
+
29
+ ### Example Commits
30
+
31
+ ```
32
+ feat(phase-1.task-1): Define user and session types — user-auth-system
33
+ feat(phase-1.task-2): Create user schema with Prisma — user-auth-system
34
+ feat(phase-2.task-1): Implement authentication middleware — user-auth-system
35
+ feat(phase-2.task-2): Add rate limiting to API routes — user-auth-system
36
+ feat(phase-3.task-1): Update API documentation — user-auth-system
37
+ ```
38
+
39
+ ### Description Truncation
40
+
41
+ - Truncate task descriptions to **50 characters maximum**
42
+ - Preserve the most meaningful part of the task name
43
+ - Use ellipsis (`...`) if truncation occurs: `Create user authentication middle...`
44
+ - This keeps commit messages concise and readable in `git log`
45
+
46
+ ---
47
+
48
+ ## Sequential Mode Behavior
49
+
50
+ In **sequential mode** (default, `wave_execution: false`), each phase runs in an **isolated Agent sub-agent**:
51
+
52
+ ```
53
+ Coordinator (main session)
54
+
55
+ ├─ Spawn Phase sub-agent
56
+ │ │
57
+ │ ├─ Task 1: Implement → ✅ Pass verification → Commit immediately
58
+ │ ├─ Task 2: Implement → ✅ Pass verification → Commit immediately
59
+ │ └─ Task 3: Implement → ✅ Pass verification → Commit immediately
60
+
61
+ ├─ Receive JSON return with tasks_completed array
62
+
63
+ ├─ Process summary:
64
+ │ └─ Sub-agent commits are already in git
65
+ │ (files are in working dir from sub-agent context)
66
+
67
+ └─ Next phase...
68
+ ```
69
+
70
+ ### Sub-Agent Commit Behavior
71
+
72
+ In sequential mode, the **phase sub-agent commits directly** after each task:
73
+
74
+ 1. Complete task implementation in isolation
75
+ 2. Run verification (if `<verify>` tag present)
76
+ 3. If verification passes: run `git add -A && git commit -m "feat(phase-N.task-M): ..."`
77
+ 4. Proceed to next task
78
+ 5. Return JSON summary with `tasks_completed` array
79
+
80
+ The coordinator receives the JSON return and knows which tasks were completed by checking `tasks_completed`. File conflicts do not occur in sequential mode because only one sub-agent runs at a time.
81
+
82
+ **Context template extension**: Add to phase sub-agent context:
83
+
84
+ ```markdown
85
+ ## Commit Instructions
86
+ - After each task completes and verification passes (if applicable):
87
+ 1. Stage changed files: `git add -A`
88
+ 2. Create atomic commit: `git commit -m "feat(phase-N.task-M): <truncated description> — <feature>"`
89
+ - Use format: feat(phase-{phase_number}.task-{task_number_in_phase}): <description> — <feature>
90
+ - Truncate description to 50 chars
91
+ - Task numbers are 1-indexed within each phase
92
+ 3. Continue to next task
93
+ - Return `tasks_completed` array in JSON with files_created/files_modified per task
94
+ - Do NOT create a final phase commit (coordinator will not create one either)
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Wave Mode Behavior
100
+
101
+ In **wave mode** (`wave_execution: true`), multiple sub-agents run in **parallel per wave**, and the **coordinator commits after the wave completes**:
102
+
103
+ ```
104
+ Coordinator (main session)
105
+
106
+ ├─ For each Wave:
107
+ │ │
108
+ │ ├─ Spawn MULTIPLE Phase sub-agents IN PARALLEL:
109
+ │ │ ├─► Phase A sub-agent (runs tasks, NO commits)
110
+ │ │ └─► Phase B sub-agent (runs tasks, NO commits)
111
+ │ │
112
+ │ ├─ Wait for all to complete
113
+ │ │
114
+ │ ├─ Collect JSON returns with tasks_completed arrays
115
+ │ │
116
+ │ ├─ Post-wave processing (sequential, in phase order):
117
+ │ │ │
118
+ │ │ ├─ Detect file conflicts
119
+ │ │ │
120
+ │ │ ├─ For each phase (A, then B):
121
+ │ │ │ └─ For each task in phase (1, 2, 3, ...):
122
+ │ │ │ └─ Commit: git add -A && git commit -m "feat(phase-N.task-M): ..."
123
+ │ │ │
124
+ │ │ └─ Commit all tasks from Phase A, then all from Phase B
125
+ │ │
126
+ │ └─ Next Wave...
127
+
128
+ └─ Completion summary
129
+ ```
130
+
131
+ ### Sub-Agent Behavior in Wave Mode
132
+
133
+ In wave mode, **sub-agents do NOT commit**. They implement all tasks and return a JSON summary:
134
+
135
+ 1. Implement all phase tasks
136
+ 2. Run per-task verification (if applicable)
137
+ 3. **Do NOT commit** — parallel git conflicts would occur
138
+ 4. Return JSON with `tasks_completed` array containing per-task metadata
139
+ 5. Exit
140
+
141
+ The coordinator collects all JSON returns, detects file conflicts, then commits sequentially.
142
+
143
+ **Context template extension**: Add to phase sub-agent context in wave mode:
144
+
145
+ ```markdown
146
+ ## Commit Instructions (Wave Mode)
147
+ - Do NOT create any commits during task implementation
148
+ - The coordinator will commit your changes after this wave completes
149
+ - Return `tasks_completed` array with per-task file lists (see Return Format below)
150
+ - Coordinator will iterate tasks and commit: feat(phase-N.task-M): ... per task
151
+ ```
152
+
153
+ ---
154
+
155
+ ## JSON Return Schema Extension
156
+
157
+ The phase isolation return format is extended with a **`tasks_completed` array** for per-task file tracking:
158
+
159
+ ```json
160
+ {
161
+ "status": "success",
162
+ "phase": "Phase 1: Create Core Resource",
163
+ "summary": "Implemented three core resource files...",
164
+ "files_created": [
165
+ ".claude/resources/core/atomic-commits.md",
166
+ ".claude/resources/core/_index.md"
167
+ ],
168
+ "files_modified": [],
169
+ "decisions": [],
170
+ "deviations": [],
171
+ "errors": [],
172
+ "patterns_captured": [],
173
+ "tasks_completed": [
174
+ {
175
+ "task_number": 1,
176
+ "task_name": "Create atomic-commits.md resource file",
177
+ "files_created": [".claude/resources/core/atomic-commits.md"],
178
+ "files_modified": []
179
+ },
180
+ {
181
+ "task_number": 2,
182
+ "task_name": "Update _index.md with reference entry",
183
+ "files_created": [],
184
+ "files_modified": [".claude/resources/core/_index.md"]
185
+ }
186
+ ]
187
+ }
188
+ ```
189
+
190
+ ### tasks_completed Field
191
+
192
+ | Field | Type | Description |
193
+ |-------|------|-------------|
194
+ | `task_number` | number | 1-indexed task number within the phase |
195
+ | `task_name` | string | Short task description from the plan |
196
+ | `files_created` | string[] | Files created by this task (empty array if none) |
197
+ | `files_modified` | string[] | Files modified by this task (empty array if none) |
198
+
199
+ ### When to Include
200
+
201
+ - Always include `tasks_completed` if any tasks ran in the phase
202
+ - Omit `tasks_completed` only if the phase has no tasks (edge case)
203
+ - Include all tasks, even those without `<verify>` tags
204
+ - Order entries by task_number (1, 2, 3, ...)
205
+
206
+ ---
207
+
208
+ ## Coordinator Processing: Sequential Mode
209
+
210
+ After receiving the sub-agent JSON return in sequential mode:
211
+
212
+ 1. **Validate return**: Check `status` field
213
+ 2. **Verify commits exist**: The sub-agent has already created per-task commits
214
+ 3. **Update plan file**: Mark phase tasks as `[x]`
215
+ 4. **Accumulate file list**: Merge `files_created` and `files_modified` into running list
216
+ 5. **Buffer patterns**: Append `patterns_captured` entries
217
+ 6. **Display summary**: Show tasks completed with verification results
218
+ 7. **Do NOT create phase commit**: Sub-agent already created per-task commits
219
+ 8. **Proceed**: Move to next phase
220
+
221
+ ---
222
+
223
+ ## Coordinator Processing: Wave Mode
224
+
225
+ After collecting all sub-agent JSON returns from a wave:
226
+
227
+ 1. **Validate all returns**: Check `status` field for each
228
+ 2. **Detect file conflicts**: Check `files_modified` overlap between phases (same as existing wave behavior)
229
+ 3. **For each phase** (in phase number order):
230
+ - **For each task** (in task_number order):
231
+ - Extract `task_name`, `files_created`, `files_modified` from `tasks_completed[i]`
232
+ - **Stage files**: `git add -A` (stages all task changes in working directory)
233
+ - **Create commit**: `git commit -m "feat(phase-N.task-M): <truncated task_name> — <feature>"`
234
+ - Truncate `task_name` to 50 chars if needed
235
+ - Use task_number from JSON (not computed)
236
+ - Use feature name from plan
237
+ - **Update plan file**: Mark phase tasks as `[x]` (after all phase tasks are committed)
238
+ - **Accumulate file list**: Merge task file lists into running list
239
+ 4. **Buffer patterns**: Collect `patterns_captured` from all phases
240
+ 5. **Display summary**: Show all phases and tasks completed, including verification results
241
+ 6. **Do NOT create wave commit**: Per-task commits already created
242
+ 7. **Proceed**: Next wave
243
+
244
+ ### Deterministic Commit Ordering
245
+
246
+ Commits are created in **strict phase order, then task order**:
247
+
248
+ ```
249
+ Wave 1 complete:
250
+ Phase A, Task 1 → commit
251
+ Phase A, Task 2 → commit
252
+ Phase A, Task 3 → commit
253
+ Phase B, Task 1 → commit
254
+ Phase B, Task 2 → commit
255
+ ```
256
+
257
+ This ensures **deterministic git history** regardless of which sub-agent finished first.
258
+
259
+ ---
260
+
261
+ ## Interaction with Per-Task Verification
262
+
263
+ Verification runs **before** the task's commit:
264
+
265
+ ```
266
+ Phase sub-agent:
267
+ Task 1: Implement
268
+ ├─ Implementation complete
269
+ ├─ Run verification (if <verify> tag present)
270
+ ├─ If fail: debug sub-agent → repair loop → re-verify
271
+ ├─ If pass or fail (max retries): commit this task
272
+ └─ Continue to Task 2
273
+ ```
274
+
275
+ **Rule**: A task commits even if verification failed (after max retries). The coordinator and user see the failure in `task_verifications[i].status == "fail"`.
276
+
277
+ ---
278
+
279
+ ## Interaction with Phase Isolation
280
+
281
+ Atomic commits per task is **independent of phase isolation**:
282
+
283
+ | phase_isolation | Behavior |
284
+ |---|---|
285
+ | `true` (default) | Sub-agent isolated with clean context; per-task commits work normally |
286
+ | `false` (legacy) | Phases execute inline in main session; per-task commits still work but less clean context isolation |
287
+
288
+ Per-task commits work the same way in both modes — the difference is context isolation, not commit behavior.
289
+
290
+ ---
291
+
292
+ ## Interaction with Wave Execution
293
+
294
+ Atomic commits per task **requires wave execution to work correctly**:
295
+
296
+ | wave_execution | Behavior |
297
+ |---|---|
298
+ | `true` (default) | Coordinator commits per-task after wave completes (no parallel git conflicts) |
299
+ | `false` (sequential) | Sub-agent commits per-task directly (no coordinator involvement) |
300
+
301
+ Per-task commits are the **only reason wave mode does NOT commit** in the sub-agent. Without per-task commits, we might revert to per-phase commits from the coordinator.
302
+
303
+ ---
304
+
305
+ ## Aggregated Phases
306
+
307
+ When phases are aggregated (combined complexity ≤ 6), they run as **one sub-agent call** with all tasks from all aggregated phases. Commit format still uses **relative phase numbering**:
308
+
309
+ ```
310
+ Phase 1 (aggregated with Phase 2):
311
+ Aggregated Phase tasks:
312
+ feat(phase-1.task-1): ...
313
+ feat(phase-1.task-2): ...
314
+ feat(phase-2.task-1): ...
315
+ feat(phase-2.task-2): ...
316
+ ```
317
+
318
+ **Rule**: Use the **actual phase number** from the plan, not a computed aggregate phase number.
319
+
320
+ ---
321
+
322
+ ## Configuration
323
+
324
+ ### `.flowconfig` Setting
325
+
326
+ Per-task commits are **not a separate feature flag**. They are **controlled by the existing `commit` setting**:
327
+
328
+ ```yaml
329
+ commit: true # Enable per-task commits (default: true)
330
+ ```
331
+
332
+ - `true`: Create atomic per-task commits (this feature)
333
+ - `false`: No commits during execution (existing behavior)
334
+
335
+ No new `.flowconfig` setting is needed — `commit: true` automatically upgrades from per-phase to per-task commits.
336
+
337
+ ### Toggle via `/flow`
338
+
339
+ ```
340
+ /flow commit=true
341
+ /flow commit=false
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Error Handling
347
+
348
+ | Scenario | Behavior |
349
+ |---|---|
350
+ | Task implementation fails | Task does NOT commit; coordinator reports failure in `errors` array |
351
+ | Verification fails (max retries) | Task commits anyway; coordinator shows failure in `task_verifications[i].status == "fail"` |
352
+ | Git commit command fails | Coordinator reports error and asks user whether to retry, skip, or stop |
353
+ | File conflict in wave mode | Same as existing wave conflict handling — present to user with options |
354
+
355
+ ---
356
+
357
+ ## Rules
358
+
359
+ 1. **Format is strict**: `feat(phase-N.task-M): <50 chars max> — <feature>`
360
+ 2. **Sequential mode**: Sub-agents commit; coordinator validates
361
+ 3. **Wave mode**: Sub-agents do NOT commit; coordinator commits in phase/task order
362
+ 4. **No final phase commit**: Replaced by per-task commits
363
+ 5. **Backward compatible**: When `commit: false`, no commits (existing behavior)
364
+ 6. **Verification before commit**: Tasks commit after passing verification
365
+ 7. **Failure still commits**: Failed verification after max retries still commits the task
366
+ 8. **Deterministic order**: Wave mode commits always in phase order, task order
367
+ 9. **Truncate descriptions**: 50 character max for readability
368
+ 10. **Task numbers reset per phase**: Phase 1 Task 1, Phase 2 Task 1 (not global numbering)
369
+
370
+ ---
371
+
372
+ ## Related Files
373
+
374
+ | File | Purpose |
375
+ |---|---|
376
+ | `.claude/resources/core/phase-isolation.md` | Sub-agent context template, JSON return format (extended by this feature) |
377
+ | `.claude/resources/core/wave-execution.md` | Wave coordinator behavior (changed to commit per-task after waves) |
378
+ | `.claude/resources/core/per-task-verification.md` | Per-task verification (runs before task's commit) |
379
+ | `.claude/resources/skills/execute-plan-skill.md` | Execute-plan skill (updated for per-task commit format) |
380
+ | `.claude/commands/execute-plan.md` | Execute-plan command docs (updated for per-task format) |
@@ -97,8 +97,9 @@ Check `flow/contracts/` for any relevant integration contracts. If found, note t
97
97
  5. If `commit: true`: auto-commit after each completed phase
98
98
  6. Run build + test verification at the end
99
99
  7. If `push: true` and build+test pass: auto-push
100
- 8. Write transition summary
101
- 9. **Auto-proceed** to Step 5
100
+ 8. If `pr: true` and push succeeds: create feature branch `feat/<feature>`, open PR via `gh pr create`, capture PR URL
101
+ 9. Write transition summary
102
+ 10. **Auto-proceed** to Step 5
102
103
 
103
104
  ### Step 5: Review Code
104
105
 
@@ -103,9 +103,23 @@ Open questions: retry policy, refund flow. Resume with remaining questions.
103
103
 
104
104
  ---
105
105
 
106
+ ## STATE.md Integration
107
+
108
+ Before compaction, write current execution state to `flow/STATE.md` using the standard state format (skill, phase, status, decisions, errors). This ensures that even if the compaction summary loses detail, the full execution position is recoverable from the file.
109
+
110
+ After compaction, re-read `flow/STATE.md` to restore execution context. This supplements the compaction summary with structured state that the summary format may not fully capture (phase numbers, file lists, decision references).
111
+
112
+ **Workflow**:
113
+ 1. Before `/compact`: Update `flow/STATE.md` with current state (or create it if it doesn't exist)
114
+ 2. Run `/compact` with the summary
115
+ 3. After compaction: Re-read `flow/STATE.md` and the active plan file to restore full context
116
+
117
+ ---
118
+
106
119
  ## Rules
107
120
 
108
121
  1. **Never compact mid-phase** — only at phase boundaries
109
122
  2. **Always include enough context to resume** — the model after compaction should know exactly what to do next
110
123
  3. **After compaction, re-read the plan file** — don't rely on memory of plan contents
111
- 4. **Default to preserving** — when in doubt, keep it. It's better to preserve something unnecessary than lose something critical.
124
+ 4. **After compaction, re-read STATE.md** — restore structured execution state that the summary may not fully capture
125
+ 5. **Default to preserving** — when in doubt, keep it. It's better to preserve something unnecessary than lose something critical.
@@ -205,9 +205,77 @@ The project log (`flow/log.md`) is also linked into the vault at `~/plan-flow/br
205
205
 
206
206
  ---
207
207
 
208
+ ## Notification System
209
+
210
+ The heartbeat daemon includes a notification system that provides visibility into background task execution.
211
+
212
+ ### Notification Channels
213
+
214
+ | Channel | What Gets Written | When |
215
+ |---------|------------------|------|
216
+ | `flow/log.md` | Timestamped one-liners | All events (start, complete, fail, blocked) |
217
+ | `flow/.heartbeat-events.jsonl` | Machine-readable JSON events | All events |
218
+ | Desktop notification (node-notifier) | Pop-up alert | Failures and blocked tasks only |
219
+
220
+ ### Log Format (flow/log.md)
221
+
222
+ ```
223
+ [2026-03-17 14:00] ✅ task-name: Started — description
224
+ [2026-03-17 14:12] ✅ task-name: Phase 1/5 complete — description
225
+ [2026-03-17 14:35] ❌ task-name: FAILED at Phase 3 — build error
226
+ [2026-03-17 14:35] ⏸️ task-name: Paused — see .heartbeat-prompt.md
227
+ ```
228
+
229
+ ### Event Types
230
+
231
+ | Type | Level | Desktop Notify |
232
+ |------|-------|---------------|
233
+ | `task_started` | info | No |
234
+ | `phase_complete` | info | No |
235
+ | `task_complete` | info | No |
236
+ | `task_failed` | error | Yes |
237
+ | `task_blocked` | error | Yes |
238
+
239
+ ### Exit Code Convention
240
+
241
+ | Exit Code | Meaning | Daemon Action |
242
+ |-----------|---------|---------------|
243
+ | 0 | Success | Log ✅, continue |
244
+ | 1 | Failure | Log ❌, desktop notify |
245
+ | 2 | Needs input | Log ⏸️, write prompt file (if autopilot OFF), desktop notify |
246
+
247
+ ### Prompt File System
248
+
249
+ When a task exits with code 2 and autopilot is OFF:
250
+ 1. Daemon writes `flow/.heartbeat-prompt.md` with task context
251
+ 2. Desktop notification alerts the user
252
+ 3. Task pauses until user responds
253
+ 4. On next session start, the prompt is auto-detected and presented
254
+ 5. After resolution, prompt is archived to `flow/archive/heartbeat-prompts/`
255
+
256
+ When autopilot is ON: exit code 2 is logged as a warning but execution continues.
257
+
258
+ ### Session Start Integration
259
+
260
+ Two behaviors activate on session start:
261
+ 1. **Heartbeat Log**: Reads `.heartbeat-events.jsonl`, compares against `.heartbeat-state.json` timestamp, summarizes unread events
262
+ 2. **Heartbeat Prompt**: Detects `.heartbeat-prompt.md` and presents pending questions immediately
263
+
264
+ ### Runtime Files
265
+
266
+ | File | Purpose |
267
+ |------|---------|
268
+ | `flow/.heartbeat-events.jsonl` | Append-only event stream (one JSON per line) |
269
+ | `flow/.heartbeat-state.json` | Tracks last-read timestamp for session start summaries |
270
+ | `flow/.heartbeat-prompt.md` | Pending user input from blocked task (temporary) |
271
+ | `flow/archive/heartbeat-prompts/` | Archived resolved prompt files |
272
+ | `flow/.telegram-poll-state.json` | Telegram polling state (update offset, mode) |
273
+
274
+ ---
275
+
208
276
  ## Rules
209
277
 
210
- 1. **No external dependencies**: Daemon uses only Node.js built-in modules
278
+ 1. **Minimal dependencies**: Daemon uses Node.js built-in modules plus `node-notifier` for desktop notifications
211
279
  2. **Graceful shutdown**: Always clean up timers and PID file on exit
212
280
  3. **Stale PID detection**: Verify PID is actually running before assuming daemon is alive
213
281
  4. **File-based config**: All configuration lives in `flow/heartbeat.md` — no CLI flags for task config
@@ -215,3 +283,63 @@ The project log (`flow/log.md`) is also linked into the vault at `~/plan-flow/br
215
283
  6. **Log rotation**: Keep `flow/.heartbeat.log` under 1000 lines by truncating oldest entries
216
284
  7. **One-shot cleanup**: After a one-shot task executes, auto-disable it and update the linked tasklist item
217
285
  8. **Vault sync**: Every heartbeat update MUST also update `~/plan-flow/brain/heartbeat.md` — see Vault Sync section
286
+
287
+ ---
288
+
289
+ ## Telegram Two-Way Polling
290
+
291
+ When `telegram_bot_token` and `telegram_chat_id` are set in `flow/.flowconfig`, the heartbeat daemon enables two-way messaging with Telegram using the Bot API's `getUpdates` long-polling endpoint.
292
+
293
+ ### Adaptive Polling Modes
294
+
295
+ | Mode | Interval | Trigger |
296
+ |------|----------|---------|
297
+ | Idle | 60 seconds | No pending prompts — lightweight keep-alive |
298
+ | Conversation | 3 seconds | A task is blocked and waiting for user input |
299
+
300
+ The daemon switches to **conversation mode** when it writes a prompt to Telegram (e.g., a task blocked with exit code 2). Once the user replies and the prompt is resolved, it drops back to **idle mode**.
301
+
302
+ ### State File
303
+
304
+ Polling state is persisted in `flow/.telegram-poll-state.json`:
305
+
306
+ ```json
307
+ {
308
+ "lastUpdateId": 123456789,
309
+ "mode": "idle",
310
+ "pendingPromptMessageId": null
311
+ }
312
+ ```
313
+
314
+ - `lastUpdateId`: Tracks the Telegram update offset to avoid processing duplicate messages
315
+ - `mode`: Current polling mode (`idle` or `conversation`)
316
+ - `pendingPromptMessageId`: The Telegram message ID of the last prompt sent, used to match replies
317
+
318
+ ### Two-Way Conversation Flow
319
+
320
+ 1. A heartbeat task blocks (exit code 2) and writes `flow/.heartbeat-prompt.md`
321
+ 2. The daemon detects the prompt file and sends it to Telegram via `sendMessage`
322
+ 3. Polling switches to **conversation mode** (3s interval)
323
+ 4. The user replies in Telegram
324
+ 5. The daemon detects the reply via `getUpdates`, writes the response to `flow/.heartbeat-prompt.md`
325
+ 6. The blocked task resumes with the user's input
326
+ 7. Polling switches back to **idle mode** (60s interval)
327
+
328
+ ### Configuration
329
+
330
+ Set both values in `flow/.flowconfig`:
331
+
332
+ ```yaml
333
+ telegram_bot_token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
334
+ telegram_chat_id: "5635356808"
335
+ ```
336
+
337
+ Configure via `/flow`:
338
+
339
+ ```
340
+ /flow telegram_bot_token=123456:ABC-DEF telegram_chat_id=5635356808
341
+ ```
342
+
343
+ ### Auto-Migration from webhook_url
344
+
345
+ If `webhook_url` contains a Telegram `api.telegram.org` URL with a bot token and chat_id in the query string, the flowconfig parser automatically extracts and populates `telegram_bot_token` and `telegram_chat_id`. The original `webhook_url` is preserved for one-way notification compatibility.
@@ -7,7 +7,7 @@ Automatic model selection at phase boundaries during `/execute-plan`. Each phase
7
7
 
8
8
  **Scope**: `/execute-plan` only. Other skills (discovery, review, brainstorm) do not have pre-defined complexity scores and are not routed.
9
9
 
10
- **Config**: Controlled by `model_routing` key in `flow/.flowconfig` (default: `true`). Set `model_routing: false` to disable.
10
+ **Config**: Controlled by `model_routing` key in `flow/.flowconfig` (default: `false`). Set `model_routing: true` to enable.
11
11
 
12
12
  ---
13
13
 
@@ -23,12 +23,16 @@ Automatic model selection at phase boundaries during `/execute-plan`. Each phase
23
23
 
24
24
  ## Platform Mappings
25
25
 
26
+ Always use the **latest and most capable model** from each provider. Model names below are examples — always prefer the most recent version available at runtime.
27
+
26
28
  | Tier | Claude Code | Codex (OpenAI) | Cursor |
27
29
  |------|------------|----------------|--------|
28
30
  | Fast | `haiku` | `gpt-4.1-mini` | auto (fast) |
29
31
  | Standard | `sonnet` | `gpt-4.1` | auto (normal) |
30
32
  | Powerful | `opus` | `o3` | auto (max) |
31
33
 
34
+ **Default model (when routing is OFF)**: Always use the most capable/recent model from the active provider — e.g., `opus` for Anthropic, `o3` for OpenAI. This is the default behavior.
35
+
32
36
  **Fallback rule**: If a platform doesn't support a tier, fall back to the next tier up (e.g., if no haiku equivalent, use Standard).
33
37
 
34
38
  ---
@@ -37,7 +41,7 @@ Automatic model selection at phase boundaries during `/execute-plan`. Each phase
37
41
 
38
42
  ### At Each Phase Boundary
39
43
 
40
- 1. **Check config**: Read `model_routing` from `flow/.flowconfig`. If `false` or missing key, skip routing (use session default).
44
+ 1. **Check config**: Read `model_routing` from `flow/.flowconfig`. If `false`, missing key, or not set, skip routing (use the most capable session model — this is the default).
41
45
  2. **Read complexity**: Get the phase's complexity score from the plan file.
42
46
  3. **Look up tier**: Map score to tier using the table above.
43
47
  4. **Spawn subagent**: Use the Agent tool with `model={tier_model}` to implement the phase.