Skip to main content

Module code_quality

Module code_quality 

Source
Expand description

The code-quality analyzer: render a payload, ask the LLM, turn the response into findings — and never report an unanalyzed file as clean.

The contract this type implements is the Phase 4b spec verbatim:

  1. No language, no analysis. drep has no opinion on a file type it does not claim, and silently returning an empty result is the correct behavior — not a failure. The CLI surfaces “no language” by simply not including the file in the work set.
  2. Empty hunks → empty result, no LLM call.
  3. Build the payload with payload::render. None → empty result.
  4. Cache first. A hit is parsed exactly as a Complete response would be, and the duplicate is silent — the caller’s view is identical.
  5. Concurrency. A limiter slot is acquired before the LLM call and held for the duration. A cache hit must not acquire a slot: the slot represents in-flight HTTP work, and a cache read is not in-flight.
  6. Ok(Extracted::Complete) → parse, store in the cache.
  7. Ok(Extracted::Truncated) → parse the partial result AND mark the file failed. Never cache a truncated response — caching it makes one truncation permanent for the whole TTL, and this layer does not know about --fail-on (a caller deciding otherwise would make failed_files depend on a CLI flag, which is the wrong layering).
  8. Err(LlmError::*) → no findings, file in failed_files with the specific LLM layer that failed.

The five rules around out-of-range lines, missing fields, unknown severities, and issues itself being absent are at the boundary between “model misreported” and “we could not understand the response”. The first is a finding we drop; the others are file-level failures, because a file we did not fully understand must never be reported clean.

Structs§

CodeQualityAnalyzer
The code-quality analyzer.