Oma Refactor logo

Oma Refactor

OrganizationPopular
first-fluke
oma-refactor

Restructure existing code while preserving observable behavior. Use for targeted technical debt or hotspot work with characterization tests.

Overview

Publisherfirst-fluke
Repositoryoh-my-agent
Skill nameoma-refactor
Stars
1.3K
Forks
149
Bundled files
3
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by first-fluke on GitHub. Read the source before you install it.

Installation

Install the Oma Refactor AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/first-fluke/oh-my-agent.git /tmp/oh-my-agent
mkdir -p .claude/skills
cp -r /tmp/oh-my-agent/skills/oma-refactor .claude/skills/oma-refactor
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Oma Refactor in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Oma Refactor on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Oma Refactor is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Refactor Agent - Behavior-Preserving Restructuring Specialist

Scheduling

Goal

Improve internal code structure - readability first - without changing observable behavior, through small verified transformations, each gated by a safety net (tests / tooling / types) and committed separately from any behavior change.

Intent signature

  • User asks to refactor, clean up, restructure, modernize, de-duplicate, or "make this code maintainable/readable".
  • User mentions code smells, technical debt, legacy code, long methods/files, god classes, hotspots, characterization tests, or extract/move/rename transformations.
  • User asks "where should we refactor first?" or wants a refactoring plan/priority for a codebase.

When to use

  • Executing a refactoring on specific files/modules (extract, move, rename, decompose, pattern/idiom alignment)
  • Preparatory refactoring before a feature ("make the change easy, then make the easy change")
  • Legacy (brownfield) rescue: seam discovery + characterization tests, then restructuring
  • Refactoring target selection and prioritization (smells + SATD + hotspot = churn x complexity)
  • Auditing whether code is safe to refactor now (coverage breadth x mutation strength x flakiness)

When NOT to use

  • Fixing a reported bug or failing behavior -> use oma-debug (refactoring must not change behavior)
  • Security/performance/accessibility review or quality audit -> use oma-qa
  • System design, module boundary decisions, ADRs, convention changes -> use oma-architecture (a convention/pattern change is an architecture decision, not a local refactoring)
  • DB schema design or migration mechanics -> use oma-db (this skill only plans the expand-contract sequence)
  • Commit splitting / staging mechanics -> use oma-scm
  • Performance optimization as a goal -> out of scope by definition (tuning is a side effect, never the objective)

Expected inputs

  • target: file/module/path, smell report, SATD marker, or the feature request motivating preparatory refactoring
  • verification: project test command(s) per the tool registry; coverage/mutation tooling if available
  • constraints: coding guide / conventions, regulated-environment flags, merge-window concerns
  • Optional: prior metric reports, hotspot data, ADRs touching the target area

Expected outputs

  • Refactored code as a sequence of atomic, refactor-only commits (no test changes mixed in)
  • Safety-net additions when missing (characterization / golden-master tests) as separate commits
  • Before/after report: metric delta (cyclomatic/cognitive complexity, size, coupling) + readability verdict
yaml
outputs:
  - name: report
    description: refactoring plan or before/after report
    artifact: ".agents/results/refactor/*.md"
    required: false

Standalone runs write plan / before-after reports under .agents/results/refactor/; orchestrated runs (via the refactor-engineer agent) write .agents/results/result-refactor[-{sessionId}].md per the agent execution protocol.

Dependencies

  • resources/definition.md (invariant definition: 5 properties, boundaries, destination principle, naming roles, inline evidence)
  • resources/measurement.md (4-layer measurement + git forensics commands)
  • resources/governance.md (org parameters: budget floor, 500-line gate, tool registry)
  • Configured code-intelligence symbol/reference tools or native inspection; project test runners per registry (vitest / pytest / flutter_test)
  • Git history for churn/ownership/hotspot analysis

Control-flow features

  • Branches by safety-net state (greenfield vs brownfield), statefulness (code-only vs expand-contract), and verification outcome (pass vs Mikado revert)
  • Reads code/history/metrics; writes code, tests (in separate commits), and reports
  • Stops and routes to oma-architecture when the change requires a convention/boundary decision

Structural Flow

Entry

  1. Establish what motivates the refactoring (smell, SATD, hotspot, or upcoming feature) and the target scope.
  2. Diagnose the safety net for that scope: coverage of changed lines, test determinism (flakiness), mutation strength if measurable.
  3. Identify the destination form: the language idiom and codebase convention the result must match.

Scenes

  1. PREPARE: Classify greenfield (safety net exists) vs brownfield (build net first); check size gates and hotspot rank; confirm two-hats scope (no feature/bug work mixed in).
  2. ACQUIRE: Read target code via symbol tools; collect metrics (complexity, size, coupling) and git signals (churn, ownership); read the coding guide for conventions.
  3. REASON: Decompose the goal into a sequence of named atomic transformations; for stateful targets plan expand-contract; verify each step is independently verifiable and revertible.
  4. ACT: Apply ONE transformation; prefer deterministic engines (IDE rename, codemod, ast-grep) over freehand edits.
  5. VERIFY: Re-run existing tests unchanged. Pass -> commit (refactor-only) -> next transformation. Repeated failure -> Mikado: record the broken prerequisite, revert fully, recurse on the prerequisite first.
  6. FINALIZE: Before/after metric delta + readability judgment (metric improvement alone is not success); report follow-ups discovered but deliberately not done.

Transitions

  • If the safety net is missing or weak (low diff coverage, flaky, no assertions), write characterization / golden-master tests FIRST, committed separately, before touching production code.
  • If verification fails repeatedly, switch to the Mikado method: never carry a half-broken tree forward.
  • If the right fix is a convention or pattern change (new dialect), stop and route to oma-architecture for an ADR + ratchet plan.
  • If the target involves persisted state or external consumers, plan expand-contract (parallel change) with feature flags; deployment, not commit, becomes the unit of incrementality.
  • If a behavior bug is discovered mid-refactoring, record it and route to oma-debug; do not fix it in the refactor commit.
  • If the work is large enough to collide with teammates' branches, recommend announcement + short merge window; register bulk mechanical commits in .git-blame-ignore-revs.

Failure and recovery

FailureRecovery
Tests fail after a transformationMikado: record prerequisite, revert all, attack prerequisite first
No tests and code is untestableFind a seam; apply only minimal mechanical changes to inject test access, then characterize
Tests are flakyFix or quarantine flaky tests before refactoring - an unreliable net is no net
Metric improves but readability worsensReject the transformation; readability is the success criterion, metrics are proxies
Scope keeps growingStop; report the boundary issue and split into a Mikado graph or route to architecture
Refactoring engine/codemod produces wrong outputEngines are not infallible - tests re-run is mandatory; fall back to manual atomic edits

Exit

  • Success: behavior verified unchanged, structure measurably improved, readability confirmed, refactor-only commits, follow-ups reported.
  • Partial success: safety net built but restructuring deferred; or prerequisites mapped (Mikado graph) with explicit blockers.
  • Failure: blocking ambiguity (no verification path, regulated freeze, convention decision needed) reported with the recommended route.

Logical Operations

Actions

ActionSSL primitiveEvidence
Diagnose safety netVALIDATECoverage/flakiness/mutation state of target scope
Collect signalsREADMetrics, git churn/ownership, smells, SATD
Rank targetsCOMPAREHotspot = complexity x churn
Plan atomic sequenceINFERNamed transformations, Mikado graph
Write characterization testsWRITEGolden-master/snapshot tests (separate commit)
Apply transformationWRITE / CALL_TOOLOne atomic refactor, engine-first
Verify preservationVALIDATEExisting tests re-run unchanged
Commit separatelyUPDATE_STATErefactor:-typed commits only
Report deltaNOTIFYMetric + readability before/after

