Skip to content

The agent that grows with you

fix(cli): guard empty message text in _display_resumed_history

AlexFucuson9f5adeed3dca7
diff --git a/hermes_cli/cli_agent_setup_mixin.py b/hermes_cli/cli_agent_setup_mixin.py
index 7a1082431ca..98e8f410b3f 100644
--- a/hermes_cli/cli_agent_setup_mixin.py
+++ b/hermes_cli/cli_agent_setup_mixin.py
@@ -901,20 +901,20 @@ class CLIAgentSetupMixin:
elif role == "user":
lines.append(" ● You: ", style=f"dim bold {_session_label_c}")
# Show first line inline, indent rest
- msg_lines = text.splitlines()
+ msg_lines = text.splitlines() or [""]
lines.append(msg_lines[0] + "\n", style="dim")
for ml in msg_lines[1:]:
lines.append(f" {ml}\n", style="dim")
elif role == "assistant_last":
# Last assistant response shown in full, non-dim
lines.append(" ◆ Hermes: ", style=f"bold {_assistant_label_c}")
- msg_lines = text.splitlines()
+ msg_lines = text.splitlines() or [""]
lines.append(msg_lines[0] + "\n", style="")
for ml in msg_lines[1:]:
lines.append(f" {ml}\n", style="")
else:
lines.append(" ◆ Hermes: ", style=f"dim bold {_assistant_label_c}")
- msg_lines = text.splitlines()
+ msg_lines = text.splitlines() or [""]
lines.append(msg_lines[0] + "\n", style="dim")
for ml in msg_lines[1:]:
lines.append(f" {ml}\n", style="dim")
diff --git a/tests/cli/test_resume_display.py b/tests/cli/test_resume_display.py
index d3090c75a6f..3c8755c31b8 100644
--- a/tests/cli/test_resume_display.py
+++ b/tests/cli/test_resume_display.py
@@ -173,6 +173,37 @@ class TestDisplayResumedHistory:
+ def test_empty_message_content_does_not_crash(self):
+ """Regression: _display_resumed_history IndexError when a message has empty text.
+
+ An assistant turn that produced no text (or a blank user message)
+ makes ``text.splitlines()`` return ``[]``, crashing on ``msg_lines[0]``.
+ The fix guards with ``or [""]`` so the message renders as a blank line.
+ """
+ cli = _make_cli()
+ cli.conversation_history = [
+ {"role": "user", "content": ""},
+ {"role": "assistant", "content": ""},
+ {"role": "user", "content": "Follow-up question"},
+ {"role": "assistant", "content": "Real answer"},
+ ]
+ # Must not raise IndexError
+ output = self._capture_display(cli)
+
+ assert "Follow-up question" in output
+ assert "Real answer" in output
+
+ def test_whitespace_only_message_does_not_crash(self):
+ """Whitespace-only messages should also not crash the resume display."""
+ cli = _make_cli()
+ cli.conversation_history = [
+ {"role": "user", "content": " "},
+ {"role": "assistant", "content": "\n\n"},
+ ]
+ output = self._capture_display(cli)
+ # Should render without error
+ assert "You:" in output
+
def test_minimal_config_suppresses_display(self):
cli = _make_cli(config_overrides={"display": {"resume_display": "minimal"}})
# resume_display is captured as an instance variable during __init__