From fable5-methodology
Executes behavior-preserving code restructuring by first establishing test coverage, then applying small transformations one at a time with verification. Refuses refactors lacking coverage.
How this skill is triggered — by the user, by Claude, or both
Slash command
/fable5-methodology:safe-refactoringThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
A refactor changes structure and preserves behavior — both halves are the definition. Without
A refactor changes structure and preserves behavior — both halves are the definition. Without a way to PROVE behavior is preserved, you are not refactoring; you are rewriting and hoping.
State in one or two lines what must be true before and after: "all existing tests pass; the
public API of billing/ is unchanged; the CLI output is byte-identical." This contract is
what "safe" means for this refactor. If any behavior IS allowed to change, that part is not a
refactor — split it out (Step 4).
Refuse (or defer pending tests) when ALL of: the code has no meaningful coverage, AND its behavior can't be cheaply characterized (nondeterminism, heavy I/O entanglement, no way to run it), AND the restructuring is more than mechanical. Say exactly that:
"This refactor isn't safe yet:
dispatch()has zero coverage and side-effects I can't capture in a harness. I can (a) write characterization tests first (~N tests), or (b) limit to mechanical renames only. Which?"
Refusing a risky refactor is a correct deliverable. A "successful" blind rewrite is a defect with a delay on it.
If you discover an actual bug mid-refactor: do NOT fix it inside the refactor. Note it, finish (or pause) the refactor to a verified state, then fix the bug as its own change with its own regression test. A diff that both moves code and changes behavior cannot be reviewed for either property. Same for improvements: new features never ride along in a refactor diff.
Full affected suite green; baseline failures unchanged; and check the contract from Step 0 directly (API surface diff, byte-compare the golden outputs). Review the diff explicitly asking one question per hunk: "could this hunk change behavior?" Any hunk answering "yes" that isn't a pure signature-propagation gets scrutiny.
Task: "Clean up report.py — 600 lines, one god function."
tests/golden/. Now every future step is checked against reality.parse_args → golden green; (2) extract load_rows → green;
(3) extract render_table → RED: one golden diff — a .strip() was lost in the move;
restore it, green (the net just paid for itself); (4) move helpers to report/lib.py →
green; (5) found an actual bug (crash on zero rows) → NOTED in report, not fixed here.The behavior contract from Step 0 is verified by executed tests (including any characterization tests written first, not after); every transformation step ran green before the next began; the diff contains zero intentional behavior changes; and any bugs discovered are reported separately — not silently fixed in, and not silently left unmentioned.
npx claudepluginhub unpaidattention/fable5-methodology --plugin fable5-methodologySafely refactors code test-first: verifies/writes tests, one structural change at a time, preserves behavior. Use for 'refactor this', 'clean this up', reorganization.
Restructures existing code without changing behavior using behavior-locking tests and incremental verification after each move.
Restructures existing code safely without changing externally observable behavior. Uses characterization tests and context-driven workflow for structural improvements.