agentleFS
andreaswasitaandreaswasita/copilot-agents-dojo/skills/refactoring/SKILL.md

refactoring

Skill54 starsChanged 6 months agoMITView on GitHub

Safe, test-backed code restructuring in small steps.

39 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use performance, ci-cd and 9 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.
  • pluginagentmarketplaceSkill

    performance

    Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.

    Also in 7 projects that use this

  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 4 projects that use this

  • MicrosoftSkill

    error-handling

    统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。

    Also in 6 projects that use this

  • CloudAI-XSkill

    database-design

    Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.

    Also in 5 projects that use this

  • MicrosoftSkill

    api-design

    Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.

    Also in 14 projects that use this

  • AnthropicSkill

    documentation

    Write and maintain technical documentation. Trigger with "write docs for", "document this", "create a README", "write a runbook", "onboarding guide", or when the user needs help with any form of technical writing — API docs, architecture docs, or operational runbooks.

    Also in 8 projects that use this

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 34 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before adding a new feature into a messy area.

    line 22
  2. Distinctive:

    NOT when there is no test coverage and the change is high-risk — write tests first.

    line 23
  3. Distinctive:

    Run the full test suite.

    line 71
  4. Distinctive:

    If red, revert immediately.

    line 72
  5. Very specific:

    If green, commit with message refactor: <named transformation>.

    line 73
  6. Distinctive:

    Run the full suite a final time.

    line 84

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

Restructures existing code without changing behavior, in small atomic steps each backed by a green test suite. Does NOT add features in the same change — refactoring and feature work travel in separate PRs.

When to Use

  • A function, class, or file has grown unmanageable.
  • Duplication is spreading across modules.
  • The demand-elegance skill flagged a hacky solution.
  • Names no longer reflect purpose after a domain shift.
  • Before adding a new feature into a messy area.
  • NOT when there is no test coverage and the change is high-risk — write tests first.

Prerequisites

  • Working test suite (or willingness to write characterization tests first).
  • git for atomic commits per transformation.
  • The view, edit, grep, and glob Copilot tools.
  • A baseline run of the test suite passing (proven, not assumed).

How to Run

1. Run the full test suite. Confirm green baseline.
2. If no tests cover the target, write characterization tests; commit separately.
3. Apply one named transformation.
4. Re-run tests. If red, revert.
5. Commit. Repeat for next transformation.
6. Final pass: full suite + review of the whole diff.

Quick Reference

SmellRefactoring
Long function (>30 lines)Extract smaller, named functions
Duplicate codeExtract shared function or module
Deep nesting (>3 levels)Early returns, extract conditions
God class / fileSplit by responsibility
Primitive obsessionIntroduce domain types
Feature envyMove logic to the class that owns the data
Long parameter list (>4)Introduce parameter object
Dead codeDelete it — version control remembers

Procedure

Step 1: Establish the Safety Net

Identify tests covering the target with grep / glob. Run them via the powershell tool. If they fail or do not exist, write characterization tests first and commit them in a separate commit before any refactor.

Step 2: Name the Transformation

Each step in the refactor must have a name from the rubric above ("extract method", "introduce parameter object", "rename for clarity"). If you cannot name it, you are freelancing — stop.

Step 3: One Transformation, One Commit

For each step:

  1. Apply the change with the edit tool.
  2. Run the full test suite.
  3. If red, revert immediately.
  4. If green, commit with message refactor: <named transformation>.
refactor: extract validateInput() from handleRequest()
refactor: rename UserManager to UserRepository
refactor: move email logic to NotificationService
refactor: delete unused formatLegacyDate()

Step 4: Verify the Whole

Run the full suite a final time. Review the cumulative diff (git diff main). Ask: is the result actually clearer, or just rearranged? If not clearer, revert.

Pitfalls

  • DO NOT refactor without a green test baseline. You are gambling, not refactoring.
  • DO NOT mix refactor and feature work in one PR. Reviewers cannot tell signal from noise.
  • DO NOT rename a symbol without searching every reference first (grep on the symbol).
  • DO NOT rewrite for a hypothetical future ("we might need this pluggable"). Refactor for today.
  • DO NOT big-bang refactor across the whole repo in one commit — small atomic steps, always.

Verification

  • Test suite is green before the first transformation.
  • Test suite is green after every commit.
  • Each commit is named refactor: <transformation>.
  • No public API changed (or, if it did, callers were updated in the same PR).
  • Final diff is meaningfully clearer than the starting code.

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.