agentleFS
DnsQueenDnsQueen/orcinus-skills/skills/refactor/SKILL.md

refactor

Skill1 starsChanged 5 days agoMITView on GitHub

Safe, behavior-preserving code refactoring for any language. Detects smells (Bloat, OO, Couplers, Layers), applies Fowler & MVVM/Clean Architecture patterns, and runs tests per step. Triggers: refactor, clean up, extract, rename, simplify, decompose, god class, MVVM, Clean Architecture. Only invoke via the orcinus router.

196 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use ascii-diagram, debug-fix and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 projects that use this

  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • parcadeiSkill

    agent-context-isolation

    Agent Context Isolation

    Also in 3 projects that use this

  • parcadeiSkill

    agentica-infrastructure

    Reference guide for Agentica multi-agent infrastructure APIs

    Also in 3 projects that use this

  • +8 more from parcadei

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 169 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Behavior is preserved: Every change leaves the program doing exactly the same thing externally.

    line 17
  2. Distinctive:

    One operation at a time: No bundling multiple logical changes into one step.

    line 18
  3. Distinctive:

    Tests gate every step: Run tests after each edit.

    line 19
  4. Distinctive:

    Read target file(s) completely

    line 79
  5. Very specific:

    Read safety.md §8 in full

    line 88
  6. Very specific:

    Never Guess File Paths: Always run search or directory listing tools (like grep_search or list_dir) to confirm the exact location of a file …

    line 98
  7. Distinctive:

    Use Structured Diffs: Always generate precise before-and-after summaries for edits to ensure the changes are atomic and understandable.

    line 101
  8. Distinctive:

    Re-Read Before Edit: If you haven't viewed a file in the last 10 minutes, re-read it before making any edits.

    line 107
  9. Distinctive:

    Commit/Stash Tracking: Check git status frequently to ensure you know exactly what is modified and avoid editing files with unstaged, …

    line 109
  10. Distinctive:

    Does not change external behavior without user approval

    line 115
  11. Distinctive:

    Does not fix bugs while refactoring (separate concerns)

    line 116
  12. Distinctive:

    Does not apply multiple operations in one edit

    line 117
  13. Distinctive:

    Does not refactor code it hasn't read

    line 118
  14. Distinctive:

    Does not skip tests "just this once"

    line 119

“Common” is measured: kept by at least 6 in 10 of the 169 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactoring Specialist

Safe, incremental, behavior-preserving code improvements for any language.

Core Contract

  1. Behavior is preserved. Every change leaves the program doing exactly the same thing externally. If a change alters behavior, it is not a refactoring — it is a feature change requiring explicit user opt-in.
  2. One operation at a time. No bundling multiple logical changes into one step. Each step is independently verifiable and revertable.
  3. Tests gate every step. Run tests after each edit. If tests fail, revert immediately — do not fix forward.

Quick Reference

[!TIP] Token Efficiency: These reference files are large. Do not read them in full. Use grep_search to find your target topic first, then view only its specific line range.

What you needReference file
Step-by-step process to follow every timeprocess.md
Detect smells before choosing an operationsmells.md
When to stop, warn, or asksafety.md
Extract, Inline, Split, Decomposecatalog-composing.md
Conditionals, Guards, Polymorphismcatalog-simplifying.md
Move, Organize, Encapsulatecatalog-organizing.md
Rename, Parameter Objects, Factorycatalog-api.md
Inheritance, Composition over Inheritancecatalog-inheritance.md
FP, Async, Reactive, DI patternscatalog-modern.md
MVVM, MVP, Repository, Use Case, Clean Architecturecatalog-architecture.md
Language idioms and test commandslanguage-profiles.md

Decision Tree

"Just refactor this" / "clean this up" / "this smells" (no specific operation given) → Read smells.md. Diagnose. Present ranked findings. Confirm priority with user. Then follow process.md.

Specific operation requested (e.g., "extract this into a function", "rename X to Y") → Check safety.md for red lines. If clear, go directly to process.md §4 Execution Loop.

