agentleFS
Art4Art4/continuous-refactoring/skills/refactor-loop/SKILL.md

refactor-loop

Skill1 starsChanged 2 months agoMITView on GitHub

Runs one refactoring pass — scan, prioritise, design, implement, learn — for a Track handed in by the caller. Internal — invoked by the continuous-<track> skills only, not a user entry point; aborts without a valid Track or an onboarded target.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    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. Very specific:

    Not a user entry point: which Track runs is decided by continuous-refactoring (or named by a human directly), and one of the …

    line 14
  2. Distinctive:

    Before step 1, tell the human in one sentence that a loop pass is starting now, naming the Track (e.g.

    line 40
  3. Distinctive:

    No git repository → pass ends now, nothing else runs (not even step 6).

    line 57

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

Refactor Loop

One loop pass for one Track (CONTEXT.md): does only the work due since the last pass, then records what it learned so the next pass starts from state, not from zero.

This skill is a thin data pipe: it calls each lifecycle skill in order and carries that skill's output forward as the next skill's input. It decides nothing a lifecycle skill could decide — refactor-scan detects, refactor-prioritize/refactor-design decide, refactor-implement executes, refactor-learn writes. It is also Track-agnostic: it never branches on a Track's name — the Track goes straight through to refactor-scan/refactor-learn, which branch per Track internally.

A completed candidate is delivered as a merge request remembered in the target repo. Git is the only hard requirement — missing tools enter the language tooling tree as small candidates instead of gating the loop. A required edge gates a child until every required parent is fulfilled; a recommended edge only advises — the child stays proposable even when the recommended parent was rejected.

Not a user entry point: which Track runs is decided by continuous-refactoring (or named by a human directly), and one of the continuous-<track> skills hands it down. Invoked by them only.

Input

Track — mandatory. One of safety-net, guardrails, investigation, passed by the invoking continuous-<track> skill. The Housekeeping Track is not valid input here: it has its own process (continuous-housekeeping) and never runs the pass below.

Track missing, empty, or anything else → abort now: nothing runs, not even step 6. Report "refactor-loop needs a Track (safety-net, guardrails, or investigation) and was given none / <what it was given> — invoke /continuous-refactoring, or the matching continuous-<track> skill, instead." Never infer, default, or guess a Track from repo state.

Onboarded target — the Bookkeeping pointer must resolve to an existing bookkeeping.md (../continuous-refactoring/references/refactoring-bookkeeping.md says where the Refactoring Notes live). Missing → abort now, same as a missing Track: nothing runs, not even step 6. Report it as refactoring-bookkeeping.md's Not onboarded yet section says. A pointer that is an issue URL is loaded first (../continuous-refactoring/references/issue-mode.md) — an issue that can't be read stops the pass there, and nothing is created in its place.

This skill never runs Track selection and never reads another Track's bookkeeping state — the caller already settled which Track runs.

Loop state

State lives in the target repo, not the conversation. Every lifecycle skill reads it directly; each writes only the field its own step produces (refactor-design adds a structural, baseline-shrink or externally-labeled candidate it plans to ## Investigation's Open) — refactor-learn writes everything else, and is the only skill that writes the suite's own state:

  • Config — the config file (.scratch/refactor/config.md): the Bookkeeping pointer, Ticket-create-mode and MR-create-mode (decided once, per person and machine, during the dispatcher's onboarding step — see ## Creating a ticket and ## Opening a merge request). The Focus areas and Refactoring goal lines are in the instruction file (AGENTS.md/CLAUDE.md).
  • Bookkeeping — the Refactoring Notes' bookkeeping.md: every currently-wired Track's (CONTEXT.md) own bookkeeping section — ## Safety Net, ## Guardrails, ## Housekeeping, ## Investigation (../continuous-refactoring/references/refactoring-bookkeeping.md).
  • Remembered MRs — every open refactor:candidate issue with a linked pull request (the tracker's native issue↔closing-PR cross-reference), when docs/agents/issue-tracker.md names a native-label tracker (GitHub, GitLab); otherwise the Refactoring Notes' merge-requests.md, a ledger file with the same facts.
  • Backlog — refactor:* issues on the tracker named by docs/agents/issue-tracker.md — scaffolded once, during the dispatcher's onboarding step (../continuous-refactoring/references/onboarding-setup-interview.md); every place that needs "does the tracker support native labels" reads this file rather than re-deriving it from gh/glab.
  • Learned rejections — the Refactoring Notes' out-of-scope/ entries.

Neither the config file nor bookkeeping.md is scaffolded here — continuous-refactoring's onboarding step writes them (the onboarding-setup node, fulfilled before any Track runs), with Ticket-create-mode and MR-create-mode already set from its interview. This skill only checks that the Bookkeeping pointer resolves to an existing bookkeeping.md (## Input); the suite never commits either file.

Process

Before step 1, tell the human in one sentence that a loop pass is starting now, naming the Track (e.g. "Starting a refactoring loop pass for the Guardrails Track."). Only after the Track input and the onboarded-target check pass — an aborted invocation announces nothing.

Report every step, before and after — one sentence for what starts, one for its result, and each write to the target on its own line, per ../continuous-refactoring/references/reporting-progress.md. Only this skill reports, after a subagent returns: a subagent has no channel to the human, so each lifecycle skill's ## Output names the writes it made, and this skill turns that list into the sentence. The per-step Report lines below give the shape.

Each step runs the named lifecycle skill and carries its output to the next. Stop between steps where the skill itself stops for user input.

Whenever a step stops the pass early — a precondition, a full backlog, two MRs already open, a breaking-change finding — tell the human at once, in one or a few sentences, what stopped it and why, before the closing report. Never end a pass silently.

This skill is the only place that creates a new issue (the Housekeeping Track's own process aside). No lifecycle skill creates one: refactor-scan, refactor-prioritize and refactor-learn return drafts in their output, and whenever a step hands drafts back, this skill creates them per ../continuous-refactoring/references/filing-a-ticket.md — it reads Ticket-create-mode, asks the human where that mode says to, dedupes by title — reports each one, and passes the resulting issue to the next step. Comments, body updates and labels on an issue that already exists stay with the skills.

Prefer dispatching each step to a fresh subagent: hand it this pass's carried-forward input, bring back only its stated ## Output. That keeps a skill's own reasoning inside its own context instead of leaking into this one's. No subagent mechanism available → run each step inline instead, same order.

  1. Scan. Report before: tell the human in one sentence what is starting in a subagent — walking through the Track's open items when its own Open list is non-empty (e.g. "Walking through the open items in a subagent."), otherwise a fresh scan (e.g. "Starting a fresh scan in a subagent.") — then run /refactor-scan in a fresh subagent — for this step always, not merely preferred — told this pass's Track (the required input above). No subagent mechanism available → run it inline and say so in that one sentence instead. Checks preconditions (git, backlog size) and resumes in-flight work before proposing anything fresh. A Track's own Open list, when it carries one, is walked by refactor-scan itself (../refactor-scan/references/track-open-processing.md) — refactor-scan doesn't decide for itself which Track is due; this skill's caller already did, and this skill hands the answer down as input. A Track Open walk hands forward a draft for the node's issue unless it already has one — create it now, before step 4, and carry the issue forward (step 4) and on to step 6 (the Open entry's issue number). Refused or unanswered (ask-each-time) → the pass ends here with a report, per filing-a-ticket.md; nothing else runs but step 6.

    Report after: what came back — how many nodes are proposed, which findings, or which resume/pending path the pass takes instead (and, when steps 2–4 are skipped because of it, say so and why).

    • No git repository → pass ends now, nothing else runs (not even step 6).
    • Backlog full → skip to step 5 with scan's findings, no new candidate.
    • Resume-candidate (an open MR with reviewer activity newer than its last commit) → skip straight to step 5 with it; steps 2–4 don't run.
    • In-flight ## Investigation Open entry, resumable → skip straight to step 4 (no plan yet, or a plan present but neither label set — refactor-design has more to finish either way) or step 5 (plan present, ready-for-agent set); steps in between don't run. Entry found but still flagged and waiting (needs-info present, ../refactor-design/references/decision-gate.md) → native tracker → treated as though none was found, continue below; git-only fallback → the pass ends here instead (refactor-scan/SKILL.md step 2) — that entry is the only record of it.
    • Track Open walk (a Track that carries an Open list) → scan walks the Track's Open list itself (../refactor-scan/references/track-open-processing.md) and hands its outcome forward: the one workable node it worked, any fulfilled at pick-up findings — nodes its re-check found already adopted, which step 2's refactor-learn call removes from Open — and any non-workable nodes with their reasons, for the closing report (step 6).
    • A flagged candidate found already carrying ready-for-agent (refactor-scan step 3b — on an Investigation pass, or a refactor:priority one) → skip straight to step 5, same as a resume-candidate; steps 2–4 don't run.
    • Otherwise → findings (possibly empty) go to step 2, proposals (every unblocked node's Name, never slugs) go to step 3.
  2. Learn, early call — only if step 1 found something. Secret-history findings come back as drafts: create them (batch question under ask-each-time), and tell step 6 whether every one now has an issue. Report before ("Recording what scan found: …") and after (what was written). Run /refactor-learn on the findings before prioritising: step 3 reads the ledger, and a finding this pass just resolved (an MR merged or closed, or a Track Open node found fulfilled at pick-up) must land there first. No findings → skip this call entirely.
  3. Prioritise. Report before ("Ranking the proposals.") and after (the chosen node by Name, why in a few words, and every issue it filed); a Select-mode dispatch is reported the same way. Rank mode returns drafts for every proposed node that had no issue yet, and Select mode drafts for every candidate it found — create them here, before step 4 (ask-each-time: one batch question for the drafts, then the chosen candidate's own question if the batch was declined), and carry the chosen candidate's issue forward. The chosen candidate's issue refused (or unanswered, unattended) → the pass ends here with a report; offer once, in that same message, to reject the node for good, and a yes goes to step 6 as a rejection. Run /refactor-prioritize (Rank mode) on scan's proposals against the now-current ledger. Stops the pass (skip to step 5) if every proposal is already in flight. Otherwise hands forward one chosen node with its rationale — a gate (structural-scan, a PHPStan baseline-shrink family) → run /refactor-prioritize again (Select mode, a fresh dispatch) to pick and minimally file the concrete candidate within it before continuing to step 4. Already concrete (tooling-tree node, externally-labeled candidate) → straight to step 4, Select mode doesn't run.
  4. Design. Report before ("Designing <Name>.") and after (the issue that now carries the plan and its labels — or the flagged question, or the breaking-change finding). Run /refactor-design on what step 3 handed forward, together with the chosen candidate's issue — design writes the full plan onto a tooling-tree node's issue (updating its minimal body) and adds it as a comment for an externally-labeled or gate-shaped candidate, never creating an issue itself; a gate-shaped candidate is first grounded and grilled. Carries the issue/plan to step 5. Grounding/grilling (or planning a PHPStan baseline-shrink fix) may instead apply the decision gate (../refactor-design/references/decision-gate.md): a flagged decision still carries the issue/plan forward, but step 5's own precondition then holds it back; a genuine breaking change carries a finding forward to step 6 instead, and step 5 doesn't run at all this pass for this candidate.
  5. Implement. Skip entirely when step 4 didn't produce a confirmed, implementable plan this pass — a flagged candidate still missing ready-for-agent, or a breaking-change finding handed to step 6 instead; continue at step 6 either way. Cap gate — new MRs only. If this step would open a new merge request, count the in-flight suite MRs first — the same remembered set refactor-prioritize step 1 reads (against this pass's now-reconciled ledger); two or more open → don't run /refactor-implement: the candidate keeps its plan and stays pending for a later pass, tell the human which MRs are waiting and that the pass ends without new work, then continue at step 6. Applies on every path into this step — a Track Open walk and an ## Investigation Open resume never pass through refactor-prioritize. Continuing an already-open MR (a resume-candidate with reviewer activity) opens no new MR and isn't gated. Report after: the branch pushed and the merge request opened (link, draft or not), or what the hand-back left for this skill to finish. Otherwise: tell the human in one sentence that implementation is starting in a subagent (e.g. "Starting the implementation in a subagent."), then run /refactor-implement in a fresh subagent — always, not merely preferred; no subagent mechanism → inline, and say so in that sentence instead — one candidate, one branch, created here. Reviews its own diff (standards + spec) until clean, looping back to its own earlier steps on findings, before opening the merge request. Carries the opened MR to step 6.

    A subagent can't ask the human or reliably reach the forge, so it hands back instead of stalling: its output names the branch and commits, plus whatever it couldn't do — seams the plan doesn't record as confirmed (nothing written yet), an MR-create-mode that asks the human (ask-each-time, human-opens), or a failed push, MR creation, or CI-status read. This skill then finishes that part itself, in its own context: confirms the seams with the human and re-dispatches, or pushes and opens the MR per ../continuous-refactoring/references/opening-a-merge-request.md (draft or not as that reference says), and reads the CI status. Never treat a hand-back as a finished step 5 until the MR is open, or no forge/remote is available at all.

  6. Learn, closing call — always, even when nothing past step 3 ran. Report before and after like step 2 — what was recorded, or "nothing to record" when the call stopped at its precondition (a pass that only did step 2 is still complete). Run /refactor-learn with the freshly opened MR, if any, or the design-time breaking-change finding step 4 produced instead (decision-gate.md), plus whether every secret-history draft from step 2 now has an issue, and any node the human rejected for good in step 3 — that finding gets the same rejection treatment (wontfix, closing note or out-of-scope/) a load-bearing MR-review rejection already gets. Records a delivered candidate (its Closes #<n> link on a native tracker, or the ledger), captures ADR/CONTEXT.md updates — and, when the pass's Track carries its own bookkeeping section, updates that section instead of (or as well as) the ledger, per the Track's own write file under ../refactor-learn/references/ (safety-net-write.md, guardrails-write.md, investigation-write.md) — this skill never branches on which Track it is.

Creating a ticket

Only this skill (and Housekeeping's own process) creates issues — rules in ../continuous-refactoring/references/filing-a-ticket.md: Ticket-create-mode (autonomous, or ask-each-time with one batch question per set of drafts and one for the chosen candidate; a field the config file doesn't state = ask-each-time), dedupe by title, what a refusal or an unattended run does.

Opening a merge request

Followed by refactor-implement when it opens the reviewable. Full rules — MR-create-mode (decided once, during the dispatcher's onboarding step; a field the config file doesn't state = human-opens), basing, description — in ../continuous-refactoring/references/opening-a-merge-request.md. The tooling-tree candidate's own outlook comment (what it unlocks next) lives on the issue instead — ../refactor-implement/references/outlook-comment.md.

Fallback

The suite must keep working in a target repo with none of the global skills installed. Each lifecycle skill's own ## Fallback covers its step: crash-safe (skip the global skill with a note — the step's core is already inline) or self-sufficient (the fallback inlines the part of the global skill the step uses). This skill engages no global skill itself.

Closing report

Wherever the pass ends, close with exactly two lines to the human — a lifecycle skill's own ## Output is handoff data for the next skill, separate from this. Name any tooling-tree node by its Name, never its slug.

Every claim in Status must reflect state freshly confirmed this pass, not an earlier step's stated intent — if refactor-implement reported CI green, that means a check run this pass, not a memory of what an earlier round meant to fix. When state can't be freshly confirmed (no forge/remote, or CI status unreadable via API), say so explicitly rather than reporting an assumed outcome.

  • Status: one line, what happened this pass. When a Track's Open was walked this pass, include any skipped non-workable nodes with their reason (e.g. "Skipped: phpstan-level-6 (blocked by phpstan-level-5), coverage-floor (needs-info)"). When scan left candidates for an Investigation pass (refactor-scan step 3b), say how many (e.g. "1 other candidate waits for an Investigation pass").
  • Next: one line, what the human can or should do now.

Examples: "Status: design flagged issue #12 for confirmation before implementing — ready-for-agent needed. Next: review the open question on issue #12 and add ready-for-agent once satisfied." / "Status: no git repository found — the loop can't run here. Next: initialize git, then rerun." / "Status: 2 merge requests already open (links). Next: review/merge one; nothing else to do until then." / "Status: delivered PHPStan Level 0 — merge request #12 open. Next: review and merge; the following pass proposes PHPStan Level 1 once this lands."

Completion criterion

One full pass completed for the given Track and loop state updated: refactor-learn ran at least once, and the pass's outcome is recorded — a delivered candidate's MR carries Closes #<n>, discoverable via the tracker's native linkage (or remembered in the ledger, on a local tracker), the issue closed once merged, nothing was actionable and that's reported, or (no forge/remote available) the candidate sits prepared on its own branch, handed to the human, per opening-a-merge-request.md.

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.