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.
- package/.claude/commands/create-contract.md +468 -0
- package/.claude/commands/create-plan.md +512 -0
- package/.claude/commands/discovery-plan.md +561 -0
- package/.claude/commands/execute-plan.md +682 -0
- package/.claude/commands/review-code.md +459 -0
- package/.claude/commands/review-pr.md +651 -0
- package/.claude/commands/setup.md +1609 -0
- package/.claude/commands/write-tests.md +543 -0
- package/.claude/rules/core/allowed-patterns.md +175 -0
- package/.claude/rules/core/complexity-scoring.md +225 -0
- package/.claude/rules/core/forbidden-patterns.md +253 -0
- package/.claude/rules/languages/python-patterns.md +6 -0
- package/.claude/rules/languages/typescript-patterns.md +7 -0
- package/.claude/rules/patterns/contract-patterns.md +332 -0
- package/.claude/rules/patterns/discovery-patterns.md +342 -0
- package/.claude/rules/patterns/discovery-templates.md +319 -0
- package/.claude/rules/patterns/jest-patterns.md +482 -0
- package/.claude/rules/patterns/plans-patterns.md +225 -0
- package/.claude/rules/patterns/plans-templates.md +227 -0
- package/.claude/rules/patterns/pytest-patterns.md +457 -0
- package/.claude/rules/patterns/review-code-templates.md +305 -0
- package/.claude/rules/patterns/review-pr-patterns.md +360 -0
- package/.claude/rules/tools/auth-pr-tool.md +30 -0
- package/.claude/rules/tools/interactive-questions-tool.md +235 -0
- package/.claude/rules/tools/jest-testing-tool.md +73 -0
- package/.claude/rules/tools/plan-mode-tool.md +164 -0
- package/.claude/rules/tools/pytest-testing-tool.md +121 -0
- package/.claude/rules/tools/reference-expansion-tool.md +326 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +139 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/handlers/claude.d.ts +9 -0
- package/dist/cli/handlers/claude.d.ts.map +1 -0
- package/dist/cli/handlers/claude.js +119 -0
- package/dist/cli/handlers/claude.js.map +1 -0
- package/dist/cli/handlers/codex.d.ts +9 -0
- package/dist/cli/handlers/codex.d.ts.map +1 -0
- package/dist/cli/handlers/codex.js +100 -0
- package/dist/cli/handlers/codex.js.map +1 -0
- package/dist/cli/handlers/cursor.d.ts +8 -0
- package/dist/cli/handlers/cursor.d.ts.map +1 -0
- package/dist/cli/handlers/cursor.js +34 -0
- package/dist/cli/handlers/cursor.js.map +1 -0
- package/dist/cli/handlers/openclaw.d.ts +8 -0
- package/dist/cli/handlers/openclaw.d.ts.map +1 -0
- package/dist/cli/handlers/openclaw.js +34 -0
- package/dist/cli/handlers/openclaw.js.map +1 -0
- package/dist/cli/handlers/shared.d.ts +9 -0
- package/dist/cli/handlers/shared.d.ts.map +1 -0
- package/dist/cli/handlers/shared.js +44 -0
- package/dist/cli/handlers/shared.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +43 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +26 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils/files.d.ts +37 -0
- package/dist/cli/utils/files.d.ts.map +1 -0
- package/dist/cli/utils/files.js +122 -0
- package/dist/cli/utils/files.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +11 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +34 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/prompts.d.ts +10 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +65 -0
- package/dist/cli/utils/prompts.js.map +1 -0
- package/dist/test/setup.d.ts +5 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/setup.js.map +1 -0
- package/package.json +63 -0
- package/rules/core/_index.mdc +89 -0
- package/rules/core/allowed-patterns.mdc +185 -0
- package/rules/core/complexity-scoring.mdc +235 -0
- package/rules/core/forbidden-patterns.mdc +263 -0
- package/rules/languages/_index.mdc +80 -0
- package/rules/languages/python-patterns.mdc +188 -0
- package/rules/languages/typescript-patterns.mdc +128 -0
- package/rules/patterns/_index.mdc +185 -0
- package/rules/patterns/contract-patterns.mdc +344 -0
- package/rules/patterns/discovery-patterns.mdc +354 -0
- package/rules/patterns/discovery-templates.mdc +329 -0
- package/rules/patterns/jest-patterns.mdc +492 -0
- package/rules/patterns/plans-patterns.mdc +237 -0
- package/rules/patterns/plans-templates.mdc +237 -0
- package/rules/patterns/pytest-patterns.mdc +467 -0
- package/rules/patterns/review-code-templates.mdc +315 -0
- package/rules/patterns/review-pr-patterns.mdc +370 -0
- package/rules/skills/_index.mdc +174 -0
- package/rules/skills/create-contract-skill.mdc +239 -0
- package/rules/skills/create-plan-skill.mdc +271 -0
- package/rules/skills/discovery-skill.mdc +295 -0
- package/rules/skills/execute-plan-skill.mdc +388 -0
- package/rules/skills/review-code-skill.mdc +308 -0
- package/rules/skills/review-pr-skill.mdc +496 -0
- package/rules/skills/setup-skill.mdc +923 -0
- package/rules/skills/write-tests-skill.mdc +294 -0
- package/rules/templates/index-template.mdc +126 -0
- package/rules/tools/_index.mdc +114 -0
- package/rules/tools/auth-pr-tool.mdc +362 -0
- package/rules/tools/interactive-questions-tool.mdc +337 -0
- package/rules/tools/jest-testing-tool.mdc +96 -0
- package/rules/tools/plan-mode-tool.mdc +229 -0
- package/rules/tools/pytest-testing-tool.mdc +144 -0
- package/rules/tools/reference-expansion-tool.mdc +338 -0
- package/skills/plan-flow/SKILL.md +109 -0
- package/skills/plan-flow/create-contract/SKILL.md +139 -0
- package/skills/plan-flow/create-plan/SKILL.md +93 -0
- package/skills/plan-flow/discovery/SKILL.md +85 -0
- package/skills/plan-flow/execute-plan/SKILL.md +89 -0
- package/skills/plan-flow/review-code/SKILL.md +100 -0
- package/skills/plan-flow/review-pr/SKILL.md +122 -0
- package/skills/plan-flow/setup/SKILL.md +73 -0
- package/skills/plan-flow/write-tests/SKILL.md +115 -0
- package/templates/shared/AGENTS.md.template +60 -0
- package/templates/shared/CLAUDE.md.template +62 -0
|
@@ -0,0 +1,1609 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: This command performs deep analysis of the current repository to index languages, frameworks, archit
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Setup Project
|
|
6
|
+
|
|
7
|
+
## Command Description
|
|
8
|
+
|
|
9
|
+
This command performs deep analysis of the current repository to index languages, frameworks, architecture patterns, and coding conventions. It samples real code, extracts actual patterns, and generates comprehensive pattern files that enable the agent to work effectively with the project's specific stack and conventions.
|
|
10
|
+
|
|
11
|
+
**Output**:
|
|
12
|
+
- Project analysis document at `flow/references/project_analysis.md`
|
|
13
|
+
- Framework pattern files in `.claude/rules/frameworks/`
|
|
14
|
+
- Library pattern files in `.claude/rules/libraries/`
|
|
15
|
+
- Project conventions in `.claude/rules/project/`
|
|
16
|
+
- Updated core pattern files
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Help
|
|
22
|
+
|
|
23
|
+
**If the user invokes this command with `-help`, display only this section and stop:**
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
/setup - Deep Project Analysis and Pattern Indexing
|
|
27
|
+
|
|
28
|
+
DESCRIPTION:
|
|
29
|
+
Performs deep analysis of the repository to understand the project's
|
|
30
|
+
stack, patterns, and conventions. Samples real code to extract actual
|
|
31
|
+
patterns and generates comprehensive pattern files with real examples.
|
|
32
|
+
|
|
33
|
+
USAGE:
|
|
34
|
+
/setup
|
|
35
|
+
/setup -help
|
|
36
|
+
|
|
37
|
+
EXAMPLES:
|
|
38
|
+
/setup # Analyze project and generate pattern files
|
|
39
|
+
|
|
40
|
+
OUTPUT:
|
|
41
|
+
- Creates: flow/ folder structure (if not exists)
|
|
42
|
+
- Creates: flow/references/project_analysis.md
|
|
43
|
+
- Creates: .claude/rules/frameworks/<framework>-patterns.md
|
|
44
|
+
- Creates: .claude/rules/libraries/<library>-patterns.md
|
|
45
|
+
- Creates: .claude/rules/project/project-patterns.md
|
|
46
|
+
- Updates: .claude/rules/core/allowed-patterns.md
|
|
47
|
+
- Updates: .claude/rules/core/forbidden-patterns.md
|
|
48
|
+
|
|
49
|
+
WORKFLOW:
|
|
50
|
+
1. Scans project structure and dependency files
|
|
51
|
+
2. Deep dependency analysis (all libraries, versions, purposes)
|
|
52
|
+
3. Deep code analysis (samples files, extracts real patterns)
|
|
53
|
+
4. Researches best practices for detected stack
|
|
54
|
+
5. Checks for existing cursor rules
|
|
55
|
+
6. Presents analysis summary
|
|
56
|
+
7. Asks confirming questions via Plan mode Questions UI
|
|
57
|
+
8. Generates pattern files based on confirmed patterns
|
|
58
|
+
9. Creates flow/ folder structure for plan-flow artifacts
|
|
59
|
+
10. Presents setup summary
|
|
60
|
+
|
|
61
|
+
WHAT IT INDEXES:
|
|
62
|
+
- Import patterns and styles
|
|
63
|
+
- File organization and naming conventions
|
|
64
|
+
- Component/function structure patterns
|
|
65
|
+
- Error handling approaches
|
|
66
|
+
- API call patterns
|
|
67
|
+
- State management patterns
|
|
68
|
+
- Validation patterns
|
|
69
|
+
- Testing patterns
|
|
70
|
+
|
|
71
|
+
DETECTS:
|
|
72
|
+
Languages: JavaScript, TypeScript, Python, Go, Rust, Java, Ruby, C#
|
|
73
|
+
Frameworks: Next.js, React, Vue, Angular, FastAPI, Django, Express, NestJS
|
|
74
|
+
Libraries: Zod, Prisma, Zustand, Redux, TailwindCSS, React Query, and 50+
|
|
75
|
+
|
|
76
|
+
RECOMMENDED MODEL:
|
|
77
|
+
Claude Opus 4.5 or Sonnet 4.5 for best results
|
|
78
|
+
|
|
79
|
+
RELATED COMMANDS:
|
|
80
|
+
/discovery-plan Start discovery after setup
|
|
81
|
+
/create-plan Create implementation plans
|
|
82
|
+
/review-code Review local changes
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Critical Rules
|
|
88
|
+
|
|
89
|
+
| Rule | Description |
|
|
90
|
+
| ------------------------ | -------------------------------------------------------- |
|
|
91
|
+
| **Deep Analysis** | Sample real code - don't just detect dependencies |
|
|
92
|
+
| **Real Examples** | Pattern files must include actual code from the project |
|
|
93
|
+
| **Research Best Practices** | Use web search to get current best practices |
|
|
94
|
+
| **Interactive Questions** | Use Plan mode Questions UI to confirm patterns |
|
|
95
|
+
| **User Confirmation** | Always confirm detected patterns before generating files |
|
|
96
|
+
| **Complete and Stop** | After presenting results, STOP and wait for user |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Required Tools
|
|
101
|
+
|
|
102
|
+
This command uses the Interactive Questions Tool for user confirmation.
|
|
103
|
+
|
|
104
|
+
See: `.claude/rules/tools/interactive-questions-tool.md`
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Instructions
|
|
109
|
+
|
|
110
|
+
### Step 1: Validate Context
|
|
111
|
+
|
|
112
|
+
Verify we're in a valid project directory:
|
|
113
|
+
|
|
114
|
+
1. Check for presence of dependency files (package.json, requirements.txt, etc.)
|
|
115
|
+
2. Check for source code directories (src/, app/, lib/, etc.)
|
|
116
|
+
3. If no project detected, inform user and ask for guidance
|
|
117
|
+
|
|
118
|
+
**If valid project found**, report initial findings:
|
|
119
|
+
|
|
120
|
+
```markdown
|
|
121
|
+
Found: [package.json/requirements.txt/etc.]
|
|
122
|
+
Source directories: [src/, app/, etc.]
|
|
123
|
+
Proceeding with deep analysis...
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### Step 2: Initial Dependency Scan
|
|
129
|
+
|
|
130
|
+
Read dependency files completely:
|
|
131
|
+
|
|
132
|
+
1. Parse all dependencies with versions
|
|
133
|
+
2. Categorize: frameworks, libraries, dev tools
|
|
134
|
+
3. Identify the complete stack
|
|
135
|
+
|
|
136
|
+
**Report findings**:
|
|
137
|
+
|
|
138
|
+
```markdown
|
|
139
|
+
## Detected Stack
|
|
140
|
+
|
|
141
|
+
**Language**: [TypeScript/JavaScript/Python/etc.]
|
|
142
|
+
**Framework**: [Next.js/FastAPI/etc.]
|
|
143
|
+
**Key Libraries**:
|
|
144
|
+
- Validation: [Zod/Pydantic/etc.]
|
|
145
|
+
- State: [Zustand/Redux/etc.]
|
|
146
|
+
- ORM: [Prisma/SQLAlchemy/etc.]
|
|
147
|
+
- Testing: [Jest/Vitest/Pytest/etc.]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### Step 3: Deep Code Analysis
|
|
153
|
+
|
|
154
|
+
**CRITICAL**: This is where the real indexing happens.
|
|
155
|
+
|
|
156
|
+
For each detected library/framework:
|
|
157
|
+
|
|
158
|
+
1. **Find relevant files** using glob patterns
|
|
159
|
+
2. **Read 2-5 sample files** to understand usage
|
|
160
|
+
3. **Extract patterns**:
|
|
161
|
+
- Import style
|
|
162
|
+
- File organization
|
|
163
|
+
- Naming conventions
|
|
164
|
+
- Code structure
|
|
165
|
+
- Usage patterns
|
|
166
|
+
|
|
167
|
+
**Document findings as you go**:
|
|
168
|
+
|
|
169
|
+
```markdown
|
|
170
|
+
## Analyzing [Library]...
|
|
171
|
+
|
|
172
|
+
**Files found**: X files matching pattern
|
|
173
|
+
**Sample files read**: [file1.ts], [file2.ts]
|
|
174
|
+
|
|
175
|
+
**Patterns detected**:
|
|
176
|
+
- Import: `import { x } from 'lib'`
|
|
177
|
+
- Location: `src/schemas/`
|
|
178
|
+
- Naming: `entitySchema`
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### Step 4: Detect Project Conventions
|
|
184
|
+
|
|
185
|
+
Analyze the codebase for conventions:
|
|
186
|
+
|
|
187
|
+
1. **File Naming**: kebab-case, camelCase, PascalCase
|
|
188
|
+
2. **Directory Structure**: feature-based, layer-based, hybrid
|
|
189
|
+
3. **Import Patterns**: path aliases, barrel exports
|
|
190
|
+
4. **Component Structure**: co-located vs separated
|
|
191
|
+
5. **Error Handling**: patterns used
|
|
192
|
+
6. **Logging**: library or console
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### Step 5: Research Best Practices
|
|
197
|
+
|
|
198
|
+
Use web search to get current best practices:
|
|
199
|
+
|
|
200
|
+
1. Search for `"[framework] best practices 2025"`
|
|
201
|
+
2. Search for `"[library] patterns"`
|
|
202
|
+
3. Compare with project patterns
|
|
203
|
+
4. Note recommendations
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### Step 6: Check Existing Cursor Rules
|
|
208
|
+
|
|
209
|
+
Check for existing rules:
|
|
210
|
+
|
|
211
|
+
1. `.claude/rules/` directory
|
|
212
|
+
2. `.cursorrules` file
|
|
213
|
+
3. Note conflicts and overlaps
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### Step 7: Ask Confirming Questions (Interactive)
|
|
218
|
+
|
|
219
|
+
**Use the Interactive Questions Tool to confirm detected patterns with the user.**
|
|
220
|
+
|
|
221
|
+
See: `.claude/rules/tools/interactive-questions-tool.md`
|
|
222
|
+
|
|
223
|
+
#### 7.1: Present Analysis Summary First
|
|
224
|
+
|
|
225
|
+
Before asking questions, present what was detected:
|
|
226
|
+
|
|
227
|
+
```markdown
|
|
228
|
+
## Project Analysis Complete
|
|
229
|
+
|
|
230
|
+
I analyzed your codebase and detected:
|
|
231
|
+
|
|
232
|
+
**Stack**: [Language] + [Framework]
|
|
233
|
+
**Key Libraries**: [Lib1], [Lib2], [Lib3]
|
|
234
|
+
**Architecture**: [Feature-based/Layer-based/etc.]
|
|
235
|
+
|
|
236
|
+
**Patterns Detected**:
|
|
237
|
+
1. [Pattern 1 with brief example]
|
|
238
|
+
2. [Pattern 2 with brief example]
|
|
239
|
+
3. [Pattern 3 with brief example]
|
|
240
|
+
|
|
241
|
+
**Conventions Detected**:
|
|
242
|
+
- File naming: [convention]
|
|
243
|
+
- Import style: [convention]
|
|
244
|
+
- Component structure: [convention]
|
|
245
|
+
|
|
246
|
+
Now I'll ask a few questions to confirm these patterns.
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### 7.2: Switch to Plan Mode
|
|
250
|
+
|
|
251
|
+
**MANDATORY**: Use `SwitchMode` tool to switch to Plan mode:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
Use Claude Code native conversation flow for questions
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
#### 7.3: Ask Setup Questions
|
|
258
|
+
|
|
259
|
+
Use `Ask the user directly in conversation` tool for each question:
|
|
260
|
+
|
|
261
|
+
**Question 1: Stack Confirmation**
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
Ask the user directly in conversation({
|
|
265
|
+
question: "I detected the following stack. Is this accurate?
|
|
266
|
+
|
|
267
|
+
[Framework]: [Detected framework]
|
|
268
|
+
[Language]: [Detected language]
|
|
269
|
+
[Key Libraries]: [List]",
|
|
270
|
+
options: [
|
|
271
|
+
"A. Yes, this is correct",
|
|
272
|
+
"B. Partially correct - I'll clarify what's different",
|
|
273
|
+
"C. No, let me describe the correct stack"
|
|
274
|
+
],
|
|
275
|
+
explanation: "Confirming the detected technology stack"
|
|
276
|
+
})
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Question 2: Architecture Confirmation**
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
Ask the user directly in conversation({
|
|
283
|
+
question: "I detected this architecture pattern:
|
|
284
|
+
|
|
285
|
+
[Detected pattern description]
|
|
286
|
+
|
|
287
|
+
Is this how your project is organized?",
|
|
288
|
+
options: [
|
|
289
|
+
"A. Yes, this is our architecture",
|
|
290
|
+
"B. No, we use a different approach",
|
|
291
|
+
"C. We're transitioning to a new architecture"
|
|
292
|
+
],
|
|
293
|
+
explanation: "Understanding the project's architectural approach"
|
|
294
|
+
})
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Question 3: Pattern Enforcement**
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
Ask the user directly in conversation({
|
|
301
|
+
question: "I found these coding patterns in your codebase. Which should I enforce?
|
|
302
|
+
|
|
303
|
+
1. [Pattern 1]
|
|
304
|
+
2. [Pattern 2]
|
|
305
|
+
3. [Pattern 3]",
|
|
306
|
+
options: [
|
|
307
|
+
"A. All detected patterns - they represent our standards",
|
|
308
|
+
"B. Let me review and select which to keep",
|
|
309
|
+
"C. These are legacy patterns - I'll describe preferred patterns"
|
|
310
|
+
],
|
|
311
|
+
explanation: "Determining which patterns to document and enforce"
|
|
312
|
+
})
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Question 4: Strictness Level**
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
Ask the user directly in conversation({
|
|
319
|
+
question: "How strictly should I enforce these patterns when generating code?",
|
|
320
|
+
options: [
|
|
321
|
+
"A. Strict - Always follow these patterns exactly",
|
|
322
|
+
"B. Moderate - Follow patterns but allow exceptions with justification",
|
|
323
|
+
"C. Loose - Use as guidelines, not requirements"
|
|
324
|
+
],
|
|
325
|
+
explanation: "Setting the enforcement level for detected patterns"
|
|
326
|
+
})
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Question 5: Best Practices** (if recommendations found)
|
|
330
|
+
|
|
331
|
+
```
|
|
332
|
+
Ask the user directly in conversation({
|
|
333
|
+
question: "I found some industry best practices your codebase could adopt:
|
|
334
|
+
|
|
335
|
+
1. [Recommendation 1]
|
|
336
|
+
2. [Recommendation 2]
|
|
337
|
+
|
|
338
|
+
Should I include these in the pattern files?",
|
|
339
|
+
options: [
|
|
340
|
+
"A. Yes, include them as recommendations",
|
|
341
|
+
"B. No, only document current patterns",
|
|
342
|
+
"C. Show me the full list first"
|
|
343
|
+
],
|
|
344
|
+
explanation: "Deciding whether to include best practice recommendations"
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Question 6: Existing Rules** (only if existing cursor rules found)
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
Ask the user directly in conversation({
|
|
352
|
+
question: "I found existing cursor rules in your project. How should I handle them?",
|
|
353
|
+
options: [
|
|
354
|
+
"A. Merge with new patterns (combine both)",
|
|
355
|
+
"B. Replace with new patterns",
|
|
356
|
+
"C. Keep existing rules, add new patterns separately",
|
|
357
|
+
"D. Let me review the conflicts first"
|
|
358
|
+
],
|
|
359
|
+
explanation: "Handling existing cursor rule files"
|
|
360
|
+
})
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
#### 7.4: Process Responses
|
|
364
|
+
|
|
365
|
+
After all questions are answered:
|
|
366
|
+
|
|
367
|
+
1. Extract selected options from each question
|
|
368
|
+
2. Map to corresponding answers
|
|
369
|
+
3. Document the confirmed patterns
|
|
370
|
+
4. Adjust pattern generation based on responses
|
|
371
|
+
|
|
372
|
+
#### 7.5: Switch Back to Agent Mode
|
|
373
|
+
|
|
374
|
+
**MANDATORY**: Use `SwitchMode` tool to return to Agent mode:
|
|
375
|
+
|
|
376
|
+
```
|
|
377
|
+
Use Claude Code native conversation flow for questions
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
### Step 8: Invoke Setup Skill
|
|
383
|
+
|
|
384
|
+
With confirmed patterns, the skill will:
|
|
385
|
+
|
|
386
|
+
1. Compile analysis into structured patterns based on user responses
|
|
387
|
+
2. Generate comprehensive pattern files with real examples
|
|
388
|
+
3. Create project analysis document
|
|
389
|
+
4. Update core pattern files
|
|
390
|
+
|
|
391
|
+
See: `.claude/rules/skills/setup-skill.md`
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
### Step 9: Create Flow Folder Structure
|
|
396
|
+
|
|
397
|
+
**Create the `flow/` directory structure for plan-flow artifacts.**
|
|
398
|
+
|
|
399
|
+
If the `flow/` folder doesn't exist, create it:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
mkdir -p flow/archive flow/contracts flow/discovery flow/plans flow/references flow/reviewed-code flow/reviewed-pr
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
**Add `.gitkeep` files**:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
touch flow/archive/.gitkeep flow/contracts/.gitkeep flow/discovery/.gitkeep flow/plans/.gitkeep flow/references/.gitkeep flow/reviewed-code/.gitkeep flow/reviewed-pr/.gitkeep
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**Directory Structure Created**:
|
|
412
|
+
|
|
413
|
+
```
|
|
414
|
+
flow/
|
|
415
|
+
├── archive/ # Completed/abandoned plans
|
|
416
|
+
├── contracts/ # Integration contracts
|
|
417
|
+
├── discovery/ # Discovery documents
|
|
418
|
+
├── plans/ # Active implementation plans
|
|
419
|
+
├── references/ # Reference materials + project_analysis.md
|
|
420
|
+
├── reviewed-code/ # Local code review documents
|
|
421
|
+
└── reviewed-pr/ # PR review documents
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
**Note**: Skip if directories already exist.
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
### Step 10: Present Results
|
|
429
|
+
|
|
430
|
+
After the skill completes:
|
|
431
|
+
|
|
432
|
+
```markdown
|
|
433
|
+
Setup Complete!
|
|
434
|
+
|
|
435
|
+
## Project Profile
|
|
436
|
+
|
|
437
|
+
| Attribute | Value |
|
|
438
|
+
| ------------------ | -------------------------------------------- |
|
|
439
|
+
| Primary Language | [Language] |
|
|
440
|
+
| Framework | [Framework] |
|
|
441
|
+
| Key Libraries | [Lib1], [Lib2], [Lib3] |
|
|
442
|
+
| Architecture | [Architecture pattern] |
|
|
443
|
+
| Strictness | [Strict/Moderate/Loose] |
|
|
444
|
+
|
|
445
|
+
## Folder Structure Created
|
|
446
|
+
|
|
447
|
+
flow/
|
|
448
|
+
├── archive/ # Completed/abandoned plans
|
|
449
|
+
├── contracts/ # Integration contracts
|
|
450
|
+
├── discovery/ # Discovery documents
|
|
451
|
+
├── plans/ # Active implementation plans
|
|
452
|
+
├── references/ # Reference materials
|
|
453
|
+
├── reviewed-code/ # Local code review documents
|
|
454
|
+
└── reviewed-pr/ # PR review documents
|
|
455
|
+
|
|
456
|
+
## Pattern Files Created
|
|
457
|
+
|
|
458
|
+
| File | Purpose |
|
|
459
|
+
| ---------------------------------------------- | --------------------- |
|
|
460
|
+
| `flow/references/project_analysis.md` | Project analysis |
|
|
461
|
+
| `.claude/rules/frameworks/[fw]-patterns.md` | Framework patterns |
|
|
462
|
+
| `.claude/rules/libraries/[lib1]-patterns.md` | [Lib1] patterns |
|
|
463
|
+
| `.claude/rules/libraries/[lib2]-patterns.md` | [Lib2] patterns |
|
|
464
|
+
| `.claude/rules/project/project-patterns.md` | Project conventions |
|
|
465
|
+
|
|
466
|
+
## Patterns Indexed
|
|
467
|
+
|
|
468
|
+
- X component patterns extracted
|
|
469
|
+
- X schema patterns documented
|
|
470
|
+
- X API patterns captured
|
|
471
|
+
- X naming conventions identified
|
|
472
|
+
- X best practices documented
|
|
473
|
+
|
|
474
|
+
## Next Steps (user must invoke manually)
|
|
475
|
+
|
|
476
|
+
1. Review generated pattern files in `.claude/rules/`
|
|
477
|
+
2. Adjust any patterns that don't match your preferences
|
|
478
|
+
3. Start using plan-flow commands:
|
|
479
|
+
- `/discovery-plan` - Explore a new feature
|
|
480
|
+
- `/create-plan` - Create implementation plans
|
|
481
|
+
- `/review-code` - Review local changes
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**CRITICAL**: This command is now complete. STOP and wait for the user to invoke the next command.
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## Flow Diagram
|
|
489
|
+
|
|
490
|
+
```
|
|
491
|
+
+----------------------------------------------------+
|
|
492
|
+
| /setup COMMAND |
|
|
493
|
+
+----------------------------------------------------+
|
|
494
|
+
|
|
|
495
|
+
v
|
|
496
|
+
+----------------------------------------------------+
|
|
497
|
+
| Step 1: Validate Context |
|
|
498
|
+
| - Check for dependency files |
|
|
499
|
+
| - Check for source directories |
|
|
500
|
+
+----------------------------------------------------+
|
|
501
|
+
|
|
|
502
|
+
v
|
|
503
|
+
+----------------------------------------------------+
|
|
504
|
+
| Step 2: Initial Dependency Scan |
|
|
505
|
+
| - Parse package.json / requirements.txt |
|
|
506
|
+
| - Categorize all dependencies |
|
|
507
|
+
| - Identify complete stack |
|
|
508
|
+
+----------------------------------------------------+
|
|
509
|
+
|
|
|
510
|
+
v
|
|
511
|
+
+----------------------------------------------------+
|
|
512
|
+
| Step 3: Deep Code Analysis |
|
|
513
|
+
| - Sample files for each library |
|
|
514
|
+
| - Extract import patterns |
|
|
515
|
+
| - Extract usage patterns |
|
|
516
|
+
| - Document naming conventions |
|
|
517
|
+
+----------------------------------------------------+
|
|
518
|
+
|
|
|
519
|
+
v
|
|
520
|
+
+----------------------------------------------------+
|
|
521
|
+
| Step 4: Detect Project Conventions |
|
|
522
|
+
| - File naming conventions |
|
|
523
|
+
| - Directory structure |
|
|
524
|
+
| - Import order and aliases |
|
|
525
|
+
| - Component structure |
|
|
526
|
+
+----------------------------------------------------+
|
|
527
|
+
|
|
|
528
|
+
v
|
|
529
|
+
+----------------------------------------------------+
|
|
530
|
+
| Step 5: Research Best Practices |
|
|
531
|
+
| - Web search for stack best practices |
|
|
532
|
+
| - Compare with project patterns |
|
|
533
|
+
| - Note recommendations |
|
|
534
|
+
+----------------------------------------------------+
|
|
535
|
+
|
|
|
536
|
+
v
|
|
537
|
+
+----------------------------------------------------+
|
|
538
|
+
| Step 6: Check Existing Cursor Rules |
|
|
539
|
+
| - .claude/rules/ |
|
|
540
|
+
| - .cursorrules |
|
|
541
|
+
| - Document conflicts |
|
|
542
|
+
+----------------------------------------------------+
|
|
543
|
+
|
|
|
544
|
+
v
|
|
545
|
+
+----------------------------------------------------+
|
|
546
|
+
| Step 7: Ask Confirming Questions (Interactive) |
|
|
547
|
+
| - Switch to Plan mode |
|
|
548
|
+
| - Present analysis summary |
|
|
549
|
+
| - Ask 4-6 confirming questions via Questions UI |
|
|
550
|
+
| - Process user responses |
|
|
551
|
+
| - Switch back to Agent mode |
|
|
552
|
+
+----------------------------------------------------+
|
|
553
|
+
|
|
|
554
|
+
v
|
|
555
|
+
+----------------------------------------------------+
|
|
556
|
+
| Step 8: Invoke Setup Skill |
|
|
557
|
+
| - Generate pattern files based on confirmations |
|
|
558
|
+
| - Create analysis document |
|
|
559
|
+
| - Update core pattern files |
|
|
560
|
+
+----------------------------------------------------+
|
|
561
|
+
|
|
|
562
|
+
v
|
|
563
|
+
+----------------------------------------------------+
|
|
564
|
+
| Step 9: Create Flow Folder Structure |
|
|
565
|
+
| - Create flow/ and subdirectories |
|
|
566
|
+
| - Add .gitkeep files |
|
|
567
|
+
+----------------------------------------------------+
|
|
568
|
+
|
|
|
569
|
+
v
|
|
570
|
+
+----------------------------------------------------+
|
|
571
|
+
| Step 10: Present Results |
|
|
572
|
+
| - Show project profile |
|
|
573
|
+
| - List files created |
|
|
574
|
+
| - Show patterns indexed |
|
|
575
|
+
+----------------------------------------------------+
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## What Gets Indexed
|
|
581
|
+
|
|
582
|
+
### Per Library/Framework
|
|
583
|
+
|
|
584
|
+
| Information | How It's Captured |
|
|
585
|
+
| --------------------- | -------------------------------------------- |
|
|
586
|
+
| Import style | Read sample files, extract import statements |
|
|
587
|
+
| File organization | Glob search, directory analysis |
|
|
588
|
+
| Naming conventions | Analyze file names and variable names |
|
|
589
|
+
| Usage patterns | Read and document 2-3 real examples |
|
|
590
|
+
| Best practices | Web search + codebase comparison |
|
|
591
|
+
| Anti-patterns | Web search for common mistakes |
|
|
592
|
+
|
|
593
|
+
### Project-Wide
|
|
594
|
+
|
|
595
|
+
| Information | How It's Captured |
|
|
596
|
+
| --------------------- | -------------------------------------------- |
|
|
597
|
+
| Directory structure | Full directory tree analysis |
|
|
598
|
+
| File naming | Pattern analysis across all files |
|
|
599
|
+
| Import order | Sample files, detect consistent ordering |
|
|
600
|
+
| Error handling | Search for try/catch, error classes |
|
|
601
|
+
| Logging | Search for logger usage |
|
|
602
|
+
| Testing patterns | Read test files, extract patterns |
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## Example: Next.js + Zod + Zustand Project
|
|
607
|
+
|
|
608
|
+
**Detected Stack**:
|
|
609
|
+
- Framework: Next.js 14 (App Router)
|
|
610
|
+
- Language: TypeScript (strict)
|
|
611
|
+
- Validation: Zod
|
|
612
|
+
- State: Zustand
|
|
613
|
+
- Styling: Tailwind CSS
|
|
614
|
+
- Testing: Vitest
|
|
615
|
+
|
|
616
|
+
**Files Created**:
|
|
617
|
+
|
|
618
|
+
1. `.claude/rules/frameworks/nextjs-patterns.md`
|
|
619
|
+
- App Router conventions
|
|
620
|
+
- Server vs Client components
|
|
621
|
+
- API route patterns
|
|
622
|
+
- Metadata handling
|
|
623
|
+
|
|
624
|
+
2. `.claude/rules/libraries/zod-patterns.md`
|
|
625
|
+
- Schema file location (`src/schemas/`)
|
|
626
|
+
- Naming convention (`entitySchema`)
|
|
627
|
+
- Real examples from codebase
|
|
628
|
+
- Type inference patterns
|
|
629
|
+
|
|
630
|
+
3. `.claude/rules/libraries/zustand-patterns.md`
|
|
631
|
+
- Store file location (`src/stores/`)
|
|
632
|
+
- Store structure pattern
|
|
633
|
+
- Selector patterns
|
|
634
|
+
- Real examples from codebase
|
|
635
|
+
|
|
636
|
+
4. `.claude/rules/project/project-patterns.md`
|
|
637
|
+
- Directory structure map
|
|
638
|
+
- File naming conventions
|
|
639
|
+
- Import order
|
|
640
|
+
- Component structure
|
|
641
|
+
- Error handling approach
|
|
642
|
+
|
|
643
|
+
---
|
|
644
|
+
|
|
645
|
+
## Context Optimization
|
|
646
|
+
|
|
647
|
+
This command uses hierarchical context loading to reduce context consumption. Instead of loading full files, load indexes first and expand specific sections on-demand.
|
|
648
|
+
|
|
649
|
+
### Recommended Loading Order
|
|
650
|
+
|
|
651
|
+
1. **Always load first**: This command file (`commands/setup.md`)
|
|
652
|
+
2. **Load indexes**: Load `_index.md` files for relevant folders
|
|
653
|
+
3. **Expand on-demand**: Use reference codes to load specific sections when needed
|
|
654
|
+
|
|
655
|
+
### Index Files for Setup
|
|
656
|
+
|
|
657
|
+
| Index | When to Load |
|
|
658
|
+
|-------|--------------|
|
|
659
|
+
| `rules/skills/_index.md` | To understand setup workflow |
|
|
660
|
+
| `rules/tools/_index.md` | For interactive questions tool |
|
|
661
|
+
| `rules/core/_index.md` | For pattern references |
|
|
662
|
+
| `rules/languages/_index.md` | For language-specific patterns |
|
|
663
|
+
|
|
664
|
+
### Reference Codes for Setup
|
|
665
|
+
|
|
666
|
+
| Code | Description | When to Expand |
|
|
667
|
+
|------|-------------|----------------|
|
|
668
|
+
| SKL-SETUP-1 | Setup skill workflow | Understanding full process |
|
|
669
|
+
| TLS-IQ-1 | Interactive questions overview | Before asking questions |
|
|
670
|
+
| TLS-IQ-2 | Switch to Plan mode | Starting question session |
|
|
671
|
+
| TLS-IQ-3 | Ask questions format | Asking confirmation questions |
|
|
672
|
+
| COR-AP-1 | Allowed patterns structure | Updating allowed patterns |
|
|
673
|
+
| COR-FP-1 | Forbidden patterns structure | Updating forbidden patterns |
|
|
674
|
+
| LNG-TS-1 | TypeScript patterns | If TS project detected |
|
|
675
|
+
| LNG-PY-1 | Python patterns | If Python project detected |
|
|
676
|
+
|
|
677
|
+
### Expansion Instructions
|
|
678
|
+
|
|
679
|
+
When executing this command:
|
|
680
|
+
|
|
681
|
+
1. **Start with indexes**: Read `rules/skills/_index.md` and `rules/tools/_index.md`
|
|
682
|
+
2. **Expand for detection phase**: Load minimal context during code analysis
|
|
683
|
+
3. **Expand for questions**: Load TLS-IQ-* before asking confirmation questions
|
|
684
|
+
4. **Expand for generation**: Load relevant language patterns when generating files
|
|
685
|
+
5. **Don't expand everything**: Only load patterns relevant to detected stack
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
## Related Resources
|
|
690
|
+
|
|
691
|
+
| Resource | Purpose |
|
|
692
|
+
| ------------------------------ | -------------------------------------- |
|
|
693
|
+
| `rules/skills/_index.md` | Index of skills with reference codes |
|
|
694
|
+
| `rules/tools/_index.md` | Index of tools with reference codes |
|
|
695
|
+
| `rules/core/_index.md` | Index of core rules with reference codes |
|
|
696
|
+
| `rules/languages/_index.md` | Index of language patterns with reference codes |
|
|
697
|
+
| `setup-skill.md` | Detailed execution logic |
|
|
698
|
+
| `interactive-questions-tool.md` | Questions UI for confirmations |
|
|
699
|
+
| `allowed-patterns.md` | Core allowed patterns |
|
|
700
|
+
| `forbidden-patterns.md` | Core forbidden patterns |
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
# Implementation Details
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
## Critical Approach
|
|
708
|
+
|
|
709
|
+
**This is NOT a surface-level scan.** The setup skill must:
|
|
710
|
+
|
|
711
|
+
1. **Sample Real Code** - Read actual files to understand how patterns are implemented
|
|
712
|
+
2. **Extract Real Examples** - Use code snippets from the project as pattern examples
|
|
713
|
+
3. **Research Best Practices** - Use web search to get current best practices for the stack
|
|
714
|
+
4. **Detect Conventions** - Identify naming, file structure, and coding conventions
|
|
715
|
+
5. **Create Actionable Patterns** - Generate patterns that can be directly followed
|
|
716
|
+
|
|
717
|
+
---
|
|
718
|
+
|
|
719
|
+
## Workflow
|
|
720
|
+
|
|
721
|
+
### Step 1: Scan Project Structure
|
|
722
|
+
|
|
723
|
+
Analyze the repository root to identify project type and structure.
|
|
724
|
+
|
|
725
|
+
**Files to Check**:
|
|
726
|
+
|
|
727
|
+
| File | Indicates |
|
|
728
|
+
| ----------------------- | -------------------------------------------- |
|
|
729
|
+
| `package.json` | JavaScript/TypeScript project |
|
|
730
|
+
| `requirements.txt` | Python project |
|
|
731
|
+
| `pyproject.toml` | Python project (modern) |
|
|
732
|
+
| `Cargo.toml` | Rust project |
|
|
733
|
+
| `go.mod` | Go project |
|
|
734
|
+
| `pom.xml` | Java/Maven project |
|
|
735
|
+
| `build.gradle` | Java/Kotlin Gradle project |
|
|
736
|
+
| `Gemfile` | Ruby project |
|
|
737
|
+
| `*.csproj` | C#/.NET project |
|
|
738
|
+
|
|
739
|
+
**Actions**:
|
|
740
|
+
|
|
741
|
+
1. List root directory files
|
|
742
|
+
2. Identify primary language from dependency files
|
|
743
|
+
3. Read dependency files completely to extract ALL libraries
|
|
744
|
+
4. Map directory structure (up to 3 levels deep)
|
|
745
|
+
|
|
746
|
+
---
|
|
747
|
+
|
|
748
|
+
### Step 2: Deep Dependency Analysis
|
|
749
|
+
|
|
750
|
+
Read and parse dependency files to build complete stack profile.
|
|
751
|
+
|
|
752
|
+
#### For JavaScript/TypeScript (package.json)
|
|
753
|
+
|
|
754
|
+
**Core Framework Detection**:
|
|
755
|
+
|
|
756
|
+
| Dependency | Framework | Pattern File to Create |
|
|
757
|
+
| ---------------------- | ---------------------- | -------------------------------- |
|
|
758
|
+
| `next` | Next.js | `nextjs-patterns.md` |
|
|
759
|
+
| `react` | React | `react-patterns.md` |
|
|
760
|
+
| `vue` | Vue.js | `vue-patterns.md` |
|
|
761
|
+
| `@angular/core` | Angular | `angular-patterns.md` |
|
|
762
|
+
| `express` | Express.js | `express-patterns.md` |
|
|
763
|
+
| `fastify` | Fastify | `fastify-patterns.md` |
|
|
764
|
+
| `hono` | Hono | `hono-patterns.md` |
|
|
765
|
+
| `@nestjs/core` | NestJS | `nestjs-patterns.md` |
|
|
766
|
+
|
|
767
|
+
**Library Detection** (create individual pattern files):
|
|
768
|
+
|
|
769
|
+
| Category | Libraries | Pattern File |
|
|
770
|
+
| ---------------------- | ---------------------- | -------------------------------- |
|
|
771
|
+
| Validation | `zod`, `yup`, `joi` | `<lib>-patterns.md` |
|
|
772
|
+
| State Management | `zustand`, `redux`, `jotai`, `recoil` | `<lib>-patterns.md` |
|
|
773
|
+
| Data Fetching | `@tanstack/react-query`, `swr`, `axios` | `<lib>-patterns.md` |
|
|
774
|
+
| ORM/Database | `prisma`, `drizzle-orm`, `typeorm` | `<lib>-patterns.md` |
|
|
775
|
+
| Authentication | `next-auth`, `clerk`, `lucia` | `<lib>-patterns.md` |
|
|
776
|
+
| Styling | `tailwindcss`, `styled-components` | `<lib>-patterns.md` |
|
|
777
|
+
| Testing | `jest`, `vitest`, `playwright` | `<lib>-patterns.md` |
|
|
778
|
+
| Forms | `react-hook-form`, `formik` | `<lib>-patterns.md` |
|
|
779
|
+
| UI Components | `shadcn/ui`, `radix-ui`, `mantine` | `<lib>-patterns.md` |
|
|
780
|
+
|
|
781
|
+
#### For Python (requirements.txt / pyproject.toml)
|
|
782
|
+
|
|
783
|
+
| Category | Libraries | Pattern File |
|
|
784
|
+
| ---------------------- | ---------------------- | -------------------------------- |
|
|
785
|
+
| Web Framework | `fastapi`, `django`, `flask` | `<lib>-patterns.md` |
|
|
786
|
+
| Validation | `pydantic` | `pydantic-patterns.md` |
|
|
787
|
+
| ORM | `sqlalchemy`, `tortoise-orm` | `<lib>-patterns.md` |
|
|
788
|
+
| Testing | `pytest`, `unittest` | `<lib>-patterns.md` |
|
|
789
|
+
| Task Queue | `celery`, `rq` | `<lib>-patterns.md` |
|
|
790
|
+
| HTTP Client | `httpx`, `aiohttp` | `<lib>-patterns.md` |
|
|
791
|
+
|
|
792
|
+
---
|
|
793
|
+
|
|
794
|
+
### Step 3: Deep Code Analysis
|
|
795
|
+
|
|
796
|
+
**CRITICAL**: This step samples actual code to understand HOW the project uses each library.
|
|
797
|
+
|
|
798
|
+
#### 3.1 Sample Files by Type
|
|
799
|
+
|
|
800
|
+
For each detected library/framework, find and read sample files:
|
|
801
|
+
|
|
802
|
+
```
|
|
803
|
+
For Next.js:
|
|
804
|
+
- Read 2-3 files from app/ or pages/
|
|
805
|
+
- Read 2-3 API routes
|
|
806
|
+
- Read layout files
|
|
807
|
+
- Read middleware if exists
|
|
808
|
+
|
|
809
|
+
For React:
|
|
810
|
+
- Read 3-5 component files
|
|
811
|
+
- Read custom hooks
|
|
812
|
+
- Read context providers
|
|
813
|
+
|
|
814
|
+
For Zod:
|
|
815
|
+
- Search for .schema.ts files
|
|
816
|
+
- Search for files importing 'zod'
|
|
817
|
+
- Extract schema definition patterns
|
|
818
|
+
|
|
819
|
+
For Prisma:
|
|
820
|
+
- Read prisma/schema.prisma
|
|
821
|
+
- Search for files importing @prisma/client
|
|
822
|
+
- Extract query patterns
|
|
823
|
+
|
|
824
|
+
For Zustand:
|
|
825
|
+
- Search for store files
|
|
826
|
+
- Extract store structure patterns
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
#### 3.2 Extract Real Patterns
|
|
830
|
+
|
|
831
|
+
For each library, document:
|
|
832
|
+
|
|
833
|
+
1. **Import Style**
|
|
834
|
+
```typescript
|
|
835
|
+
// How does the project import this library?
|
|
836
|
+
import { z } from 'zod' // Named import
|
|
837
|
+
import prisma from '@/lib/prisma' // Default import from lib
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
2. **File Organization**
|
|
841
|
+
```
|
|
842
|
+
// Where are files for this library located?
|
|
843
|
+
src/schemas/*.ts - Zod schemas
|
|
844
|
+
src/stores/*.ts - Zustand stores
|
|
845
|
+
prisma/schema.prisma - Prisma schema
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
3. **Naming Conventions**
|
|
849
|
+
```typescript
|
|
850
|
+
// How are things named?
|
|
851
|
+
userSchema, createUserSchema // Schemas: camelCase + Schema suffix
|
|
852
|
+
useUserStore, useCartStore // Stores: use + Name + Store
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
4. **Usage Patterns**
|
|
856
|
+
```typescript
|
|
857
|
+
// How is the library typically used?
|
|
858
|
+
// Extract 2-3 real examples from the codebase
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
#### 3.3 Detect Project Conventions
|
|
862
|
+
|
|
863
|
+
**File Naming**:
|
|
864
|
+
- Analyze file names in src/ to detect: kebab-case, camelCase, PascalCase
|
|
865
|
+
- Check for patterns like: `*.schema.ts`, `*.store.ts`, `*.hook.ts`
|
|
866
|
+
|
|
867
|
+
**Directory Structure**:
|
|
868
|
+
- Map the src/ directory structure
|
|
869
|
+
- Identify organization: feature-based, layer-based, hybrid
|
|
870
|
+
|
|
871
|
+
**Import Patterns**:
|
|
872
|
+
- Check tsconfig.json for path aliases (e.g., `@/`, `~/`)
|
|
873
|
+
- Detect barrel exports (index.ts files)
|
|
874
|
+
|
|
875
|
+
**Component Structure**:
|
|
876
|
+
- Check for co-located files (Component.tsx, Component.test.tsx, Component.module.css)
|
|
877
|
+
- Check for separated files (components/, tests/, styles/)
|
|
878
|
+
|
|
879
|
+
**Error Handling**:
|
|
880
|
+
- Search for try/catch patterns
|
|
881
|
+
- Identify custom error classes
|
|
882
|
+
- Check for error boundary usage
|
|
883
|
+
|
|
884
|
+
**Logging**:
|
|
885
|
+
- Search for console.log, logger imports
|
|
886
|
+
- Identify logging library if any
|
|
887
|
+
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
### Step 4: Research Best Practices
|
|
891
|
+
|
|
892
|
+
**Use web search to get current best practices for detected stack.**
|
|
893
|
+
|
|
894
|
+
For each major library/framework detected:
|
|
895
|
+
|
|
896
|
+
1. Search for: `"[library] best practices 2025"` or `"[library] patterns"`
|
|
897
|
+
2. Search for: `"[library] common mistakes to avoid"`
|
|
898
|
+
3. Compare project patterns with industry standards
|
|
899
|
+
|
|
900
|
+
**Example Searches**:
|
|
901
|
+
- "Next.js App Router best practices 2025"
|
|
902
|
+
- "Zod schema validation patterns"
|
|
903
|
+
- "Zustand store organization patterns"
|
|
904
|
+
- "Prisma query optimization patterns"
|
|
905
|
+
|
|
906
|
+
**Document**:
|
|
907
|
+
- Best practices the project already follows
|
|
908
|
+
- Best practices the project should adopt
|
|
909
|
+
- Anti-patterns to avoid
|
|
910
|
+
|
|
911
|
+
---
|
|
912
|
+
|
|
913
|
+
### Step 5: Check Existing Cursor Rules
|
|
914
|
+
|
|
915
|
+
Look for existing cursor configuration:
|
|
916
|
+
|
|
917
|
+
**Locations to Check**:
|
|
918
|
+
|
|
919
|
+
1. `.claude/rules/` - Custom rules directory
|
|
920
|
+
2. `.cursorrules` - Legacy rules file
|
|
921
|
+
3. `.cursor/settings.json` - Cursor settings
|
|
922
|
+
|
|
923
|
+
**Actions**:
|
|
924
|
+
|
|
925
|
+
1. If `.claude/rules/` exists:
|
|
926
|
+
- Read all `.md` files
|
|
927
|
+
- Extract patterns and conventions
|
|
928
|
+
- Note which patterns are already defined
|
|
929
|
+
- Identify conflicts with detected patterns
|
|
930
|
+
|
|
931
|
+
2. If `.cursorrules` exists:
|
|
932
|
+
- Read the file completely
|
|
933
|
+
- Parse all rules and guidelines
|
|
934
|
+
- Plan migration to `.md` format
|
|
935
|
+
|
|
936
|
+
3. Create inventory of existing rules
|
|
937
|
+
|
|
938
|
+
---
|
|
939
|
+
|
|
940
|
+
### Step 6: Ask Confirming Questions
|
|
941
|
+
|
|
942
|
+
Use Plan Mode to ask targeted questions about detected patterns.
|
|
943
|
+
|
|
944
|
+
**Switch to Plan mode and present findings first:**
|
|
945
|
+
|
|
946
|
+
```markdown
|
|
947
|
+
## Project Analysis Results
|
|
948
|
+
|
|
949
|
+
I analyzed your codebase and detected:
|
|
950
|
+
|
|
951
|
+
**Stack**: [Language] + [Framework]
|
|
952
|
+
**Key Libraries**: [List]
|
|
953
|
+
**Architecture**: [Pattern]
|
|
954
|
+
|
|
955
|
+
**Code Patterns Detected**:
|
|
956
|
+
1. [Pattern with example]
|
|
957
|
+
2. [Pattern with example]
|
|
958
|
+
3. [Pattern with example]
|
|
959
|
+
|
|
960
|
+
**Conventions Detected**:
|
|
961
|
+
- File naming: [convention]
|
|
962
|
+
- Component structure: [convention]
|
|
963
|
+
- Import style: [convention]
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
**Then ask questions:**
|
|
967
|
+
|
|
968
|
+
#### Question 1: Stack Confirmation
|
|
969
|
+
|
|
970
|
+
```
|
|
971
|
+
Is this stack detection accurate?
|
|
972
|
+
|
|
973
|
+
A. Yes, this is correct
|
|
974
|
+
B. Partially correct - I'll specify what's different
|
|
975
|
+
C. No, let me describe the stack
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
#### Question 2: Pattern Confirmation
|
|
979
|
+
|
|
980
|
+
```
|
|
981
|
+
I detected these coding patterns. Which should I enforce?
|
|
982
|
+
|
|
983
|
+
A. All detected patterns - they represent our standards
|
|
984
|
+
B. Let me review and select which to keep
|
|
985
|
+
C. These are legacy patterns - I'll describe our preferred patterns
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
#### Question 3: Strictness Level
|
|
989
|
+
|
|
990
|
+
```
|
|
991
|
+
How strictly should I enforce these patterns?
|
|
992
|
+
|
|
993
|
+
A. Strict - Always follow these patterns exactly
|
|
994
|
+
B. Moderate - Follow patterns but allow exceptions with justification
|
|
995
|
+
C. Loose - Use as guidelines, not requirements
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
#### Question 4: Best Practices Integration
|
|
999
|
+
|
|
1000
|
+
```
|
|
1001
|
+
I found some industry best practices your codebase could adopt. Should I:
|
|
1002
|
+
|
|
1003
|
+
A. Include them in pattern files as recommendations
|
|
1004
|
+
B. Only document current patterns, no new recommendations
|
|
1005
|
+
C. Show me the recommendations first
|
|
1006
|
+
```
|
|
1007
|
+
|
|
1008
|
+
#### Question 5: Existing Rules
|
|
1009
|
+
|
|
1010
|
+
(Only if existing rules found)
|
|
1011
|
+
|
|
1012
|
+
```
|
|
1013
|
+
I found existing cursor rules. How should I handle them?
|
|
1014
|
+
|
|
1015
|
+
A. Merge with new patterns (combine both)
|
|
1016
|
+
B. Replace with new patterns
|
|
1017
|
+
C. Keep existing, add new patterns separately
|
|
1018
|
+
D. Let me review the conflicts
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
---
|
|
1022
|
+
|
|
1023
|
+
### Step 7: Generate Pattern Files
|
|
1024
|
+
|
|
1025
|
+
Create comprehensive pattern files based on confirmed patterns.
|
|
1026
|
+
|
|
1027
|
+
#### 7.1 Framework Pattern File
|
|
1028
|
+
|
|
1029
|
+
**Location**: `.claude/rules/frameworks/<framework>-patterns.md`
|
|
1030
|
+
|
|
1031
|
+
**Template**:
|
|
1032
|
+
|
|
1033
|
+
```markdown
|
|
1034
|
+
---
|
|
1035
|
+
description: "Include when working with [Framework] files"
|
|
1036
|
+
globs: ["[appropriate globs]"]
|
|
1037
|
+
alwaysApply: false
|
|
1038
|
+
---
|
|
1039
|
+
|
|
1040
|
+
# [Framework] Patterns
|
|
1041
|
+
|
|
1042
|
+
## Project Usage
|
|
1043
|
+
|
|
1044
|
+
This project uses [Framework] with [specific configuration].
|
|
1045
|
+
|
|
1046
|
+
**Detected Configuration**:
|
|
1047
|
+
- [Config item 1]
|
|
1048
|
+
- [Config item 2]
|
|
1049
|
+
|
|
1050
|
+
---
|
|
1051
|
+
|
|
1052
|
+
## File Organization
|
|
1053
|
+
|
|
1054
|
+
| Type | Location | Naming |
|
|
1055
|
+
|------|----------|--------|
|
|
1056
|
+
| [Type] | [Path] | [Convention] |
|
|
1057
|
+
|
|
1058
|
+
---
|
|
1059
|
+
|
|
1060
|
+
## Allowed Patterns
|
|
1061
|
+
|
|
1062
|
+
### [Pattern Category 1]
|
|
1063
|
+
|
|
1064
|
+
**Description**: [What this pattern does]
|
|
1065
|
+
|
|
1066
|
+
**Example from this codebase**:
|
|
1067
|
+
|
|
1068
|
+
\`\`\`typescript
|
|
1069
|
+
// From: [actual file path]
|
|
1070
|
+
[Real code example from project]
|
|
1071
|
+
\`\`\`
|
|
1072
|
+
|
|
1073
|
+
**Guidelines**:
|
|
1074
|
+
- [Guideline 1]
|
|
1075
|
+
- [Guideline 2]
|
|
1076
|
+
|
|
1077
|
+
### [Pattern Category 2]
|
|
1078
|
+
|
|
1079
|
+
[Same structure...]
|
|
1080
|
+
|
|
1081
|
+
---
|
|
1082
|
+
|
|
1083
|
+
## Forbidden Patterns
|
|
1084
|
+
|
|
1085
|
+
### DON'T: [Anti-pattern name]
|
|
1086
|
+
|
|
1087
|
+
**Problem**: [Why this is bad]
|
|
1088
|
+
|
|
1089
|
+
\`\`\`typescript
|
|
1090
|
+
// BAD
|
|
1091
|
+
[Example of what not to do]
|
|
1092
|
+
|
|
1093
|
+
// GOOD
|
|
1094
|
+
[Example of correct approach]
|
|
1095
|
+
\`\`\`
|
|
1096
|
+
|
|
1097
|
+
---
|
|
1098
|
+
|
|
1099
|
+
## Best Practices
|
|
1100
|
+
|
|
1101
|
+
### [Best Practice 1]
|
|
1102
|
+
|
|
1103
|
+
[Description with example]
|
|
1104
|
+
|
|
1105
|
+
### [Best Practice 2]
|
|
1106
|
+
|
|
1107
|
+
[Description with example]
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
#### 7.2 Library Pattern Files
|
|
1111
|
+
|
|
1112
|
+
**Location**: `.claude/rules/libraries/<library>-patterns.md`
|
|
1113
|
+
|
|
1114
|
+
Create for each significant library with:
|
|
1115
|
+
|
|
1116
|
+
1. How the project imports it
|
|
1117
|
+
2. Where related files are located
|
|
1118
|
+
3. Naming conventions for this library
|
|
1119
|
+
4. 2-3 real usage examples from the codebase
|
|
1120
|
+
5. Common mistakes to avoid
|
|
1121
|
+
|
|
1122
|
+
**Example for Zod**:
|
|
1123
|
+
|
|
1124
|
+
```markdown
|
|
1125
|
+
---
|
|
1126
|
+
description: "Include when working with Zod schemas"
|
|
1127
|
+
globs: ["**/*.schema.ts", "**/schemas/**"]
|
|
1128
|
+
alwaysApply: false
|
|
1129
|
+
---
|
|
1130
|
+
|
|
1131
|
+
# Zod Patterns
|
|
1132
|
+
|
|
1133
|
+
## Project Usage
|
|
1134
|
+
|
|
1135
|
+
Schemas are located in `src/schemas/` and follow `[entity]Schema` naming.
|
|
1136
|
+
|
|
1137
|
+
## Import Pattern
|
|
1138
|
+
|
|
1139
|
+
\`\`\`typescript
|
|
1140
|
+
import { z } from 'zod'
|
|
1141
|
+
\`\`\`
|
|
1142
|
+
|
|
1143
|
+
## Schema Definition
|
|
1144
|
+
|
|
1145
|
+
\`\`\`typescript
|
|
1146
|
+
// From: src/schemas/user.schema.ts
|
|
1147
|
+
export const userSchema = z.object({
|
|
1148
|
+
id: z.string().uuid(),
|
|
1149
|
+
email: z.string().email(),
|
|
1150
|
+
name: z.string().min(1).max(100),
|
|
1151
|
+
})
|
|
1152
|
+
|
|
1153
|
+
export type User = z.infer<typeof userSchema>
|
|
1154
|
+
\`\`\`
|
|
1155
|
+
|
|
1156
|
+
## Allowed Patterns
|
|
1157
|
+
|
|
1158
|
+
### Schema Naming
|
|
1159
|
+
- Use `[entity]Schema` for main schemas
|
|
1160
|
+
- Use `create[Entity]Schema` for creation schemas
|
|
1161
|
+
- Use `update[Entity]Schema` for update schemas
|
|
1162
|
+
|
|
1163
|
+
### Type Inference
|
|
1164
|
+
- Always export inferred types alongside schemas
|
|
1165
|
+
- Use `z.infer<typeof schema>` pattern
|
|
1166
|
+
|
|
1167
|
+
## Forbidden Patterns
|
|
1168
|
+
|
|
1169
|
+
### DON'T: Define schemas inline
|
|
1170
|
+
\`\`\`typescript
|
|
1171
|
+
// BAD - Schema defined inline
|
|
1172
|
+
const data = z.object({ name: z.string() }).parse(input)
|
|
1173
|
+
|
|
1174
|
+
// GOOD - Schema defined and exported
|
|
1175
|
+
import { userSchema } from '@/schemas/user.schema'
|
|
1176
|
+
const data = userSchema.parse(input)
|
|
1177
|
+
\`\`\`
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
#### 7.3 Project Patterns File
|
|
1181
|
+
|
|
1182
|
+
**Location**: `.claude/rules/project/project-patterns.md`
|
|
1183
|
+
|
|
1184
|
+
Document project-specific conventions:
|
|
1185
|
+
|
|
1186
|
+
```markdown
|
|
1187
|
+
---
|
|
1188
|
+
description: "Project-specific patterns and conventions"
|
|
1189
|
+
alwaysApply: true
|
|
1190
|
+
---
|
|
1191
|
+
|
|
1192
|
+
# Project Patterns
|
|
1193
|
+
|
|
1194
|
+
## Directory Structure
|
|
1195
|
+
|
|
1196
|
+
\`\`\`
|
|
1197
|
+
src/
|
|
1198
|
+
├── app/ # Next.js App Router pages
|
|
1199
|
+
├── components/ # React components
|
|
1200
|
+
│ ├── ui/ # UI primitives (buttons, inputs)
|
|
1201
|
+
│ └── features/ # Feature-specific components
|
|
1202
|
+
├── hooks/ # Custom React hooks
|
|
1203
|
+
├── lib/ # Utility functions and clients
|
|
1204
|
+
├── schemas/ # Zod validation schemas
|
|
1205
|
+
├── stores/ # Zustand state stores
|
|
1206
|
+
├── types/ # TypeScript type definitions
|
|
1207
|
+
└── services/ # API service functions
|
|
1208
|
+
\`\`\`
|
|
1209
|
+
|
|
1210
|
+
## File Naming
|
|
1211
|
+
|
|
1212
|
+
| Type | Convention | Example |
|
|
1213
|
+
|------|------------|---------|
|
|
1214
|
+
| Components | PascalCase | `UserProfile.tsx` |
|
|
1215
|
+
| Hooks | camelCase with use prefix | `useAuth.ts` |
|
|
1216
|
+
| Schemas | camelCase with .schema suffix | `user.schema.ts` |
|
|
1217
|
+
| Stores | camelCase with .store suffix | `cart.store.ts` |
|
|
1218
|
+
| Utils | camelCase | `formatDate.ts` |
|
|
1219
|
+
|
|
1220
|
+
## Import Order
|
|
1221
|
+
|
|
1222
|
+
\`\`\`typescript
|
|
1223
|
+
// 1. React/Framework imports
|
|
1224
|
+
import { useState, useEffect } from 'react'
|
|
1225
|
+
import { useRouter } from 'next/navigation'
|
|
1226
|
+
|
|
1227
|
+
// 2. Third-party libraries
|
|
1228
|
+
import { z } from 'zod'
|
|
1229
|
+
import { useQuery } from '@tanstack/react-query'
|
|
1230
|
+
|
|
1231
|
+
// 3. Internal imports (absolute)
|
|
1232
|
+
import { Button } from '@/components/ui/button'
|
|
1233
|
+
import { userSchema } from '@/schemas/user.schema'
|
|
1234
|
+
|
|
1235
|
+
// 4. Relative imports
|
|
1236
|
+
import { formatDate } from './utils'
|
|
1237
|
+
import type { UserProps } from './types'
|
|
1238
|
+
\`\`\`
|
|
1239
|
+
|
|
1240
|
+
## Component Structure
|
|
1241
|
+
|
|
1242
|
+
\`\`\`typescript
|
|
1243
|
+
// Standard component structure in this project
|
|
1244
|
+
|
|
1245
|
+
// 1. Imports (ordered as above)
|
|
1246
|
+
|
|
1247
|
+
// 2. Types/Interfaces
|
|
1248
|
+
interface ComponentProps {
|
|
1249
|
+
// Props definition
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// 3. Component
|
|
1253
|
+
export function Component({ prop1, prop2 }: ComponentProps) {
|
|
1254
|
+
// 4. Hooks first
|
|
1255
|
+
const [state, setState] = useState()
|
|
1256
|
+
|
|
1257
|
+
// 5. Derived state
|
|
1258
|
+
const computed = useMemo(() => ..., [deps])
|
|
1259
|
+
|
|
1260
|
+
// 6. Effects
|
|
1261
|
+
useEffect(() => { ... }, [deps])
|
|
1262
|
+
|
|
1263
|
+
// 7. Handlers
|
|
1264
|
+
const handleClick = () => { ... }
|
|
1265
|
+
|
|
1266
|
+
// 8. Render
|
|
1267
|
+
return (...)
|
|
1268
|
+
}
|
|
1269
|
+
\`\`\`
|
|
1270
|
+
|
|
1271
|
+
## Error Handling
|
|
1272
|
+
|
|
1273
|
+
[Detected error handling patterns]
|
|
1274
|
+
|
|
1275
|
+
## API Patterns
|
|
1276
|
+
|
|
1277
|
+
[Detected API call patterns]
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
---
|
|
1281
|
+
|
|
1282
|
+
### Step 8: Update Core Pattern Files
|
|
1283
|
+
|
|
1284
|
+
Integrate project-specific patterns into core files.
|
|
1285
|
+
|
|
1286
|
+
**Update `allowed-patterns.md`**:
|
|
1287
|
+
|
|
1288
|
+
Add a section at the end:
|
|
1289
|
+
|
|
1290
|
+
```markdown
|
|
1291
|
+
---
|
|
1292
|
+
|
|
1293
|
+
## Project-Specific Patterns
|
|
1294
|
+
|
|
1295
|
+
The following patterns are specific to this project's stack:
|
|
1296
|
+
|
|
1297
|
+
### [Framework] Patterns
|
|
1298
|
+
See: `.claude/rules/frameworks/[framework]-patterns.md`
|
|
1299
|
+
|
|
1300
|
+
### Library Patterns
|
|
1301
|
+
See: `.claude/rules/libraries/` for individual library patterns
|
|
1302
|
+
|
|
1303
|
+
### Project Conventions
|
|
1304
|
+
See: `.claude/rules/project/project-patterns.md`
|
|
1305
|
+
```
|
|
1306
|
+
|
|
1307
|
+
**Update `forbidden-patterns.md`**:
|
|
1308
|
+
|
|
1309
|
+
Add detected anti-patterns specific to the project's stack.
|
|
1310
|
+
|
|
1311
|
+
---
|
|
1312
|
+
|
|
1313
|
+
### Step 9: Create Project Analysis Document
|
|
1314
|
+
|
|
1315
|
+
**Location**: `flow/references/project_analysis.md`
|
|
1316
|
+
|
|
1317
|
+
Create comprehensive analysis:
|
|
1318
|
+
|
|
1319
|
+
```markdown
|
|
1320
|
+
# Project Analysis
|
|
1321
|
+
|
|
1322
|
+
Generated: [Date]
|
|
1323
|
+
|
|
1324
|
+
## Stack Overview
|
|
1325
|
+
|
|
1326
|
+
| Attribute | Value |
|
|
1327
|
+
| ------------------ | -------------------------------------------- |
|
|
1328
|
+
| Primary Language | [Language] |
|
|
1329
|
+
| Framework | [Framework + Version] |
|
|
1330
|
+
| Package Manager | [npm/yarn/pnpm/pip/poetry] |
|
|
1331
|
+
| Testing Framework | [Jest/Vitest/Pytest] |
|
|
1332
|
+
| Architecture | [Feature-based/Layer-based/etc.] |
|
|
1333
|
+
| TypeScript | [Yes/No + strict mode?] |
|
|
1334
|
+
|
|
1335
|
+
## Dependencies
|
|
1336
|
+
|
|
1337
|
+
### Core Dependencies
|
|
1338
|
+
| Package | Version | Purpose |
|
|
1339
|
+
|---------|---------|---------|
|
|
1340
|
+
| [pkg] | [ver] | [purpose] |
|
|
1341
|
+
|
|
1342
|
+
### Dev Dependencies
|
|
1343
|
+
| Package | Version | Purpose |
|
|
1344
|
+
|---------|---------|---------|
|
|
1345
|
+
| [pkg] | [ver] | [purpose] |
|
|
1346
|
+
|
|
1347
|
+
## Architecture Analysis
|
|
1348
|
+
|
|
1349
|
+
### Directory Structure
|
|
1350
|
+
[Full directory tree with annotations]
|
|
1351
|
+
|
|
1352
|
+
### Code Organization
|
|
1353
|
+
- [Pattern 1]: [Description]
|
|
1354
|
+
- [Pattern 2]: [Description]
|
|
1355
|
+
|
|
1356
|
+
## Detected Patterns
|
|
1357
|
+
|
|
1358
|
+
### Framework Patterns
|
|
1359
|
+
[List with examples]
|
|
1360
|
+
|
|
1361
|
+
### Library Patterns
|
|
1362
|
+
[List with examples]
|
|
1363
|
+
|
|
1364
|
+
### Coding Conventions
|
|
1365
|
+
[List with examples]
|
|
1366
|
+
|
|
1367
|
+
## Generated Pattern Files
|
|
1368
|
+
|
|
1369
|
+
| File | Purpose |
|
|
1370
|
+
|------|---------|
|
|
1371
|
+
| [path] | [description] |
|
|
1372
|
+
|
|
1373
|
+
## Recommendations
|
|
1374
|
+
|
|
1375
|
+
### Already Following Best Practices
|
|
1376
|
+
- [Practice 1]
|
|
1377
|
+
- [Practice 2]
|
|
1378
|
+
|
|
1379
|
+
### Suggested Improvements
|
|
1380
|
+
- [Improvement 1]
|
|
1381
|
+
- [Improvement 2]
|
|
1382
|
+
```
|
|
1383
|
+
|
|
1384
|
+
---
|
|
1385
|
+
|
|
1386
|
+
### Step 10: Index Documentation Files
|
|
1387
|
+
|
|
1388
|
+
**Automatically index markdown documentation files in the project.**
|
|
1389
|
+
|
|
1390
|
+
This step scans for documentation folders and creates `_index.md` files with USR- reference codes for on-demand access.
|
|
1391
|
+
|
|
1392
|
+
#### 10.1 Detect Documentation Folders
|
|
1393
|
+
|
|
1394
|
+
Search for common documentation folder names in the project root:
|
|
1395
|
+
|
|
1396
|
+
| Folder Name | Priority |
|
|
1397
|
+
| ---------------- | -------- |
|
|
1398
|
+
| `docs/` | Primary |
|
|
1399
|
+
| `documentation/` | Primary |
|
|
1400
|
+
|
|
1401
|
+
**Actions**:
|
|
1402
|
+
|
|
1403
|
+
1. Check if `docs/` or `documentation/` folder exists at project root
|
|
1404
|
+
2. If neither exists, skip this step silently (no error)
|
|
1405
|
+
3. If found, proceed to scan for markdown files
|
|
1406
|
+
|
|
1407
|
+
#### 10.2 Scan Markdown Files
|
|
1408
|
+
|
|
1409
|
+
For each detected documentation folder:
|
|
1410
|
+
|
|
1411
|
+
1. List all `.md` files in the folder (non-recursive, top-level only)
|
|
1412
|
+
2. Limit to first 50 files (warn if more exist)
|
|
1413
|
+
3. For each file, extract a brief description:
|
|
1414
|
+
- Read first 10 lines of the file
|
|
1415
|
+
- Use the first heading (`# Title`) as description
|
|
1416
|
+
- If no heading, use the first non-empty paragraph
|
|
1417
|
+
- If neither, use the filename as fallback
|
|
1418
|
+
|
|
1419
|
+
#### 10.3 Generate Index File
|
|
1420
|
+
|
|
1421
|
+
Create `_index.md` in each documentation folder.
|
|
1422
|
+
|
|
1423
|
+
**Location**: `docs/_index.md` or `documentation/_index.md`
|
|
1424
|
+
|
|
1425
|
+
**Template**:
|
|
1426
|
+
|
|
1427
|
+
```markdown
|
|
1428
|
+
---
|
|
1429
|
+
description: "Index of project documentation - load this to see available references"
|
|
1430
|
+
alwaysApply: false
|
|
1431
|
+
---
|
|
1432
|
+
|
|
1433
|
+
# Documentation Index
|
|
1434
|
+
|
|
1435
|
+
## Overview
|
|
1436
|
+
|
|
1437
|
+
Project documentation files. Use reference codes to access specific documents.
|
|
1438
|
+
|
|
1439
|
+
**Total Files**: X files
|
|
1440
|
+
|
|
1441
|
+
---
|
|
1442
|
+
|
|
1443
|
+
## Reference Codes
|
|
1444
|
+
|
|
1445
|
+
| Code | File | Description |
|
|
1446
|
+
| ----- | --------------- | ------------------------------------ |
|
|
1447
|
+
| USR-1 | README.md | [Extracted description] |
|
|
1448
|
+
| USR-2 | api-guide.md | [Extracted description] |
|
|
1449
|
+
| USR-3 | contributing.md | [Extracted description] |
|
|
1450
|
+
|
|
1451
|
+
---
|
|
1452
|
+
|
|
1453
|
+
## When to Expand
|
|
1454
|
+
|
|
1455
|
+
| Code | Expand When |
|
|
1456
|
+
| ----- | ---------------------------------------- |
|
|
1457
|
+
| USR-1 | Need project overview or getting started |
|
|
1458
|
+
| USR-2 | Working with API integration |
|
|
1459
|
+
```
|
|
1460
|
+
|
|
1461
|
+
**Reference Code Convention**:
|
|
1462
|
+
|
|
1463
|
+
- Use `USR-` prefix for all user documentation
|
|
1464
|
+
- Number sequentially: USR-1, USR-2, USR-3, etc.
|
|
1465
|
+
- Keep codes stable (don't renumber on updates)
|
|
1466
|
+
|
|
1467
|
+
#### 10.4 Handle Edge Cases
|
|
1468
|
+
|
|
1469
|
+
| Scenario | Action |
|
|
1470
|
+
| --------------------------- | ------------------------------------------- |
|
|
1471
|
+
| No docs folder exists | Skip silently, no error |
|
|
1472
|
+
| Empty docs folder | Skip silently, no error |
|
|
1473
|
+
| More than 50 files | Index first 50, add warning in index file |
|
|
1474
|
+
| File without clear heading | Use filename as description |
|
|
1475
|
+
| Existing `_index.md` | Overwrite with fresh index |
|
|
1476
|
+
| Nested folders | Only index top-level files (not recursive) |
|
|
1477
|
+
|
|
1478
|
+
---
|
|
1479
|
+
|
|
1480
|
+
### Step 11: Create Flow Folder Structure
|
|
1481
|
+
|
|
1482
|
+
**Create the `flow/` directory structure for plan-flow artifacts.**
|
|
1483
|
+
|
|
1484
|
+
If the `flow/` folder doesn't exist, create it with all subdirectories:
|
|
1485
|
+
|
|
1486
|
+
```bash
|
|
1487
|
+
mkdir -p flow/archive
|
|
1488
|
+
mkdir -p flow/contracts
|
|
1489
|
+
mkdir -p flow/discovery
|
|
1490
|
+
mkdir -p flow/plans
|
|
1491
|
+
mkdir -p flow/references
|
|
1492
|
+
mkdir -p flow/reviewed-code
|
|
1493
|
+
mkdir -p flow/reviewed-pr
|
|
1494
|
+
```
|
|
1495
|
+
|
|
1496
|
+
**Add `.gitkeep` files to preserve empty directories**:
|
|
1497
|
+
|
|
1498
|
+
```bash
|
|
1499
|
+
touch flow/archive/.gitkeep
|
|
1500
|
+
touch flow/contracts/.gitkeep
|
|
1501
|
+
touch flow/discovery/.gitkeep
|
|
1502
|
+
touch flow/plans/.gitkeep
|
|
1503
|
+
touch flow/references/.gitkeep
|
|
1504
|
+
touch flow/reviewed-code/.gitkeep
|
|
1505
|
+
touch flow/reviewed-pr/.gitkeep
|
|
1506
|
+
```
|
|
1507
|
+
|
|
1508
|
+
**Directory Purposes**:
|
|
1509
|
+
|
|
1510
|
+
| Directory | Purpose |
|
|
1511
|
+
| ------------------ | ---------------------------------------------------- |
|
|
1512
|
+
| `flow/archive/` | Completed/abandoned plans and documents |
|
|
1513
|
+
| `flow/contracts/` | Integration contract documents |
|
|
1514
|
+
| `flow/discovery/` | Discovery and research documents |
|
|
1515
|
+
| `flow/plans/` | Active implementation plans |
|
|
1516
|
+
| `flow/references/` | Reference materials (including project_analysis.md) |
|
|
1517
|
+
| `flow/reviewed-code/` | Local code review documents |
|
|
1518
|
+
| `flow/reviewed-pr/` | Pull request review documents |
|
|
1519
|
+
|
|
1520
|
+
**Note**: If the directories already exist, skip creation silently.
|
|
1521
|
+
|
|
1522
|
+
---
|
|
1523
|
+
|
|
1524
|
+
### Step 12: Present Setup Summary
|
|
1525
|
+
|
|
1526
|
+
```markdown
|
|
1527
|
+
Setup Complete!
|
|
1528
|
+
|
|
1529
|
+
## Project Profile
|
|
1530
|
+
|
|
1531
|
+
| Attribute | Value |
|
|
1532
|
+
| ------------------ | -------------------------------------------- |
|
|
1533
|
+
| Primary Language | [Language] |
|
|
1534
|
+
| Framework | [Framework] |
|
|
1535
|
+
| Key Libraries | [Lib1], [Lib2], [Lib3] |
|
|
1536
|
+
| Architecture | [Architecture pattern] |
|
|
1537
|
+
| Strictness | [Strict/Moderate/Loose] |
|
|
1538
|
+
|
|
1539
|
+
## Folder Structure Created
|
|
1540
|
+
|
|
1541
|
+
\`\`\`
|
|
1542
|
+
flow/
|
|
1543
|
+
├── archive/ # Completed/abandoned plans
|
|
1544
|
+
├── contracts/ # Integration contracts
|
|
1545
|
+
├── discovery/ # Discovery documents
|
|
1546
|
+
├── plans/ # Active implementation plans
|
|
1547
|
+
├── references/ # Reference materials
|
|
1548
|
+
├── reviewed-code/ # Local code review documents
|
|
1549
|
+
└── reviewed-pr/ # PR review documents
|
|
1550
|
+
\`\`\`
|
|
1551
|
+
|
|
1552
|
+
## Pattern Files Created
|
|
1553
|
+
|
|
1554
|
+
| File | Patterns Documented |
|
|
1555
|
+
| ---------------------------------------------- | ------------------- |
|
|
1556
|
+
| `flow/references/project_analysis.md` | Project analysis |
|
|
1557
|
+
| `.claude/rules/frameworks/[fw]-patterns.md` | X patterns |
|
|
1558
|
+
| `.claude/rules/libraries/[lib]-patterns.md` | X patterns each |
|
|
1559
|
+
| `.claude/rules/project/project-patterns.md` | X conventions |
|
|
1560
|
+
|
|
1561
|
+
## Code Samples Indexed
|
|
1562
|
+
|
|
1563
|
+
- X component patterns extracted
|
|
1564
|
+
- X schema patterns documented
|
|
1565
|
+
- X API patterns captured
|
|
1566
|
+
- X naming conventions identified
|
|
1567
|
+
|
|
1568
|
+
## Documentation Indexed
|
|
1569
|
+
|
|
1570
|
+
| Folder | Files | Index Created |
|
|
1571
|
+
| ------ | ----- | ------------- |
|
|
1572
|
+
| `docs/` | X files | `docs/_index.md` |
|
|
1573
|
+
|
|
1574
|
+
*Use USR-1, USR-2, etc. reference codes to access documentation on-demand.*
|
|
1575
|
+
|
|
1576
|
+
## Next Steps (user must invoke manually)
|
|
1577
|
+
|
|
1578
|
+
1. Review generated pattern files in `.claude/rules/`
|
|
1579
|
+
2. Adjust any patterns that don't match your preferences
|
|
1580
|
+
3. Start using plan-flow commands:
|
|
1581
|
+
- `/discovery-plan` - Explore a new feature
|
|
1582
|
+
- `/create-plan` - Create implementation plans
|
|
1583
|
+
- `/review-code` - Review local changes
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
---
|
|
1587
|
+
|
|
1588
|
+
## Pattern Quality Checklist
|
|
1589
|
+
|
|
1590
|
+
Before completing setup, verify each pattern file:
|
|
1591
|
+
|
|
1592
|
+
- [ ] Contains real code examples from the project
|
|
1593
|
+
- [ ] Includes file paths where patterns are used
|
|
1594
|
+
- [ ] Documents naming conventions with examples
|
|
1595
|
+
- [ ] Lists what to do AND what not to do
|
|
1596
|
+
- [ ] Uses consistent formatting
|
|
1597
|
+
- [ ] Globs correctly match relevant files
|
|
1598
|
+
- [ ] Description enables agent to know when to include
|
|
1599
|
+
|
|
1600
|
+
---
|
|
1601
|
+
|
|
1602
|
+
## Related Files
|
|
1603
|
+
|
|
1604
|
+
| File | Purpose |
|
|
1605
|
+
| ---------------------------------------------- | --------------------------------- |
|
|
1606
|
+
| `.claude/rules/core/allowed-patterns.md` | Core allowed patterns |
|
|
1607
|
+
| `.claude/rules/core/forbidden-patterns.md` | Core forbidden patterns |
|
|
1608
|
+
| `.claude/rules/tools/interactive-questions-tool.md` | Questions UI |
|
|
1609
|
+
| `flow/references/project_analysis.md` | Analysis output |
|