oma-refactor

Plans and executes behavior-preserving code refactoring with characterization tests, hotspot analysis, and atomic commits.

1.3k|146|Updated Jan 30, 2026
One-click install
npx skills add https://github.com/first-fluke/oh-my-agent --skill oma-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: oma-refactor
Source: https://github.com/first-fluke/oh-my-agent/tree/main/.agents/skills/oma-refactor
Command: npx skills add https://github.com/first-fluke/oh-my-agent --skill oma-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactoring without a safety net risks silently changing behavior, and teams often don't know which code to refactor first or whether their tests would even catch a regression. This Skill enforces disciplined, verifiable restructuring: it diagnoses test coverage before touching code, ranks targets by complexity and churn, and commits each transformation separately so behavior changes never hide inside refactors.

Core Features & Use Cases

  • Safety-net diagnosis and characterization tests: Classifies targets as greenfield or brownfield, checks coverage/flakiness/mutation strength, and writes golden-master tests before restructuring legacy code.
  • Hotspot-driven target selection: Combines static complexity metrics (radon, lizard) with git forensics (churn, bug-fix history, SATD markers) to rank what to refactor first.
  • Atomic transformation workflow: Applies one named transformation per commit using engine-first tools (Serena rename_symbol, codemods, ast-grep), re-running unchanged tests after each step, with Mikado-method revert-and-recurse recovery on failure.
  • Use Case: You inherit a legacy module with no tests and several 800-line files. The Skill finds a seam, writes characterization tests pinning current behavior, then executes an extract-and-rename sequence as separate refactor-only commits, ending with a before/after complexity and readability report.

Quick Start

Ask the agent to refactor the legacy module at src/payments into smaller behavior-preserving commits, building characterization tests first if coverage is missing.

Frequently Asked Questions about oma-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely refactor legacy code that has no tests?

Build a safety net first: find a seam with minimal mechanical changes, then write characterization or golden-master tests that pin current behavior, bugs included. Commit those tests separately before restructuring any production code.

How do I decide which files to refactor first?

Rank targets by hotspot score: static complexity from tools like lizard or radon multiplied by change frequency from git history. Add SATD markers such as TODO and FIXME as a third independent signal, and avoid refactoring cold low-churn code.

What is the Mikado method in refactoring?

The Mikado method handles failed transformations: when a change breaks tests repeatedly, record the broken prerequisite, revert the working tree fully, and recursively attack the prerequisite first. It treats revert as a navigation tool rather than a failure.

When should I not refactor code?

Skip code about to be deleted, cold stable low-churn code, and anything right before a release. Also stop when the real fix is a convention or boundary change, which requires an architecture decision record instead of a local edit.

Can refactoring commits include bug fixes found along the way?

No. The two-hats rule forbids mixing behavior changes into refactor commits because tangled commits make preservation unreviewable. Record the discovered bug and route it to a separate debugging workflow.