agentleFS
mystilleefmystilleef/spae-framework/skills/refactor/SKILL.md

refactor

Skill2 starsChanged 14 days agoMITView on GitHub

- Rule of Three: Third instance triggers extraction. Exception: security and validation logic warrants unification at 2+. - Adding features: Restructure to accommodate the change first. - Fixing bugs: Clarify structure to expose the error. - Code review: Improve unfamiliar code incrementally. - Smells detected: See violation catalog in references/refactoring-guide.md. - Execute disciplined, semantics-preserving transformations to remove DRY, SOLID, and Structure violations, improving maintainability without altering observable behavior. Determine scope by the first available source: Abort if no scope exists.

196 other projects use a version of this.

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

15 rules. 0 are common, 8 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 169 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read relevant production code, adjacent tests, and test commands.

    line 63
  2. Very specific:

    When detected smells carry high regression risk resisting safe atomic extraction under existing tests: record in Findings, omit edits, and …

    line 74
  3. Very specific:

    Run the full suite after each ACT step.

    line 94
  4. Distinctive:

    Two Hats: Never add features or new tests while refactoring.

    line 116
  5. Very specific:

    No Confirmation Halts: Never halt to request user scope confirmation or interactive direction.

    line 125
  6. Distinctive:

    Inherit Baseline: Treat the test suite as-found at refactor start as the authoritative baseline, regardless of prior tooling in the same …

    line 131
  7. Distinctive:

    No hacks, workarounds, or shortcuts.

    line 148
  8. Very specific:

    Never edit build or tool configuration files.

    line 150
  9. Very specific:

    Never suppress or disable compiler or linter diagnostics.

    line 153
  10. Very specific:

    Never weaken type contracts to silence errors.

    line 155
  11. Distinctive:

    Every detection line names code examined or why none applies—restating the section never counts.

    line 160
  12. Distinctive:

    No dangling references or unintended interface breaks.

    line 166
  13. Very specific:

    No self-introduced cleanup violation remains per references/cleanup-guide.md.

    line 169
  14. Distinctive:

    Keep prose terse while ensuring clarity.

    line 177
  15. Distinctive:

    Use lists and sub-lists for long sentences and dense paragraphs.

    line 179

“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 agent

When to use

  • Rule of Three: Third instance triggers extraction. Exception: security and validation logic warrants unification at 2+.
  • Adding features: Restructure to accommodate the change first.
  • Fixing bugs: Clarify structure to expose the error.
  • Code review: Improve unfamiliar code incrementally.
  • Smells detected: See violation catalog in references/refactoring-guide.md.

Goal

  • Execute disciplined, semantics-preserving transformations to remove DRY, SOLID, and Structure violations, improving maintainability without altering observable behavior.

Input

Determine scope by the first available source:

  • Files or folders provided by the user.
  • Current changes in the repository.

Abort if no scope exists.

Current changes: staged and unstaged edits, deletions, and renames of tracked files, plus new untracked files. Requires a versioned project. Abort with a clear message if none detected.

Testing

See references/testing-guide.md for test structure, isolation, mocking, assertion, and performance standards.

Shell commands

See references/shell-command-guide.md for command safety, timeouts, redirects, and non-interactive environment directives.

Cleanup

See references/cleanup-guide.md for the self-introduced-artifact checklist and diff-only audit scope.

Workflow

  1. GATE—Precondition guard. Halt immediately on failure.
    • Abort if no scope exists.
    • Read references/testing-guide.md.
    • Read references/shell-command-guide.md.
    • Read references/cleanup-guide.md.
    • Read relevant production code, adjacent tests, and test commands.
    • Confirm automated test suite passes before touching code.
    • Detect antipatterns using the DRY, SRP, OCP, LSP, ISP, DIP, and Structure sections of the violation catalog in references/refactoring-guide.md, plus long methods and primitive obsession.
    • Record one detection line for each section and one for those remaining smells: code examined (or why none applies) and violations found.
    • Short-circuit: once every line exists, halt and emit Result: No Changes if none found a violation.
    • When detected smells carry high regression risk resisting safe atomic extraction under existing tests: record in Findings, omit edits, and emit Result: No Changes.
  2. ORIENT—Name the smallest production area worth refactoring and what won't change. Capture pre-task baseline snapshot per references/cleanup-guide.md.
  3. PLAN—Declare the minimal change and rationale.
    • Target one cohesive responsibility boundary (for example, extracting a dedicated collaborator, domain service, or validation module) rather than whole-class overhauls or disconnected micro-edits.
    • Declare the ordered sequence of transformations needed to decouple that responsibility.
    • Analyze package, module, or class boundaries for cyclic imports and unresolved downstream consumers.
    • Select the fix from the playbook; resolve compound violations using the triage rules in references/refactoring-guide.md.
  4. ACT—Apply one transformation at a time. Execute only what PLAN declared.
  5. VERIFY—Loop over every criterion declared in PLAN:
    • Run the full suite after each ACT step.
    • Audit task edits against the pre-task baseline using the Self-cleanup checklist in references/cleanup-guide.md; remove every self-introduced artifact before proceeding.
    • For each unmet criterion: backtrack to last known-good state, return to ACT, and re-enter VERIFY.
    • Exit only when all criteria pass.
    • Halt only for out-of-scope blockers (failing baseline tests, compilation errors, or missing runtime environments); never treat complex codebase smells as blockers.
  6. REPORT—Emit the result following the result directives and using the result template.

