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

refactor

Skill1 starsChanged 4 months 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.

111 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use modern-go, to-design 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.
  • jidechaoSkill

    modern-go

    Modernize Go code by applying version-appropriate idioms and APIs (gofix-style transformations). Scans go.mod for the Go version, then transforms Go source files to use modern patterns—from Go 1.0 through 1.26+. Use when the user says "现代化","现代Go语言", "地道的", "idiomatic", "modernize", "modern-go", "update Go code", "gofix", or wants to upgrade Go idioms.

    Also in 3 projects that use this

  • jidechaoSkill

    to-design

    Generate a design document (design proposal) from a PRD, in the style of Go's official design proposals — Abstract / Background / Design / Rationale / Compatibility / Implementation, heavy on the 'why' and tradeoffs. Triggers on: to-design, prd-to-design, prd转设计文档, 生成设计文档, 写设计文档, design doc, design proposal, 设计提案, 技术设计文档.

    Also in 3 projects that use this

  • chidekinaSkill

    test-gen

    Generate test cases from type constraints and specs. Creates boundary tests, edge cases, and fixtures automatically. Pact-lang inspired. Triggers on: generate tests, test from spec, create fixtures, boundary tests.

    Also in 5 projects that use this

  • pvnarpSkill

    incident

    Guides incident response and post-mortem analysis. Covers triage, mitigation, root cause analysis, and prevention. Use when responding to active incidents, writing post-mortems, or improving incident processes.

    Also in 6 projects that use this

  • platformplatformSkill

    db-query

    Query the local Postgres database of the active Aspire worktree via psql.

    Also in 3 projects that use this

  • JetBrainsSkill

    fix-bug

    End-to-end bug fix workflow for the Exposed project. Accepts a GitHub issue (#NUMBER), YouTrack issue (EXPOSED-NUMBER), or YouTrack URL (https://youtrack.jetbrains.com/issue/EXPOSED-NUMBER). Fetches the issue, creates a failing reproducer test, commits on a new branch, implements the fix, validates, and opens a PR. Use this skill whenever the user wants to fix a bug from an issue tracker, mentions a EXPOSED issue number, or references a GitHub issue to fix.

    Also in 6 projects that use this

  • +2 more from jidechao

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 7 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 94 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 5

    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:

    Run the full suite after each ACT step.

    line 80
  3. Distinctive:

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

    line 93
  4. Distinctive:

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

    line 102
  5. Distinctive:

    No hacks, workarounds, or shortcuts.

    line 119
  6. Very specific:

    Never edit build or tool configuration files.

    line 121
  7. Very specific:

    Never suppress or disable compiler or linter diagnostics.

    line 124
  8. Very specific:

    Never weaken type contracts to silence errors.

    line 126
  9. Distinctive:

    No dangling references or unintended interface breaks.

    line 135
  10. Very specific:

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

    line 138
  11. Distinctive:

    Keep prose terse while ensuring clarity.

    line 146
  12. Distinctive:

    Use lists and sub-lists over paragraphs and long sentences.

    line 148

“Common” is measured: kept by at least 6 in 10 of the 94 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 violation catalog in references/refactoring-guide.md.
    • Short-circuit: halt and emit Result: No Changes if none detected: duplicated logic, long methods, large classes, primitive obsession, SOLID violations.
  2. ORIENT—Name the smallest production area worth refactoring and what won't change.
  3. PLAN—Declare the minimal change and rationale.
    • 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 the task's own git diff/git status against 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.
  6. REPORT—Emit the result following the result directives and using the result template.

Directives

  • Two Hats: Never add features or new tests while refactoring.
  • Violations: Detect and fix using the violation catalog and fix playbook in references/refactoring-guide.md.

Constraints

  • 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

  • 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 over paragraphs and long sentences.
  • 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.