agentleFS
nizovtsevnvnizovtsevnv/outline-mcp-rs/.claude/skills/refactor/SKILL.md

refactor

Skill7 starsChanged 9 months agoMITView on GitHub

Code quality analysis and refactoring with validation

195 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use debug-fix, ascii-diagram 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.
  • 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

  • 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

  • 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

We split this skill into the rules it gives an agent

10 rules. 0 are common, 8 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 170 edited versions we read keep these.

  • 8

    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:

    No arguments — analyze the entire project

    line 14
  2. Very specific:

    Read CLAUDE.md and doc/ru/PRD.md for project rules and conventions

    line 20
  3. Distinctive:

    If tests fail or code doesn't compile — report and stop

    line 25
  4. Distinctive:

    Ask the user via AskUserQuestion:

    line 107
  5. Distinctive:

    Read the file, understand context

    line 114
  6. Very specific:

    If logic is affected — cargo test --workspace

    line 117
  7. Distinctive:

    Do not create abstractions "for the future" — only when duplication already exists

    line 136
  8. Distinctive:

    Do not change public API without explicit consent

    line 137
  9. Distinctive:

    Do not touch files you haven't read

    line 138
  10. Distinctive:

    Do not expand refactoring beyond the agreed scope

    line 139

“Common” is measured: kept by at least 6 in 10 of the 170 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

Code quality analysis and incremental refactoring with continuous validation.

Arguments (optional):

  • Path or crate: /refactor crates/app — limit scope
  • No arguments — analyze the entire project

Process

Phase 1: Exploration

  1. Read CLAUDE.md and doc/ru/PRD.md for project rules and conventions
  2. Collect baseline metrics (in parallel):
    • cargo clippy --workspace --all-targets 2>&1 — warnings count
    • Glob + wc — LOC per crate, files >400 lines
    • cargo test --workspace 2>&1 — baseline: all tests passing?
  3. If tests fail or code doesn't compile — report and stop

Phase 2: Diagnosis

Analyze code across 8 dimensions. For large scope, use parallel Task agents (subagent_type=Explore) — one per category or group of categories.

Analysis checklist:

Architecture (SOLID)

  • Files >400 LOC with multiple public types — splitting candidates
  • Modules with >1 responsibility
  • Hard dependencies between modules (concrete types instead of traits)
  • Open/Closed violations: match on types that will be extended

Legitimate exceptions to "1 file = 1 type": Error+ErrorKind pairs, Builder+Target, small private helpers (<30 LOC), related DTO families (Request/Response), typestate marker types, newtype wrapper collections.

Module coupling / cohesion

  • Crate dependency graph: unidirectional? (core ← mid ← app)
  • Circular dependencies between modules within a crate
  • Excessive pub API — types/functions public without necessity
  • Crate knows implementation details of another crate (leaky abstraction)
  • Changing one module cascades breakage into unrelated modules

Duplication (DRY)

  • Repeated code blocks (>5 lines, >2 occurrences)
  • Similar match patterns across different files
  • Copy-pasted error handling

Dead code

  • Unused use, functions, types, constants
  • Commented-out code
  • Unreachable branches

Performance

  • Unnecessary .clone() / .to_string() / .to_owned() where a reference suffices
  • O(n²) loops (nested iterations over collections)
  • Repeated lookups in HashMap/Vec inside a loop
  • Allocations in hot paths

Error boundaries

  • Consistent error types at crate boundaries (From / thiserror)
  • unwrap() / expect() in production code — replace with ? or explicit handling
  • Lost error context (.map_err(|_| ...) without information)
  • Panic instead of Result at input boundaries (user, DB, network)

Security

  • SQL queries via string concatenation instead of parameterized
  • Secrets / tokens hardcoded or logged
  • Unvalidated user input (path traversal, XSS)
  • Magic numbers and hardcoded config that should be parameters

Style and idioms

  • Inconsistent naming
  • Missing #[must_use] on pure functions
  • Over-abstractions with no usage
  • Uncovered edge cases in tests (empty input, errors, overflow)

Phase 3: Report and prioritization

Output to terminal (do not create files):

## Analysis results

| Category       | Found | Critical |
|----------------|-------|----------|
| Architecture   | N     | N        |
| Coupling       | N     | N        |
| Duplication    | N     | N        |
| Dead code      | N     | N        |
| Performance    | N     | N        |
| Errors         | N     | N        |
| Security       | N     | N        |
| Style          | N     | N        |

Baseline: X clippy warnings, Y total LOC

### Top issues (by impact)
1. ...
2. ...

Ask the user via AskUserQuestion:

  • Which categories to fix?
  • Budget: quick cleanup / full refactoring?

Phase 4: Execution

For each fix:

  1. Read the file, understand context
  2. Make the change (Edit)
  3. cargo check — compiles?
  4. If logic is affected — cargo test --workspace
  5. Move to next

Order: simple and safe first (dead code, style), then structural.

On compilation/test failure — revert the change and move to next.

Phase 5: Validation

cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace

Compare with baseline: warnings removed, LOC deleted/changed.

Rules

  • Do not create abstractions "for the future" — only when duplication already exists
  • Do not change public API without explicit consent
  • Do not touch files you haven't read
  • Do not expand refactoring beyond the agreed scope
  • Atomic changes: one fix at a time, verify after each
  • Output to terminal, not to report files
  • Communicate in the user's language

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.