write-refactor
Implement a refactor
Restructure code so it reads, factors, or layers better — without moving any observable
behavior. A refactor fails in exactly two ways: a behavior delta smuggled in under the "purely
internal" label, and a compatibility shim that quietly becomes permanent. This guide adds the
refactor discipline on top of the base implement-task rules. These are conventions the review
packet inspects — nothing enforces them at edit time.
Plan the transformation first — the workspace's change plan covers baseline, waves, and rollback; this guide is the execution half. The defining test: if any observable behavior moves, the work is no longer a refactor — it is a rewrite (behavior changes on purpose) or a migration (API A → B). Stop and say so; do not proceed under the wrong label.
Before you start, open references/task-template.md and copy it
into your task file — it is the session frame for this work; fill it in as you go (don't reconstruct
the structure from memory). It scaffolds the equivalence check, batch checkpoints, the shim table,
the deletion-safety searches, and the self-review. The task packet itself uses the kit's task
template; the baseline, batch plan, and rollback live in the change plan.