用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill safe-refactor命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | safe-refactor |
| description | | Use when this capability is needed. |
This elixir works best with these skills installed:
| Skill | Purpose | If Missing |
|---|---|---|
| pre-mortem | Risk assessment before starting | Falls back to built-in checklist |
| prove-it | Verification enforcement | Falls back to built-in verification |
| retrospective | Document learnings | Skipped (optional phase) |
<phase_risk> If pre-mortem skill installed: Invoke it now.
If not installed, evaluate:
## Refactor Risk Assessment
**What's changing:**
- [ ] Files affected: [list them]
- [ ] Functions/classes modified: [list them]
- [ ] Estimated lines changed: [number]
**Risk factors:**
- [ ] Touches shared/core code (used by multiple features)
- [ ] Affects data persistence (database, files, cache)
- [ ] Changes public API/interfaces
- [ ] Lacks test coverage
- [ ] Written by someone else / unfamiliar code
- [ ] Production-critical path
**Risk level:** [Low / Medium / High / Abort]
GATE: Do not proceed if:
If high risk: Consider breaking into smaller refactors. </phase_risk>
<phase_prepare> Before touching code:
Ensure tests exist (or write them first)
- [ ] Existing tests cover the behavior being preserved
- [ ] If no tests: write characterization tests NOW
Create escape hatch
git stash # or commit current state
git checkout -b refactor/[description]
Document current behavior
Before: [How it works now]
After: [How it should work - must be identical externally]
GATE: Do not proceed without:
<phase_implement> Rules for safe refactoring:
One thing at a time
Small commits
# Good: multiple small commits
git commit -m "Extract helper function"
git commit -m "Rename variables for clarity"
git commit -m "Move file to new location"
# Bad: one giant commit
git commit -m "Refactor everything"
Run tests frequently
Preserve behavior exactly
<phase_verify> If prove-it skill installed: Invoke it now.
If not installed:
## Refactor Verification
**Automated checks:**
- [ ] All existing tests pass
- [ ] No new linter errors
- [ ] Type checking passes (if applicable)
**Manual verification:**
- [ ] Tested the primary use case manually
- [ ] Checked one edge case
- [ ] Compared behavior before/after for critical paths
**Regression check:**
- [ ] git diff shows only intended changes
- [ ] No accidental behavior changes
- [ ] No debug code left in
GATE: Do not merge until all checks pass.
If verification fails:
git revert HEAD # or reset to before refactor
# Start over with smaller scope
</phase_verify>
<phase_document> If retrospective skill installed: Invoke for significant refactors.
For large refactors, capture:
## Safe Refactor: [Description]
### Risk Assessment
- Risk level: [Low/Medium/High]
- Files affected: [count]
- Risk factors: [list]
### Preparation
- [x] Tests verified/written
- [x] Branch created: refactor/[name]
- [x] Current behavior documented
### Implementation
- Commits: [count]
- Approach: [brief description]
### Verification
- [x] Tests pass
- [x] Manual verification complete
- [x] No regressions detected
### Learnings (if significant)
[What you'd do differently]
User: "Refactor the authentication module to use the new token format"
Phase 1 - Risk Assessment:
Refactor Risk Assessment:
- Files affected: auth.ts, token.ts, middleware.ts, 12 test files
- Risk factors: ✓ Core code, ✓ Production-critical, ✓ Written by someone else
- Risk level: High
Recommendation: Break into smaller refactors:
- First: Add new token format support alongside old
- Second: Migrate consumers one by one
- Third: Remove old format
Phase 2 - Prepare:
- Existing tests cover token generation and validation
- Created branch: refactor/token-format-v2
- Documented: Old format is JWT with RS256, new format adds
typheader
Phase 3 - Implement:
Making changes incrementally...
- Commit 1: "Add TokenV2 class with new format"
- Commit 2: "Add feature flag for token format"
- Commit 3: "Update token generation to use flag"
- Tests passing after each commit ✓
Phase 4 - Verify:
- All 47 auth tests pass
- Manual test: login flow works with both formats
- Manual test: token refresh works
- git diff shows only intended changes
Ready to merge.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.