---
id: gh-safe-refactor
name: "safe-refactor"
url: https://skills.yangsir.net/skill/gh-safe-refactor
author: juliusbrussee
domain: ai-code-generation-quality
tags: ["code-refactoring", "behavior-preservation", "verification", "refactoring-safety"]
install_count: 101600
rating: 4.80 (120 reviews)
github: https://github.com/juliusbrussee/caveman/tree/main/skills/safe-refactor
---

# safe-refactor

> 在重构代码时确保行为不变。此技能在结构编辑前定义行为保持边界并建立验证机制，支持提取、合并、所有权移动和清理等操作，在每一步保持中间状态可构建可测试，最终运行相同验证确保行为匹配且结构调整达成，有效防止回归和隐藏缺陷。

**Stats**: 101,600 installs · 4.8/5 (120 reviews)

## Before / After 对比

### 重构返工时长降低

**Before**:

开发者手动重构时缺乏行为验证边界，容易在提取或移动代码时意外改变接口和顺序，导致问题在后续阶段才暴露，不得不花大量时间返工调试，影响交付进度。

**After**:

此技能在结构编辑前建立验证机制，逐步移动所有权边界并保持中间状态可测试，重构后行为一致，返工时间大幅缩短，开发效率显著提升。

| Metric | Before | After | Change |
|---|---|---|---|
| 重构返工时长 | 6小时 | 0.5小时 | -92% |

## Readme

# Safe refactor

Define behavior-preservation boundary and establish verification before structural edits.

- Keep feature changes outside refactor.
- Move one ownership boundary at a time.
- Preserve public interfaces, failure behavior, ordering, and compatibility unless explicitly scoped.
- Keep intermediate states buildable and testable.
- Avoid dependency or configuration growth without correctness need.

Run same proof after change. Stop when behavior matches and requested structure is achieved.


---
*Source: https://skills.yangsir.net/skill/gh-safe-refactor*
*Markdown mirror: https://skills.yangsir.net/api/skill/gh-safe-refactor/markdown*