Logo vun Refactor

Refactor

Communautéit
rustyrazorblade
refactor

Plan and execute a behavior-preserving structural change, then hold the refactoring contract for the whole run. Use this skill when the user says "refactor this", "clean up this code", "restructure", "extract this", "split this up", "pay down tech debt", or "the tests are fighting me"; when the work is a `type:tech-debt` issue; or at the REFACTOR step of a TDD cycle. It produces a written plan for the owner to approve before anything is deleted or moved, and it governs every failing test after that. It is for behavior-preserving work only. Do not use it for a behavior change; tests are supposed to fail for those.

Iwwersiicht

Editeurrustyrazorblade
Repositoryskills
Skill-Nummrefactor
Stären
44
Forks
9
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzApache-2.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum rustyrazorblade op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Refactor an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/rustyrazorblade/skills/tree/main/plugins/dev-skills/skills/refactor
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/rustyrazorblade/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/plugins/dev-skills/skills/refactor .claude/skills/refactor
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Refactor an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Refactor automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Refactor net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Refactor

Structure changes; behavior does not. This skill has two parts, because a plan alone enforces nothing.

Part 1 is the plan. You write it before you delete or move anything, and the owner approves it.

Part 2 is the standing contract. Rules R1, R2, and R3 bind you for the whole run.

Do not use this skill for a behavior change

A behavior change is supposed to break tests. This skill treats a broken test as evidence of a mistake, so it gives the wrong answer for feature work. Use ordinary TDD instead.

If the work mixes both, split it. Land the structural half first, under this skill. Then make the behavior change as its own commit. That split is R4, and Part 1 sequences it for you.

The contract is live, not advisory

This text is in your context right now, and it stays there. So the triage gate below applies at the moment a test actually goes red, not only while you plan. Read R2 again at that moment. Do not act from memory of it.

The full rules live in references/refactoring-discipline.md in this plugin. That file is the source of truth. This skill carries what you need, because you may not be able to read that file from another plugin root.

Part 1 — Write the plan first

Produce a written, reviewable plan. Do not delete, move, or rename anything until the owner approves it.

1. Name the target and the spec

State what you restructure, and state the spec that defines its contract. The spec is one of these:

  • the committed OpenSpec spec, for a normal issue;
  • the ## Direction and ## Acceptance criteria sections, for a type:tech-debt issue;
  • characterization tests you write first, for untested legacy code.

If the code has no tests, you cannot refactor it. You can only change it and hope. Write characterization tests first. Pin what the code does now, including behavior that looks wrong. Assert the observed output, not the intended output. These tests detect change; they do not judge correctness. That is R6, and it settles R2's hardest cases in advance.

If you cannot identify the spec, stop. Report it to the owner as a spec gap.

2. Sequence the work by R4 and R5

R4: a structural change and a behavioral change never share a commit. Make the change easy, then make the easy change, in two commits. A commit that moves code and alters behavior cannot be bisected or reviewed. Land the structural move green first.

R5: to remove an API that callers depend on, use parallel change. Do not edit it in place.

  1. Expand — add the new API beside the old one. Both work.
  2. Migrate — move callers one at a time. Go green between each one.
  3. Contract — delete the old API and its tests, as a deliberate step.

The old path's tests die at contract time. Never repair them to pass against the new API. That deletion is the point of the step, and it gets its own commit citing the spec line.

Write the sequence as an ordered list of commits. Mark each one structural or behavioral.

3. List every test you expect to die

For each test, give three things:

  • the test's name and file;
  • the spec line that kills it;
  • the R2 classification that applies.

A test you cannot classify in advance is a spec gap. Raise it in the plan. The owner decides spec gaps.

4. Name the prerequisites

Write each dependency in this form: "X cannot move until Y is done." These become the leaves you commit from later.

5. Stop and present the plan

Give the plan to the owner. Wait for approval. Do not begin execution until you have it.

Part 2 — The standing contract

R1 — A refactor preserves behavior

That is what the word means. So a failing test has exactly two explanations:

  1. The refactor is wrong.
  2. The test asserts something that was never part of the contract.

"Edit the test until it goes green" is not a third explanation. It is how a refactor silently becomes a behavior change that nobody reviewed.

Default to explanation 1. Prove explanation 2 from the spec before you act on it.

R2 — Triage before you touch any failing test

Never open a failing test file to "fix it." Classify it first, from the spec. Do not classify it from the test body. The test body tells you what the old code did; only the spec tells you what the contract is.

There are three outcomes, and no others.

ClassificationAction
Asserts required behaviorThe code is wrong. Fix the code.
Asserts behavior the spec deliberately removedDelete the test. Cite the spec line in the commit message.
Asserts an implementation detail of a structure that no longer existsDelete the test. Name the removed structure.

Never repair a test whose subject was removed. Only delete it. A rewrite re-creates the old design's shape in the test suite, and it blocks the refactor you were asked to do.

If you cannot classify a failing test from the spec, stop and report it. An unclassifiable failure is a spec gap, and the owner decides spec gaps.

R3 — Revert, do not grind

When an attempt breaks something you did not expect:

  1. Revert immediately. Do not start repairing outward from the breakage.
  2. Record the breakage as a prerequisite: "X cannot move until Y is done."
  3. Recurse on Y. Attempt it. Revert again if it also breaks.
  4. Commit only from a leaf: a step small enough to land green on its own.

The revert is the whole method. An attempt held open while you patch what it broke grows a change nobody can review and nobody can abandon.

Here is the signal that you are grinding: you are editing files you did not plan to touch, to support a change you have not committed. When you see it, revert.

Language-specific hazards

Some changes look structural but alter the public contract. Each language has its own set. Load your language's style guide and check its hazards before you plan. Every language agent supplies its own list.

Rust is the worked example:

  • a trait-bound change, which reads as a tidy-up but narrows what callers can pass;
  • a lifetime change, which reads as a signature detail but alters what callers can hold;
  • a feature-gated path, whose tests never run in the default build;
  • a #[cfg(test)] helper that pins an internal shape you just removed;
  • a doctest that breaks when a signature moves.

Treat each hazard as a test you expect to die, and list it in the plan.

The stopping condition

Editing the same test file more than twice in one unit of work is a signal, not a crime. It means the classification was probably wrong, or the step was too big.

Treat the third edit as a prompt to re-read R2 and re-classify. It is not a licence to keep going.

If your instructions name a refactor circuit breaker mode, obey that mode. If they say nothing about one, nothing halts you. Re-classify and continue. Do not invent a stop the owner did not ask for, and do not revert anything on your own initiative.

Heefeg gestallte Froen

Wat mécht de KI-Skill Refactor?

Plan and execute a behavior-preserving structural change, then hold the refactoring contract for the whole run. Use this skill when the user says "refactor this", "clean up this code", "restructure", "extract this", "split this up", "pay down tech debt", or "the tests are fighting me"; when the work is a `type:tech-debt` issue; or at the REFACTOR step of a TDD cycle. It produces a written plan for the owner to approve before anything is deleted or moved, and it governs every failing test after that. It is for behavior-preserving work only. Do not use it for a behavior change; tests are supp...

Firwat Refactor op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Refactor besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Refactor an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/rustyrazorblade/skills/tree/main/plugins/dev-skills/skills/refactor an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Refactor benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Refactor benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Refactor domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Refactor gratis?

Jo. De Skill gëtt vum rustyrazorblade ënner der Lizenz Apache-2.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