planflow-ai 1.3.5 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/.claude/commands/brainstorm.md +6 -14
  2. package/.claude/commands/create-contract.md +6 -38
  3. package/.claude/commands/create-plan.md +18 -38
  4. package/.claude/commands/discovery-plan.md +19 -49
  5. package/.claude/commands/execute-plan.md +116 -77
  6. package/.claude/commands/flow.md +27 -2
  7. package/.claude/commands/heartbeat.md +12 -14
  8. package/.claude/commands/learn.md +20 -80
  9. package/.claude/commands/note.md +6 -23
  10. package/.claude/commands/resume-work.md +261 -0
  11. package/.claude/commands/review-code.md +19 -51
  12. package/.claude/commands/review-pr.md +21 -57
  13. package/.claude/commands/setup.md +8 -56
  14. package/.claude/commands/write-tests.md +7 -41
  15. package/.claude/resources/core/atomic-commits.md +380 -0
  16. package/.claude/resources/core/autopilot-mode.md +3 -2
  17. package/.claude/resources/core/compaction-guide.md +15 -1
  18. package/.claude/resources/core/heartbeat.md +129 -1
  19. package/.claude/resources/core/per-task-verification.md +362 -0
  20. package/.claude/resources/core/phase-isolation.md +237 -4
  21. package/.claude/resources/core/session-scratchpad.md +1 -0
  22. package/.claude/resources/core/shared-context.md +110 -0
  23. package/.claude/resources/core/wave-execution.md +407 -0
  24. package/.claude/resources/patterns/plans-patterns.md +56 -0
  25. package/.claude/resources/patterns/plans-templates.md +152 -0
  26. package/.claude/resources/skills/create-plan-skill.md +71 -5
  27. package/.claude/resources/skills/execute-plan-skill.md +420 -14
  28. package/.claude/resources/skills/resume-work-skill.md +159 -0
  29. package/README.md +154 -96
  30. package/dist/cli/commands/brain.d.ts +20 -0
  31. package/dist/cli/commands/brain.d.ts.map +1 -0
  32. package/dist/cli/commands/brain.js +127 -0
  33. package/dist/cli/commands/brain.js.map +1 -0
  34. package/dist/cli/commands/init.d.ts.map +1 -1
  35. package/dist/cli/commands/init.js +10 -1
  36. package/dist/cli/commands/init.js.map +1 -1
  37. package/dist/cli/commands/state-query.d.ts +13 -0
  38. package/dist/cli/commands/state-query.d.ts.map +1 -0
  39. package/dist/cli/commands/state-query.js +32 -0
  40. package/dist/cli/commands/state-query.js.map +1 -0
  41. package/dist/cli/commands/state.d.ts +12 -0
  42. package/dist/cli/commands/state.d.ts.map +1 -0
  43. package/dist/cli/commands/state.js +47 -0
  44. package/dist/cli/commands/state.js.map +1 -0
  45. package/dist/cli/daemon/desktop-notifier.d.ts +16 -0
  46. package/dist/cli/daemon/desktop-notifier.d.ts.map +1 -0
  47. package/dist/cli/daemon/desktop-notifier.js +53 -0
  48. package/dist/cli/daemon/desktop-notifier.js.map +1 -0
  49. package/dist/cli/daemon/event-writer.d.ts +22 -0
  50. package/dist/cli/daemon/event-writer.d.ts.map +1 -0
  51. package/dist/cli/daemon/event-writer.js +76 -0
  52. package/dist/cli/daemon/event-writer.js.map +1 -0
  53. package/dist/cli/daemon/heartbeat-daemon.js +81 -1
  54. package/dist/cli/daemon/heartbeat-daemon.js.map +1 -1
  55. package/dist/cli/daemon/log-writer.d.ts +17 -0
  56. package/dist/cli/daemon/log-writer.d.ts.map +1 -0
  57. package/dist/cli/daemon/log-writer.js +62 -0
  58. package/dist/cli/daemon/log-writer.js.map +1 -0
  59. package/dist/cli/daemon/notification-router.d.ts +17 -0
  60. package/dist/cli/daemon/notification-router.d.ts.map +1 -0
  61. package/dist/cli/daemon/notification-router.js +35 -0
  62. package/dist/cli/daemon/notification-router.js.map +1 -0
  63. package/dist/cli/daemon/prompt-manager.d.ts +27 -0
  64. package/dist/cli/daemon/prompt-manager.d.ts.map +1 -0
  65. package/dist/cli/daemon/prompt-manager.js +107 -0
  66. package/dist/cli/daemon/prompt-manager.js.map +1 -0
  67. package/dist/cli/daemon/shared-context.d.ts +38 -0
  68. package/dist/cli/daemon/shared-context.d.ts.map +1 -0
  69. package/dist/cli/daemon/shared-context.js +129 -0
  70. package/dist/cli/daemon/shared-context.js.map +1 -0
  71. package/dist/cli/handlers/claude.d.ts.map +1 -1
  72. package/dist/cli/handlers/claude.js +18 -0
  73. package/dist/cli/handlers/claude.js.map +1 -1
  74. package/dist/cli/handlers/shared.js +1 -1
  75. package/dist/cli/handlers/shared.js.map +1 -1
  76. package/dist/cli/index.js +30 -0
  77. package/dist/cli/index.js.map +1 -1
  78. package/dist/cli/state/brain-query.d.ts +48 -0
  79. package/dist/cli/state/brain-query.d.ts.map +1 -0
  80. package/dist/cli/state/brain-query.js +113 -0
  81. package/dist/cli/state/brain-query.js.map +1 -0
  82. package/dist/cli/state/flowconfig-parser.d.ts +16 -0
  83. package/dist/cli/state/flowconfig-parser.d.ts.map +1 -0
  84. package/dist/cli/state/flowconfig-parser.js +166 -0
  85. package/dist/cli/state/flowconfig-parser.js.map +1 -0
  86. package/dist/cli/state/heartbeat-state.d.ts +16 -0
  87. package/dist/cli/state/heartbeat-state.d.ts.map +1 -0
  88. package/dist/cli/state/heartbeat-state.js +97 -0
  89. package/dist/cli/state/heartbeat-state.js.map +1 -0
  90. package/dist/cli/state/model-router.d.ts +8 -0
  91. package/dist/cli/state/model-router.d.ts.map +1 -0
  92. package/dist/cli/state/model-router.js +36 -0
  93. package/dist/cli/state/model-router.js.map +1 -0
  94. package/dist/cli/state/plan-parser.d.ts +16 -0
  95. package/dist/cli/state/plan-parser.d.ts.map +1 -0
  96. package/dist/cli/state/plan-parser.js +124 -0
  97. package/dist/cli/state/plan-parser.js.map +1 -0
  98. package/dist/cli/state/session-state.d.ts +21 -0
  99. package/dist/cli/state/session-state.d.ts.map +1 -0
  100. package/dist/cli/state/session-state.js +36 -0
  101. package/dist/cli/state/session-state.js.map +1 -0
  102. package/dist/cli/state/state-md-parser.d.ts +18 -0
  103. package/dist/cli/state/state-md-parser.d.ts.map +1 -0
  104. package/dist/cli/state/state-md-parser.js +222 -0
  105. package/dist/cli/state/state-md-parser.js.map +1 -0
  106. package/dist/cli/state/types.d.ts +137 -0
  107. package/dist/cli/state/types.d.ts.map +1 -0
  108. package/dist/cli/state/types.js +8 -0
  109. package/dist/cli/state/types.js.map +1 -0
  110. package/dist/cli/state/wave-calculator.d.ts +18 -0
  111. package/dist/cli/state/wave-calculator.d.ts.map +1 -0
  112. package/dist/cli/state/wave-calculator.js +134 -0
  113. package/dist/cli/state/wave-calculator.js.map +1 -0
  114. package/dist/cli/types.d.ts +15 -0
  115. package/dist/cli/types.d.ts.map +1 -1
  116. package/package.json +7 -2
  117. package/templates/shared/CLAUDE.md.template +4 -0
  118. package/.claude/resources/core/_index.md +0 -304
  119. package/.claude/resources/languages/_index.md +0 -76
  120. package/.claude/resources/patterns/_index.md +0 -200
  121. package/.claude/resources/skills/_index.md +0 -285
  122. package/.claude/resources/tools/_index.md +0 -110
  123. package/.claude/resources/tools/reference-expansion-tool.md +0 -326
