通用编程33k · #9141
refactor-safely
它能做什么
这个技能指导智能体使用 code-review-graph 工具安全地重构代码。适合想重命名或重组代码、又不破坏其他部分的开发者。
适用场景
- ✓当你想在整个代码库中重命名某个函数或类时。
- ✓当你需要找出没有被引用的死代码时。
- ✓当你计划拆分大型函数,并想先查看它的依赖项时。
技能链接
https://github.com/tirth8205/code-review-graph/blob/staging/skills/refactor-safely/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
请用这个技能帮我:https://github.com/tirth8205/code-review-graph/blob/staging/skills/refactor-safely/SKILL.md
阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
npx skills add tirth8205/code-review-graph --skill refactor-safely
下载 SKILL.md,放进智能体的技能文件夹。
curl -L https://raw.githubusercontent.com/tirth8205/code-review-graph/staging/skills/refactor-safely/SKILL.md -o SKILL.md
可以这样问 AI
“能把函数 calculateTotal 在所有地方都改名为 computeOrderTotal 吗?先给我看它会改动哪些地方。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体请求图谱提供重命名预览及其编辑列表,向你展示该列表,并且只在你确认后才应用修改。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Refactor Safely
Plan a refactor from the dependency graph and apply renames from a preview.
Steps
- Call
refactor_toolwithmode="suggest"for refactoring candidates, ormode="dead_code"for unreferenced code. - For a rename, call
refactor_toolwithmode="rename",old_nameandnew_name. Check the returned edit list before applying. - Call
apply_refactor_toolwith the returnedrefactor_idto apply the rename. - Before a large refactor, call
get_impact_radius_toolandget_affected_flows_toolto see the dependents and critical paths involved. - Call
find_large_functions_toolto find functions worth splitting. - After the change, call
detect_changes_toolto confirm the impact matches the plan.
Token Efficiency Rules
- Call
get_minimal_context_tool(task="<your task>")before any other graph tool. - Pass
detail_level="minimal"wherever a tool accepts it. Use "standard" only when minimal is not enough. - Prefer a targeted
query_graph_toolcall over a broad listing call. - Budget: about five tool calls and 800 tokens of graph output per task.
- Read the implementation and its tests before changing code. The graph narrows scope; it does not replace the source.
常见问题
会不经预览就应用修改吗?
不会。技能说明,在应用重命名之前应先检查返回的编辑列表。
能找出未使用的代码吗?
能。死代码模式会列出没有被引用的代码。
之后还需要做什么检查?
技能建议运行一次变更检测步骤,以确认影响范围与计划一致。
详情
热度
- GitHub 星标
- 33k
- 排名
- #9141
- 许可证
- MIT
- 更新时间
- 2026/10/29
评论
- …