{"manifest":{"name":"Refactor Planner","version":"1.0.0","description":"Analyze messy code and produce a safe, incremental refactor plan with risk assessment, rollback strategy, and a test-first checklist.","tags":["refactoring","code-quality","architecture","workflow","agent"],"standard":"agentskills.io","standard_version":"1.0","content_checksum":"245dd5bdb72ded8cf6c7d4006b180e49252806d8149a0736ef035df87cf427fe","bundle_checksum":null,"metadata":{},"files":[]},"files":{"SKILL.md":"# Refactor Planner\n\n> **Purpose:** Analyze a code file, module, or system component and produce a safe, incremental refactor plan with risk assessment, rollback strategy, and a test-first validation checklist. Prevents big-bang rewrites that break production.\n\n---\n\n## Invocation\n\n```\n/refactor <file-or-description>\n```\n\n**Examples:**\n- `/refactor src/lib/auth.ts`\n- `/refactor The checkout flow uses a 400-line switch statement with no error handling`\n\n---\n\n## Analysis Steps\n\n### Step 1: Diagnose Current State\n\nIdentify code smells present:\n- **Long methods**: functions > 50 lines\n- **Deep nesting**: conditionals > 3 levels deep\n- **God object**: class or module doing too many things\n- **Duplicated logic**: same pattern repeated 3+ times\n- **Magic numbers/strings**: unnamed constants\n- **Missing error handling**: silent failures, swallowed exceptions\n- **Coupling**: this code is hard to test in isolation because it depends on X\n\nMap dependencies:\n- What calls this code?\n- What does it call?\n- What would break if its interface changed?\n\nAssess test coverage:\n- Is this code protected by tests?\n- If NO: tests must be written BEFORE refactoring begins\n\n---\n\n### Step 2: Define Target State\n\n- What will the code look like after refactoring?\n- What pattern or principle does this refactor apply?\n  - Extract Method, Extract Class, Strategy Pattern, Repository Pattern, etc.\n- What concrete metrics improve?\n  - Fewer lines, reduced cyclomatic complexity, better separation of concerns\n\n---\n\n### Step 3: Risk Assessment\n\n| Risk | Likelihood | Impact | Mitigation |\n|------|------------|--------|------------|\n| Breaking change to public API | Medium | High | Add adapter layer |\n| Missing test coverage | High | High | Write tests first (blocker) |\n| Concurrent modification by team | Low | Medium | Use a feature branch |\n| Performance regression | Low | High | Benchmark before and after |\n\n---\n\n### Step 4: Implementation Plan\n\nProduce a numbered task list — each step independently verifiable:\n\n```\n[ ] 0. PREREQUISITE: Write tests covering current behavior (if missing)\n[ ] 1. [Smallest safe change] — run tests, must pass\n[ ] 2. [Next change] — run tests, must pass\n[ ] 3. [Next change] — run tests, must pass\n...\n[ ] N. Delete dead code confirmed unreachable after refactor\n[ ] N+1. Update documentation and comments\n```\n\n---\n\n### Step 5: Rollback Plan\n\n- How to revert if something breaks in production?\n- Is this behind a feature flag? (recommended for risky refactors)\n- What is the blast radius if it fails? (1 endpoint, 1 user flow, entire app?)\n\n---\n\n## Output Format\n\n```\n## Refactor Plan: [Module/File Name]\n\n### Current State\n[Code smells identified, complexity metrics]\n\n### Target State\n[What it looks like after, patterns applied]\n\n### Risk Assessment\n[Table]\n\n### Prerequisites\n[Tests that must exist before starting]\n\n### Implementation Steps\n[Numbered checklist]\n\n### Rollback Strategy\n[How to revert]\n\n### Definition of Done\n- [ ] All pre-existing tests still pass\n- [ ] New tests cover the refactored logic\n- [ ] No public API surface changed (or migration provided)\n- [ ] Code reviewed by one other engineer\n```\n\n---\n\n## Rules\n\n- **Tests before refactoring** is non-negotiable — stop if coverage is missing and say so\n- Each step must pass tests independently — no \"it'll work when step 5 is done\"\n- Never rename a public API without a deprecation period\n- Prefer 10 small safe steps over 1 big clever change\n- If the refactor requires more than 500 lines changed: propose splitting into phases\n"}}