agentleFS
irahardiantoirahardianto/awesome-agv/.agents/skills/refactor/SKILL.md

refactor

Skill157 starsChanged 33 days agoMITView on GitHub

Safely restructures existing code while preserving behavior through impact analysis and TDD. User-invoked entry point via /refactor; not for autonomous or subagent use.

195 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

13 rules. 0 are common, 6 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 170 edited versions we read keep these.

  • 6

    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:

    Before starting, you MUST:

    line 68
  2. Very specific:

    Read architectural-pattern.md and project-structure.md

    line 70
  3. Very specific:

    Read rule-priority.md for conflict resolution

    line 71
  4. Very specific:

    Set Mode: Use task_boundary to set mode to PLANNING

    line 76
  5. Distinctive:

    If decision involves trade-offs, create an ADR using the ADR Skill

    line 82
  6. Very specific:

    Set Mode: Use task_boundary to set mode to EXECUTION

    line 88
  7. Distinctive:

    Ensure existing tests pass: before making any change

    line 91
  8. Distinctive:

    Add new tests: if the refactoring exposes untested behavior

    line 94
  9. Distinctive:

    Key principle: Never break the build for more than one step at a time.

    line 99
  10. Very specific:

    Set Mode: Use task_boundary to set mode to VERIFICATION

    line 102
  11. Distinctive:

    Run the full validation suite: quality checks per idiom skill, all tests, build check

    line 104
  12. Very specific:

    If applicable, run E2E tests per browser-automation skill

    line 107
  13. Very specific:

    Commit with type refactor(<scope>): <description> per @git-workflow-principles.md

    line 110

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

Entry-point guard: This is a user-invoked command skill (/refactor). If you are a spawned subagent, do NOT execute this skill — return to your assigned scope card.

Purpose

Safely restructure existing code while preserving behavior. Uses a different mindset than greenfield feature development: understand first, then change structure.

Requirement Elicitation

Determine refactoring source before proceeding:

Path A — Human-Specified

User provides a specific, actionable target:

  • ✅ /refactor extract storage interface in task feature
  • ✅ /refactor split user handler into separate auth handler
  • ✅ /refactor migrate callbacks to async/await in notification service → Proceed directly to Phase 1

Path B — Tool-Driven

User references a static analysis tool as the requirement source:

  • ✅ /refactor from-deepsource — read DeepSource MCP findings
  • ✅ /refactor from-clippy — parse cargo clippy output
  • ✅ /refactor from-lint — parse linter output (ESLint, golangci-lint, ruff) → Parse tool findings → present summary → user approves scope → proceed to Phase 1

Supported tools:

ToolIntegration
DeepSource MCPRead findings via deepsource MCP tools
cargo clippyParse cargo clippy --message-format json
golangci-lintParse golangci-lint run --out-format json
ESLintParse npx eslint . --format json
ruffParse ruff check . --output-format json
SonarQubeRead via API if available

Path C — Discovery

User doesn't know what to refactor, or provides vague request:

  • ✅ /refactor discover — audit first, then refactor
  • ❌ /refactor apps/backend — too vague
  • ❌ /refactor improve code quality — what specific issue? → Multi-agent mode (/workflow-team): Dispatch SCOUT(@scout + @reviewer, code smell audit) → Single-agent mode: Run /audit on the target area first, then use findings as input → Present findings → user approves scope → proceed to Phase 1

Vague request without path → "Run /refactor discover to find issues, or specify a target like /refactor extract storage interface in task feature."

When to Use

  • Code restructuring (moving, renaming, splitting modules)
  • Pattern migration (e.g., switching from callbacks to async/await)
  • Dependency upgrades with breaking changes
  • Addressing tech debt or architectural improvements
  • Tool-driven cleanup from static analysis findings

When NOT to Use

  • New features (use /workflow-solo)
  • Small bug fixes (use /bugfix)
  • "Find what to improve" without /refactor discover (use /audit first)

Pre-Implementation Checklist

Before starting, you MUST:

  1. Scan .agents/rules/ directory for applicable rules
  2. Read architectural-pattern.md and project-structure.md
  3. Read rule-priority.md for conflict resolution

Phases

Phase 1: Impact Analysis

Set Mode: Use task_boundary to set mode to PLANNING

  1. Map the blast radius — what files, modules, and tests are affected?
  2. Document existing behavior — what tests currently pass? what contracts exist?
  3. Identify risks — can this be done incrementally or is a big-bang needed?
  4. Create refactoring plan in task.md with incremental steps
  5. If decision involves trade-offs, create an ADR using the ADR Skill

Skills to consider:

  • Sequential Thinking — for multi-step refactoring with interdependencies

Phase 2: Incremental Change (TDD)

Set Mode: Use task_boundary to set mode to EXECUTION

For each step in the refactoring plan:

  1. Ensure existing tests pass before making any change
  2. Make one incremental change — move, rename, or restructure
  3. Run tests after each change — behavior must be preserved
  4. Add new tests if the refactoring exposes untested behavior
  5. Follow applicable rules:
    • Architectural Patterns @architectural-pattern.md
    • Code Organization Principles @code-organization-principles.md (includes circular dependency guidance)

Key principle: Never break the build for more than one step at a time.

Phase 3: Parity Verification

Set Mode: Use task_boundary to set mode to VERIFICATION

  1. Run the full validation suite: quality checks per idiom skill, all tests, build check
  2. Compare test coverage — coverage should be equal to or better than before
  3. Verify no behavior changes — same inputs produce same outputs
  4. If applicable, run E2E tests per browser-automation skill

Phase 4: Ship

Commit with type refactor(<scope>): <description> per @git-workflow-principles.md

Completion Criteria

  • Requirement source identified (Path A, B, or C)
  • Impact analysis documented
  • All changes made incrementally with tests passing at each step
  • Full verification suite passes
  • Test coverage is equal to or better than before
  • Committed with refactor type

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.