The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): footer no longer collapses into "Window too small..." mid-turn (#57393)
teknium13b51213c0394
diff --git a/hermes_cli/cli_footer_split.py b/hermes_cli/cli_footer_split.pynew file mode 100644index 00000000000..b00b7639b63--- /dev/null+++ b/hermes_cli/cli_footer_split.py@@ -0,0 +1,40 @@+"""Root container of the classic CLI footer: clips a late row instead of giving up.++prompt_toolkit renders a non-full-screen layout into exactly the height it measured a moment+earlier (``Renderer.render`` → ``HSplit.preferred_height``), then ``HSplit._divide_heights``+measures every child again while painting. Each footer row here has a callable height that the+agent thread flips mid-turn (``_agent_running`` → spacer, ``_spinner_text`` → spinner,+``_command_running`` → hint), so a row appearing between the two passes makes the summed minimum+exceed the budget by one and stock ``HSplit`` replaces the WHOLE footer with its+" Window too small... " placeholder (#57393) — on any terminal size, including a maximised 200×50+pane. Hermes's throttled ``_invalidate`` can then drop the healing repaint for the length of a+tool call, so the placeholder sits there looking like a geometry error.+"""+from __future__ import annotations++from prompt_toolkit.application import get_app+from prompt_toolkit.layout import HSplit+from prompt_toolkit.layout.screen import WritePosition+++class FooterSplit(HSplit):+ """``HSplit`` whose overflow path keeps the composer on screen and repaints right away.++ When the base class would paint the placeholder, allocate the children's minimum heights+ bottom-up (composer, rules and status bar first) so only the row that appeared late — always+ above them — loses its row for this one frame, and schedule an unthrottled redraw so the+ next frame measures and paints against the same state.+ """++ def _divide_heights(self, write_position: WritePosition) -> list[int] | None:+ sizes = super()._divide_heights(write_position)+ if sizes is not None:+ return sizes+ budget = write_position.height+ clipped: list[int] = []+ for child in reversed(self._all_children):+ rows = min(child.preferred_height(write_position.width, budget).min, budget)+ budget -= rows+ clipped.append(rows)+ get_app().invalidate()+ return clipped[::-1]diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.pyindex 4dc8b363e48..f68d8b4eaf5 100644--- a/hermes_cli/cli_tui_mixin.py+++ b/hermes_cli/cli_tui_mixin.py@@ -23,7 +23,6 @@ from prompt_toolkit.key_binding import KeyBindingsfrom prompt_toolkit.layout import (ConditionalContainer,FormattedTextControl,- HSplit,Layout,Window,WindowAlign)@@ -38,6 +37,8 @@ from prompt_toolkit.styles import Style as PTStylefrom prompt_toolkit.widgets import TextAreafrom typing import Optional+from hermes_cli.cli_footer_split import FooterSplit+# Rows below an overlay panel taken by spinner/tool-progress, status bar, input, separators and# prompt symbol (measured ~6 during live PTY approval prompts) — shared by every panel budget._PANEL_RESERVED_BELOW = 6@@ -2156,7 +2157,7 @@ class CLITuiMixin:filter=Condition(lambda: cli_ref._prompt_stash.panel_open and bool(len(cli_ref._prompt_stash))),)self._register_extra_tui_keybindings(kb, input_area=input_area)- layout = Layout(HSplit(self._build_tui_layout_children(+ layout = Layout(FooterSplit(self._build_tui_layout_children(sudo_widget=sudo_widget,secret_widget=secret_widget,approval_widget=approval_widget,diff --git a/tests/hermes_cli/test_cli_footer_split.py b/tests/hermes_cli/test_cli_footer_split.pynew file mode 100644index 00000000000..2256708fd5d--- /dev/null+++ b/tests/hermes_cli/test_cli_footer_split.py@@ -0,0 +1,99 @@+"""The classic CLI footer never paints prompt_toolkit's "Window too small..." placeholder.++Regression for #57393: a footer row appearing between the renderer's measure pass and the paint+pass (the agent thread starting a turn) made the root ``HSplit`` give up on the whole footer, on+any terminal size.+"""+import asyncio++from prompt_toolkit.application import Application+from prompt_toolkit.data_structures import Size+from prompt_toolkit.input import create_pipe_input+from prompt_toolkit.key_binding import KeyBindings+from prompt_toolkit.layout import HSplit, Layout, Window+from prompt_toolkit.layout.dimension import Dimension+from prompt_toolkit.layout.screen import WritePosition+from prompt_toolkit.output.vt100 import Vt100_Output+++class _Tty:+ encoding = "utf-8"++ def __init__(self):+ self.chunks = []++ def write(self, data):+ self.chunks.append(data)++ def flush(self):+ pass++ def isatty(self):+ return True++ def fileno(self):+ return 1++ @property+ def text(self):+ return "".join(self.chunks)+++def _render_once(layout, kb, style, tty, rows=50, columns=200):+ """One non-full-screen frame through the same CPR-disabled vt100 output the CLI ships."""+ output = Vt100_Output(tty, lambda: Size(rows=rows, columns=columns), term="xterm-256color", enable_cpr=False)++ async def run():+ with create_pipe_input() as pipe:+ app = Application(layout=layout, key_bindings=kb, style=style, full_screen=False,+ input=pipe, output=output)+ painted = asyncio.Event()+ app.after_render += lambda _: painted.set()+ task = asyncio.create_task(app.run_async())+ await asyncio.wait_for(painted.wait(), 5)+ app.exit()+ await asyncio.wait_for(task, 3)++ asyncio.run(run())+++def test_footer_survives_a_row_appearing_between_measure_and_paint(monkeypatch):+ monkeypatch.setenv("HERMES_DEFER_AGENT_STARTUP", "1")+ from cli import HermesCLI++ cli = HermesCLI(model="fixture", provider="openai-compat", api_key="fixture", base_url="http://127.0.0.1:1/v1")+ cli._tui_init_run_state()+ kb = KeyBindings()+ layout, style = cli._tui_build_layout(kb)+ root = layout.container++ measured = HSplit.preferred_height++ def measure_then_agent_starts(self, width, max_available_height):+ dimension = measured(self, width, max_available_height)+ if self is root:+ # The agent thread flips these right after the renderer measured the footer.+ cli._agent_running = True+ cli._spinner_text = "⠋ Thinking..."+ return dimension++ monkeypatch.setattr(HSplit, "preferred_height", measure_then_agent_starts)+ tty = _Tty()+ _render_once(layout, kb, style, tty)++ assert "Window too small" not in tty.text+ assert "❯" in tty.text, "the composer prompt must survive the frame"+++def test_footer_split_clips_from_the_top_when_minimums_overflow():+ from prompt_toolkit.application import DummyApplication, set_app++ from hermes_cli.cli_footer_split import FooterSplit++ top, middle, bottom = (Window(height=Dimension.exact(1)) for _ in range(3))+ split = FooterSplit([top, middle, bottom])+ with set_app(DummyApplication()):+ sizes = split._divide_heights(WritePosition(0, 0, 80, 2))++ # ``_all_children`` interleaves zero-height padding windows between the three children.+ assert sizes == [0, 0, 1, 0, 1], "composer-side rows keep their height; the late top row is clipped"