skills/refactoring-surgeon/SKILL.md
Expert code refactoring specialist for improving code quality without changing behavior. Activate on: refactor, code smell, technical debt, legacy code, cleanup, simplify, extract method, extract class, DRY, SOLID principles. NOT for: new feature development (use feature skills), bug fixing (use debugging skills), performance optimization (use performance skills).
npx skillsauth add curiositech/windags-skills refactoring-surgeonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Expert code refactoring specialist focused on improving code quality without changing behavior.
| Category | Techniques | |----------|------------| | Extraction | Extract Method, Extract Class, Extract Interface | | Movement | Move Method, Move Field, Inline Method | | Simplification | Replace Conditional with Polymorphism, Decompose Conditional | | Organization | Introduce Parameter Object, Replace Magic Numbers | | Legacy Migration | Strangler Fig, Branch by Abstraction, Parallel Change |
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ Long Method │ │ Large Class │ │ Long Parameter │
│ > 20 lines? │ │ > 200 lines? │ │ List │
│ → Extract Method │ │ → Extract Class │ │ → Parameter Object │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ Switch Statements │ │ Refused Bequest │ │ Parallel │
│ Type-checking? │ │ Unused inheritance?│ │ Hierarchies │
│ → Polymorphism │ │ → Delegation │ │ → Move Method │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
┌─────────────────────┐ ┌─────────────────────┐
│ Divergent Change │ │ Shotgun Surgery │
│ One class, many │ │ One change, many │
│ reasons to change? │ │ classes affected? │
│ → Extract Class │ │ → Move/Inline │
└─────────────────────┘ └─────────────────────┘
Complete refactoring examples in ./references/:
| File | Pattern | Use Case |
|------|---------|----------|
| extract-method.ts | Extract Method | Long methods → focused functions |
| replace-conditional-polymorphism.ts | Replace Conditional | switch/if → polymorphic classes |
| introduce-parameter-object.ts | Parameter Object | Long params → structured objects |
| strangler-fig-pattern.ts | Strangler Fig | Legacy code → gradual migration |
Symptom: Rewriting entire modules in one massive change Fix: Strangler fig pattern, small incremental changes with tests
Symptom: Changing structure without test coverage Fix: Write characterization tests first, add coverage for affected areas
Symptom: Creating generic frameworks "for future flexibility" Fix: Wait for three concrete examples before abstracting (Rule of Three)
Symptom: Find-and-replace that misses occurrences Fix: Use IDE refactoring tools, search for usages first
Symptom: Adding new functionality while restructuring Fix: Separate commits - refactor first, then add features
Symptom: Large refactoring PRs that are hard to review Fix: Small, focused PRs with clear commit messages
Symptom: Three layers of abstraction for a simple operation Fix: YAGNI - start concrete, abstract when patterns emerge
Symptom: Starting Extract Method but leaving partial duplication Fix: Complete the refactoring or revert - no half-measures
Symptom: "I'll just clean this up while I'm here..." Fix: Never refactor during incidents - fix the bug, create a ticket
Symptom: Refactoring without knowing if it helped Fix: Track metrics: complexity, test coverage, build time
Before Refactoring:
During Refactoring:
After Refactoring:
Run ./scripts/validate-refactoring.sh to check:
tools
Building resilient distributed systems with circuit breakers, retries with full-jitter exponential backoff, retry budgets (per-request 3-attempt + per-client 10% ratio per Google SRE), deadline propagation, and the cascading-failure math (4 layers × 3 retries = 64x amplification). Grounded in Resilience4j, Microsoft Cloud Patterns, AWS Architecture Blog (Marc Brooker), and Google SRE Book.
testing
Designing HTTP cache headers that work correctly across browsers, CDNs, and shared proxies — `Cache-Control` directives per RFC 9111, `stale-while-revalidate` and `stale-if-error` per RFC 5861, the Vary header for varying responses, and surrogate keys for tag-based purging. Grounded in IETF RFCs and Cloudflare/Fastly docs.
development
Use when designing or fixing a Content Security Policy on a real site, choosing between nonce-based and hash-based CSP, adding strict-dynamic, debugging "Refused to execute inline script" errors, deploying CSP in report-only mode first, configuring report-to / report-uri, or auditing an existing policy for unsafe-inline / unsafe-eval / wildcards. Triggers: "CSP blocks legitimate inline script", strict-dynamic, nonce-{RANDOM}, sha256-{HASH}, object-src none, base-uri none, frame-ancestors, Trusted Types, X-Content-Security-Policy obsolete, report-only vs enforced. NOT for general HTTP security headers (HSTS, COOP/COEP), Trusted Types deep dive, CORS configuration, or building a WAF.
tools
Choosing and operating an HTTP API versioning strategy that doesn't break clients — Stripe's date-based pinned versions, the Deprecation/Sunset header pair (RFC 9745 + RFC 8594), URI vs header vs media-type approaches, and the version-transformer pattern. Grounded in Stripe's published architecture and IETF RFCs.