@claude-pw/framework 0.3.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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.es.md +173 -0
  3. package/README.ja.md +173 -0
  4. package/README.md +173 -0
  5. package/README.pt-br.md +173 -0
  6. package/README.zh-cn.md +173 -0
  7. package/RELEASES.md +66 -0
  8. package/install.js +593 -0
  9. package/package.json +35 -0
  10. package/templates/CHANGELOG.md +6 -0
  11. package/templates/CLAUDE.md.tpl +38 -0
  12. package/templates/Makefile +37 -0
  13. package/templates/PLAN.md.tpl +18 -0
  14. package/templates/STATUS.md.tpl +15 -0
  15. package/templates/claude/agents/codebase-mapper.md +105 -0
  16. package/templates/claude/agents/debugger.md +90 -0
  17. package/templates/claude/agents/decision-impact.md +36 -0
  18. package/templates/claude/agents/implementer.md +73 -0
  19. package/templates/claude/agents/interface-reviewer.md +22 -0
  20. package/templates/claude/agents/learning-extractor.md +104 -0
  21. package/templates/claude/agents/phase-validator.md +108 -0
  22. package/templates/claude/agents/plan-checker.md +18 -0
  23. package/templates/claude/agents/researcher.md +85 -0
  24. package/templates/claude/agents/session-recovery.md +127 -0
  25. package/templates/claude/agents/spike-explorer.md +34 -0
  26. package/templates/claude/commands/cpw-debug.md +116 -0
  27. package/templates/claude/commands/cpw-discuss.md +70 -0
  28. package/templates/claude/commands/cpw-health.md +67 -0
  29. package/templates/claude/commands/cpw-impact.md +22 -0
  30. package/templates/claude/commands/cpw-next-step.md +492 -0
  31. package/templates/claude/commands/cpw-pause.md +49 -0
  32. package/templates/claude/commands/cpw-quick.md +83 -0
  33. package/templates/claude/commands/cpw-reflect.md +209 -0
  34. package/templates/claude/commands/cpw-startup.md +321 -0
  35. package/templates/claude/commands/cpw-todos.md +100 -0
  36. package/templates/claude/hooks/cpw-context-monitor.js +59 -0
  37. package/templates/claude/hooks/cpw-statusline.js +36 -0
  38. package/templates/claude/rules/git.md +27 -0
  39. package/templates/claude/rules/interfaces.md +9 -0
  40. package/templates/claude/rules/testing.md +8 -0
  41. package/templates/claude/settings.json +42 -0
  42. package/templates/docs/architecture.md +4 -0
  43. package/templates/docs/codebase-map.md +3 -0
  44. package/templates/docs/conventions.md +3 -0
  45. package/templates/docs/interfaces.md +10 -0
  46. package/templates/docs/tech-debt.md +3 -0
  47. package/templates/docs/tooling.md +15 -0
  48. package/templates/gitignore +17 -0
  49. package/templates/husky/pre-commit +23 -0
  50. package/templates/planning/config.json +11 -0
  51. package/templates/planning/learnings/applied.md +3 -0
  52. package/templates/planning/learnings/queue.md +5 -0
  53. package/templates/planning/quick/log.md +4 -0
  54. package/templates/plans/decisions.md +9 -0
  55. package/templates/plans/phase-0.md +57 -0
  56. package/templates/plans/phase-1.md +49 -0
