Cleanup fleet

From Intense-Visions/harness-engineering · View interactive version

Cleanup fleet is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Autonomous entropy/hotspot remediation sweep — enumerate the entropy/hotspot backlog by composing the existing detection skills, rank the targets by remediation value, confirm the batch with the hum

How to use this skill

Skill file

Cleanup Fleet

Autonomous entropy/hotspot remediation sweep — enumerate the entropy/hotspot backlog by composing the existing detection skills, rank the targets by remediation value, confirm the batch with the human in one up-front round, fan out worktree-isolated subagents that each run the real per-target cleanup pipeline (harness-codebase-cleanup), independently verify every result by convergence artifact and all-OS CI, and hand back a set of scoped cleanup PRs for one bulk review. The fleet never auto-merges and never trusts a subagent's self-report.

Working an entropy/hotspot backlog down by hand is a per-target attention slog: every high-churn, high-risk area must be found, its remediation scoped, driven through harness-codebase-cleanup to convergence, and turned into a reviewable PR — one at a time, with a human present throughout. For a codebase with dozens of risk hotspots the human's attention, not the machinery, is the bottleneck. cleanup-fleet inverts the model: it enumerates the backlog by composing the existing detectors, runs the real per-target pipeline autonomously and in isolation for each target, verifies the result, and returns scoped cleanup PRs to review in bulk — moving the human from "remediate every hotspot" to "confirm the batch once, review the PRs once." It is a quality-queue member of the -fleet family: it does not sit on the core intake → decide → build → land spine, but works the entropy/hotspot queue alongside it.

This skill builds on the shared -fleet spine documented in docs/reference/fleet-family.md — the five-phase SELECT → CONFIRM → DISPATCH → VERIFY → terminal skeleton, the concurrency governor, the artifact + all-OS-CI verification discipline, the worktree fan-out with its .claude/-nested push caveat, and the never-silent-merge invariant. That page states the family contract once; this SKILL.md defines only what is cleanup-fleet's own: its queue, its triage taxonomy, its per-target pipeline, its terminal act, and its domain-specific rationalizations.

When to Use

Flags

| Flag | Effect |

| --------------- | --------------------------------------------------------------------------------------------- |

| --concurrency | Cap concurrent remediation subagents (default 2, max recommended 3 — the machine-storm limit) |

| --report-only | Enumerate, score, and present the ranked target batch; do not dispatch, verify, or open PRs |

| --dry-run | Run SELECT and CONFIRM only; stop before fan-out |

| --safe-only | Restrict remediation to the safe class even if a target's risky change looks mechanical |

Process

Iron Law

A cleanup PR is "merge-ready" only after independent convergence + all-OS-CI verification. The fleet never auto-merges, never applies a risky structural change autonomously, and never accepts a subagent's self-report as proof its pipeline ran.

A subagent that reports "cleaned it up — findings gone, CI green" has told you what it believes, not what is true. The only evidence that the real per-target pipeline ran and worked is the convergence record it necessarily leaves behind — the findings the target opened with are resolved and a re-scan of the target is clean — plus the CI signal on the pushed branch. If the re-scan still shows findings, the cleanup did not converge and the item is rejected or retried, regardless of how confident the report reads. And landing the batch is the human's call: the fleet stops at a set of verified, reviewable PRs, because remediation lands in the codebase's highest-risk corners — exactly where a silently-merged bad change hides.

Phase 1: SELECT --> Phase 2: CONFIRM --> Phase 3: DISPATCH
                                                    |
                                                    v
                     Phase 5: REPORT <-- Phase 4: VERIFY

| Phase | Purpose | Exit Condition |

| ----------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |

| 1. SELECT | Compose detectors into targets, cross-check, score by remediation value | Ranked Target[] with safety class, cross-check verdicts, detected forks |

| 2. CONFIRM | One up-front human round: approve/trim, confirm safe/risky calls, set cap | Human-approved batch with confirmed classes and agreed concurrency |

