The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cli): move the output-history row helpers out of the cli facade (#95375)
teknium10004e3a8dfd5
diff --git a/cli.py b/cli.pyindex 659f6ec1337..ca9d227afb3 100644--- a/cli.py+++ b/cli.py@@ -110,7 +110,9 @@ from hermes_cli.cli_render import ( # noqa: F401,E402_line_rows,_luminance_from_hex,_maybe_remap_for_light_mode,+ _output_history_lines,_output_history_recording,+ _output_history_rows,_output_tail_fitting,_painted_columns,_PaintedLine,@@ -654,35 +656,6 @@ def _suspend_output_history():_OUTPUT_HISTORY_SUPPRESSED = old_value-def _output_history_lines() -> list[str]:- """The recorded output as the lines a replay paints (callable entries render now)."""- rendered_lines = []- for entry in tuple(_OUTPUT_HISTORY):- lines = [entry]- if callable(entry):- try:- lines = entry()- except Exception:- continue- if isinstance(lines, str):- lines = lines.splitlines()- rendered_lines.extend(line if isinstance(line, str) else str(line) for line in lines)- return rendered_lines---def _output_history_rows(limit: int, columns: int, painted: bool):- """Rows the whole recorded output fills (counted as ``_output_tail_fitting`` does), or- ``None`` when that is ``limit`` rows or more."""- if not _OUTPUT_HISTORY_ENABLED:- return None- total = 0- for line in reversed(_output_history_lines()):- total += _line_rows(line, (getattr(line, "width", None) if painted else None) or columns)- if total >= limit:- return None- return total--def _replay_output_history(fit=None, output=None) -> None:"""Repaint recent output above the prompt after a full screen clear.diff --git a/hermes_cli/cli_render.py b/hermes_cli/cli_render.pyindex 1e4cafd8e48..195cb945ddb 100644--- a/hermes_cli/cli_render.py+++ b/hermes_cli/cli_render.py@@ -616,6 +616,35 @@ def _output_tail_fitting(lines: list[str], max_rows: int, columns: int, painted:return kept+def _output_history_lines() -> list[str]:+ """The recorded output as the lines a replay paints (callable entries render now)."""+ rendered_lines = []+ for entry in tuple(_cli()._OUTPUT_HISTORY):+ lines = [entry]+ if callable(entry):+ try:+ lines = entry()+ except Exception:+ continue+ if isinstance(lines, str):+ lines = lines.splitlines()+ rendered_lines.extend(line if isinstance(line, str) else str(line) for line in lines)+ return rendered_lines+++def _output_history_rows(limit: int, columns: int, painted: bool):+ """Rows the whole recorded output fills (counted as ``_output_tail_fitting`` does), or+ ``None`` when that is ``limit`` rows or more."""+ if not _cli()._OUTPUT_HISTORY_ENABLED:+ return None+ total = 0+ for line in reversed(_output_history_lines()):+ total += _line_rows(line, (getattr(line, "width", None) if painted else None) or columns)+ if total >= limit:+ return None+ return total++def _pt_print_ansi(text: str) -> None:"""``_pt_print(ANSI(text))``, falling back to ``print`` when stdout is not a real console."""from cli import _PT_ANSI, _pt_printdiff --git a/hermes_cli/cli_terminal_mixin.py b/hermes_cli/cli_terminal_mixin.pyindex 110ba9a7fd3..32ddd8f3ad9 100644--- a/hermes_cli/cli_terminal_mixin.py+++ b/hermes_cli/cli_terminal_mixin.py@@ -14,6 +14,7 @@ import timefrom hermes_cli.cli_render import (_chrome_floor,_hold_paints,+ _output_history_rows,_release_paints,_set_chrome_floor,_set_paint_gate,@@ -221,7 +222,7 @@ class CLITerminalMixin:drawn from there to the bottom (``_set_chrome_floor``), where the next count assumes it.A clear that fails replays nothing: the history is already on screen or in scrollback."""- from cli import _output_history_rows, _terminal_reflows+ from cli import _terminal_reflowsif getattr(self, "_terminal_io_broken", False):return _NO_REPLAYtry: