planflow-ai 1.0.8 → 1.1.0

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 (168) hide show
  1. package/.claude/commands/brain.md +251 -0
  2. package/.claude/commands/create-contract.md +50 -0
  3. package/.claude/commands/create-plan.md +66 -0
  4. package/.claude/commands/discovery-plan.md +113 -5
  5. package/.claude/commands/execute-plan.md +122 -23
  6. package/.claude/commands/flow.md +55 -20
  7. package/.claude/commands/learn.md +245 -0
  8. package/.claude/commands/review-code.md +64 -0
  9. package/.claude/commands/review-pr.md +49 -0
  10. package/.claude/commands/setup.md +50 -2
  11. package/.claude/commands/write-tests.md +42 -0
  12. package/.claude/resources/core/_index.md +61 -2
  13. package/.claude/resources/core/agent-profiles.md +107 -0
  14. package/.claude/resources/core/audit-trail.md +180 -0
  15. package/.claude/resources/core/autopilot-mode.md +240 -44
  16. package/.claude/resources/core/brain-capture.md +424 -0
  17. package/.claude/resources/core/complexity-scoring.md +30 -1
  18. package/.claude/resources/core/orchestration-workflows.md +178 -0
  19. package/.claude/resources/core/project-ledger.md +57 -0
  20. package/.claude/resources/core/resource-capture.md +91 -0
  21. package/.claude/resources/core/tech-detection.md +82 -0
  22. package/.claude/resources/languages/_index.md +61 -13
  23. package/.claude/resources/languages/go-patterns.md +337 -0
  24. package/.claude/resources/languages/python-patterns.md +243 -0
  25. package/.claude/resources/languages/rust-patterns.md +363 -0
  26. package/.claude/resources/languages/typescript-patterns.md +213 -0
  27. package/.claude/resources/patterns/_index.md +80 -2
  28. package/.claude/resources/patterns/autopilot-progress-patterns.md +124 -0
  29. package/.claude/resources/patterns/brain-patterns.md +252 -0
  30. package/.claude/resources/patterns/discovery-patterns.md +58 -2
  31. package/.claude/resources/patterns/discovery-templates.md +14 -0
  32. package/.claude/resources/patterns/handoff-patterns.md +160 -0
  33. package/.claude/resources/patterns/parallel-review-patterns.md +164 -0
  34. package/.claude/resources/patterns/plans-patterns.md +22 -3
  35. package/.claude/resources/patterns/plans-templates.md +104 -9
  36. package/.claude/resources/patterns/review-code-templates.md +23 -4
  37. package/.claude/resources/patterns/review-pr-patterns.md +21 -0
  38. package/.claude/resources/patterns/security-scan-patterns.md +137 -0
  39. package/.claude/resources/skills/_index.md +22 -2
  40. package/.claude/resources/skills/brain-skill.md +144 -0
  41. package/.claude/resources/skills/create-contract-skill.md +15 -30
  42. package/.claude/resources/skills/create-plan-skill.md +125 -33
  43. package/.claude/resources/skills/discovery-skill.md +158 -34
  44. package/.claude/resources/skills/execute-plan-skill.md +394 -18
  45. package/.claude/resources/skills/learn-skill.md +140 -0
  46. package/.claude/resources/skills/review-code-skill.md +125 -39
  47. package/.claude/resources/skills/review-pr-skill.md +82 -92
  48. package/.claude/resources/skills/setup-skill.md +93 -0
  49. package/.claude/resources/skills/write-tests-skill.md +22 -0
  50. package/dist/cli/commands/init.d.ts.map +1 -1
  51. package/dist/cli/commands/init.js +27 -4
  52. package/dist/cli/commands/init.js.map +1 -1
  53. package/dist/cli/commands/sessions.d.ts +34 -0
  54. package/dist/cli/commands/sessions.d.ts.map +1 -0
  55. package/dist/cli/commands/sessions.js +128 -0
  56. package/dist/cli/commands/sessions.js.map +1 -0
  57. package/dist/cli/commands/update.d.ts +1 -0
  58. package/dist/cli/commands/update.d.ts.map +1 -1
  59. package/dist/cli/commands/update.js +7 -1
  60. package/dist/cli/commands/update.js.map +1 -1
  61. package/dist/cli/commands/validate.d.ts +31 -0
  62. package/dist/cli/commands/validate.d.ts.map +1 -0
  63. package/dist/cli/commands/validate.js +213 -0
  64. package/dist/cli/commands/validate.js.map +1 -0
  65. package/dist/cli/handlers/claude.d.ts +1 -1
  66. package/dist/cli/handlers/claude.d.ts.map +1 -1
  67. package/dist/cli/handlers/claude.js +45 -2
  68. package/dist/cli/handlers/claude.js.map +1 -1
  69. package/dist/cli/handlers/clawhub.d.ts +9 -0
  70. package/dist/cli/handlers/clawhub.d.ts.map +1 -0
  71. package/dist/cli/handlers/clawhub.js +67 -0
  72. package/dist/cli/handlers/clawhub.js.map +1 -0
  73. package/dist/cli/handlers/codex.d.ts.map +1 -1
  74. package/dist/cli/handlers/codex.js +11 -0
  75. package/dist/cli/handlers/codex.js.map +1 -1
  76. package/dist/cli/handlers/cursor.d.ts +1 -1
  77. package/dist/cli/handlers/cursor.d.ts.map +1 -1
  78. package/dist/cli/handlers/cursor.js +28 -2
  79. package/dist/cli/handlers/cursor.js.map +1 -1
  80. package/dist/cli/handlers/shared.d.ts +19 -0
  81. package/dist/cli/handlers/shared.d.ts.map +1 -1
  82. package/dist/cli/handlers/shared.js +1343 -4
  83. package/dist/cli/handlers/shared.js.map +1 -1
  84. package/dist/cli/index.js +74 -0
  85. package/dist/cli/index.js.map +1 -1
  86. package/dist/cli/types.d.ts +3 -1
  87. package/dist/cli/types.d.ts.map +1 -1
  88. package/dist/cli/utils/detect-stack.d.ts +39 -0
  89. package/dist/cli/utils/detect-stack.d.ts.map +1 -0
  90. package/dist/cli/utils/detect-stack.js +239 -0
  91. package/dist/cli/utils/detect-stack.js.map +1 -0
  92. package/dist/cli/utils/files.d.ts +18 -0
  93. package/dist/cli/utils/files.d.ts.map +1 -1
  94. package/dist/cli/utils/files.js +57 -2
  95. package/dist/cli/utils/files.js.map +1 -1
  96. package/dist/cli/utils/hooks.d.ts +42 -0
  97. package/dist/cli/utils/hooks.d.ts.map +1 -0
  98. package/dist/cli/utils/hooks.js +98 -0
  99. package/dist/cli/utils/hooks.js.map +1 -0
  100. package/dist/cli/utils/ledger.d.ts +38 -0
  101. package/dist/cli/utils/ledger.d.ts.map +1 -0
  102. package/dist/cli/utils/ledger.js +148 -0
  103. package/dist/cli/utils/ledger.js.map +1 -0
  104. package/dist/cli/utils/phase-hooks.d.ts +53 -0
  105. package/dist/cli/utils/phase-hooks.d.ts.map +1 -0
  106. package/dist/cli/utils/phase-hooks.js +122 -0
  107. package/dist/cli/utils/phase-hooks.js.map +1 -0
  108. package/dist/cli/utils/platform-hooks.d.ts +31 -0
  109. package/dist/cli/utils/platform-hooks.d.ts.map +1 -0
  110. package/dist/cli/utils/platform-hooks.js +101 -0
  111. package/dist/cli/utils/platform-hooks.js.map +1 -0
  112. package/dist/cli/utils/prompts.d.ts.map +1 -1
  113. package/dist/cli/utils/prompts.js +11 -6
  114. package/dist/cli/utils/prompts.js.map +1 -1
  115. package/dist/cli/utils/sessions.d.ts +82 -0
  116. package/dist/cli/utils/sessions.d.ts.map +1 -0
  117. package/dist/cli/utils/sessions.js +203 -0
  118. package/dist/cli/utils/sessions.js.map +1 -0
  119. package/dist/test/setup.js +1 -1
  120. package/dist/test/setup.js.map +1 -1
  121. package/package.json +4 -2
  122. package/rules/core/_index.mdc +54 -2
  123. package/rules/core/agent-profiles.mdc +111 -0
  124. package/rules/core/audit-trail.mdc +114 -0
  125. package/rules/core/autopilot-mode.mdc +253 -89
  126. package/rules/core/brain-capture.mdc +112 -0
  127. package/rules/core/orchestration-workflows.mdc +139 -0
  128. package/rules/core/resource-capture.mdc +90 -0
  129. package/rules/patterns/_index.mdc +70 -0
  130. package/rules/patterns/autopilot-progress-patterns.mdc +124 -0
  131. package/rules/patterns/brain-patterns.mdc +79 -0
  132. package/rules/patterns/discovery-patterns.mdc +152 -6
  133. package/rules/patterns/discovery-templates.mdc +2 -0
  134. package/rules/patterns/handoff-patterns.mdc +164 -0
  135. package/rules/patterns/parallel-review-patterns.mdc +168 -0
  136. package/rules/patterns/plans-patterns.mdc +28 -9
  137. package/rules/patterns/plans-templates.mdc +59 -0
  138. package/rules/patterns/review-code-templates.mdc +2 -0
  139. package/rules/patterns/security-scan-patterns.mdc +141 -0
  140. package/rules/skills/_index.mdc +12 -1
  141. package/rules/skills/brain-skill.mdc +71 -0
  142. package/rules/skills/create-contract-skill.mdc +15 -30
  143. package/rules/skills/create-plan-skill.mdc +115 -30
  144. package/rules/skills/discovery-skill.mdc +154 -34
  145. package/rules/skills/execute-plan-skill.mdc +264 -3
  146. package/rules/skills/learn-skill.mdc +92 -0
  147. package/rules/skills/review-code-skill.mdc +123 -39
  148. package/rules/skills/review-pr-skill.mdc +82 -93
  149. package/rules/skills/setup-skill.mdc +91 -0
  150. package/rules/skills/write-tests-skill.mdc +18 -0
  151. package/scripts/hooks/pre-compact.cjs +85 -0
  152. package/scripts/hooks/session-end.cjs +284 -0
  153. package/scripts/hooks/session-start.cjs +145 -0
  154. package/skills/plan-flow/SKILL.md +16 -2
  155. package/skills/plan-flow/brain/SKILL.md +64 -0
  156. package/skills/plan-flow/create-contract/SKILL.md +11 -0
  157. package/skills/plan-flow/create-plan/SKILL.md +12 -0
  158. package/skills/plan-flow/discovery/SKILL.md +12 -0
  159. package/skills/plan-flow/execute-plan/SKILL.md +10 -0
  160. package/skills/plan-flow/learn/SKILL.md +49 -0
  161. package/skills/plan-flow/review-code/SKILL.md +12 -0
  162. package/skills/plan-flow/review-pr/SKILL.md +12 -0
  163. package/skills/plan-flow/setup/SKILL.md +10 -0
  164. package/skills/plan-flow/write-tests/SKILL.md +10 -0
  165. package/templates/shared/AGENTS.md.template +11 -0
  166. package/templates/shared/CLAUDE.md.template +13 -0
  167. package/templates/shared/hooks.json.example +7 -0
  168. package/templates/shared/session-hooks-instructions.md +29 -0
