Skip to content

Integrate static analysis tools for dead code detection in quality gate #524

@mickume

Description

@mickume

Problem

Dead code detection in nightshift relies solely on AI prompt analysis (nightshift/categories/builtins.py lines 14-26). The quality_gate.py category detects and runs pytest/ruff/mypy but doesn't include dead-code-specific static tools. AI analysis misses dead code that deterministic tools catch reliably.

The audit found v7 had a dead InvalidTransition error variant with no code behind it — exactly the kind of thing static tools catch.

Current behavior:

  • DeadCodeCategory sends file contents to an LLM with "analyze for dead code" prompt
  • No integration with vulture, ruff unused rules, or language-specific dead-code detectors
  • Quality gate runs pytest, ruff, mypy but not dead-code tools
  • Dead code findings are nightshift-only (hunt mode) — not checked during coder sessions

Proposed Changes

  1. Add dead-code static tools to quality_gate.py:

    • For Python targets: run ruff check --select F401,F811,F841 (unused imports, redefined unused, unused variables)
    • Optionally integrate vulture for deeper analysis (unused functions, classes, attributes)
    • For Rust targets: check cargo clippy dead_code warnings
    • For Go targets: check staticcheck unused results
  2. Run dead-code checks in the reviewer pipeline: after a coder session commits, run the static tool on modified files. Emit findings for any new dead code introduced.

  3. Add to preflight gate: include dead-code check results as a non-blocking warning (or blocking for egregious cases like entire unused modules).

Key Files

  • agent_fox/nightshift/categories/builtins.pyDeadCodeCategory (AI-only)
  • agent_fox/nightshift/categories/quality_gate.py — static tool runner infrastructure
  • agent_fox/nightshift/categories/base.pyBaseHuntCategory two-phase pattern
  • agent_fox/engine/preflight.py — preflight quality gates

Audit Evidence

From docs/audits/code_quality_5to7.md:

  • "Dead code in state manager — StateError::InvalidTransition variant exists, but transition() accepts anything" (Design smell in v7)
  • Static tools would have caught this deterministically without relying on AI judgment

Impact

Low effort, medium impact. The infrastructure for running external tools already exists in quality_gate.py. Adding ruff rules is a one-line config change. This catches an entire class of issues that AI analysis misses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions