Skip to content

The agent that grows with you

fix(cli): frame every block with bars and blank lines

Tekniumdfe787496a0a
diff --git a/hermes_cli/cli_chat_turn_mixin.py b/hermes_cli/cli_chat_turn_mixin.py
index c236cb921f4..e2677626353 100644
--- a/hermes_cli/cli_chat_turn_mixin.py
+++ b/hermes_cli/cli_chat_turn_mixin.py
@@ -638,7 +638,6 @@ class CLIChatTurnMixin:
reasoning = turn.result.get("last_reasoning")
if reasoning and getattr(self, "_modern_layout", False):
from hermes_cli.cli_modern_layout import thought_rows
- _cprint("")
for line in thought_rows(None, reasoning, self.reasoning_full):
_cprint(line)
elif reasoning:
@@ -687,7 +686,10 @@ class CLIChatTurnMixin:
modern = getattr(self, "_modern_layout", False)
if turn.use_streaming_tts and turn.box_opened and not is_error_response:
# Text already printed sentence-by-sentence; just close the box.
- if not modern:
+ if modern:
+ from hermes_cli.cli_modern_layout import closing_separator
+ _cprint(closing_separator(True))
+ else:
_cprint(f"\n{_ACCENT}╰{'─' * (self._scrollback_box_width() - 2)}╯{_RST}")
elif already_streamed:
# _flush_stream() already closed the streamed box; a post-stream transform
@@ -696,10 +698,11 @@ class CLIChatTurnMixin:
if _post_stream_text.strip():
_cprint(_post_stream_text)
elif modern:
- from hermes_cli.cli_modern_layout import answer_label
+ from hermes_cli.cli_modern_layout import answer_label, closing_separator
_cprint(answer_label())
ChatConsole().print(_render_final_assistant_content(response, mode=self.final_response_markdown),
style=_resp_text, soft_wrap=True) # terminal wraps; resize re-flows
+ _cprint(closing_separator(True))
else:
ChatConsole().print(Panel(
_render_final_assistant_content(response, mode=self.final_response_markdown),
diff --git a/hermes_cli/cli_modern_layout.py b/hermes_cli/cli_modern_layout.py
index 9df084747b0..23f0f5a24b1 100644
--- a/hermes_cli/cli_modern_layout.py
+++ b/hermes_cli/cli_modern_layout.py
@@ -70,23 +70,27 @@ def prompt_glyph() -> str:
_SEPARATOR_WIDTH = 40
-_GAP_PENDING = False # a user message was just echoed and nothing has opened a block under it yet
+# Every block (user message, reasoning, answer) is framed the same way: blank line, bar, content,
+# bar, blank line. A closing bar leaves the blank line owed; whatever prints next (a tool row, the
+# turn footer) pays it, and an opening bar pays it with its own leading blank line.
+_GAP_PENDING = False
def separator(accent: bool) -> str:
- """The bar above each user message and answer (accent) or reasoning block (dim). Every caller
- prints a blank line ahead of it, so it also settles the gap a fresh user message owes."""
+ """An opening bar: accent for user messages and answers, dim for reasoning. Every caller prints
+ a blank line ahead of it, so it also settles a gap the previous block owes."""
global _GAP_PENDING
_GAP_PENDING = False
color = _fg(_skin_hex("ui_accent", "#FFBF00")) if accent else _DIM
return f"{color}{'─' * _SEPARATOR_WIDTH}{_RST}"
-def owe_gap_after_user_message() -> None:
- """Called once the user's message is echoed: the next tool row opens with a blank line, as
- reasoning and answers already do, so the message never runs straight into the tool calls."""
+def closing_separator(accent: bool) -> str:
+ """The bar that closes a block; the blank line after it is owed to whatever prints next."""
global _GAP_PENDING
+ bar = separator(accent)
_GAP_PENDING = True
+ return bar
def _take_gap() -> str:
@@ -138,10 +142,10 @@ def thought_rows(seconds: float | None, text: str, full: bool) -> list[str]:
lines unless ``full``, as classic), then the ``∴ Thought for 3s`` summary."""
lines = (text or "").strip().splitlines()
shown = lines if full or len(lines) <= _REASONING_PREVIEW_LINES else lines[:_REASONING_PREVIEW_LINES]
- rows = [separator(False), *(reasoning_text_line(line) for line in shown)]
+ rows = ["", separator(False), *(reasoning_text_line(line) for line in shown)]
if len(shown) < len(lines):
rows.append(f"{_DIM} {t('cli.chat.reasoning_more_lines', count=len(lines) - len(shown))}{_RST}")
- return [*rows, thought_line(seconds, text)]
+ return [*rows, thought_line(seconds, text), closing_separator(False)]
def completed_tool_line(cli, function_name: str, args: dict | None, duration: float, result=None,
@@ -220,7 +224,7 @@ def turn_footer(summary: str) -> str:
"""``─ 12.4s · read 3 files · edited 1 file +4 -0 · 7:02 AM`` closing each turn."""
body = summary.lstrip("⋯ ").strip()
clock = datetime.now().strftime("%-I:%M %p") if os.name != "nt" else datetime.now().strftime("%I:%M %p")
- return f"{_DIM}─ {body} · {clock}{_RST}" if body else f"{_DIM}─ {clock}{_RST}"
+ return _take_gap() + (f"{_DIM}─ {body} · {clock}{_RST}" if body else f"{_DIM}─ {clock}{_RST}")
# ── live region (prompt_toolkit fragments, redrawn every frame) ─────────────────────────────
diff --git a/hermes_cli/cli_stream_mixin.py b/hermes_cli/cli_stream_mixin.py
index c5302c2c1bd..00ed37e8f7c 100644
--- a/hermes_cli/cli_stream_mixin.py
+++ b/hermes_cli/cli_stream_mixin.py
@@ -253,11 +253,8 @@ class CLIStreamMixin:
else:
ChatConsole().print(f"[bold {_accent_hex()}]●[/] [bold]{_escape(text)}[/]")
if modern:
- # Close the message with its own bar (as classic does), then a blank line before
- # whatever the turn prints first.
- from hermes_cli.cli_modern_layout import owe_gap_after_user_message
- _cprint(separator(True))
- owe_gap_after_user_message()
+ from hermes_cli.cli_modern_layout import closing_separator
+ _cprint(closing_separator(True))
def _stream_reasoning_delta(self, text: str) -> None:
"""Stream reasoning tokens into a dim box above the response.
@@ -330,12 +327,13 @@ class CLIStreamMixin:
if not getattr(self, "_reasoning_box_opened", False):
return
if getattr(self, "_modern_layout", False):
- from hermes_cli.cli_modern_layout import reasoning_text_line, thought_line
+ from hermes_cli.cli_modern_layout import closing_separator, reasoning_text_line, thought_line
if getattr(self, "_reasoning_buf", ""):
_cprint(reasoning_text_line(self._reasoning_buf))
started = getattr(self, "_reasoning_started_at", 0.0)
_cprint(thought_line(time.monotonic() - started if started else None,
getattr(self, "_reasoning_full_text", "")))
+ _cprint(closing_separator(False))
self._reasoning_buf, self._reasoning_full_text, self._reasoning_box_opened = "", "", False
if not getattr(self, "_stream_box_live", False):
self._release_held_status_lines()
@@ -568,9 +566,13 @@ class CLIStreamMixin:
line = _strip_markdown_syntax(self._stream_buf) if self.final_response_markdown == "strip" else self._stream_buf
self._emit_stream_line(line)
self._stream_buf = ""
- if self._stream_box_opened and getattr(self, "_stream_box_live", False) and not getattr(self, "_modern_layout", False):
- w = self._scrollback_box_width()
- _cprint(f"{_ACCENT}╰{'─' * (w - 2)}╯{_RST}")
+ if self._stream_box_opened and getattr(self, "_stream_box_live", False):
+ if getattr(self, "_modern_layout", False):
+ from hermes_cli.cli_modern_layout import closing_separator
+ _cprint(closing_separator(True))
+ else:
+ w = self._scrollback_box_width()
+ _cprint(f"{_ACCENT}╰{'─' * (w - 2)}╯{_RST}")
self._stream_box_live = False
self._release_held_status_lines()
diff --git a/tests/hermes_cli/test_cli_modern_layout.py b/tests/hermes_cli/test_cli_modern_layout.py
index 22cb5e00bcd..9943e1fa4bf 100644
--- a/tests/hermes_cli/test_cli_modern_layout.py
+++ b/tests/hermes_cli/test_cli_modern_layout.py
@@ -181,24 +181,36 @@ def test_tool_rows_keep_the_classic_tool_emoji():
assert failed.startswith("✗ ") and "[exit 1]" in failed, failed
-def test_a_blank_line_separates_the_user_message_from_the_first_tool_row(monkeypatch):
- """The user's message closes with its own bar, and the first tool row opens under a blank line,
- so the message never runs straight into the tool calls. Later rows stay tight."""
+def test_every_block_is_framed_by_bars_and_blank_lines(monkeypatch):
+ """User message, reasoning and answer each read as: blank line, bar, content, bar, blank line.
+ The blank line after a closing bar is paid by whatever prints next (a tool row, the footer)
+ and never doubled when the next block opens with its own blank line + bar. Tool rows inside a
+ run stay tight."""
from cli import HermesCLI
import cli as climod
from hermes_cli import cli_modern_layout as layout
- emitted: list[str] = []
- monkeypatch.setattr(climod, "_cprint", lambda s: emitted.append(_plain(s)))
+ out: list[str] = []
+ monkeypatch.setattr(climod, "_cprint", lambda s: out.extend(_plain(s).split("\n")))
cli = HermesCLI.__new__(HermesCLI)
cli._modern_layout, cli.show_timestamps = True, False
+ bar = "─" * 40
+
cli._print_user_message_preview("read the hostname")
- assert emitted[-1] == "─" * 40, emitted # the message closes with its own bar
- first = layout.completed_tool_line(cli, "read_file", {"path": "/etc/hostname"}, 0.2)
- second = layout.completed_tool_line(cli, "terminal", {"command": "echo hi"}, 0.1)
- assert first.startswith("\n") and _plain(first).lstrip("\n").startswith("📖 "), repr(first)
- assert not second.startswith("\n"), repr(second)
- # A reasoning block opened first already printed its own blank line + bar: no double gap.
- cli._print_user_message_preview("again")
- layout.separator(False)
- assert not layout.completed_tool_line(cli, "read_file", {"path": "/etc/hostname"}, 0.2).startswith("\n")
+ for row in layout.thought_rows(2.0, "Plan the read.", full=True):
+ climod._cprint(row)
+ climod._cprint(layout.completed_tool_line(cli, "read_file", {"path": "/etc/hostname"}, 0.2))
+ climod._cprint(layout.completed_tool_line(cli, "terminal", {"command": "echo hi"}, 0.1))
+ climod._cprint(layout.answer_label())
+ climod._cprint("It is LINUX.")
+ climod._cprint(layout.closing_separator(True))
+ climod._cprint(layout.turn_footer("1.0s"))
+
+ rows = [r.rstrip() for r in out]
+ start = rows.index("❯ read the hostname") - 1
+ got = ["BAR" if r == bar else ("" if not r else r.split()[0]) for r in rows[start - 1:]]
+ assert got == ["", "BAR", "❯", "BAR", # user message
+ "", "BAR", "Plan", "∴", "BAR", # reasoning
+ "", "📖", "💻", # tool rows, tight
+ "", "BAR", "☤", "It", "BAR", # answer
+ "", "─"], got # footer