@@ -0,0 +1,251 @@
1
+ ---
2
+ description: Manual brain entry - capture meeting notes, ideas, brainstorms, and insights into the project brain
3
+ ---
4
+
5
+ # Brain: Manual Knowledge Capture
6
+
7
+ ## Command Description
8
+
9
+ This command allows manual brain entries for capturing meeting notes, brainstorms, ad-hoc ideas, and insights that don't come from automatic skill execution. Supports two modes: free-text (default) and guided prompts.
10
+
11
+ **Output**: Brain entries in `flow/brain/` with `[[wiki-links]]` for Obsidian compatibility.
12
+
13
+ ---
14
+
15
+
16
+ ## Help
17
+
18
+ **If the user invokes this command with `-help`, display only this section and stop:**
19
+
20
+ ```
21
+ /brain - Manual Brain Entry
22
+
23
+ DESCRIPTION:
24
+ Capture meeting notes, brainstorms, ideas, and insights into the
25
+ project brain. Creates Obsidian-compatible markdown with [[wiki-links]].
26
+
27
+ USAGE:
28
+ /brain <free text> Free-text mode (default)
29
+ /brain -guided Guided mode with structured questions
30
+ /brain -help Show this help
31
+
32
+ ARGUMENTS:
33
+ free text Unstructured text to parse and categorize
34
+ -guided Triggers structured question mode
35
+
36
+ EXAMPLES:
37
+ /brain Had a call with the team about auth flow. Decision: use JWT with refresh tokens.
38
+ /brain Discovered that the API rate limits at 100 req/min. Need to add throttling.
39
+ /brain -guided
40
+
41
+ OUTPUT:
42
+ - Writes to appropriate flow/brain/ subdirectory
43
+ - Creates [[wiki-links]] to related entries
44
+ - Updates flow/brain/index.md if needed
45
+
46
+ MODES:
47
+ Free-text: Parses input, extracts entities, categorizes, writes entry
48
+ Guided: Asks structured questions about work, insights, meetings, decisions
49
+
50
+ BRAIN STRUCTURE:
51
+ flow/brain/
52
+ ├── index.md # Brain index (always loaded at session start)
53
+ ├── features/ # Feature history and context
54
+ ├── errors/ # Reusable error patterns
55
+ ├── decisions/ # Decision records
56
+ └── sessions/ # Daily activity logs
57
+
58
+ RELATED COMMANDS:
59
+ /setup Creates brain directory structure
60
+ /discovery-plan Auto-captures to brain after completion
61
+ /execute-plan Auto-captures to brain after completion
62
+ ```
63
+
64
+ ---
65
+
66
+ > **AGENT_PROFILE: write-restricted**
67
+ > See `.claude/resources/core/agent-profiles.md` for tool access rules.
68
+
69
+ ## Critical Rules
70
+
71
+ | Rule | Description |
72
+ | ------------------------ | -------------------------------------------------------- |
73
+ | **Brain Only** | ONLY write to `flow/brain/` - no source code, no config |
74
+ | **Wiki-Links** | All cross-references use `[[kebab-case-name]]` format |
75
+ | **Index Caps** | Max 5 errors, 3 decisions, 3 cross-project in index |
76
+ | **No Code** | Brain is for knowledge capture, never write source code |
77
+ | **Complete and Stop** | After writing entry, STOP and wait for user |
78
+
79
+ ---
80
+
81
+ ## Instructions
82
+
83
+ ### Step 1: Validate Inputs
84
+
85
+ | Input | Required | Description |
86
+ | ----------- | -------- | ---------------------------------------------- |
87
+ | `content` | Yes | Free-text or triggered by `-guided` flag |
88
+ | `-guided` | Optional | Triggers structured question mode |
89
+
90
+ If no content and no `-guided` flag, ask:
91
+
92
+ ```markdown
93
+ What would you like to capture? You can:
94
+ 1. Type free text and I'll categorize it automatically
95
+ 2. Use `/brain -guided` for structured prompts
96
+ ```
97
+
98
+ ---
99
+
100
+ ### Step 2: Ensure Brain Directory Exists
101
+
102
+ Check if `flow/brain/` exists. If not, create:
103
+
104
+ ```bash
105
+ mkdir -p flow/brain/features flow/brain/errors flow/brain/decisions flow/brain/sessions
106
+ ```
107
+
108
+ Check if `flow/brain/index.md` exists. If not, create initial index:
109
+
110
+ ```markdown
111
+ # Project Brain
112
+
113
+ ## Active Features
114
+ _No features tracked yet._
115
+
116
+ ## Recent Errors
117
+ _No errors captured yet._
118
+
119
+ ## Recent Decisions
120
+ _No decisions recorded yet._
121
+
122
+ ## Cross-Project Patterns
123
+ _No cross-project patterns yet._
124
+ ```
125
+
126
+ ---
127
+
128
+ ### Step 3: Invoke Brain Skill
129
+
130
+ The skill will handle:
131
+
132
+ **Free-text mode**:
133
+ 1. Parse input text
134
+ 2. Extract entities (features, technologies, people, errors, decisions)
135
+ 3. Categorize into appropriate brain subdirectory
136
+ 4. Create/update brain files with `[[wiki-links]]`
137
+ 5. Update `flow/brain/index.md` if needed
138
+
139
+ **Guided mode** (`-guided`):
140
+ 1. Ask structured questions via `AskUserQuestion`
141
+ 2. Gather responses and follow-up text
142
+ 3. Generate properly formatted brain files
143
+ 4. Link everything with `[[wiki-links]]`
144
+ 5. Update `flow/brain/index.md`
145
+
146
+ See: `.claude/resources/skills/brain-skill.md`
147
+
148
+ ---
149
+
150
+ ### Step 4: Present Results
151
+
152
+ After the skill completes:
153
+
154
+ **Free-text result**:
155
+
156
+ ```markdown
157
+ Brain entry captured!
158
+
159
+ **Written to**: flow/brain/[subdirectory]/[file].md
160
+ **Links created**: [[feature-1]], [[error-name]]
161
+ **Index updated**: Yes/No
162
+ ```
163
+
164
+ **Guided result**:
165
+
166
+ ```markdown
167
+ Brain entry captured!
168
+
169
+ **Topics covered**:
170
+ - Feature: [[feature-name]] - summary
171
+ - Decision: [[decision-name]] - choice
172
+ - Meeting notes added to [[YYYY-MM-DD]]
173
+
174
+ **Index updated**: Yes
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Flow Diagram
180
+
181
+ ```
182
+ +------------------------------------------+
183
+ | /brain COMMAND |
184
+ +------------------------------------------+
185
+ |
186
+ v
187
+ +------------------------------------------+
188
+ | Step 1: Validate Inputs |
189
+ | - Check for content or -guided flag |
190
+ +------------------------------------------+
191
+ |
192
+ v
193
+ +------------------------------------------+
194
+ | Step 2: Ensure Brain Directory |
195
+ | - Create flow/brain/ if needed |
196
+ | - Create index.md if needed |
197
+ +------------------------------------------+
198
+ |
199
+ v
200
+ +------------------------------------------+
201
+ | Step 3: Invoke Brain Skill |
202
+ | - Free-text: parse, extract, categorize |
203
+ | - Guided: structured questions |
204
+ | - See brain-skill.md |
205
+ +------------------------------------------+
206
+ |
207
+ v
208
+ +------------------------------------------+
209
+ | Step 4: Present Results |
210
+ | - Show files written |
211
+ | - Show links created |
212
+ | - Show index update status |
213
+ +------------------------------------------+
214
+ ```
215
+
216
+ ---
217
+
218
+ ## Context Optimization
219
+
220
+ ### Recommended Loading Order
221
+
222
+ 1. **Always load first**: This command file (`commands/brain.md`)
223
+ 2. **Load indexes**: Load `_index.md` files for relevant folders
224
+ 3. **Expand on-demand**: Use reference codes to load specific sections when needed
225
+
226
+ ### Reference Codes for Brain
227
+
228
+ | Code | Description | When to Expand |
229
+ |------|-------------|----------------|
230
+ | SKL-BR-1 | Brain skill restrictions | Understanding allowed actions |
231
+ | SKL-BR-2 | Brain skill workflow | Processing entries |
232
+ | SKL-BR-3 | Output format and validation | Formatting output |
233
+ | PTN-BR-1 | Directory structure and naming | Creating brain files |
234
+ | PTN-BR-2 | Wiki-link patterns | Creating cross-references |
235
+ | PTN-BR-3 | Feature status lifecycle | Updating feature entries |
236
+ | COR-BR-1 | Session start behavior | Understanding brain loading |
237
+ | COR-BR-2 | File templates | Creating new brain files |
238
+ | COR-BR-3 | Index management caps | Enforcing index limits |
239
+
240
+ ---
241
+
242
+ ## Related Resources
243
+
244
+ | Resource | Purpose |
245
+ | --------------------------- | --------------------------------- |
246
+ | `resources/skills/_index.md` | Index of skills with reference codes |
247
+ | `resources/patterns/_index.md` | Index of patterns with reference codes |
248
+ | `resources/core/_index.md` | Index of core rules with reference codes |
249
+ | `brain-skill.md` | Skill that processes brain entries |
250
+ | `brain-patterns.md` | File naming and link conventions |
251
+ | `brain-capture.md` | Processing rules and templates |
@@ -55,6 +55,13 @@ RELATED COMMANDS:
55
55
 
56
56
  ---
57
57
 
58
+ > **MODE: Research**
59
+ > Explore before concluding. Read 3x more than you write. Prefer Read/Grep/Glob/WebSearch tools.
60
+ > Ask clarifying questions when uncertain. Don't jump to implementation.
61
+
62
+ > **AGENT_PROFILE: read-only**
63
+ > See `.claude/resources/core/agent-profiles.md` for tool access rules.
64
+
58
65
  ## Critical Rules
59
66
 
60
67
  | Rule | Description |
@@ -242,3 +249,46 @@ When executing this command:
242
249
  | `/discovery-plan` command | Create discovery from contract |
243
250
  | `/create-plan` command | Create plan from discovery |
244
251
 
252
+ ---
253
+
254
+ ## Compaction Suggestion
255
+
256
+ After contract creation completes, suggest context cleanup if the contract was complex (> 5 endpoints):
257
+
258
+ > Contract created. Consider running `/compact` to free context before the next task.
259
+
260
+ Skip if autopilot is ON.
261
+
262
+ ---
263
+
264
+ ## Brain Capture
265
+
266
+ After contract creation completes, append a brain-capture block. See `.claude/resources/core/brain-capture.md` for processing rules.
267
+
268
+ **Capture the following**:
269
+
270
+ ```
271
+ <!-- brain-capture
272
+ skill: create-contract
273
+ feature: [service name]
274
+ status: completed
275
+ data:
276
+ service_name: [API/service name]
277
+ endpoints_documented: [count]
278
+ auth_type: [detected auth type]
279
+ contract_doc: [path to contract document]
280
+ -->
281
+ ```
282
+
283
+ Update `flow/brain/features/[service-name].md` with contract context and update `flow/brain/index.md`.
284
+
285
+ ---
286
+
287
+ ## Resource Capture
288
+
289
+ During this skill's execution, watch for valuable reference materials worth preserving. See `.claude/resources/core/resource-capture.md` for capture rules, file format, and naming conventions.
290
+
291
+ At natural break points, if you encounter information that could be useful for future development (API specs, architecture notes, config references, domain knowledge, etc.), ask the user: "I found something that could be useful for future reference: _{brief description}_. Should I save it to `flow/resources/`?"
292
+
293
+ Only save if the user approves. Do not re-ask if declined.
294
+
@@ -64,6 +64,13 @@ RELATED COMMANDS:
64
64
  > - **If YES**: Autopilot is ON. After creating the plan and getting user approval, **auto-proceed** to `/execute-plan` with the plan output. Do NOT wait for manual invocation.
65
65
  > - **If NO**: Follow the standard rules below (stop and wait for user).
66
66
 
67
+ > **MODE: Research**
68
+ > Explore before concluding. Read 3x more than you write. Prefer Read/Grep/Glob/WebSearch tools.
69
+ > Ask clarifying questions when uncertain. Don't jump to implementation.
70
+
71
+ > **AGENT_PROFILE: read-only**
72
+ > See `.claude/resources/core/agent-profiles.md` for tool access rules.
73
+
67
74
  ## Critical Rules
68
75
 
69
76
  | Rule | Description |
@@ -293,3 +300,62 @@ When executing this command:
293
300
  | `/discovery-plan` command | Run discovery first |
294
301
  | `/execute-plan` command | Execute the created plan |
295
302
 
303
+ ---
304
+
305
+ ## Compaction Suggestion
306
+
307
+ After plan creation completes, suggest context cleanup:
308
+
309
+ > Plan created. Consider running `/compact` before execution to maximize available context for the implementation phases.
310
+
311
+ Only suggest if the plan has > 3 phases. Skip if autopilot is ON.
312
+
313
+ ---
314
+
315
+ ## Brain Capture
316
+
317
+ After plan creation completes successfully, append a brain-capture block. See `.claude/resources/core/brain-capture.md` for processing rules.
318
+
319
+ **Capture the following**:
320
+
321
+ ```
322
+ <!-- brain-capture
323
+ skill: create-plan
324
+ feature: [feature name]
325
+ status: completed
326
+ data:
327
+ phase_count: [number of phases]
328
+ total_complexity: [sum of complexity scores]
329
+ highest_phase: [phase name with highest score]
330
+ discovery_link: [[discovery-feature-name]]
331
+ plan_doc: [path to plan document]
332
+ -->
333
+ ```
334
+
335
+ Update `flow/brain/features/[feature-name].md` with plan details and link to discovery entry.
336
+
337
+ ---
338
+
339
+ ## Resource Capture
340
+
341
+ During this skill's execution, watch for valuable reference materials worth preserving. See `.claude/resources/core/resource-capture.md` for capture rules, file format, and naming conventions.
342
+
343
+ At natural break points, if you encounter information that could be useful for future development (API specs, architecture notes, config references, domain knowledge, etc.), ask the user: "I found something that could be useful for future reference: _{brief description}_. Should I save it to `flow/resources/`?"
344
+
345
+ Only save if the user approves. Do not re-ask if declined.
346
+
347
+ ---
348
+
349
+ ## Handoff
350
+
351
+ ### Consumption
352
+
353
+ Before creating the plan, check for `flow/handoffs/handoff_<feature>_discovery_to_plan.md` (or `handoff_<feature>_review_to_plan.md` for bugfix workflow). If it exists, read it silently and use its focus guidance to inform plan structure. If it doesn't exist, proceed normally (backward compatible).
354
+
355
+ ### Production
356
+
357
+ After the plan is created, produce a handoff for the execution step.
358
+
359
+ **Output**: `flow/handoffs/handoff_<feature>_plan_to_execute.md`
360
+
361
+ Include: feature name, workflow type, phase count, total complexity, highest complexity phase, plan and discovery paths, and focus guidance for execution.
@@ -18,6 +18,13 @@ This command creates a discovery document for gathering and clarifying requireme
18
18
  > - **If YES**: Autopilot is ON. After completing discovery and user Q&A, **auto-proceed** to `/create-plan` with the discovery output. Do NOT ask "Would you like to proceed?" - just continue.
19
19
  > - **If NO**: Follow the standard rules below (stop and wait for user).
20
20
 
21
+ > **MODE: Research**
22
+ > Explore before concluding. Read 3x more than you write. Prefer Read/Grep/Glob/WebSearch tools.
23
+ > Ask clarifying questions when uncertain. Don't jump to implementation.
24
+
25
+ > **AGENT_PROFILE: read-only**
26
+ > See `.claude/resources/core/agent-profiles.md` for tool access rules.
27
+
21
28
  > ⚠️ **IMPORTANT - DISCOVERY ONLY**
22
29
  >
23
30
  > This command ONLY creates a discovery document. It does NOT:
@@ -66,8 +73,9 @@ WORKFLOW:
66
73
  4. Documents requirements (FR, NFR, Constraints)
67
74
  5. Proposes high-level approach (no code)
68
75
  6. Creates discovery document for review
69
- 7. Asks user if they want to proceed to /create-plan
70
- 8. Waits for user confirmation before proceeding
76
+ 7. Asks user if they want to proceed, refine, or stop
77
+ 8. Supports iterative refinement (max 3 rounds)
78
+ 9. Waits for user confirmation before proceeding
71
79
 
72
80
  RECOMMENDED MODEL:
73
81
  Claude Opus 4.6 or Sonnet 4.5 for best results
@@ -121,6 +129,24 @@ To start the discovery process, I need to understand:
121
129
 
122
130
  ---
123
131
 
132
+ ### Step 1.5: Search for Existing Solutions
133
+
134
+ **Before recommending implementation**, check if the problem is already solved:
135
+
136
+ 1. **Project code**: Use Grep/Glob to search for existing implementations, similar patterns, or utilities that already address part of the requirement
137
+ 2. **Package registries**: Use WebSearch to check npm (for JS/TS projects) or PyPI (for Python projects) for established libraries
138
+ - Search: `"{problem description} npm package"` or `"{problem description} python library"`
139
+ - Evaluate: maintenance status (last publish date), weekly downloads, compatibility with project stack
140
+ 3. **Document findings** in an "Existing Solutions Analysis" section in the discovery document
141
+
142
+ **Decision criteria**:
143
+ - If an existing library covers **>80%** of the need → recommend using it instead of building from scratch
144
+ - If **<80%** → note what it covers and what custom work remains
145
+
146
+ **Graceful degradation**: If WebSearch is unavailable, skip registry search and note "Package registry search skipped — WebSearch unavailable" in the discovery document. Always perform the project code search.
147
+
148
+ ---
149
+
124
150
  ### Step 2: Extract Feature Name
125
151
 
126
152
  From the user input, extract or derive a feature name for the discovery document.
@@ -155,8 +181,9 @@ The skill will:
155
181
  7. Propose high-level approach
156
182
  8. Document risks and unknowns
157
183
  9. Generate discovery document
158
- 10. Ask user if they want to proceed to /create-plan
159
- 11. Wait for user confirmation before proceeding
184
+ 10. Support iterative refinement (max 3 rounds) if user requests it
185
+ 11. Ask user if they want to proceed to /create-plan
186
+ 12. Wait for user confirmation before proceeding
160
187
 
161
188
  See: `.claude/resources/skills/discovery-skill.md`
162
189
 
@@ -193,7 +220,7 @@ AskUserQuestion({
193
220
  options: [
194
221
  { label: "Yes, create plan", description: "I'll invoke /create-plan with the discovery document" },
195
222
  { label: "No, review first", description: "You can review the discovery and invoke /create-plan when ready" },
196
- { label: "Refine discovery", description: "Let me know what needs to be adjusted in the discovery" }
223
+ { label: "Refine discovery", description: "Iteratively refine the discovery document (max 3 rounds)" }
197
224
  ],
198
225
  multiSelect: false
199
226
  }]
@@ -204,6 +231,31 @@ AskUserQuestion({
204
231
 
205
232
  Do NOT auto-invoke `/create-plan` without user confirmation.
206
233
 
234
+ #### Refinement Loop (when "Refine discovery" is selected)
235
+
236
+ When the user selects "Refine discovery", invoke the discovery skill's **Step 9: Refinement Loop**:
237
+
238
+ 1. **Accept feedback**: Ask user what areas need adjustment (requirements, approach, scope, risks)
239
+ 2. **Follow-up questions**: Ask 1-3 targeted questions about the refinement areas only
240
+ 3. **Update document**: Modify the discovery document in-place, add/update Refinement History section
241
+ 4. **Re-present**: Show the updated document and offer the same 3 options again
242
+ 5. **Round tracking**: Track refinement round count (max 3). After 3 rounds, only offer "Yes, create plan" and "No, review first" — the "Refine discovery" option is removed
243
+
244
+ ```typescript
245
+ // After 3 refinement rounds, remove the refine option:
246
+ AskUserQuestion({
247
+ questions: [{
248
+ question: "Discovery refined 3 times (maximum). Would you like to proceed?",
249
+ header: "Next step",
250
+ options: [
251
+ { label: "Yes, create plan", description: "I'll invoke /create-plan with the discovery document" },
252
+ { label: "No, stop here", description: "You can review and invoke /create-plan manually when ready" }
253
+ ],
254
+ multiSelect: false
255
+ }]
256
+ })
257
+ ```
258
+
207
259
  ---
208
260
 
209
261
  ## Flow Diagram
@@ -323,3 +375,59 @@ Read: resources/tools/interactive-questions-tool.md (lines from TLS-IQ-3)
323
375
  | `interactive-questions-tool.md` | Interactive Questions UI workflow |
324
376
  | `/create-plan` command | Creates plan from discovery document |
325
377
 
378
+ ---
379
+
380
+ ## Compaction Suggestion
381
+
382
+ After discovery completes, suggest context cleanup:
383
+
384
+ > Discovery complete. Consider running `/compact` before creating a plan to free context for the planning phase.
385
+
386
+ Only suggest if the discovery was substantial (> 5 requirements gathered). Skip if autopilot is ON (context will be managed automatically).
387
+
388
+ ---
389
+
390
+ ## Brain Capture
391
+
392
+ After discovery completes successfully, append a brain-capture block. See `.claude/resources/core/brain-capture.md` for processing rules.
393
+
394
+ **Capture the following**:
395
+
396
+ ```
397
+ <!-- brain-capture
398
+ skill: discovery
399
+ feature: [feature name from discovery]
400
+ status: completed
401
+ data:
402
+ user_prompt: [original user request]
403
+ questions_asked: [count]
404
+ questions_answered: [count]
405
+ requirements_fr: [count of functional requirements]
406
+ requirements_nfr: [count of non-functional requirements]
407
+ discovery_doc: [path to discovery document]
408
+ -->
409
+ ```
410
+
411
+ Write/update `flow/brain/features/[feature-name].md` with discovery context and update `flow/brain/index.md`.
412
+
413
+ ---
414
+
415
+ ## Resource Capture
416
+
417
+ During this skill's execution, watch for valuable reference materials worth preserving. See `.claude/resources/core/resource-capture.md` for capture rules, file format, and naming conventions.
418
+
419
+ At natural break points, if you encounter information that could be useful for future development (API specs, architecture notes, config references, domain knowledge, etc.), ask the user: "I found something that could be useful for future reference: _{brief description}_. Should I save it to `flow/resources/`?"
420
+
421
+ Only save if the user approves. Do not re-ask if declined.
422
+
423
+ ---
424
+
425
+ ## Handoff Production
426
+
427
+ After discovery completes, produce a handoff document for the next step. See `.claude/resources/patterns/handoff-patterns.md` [PTN-HND-1] for the template.
428
+
429
+ **Output**: `flow/handoffs/handoff_<feature>_discovery_to_plan.md`
430
+
431
+ Include: feature name, workflow type, requirements summary (FR/NFR/C counts), key decisions from Q&A, top risks, discovery doc path, and focus guidance for planning.
432
+
433
+ Create the `flow/handoffs/` directory if it doesn't exist.