agentsclimarketplace

Refactor

Skill jacob-balslev/skill-graph/marketplace/skills/refactor

Skills that know your codebase. Repo-grounded, contract-validated, agent-routable.

Install
npx -y skills add jacob-balslev/skill-graph --skill refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when reorganizing existing code without changing external behavior — extracting functions, reducing duplication, renaming for clarity, splitting modules, or tightening structure. Covers behavior preservation, duplication reduction, decomposition, naming improvements, structural reorganization, and before/after verification. Do NOT use for bug investigation, adding new product behavior, or writing documentation (even when the docs describe the refactored code). Do NOT use for the test is failing after my edit — what did I break? Do NOT use for write an architecture note explaining this pattern for new team members. Do NOT use for reproduce why this function retries three times on transient network errors.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.7 KB, as published. Nobody here has run it

Refactor

Concept of the skill

Behavior-preserving restructuring of existing code — extracting functions, reducing duplication, renaming for clarity, splitting modules, and tightening structure, with every change verified against before/after behavior so external contracts stay identical.

Coverage

  • Behavior preservation: identifying the external contract that must remain stable before any change
  • Duplication reduction: consolidating repeated logic without over-abstraction
  • Decomposition: extracting functions, modules, or types to improve readability and reuse
  • Naming improvements: renaming so identifiers carry their real meaning
  • Structure improvements: reorganizing file and module boundaries when the current layout obscures intent
  • Verification before and after: running the same behavioral checks on both sides of the change

Philosophy of the skill

Refactoring pays off only when the shape of the code has diverged from the shape of the problem. Before that point it is risk without reward — every move invites a regression, and "cleaner" is a preference, not a justification. The honest test for a legitimate refactor is not "this feels better" but "the next concrete change will be materially easier because of this one." If you cannot name the next change, stop — you are rearranging, not refactoring, and the safest rearrangement is none.

Workflow

Each step decides whether to continue, split, or stop. "Stop" is always a valid answer; speculative refactoring is a failure mode, not a signal of ambition.

StepAskIf yesIf no
1. ContractWhat externally observable behavior must stay the same?Write it down as a test suite or explicit checklistStop — you cannot refactor what you cannot pin down
2. Next-change justificationCan you name one concrete pending change that becomes easier because of this refactor?Go to step 3Stop — you are rearranging for taste, not improving the codebase
3. Smallest useful cutWhat is the smallest structural change that moves toward the next-change goal?Make only that changeSplit into sequential cuts; do not change multiple abstraction layers at once
4. Behavior re-verifyDoes the contract from step 1 still hold exactly?CommitRevert; the refactor was not behavior-preserving. Start over smaller
5. Stop conditionHave you made the next change materially easier than it would have been before?DoneDo not keep going — refactoring beyond the next change is speculative waste

When to back out

  • A green test from before the refactor is now red → revert immediately, then cut smaller.
  • The next-change goal shifted during the refactor → restart at step 2 with the new goal before continuing.
  • The refactor requires touching more than one abstraction layer in a single commit → split into per-layer commits and re-verify each.

Evals

This skill ships a comprehension-eval artifact at examples/evals/refactor.json. The Verification checklist below is the authoring gate for a completed refactor; the eval file is how this skill is graded by scripts/skill-audit.js --graded. Do not conflate them — the checklist is for the engineer, the eval is for the grader.

Verification

  • External behavior is unchanged — same tests green before and after
  • The named next change is now demonstrably easier, not merely "more possible"
  • No new abstraction was introduced speculatively (no "future-proofing" without a named consumer)
  • Each commit is a single structural change, not a bundle of rearrangements

Do NOT Use When

Use insteadWhen
debuggingThe task starts from a failing behavior, not from structural cleanup
documentationThe task is rewriting docs — even docs about the refactored code — it belongs to a separate commit and skill
testing-strategyThe task is designing a new test suite; the refactor's own tests should already exist before step 1

Skill Graph context

<!-- skill-graph-context:start (generated — do not edit by hand) -->

Classification

  • Subject: software-engineering-method
  • Public: true
  • Scope: Behavior-preserving restructuring of existing code — extracting functions, reducing duplication, renaming for clarity, splitting modules, and tightening structure, with every change verified against before/after behavior so external contracts stay identical. Portable across any language or codebase; principle-grounded, not repo-bound. Excludes bug investigation and root-cause isolation (debugging, diagnosis), adding new product behavior (feature implementation), and documentation authoring (doc-updater) even when the docs describe the refactored code.

When to use

  • this 600-line function is hard to reason about — decompose it while keeping tests green
  • extract the duplicated validation logic from these three handlers into a helper
  • rename this module from utils to something that describes what it actually does
  • split this file by responsibility; no behavior changes, tests must still pass
  • Triggers: refactor-skill

Not for

  • the test is failing after my edit — what did I break?
  • write an architecture note explaining this pattern for new team members
  • reproduce why this function retries three times on transient network errors

Related skills

  • Depends on: testing-strategy
  • Verify with: testing-strategy, test-driven-development, test-doubles-design
  • Related: semantics, tool-call-flow, generative-ui, context-graph, error-boundary, performance-testing

Keywords

  • refactor, cleanup, extract function, reduce duplication, rename module, rename for clarity, split this file, decompose function, duplicated logic, behavior preserving
<!-- skill-graph-context:end -->

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.