agentleFS
BaratovSokhibjonBaratovSokhibjon/skills/skills/generic/refactor/SKILL.md

refactor

Skill1 starsChanged 4 months agoMITView on GitHub

Make the smallest safe, behavior-preserving edits that make changed code easier to scan, name, and maintain. Language-agnostic. Works from the current git diff. Use when the user asks to refactor, clean up, tidy, restructure, reorganize, or improve the readability of changed code without changing behavior, exports, public APIs, routes, or schemas. For language-specific rules, prefer the python, javascript, typescript, or go refactor variants when the diff is dominated by one language.

  • Reads credentials

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

28 rules. 0 are common, 18 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 169 edited versions we read keep these.

  • 18

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer project conventions first, formatter/linter rules second, official language idioms third, and external style guides only when the …

    line 27
  2. Distinctive:

    If there is no diff, ask which files or range to refactor.

    line 40
  3. Distinctive:

    If present, fix CRITICAL findings first, then WARNING, then SUGGESTION.

    line 51
  4. Distinctive:

    Follow the local convention even when another style guide would be acceptable.

    line 56
  5. Very specific:

    Do not impose generic structure such as src/, mirrored tests/, .env.example, or VERSION unless the repo already uses it.

    line 57
  6. Very specific:

    Search with regex before editing (ripgrep needs -P for the \x{...} escape):

    line 61
  7. Very specific:

    If matches are noisy, inspect or narrow with fzf, for example:

    line 67
  8. Very specific:

    Use exactly one format for code-section markers: the file's comment leader, a single space, MARK:, a single space, then the label (e.g.

    line 84
  9. Very specific:

    No space after the colon: # MARK:helpers -> # MARK: helpers

    line 95
  10. Very specific:

    No space after the leader: #MARK: helpers -> # MARK: helpers

    line 96
  11. Distinctive:

    Ask before high-risk changes unless the user explicitly requested them.

    line 122
  12. Distinctive:

    Prefer clear names, direct control flow, low nesting, and locality.

    line 125
  13. Very specific:

    Add MARK:, TODO:, NOTE:, constants, helpers, or docstrings only when they solve a real readability problem.

    line 128
  14. Distinctive:

    Prefer deleting boilerplate over rewriting it.

    line 131
  15. Very specific:

    After file moves or renames, remove empty orphan directories and update affected imports/exports/tests.

    line 136
  16. Distinctive:

    Run the nearest relevant formatter, linter, typecheck, or tests when discoverable.

    line 140
  17. Distinctive:

    Prefer targeted checks unless the change is broad.

    line 141
  18. Distinctive:

    If verification cannot run, say why.

    line 143
  19. Distinctive:

    Never change observable behavior unless explicitly asked.

    line 152
  20. Distinctive:

    Never remove or rename exported symbols unless explicitly asked.

    line 153
  21. Distinctive:

    Never remove function, class, or method docstrings.

    line 154
  22. Very specific:

    Never replace structured logging with print or console.log.

    line 155
  23. Distinctive:

    Never stage unrelated files.

    line 156
  24. Distinctive:

    Never force generic architecture on a repo with its own convention.

    line 157
  25. Distinctive:

    Never add comments, docstrings, constants, helpers, or section markers just to satisfy a checklist.

    line 158
  26. Very specific:

    Always normalize existing section markers to a single <leader> MARK: <label> format.

    line 160
  27. Distinctive:

    Prefer code that a human understands on first pass over cleverness.

    line 161
  28. Distinctive:

    If a file is already clean, skip it and say so.

    line 162

“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

refactor

You are a strict, pragmatic refactor workflow. Work from the current diff. Make the smallest safe edits that make changed code easier to scan, name, and maintain without changing behavior, exports, public APIs, routes, schemas, or unrelated code.

Prefer project conventions first, formatter/linter rules second, official language idioms third, and external style guides only when the repo has no clear convention.

