pdd-skills 3.1.13 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -21
  2. package/package.json +1 -1
  3. package/scaffolds/python-fullstack/.github/workflows/ci.yml +1 -1
  4. package/scaffolds/python-fullstack/Dockerfile +1 -1
  5. package/scaffolds/python-fullstack/docker-compose.yml +1 -1
  6. package/scaffolds/python-fullstack/frontend/Dockerfile +1 -1
  7. package/scaffolds/python-fullstack/frontend/nginx.conf +1 -1
  8. package/scaffolds/python-fullstack/frontend/postcss.config.js +1 -1
  9. package/scaffolds/python-fullstack/frontend/src/api/client.ts +1 -1
  10. package/scaffolds/python-fullstack/frontend/src/composables/useResponsive.ts +1 -1
  11. package/scaffolds/python-fullstack/frontend/src/router/index.ts +1 -1
  12. package/scaffolds/python-fullstack/frontend/src/stores/user.ts +1 -1
  13. package/scaffolds/python-fullstack/frontend/src/styles/responsive.css +1 -1
  14. package/scaffolds/python-fullstack/frontend/src/styles/variables.css +1 -1
  15. package/scaffolds/python-fullstack/frontend/src/views/DashboardView.vue +1 -1
  16. package/scaffolds/python-fullstack/frontend/src/views/HomeView.vue +1 -1
  17. package/scaffolds/python-fullstack/frontend/src/views/LoginView.vue +1 -1
  18. package/scaffolds/python-fullstack/frontend/tailwind.config.js +1 -1
  19. package/skills/core/official-doc-writer/README.md +232 -232
  20. package/skills/core/official-doc-writer/SKILL.md +4 -7
  21. package/skills/core/official-doc-writer/fonts/FONTS_LIST.md +44 -44
  22. package/skills/core/official-doc-writer/references/GBT_9704-2012_/345/205/232/346/224/277/346/234/272/345/205/263/345/205/254/346/226/207/346/240/274/345/274/217.md +422 -422
  23. package/skills/core/pdd-ba/SKILL.md +1 -11
  24. package/skills/core/pdd-entropy-reduction/SKILL.md +1 -9
  25. package/skills/core/pdd-extract-features/SKILL.md +1 -10
  26. package/skills/core/pdd-generate-spec/SKILL.md +1 -10
  27. package/skills/core/pdd-main/evals/evals.json +215 -215
  28. package/skills/core/pdd-verify-feature/SKILL.md +1 -10
  29. package/skills/core/pdd-vm/SKILL.md +1 -11
  30. package/skills/entropy/expert-arch-enforcer/SKILL.md +292 -292
  31. package/skills/entropy/expert-auto-refactor/SKILL.md +316 -327
  32. package/skills/entropy/expert-code-quality/SKILL.md +468 -468
  33. package/skills/entropy/expert-entropy-auditor/SKILL.md +276 -276
  34. package/skills/expert/expert-activiti/SKILL.md +488 -497
  35. package/skills/expert/expert-bug-fixer/SKILL.md +1 -26
  36. package/skills/expert/expert-mysql/SKILL.md +832 -832
  37. package/skills/expert/expert-ruoyi/SKILL.md +664 -674
  38. package/skills/expert/expert-springcloud/SKILL.md +1 -10
  39. package/skills/expert/expert-vue3/SKILL.md +1 -10
  40. package/skills/expert/testcase-agent/SKILL.md +5 -0
  41. package/skills/expert/testcase-modeler/SKILL.md +40 -2
  42. package/skills/pr/pdd-multi-review/SKILL.md +534 -534
  43. package/skills/pr/pdd-pr-batch/SKILL.md +303 -303
  44. package/skills/pr/pdd-pr-create/SKILL.md +344 -344
  45. package/skills/pr/pdd-pr-merge/SKILL.md +286 -286
  46. package/skills/pr/pdd-pr-review/SKILL.md +217 -217
  47. package/skills/pr/pdd-task-manager/SKILL.md +636 -636
  48. package/skills/pr/pdd-template-engine/SKILL.md +386 -386
  49. package/tests/login_manager.py +5 -30
  50. package/tests/recorder.py +362 -294
  51. package/tests/testcase-ai.py +1184 -11