@@ -0,0 +1,159 @@
1
+
2
+ # Resume Work Skill
3
+
4
+ ## Purpose
5
+
6
+ Reconstruct full session context from `flow/STATE.md` after a context reset (compaction, new session, crash). This skill reads the unified state file, identifies the active work, cross-references with the plan file, and outputs a structured summary that enables the LLM to resume work seamlessly.
7
+
8
+ **This skill is read-only** — it does not create, modify, or delete any files.
9
+
10
+ ---
11
+
12
+ ## Restrictions — READ-ONLY
13
+
14
+ | Allowed Action | Purpose |
15
+ |----------------|---------|
16
+ | Read `flow/STATE.md` | Parse execution state |
17
+ | Read plan files (`flow/plans/`) | Cross-reference progress |
18
+ | Read discovery files (`flow/discovery/`) | Context for active discovery |
19
+ | Read `flow/.scratchpad.md` | Restore ephemeral notes |
20
+ | Read `flow/tasklist.md` | Check task status |
21
+
22
+ | Forbidden Action | Reason |
23
+ |------------------|--------|
24
+ | Create/edit any files | Resume is observation-only |
25
+ | Run build or test commands | No execution during resume |
26
+ | Auto-invoke other skills | User decides next action |
27
+ | Modify STATE.md | State persists until actively changed by a skill |
28
+
29
+ ---
30
+
31
+ ## Workflow
32
+
33
+ ### Step 1: Read STATE.md
34
+
35
+ 1. Check if `flow/STATE.md` exists — if not, inform user and stop
36
+ 2. Read the file and parse all sections:
37
+ - `**Updated**` timestamp
38
+ - `## Execution State` — active skill, plan, phase, task, completed phases
39
+ - `## Decisions` — decisions with rationale
40
+ - `## Blockers` — issues with status
41
+ - `## Files Modified` — changed file paths
42
+ - `## Next Action` — immediate next step
43
+
44
+ ---
45
+
46
+ ### Step 2: Staleness Check
47
+
48
+ Parse the `**Updated**` timestamp and compare to current time.
49
+
50
+ | Age | Behavior |
51
+ |-----|----------|
52
+ | < 24 hours | Continue silently |
53
+ | 24-72 hours | Warn: "State is {N} hours old. Context may be outdated." Ask: resume or start fresh? |
54
+ | > 72 hours | Strong warning: "State is {N} days old. Recommend starting fresh." Ask: resume or start fresh? |
55
+
56
+ If user chooses "start fresh":
57
+ 1. Inform them to delete `flow/STATE.md` manually
58
+ 2. Stop — do not proceed with resume
59
+
60
+ ---
61
+
62
+ ### Step 3: Read Active Plan
63
+
64
+ If `Active Plan` references a plan file:
65
+
66
+ 1. Read the plan file from `flow/plans/`
67
+ 2. Parse phase structure and task checkboxes
68
+ 3. Cross-reference:
69
+ - STATE.md `Completed Phases` → plan's `[x]` tasks should match
70
+ - STATE.md `Current Phase` → identify exact task position
71
+ 4. If discrepancies found, note them and trust the plan file
72
+
73
+ If `Active Plan` is "none", skip this step.
74
+
75
+ ---
76
+
77
+ ### Step 4: Identify Next Task
78
+
79
+ Based on STATE.md and plan cross-reference:
80
+
81
+ 1. If `Next Action` is set → use it as the recommended next step
82
+ 2. If `Current Task` is set → resume from that task
83
+ 3. If `Current Phase` is set but no task → start at the first unchecked task in that phase
84
+ 4. If no current phase → suggest continuing from the first unchecked phase
85
+
86
+ ---
87
+
88
+ ### Step 5: Output Context Summary
89
+
90
+ Present a structured summary:
91
+
92
+ ```markdown
93
+ ## Session Resumed
94
+
95
+ **Active Skill**: {skill name}
96
+ **Active Plan**: `{plan file path}`
97
+ **Progress**: Phase {current} of {total} — {phase name}
98
+ **Last Updated**: {timestamp} ({relative time})
99
+
100
+ ### Completed Phases
101
+ | Phase | Name | Outcome |
102
+ |-------|------|---------|
103
+ | 1 | Types and Schemas | done |
104
+ | 2 | Backend Setup | done |
105
+
106
+ ### Decisions Made
107
+ - {decision} — {choice} (reason: {reason})
108
+
109
+ ### Blockers
110
+ | Issue | Status | Tried |
111
+ |-------|--------|-------|
112
+ | {issue} | {status} | {tried} |
113
+
114
+ ### Files Modified ({count})
115
+ - `{file1}`
116
+ - `{file2}`
117
+
118
+ ### Next Action
119
+ > {next action description}
120
+
121
+ ---
122
+
123
+ Ready to continue. Suggested command: `/execute-plan @{plan-file}`
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Error Handling
129
+
130
+ | Scenario | Behavior |
131
+ |----------|----------|
132
+ | STATE.md missing | Inform user: "No active state found." Stop. |
133
+ | Plan file referenced but missing | Warn: "Plan file not found." Show state without plan cross-reference. |
134
+ | STATE.md malformed | Parse what's possible, warn about missing sections. |
135
+ | Active skill is unknown | Show state as-is, don't suggest a specific command. |
136
+ | Scratchpad exists | Mention: "Session scratchpad has notes — read `flow/.scratchpad.md` for context." |
137
+
138
+ ---
139
+
140
+ ## Rules
141
+
142
+ 1. **Read-only** — never modify any files during resume
143
+ 2. **No auto-chaining** — present summary and stop
144
+ 3. **Plan file is truth** — if STATE.md and plan disagree, trust the plan
145
+ 4. **Graceful degradation** — parse what's available, skip missing sections
146
+ 5. **Staleness gate** — always check timestamp before proceeding
147
+ 6. **Complement scratchpad** — mention scratchpad if it exists, but don't merge content
148
+
149
+ ---
150
+
151
+ ## Related Files
152
+
153
+ | File | Purpose |
154
+ |------|---------|
155
+ | `.claude/commands/resume-work.md` | Command file for /resume-work |
156
+ | `.claude/resources/core/compaction-guide.md` | What to preserve during compaction |
157
+ | `.claude/resources/core/session-scratchpad.md` | Complementary session notes |
158
+ | `src/cli/state/state-md-parser.ts` | Programmatic parser for STATE.md |
159
+ | `src/cli/state/types.ts` | ExecutionState type definition |
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"}
@@ -0,0 +1,127 @@
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
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import { resolve, join, basename } from 'node:path';
16
+ import { homedir } from 'node:os';
17
+ import * as log from '../utils/logger.js';
18
+ const DEFAULT_BRAIN_DIR = join(homedir(), 'plan-flow', 'brain');
19
+ export async function runBrain(action, args, options) {
20
+ const brainDir = options.brainDir
21
+ ? resolve(options.brainDir)
22
+ : resolve(DEFAULT_BRAIN_DIR);
23
+ const { Brain } = await import('planflow-brain');
24
+ switch (action) {
25
+ case 'search': {
26
+ if (args.length === 0) {
27
+ log.error('Usage: brain search <query>');
28
+ process.exit(1);
29
+ }
30
+ const query = args.join(' ');
31
+ log.info(`Searching brain at ${brainDir}...`);
32
+ const brain = await Brain.open(brainDir);
33
+ try {
34
+ const results = await brain.search(query, {
35
+ limit: options.limit ?? 10,
36
+ chunkTypes: options.type ? [options.type] : undefined,
37
+ });
38
+ if (results.length === 0) {
39
+ log.info('No results found.');
40
+ }
41
+ else {
42
+ log.header(`${results.length} result(s) for: "${query}"`);
43
+ log.blank();
44
+ for (const r of results) {
45
+ const location = r.heading ? `${r.sourceFile} › ${r.heading}` : r.sourceFile;
46
+ console.log(` [${(r.score * 100).toFixed(1)}%] ${location}`);
47
+ const preview = r.text.slice(0, 200).replace(/\n/g, ' ');
48
+ const ellipsis = r.text.length > 200 ? '...' : '';
49
+ console.log(` ${preview}${ellipsis}`);
50
+ log.blank();
51
+ }
52
+ }
53
+ }
54
+ finally {
55
+ brain.close();
56
+ }
57
+ break;
58
+ }
59
+ case 'ingest': {
60
+ if (args.length === 0) {
61
+ log.error('Usage: brain ingest <file>');
62
+ process.exit(1);
63
+ }
64
+ const filePath = resolve(args[0]);
65
+ if (!existsSync(filePath)) {
66
+ log.error(`File not found: ${filePath}`);
67
+ process.exit(1);
68
+ }
69
+ const content = readFileSync(filePath, 'utf-8');
70
+ const relPath = basename(filePath);
71
+ log.info(`Ingesting ${filePath} into brain at ${brainDir}...`);
72
+ const brain = await Brain.open(brainDir);
73
+ try {
74
+ await brain.ingest(relPath, content);
75
+ log.success(`Ingested: ${relPath}`);
76
+ }
77
+ finally {
78
+ brain.close();
79
+ }
80
+ break;
81
+ }
82
+ case 'rebuild': {
83
+ log.info(`Rebuilding brain index at ${brainDir}...`);
84
+ const brain = await Brain.open(brainDir);
85
+ try {
86
+ const stats = await brain.rebuild();
87
+ log.success(`Rebuild complete: ${stats.filesIndexed} files, ${stats.chunksCreated} chunks (${stats.durationMs}ms)`);
88
+ }
89
+ finally {
90
+ brain.close();
91
+ }
92
+ break;
93
+ }
94
+ case 'stats': {
95
+ const brain = await Brain.open(brainDir);
96
+ try {
97
+ const stats = brain.stats();
98
+ log.header('Brain Stats');
99
+ console.log(` Location: ${brainDir}`);
100
+ console.log(` Files: ${stats.totalFiles}`);
101
+ console.log(` Chunks: ${stats.totalChunks}`);
102
+ console.log(` DB size: ${(stats.dbSizeBytes / 1024).toFixed(1)} KB`);
103
+ console.log(` Last sync: ${stats.lastIndexed ?? 'never'}`);
104
+ }
105
+ finally {
106
+ brain.close();
107
+ }
108
+ break;
109
+ }
110
+ case 'sync': {
111
+ log.info(`Syncing brain at ${brainDir}...`);
112
+ const brain = await Brain.open(brainDir);
113
+ try {
114
+ const stats = await brain.sync();
115
+ log.success(`Sync complete: +${stats.filesAdded} added, ~${stats.filesUpdated} updated, -${stats.filesRemoved} removed (${stats.durationMs}ms)`);
116
+ }
117
+ finally {
118
+ brain.close();
119
+ }
120
+ break;
121
+ }
122
+ default:
123
+ log.error(`Unknown brain action: "${action}". Valid actions: search, ingest, rebuild, stats, sync`);
124
+ process.exit(1);
125
+ }
126
+ }
127
+ //# sourceMappingURL=brain.js.map