Workflow

  1. Inspect the worktree (read-only):

    git status --porcelain=v1
    git diff HEAD
    git diff --cached

    If there is no diff, ask which files or range to refactor.

  2. Use optional review context:
    • Review findings live at a per-project path so concurrent refactors never collide: /tmp/<dirname>/code-review.md, where <dirname> is the current directory's name (e.g. /tmp/agent-setup/code-review.md).

      cat "/tmp/$(basename "$PWD")/code-review.md" 2>/dev/null
    • If present, fix CRITICAL findings first, then WARNING, then SUGGESTION.
  3. Find project conventions:
    • Inspect nearby files, package/config files, formatter/linter settings, tests, imports, names, and file layout.
    • Follow the local convention even when another style guide would be acceptable.
    • Do not impose generic structure such as src/, mirrored tests/, .env.example, or VERSION unless the repo already uses it.
  4. Normalize em-dashes globally:
    • Search with regex before editing (ripgrep needs -P for the \x{...} escape):

      rg -n -P '\x{2014}'
    • If matches are noisy, inspect or narrow with fzf, for example:

      rg -l -P '\x{2014}' | fzf --multi
    • Replace safe matches with ASCII -. Perl must decode UTF-8 (-CSD), or \x{2014} matches nothing:

      perl -CSD -0pi -e 's/\x{2014}/-/g' <files>
    • Skip semantic data values, snapshots, fixtures, URLs, or tests where the exact character matters.
  5. Normalize section markers:
    • Use exactly one format for code-section markers: the file's comment leader, a single space, MARK:, a single space, then the label (e.g. # MARK: helpers, // MARK: helpers). Keep the leader appropriate to the language (#, //, --).
    • Find every variant before editing (case-insensitive):

      rg -n -i 'mark:?\b'
    • Rewrite alternates to the canonical form. Common variants to fix:
      • Missing colon: # MARK helpers -> # MARK: helpers
      • No space after the colon: # MARK:helpers -> # MARK: helpers
      • No space after the leader: #MARK: helpers -> # MARK: helpers
      • Wrong case: # mark: helpers, # Mark: helpers -> # MARK: helpers
      • Xcode-style dash separator: // MARK: - helpers -> // MARK: helpers
      • Surrounding decoration such as dashes or === around the label
    • Preserve the label text and the language's comment leader; only normalize the marker shape.
    • Skip matches inside strings, data, fixtures, or docs where MARK is not a code section marker.
  6. Analyze changed code:
    • Naming consistency across analogous files, services, routers, helpers, and shims.
    • Dead imports, unreachable code, stale comments, boilerplate comments, and redundant docstrings.
    • Long functions, deep nesting, unclear control flow, duplicated logic, and misleading names.
    • Error handling, logging, type safety, magic values, and module boundaries.
  7. Classify risk before editing:
    • Low risk: unused imports, local renames, stale comments, docstring cleanup, simple formatting, tiny helper extraction.
    • Medium risk: moving code inside a file, reorganizing private helpers, changing internal imports.
    • High risk: file moves, export changes, route/path changes, broad renames, new modules, public API changes, test rewrites.
    • Apply useful low-risk changes directly.
    • Apply medium-risk changes only when the readability win is clear.
    • Ask before high-risk changes unless the user explicitly requested them.
  8. Improve scanability:
    • Prefer clear names, direct control flow, low nesting, and locality.
    • Group code as imports, constants, types, helpers, public API, private internals, and exports when that matches the file.
    • Add MARK:, TODO:, NOTE:, constants, helpers, or docstrings only when they solve a real readability problem. New MARK: markers must use the canonical <leader> MARK: <label> form from step 5.
    • Prefer deleting boilerplate over rewriting it.
  9. Apply focused edits:
    • Edit only files needed for the refactor.
    • Preserve behavior, public interfaces, dependency shape, and unrelated user changes.
    • After file moves or renames, remove empty orphan directories and update affected imports/exports/tests.
  10. Verify:
    • Run the nearest relevant formatter, linter, typecheck, or tests when discoverable.
    • Prefer targeted checks unless the change is broad.
    • For rename/move batches, run the full test suite and build when discoverable.
    • If verification cannot run, say why.
  11. Summarize:
    • List files changed and why.
    • Note risky refactors skipped.
    • Report verification results.

Rules

  • Never change observable behavior unless explicitly asked.
  • Never remove or rename exported symbols unless explicitly asked.
  • Never remove function, class, or method docstrings.
  • Never replace structured logging with print or console.log.
  • Never stage unrelated files.
  • Never force generic architecture on a repo with its own convention.
  • Never add comments, docstrings, constants, helpers, or section markers just to satisfy a checklist.
  • Always normalize existing section markers to a single <leader> MARK: <label> format.
  • Prefer code that a human understands on first pass over cleverness.
  • If a file is already clean, skip it and say so.</content>

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.