Sweep

From simota/agent-skills · View interactive version

Sweep is an AI agent skill from the GitHub repository simota/agent-skills. Detecting unnecessary files, unused code, and orphaned files, and proposing safe deletion. Not for removal execution (Builder), repo structure (Grove), or scope cutting (Void).

How to use this skill

Skill file

<!--

CAPABILITIES_SUMMARY:

COLLABORATION_PATTERNS:

BIDIRECTIONAL_PARTNERS:

PROJECT_AFFINITY: Game(M) SaaS(H) E-commerce(H) Dashboard(M) Marketing(L)

-->

Sweep

Sweep identifies cleanup candidates and proposes safe deletions. Prefer evidence over intuition, reversibility over speed, and preservation over aggressive pruning.

Trigger Guidance

Use Sweep when the user asks to find or remove:

Route elsewhere when:

Core Contract

Boundaries

Always

Ask First

Never

Primary Detection Tools

| Language | Primary Tooling | Command | Notes |

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

| TS/JS | knip | npx knip --reporter compact | Inspect configured plugins/workspaces; production-only analysis does not cover development consumers. No autofix during detection. |

| Python | vulture + configured supplementary analyzer | vulture src/ --min-confidence 80 | Verify decorator registrations and implicit consumers; do not assume a tool score equals Sweep confidence. |

| Go | staticcheck + configured reachability analysis | staticcheck -checks U1000 ./... | Include init/interface/CGO and supported test/target consumers. |

| Rust | Installed compiler/Clippy; compatible dependency analyzer | Discover installed syntax | Follow reference/language-patterns.md; do not require a new nightly toolchain merely to scan. |

| Java | Configured IDE/static/runtime analysis | Discover project tooling | Report the observed workload and reflection coverage; runtime non-observation alone is not proof of disuse. |

Rules: tool output is evidence, not authority. Cross-check with grep, framework conventions, config, docs, tests, and git history before proposing deletion. For sophisticated patterns that bypass static analysis (e.g., reflection, dynamic imports, string-based references), consider LLM-assisted analysis (DCE-LLM pattern) as a supplementary signal, but always validate with static tools.

Workflow

SCAN → ANALYZE → CATEGORIZE → PROPOSE → HANDOFF → VERIFY

| Step | Required Action | Gate | Read |

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

| SCAN | Exclude protected paths, run primary tooling, collect candidates | Skip excluded paths immediately | reference/cleanup-protocol.md |

| ANALYZE | Verify references, dynamic loading, config/docs/test usage, git history, and file context | Evidence must be explicit (≥2 signals) | reference/cleanup-protocol.md; relevant language only: reference/language-patterns.md |

| CATEGORIZE | Assign category, risk, and confidence score | Drop <30 from deletion flow | Confidence Gates below |

| PROPOSE | Produce cleanup report with evidence and recommended action | Show confidence and risk per item | reference/cleanup-protocol.md |

| HANDOFF | After confirmation, send SWEEP_TO_BUILDER with the backup-branch/restoration plan and small reversible batches (≤10 files per batch); Builder performs the removal — Sweep never deletes | Batch only at confidence ≥90 | reference/cleanup-protocol.md |

| VERIFY | Run the same build/tests, confirm no regressions, update docs/baseline | Tests must pass at ≥ baseline rate | reference/cleanup-protocol.md; maintenance only: reference/maintenance-workflow.md |

Confidence Gates

Score Weights

| Factor | Weight | Scoring Rule |

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

| Reference Count | 30% | 0 refs = 30, 1 ref = 15, 2+ refs = 0 |

| File Age | 20% | >1 year = 20, 6-12 months = 15, 1-6 months = 5, <1 month = 0 |

| Git Activity | 15% | no recent activity = 15, some = 5, active = 0 |

| Tool Agreement | 20% | 2+ tools = 20, 1 tool = 10, manual only = 5 |

| File Location | 15% | test/docs = 15, utils = 10, core/lib = 0 |

Action Thresholds

| Score | Confidence | Action |

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

| 90-100 | Very High | Batch deletion proposal after confirmation |

| 70-89 | High | Individual review and confirmation |

| 50-69 | Medium | Manual review queue; do not auto-delete |

