name: audit description: Run a multi-category code audit on the cqs codebase. Spawns parallel agents per batch. disable-model-invocation: true argument-hint: "[batch-number|all]"
Audit
Run the 14-category code audit. Full design: docs/plans/2026-02-04-20-category-audit-design.md
Arguments
$ARGUMENTS— batch number (1-2) orallfor full audit
all means run BOTH batches — all 16 categories. Run batch 1, then batch 2, then triage all findings together. Do NOT stop after batch 1.
Batches
There are 16 categories split into 2 batches of 8. Each batch spawns 8 parallel agents (one per category). all runs both batches sequentially.
| Batch | Categories |
|---|---|
| 1 | Code Quality, Documentation, API Design, Error Handling, Observability, Test Coverage (adversarial), Robustness, Scaling & Hardcoded Limits |
| 2 | Algorithm Correctness, Extensibility, Platform Behavior, Security, Data Safety, Performance, Resource Management, Test Coverage (happy path) |
Process
Setup
Archive previous audit: If
docs/audit-findings.mdordocs/audit-triage.mdexist, rename both with the version suffix (e.g.,audit-findings-v0.9.1.md,audit-triage-v0.9.1.md). Each audit starts with fresh files.Enable audit mode:
cqs audit-mode on --expires 2h -q— prevents stale notes from biasing review
Per-Batch
Create team: One team per batch (
audit-batch-N)Spawn teammates: One per category (use
sonnetfor judgment-heavy categories,haikufor mechanical ones)Each teammate prompt must include:
- Their category scope (from table below)
- Instruction to read archived triage files (e.g.,
docs/audit-triage-v*.md) — skip anything already triaged in prior audits - Instruction to read
docs/audit-findings.mdfirst — skip anything already reported by earlier batches in this audit - Instruction to append findings to
docs/audit-findings.md - Format:
## [Category]\n\n#### [Finding title]\n- **Difficulty:** easy | medium | hard\n- **Location:** ...\n- **Description:** ...\n- **Suggested fix:** ... - Use
subagent_type: "auditor"when spawning — the auditor agent definition (.claude/agents/auditor.md) has cqs tools built in
Shutdown team after all agents complete
After All Batches
Triage: Read
docs/audit-findings.mdin full, then classify:- P1: Easy + high impact → fix immediately
- P2: Medium effort + high impact → fix in batch
- P3: Easy + low impact → fix if time
- P4: Hard or low impact → create issues for hard items; fix trivial ones inline (doc comments, one-liners, undocumented edge cases)
- Write triage to
docs/audit-triage.md— fresh file with P1-P4 tables (include Status column). This survives context compaction.
Generate fix prompts: For each P1, P2, and P3 finding, spawn opus agents to (P4 trivials get prompts too; hard P4s get issue descriptions):
- Read the actual source file at the stated line numbers
- Write a self-contained fix prompt with: exact file path, current code verbatim, replacement code, one-line "why"
- Group related findings (e.g., stale doc references) into a single prompt
- Save to
docs/audit-fix-prompts.md
Review fix prompts: Spawn a second opus agent to verify each prompt against the actual source:
- Does the "current code" match what's really in the file? (catches line drift)
- Does the fix compile? (check types, imports, API existence)
- Are there any missing edge cases?
- Report: "VERIFIED" or "NEEDS FIX — [specific issue]"
- This step catches ~20% of prompt errors (wrong field names, nonexistent APIs, moved code)
Execute fixes: P1 first, then P2. Mark each item in triage as fixed.
Disable audit mode:
cqs audit-mode off
Category Scopes
| Category | Covers (merged from) |
|---|---|
| Code Quality | Dead code, duplication, complexity, coupling, cohesion, module boundaries, convenience wrappers that hardcode defaults |
| Documentation | Accuracy, completeness, staleness of docs and comments |
| API Design | Consistency, ergonomics, naming, type design |
| Error Handling | Result chains, context, recovery, swallowed errors |
| Observability | Logging coverage, tracing, debuggability |
| Test Coverage (adversarial) | Edge-case/sad-path gaps: malformed input, NaN/Inf embeddings, concurrent access, empty queries, huge inputs, error paths not tested |
| Test Coverage (happy path) | Missing tests for high-caller public functions, untested modules, integration test gaps, meaningful assertion quality |
| Scaling & Hardcoded Limits | Constants that should scale with model config, corpus size, or hardware. Magic numbers without rationale. |
| Robustness | unwrap/expect, edge cases (empty/huge/unicode/malformed), panic paths |
| Algorithm Correctness | Off-by-one, boundary conditions, logic errors |
| Extensibility | Adding features without surgery, hardcoded values |
| Platform Behavior | OS differences, path handling, WSL quirks |
| Security | Injection, path traversal, file permissions, secrets, access control |
| Data Safety | Corruption, validation, migrations, races, deadlocks, thread safety |
| Performance | O(n²), unnecessary iterations, batching, caching, I/O patterns |
| Resource Management | Memory usage, startup time, idle cost, OOM protection, leaks |
Mandatory First Steps per Category
Run these cqs commands before manual exploration — they surface the highest-value data in a single call.
Batch 1:
- Code Quality: Run
cqs dead --json+cqs health --jsonfirst. Also grep for convenience wrappers that hardcode defaults (e.g.,fn foo()that callsfoo_with_dim(HARDCODED)) — these mask incorrect wiring when the default changes. - Documentation: Run
cqs health --jsonfor staleness counts. - API Design: No mandatory command.
- Error Handling: No mandatory command — grep-driven.
- Observability: No mandatory command — grep for
tracing::patterns.
Batch 2:
- Test Coverage: Run
cqs health --jsonfirst (includes untested hotspots). Also check for adversarial test gaps: functions that accept user input, external data, or embeddings should have tests for malformed/adversarial inputs (empty, NaN, truncated, wrong-type, concurrent). - Robustness: No mandatory command — grep for
.unwrap(),.expect(,panic!. - Algorithm Correctness: Use
cqs explain <fn> --jsonon algorithmic functions. - Extensibility: Run
cqs health --jsonfor hotspot overview. - Platform Behavior: No mandatory command.
Batch 3:
- Security: No mandatory command.
- Data Safety: No mandatory command.
- Performance: Run
cqs health --jsonfirst (identifies hotspots). - Resource Management: No mandatory command.
Rules
- Collect ALL findings before fixing ANY
- One batch at a time (context limits)
- Clean up teams between batches
- Stop at diminishing returns during discovery
- Once triaged, complete the tier — don't suggest stopping mid-priority
- Cross-check findings against open GitHub issues — note overlaps as "existing #NNN"
- Mark items in
docs/audit-triage.mdas fixed when done — update the Status column (e.g.,✅ PR #Nor✅ fixed). This is the source of truth for what's been addressed.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.