Refactor

作者 parcadeid07ff4b06b62无许可证3.9K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库8个月前更新

Code refactoring workflow - analyze → plan → implement → review → validate

AI 生成的概览

指导五阶段代码重构流程:分析、规划、实现、审查与验证。

功能
该技能定义了一套分阶段的重构工作流,依次经过分析、规划、实现、审查和验证,并将每个阶段分配给指定的代理。它会产出分析报告、分步重构计划、代码改动、审查报告和测试报告。它还列出了重构原则、常见重构类型以及 dry-run、step-by-step 等安全选项。
适用场景
当被要求重构代码、清理代码、将逻辑抽取为模块、调整代码库结构或减少技术债务时使用。它适合需要先规划、再审查并依据测试验证的较大规模重构工作。
运行要求
不包含脚本,仅为指令。它假定运行环境中的代理能够调用指定的子代理,并执行测试、类型检查和代码检查。

/refactor - Refactoring Workflow

Safe refactoring with review gates.

When to Use

  • "Refactor X"
  • "Clean up this code"
  • "Extract this into a module"
  • "Improve the architecture of Y"
  • Large-scale code restructuring
  • Technical debt reduction

Workflow Overview

┌──────────┐    ┌────────────┐    ┌──────────┐    ┌──────────┐    ┌───────────┐│ phoenix  │───▶│   plan-    │───▶│  kraken  │───▶│plan-reviewer│───▶│ arbiter  ││          │    │   agent    │    │          │    │          │    │           │└──────────┘    └────────────┘    └──────────┘    └──────────┘    └───────────┘  Analyze         Plan             Implement       Review          Verify  current         changes          refactor        changes         tests pass

Agent Sequence

#AgentRoleOutput
1phoenixAnalyze current code, identify improvement areasAnalysis report
2plan-agentCreate safe refactoring planStep-by-step plan
3krakenImplement the refactoringCode changes
4plan-reviewerReview changes for correctnessReview report
5arbiterVerify all tests still passTest report

Refactoring Principles

  1. Tests first: Ensure adequate test coverage before refactoring
  2. Small steps: Each change should be independently verifiable
  3. Behavior preserved: No functional changes during refactor
  4. Reviewable: Changes should be easy to review

Execution

Phase 1: Analyze

Task(  subagent_type="phoenix",  prompt="""  Analyze for refactoring: [TARGET_CODE]
  Identify:  - Current pain points  - Code smells  - Improvement opportunities  - Risk areas  - Test coverage gaps  """)

Phase 2: Plan

Task(  subagent_type="plan-agent",  prompt="""  Plan refactoring: [TARGET_CODE]
  Analysis: [from phoenix]
  Create:  - Step-by-step refactoring plan  - Each step should be:    - Small and focused    - Independently testable    - Reversible  - Identify files affected  - Risk mitigation strategy  """)

Phase 3: Implement

Task(  subagent_type="kraken",  prompt="""  Implement refactoring: [TARGET_CODE]
  Plan: [from plan-agent]
  Requirements:  - Follow plan exactly  - Run tests after each step  - Stop if tests fail  - NO behavior changes  """)

Phase 4: Review

Task(  subagent_type="plan-reviewer",  prompt="""  Review refactoring: [TARGET_CODE]
  Changes: [git diff from kraken]
  Check:  - Behavior preserved  - No unintended changes  - Code quality improved  - Patterns consistent  """)

Phase 5: Validate

Task(  subagent_type="arbiter",  prompt="""  Validate refactoring: [TARGET_CODE]
  - Run full test suite  - Verify no regressions  - Check type errors  - Run linting  """)

Refactoring Types

Extract Module

phoenix → plan-agent → kraken → plan-reviewer → arbiter

Rename/Restructure

phoenix → kraken → arbiter  (simpler, skip detailed planning)

Architecture Change

phoenix → plan-agent → [kraken → plan-reviewer] × N phases → arbiter

Example

User: /refactor Extract the validation logic into a separate module
Claude: Starting /refactor workflow...
Phase 1: Analyzing current structure...[Spawns phoenix]Found: Validation logic spread across 4 files- form.ts (lines 45-120)- api.ts (lines 200-280)- user.ts (lines 15-45)- order.ts (lines 88-130)
Phase 2: Planning extraction...[Spawns plan-agent]Plan:1. Create src/validation/index.ts2. Extract common validators3. Update imports one file at a time4. Run tests after each change
Phase 3: Implementing...[Spawns kraken]Completed all 4 steps, tests green after each
Phase 4: Reviewing changes...[Spawns plan-reviewer]✅ All behavior preserved✅ DRY improved (removed 45 duplicate lines)✅ New structure consistent
Phase 5: Final validation...[Spawns arbiter]✅ 312 tests passing, 0 regressions
Refactoring complete!

Safety Flags

  • --dry-run: Plan but don't implement
  • --step-by-step: Pause after each change for approval
  • --coverage-check: Require >80% coverage before proceeding

来源与署名

来源:parcadei/continuous-claude-v3位于.claude/skills/refactor提交d07ff4b

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架