| 3. DISPATCH | Worktree-isolated subagents run the real harness-codebase-cleanup per target | Every confirmed target returned a branch, parked, or failed (all recorded) |

| 4. VERIFY | Independent convergence + all-OS-CI confirmation, never self-report | Each returned target marked verified / rejected / retry |

| 5. REPORT | One-row-per-target batch summary; never merge | Report delivered; parked risky remediations surfaced for the human |

Phase 1: SELECT — Compose Detectors, Cross-Check, Score

  1. Enumerate the entropy/hotspot backlog by composing the existing detectors — reimplement none of them. Run and fold together:

Missing any one source degrades to whichever detectors are available; record which source was unavailable rather than aborting.

  1. Fold findings into remediation targets. A target is one coherent hotspot cluster or one entropy finding-group — the unit that becomes one PR. Group co-located findings in the same high-churn area into a single target; never split a coherent cleanup across PRs, and never bundle unrelated cleanups into one.
  1. Classify each target's safety. Tag each target safe or risky:
  1. Cross-check each target against merged and open PRs. For every target, search merged/open PRs for one that already cleaned that area. A target whose area was already remediated is already-cleaned — flag it for drop/annotate, not re-remediation.
  1. Score and order by composite remediation value. Do not rank ad-hoc. Reuse roadmap-pilot-style impact scoring over a composite of churn × structural risk × entropy-finding density, so the highest-risk areas that also carry remediable findings come first and selection is principled and reproducible.
  1. Build the Target record for each survivor:

```

Target {

sources, // which detectors surfaced it (may be several)

id, // target slug

area, // files / module the target covers

findings, // the findings summary the target opens with

safety, // "safe" | "risky"

score, // composite remediation-value score

crossCheck, // "novel" | "already-cleaned"

resolvingPr, // set when crossCheck = already-cleaned

forks, // detected risky-remediation forks (may be empty)

}

```

Phase 2: CONFIRM — The Single Up-Front Human Gate `[checkpoint:human-verify]`

  1. Present the ranked target batch in one round. This is the only guaranteed human touchpoint before PR review — everything downstream runs autonomously. Present, together, in a single surface:
  1. The human approves or trims once, and confirms the classifications. Batch approval, safe/risky confirmation, and already-cleaned triage all happen in this same gate — front-loading the genuinely-ambiguous calls is what keeps wrong-remediation rework low. A target the human downgrades to risky is treated as parked from the start.
  1. From here it is autonomous. After this gate the fleet does not pause per-target. The only thing that re-surfaces to the human before REPORT is a target that turns out mid-flight to need a risky change (see DISPATCH) — and even that parks only that one target without blocking the batch. Under --dry-run the skill stops at the end of this phase.

Phase 3: DISPATCH — Worktree Fan-Out With a Concurrency Governor

The lane unit is a CLUMP, not a target. A confirmed batch is a set of CLUMPS: like targets of one detector family over one coherent scope, grouped mechanically at SELECT rather than one target per lane. Run harness fleet clump-dispatch --input <run.json> over the confirmed clump set: it emits one PR plan per clump and refuses an input that carries no clumps block (exit 14) rather than quietly planning nothing. Each lane then honors the one-PR-per-clump contract — one branch, one PR, one commit per member, the title naming the clump and the body listing every member with its citation. Commit-per-member is not bookkeeping: it is what makes VERIFY's drop a one-commit revert instead of a re-run of the whole lane, which is the only thing that keeps bundling N targets from making one bad target N times as expensive as it is today. A clump of one is just a target, and runs exactly as it always did. See docs/reference/fleet-family.md §The clumping floor and ADR 0135.

  1. One worktree-isolated subagent per confirmed target. Each subagent is briefed to run the real per-target pipeline for its one target: harness-codebase-cleanup --fix in convergence mode. It does not hand-edit, and it does not short-cut the pipeline — the convergence record the pipeline leaves behind is what VERIFY checks for.
  1. Cap concurrency at the governor (default 2, max ~3). This is the machine-storm limit: beyond roughly three concurrent remediation agents the compound load produces flaky failures indistinguishable from real ones. Never exceed the confirmed concurrency to "go faster" — a stormed batch is slower once re-runs are counted.
  1. Park risky remediation; never apply it autonomously. A subagent runs autonomously on the safe class for its target. But if remediating the target turns out to require a risky structural change — one that alters a public API or observable behavior, or that rewrites a high-churn hotspot — that target parks and reports the change (with a recommendation) instead of applying it. Parking is per-target: the other targets in the batch continue uninterrupted. The parked risky remediation appears in REPORT for the human.
  1. Record an "assumptions made" note per target. Each subagent records the ranking basis, the remediation scope it took, and the safe-vs-risky calls it made, so the eventual PR carries an assumptions note — batch review is only trustworthy when the reviewer can see what was assumed and what was deliberately left un-remediated.
  1. Push-path caveat. A worktree created under a .claude/-nested path breaks the local pre-push check-docs gate (it self-excludes and scans zero files). Subagents push via the GitHub API or from a non-.claude throwaway worktree. Never --no-verify — bypassing the gate defeats the verification the fleet depends on.

