Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

refactor(core): remove unreferenced helpers, attributes and a shadowed module (#4091)

Tejas Chopra08fce1831067
diff --git a/headroom/ccr/batch_processor.py b/headroom/ccr/batch_processor.py
index bfe73b317..49abf4230 100644
--- a/headroom/ccr/batch_processor.py
+++ b/headroom/ccr/batch_processor.py
@@ -23,7 +23,7 @@ from __future__ import annotations
import json
import logging
from dataclasses import dataclass
-from typing import Any, Protocol
+from typing import Any
import httpx
@@ -34,19 +34,6 @@ from .tool_injection import CCR_TOOL_NAME
logger = logging.getLogger(__name__)
-class APIClient(Protocol):
- """Protocol for making API calls."""
-
- async def post(
- self,
- url: str,
- headers: dict[str, str],
- json: dict[str, Any],
- ) -> httpx.Response:
- """Make a POST request."""
- ...
-
-
@dataclass
class BatchResultProcessorConfig:
"""Configuration for batch result processing."""
diff --git a/headroom/ccr/batch_store.py b/headroom/ccr/batch_store.py
index 4bee79897..a68779a99 100644
--- a/headroom/ccr/batch_store.py
+++ b/headroom/ccr/batch_store.py
@@ -126,7 +126,6 @@ class BatchContextStore:
self._ttl = ttl
self._max_contexts = max_contexts
self._lock = asyncio.Lock()
- self._cleanup_task: asyncio.Task | None = None
async def store(self, context: BatchContext) -> None:
"""Store a batch context.
diff --git a/headroom/ccr/mcp_server.py b/headroom/ccr/mcp_server.py
index 53fe4f977..de0e0e045 100644
--- a/headroom/ccr/mcp_server.py
+++ b/headroom/ccr/mcp_server.py
@@ -388,7 +388,6 @@ class HeadroomMCPServer:
self._stats = SessionStats()
self._local_store: Any = None # Lazy-initialized CompressionStore
self._token_estimator: EstimatingTokenCounter | None = None
- self._compressor_initialized = False
# File read cache: path → (content_hash, ccr_hash, line_count, token_count)
self._file_cache: dict[str, tuple[str, str, int, int]] = {}
diff --git a/headroom/cli.py b/headroom/cli.py
deleted file mode 100644
index c7e8c4775..000000000
--- a/headroom/cli.py
+++ /dev/null
@@ -1,6 +0,0 @@
-"""Backwards compatibility - CLI moved to headroom.cli package."""
-
-from headroom.cli import main
-
-if __name__ == "__main__":
- main()
diff --git a/headroom/client.py b/headroom/client.py
index c71133399..8ae403f10 100644
--- a/headroom/client.py
+++ b/headroom/client.py
@@ -642,46 +642,6 @@ class HeadroomClient:
self._storage.save(metrics)
raise
- def _call_openai(
- self,
- *,
- model: str,
- messages: list[dict[str, Any]],
- stream: bool,
- metrics: RequestMetrics,
- **kwargs: Any,
- ) -> Any:
- """Call OpenAI-style API."""
- return call_client_transport(
- "openai",
- self,
- model=model,
- messages=messages,
- stream=stream,
- metrics=metrics,
- **kwargs,
- )
-
- def _call_anthropic(
- self,
- *,
- model: str,
- messages: list[dict[str, Any]],
- stream: bool,
- metrics: RequestMetrics,
- **kwargs: Any,
- ) -> Any:
- """Call Anthropic-style API."""
- return call_client_transport(
- "anthropic",
- self,
- model=model,
- messages=messages,
- stream=stream,
- metrics=metrics,
- **kwargs,
- )
-
def _wrap_stream(
self,
stream: Iterator[Any],
diff --git a/headroom/copilot_auth.py b/headroom/copilot_auth.py
index d88bf27e4..a1fe3554e 100644
--- a/headroom/copilot_auth.py
+++ b/headroom/copilot_auth.py
@@ -281,17 +281,6 @@ def _configured_api_url() -> str:
return DEFAULT_API_URL
-def copilot_api_url() -> str:
- """Return the configured Copilot API base URL without any network calls.
-
- Resolves ``GITHUB_COPILOT_API_URL``, then the configured enterprise domain,
- then ``api.githubcopilot.com``. Unlike :func:`resolve_copilot_api_url` this
- performs no token exchange, so it is safe to call while routing a request.
- """
-
- return _configured_api_url()
-
-
# GitHub's token exchange advertises the host that serves inline completions
# under ``endpoints.proxy``, alongside the ``endpoints.api`` chat host. It is
# recorded here when observed so completions routing uses GitHub's own answer
diff --git a/headroom/perf/analyzer.py b/headroom/perf/analyzer.py
index 059cdd9ec..de32f4aca 100644
--- a/headroom/perf/analyzer.py
+++ b/headroom/perf/analyzer.py
@@ -67,12 +67,11 @@ _STAGE_TIMINGS_RE = re.compile(
# ---------------------------------------------------------------------------
-# Cache-aware pricing via LiteLLM
+# List pricing via LiteLLM
# ---------------------------------------------------------------------------
-# LiteLLM already knows per-token costs for 100+ models including
-# cache_read and cache_creation pricing. We call it directly instead
-# of maintaining our own pricing tables.
+# LiteLLM already knows per-token costs for 100+ models. We read it
+# directly instead of maintaining our own pricing tables.
try:
import litellm as _litellm
@@ -82,32 +81,6 @@ except ImportError:
_LITELLM_AVAILABLE = False
-def _litellm_cost(
- model: str,
- prompt_tokens: int,
- cache_read_tokens: int = 0,
- cache_write_tokens: int = 0,
-) -> float | None:
- """Compute input cost via litellm.cost_per_token (cache-aware).
-
- Returns total input cost in USD, or None if model not found.
- """
- if not _LITELLM_AVAILABLE:
- return None
- resolved = resolve_litellm_model(model)
- try:
- input_cost, _ = _litellm.cost_per_token(
- model=resolved,
- prompt_tokens=prompt_tokens,
- completion_tokens=0,
- cache_read_input_tokens=cache_read_tokens,
- cache_creation_input_tokens=cache_write_tokens,
- )
- return float(input_cost)
- except Exception:
- return None
-
-
def _get_list_price(model: str) -> float | None:
"""Get list input price per 1M tokens."""
if not _LITELLM_AVAILABLE:
diff --git a/headroom/telemetry/models.py b/headroom/telemetry/models.py
index 1c88499b6..86b25f44b 100644
--- a/headroom/telemetry/models.py
+++ b/headroom/telemetry/models.py
@@ -633,38 +633,6 @@ class FieldSemantics:
self.inferred_type = inferred
self.confidence = confidence
- def is_value_important(self, value_hash: str) -> bool:
- """Check if a specific value is considered important.
-
- A value is important if:
- 1. It's in the important_value_hashes list (has been retrieved)
- 2. It's NOT the default value (for error_indicator type)
-
- Args:
- value_hash: SHA256[:8] hash of the value to check.
-
- Returns:
- True if this value should be preserved during compression.
- """
- # If we don't have enough data, be conservative
- if self.confidence < 0.3:
- return False
-
- # For error_indicator: non-default values are important
- if self.inferred_type == "error_indicator":
- if self.default_value_hash and value_hash != self.default_value_hash:
- return True
-
- # For any type: values that have been retrieved are important
- if value_hash in self.important_value_hashes:
- return True
-
- # For status: check if this value has been retrieved
- if self.inferred_type == "status":
- return value_hash in self.value_retrieval_frequency
-
- return False
-
@dataclass
class CompressionEvent:
diff --git a/headroom/telemetry/toin.py b/headroom/telemetry/toin.py
index 5d68a900e..ccf62f2d1 100644
--- a/headroom/telemetry/toin.py
+++ b/headroom/telemetry/toin.py
@@ -78,10 +78,6 @@ logger = logging.getLogger(__name__)
# Environment variable for custom TOIN storage path
TOIN_PATH_ENV_VAR = "HEADROOM_TOIN_PATH"
-# Default TOIN storage directory and file
-DEFAULT_TOIN_DIR = ".headroom"
-DEFAULT_TOIN_FILE = "toin.json"
-
# ── Aggregation-key defaults ────────────────────────────────────────────
# Used when callers haven't plumbed auth-mode / model-family detection
# (PR-F3 wires the real detectors). Shipping a real `"unknown"` slice is
diff --git a/pyproject.toml b/pyproject.toml
index f51483723..92679bf00 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -541,7 +541,6 @@ markers = [
source = ["headroom"]
branch = true
omit = [
- "headroom/cli.py",
"*/tests/*",
]