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.

Fix ruff format for litellm, wrap, test_scanner

chopratejasf6a6c609ada8
diff --git a/headroom/backends/litellm.py b/headroom/backends/litellm.py
index ddcf0b5f8..296aba53b 100644
--- a/headroom/backends/litellm.py
+++ b/headroom/backends/litellm.py
@@ -120,9 +120,7 @@ def _build_bedrock_fallback_map(region: str) -> dict[str, str]:
("claude-haiku-4-5-20251001", "anthropic.claude-haiku-4-5-20251001-v1:0"),
]
- return {
- name: f"bedrock/{prefix}.{model_id}" for name, model_id in _CLAUDE_MODELS
- }
+ return {name: f"bedrock/{prefix}.{model_id}" for name, model_id in _CLAUDE_MODELS}
def _fetch_bedrock_inference_profiles(region: str | None) -> dict[str, str]:
diff --git a/headroom/cli/wrap.py b/headroom/cli/wrap.py
index 9f41308da..6d7b60932 100644
--- a/headroom/cli/wrap.py
+++ b/headroom/cli/wrap.py
@@ -221,9 +221,7 @@ def _inject_rtk_instructions(file_path: Path, verbose: bool = False) -> bool:
return True
-def _ensure_proxy(
- port: int, no_proxy: bool, *, learn: bool = False
-) -> subprocess.Popen | None:
+def _ensure_proxy(port: int, no_proxy: bool, *, learn: bool = False) -> subprocess.Popen | None:
"""Start or verify proxy. Returns process handle if we started it."""
if not no_proxy:
if _check_proxy(port):
@@ -356,10 +354,14 @@ def wrap() -> None:
@click.option("--port", "-p", default=8787, type=int, help="Proxy port (default: 8787)")
@click.option("--no-rtk", is_flag=True, help="Skip rtk installation and hook registration")
@click.option("--no-proxy", is_flag=True, help="Skip proxy startup (use existing proxy)")
[email protected]("--learn", is_flag=True, help="Enable live traffic learning (patterns saved to MEMORY.md)")
+ "--learn", is_flag=True, help="Enable live traffic learning (patterns saved to MEMORY.md)"
+)
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
@click.argument("claude_args", nargs=-1, type=click.UNPROCESSED)
-def claude(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, claude_args: tuple) -> None:
+def claude(
+ port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, claude_args: tuple
+) -> None:
"""Launch Claude Code through Headroom proxy.
\b
@@ -432,10 +434,14 @@ def claude(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool,
@click.option("--port", "-p", default=8787, type=int, help="Proxy port (default: 8787)")
@click.option("--no-rtk", is_flag=True, help="Skip rtk installation and AGENTS.md injection")
@click.option("--no-proxy", is_flag=True, help="Skip proxy startup (use existing proxy)")
[email protected]("--learn", is_flag=True, help="Enable live traffic learning (patterns saved to AGENTS.md)")
+ "--learn", is_flag=True, help="Enable live traffic learning (patterns saved to AGENTS.md)"
+)
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
@click.argument("codex_args", nargs=-1, type=click.UNPROCESSED)
-def codex(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, codex_args: tuple) -> None:
+def codex(
+ port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, codex_args: tuple
+) -> None:
"""Launch OpenAI Codex CLI through Headroom proxy.
\b
@@ -496,7 +502,9 @@ def codex(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, c
@click.option("--learn", is_flag=True, help="Enable live traffic learning")
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
@click.argument("aider_args", nargs=-1, type=click.UNPROCESSED)
-def aider(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, aider_args: tuple) -> None:
+def aider(
+ port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, aider_args: tuple
+) -> None:
"""Launch aider through Headroom proxy.
\b
@@ -554,7 +562,9 @@ def aider(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool, a
@click.option("--port", "-p", default=8787, type=int, help="Proxy port (default: 8787)")
@click.option("--no-rtk", is_flag=True, help="Skip rtk installation and .cursorrules injection")
@click.option("--no-proxy", is_flag=True, help="Skip proxy startup (use existing proxy)")
[email protected]("--learn", is_flag=True, help="Enable live traffic learning (patterns saved to .cursor/rules/)")
+ "--learn", is_flag=True, help="Enable live traffic learning (patterns saved to .cursor/rules/)"
+)
@click.option("--verbose", "-v", is_flag=True, help="Verbose output")
def cursor(port: int, no_rtk: bool, no_proxy: bool, learn: bool, verbose: bool) -> None:
"""Start Headroom proxy for use with Cursor.
diff --git a/tests/test_learn/test_scanner.py b/tests/test_learn/test_scanner.py
index f91f906a9..2aa1cd30e 100644
--- a/tests/test_learn/test_scanner.py
+++ b/tests/test_learn/test_scanner.py
@@ -88,9 +88,7 @@ class TestGreedyPathDecode:
def test_multi_hyphen_dot_dir_containing_subproject(self, tmp_path: Path) -> None:
"""Path like my-cool-project.nosync/headroom — hardest combination."""
_make_dirs(tmp_path, "my-cool-project.nosync/headroom")
- result = _greedy_path_decode(
- tmp_path, ["my", "cool", "project.nosync", "headroom"]
- )
+ result = _greedy_path_decode(tmp_path, ["my", "cool", "project.nosync", "headroom"])
assert result == tmp_path / "my-cool-project.nosync" / "headroom"
def test_dot_flattened_into_separate_tokens(self, tmp_path: Path) -> None: