AgentSkillsCN

refactoring-code

借助 MorphLLM 的 edit_file 功能进行批量重构。适用于“跨文件重构”“批量重命名”“全局更新模式”“处理超大文件(500 行以上)”,或在同一文件中进行 5 次以上的编辑操作。

SKILL.md
--- frontmatter
name: refactoring-code
description: Batch refactoring via MorphLLM edit_file. Use for "refactor across files", "batch rename", "update pattern everywhere", large files (500+ lines), or 5+ edits in same file.
user-invocable: false
allowed-tools:
  - mcp__morphllm__edit_file
  - mcp__morphllm__warpgrep_codebase_search
  - mcp__morphllm__codebase_search
  - Read
  - Grep
  - Glob

Fast Refactoring with MorphLLM

MorphLLM edit_file provides semantic code merging at 10,500+ tokens/sec with 98% accuracy.

When to Use edit_file

Use edit_fileUse Built-in Edit/MultiEdit
Multi-file batch refactoringSingle file, clear edit
Style/pattern update everywhere2-3 targeted replacements
Complex prompt → many changesNeed clear diff to review/tune
Structural refactoring at scaleSimple rename (replace_all)
5+ files need same patternStraightforward single-file work

Key Features

  • Semantic merge: Understands code structure, not just text
  • Speed: 10,500 tok/s vs 180 tok/s streaming
  • Accuracy: 98% success rate on edge cases
  • dryRun: Preview changes before applying

Workflow

Standard Refactoring

code
1. Use WarpGrep to find all locations needing change
2. For each file: call edit_file with changes
3. Verify with lint/test

High-Stakes Changes (dryRun)

code
1. Call edit_file with dryRun: true
2. Review preview output
3. If approved, call again with dryRun: false

Parameters

code
path: "/absolute/path/to/file"
code_edit: "changed lines with // ... existing code ... markers"
instruction: "brief description of changes"
dryRun: false (set true to preview)

Edit Format

Use // ... existing code ... markers for unchanged sections:

typescript
// ... existing code ...
function updatedFunction() {
  // new implementation
}
// ... existing code ...

Common Patterns

Batch Error Handling

code
instruction: "Add error wrapping to all repository methods"
code_edit: Shows only changed functions with context markers

Import Updates

code
instruction: "Update imports from old-pkg to new-pkg"
code_edit: Shows import section with changes

Multi-Location Rename

code
instruction: "Rename getUserById to findUser throughout file"
code_edit: Shows all locations with changes

Tips

  • Batch all edits to same file in one call
  • Include enough context to locate changes precisely
  • Preserve exact indentation in code_edit
  • Use WarpGrep first to understand scope
  • Run tests after each file to catch issues early