refactor_to_patternlisted
Install: claude install-skill feralbureau/luminy
# refactor_to_pattern
Refactoring to a pattern is about improving structure without changing behavior. The external behavior must be identical before and after. The benefit is improved testability, separation of concerns, and long-term maintainability.
## Guiding Principle
A pattern is a solution to a recurring problem. Before applying one, confirm the problem exists in the code you're working on. Don't apply patterns speculatively — they add complexity. Apply them because the current structure is causing concrete pain (hard to test, duplicate logic, unclear responsibilities).
## Step 0: Confirm the Pattern Fits
Ask (or assess) these questions before starting:
1. What specific pain is this refactor solving? (hard to test? too much coupling? business logic leaking into the wrong layer?)
2. Is the team familiar with this pattern? A pattern nobody understands creates more problems than it solves.
3. How large is the blast radius? Patterns often require changing multiple files.
4. Are there existing tests that will serve as a safety net during the refactor?
## The Safe Refactor Loop
Use this loop for every refactor, regardless of pattern:
```
Read → Understand → Write tests (if missing) → Refactor step → Verify → Repeat
```
Never refactor without a safety net. If tests don't exist, write characterization tests first:
```python
# Characterization test — captures current behavior, even if imperfect
def test_current_behavior():
result = legacy_function(known_input)