pan-wizard 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +772 -0
  3. package/agents/pan-debugger.md +1246 -0
  4. package/agents/pan-document_code.md +965 -0
  5. package/agents/pan-executor.md +469 -0
  6. package/agents/pan-integration-checker.md +443 -0
  7. package/agents/pan-phase-researcher.md +572 -0
  8. package/agents/pan-plan-checker.md +763 -0
  9. package/agents/pan-planner.md +1297 -0
  10. package/agents/pan-project-researcher.md +647 -0
  11. package/agents/pan-research-synthesizer.md +239 -0
  12. package/agents/pan-reviewer.md +112 -0
  13. package/agents/pan-roadmapper.md +642 -0
  14. package/agents/pan-verifier.md +672 -0
  15. package/assets/pan-logo-2000-transparent.svg +30 -0
  16. package/assets/pan-logo-2000.svg +43 -0
  17. package/assets/terminal.svg +119 -0
  18. package/bin/install-lib.cjs +616 -0
  19. package/bin/install.js +1936 -0
  20. package/commands/pan/add-phase.md +44 -0
  21. package/commands/pan/assumptions.md +47 -0
  22. package/commands/pan/audit-deployment.md +378 -0
  23. package/commands/pan/debug.md +168 -0
  24. package/commands/pan/discord.md +19 -0
  25. package/commands/pan/discuss-phase.md +84 -0
  26. package/commands/pan/exec-phase.md +45 -0
  27. package/commands/pan/focus-auto.md +323 -0
  28. package/commands/pan/focus-design.md +816 -0
  29. package/commands/pan/focus-exec.md +316 -0
  30. package/commands/pan/focus-plan.md +101 -0
  31. package/commands/pan/focus-scan.md +272 -0
  32. package/commands/pan/focus-sync.md +104 -0
  33. package/commands/pan/health.md +23 -0
  34. package/commands/pan/help.md +23 -0
  35. package/commands/pan/insert-phase.md +33 -0
  36. package/commands/pan/map-codebase.md +72 -0
  37. package/commands/pan/milestone-audit.md +37 -0
  38. package/commands/pan/milestone-cleanup.md +19 -0
  39. package/commands/pan/milestone-done.md +137 -0
  40. package/commands/pan/milestone-gaps.md +35 -0
  41. package/commands/pan/milestone-new.md +45 -0
  42. package/commands/pan/new-project.md +43 -0
  43. package/commands/pan/patches.md +110 -0
  44. package/commands/pan/pause.md +39 -0
  45. package/commands/pan/phase-budget.md +23 -0
  46. package/commands/pan/phase-tests.md +42 -0
  47. package/commands/pan/plan-phase.md +46 -0
  48. package/commands/pan/profile.md +36 -0
  49. package/commands/pan/progress.md +25 -0
  50. package/commands/pan/quick.md +42 -0
  51. package/commands/pan/remove-phase.md +32 -0
  52. package/commands/pan/research-phase.md +190 -0
  53. package/commands/pan/resume.md +41 -0
  54. package/commands/pan/retro.md +33 -0
  55. package/commands/pan/settings.md +37 -0
  56. package/commands/pan/todo-add.md +48 -0
  57. package/commands/pan/todo-check.md +46 -0
  58. package/commands/pan/update.md +38 -0
  59. package/commands/pan/verify-phase.md +39 -0
  60. package/hooks/dist/pan-check-update.js +62 -0
  61. package/hooks/dist/pan-context-monitor.js +122 -0
  62. package/hooks/dist/pan-statusline.js +108 -0
  63. package/package.json +66 -0
  64. package/pan-wizard-core/bin/lib/codebase.cjs +746 -0
  65. package/pan-wizard-core/bin/lib/commands.cjs +1435 -0
  66. package/pan-wizard-core/bin/lib/config.cjs +611 -0
  67. package/pan-wizard-core/bin/lib/constants.cjs +696 -0
  68. package/pan-wizard-core/bin/lib/context-budget.cjs +150 -0
  69. package/pan-wizard-core/bin/lib/core.cjs +650 -0
  70. package/pan-wizard-core/bin/lib/focus.cjs +900 -0
  71. package/pan-wizard-core/bin/lib/frontmatter.cjs +442 -0
  72. package/pan-wizard-core/bin/lib/init.cjs +881 -0
  73. package/pan-wizard-core/bin/lib/milestone.cjs +276 -0
  74. package/pan-wizard-core/bin/lib/phase.cjs +1212 -0
  75. package/pan-wizard-core/bin/lib/roadmap.cjs +470 -0
  76. package/pan-wizard-core/bin/lib/state.cjs +1029 -0
  77. package/pan-wizard-core/bin/lib/template.cjs +314 -0
  78. package/pan-wizard-core/bin/lib/utils.cjs +171 -0
  79. package/pan-wizard-core/bin/lib/verify.cjs +1808 -0
  80. package/pan-wizard-core/bin/pan-tools.cjs +773 -0
  81. package/pan-wizard-core/references/checkpoints.md +776 -0
  82. package/pan-wizard-core/references/continuation-format.md +249 -0
  83. package/pan-wizard-core/references/decimal-phase-calculation.md +65 -0
  84. package/pan-wizard-core/references/git-integration.md +248 -0
  85. package/pan-wizard-core/references/git-planning-commit.md +38 -0
  86. package/pan-wizard-core/references/model-profile-resolution.md +34 -0
  87. package/pan-wizard-core/references/model-profiles.md +111 -0
  88. package/pan-wizard-core/references/phase-argument-parsing.md +61 -0
  89. package/pan-wizard-core/references/planning-config.md +196 -0
  90. package/pan-wizard-core/references/questioning.md +145 -0
  91. package/pan-wizard-core/references/tdd.md +263 -0
  92. package/pan-wizard-core/references/ui-brand.md +160 -0
  93. package/pan-wizard-core/references/verification-patterns.md +612 -0
  94. package/pan-wizard-core/templates/codebase/architecture.md +283 -0
  95. package/pan-wizard-core/templates/codebase/best-practices.md +133 -0
  96. package/pan-wizard-core/templates/codebase/concerns.md +325 -0
  97. package/pan-wizard-core/templates/codebase/conventions.md +307 -0
  98. package/pan-wizard-core/templates/codebase/integrations.md +305 -0
  99. package/pan-wizard-core/templates/codebase/relationships.md +124 -0
  100. package/pan-wizard-core/templates/codebase/stack.md +199 -0
  101. package/pan-wizard-core/templates/codebase/structure.md +298 -0
  102. package/pan-wizard-core/templates/codebase/testing.md +480 -0
  103. package/pan-wizard-core/templates/config.json +37 -0
  104. package/pan-wizard-core/templates/context.md +283 -0
  105. package/pan-wizard-core/templates/continue-here.md +78 -0
  106. package/pan-wizard-core/templates/debug-subagent-prompt.md +91 -0
  107. package/pan-wizard-core/templates/debug.md +164 -0
  108. package/pan-wizard-core/templates/discovery.md +146 -0
  109. package/pan-wizard-core/templates/milestone-archive.md +123 -0
  110. package/pan-wizard-core/templates/milestone.md +115 -0
  111. package/pan-wizard-core/templates/phase-prompt.md +593 -0
  112. package/pan-wizard-core/templates/planner-subagent-prompt.md +117 -0
  113. package/pan-wizard-core/templates/project.md +184 -0
  114. package/pan-wizard-core/templates/requirements.md +231 -0
  115. package/pan-wizard-core/templates/research-project/architecture.md +204 -0
  116. package/pan-wizard-core/templates/research-project/features.md +147 -0
  117. package/pan-wizard-core/templates/research-project/pitfalls.md +200 -0
  118. package/pan-wizard-core/templates/research-project/stack.md +120 -0
  119. package/pan-wizard-core/templates/research-project/summary.md +170 -0
  120. package/pan-wizard-core/templates/research.md +552 -0
  121. package/pan-wizard-core/templates/retrospective.md +54 -0
  122. package/pan-wizard-core/templates/roadmap.md +202 -0
  123. package/pan-wizard-core/templates/standards.md +24 -0
  124. package/pan-wizard-core/templates/state.md +176 -0
  125. package/pan-wizard-core/templates/summary-complex.md +59 -0
  126. package/pan-wizard-core/templates/summary-minimal.md +41 -0
  127. package/pan-wizard-core/templates/summary-standard.md +49 -0
  128. package/pan-wizard-core/templates/summary.md +249 -0
  129. package/pan-wizard-core/templates/uat.md +247 -0
  130. package/pan-wizard-core/templates/user-setup.md +311 -0
  131. package/pan-wizard-core/templates/validation.md +76 -0
  132. package/pan-wizard-core/templates/verification-report.md +322 -0
  133. package/pan-wizard-core/workflows/add-phase.md +111 -0
  134. package/pan-wizard-core/workflows/assumptions.md +178 -0
  135. package/pan-wizard-core/workflows/diagnose-issues.md +219 -0
  136. package/pan-wizard-core/workflows/discuss-phase.md +542 -0
  137. package/pan-wizard-core/workflows/exec-phase.md +572 -0
  138. package/pan-wizard-core/workflows/execute-plan.md +448 -0
  139. package/pan-wizard-core/workflows/health.md +156 -0
  140. package/pan-wizard-core/workflows/help.md +431 -0
  141. package/pan-wizard-core/workflows/insert-phase.md +129 -0
  142. package/pan-wizard-core/workflows/map-codebase.md +401 -0
  143. package/pan-wizard-core/workflows/milestone-audit.md +297 -0
  144. package/pan-wizard-core/workflows/milestone-cleanup.md +152 -0
  145. package/pan-wizard-core/workflows/milestone-gaps.md +274 -0
  146. package/pan-wizard-core/workflows/milestone-new.md +382 -0
  147. package/pan-wizard-core/workflows/new-project.md +1178 -0
  148. package/pan-wizard-core/workflows/pause.md +122 -0
  149. package/pan-wizard-core/workflows/phase-tests.md +388 -0
  150. package/pan-wizard-core/workflows/plan-phase.md +569 -0
  151. package/pan-wizard-core/workflows/profile.md +115 -0
  152. package/pan-wizard-core/workflows/progress.md +381 -0
  153. package/pan-wizard-core/workflows/quick.md +453 -0
  154. package/pan-wizard-core/workflows/remove-phase.md +154 -0
  155. package/pan-wizard-core/workflows/research-phase.md +73 -0
  156. package/pan-wizard-core/workflows/resume-project.md +306 -0
  157. package/pan-wizard-core/workflows/retro.md +121 -0
  158. package/pan-wizard-core/workflows/settings.md +213 -0
  159. package/pan-wizard-core/workflows/todo-add.md +157 -0
  160. package/pan-wizard-core/workflows/todo-check.md +176 -0
  161. package/pan-wizard-core/workflows/transition.md +544 -0
  162. package/pan-wizard-core/workflows/update.md +219 -0
  163. package/pan-wizard-core/workflows/verify-phase.md +301 -0
  164. package/scripts/build-hooks.js +43 -0