@@ -0,0 +1,209 @@
1
+ ---
2
+ description: "Review captured corrections and turn them into project learnings"
3
+ ---
4
+
5
+ ## Arguments
6
+ - No arguments: normal flow (steps 1-5)
7
+ - `--dedupe`: scan destination files for duplicates and contradictions (step 6)
8
+ - `--scan-history`: scan past sessions for missed corrections (step 1.1)
9
+ - `--days N`: limit history scan to last N days (default: 30). Only with --scan-history.
10
+
11
+ ## 0. Check arguments
12
+
13
+ If the user passed `--dedupe`, go directly to step 6.
14
+ If `--scan-history`, continue to step 1 then step 1.1.
15
+ Otherwise, continue with the normal flow (skip step 1.1).
16
+
17
+ ## 1. Load learning queue
18
+ Read `.planning/learnings/queue.md`.
19
+ - If it doesn't exist or is empty (no `---` entries): "No pending corrections. Nothing to do."
20
+ - If it has entries: continue.
21
+ - **Backwards compatibility**: if there are entries in the old table format (`| Fecha | Correccion | Contexto |`), migrate each row to v2 format with `Pattern: correction`, `Confidence: 0.65`, `Validated: no`.
22
+
23
+ ## 1.1 Scan session history (only with --scan-history)
24
+
25
+ ### Locate session files
26
+ Determine the project session directory:
27
+ - Project path: current working directory (pwd)
28
+ - Encode path: replace `/` with `-`, remove leading `-`
29
+ - Session dir: `~/.claude/projects/-[ENCODED_PATH]/`
30
+ - Find `*.jsonl` files, filter by `--days N` modification time (default: 30 days)
31
+
32
+ If no session files found: "No sessions found for this project in the last N days."
33
+
34
+ ### Extract corrections from sessions
35
+ For each session file, read and scan for user messages (role: "user") that match correction patterns:
36
+ - Explicit: "remember:", "recuerda:"
37
+ - Strong corrections: "no use", "don't", "actually", "stop", "never", "always", "I told you", "I said"
38
+ - Tool rejections: messages where the user blocked a tool action and provided corrective feedback
39
+
40
+ Skip:
41
+ - Messages marked as `isMeta: true` (command expansions like /cpw-reflect itself)
42
+ - Very long messages (>500 chars) unless they contain explicit markers
43
+ - Messages that are clearly task requests or questions
44
+
45
+ ### Add to working queue
46
+ For each extracted correction:
47
+ - Create a queue entry: `Pattern: correction`, `Confidence: 0.65`, `Validated: no`
48
+ - Tool rejections get `Confidence: 0.80` (user explicitly stopped an action)
49
+ - Deduplicate against existing queue entries and `.planning/learnings/applied.md`
50
+
51
+ Show summary:
52
+ ```
53
+ Session scan: X sessions analyzed (last N days)
54
+ - Y potential corrections found
55
+ - Z already in queue/applied (skipped)
56
+ - W new entries added to working queue
57
+ ```
58
+
59
+ Continue to step 1.5 with the enriched queue.
60
+
61
+ ## 1.5 Semantic validation
62
+
63
+ For each entry with `Validated: no`, analyze semantically:
64
+
65
+ ### Filter false positives
66
+ Silently discard if the correction is:
67
+ - A disguised question ("why did you use X?" without proposing an alternative)
68
+ - A bug report ("this fails", "there's an error in...")
69
+ - A task request ("add a test for...", "implement...")
70
+ - A simple confirmation ("ok", "yes", "sure", "done")
71
+ - A one-off instruction, not generalizable
72
+
73
+ This step supports any language — analyze the intent, not just keywords.
74
+
75
+ ### Extract actionable learning
76
+ For each valid entry, rewrite the correction as a concise imperative statement:
77
+ - Input: "no no, actually use Zod for that, don't use Joi"
78
+ - Learning: "Use Zod instead of Joi for schema validation"
79
+
80
+ ### Adjust confidence
81
+ Evaluate semantic confidence (0.0-1.0) based on:
82
+ - **Clarity**: is it specific? does it mention concrete tools/patterns? (+)
83
+ - **Generality**: does it always apply or only in this specific case? (+)
84
+ - **Emphasis**: was the user emphatic (repetition, "I told you", "always")? (+)
85
+
86
+ Final confidence = `max(pattern_confidence, semantic_confidence)`
87
+
88
+ ### Update entries
89
+ - Valid entries: set `Validated: yes`, update `Confidence`, annotate the rewritten learning
90
+ - Discarded entries: remove from queue
91
+
92
+ Show summary before continuing:
93
+ ```
94
+ Semantic validation: X entries analyzed
95
+ - Y confirmed as learnings
96
+ - Z discarded (false positives)
97
+
98
+ Discarded:
99
+ - "why did you use that?" — question, not correction
100
+ - "there's an error in the login" — bug report
101
+ ```
102
+
103
+ ## 2. Review each entry
104
+ For each validated correction, delegate to the learning-extractor agent:
105
+ <files_to_read>
106
+ - ./CLAUDE.md (if exists)
107
+ - .planning/learnings/queue.md
108
+ - .planning/learnings/applied.md (if exists)
109
+ </files_to_read>
110
+ Correction: [the correction entry]
111
+ The agent classifies and proposes a destination:
112
+ - **RULE**: new rule or adjustment to CLAUDE.md / .claude/rules/
113
+ - **CONVENTION**: document in docs/conventions.md
114
+ - **DECISION**: record in plans/decisions.md
115
+ - **PIPELINE**: adjust default stages in next-step, startup, or route back to the specific command/agent file
116
+ - **SKILL**: non-obvious discovery → create .claude/skills/[name].md
117
+ - **DISCARD**: not generalizable, one-off case
118
+
119
+ ### Command-aware routing
120
+ If the entry has a **Command** field, the learning-extractor uses it to route corrections back to the originating command or its agents. For example, a correction captured during `/cpw-next-step` about skipping SPIKE stage routes to `.claude/commands/cpw-next-step.md`, not to a generic file.
121
+
122
+ ## 3. Present to user
123
+ Show each proposal with change preview and confidence:
124
+ ```
125
+ 1. [RULE] (0.85) "Use X instead of Y for Z" -> CLAUDE.md
126
+ 2. [CONVENTION] (0.75) "Always use alias imports @/" -> docs/conventions.md
127
+ 3. [PIPELINE] (0.85) "Always run tests before CLOSE" -> .claude/commands/cpw-next-step.md
128
+ (captured during /cpw-next-step)
129
+ 4. [SKILL] (0.80) "ESM import error in Jest actually means missing transform config" -> .claude/skills/jest-esm-transform.md
130
+ 5. [DISCARD] (0.50) "Variable typo" -> n/a
131
+ ```
132
+ Wait for item-by-item approval (or "apply all").
133
+
134
+ ### SKILL creation
135
+ For approved SKILL items:
136
+ - Create the skill file at `.claude/skills/[name-slug].md` using the template from learning-extractor output
137
+ - Ask: "Should this skill apply globally (~/.claude/skills/) or only to this project? (project/global)"
138
+ - In autoAdvance auto/yolo: default to project
139
+ - Verify the description contains specific keywords for semantic retrieval (error messages, framework names, symptoms)
140
+
141
+ ## 4. Apply approved changes
142
+ - Write to the corresponding destination
143
+ - For SKILL items: create .claude/skills/[name-slug].md
144
+ - For PIPELINE items routed to commands/agents: append as a new section or update existing guidance
145
+ - Mark as processed in queue.md
146
+ - `make commit m="learn: apply session learnings"`
147
+
148
+ ## 5. Clean up
149
+ Move processed entries to `.planning/learnings/applied.md` with this format:
150
+ ```
151
+ ---
152
+ - **Date applied**: [today]
153
+ - **Learning**: [concise learning statement]
154
+ - **Type**: [RULE|CONVENTION|DECISION|PIPELINE]
155
+ - **Destination**: [file where it was applied]
156
+ - **Final confidence**: [numeric score]
157
+ ---
158
+ ```
159
+ Remove processed entries from queue.md.
160
+
161
+ ## 6. Deduplication (only with --dedupe)
162
+
163
+ ### 6.1 Load destinations
164
+ Read all files containing applied learnings:
165
+ - CLAUDE.md
166
+ - docs/conventions.md (if exists)
167
+ - plans/decisions.md (if exists)
168
+ - .claude/rules/*.md
169
+
170
+ ### 6.2 Extract entries
171
+ For each file, extract individual lines/bullet points that represent rules, conventions, or decisions.
172
+
173
+ ### 6.3 Detect semantic duplicates
174
+ Group entries that:
175
+ - Refer to the same tool, pattern, or concept
176
+ - Give redundant or overlapping advice
177
+ - Could be merged without losing information
178
+
179
+ ### 6.4 Detect contradictions
180
+ Look for entries that contradict each other:
181
+ - "Use X" vs "Don't use X"
182
+ - "Always do Y" vs "Never do Y"
183
+
184
+ ### 6.5 Present findings
185
+ ```
186
+ ══════════════════════════════════════════
187
+ DEDUPLICATION
188
+ ══════════════════════════════════════════
189
+
190
+ CONTRADICTIONS (if any):
191
+ file:line "Rule A"
192
+ file:line "Rule B"
193
+ -> Description of the conflict
194
+
195
+ SIMILAR ENTRIES (if any):
196
+ Group 1:
197
+ file:line "Entry A"
198
+ file:line "Entry B"
199
+ -> Consolidated proposal: "Unified text"
200
+
201
+ Unique entries: N (no changes needed)
202
+ ══════════════════════════════════════════
203
+ ```
204
+
205
+ ### 6.6 Apply with approval
206
+ - For each contradiction: ask the user which one to keep
207
+ - For each similar group: ask whether to apply the consolidated version
208
+ - Apply approved changes with Edit
209
+ - `make commit m="learn: deduplicate learnings"`
@@ -0,0 +1,321 @@
1
+ ---
2
+ description: "Discovery session -- detect mode (greenfield/brownfield/bluefield), interview and generate plan"
3
+ ---
4
+
5
+ Note: For standalone codebase analysis without starting the full workflow,
6
+ run /cpw-startup on an existing project — the SCAN step produces a full
7
+ analysis report. You can stop after the scan by declining plan generation.
8
+
9
+ ## 0. MODE DETECTION
10
+
11
+ Check the directory state:
12
+ - Are there source files? (src/, lib/, app/, *.py, *.ts, *.go, etc.)
13
+ - Is there git history? (more than 3 commits)
14
+ - Is there a package manager? (package.json, requirements.txt, go.mod, Cargo.toml, etc.)
15
+
16
+ If there is NO code:
17
+ - Automatic **GREENFIELD** mode. Go to step 1.
18
+
19
+ If there IS code, ask:
20
+ ```
21
+ Detected an existing project ([detected stack], [N files], [N commits]).
22
+ What do you want to do?
23
+
24
+ 1. BROWNFIELD — Add claude-pw workflow structure to this project as-is
25
+ 2. BLUEFIELD — Rewrite or replace parts of this project
26
+ 3. GREENFIELD — Ignore existing code, start from scratch
27
+ ```
28
+
29
+ ## 0.5 SCAN (brownfield/bluefield only)
30
+
31
+ Delegate to the codebase-mapper agent:
32
+ <files_to_read>
33
+ - ./CLAUDE.md (if exists)
34
+ </files_to_read>
35
+ Wait for report.
36
+ Pre-fill context with findings:
37
+ - Stack -> detected
38
+ - Modules -> inferred from code
39
+ - Conventions -> detected
40
+ - Integrations -> detected
41
+ - Tech debt -> identified (relevant for bluefield)
42
+
43
+ Write docs/ with the report (same logic as /cpw-startup steps 3-4).
44
+
45
+ ## 0.7 TOOLING HEALTH CHECK (brownfield only)
46
+
47
+ Skip this step for greenfield and bluefield.
48
+
49
+ After the codebase scan, audit the project's existing tooling against best practices for the detected stack. Check each category:
50
+
51
+ | Category | What to check |
52
+ |----------|--------------|
53
+ | **Linter** | Installed? Configured? Version current? (ESLint, Pylint, golangci-lint, etc.) |
54
+ | **Formatter** | Installed? Configured? (Prettier, Black, gofmt, etc.) |
55
+ | **Type checking** | TypeScript, JSDoc, mypy, type hints? strictness level? |
56
+ | **Test runner** | Installed? Tests exist? Coverage configured? Coverage threshold? |
57
+ | **Pre-commit hooks** | Husky, lint-staged, pre-commit (Python)? What do they run? |
58
+ | **CI/CD** | Pipeline exists? (.github/workflows, .gitlab-ci, etc.) What does it run? |
59
+ | **Git hygiene** | .gitignore complete? Lockfile committed? Secrets exposed? (.env, credentials, API keys in repo) |
60
+ | **Dependencies** | Major versions outdated? Deprecated packages? Known vulnerabilities? |
61
+
62
+ Present a report:
63
+
64
+ ```
65
+ ══════════════════════════════════════════
66
+ TOOLING HEALTH — [project name]
67
+ ══════════════════════════════════════════
68
+
69
+ ✓ Linter: ESLint 9.x (up to date)
70
+ ✗ Formatter: none detected
71
+ ✓ Tests: Jest (48 tests, no coverage config)
72
+ ✗ Pre-commit: none
73
+ ✗ CI/CD: none
74
+ ✓ Types: TypeScript 5.x (strict mode)
75
+ ⚠ .gitignore: missing .env
76
+ ✓ Dependencies: all current
77
+
78
+ Recommendations:
79
+ 1. Add Prettier for code formatting
80
+ 2. Add Husky + lint-staged for pre-commit
81
+ 3. Configure coverage threshold (suggest 80%)
82
+ 4. Add CI pipeline (GitHub Actions recommended for this stack)
83
+ ══════════════════════════════════════════
84
+ ```
85
+
86
+ These recommendations will be incorporated as steps in Phase 0 of the generated plan.
87
+ Do NOT ask the user to act on them now — just present the report and continue to the interview.
88
+
89
+ ---
90
+
91
+ ## 1. INITIAL CONTEXT
92
+
93
+ **Greenfield**: Ask the user to describe the project freely. Don't interrupt.
94
+
95
+ **Brownfield**: Present scan synthesis. Ask: "Does this accurately reflect the project? What's missing or wrong?"
96
+
97
+ **Bluefield**: Present scan synthesis + ask: "Which parts do you want to rewrite and why? What stays?"
98
+
99
+ ## 2. STRUCTURED INTERVIEW
100
+
101
+ MAXIMUM 3-4 questions per turn. Adapt based on mode:
102
+
103
+ ### Greenfield (6 full rounds)
104
+
105
+ **Round 1 -- Problem and objective:**
106
+ - What problem does this project solve?
107
+ - Who will use it?
108
+ - Is there something existing we're replacing or is it completely new?
109
+
110
+ **Round 2 -- Scope:**
111
+ - What should it be able to do in the first version (v1)?
112
+ - What should it explicitly NOT do? (boundaries)
113
+ - Is there a deadline or time constraint?
114
+
115
+ **Round 3 -- Components and architecture:**
116
+ - What logical parts do you see? (if unsure, propose modules based on what was described)
117
+ - Are there external integrations? (APIs, DBs, third-party services)
118
+ - Architecture preference? (monolith, services, serverless, etc.)
119
+
120
+ **Round 4 -- Stack and technical constraints:**
121
+ - Preferred language/framework or open to proposals?
122
+ - Infrastructure? (cloud, local, docker, etc.)
123
+ - Any tech already decided or prohibited?
124
+
125
+ **Round 5 -- Tooling and accelerators:**
126
+ - Are there domains where a skill or MCP server would help?
127
+ - Do you already use any MCP server or Claude Code skill?
128
+ - Prefer keeping it minimal or open to installing tools that speed things up?
129
+
130
+ **Round 6 -- Development context:**
131
+ - Working solo or in a team?
132
+ - Priority: delivery speed vs robustness?
133
+
134
+ ### Brownfield (2 rounds — the scan covers the rest)
135
+
136
+ **Round 1 -- Objective:**
137
+ - What do you want to achieve now with this project? (new feature, refactor, improvement?)
138
+ - Is there a defined scope for what's next?
139
+ - Any deadline or constraint?
140
+
141
+ **Round 2 -- Gaps:**
142
+ - Did the scan detect the architecture correctly? Anything to fix?
143
+ - Are there undocumented decisions I should know about?
144
+ - Useful skills/MCPs for what's coming?
145
+
146
+ ### Bluefield (3 rounds)
147
+
148
+ **Round 1 -- Motivation:**
149
+ - Why rewrite? (tech debt, new requirement, stack change, compliance?)
150
+ - What stays from the current system? (data, public APIs, UI?)
151
+ - What gets discarded?
152
+
153
+ **Round 2 -- Target:**
154
+ - What should the new system look like?
155
+ - Stack change? Yes/No and why
156
+ - Strategy: big bang or gradual migration?
157
+
158
+ **Round 3 -- Constraints:**
159
+ - Need to maintain backward compatibility? With what?
160
+ - Deadline for the migration?
161
+ - Useful skills/MCPs?
162
+
163
+ If the user doesn't know something, mark it as "pending decision for Phase 0".
164
+ Don't bombard -- if a round is partially answered, adapt the next one.
165
+
166
+ ## 3. SYNTHESIS
167
+ Produce a structured summary:
168
+
169
+ ```
170
+ ### Mode: [GREENFIELD | BROWNFIELD | BLUEFIELD]
171
+
172
+ ### Vision
173
+ [2-3 sentences]
174
+
175
+ ### Identified modules
176
+ - [module]: [responsibility]
177
+
178
+ ### Scope v1
179
+ - Includes: [list]
180
+ - Excludes: [list]
181
+
182
+ ### Constraints and decisions already made
183
+ - [decision]: [reason]
184
+
185
+ ### Skills and MCPs to evaluate in Phase 0
186
+ - [skill/MCP]: [what it would be used for]
187
+ - (or "none identified for now")
188
+
189
+ ### Pending for Phase 0
190
+ - [what still needs to be decided]
191
+ ```
192
+
193
+ **Bluefield extra:**
194
+ ```
195
+ ### Migration plan
196
+ - Keep: [what stays untouched]
197
+ - Rewrite: [modules to replace]
198
+ - Strategy: [big bang | gradual]
199
+ - Backward compat: [yes/no + details]
200
+ ```
201
+
202
+ Present it to the user. Do NOT proceed without approval.
203
+
204
+ ## 3.5 AUTO-RESEARCH (if applicable)
205
+ Review the synthesis. For each item in "Pending for Phase 0" and uncertain technical decisions:
206
+ - If it's "which library/framework to use" -> delegate to the researcher agent:
207
+ <files_to_read>
208
+ - ./CLAUDE.md (if exists)
209
+ - docs/architecture.md (if exists)
210
+ </files_to_read>
211
+ Type: library
212
+ Topic: [item from pending decisions]
213
+ - If it's "is this approach viable" -> delegate to the researcher agent:
214
+ <files_to_read>
215
+ - ./CLAUDE.md (if exists)
216
+ - docs/architecture.md (if exists)
217
+ </files_to_read>
218
+ Type: feasibility
219
+ Topic: [item from pending decisions]
220
+ - If it's a preference/business decision -> skip (needs human)
221
+
222
+ Save results in docs/research/. Present summaries along with the synthesis.
223
+ If there's nothing to research, skip this section.
224
+
225
+ ## 3.7 WORKFLOW CONFIGURATION
226
+
227
+ Before generating the plan, ask workflow preferences:
228
+
229
+ ```
230
+ Workflow configuration:
231
+
232
+ 1. Advance mode:
233
+ a) MANUAL -- I approve each pipeline stage (recommended for learning)
234
+ b) AUTO -- Auto-advances all stages, pauses only for UAT and ambiguous decisions
235
+ c) YOLO -- Auto-advances everything including UAT, pauses only on errors or issues found
236
+
237
+ 2. Plan granularity:
238
+ a) COARSE -- 3-5 phases, large steps (small projects)
239
+ b) STANDARD -- 5-8 phases (default)
240
+ c) FINE -- 8-12 phases, smaller steps (complex projects)
241
+
242
+ 3. Model profile for agents:
243
+ a) QUALITY -- opus for all (maximum performance, higher cost)
244
+ b) BALANCED -- sonnet + haiku by role (default)
245
+ c) BUDGET -- haiku for most (lower cost)
246
+
247
+ 4. Git strategy:
248
+ a) TRUNK-BASED -- commit directly to main, push after each step (default, solo dev)
249
+ b) FEATURE-BRANCH -- branch per phase, PR to merge when phase completes (teams, code review)
250
+ c) GITFLOW -- develop branch + feature branches per phase, release branches (teams, formal releases)
251
+
252
+ 5. Track planning docs in git?
253
+ a) YES -- .planning/ committed to git (team projects, shared decisions)
254
+ b) NO -- .planning/ stays local-only (default, solo projects, OSS contributions)
255
+ ```
256
+
257
+ Recommend based on context:
258
+ - Solo dev or small project → trunk-based
259
+ - Team or needs code review → feature-branch
260
+ - Team with release cycles → gitflow
261
+
262
+ Save responses in `.planning/config.json`:
263
+ ```json
264
+ {
265
+ "autoAdvance": "off|auto|yolo",
266
+ "granularity": "coarse|standard|fine",
267
+ "modelProfile": "quality|balanced|budget",
268
+ "modelOverrides": {},
269
+ "gitStrategy": "trunk-based|feature-branch|gitflow",
270
+ "commitPlanning": false
271
+ }
272
+ ```
273
+
274
+ If the user has no preference, use defaults (off/standard/balanced/no).
275
+
276
+ **If `commitPlanning: true`:**
277
+ - Remove `.planning/` from `.gitignore`
278
+ - Planning artifacts (config, learnings, decisions, debug sessions) will be tracked in git
279
+ - STATUS.md is ALWAYS gitignored (personal session state)
280
+
281
+ **If `commitPlanning: false` (default):**
282
+ - Keep `.planning/` in `.gitignore`
283
+ - Planning stays local-only
284
+
285
+ ---
286
+
287
+ ## 4. PLAN GENERATION
288
+ Once the synthesis is approved, generate:
289
+
290
+ Read `granularity` from `.planning/config.json` to determine how many phases to generate:
291
+ - **coarse**: 3-5 total phases. Combine related modules. Larger steps.
292
+ - **standard**: 5-8 phases. One phase per module. (default)
293
+ - **fine**: 8-12 phases. Large modules split into sub-features. Smaller steps.
294
+
295
+ 1. **README.md** -- Project README with: what it is (1-2 sentences), stack, how to install/run, project structure, contributing notes. Keep it concise but useful for any developer opening the repo for the first time.
296
+ 2. **PLAN.md** -- Index: description, modules, phase table, key files
297
+ 3. **plans/phase-0.md** -- Stack and Scaffolding
298
+ - Greenfield: complete (6 steps)
299
+ - Brownfield: adapted — skip steps covered by scan (stack already detected), add steps from tooling health check recommendations (e.g.: "add pre-commit hooks", "configure CI pipeline", "add coverage threshold")
300
+ - Bluefield: includes migration steps (new setup + bridge with old)
301
+ 4. **plans/phase-1.md** -- Interfaces and Modules (always)
302
+ 5. **plans/phase-2+.md** -- One phase per identified module (draft if info is missing)
303
+ - Bluefield: migration phases per module (old -> new)
304
+ 6. **plans/decisions.md** -- With decisions made during startup
305
+ 7. **docs/architecture.md** -- Draft (greenfield) or updated (brownfield/bluefield)
306
+ 8. **STATUS.md** -- Pointing to Phase 0, Step 0.1, Stage DESIGN
307
+
308
+ ## 5. PLAN REVIEW
309
+ Present the plan phase by phase for review:
310
+ - First PLAN.md (complete index)
311
+ - Then each sub-plan, one by one
312
+ - Wait for approval/adjustment on each before moving to the next
313
+ - Update files with adjustments
314
+
315
+ ## 6. COMMIT AND START
316
+ - `make commit m="chore: initial plan from startup ([mode])"`
317
+ - Report: "Plan generated. Run `/clear` first to reset context, then:"
318
+ - " 1. `/cpw-discuss` — clarify ambiguities before building (recommended)"
319
+ - " 2. `/cpw-todos` — review pending todos before starting"
320
+ - " 3. `/cpw-next-step` — start Phase 0 directly"
321
+ - IMPORTANT: startup fills the context window significantly. Always recommend `/clear` before continuing.
@@ -0,0 +1,100 @@
1
+ ---
2
+ description: "Capture ideas for later or review pending todos"
3
+ ---
4
+
5
+ If the user provided a description (e.g., `/cpw-todos Add rate limiting`):
6
+ → Go to **CAPTURE mode**
7
+
8
+ If no description provided:
9
+ → Go to **REVIEW mode**
10
+
11
+ ---
12
+
13
+ ## CAPTURE mode
14
+
15
+ ### 1. Extract description
16
+ Take the todo from the user's message. Keep it concise — one sentence that future-you will understand weeks later.
17
+
18
+ ### 2. Infer area
19
+ Based on file paths mentioned or keywords, classify into one area:
20
+ - `api` — endpoints, routes, controllers, middleware
21
+ - `ui` — components, layouts, styles, responsive
22
+ - `data` — models, schemas, migrations, queries
23
+ - `auth` — authentication, authorization, sessions
24
+ - `testing` — tests, coverage, fixtures, mocks
25
+ - `docs` — documentation, README, guides
26
+ - `tooling` — build, CI/CD, scripts, config
27
+ - `general` — anything else
28
+
29
+ If ambiguous, default to `general`.
30
+
31
+ ### 3. Check duplicates
32
+ Read `.planning/quick/log.md`. If there's an existing entry with a very similar description, warn:
33
+ "Similar todo already exists: '[existing]'. Still add? (y/n)"
34
+
35
+ ### 4. Add to log
36
+ Append to `.planning/quick/log.md`:
37
+ ```
38
+ ---
39
+ - **Date**: [today]
40
+ - **Todo**: [concise description]
41
+ - **Area**: [inferred area]
42
+ - **Files**: [relevant file paths, or "none"]
43
+ - **Status**: pending
44
+ ---
45
+ ```
46
+
47
+ ### 5. Confirm and continue
48
+ Report: "Captured: [description]. Continue with current work."
49
+ Do NOT change context, read additional files, or start working on the todo.
50
+
51
+ ---
52
+
53
+ ## REVIEW mode
54
+
55
+ ### 1. Load todos
56
+ Read `.planning/quick/log.md`. Parse all entries with `Status: pending`.
57
+ If no pending todos: "No pending todos. Nothing to review."
58
+
59
+ ### 2. Display list
60
+ Show numbered list with area, description, and age:
61
+ ```
62
+ Pending todos (N):
63
+ 1. [api] Add rate limiting to public endpoints (3 days ago)
64
+ 2. [ui] Empty state for dashboard when no data (1 week ago)
65
+ 3. [testing] Add contract tests for auth service (2 weeks ago)
66
+ ```
67
+
68
+ If the user provided an area filter (e.g., `/cpw-todos --area api`), show only matching entries.
69
+
70
+ ### 3. User selects
71
+ Ask: "Which todo? (number, or 'done' to exit)"
72
+
73
+ ### 4. Show detail and offer actions
74
+ Show the full todo entry (description, area, files) and offer:
75
+
76
+ ```
77
+ Actions:
78
+ a) Work on it now — start /cpw-quick with this context
79
+ b) Add to current plan — suggest which phase/step it fits
80
+ c) Dismiss — mark as dismissed with reason
81
+ d) Back to list
82
+ ```
83
+
84
+ ### Action a: Work on it now
85
+ - Update the entry's Status to `in-progress`
86
+ - Start `/cpw-quick` with the todo description as context
87
+
88
+ ### Action b: Add to current plan
89
+ - Read STATUS.md to determine current phase
90
+ - Read the phase sub-plan
91
+ - Suggest where this todo fits (which step, or as a new step)
92
+ - If user agrees, add to the sub-plan and mark Status as `planned`
93
+
94
+ ### Action c: Dismiss
95
+ - Ask for brief reason
96
+ - Update Status to `dismissed`
97
+ - No further action
98
+
99
+ ### Action d: Back to list
100
+ - Return to step 2
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ // Context monitor — PostToolUse hook that warns agent when context is running low
3
+ // Reads bridge file written by cpw-statusline.js
4
+ // Never blocks tool execution — exits silently on any error
5
+
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+ const path = require('path');
9
+
10
+ try {
11
+ // Find most recent bridge file
12
+ const tmpdir = os.tmpdir();
13
+ const files = fs.readdirSync(tmpdir).filter(f => f.startsWith('cpw-ctx-') && f.endsWith('.json'));
14
+ if (files.length === 0) process.exit(0);
15
+
16
+ const bridge = path.join(tmpdir, files[0]);
17
+ const data = JSON.parse(fs.readFileSync(bridge, 'utf8'));
18
+ const usedPct = data.used_pct || 0;
19
+ const ts = data.ts || 0;
20
+
21
+ // Ignore stale data (>60s old)
22
+ const now = Math.floor(Date.now() / 1000);
23
+ if (now - ts > 60) process.exit(0);
24
+
25
+ // Determine severity
26
+ let level;
27
+ if (usedPct >= 80) level = 'CRITICAL';
28
+ else if (usedPct >= 65) level = 'WARNING';
29
+ else process.exit(0);
30
+
31
+ // Debounce: track last warning to avoid spamming agent
32
+ // Severity escalation (WARNING->CRITICAL) bypasses debounce
33
+ const stateFile = path.join(tmpdir, 'cpw-ctx-state');
34
+ let lastLevel = 'none';
35
+ let lastCount = 0;
36
+
37
+ if (fs.existsSync(stateFile)) {
38
+ const parts = fs.readFileSync(stateFile, 'utf8').trim().split(':');
39
+ lastLevel = parts[0] || 'none';
40
+ lastCount = parseInt(parts[1] || '0', 10);
41
+ }
42
+
43
+ if (level === lastLevel && lastCount < 5) {
44
+ fs.writeFileSync(stateFile, `${level}:${lastCount + 1}`);
45
+ process.exit(0);
46
+ }
47
+
48
+ // Reset debounce counter
49
+ fs.writeFileSync(stateFile, `${level}:0`);
50
+
51
+ // Emit warning
52
+ if (level === 'CRITICAL') {
53
+ process.stdout.write(`[CONTEXT CRITICAL — ${usedPct}%] Stop after the current task. Save state with /cpw-pause immediately. Do NOT start new complex work.\n`);
54
+ } else {
55
+ process.stdout.write(`[CONTEXT WARNING — ${usedPct}%] Context window filling up. Wrap up the current step and consider /cpw-pause or completing CLOSE stage soon.\n`);
56
+ }
57
+ } catch (e) {
58
+ // Silent fail — never break tool execution
59
+ }