The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): render account limits in /usage without a live agent
ZishiW3ee389afdd51
diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.pyindex 1c55c38b43b..912b67a8d6d 100644--- a/hermes_cli/cli_info_mixin.py+++ b/hermes_cli/cli_info_mixin.py@@ -681,9 +681,12 @@ class CLIInfoMixin:from cli import datetime, format_duration_compactdef _credits_or(fallback: str) -> None:+ # Account limits (e.g. Codex subscription windows) need only the configured provider+ # plus on-disk credentials, so they render without a live agent too (#42904).+ shown = self._print_account_limits()if self._print_nous_credits_block():self._print_usage_cta()- else:+ elif not shown:print(fallback)if not self.agent:@@ -730,25 +733,7 @@ class CLIInfoMixin:print(f" Messages: {len(self.conversation_history)}")print(f" Compressions: {compressor.compression_count}")- # Account limits — fetched off-thread with a hard timeout so slow provider APIs don't- # hang the prompt. Lazy import: pulls the OpenAI SDK chain.- provider = self._agent_or_self("provider")- from agent.account_usage import fetch_account_usage, render_account_usage_lines- account_snapshot = None- if provider:- with concurrent.futures.ThreadPoolExecutor(max_workers=1) as _pool:- try:- account_snapshot = _pool.submit(- fetch_account_usage, provider, base_url=self._agent_or_self("base_url"),- api_key=self._agent_or_self("api_key"),- ).result(timeout=10.0)- except (concurrent.futures.TimeoutError, Exception):- account_snapshot = None- account_lines = [f" {line}" for line in render_account_usage_lines(account_snapshot)]- if account_lines:- print()- for line in account_lines:- print(line)+ self._print_account_limits()if self._print_nous_credits_block():self._print_usage_cta()@@ -760,6 +745,35 @@ class CLIInfoMixin:else:logging.getLogger().setLevel(logging.INFO)+ def _print_account_limits(self) -> bool:+ """Provider account limits block for `/usage`; True if anything printed.++ Uses the live agent's route when present, else the CLI's own configured provider (the+ TUI/Desktop slash-worker runs without an agent). Fetched off-thread with a hard timeout so+ slow provider APIs don't hang the prompt; failures are non-fatal. Lazy import: pulls the+ OpenAI SDK chain.+ """+ provider = self._agent_or_self("provider")+ if not provider:+ return False+ from agent.account_usage import fetch_account_usage, render_account_usage_lines+ account_snapshot = None+ with concurrent.futures.ThreadPoolExecutor(max_workers=1) as _pool:+ try:+ account_snapshot = _pool.submit(+ fetch_account_usage, provider, base_url=self._agent_or_self("base_url"),+ api_key=self._agent_or_self("api_key"),+ ).result(timeout=10.0)+ except (concurrent.futures.TimeoutError, Exception):+ account_snapshot = None+ account_lines = [f" {line}" for line in render_account_usage_lines(account_snapshot)]+ if not account_lines:+ return False+ print()+ for line in account_lines:+ print(line)+ return True+def _show_insights(self, command: str = "/insights"):"""Show usage insights and analytics from session history (`--days N` / `N`, `--source`)."""parts = command.split()diff --git a/tests/hermes_cli/test_cli_status_bar.py b/tests/hermes_cli/test_cli_status_bar.pyindex 76d25a8578c..9094a3a8fae 100644--- a/tests/hermes_cli/test_cli_status_bar.py+++ b/tests/hermes_cli/test_cli_status_bar.py@@ -265,6 +265,42 @@ class TestCLIUsageReport:assert "Cache write tokens:" not in output+class TestCLIUsageNoAgentAccountLimits:+ """#42904: `/usage` without a live agent (TUI/Desktop slash-worker) still renders account limits."""++ def _no_agent_cli(self, monkeypatch, snapshot):+ from agent.account_usage import AccountUsageSnapshot, AccountUsageWindow+ cli_obj = _make_cli()+ cli_obj.provider, cli_obj.base_url, cli_obj.api_key = "openai-codex", None, None+ cli_obj._print_nous_credits_block = lambda: False+ seen = {}++ def _fetch(provider, **kwargs):+ seen["provider"] = provider+ if snapshot is None:+ return None+ return AccountUsageSnapshot(+ provider=provider, source="usage_api", fetched_at=datetime.now(), plan="Pro",+ windows=(AccountUsageWindow(label="Weekly", used_percent=1.0),),+ )+ monkeypatch.setattr("agent.account_usage.fetch_account_usage", _fetch)+ return cli_obj, seen++ def test_no_agent_prints_codex_account_limits(self, capsys, monkeypatch):+ cli_obj, seen = self._no_agent_cli(monkeypatch, snapshot=True)+ cli_obj._show_usage()+ out = capsys.readouterr().out+ assert seen["provider"] == "openai-codex"+ assert "Account limits" in out and "Weekly: 99% remaining (1% used)" in out+ assert "No active agent" not in out++ def test_no_agent_keeps_fallback_message_when_limits_unavailable(self, capsys, monkeypatch):+ cli_obj, _ = self._no_agent_cli(monkeypatch, snapshot=None)+ cli_obj._show_usage()+ out = capsys.readouterr().out+ assert "No active agent" in out and "Account limits" not in out++class TestStatusBarWidthSource:"""Ensure status bar fragments don't overflow the terminal width."""