Refactor planner

From WrongStack/WrongStack · View interactive version

Refactor planner is an AI agent skill from the GitHub repository WrongStack/WrongStack. Refactor and migration planning: split large files or modules, break circular deps, untangle coupling, rename or move APIs safely. Plans behavior-preserving changes from actual dependencies, callers and tests. Use when decomposing modules, untangling coupling or sequencing a multi-file change; deliv

How to use this skill

Skill file

Refactor Planner

Selection card

Overview

Produce a reviewable sequence of changes with preserved contracts, measured

risks and executable checks. Separate behavior-preserving refactoring from

requested behavior changes so their validation is clear.

Rules

  1. Derive dependency and reverse-call edges from source or a current index.

State arrow direction; include dynamic registration and public consumers.

  1. Identify invariants before moving code: identity, error semantics, side

effects, serialization, lifecycle ownership and module initialization.

  1. Estimate risk from evidence: callers, statefulness, concurrency, public API

and meaningful tests. Missing coverage data is unknown, not an invented score.

  1. Characterize unprotected behavior before changing risky paths; raw coverage

percentages do not prove the important cases are protected.

  1. Make each checkpoint buildable and testable. A small refactor can be one

step; do not force three phases, feature flags or a minimum task duration.

  1. Preserve dirty work. Rollback means reversing the owned change or a

separable commit when authorized, never overwriting a shared checkout.

  1. Detect and use the repository's actual language and verification toolchain; never introduce compiler/type/lint suppressions (as any, @ts-ignore, # type: ignore, #[allow(...)], //nolint) to force a refactoring step green, and finish immediately once the planned or authorized steps are verified.

Workflow

  1. Map scope, closest existing conventions, dependents and tests.
  2. Name the problem and observable improvement: reduce coupling, isolate state,

remove a cycle, clarify an API. Line count alone is not a correctness goal.

  1. Analyze cycles as strongly connected components. Break the relevant coupling

if it blocks the intended change; an unrelated cycle need not halt the work.

  1. Sequence the smallest coherent moves. Keep compatibility shims only when

consumers need them, and give each a removal condition.

  1. For each step, record paths, dependencies, preserved contracts, check command,

exit condition and a rollback that someone else can perform.

  1. Return the plan for a planning-only request. When execution is already

requested, use this plan to implement and verify within the same task.

Move patterns

Plan shape

| Step | Paths / change | Depends on | Risk evidence | Validation | Rollback |

|---|---|---|---|---|---|

| <step> | <concrete scope> | <real prerequisite> | <callers/state/tests> | <command + assertion> | <owned reversal> |

Mark estimates as ranges with assumptions. Do not invent metrics or require

parallel agents solely because the target contains many files.

Before returning

Skills in scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.