Refactor

From KRISACHAN/ying-practice · View interactive version

Refactor is an AI agent skill from the GitHub repository KRISACHAN/ying-practice. Execute an explicitly approved refactor plan or scope using small behavior-preserving transformations with continuous verification and a final scope-level convergence check. By default complete the approved scope in one pass; do not invent a new architecture while implementing.

How to use this skill

Skill file

Refactor

Implement an approved refactor safely and efficiently.

Read:

Load the approved Refactor Plan or equivalently precise user-authorized scope and target-project rules first.

Preconditions

If these are missing, do not substitute your own broad redesign.

Default Execution Model

Default to executing the whole approved scope in one coherent implementation pass.

A plan may contain multiple Work Items. Treat them as an ordered checklist inside the same task, not as separate lifecycle gates.

Only stop between Work Items when:

Do not pause merely because one internal Work Item finished.

Workflow

  1. Baseline — run relevant pre-change checks or establish existing failures.
  2. Protect behavior — add focused characterization/regression coverage first when risk is high and protection is missing.
  3. Execute Work Items in order — rename/extract/move/simplify before introducing new abstractions; use Strategy/Plugin/Port only when the approved design and real variation justify them.
  4. Verify during execution — run focused tests/typecheck/lint at meaningful risk boundaries, not mechanically after every trivial edit.
  5. Do not hide failures — do not weaken tests, widen catch blocks, suppress types/lint, or change error semantics merely to make checks pass.
  6. Synchronize code-level knowledge when directly affected — update structured comments that are made stale by changed responsibility, capability, boundary, invariant, lifecycle, or tradeoff. Do not run a repository-wide comment campaign unless explicitly requested; $code-comments exists for dedicated comment work.
  7. Synchronize engineering docs when directly affected — update README/AGENTS/ADR/index documents required to keep changed structure/contracts/navigation accurate. Do not run a broad documentation rewrite unless explicitly requested; $engineering-documentation exists for dedicated documentation work.
  8. Scope-level regression — after the approved scope is complete, run the package/app/integration/E2E gates required by the plan and blast radius.
  9. Hotspot convergence check — revisit the audit/plan Hotspot Watchlist and any new hotspots created by the refactor. Do not declare a structural refactor complete merely because tests pass while obvious mixed-responsibility hotspots remain.
  10. Convergence check — confirm the target state is reached, preserved contracts remain intact, unrelated behavior did not drift, hotspot dispositions are resolved, and directly affected code comments/engineering docs are synchronized or explicitly deferred.

Hotspot Convergence Check

Large or long files are review triggers, not automatic defects. LOC must never be the sole reason to split a file, but major hotspots must be consciously re-evaluated before completion.

For every major pre-existing hotspot and any significant new hotspot, ask:

Allowed outcomes:

A hotspot may remain large. What is not acceptable is leaving it unexamined or claiming structural completion solely from green verification.

Do not chase arbitrary file-size targets. Avoid replacing one large file with many pass-through wrappers, Manager/Helper/Processor shells, or abstractions that only relocate complexity.

Boundaries

Completion Output

Report:

A failed required check means the scope is not complete.

Do not automatically invoke or require code-review. The user decides whether independent review is needed and how often.

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.