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(cli): eagerly bind subcommand submodules to headroom.cli

Garm3680707e60d9
diff --git a/headroom/cli/__init__.py b/headroom/cli/__init__.py
index cc774f527..d4e20bc3c 100644
--- a/headroom/cli/__init__.py
+++ b/headroom/cli/__init__.py
@@ -1,5 +1,33 @@
-"""Headroom CLI - Command-line interface for memory and proxy management."""
+"""Headroom CLI - Command-line interface for memory and proxy management.
+The subcommand submodules are imported eagerly below so they are bound as
+attributes of `headroom.cli`. Click registration happens via side effects in
+`main.py::_register_commands`, but that only binds them to the *main.py*
+module. Tests that do `patch("headroom.cli.<sub>.<attr>")` resolve the target
+by walking attributes on the package object, and that lookup fails when a
+prior test has popped `headroom.cli` from `sys.modules` and re-imported it
+through a path other than `main.py` (e.g. a test that replaces
+`sys.modules["headroom.cli.main"]` with a fake to isolate one subcommand).
+Doing `from . import ...` here means the submodule attribute binding
+survives that kind of sys.modules mutation.
+"""
+
+from . import ( # noqa: F401
+ evals,
+ init,
+ install,
+ learn,
+ mcp,
+ perf,
+ proxy,
+ tools,
+ wrap,
+)
from .main import main
+try:
+ from . import memory # noqa: F401
+except ImportError:
+ pass
+
__all__ = ["main"]