pdd-skills 3.1.13 → 3.2.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/LICENSE +21 -21
- package/package.json +1 -1
- package/scaffolds/python-fullstack/.github/workflows/ci.yml +1 -1
- package/scaffolds/python-fullstack/Dockerfile +1 -1
- package/scaffolds/python-fullstack/docker-compose.yml +1 -1
- package/scaffolds/python-fullstack/frontend/Dockerfile +1 -1
- package/scaffolds/python-fullstack/frontend/nginx.conf +1 -1
- package/scaffolds/python-fullstack/frontend/postcss.config.js +1 -1
- package/scaffolds/python-fullstack/frontend/src/api/client.ts +1 -1
- package/scaffolds/python-fullstack/frontend/src/composables/useResponsive.ts +1 -1
- package/scaffolds/python-fullstack/frontend/src/router/index.ts +1 -1
- package/scaffolds/python-fullstack/frontend/src/stores/user.ts +1 -1
- package/scaffolds/python-fullstack/frontend/src/styles/responsive.css +1 -1
- package/scaffolds/python-fullstack/frontend/src/styles/variables.css +1 -1
- package/scaffolds/python-fullstack/frontend/src/views/DashboardView.vue +1 -1
- package/scaffolds/python-fullstack/frontend/src/views/HomeView.vue +1 -1
- package/scaffolds/python-fullstack/frontend/src/views/LoginView.vue +1 -1
- package/scaffolds/python-fullstack/frontend/tailwind.config.js +1 -1
- package/skills/core/official-doc-writer/README.md +232 -232
- package/skills/core/official-doc-writer/fonts/FONTS_LIST.md +44 -44
- 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
- package/skills/core/pdd-main/evals/evals.json +215 -215
- package/skills/entropy/expert-arch-enforcer/SKILL.md +292 -292
- package/skills/entropy/expert-auto-refactor/SKILL.md +327 -327
- package/skills/entropy/expert-code-quality/SKILL.md +468 -468
- package/skills/entropy/expert-entropy-auditor/SKILL.md +276 -276
- package/skills/expert/expert-activiti/SKILL.md +497 -497
- package/skills/expert/expert-mysql/SKILL.md +832 -832
- package/skills/expert/expert-ruoyi/SKILL.md +674 -674
- package/skills/expert/testcase-agent/SKILL.md +10 -0
- package/skills/expert/testcase-modeler/SKILL.md +45 -2
- package/skills/pr/pdd-multi-review/SKILL.md +534 -534
- package/skills/pr/pdd-pr-batch/SKILL.md +303 -303
- package/skills/pr/pdd-pr-create/SKILL.md +344 -344
- package/skills/pr/pdd-pr-merge/SKILL.md +286 -286
- package/skills/pr/pdd-pr-review/SKILL.md +217 -217
- package/skills/pr/pdd-task-manager/SKILL.md +636 -636
- package/skills/pr/pdd-template-engine/SKILL.md +386 -386
- package/tests/login_manager.py +5 -30
- package/tests/recorder.py +362 -294
- package/tests/testcase-ai.py +1184 -11
|
@@ -1,327 +1,327 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: expert-auto-refactor
|
|
3
|
-
description: Automated refactoring expert transforming quality improvements into concrete code operations. Call when eliminating duplication or simplifying complexity systematically. 支持中文触发:重构代码、消除重复、简化代码。
|
|
4
|
-
|
|
5
|
-
Core responsibility: Initiate targeted refactoring PRs regularly in a "small debt repayment" manner to prevent technical debt accumulation.
|
|
6
|
-
|
|
7
|
-
Trigger scenarios:
|
|
8
|
-
- User requests "refactor code", "eliminate duplicates", "simplify code"
|
|
9
|
-
- Called by pdd-entropy-reduction coordinator
|
|
10
|
-
- Refactoring suggestions passed from expert-entropy-auditor
|
|
11
|
-
|
|
12
|
-
支持中文触发:自动重构、代码重构、消除重复、简化代码、重构专家、PDD重构。
|
|
13
|
-
author: neuqik@hotmail.com
|
|
14
|
-
license: MIT
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
# Automated Refactoring Expert (expert-auto-refactor)
|
|
18
|
-
|
|
19
|
-
## Core Philosophy
|
|
20
|
-
|
|
21
|
-
> "Initiate targeted refactoring PRs regularly in a 'small debt repayment' manner to prevent technical debt from accumulating into unmanageable 'painful interest'." —— Harness Engineering
|
|
22
|
-
|
|
23
|
-
The automated refactoring expert is an upgraded version of `expert-code-quality`, not just recording issues but actively executing refactoring operations.
|
|
24
|
-
|
|
25
|
-
## Refactoring Types
|
|
26
|
-
|
|
27
|
-
### 1. Extract Common Methods
|
|
28
|
-
|
|
29
|
-
**Scenario**: Similar code logic in multiple places
|
|
30
|
-
|
|
31
|
-
**Refactoring Method**:
|
|
32
|
-
1. Identify similar code
|
|
33
|
-
2. Extract common methods
|
|
34
|
-
3. Replace original calls
|
|
35
|
-
|
|
36
|
-
**Example**:
|
|
37
|
-
|
|
38
|
-
Before refactoring:
|
|
39
|
-
```javascript
|
|
40
|
-
// File A
|
|
41
|
-
function formatDate(date) {
|
|
42
|
-
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// File B
|
|
46
|
-
function formatDateString(d) {
|
|
47
|
-
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
After refactoring:
|
|
52
|
-
```javascript
|
|
53
|
-
// utils/dateUtils.ts
|
|
54
|
-
export function formatDate(date: Date): string {
|
|
55
|
-
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// File A
|
|
59
|
-
import { formatDate } from '../utils/dateUtils';
|
|
60
|
-
|
|
61
|
-
// File B
|
|
62
|
-
import { formatDate } from '../utils/dateUtils';
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 2. Eliminate Duplicate Code
|
|
66
|
-
|
|
67
|
-
**Scenario**: Identical or highly similar code blocks
|
|
68
|
-
|
|
69
|
-
**Refactoring Method**:
|
|
70
|
-
1. Detect duplicate code
|
|
71
|
-
2. Extract to shared module
|
|
72
|
-
3. Update references
|
|
73
|
-
|
|
74
|
-
**Example**:
|
|
75
|
-
|
|
76
|
-
Before refactoring:
|
|
77
|
-
```javascript
|
|
78
|
-
// Repeated validation logic in multiple places
|
|
79
|
-
if (!user.email || !user.email.includes('@')) {
|
|
80
|
-
throw new Error('Invalid email');
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
After refactoring:
|
|
85
|
-
```javascript
|
|
86
|
-
// utils/validators.ts
|
|
87
|
-
export function validateEmail(email: string): boolean {
|
|
88
|
-
return email && email.includes('@');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Usage
|
|
92
|
-
if (!validateEmail(user.email)) {
|
|
93
|
-
throw new Error('Invalid email');
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### 3. Simplify Complex Logic
|
|
98
|
-
|
|
99
|
-
**Scenario**: Functions that are too long, deeply nested, or have complex logic
|
|
100
|
-
|
|
101
|
-
**Refactoring Method**:
|
|
102
|
-
1. Split long functions
|
|
103
|
-
2. Extract sub-functions
|
|
104
|
-
3. Simplify conditional logic
|
|
105
|
-
|
|
106
|
-
**Example**:
|
|
107
|
-
|
|
108
|
-
Before refactoring:
|
|
109
|
-
```javascript
|
|
110
|
-
function processOrder(order) {
|
|
111
|
-
if (order.status === 'pending') {
|
|
112
|
-
if (order.items.length > 0) {
|
|
113
|
-
if (order.payment) {
|
|
114
|
-
// Processing logic...
|
|
115
|
-
if (order.shipping) {
|
|
116
|
-
// More processing...
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
After refactoring:
|
|
125
|
-
```javascript
|
|
126
|
-
function processOrder(order) {
|
|
127
|
-
if (!canProcessOrder(order)) return;
|
|
128
|
-
|
|
129
|
-
processPayment(order);
|
|
130
|
-
processShipping(order);
|
|
131
|
-
updateOrderStatus(order);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function canProcessOrder(order) {
|
|
135
|
-
return order.status === 'pending'
|
|
136
|
-
&& order.items.length > 0
|
|
137
|
-
&& order.payment;
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### 4. Optimize Naming
|
|
142
|
-
|
|
143
|
-
**Scenario**: Non-standard naming, unclear meaning
|
|
144
|
-
|
|
145
|
-
**Refactoring Method**:
|
|
146
|
-
1. Analyze naming context
|
|
147
|
-
2. Generate better naming
|
|
148
|
-
3. Batch replacement
|
|
149
|
-
|
|
150
|
-
**Example**:
|
|
151
|
-
|
|
152
|
-
Before refactoring:
|
|
153
|
-
```javascript
|
|
154
|
-
function calc(a, b) {
|
|
155
|
-
return a * b * 0.1;
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
After refactoring:
|
|
160
|
-
```javascript
|
|
161
|
-
function calculateTax(basePrice: number, quantity: number): number {
|
|
162
|
-
const TAX_RATE = 0.1;
|
|
163
|
-
return basePrice * quantity * TAX_RATE;
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
## Refactoring Process
|
|
170
|
-
|
|
171
|
-
```
|
|
172
|
-
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
173
|
-
│ Analyze │ ──→ │ Plan │ ──→ │ Execute │ ──→ │ Verify │
|
|
174
|
-
│ │ │ │ │ │ │ │
|
|
175
|
-
│ • Code │ │ • Refactor │ │ • Code │ │ • Test │
|
|
176
|
-
│ structure │ │ strategy │ │ changes │ │ execution │
|
|
177
|
-
│ • │ │ • Impact │ │ • Reference │ │ • Function │
|
|
178
|
-
│ Dependencies│ │ scope │ │ updates │ │ validation│
|
|
179
|
-
│ • Test │ │ • Risk │ │ • Document │ │ • PR │
|
|
180
|
-
│ coverage │ │ assessment│ │ sync │ │ creation │
|
|
181
|
-
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## Refactoring Strategy
|
|
187
|
-
|
|
188
|
-
### Small Debt Repayment Principle
|
|
189
|
-
|
|
190
|
-
Each refactoring should:
|
|
191
|
-
1. **Small steps**: Only change a small part each time
|
|
192
|
-
2. **Maintain tests**: Ensure tests always pass
|
|
193
|
-
3. **Frequent commits**: Commit after each small step
|
|
194
|
-
4. **Rollback capable**: Keep each commit independently rollbackable
|
|
195
|
-
|
|
196
|
-
### Risk Assessment
|
|
197
|
-
|
|
198
|
-
| Risk Level | Condition | Strategy |
|
|
199
|
-
|---------|------|------|
|
|
200
|
-
| Low | Complete test coverage | Auto execute |
|
|
201
|
-
| Medium | Partial test coverage | Create PR |
|
|
202
|
-
| High | No test coverage | Add tests first then refactor |
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
## Output Format
|
|
207
|
-
|
|
208
|
-
### Refactoring Report
|
|
209
|
-
|
|
210
|
-
```markdown
|
|
211
|
-
# Refactoring Report - YYYY-MM-DD
|
|
212
|
-
|
|
213
|
-
## Refactoring Scope
|
|
214
|
-
- Target files: X
|
|
215
|
-
- Affected files: X
|
|
216
|
-
- Test coverage: X%
|
|
217
|
-
|
|
218
|
-
## Refactoring Operations
|
|
219
|
-
|
|
220
|
-
### Extract Common Methods
|
|
221
|
-
| Original File | New File | Method Name | Status |
|
|
222
|
-
|-------|-------|-------|------|
|
|
223
|
-
| utils/formatDate.js | utils/dateUtils.ts | formatDate | ✅ Completed |
|
|
224
|
-
|
|
225
|
-
### Eliminate Duplicate Code
|
|
226
|
-
| File A | File B | Duplicate Lines | Status |
|
|
227
|
-
|-------|-------|---------|------|
|
|
228
|
-
| service/UserService.ts | service/OrderService.ts | 25 lines | ✅ Completed |
|
|
229
|
-
|
|
230
|
-
### Simplify Complex Logic
|
|
231
|
-
| File | Function Name | Original Lines | New Lines | Status |
|
|
232
|
-
|------|-------|-------|-------|------|
|
|
233
|
-
| service/OrderService.ts | processOrder | 80 | 35 | ✅ Completed |
|
|
234
|
-
|
|
235
|
-
## Verification Results
|
|
236
|
-
- Unit tests: ✅ All passed
|
|
237
|
-
- Integration tests: ✅ All passed
|
|
238
|
-
- Functional verification: ✅ No anomalies
|
|
239
|
-
|
|
240
|
-
## PR Information
|
|
241
|
-
- PR number: #XXX
|
|
242
|
-
- Branch: refactor/entropy-reduction-YYYYMMDD
|
|
243
|
-
- Status: Pending review
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## Configuration Options
|
|
249
|
-
|
|
250
|
-
```yaml
|
|
251
|
-
# auto-refactor-config.yaml
|
|
252
|
-
auto_refactor:
|
|
253
|
-
# Refactoring scope
|
|
254
|
-
scope:
|
|
255
|
-
code_paths: ["src/"]
|
|
256
|
-
exclude: ["node_modules/", "dist/", "build/"]
|
|
257
|
-
|
|
258
|
-
# Refactoring rules
|
|
259
|
-
rules:
|
|
260
|
-
max_file_lines: 300
|
|
261
|
-
max_function_lines: 50
|
|
262
|
-
min_similarity: 0.8
|
|
263
|
-
|
|
264
|
-
# Execution strategy
|
|
265
|
-
execution:
|
|
266
|
-
auto_fix_low_risk: true # Auto fix low risk
|
|
267
|
-
create_pr: true # Create PR
|
|
268
|
-
max_changes_per_run: 10 # Max changes per run
|
|
269
|
-
|
|
270
|
-
# Testing requirements
|
|
271
|
-
testing:
|
|
272
|
-
require_tests: true # Require tests
|
|
273
|
-
min_coverage: 80 # Minimum coverage
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
278
|
-
## Usage Examples
|
|
279
|
-
|
|
280
|
-
### Example 1: Extract Duplicate Code
|
|
281
|
-
|
|
282
|
-
```
|
|
283
|
-
User: Eliminate duplicates in code
|
|
284
|
-
|
|
285
|
-
AI:
|
|
286
|
-
1. Detect duplicate code
|
|
287
|
-
2. Analyze similarity
|
|
288
|
-
3. Extract to shared module
|
|
289
|
-
4. Update all references
|
|
290
|
-
5. Create PR
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Example 2: Simplify Complex Function
|
|
294
|
-
|
|
295
|
-
```
|
|
296
|
-
User: Simplify processOrder function
|
|
297
|
-
|
|
298
|
-
AI:
|
|
299
|
-
1. Analyze function structure
|
|
300
|
-
2. Identify extractable sub-functions
|
|
301
|
-
3. Execute split refactoring
|
|
302
|
-
4. Run test verification
|
|
303
|
-
5. Create PR
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
### Example 3: Optimize Naming
|
|
307
|
-
|
|
308
|
-
```
|
|
309
|
-
User: Optimize code naming
|
|
310
|
-
|
|
311
|
-
AI:
|
|
312
|
-
1. Scan non-standard naming
|
|
313
|
-
2. Analyze context
|
|
314
|
-
3. Generate better naming
|
|
315
|
-
4. Batch replacement
|
|
316
|
-
5. Create PR
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
## Collaboration with Other Skills
|
|
322
|
-
|
|
323
|
-
- **pdd-entropy-reduction**: Called as a sub-skill by the coordinator
|
|
324
|
-
- **expert-entropy-auditor**: Receive refactoring suggestions
|
|
325
|
-
- **expert-arch-enforcer**: Receive architecture violation fixes
|
|
326
|
-
- **pdd-code-reviewer**: Trigger code review after refactoring
|
|
327
|
-
- **pdd-doc-change**: Synchronously update related documentation
|
|
1
|
+
---
|
|
2
|
+
name: expert-auto-refactor
|
|
3
|
+
description: Automated refactoring expert transforming quality improvements into concrete code operations. Call when eliminating duplication or simplifying complexity systematically. 支持中文触发:重构代码、消除重复、简化代码。
|
|
4
|
+
|
|
5
|
+
Core responsibility: Initiate targeted refactoring PRs regularly in a "small debt repayment" manner to prevent technical debt accumulation.
|
|
6
|
+
|
|
7
|
+
Trigger scenarios:
|
|
8
|
+
- User requests "refactor code", "eliminate duplicates", "simplify code"
|
|
9
|
+
- Called by pdd-entropy-reduction coordinator
|
|
10
|
+
- Refactoring suggestions passed from expert-entropy-auditor
|
|
11
|
+
|
|
12
|
+
支持中文触发:自动重构、代码重构、消除重复、简化代码、重构专家、PDD重构。
|
|
13
|
+
author: neuqik@hotmail.com
|
|
14
|
+
license: MIT
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Automated Refactoring Expert (expert-auto-refactor)
|
|
18
|
+
|
|
19
|
+
## Core Philosophy
|
|
20
|
+
|
|
21
|
+
> "Initiate targeted refactoring PRs regularly in a 'small debt repayment' manner to prevent technical debt from accumulating into unmanageable 'painful interest'." —— Harness Engineering
|
|
22
|
+
|
|
23
|
+
The automated refactoring expert is an upgraded version of `expert-code-quality`, not just recording issues but actively executing refactoring operations.
|
|
24
|
+
|
|
25
|
+
## Refactoring Types
|
|
26
|
+
|
|
27
|
+
### 1. Extract Common Methods
|
|
28
|
+
|
|
29
|
+
**Scenario**: Similar code logic in multiple places
|
|
30
|
+
|
|
31
|
+
**Refactoring Method**:
|
|
32
|
+
1. Identify similar code
|
|
33
|
+
2. Extract common methods
|
|
34
|
+
3. Replace original calls
|
|
35
|
+
|
|
36
|
+
**Example**:
|
|
37
|
+
|
|
38
|
+
Before refactoring:
|
|
39
|
+
```javascript
|
|
40
|
+
// File A
|
|
41
|
+
function formatDate(date) {
|
|
42
|
+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// File B
|
|
46
|
+
function formatDateString(d) {
|
|
47
|
+
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
After refactoring:
|
|
52
|
+
```javascript
|
|
53
|
+
// utils/dateUtils.ts
|
|
54
|
+
export function formatDate(date: Date): string {
|
|
55
|
+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// File A
|
|
59
|
+
import { formatDate } from '../utils/dateUtils';
|
|
60
|
+
|
|
61
|
+
// File B
|
|
62
|
+
import { formatDate } from '../utils/dateUtils';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2. Eliminate Duplicate Code
|
|
66
|
+
|
|
67
|
+
**Scenario**: Identical or highly similar code blocks
|
|
68
|
+
|
|
69
|
+
**Refactoring Method**:
|
|
70
|
+
1. Detect duplicate code
|
|
71
|
+
2. Extract to shared module
|
|
72
|
+
3. Update references
|
|
73
|
+
|
|
74
|
+
**Example**:
|
|
75
|
+
|
|
76
|
+
Before refactoring:
|
|
77
|
+
```javascript
|
|
78
|
+
// Repeated validation logic in multiple places
|
|
79
|
+
if (!user.email || !user.email.includes('@')) {
|
|
80
|
+
throw new Error('Invalid email');
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
After refactoring:
|
|
85
|
+
```javascript
|
|
86
|
+
// utils/validators.ts
|
|
87
|
+
export function validateEmail(email: string): boolean {
|
|
88
|
+
return email && email.includes('@');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Usage
|
|
92
|
+
if (!validateEmail(user.email)) {
|
|
93
|
+
throw new Error('Invalid email');
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 3. Simplify Complex Logic
|
|
98
|
+
|
|
99
|
+
**Scenario**: Functions that are too long, deeply nested, or have complex logic
|
|
100
|
+
|
|
101
|
+
**Refactoring Method**:
|
|
102
|
+
1. Split long functions
|
|
103
|
+
2. Extract sub-functions
|
|
104
|
+
3. Simplify conditional logic
|
|
105
|
+
|
|
106
|
+
**Example**:
|
|
107
|
+
|
|
108
|
+
Before refactoring:
|
|
109
|
+
```javascript
|
|
110
|
+
function processOrder(order) {
|
|
111
|
+
if (order.status === 'pending') {
|
|
112
|
+
if (order.items.length > 0) {
|
|
113
|
+
if (order.payment) {
|
|
114
|
+
// Processing logic...
|
|
115
|
+
if (order.shipping) {
|
|
116
|
+
// More processing...
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
After refactoring:
|
|
125
|
+
```javascript
|
|
126
|
+
function processOrder(order) {
|
|
127
|
+
if (!canProcessOrder(order)) return;
|
|
128
|
+
|
|
129
|
+
processPayment(order);
|
|
130
|
+
processShipping(order);
|
|
131
|
+
updateOrderStatus(order);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function canProcessOrder(order) {
|
|
135
|
+
return order.status === 'pending'
|
|
136
|
+
&& order.items.length > 0
|
|
137
|
+
&& order.payment;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 4. Optimize Naming
|
|
142
|
+
|
|
143
|
+
**Scenario**: Non-standard naming, unclear meaning
|
|
144
|
+
|
|
145
|
+
**Refactoring Method**:
|
|
146
|
+
1. Analyze naming context
|
|
147
|
+
2. Generate better naming
|
|
148
|
+
3. Batch replacement
|
|
149
|
+
|
|
150
|
+
**Example**:
|
|
151
|
+
|
|
152
|
+
Before refactoring:
|
|
153
|
+
```javascript
|
|
154
|
+
function calc(a, b) {
|
|
155
|
+
return a * b * 0.1;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
After refactoring:
|
|
160
|
+
```javascript
|
|
161
|
+
function calculateTax(basePrice: number, quantity: number): number {
|
|
162
|
+
const TAX_RATE = 0.1;
|
|
163
|
+
return basePrice * quantity * TAX_RATE;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Refactoring Process
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
173
|
+
│ Analyze │ ──→ │ Plan │ ──→ │ Execute │ ──→ │ Verify │
|
|
174
|
+
│ │ │ │ │ │ │ │
|
|
175
|
+
│ • Code │ │ • Refactor │ │ • Code │ │ • Test │
|
|
176
|
+
│ structure │ │ strategy │ │ changes │ │ execution │
|
|
177
|
+
│ • │ │ • Impact │ │ • Reference │ │ • Function │
|
|
178
|
+
│ Dependencies│ │ scope │ │ updates │ │ validation│
|
|
179
|
+
│ • Test │ │ • Risk │ │ • Document │ │ • PR │
|
|
180
|
+
│ coverage │ │ assessment│ │ sync │ │ creation │
|
|
181
|
+
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Refactoring Strategy
|
|
187
|
+
|
|
188
|
+
### Small Debt Repayment Principle
|
|
189
|
+
|
|
190
|
+
Each refactoring should:
|
|
191
|
+
1. **Small steps**: Only change a small part each time
|
|
192
|
+
2. **Maintain tests**: Ensure tests always pass
|
|
193
|
+
3. **Frequent commits**: Commit after each small step
|
|
194
|
+
4. **Rollback capable**: Keep each commit independently rollbackable
|
|
195
|
+
|
|
196
|
+
### Risk Assessment
|
|
197
|
+
|
|
198
|
+
| Risk Level | Condition | Strategy |
|
|
199
|
+
|---------|------|------|
|
|
200
|
+
| Low | Complete test coverage | Auto execute |
|
|
201
|
+
| Medium | Partial test coverage | Create PR |
|
|
202
|
+
| High | No test coverage | Add tests first then refactor |
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Output Format
|
|
207
|
+
|
|
208
|
+
### Refactoring Report
|
|
209
|
+
|
|
210
|
+
```markdown
|
|
211
|
+
# Refactoring Report - YYYY-MM-DD
|
|
212
|
+
|
|
213
|
+
## Refactoring Scope
|
|
214
|
+
- Target files: X
|
|
215
|
+
- Affected files: X
|
|
216
|
+
- Test coverage: X%
|
|
217
|
+
|
|
218
|
+
## Refactoring Operations
|
|
219
|
+
|
|
220
|
+
### Extract Common Methods
|
|
221
|
+
| Original File | New File | Method Name | Status |
|
|
222
|
+
|-------|-------|-------|------|
|
|
223
|
+
| utils/formatDate.js | utils/dateUtils.ts | formatDate | ✅ Completed |
|
|
224
|
+
|
|
225
|
+
### Eliminate Duplicate Code
|
|
226
|
+
| File A | File B | Duplicate Lines | Status |
|
|
227
|
+
|-------|-------|---------|------|
|
|
228
|
+
| service/UserService.ts | service/OrderService.ts | 25 lines | ✅ Completed |
|
|
229
|
+
|
|
230
|
+
### Simplify Complex Logic
|
|
231
|
+
| File | Function Name | Original Lines | New Lines | Status |
|
|
232
|
+
|------|-------|-------|-------|------|
|
|
233
|
+
| service/OrderService.ts | processOrder | 80 | 35 | ✅ Completed |
|
|
234
|
+
|
|
235
|
+
## Verification Results
|
|
236
|
+
- Unit tests: ✅ All passed
|
|
237
|
+
- Integration tests: ✅ All passed
|
|
238
|
+
- Functional verification: ✅ No anomalies
|
|
239
|
+
|
|
240
|
+
## PR Information
|
|
241
|
+
- PR number: #XXX
|
|
242
|
+
- Branch: refactor/entropy-reduction-YYYYMMDD
|
|
243
|
+
- Status: Pending review
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Configuration Options
|
|
249
|
+
|
|
250
|
+
```yaml
|
|
251
|
+
# auto-refactor-config.yaml
|
|
252
|
+
auto_refactor:
|
|
253
|
+
# Refactoring scope
|
|
254
|
+
scope:
|
|
255
|
+
code_paths: ["src/"]
|
|
256
|
+
exclude: ["node_modules/", "dist/", "build/"]
|
|
257
|
+
|
|
258
|
+
# Refactoring rules
|
|
259
|
+
rules:
|
|
260
|
+
max_file_lines: 300
|
|
261
|
+
max_function_lines: 50
|
|
262
|
+
min_similarity: 0.8
|
|
263
|
+
|
|
264
|
+
# Execution strategy
|
|
265
|
+
execution:
|
|
266
|
+
auto_fix_low_risk: true # Auto fix low risk
|
|
267
|
+
create_pr: true # Create PR
|
|
268
|
+
max_changes_per_run: 10 # Max changes per run
|
|
269
|
+
|
|
270
|
+
# Testing requirements
|
|
271
|
+
testing:
|
|
272
|
+
require_tests: true # Require tests
|
|
273
|
+
min_coverage: 80 # Minimum coverage
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Usage Examples
|
|
279
|
+
|
|
280
|
+
### Example 1: Extract Duplicate Code
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
User: Eliminate duplicates in code
|
|
284
|
+
|
|
285
|
+
AI:
|
|
286
|
+
1. Detect duplicate code
|
|
287
|
+
2. Analyze similarity
|
|
288
|
+
3. Extract to shared module
|
|
289
|
+
4. Update all references
|
|
290
|
+
5. Create PR
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Example 2: Simplify Complex Function
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
User: Simplify processOrder function
|
|
297
|
+
|
|
298
|
+
AI:
|
|
299
|
+
1. Analyze function structure
|
|
300
|
+
2. Identify extractable sub-functions
|
|
301
|
+
3. Execute split refactoring
|
|
302
|
+
4. Run test verification
|
|
303
|
+
5. Create PR
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Example 3: Optimize Naming
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
User: Optimize code naming
|
|
310
|
+
|
|
311
|
+
AI:
|
|
312
|
+
1. Scan non-standard naming
|
|
313
|
+
2. Analyze context
|
|
314
|
+
3. Generate better naming
|
|
315
|
+
4. Batch replacement
|
|
316
|
+
5. Create PR
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Collaboration with Other Skills
|
|
322
|
+
|
|
323
|
+
- **pdd-entropy-reduction**: Called as a sub-skill by the coordinator
|
|
324
|
+
- **expert-entropy-auditor**: Receive refactoring suggestions
|
|
325
|
+
- **expert-arch-enforcer**: Receive architecture violation fixes
|
|
326
|
+
- **pdd-code-reviewer**: Trigger code review after refactoring
|
|
327
|
+
- **pdd-doc-change**: Synchronously update related documentation
|