AgentSkillsCN

refactoring

在不改变外部行为的前提下,优化内部代码结构。

SKILL.md
--- frontmatter
name: refactoring
description: Improving internal code structure without changing external behavior.

Refactoring Skill

Use this skill strictly for behavior-preserving code improvements. If you need to fix a bug or add functionality, use the bug-fixing or standard coding flow instead.

Core Principles

  1. Zero Behavior Change: The code MUST produce the same output for the same input after refactoring.
  2. Small, Reversible Steps: Make incremental changes that can be easily reverted if a test fails.
  3. Clean Code Focus: Focus on readability, maintainability (DRY, SOLID), and removing technical debt.

Refactoring Process

  1. Baseline: Ensure existing tests pass. If no tests exist, write them before refactoring.
  2. Identify Smells: Long methods, dead code, logic duplication, or poor naming.
  3. Apply Pattern: Use established patterns like "Extract Method", "Rename Variable", or "Simplified Conditionals".
  4. Verify: Run tests after every small change to confirm no breakage.

[!TIP] Refactoring is a "clean as you go" process. It should make future changes easier, not change what the code does today.