Tools and instruments

  • Configured code intelligence for symbol/reference/pattern impact analysis; an available semantic rename engine for renames. Native inspection remains valid, but do not replace a semantic rename with blind text replacement
  • Deterministic transformers: IDE refactoring actions, codemods (jscodeshift / OpenRewrite / ast-grep / comby)
  • Metrics: lizard / radon (complexity) — both are PyPI packages, run via uvx lizard / uvx radon so no pre-install is required; per-language linters with max-lines gates
  • Test stack per registry: vitest + StrykerJS / pytest + mutmut / flutter_test (see resources/governance.md)
  • Git forensics one-liners (see resources/measurement.md)

Canonical workflow path

  1. Diagnose: run coverage on the target scope and check test determinism; classify green/brownfield.
  2. If brownfield: find a seam, write characterization (golden-master) tests for CURRENT behavior, commit.
  3. Select targets by hotspot rank (complexity x churn), not by smell aesthetics alone.
  4. Plan a sequence of named atomic transformations toward the language-idiomatic, convention-conforming form.
  5. Loop per transformation: apply (engine-first) -> re-run tests UNCHANGED -> commit refactor: only. On repeated failure: record prerequisite, revert fully, recurse (Mikado).
  6. Finish: metric delta + readability verdict; list discovered-but-deferred work; never mix in behavior changes.

Resource scope

ScopeResource target
CODEBASETarget source, tests, coding guide, lint configs
LOCAL_FSReports under .agents/results/refactor/, .git-blame-ignore-revs
PROCESSTest runners, coverage/mutation tools, codemod engines, git log analysis
MEMORYMikado prerequisite graph, deferred follow-ups, metric baselines

Preconditions

  • A verification path exists or can be built (tests/types/tooling); otherwise the first deliverable is the safety net, not restructuring.
  • The target's conventions are known (coding guide read) or explicitly absent.

Effects and side effects

  • Mutates production code (structure only) and adds tests in separate commits.
  • Runs test/coverage/mutation commands; reads git history.
  • May write reports under .agents/results/refactor/ and entries to .git-blame-ignore-revs.
  • Never alters observable behavior, public contracts, or persisted data without an expand-contract plan.

Guardrails

  1. Behavior-preserving: the consumer contract (Hyrum-aware) is inviolable; tuning is a side effect, never a goal.
  2. Verifiable: never restructure without a net; during production refactoring tests are frozen, during test refactoring production is frozen - one side at a time.
  3. Incremental: one named transformation per commit; revert is a navigation tool (Mikado), not an accident.
  4. Economic: readability is the objective function's dominant term; do not refactor code slated for deletion or cold low-churn code.
  5. Separated (two hats): never mix behavior changes into refactor commits; tangled changes are a measured quality risk.
  6. Destination = f(language idiom, code layer, codebase convention); convention deviation requires the ADR route, not a local edit.
  7. Abstraction timing follows the Rule of Three; speculative generality is itself a smell.
  8. All metrics are proxies (Goodhart): a 499-line mechanical split, assertion-free coverage, or pattern-count gains are failures, not wins.

References

  • Local code tools: ../_shared/core/code-intelligence.md (code search/navigation)

  • Invariant definition (5 properties, boundaries, destination, naming roles, contexts, D&C, inline evidence): resources/definition.md

  • Measurement: 4 layers + git forensics commands: resources/measurement.md

  • Org parameters: budget floor, 500-line gate, tool registry: resources/governance.md

  • Context loading: ../_shared/core/context-loading.md

  • Quality principles: ../_shared/core/quality-principles.md

  • Adjacent skills: oma-debug (bugs), oma-qa (audits), oma-architecture (boundaries/ADR), oma-db (schema), oma-scm (commits)

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Oma Refactor AI skill do?

Restructure existing code while preserving observable behavior. Use for targeted technical debt or hotspot work with characterization tests.

Why use Oma Refactor on TypingMind?

Because you install it once and use it with any model. Oma Refactor is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Oma Refactor in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/first-fluke/oh-my-agent/tree/main/skills/oma-refactor. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Oma Refactor?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Oma Refactor?

As many as you like. As long as a model supports skills, you can use Oma Refactor with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Oma Refactor AI skill free?

Yes. It is published on GitHub by first-fluke under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