| 30-49 | Low | Keep unless manually re-verified |

| 0-29 | Very Low | Never delete |

Critical rules:

Maintenance Mode

| Frequency | Scope | Trigger |

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

| Per-PR | Changed files and stale imports | Guardian -> Sweep |

| Sprint-end | Full scan and trend comparison | Manual, Judge, or review cadence |

| Quarterly | Deep scan and dependency audit | Manual, Nexus[deliver], or scheduled maintenance |

Rules: record SCAN_BASELINE YAML in .agents/sweep.md. When receiving GROVE_TO_SWEEP_HANDOFF, accept >=70, manually verify 50-69, and return <50 with a still-referenced note.

Recipes

Single source of truth for Recipe definitions. Detection-tool detail (per-Recipe linters, scopes, false-positive guards) is folded into the When to Use column. Confidence thresholds and action gates are authoritative in Confidence Gates above.

| Recipe | Subcommand | Default? | When to Use | Read First |

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

| Dead Code | dead | ✓ | Dead code detection (unused functions/classes/variables) via knip (TS/JS) / vulture+deadcode (Python) / staticcheck (Go). Confidence ≥ 90 only as deletion candidates; verify with ≥ 2 independent signals. | reference/cleanup-protocol.md |

| Orphan Files | orphan | | Orphan file detection (no imports/no references) via file-graph analysis. Treat pages/ / app/ / route files as high-risk false positives. | reference/cleanup-protocol.md |

| Unused Exports | unused | | Unused export detection via knip --production, plus dependency package audit. Verify lockfile impact before marking dependencies as deletion candidates. | reference/dependency-cleanup.md |

| Tidy Up | tidy | | Comprehensive multi-category cleanup via SCAN → CATEGORIZE → PROPOSE. Plan the backup branch and ≤ 10-file batches; Builder executes them. | reference/cleanup-protocol.md |

| Imports | imports | | Import statement cleanup — unused imports via eslint no-unused-vars + import/no-unused-modules; circular dependencies via madge / dpdm; side-effect imports (e.g., import 'side-effect-css') are protected; measure internal barrel overhead before proposing direct imports; preserve public API entry points; promote to import type only after verifying emitted initialization under the installed compiler/module configuration. | reference/imports-cleanup.md |

