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.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(learn): handle FileNotFoundError when CLI tool is not installed
Gyeonghun Parkc3cf02288629
diff --git a/headroom/learn/analyzer.py b/headroom/learn/analyzer.pyindex 03761fdb8..15b27e51e 100644--- a/headroom/learn/analyzer.py+++ b/headroom/learn/analyzer.py@@ -361,7 +361,7 @@ def _call_cli_llm(digest: str, model: str) -> dict:Raises:ValueError: If *model* is not a known CLI backend.- RuntimeError: If the CLI exits with a non-zero code or times out.+ RuntimeError: If the CLI is not installed, exits non-zero, or times out."""cmd: list[str] | None = Nonefor _name, model_name, cmd_parts in _CLI_BACKENDS:@@ -381,6 +381,11 @@ def _call_cli_llm(digest: str, model: str) -> dict:text=True,timeout=_CLI_TIMEOUT,)+ except FileNotFoundError:+ raise RuntimeError(+ f"`{cmd[0]}` not found in PATH. Install it or use a different backend "+ "with --model <litellm-model-name>."+ ) from Noneexcept subprocess.TimeoutExpired:raise RuntimeError(f"`{' '.join(cmd)}` did not respond within {_CLI_TIMEOUT}s. "diff --git a/tests/test_learn/test_analyzer.py b/tests/test_learn/test_analyzer.pyindex 4c1225d0d..f15ba9c86 100644--- a/tests/test_learn/test_analyzer.py+++ b/tests/test_learn/test_analyzer.py@@ -547,6 +547,12 @@ class TestCallCliLlm:result = _call_cli_llm("test digest", "claude-cli")assert result == {"context_file_rules": [], "memory_file_rules": []}+ @patch("headroom.learn.analyzer.subprocess.run")+ def test_cli_not_installed_raises(self, mock_run: MagicMock):+ mock_run.side_effect = FileNotFoundError("No such file or directory: 'codex'")+ with pytest.raises(RuntimeError, match="not found in PATH"):+ _call_cli_llm("test digest", "codex-cli")+@patch("headroom.learn.analyzer.subprocess.run")def test_timeout_raises_runtime_error(self, mock_run: MagicMock):mock_run.side_effect = subprocess.TimeoutExpired(cmd=["claude", "-p"], timeout=120)