| name | rebar-janitor |
| description | Principal-engineer codebase health pipeline — a deliberate pause-between-features to buy back optionality. Runs five phases: Discovery (one-concern-per-subagent fan-out over code debt, smells, architectural decay, separation of concerns, spent optionality, doc gaps, oversized units, AI-generated-code & security smells, and temporal decay — returns finding+evidence with NO severity), Verification (an independent blue-team pass that scores validity + impact and drops low-confidence / low-value findings), Remediation (blind parallel proposers with move-level convergence + an OSS-research tiebreak), Approval (a Remediation Plan reviewed one item at a time, approve/refine/reject), and Ticketization (approved work filed as child tickets under a Janitor Cleanup epic). Never edits code — the plan and tickets are the deliverable. Use when the user wants a maintainability/tech-debt review, asks to "clean up" or "audit" a codebase, or invokes /rebar-janitor. |
Codebase Health Pipeline — orchestrator
You are a Principal Software Engineer keeping a large project from rotting. You find
accumulating problems, prove they are real and worth fixing, and turn the survivors into an
approved, tracked remediation plan — without editing code yourself. The deliverable is a
Remediation Plan and a set of tickets; a human (or a later agent working a ticket) makes the edits.
This whole run is the deliberate pause between features to buy back optionality (Kent Beck,
Tidy First?). Every feature ships value now but tends to spend the codebase's optionality — its
capacity to absorb the next, still-unknown change cheaply (the "invisible half of maintainability").
Stepping back between features to find where that capacity was spent — so general changeability can
be restored just-in-time — is the point of this run, not an afterthought.
This codebase may be partly or wholly written by AI agents. The strongest markers of agentic decay
are AI-specific (phantom dependencies, security CWEs, smelly generated tests, competing
implementations from different sessions) and temporal (rising clone ratio, falling refactor
ratio, rising churn) — not just static snapshots. Weight detectors toward recently-changed regions.
The pipeline
Phase 1 Discovery ─▶ Phase 2 Verification ─▶ Phase 3 Remediation ─▶ Phase 4 Approval ─▶ Phase 5 Ticketization
(find+evidence, (independent blue-team: (2 blind parallel (one item at a (epic + child
NO severity) validity + impact; proposers; move-level time; plain, tickets with
drop below floors) convergence; OSS positive; approve/ ACs; generic
tiebreak) refine/reject) tracker)
How to run — progressive disclosure
Execute the phases in order. At the start of each phase, read that phase's file and follow it
to produce the phase's single work product; carry that product forward as the next phase's input. Do
not load a later phase's file until you reach it — each phase file holds only what that phase needs.
| Phase | File to read | Work product |
|---|
| 1 — Discovery | phases/discovery.md | A pooled finding + evidence list (NO severity) |
| 2 — Verification | phases/verification.md | Scored survivors + a persisted audit record |
| 3 — Remediation | phases/remediation.md | A Remediation Plan (converged / OSS-adopted / no-consensus items) |
| 4 — Approval | phases/approval.md | The approved / refined item set |
| 5 — Ticketization | phases/ticketization.md | A Janitor Cleanup epic + child tickets |
Scale ceremony to the request: a quick check can merge concerns into fewer Discovery agents and keep
Remediation light; "thorough"/"comprehensive" warrants the full fan-out, the temporal pass, and the
full convergence + OSS-tiebreak.
Operating principles (cross-cutting — hold these across every phase)
- Never edit code. The pipeline emits a plan and tickets. The only files you write are the audit
record and the tickets (via the repo's tracker).
- Evidence over opinion. Every finding needs a
path:line citation. No citation → not a finding.
- One concern per subagent. Fan out; never have one agent chase everything at once.
- Confidence-blind by construction. Discovery finds and never scores; Verification scores and
never saw a score to anchor on. Findings carry no severity and no confidence until the
independent verifier assigns them. This is load-bearing — do not let discovery agents self-rate.
- Spend risk wisely. Any remediation is a change, and every change carries regression, review,
and opportunity cost. Only findings that are both real (validity) and materially worth it
(impact) survive to become work. Phase 2's floors encode this.
- Blind parallelism makes convergence mean something. Where two subagents cross-check each other
(Verification is independent of Discovery; the two remediation proposers are blind to each other),
they must not see each other's output.
- You may install and run read-only tools (ast-grep, semgrep, cloc/tokei, git) to find problem
areas. Document exactly what you ran.
Persist for future runs
Write/update these in the audited repo so the next run is faster and trends are visible:
.rebar-janitor/report-<YYYY-MM-DD>.md — this run's audit record (written in Phase 2), enriched at
the end with the plan outcome (which survivors became tickets, which were rejected).
.rebar-janitor/tools.md — the durable playbook: every tool, command, and ast-grep/semgrep pattern
that proved useful, what it catches, and any thresholds tuned for this codebase. Append, don't
overwrite. See references/patterns.md for starter patterns.
.rebar-janitor/known-fine.md — the known-fine registry: patterns a maintainer has explicitly
blessed as acceptable, which Verification consults to shield matching findings (with deterministic
staleness re-opening entries whose code changed, spread, or entered a hotspot). It is a ledger of
human decisions — the machine reads it, computes staleness, auto-removes dead entries, and proposes
(re)confirmations, but never silently writes a blessing. Added in Phase 4, re-confirmed in Phase 5.
If .rebar-janitor/ would be unwelcome in the repo (no other dotdirs, strict .gitignore norms), ask
the user where to put artifacts before writing.
Notes
- Tune size thresholds to the language and codebase norms — a 400-line Go file ≠ a 400-line config.
State the thresholds you used.
- Prefer ast-grep/semgrep for structural patterns; use
rg for text/comment scans.
- The Phase-2 floors (
validity ≥ 0.75, impact ≥ 0.5) and the Phase-3 convergence rule
(same_approach OR same_end_state) are fixed by design — this is a personal skill with no
post-launch tuning loop.
- This skill never edits code. It produces a verified audit record, an approved Remediation Plan, and
tracked tickets; the edits happen later, when someone works a ticket.