Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add commands/ysicing/code-pilot/refactorgit clone --depth 1 https://github.com/ysicing/code-pilotWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00018 | $0.00633 |
| Opus 5 | $0.00009 | $0.00316 |
| Sonnet 5 | $0.00004 | $0.00127 |
| Haiku 4.5 | $0.00002 | $0.00063 |
Grade A, and why
refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
/refactor 命令
专注于安全重构实施的执行专家,与/review和/optimize形成互补,专门负责代码结构改进的具体实施。
命令语法
/refactor <具体文件或类/方法>
核心定位
实施型命令:专门执行已识别的重构需求,而非分析阶段
/review→ 发现问题和建议/refactor→ 实施具体重构/optimize→ 性能导向优化
适用场景
- 基于code review结果的具体重构实施
- 违反SOLID原则的代码修正
- 技术债务的系统性清理
- 已确定的架构调整执行
重构模式库
经典重构模式
- 提取方法(Extract Method):分解长方法
- 提取类(Extract Class):分离职责过多的类
- 移动方法(Move Method):优化方法归属
- 重命名(Rename):改善可读性
- 引入参数对象:简化参数列表
- 替换算法:优化实现方式
SOLID原则修正
- S:分离混合职责,单一职责化
- O:增加扩展点,支持开闭原则
- L:修正继承关系,确保可替换性
- I:拆分臃肿接口,实现接口隔离
- D:引入依赖注入,实现依赖倒置
严格执行规则
前置条件:
- 所有测试必须通过
- 有明确的重构目标(来自/review或需求分析)
执行纪律:
- 每个重构步骤后立即运行测试
- 测试失败立即回滚到上一稳定状态
- 一次只做一种类型的重构
- 保持功能行为完全不变
安全措施:
- Git提交每个安全的重构步骤
- 保持向后兼容的API
- 渐进式重构,避免大爆炸式改动
与其他命令的协作
# 典型工作流
/review "UserService类" # 发现问题
/refactor "UserService.authenticate方法" # 实施具体重构
/test "UserService重构后验证" # 验证重构效果
输出交付
- 重构实施计划(具体步骤)
- 逐步重构的代码变更
- 重构前后对比说明
- 后续监控建议
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday First seen · 72 lines · 18 tokens per session scan A 8e8ed15c76bf
refactor is a command published in the GitHub repository ysicing/code-pilot (38 stars, last pushed 5mo ago), licensed Apache-2.0. It adds 18 tokens to every session and 633 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other commands, from other repositories
specify
Create or update the feature specification from a natural language feature description.
speckit.git.validate
Validate current branch follows feature branch naming conventions.
pr-address
Address PR review comments on current branch.
plan-save
Save the current session's plan to GitHub as an issue.
enforce_standards
CRITICAL: Before running the code standards enforcer, we must prepare the stack properly and abort if there are merge conflicts.
OPSX: Sync
Sync delta specs from a change to main specs.