planflow-ai 1.4.1 → 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 (52) 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 +7 -38
  4. package/.claude/commands/discovery-plan.md +7 -49
  5. package/.claude/commands/execute-plan.md +11 -63
  6. package/.claude/commands/heartbeat.md +12 -14
  7. package/.claude/commands/learn.md +20 -80
  8. package/.claude/commands/note.md +6 -23
  9. package/.claude/commands/review-code.md +8 -51
  10. package/.claude/commands/review-pr.md +10 -57
  11. package/.claude/commands/setup.md +8 -56
  12. package/.claude/commands/write-tests.md +7 -41
  13. package/.claude/resources/core/phase-isolation.md +46 -1
  14. package/.claude/resources/core/shared-context.md +110 -0
  15. package/.claude/resources/core/wave-execution.md +79 -1
  16. package/.claude/resources/skills/execute-plan-skill.md +74 -13
  17. package/README.md +154 -96
  18. package/dist/cli/commands/brain.d.ts +20 -0
  19. package/dist/cli/commands/brain.d.ts.map +1 -0
  20. package/dist/cli/commands/brain.js +127 -0
  21. package/dist/cli/commands/brain.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts.map +1 -1
  23. package/dist/cli/commands/init.js +9 -0
  24. package/dist/cli/commands/init.js.map +1 -1
  25. package/dist/cli/commands/state-query.d.ts +13 -0
  26. package/dist/cli/commands/state-query.d.ts.map +1 -0
  27. package/dist/cli/commands/state-query.js +32 -0
  28. package/dist/cli/commands/state-query.js.map +1 -0
  29. package/dist/cli/daemon/shared-context.d.ts +38 -0
  30. package/dist/cli/daemon/shared-context.d.ts.map +1 -0
  31. package/dist/cli/daemon/shared-context.js +129 -0
  32. package/dist/cli/daemon/shared-context.js.map +1 -0
  33. package/dist/cli/handlers/claude.d.ts.map +1 -1
  34. package/dist/cli/handlers/claude.js +18 -0
  35. package/dist/cli/handlers/claude.js.map +1 -1
  36. package/dist/cli/handlers/shared.js +1 -1
  37. package/dist/cli/handlers/shared.js.map +1 -1
  38. package/dist/cli/index.js +21 -0
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/state/brain-query.d.ts +48 -0
  41. package/dist/cli/state/brain-query.d.ts.map +1 -0
  42. package/dist/cli/state/brain-query.js +113 -0
  43. package/dist/cli/state/brain-query.js.map +1 -0
  44. package/dist/cli/state/types.d.ts +31 -0
  45. package/dist/cli/state/types.d.ts.map +1 -1
  46. package/package.json +4 -1
  47. package/.claude/resources/core/_index.md +0 -347
  48. package/.claude/resources/languages/_index.md +0 -76
  49. package/.claude/resources/patterns/_index.md +0 -200
  50. package/.claude/resources/skills/_index.md +0 -287
  51. package/.claude/resources/tools/_index.md +0 -110
  52. package/.claude/resources/tools/reference-expansion-tool.md +0 -326
@@ -317,34 +317,84 @@ After ALL phases in the wave are approved, proceed to parallel spawning.
317
317
  Launch all approved wave phases simultaneously as independent Agent sub-agents:
318
318
 
