plan-flow-skill 1.0.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 (124) hide show
  1. package/.claude/commands/create-contract.md +468 -0
  2. package/.claude/commands/create-plan.md +512 -0
  3. package/.claude/commands/discovery-plan.md +561 -0
  4. package/.claude/commands/execute-plan.md +682 -0
  5. package/.claude/commands/review-code.md +459 -0
  6. package/.claude/commands/review-pr.md +651 -0
  7. package/.claude/commands/setup.md +1609 -0
  8. package/.claude/commands/write-tests.md +543 -0
  9. package/.claude/rules/core/allowed-patterns.md +175 -0
  10. package/.claude/rules/core/complexity-scoring.md +225 -0
  11. package/.claude/rules/core/forbidden-patterns.md +253 -0
  12. package/.claude/rules/languages/python-patterns.md +6 -0
  13. package/.claude/rules/languages/typescript-patterns.md +7 -0
  14. package/.claude/rules/patterns/contract-patterns.md +332 -0
  15. package/.claude/rules/patterns/discovery-patterns.md +342 -0
  16. package/.claude/rules/patterns/discovery-templates.md +319 -0
  17. package/.claude/rules/patterns/jest-patterns.md +482 -0
  18. package/.claude/rules/patterns/plans-patterns.md +225 -0
  19. package/.claude/rules/patterns/plans-templates.md +227 -0
  20. package/.claude/rules/patterns/pytest-patterns.md +457 -0
  21. package/.claude/rules/patterns/review-code-templates.md +305 -0
  22. package/.claude/rules/patterns/review-pr-patterns.md +360 -0
  23. package/.claude/rules/tools/auth-pr-tool.md +30 -0
  24. package/.claude/rules/tools/interactive-questions-tool.md +235 -0
  25. package/.claude/rules/tools/jest-testing-tool.md +73 -0
  26. package/.claude/rules/tools/plan-mode-tool.md +164 -0
  27. package/.claude/rules/tools/pytest-testing-tool.md +121 -0
  28. package/.claude/rules/tools/reference-expansion-tool.md +326 -0
  29. package/LICENSE +21 -0
  30. package/README.md +167 -0
  31. package/dist/cli/commands/init.d.ts +6 -0
  32. package/dist/cli/commands/init.d.ts.map +1 -0
  33. package/dist/cli/commands/init.js +139 -0
  34. package/dist/cli/commands/init.js.map +1 -0
  35. package/dist/cli/handlers/claude.d.ts +9 -0
  36. package/dist/cli/handlers/claude.d.ts.map +1 -0
  37. package/dist/cli/handlers/claude.js +119 -0
  38. package/dist/cli/handlers/claude.js.map +1 -0
  39. package/dist/cli/handlers/codex.d.ts +9 -0
  40. package/dist/cli/handlers/codex.d.ts.map +1 -0
  41. package/dist/cli/handlers/codex.js +100 -0
  42. package/dist/cli/handlers/codex.js.map +1 -0
  43. package/dist/cli/handlers/cursor.d.ts +8 -0
  44. package/dist/cli/handlers/cursor.d.ts.map +1 -0
  45. package/dist/cli/handlers/cursor.js +34 -0
  46. package/dist/cli/handlers/cursor.js.map +1 -0
  47. package/dist/cli/handlers/openclaw.d.ts +8 -0
  48. package/dist/cli/handlers/openclaw.d.ts.map +1 -0
  49. package/dist/cli/handlers/openclaw.js +34 -0
  50. package/dist/cli/handlers/openclaw.js.map +1 -0
  51. package/dist/cli/handlers/shared.d.ts +9 -0
  52. package/dist/cli/handlers/shared.d.ts.map +1 -0
  53. package/dist/cli/handlers/shared.js +44 -0
  54. package/dist/cli/handlers/shared.js.map +1 -0
  55. package/dist/cli/index.d.ts +8 -0
  56. package/dist/cli/index.d.ts.map +1 -0
  57. package/dist/cli/index.js +43 -0
  58. package/dist/cli/index.js.map +1 -0
  59. package/dist/cli/types.d.ts +26 -0
  60. package/dist/cli/types.d.ts.map +1 -0
  61. package/dist/cli/types.js +5 -0
  62. package/dist/cli/types.js.map +1 -0
  63. package/dist/cli/utils/files.d.ts +37 -0
  64. package/dist/cli/utils/files.d.ts.map +1 -0
  65. package/dist/cli/utils/files.js +122 -0
  66. package/dist/cli/utils/files.js.map +1 -0
  67. package/dist/cli/utils/logger.d.ts +11 -0
  68. package/dist/cli/utils/logger.d.ts.map +1 -0
  69. package/dist/cli/utils/logger.js +34 -0
  70. package/dist/cli/utils/logger.js.map +1 -0
  71. package/dist/cli/utils/prompts.d.ts +10 -0
  72. package/dist/cli/utils/prompts.d.ts.map +1 -0
  73. package/dist/cli/utils/prompts.js +65 -0
  74. package/dist/cli/utils/prompts.js.map +1 -0
  75. package/dist/test/setup.d.ts +5 -0
  76. package/dist/test/setup.d.ts.map +1 -0
  77. package/dist/test/setup.js +7 -0
  78. package/dist/test/setup.js.map +1 -0
  79. package/package.json +63 -0
  80. package/rules/core/_index.mdc +89 -0
  81. package/rules/core/allowed-patterns.mdc +185 -0
  82. package/rules/core/complexity-scoring.mdc +235 -0
  83. package/rules/core/forbidden-patterns.mdc +263 -0
  84. package/rules/languages/_index.mdc +80 -0
  85. package/rules/languages/python-patterns.mdc +188 -0
  86. package/rules/languages/typescript-patterns.mdc +128 -0
  87. package/rules/patterns/_index.mdc +185 -0
  88. package/rules/patterns/contract-patterns.mdc +344 -0
  89. package/rules/patterns/discovery-patterns.mdc +354 -0
  90. package/rules/patterns/discovery-templates.mdc +329 -0
  91. package/rules/patterns/jest-patterns.mdc +492 -0
  92. package/rules/patterns/plans-patterns.mdc +237 -0
  93. package/rules/patterns/plans-templates.mdc +237 -0
  94. package/rules/patterns/pytest-patterns.mdc +467 -0
  95. package/rules/patterns/review-code-templates.mdc +315 -0
  96. package/rules/patterns/review-pr-patterns.mdc +370 -0
  97. package/rules/skills/_index.mdc +174 -0
  98. package/rules/skills/create-contract-skill.mdc +239 -0
  99. package/rules/skills/create-plan-skill.mdc +271 -0
  100. package/rules/skills/discovery-skill.mdc +295 -0
  101. package/rules/skills/execute-plan-skill.mdc +388 -0
  102. package/rules/skills/review-code-skill.mdc +308 -0
  103. package/rules/skills/review-pr-skill.mdc +496 -0
  104. package/rules/skills/setup-skill.mdc +923 -0
  105. package/rules/skills/write-tests-skill.mdc +294 -0
  106. package/rules/templates/index-template.mdc +126 -0
  107. package/rules/tools/_index.mdc +114 -0
  108. package/rules/tools/auth-pr-tool.mdc +362 -0
  109. package/rules/tools/interactive-questions-tool.mdc +337 -0
  110. package/rules/tools/jest-testing-tool.mdc +96 -0
  111. package/rules/tools/plan-mode-tool.mdc +229 -0
  112. package/rules/tools/pytest-testing-tool.mdc +144 -0
  113. package/rules/tools/reference-expansion-tool.mdc +338 -0
  114. package/skills/plan-flow/SKILL.md +109 -0
  115. package/skills/plan-flow/create-contract/SKILL.md +139 -0
  116. package/skills/plan-flow/create-plan/SKILL.md +93 -0
  117. package/skills/plan-flow/discovery/SKILL.md +85 -0
  118. package/skills/plan-flow/execute-plan/SKILL.md +89 -0
  119. package/skills/plan-flow/review-code/SKILL.md +100 -0
  120. package/skills/plan-flow/review-pr/SKILL.md +122 -0
  121. package/skills/plan-flow/setup/SKILL.md +73 -0
  122. package/skills/plan-flow/write-tests/SKILL.md +115 -0
  123. package/templates/shared/AGENTS.md.template +60 -0
  124. package/templates/shared/CLAUDE.md.template +62 -0
