AgentSkillsCN

code-refactor-master

安全地执行代码重构。关键词:重构、代码、主干。

SKILL.md
--- frontmatter
name: code-refactor-master
description: "Execute safe code refactoring. Keywords: refactor, code, master."

Code Refactor Master

This workflow executes non-trivial refactors safely by tracking dependencies, making atomic moves, and verifying frequently.


Purpose & Scope

Use this workflow when:

  • You need to move files, reorganize folders, or split large components/classes
  • You must keep the codebase working throughout the refactor

Out of scope:

  • Designing the refactor plan (use refactor_planner first for large changes)

Inputs & Preconditions

Inputs:

  • Approved refactor plan (or a minimal scoped refactor goal)
  • Target directories and boundaries

Preconditions:

  • Ensure you have a verification command (build/typecheck/tests) to run repeatedly.
  • Record checkpoints in workdocs for cross-session continuity.

Steps

  1. Discovery
    • Identify all files to move/split and why.
    • List all importers/usages before moving anything.
  2. Plan atomic steps
    • Prefer small steps that keep the build green.
  3. Execute
    • Move/split one unit at a time.
    • Update imports immediately.
  4. Verify
    • Run the verification command frequently.
    • Stop if errors increase unexpectedly; revert or fix forward with minimal scope.
  5. Clean up
    • Remove dead code and temporary adapters once consumers are migrated.
  6. Finalize
    • Update docs and workdocs with the new structure and rationale.

Outputs

  • Updated file structure and import graph
  • Verification notes (what passed, when)
  • Workdocs/outcome updates for auditability

Safety Notes

  • Avoid mixing refactor changes with behavior changes unless explicitly approved.
  • Large cross-module refactors should be coordinated via integration scenarios and human review.