319
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.
320
+ 2. **Inject shared context from sibling phases** (multi-phase waves only):
321
+ - Skip this step for single-phase waves (no siblings to share with)
322
+ - Read `flow/.wave-context.jsonl` (create it if it doesn't exist yet — see wave lifecycle below)
323
+ - Filter entries: include only entries from OTHER phases in the current wave (not the agent's own phase). Also include entries from all previous waves.
324
+ - If there are matching entries, add an inline section in the sub-agent prompt after the phase spec:
325
+ ```
326
+ ## Shared Context from Sibling Phases
327
+
328
+ The following context entries were published by other phases. Use them to align on shared contracts, types, and architectural decisions.
329
+
330
+ - [phase N] (type: contract) name: UserAPI, signature: GET /users → { id, name, email }
331
+ - [phase N] (type: type_definition) name: UserRecord, fields: { id: string, name: string }
332
+ - [phase N] (type: decision) summary: Using Redis for session caching
333
+ ```
334
+ - If no matching entries exist, omit the section entirely
321
335
  3. **Spawn all in parallel**: Launch all wave phases simultaneously using Agent sub-agents with their respective model tiers.
322
336
  4. **Wait for all to complete**: All sub-agents must return before post-wave processing.
323
337
 
338
+ **Wave context lifecycle**:
339
+ - **Create** `flow/.wave-context.jsonl` at wave start (before first spawn in Step 4b), if it does not already exist. Start with an empty file.
340
+ - Context entries **accumulate across all waves** — the file is NOT cleared between waves. Later waves benefit from contracts and decisions published by earlier waves.
341
+ - **Delete** `flow/.wave-context.jsonl` after execution completes (Step 7, after build/test verification).
342
+
324
343
  ##### 4c. Wave Coordinator — Post-Wave Processing
325
344
 
326
345
  After all sub-agents in the wave return, process results **sequentially in phase number order**:
327
346
 
328
347
  1. **Collect JSON returns**: Gather the structured JSON summary from each sub-agent
329
348
  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:
349
+ 3. **Collect context entries**: For each phase's JSON return, check for a `context_entries` array:
350
+ - If `context_entries` is present and non-empty, append each entry to `flow/.wave-context.jsonl` (one JSON object per line)
351
+ - If `context_entries` is absent or empty, treat as empty array — no entries to append
352
+ - Entry format: `{"phase": N, "type": "contract|type_definition|decision", "name": "...", "signature": "...", "fields": "...", "summary": "..."}`
353
+ - These entries become available to phases in subsequent waves via Step 4b
354
+ 4. **Detect file conflicts**: Check for `files_modified` overlap between phases in this wave:
331
355
  - For each pair of phases (A, B) in the wave: compute `overlap = A.files_modified ∩ B.files_modified`
332
356
  - If overlap is not empty → file conflict detected
333
- 4. **Handle file conflicts** (if any):
357
+ 5. **Handle file conflicts** (if any):
334
358
  - Present the conflicting files and which phases modified them
335
359
  - Offer options:
336
360
  - **(1) Accept as-is**: Last writer wins (the phase with the higher number committed last)
337
361
  - **(2) Re-run conflicting phases sequentially**: Re-execute only the conflicting phases in order
338
362
  - **(3) Stop execution**: Halt for manual resolution
339
363
  - File conflicts do NOT affect non-conflicting phases — their results are preserved
340
- 5. **Process each phase** (in phase number order):
364
+ 6. **Detect contract conflicts**: For each pair of phases (A, B) in the wave, check their `context_entries` for contract entries with the same `name` but different `signature` or `fields`:
365
+ - Compare all entries where `type` is `contract` or `type_definition`
366
+ - If same `name` but different `signature`/`fields` → contract conflict detected
367
+ - Present conflicts and offer resolution (see Contract Conflicts below)
368
+ - Contract conflicts do NOT affect non-conflicting phases — their results are preserved
369
+ 7. **Process each phase** (in phase number order):
341
370
  - Check `status` field: `success` → continue; `failure` → present errors, ask retry/skip/stop; `partial` → present deviations, ask user
342
371
  - Update plan file (mark tasks `[x]`)
343
372
  - Accumulate `files_created` and `files_modified` into running list
344
373
  - Buffer `patterns_captured` entries to `flow/resources/pending-patterns.md`
345
374
  - 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
375
  - Log `decisions` in phase completion message
347
- 6. **Report wave completion**: Present summary of all phases in this wave, including task verification stats:
376
+
377
+ ##### Contract Conflicts
378
+
379
+ If contract conflicts are detected (same API name, different signatures):
380
+
381
+ 1. Present both versions:
382
+ ```
383
+ Warning: Contract conflict detected:
384
+ **API**: GET /users
385
+
386
+ Phase 1 signature: GET /users → { id: string, name: string }
387
+ Phase 3 signature: GET /users → { id: string, name: string, email: string }
388
+
389
+ Options:
390
+ 1. Use Phase 1's version
391
+ 2. Use Phase 3's version
392
+ 3. Stop execution for manual resolution
393
+ ```
394
+ 2. Apply the chosen version: update the corresponding entry in `flow/.wave-context.jsonl` so subsequent waves see the resolved contract
395
+ 3. Contract conflicts do NOT affect non-conflicting phases — only the conflicting contract entries need resolution
396
+
397
+ 8. **Report wave completion**: Present summary of all phases in this wave, including task verification stats:
348
398
  - For each phase in the wave that returned `task_verifications`, include pass/fail counts and repairs applied
349
399
  - Wave completion report template:
350
400
  ```
@@ -572,18 +622,20 @@ This allows users to quickly jump to the PR from notifications without needing t
572
622
 
573
623
  After ALL phases are complete (including Tests phase):
574
624
 
575
- 1. **Run final verification**:
625
+ 1. **Clean up shared context**: If `flow/.wave-context.jsonl` exists, delete it. This file is ephemeral and should not persist after execution completes.
626
+
627
+ 2. **Run final verification**:
576
628
 
577
629
  ```bash
578
630
  npm run build && npm run test
579
631
  ```
580
632
 
581
- 2. **Handle failures**:
633
+ 3. **Handle failures**:
582
634
  - If build fails: Fix the issue, re-run verification
583
635
  - If tests fail: Fix the issue, re-run verification
584
636
  - Only proceed after everything passes
585
637
 
586
- 3. **Present summary** of completed work, including model routing and wave execution info if enabled:
638
+ 4. **Present summary** of completed work, including model routing and wave execution info if enabled:
587
639
 
588
640
  **Sequential mode summary**:
589
641
 
@@ -616,6 +668,7 @@ npm run build && npm run test
616
668
  - Waves executed: 4
617
669
  - Parallel phases: 2 (in Wave 1)
618
670
  - File conflicts: 0
671
+ - Contract conflicts: 0
619
672
  - Failed phases: 0
620
673
  - Estimated speedup: ~20%
621
674
 
@@ -625,9 +678,9 @@ npm run build && npm run test
625
678
  **PR**: https://github.com/owner/repo/pull/123
626
679
  ```
627
680
 
628
- 4. **List all key changes** made
681
+ 5. **List all key changes** made
629
682
 
630
- 5. **Ask if the plan should be archived**:
683
+ 6. **Ask if the plan should be archived**:
631
684
 
632
685
  ```bash
633
686
  mv flow/plans/plan_feature_name_v1.md flow/archive/
@@ -672,13 +725,17 @@ Wave 1: Phase 1 + Phase 2 (parallel, no dependencies)
672
725
  | +-- Get user approval
673
726
  |
674
727
  +-- 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 ──┘
728
+ | +-- Create flow/.wave-context.jsonl (if not exists)
729
+ | +-- Read shared context from sibling phases (if multi-phase wave)
730
+ | +-- Spawn Agent: Phase 1 (model: haiku, + shared context) ──┐
731
+ | +-- Spawn Agent: Phase 2 (model: haiku, + shared context) ──┤ (running simultaneously)
732
+ | +-- Wait for all to return ──┘
678
733
  |
679
734
  +-- POST-WAVE PROCESSING (sequential):
680
735
  | +-- Collect JSON returns
736
+ | +-- Collect context_entries → append to .wave-context.jsonl
681
737
  | +-- Check for file conflicts
738
+ | +-- Check for contract conflicts (same name, different signature)
682
739
  | +-- Process Phase 1 result → update plan → git commit per task
683
740
  | +-- Process Phase 2 result → update plan → git commit per task
684
741
  | +-- Report wave completion
@@ -782,6 +839,9 @@ If the user wants to stop execution:
782
839
  | **Deterministic commits** | Git commits happen per-task in phase/task order after wave completes: `feat(phase-N.task-M): <desc> — <feature>` |
783
840
  | **Failures are isolated** | One failed phase does not cancel sibling phases in the same wave |
784
841
  | **File conflicts presented** | Never silently resolve file conflicts, always ask the user |
842
+ | **Shared context injected** | Multi-phase waves inject sibling context entries; single-phase waves skip |
843
+ | **Contract conflicts detected** | Same API name with different signatures triggers user resolution |
844
+ | **Wave context is ephemeral** | `.wave-context.jsonl` accumulates across waves, deleted after execution completes |
785
845
 
786
846
  ---
787
847
 
@@ -796,4 +856,5 @@ If the user wants to stop execution:
796
856
  | `.claude/resources/core/per-task-verification.md` | Per-task verification system and debug sub-agents |
797
857
  | `.claude/resources/tools/plan-mode-tool.md` | Plan mode switching instructions |
798
858
  | `flow/plans/` | Input plan documents |
859
+ | `flow/.wave-context.jsonl` | Ephemeral shared context between wave phases (deleted after execution) |
799
860
  | `flow/archive/` | Completed plans destination |
package/README.md CHANGED
@@ -78,11 +78,13 @@ Installs for Claude Code, Cursor, OpenClaw, and Codex CLI simultaneously.
78
78
  | `/review-code` | Review local uncommitted changes (adaptive depth + multi-agent) |
79
79
  | `/review-pr` | Review a Pull Request (adaptive depth + multi-agent) |
80
80
  | `/write-tests` | Generate tests for coverage target |
81
+ | `/brainstorm` | Free-form idea exploration with interactive questions |
81
82
  | `/flow` | Configure plan-flow settings (autopilot, git control, runtime options) |
82
83
  | `/note` | Capture meeting notes, ideas, brainstorms |
83
84
  | `/learn` | Extract reusable patterns or learn a topic step-by-step |
84
- | `/pattern-validate` | Scan and index global brain patterns |
85
85
  | `/heartbeat` | Manage scheduled automated tasks |
86
+ | `/resume-work` | Resume interrupted work from STATE.md |
87
+ | `state-query` | Query brain index for relevant documentation (CLI: `planflow-ai state-query "topic"`) |
86
88
 
87
89
  ## Workflow
88
90
 
@@ -90,10 +92,11 @@ Installs for Claude Code, Cursor, OpenClaw, and Codex CLI simultaneously.
90
92
 
91
93
  ```
92
94
  1. /setup -> Index project patterns (run once)
93
- 2. /discovery-plan -> Gather requirements for a feature
94
- 3. /create-plan -> Create structured implementation plan
95
- 4. /execute-plan -> Execute the plan phase by phase
96
- 5. /review-code -> Review changes before committing
95
+ 2. /brainstorm -> (Optional) Explore and crystallize a vague idea
96
+ 3. /discovery-plan -> Gather requirements for a feature
97
+ 4. /create-plan -> Create structured implementation plan
98
+ 5. /execute-plan -> Execute the plan phase by phase
99
+ 6. /review-code -> Review changes before committing
97
100
  ```
98
101
 
99
102
  ### Autopilot Mode
@@ -113,10 +116,85 @@ You: "Add dark mode support"
113
116
 
114
117
  Autopilot classifies every input and only triggers the full flow for feature requests (complexity 3+). Questions, trivial tasks, and slash commands are handled normally.
115
118
 
116
- **Mandatory checkpoints** even in autopilot, the flow always pauses for:
119
+ **Mandatory checkpoints** -- even in autopilot, the flow always pauses for:
117
120
  - **Discovery Q&A**: You answer requirements questions
118
121
  - **Plan approval**: You review and approve the plan before execution
119
122
 
123
+ ## Core Features
124
+
125
+ ### Wave-Based Parallel Execution
126
+
127
+ Independent phases run in parallel within waves, with dependency-aware grouping:
128
+
129
+ ```
130
+ Wave 1 (parallel): Phase 1: Types, Phase 2: Utilities
131
+ Wave 2 (sequential): Phase 3: API Integration (depends on 1+2)
132
+ Wave 3 (parallel): Phase 4: Config, Phase 5: UI Components
133
+ Wave 4 (sequential): Phase 6: Tests (always last)
134
+ ```
135
+
136
+ Plans support a `**Dependencies**:` field per phase. Topological sort assigns wave numbers automatically. Phases without dependencies run in Wave 1. Tests always run in their own final wave.
137
+
138
+ Enable with `/flow wave_execution=true` (default: on).
139
+
140
+ ### Multi-Agent Coordination
141
+
142
+ During wave execution, parallel phases share a context file (`flow/.wave-context.jsonl`) that enables real-time coordination. Agents share:
143
+
144
+ - **API contracts** -- endpoint shapes, type interfaces, function signatures
145
+ - **Decisions** -- architecture choices, library selections
146
+ - **Progress** -- task completion status
147
+
148
+ Before each task, sub-agents receive shared context from sibling phases -- preventing broken contracts and duplicate decisions. Post-wave processing includes contract conflict detection: same API name with different signatures triggers user intervention.
149
+
150
+ ### Brain Index (SQLite)
151
+
152
+ All markdown files are indexed with SQLite FTS5 + vector embeddings for hybrid search. Query with `planflow-ai state-query "topic"` to find relevant documentation instantly. Replaces the previous reference code system — 10-50x faster context loading with semantic matching.
153
+
154
+ ### Phase Isolation
155
+
156
+ Each phase runs in an isolated sub-agent with a clean context window. The sub-agent receives only the context it needs (phase spec, files modified so far, patterns, design context) and returns a structured JSON summary. This eliminates context rot -- phase 7 has the same quality as phase 1.
157
+
158
+ Disable with `/flow phase_isolation=false`.
159
+
160
+ ### Per-Task Verification
161
+
162
+ Plan tasks can include `<verify>` tags with shell commands. After completing each task, the sub-agent runs verification automatically. On failure, a debug sub-agent (haiku) diagnoses the root cause and the implementation agent applies repairs (up to `max_verify_retries` attempts, default: 2).
163
+
164
+ ### Atomic Commits Per Task
165
+
166
+ When `commit=true`, each individual task within a phase gets its own git commit (not per phase). Format: `feat(phase-N.task-M): description`. Enables `git bisect`, independent reverts, and clearer git history.
167
+
168
+ ### Auto-PR Creation
169
+
170
+ When `pr=true`, after execution completes (build+test pass), plan-flow automatically creates a feature branch and opens a PR via `gh pr create` with an auto-generated title and summary.
171
+
172
+ ### Model Routing
173
+
174
+ By default, all phases use the most capable model from the active provider. Enable cost-based routing with `/flow model_routing=true` to auto-select models per phase based on complexity:
175
+
176
+ | Complexity | Tier | Model |
177
+ |-----------|------|-------|
178
+ | 0-3 | Fast | haiku |
179
+ | 4-5 | Standard | sonnet |
180
+ | 6-10 | Powerful | opus |
181
+
182
+ ### Design Awareness
183
+
184
+ Discovery asks whether features involve UI work. If confirmed, captures structured design tokens (colors, typography, spacing) into a Design Context section. During execution, tokens are auto-injected into UI phase prompts. Includes 6 built-in design personalities.
185
+
186
+ ### Pattern Capture
187
+
188
+ During skill execution, the LLM silently buffers coding patterns and anti-patterns. At the end, captured patterns are presented for approval and written to `.claude/rules/core/allowed-patterns.md` or `forbidden-patterns.md`.
189
+
190
+ ### Session Resumability (STATE.md)
191
+
192
+ `flow/STATE.md` tracks decisions, blockers, current position, and active phase. If a session is interrupted, `/resume-work` rebuilds full context from stored files and continues from where you left off.
193
+
194
+ ### Deterministic State Script
195
+
196
+ Config and state parsing runs as a Node.js script (`planflow-ai state`) that returns structured JSON -- deterministic logic in code, not prompts. Ensures reliable flowconfig reading, phase calculations, and file existence checks.
197
+
120
198
  ## Flow Configuration (`/flow`)
121
199
 
122
200
  The `/flow` command is the central configuration hub. All settings use `key=value` syntax and persist in `flow/.flowconfig` (YAML).
@@ -124,58 +202,43 @@ The `/flow` command is the central configuration hub. All settings use `key=valu
124
202
  | Setting | Values | Default | Description |
125
203
  |---------|--------|---------|-------------|
126
204
  | `autopilot` | `true/false` | `false` | Enable/disable autopilot mode |
127
- | `commit` | `true/false` | `false` | Auto-commit after each completed phase |
205
+ | `commit` | `true/false` | `false` | Auto-commit after each completed task |
128
206
  | `push` | `true/false` | `false` | Auto-push after all phases + build/test pass |
207
+ | `pr` | `true/false` | `false` | Auto-create PR after execution |
129
208
  | `branch` | any string | current branch | Target branch for git operations |
209
+ | `wave_execution` | `true/false` | `true` | Dependency-aware parallel phase execution |
210
+ | `phase_isolation` | `true/false` | `true` | Isolated sub-agent per phase |
211
+ | `model_routing` | `true/false` | `false` | Cost-based model selection per phase |
212
+ | `max_verify_retries` | `1-5` | `2` | Max repair attempts per task verification |
130
213
 
131
214
  ### Examples
132
215
 
133
216
  ```bash
134
217
  /flow autopilot=true # Enable autopilot
135
- /flow commit=true push=true # Enable git control (works without autopilot)
136
- /flow autopilot=true commit=true # Enable both
137
- /flow branch=development # Set target branch
218
+ /flow commit=true push=true pr=true # Full git control with auto-PR
219
+ /flow wave_execution=false # Disable parallel execution
220
+ /flow phase_isolation=false # Inline execution (for debugging)
221
+ /flow model_routing=true # Enable cost-based model routing
138
222
  /flow -status # Show current config
139
223
  /flow -reset # Reset everything
140
224
 
141
225
  # Shorthand: text without key=value enables autopilot and starts flow
142
226
  /flow add dark mode support # autopilot=true + start discovery
143
- /flow commit=true add user auth # autopilot=true + git + start discovery
144
227
  ```
145
228
 
146
229
  ### Git Control
147
230
 
148
- When `commit=true`, plan-flow auto-commits after each completed execution phase:
149
-
150
- ```
151
- Phase 1: Setup types → git commit "Phase 1: Setup types — user-auth"
152
- Phase 2: API endpoints → git commit "Phase 2: API endpoints — user-auth"
153
- Phase 3: Tests → git commit "Phase 3: Tests — user-auth"
154
- Build + Test pass → git commit "Complete: user-auth — all phases done"
155
- → git push origin development (if push=true)
156
- ```
157
-
158
- Git control works independently of autopilot — you can use `commit=true` with manual `/execute-plan` runs.
159
-
160
- ## Project Tasklist
161
-
162
- Each project has a `flow/tasklist.md` that tracks work items across sessions. On session start, active tasks are summarized and you can pick one to work on.
163
-
164
- Every command automatically updates the tasklist:
165
- - On start: adds the task to **In Progress**
166
- - On complete: moves it to **Done** with the date
167
- - Next step: adds the logical follow-up to **To Do**
168
-
169
- ### Scheduled Tasks
170
-
171
- Tasks can be scheduled for later execution by linking them to the heartbeat daemon:
231
+ When `commit=true`, plan-flow auto-commits after each completed task:
172
232
 
173
233
  ```
174
- /flow add to tasklist: implement feature X and execute in 1 hour
234
+ feat(phase-1.task-1): Create user types -- user-auth
235
+ feat(phase-1.task-2): Add validation schemas -- user-auth
236
+ feat(phase-2.task-1): Create login endpoint -- user-auth
237
+ ...
238
+ Build + Test pass -> git push origin development (if push=true)
239
+ -> gh pr create (if pr=true)
175
240
  ```
176
241
 
177
- This creates a tasklist entry linked to a heartbeat one-shot task via `[[]]` references. Both files cross-reference each other for Obsidian navigation.
178
-
179
242
  ## Heartbeat (Scheduled Automation)
180
243
 
181
244
  The heartbeat daemon is a background process that executes scheduled tasks defined in `flow/heartbeat.md`.
@@ -201,13 +264,17 @@ npx planflow-ai heartbeat status # Show daemon status
201
264
 
202
265
  The daemon **auto-starts** during `planflow-ai init` if `flow/heartbeat.md` exists.
203
266
 
267
+ ### Notifications
268
+
269
+ The daemon sends OS desktop notifications (via node-notifier) for task completions, failures, and blocked tasks. Events are also logged to `flow/log.md` and `flow/.heartbeat-events.jsonl`.
270
+
204
271
  ### One-Shot Tasks
205
272
 
206
- Tasks with `in {N} hours/minutes` schedules run once and auto-disable after execution. These are used for scheduled tasklist items.
273
+ Tasks with `in {N} hours/minutes` schedules run once and auto-disable after execution.
207
274
 
208
275
  ### Retry on Active Session
209
276
 
210
- If a task fails because a Claude Code session is already active, the daemon retries up to 5 times at 60-second intervals instead of failing permanently.
277
+ If a task fails because a Claude Code session is already active, the daemon retries up to 5 times at 60-second intervals.
211
278
 
212
279
  ## Code Review
213
280
 
@@ -215,25 +282,19 @@ If a task fails because a Claude Code session is already active, the daemon retr
215
282
 
216
283
  ### Adaptive Depth
217
284
 
218
- Review depth scales automatically based on changeset size:
219
-
220
285
  | Lines Changed | Mode | Behavior |
221
286
  |--------------|------|----------|
222
287
  | < 50 | Lightweight | Quick-scan for security, logic bugs, and breaking changes only |
223
- | 50500 | Standard | Full review with pattern matching and similar implementation search |
288
+ | 50-500 | Standard | Full review with pattern matching and similar implementation search |
224
289
  | 500+ | Deep | Multi-pass review with file categorization, executive summary, and multi-agent analysis |
225
290
 
226
291
  ### Verification Pass
227
292
 
228
- Every finding goes through a second-pass verification that re-reads surrounding context and asks structured questions to classify findings as Confirmed, Likely, or Dismissed. False positives are filtered before output.
229
-
230
- ### Severity Re-Ranking
231
-
232
- Findings are sorted by impact (Critical > Major > Minor > Suggestion), related findings across files are grouped, and an executive summary is added when there are 5+ findings.
293
+ Every finding goes through a second-pass verification that re-reads surrounding context to classify findings as Confirmed, Likely, or Dismissed. False positives are filtered before output.
233
294
 
234
295
  ### Multi-Agent Parallel Review
235
296
 
236
- In Deep mode (500+ lines), the review is split into 4 specialized subagents running in parallel:
297
+ In Deep mode (500+ lines), 4 specialized subagents run in parallel:
237
298
 
238
299
  | Agent | Focus | Model |
239
300
  |-------|-------|-------|
@@ -242,8 +303,6 @@ In Deep mode (500+ lines), the review is split into 4 specialized subagents runn
242
303
  | Performance | N+1 queries, memory leaks, blocking I/O | sonnet |
243
304
  | Pattern Compliance | Forbidden/allowed patterns, naming consistency | haiku |
244
305
 
245
- The coordinator merges results, deduplicates overlapping findings, then runs verification and re-ranking.
246
-
247
306
  ## Complexity Scoring
248
307
 
249
308
  Every plan phase has a complexity score (0-10):
@@ -256,64 +315,63 @@ Every plan phase has a complexity score (0-10):
256
315
  | 7-8 | High | Complex, multiple considerations |
257
316
  | 9-10 | Very High | Significant complexity/risk |
258
317
 
259
- ## Directory Structure
260
-
261
- All artifacts are stored in `flow/`:
262
-
263
- ```
264
- flow/
265
- ├── archive/ # Completed/abandoned plans
266
- ├── brain/ # Automatic knowledge capture (Obsidian-compatible)
267
- │ ├── index.md # Brain index (loaded at session start)
268
- │ ├── features/ # Feature history and context
269
- │ └── errors/ # Reusable error patterns
270
- ├── contracts/ # Integration contracts
271
- ├── discovery/ # Discovery documents
272
- ├── plans/ # Active implementation plans
273
- ├── references/ # Reference materials
274
- ├── resources/ # Valuable artifacts captured during skill execution
275
- ├── reviewed-code/ # Code review documents
276
- ├── reviewed-pr/ # PR review documents
277
- ├── tasklist.md # Project task list (updated in real-time during execution)
278
- ├── memory.md # Persistent artifact tracker (completed work)
279
- ├── heartbeat.md # Scheduled task definitions for the heartbeat daemon
280
- ├── log.md # Heartbeat event log
281
- ├── ledger.md # Persistent project learning journal
282
- ├── .flowconfig # Central config file (autopilot, git control, settings)
283
- └── .gitcontrol # Git control settings (backward compat)
284
- ```
318
+ ## Discovery Sub-Agents
285
319
 
286
- ## Session Start Behaviors
320
+ During `/discovery-plan`, three parallel haiku sub-agents explore the codebase simultaneously (similar features, API/data patterns, schema/types). Returns condensed findings merged into a Codebase Analysis section.
287
321
 
288
- When a session starts, plan-flow automatically loads context from your project:
322
+ ## Project Brain and Knowledge Graph
289
323
 
290
- - **Tasklist** (`flow/tasklist.md`) Presents active tasks and lets you pick one to work on
291
- - **Memory** (`flow/memory.md`) — Loads the last 7 days of completed work so context is never lost
292
- - **Brain** (`flow/brain/index.md`) — Internalizes active features and recent error patterns
293
- - **Ledger** (`flow/ledger.md`) — Internalizes project-specific lessons learned
294
- - **Autopilot** (`flow/.flowconfig`) — If `autopilot: true`, activates automatic workflow orchestration
324
+ All projects are linked into a central Obsidian vault at `~/plan-flow/brain/`. Each `planflow-ai init` creates a project directory in the vault with symlinks for brain subdirectories.
295
325
 
296
- ## Intelligent Learn Skill
326
+ Features:
327
+ - `flow/brain/features/` -- Feature history and context with `[[wiki-links]]`
328
+ - `flow/brain/errors/` -- Reusable error patterns
329
+ - `flow/ledger.md` -- Persistent project learning journal
330
+ - `flow/memory.md` -- Last 7 days of completed work
331
+ - `flow/.scratchpad.md` -- Ephemeral per-session notes
297
332
 
298
- The `/learn` skill supports step-by-step teaching. When you run `/learn about <topic>`, it creates a structured curriculum stored as a brain `.md` file. Each step requires your confirmation before progressing, and confirmed steps become learned patterns.
333
+ Open `~/plan-flow/brain/` as an Obsidian vault to browse all projects in one graph.
299
334
 
300
- Commands also recommend `/learn` automatically when:
301
- - New dependencies are added during execution
302
- - Non-trivial errors are resolved (3+ attempts)
303
- - The user corrects the approach
304
- - A new technology or pattern is introduced
335
+ ## Directory Structure
305
336
 
306
- ## Central Obsidian Vault
337
+ ```
338
+ flow/
339
+ ├── archive/ # Completed/abandoned plans
340
+ ├── brain/ # Automatic knowledge capture (Obsidian-compatible)
341
+ │ ├── index.md # Brain index
342
+ │ ├── features/ # Feature history and context
343
+ │ └── errors/ # Reusable error patterns
344
+ ├── brainstorms/ # Brainstorm exploration documents
345
+ ├── contracts/ # Integration contracts
346
+ ├── discovery/ # Discovery documents
347
+ ├── plans/ # Active implementation plans
348
+ ├── references/ # Reference materials
349
+ ├── resources/ # Valuable artifacts from skill execution
350
+ ├── reviewed-code/ # Code review documents
351
+ ├── reviewed-pr/ # PR review documents
352
+ ├── tasklist.md # Project task list
353
+ ├── memory.md # Persistent artifact tracker
354
+ ├── heartbeat.md # Scheduled task definitions
355
+ ├── log.md # Heartbeat event log
356
+ ├── ledger.md # Project learning journal
357
+ ├── STATE.md # Execution state for session resumability
358
+ ├── .flowconfig # Central config file
359
+ ├── .wave-context.jsonl # Shared context for multi-agent coordination
360
+ ├── .heartbeat-events.jsonl # Notification event stream
361
+ ├── .heartbeat-state.json # Session read position tracking
362
+ └── .gitcontrol # Git control settings (backward compat)
363
+ ```
307
364
 
308
- All projects are linked into a central Obsidian vault at `~/plan-flow/brain/`. Each `planflow-ai init` creates a project directory in the vault with symlinks for brain subdirectories and the tasklist. A global tasklist at `~/plan-flow/brain/tasklist.md` aggregates task counts across all projects.
365
+ ### Brain Index Database
309
366
 
310
- Open `~/plan-flow/brain/` as an Obsidian vault to browse all projects in one graph.
367
+ The SQLite brain index (`.brain.sqlite`) lives at the **project root** (not inside `flow/`). It's gitignored and rebuildable from markdown files.
368
+ ```
311
369
 
312
370
  ## Requirements
313
371
 
314
372
  - Node.js 18+
315
- - `git` - For version control
316
- - `gh` - GitHub CLI (for PR reviews)
373
+ - `git` -- For version control
374
+ - `gh` -- GitHub CLI (for PR reviews and auto-PR)
317
375
 
318
376
  ## Development
319
377
 
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Brain CLI command
3
+ *
4
+ * Provides semantic search and indexing over the shared planflow-brain knowledge base.
5
+ * The brain directory defaults to ~/plan-flow/brain but can be overridden with --brain-dir.
6
+ *
7
+ * Subcommands:
8
+ * search <query> Hybrid semantic + keyword search
9
+ * ingest <file> Index a markdown file into the brain
10
+ * rebuild Rebuild entire index from markdown files on disk
11
+ * stats Show brain statistics
12
+ * sync Incremental sync (re-index only changed files)
13
+ */
14
+ export interface BrainOptions {
15
+ brainDir?: string;
16
+ limit?: number;
17
+ type?: string;
18
+ }
19
+ export declare function runBrain(action: string, args: string[], options: BrainOptions): Promise<void>;
20
+ //# sourceMappingURL=brain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAgHnG"}