@@ -1,468 +1,468 @@
1
- ---
2
- name: expert-code-quality
3
- description: "Code quality expert integrating refactoring techniques and design patterns for systematic improvement. Call when reviewing code, refactoring, or applying SOLID principles."
4
- license: "MIT"
5
- author: "neuqik@hotmail.com"
6
- version: "2.0"
7
- ---
8
-
9
- # Code Quality Expert
10
-
11
- ## Overview
12
-
13
- This skill integrates two foundational software engineering disciplines:
14
- 1. **Refactoring** - Improving code structure without changing behavior
15
- 2. **Design Patterns** - Proven solutions to common design problems
16
-
17
- Combined, they form a powerful toolkit for writing clean, maintainable, and extensible code.
18
-
19
- ## Directory Structure
20
-
21
- ```
22
- expert-code-quality/
23
- ├── SKILL.md # Skill definition file
24
- ├── LICENSE # MIT License
25
- └── references/ # Reference documents
26
- ├── refactoring-catalog.md # Complete catalog of refactoring techniques
27
- ├── design-patterns.md # 23 GoF patterns
28
- ├── code-smells.md # Detailed description of code smells
29
- └── solid-principles.md # In-depth analysis of SOLID principles
30
- ```
31
-
32
- ## Trigger Conditions
33
-
34
- **Automatic Triggers:**
35
- - User asks about code quality issues
36
- - Need to identify code smells
37
- - Request for design pattern recommendations
38
- - Performing code refactoring
39
- - Evaluating SOLID principle compliance
40
-
41
- **Manual Triggers:**
42
- - User enters commands like `/code-quality`, `/refactor`, `/pattern`, etc.
43
-
44
- ---
45
-
46
- ## Core Capabilities
47
-
48
- ### 1. Code Smell Detection
49
-
50
- #### 1.1 Quick Reference: 22 Code Smells
51
-
52
- **Method-Level Smells:**
53
-
54
- | Smell | Detection Pattern | Severity |
55
- |-------|------------------|----------|
56
- | **Long Method** | Method > 20 lines | High |
57
- | **Duplicated Code** | Similar code blocks | Critical |
58
- | **Long Parameter List** | Parameters > 4 | Medium |
59
- | **Switch Statements** | Large switch/case blocks | Medium |
60
-
61
- **Class-Level Smells:**
62
-
63
- | Smell | Detection Pattern | Severity |
64
- |-------|------------------|----------|
65
- | **Large Class** | Class > 300 lines or > 10 fields | High |
66
- | **Divergent Change** | One class changes for multiple reasons | High |
67
- | **Shotgun Surgery** | One change requires modifying many classes | High |
68
- | **Feature Envy** | Method uses data from other classes more | Medium |
69
-
70
- **Relationship-Level Smells:**
71
-
72
- | Smell | Detection Pattern | Severity |
73
- |-------|------------------|----------|
74
- | **Inappropriate Intimacy** | Classes access each other's private parts | Medium |
75
- | **Message Chains** | `a.b().c().d()` chains | Medium |
76
- | **Middle Man** | Class only does delegation | Low |
77
- | **Data Clumps** | Same data items always appear together | Medium |
78
-
79
- #### 1.2 Smell Detection Checklist
80
-
81
- When reviewing code, check:
82
- - [ ] Are there methods longer than 20 lines?
83
- - [ ] Is there duplicated code?
84
- - [ ] Are there classes with more than 10 fields?
85
- - [ ] Are there switch statements that could use polymorphism?
86
- - [ ] Are there methods with more than 4 parameters?
87
- - [ ] Is there deep inheritance hierarchy (> 3 levels)?
88
- - [ ] Does the class change for multiple reasons?
89
- - [ ] Are there message chains with more than 3 calls?
90
- - [ ] Are there "data classes" with only data and no behavior?
91
- - [ ] Are there "lazy classes" that do almost nothing?
92
-
93
- ---
94
-
95
- ### 2. Refactoring Techniques
96
-
97
- #### 2.1 Refactoring Principles
98
-
99
- **Two Hats (Kent Beck):**
100
-
101
- | Hat | Activity | Rule |
102
- |-----|----------|------|
103
- | **Adding Features** | Add new functionality | Don't modify existing code |
104
- | **Refactoring** | Improve structure | Don't add new features |
105
-
106
- **Never wear both hats at the same time!**
107
-
108
- **Refactoring Rhythm:**
109
- ```
110
- Test → Small Change → Test → Small Change → Test
111
- ```
112
-
113
- #### 2.2 Key Refactoring Techniques
114
-
115
- **Composing Methods:**
116
-
117
- | Refactoring | When to Use | Steps |
118
- |-------------|-------------|-------|
119
- | **Extract Method** | Method too long, code block needs naming | 1.Create new method 2.Copy code 3.Replace original code with call |
120
- | **Inline Method** | Method body as clear as its name | 1.Replace calls with method body 2.Delete method |
121
- | **Replace Temp with Query** | Temporary variable holds expression | 1.Extract expression to method 2.Replace temp with call |
122
- | **Replace Method with Method Object** | Too many temporaries in long method | 1.Create class for method 2.Temporaries become fields |
123
-
124
- **Moving Features:**
125
-
126
- | Refactoring | When to Use | Steps |
127
- |-------------|-------------|-------|
128
- | **Move Method** | Method uses other class more | 1.Copy to target 2.Delegate in source 3.Delete source method |
129
- | **Extract Class** | Class does too much | 1.Create new class 2.Move fields/methods 3.Link classes |
130
- | **Hide Delegate** | Client knows delegation chain | 1.Add delegate method 2.Hide chain |
131
-
132
- **Simplifying Conditionals:**
133
-
134
- | Refactoring | When to Use | Steps |
135
- |-------------|-------------|-------|
136
- | **Decompose Conditional** | Complex conditional logic | 1.Extract condition 2.Extract then/else |
137
- | **Consolidate Conditional** | Multiple checks with same result | 1.Combine with && or \|\| 2.Extract method |
138
- | **Replace Nested Conditional with Guard Clauses** | Deeply nested if-else | 1.Add guard clause returns 2.Flatten structure |
139
- | **Replace Conditional with Polymorphism** | Switch by type | 1.Create subclasses 2.Move behavior to each subclass |
140
-
141
- #### 2.3 Refactoring Decision Tree
142
-
143
- ```
144
- Found code smell?
145
-
146
- ├─ Do you have tests?
147
- │ ├─ No → Write tests first
148
- │ └─ Yes → Continue
149
-
150
- ├─ Do you understand the code?
151
- │ ├─ No → Refactor to understand
152
- │ └─ Yes → Continue
153
-
154
- └─ Choose refactoring approach:
155
-
156
- ├─ Method too long → Extract Method
157
- ├─ Duplicated code → Extract Method / Pull Up
158
- ├─ Class too large → Extract Class
159
- ├─ Parameter list too long → Introduce Parameter Object
160
- ├─ Switch statement → Replace with Polymorphism
161
- └─ Complex conditionals → Decompose / Guard Clauses
162
- ```
163
-
164
- ---
165
-
166
- ### 3. Design Patterns
167
-
168
- #### 3.1 SOLID Principles Foundation
169
-
170
- Before applying patterns, ensure understanding of SOLID principles:
171
-
172
- | Principle | Name | Description |
173
- |-----------|------|-------------|
174
- | **S** | Single Responsibility | One reason to change |
175
- | **O** | Open/Closed | Open for extension, closed for modification |
176
- | **L** | Liskov Substitution | Subtypes must be substitutable |
177
- | **I** | Interface Segregation | Small, focused interfaces |
178
- | **D** | Dependency Inversion | Depend on abstractions |
179
-
180
- #### 3.2 Selection by Problem Type
181
-
182
- | Problem | Pattern | Key Benefit |
183
- |---------|---------|-------------|
184
- | Need single instance | Singleton | Controlled access |
185
- | Flexible object creation | Factory Method | Decouple creation |
186
- | Create families of objects | Abstract Factory | Consistent products |
187
- | Build complex objects | Builder | Step-by-step construction |
188
- | Incompatible interfaces | Adapter | Make incompatible work |
189
- | Dynamically add responsibilities | Decorator | Flexible extension |
190
- | Control access | Proxy | Indirection layer |
191
- | Simplify complex system | Facade | Simple interface |
192
- | Tree structure | Composite | Uniform handling |
193
- | Switch algorithms | Strategy | Interchangeable behaviors |
194
- | Event notification | Observer | Loose coupling |
195
- | Encapsulate requests | Command | Undo/redo support |
196
- | State-dependent behavior | State | Clear state transitions |
197
-
198
- #### 3.3 Selection by Code Smell
199
-
200
- | Smell | Pattern Solution |
201
- |-------|------------------|
202
- | Large switch statement | State, Strategy |
203
- | Multiple conditionals | Strategy, State, Null Object |
204
- | Tight coupling | Observer, Mediator, Facade |
205
- | Difficult object creation | Factory, Builder |
206
- | Hard to extend class | Decorator, Adapter |
207
- | Complex subsystem | Facade |
208
- | Need varying algorithms | Strategy, Template Method |
209
-
210
- #### 3.4 Pattern Quick Reference
211
-
212
- **Creational Patterns:**
213
-
214
- | Pattern | When to Use |
215
- |---------|-------------|
216
- | Singleton | Need single instance |
217
- | Factory Method | Don't know exact class to create |
218
- | Abstract Factory | Need families of related objects |
219
- | Builder | Complex object with many options |
220
- | Prototype | Clone existing objects |
221
-
222
- **Structural Patterns:**
223
-
224
- | Pattern | When to Use |
225
- |---------|-------------|
226
- | Adapter | Incompatible interfaces |
227
- | Decorator | Dynamically add responsibilities |
228
- | Proxy | Control access, lazy loading |
229
- | Facade | Simplify complex interfaces |
230
- | Composite | Tree structure, uniform handling |
231
- | Flyweight | Many similar objects, share state |
232
- | Bridge | Separate abstraction from implementation |
233
-
234
- **Behavioral Patterns:**
235
-
236
- | Pattern | When to Use |
237
- |---------|-------------|
238
- | Strategy | Interchangeable algorithms |
239
- | Observer | One-to-many notifications |
240
- | Command | Encapsulate requests, undo/redo |
241
- | State | State-dependent behavior |
242
- | Template Method | Algorithm skeleton, varying steps |
243
- | Iterator | Uniform collection traversal |
244
- | Mediator | Complex object interactions |
245
- | Memento | Save/restore state |
246
- | Chain of Resp. | Request has multiple handlers |
247
- | Visitor | Add operations to object structure |
248
-
249
- ---
250
-
251
- ### 4. Integrated Workflow
252
-
253
- #### 4.1 Code Quality Improvement Process
254
-
255
- ```
256
- 1. IDENTIFY
257
- └── Detect code smells
258
- └── Use smell checklist
259
- └── Rate severity (Critical/High/Medium/Low)
260
-
261
- 2. DIAGNOSE
262
- └── Understand root cause
263
- └── Why does this smell exist?
264
- └── What problems will it cause?
265
-
266
- 3. PLAN
267
- └── Choose refactoring or pattern
268
- └── Consider dependencies
269
- └── Estimate impact
270
-
271
- 4. PREPARE
272
- └── Ensure tests exist
273
- └── Run tests to verify behavior
274
- └── Create tests if missing
275
-
276
- 5. EXECUTE
277
- └── Apply small changes
278
- └── Test after each change
279
- └── Keep code working
280
-
281
- 6. VERIFY
282
- └── Run all tests
283
- └── Check for new smells
284
- └── Confirm improvement
285
- ```
286
-
287
- #### 4.2 Smell→Refactoring→Pattern Flow
288
-
289
- ```
290
- Detected code smell
291
-
292
-
293
- ┌───────────────────┐
294
- │ Is this a method │
295
- │ level problem? │
296
- └────────┬──────────┘
297
-
298
- ┌────┴────┐
299
- │ Yes │ No
300
- ▼ ▼
301
- Extract Is this a class
302
- Method level problem?
303
-
304
- ┌────┴────┐
305
- │ Yes │ No
306
- ▼ ▼
307
- Extract Is this a
308
- Class relationship
309
- problem?
310
-
311
- ┌────┴────┐
312
- │ Yes │ No
313
- ▼ ▼
314
- Move/Hide Consider
315
- Delegate Pattern
316
-
317
-
318
- ┌──────────────┐
319
- │ Which │
320
- │ pattern fits │
321
- │ best? │
322
- └──────┬───────┘
323
-
324
- ┌───────────────┼───────────────┐
325
- ▼ ▼ ▼
326
- Creational Structural Behavioral
327
- Patterns Patterns Patterns
328
- ```
329
-
330
- ---
331
-
332
- ### 5. Collaboration Table
333
-
334
- #### 5.1 Collaboration with Other Skills
335
-
336
- | Collaborating Skill | Collaboration Mode | Description |
337
- |--------------------|-------------------|-------------|
338
- | **test-driven-development** | Sequential | Write tests before refactoring |
339
- | **systematic-debugging** | Consultation | Find root cause before fixing |
340
- | **requesting-code-review** | Reference | Get feedback on refactored code |
341
- | **pdd-code-reviewer** | Reference | Get PDD project code review |
342
- | **software-engineer** | Delegation | Quality check after code implementation |
343
-
344
- #### 5.2 Collaboration Workflow
345
-
346
- ```
347
- Code quality issue detected
348
-
349
- Invoke expert-code-quality
350
-
351
- Identify code smells + Recommend refactoring/patterns
352
-
353
- (If tests needed first) → Invoke test-driven-development
354
-
355
- (If code implementation needed) → Invoke software-engineer
356
-
357
- Complete code quality improvement
358
- ```
359
-
360
- ---
361
-
362
- ### 6. Quick Decision Matrix
363
-
364
- | Scenario | Primary Action |
365
- |----------|---------------|
366
- | Found duplicated code | Extract Method |
367
- | Method too long | Extract Method |
368
- | Class too large | Extract Class |
369
- | Parameter list too long | Introduce Parameter Object |
370
- | Switch by type | Replace with Polymorphism |
371
- | Need single instance | Consider Singleton |
372
- | Need flexible creation | Factory Method or Builder |
373
- | Incompatible interfaces | Adapter |
374
- | Need to add behavior | Decorator |
375
- | Complex subsystem | Facade |
376
- | Need varying algorithms | Strategy |
377
- | Need event notification | Observer |
378
-
379
- ---
380
-
381
- ### 7. Anti-Patterns
382
-
383
- #### 7.1 Refactoring Anti-Patterns
384
-
385
- | Anti-Pattern | Description | Correct Approach |
386
- |--------------|-------------|------------------|
387
- | **Big Bang Refactoring** | Rewrite everything at once | Small incremental changes |
388
- | **Refactoring Without Tests** | Change code without safety net | Write tests first |
389
- | **Over-Refactoring** | Refactor clean code | Stop when code is clear |
390
- | **Refactoring Addiction** | Only refactor, never deliver | Balance refactoring with features |
391
- | **Random Refactoring** | No clear goal | Identify smells first |
392
-
393
- #### 7.2 Pattern Anti-Patterns
394
-
395
- | Anti-Pattern | Description | Correct Approach |
396
- |--------------|-------------|------------------|
397
- | **Pattern Obsession** | Use patterns everywhere | Use patterns to solve problems |
398
- | **Singleton Abuse** | Everything is singleton | Use only when truly needed |
399
- | **Factory Overkill** | Factory for single product | Use factory for multiple products |
400
- | **Decorator Nesting** | Too many decorator layers | Limit nesting depth |
401
- | **Premature Pattern** | Use pattern before needed | Let patterns emerge from refactoring |
402
-
403
- ---
404
-
405
- ### 8. Practice Checklists
406
-
407
- #### 8.1 Code Review Checklist
408
-
409
- Before approving code, verify:
410
- - [ ] No critical code smells
411
- - [ ] Reasonable method size (< 20 lines)
412
- - [ ] Class has single responsibility
413
- - [ ] No duplicated code
414
- - [ ] Clear conditionals
415
- - [ ] Meaningful names
416
- - [ ] Tests exist and pass
417
- - [ ] Follows SOLID principles
418
- - [ ] Patterns used appropriately (not overused)
419
-
420
- #### 8.2 Refactoring Safety Checklist
421
-
422
- Before refactoring:
423
- - [ ] All tests pass
424
- - [ ] Tests cover code to refactor
425
- - [ ] Understand code functionality
426
- - [ ] Have rollback plan
427
- - [ ] Make small changes
428
- - [ ] Test after each change
429
-
430
- #### 8.3 Pattern Application Checklist
431
-
432
- Before applying pattern:
433
- - [ ] Problem matches pattern intent
434
- - [ ] Pattern solves real problem (not imagined)
435
- - [ ] Team understands pattern
436
- - [ ] Pattern doesn't overcomplicate
437
- - [ ] Alternatives considered
438
- - [ ] Pattern fits project context
439
-
440
- ---
441
-
442
- ## Guardrails
443
-
444
- - Must provide suggestions based on Martin Fowler's refactoring catalog and GoF design patterns
445
- - Refactoring suggestions need specific code transformation examples
446
- - Pattern application needs to weigh pros and cons, not blindly recommend
447
- - Code review needs to specifically point out problems and improvement suggestions
448
- - Clearly state uncertain issues to avoid misleading
449
-
450
- ---
451
-
452
- ## Version History
453
-
454
- ### v2.0 (2026-03-21)
455
- - Unified to Chinese description
456
- - Added collaboration table, clarified collaboration with other skills
457
- - Enhanced quick decision matrix
458
- - Optimized refactoring decision tree
459
- - Added anti-pattern checklist
460
-
461
- ### v1.0 (Initial version)
462
- - Basic code quality detection
463
- - Refactoring technique catalog
464
- - Design pattern reference
465
-
466
- ---
467
-
468
- > **Remember**: Good code isn't about being clever—it's about being clear. Refactoring and patterns are tools to achieve clarity, not ends in themselves.
1
+ ---
2
+ name: expert-code-quality
3
+ description: "Code quality expert integrating refactoring techniques and design patterns for systematic improvement. Call when reviewing code, refactoring, or applying SOLID principles."
4
+ license: "MIT"
5
+ author: "neuqik@hotmail.com"
6
+ version: "2.0"
7
+ ---
8
+
9
+ # Code Quality Expert
10
+
11
+ ## Overview
12
+
13
+ This skill integrates two foundational software engineering disciplines:
14
+ 1. **Refactoring** - Improving code structure without changing behavior
15
+ 2. **Design Patterns** - Proven solutions to common design problems
16
+
17
+ Combined, they form a powerful toolkit for writing clean, maintainable, and extensible code.
18
+
19
+ ## Directory Structure
20
+
21
+ ```
22
+ expert-code-quality/
23
+ ├── SKILL.md # Skill definition file
24
+ ├── LICENSE # MIT License
25
+ └── references/ # Reference documents
26
+ ├── refactoring-catalog.md # Complete catalog of refactoring techniques
27
+ ├── design-patterns.md # 23 GoF patterns
28
+ ├── code-smells.md # Detailed description of code smells
29
+ └── solid-principles.md # In-depth analysis of SOLID principles
30
+ ```
31
+
32
+ ## Trigger Conditions
33
+
34
+ **Automatic Triggers:**
35
+ - User asks about code quality issues
36
+ - Need to identify code smells
37
+ - Request for design pattern recommendations
38
+ - Performing code refactoring
39
+ - Evaluating SOLID principle compliance
40
+
41
+ **Manual Triggers:**
42
+ - User enters commands like `/code-quality`, `/refactor`, `/pattern`, etc.
43
+
44
+ ---
45
+
46
+ ## Core Capabilities
47
+
48
+ ### 1. Code Smell Detection
49
+
50
+ #### 1.1 Quick Reference: 22 Code Smells
51
+
52
+ **Method-Level Smells:**
53
+
54
+ | Smell | Detection Pattern | Severity |
55
+ |-------|------------------|----------|
56
+ | **Long Method** | Method > 20 lines | High |
57
+ | **Duplicated Code** | Similar code blocks | Critical |
58
+ | **Long Parameter List** | Parameters > 4 | Medium |
59
+ | **Switch Statements** | Large switch/case blocks | Medium |
60
+
61
+ **Class-Level Smells:**
62
+
63
+ | Smell | Detection Pattern | Severity |
64
+ |-------|------------------|----------|
65
+ | **Large Class** | Class > 300 lines or > 10 fields | High |
66
+ | **Divergent Change** | One class changes for multiple reasons | High |
67
+ | **Shotgun Surgery** | One change requires modifying many classes | High |
68
+ | **Feature Envy** | Method uses data from other classes more | Medium |
69
+
70
+ **Relationship-Level Smells:**
71
+
72
+ | Smell | Detection Pattern | Severity |
73
+ |-------|------------------|----------|
74
+ | **Inappropriate Intimacy** | Classes access each other's private parts | Medium |
75
+ | **Message Chains** | `a.b().c().d()` chains | Medium |
76
+ | **Middle Man** | Class only does delegation | Low |
77
+ | **Data Clumps** | Same data items always appear together | Medium |
78
+
79
+ #### 1.2 Smell Detection Checklist
80
+
81
+ When reviewing code, check:
82
+ - [ ] Are there methods longer than 20 lines?
83
+ - [ ] Is there duplicated code?
84
+ - [ ] Are there classes with more than 10 fields?
85
+ - [ ] Are there switch statements that could use polymorphism?
86
+ - [ ] Are there methods with more than 4 parameters?
87
+ - [ ] Is there deep inheritance hierarchy (> 3 levels)?
88
+ - [ ] Does the class change for multiple reasons?
89
+ - [ ] Are there message chains with more than 3 calls?
90
+ - [ ] Are there "data classes" with only data and no behavior?
91
+ - [ ] Are there "lazy classes" that do almost nothing?
92
+
93
+ ---
94
+
95
+ ### 2. Refactoring Techniques
96
+
97
+ #### 2.1 Refactoring Principles
98
+
99
+ **Two Hats (Kent Beck):**
100
+
101
+ | Hat | Activity | Rule |
102
+ |-----|----------|------|
103
+ | **Adding Features** | Add new functionality | Don't modify existing code |
104
+ | **Refactoring** | Improve structure | Don't add new features |
105
+
106
+ **Never wear both hats at the same time!**
107
+
108
+ **Refactoring Rhythm:**
109
+ ```
110
+ Test → Small Change → Test → Small Change → Test
111
+ ```
112
+
113
+ #### 2.2 Key Refactoring Techniques
114
+
115
+ **Composing Methods:**
116
+
117
+ | Refactoring | When to Use | Steps |
118
+ |-------------|-------------|-------|
119
+ | **Extract Method** | Method too long, code block needs naming | 1.Create new method 2.Copy code 3.Replace original code with call |
120
+ | **Inline Method** | Method body as clear as its name | 1.Replace calls with method body 2.Delete method |
121
+ | **Replace Temp with Query** | Temporary variable holds expression | 1.Extract expression to method 2.Replace temp with call |
122
+ | **Replace Method with Method Object** | Too many temporaries in long method | 1.Create class for method 2.Temporaries become fields |
123
+
124
+ **Moving Features:**
125
+
126
+ | Refactoring | When to Use | Steps |
127
+ |-------------|-------------|-------|
128
+ | **Move Method** | Method uses other class more | 1.Copy to target 2.Delegate in source 3.Delete source method |
129
+ | **Extract Class** | Class does too much | 1.Create new class 2.Move fields/methods 3.Link classes |
130
+ | **Hide Delegate** | Client knows delegation chain | 1.Add delegate method 2.Hide chain |
131
+
132
+ **Simplifying Conditionals:**
133
+
134
+ | Refactoring | When to Use | Steps |
135
+ |-------------|-------------|-------|
136
+ | **Decompose Conditional** | Complex conditional logic | 1.Extract condition 2.Extract then/else |
137
+ | **Consolidate Conditional** | Multiple checks with same result | 1.Combine with && or \|\| 2.Extract method |
138
+ | **Replace Nested Conditional with Guard Clauses** | Deeply nested if-else | 1.Add guard clause returns 2.Flatten structure |
139
+ | **Replace Conditional with Polymorphism** | Switch by type | 1.Create subclasses 2.Move behavior to each subclass |
140
+
141
+ #### 2.3 Refactoring Decision Tree
142
+
143
+ ```
144
+ Found code smell?
145
+
146
+ ├─ Do you have tests?
147
+ │ ├─ No → Write tests first
148
+ │ └─ Yes → Continue
149
+
150
+ ├─ Do you understand the code?
151
+ │ ├─ No → Refactor to understand
152
+ │ └─ Yes → Continue
153
+
154
+ └─ Choose refactoring approach:
155
+
156
+ ├─ Method too long → Extract Method
157
+ ├─ Duplicated code → Extract Method / Pull Up
158
+ ├─ Class too large → Extract Class
159
+ ├─ Parameter list too long → Introduce Parameter Object
160
+ ├─ Switch statement → Replace with Polymorphism
161
+ └─ Complex conditionals → Decompose / Guard Clauses
162
+ ```
163
+
164
+ ---
165
+
166
+ ### 3. Design Patterns
167
+
168
+ #### 3.1 SOLID Principles Foundation
169
+
170
+ Before applying patterns, ensure understanding of SOLID principles:
171
+
172
+ | Principle | Name | Description |
173
+ |-----------|------|-------------|
174
+ | **S** | Single Responsibility | One reason to change |
175
+ | **O** | Open/Closed | Open for extension, closed for modification |
176
+ | **L** | Liskov Substitution | Subtypes must be substitutable |
177
+ | **I** | Interface Segregation | Small, focused interfaces |
178
+ | **D** | Dependency Inversion | Depend on abstractions |
179
+
180
+ #### 3.2 Selection by Problem Type
181
+
182
+ | Problem | Pattern | Key Benefit |
183
+ |---------|---------|-------------|
184
+ | Need single instance | Singleton | Controlled access |
185
+ | Flexible object creation | Factory Method | Decouple creation |
186
+ | Create families of objects | Abstract Factory | Consistent products |
187
+ | Build complex objects | Builder | Step-by-step construction |
188
+ | Incompatible interfaces | Adapter | Make incompatible work |
189
+ | Dynamically add responsibilities | Decorator | Flexible extension |
190
+ | Control access | Proxy | Indirection layer |
191
+ | Simplify complex system | Facade | Simple interface |
192
+ | Tree structure | Composite | Uniform handling |
193
+ | Switch algorithms | Strategy | Interchangeable behaviors |
194
+ | Event notification | Observer | Loose coupling |
195
+ | Encapsulate requests | Command | Undo/redo support |
196
+ | State-dependent behavior | State | Clear state transitions |
197
+
198
+ #### 3.3 Selection by Code Smell
199
+
200
+ | Smell | Pattern Solution |
201
+ |-------|------------------|
202
+ | Large switch statement | State, Strategy |
203
+ | Multiple conditionals | Strategy, State, Null Object |
204
+ | Tight coupling | Observer, Mediator, Facade |
205
+ | Difficult object creation | Factory, Builder |
206
+ | Hard to extend class | Decorator, Adapter |
207
+ | Complex subsystem | Facade |
208
+ | Need varying algorithms | Strategy, Template Method |
209
+
210
+ #### 3.4 Pattern Quick Reference
211
+
212
+ **Creational Patterns:**
213
+
214
+ | Pattern | When to Use |
215
+ |---------|-------------|
216
+ | Singleton | Need single instance |
217
+ | Factory Method | Don't know exact class to create |
218
+ | Abstract Factory | Need families of related objects |
219
+ | Builder | Complex object with many options |
220
+ | Prototype | Clone existing objects |
221
+
222
+ **Structural Patterns:**
223
+
224
+ | Pattern | When to Use |
225
+ |---------|-------------|
226
+ | Adapter | Incompatible interfaces |
227
+ | Decorator | Dynamically add responsibilities |
228
+ | Proxy | Control access, lazy loading |
229
+ | Facade | Simplify complex interfaces |
230
+ | Composite | Tree structure, uniform handling |
231
+ | Flyweight | Many similar objects, share state |
232
+ | Bridge | Separate abstraction from implementation |
233
+
234
+ **Behavioral Patterns:**
235
+
236
+ | Pattern | When to Use |
237
+ |---------|-------------|
238
+ | Strategy | Interchangeable algorithms |
239
+ | Observer | One-to-many notifications |
240
+ | Command | Encapsulate requests, undo/redo |
241
+ | State | State-dependent behavior |
242
+ | Template Method | Algorithm skeleton, varying steps |
243
+ | Iterator | Uniform collection traversal |
244
+ | Mediator | Complex object interactions |
245
+ | Memento | Save/restore state |
246
+ | Chain of Resp. | Request has multiple handlers |
247
+ | Visitor | Add operations to object structure |
248
+
249
+ ---
250
+
251
+ ### 4. Integrated Workflow
252
+
253
+ #### 4.1 Code Quality Improvement Process
254
+
255
+ ```
256
+ 1. IDENTIFY
257
+ └── Detect code smells
258
+ └── Use smell checklist
259
+ └── Rate severity (Critical/High/Medium/Low)
260
+
261
+ 2. DIAGNOSE
262
+ └── Understand root cause
263
+ └── Why does this smell exist?
264
+ └── What problems will it cause?
265
+
266
+ 3. PLAN
267
+ └── Choose refactoring or pattern
268
+ └── Consider dependencies
269
+ └── Estimate impact
270
+
271
+ 4. PREPARE
272
+ └── Ensure tests exist
273
+ └── Run tests to verify behavior
274
+ └── Create tests if missing
275
+
276
+ 5. EXECUTE
277
+ └── Apply small changes
278
+ └── Test after each change
279
+ └── Keep code working
280
+
281
+ 6. VERIFY
282
+ └── Run all tests
283
+ └── Check for new smells
284
+ └── Confirm improvement
285
+ ```
286
+
287
+ #### 4.2 Smell→Refactoring→Pattern Flow
288
+
289
+ ```
290
+ Detected code smell
291
+
292
+
293
+ ┌───────────────────┐
294
+ │ Is this a method │
295
+ │ level problem? │
296
+ └────────┬──────────┘
297
+
298
+ ┌────┴────┐
299
+ │ Yes │ No
300
+ ▼ ▼
301
+ Extract Is this a class
302
+ Method level problem?
303
+
304
+ ┌────┴────┐
305
+ │ Yes │ No
306
+ ▼ ▼
307
+ Extract Is this a
308
+ Class relationship
309
+ problem?
310
+
311
+ ┌────┴────┐
312
+ │ Yes │ No
313
+ ▼ ▼
314
+ Move/Hide Consider
315
+ Delegate Pattern
316
+
317
+
318
+ ┌──────────────┐
319
+ │ Which │
320
+ │ pattern fits │
321
+ │ best? │
322
+ └──────┬───────┘
323
+
324
+ ┌───────────────┼───────────────┐
325
+ ▼ ▼ ▼
326
+ Creational Structural Behavioral
327
+ Patterns Patterns Patterns
328
+ ```
329
+
330
+ ---
331
+
332
+ ### 5. Collaboration Table
333
+
334
+ #### 5.1 Collaboration with Other Skills
335
+
336
+ | Collaborating Skill | Collaboration Mode | Description |
337
+ |--------------------|-------------------|-------------|
338
+ | **test-driven-development** | Sequential | Write tests before refactoring |
339
+ | **systematic-debugging** | Consultation | Find root cause before fixing |
340
+ | **requesting-code-review** | Reference | Get feedback on refactored code |
341
+ | **pdd-code-reviewer** | Reference | Get PDD project code review |
342
+ | **software-engineer** | Delegation | Quality check after code implementation |
343
+
344
+ #### 5.2 Collaboration Workflow
345
+
346
+ ```
347
+ Code quality issue detected
348
+
349
+ Invoke expert-code-quality
350
+
351
+ Identify code smells + Recommend refactoring/patterns
352
+
353
+ (If tests needed first) → Invoke test-driven-development
354
+
355
+ (If code implementation needed) → Invoke software-engineer
356
+
357
+ Complete code quality improvement
358
+ ```
359
+
360
+ ---
361
+
362
+ ### 6. Quick Decision Matrix
363
+
364
+ | Scenario | Primary Action |
365
+ |----------|---------------|
366
+ | Found duplicated code | Extract Method |
367
+ | Method too long | Extract Method |
368
+ | Class too large | Extract Class |
369
+ | Parameter list too long | Introduce Parameter Object |
370
+ | Switch by type | Replace with Polymorphism |
371
+ | Need single instance | Consider Singleton |
372
+ | Need flexible creation | Factory Method or Builder |
373
+ | Incompatible interfaces | Adapter |
374
+ | Need to add behavior | Decorator |
375
+ | Complex subsystem | Facade |
376
+ | Need varying algorithms | Strategy |
377
+ | Need event notification | Observer |
378
+
379
+ ---
380
+
381
+ ### 7. Anti-Patterns
382
+
383
+ #### 7.1 Refactoring Anti-Patterns
384
+
385
+ | Anti-Pattern | Description | Correct Approach |
386
+ |--------------|-------------|------------------|
387
+ | **Big Bang Refactoring** | Rewrite everything at once | Small incremental changes |
388
+ | **Refactoring Without Tests** | Change code without safety net | Write tests first |
389
+ | **Over-Refactoring** | Refactor clean code | Stop when code is clear |
390
+ | **Refactoring Addiction** | Only refactor, never deliver | Balance refactoring with features |
391
+ | **Random Refactoring** | No clear goal | Identify smells first |
392
+
393
+ #### 7.2 Pattern Anti-Patterns
394
+
395
+ | Anti-Pattern | Description | Correct Approach |
396
+ |--------------|-------------|------------------|
397
+ | **Pattern Obsession** | Use patterns everywhere | Use patterns to solve problems |
398
+ | **Singleton Abuse** | Everything is singleton | Use only when truly needed |
399
+ | **Factory Overkill** | Factory for single product | Use factory for multiple products |
400
+ | **Decorator Nesting** | Too many decorator layers | Limit nesting depth |
401
+ | **Premature Pattern** | Use pattern before needed | Let patterns emerge from refactoring |
402
+
403
+ ---
404
+
405
+ ### 8. Practice Checklists
406
+
407
+ #### 8.1 Code Review Checklist
408
+
409
+ Before approving code, verify:
410
+ - [ ] No critical code smells
411
+ - [ ] Reasonable method size (< 20 lines)
412
+ - [ ] Class has single responsibility
413
+ - [ ] No duplicated code
414
+ - [ ] Clear conditionals
415
+ - [ ] Meaningful names
416
+ - [ ] Tests exist and pass
417
+ - [ ] Follows SOLID principles
418
+ - [ ] Patterns used appropriately (not overused)
419
+
420
+ #### 8.2 Refactoring Safety Checklist
421
+
422
+ Before refactoring:
423
+ - [ ] All tests pass
424
+ - [ ] Tests cover code to refactor
425
+ - [ ] Understand code functionality
426
+ - [ ] Have rollback plan
427
+ - [ ] Make small changes
428
+ - [ ] Test after each change
429
+
430
+ #### 8.3 Pattern Application Checklist
431
+
432
+ Before applying pattern:
433
+ - [ ] Problem matches pattern intent
434
+ - [ ] Pattern solves real problem (not imagined)
435
+ - [ ] Team understands pattern
436
+ - [ ] Pattern doesn't overcomplicate
437
+ - [ ] Alternatives considered
438
+ - [ ] Pattern fits project context
439
+
440
+ ---
441
+
442
+ ## Guardrails
443
+
444
+ - Must provide suggestions based on Martin Fowler's refactoring catalog and GoF design patterns
445
+ - Refactoring suggestions need specific code transformation examples
446
+ - Pattern application needs to weigh pros and cons, not blindly recommend
447
+ - Code review needs to specifically point out problems and improvement suggestions
448
+ - Clearly state uncertain issues to avoid misleading
449
+
450
+ ---
451
+
452
+ ## Version History
453
+
454
+ ### v2.0 (2026-03-21)
455
+ - Unified to Chinese description
456
+ - Added collaboration table, clarified collaboration with other skills
457
+ - Enhanced quick decision matrix
458
+ - Optimized refactoring decision tree
459
+ - Added anti-pattern checklist
460
+
461
+ ### v1.0 (Initial version)
462
+ - Basic code quality detection
463
+ - Refactoring technique catalog
464
+ - Design pattern reference
465
+
466
+ ---
467
+
468
+ > **Remember**: Good code isn't about being clever—it's about being clear. Refactoring and patterns are tools to achieve clarity, not ends in themselves.