--- name: request-refactor-plan description: Create a detailed refactor plan with tiny commits via user interview, then file it as a Jira ticket. Use when planning a refactor, creating a refactoring RFC, or breaking a refactor into safe incremental steps. autoTrigger: - when user wants to plan a refactor - when user mentions "refactor plan", "RFC", or "safe incremental steps" globs: - "**/*" --- # Request Refactor Plan Create a structured refactor plan through deep interview and codebase exploration, then file it as a Jira ticket for the team. ## What the User Provides $ARGUMENTS ## Workflow ### Step 1 — Understand the problem Ask the user for a detailed description of: - What problem they're trying to solve (not just "clean this up" — why does it matter?) - Any ideas they already have for the solution - What triggered this refactor now (new feature blocked by it? bug pattern? team pain?) ### Step 2 — Explore and verify Use the Explore agent to understand the current state: - What does the code actually look like today? - Does the problem the user described match what's in the codebase? - What's the test coverage of this area? - What other code depends on the area being refactored? - Any recent git history that explains why it got this way? Report back: "Here's what I found..." before proceeding. ### Step 3 — Consider alternatives Present 2-3 alternative approaches before interviewing on implementation. Ask: - "Have you considered [alternative]?" - "What makes your proposed approach better than [alternative]?" This surfaces assumptions and ensures the planned solution is the right one. ### Step 4 — Interview on implementation Go deep on the specifics. Be thorough — vague plans produce bad refactors: - **Scope**: What's changing? What's explicitly NOT changing? - **Interfaces**: Which public APIs / component props / service methods change shape? - **Data model**: Any schema or EF migration changes? - **Layering**: Does this change which layer owns which logic? - **Consumers**: Who calls the thing being refactored? Will they need updates? - **Feature flags**: Does this need a flag or can it land clean? - **Rollback**: If something goes wrong mid-refactor, what's the recovery plan? ### Step 5 — Assess test coverage Check the current test coverage of the area: - Frontend: are there Vitest tests for the hooks/components being changed? - Backend: are there xUnit tests for the services/repositories being changed? If coverage is insufficient, ask: "There are no tests covering [area]. How do you want to handle this — write characterization tests first, or proceed carefully with manual verification?" Don't proceed until there's a clear answer. Refactors without tests are the highest-risk code changes in the codebase. ### Step 6 — Plan tiny commits Break the refactor into the smallest possible commits. Follow Martin Fowler's rule: **every commit leaves the codebase in a working state**. Tests pass after every single step. Format each commit as: ``` [n]. Why: Risk: ``` Example pattern for a service extraction: ``` 1. Add INewService interface (no implementation yet) Why: Establishes the contract before touching anything Risk: Low — additive only 2. Implement NewService behind the interface (not wired up) Why: Build and test in isolation before integrating Risk: Low — not called yet 3. Wire NewService into DI container alongside OldService Why: Both exist simultaneously — no callers broken Risk: Low — parallel run 4. Migrate callers one at a time to NewService Why: Each migration is independently rollbackable Risk: Medium — test each caller after migration 5. Delete OldService Why: Cleanup only after all callers verified Risk: Low — all callers already migrated ``` ### Step 7 — Create the Jira ticket Write the plan to `/tmp/refactor-plan-.txt` then create the ticket: ```bash acli jira workitem create \ --project PLRS \ --type Task \ --title "Refactor: " \ --body-file /tmp/refactor-plan-.txt ``` Use this template for the body (plain text — no Jira wiki markup): ``` PROBLEM STATEMENT ----------------- SOLUTION -------- COMMIT PLAN ----------- DECISIONS --------- - Modules affected: - Interface changes: - Schema/migration changes: - API contract changes: - Key architectural decisions made: TESTING APPROACH ---------------- - What makes a good test here: only test external behavior, not internals - Modules to test: - Existing test patterns to follow: - Coverage gaps to address first: OUT OF SCOPE ------------ NOTES ----- ``` After creating the ticket, print the ticket key and a one-line summary of the plan. ### Step 8 — Offer next steps - "Want to start implementation now? (`/workspace-launch `)" - "Or leave it for sprint planning?"