Large file or large codebase (file >500 lines, or change touches >3 files) → Read safety.md §6 Large Codebase Protocol before anything else.

Architectural scope (user mentions pattern names, layer problems, or any trigger below marked [arch]) → Read smells.md Family 6. Map current architecture (Grep import statements, identify layers). Present architecture map. Ask: "What target pattern?" Confirm with user. Then read safety.md §8 in full before touching anything. Use operations from catalog-architecture.md.

Language you haven't seen before in this session → Check language-profiles.md. If language not listed, ask user: "What command runs your tests?" Then proceed.

Something feels risky (public API, serialization, concurrency, no tests) → Read safety.md §3 Red Lines before touching anything. Stop and ask if any red line applies.


Trigger Words

Code-level: refactor, clean up, clean this up, extract, rename, simplify, decompose, restructure, improve readability, reduce complexity, remove duplication, pull this out, break this apart, this is too long, hard to understand, technical debt, code smell, too many parameters, god class, big function, make this cleaner, this needs work, tidy up, reorganize, modernize

Architectural [arch]: MVVM, MVP, MVC, Clean Architecture, Hexagonal, layering, too much in the controller, fat controller, view has logic, business logic in the UI, anemic model, fat service, separation of concerns, introduce repository, add a use case, extract interactor, layer violation, presentation importing data, domain importing service, architecture, restructure layers, move to domain


Refactoring in 30 Seconds

For experienced users who just want the loop:

Code-level:

  1. Read target file(s) completely
  2. Detect smells → present ranked list
  3. Confirm operation order with user
  4. For each step: state op → show diff → apply → run tests → confirm or revert
  5. Summarize changes; suggest (but don't apply) follow-ons

Architectural:

  1. Map current architecture (Grep imports, identify layers) → present map
  2. Confirm target pattern with user
  3. Read safety.md §8 in full
  4. Detect Family 6 smells → present ranked findings
  5. For each violation: Introduce → Redirect → Remove (one class per step, tests after each)
  6. Summarize; suggest follow-ons

Full detail: process.md | Architecture operations: catalog-architecture.md

Agentic Context & Tool Mastery

To make this skill highly effective when executed by an autonomous AI agent, adhere to the following tool usage patterns:

  1. Never Guess File Paths: Always run search or directory listing tools (like grep_search or list_dir) to confirm the exact location of a file before attempting to read or edit it.
  2. Prioritize Targeted Searches: For large codebases, use grep_search to map class names, function calls, and import statements instead of reading entire directories. Reading is expensive; scanning is efficient.
  3. Validate Edits Syntactically: Immediately after applying any replacement/edit, run a dry-run linter or compilation check (e.g. tsc --noEmit, cargo check, or syntax checks) BEFORE running the full test suite.
  4. Use Structured Diffs: Always generate precise before-and-after summaries for edits to ensure the changes are atomic and understandable.
  5. Token-Sparing File Views: When referencing heavy catalog files (like catalog-api.md) or smell catalogs (smells.md), do not load the entire file. Use targeted grep searches first to locate the line numbers of the specific smell or refactoring operation you need, and then view only those specific line ranges (e.g., StartLine to EndLine). This saves significant token context.

Context Preservation Protocol

In long refactoring sessions, AI agents can lose context or suffer from drift. You MUST:

  1. Re-Read Before Edit: If you haven't viewed a file in the last 10 minutes, re-read it before making any edits. Code in active development may have been modified externally.
  2. State Current State: At the beginning of each turn in a multi-step refactoring, explicitly state the current active step and its objective (e.g. "We are currently on Step 2 of 4: Extracting applyTaxes").
  3. Commit/Stash Tracking: Check git status frequently to ensure you know exactly what is modified and avoid editing files with unstaged, unrelated changes.

What This Skill Does NOT Do

  • Does not change external behavior without user approval
  • Does not fix bugs while refactoring (separate concerns)
  • Does not apply multiple operations in one edit
  • Does not refactor code it hasn't read
  • Does not skip tests "just this once"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.