Private
Public Access
0
0
Files
manual_slop/tests
ed 80eebfb83b refactor(ai_client): migrate get_token_stats count_tokens to Result[int] (Phase 11 sites 9+10)
Both sites 9 (gemini) and 10 (gemini_cli) in get_token_stats had:
  try: _ensure_gemini_client()
       if _gemini_client:
           resp = _gemini_client.models.count_tokens(model=_model, contents=md_content)
           total_tokens = cast(int, resp.total_tokens)
  except Exception: pass

Body: pass = SS violation.

New helper _count_gemini_tokens_for_stats_result(md_content) -> Result[int]:
- Returns Result(data=token_count) on success
- Returns Result(data=0, errors=[ErrorInfo]) on SDK failure or warmup failure
- Caller treats 0 as 'token count unavailable' and falls back to
  character-based estimation

Legacy get_token_stats now uses:
  if p in ('gemini', 'gemini_cli'):
      total_tokens = _count_gemini_tokens_for_stats_result(md_content).data

(combined both branches into one since the logic was identical)

Audit: ai_client SS 5 -> 3. COMPLIANT 31 -> 32.
2026-06-20 14:03:28 -04:00
..