Worker handoff — return the canonical FleetHandoffRecord. When a worker finishes its target it hands the orchestrator exactly one FleetHandoffRecord (from @harness-engineering/types) — the ONE bounded envelope every -fleet member emits, so fleet-command parses any fleet's worker output uniformly instead of special-casing an ad hoc per-worker report shape. The record carries status (done | parked | blocked | failed), fleet, item, a one-line summary, an evidence[] of verifiable pointers (branch, PR, artifact path, CI check — exactly the references VERIFY re-checks), next_steps[], and, for any non-done status, a blocker. The orchestrator validates it with validateFleetHandoffRecord; a malformed or unknown-keyed record is rejected, never silently misread. See the canonical handoff record in docs/reference/fleet-family.md.

Phase 4: VERIFY — Independent Confirmation, Never Self-Report

One verdict per clump (D10). VERIFY assigns exactly ONE verdict to a clump — never one per member, and never a whole-clump failure for one bad member. A member that fails this phase's standard is dropped by reverting its own commit, and the clump proceeds with the rest, recording the drop and its reason. The clump fails only when the post-drop remainder is empty or no longer builds; a post-drop build that was not run is not a green one, and settles as a failure for want of proof, exactly as a convergence record that cannot be produced leaves the target unverified rather than assumed clean. Settle it with harness fleet clump-dispatch --input <run.json> --verdict <outcomes.json> --post-drop-build <green|red|unknown>, which exits 13 on a failed clump and refuses a clump nobody reported outcomes for. A verdict read off the pretty output without its exit code is a claim, not a check.

  1. Never accept a subagent's self-report as verification. "The cleanup ran and CI is green" is a claim to be checked, not a result. For each returned branch, the orchestrator independently confirms the evidence itself.
  1. Require the convergence artifact. Confirm that the target actually converged:

A branch whose re-scan still reports findings did not converge — regardless of what the subagent reported. Reject it (or retry once); it is never marked merge-ready.

  1. Require all-OS CI green. Confirm the pushed branch's CI is green on all target operating systems plus the project's required checks (gh pr checks / gh run list). Green on one OS is not green. A subset-red branch is not merge-ready — it is reported as failed, and the batch continues. Base freshness (spine clause): all-OS green is trusted as verified only when it ran against current main — the branch is up to date with main, or branch protection enforces strict / up-to-date-before-merge. Green gathered against a base that main has since moved past is stale: downgrade the item to degraded, not verified, and report the stale tested base SHA vs current main. See docs/reference/fleet-family.md § _Base freshness_ (classifyBaseFreshness).
  1. Classify each returned target as verified (converged + all-OS CI green), rejected (did not converge or definitively red), or retry (transient, retried at most once). No target reaches REPORT as merge-ready without passing both the convergence and the CI check.