@@ -0,0 +1,325 @@
1
+ # Codebase Concerns Template
2
+
3
+ Template for `.planning/codebase/CONCERNS.md` - captures known issues and areas requiring care.
4
+
5
+ **Purpose:** Surface actionable warnings about the codebase. Focused on "what to watch out for when making changes."
6
+
7
+ ---
8
+
9
+ ## File Template
10
+
11
+ ```markdown
12
+ # Codebase Concerns
13
+
14
+ **Analysis Date:** [YYYY-MM-DD]
15
+
16
+ ## Risk Overview
17
+
18
+ ### Impact vs Probability
19
+
20
+ ```mermaid
21
+ quadrantChart
22
+ title Risk Assessment
23
+ x-axis Low Probability --> High Probability
24
+ y-axis Low Impact --> High Impact
25
+ quadrant-1 Monitor
26
+ quadrant-2 Act Now
27
+ quadrant-3 Accept
28
+ quadrant-4 Mitigate
29
+ ```
30
+
31
+ ## Tech Debt
32
+
33
+ **[Area/Component]:**
34
+ - Issue: [What's the shortcut/workaround]
35
+ - Why: [Why it was done this way]
36
+ - Impact: [What breaks or degrades because of it]
37
+ - Fix approach: [How to properly address it]
38
+
39
+ **[Area/Component]:**
40
+ - Issue: [What's the shortcut/workaround]
41
+ - Why: [Why it was done this way]
42
+ - Impact: [What breaks or degrades because of it]
43
+ - Fix approach: [How to properly address it]
44
+
45
+ ## Known Bugs
46
+
47
+ **[Bug description]:**
48
+ - Symptoms: [What happens]
49
+ - Trigger: [How to reproduce]
50
+ - Workaround: [Temporary mitigation if any]
51
+ - Root cause: [If known]
52
+ - Blocked by: [If waiting on something]
53
+
54
+ **[Bug description]:**
55
+ - Symptoms: [What happens]
56
+ - Trigger: [How to reproduce]
57
+ - Workaround: [Temporary mitigation if any]
58
+ - Root cause: [If known]
59
+
60
+ ## Security Considerations
61
+
62
+ **[Area requiring security care]:**
63
+ - Risk: [What could go wrong]
64
+ - Current mitigation: [What's in place now]
65
+ - Recommendations: [What should be added]
66
+
67
+ **[Area requiring security care]:**
68
+ - Risk: [What could go wrong]
69
+ - Current mitigation: [What's in place now]
70
+ - Recommendations: [What should be added]
71
+
72
+ ## Performance Bottlenecks
73
+
74
+ **[Slow operation/endpoint]:**
75
+ - Problem: [What's slow]
76
+ - Measurement: [Actual numbers: "500ms p95", "2s load time"]
77
+ - Cause: [Why it's slow]
78
+ - Improvement path: [How to speed it up]
79
+
80
+ **[Slow operation/endpoint]:**
81
+ - Problem: [What's slow]
82
+ - Measurement: [Actual numbers]
83
+ - Cause: [Why it's slow]
84
+ - Improvement path: [How to speed it up]
85
+
86
+ ## Fragile Areas
87
+
88
+ **[Component/Module]:**
89
+ - Why fragile: [What makes it break easily]
90
+ - Common failures: [What typically goes wrong]
91
+ - Safe modification: [How to change it without breaking]
92
+ - Test coverage: [Is it tested? Gaps?]
93
+
94
+ **[Component/Module]:**
95
+ - Why fragile: [What makes it break easily]
96
+ - Common failures: [What typically goes wrong]
97
+ - Safe modification: [How to change it without breaking]
98
+ - Test coverage: [Is it tested? Gaps?]
99
+
100
+ ## Scaling Limits
101
+
102
+ **[Resource/System]:**
103
+ - Current capacity: [Numbers: "100 req/sec", "10k users"]
104
+ - Limit: [Where it breaks]
105
+ - Symptoms at limit: [What happens]
106
+ - Scaling path: [How to increase capacity]
107
+
108
+ ## Dependencies at Risk
109
+
110
+ **[Package/Service]:**
111
+ - Risk: [e.g., "deprecated", "unmaintained", "breaking changes coming"]
112
+ - Impact: [What breaks if it fails]
113
+ - Migration plan: [Alternative or upgrade path]
114
+
115
+ ## Missing Critical Features
116
+
117
+ **[Feature gap]:**
118
+ - Problem: [What's missing]
119
+ - Current workaround: [How users cope]
120
+ - Blocks: [What can't be done without it]
121
+ - Implementation complexity: [Rough effort estimate]
122
+
123
+ ## Test Coverage Gaps
124
+
125
+ **[Untested area]:**
126
+ - What's not tested: [Specific functionality]
127
+ - Risk: [What could break unnoticed]
128
+ - Priority: [High/Medium/Low]
129
+ - Difficulty to test: [Why it's not tested yet]
130
+
131
+ ---
132
+
133
+ *Concerns audit: [date]*
134
+ *Update as issues are fixed or new ones discovered*
135
+ ```
136
+
137
+ <good_examples>
138
+ ```markdown
139
+ # Codebase Concerns
140
+
141
+ **Analysis Date:** 2025-01-20
142
+
143
+ ## Tech Debt
144
+
145
+ **Database queries in React components:**
146
+ - Issue: Direct Supabase queries in 15+ page components instead of server actions
147
+ - Files: `app/dashboard/page.tsx`, `app/profile/page.tsx`, `app/courses/[id]/page.tsx`, `app/settings/page.tsx` (and 11 more in `app/`)
148
+ - Why: Rapid prototyping during MVP phase
149
+ - Impact: Can't implement RLS properly, exposes DB structure to client
150
+ - Fix approach: Move all queries to server actions in `app/actions/`, add proper RLS policies
151
+
152
+ **Manual webhook signature validation:**
153
+ - Issue: Copy-pasted Stripe webhook verification code in 3 different endpoints
154
+ - Files: `app/api/webhooks/stripe/route.ts`, `app/api/webhooks/checkout/route.ts`, `app/api/webhooks/subscription/route.ts`
155
+ - Why: Each webhook added ad-hoc without abstraction
156
+ - Impact: Easy to miss verification in new webhooks (security risk)
157
+ - Fix approach: Create shared `lib/stripe/validate-webhook.ts` middleware
158
+
159
+ ## Known Bugs
160
+
161
+ **Race condition in subscription updates:**
162
+ - Symptoms: User shows as "free" tier for 5-10 seconds after successful payment
163
+ - Trigger: Fast navigation after Stripe checkout redirect, before webhook processes
164
+ - Files: `app/checkout/success/page.tsx` (redirect handler), `app/api/webhooks/stripe/route.ts` (webhook)
165
+ - Workaround: Stripe webhook eventually updates status (self-heals)
166
+ - Root cause: Webhook processing slower than user navigation, no optimistic UI update
167
+ - Fix: Add polling in `app/checkout/success/page.tsx` after redirect
168
+
169
+ **Inconsistent session state after logout:**
170
+ - Symptoms: User redirected to /dashboard after logout instead of /login
171
+ - Trigger: Logout via button in mobile nav (desktop works fine)
172
+ - File: `components/MobileNav.tsx` (line ~45, logout handler)
173
+ - Workaround: Manual URL navigation to /login works
174
+ - Root cause: Mobile nav component not awaiting supabase.auth.signOut()
175
+ - Fix: Add await to logout handler in `components/MobileNav.tsx`
176
+
177
+ ## Security Considerations
178
+
179
+ **Admin role check client-side only:**
180
+ - Risk: Admin dashboard pages check isAdmin from Supabase client, no server verification
181
+ - Files: `app/admin/page.tsx`, `app/admin/users/page.tsx`, `components/AdminGuard.tsx`
182
+ - Current mitigation: None (relying on UI hiding)
183
+ - Recommendations: Add middleware to admin routes in `middleware.ts`, verify role server-side
184
+
185
+ **Unvalidated file uploads:**
186
+ - Risk: Users can upload any file type to avatar bucket (no size/type validation)
187
+ - File: `components/AvatarUpload.tsx` (upload handler)
188
+ - Current mitigation: Supabase bucket limits to 2MB (configured in dashboard)
189
+ - Recommendations: Add file type validation (image/* only) in `lib/storage/validate.ts`
190
+
191
+ ## Performance Bottlenecks
192
+
193
+ **/api/courses endpoint:**
194
+ - Problem: Fetching all courses with nested lessons and authors
195
+ - File: `app/api/courses/route.ts`
196
+ - Measurement: 1.2s p95 response time with 50+ courses
197
+ - Cause: N+1 query pattern (separate query per course for lessons)
198
+ - Improvement path: Use Prisma include to eager-load lessons in `lib/db/courses.ts`, add Redis caching
199
+
200
+ **Dashboard initial load:**
201
+ - Problem: Waterfall of 5 serial API calls on mount
202
+ - File: `app/dashboard/page.tsx`
203
+ - Measurement: 3.5s until interactive on slow 3G
204
+ - Cause: Each component fetches own data independently
205
+ - Improvement path: Convert to Server Component with single parallel fetch
206
+
207
+ ## Fragile Areas
208
+
209
+ **Authentication middleware chain:**
210
+ - File: `middleware.ts`
211
+ - Why fragile: 4 different middleware functions run in specific order (auth -> role -> subscription -> logging)
212
+ - Common failures: Middleware order change breaks everything, hard to debug
213
+ - Safe modification: Add tests before changing order, document dependencies in comments
214
+ - Test coverage: No integration tests for middleware chain (only unit tests)
215
+
216
+ **Stripe webhook event handling:**
217
+ - File: `app/api/webhooks/stripe/route.ts`
218
+ - Why fragile: Giant switch statement with 12 event types, shared transaction logic
219
+ - Common failures: New event type added without handling, partial DB updates on error
220
+ - Safe modification: Extract each event handler to `lib/stripe/handlers/*.ts`
221
+ - Test coverage: Only 3 of 12 event types have tests
222
+
223
+ ## Scaling Limits
224
+
225
+ **Supabase Free Tier:**
226
+ - Current capacity: 500MB database, 1GB file storage, 2GB bandwidth/month
227
+ - Limit: ~5000 users estimated before hitting limits
228
+ - Symptoms at limit: 429 rate limit errors, DB writes fail
229
+ - Scaling path: Upgrade to Pro ($25/mo) extends to 8GB DB, 100GB storage
230
+
231
+ **Server-side render blocking:**
232
+ - Current capacity: ~50 concurrent users before slowdown
233
+ - Limit: Vercel Hobby plan (10s function timeout, 100GB-hrs/mo)
234
+ - Symptoms at limit: 504 gateway timeouts on course pages
235
+ - Scaling path: Upgrade to Vercel Pro ($20/mo), add edge caching
236
+
237
+ ## Dependencies at Risk
238
+
239
+ **react-hot-toast:**
240
+ - Risk: Unmaintained (last update 18 months ago), React 19 compatibility unknown
241
+ - Impact: Toast notifications break, no graceful degradation
242
+ - Migration plan: Switch to sonner (actively maintained, similar API)
243
+
244
+ ## Missing Critical Features
245
+
246
+ **Payment failure handling:**
247
+ - Problem: No retry mechanism or user notification when subscription payment fails
248
+ - Current workaround: Users manually re-enter payment info (if they notice)
249
+ - Blocks: Can't retain users with expired cards, no dunning process
250
+ - Implementation complexity: Medium (Stripe webhooks + email flow + UI)
251
+
252
+ **Course progress tracking:**
253
+ - Problem: No persistent state for which lessons completed
254
+ - Current workaround: Users manually track progress
255
+ - Blocks: Can't show completion percentage, can't recommend next lesson
256
+ - Implementation complexity: Low (add completed_lessons junction table)
257
+
258
+ ## Test Coverage Gaps
259
+
260
+ **Payment flow end-to-end:**
261
+ - What's not tested: Full Stripe checkout -> webhook -> subscription activation flow
262
+ - Risk: Payment processing could break silently (has happened twice)
263
+ - Priority: High
264
+ - Difficulty to test: Need Stripe test fixtures and webhook simulation setup
265
+
266
+ **Error boundary behavior:**
267
+ - What's not tested: How app behaves when components throw errors
268
+ - Risk: White screen of death for users, no error reporting
269
+ - Priority: Medium
270
+ - Difficulty to test: Need to intentionally trigger errors in test environment
271
+
272
+ ---
273
+
274
+ *Concerns audit: 2025-01-20*
275
+ *Update as issues are fixed or new ones discovered*
276
+ ```
277
+ </good_examples>
278
+
279
+ <guidelines>
280
+ **What belongs in CONCERNS.md:**
281
+ - Tech debt with clear impact and fix approach
282
+ - Known bugs with reproduction steps
283
+ - Security gaps and mitigation recommendations
284
+ - Performance bottlenecks with measurements
285
+ - Fragile code that breaks easily
286
+ - Scaling limits with numbers
287
+ - Dependencies that need attention
288
+ - Missing features that block workflows
289
+ - Test coverage gaps
290
+
291
+ **What does NOT belong here:**
292
+ - Opinions without evidence ("code is messy")
293
+ - Complaints without solutions ("auth sucks")
294
+ - Future feature ideas (that's for product planning)
295
+ - Normal TODOs (those live in code comments)
296
+ - Architectural decisions that are working fine
297
+ - Minor code style issues
298
+
299
+ **When filling this template:**
300
+ - **Always include file paths** - Concerns without locations are not actionable. Use backticks: `src/file.ts`
301
+ - Be specific with measurements ("500ms p95" not "slow")
302
+ - Include reproduction steps for bugs
303
+ - Suggest fix approaches, not just problems
304
+ - Focus on actionable items
305
+ - Prioritize by risk/impact
306
+ - Update as issues get resolved
307
+ - Add new concerns as discovered
308
+
309
+ **Tone guidelines:**
310
+ - Professional, not emotional ("N+1 query pattern" not "terrible queries")
311
+ - Solution-oriented ("Fix: add index" not "needs fixing")
312
+ - Risk-focused ("Could expose user data" not "security is bad")
313
+ - Factual ("3.5s load time" not "really slow")
314
+
315
+ **Useful for phase planning when:**
316
+ - Deciding what to work on next
317
+ - Estimating risk of changes
318
+ - Understanding where to be careful
319
+ - Prioritizing improvements
320
+ - Onboarding new Claude contexts
321
+ - Planning refactoring work
322
+
323
+ **How this gets populated:**
324
+ Explore agents detect these during codebase mapping. Manual additions welcome for human-discovered issues. This is living documentation, not a complaint list.
325
+ </guidelines>
@@ -0,0 +1,307 @@
1
+ # Coding Conventions Template
2
+
3
+ Template for `.planning/codebase/CONVENTIONS.md` - captures coding style and patterns.
4
+
5
+ **Purpose:** Document how code is written in this codebase. Prescriptive guide for Claude to match existing style.
6
+
7
+ ---
8
+
9
+ ## File Template
10
+
11
+ ```markdown
12
+ # Coding Conventions
13
+
14
+ **Analysis Date:** [YYYY-MM-DD]
15
+
16
+ ## Naming Patterns
17
+
18
+ **Files:**
19
+ - [Pattern: e.g., "kebab-case for all files"]
20
+ - [Test files: e.g., "*.test.ts alongside source"]
21
+ - [Components: e.g., "PascalCase.tsx for React components"]
22
+
23
+ **Functions:**
24
+ - [Pattern: e.g., "camelCase for all functions"]
25
+ - [Async: e.g., "no special prefix for async functions"]
26
+ - [Handlers: e.g., "handleEventName for event handlers"]
27
+
28
+ **Variables:**
29
+ - [Pattern: e.g., "camelCase for variables"]
30
+ - [Constants: e.g., "UPPER_SNAKE_CASE for constants"]
31
+ - [Private: e.g., "_prefix for private members" or "no prefix"]
32
+
33
+ **Types:**
34
+ - [Interfaces: e.g., "PascalCase, no I prefix"]
35
+ - [Types: e.g., "PascalCase for type aliases"]
36
+ - [Enums: e.g., "PascalCase for enum name, UPPER_CASE for values"]
37
+
38
+ ## Code Style
39
+
40
+ **Formatting:**
41
+ - [Tool: e.g., "Prettier with config in .prettierrc"]
42
+ - [Line length: e.g., "100 characters max"]
43
+ - [Quotes: e.g., "single quotes for strings"]
44
+ - [Semicolons: e.g., "required" or "omitted"]
45
+
46
+ **Linting:**
47
+ - [Tool: e.g., "ESLint with eslint.config.js"]
48
+ - [Rules: e.g., "extends airbnb-base, no console in production"]
49
+ - [Run: e.g., "npm run lint"]
50
+
51
+ ## Import Organization
52
+
53
+ **Order:**
54
+ 1. [e.g., "External packages (react, express, etc.)"]
55
+ 2. [e.g., "Internal modules (@/lib, @/components)"]
56
+ 3. [e.g., "Relative imports (., ..)"]
57
+ 4. [e.g., "Type imports (import type {})"]
58
+
59
+ **Grouping:**
60
+ - [Blank lines: e.g., "blank line between groups"]
61
+ - [Sorting: e.g., "alphabetical within each group"]
62
+
63
+ **Path Aliases:**
64
+ - [Aliases used: e.g., "@/ for src/, @components/ for src/components/"]
65
+
66
+ ## Error Handling
67
+
68
+ **Patterns:**
69
+ - [Strategy: e.g., "throw errors, catch at boundaries"]
70
+ - [Custom errors: e.g., "extend Error class, named *Error"]
71
+ - [Async: e.g., "use try/catch, no .catch() chains"]
72
+
73
+ **Error Types:**
74
+ - [When to throw: e.g., "invalid input, missing dependencies"]
75
+ - [When to return: e.g., "expected failures return Result<T, E>"]
76
+ - [Logging: e.g., "log error with context before throwing"]
77
+
78
+ ## Logging
79
+
80
+ **Framework:**
81
+ - [Tool: e.g., "console.log, pino, winston"]
82
+ - [Levels: e.g., "debug, info, warn, error"]
83
+
84
+ **Patterns:**
85
+ - [Format: e.g., "structured logging with context object"]
86
+ - [When: e.g., "log state transitions, external calls"]
87
+ - [Where: e.g., "log at service boundaries, not in utils"]
88
+
89
+ ## Comments
90
+
91
+ **When to Comment:**
92
+ - [e.g., "explain why, not what"]
93
+ - [e.g., "document business logic, algorithms, edge cases"]
94
+ - [e.g., "avoid obvious comments like // increment counter"]
95
+
96
+ **JSDoc/TSDoc:**
97
+ - [Usage: e.g., "required for public APIs, optional for internal"]
98
+ - [Format: e.g., "use @param, @returns, @throws tags"]
99
+
100
+ **TODO Comments:**
101
+ - [Pattern: e.g., "// TODO(username): description"]
102
+ - [Tracking: e.g., "link to issue number if available"]
103
+
104
+ ## Function Design
105
+
106
+ **Size:**
107
+ - [e.g., "keep under 50 lines, extract helpers"]
108
+
109
+ **Parameters:**
110
+ - [e.g., "max 3 parameters, use object for more"]
111
+ - [e.g., "destructure objects in parameter list"]
112
+
113
+ **Return Values:**
114
+ - [e.g., "explicit returns, no implicit undefined"]
115
+ - [e.g., "return early for guard clauses"]
116
+
117
+ ## Module Design
118
+
119
+ **Exports:**
120
+ - [e.g., "named exports preferred, default exports for React components"]
121
+ - [e.g., "export from index.ts for public API"]
122
+
123
+ **Barrel Files:**
124
+ - [e.g., "use index.ts to re-export public API"]
125
+ - [e.g., "avoid circular dependencies"]
126
+
127
+ ---
128
+
129
+ *Convention analysis: [date]*
130
+ *Update when patterns change*
131
+ ```
132
+
133
+ <good_examples>
134
+ ```markdown
135
+ # Coding Conventions
136
+
137
+ **Analysis Date:** 2025-01-20
138
+
139
+ ## Naming Patterns
140
+
141
+ **Files:**
142
+ - kebab-case for all files (command-handler.ts, user-service.ts)
143
+ - *.test.ts alongside source files
144
+ - index.ts for barrel exports
145
+
146
+ **Functions:**
147
+ - camelCase for all functions
148
+ - No special prefix for async functions
149
+ - handleEventName for event handlers (handleClick, handleSubmit)
150
+
151
+ **Variables:**
152
+ - camelCase for variables
153
+ - UPPER_SNAKE_CASE for constants (MAX_RETRIES, API_BASE_URL)
154
+ - No underscore prefix (no private marker in TS)
155
+
156
+ **Types:**
157
+ - PascalCase for interfaces, no I prefix (User, not IUser)
158
+ - PascalCase for type aliases (UserConfig, ResponseData)
159
+ - PascalCase for enum names, UPPER_CASE for values (Status.PENDING)
160
+
161
+ ## Code Style
162
+
163
+ **Formatting:**
164
+ - Prettier with .prettierrc
165
+ - 100 character line length
166
+ - Single quotes for strings
167
+ - Semicolons required
168
+ - 2 space indentation
169
+
170
+ **Linting:**
171
+ - ESLint with eslint.config.js
172
+ - Extends @typescript-eslint/recommended
173
+ - No console.log in production code (use logger)
174
+ - Run: npm run lint
175
+
176
+ ## Import Organization
177
+
178
+ **Order:**
179
+ 1. External packages (react, express, commander)
180
+ 2. Internal modules (@/lib, @/services)
181
+ 3. Relative imports (./utils, ../types)
182
+ 4. Type imports (import type { User })
183
+
184
+ **Grouping:**
185
+ - Blank line between groups
186
+ - Alphabetical within each group
187
+ - Type imports last within each group
188
+
189
+ **Path Aliases:**
190
+ - @/ maps to src/
191
+ - No other aliases defined
192
+
193
+ ## Error Handling
194
+
195
+ **Patterns:**
196
+ - Throw errors, catch at boundaries (route handlers, main functions)
197
+ - Extend Error class for custom errors (ValidationError, NotFoundError)
198
+ - Async functions use try/catch, no .catch() chains
199
+
200
+ **Error Types:**
201
+ - Throw on invalid input, missing dependencies, invariant violations
202
+ - Log error with context before throwing: logger.error({ err, userId }, 'Failed to process')
203
+ - Include cause in error message: new Error('Failed to X', { cause: originalError })
204
+
205
+ ## Logging
206
+
207
+ **Framework:**
208
+ - pino logger instance exported from lib/logger.ts
209
+ - Levels: debug, info, warn, error (no trace)
210
+
211
+ **Patterns:**
212
+ - Structured logging with context: logger.info({ userId, action }, 'User action')
213
+ - Log at service boundaries, not in utility functions
214
+ - Log state transitions, external API calls, errors
215
+ - No console.log in committed code
216
+
217
+ ## Comments
218
+
219
+ **When to Comment:**
220
+ - Explain why, not what: // Retry 3 times because API has transient failures
221
+ - Document business rules: // Users must verify email within 24 hours
222
+ - Explain non-obvious algorithms or workarounds
223
+ - Avoid obvious comments: // set count to 0
224
+
225
+ **JSDoc/TSDoc:**
226
+ - Required for public API functions
227
+ - Optional for internal functions if signature is self-explanatory
228
+ - Use @param, @returns, @throws tags
229
+
230
+ **TODO Comments:**
231
+ - Format: // TODO: description (no username, using git blame)
232
+ - Link to issue if exists: // TODO: Fix race condition (issue #123)
233
+
234
+ ## Function Design
235
+
236
+ **Size:**
237
+ - Keep under 50 lines
238
+ - Extract helpers for complex logic
239
+ - One level of abstraction per function
240
+
241
+ **Parameters:**
242
+ - Max 3 parameters
243
+ - Use options object for 4+ parameters: function create(options: CreateOptions)
244
+ - Destructure in parameter list: function process({ id, name }: ProcessParams)
245
+
246
+ **Return Values:**
247
+ - Explicit return statements
248
+ - Return early for guard clauses
249
+ - Use Result<T, E> type for expected failures
250
+
251
+ ## Module Design
252
+
253
+ **Exports:**
254
+ - Named exports preferred
255
+ - Default exports only for React components
256
+ - Export public API from index.ts barrel files
257
+
258
+ **Barrel Files:**
259
+ - index.ts re-exports public API
260
+ - Keep internal helpers private (don't export from index)
261
+ - Avoid circular dependencies (import from specific files if needed)
262
+
263
+ ---
264
+
265
+ *Convention analysis: 2025-01-20*
266
+ *Update when patterns change*
267
+ ```
268
+ </good_examples>
269
+
270
+ <guidelines>
271
+ **What belongs in CONVENTIONS.md:**
272
+ - Naming patterns observed in the codebase
273
+ - Formatting rules (Prettier config, linting rules)
274
+ - Import organization patterns
275
+ - Error handling strategy
276
+ - Logging approach
277
+ - Comment conventions
278
+ - Function and module design patterns
279
+
280
+ **What does NOT belong here:**
281
+ - Architecture decisions (that's ARCHITECTURE.md)
282
+ - Technology choices (that's STACK.md)
283
+ - Test patterns (that's TESTING.md)
284
+ - File organization (that's STRUCTURE.md)
285
+
286
+ **When filling this template:**
287
+ - Check .prettierrc, .eslintrc, or similar config files
288
+ - Examine 5-10 representative source files for patterns
289
+ - Look for consistency: if 80%+ follows a pattern, document it
290
+ - Be prescriptive: "Use X" not "Sometimes Y is used"
291
+ - Note deviations: "Legacy code uses Y, new code should use X"
292
+ - Keep under ~150 lines total
293
+
294
+ **Useful for phase planning when:**
295
+ - Writing new code (match existing style)
296
+ - Adding features (follow naming patterns)
297
+ - Refactoring (apply consistent conventions)
298
+ - Code review (check against documented patterns)
299
+ - Onboarding (understand style expectations)
300
+
301
+ **Analysis approach:**
302
+ - Scan src/ directory for file naming patterns
303
+ - Check package.json scripts for lint/format commands
304
+ - Read 5-10 files to identify function naming, error handling
305
+ - Look for config files (.prettierrc, eslint.config.js)
306
+ - Note patterns in imports, comments, function signatures
307
+ </guidelines>