expert-auto-refactor
Skill41 starsChanged 8 months agoMITView on GitHub
Automated refactoring expert skill that transforms collected quality improvement tasks into concrete code operations. Automatically triggers when users need code refactoring, duplicate elimination, or complexity simplification.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- wonderslife/pdd-skills-v3edited, first seen Oct 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- wonderslife/pdd-skills-v3★ 1597% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- expert-activitiSkill
- expert-arch-enforcerSkill
- expert-code-qualitySkill
- expert-entropy-auditorSkill
- expert-mysqlSkill
- expert-ruoyiSkill
- official-doc-writerSkill
- pdd-baSkill
- pdd-code-reviewerSkill
- pdd-doc-changeSkill
- pdd-doc-gardenerSkill
- pdd-entropy-reductionSkill
- pdd-extract-featuresSkill
- pdd-generate-specSkill
- pdd-implement-featureSkill
- pdd-mainSkill
- pdd-pr-batchSkill
- pdd-pr-createSkill
- pdd-pr-mergeSkill
- pdd-pr-reviewSkill
- pdd-verify-featureSkill
- software-architectSkill
- software-engineerSkill
- system-architectSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 192
Small steps: Only change a small part each time
- Distinctive: line 193
Maintain tests: Ensure tests always pass
- Distinctive: line 194
Frequent commits: Commit after each small step
- Distinctive: line 195
Rollback capable: Keep each commit independently rollbackable
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Automated Refactoring Expert (expert-auto-refactor)
Core Philosophy
"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.
Refactoring Types
1. Extract Common Methods
Scenario: Similar code logic in multiple places
Refactoring Method:
- Identify similar code
- Extract common methods
- Replace original calls
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';2. Eliminate Duplicate Code
Scenario: Identical or highly similar code blocks
Refactoring Method:
- Detect duplicate code
- Extract to shared module
- Update references
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');
}3. Simplify Complex Logic
Scenario: Functions that are too long, deeply nested, or have complex logic
Refactoring Method:
- Split long functions
- Extract sub-functions
- Simplify conditional logic
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;
}4. Optimize Naming
Scenario: Non-standard naming, unclear meaning
Refactoring Method:
- Analyze naming context
- Generate better naming
- Batch replacement
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;
}Refactoring Process
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 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 │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘Refactoring Strategy
Small Debt Repayment Principle
Each refactoring should:
- Small steps: Only change a small part each time
- Maintain tests: Ensure tests always pass
- Frequent commits: Commit after each small step
- Rollback capable: Keep each commit independently rollbackable
Risk Assessment
| 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 |
Output Format
Refactoring Report
# 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 reviewConfiguration Options
# 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 coverageUsage Examples
Example 1: Extract Duplicate Code
User: Eliminate duplicates in code
AI:
1. Detect duplicate code
2. Analyze similarity
3. Extract to shared module
4. Update all references
5. Create PRExample 2: Simplify Complex Function
User: Simplify processOrder function
AI:
1. Analyze function structure
2. Identify extractable sub-functions
3. Execute split refactoring
4. Run test verification
5. Create PRExample 3: Optimize Naming
User: Optimize code naming
AI:
1. Scan non-standard naming
2. Analyze context
3. Generate better naming
4. Batch replacement
5. Create PRCollaboration with Other Skills
- pdd-entropy-reduction: Called as a sub-skill by the coordinator
- expert-entropy-auditor: Receive refactoring suggestions
- expert-arch-enforcer: Receive architecture violation fixes
- pdd-code-reviewer: Trigger code review after refactoring
- pdd-doc-change: Synchronously update related documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

