fix: improve CLI output rendering and response display

- Adjusted console width handling to ensure consistent output formatting.
- Introduced a short sleep after flushing stdout to allow for proper rendering of tool/status lines before displaying responses.
- Enhanced the response display by modifying the rendering logic to improve visual clarity and prevent interleaving of output.
This commit is contained in:
teknium1
2026-02-19 01:46:56 -08:00
parent d0c8dd78c2
commit 2daf5e4296

10
cli.py
View File

@@ -1465,7 +1465,7 @@ class HermesCLI:
# Add user message to history
self.conversation_history.append({"role": "user", "content": message})
w = min(self.console.width, 80)
w = self.console.width
_cprint(f"{_GOLD}{'' * w}{_RST}")
print(flush=True)
@@ -1506,7 +1506,11 @@ class HermesCLI:
# Drain any remaining agent output still in the StdoutProxy
# buffer so tool/status lines render ABOVE our response box.
# The flush pushes data into the renderer queue; the short
# sleep lets the renderer actually paint it before we draw.
import time as _time
sys.stdout.flush()
_time.sleep(0.15)
# Update history with full conversation
self.conversation_history = result.get("messages", self.conversation_history) if result else self.conversation_history
@@ -1528,7 +1532,7 @@ class HermesCLI:
response = response + "\n\n---\n_[Interrupted - processing new message]_"
if response:
w = min(self.console.width, 80)
w = self.console.width
label = " ⚕ Hermes "
fill = w - 2 - len(label) # 2 for ╭ and ╮
top = f"{_GOLD}╭─{label}{'' * max(fill - 1, 0)}{_RST}"
@@ -1536,7 +1540,7 @@ class HermesCLI:
# Render box + response as a single _cprint call so
# nothing can interleave between the box borders.
_cprint(f"\n{top}\n\n{response}\n\n{bot}")
_cprint(f"\n{top}\n{response}\n\n{bot}")
# If we have a pending message from interrupt, re-queue it for process_loop
# instead of recursing (avoids unbounded recursion from rapid interrupts)