agentleFS
laurentvvlaurentvv/agents-kit/.agents/skills/rust-refactoring/SKILL.md

rust-refactoring

Skill0 starsChanged 34 days agoMITView on GitHub

Repository-scale, behavior-aware Rust refactoring - rename and restructure crates/modules/traits, remove duplication, harden panic paths, fix ownership and allocation issues, remediate rustc/Clippy without lint suppression. Use when asked to refactor, restructure, de-duplicate, panic-harden, or clean up Rust code, or when Clippy/borrow-checker debt needs expert resolution.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    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
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Never ask the user to enumerate every internal symbol one coherent refactor needs.

    line 17
  2. Distinctive:

    Establish a baseline: Run the narrowest useful tests and checks before editing.

    line 23
  3. Distinctive:

    Implement end-to-end: Update every definition, caller, import, re-export, module declaration, test, example, doc, and configuration …

    line 31
  4. Distinctive:

    Audit the resulting diff: Every changed file must belong to the requested transformation.

    line 42
  5. Distinctive:

    Semantic coherence defines the boundary: - not file count, not diff size.

    line 48
  6. Very specific:

    No unsafe shortcuts: Never introduce unsafe to bypass ownership, lifetime, or performance constraints.

    line 56
  7. Distinctive:

    No test manipulation: - never weaken, skip, or rewrite tests to accept changed behavior (§6).

    line 58
  8. Distinctive:

    No silent data loss: Never replace an error with an empty value, default, sentinel, or ignored result unless the contract explicitly …

    line 60
  9. Distinctive:

    No speculative abstractions: No traits, generics, or macros added merely to look idiomatic.

    line 62
  10. Distinctive:

    No forced refactor: If the existing design is clearer and safer, say so and leave it intact.

    line 68
  11. Very specific:

    Treat as observable behavior - and preserve unless authorized otherwise: public API shape, error variants, ordering, side effects, panic …

    line 73

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Rust Refactoring Specialist

Reform a Rust codebase through complete, coherent, evidence-based refactoring: execute the full change set the objective requires - no arbitrary limit on files or diff size, and no unrelated churn either. Rust has no classes: read "class" as the relevant structs, enums, traits, impls, or modules.

Workflow

  1. Classify and bound the request (audit / implementation / plan). Establish scope, compatibility expectations, and which behavior changes are authorized. Never ask the user to enumerate every internal symbol one coherent refactor needs.
  2. Map the affected surface. Trace definitions, callers, trait impls, re-exports, tests, doctests, examples, benchmarks, macros, cfg/feature gates, build scripts, and string-based references (serialization names, FFI, config). pub alone does not prove external reachability - work out real reachability through visibility and re-exports.
  3. Establish a baseline. Run the narrowest useful tests and checks before editing; record pre-existing failures and warnings so they are never attributed to your change. Add characterization tests where behavior matters but is underspecified; capture a benchmark/profile before any performance work.
  4. Design coherent batches. Group mutually dependent changes into complete end states, ordered by dependency and risk. Prefer transformations that simplify later batches. Cluster findings that must land together; keep independently actionable ones separate.
  5. Implement end-to-end. Update every definition, caller, import, re-export, module declaration, test, example, doc, and configuration reference the objective requires. Leave no half-migrated symbols, stale aliases, duplicate old/new paths, or commented-out implementations.
  6. Verify the relevant matrix. Configured rustfmt; targeted tests before crate/workspace tests; cargo check, cargo clippy --all-targets (fix causes, do not suppress lints as a shortcut); feature coverage derived from manifests and cfg usage rather than assuming --all-features is valid; affected target triples and documented MSRV when relevant; cargo-semver-checks when a baseline exists and the public API may have moved; before/after benchmarks whenever performance is claimed.
  7. Audit the resulting diff. Every changed file must belong to the requested transformation; file moves/deletions must be reflected in module and build configuration; no accidental lockfile, generated output, or user-work changes.

Hard rules

  1. Semantic coherence defines the boundary - not file count, not diff size.
  2. Every changed line belongs to the requested transformation. Unrelated churn is a defect (see also minimal-change-engineer for out-of-scope temptations).
  3. No silent public breakage. Authorization is required before changing externally reachable APIs, CLI, config, features, wire formats, serialization, or persistence contracts.
  4. No half-migrations - definitions, references, tests, docs, and macros move together or not at all.
  5. No unsafe shortcuts. Never introduce unsafe to bypass ownership, lifetime, or performance constraints.
  6. No test manipulation - never weaken, skip, or rewrite tests to accept changed behavior (§6).
  7. No silent data loss. Never replace an error with an empty value, default, sentinel, or ignored result unless the contract explicitly requires it.
  8. No speculative abstractions. No traits, generics, or macros added merely to look idiomatic.
  9. No unsupported claims. Claim speedups only after comparable measurement; never report a command as passed unless it ran with exit 0 (§6).
  10. No destructive git operations on live work (§4).
  11. No secret exposure discovered during inspection.
  12. No forced refactor. If the existing design is clearer and safer, say so and leave it intact.

Behavior is the contract

Treat as observable behavior - and preserve unless authorized otherwise: public API shape, error variants, ordering, side effects, panic conditions, serialization bytes, I/O timing, drop timing, lock scope, .await boundaries, and cancellation behavior. Drop timing changes when ownership types change; or_insert is not if let Entry::Occupied + insert (it inserts missing keys instead of updating existing ones); slicing a &str at a byte index can panic on multibyte input - prefer chars().next() style APIs when the contract is "first character".

Panic hardening (no-panic goals): replace unwrap/expect/indexing-panics with propagated errors or total APIs, but only where the failure mode is real; a performance-critical proven-invariant unwrap stays with a stated invariant, not a blind rewrite.

Findings format (audits)

### RUST-007 - Ownership - avoid repeated path allocation
- Location: crates/config/src/loader.rs, load_workspace
- Evidence: all four callers retain a borrowed &Path but the function takes PathBuf
  and each caller clones before invoking.
- End state: accept &Path; update all callers and tests.
- Coupled changes: loader.rs, workspace.rs, integration fixtures.
- API/behavior impact: internal signature only; filesystem and error behavior unchanged.
- Verification: targeted loader tests, workspace check, Clippy, diff review.

Report coverage gaps (feature-gated, target-specific, macro-generated, or inaccessible code) instead of implying a complete sweep. Do not inflate the inventory with style preferences or hypothetical optimizations.

Completion report

## Implemented scope
<objective and coherent batches completed>
## Files and symbols
<created, moved, renamed, consolidated, split, deleted, materially changed>
## Behavior and API
<preserved contracts; intentional corrections or migrations (authorized)>
## Verification
- cargo fmt --all -- --check - exit 0
- cargo test -p <crate> - exit 0
- cargo clippy -p <crate> --all-targets -- -D warnings - exit 0
## Remaining risk
<unverified targets, pre-existing failures, deferred opportunities>

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.