The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): /clear redraws the banner from the new gateway session
kshitijk4poor2267d3b961bb
diff --git a/hermes_cli/cli_info_mixin.py b/hermes_cli/cli_info_mixin.pyindex b02f5239645..1d9b4b87fed 100644--- a/hermes_cli/cli_info_mixin.py+++ b/hermes_cli/cli_info_mixin.py@@ -13,6 +13,7 @@ import osimport shutilimport threadingimport time+from typing import Any, NamedTuplefrom agent.i18n import tfrom hermes_constants import is_termux as _is_termux_environment@@ -92,19 +93,47 @@ def _skill_line(item: dict) -> str:return f" - {nm}: {desc}" if desc else f" - {nm}"+class BannerPlan(NamedTuple):+ """What the welcome banner draws, shared by startup (``show_banner``) and ``/clear`` so the two+ cannot drift apart."""+ store: Any # the gateway session store, or None off the gateway+ inventory: dict | None # a gateway session's tools: its snapshot, never this process's registry+ ctx_len: int | None+ banner_kw: dict | None # build_welcome_banner's common kwargs; None → the compact banner+++def banner_plan(cli, console) -> BannerPlan:+ """The welcome banner's plan. The compact banner (``banner_kw`` None) is for a narrow terminal,+ ``display.compact``, or a gateway session with no snapshot yet."""+ from agent.context_pin import is_context_pinned+ from hermes_cli.gateway_tools_notify import gateway_store+ store = gateway_store(cli)+ inventory = store.banner_inventory() if store is not None else None+ agent = getattr(cli, "agent", None)+ compressor = getattr(agent, "context_compressor", None)+ ctx_len = compressor.context_length if compressor is not None else None+ if cli.compact or shutil.get_terminal_size().columns < 80 or (store is not None and inventory is None):+ return BannerPlan(store, inventory, ctx_len, None)+ return BannerPlan(store, inventory, ctx_len, dict(+ console=console, model=cli.model, cwd=os.getenv("TERMINAL_CWD", os.getcwd()),+ enabled_toolsets=cli.enabled_toolsets, session_id=cli.session_id, context_length=ctx_len,+ provider=cli.provider,+ context_pinned=is_context_pinned(ctx_len, getattr(agent, "_config_context_length", None))))++class CLIInfoMixin:"""Informational views and reload flows for the interactive CLI: banner, help, tools, usage,insights, MCP/skills reload, bang shell."""- def _show_gateway_banner(self, build_welcome_banner, inventory, banner_kw, cwd, ctx_len):+ def _show_gateway_banner(self, build_welcome_banner, inventory, banner_kw):"""Main's banner from the gateway session's snapshot (the TUI banner's data): the CLIenumerates nothing. The canonical id shows as main's 8-character label (display only)."""from hermes_cli.gateway_session_store import session_label- self._defer_tool_warnings = Truebuild_welcome_banner(tools=inventory["tools"], get_toolset_for_tool=inventory["get_toolset_for_tool"],availability=inventory["availability"], skills_by_category=inventory["skills_by_category"],- **{**banner_kw, "cwd": inventory["cwd"] or cwd, "context_length": inventory["context_length"] or ctx_len,+ **{**banner_kw, "cwd": inventory["cwd"] or banner_kw["cwd"],+ "context_length": inventory["context_length"] or banner_kw["context_length"],"session_id": session_label(self.session_id)})def _print_gateway_tool_warnings(self, lines):@@ -120,17 +149,11 @@ class CLIInfoMixin:from cli import _build_compact_banner, get_tool_definitions, loggerfrom hermes_cli.banner import build_welcome_bannerself.console.clear()- ctx_len = None- gateway_inventory = getattr(getattr(self, "_session_db", None), "banner_inventory", lambda: None)()- from hermes_cli.gateway_tools_notify import gateway_store- on_gateway = gateway_store(self) is not None # its tools come from the gateway: never enumerated here- if hasattr(self, 'agent') and self.agent and hasattr(self.agent, 'context_compressor'):- ctx_len = self.agent.context_compressor.context_length- from agent.context_pin import is_context_pinned- ctx_pinned = is_context_pinned(ctx_len, getattr(getattr(self, "agent", None), "_config_context_length", None))+ store, gateway_inventory, ctx_len, banner_kw = banner_plan(self, self.console)+ on_gateway = store is not None # its tools come from the gateway: never enumerated here# Auto-compact for narrow terminals — the full banner needs ~80 columns to avoid wrapping.- if self.compact or shutil.get_terminal_size().columns < 80 or (on_gateway and gateway_inventory is None):+ if banner_kw is None:self._console_print(_build_compact_banner())self._show_status()else:@@ -144,14 +167,9 @@ class CLIInfoMixin:snapshot = load_banner_snapshot(self.enabled_toolsets)except Exception:snapshot = None- cwd = os.getenv("TERMINAL_CWD", os.getcwd()) # where commands will execute- banner_kw = dict(- console=self.console, model=self.model, cwd=cwd,- enabled_toolsets=self.enabled_toolsets, session_id=self.session_id,- context_length=ctx_len, provider=self.provider, context_pinned=ctx_pinned)if gateway_inventory is not None:- self._show_gateway_banner(build_welcome_banner, gateway_inventory, banner_kw, cwd, ctx_len)+ self._show_gateway_banner(build_welcome_banner, gateway_inventory, banner_kw)elif snapshot is not None:self._defer_tool_warnings = Truetoolset_map = snapshot["toolset_map"]diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.pyindex e1c4fa607d4..b7b191dafcd 100644--- a/hermes_cli/cli_loops_mixin.py+++ b/hermes_cli/cli_loops_mixin.py@@ -4,8 +4,6 @@ Mixin on ``HermesCLI``; cli.py symbols are imported lazily inside methods (imporfrom __future__ import annotationsimport logging-import os-import shutilimport threadingimport time@@ -126,21 +124,19 @@ class CLILoopsMixin:out.cursor_goto(0, 0)out.flush()cc = ChatConsole()- if self.compact or shutil.get_terminal_size().columns < 80:+ # The banner plan startup uses (show_banner): a gateway session's banner is the new+ # session's snapshot (its tools, MCP included, and main's short label), never this+ # process's registry.+ from hermes_cli.cli_info_mixin import banner_plan+ plan = banner_plan(self, cc)+ if plan.banner_kw is None:cc.print(_build_compact_banner())+ elif plan.inventory is not None:+ self._show_gateway_banner(build_welcome_banner, plan.inventory, plan.banner_kw)else:tools = get_tool_definitions(enabled_toolsets=self.enabled_toolsets,disabled_toolsets=self.disabled_toolsets, quiet_mode=True)- agent = getattr(self, "agent", None)- ctx_len = None- if agent and hasattr(agent, "context_compressor"):- ctx_len = agent.context_compressor.context_length- from agent.context_pin import is_context_pinned- build_welcome_banner(- console=cc, model=self.model, cwd=os.getenv("TERMINAL_CWD", os.getcwd()),- tools=tools, enabled_toolsets=self.enabled_toolsets, session_id=self.session_id,- context_length=ctx_len, provider=self.provider,- context_pinned=is_context_pinned(ctx_len, getattr(agent, "_config_context_length", None)))+ build_welcome_banner(tools=tools, **plan.banner_kw)_cprint(_fresh_start())self._print_random_tip()diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex 59ad2dc1b54..177fa781844 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -772,3 +772,41 @@ def test_resume_refusal_names_the_clashing_flag_and_the_way_forward(store):with pytest.raises(GatewayClientError, match="--provider differs .* use /model after resuming"):check_resume_policy(argparse.Namespace(provider="anthropic"),{"info": {"launch_request": {"provider": "openrouter"}}})+++def test_clear_banner_shows_the_new_gateway_sessions_tools_and_short_label(store, monkeypatch):+ """#134889 CLI-22: `/clear` inside the running CLI redraws the banner from the new gateway+ session's snapshot (its MCP tools, main's 8-character label), as the startup banner does; this+ process's own tool registry has no MCP servers and is never walked."""+ import cli as cli_mod+ from cli import HermesCLI+ db, client = store+ canonical = "local-ab12cd34" + "e" * 56+ info = {**INFO, "tools": {"file": ["read_file"], "mcp-zeta": ["mcp__zeta__ro_probe"]}}+ created = {**snapshot(canonical), "info": info}++ async def rpc(method, *, _timeout=None, **params):+ client.calls.append((method, params))+ return created if method == "session.create" else {}+ client.rpc = rpc+ banners = []+ monkeypatch.setattr("hermes_cli.banner.build_welcome_banner", lambda **kw: banners.append(kw))+ monkeypatch.setattr(cli_mod, "get_tool_definitions", lambda **_kw: pytest.fail("walked the CLI's registry"))+ monkeypatch.setattr(cli_mod, "_cprint", lambda *_a: None)+ monkeypatch.setattr("shutil.get_terminal_size", lambda *_a: types.SimpleNamespace(columns=200, lines=50))+ shell = HermesCLI.__new__(HermesCLI)+ shell.__dict__.update(+ _session_db=db, session_id="local-old", compact=False, model="fake-model", provider="custom",+ enabled_toolsets=["hermes-cli"], disabled_toolsets=[], agent=None,+ _app=types.SimpleNamespace(output=types.SimpleNamespace(+ erase_screen=lambda: None, cursor_goto=lambda *_a: None, flush=lambda: None)))+ shell._confirm_destructive_slash = lambda *_a, **_k: "once"+ shell._print_random_tip = lambda: None+ shell.new_session = lambda silent=False: setattr(shell, "session_id", db.create({}))++ shell._cmd_clear("/clear")++ (banner,) = banners+ assert banner["session_id"] == "ab12cd34"+ assert sorted(t["function"]["name"] for t in banner["tools"]) == ["mcp__zeta__ro_probe", "read_file"]+ assert banner["get_toolset_for_tool"]("mcp__zeta__ro_probe") == "mcp-zeta"