Night refactor
One iteration tackles one bounded hypothesis, using improve, test-everything, review-code
for the craft. Read the shared contract in ../night/references/loop-interface.md;
this skill supplies the target, evidence and stopping rules.
Activation
- Use for a bounded complexity problem with behaviour that can be characterised.
- Not for feature changes or public API redesign; route those to a separate owner decision.
- Read the handoff first and avoid repeating a target already resolved by earlier iterations.
Workflow
- Baseline: Record public API and current outputs; add and pass characterisation tests before moving code.
- Choose: Choose one simplification with a concrete measure such as branches, duplication or dependencies.
- One change: Use
improvewithin a cap of fewer than 300 changed lines, including tests, per iteration. - Check: Run
test-everythingand usereview-codeto compare behaviour, API and the complexity measure. - Hand back: run fast checks and report evidence, including failed or unavailable commands. The supervisor re-runs checks and decides keep/revert; never weaken tests or assertions.
Evaluation
- Keep: Characterisation and existing checks pass, the public API is unchanged and complexity drops.
- Revert: Observable behaviour changes, the diff reaches 300 changed lines or the complexity benefit is absent.
- Inconclusive: missing evidence or unavailable checks cannot count as a successful iteration.
- Record baseline and candidate results with exact commands so the supervisor can repeat them.
Stop conditions
- The next useful refactor cannot fit the cap; propose a smaller independent step.
- No defensible simplification remains, or behaviour cannot be characterised safely.
- Stop at the supplied time or iteration limit; report the next bounded hypothesis.
Examples
- Day: "run night-refactor on the parser internals" investigates one target with the owner watching.
- Night:
/night refactorrepeats bounded iterations within the supplied budget, with each outcome independently evaluated by the supervisor.
End the final message with NIGHT_RESULT: {json} using the shared contract's fields.
Report evidence rather than grading your own result. Include changed paths and reproducible checks.