@@ -0,0 +1,923 @@
1
+ ---
2
+ description: "Include when /setup is invoked or project analysis and pattern detection is needed"
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # Setup Skill
7
+
8
+ ## Purpose
9
+
10
+ Perform deep analysis of the current repository to index languages, frameworks, architecture patterns, and coding conventions. Generate comprehensive, actionable pattern files based on real code samples and industry best practices.
11
+
12
+ This skill produces:
13
+ - Project analysis document in `flow/references/`
14
+ - Framework pattern files with real examples in `.cursor/rules/frameworks/`
15
+ - Library pattern files with usage examples in `.cursor/rules/libraries/`
16
+ - Project-specific patterns in `.cursor/rules/project/`
17
+ - Updated core pattern files
18
+
19
+ ---
20
+
21
+ ## Critical Approach
22
+
23
+ **This is NOT a surface-level scan.** The setup skill must:
24
+
25
+ 1. **Sample Real Code** - Read actual files to understand how patterns are implemented
26
+ 2. **Extract Real Examples** - Use code snippets from the project as pattern examples
27
+ 3. **Research Best Practices** - Use web search to get current best practices for the stack
28
+ 4. **Detect Conventions** - Identify naming, file structure, and coding conventions
29
+ 5. **Create Actionable Patterns** - Generate patterns that can be directly followed
30
+
31
+ ---
32
+
33
+ ## Workflow
34
+
35
+ ### Step 1: Scan Project Structure
36
+
37
+ Analyze the repository root to identify project type and structure.
38
+
39
+ **Files to Check**:
40
+
41
+ | File | Indicates |
42
+ | ----------------------- | -------------------------------------------- |
43
+ | `package.json` | JavaScript/TypeScript project |
44
+ | `requirements.txt` | Python project |
45
+ | `pyproject.toml` | Python project (modern) |
46
+ | `Cargo.toml` | Rust project |
47
+ | `go.mod` | Go project |
48
+ | `pom.xml` | Java/Maven project |
49
+ | `build.gradle` | Java/Kotlin Gradle project |
50
+ | `Gemfile` | Ruby project |
51
+ | `*.csproj` | C#/.NET project |
52
+
53
+ **Actions**:
54
+
55
+ 1. List root directory files
56
+ 2. Identify primary language from dependency files
57
+ 3. Read dependency files completely to extract ALL libraries
58
+ 4. Map directory structure (up to 3 levels deep)
59
+
60
+ ---
61
+
62
+ ### Step 2: Deep Dependency Analysis
63
+
64
+ Read and parse dependency files to build complete stack profile.
65
+
66
+ #### For JavaScript/TypeScript (package.json)
67
+
68
+ **Core Framework Detection**:
69
+
70
+ | Dependency | Framework | Pattern File to Create |
71
+ | ---------------------- | ---------------------- | -------------------------------- |
72
+ | `next` | Next.js | `nextjs-patterns.mdc` |
73
+ | `react` | React | `react-patterns.mdc` |
74
+ | `vue` | Vue.js | `vue-patterns.mdc` |
75
+ | `@angular/core` | Angular | `angular-patterns.mdc` |
76
+ | `express` | Express.js | `express-patterns.mdc` |
77
+ | `fastify` | Fastify | `fastify-patterns.mdc` |
78
+ | `hono` | Hono | `hono-patterns.mdc` |
79
+ | `@nestjs/core` | NestJS | `nestjs-patterns.mdc` |
80
+
81
+ **Library Detection** (create individual pattern files):
82
+
83
+ | Category | Libraries | Pattern File |
84
+ | ---------------------- | ---------------------- | -------------------------------- |
85
+ | Validation | `zod`, `yup`, `joi` | `<lib>-patterns.mdc` |
86
+ | State Management | `zustand`, `redux`, `jotai`, `recoil` | `<lib>-patterns.mdc` |
87
+ | Data Fetching | `@tanstack/react-query`, `swr`, `axios` | `<lib>-patterns.mdc` |
88
+ | ORM/Database | `prisma`, `drizzle-orm`, `typeorm` | `<lib>-patterns.mdc` |
89
+ | Authentication | `next-auth`, `clerk`, `lucia` | `<lib>-patterns.mdc` |
90
+ | Styling | `tailwindcss`, `styled-components` | `<lib>-patterns.mdc` |
91
+ | Testing | `jest`, `vitest`, `playwright` | `<lib>-patterns.mdc` |
92
+ | Forms | `react-hook-form`, `formik` | `<lib>-patterns.mdc` |
93
+ | UI Components | `shadcn/ui`, `radix-ui`, `mantine` | `<lib>-patterns.mdc` |
94
+
95
+ #### For Python (requirements.txt / pyproject.toml)
96
+
97
+ | Category | Libraries | Pattern File |
98
+ | ---------------------- | ---------------------- | -------------------------------- |
99
+ | Web Framework | `fastapi`, `django`, `flask` | `<lib>-patterns.mdc` |
100
+ | Validation | `pydantic` | `pydantic-patterns.mdc` |
101
+ | ORM | `sqlalchemy`, `tortoise-orm` | `<lib>-patterns.mdc` |
102
+ | Testing | `pytest`, `unittest` | `<lib>-patterns.mdc` |
103
+ | Task Queue | `celery`, `rq` | `<lib>-patterns.mdc` |
104
+ | HTTP Client | `httpx`, `aiohttp` | `<lib>-patterns.mdc` |
105
+
106
+ ---
107
+
108
+ ### Step 3: Deep Code Analysis
109
+
110
+ **CRITICAL**: This step samples actual code to understand HOW the project uses each library.
111
+
112
+ #### 3.1 Sample Files by Type
113
+
114
+ For each detected library/framework, find and read sample files:
115
+
116
+ ```
117
+ For Next.js:
118
+ - Read 2-3 files from app/ or pages/
119
+ - Read 2-3 API routes
120
+ - Read layout files
121
+ - Read middleware if exists
122
+
123
+ For React:
124
+ - Read 3-5 component files
125
+ - Read custom hooks
126
+ - Read context providers
127
+
128
+ For Zod:
129
+ - Search for .schema.ts files
130
+ - Search for files importing 'zod'
131
+ - Extract schema definition patterns
132
+
133
+ For Prisma:
134
+ - Read prisma/schema.prisma
135
+ - Search for files importing @prisma/client
136
+ - Extract query patterns
137
+
138
+ For Zustand:
139
+ - Search for store files
140
+ - Extract store structure patterns
141
+ ```
142
+
143
+ #### 3.2 Extract Real Patterns
144
+
145
+ For each library, document:
146
+
147
+ 1. **Import Style**
148
+ ```typescript
149
+ // How does the project import this library?
150
+ import { z } from 'zod' // Named import
151
+ import prisma from '@/lib/prisma' // Default import from lib
152
+ ```
153
+
154
+ 2. **File Organization**
155
+ ```
156
+ // Where are files for this library located?
157
+ src/schemas/*.ts - Zod schemas
158
+ src/stores/*.ts - Zustand stores
159
+ prisma/schema.prisma - Prisma schema
160
+ ```
161
+
162
+ 3. **Naming Conventions**
163
+ ```typescript
164
+ // How are things named?
165
+ userSchema, createUserSchema // Schemas: camelCase + Schema suffix
166
+ useUserStore, useCartStore // Stores: use + Name + Store
167
+ ```
168
+
169
+ 4. **Usage Patterns**
170
+ ```typescript
171
+ // How is the library typically used?
172
+ // Extract 2-3 real examples from the codebase
173
+ ```
174
+
175
+ #### 3.3 Detect Project Conventions
176
+
177
+ **File Naming**:
178
+ - Analyze file names in src/ to detect: kebab-case, camelCase, PascalCase
179
+ - Check for patterns like: `*.schema.ts`, `*.store.ts`, `*.hook.ts`
180
+
181
+ **Directory Structure**:
182
+ - Map the src/ directory structure
183
+ - Identify organization: feature-based, layer-based, hybrid
184
+
185
+ **Import Patterns**:
186
+ - Check tsconfig.json for path aliases (e.g., `@/`, `~/`)
187
+ - Detect barrel exports (index.ts files)
188
+
189
+ **Component Structure**:
190
+ - Check for co-located files (Component.tsx, Component.test.tsx, Component.module.css)
191
+ - Check for separated files (components/, tests/, styles/)
192
+
193
+ **Error Handling**:
194
+ - Search for try/catch patterns
195
+ - Identify custom error classes
196
+ - Check for error boundary usage
197
+
198
+ **Logging**:
199
+ - Search for console.log, logger imports
200
+ - Identify logging library if any
201
+
202
+ ---
203
+
204
+ ### Step 4: Research Best Practices
205
+
206
+ **Use web search to get current best practices for detected stack.**
207
+
208
+ For each major library/framework detected:
209
+
210
+ 1. Search for: `"[library] best practices 2025"` or `"[library] patterns"`
211
+ 2. Search for: `"[library] common mistakes to avoid"`
212
+ 3. Compare project patterns with industry standards
213
+
214
+ **Example Searches**:
215
+ - "Next.js App Router best practices 2025"
216
+ - "Zod schema validation patterns"
217
+ - "Zustand store organization patterns"
218
+ - "Prisma query optimization patterns"
219
+
220
+ **Document**:
221
+ - Best practices the project already follows
222
+ - Best practices the project should adopt
223
+ - Anti-patterns to avoid
224
+
225
+ ---
226
+
227
+ ### Step 5: Check Existing Cursor Rules
228
+
229
+ Look for existing cursor configuration:
230
+
231
+ **Locations to Check**:
232
+
233
+ 1. `.cursor/rules/` - Custom rules directory
234
+ 2. `.cursorrules` - Legacy rules file
235
+ 3. `.cursor/settings.json` - Cursor settings
236
+
237
+ **Actions**:
238
+
239
+ 1. If `.cursor/rules/` exists:
240
+ - Read all `.mdc` files
241
+ - Extract patterns and conventions
242
+ - Note which patterns are already defined
243
+ - Identify conflicts with detected patterns
244
+
245
+ 2. If `.cursorrules` exists:
246
+ - Read the file completely
247
+ - Parse all rules and guidelines
248
+ - Plan migration to `.mdc` format
249
+
250
+ 3. Create inventory of existing rules
251
+
252
+ ---
253
+
254
+ ### Step 6: Ask Confirming Questions
255
+
256
+ Use Plan Mode to ask targeted questions about detected patterns.
257
+
258
+ **Switch to Plan mode and present findings first:**
259
+
260
+ ```markdown
261
+ ## Project Analysis Results
262
+
263
+ I analyzed your codebase and detected:
264
+
265
+ **Stack**: [Language] + [Framework]
266
+ **Key Libraries**: [List]
267
+ **Architecture**: [Pattern]
268
+
269
+ **Code Patterns Detected**:
270
+ 1. [Pattern with example]
271
+ 2. [Pattern with example]
272
+ 3. [Pattern with example]
273
+
274
+ **Conventions Detected**:
275
+ - File naming: [convention]
276
+ - Component structure: [convention]
277
+ - Import style: [convention]
278
+ ```
279
+
280
+ **Then ask questions:**
281
+
282
+ #### Question 1: Stack Confirmation
283
+
284
+ ```
285
+ Is this stack detection accurate?
286
+
287
+ A. Yes, this is correct
288
+ B. Partially correct - I'll specify what's different
289
+ C. No, let me describe the stack
290
+ ```
291
+
292
+ #### Question 2: Pattern Confirmation
293
+
294
+ ```
295
+ I detected these coding patterns. Which should I enforce?
296
+
297
+ A. All detected patterns - they represent our standards
298
+ B. Let me review and select which to keep
299
+ C. These are legacy patterns - I'll describe our preferred patterns
300
+ ```
301
+
302
+ #### Question 3: Strictness Level
303
+
304
+ ```
305
+ How strictly should I enforce these patterns?
306
+
307
+ A. Strict - Always follow these patterns exactly
308
+ B. Moderate - Follow patterns but allow exceptions with justification
309
+ C. Loose - Use as guidelines, not requirements
310
+ ```
311
+
312
+ #### Question 4: Best Practices Integration
313
+
314
+ ```
315
+ I found some industry best practices your codebase could adopt. Should I:
316
+
317
+ A. Include them in pattern files as recommendations
318
+ B. Only document current patterns, no new recommendations
319
+ C. Show me the recommendations first
320
+ ```
321
+
322
+ #### Question 5: Existing Rules
323
+
324
+ (Only if existing rules found)
325
+
326
+ ```
327
+ I found existing cursor rules. How should I handle them?
328
+
329
+ A. Merge with new patterns (combine both)
330
+ B. Replace with new patterns
331
+ C. Keep existing, add new patterns separately
332
+ D. Let me review the conflicts
333
+ ```
334
+
335
+ ---
336
+
337
+ ### Step 7: Generate Pattern Files
338
+
339
+ Create comprehensive pattern files based on confirmed patterns.
340
+
341
+ #### 7.1 Framework Pattern File
342
+
343
+ **Location**: `.cursor/rules/frameworks/<framework>-patterns.mdc`
344
+
345
+ **Template**:
346
+
347
+ ```markdown
348
+ ---
349
+ description: "Include when working with [Framework] files"
350
+ globs: ["[appropriate globs]"]
351
+ alwaysApply: false
352
+ ---
353
+
354
+ # [Framework] Patterns
355
+
356
+ ## Project Usage
357
+
358
+ This project uses [Framework] with [specific configuration].
359
+
360
+ **Detected Configuration**:
361
+ - [Config item 1]
362
+ - [Config item 2]
363
+
364
+ ---
365
+
366
+ ## File Organization
367
+
368
+ | Type | Location | Naming |
369
+ |------|----------|--------|
370
+ | [Type] | [Path] | [Convention] |
371
+
372
+ ---
373
+
374
+ ## Allowed Patterns
375
+
376
+ ### [Pattern Category 1]
377
+
378
+ **Description**: [What this pattern does]
379
+
380
+ **Example from this codebase**:
381
+
382
+ \`\`\`typescript
383
+ // From: [actual file path]
384
+ [Real code example from project]
385
+ \`\`\`
386
+
387
+ **Guidelines**:
388
+ - [Guideline 1]
389
+ - [Guideline 2]
390
+
391
+ ### [Pattern Category 2]
392
+
393
+ [Same structure...]
394
+
395
+ ---
396
+
397
+ ## Forbidden Patterns
398
+
399
+ ### DON'T: [Anti-pattern name]
400
+
401
+ **Problem**: [Why this is bad]
402
+
403
+ \`\`\`typescript
404
+ // BAD
405
+ [Example of what not to do]
406
+
407
+ // GOOD
408
+ [Example of correct approach]
409
+ \`\`\`
410
+
411
+ ---
412
+
413
+ ## Best Practices
414
+
415
+ ### [Best Practice 1]
416
+
417
+ [Description with example]
418
+
419
+ ### [Best Practice 2]
420
+
421
+ [Description with example]
422
+ ```
423
+
424
+ #### 7.2 Library Pattern Files
425
+
426
+ **Location**: `.cursor/rules/libraries/<library>-patterns.mdc`
427
+
428
+ Create for each significant library with:
429
+
430
+ 1. How the project imports it
431
+ 2. Where related files are located
432
+ 3. Naming conventions for this library
433
+ 4. 2-3 real usage examples from the codebase
434
+ 5. Common mistakes to avoid
435
+
436
+ **Example for Zod**:
437
+
438
+ ```markdown
439
+ ---
440
+ description: "Include when working with Zod schemas"
441
+ globs: ["**/*.schema.ts", "**/schemas/**"]
442
+ alwaysApply: false
443
+ ---
444
+
445
+ # Zod Patterns
446
+
447
+ ## Project Usage
448
+
449
+ Schemas are located in `src/schemas/` and follow `[entity]Schema` naming.
450
+
451
+ ## Import Pattern
452
+
453
+ \`\`\`typescript
454
+ import { z } from 'zod'
455
+ \`\`\`
456
+
457
+ ## Schema Definition
458
+
459
+ \`\`\`typescript
460
+ // From: src/schemas/user.schema.ts
461
+ export const userSchema = z.object({
462
+ id: z.string().uuid(),
463
+ email: z.string().email(),
464
+ name: z.string().min(1).max(100),
465
+ })
466
+
467
+ export type User = z.infer<typeof userSchema>
468
+ \`\`\`
469
+
470
+ ## Allowed Patterns
471
+
472
+ ### Schema Naming
473
+ - Use `[entity]Schema` for main schemas
474
+ - Use `create[Entity]Schema` for creation schemas
475
+ - Use `update[Entity]Schema` for update schemas
476
+
477
+ ### Type Inference
478
+ - Always export inferred types alongside schemas
479
+ - Use `z.infer<typeof schema>` pattern
480
+
481
+ ## Forbidden Patterns
482
+
483
+ ### DON'T: Define schemas inline
484
+ \`\`\`typescript
485
+ // BAD - Schema defined inline
486
+ const data = z.object({ name: z.string() }).parse(input)
487
+
488
+ // GOOD - Schema defined and exported
489
+ import { userSchema } from '@/schemas/user.schema'
490
+ const data = userSchema.parse(input)
491
+ \`\`\`
492
+ ```
493
+
494
+ #### 7.3 Project Patterns File
495
+
496
+ **Location**: `.cursor/rules/project/project-patterns.mdc`
497
+
498
+ Document project-specific conventions:
499
+
500
+ ```markdown
501
+ ---
502
+ description: "Project-specific patterns and conventions"
503
+ alwaysApply: true
504
+ ---
505
+
506
+ # Project Patterns
507
+
508
+ ## Directory Structure
509
+
510
+ \`\`\`
511
+ src/
512
+ ├── app/ # Next.js App Router pages
513
+ ├── components/ # React components
514
+ │ ├── ui/ # UI primitives (buttons, inputs)
515
+ │ └── features/ # Feature-specific components
516
+ ├── hooks/ # Custom React hooks
517
+ ├── lib/ # Utility functions and clients
518
+ ├── schemas/ # Zod validation schemas
519
+ ├── stores/ # Zustand state stores
520
+ ├── types/ # TypeScript type definitions
521
+ └── services/ # API service functions
522
+ \`\`\`
523
+
524
+ ## File Naming
525
+
526
+ | Type | Convention | Example |
527
+ |------|------------|---------|
528
+ | Components | PascalCase | `UserProfile.tsx` |
529
+ | Hooks | camelCase with use prefix | `useAuth.ts` |
530
+ | Schemas | camelCase with .schema suffix | `user.schema.ts` |
531
+ | Stores | camelCase with .store suffix | `cart.store.ts` |
532
+ | Utils | camelCase | `formatDate.ts` |
533
+
534
+ ## Import Order
535
+
536
+ \`\`\`typescript
537
+ // 1. React/Framework imports
538
+ import { useState, useEffect } from 'react'
539
+ import { useRouter } from 'next/navigation'
540
+
541
+ // 2. Third-party libraries
542
+ import { z } from 'zod'
543
+ import { useQuery } from '@tanstack/react-query'
544
+
545
+ // 3. Internal imports (absolute)
546
+ import { Button } from '@/components/ui/button'
547
+ import { userSchema } from '@/schemas/user.schema'
548
+
549
+ // 4. Relative imports
550
+ import { formatDate } from './utils'
551
+ import type { UserProps } from './types'
552
+ \`\`\`
553
+
554
+ ## Component Structure
555
+
556
+ \`\`\`typescript
557
+ // Standard component structure in this project
558
+
559
+ // 1. Imports (ordered as above)
560
+
561
+ // 2. Types/Interfaces
562
+ interface ComponentProps {
563
+ // Props definition
564
+ }
565
+
566
+ // 3. Component
567
+ export function Component({ prop1, prop2 }: ComponentProps) {
568
+ // 4. Hooks first
569
+ const [state, setState] = useState()
570
+
571
+ // 5. Derived state
572
+ const computed = useMemo(() => ..., [deps])
573
+
574
+ // 6. Effects
575
+ useEffect(() => { ... }, [deps])
576
+
577
+ // 7. Handlers
578
+ const handleClick = () => { ... }
579
+
580
+ // 8. Render
581
+ return (...)
582
+ }
583
+ \`\`\`
584
+
585
+ ## Error Handling
586
+
587
+ [Detected error handling patterns]
588
+
589
+ ## API Patterns
590
+
591
+ [Detected API call patterns]
592
+ ```
593
+
594
+ ---
595
+
596
+ ### Step 8: Update Core Pattern Files
597
+
598
+ Integrate project-specific patterns into core files.
599
+
600
+ **Update `allowed-patterns.mdc`**:
601
+
602
+ Add a section at the end:
603
+
604
+ ```markdown
605
+ ---
606
+
607
+ ## Project-Specific Patterns
608
+
609
+ The following patterns are specific to this project's stack:
610
+
611
+ ### [Framework] Patterns
612
+ See: `.cursor/rules/frameworks/[framework]-patterns.mdc`
613
+
614
+ ### Library Patterns
615
+ See: `.cursor/rules/libraries/` for individual library patterns
616
+
617
+ ### Project Conventions
618
+ See: `.cursor/rules/project/project-patterns.mdc`
619
+ ```
620
+
621
+ **Update `forbidden-patterns.mdc`**:
622
+
623
+ Add detected anti-patterns specific to the project's stack.
624
+
625
+ ---
626
+
627
+ ### Step 9: Create Project Analysis Document
628
+
629
+ **Location**: `flow/references/project_analysis.md`
630
+
631
+ Create comprehensive analysis:
632
+
633
+ ```markdown
634
+ # Project Analysis
635
+
636
+ Generated: [Date]
637
+
638
+ ## Stack Overview
639
+
640
+ | Attribute | Value |
641
+ | ------------------ | -------------------------------------------- |
642
+ | Primary Language | [Language] |
643
+ | Framework | [Framework + Version] |
644
+ | Package Manager | [npm/yarn/pnpm/pip/poetry] |
645
+ | Testing Framework | [Jest/Vitest/Pytest] |
646
+ | Architecture | [Feature-based/Layer-based/etc.] |
647
+ | TypeScript | [Yes/No + strict mode?] |
648
+
649
+ ## Dependencies
650
+
651
+ ### Core Dependencies
652
+ | Package | Version | Purpose |
653
+ |---------|---------|---------|
654
+ | [pkg] | [ver] | [purpose] |
655
+
656
+ ### Dev Dependencies
657
+ | Package | Version | Purpose |
658
+ |---------|---------|---------|
659
+ | [pkg] | [ver] | [purpose] |
660
+
661
+ ## Architecture Analysis
662
+
663
+ ### Directory Structure
664
+ [Full directory tree with annotations]
665
+
666
+ ### Code Organization
667
+ - [Pattern 1]: [Description]
668
+ - [Pattern 2]: [Description]
669
+
670
+ ## Detected Patterns
671
+
672
+ ### Framework Patterns
673
+ [List with examples]
674
+
675
+ ### Library Patterns
676
+ [List with examples]
677
+
678
+ ### Coding Conventions
679
+ [List with examples]
680
+
681
+ ## Generated Pattern Files
682
+
683
+ | File | Purpose |
684
+ |------|---------|
685
+ | [path] | [description] |
686
+
687
+ ## Recommendations
688
+
689
+ ### Already Following Best Practices
690
+ - [Practice 1]
691
+ - [Practice 2]
692
+
693
+ ### Suggested Improvements
694
+ - [Improvement 1]
695
+ - [Improvement 2]
696
+ ```
697
+
698
+ ---
699
+
700
+ ### Step 10: Index Documentation Files
701
+
702
+ **Automatically index markdown documentation files in the project.**
703
+
704
+ This step scans for documentation folders and creates `_index.mdc` files with USR- reference codes for on-demand access.
705
+
706
+ #### 10.1 Detect Documentation Folders
707
+
708
+ Search for common documentation folder names in the project root:
709
+
710
+ | Folder Name | Priority |
711
+ | ---------------- | -------- |
712
+ | `docs/` | Primary |
713
+ | `documentation/` | Primary |
714
+
715
+ **Actions**:
716
+
717
+ 1. Check if `docs/` or `documentation/` folder exists at project root
718
+ 2. If neither exists, skip this step silently (no error)
719
+ 3. If found, proceed to scan for markdown files
720
+
721
+ #### 10.2 Scan Markdown Files
722
+
723
+ For each detected documentation folder:
724
+
725
+ 1. List all `.md` files in the folder (non-recursive, top-level only)
726
+ 2. Limit to first 50 files (warn if more exist)
727
+ 3. For each file, extract a brief description:
728
+ - Read first 10 lines of the file
729
+ - Use the first heading (`# Title`) as description
730
+ - If no heading, use the first non-empty paragraph
731
+ - If neither, use the filename as fallback
732
+
733
+ #### 10.3 Generate Index File
734
+
735
+ Create `_index.mdc` in each documentation folder.
736
+
737
+ **Location**: `docs/_index.mdc` or `documentation/_index.mdc`
738
+
739
+ **Template**:
740
+
741
+ ```markdown
742
+ ---
743
+ description: "Index of project documentation - load this to see available references"
744
+ alwaysApply: false
745
+ ---
746
+
747
+ # Documentation Index
748
+
749
+ ## Overview
750
+
751
+ Project documentation files. Use reference codes to access specific documents.
752
+
753
+ **Total Files**: X files
754
+
755
+ ---
756
+
757
+ ## Reference Codes
758
+
759
+ | Code | File | Description |
760
+ | ----- | --------------- | ------------------------------------ |
761
+ | USR-1 | README.md | [Extracted description] |
762
+ | USR-2 | api-guide.md | [Extracted description] |
763
+ | USR-3 | contributing.md | [Extracted description] |
764
+
765
+ ---
766
+
767
+ ## When to Expand
768
+
769
+ | Code | Expand When |
770
+ | ----- | ---------------------------------------- |
771
+ | USR-1 | Need project overview or getting started |
772
+ | USR-2 | Working with API integration |
773
+ ```
774
+
775
+ **Reference Code Convention**:
776
+
777
+ - Use `USR-` prefix for all user documentation
778
+ - Number sequentially: USR-1, USR-2, USR-3, etc.
779
+ - Keep codes stable (don't renumber on updates)
780
+
781
+ #### 10.4 Handle Edge Cases
782
+
783
+ | Scenario | Action |
784
+ | --------------------------- | ------------------------------------------- |
785
+ | No docs folder exists | Skip silently, no error |
786
+ | Empty docs folder | Skip silently, no error |
787
+ | More than 50 files | Index first 50, add warning in index file |
788
+ | File without clear heading | Use filename as description |
789
+ | Existing `_index.mdc` | Overwrite with fresh index |
790
+ | Nested folders | Only index top-level files (not recursive) |
791
+
792
+ ---
793
+
794
+ ### Step 11: Create Flow Folder Structure
795
+
796
+ **Create the `flow/` directory structure for plan-flow artifacts.**
797
+
798
+ If the `flow/` folder doesn't exist, create it with all subdirectories:
799
+
800
+ ```bash
801
+ mkdir -p flow/archive
802
+ mkdir -p flow/contracts
803
+ mkdir -p flow/discovery
804
+ mkdir -p flow/plans
805
+ mkdir -p flow/references
806
+ mkdir -p flow/reviewed-code
807
+ mkdir -p flow/reviewed-pr
808
+ ```
809
+
810
+ **Add `.gitkeep` files to preserve empty directories**:
811
+
812
+ ```bash
813
+ touch flow/archive/.gitkeep
814
+ touch flow/contracts/.gitkeep
815
+ touch flow/discovery/.gitkeep
816
+ touch flow/plans/.gitkeep
817
+ touch flow/references/.gitkeep
818
+ touch flow/reviewed-code/.gitkeep
819
+ touch flow/reviewed-pr/.gitkeep
820
+ ```
821
+
822
+ **Directory Purposes**:
823
+
824
+ | Directory | Purpose |
825
+ | ------------------ | ---------------------------------------------------- |
826
+ | `flow/archive/` | Completed/abandoned plans and documents |
827
+ | `flow/contracts/` | Integration contract documents |
828
+ | `flow/discovery/` | Discovery and research documents |
829
+ | `flow/plans/` | Active implementation plans |
830
+ | `flow/references/` | Reference materials (including project_analysis.md) |
831
+ | `flow/reviewed-code/` | Local code review documents |
832
+ | `flow/reviewed-pr/` | Pull request review documents |
833
+
834
+ **Note**: If the directories already exist, skip creation silently.
835
+
836
+ ---
837
+
838
+ ### Step 12: Present Setup Summary
839
+
840
+ ```markdown
841
+ Setup Complete!
842
+
843
+ ## Project Profile
844
+
845
+ | Attribute | Value |
846
+ | ------------------ | -------------------------------------------- |
847
+ | Primary Language | [Language] |
848
+ | Framework | [Framework] |
849
+ | Key Libraries | [Lib1], [Lib2], [Lib3] |
850
+ | Architecture | [Architecture pattern] |
851
+ | Strictness | [Strict/Moderate/Loose] |
852
+
853
+ ## Folder Structure Created
854
+
855
+ \`\`\`
856
+ flow/
857
+ ├── archive/ # Completed/abandoned plans
858
+ ├── contracts/ # Integration contracts
859
+ ├── discovery/ # Discovery documents
860
+ ├── plans/ # Active implementation plans
861
+ ├── references/ # Reference materials
862
+ ├── reviewed-code/ # Local code review documents
863
+ └── reviewed-pr/ # PR review documents
864
+ \`\`\`
865
+
866
+ ## Pattern Files Created
867
+
868
+ | File | Patterns Documented |
869
+ | ---------------------------------------------- | ------------------- |
870
+ | `flow/references/project_analysis.md` | Project analysis |
871
+ | `.cursor/rules/frameworks/[fw]-patterns.mdc` | X patterns |
872
+ | `.cursor/rules/libraries/[lib]-patterns.mdc` | X patterns each |
873
+ | `.cursor/rules/project/project-patterns.mdc` | X conventions |
874
+
875
+ ## Code Samples Indexed
876
+
877
+ - X component patterns extracted
878
+ - X schema patterns documented
879
+ - X API patterns captured
880
+ - X naming conventions identified
881
+
882
+ ## Documentation Indexed
883
+
884
+ | Folder | Files | Index Created |
885
+ | ------ | ----- | ------------- |
886
+ | `docs/` | X files | `docs/_index.mdc` |
887
+
888
+ *Use USR-1, USR-2, etc. reference codes to access documentation on-demand.*
889
+
890
+ ## Next Steps (user must invoke manually)
891
+
892
+ 1. Review generated pattern files in `.cursor/rules/`
893
+ 2. Adjust any patterns that don't match your preferences
894
+ 3. Start using plan-flow commands:
895
+ - `/discovery-plan` - Explore a new feature
896
+ - `/create-plan` - Create implementation plans
897
+ - `/review-code` - Review local changes
898
+ ```
899
+
900
+ ---
901
+
902
+ ## Pattern Quality Checklist
903
+
904
+ Before completing setup, verify each pattern file:
905
+
906
+ - [ ] Contains real code examples from the project
907
+ - [ ] Includes file paths where patterns are used
908
+ - [ ] Documents naming conventions with examples
909
+ - [ ] Lists what to do AND what not to do
910
+ - [ ] Uses consistent formatting
911
+ - [ ] Globs correctly match relevant files
912
+ - [ ] Description enables agent to know when to include
913
+
914
+ ---
915
+
916
+ ## Related Files
917
+
918
+ | File | Purpose |
919
+ | ---------------------------------------------- | --------------------------------- |
920
+ | `.cursor/rules/core/allowed-patterns.mdc` | Core allowed patterns |
921
+ | `.cursor/rules/core/forbidden-patterns.mdc` | Core forbidden patterns |
922
+ | `.cursor/rules/tools/interactive-questions-tool.mdc` | Questions UI |
923
+ | `flow/references/project_analysis.md` | Analysis output |