AgentSkillsCN

refactor

分析代码库中的重构机会,并按影响程度进行优先级排序

SKILL.md
--- frontmatter
name: refactor
description: Analyze codebase for refactoring opportunities and prioritize by impact

Refactoring Agent

Analyze the codebase to identify and prioritize refactoring opportunities.

Workflow

1. Gather Codebase Context

bash
# High churn files (frequently modified = priority)
git log --pretty=format: --name-only --since="6 months ago" | sort | uniq -c | sort -rn | head -30

# Tech debt markers
grep -rn "TODO\\|FIXME\\|HACK\\|XXX\\|REFACTOR" --include="*.ts" --include="*.tsx" .

# Large files (potential god classes)
find . -name "*.ts" -o -name "*.tsx" | xargs wc -l | sort -rn | head -20

2. Issue Types to Detect

IssueDetectionRefactor
Code DuplicationSimilar blocks across filesExtract Function
Long Functions>50 lines or complexity >10Extract Method
God Classes>10 methods or >300 linesExtract Class
Feature EnvyMethod uses other class data excessivelyMove Method
Dead CodeUnused exports, unreachable codeDelete
Deep Nesting>3 levels of conditionals/loopsGuard Clauses
Primitive ObsessionRepeated primitive combosValue Object
Long Parameter Lists>4 parametersParameter Object
Inconsistent PatternsDifferent approaches for same problemConsolidate
Missing AbstractionsRepeated inline logicExtract

3. Severity Assessment

  • High 🔴: Bug risk, critical path, high churn
  • Medium 🟠: Tech debt accumulating, moderate burden
  • Low 🟡: Code smell, readability issue

4. Priority Formula

code
Priority = Severity (High=3, Med=2, Low=1) × (1 / Effort)
Effort: Small=1, Medium=2, Large=3

Output Format

code
## Refactoring Opportunities

### 1. 🔴 [Type] `file.ts:L10-85` | High | Small | Score: 3.0
   Problem: <description>
   Refactoring: <technique>

## Quick Wins (High + Small effort)
1. ...

## Summary
| Severity | Count |
|----------|-------|
| 🔴 High  | X     |
| 🟠 Medium| X     |
| 🟡 Low   | X     |

Execution Mode

When asked to apply refactorings:

  1. Start with highest priority Small-effort items
  2. Make atomic commits per refactoring
  3. Run tests after each change
  4. Stop if tests fail and report the issue