Phase 5: REPORT — Batch Summary, Never Merge

  1. Emit a one-row-per-target batch summary for bulk human review:

| Target | Verdict | PR | Findings resolved | Assumptions made | Parked risky remediation |

| ------ | ------- | --- | ----------------- | ---------------- | ------------------------ |

Every verified target's row carries its PR link, the count of findings resolved, the assumptions-made note from DISPATCH, and any parked risky remediation. Rejected/failed targets are listed with the reason.

  1. Annotate already-cleaned targets accurately. For each target flagged already-cleaned in SELECT and confirmed in CONFIRM, record it as dropped with a note citing the resolving PR — never a re-remediation.
  1. Never merge. The fleet delivers verified, reviewable cleanup PRs; the human (optionally via pr-fleet) lands the batch. Auto-merging a cleanup PR is out of scope by design — the highest-risk corners of the codebase are exactly where a silent merge hides a regression.
  1. Degrade gracefully. A missing detector source, an already-cleaned area, or a single target's non-converging cleanup results in that target (or source) being reported while the rest of the batch proceeds. One bad target never sinks the batch.

Harness Integration

Success Criteria

Gates

Escalation

Rationalizations to Reject

| Rationalization | Reality |

| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "The subagent reported the findings are gone and CI is green, so the target is clean" | A self-report is a claim, not evidence. Independently confirm the target's re-scan is clean and CI is green — or the cleanup did not converge. |

| "Dead code is obviously safe — bundle every target's cleanup into one big PR" | Scope one coherent target per PR. A mega-cleanup is un-reviewable and un-revertible; the whole model depends on the reviewer holding one target's diff in their head. |

| "This hotspot is high-churn, so just refactor it aggressively while we're in there" | High churn means high risk. Auto-apply only the safe class; a structural rewrite of the busiest file parks for the human — it is not mechanical hygiene. |

| "The re-scan still shows a couple of findings but CI is green — ship it" | Convergence is a gate. A cleanup that did not resolve the findings it opened with is not merge-ready; report it as non-converging, do not ship a half-cleanup. |

| "Just suppress / ignore the finding — that clears the detector" | Suppression is not remediation. A silenced finding fails the convergence re-scan by design; the fleet remediates, it does not mute. |

| "I'll hand-edit this one target — it's faster than driving the whole cleanup pipeline" | Dogfood the real per-target skill. A hand-edited target leaves no convergence record, fails VERIFY, and breaks the guarantee that every PR ran the audited pipeline. |

| "The batch is verified — I'll merge these cleanups to save the human a step" | Never auto-merge. Cleanup lands in the highest-risk corners of the codebase; that is exactly where the one review the whole model is built around must happen. |

| "One target's cleanup didn't converge, so the sweep is a bust — abort the batch" | Degrade gracefully. Report the non-converging target and keep the verified ones; one bad target never sinks the batch. |

| "I'll reimplement dead-code detection here so the fleet is self-contained" | Compose, don't reimplement. The detectors exist and are battle-tested; a second detection engine is drift waiting to happen. The fleet's value is orchestration + batch review. |

Red Flags

| Flag | Corrective Action |

| -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |

| "I'll mark it verified based on the subagent's summary" | STOP. Independently re-scan the target and check CI. A summary is not a verification. |

| "This structural refactor looks safe enough — I'll just apply it" | STOP. Risky remediations park and report. Record it with a recommendation for the human; do not auto-apply it. |

| "The pre-push gate is failing in this worktree — I'll --no-verify" | STOP. Never bypass. Push via the GitHub API or a non-.claude worktree; the gate is part of the verification. |

| "All verified — let me merge and close the loop" | STOP. The fleet never merges. Deliver the PRs for review; landing is the human's step. |

| "The detector's finding is noisy — I'll just suppress it" | STOP. Suppression is not remediation. Remediate the finding or park the target; never mute the detector. |

Examples

Example: A five-target entropy/hotspot sweep

$ harness skill run cleanup-fleet --concurrency 2

