playbook/codex/skills/bulk-refactor-workflow/SKILL.md

54 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: bulk-refactor-workflow
description: Safe bulk refactors and mass edits across a repo (rename APIs, global replacements, mechanical changes). Triggers: bulk refactor, mass edit, rename symbol, global replace, 批量重构, 全局替换, 统一改名, 大范围修改.
---
# Bulk Refactor Workflow批量重构 / 大范围修改)
## When to Use
- Rename API / symbol / file convention across many files
- Mechanical refactors (imports, formatting, lint fixes, signature migrations)
- Cross-cutting changes touching 10+ files
## Inputsrequired
- Scope目录/文件类型/排除项include/exclude
- Transformation要做的规则rename A→B、替换模式、接口迁移策略
- Constraints是否允许行为变化是否需要兼容期是否允许自动格式化
- Verification必须通过哪些命令/检查(最少一个)
## Proceduredefault
1. **Baseline**
- 确保工作区干净:`git status --porcelain`
- 跑一个基线验证(至少 build 或核心测试子集),避免“本来就坏”
2. **Enumerate**
- 先搜索再改:用 `rg`/`git grep` 列出全部命中
- 分类命中:真实调用 vs 注释/文档/样例;避免误改
3. **Apply Mechanical Change**
- 优先使用确定性的机械变换(脚本/结构化编辑)而非手工逐个改
- 每轮改动后立即做小验证(编译/单测子集)
- 复杂迁移优先“两阶段”先兼容旧接口deprecated再清理旧接口
4. **Format & Lint按项目约定**
- 仅在确认“会破坏 diff 可读性”前提下分批格式化(避免把重构和格式揉在一起)
5. **Verify & Report**
- 跑约定的验证命令并记录输出
- 汇总影响范围:改动文件数、主要改动点、潜在风险
## Execution Hintoptional
如果环境支持“执行型批量处理”(例如脚本执行),优先用脚本完成批量修改,然后只把**最小 diff + 摘要**交付,避免上下文膨胀与漏改。
## Output Contractstable
- Scope改动覆盖范围文件/目录/语言)
- Transformation执行的规则可复用
- Changes关键改动摘要按类别
- Verification命令 + 证据(输出/退出码/产物)
- Risks高风险点与回滚建议
## Guardrails
- 任何“全局替换”都必须先给出命中清单与排除策略
- 避免把行为重构与格式化/无关清理混在同一轮