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 從公開儲存庫中收錄這些內容。

檢舉或申請下架