Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit Β·
01df4c7
1
Parent(s): 89a00bb
Tool output: last 10 lines for main agent, rolling 3-line display for sub-agents
Browse files
agent/utils/terminal_display.py
CHANGED
|
@@ -5,7 +5,6 @@ Terminal display utilities β rich-powered CLI formatting.
|
|
| 5 |
from rich.console import Console
|
| 6 |
from rich.markdown import Markdown
|
| 7 |
from rich.panel import Panel
|
| 8 |
-
from rich.text import Text
|
| 9 |
from rich.theme import Theme
|
| 10 |
|
| 11 |
_THEME = Theme({
|
|
@@ -27,7 +26,6 @@ def get_console() -> Console:
|
|
| 27 |
# ββ Banner βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
|
| 29 |
def print_banner() -> None:
|
| 30 |
-
# HF yellow: rgb(255, 200, 50) β warm gold matching the brand
|
| 31 |
Y = "\033[38;2;255;200;50m" # HF yellow
|
| 32 |
D = "\033[38;2;180;140;40m" # dimmer gold for accents
|
| 33 |
R = "\033[0m"
|
|
@@ -56,13 +54,69 @@ def print_tool_call(tool_name: str, args_preview: str) -> None:
|
|
| 56 |
|
| 57 |
def print_tool_output(output: str, success: bool, truncate: bool = True) -> None:
|
| 58 |
if truncate:
|
| 59 |
-
output = _truncate(output, max_lines=
|
| 60 |
style = "tool.ok" if success else "tool.fail"
|
| 61 |
_console.print(f" [{style}]{output}[/{style}]")
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def print_tool_log(tool: str, log: str) -> None:
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
# ββ Messages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 5 |
from rich.console import Console
|
| 6 |
from rich.markdown import Markdown
|
| 7 |
from rich.panel import Panel
|
|
|
|
| 8 |
from rich.theme import Theme
|
| 9 |
|
| 10 |
_THEME = Theme({
|
|
|
|
| 26 |
# ββ Banner βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
|
| 28 |
def print_banner() -> None:
|
|
|
|
| 29 |
Y = "\033[38;2;255;200;50m" # HF yellow
|
| 30 |
D = "\033[38;2;180;140;40m" # dimmer gold for accents
|
| 31 |
R = "\033[0m"
|
|
|
|
| 54 |
|
| 55 |
def print_tool_output(output: str, success: bool, truncate: bool = True) -> None:
|
| 56 |
if truncate:
|
| 57 |
+
output = _truncate(output, max_lines=10)
|
| 58 |
style = "tool.ok" if success else "tool.fail"
|
| 59 |
_console.print(f" [{style}]{output}[/{style}]")
|
| 60 |
|
| 61 |
|
| 62 |
+
class SubAgentDisplay:
|
| 63 |
+
"""Rolling 3-line display showing the last 3 sub-agent tool calls, updated in-place."""
|
| 64 |
+
|
| 65 |
+
_MAX_VISIBLE = 3
|
| 66 |
+
|
| 67 |
+
def __init__(self):
|
| 68 |
+
self._calls: list[str] = []
|
| 69 |
+
self._lines_on_screen = 0
|
| 70 |
+
|
| 71 |
+
def update(self, tool_desc: str) -> None:
|
| 72 |
+
"""Add a tool call and redraw the rolling display."""
|
| 73 |
+
self._calls.append(tool_desc)
|
| 74 |
+
visible = self._calls[-self._MAX_VISIBLE:]
|
| 75 |
+
self._redraw(visible)
|
| 76 |
+
|
| 77 |
+
def clear(self) -> None:
|
| 78 |
+
"""Erase the display and reset state."""
|
| 79 |
+
if self._lines_on_screen > 0:
|
| 80 |
+
# Move up and clear each line we drew
|
| 81 |
+
f = _console.file
|
| 82 |
+
for _ in range(self._lines_on_screen):
|
| 83 |
+
f.write("\033[A\033[K")
|
| 84 |
+
f.flush()
|
| 85 |
+
self._lines_on_screen = 0
|
| 86 |
+
self._calls = []
|
| 87 |
+
|
| 88 |
+
def _redraw(self, visible: list[str]) -> None:
|
| 89 |
+
f = _console.file
|
| 90 |
+
# Erase previous lines
|
| 91 |
+
if self._lines_on_screen > 0:
|
| 92 |
+
for _ in range(self._lines_on_screen):
|
| 93 |
+
f.write("\033[A\033[K")
|
| 94 |
+
# Draw new lines
|
| 95 |
+
for i, desc in enumerate(visible):
|
| 96 |
+
dim = i < len(visible) - 1 # older calls are dimmer
|
| 97 |
+
if dim:
|
| 98 |
+
f.write(f" \033[2m {desc}\033[0m\n")
|
| 99 |
+
else:
|
| 100 |
+
f.write(f" \033[36mβΈ {desc}\033[0m\n")
|
| 101 |
+
f.flush()
|
| 102 |
+
self._lines_on_screen = len(visible)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
_subagent_display = SubAgentDisplay()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
def print_tool_log(tool: str, log: str) -> None:
|
| 109 |
+
"""Handle tool log events β sub-agent calls get the rolling display."""
|
| 110 |
+
if tool == "research":
|
| 111 |
+
if log == "Starting research sub-agent...":
|
| 112 |
+
_subagent_display.clear()
|
| 113 |
+
_console.print(f" [tool.name]βΈ research[/tool.name]")
|
| 114 |
+
elif log == "Research complete.":
|
| 115 |
+
_subagent_display.clear()
|
| 116 |
+
else:
|
| 117 |
+
_subagent_display.update(log)
|
| 118 |
+
else:
|
| 119 |
+
_console.print(f" [dim]{tool}: {log}[/dim]")
|
| 120 |
|
| 121 |
|
| 122 |
# ββ Messages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|