一键导入
refactor
Refactoring process with test safety. Invoke immediately when user or document mentions refactoring, or proactively when code gets too complex or messy.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Refactoring process with test safety. Invoke immediately when user or document mentions refactoring, or proactively when code gets too complex or messy.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Implement phase of RPI methodology. Executes a task-graph-driven implementation using isolated agents with strict RED/GREEN/VALIDATE gate enforcement. Use when executing an implementation plan from the draft skill.
Draft phase of RPI methodology. Consumes research artifact or topic and produces compact implementation plan with test specs and Agent Context blocks. Activates naturally inside plan mode for non-trivial work, or invoke explicitly with /draft. Use after research or to start planning a non-trivial feature.
Post-session skill to reflect on what was built and produce improvement proposals. Reads recent git history, artifacts, and context files to extract learnings for skills, CLAUDE.md, hooks, and plan templates. Use after any substantive session as a post-mortem or retrospective.
Research phase of RPI methodology. Spawns parallel subagents for codebase exploration AND web/pattern research, then synthesizes findings for user review. Produces a temporary research artifact at .crafter/scratch/ and transitions into plan mode. Use before implementing non-trivial features to understand what already exists.
Boundary-focused TDD workflow enforcing L3/L4 altitude testing, property-based tests, and red-green-refactor phase separation. Use when starting a new module or feature with test-first discipline.
Guides writing minimal Architecture Decision Records (ADRs). Use when recording architectural decisions, documenting design choices, capturing technical decisions with context and alternatives, or when user mentions ADR, architecture decision, or decision record.
基于 SOC 职业分类
| name | refactor |
| description | Refactoring process with test safety. Invoke immediately when user or document mentions refactoring, or proactively when code gets too complex or messy. |
| triggers | ["refactor this code","refactor the code","refactoring code","clean up code","extract method"] |
| allowed-tools | Read Glob Write Bash |
Work autonomously as much as possible. Start with the simplest thing or file and proceed to the more complex ones.
Do not change test code during refactoring, except:
Never change test assertions, test data, or test logic.
REFACTORING_SUMMARY.md in the project root with the following initial content:
# Refactoring Summary
## Baseline
- Files in scope: {list of files}
- Test result: {PASS/FAIL with test count}
## Steps
Prefer self-explanatory, readable code over comments.
Example — extract method and rename variable:
Before:
// apply discount
const x = order.items.reduce((sum, i) => sum + i.price, 0);
return x * (1 - order.dc);
After:
const subtotal = sumItemPrices(order.items);
return subtotal * (1 - order.discountRate);
function sumItemPrices(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}
Example — remove dead code and use domain language:
Before:
function process(u, t) {
// TODO: remove legacy path
if (false) { return legacyProcess(u, t); }
return chargeCard(u.card, t.amount);
}
After:
function processPayment(user, transaction) {
return chargeCard(user.card, transaction.amount);
}
For each refactor:
REFACTORING_SUMMARY.md:
### Step {N}: {refactoring description}
- Commit: `- r {message}`
- Test result: {PASS with test count}
- Files changed: {list}
When you see no more obvious refactoring opportunities, say "Entering final evaluation."
Shift focus: you've been implementing. Now become a critic. Your job is to find problems, not produce code.
Re-read Code Style guidelines. Look at each file in scope. Consider blind spots - what improvements haven't we even considered that would make the code better, easier, more maintainable?
For each file, find ONE thing that could be better. If you find something:
Repeat until you find nothing more to improve.
Provide a high-level summary of the refactoring:
Append a final section to REFACTORING_SUMMARY.md:
## Final
- Total steps: {N}
- Files touched: {list of all files changed}
- All commits: {list of commit messages}
- Final test result: {PASS with test count}
This skill was originally adapted from Llewellyn Falco's refactoring process. See credits.md for attribution.