Refactor Safely

tirth8205/code-review-graph/skills/refactor-safely

作者 tirth82056b12d11625cbec3b6773e076cb3d136464fa90e5无许可证收录于 2026年10月9日更新于 2026年10月9日

Plan and execute safe refactoring using dependency analysis

AI 生成的概览

利用依赖图分析并预览重命名,规划并执行安全的代码重构。

功能
引导智能体完成重构流程:给出重构候选或死代码建议,预览重命名并按 refactor id 应用,在大型改动前查看影响范围和受影响的调用流。它还能找出值得拆分的大型函数,并在改动后确认检测到的变更与计划一致。该技能包含图工具调用的令牌效率规则,并提醒智能体在改代码前阅读实现与测试。
适用场景
适用于重构现有代码的场景,例如重命名符号、删除未被引用的代码或拆分大型函数,也适用于在应用改动前评估影响范围。适合具备依赖图、可用于缩小范围的代码库。
运行要求
需要指令中提到的重构与图工具(refactor_tool、apply_refactor_tool、get_impact_radius_tool、get_affected_flows_tool、find_large_functions_tool、detect_changes_tool、get_minimal_context_tool、query_graph_tool)。不附带脚本,仅为指令。

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.

来源与署名

来源:tirth8205/code-review-graph位于skills/refactor-safely提交6b12d11

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架