一键导入
expert-auto-refactor
自动化重构专家技能,将收集到的质量改进任务转化为具体的代码操作。当用户需要代码重构、消除重复、简化复杂度时自动触发。即使用户只说'重构代码'、'消除重复'或'简化代码',也应触发此Skill。支持中文触发:重构代码、消除重复、简化复杂度、自动重构、代码重构、PDD重构。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
自动化重构专家技能,将收集到的质量改进任务转化为具体的代码操作。当用户需要代码重构、消除重复、简化复杂度时自动触发。即使用户只说'重构代码'、'消除重复'或'简化代码',也应触发此Skill。支持中文触发:重构代码、消除重复、简化复杂度、自动重构、代码重构、PDD重构。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
"PDD框架下的业务分析Skill,运用专业方法论进行需求分析和业务建模。当用户输入/analyze、/audit、/doc等命令,或需要对业务流程、管理制度、Excel表单进行专业分析时触发。支持中文触发:业务分析、需求分析、需求建模、5W1H分析、MECE、流程分析。"
"PDD熵减智能体,持续监控和偿还技术债务,防止系统腐化。当用户需要代码清理、文档更新、技术债务管理、架构对齐、熵减、垃圾回收、清理技术债务时自动触发。即使用户只说'熵减'、'清理技术债务'或'垃圾回收',也应触发此Skill。支持中文触发:熵减、技术债务、代码清理、文档更新、架构对齐、垃圾回收。"
根据开发规格实现功能点代码的核心Skill。当用户想要开始编码实现、根据规格文档生成代码、实现功能点时调用此Skill。此Skill会自动调用pdd-template-engine生成基础代码框架,然后由software-engineer补充业务逻辑。即使只有规格文档没有明确说'实现',只要涉及代码生成、功能开发,都应触发此Skill。支持中文触发:实现功能点、编码实现、开始编码、功能开发、代码实现、PDD实现。
PRD驱动开发的主入口Skill,协调整个开发流程。当用户想要基于PRD文档进行功能开发、从需求文档生成代码、执行PDD方法论流程、开发业务模块、实现完整功能、'搞个功能'、'资产转让'、'国有产权转让'、'帮我搞个资产转让的功能'时必须调用此Skill。即使用户没有明确说'使用PDD',只要涉及PRD文档、需求文档、功能点开发、规格文档、模块开发、根据文档开发、业务功能实现、'开发ZCCZ'、'我想开发'、'搞个功能'等场景,都应触发此Skill。此Skill会自动协调pdd-ba、pdd-extract-features、pdd-generate-spec、pdd-implement-feature等子Skill完成从需求分析到代码交付的完整流程。注意:单一接口设计、调试问题、文档查询等场景不应触发此Skill。支持中文触发:PRD驱动开发、PDD开发、功能开发、启动PDD。
"交通事故责任评估与判定专业技能。当用户需要交通事故责任分析、事故现场照片评估、交通法规咨询、事故责任划分、法律依据查询时触发此技能。适用于车辆碰撞事故、行人事故、非机动车事故等各类道路交通事故的责任认定场景。无论用户使用'交通事故'、'车祸'、'责任判定'、'交通法规'、'事故定责'等何种表述,只要涉及交通事故评估或责任认定,均应调用此技能。支持中文触发:交通事故、车祸、责任判定、交通法规、事故定责、责任划分、事故评估、追尾、碰撞、违章、赔偿。"
代码质量专家,整合Martin Fowler重构技术和GoF设计模式,帮助开发者系统性地提升代码质量。当用户询问代码审查、重构、设计模式、代码异味、SOLID原则或软件架构改进时触发此技能。支持中文触发:代码质量、代码审查、重构、设计模式、代码异味、SOLID原则、架构改进。
| name | expert-auto-refactor |
| description | 自动化重构专家技能,将收集到的质量改进任务转化为具体的代码操作。当用户需要代码重构、消除重复、简化复杂度时自动触发。即使用户只说'重构代码'、'消除重复'或'简化代码',也应触发此Skill。支持中文触发:重构代码、消除重复、简化复杂度、自动重构、代码重构、PDD重构。 |
| author | neuqik@hotmail.com |
| license | MIT |
"Initiate targeted refactoring PRs regularly in a 'small debt repayment' manner to prevent technical debt from accumulating into unmanageable 'painful interest'." —— Harness Engineering
The automated refactoring expert is an upgraded version of expert-code-quality, not just recording issues but actively executing refactoring operations.
Scenario: Similar code logic in multiple places
Refactoring Method:
Example:
Before refactoring:
// File A
function formatDate(date) {
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
}
// File B
function formatDateString(d) {
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
}
After refactoring:
// utils/dateUtils.ts
export function formatDate(date: Date): string {
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
}
// File A
import { formatDate } from '../utils/dateUtils';
// File B
import { formatDate } from '../utils/dateUtils';
Scenario: Identical or highly similar code blocks
Refactoring Method:
Example:
Before refactoring:
// Repeated validation logic in multiple places
if (!user.email || !user.email.includes('@')) {
throw new Error('Invalid email');
}
After refactoring:
// utils/validators.ts
export function validateEmail(email: string): boolean {
return email && email.includes('@');
}
// Usage
if (!validateEmail(user.email)) {
throw new Error('Invalid email');
}
Scenario: Functions that are too long, deeply nested, or have complex logic
Refactoring Method:
Example:
Before refactoring:
function processOrder(order) {
if (order.status === 'pending') {
if (order.items.length > 0) {
if (order.payment) {
// Processing logic...
if (order.shipping) {
// More processing...
}
}
}
}
}
After refactoring:
function processOrder(order) {
if (!canProcessOrder(order)) return;
processPayment(order);
processShipping(order);
updateOrderStatus(order);
}
function canProcessOrder(order) {
return order.status === 'pending'
&& order.items.length > 0
&& order.payment;
}
Scenario: Non-standard naming, unclear meaning
Refactoring Method:
Example:
Before refactoring:
function calc(a, b) {
return a * b * 0.1;
}
After refactoring:
function calculateTax(basePrice: number, quantity: number): number {
const TAX_RATE = 0.1;
return basePrice * quantity * TAX_RATE;
}
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Analyze │ ──→ │ Plan │ ──→ │ Execute │ ──→ │ Verify │
│ │ │ │ │ │ │ │
│ • Code │ │ • Refactor │ │ • Code │ │ • Test │
│ structure │ │ strategy │ │ changes │ │ execution │
│ • │ │ • Impact │ │ • Reference │ │ • Function │
│ Dependencies│ │ scope │ │ updates │ │ validation│
│ • Test │ │ • Risk │ │ • Document │ │ • PR │
│ coverage │ │ assessment│ │ sync │ │ creation │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
Each refactoring should:
| Risk Level | Condition | Strategy |
|---|---|---|
| Low | Complete test coverage | Auto execute |
| Medium | Partial test coverage | Create PR |
| High | No test coverage | Add tests first then refactor |
# Refactoring Report - YYYY-MM-DD
## Refactoring Scope
- Target files: X
- Affected files: X
- Test coverage: X%
## Refactoring Operations
### Extract Common Methods
| Original File | New File | Method Name | Status |
|-------|-------|-------|------|
| utils/formatDate.js | utils/dateUtils.ts | formatDate | ✅ Completed |
### Eliminate Duplicate Code
| File A | File B | Duplicate Lines | Status |
|-------|-------|---------|------|
| service/UserService.ts | service/OrderService.ts | 25 lines | ✅ Completed |
### Simplify Complex Logic
| File | Function Name | Original Lines | New Lines | Status |
|------|-------|-------|-------|------|
| service/OrderService.ts | processOrder | 80 | 35 | ✅ Completed |
## Verification Results
- Unit tests: ✅ All passed
- Integration tests: ✅ All passed
- Functional verification: ✅ No anomalies
## PR Information
- PR number: #XXX
- Branch: refactor/entropy-reduction-YYYYMMDD
- Status: Pending review
# auto-refactor-config.yaml
auto_refactor:
# Refactoring scope
scope:
code_paths: ["src/"]
exclude: ["node_modules/", "dist/", "build/"]
# Refactoring rules
rules:
max_file_lines: 300
max_function_lines: 50
min_similarity: 0.8
# Execution strategy
execution:
auto_fix_low_risk: true # Auto fix low risk
create_pr: true # Create PR
max_changes_per_run: 10 # Max changes per run
# Testing requirements
testing:
require_tests: true # Require tests
min_coverage: 80 # Minimum coverage
User: Eliminate duplicates in code
AI:
1. Detect duplicate code
2. Analyze similarity
3. Extract to shared module
4. Update all references
5. Create PR
User: Simplify processOrder function
AI:
1. Analyze function structure
2. Identify extractable sub-functions
3. Execute split refactoring
4. Run test verification
5. Create PR
User: Optimize code naming
AI:
1. Scan non-standard naming
2. Analyze context
3. Generate better naming
4. Batch replacement
5. Create PR