refactor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Refactor Command

重构命令

Execute automated refactoring for $ARGUMENTS using
refactor:code-simplifier
agent.
使用
refactor:code-simplifier
Agent对$ARGUMENTS执行自动化重构。

Pre-operation Checks

操作前检查

Goal: Ensure scope resolution is deterministic before launching the agent.
Actions:
  1. Run
    git rev-parse --is-inside-work-tree
    and continue even if false when explicit paths are provided
  2. Normalize arguments by trimming whitespace and preserving quoted path segments
  3. Treat an empty argument list as "recent changes" mode
目标:在启动Agent前确保范围解析的确定性。
操作步骤
  1. 运行
    git rev-parse --is-inside-work-tree
    ,即使结果为false,若提供了明确路径则继续执行
  2. 标准化参数:修剪空格并保留带引号的路径段
  3. 将空参数列表视为“最近更改”模式

Phase 1: Determine Target Scope

阶段1:确定目标范围

Goal: Identify files to refactor based on arguments or session context.
Actions:
  1. If arguments provided: verify as file/directory paths using Glob
  2. If paths exist: use them directly as refactoring scope
  3. If paths don't exist: treat arguments as semantic query, search codebase with Grep
  4. If no arguments: run
    git diff --name-only
    to find recently modified code files
  5. If no recent changes found: inform user and exit without refactoring
See
references/scope-determination.md
for search strategies and edge cases.
目标:根据参数或会话上下文识别需要重构的文件。
操作步骤
  1. 若提供参数:使用Glob验证是否为文件/目录路径
  2. 若路径存在:直接将其作为重构范围
  3. 若路径不存在:将参数视为语义查询,使用Grep搜索代码库
  4. 若无参数:运行
    git diff --name-only
    查找最近修改的代码文件
  5. 若未找到最近更改:告知用户并不执行重构即退出
有关搜索策略和边缘情况,请参阅
references/scope-determination.md

Phase 2: Launch Refactoring Agent

阶段2:启动重构Agent

Goal: Execute
refactor:code-simplifier
agent with aggressive mode enabled.
Actions:
  1. Launch
    refactor:code-simplifier
    agent with target scope and aggressive mode flag
  2. Pass scope determination method (paths, semantic query, or session context)
  3. Agent auto-loads
    refactor:best-practices
    skill and applies language-specific patterns
See
references/agent-configuration.md
for detailed Task parameters.
目标:启用激进模式,启动
refactor:code-simplifier
Agent。
操作步骤
  1. 启动带有目标范围和激进模式标志的
    refactor:code-simplifier
    Agent
  2. 传递范围确定方法(路径、语义查询或会话上下文)
  3. Agent会自动加载
    refactor:best-practices
    Skill并应用特定语言的模式
有关详细任务参数,请参阅
references/agent-configuration.md

Phase 3: Summary

阶段3:总结

Goal: Report comprehensive summary of changes.
Actions:
  1. Report total files refactored and changes categorized by improvement type
  2. List best practices applied and legacy code removed
  3. Suggest tests to run and provide rollback command tailored to actual scope (for example:
    git restore --worktree --staged <files>
    )
See
references/output-requirements.md
for detailed summary format.
目标:报告变更的全面总结。
操作步骤
  1. 报告重构的文件总数,并按改进类型分类变更
  2. 列出应用的最佳实践和移除的遗留代码
  3. 建议运行的测试,并提供针对实际范围的回滚命令(例如:
    git restore --worktree --staged <files>
有关详细的总结格式,请参阅
references/output-requirements.md

Requirements

要求

  • Execute immediately without user confirmation
  • Refactor ALL matching files when semantic search returns multiple results
  • Direct users to
    /refactor-project
    for project-wide scope
  • Preserve behavior and public interfaces unless user explicitly requests a behavior change
  • 无需用户确认立即执行
  • 当语义搜索返回多个结果时,重构所有匹配的文件
  • 引导用户使用
    /refactor-project
    进行项目范围的重构
  • 除非用户明确要求更改行为,否则保留现有行为和公共接口