clean
End-to-end cleanup orchestrator. The primary agent owns scope, sequencing, test risk assessment, and final synthesis. Phase work runs in subagents using the existing focused skills: spectre-prune, spectre-test, and spectre-sweep.
Inputs
$ARGUMENTS— optional scope hint: commit/SHA,unstaged/staged,context/session, task dir, files, or--orchestratedwhen a parent workflow owns the next step.FEATURE_ROOT— explicit feature name/root or one descendant feature artifact.
Working Set
- Resolve one managed
FEATURE_ROOTfor this work from explicit/current-thread evidence only (physical directory wins; never branch/recency/lifecycle/scans). If none is confirmed, including when the candidate path is occupied, standalone MUST first load and followSkill(spectre-feature-root)through DONE; orchestrated calls escalate. Keep writes beneath it and pass it unchanged. - Resolve the same full working set used by prune/test/sweep from committed changes, staged, unstaged, and untracked files. If a provided ref/scope is invalid or ambiguous, stop and ask.
- Keep the resolved file set and primary's compact P0-P3 risk plan in-thread; write no working-set/lifecycle artifact.
Outputs + DONE
spectre-prunecleanup completed by a subagent; manual-review items preserved.- Primary-authored P0-P3 risk assessment and test plan passed in-thread to test owners.
spectre-testwork completed by@spectre_testertest-lead subagents using the primary's risk plan.spectre-sweepcompleted by a subagent, including final hygiene, verification, and conventional commits.- Final report: prune/manual review · risk tiers · tests/affected checks · routed findings · sweep commits ·
NEEDS_AUTHORITY, if any. - DONE when: every phase ran in its owning subagent, the primary supplied risk tiers, repairable findings were repaired/routed by their owner, manual-review items surfaced, and sweep committed or returned genuine
NEEDS_AUTHORITY.
Method / guardrails
- Resolve scope once. Establish files and feature root. Keep dynamic details out of the prompt body; read them live.
- Prune phase. Dispatch a prune-lead subagent instructed to load and execute
Skill(spectre-prune)with{FEATURE_ROOT} --orchestratedfor the resolved scope. It returns cleanup edits, compact summary, validation status, and manual-review items. - Primary risk assessment. After prune returns, the primary classifies every changed file P0-P3:
- P0 Critical: auth/payment/security/crypto/session/token, PII, permissions, user-data mutation, external API handlers, DB migrations,
@critical. - P1 Core: feature components, API handlers, state/business logic, fetch/cache, user-visible error paths.
- P2 Supporting: exported utilities, validators, transformers, adapters, hooks with real logic.
- P3 Skip: docs, styles, config, types, constants/enums, re-export barrels, pass-through wrappers, generated files.
Keep a compact plan in-thread:
- [P{tier}] {file}: {behavior or SKIP reason}.
- P0 Critical: auth/payment/security/crypto/session/token, PII, permissions, user-data mutation, external API handlers, DB migrations,
- Test phase. Dispatch
@spectre_testertest-lead subagents in parallel. Each subagent loadsSkill(spectre-test)with{FEATURE_ROOT} --orchestrated, consumes the primary risk plan for its batch, and does the test/verification work. P0 gets dedicated focus; P1/P2 may be grouped; P3 is skipped with reason. - Sweep phase. Dispatch a sweep-lead subagent instructed to load and execute
Skill(spectre-sweep)with--orchestratedon the resulting diff. Sweep owns final hygiene, verification, and commits. - Synthesize. Route repairable findings to their owner; report final state, routed findings, and genuine authority/safety impasses.
Guardrails:
- Do not inline the bodies of prune/test/sweep; call the skills.
- Do not let the primary perform prune edits, test authoring, or sweep commits; repairable findings remain with the owning child, which continues without a user gate.
CONFIRMED_SAFEcleanup may be applied;UNCERTAIN/UNSAFEcleanup stays untouched and appears in final manual review.--no-verify, lint/type suppressions, and forced green are forbidden unless the user explicitly permits them.
Handoff
NEEDS_AUTHORITY reports its phase/impasse and manual-review list. Ordinary test/lint/build failures never produce it; repair or route them. Otherwise report commits.
--orchestrated→ return the result to the caller without user-facing Next Steps.- Standalone →
Next (recommended): spectre-rebase — clean completed and the committed branch is ready for safe merge preparation.Addspectre-proveonly as a conditional alternative when acceptance evidence is still desired before shipping.
Escalate-If
- Scope is ambiguous, a ref is invalid, or no meaningful working set exists.
- A phase skill conflicts with this orchestration contract; surface the conflict instead of improvising.
- P0 coverage exposes a product-requirement or user-authority conflict with no safe executable alternative; ordinary coverage gaps remain in repair/adaptation.
- Sweep finds secrets/PII or cannot commit without bypassing verification.