跳到正文
Skillpedia
通用编程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 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“能把函数 calculateTotal 在所有地方都改名为 computeOrderTotal 吗?先给我看它会改动哪些地方。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体请求图谱提供重命名预览及其编辑列表,向你展示该列表,并且只在你确认后才应用修改。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Refactor Safely

Plan a refactor from the dependency graph and apply renames from a preview.

Steps

  1. Call refactor_tool with mode="suggest" for refactoring candidates, or mode="dead_code" for unreferenced code.
  2. For a rename, call refactor_tool with mode="rename", old_name and new_name. Check the returned edit list before applying.
  3. Call apply_refactor_tool with the returned refactor_id to apply the rename.
  4. Before a large refactor, call get_impact_radius_tool and get_affected_flows_tool to see the dependents and critical paths involved.
  5. Call find_large_functions_tool to find functions worth splitting.
  6. After the change, call detect_changes_tool to 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_tool call 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.
常见问题

会不经预览就应用修改吗?

不会。技能说明,在应用重命名之前应先检查返回的编辑列表。

能找出未使用的代码吗?

能。死代码模式会列出没有被引用的代码。

之后还需要做什么检查?

技能建议运行一次变更检测步骤,以确认影响范围与计划一致。

详情

作者的原始描述

Plan and execute safe refactoring using dependency analysis

repo: tirth8205/code-review-graph

热度

GitHub 星标
33k
排名
#9141
许可证
MIT
更新时间
2026/10/29

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能