Refactor
Target: $1
Focus: $2 (or general if not specified)
- Read the file thoroughly.
- Identify refactoring opportunities:
- Extract: large functions that do multiple things
- Simplify: complex conditionals that can be flattened
- Naming: variables/functions that don't communicate intent
- Duplication: repeated logic that should be a shared utility
- Early returns: replace nested if-else with guard clauses
- Data structures: arrays used where Maps/Sets would be clearer
- Async: callback hell → async/await
- Show a before/after diff for each change. Explain the reasoning.
- List any tests that should be updated (behavior must be identical).
- Ask for confirmation, then apply changes.
Rule: Do not change observable behavior. If a change would affect behavior, note it and ask separately.