Codebase Sweep
Deploy 4 parallel review agents to scan the entire SwarmLLM codebase for issues. Each agent focuses on a different category. All findings are collected, deduplicated, and presented as a prioritized action list.
Pre-Sweep: Load Prior Findings
Before launching agents, check if .claude/sweep-log.jsonl exists. If it does:
- Read its contents — each line is a JSON object:
{"file":"...","line":N,"kind":"...","summary":"...","status":"fixed|wontfix|deferred","date":"YYYY-MM-DD"}
- Extract all entries where
status is "fixed" or "wontfix" — these are KNOWN issues
- Pass the known-issues list to EACH agent with explicit instructions: "Do NOT re-report any of these known issues. Focus on finding NEW issues not in this list."
If the file doesn't exist, proceed normally (first sweep).
File Rotation Strategy
To avoid always scanning files in the same order (which causes convergence):
- Get the list of all
.rs files: find src/ -name '*.rs' | sort
- Get the list of all
.js files: find frontend/js/ -name '*.js' | sort
- Pick a rotation offset based on the current sweep count (line count of sweep-log.jsonl ÷ 10, modulo file count)
- Tell Agent 1+3 to start from offset N in the Rust file list, wrapping around
- Tell Agent 2+4 to start from offset N in the JS/frontend file list, wrapping around
This ensures each sweep round examines files in a different order.
Agents to Deploy (in parallel, with isolation: "worktree")
IMPORTANT: Launch all agents with isolation: "worktree" so they get clean context without session history pollution.
Agent 1: Dead Code + Stale References (model: sonnet, type: feature-dev:code-reviewer)
- pub functions with zero external callers
- Unused imports, dead constants, unreachable match arms
- Stale comments referencing removed code ("NOTE: X removed", "replaced by Y")
- References to old channel names, old struct fields, removed endpoints
#[allow(dead_code)] that suppress legitimate warnings
Agent 2: Duplication + Copy-Paste (model: sonnet, type: feature-dev:code-reviewer)
- Nearly identical code blocks in different files (>5 lines)
- Same data transformation done in multiple places
- Duplicate API response shapes for the same data
- Frontend: duplicate fetch calls, duplicate DOM manipulation patterns
Agent 3: Consistency + Production Readiness (model: sonnet, type: feature-dev:code-reviewer)
- SwarmError type misuse (Config/Internal for validation)
- Unbounded collections without cleanup
- Missing input validation on API endpoints
- Hardcoded magic numbers that should be named constants
- Bare string tracing calls without structured fields
Agent 4: Frontend + i18n + Docs (model: sonnet, type: feature-dev:code-reviewer)
- Hardcoded English strings bypassing I18n.t()
- Dead CSS rules, dead JS functions, broken references
- Stale doc comments that don't match current code
- CLAUDE.md, ARCHITECTURE.md, book/ out of sync with code
After Agents Return
- Deduplicate findings across agents
- Compare against known issues from sweep-log.jsonl — drop any re-reports
- Rate each NEW finding by priority (CRITICAL > HIGH > MEDIUM > LOW) and effort (small/medium/large)
- Triage into two buckets:
- Auto-fix (do immediately, no prompting): dead code removal, unused imports, stale comments, dead CSS/JS, missing i18n keys, hardcoded strings, duplicate code extraction, stale doc updates, magic number constants, simple consistency fixes. Anything where the correct fix is obvious and low-risk.
- Needs discussion (present to user): architectural changes, behavior changes, ambiguous deletions (might be used via reflection/macros), security-sensitive fixes, anything touching the inference hot path, changes that affect the public API contract, or findings where you're <90% confident in the fix.
- Research before fixing — Before implementing any non-trivial fix, WebSearch for:
- Latest docs/best practices for the relevant library or pattern (e.g., libp2p API changes, axum middleware patterns, candle tensor ops)
- Similar open-source projects solving the same problem — check how they handle it
- GitHub issues/discussions if the fix involves a known library quirk
- Even for fixes you're confident about, a quick search often reveals a better idiomatic approach
- Skip research only for truly mechanical fixes (deleting dead code, removing unused imports, fixing typos)
- Fix everything in the auto-fix bucket immediately — commit as you go
- Present only the "needs discussion" items to the user, if any
After Fixes Are Applied
For every finding that was addressed (fixed, deferred, or won't-fix), append a line to .claude/sweep-log.jsonl:
{"file":"src/api/server.rs","line":42,"kind":"dead_code","summary":"unused handle_legacy() function","status":"fixed","date":"2026-04-04"}
This log ensures future sweeps skip known issues and focus on genuinely new problems.
Rules
- Every finding must include: file, line, what's wrong, confidence (80%+ only)
- Do NOT report items that are intentionally deferred (check CLAUDE.md deferred list)
- Do NOT report test-only code as dead (check if it's used in #[cfg(test)] blocks)
- Do NOT re-report anything already in sweep-log.jsonl
- Each agent MUST scan its full assigned file range, not just "interesting" files
- If a sweep round finds 0 new issues, report that clearly — don't manufacture findings
1---2name: sweep3description: Deploy parallel agents to scan the entire codebase for dead code, duplication, inconsistencies, and stale references4---56# Codebase Sweep78Deploy 4 parallel review agents to scan the entire SwarmLLM codebase for issues. Each agent focuses on a different category. All findings are collected, deduplicated, and presented as a prioritized action list.910## Pre-Sweep: Load Prior Findings1112Before launching agents, check if `.claude/sweep-log.jsonl` exists. If it does:131. Read its contents — each line is a JSON object: `{"file":"...","line":N,"kind":"...","summary":"...","status":"fixed|wontfix|deferred","date":"YYYY-MM-DD"}`142. Extract all entries where `status` is `"fixed"` or `"wontfix"` — these are KNOWN issues153. Pass the known-issues list to EACH agent with explicit instructions: "Do NOT re-report any of these known issues. Focus on finding NEW issues not in this list."1617If the file doesn't exist, proceed normally (first sweep).1819## File Rotation Strategy2021To avoid always scanning files in the same order (which causes convergence):22231. Get the list of all `.rs` files: `find src/ -name '*.rs' | sort`242. Get the list of all `.js` files: `find frontend/js/ -name '*.js' | sort`253. Pick a rotation offset based on the current sweep count (line count of sweep-log.jsonl ÷ 10, modulo file count)264. Tell Agent 1+3 to start from offset N in the Rust file list, wrapping around275. Tell Agent 2+4 to start from offset N in the JS/frontend file list, wrapping around2829This ensures each sweep round examines files in a different order.3031## Agents to Deploy (in parallel, with isolation: "worktree")3233IMPORTANT: Launch all agents with `isolation: "worktree"` so they get clean context without session history pollution.3435### Agent 1: Dead Code + Stale References (model: sonnet, type: feature-dev:code-reviewer)36- pub functions with zero external callers37- Unused imports, dead constants, unreachable match arms38- Stale comments referencing removed code ("NOTE: X removed", "replaced by Y")39- References to old channel names, old struct fields, removed endpoints40- `#[allow(dead_code)]` that suppress legitimate warnings4142### Agent 2: Duplication + Copy-Paste (model: sonnet, type: feature-dev:code-reviewer)43- Nearly identical code blocks in different files (>5 lines)44- Same data transformation done in multiple places45- Duplicate API response shapes for the same data46- Frontend: duplicate fetch calls, duplicate DOM manipulation patterns4748### Agent 3: Consistency + Production Readiness (model: sonnet, type: feature-dev:code-reviewer)49- SwarmError type misuse (Config/Internal for validation)50- Unbounded collections without cleanup51- Missing input validation on API endpoints52- Hardcoded magic numbers that should be named constants53- Bare string tracing calls without structured fields5455### Agent 4: Frontend + i18n + Docs (model: sonnet, type: feature-dev:code-reviewer)56- Hardcoded English strings bypassing I18n.t()57- Dead CSS rules, dead JS functions, broken references58- Stale doc comments that don't match current code59- CLAUDE.md, ARCHITECTURE.md, book/ out of sync with code6061## After Agents Return62631. Deduplicate findings across agents642. Compare against known issues from sweep-log.jsonl — drop any re-reports653. Rate each NEW finding by priority (CRITICAL > HIGH > MEDIUM > LOW) and effort (small/medium/large)664. **Triage into two buckets:**67 - **Auto-fix** (do immediately, no prompting): dead code removal, unused imports, stale comments, dead CSS/JS, missing i18n keys, hardcoded strings, duplicate code extraction, stale doc updates, magic number constants, simple consistency fixes. Anything where the correct fix is obvious and low-risk.68 - **Needs discussion** (present to user): architectural changes, behavior changes, ambiguous deletions (might be used via reflection/macros), security-sensitive fixes, anything touching the inference hot path, changes that affect the public API contract, or findings where you're <90% confident in the fix.695. **Research before fixing** — Before implementing any non-trivial fix, WebSearch for:70 - Latest docs/best practices for the relevant library or pattern (e.g., libp2p API changes, axum middleware patterns, candle tensor ops)71 - Similar open-source projects solving the same problem — check how they handle it72 - GitHub issues/discussions if the fix involves a known library quirk73 - Even for fixes you're confident about, a quick search often reveals a better idiomatic approach74 - Skip research only for truly mechanical fixes (deleting dead code, removing unused imports, fixing typos)756. Fix everything in the auto-fix bucket immediately — commit as you go767. Present only the "needs discussion" items to the user, if any7778## After Fixes Are Applied7980For every finding that was addressed (fixed, deferred, or won't-fix), append a line to `.claude/sweep-log.jsonl`:81```json82{"file":"src/api/server.rs","line":42,"kind":"dead_code","summary":"unused handle_legacy() function","status":"fixed","date":"2026-04-04"}83```8485This log ensures future sweeps skip known issues and focus on genuinely new problems.8687## Rules88- Every finding must include: file, line, what's wrong, confidence (80%+ only)89- Do NOT report items that are intentionally deferred (check CLAUDE.md deferred list)90- Do NOT report test-only code as dead (check if it's used in #[cfg(test)] blocks)91- Do NOT re-report anything already in sweep-log.jsonl92- Each agent MUST scan its full assigned file range, not just "interesting" files93- If a sweep round finds 0 new issues, report that clearly — don't manufacture findings