Martin Fowler Refactoring Advisor
Analyzes code for smells using Martin Fowler's Refactoring catalog, conducts a grill-me-style interview to understand the requirement, proposes a structured plan with Before/After design, and applies changes only after explicit user approval — ensuring zero breaking changes to existing callers.
Pattern catalog and code smell reference: references/fowler-patterns.md
⚠️ Operating Principles
- Explicit invocation only: Does not auto-trigger on casual language like "clean this up". Activates when the user explicitly calls
/fowler-refactor-skill or mentions refactoring with clear intent.
- Zero Side-Effect / Backward Compatibility: Public interfaces (function signatures, props, return types) are preserved 100%. No breaking changes to existing callers. Non-breaking structure is non-negotiable.
- Propose before touching: A refactoring proposal (report) is presented first. Code is modified only after the user approves — or after feedback is incorporated.
- One question at a time (
grill-me): If the scope or intent is unclear, ask one focused question with a recommended answer until the three core axes are resolved.
Workflow
[1. Requirements Analysis (grill-me interview)]
↓
[2. Fowler Pattern Mapping & Proposal Report]
↓
[3. User Feedback Loop & Approval]
↓
[4. Code Application & Verification]
Step 1 — Requirements Analysis (grill-me)
If the target file or refactoring intent is ambiguous, run the interview below.
Interview Rules
- One question at a time.
- Provide a 💡 Recommended answer with each question.
- If the answer can be found by reading the codebase directly, read it — do not ask.
Three Core Axes (resolve all three, then stop asking)
- Target / Scope — specific function, component, module, or file
- Problem / Code Smell — what hurts: long function, duplicated logic, deep nesting, tight coupling, etc.
- Constraints — interfaces to preserve, presence of tests, external API contracts
Step 2 — Fowler Pattern Mapping & Proposal Report
Read references/fowler-patterns.md and map the identified smells to the most appropriate patterns. Output the following report:
## 🔍 Refactoring Proposal
### 1. Target & Identified Code Smells
- **Target**: `path/to/File.ts`
- **Smells**:
- 🦨 **[Smell name]** — [why it hurts]
### 2. Recommended Fowler Patterns
- 🎯 **[Pattern name]** — [why this pattern addresses the smell]
- 🎯 **[Pattern name]** — [why this pattern addresses the smell]
### 3. Before vs After Design
#### Before
```ts
// current structure (summarised)
After
// refactored structure (interfaces / key extractions)
4. Compatibility & Side-Effect Guarantee
- Public interface preserved: [yes/no + details]
- Callers impacted: [none / list]
- Safety notes: [defaults, fallbacks, migration notes if any]
5. Expected Benefits
- [readability, cohesion, testability, OCP compliance, etc.]
---
## Step 3 — Feedback Loop & Approval
- After presenting the proposal, ask the user if they have additional requests or concerns.
- Update the proposal to reflect feedback.
- **Do not touch code** until the user gives explicit approval ("apply", "go ahead", "confirmed", etc.).
---
## Step 4 — Code Application & Verification
Once approved, apply changes in this order:
1. **Non-breaking code changes**
- Apply the minimum change required.
- Preserve all public interfaces and call sites.
- Follow the project's existing style conventions (arrow functions, destructuring, naming, etc.).
2. **Static verification**
- Run type-check / lint (`lsp_diagnostics` or project's own `tsc --noEmit` / `eslint`) to confirm zero type and reference errors.
- Confirm existing call sites compile without modification.
3. **Format & organize**
- Apply the project's formatter (Prettier / Biome / gofmt / rustfmt — whatever is configured) on modified files.
4. **Report**
- List modified files and summarize what changed and what was intentionally left unchanged.
1---2name: fowler-refactor-skill3description: Analyze code using Martin Fowler's refactoring catalog (Extract Function, Decompose Conditional, Replace Conditional with Lookup Table, Split Phase, etc.) and propose safe, backward-compatible improvements via a structured interview. Use when asked to refactor, improve code structure, remove code smells, introduce indirection layers, or when invoking /fowler-refactor-skill explicitly.4---56# Martin Fowler Refactoring Advisor78Analyzes code for smells using Martin Fowler's *Refactoring* catalog, conducts a `grill-me`-style interview to understand the requirement, proposes a structured plan with Before/After design, and applies changes only after explicit user approval — ensuring zero breaking changes to existing callers.910> Pattern catalog and code smell reference: [references/fowler-patterns.md](./references/fowler-patterns.md)1112---1314## ⚠️ Operating Principles15161. **Explicit invocation only**: Does not auto-trigger on casual language like "clean this up". Activates when the user explicitly calls `/fowler-refactor-skill` or mentions refactoring with clear intent.172. **Zero Side-Effect / Backward Compatibility**: Public interfaces (function signatures, props, return types) are preserved 100%. No breaking changes to existing callers. Non-breaking structure is non-negotiable.183. **Propose before touching**: A refactoring proposal (report) is presented first. Code is modified only after the user approves — or after feedback is incorporated.194. **One question at a time (`grill-me`)**: If the scope or intent is unclear, ask one focused question with a recommended answer until the three core axes are resolved.2021---2223## Workflow2425```26[1. Requirements Analysis (grill-me interview)]27 ↓28[2. Fowler Pattern Mapping & Proposal Report]29 ↓30[3. User Feedback Loop & Approval]31 ↓32[4. Code Application & Verification]33```3435---3637## Step 1 — Requirements Analysis (`grill-me`)3839If the target file or refactoring intent is ambiguous, run the interview below.4041### Interview Rules42- **One question at a time.**43- Provide a **💡 Recommended answer** with each question.44- If the answer can be found by reading the codebase directly, read it — do not ask.4546### Three Core Axes (resolve all three, then stop asking)471. **Target / Scope** — specific function, component, module, or file482. **Problem / Code Smell** — what hurts: long function, duplicated logic, deep nesting, tight coupling, etc.493. **Constraints** — interfaces to preserve, presence of tests, external API contracts5051---5253## Step 2 — Fowler Pattern Mapping & Proposal Report5455Read [references/fowler-patterns.md](./references/fowler-patterns.md) and map the identified smells to the most appropriate patterns. Output the following report:5657```markdown58## 🔍 Refactoring Proposal5960### 1. Target & Identified Code Smells61- **Target**: `path/to/File.ts`62- **Smells**:63 - 🦨 **[Smell name]** — [why it hurts]6465### 2. Recommended Fowler Patterns66- 🎯 **[Pattern name]** — [why this pattern addresses the smell]67- 🎯 **[Pattern name]** — [why this pattern addresses the smell]6869### 3. Before vs After Design7071#### Before72```ts73// current structure (summarised)74```7576#### After77```ts78// refactored structure (interfaces / key extractions)79```8081### 4. Compatibility & Side-Effect Guarantee82- **Public interface preserved**: [yes/no + details]83- **Callers impacted**: [none / list]84- **Safety notes**: [defaults, fallbacks, migration notes if any]8586### 5. Expected Benefits87- [readability, cohesion, testability, OCP compliance, etc.]88```8990---9192## Step 3 — Feedback Loop & Approval9394- After presenting the proposal, ask the user if they have additional requests or concerns.95- Update the proposal to reflect feedback.96- **Do not touch code** until the user gives explicit approval ("apply", "go ahead", "confirmed", etc.).9798---99100## Step 4 — Code Application & Verification101102Once approved, apply changes in this order:1031041. **Non-breaking code changes**105 - Apply the minimum change required.106 - Preserve all public interfaces and call sites.107 - Follow the project's existing style conventions (arrow functions, destructuring, naming, etc.).1081092. **Static verification**110 - Run type-check / lint (`lsp_diagnostics` or project's own `tsc --noEmit` / `eslint`) to confirm zero type and reference errors.111 - Confirm existing call sites compile without modification.1121133. **Format & organize**114 - Apply the project's formatter (Prettier / Biome / gofmt / rustfmt — whatever is configured) on modified files.1151164. **Report**117 - List modified files and summarize what changed and what was intentionally left unchanged.