Directives

  • Cohesive Scope: Scope each invocation to one distinct responsibility boundary; batch related transformations internally under sequential test verification rather than micro-slicing single methods.
  • Detection lines: Surface them as one Actions line (for example, detection: 8/8 lines; 1 found); keep per-section detail out of the result.
  • Two Hats: Never add features or new tests while refactoring. Extracting internal functions, modules, or cohesive units under existing test suites satisfies Two Hats without requiring new test files.
  • Violations: Detect and fix using the violation catalog and fix playbook in references/refactoring-guide.md.

Constraints

  • No Confirmation Halts: Never halt to request user scope confirmation or interactive direction; execute the smallest safe transformation within detected scope or emit Result: No Changes.
  • Zero Behavioral Change: External function and observable behavior must remain identical.
  • Defer if Broken: Stabilize failing code before refactoring.
  • Inherit Baseline: Treat the test suite as-found at refactor start as the authoritative baseline, regardless of prior tooling in the same session.
  • Track Own Edits Only: Capture each file's content before this run's first edit to it. Revert means rewriting captured content back, or deleting files this run created—never a git-level reset, stash, checkout, or restore, which erases uncommitted work from earlier phases in the same tree.
  • Never Leave It Broken: End every refactor with the suite green again or the offending edits reverted, regardless of why VERIFY halts.
  • Self-Inflicted Failures Stay In-Scope: A failure this pass's own edits cause never qualifies as an out-of-scope blocker; loop VERIFY's backtrack step instead of halting.
  • Bug Found Mid-Refactor: A pre-existing bug the refactor exposes counts as out-of-scope. Revert the edits that surfaced it, then report the bug as a separate finding. Never fix it in the same pass (Two Hats).
  • No hacks, workarounds, or shortcuts.
  • Forbid laziness; fix issues properly, correctly, and idiomatically.
  • Never edit build or tool configuration files; for example, tsconfig.json, .eslintrc.*, webpack.config.*, vite.config.*, jest.config.*, Makefile, pyproject.toml, Cargo.toml.
  • Never suppress or disable compiler or linter diagnostics; for example, @ts-ignore, eslint-disable, @SuppressWarnings, # type: ignore.
  • Never weaken type contracts to silence errors; for example, as any, ! non-null assertions, or broadening union types.

Verification

  • Every detection line names code examined or why none applies—restating the section never counts.
  • Full test suite passes 100% with no new failures or errors.
  • Code compiles without warnings or missing dependencies.
  • Complexity metrics (class size, method length, parameter count) show measurable reduction.
  • No dangling references or unintended interface breaks.
  • Re-run smell detection against the violation catalog to confirm no new violations introduced.
  • No self-introduced cleanup violation remains per references/cleanup-guide.md.
  • Result: Failed only follows a working tree the agent restores to the pre-refactor baseline; never a suite left red.

Result directives

  • Minimum words. Maximum signal.
  • Keep prose terse while ensuring clarity.
  • Optimize prose for agent, token, and context efficiency.
  • Use lists and sub-lists for long sentences and dense paragraphs.
  • Emit the result template as live markdown—never in a code fence.
  • Output nothing outside the template.

Result template

<!-- prettier-ignore-start -->
### Execution Summary

- **Actions**:
  - [Terse list of actions taken]
- **Files**:
  - [Terse list of affected files]
- **Findings**:
  - [Terse list of notable findings]
- **Summary**:
  - [Terse list of summary of changes]

> **Refactor Status** • `[scope]`
> **Result**: [Complete | No Changes | Failed]
> **Impact**: [Terse impact statement]
<!-- prettier-ignore-end -->

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.