akseljoonas HF Staff commited on
Commit
2fc9917
Β·
1 Parent(s): 3108680

Tool output: last 10 lines for main agent, rolling 3-line display for sub-agents

Browse files
Files changed (1) hide show
  1. agent/utils/terminal_display.py +70 -22
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({
@@ -26,26 +25,19 @@ def get_console() -> Console:
26
 
27
  # ── Banner ─────────────────────────────────────────────────────────────
28
 
29
- _BANNER = r"""
30
- [yellow] _ _ ___ _ _ [/yellow]
31
- [yellow]| || | __| /_\ __ _ ___ _ _| |_ [/yellow]
32
- [yellow]| __ | _| / _ \/ _` / -_) ' \ _|[/yellow]
33
- [yellow]|_||_|_| /_/ \_\__, \___|_||_\__|[/yellow]
34
- [yellow] |___/ [/yellow]"""
35
-
36
-
37
  def print_banner() -> None:
38
- _console.print()
39
- _console.print(
40
- Panel(
41
- _BANNER,
42
- subtitle="[dim]/help Β· /quit[/dim]",
43
- border_style="dim yellow",
44
- expand=False,
45
- padding=(0, 1),
46
- )
47
- )
48
- _console.print()
 
49
 
50
 
51
  # ── Init progress ──────────────────────────────────────────────────────
@@ -62,13 +54,69 @@ def print_tool_call(tool_name: str, args_preview: str) -> None:
62
 
63
  def print_tool_output(output: str, success: bool, truncate: bool = True) -> None:
64
  if truncate:
65
- output = _truncate(output, max_lines=6)
66
  style = "tool.ok" if success else "tool.fail"
67
  _console.print(f" [{style}]{output}[/{style}]")
68
 
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def print_tool_log(tool: str, log: str) -> None:
71
- _console.print(f" [dim]{tool}:[/dim] [dim]{log}[/dim]")
 
 
 
 
 
 
 
 
 
 
72
 
73
 
74
  # ── 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({
 
25
 
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"
32
+ art = f"""
33
+ {Y} _ _ _ ___ _ _ {R}
34
+ {Y}| || |_ _ __ _ __ _(_)_ _ __ _ | __|_ _ __ ___ /_\\ __ _ ___ _ _| |_ {R}
35
+ {Y}| __ | || / _` / _` | | ' \\/ _` | | _/ _` / _/ -_) / _ \\/ _` / -_) ' \\ _|{R}
36
+ {Y}|_||_|\\_,_\\__, \\__, |_|_||_\\__, | |_|\\__,_\\__\\___| /_/ \\_\\__, \\___|_||_\\__|{R}
37
+ {D} |___/|___/ |___/ |___/ {R}
38
+ """
39
+ _console.print(art, highlight=False)
40
+ _console.print(" [dim]πŸ€— /help for commands Β· /quit to exit[/dim]\n")
41
 
42
 
43
  # ── Init progress ──────────────────────────────────────────────────────
 
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 ───────────────────────────────────────────────────────────