agentleFS
TokiDEVTokiDEV/team-skills/skills/team-refactor/SKILL.md

team-refactor

Skill1 starsChanged 2 months agoMITView on GitHub

Use when code needs refactoring, cleanup, or a design-quality review — god functions, tangled responsibilities, duplication, over-engineering, legacy code without tests, or code that resists the next change. Also when the user invokes Uncle Bob, Fowler, Beck, SOLID, KISS, YAGNI or clean code on existing code. Panel of refactoring masters with a KISS/YAGNI gate and a human approval gate.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. DayronDLR/sap-enterprise-stack-plugin★ 4same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    REQUIRED BACKGROUND: follow team-protocol for dispatch, the run folder, the agent contract, counting positions and the handoff.

    line 12
  2. Distinctive:

    Stay inside the approved scope: No drive-by edits outside the files and steps the CEO approved.

    line 21
  3. Distinctive:

    Every agent gets the minimum it needs and nothing else.

    line 42
  4. Very specific:

    Never play the roles yourself in one context.

    line 54
  5. Very specific:

    Profile: read .council/project-profile.md if present.

    line 73
  6. Distinctive:

    Hand off to a fresh session: Write two files now:

    line 152
  7. Distinctive:

    Start from the exec brief.

    line 159

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

team-refactor

A panel of refactoring masters reviews a scoped piece of code in isolated contexts, a KISS/YAGNI gate kills speculative work, the human (CEO) approves a backlog, then execution happens in tiny behavior-preserving steps. Same family as team-council: evidence-backed, attributed, recorded under .council/.

Core principle: refactoring changes structure, never behavior. Everything else in this skill protects that line or keeps the refactoring from becoming its own over-engineering.

REQUIRED BACKGROUND: follow team-protocol for dispatch, the run folder, the agent contract, counting positions and the handoff.

Iron Laws

  1. Behavior-preserving only. Any observable change — outputs, rounding, error types, side effects, call order, emails, logs relied on — is a Found, not fixed item for the CEO. It is never a backlog step, even if the user said "fix it while you're there" or "whatever, make it clean".
  2. No safety net, no refactor. Code the step touches must be pinned by tests first, and the tests must be proven to bite (see Step 0).
  3. One named refactoring per commit. Structure and behavior never share a commit (Beck, Tidy First).
  4. Red means revert. A failing gate after a step → git checkout the step, shrink it, retry. Never debug forward.
  5. An abstraction needs a present second case. Roadmap talk ("we plan to add providers"), TODOs, and "might" are not cases. Two real call sites today, or it doesn't exist.
  6. Stay inside the approved scope. No drive-by edits outside the files and steps the CEO approved.

Violating the letter of these laws is violating their spirit.

The Panel

Templates in roles/ (overridable per project, see team-protocol). Each role is a lens on a body of work, not an impersonation.

RoleCanonSignature questionOwns
Uncle Bob (role-uncle-bob.md)Clean Code, Clean Architecture, SOLID"How many reasons does this have to change?"Responsibilities, naming, dependency direction
Fowler (role-fowler.md)Refactoring (2nd ed.), smell catalog"Which smell, and which named refactoring removes it?"Vocabulary, mechanics
Beck (role-beck.md)Simple Design, Tidy First, TDD"What change is coming, and what tidying makes it easy?"Sequencing, step size
Feathers (role-feathers.md)Working Effectively with Legacy Code"How do we get this under test before we touch it?"Safety net, seams
Ousterhout (role-ousterhout.md)A Philosophy of Software Design"Is the interface simpler than what it hides?"Depth; counterweight to over-splitting
Minimalist (role-minimalist.md)KISS, YAGNI, Metz, Rule of Three, Gall"What breaks if we don't do this?"The gate

Built-in tensions worth surfacing, not smoothing: Uncle Bob's small functions ↔ Ousterhout's deep modules; Uncle Bob/Fowler's abstractions ↔ Minimalist's deletion.

Separation of Context

Every agent gets the minimum it needs and nothing else. This is what makes the panel a panel instead of one opinion wearing six costumes.

AgentModelTool budgetReceivesNever receives
Reconsonnet~30scope, profile—
Panelist (R1)sonnet~15role template + Code Brief + Finding Card formatother panelists' output, conversation history
Minimalist gate (R2)opus~10all Finding Cardsfull R1 transcripts
Tension pair (R2)sonnet~5own + counterpart's cards onlythe rest
Synthesizeropus~10cards + verdicts + tension repliesraw transcripts
Executorsonnet—one Step Batch + the exec brief's headerother steps, the record, the debate
Final revieweropus—full diff + exec briefthe debate

Never play the roles yourself in one context. Dispatch them, passing the model from the table, with the team-protocol agent contract. Put this line first in its How to work block: - Start from the Code Brief. Open a file only to confirm or cite evidence.

Flow