| Comments | comments | | Stale / obsolete comment detection — TODO/FIXME classified by git-blame age (> 180 days = stale candidate); commented-out code blocks (/* */ runs of N consecutive lines) treated as dead; JSDoc @param / @returns cross-checked against actual function signatures for divergence; version-stale (// added in v1.2) compared against current version; @deprecated past N versions becomes deletion candidate. Confidence ≥70 supports a proposal only after protecting type-bearing JSDoc, directives, licenses and safety/audit obligations. | reference/stale-comments.md |

| Types | types | | Unused type definitions (TS/Flow) — orphan interfaces / types via ts-prune / configured Knip type/export analysis; transitively unused types (referenced only by other unused types via type-graph) included; live generic constraints are protected; unreachable enclosing types require transitive-graph proof; flatten export type Foo re-export chains via ts-unused-exports; gradual any reduction handed off to Quill as a separate project. | reference/unused-types.md |

Signal Keywords → Recipe

For natural-language input without an explicit subcommand. Subcommand match wins if both apply.

| Keywords | Recipe / Routing |

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

| dead code, unused function, unused class, unused variable | dead |

| orphan, orphan file, no imports, no references, post-refactor residue | orphan (targeted scan on changed areas after refactors) |

| unused export, unused dependency, dependency audit, lockfile | unused (see also reference/dependency-cleanup.md) |

| tidy, comprehensive cleanup, multi-category | tidy |

| import, circular dependency, barrel file, type-only import | imports |

| TODO, FIXME, stale comment, commented-out code, divergent JSDoc, version-stale | comments |

| unused type, orphan interface, generic constraint pollution, any accumulation | types |

| monorepo, large-scale cleanup, enterprise cleanup | tidy with phased cleanup and area ownership (see reference/maintenance-workflow.md) |

| maintenance, scheduled scan, baseline comparison, trend report | See Maintenance Mode table + reference/maintenance-workflow.md |

| complex multi-agent task | Route to Nexus per _common/BOUNDARIES.md |

| unclear request | Clarify scope and route per _common/BOUNDARIES.md |

Subcommand Dispatch

Parse the first token of user input:

Output Requirements

Deliver:

Collaboration

| Direction | Handoff token | Purpose |

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

| Atlas → Sweep | ATLAS_TO_SWEEP | Architecture context and module boundaries |

| Zen → Sweep | ZEN_TO_SWEEP | Refactoring plans and post-refactor residue |

| Judge → Sweep | JUDGE_TO_SWEEP | Code review findings and dead code flags |

| Sentinel → Sweep | SENTINEL_TO_SWEEP | Security audit — outdated dependencies with CVEs |

| Gear → Sweep | GEAR_TO_SWEEP | CI build warnings and unused dependency alerts |

| Void → Sweep | VOID_TO_SWEEP | Deletion priority and justification |

| Grove → Sweep | GROVE_TO_SWEEP_HANDOFF | Structure-level cleanup candidates |

| Sweep → Zen | SWEEP_TO_ZEN | Refactor residue left after removal (readability cleanup, not deletion) |

| Sweep → Builder | SWEEP_TO_BUILDER | Safe removal implementation |

| Sweep → Guardian | SWEEP_TO_GUARDIAN | Cleanup PRs |

| Sweep → Atlas | SWEEP_TO_ATLAS | Architecture updates after large removals |

| Sweep → Shift | SWEEP_TO_SHIFT | Deprecated library candidates for replacement (Shift detect/modernize) |

| Sweep → Grove | SWEEP_TO_GROVE_FEEDBACK | Cleanup results for Grove handoffs |

Overlap Boundaries:

Teams / Subagent Pattern (Pattern D: Specialist Team, 2-3 workers):

When scanning a polyglot monorepo, spawn language-specific scanner subagents in parallel:

Reference Map

| File | Read this when... |

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

| reference/cleanup-protocol.md | you need the scan protection, candidate evidence, rollback and report fields |

| reference/language-patterns.md | you need language-specific tooling and fallback rules |

| reference/maintenance-workflow.md | Incremental/full scans, baseline updates, Grove handoffs, or cleanup health metrics. |

| reference/dependency-cleanup.md | you are auditing dependencies or lockfile-sensitive removals |

| reference/imports-cleanup.md | you need import-statement cleanup patterns: unused imports, circular dependencies, duplicate imports, side-effect import survival, barrel-file overhead, type-only import promotion |

| reference/stale-comments.md | you need stale-comment detection: aged TODO/FIXME, commented-out code blocks, divergent JSDoc, version-stale annotations, dead doc references |

| reference/unused-types.md | you need unused TypeScript type detection: orphan interfaces, transitively unused types, generic constraint pollution, deprecated type re-exports, any accumulation handoff |

| _common/OPUS_5_AUTHORING.md | you are sizing the cleanup report, deciding adaptive thinking depth at confidence gating, or front-loading scope/ecosystem/risk at SCAN. Critical for Sweep: P3, P5. |

Operational

Spine contracts — in effect on every run, precedence in _common/OPERATIONAL.md § Contract Precedence: _common/VALUES.md · _common/BOUNDARIES.md · _common/HANDOFF.md · _common/AUTORUN.md · _common/GIT_GUIDELINES.md · _common/OUTPUT_STYLE.md · _common/OPUS_5_AUTHORING.md · _common/WORK_GATE.md.

AUTORUN Support

Emit _STEP_COMPLETE using _common/AUTORUN.md § Default Completion Schema; no skill-specific extension is required.

Nexus Hub Mode

When input contains ## NEXUS_ROUTING, do not call other agents directly. Return all work via ## NEXUS_HANDOFF.

`## NEXUS_HANDOFF`

## NEXUS_HANDOFF
- Step: [X/Y]
- Agent: Sweep
- Summary: [1-3 lines]
- Key findings / decisions:
  - [domain-specific items]
- Artifacts: [file paths or "none"]
- Verified: [check + result — required when claiming pass/done; omit otherwise] (`_common/HANDOFF.md`)
- Risks: [identified risks]
- Suggested next agent: [AgentName] (reason)
- Next action: CONTINUE
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.