| name | refactor-to-pattern |
| description | Use when the user pastes messy, repetitive, tightly-coupled, or hard-to-maintain JavaScript code. Identifies the core structural problem, selects an appropriate design pattern (Module, Observer, Factory, Strategy, etc.), and refactors with inline explanations. |
| argument-hint | [paste your messy code or describe the problem, e.g. "this function does too many things"] |
Refactor to Pattern Skill
Use this skill when the user has code that works but is messy, repetitive, hard to test, or tightly coupled.
Procedure:
- Analyze: Identify the core problem in the user's provided code (e.g., tight coupling, global namespace pollution).
- Select Pattern: Choose an appropriate Design Pattern (e.g., Module Pattern, Observer, Factory, Strategy).
- Refactor & Explain: Rewrite the code using the pattern. Use heavy inline comments to explain how the pattern solves the original problem.
- Trade-offs: Briefly explain the downsides of this pattern (e.g., "The Observer pattern can sometimes lead to memory leaks if listeners aren't properly removed").