0. Preconditions   → scope, clean tree, green tests, profile
1. Recon           → Code Brief (one agent)
2. Round 1 (blind) → 6 panelists in parallel → Finding Cards
3. Round 2         → Minimalist gate on every card + tension pairs
4. Synthesis       → Backlog + Found-not-fixed + Rejected + Tensions
5. CEO gate        → approves steps, decides each anomaly; write record + exec brief
   ── fresh session ──
6. Execute         → from the exec brief: Step 0 safety net, then one Step Batch per fresh executor, gated
7. Record          → .council/refactors/YYYY-MM-DD-<topic>.md

0. Preconditions

  • Scope: a path, module, or diff. "The whole repo" → ask the user to narrow it, or have Recon rank hotspots (churn × complexity) and propose the top one.
  • Clean working tree (.council/ excepted; the record is committed alongside Step 0) and a green test run. Record the exact test/lint/typecheck commands.
  • Profile: read .council/project-profile.md if present; offer team-scan if not (not required).
  • Proportionality: for a scope under ~150 lines, the orchestrator writes the Code Brief itself instead of dispatching Recon, and runs at most 2 tension pairs. The panel and the gate always run. Above ~3,000 lines, or more than one package, narrow the scope before dispatching the panel.

1. Recon → Code Brief

One read-only agent (a code-exploration agent from the profile's Technical domain, or the built-in Explore) writes the brief — the only shared context for the panel, so six panelists don't each re-read the same files. Keep it under ~60 lines, plus the excerpts:

  • Files in scope with line counts; public API and its callers (outside-in)
  • Coverage map: which branches/behaviors tests pin, which are unpinned
  • Hotspots: git log churn for these files
  • Quality-gate commands
  • Upcoming change, if the user named one (Beck sequences toward it)
  • Excerpts: the hotspot code itself, with file:line headers, at most ~200 lines in all

2. Round 1 — blind panel (parallel)

Dispatch all 6 in one message. Fill each template's placeholders: {PROJECT_PROFILE} (or "none"), {SCOPE}, {CODE_BRIEF}, {FINDING_CARD_FORMAT} (the block below), and append the agent contract. Each checks the code itself (read-only) within its budget and writes at most 5 Finding Cards, plus a Leave alone list and any Behavior anomalies spotted. The cap forces prioritization. Feathers also returns the Step 0 safety-net spec.

### <ROLE>-<n>: <Smell name> in <file:lines>
- Principle: <SRP | OCP | DIP | Simple Design rule | Depth | KISS | YAGNI | ...>
- Evidence: <cited lines; what in the code shows it>
- Refactoring: <named: Extract Function, Replace Conditional with Polymorphism, Guard Clause, Inline Class, Remove Dead Code, Sprout Method...>
- Payoff: <a concrete, present gain — "adding a customer type touches 1 place instead of 3". Not "cleaner", not "more extensible">
- Cost/risk: <S|M|L> — <what could break>
- Safety net: <pinned by <tests> | needs characterization of <behavior>>
- Confidence: <high|med|low>

3. Round 2 — gate and tensions (parallel)

  • Minimalist gate (its Round 2 job, {ALL_FINDING_CARDS} filled) sees every card and returns one line each: KEEP | SHRINK → <smaller version> | KILL — <reason>. Kill test: no present pain removed, no second real use today, no faster read afterwards, not deeper than what it replaces. The verdict is a gate, not a vote. SHRINK replaces the card with its smaller version. KILL sends the card to Considered and rejected, except when the card was proposed independently by two or more panelists (the gate lists these duplicates): blind convergence is evidence, so that card becomes a tension, Minimalist against its authors, for the CEO.
  • Tension pairs: where two cards conflict (same code, opposite moves), send each side the other's card for one direct reply. Agreeing roles skip.

4. Synthesis

A separate synthesizer agent produces the following. The orchestrator reads only this file, so it holds everything the gate page and the exec brief need:

## Refactoring Backlog — <scope>

### Steps (in order)
Step 0 is always the safety net. Then Beck's order: tidyings that make
the next change easy → structural moves → deletions.
| # | Named refactoring | Target | From cards | Size |

### Step 0 — safety net
[Feathers's safety-net spec, copied in full]

### Step Cards
[One per step, in the Step Card format of step 6, followed by its gate
material: before/after code (≤ ~15 lines each), and `for`/`against`
points from the cards and the Minimalist's verdict, each credited]

### Found, not fixed — top 5 by stakes (CEO decides each; default = leave as-is)
[Money, public contract, user-visible output, data. Anything the user asked
about goes first. Each: current behavior, concrete impact, options]

### Minor quirks (pinned as-is by Step 0, no decision needed)
[One line each: edge-case coercions, cosmetic output, stub behavior]

### Considered and rejected
[Card id — gate reason. Kept so the next refactor doesn't relitigate it]

### Tensions for the CEO — at most 3
[Only conflicts with no majority that change what gets executed. Strongest
version of each side, each side's step as a Step Card, and a suggested default]

### Next run
[Kept steps beyond the cap of 8, ranked, one line each]

A card the gate kept but two panelists conflict on is settled by Counting positions (team-protocol); a Finding Card's Evidence line is its evidence. A majority's move is a backlog step, with the dissent in its against. With no majority, the conflict is a tension, and neither side's step is in Steps. The tension names the slot where the winning side's step goes, and the step joins the backlog there once the CEO picks a side.

The backlog holds at most 8 steps after Step 0. The rest go in Next run, ranked, and from there into the record. Each step costs a context load and a gate run, and a long backlog is how a review turns into a weekend of execution.

The caps are the synthesizer's job, not the CEO's: a gate with 13 findings and 4 tensions gets rubber-stamped.

Architecture-level questions (new layers, changing a public contract) → recommend team-council instead of deciding here.

5. CEO gate

REQUIRED SUB-SKILL: use team-ceo-view to present the backlog as a local HTML decision page. The Found, not fixed items, optional steps and tensions are major decisions; minor quirks are minor: true, default: "leave". Take each step's before/after code and its credited for/against from its Step Card's gate material in the synthesis. When module boundaries move, add an outcome (system view: the module map today and after the approved steps). Put each metric on the step it measures, and each screenshot on the finding it shows. Tensions and gate-rejected cards go in tensions and rejected, so the CEO can side or revive. A tension's steps have no card of their own. Put their code on the tension. Write summary as labelled bullets: Verdict, Weak spots, Found, not fixed, Recommendation. Set source to the refactor record. Record the returned decisions in the .md. The CEO approves steps (all, some, or edits) and decides every Found, not fixed item. An approved behavior fix is not a refactoring step: it runs after the refactor, as its own fix: commit, test-first (with the profile's TDD skill, if it lists one).

Hand off to a fresh session. Write two files now:

  • The record, .council/refactors/YYYY-MM-DD-<topic>.md, for humans and future refactors: Status: approved, not executed, the synthesis, the CEO decisions with their notes, rejected cards, tensions and the Next run list.
  • The exec brief, .council/refactors/YYYY-MM-DD-<topic>.exec.md, for the executors and nothing else: a header (scope, quality-gate commands, fences for the whole run), Feathers's Step 0 spec, the approved Step Cards in order, and the approved fix: items. No debate, no arguments, no rejected items. Aim under ~150 lines.

Then hand off (team-protocol): "/clear, then: execute the refactor in <exec brief path>."

6. Execute

Start from the exec brief. Don't read the record or the run folder.

Step 0 — safety net (Feathers): add characterization tests for every unpinned behavior the approved steps touch, run them green against the untouched code, then prove they bite: break the code deliberately (flip a rounding, a comparison, a constant), confirm a test fails, restore. Commit test: characterize <scope>.

Then group the approved steps into Step Batches: consecutive steps in backlog order, size S, touching overlapping files, at most 4 per batch. Any M or L step is a batch of one. Dispatch a fresh executor per batch with its Step Cards and the exec brief's header:

## Step <n>: <Named refactoring> — <target>
Why: <card ids + principle>
Do: <1–5 bullets of mechanics>
Fence: <files and behaviors not to touch>
Verify: <exact test/lint/typecheck commands>
Commit: refactor(<scope>): <Named refactoring> in <target>
On red: revert the step, report why, stop.

The executor runs the steps in order and commits after each one, so Iron Laws 3 and 4 still hold per step. It replies with one line per step: commit hash, or reverted — <reason>. Between batches, the orchestrator runs the gates itself. Last, one reviewer agent (opus) reads the full diff against the exec brief: nothing smuggled in, nothing behavioral, no step skipped.

7. Record

Complete .council/refactors/YYYY-MM-DD-<topic>.md: add the commits (hash and step, one line each), the reverted steps with their reason, and any open anomalies, and set Status: executed. Delete the exec brief: anything worth keeping is in the record by now (the run folder went at the gate). Future refactors read past records first.

Rationalizations

ExcuseReality
"The user plans more providers, so an interface now is cheap"One data point is a guess at an API. When the second one arrives you'll know its shape; adding the seam then costs the same.
"One file per concern is SRP"Splitting 50 lines into 4 files creates shallow modules. SRP is about reasons to change, not file count.
"They said 'whatever, make it clean', so I can fix the rounding"A vague aside isn't a decision on customer-facing money. Surface it, don't make the call.
"I'll play the roles myself, it's faster"One context gives one opinion. You'll get "all three agree" and no tension.
"The tests pass, so it's safe"Two tests on one branch pin nothing. Check the coverage map.
"This step is tiny, I'll fold it into the next commit"Folded steps lose the ability to revert one cleanly. Batch steps in one executor, never in one commit.
"It went red, I'll just fix the test"The test is the spec. Revert the step.

Red Flags — stop and return to the flow

  • Writing an interface, base class, registry or plugin point with one implementation
  • A commit message containing "and"
  • Changing an expected value in an existing test
  • Editing a file outside the fence
  • Reasoning "they'll need this later"
  • Panel output where every role agrees on everything

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.