cursor-quality-suite 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/README.md +155 -0
- package/bin/cli.js +303 -0
- package/commands/code-quality/churn-map.md +431 -0
- package/commands/code-quality/code-standards.md +219 -0
- package/commands/code-quality/pattern-drift.md +295 -0
- package/commands/code-quality/visualize-architecture.md +464 -0
- package/commands/testing/mutation-audit.md +229 -0
- package/commands/testing/risk-test-gen.md +232 -0
- package/commands/testing/write-unit-tests.md +42 -0
- package/package.json +36 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Detect when new code diverges from established codebase patterns/conventions
|
|
3
|
+
category: Context & Analysis
|
|
4
|
+
aliases: [drift, inconsistency, pattern-check]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Pattern Drift - Detect Architectural Drift
|
|
8
|
+
|
|
9
|
+
Detect when new code introduces patterns that don't match historical convergence.
|
|
10
|
+
|
|
11
|
+
**Very advanced, very valuable** — flags early architectural drift before it spreads.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
/pattern-drift
|
|
17
|
+
/pattern-drift {PATH}
|
|
18
|
+
/pattern-drift --since="3 months"
|
|
19
|
+
/pattern-drift --compare-to="master"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
/pattern-drift src/features/checkout
|
|
26
|
+
/pattern-drift src/components --since="6 months"
|
|
27
|
+
/pattern-drift --compare-to="origin/master"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What This Detects
|
|
31
|
+
|
|
32
|
+
### 1. New Patterns Without Precedent
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
════════════════════════════════════════════════════════════════
|
|
36
|
+
PATTERN DRIFT ANALYSIS: src/features/checkout
|
|
37
|
+
════════════════════════════════════════════════════════════════
|
|
38
|
+
|
|
39
|
+
🆕 NEW PATTERNS INTRODUCED (No Historical Precedent)
|
|
40
|
+
|
|
41
|
+
1. State Management Pattern
|
|
42
|
+
File: src/components/NewFeature/useNewFeature.ts
|
|
43
|
+
Pattern: Using Zustand store
|
|
44
|
+
Historical: 0 uses of Zustand in codebase
|
|
45
|
+
Established: React Query + Context (47 instances)
|
|
46
|
+
|
|
47
|
+
⚠️ DRIFT ALERT: This introduces a new state management approach
|
|
48
|
+
Action: Either adopt project-wide or align with existing pattern
|
|
49
|
+
Consider: /decision-record if intentional
|
|
50
|
+
|
|
51
|
+
2. Styling Approach
|
|
52
|
+
File: src/components/NewFeature/NewFeature.module.css
|
|
53
|
+
Pattern: CSS Modules
|
|
54
|
+
Historical: 0 CSS module files
|
|
55
|
+
Established: styled-components (234 instances)
|
|
56
|
+
|
|
57
|
+
⚠️ DRIFT ALERT: Different styling approach
|
|
58
|
+
Action: Convert to styled-components or document decision
|
|
59
|
+
|
|
60
|
+
3. Data Fetching
|
|
61
|
+
File: src/hooks/useNewData.ts
|
|
62
|
+
Pattern: Raw fetch() with custom caching
|
|
63
|
+
Historical: 2 instances (legacy code)
|
|
64
|
+
Established: React Query (89 instances)
|
|
65
|
+
|
|
66
|
+
⚠️ DRIFT ALERT: Bypassing established data fetching pattern
|
|
67
|
+
Action: Migrate to React Query
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 2. Inconsistent Component Styles
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
════════════════════════════════════════════════════════════════
|
|
74
|
+
COMPONENT STYLE DRIFT
|
|
75
|
+
════════════════════════════════════════════════════════════════
|
|
76
|
+
|
|
77
|
+
📊 Component Structure Analysis
|
|
78
|
+
|
|
79
|
+
Established Pattern (87% of components):
|
|
80
|
+
ComponentName/
|
|
81
|
+
├── ComponentName.tsx
|
|
82
|
+
├── ComponentName.styled.ts
|
|
83
|
+
├── ComponentName.types.ts
|
|
84
|
+
└── ComponentName.test.tsx
|
|
85
|
+
|
|
86
|
+
Drift Detected (13% of components):
|
|
87
|
+
|
|
88
|
+
1. Missing styled files:
|
|
89
|
+
- NewComponent.tsx (inline styles)
|
|
90
|
+
- AnotherComponent.tsx (inline styles)
|
|
91
|
+
|
|
92
|
+
2. Different file organization:
|
|
93
|
+
- FeatureX/index.tsx (barrel file pattern)
|
|
94
|
+
- FeatureY/styles.ts (non-standard naming)
|
|
95
|
+
|
|
96
|
+
3. Hook organization:
|
|
97
|
+
- useFeatureA.ts: hooks at bottom (non-standard)
|
|
98
|
+
- useFeatureB.ts: missing cleanup in useEffect
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 3. New Abstractions Without Precedent
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
════════════════════════════════════════════════════════════════
|
|
105
|
+
NEW ABSTRACTIONS DETECTED
|
|
106
|
+
════════════════════════════════════════════════════════════════
|
|
107
|
+
|
|
108
|
+
🆕 New Utility/Helper Patterns
|
|
109
|
+
|
|
110
|
+
1. src/utils/createStore.ts
|
|
111
|
+
Purpose: Generic store factory
|
|
112
|
+
Similar existing: None
|
|
113
|
+
|
|
114
|
+
Questions:
|
|
115
|
+
- Is this necessary? Could use existing patterns?
|
|
116
|
+
- Will this be adopted project-wide?
|
|
117
|
+
- Does this belong in a shared library?
|
|
118
|
+
|
|
119
|
+
2. src/hooks/useGenericFetch.ts
|
|
120
|
+
Purpose: Generic data fetching hook
|
|
121
|
+
Similar existing: React Query (established)
|
|
122
|
+
|
|
123
|
+
⚠️ This duplicates React Query functionality
|
|
124
|
+
Recommendation: Remove and use React Query
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 4. Dependency Direction Violations
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
════════════════════════════════════════════════════════════════
|
|
131
|
+
DEPENDENCY DIRECTION ANALYSIS
|
|
132
|
+
════════════════════════════════════════════════════════════════
|
|
133
|
+
|
|
134
|
+
Established Rules:
|
|
135
|
+
apps → libraries → core (downward only)
|
|
136
|
+
|
|
137
|
+
Violations Found:
|
|
138
|
+
|
|
139
|
+
1. ⚠️ Upward Dependency
|
|
140
|
+
src/components/src/Component.tsx
|
|
141
|
+
imports from: src/features/checkout/src/utils/helper.ts
|
|
142
|
+
|
|
143
|
+
This creates a circular dependency risk!
|
|
144
|
+
Fix: Move helper to business-modules or core
|
|
145
|
+
|
|
146
|
+
2. ⚠️ Cross-App Import
|
|
147
|
+
src/features/search/src/Component.tsx
|
|
148
|
+
imports from: src/features/checkout/src/types.ts
|
|
149
|
+
|
|
150
|
+
Apps should not depend on each other!
|
|
151
|
+
Fix: Move shared types to libraries
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Drift Categories
|
|
155
|
+
|
|
156
|
+
| Category | Severity | Action |
|
|
157
|
+
| ---------------- | -------- | ---------------------------- |
|
|
158
|
+
| 🔴 Architectural | Critical | Must resolve before merge |
|
|
159
|
+
| 🟠 Pattern | High | Strongly recommend alignment |
|
|
160
|
+
| 🟡 Style | Medium | Consider aligning |
|
|
161
|
+
| 🟢 Minor | Low | Note for future |
|
|
162
|
+
|
|
163
|
+
## Drift Report
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
════════════════════════════════════════════════════════════════
|
|
167
|
+
PATTERN DRIFT SUMMARY
|
|
168
|
+
════════════════════════════════════════════════════════════════
|
|
169
|
+
|
|
170
|
+
📊 Overall Drift Score: 23% (Moderate)
|
|
171
|
+
|
|
172
|
+
By Category:
|
|
173
|
+
🔴 Architectural Drift: 2 issues
|
|
174
|
+
🟠 Pattern Drift: 5 issues
|
|
175
|
+
🟡 Style Drift: 8 issues
|
|
176
|
+
🟢 Minor Drift: 12 issues
|
|
177
|
+
|
|
178
|
+
Trend (last 3 months):
|
|
179
|
+
Previous: 18% drift
|
|
180
|
+
Current: 23% drift
|
|
181
|
+
Direction: ↑ Increasing ⚠️
|
|
182
|
+
|
|
183
|
+
════════════════════════════════════════════════════════════════
|
|
184
|
+
RECOMMENDATIONS
|
|
185
|
+
════════════════════════════════════════════════════════════════
|
|
186
|
+
|
|
187
|
+
Immediate Actions:
|
|
188
|
+
1. 🔴 Fix dependency direction violations
|
|
189
|
+
2. 🔴 Decide on state management (React Query vs Zustand)
|
|
190
|
+
|
|
191
|
+
Short-term:
|
|
192
|
+
3. 🟠 Align styling approach (styled-components)
|
|
193
|
+
4. 🟠 Standardize component structure
|
|
194
|
+
|
|
195
|
+
Create Decision Records:
|
|
196
|
+
- If Zustand is intentional: /decision-record "Adopt Zustand for X"
|
|
197
|
+
- If CSS Modules intentional: /decision-record "Use CSS Modules for Y"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Pattern Detection Logic
|
|
201
|
+
|
|
202
|
+
### What We Analyze
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
1. Import Patterns
|
|
206
|
+
- What libraries are imported
|
|
207
|
+
- Import structure (named vs default)
|
|
208
|
+
- Relative vs absolute paths
|
|
209
|
+
|
|
210
|
+
2. Component Patterns
|
|
211
|
+
- File structure
|
|
212
|
+
- Hook usage
|
|
213
|
+
- State management approach
|
|
214
|
+
- Styling method
|
|
215
|
+
|
|
216
|
+
3. API Patterns
|
|
217
|
+
- Data fetching approach
|
|
218
|
+
- Error handling
|
|
219
|
+
- Caching strategy
|
|
220
|
+
|
|
221
|
+
4. Testing Patterns
|
|
222
|
+
- Test file location
|
|
223
|
+
- Test structure
|
|
224
|
+
- Mock patterns
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Convergence Detection
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
For each pattern category:
|
|
231
|
+
1. Count instances of each variant
|
|
232
|
+
2. Calculate dominance (% of total)
|
|
233
|
+
3. Flag variants < 20% as "drift"
|
|
234
|
+
4. Flag new variants (0 history) as "new pattern"
|
|
235
|
+
|
|
236
|
+
Example:
|
|
237
|
+
State Management:
|
|
238
|
+
- React Query + Context: 47 instances (85%) → Established
|
|
239
|
+
- Redux: 5 instances (9%) → Legacy
|
|
240
|
+
- Zustand: 1 instance (2%) → Drift (new)
|
|
241
|
+
- MobX: 2 instances (4%) → Drift (legacy)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Integration with Other Commands
|
|
245
|
+
|
|
246
|
+
| Command | Integration |
|
|
247
|
+
| --------------------------- | -------------------------------------------- |
|
|
248
|
+
| `/pre-pr-check` | Runs pattern-drift as part of validation |
|
|
249
|
+
| `/pr-review --architecture` | References drift analysis |
|
|
250
|
+
| `/decision-record` | Creates ADR for intentional new patterns |
|
|
251
|
+
| `/learn-from-prs` | Updates pattern baseline |
|
|
252
|
+
| `/refactor-new` | Suggests alignment with established patterns |
|
|
253
|
+
|
|
254
|
+
## AI Execution
|
|
255
|
+
|
|
256
|
+
When user runs `/pattern-drift`:
|
|
257
|
+
|
|
258
|
+
1. **Analyze Codebase**
|
|
259
|
+
|
|
260
|
+
- Scan all files in scope
|
|
261
|
+
- Categorize patterns by type
|
|
262
|
+
|
|
263
|
+
2. **Calculate Convergence**
|
|
264
|
+
|
|
265
|
+
- Count instances of each pattern
|
|
266
|
+
- Identify dominant patterns (established)
|
|
267
|
+
- Flag minority patterns (drift)
|
|
268
|
+
|
|
269
|
+
3. **Detect New Patterns**
|
|
270
|
+
|
|
271
|
+
- Compare recent changes to historical baseline
|
|
272
|
+
- Flag patterns with no precedent
|
|
273
|
+
|
|
274
|
+
4. **Check Decision Records**
|
|
275
|
+
|
|
276
|
+
- If pattern has ADR → Intentional, don't flag
|
|
277
|
+
- If no ADR → Potential drift
|
|
278
|
+
|
|
279
|
+
5. **Generate Report**
|
|
280
|
+
- Categorize by severity
|
|
281
|
+
- Provide actionable recommendations
|
|
282
|
+
- Suggest ADRs for intentional changes
|
|
283
|
+
|
|
284
|
+
## Customization
|
|
285
|
+
|
|
286
|
+
Create `.cursor/pattern-config.json`:
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
{
|
|
290
|
+
"established_threshold": 0.7,
|
|
291
|
+
"drift_threshold": 0.2,
|
|
292
|
+
"ignore_patterns": ["test files", "legacy/ folder"],
|
|
293
|
+
"intentional_patterns": ["CSS Modules in design-system"]
|
|
294
|
+
}
|
|
295
|
+
```
|