Phase 1: SELECT
  Composed detectors:
    hotspot-detector -> 6 high-churn/high-coupling hotspots
    cleanup-dead-code -> 22 dead exports, 4 orphaned deps across 9 files
    dependency-health -> 3 over-central modules
    detect_entropy -> 11 drift findings
    churn pass -> top-10% files identified
  Folded into 7 targets; cross-check vs merged/open PRs:
    - "legacy date-utils module" -> already-cleaned (merged PR: link) -> flag for drop
  Classified: 5 safe, 1 risky ("split god-module orchestrator/router.ts")
  Scored 6 survivors by churn x risk x finding-density; ordered highest-first.

Phase 2: CONFIRM  [checkpoint:human-verify]
  Ranked batch (6) presented. Already-cleaned target flagged for drop.
  Risky target "split router.ts" flagged as will-park (not auto-applied).
  Human trims 1 low-value target -> batch = 5 (4 safe + 1 risky). Concurrency: 2.

Phase 3: DISPATCH (governor = 2)
  4 safe targets: worktree-isolated subagents, 2 at a time, each running real
  harness-codebase-cleanup --fix for its one target.
  Risky target "split router.ts" -> parks and reports (structural, alters imports
  across many callers); the other 4 continue.

Phase 4: VERIFY (independent — no self-report)
  target A (dead exports): re-scan clean, CI green all 3 OS + enforce + harness -> verified
  target B (orphaned deps): re-scan clean, CI green all 3 OS -> verified
  target C (import-order + forbidden-import): re-scan clean, CI green -> verified
  target D (commented-out code): re-scan STILL shows 3 findings (did not converge) -> REJECTED
  target E (split router.ts): parked in DISPATCH -> not verified (risky, awaits human)

Phase 5: REPORT
  | Target             | Verdict  | PR   | Findings resolved | Assumptions made                  | Parked risky remediation |
  | ------------------ | -------- | ---- | ----------------- | --------------------------------- | ------------------------ |
  | dead exports       | verified | link | 14                | scope: web/ exports only          | —                        |
  | orphaned deps      | verified | link | 4                 | removed 4 unused deps             | —                        |
  | import-order       | verified | link | 9                 | forbidden-import -> shared util   | —                        |
  | commented-out code | rejected | —    | —                 | —                                 | — (did not converge)     |
  | split router.ts    | parked   | —    | —                 | —                                 | god-module split (risky) |
  Dropped 1 already-cleaned target with a note citing the resolving PR.
  Never merged. 3 PRs handed to the human for bulk review.

Example: Rejecting a non-converging target

A subagent returns a branch and reports "done — removed the dead code, CI green." VERIFY re-scans the target's area with cleanup-dead-code and still finds three dead exports the subagent missed: the cleanup did not converge. Per the Iron Law it is rejected (retried once, still non-converging → reported as "did not converge"), never marked merge-ready. The batch's other verified targets proceed to REPORT unaffected.

Test Scenarios

Scenario 1: Gate — a self-report accepted as verification

VERIFY receives a subagent claiming "findings gone, CI green" but a fresh re-scan of the target still reports findings. Expected: the "no merge-ready without a verified convergence record" Gate halts marking it merge-ready; the target is rejected/retried, not reported as a PR. Accepting the self-report is the failure this scenario guards against.

Scenario 2: Gate — auto-applying a risky remediation

A target's cleanup turns out to require splitting a god-module, which alters imports across many callers. Expected: the "never auto-apply a risky remediation" Gate parks the target and reports the change with a recommendation; the risky change is never applied autonomously. The other in-flight targets continue uninterrupted.

Scenario 3: Rationalization — reimplementing detection

An operator reasons "I'll reimplement dead-code detection inside the fleet so it's self-contained." Expected: rejected by the "compose, don't reimplement" rationalization — the fleet composes harness-hotspot-detector, cleanup-dead-code, harness-dependency-health, and detect_entropy for its queue, and runs the real harness-codebase-cleanup per target. A second detection engine is drift waiting to happen.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.