用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/andrem-sec/psc-comet --skill refactor命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | refactor |
| description | Safe refactoring protocol — behavior-preserving restructuring with test coverage gate |
| version | 0.1.0 |
| level | 2 |
| triggers | ["refactor","clean this up","restructure","extract this","simplify this"] |
| context_files | ["context/project.md"] |
| steps | [{"name":"Coverage Gate","description":"Confirm test coverage exists before touching anything. If coverage is below 80%, write tests first."},{"name":"Define Behavior Contract","description":"State what the code currently does — its observable behavior, not its structure. This is what must be preserved."},{"name":"Scope","description":"What is being refactored? One concern at a time."},{"name":"One Change","description":"Make one structural change. Run tests. Green. Move to next change."},{"name":"No Behavior Changes","description":"If a test breaks, the refactor changed behavior — stop and reassess."},{"name":"Verify","description":"Full test suite passes. Coverage did not regress. Behavior contract preserved."}] |
Behavior-preserving restructuring. The goal is a different structure that produces identical observable behavior.
Without refactor discipline, "refactoring" becomes a mix of restructuring, behavior changes, and new features in one pass. When something breaks, there is no way to know which change caused it. Tests that fail mid-refactor mean the scope was too large, but without the discipline to go one change at a time, the error is impossible to isolate.
Before touching any code, state what it currently does in terms of observable behavior — inputs, outputs, side effects. This is the contract.
If the refactor changes any of these, it is not a refactor — it is a feature change or a bug fix. Handle those separately.
One structural change at a time:
Run tests after each. If they pass, continue. If they fail, the change broke something — revert it and understand why before proceeding.
Do not batch. Do not "while I'm in here" add improvements. Do not rename AND restructure in one change.
Refactoring without tests is rearranging furniture in the dark. Before the first structural change:
This is not optional. Skipping it means the refactor cannot be verified.
| Operation | When to Use |
|---|---|
| Extract function | Block of code used in 2+ places, or a block that has a single clear responsibility |
| Rename | Name does not reflect current purpose (this happens after behavior is understood, not before) |
| Remove duplication | Same logic in 3+ places — but only if the logic is genuinely identical, not just similar |
| Flatten nesting | More than 3 levels of nesting in a single function |
| Extract class | A function or module has grown to handle 2+ distinct concerns |
| Inline | An abstraction that adds complexity without clarity — sometimes the direct version is better |
Do not refactor code you do not understand. Read it until you can state its behavior contract before touching it.
Do not refactor and fix bugs in the same pass. Fix first, then refactor.
Do not refactor code with no tests. Write tests first.
Do not "improve" variable names speculatively — rename only when you understand the current name is wrong.