codingbuddy-rules 2.4.2 → 3.0.2
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/.ai-rules/CHANGELOG.md +122 -0
- package/.ai-rules/agents/README.md +527 -11
- package/.ai-rules/agents/accessibility-specialist.json +0 -1
- package/.ai-rules/agents/act-mode.json +0 -1
- package/.ai-rules/agents/agent-architect.json +0 -1
- package/.ai-rules/agents/ai-ml-engineer.json +0 -1
- package/.ai-rules/agents/architecture-specialist.json +14 -2
- package/.ai-rules/agents/backend-developer.json +14 -2
- package/.ai-rules/agents/code-quality-specialist.json +0 -1
- package/.ai-rules/agents/data-engineer.json +0 -1
- package/.ai-rules/agents/devops-engineer.json +24 -2
- package/.ai-rules/agents/documentation-specialist.json +0 -1
- package/.ai-rules/agents/eval-mode.json +0 -1
- package/.ai-rules/agents/event-architecture-specialist.json +719 -0
- package/.ai-rules/agents/frontend-developer.json +14 -2
- package/.ai-rules/agents/i18n-specialist.json +0 -1
- package/.ai-rules/agents/integration-specialist.json +11 -1
- package/.ai-rules/agents/migration-specialist.json +676 -0
- package/.ai-rules/agents/mobile-developer.json +0 -1
- package/.ai-rules/agents/observability-specialist.json +747 -0
- package/.ai-rules/agents/performance-specialist.json +24 -2
- package/.ai-rules/agents/plan-mode.json +0 -1
- package/.ai-rules/agents/platform-engineer.json +0 -1
- package/.ai-rules/agents/security-specialist.json +27 -16
- package/.ai-rules/agents/seo-specialist.json +0 -1
- package/.ai-rules/agents/solution-architect.json +0 -1
- package/.ai-rules/agents/technical-planner.json +0 -1
- package/.ai-rules/agents/test-strategy-specialist.json +14 -2
- package/.ai-rules/agents/ui-ux-designer.json +0 -1
- package/.ai-rules/rules/core.md +25 -0
- package/.ai-rules/skills/README.md +35 -0
- package/.ai-rules/skills/database-migration/SKILL.md +531 -0
- package/.ai-rules/skills/database-migration/expand-contract-patterns.md +314 -0
- package/.ai-rules/skills/database-migration/large-scale-migration.md +414 -0
- package/.ai-rules/skills/database-migration/rollback-strategies.md +359 -0
- package/.ai-rules/skills/database-migration/validation-procedures.md +428 -0
- package/.ai-rules/skills/dependency-management/SKILL.md +381 -0
- package/.ai-rules/skills/dependency-management/license-compliance.md +282 -0
- package/.ai-rules/skills/dependency-management/lock-file-management.md +437 -0
- package/.ai-rules/skills/dependency-management/major-upgrade-guide.md +292 -0
- package/.ai-rules/skills/dependency-management/security-vulnerability-response.md +230 -0
- package/.ai-rules/skills/incident-response/SKILL.md +373 -0
- package/.ai-rules/skills/incident-response/communication-templates.md +322 -0
- package/.ai-rules/skills/incident-response/escalation-matrix.md +347 -0
- package/.ai-rules/skills/incident-response/postmortem-template.md +351 -0
- package/.ai-rules/skills/incident-response/severity-classification.md +256 -0
- package/.ai-rules/skills/performance-optimization/CREATION-LOG.md +87 -0
- package/.ai-rules/skills/performance-optimization/SKILL.md +76 -0
- package/.ai-rules/skills/performance-optimization/documentation-template.md +70 -0
- package/.ai-rules/skills/pr-review/SKILL.md +768 -0
- package/.ai-rules/skills/refactoring/SKILL.md +192 -0
- package/.ai-rules/skills/refactoring/refactoring-catalog.md +1377 -0
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: refactoring
|
|
3
|
+
description: Use when improving code structure without changing behavior, cleaning up technical debt, or preparing code for new features
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Refactoring
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Refactoring improves code structure without changing behavior. Tests must pass before AND after.
|
|
11
|
+
|
|
12
|
+
**Core principle:** Behavior preservation is non-negotiable. If tests fail, you changed behavior.
|
|
13
|
+
|
|
14
|
+
**Violating the letter of this process is violating the spirit of refactoring.**
|
|
15
|
+
|
|
16
|
+
## The Iron Law
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
NO REFACTORING WITHOUT TESTS PASSING FIRST AND AFTER
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Refactored with failing tests? You introduced bugs. Revert immediately.
|
|
23
|
+
|
|
24
|
+
**No exceptions:**
|
|
25
|
+
- "Tests don't cover this code" → Add tests first
|
|
26
|
+
- "I'll run tests after all changes" → One refactoring, verify, commit
|
|
27
|
+
- "IDE did it automatically" → Verify tests anyway
|
|
28
|
+
|
|
29
|
+
## When to Use
|
|
30
|
+
|
|
31
|
+
```dot
|
|
32
|
+
digraph when_refactor {
|
|
33
|
+
"Want to change code?" [shape=diamond];
|
|
34
|
+
"Adding/changing behavior?" [shape=diamond];
|
|
35
|
+
"Tests passing?" [shape=diamond];
|
|
36
|
+
"Use TDD skill" [shape=box];
|
|
37
|
+
"Make tests pass first" [shape=box];
|
|
38
|
+
"Apply this skill" [shape=box, style=filled, fillcolor="#ccffcc"];
|
|
39
|
+
|
|
40
|
+
"Want to change code?" -> "Adding/changing behavior?" [label="yes"];
|
|
41
|
+
"Adding/changing behavior?" -> "Use TDD skill" [label="yes"];
|
|
42
|
+
"Adding/changing behavior?" -> "Tests passing?" [label="no"];
|
|
43
|
+
"Tests passing?" -> "Make tests pass first" [label="no"];
|
|
44
|
+
"Tests passing?" -> "Apply this skill" [label="yes"];
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Use for:** Code cleanup, technical debt, preparing for features
|
|
49
|
+
**Don't use for:** Bug fixes, new features (use TDD skill)
|
|
50
|
+
|
|
51
|
+
## The Safe Refactoring Loop
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
1. VERIFY GREEN - Run tests, confirm all pass
|
|
55
|
+
2. IDENTIFY - Pick ONE code smell (see Quick Reference table)
|
|
56
|
+
3. SELECT PATTERN - Choose refactoring from refactoring-catalog.md
|
|
57
|
+
4. APPLY - Make minimal structural change
|
|
58
|
+
5. VERIFY GREEN - Run tests, confirm still pass
|
|
59
|
+
6. COMMIT - One refactoring per commit
|
|
60
|
+
7. REPEAT or STOP
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**REQUIRED SUB-SKILL:** Use superpowers:test-driven-development for test verification.
|
|
64
|
+
|
|
65
|
+
**Pattern Selection:** The `refactoring-catalog.md` file in this directory contains 24 patterns with before/after examples. Match your code smell to the pattern, review the example, then apply.
|
|
66
|
+
|
|
67
|
+
## Quick Reference
|
|
68
|
+
|
|
69
|
+
| Code Smell | Pattern | Action |
|
|
70
|
+
|------------|---------|--------|
|
|
71
|
+
| Long Method | Extract Method | Split into smaller functions |
|
|
72
|
+
| Duplicate Code | Extract + Reuse | Create shared helper |
|
|
73
|
+
| Feature Envy | Move Method | Move to correct class |
|
|
74
|
+
| Primitive Obsession | Replace with Object | Create value object |
|
|
75
|
+
| Large Class | Extract Class | Split responsibilities |
|
|
76
|
+
| Stateful Logic Duplication | Extract Custom Hook | Move to reusable hook (React) |
|
|
77
|
+
| Client-only Data Display | Convert to Server Component | Remove client JS (Next.js) |
|
|
78
|
+
|
|
79
|
+
See `refactoring-catalog.md` for complete pattern reference (29 patterns including React/Next.js).
|
|
80
|
+
|
|
81
|
+
## Example: Extract Method Walkthrough
|
|
82
|
+
|
|
83
|
+
**Scenario:** Long function with calculation buried in display logic.
|
|
84
|
+
|
|
85
|
+
**Step 1 - VERIFY GREEN:**
|
|
86
|
+
```bash
|
|
87
|
+
npm test
|
|
88
|
+
# ✅ 47 passing
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Step 2 - IDENTIFY:** Long method smell - `printReport()` is 35 lines with embedded price calculation.
|
|
92
|
+
|
|
93
|
+
**Step 3 - SELECT PATTERN:** Extract Method (from catalog).
|
|
94
|
+
|
|
95
|
+
**Step 4 - APPLY:**
|
|
96
|
+
```typescript
|
|
97
|
+
// Before: calculation embedded in printReport()
|
|
98
|
+
// After: extract to calculateOrderTotal()
|
|
99
|
+
function calculateOrderTotal(order: Order): number {
|
|
100
|
+
return order.items.reduce((sum, item) =>
|
|
101
|
+
sum + item.price * item.quantity, 0);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Step 5 - VERIFY GREEN:**
|
|
106
|
+
```bash
|
|
107
|
+
npm test
|
|
108
|
+
# ✅ 47 passing (same count = no behavior change)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Step 6 - COMMIT:**
|
|
112
|
+
```bash
|
|
113
|
+
git commit -m "refactor: extract calculateOrderTotal from printReport"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Step 7 - REPEAT:** Next smell: magic number `0.08` for tax rate → Replace Magic Number with Constant.
|
|
117
|
+
|
|
118
|
+
## Commit Conventions
|
|
119
|
+
|
|
120
|
+
| Type | Pattern | Example |
|
|
121
|
+
|------|---------|---------|
|
|
122
|
+
| Extract | `refactor: extract X from Y` | `refactor: extract validateEmail from submitForm` |
|
|
123
|
+
| Rename | `refactor: rename X to Y` | `refactor: rename usr to user` |
|
|
124
|
+
| Move | `refactor: move X to Y` | `refactor: move parseDate to utils` |
|
|
125
|
+
| Inline | `refactor: inline X` | `refactor: inline tempVariable` |
|
|
126
|
+
|
|
127
|
+
## Common Rationalizations
|
|
128
|
+
|
|
129
|
+
| Excuse | Reality |
|
|
130
|
+
|--------|---------|
|
|
131
|
+
| "Just a quick cleanup" | Verify tests first. Always. |
|
|
132
|
+
| "Tests don't cover this" | Add tests before refactoring. |
|
|
133
|
+
| "IDE does this safely" | IDE refactorings can fail. Verify. |
|
|
134
|
+
| "I'll test after all changes" | One refactoring, verify, commit. |
|
|
135
|
+
| "Need to refactor to fix bug" | Bug fix = behavioral. Separate commits. |
|
|
136
|
+
| "The whole file needs cleanup" | One refactoring at a time. |
|
|
137
|
+
|
|
138
|
+
## Red Flags - STOP
|
|
139
|
+
|
|
140
|
+
- Tests not passing before starting
|
|
141
|
+
- Multiple refactorings before verify
|
|
142
|
+
- Mixing structural and behavioral changes
|
|
143
|
+
- "I'll run tests at the end"
|
|
144
|
+
- Refactoring without understanding code
|
|
145
|
+
- Fixing bugs while refactoring
|
|
146
|
+
|
|
147
|
+
**All of these mean: STOP. Revert. Start over.**
|
|
148
|
+
|
|
149
|
+
## When Stuck
|
|
150
|
+
|
|
151
|
+
| Situation | Action |
|
|
152
|
+
|-----------|--------|
|
|
153
|
+
| Tests fail after refactoring | Revert immediately. Re-read the pattern. Try smaller step. |
|
|
154
|
+
| Can't find matching pattern | Check `refactoring-catalog.md`. If truly novel, add tests first. |
|
|
155
|
+
| Refactoring reveals bug | STOP refactoring. Fix bug separately using **superpowers:systematic-debugging**. |
|
|
156
|
+
| Need to add feature mid-refactoring | STOP. Commit current refactoring. Switch to **superpowers:test-driven-development**. |
|
|
157
|
+
| Code has no tests | Add tests first using **superpowers:test-driven-development**, then refactor. |
|
|
158
|
+
| Unsure if change is behavioral | If in doubt, it's behavioral. Write a test that captures current behavior first. |
|
|
159
|
+
|
|
160
|
+
## Verification Checklist
|
|
161
|
+
|
|
162
|
+
**Before:**
|
|
163
|
+
- [ ] All tests pass (verified, not assumed)
|
|
164
|
+
- [ ] I understand what this code does
|
|
165
|
+
- [ ] I identified a specific code smell
|
|
166
|
+
- [ ] I selected a named refactoring pattern
|
|
167
|
+
|
|
168
|
+
**After:**
|
|
169
|
+
- [ ] All tests still pass
|
|
170
|
+
- [ ] Behavior unchanged (verified)
|
|
171
|
+
- [ ] One commit per refactoring
|
|
172
|
+
- [ ] Commit message follows convention
|
|
173
|
+
|
|
174
|
+
## Technical Debt Prioritization
|
|
175
|
+
|
|
176
|
+
**Severity:**
|
|
177
|
+
- **Critical:** Blocks development, causes bugs
|
|
178
|
+
- **High:** Slows development, increases risk
|
|
179
|
+
- **Medium:** Code smell, future concern
|
|
180
|
+
- **Low:** Cosmetic, nice to have
|
|
181
|
+
|
|
182
|
+
**Priority = (Velocity Impact x Bug Risk) / Effort**
|
|
183
|
+
|
|
184
|
+
**Example:** Scale 1-5 for each factor:
|
|
185
|
+
|
|
186
|
+
| Debt Item | Velocity | Bug Risk | Effort | Priority |
|
|
187
|
+
|-----------|----------|----------|--------|----------|
|
|
188
|
+
| God class in OrderService | 5 | 4 | 3 | (5×4)/3 = **6.7** ← Do first |
|
|
189
|
+
| Inconsistent naming | 2 | 1 | 1 | (2×1)/1 = **2.0** |
|
|
190
|
+
| Missing null checks | 3 | 5 | 2 | (3×5)/2 = **7.5** ← Highest priority |
|
|
191
|
+
|
|
192
|
+
Address Critical first, then High during feature work.
|