Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit Β·
ad9fcf9
1
Parent(s): f8cf893
Indent all agent output, remove turn separator line
Browse files- agent/main.py +1 -1
- agent/utils/terminal_display.py +33 -30
agent/main.py
CHANGED
|
@@ -203,7 +203,7 @@ class _ThinkingShimmer:
|
|
| 203 |
try:
|
| 204 |
while self._running:
|
| 205 |
frame = self._render_frame(text, pos)
|
| 206 |
-
self._console.file.write(f"\r{frame}")
|
| 207 |
self._console.file.flush()
|
| 208 |
pos = (pos + speed) % (n + self._WIDTH)
|
| 209 |
await asyncio.sleep(1.0 / self._FPS)
|
|
|
|
| 203 |
try:
|
| 204 |
while self._running:
|
| 205 |
frame = self._render_frame(text, pos)
|
| 206 |
+
self._console.file.write(f"\r {frame}")
|
| 207 |
self._console.file.flush()
|
| 208 |
pos = (pos + speed) % (n + self._WIDTH)
|
| 209 |
await asyncio.sleep(1.0 / self._FPS)
|
agent/utils/terminal_display.py
CHANGED
|
@@ -18,6 +18,9 @@ _THEME = Theme({
|
|
| 18 |
|
| 19 |
_console = Console(theme=_THEME, highlight=False)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def get_console() -> Console:
|
| 23 |
return _console
|
|
@@ -37,26 +40,28 @@ def print_banner() -> None:
|
|
| 37 |
{D} |___/|___/ |___/ |___/ {R}
|
| 38 |
"""
|
| 39 |
_console.print(art, highlight=False)
|
| 40 |
-
_console.print("
|
| 41 |
|
| 42 |
|
| 43 |
# ββ Init progress ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 44 |
|
| 45 |
def print_init_done() -> None:
|
| 46 |
-
_console.print("[dim]Ready.[/dim]\n")
|
| 47 |
|
| 48 |
|
| 49 |
# ββ Tool calls βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 50 |
|
| 51 |
def print_tool_call(tool_name: str, args_preview: str) -> None:
|
| 52 |
-
_console.print(f"
|
| 53 |
|
| 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 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
class SubAgentDisplay:
|
|
@@ -77,7 +82,6 @@ class SubAgentDisplay:
|
|
| 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")
|
|
@@ -95,9 +99,9 @@ class SubAgentDisplay:
|
|
| 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
|
| 99 |
else:
|
| 100 |
-
f.write(f"
|
| 101 |
f.flush()
|
| 102 |
self._lines_on_screen = len(visible)
|
| 103 |
|
|
@@ -110,13 +114,13 @@ def print_tool_log(tool: str, log: str) -> None:
|
|
| 110 |
if tool == "research":
|
| 111 |
if log == "Starting research sub-agent...":
|
| 112 |
_subagent_display.clear()
|
| 113 |
-
_console.print(f"
|
| 114 |
elif log == "Research complete.":
|
| 115 |
_subagent_display.clear()
|
| 116 |
else:
|
| 117 |
_subagent_display.update(log)
|
| 118 |
else:
|
| 119 |
-
_console.print(f"
|
| 120 |
|
| 121 |
|
| 122 |
# ββ Messages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -128,20 +132,19 @@ def print_markdown(text: str) -> None:
|
|
| 128 |
|
| 129 |
|
| 130 |
def print_error(message: str) -> None:
|
| 131 |
-
_console.print(f"\n[bold red]Error:[/bold red] {message}")
|
| 132 |
|
| 133 |
|
| 134 |
def print_turn_complete() -> None:
|
| 135 |
-
#
|
| 136 |
-
_console.print("[dim]β[/dim]")
|
| 137 |
|
| 138 |
|
| 139 |
def print_interrupted() -> None:
|
| 140 |
-
_console.print("\n[dim italic]interrupted[/dim italic]")
|
| 141 |
|
| 142 |
|
| 143 |
def print_compacted(old_tokens: int, new_tokens: int) -> None:
|
| 144 |
-
_console.print(f"
|
| 145 |
|
| 146 |
|
| 147 |
# ββ Approval βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -149,28 +152,28 @@ def print_compacted(old_tokens: int, new_tokens: int) -> None:
|
|
| 149 |
def print_approval_header(count: int) -> None:
|
| 150 |
label = f"Approval required β {count} item{'s' if count != 1 else ''}"
|
| 151 |
_console.print()
|
| 152 |
-
_console.print(Panel(f"[bold yellow]{label}[/bold yellow]", border_style="yellow", expand=False))
|
| 153 |
|
| 154 |
|
| 155 |
def print_approval_item(index: int, total: int, tool_name: str, operation: str) -> None:
|
| 156 |
-
_console.print(f"\n
|
| 157 |
|
| 158 |
|
| 159 |
def print_yolo_approve(count: int) -> None:
|
| 160 |
-
_console.print(f"
|
| 161 |
|
| 162 |
|
| 163 |
# ββ Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 164 |
|
| 165 |
-
HELP_TEXT = """\
|
| 166 |
-
[bold]Commands[/bold]
|
| 167 |
-
[cyan]/help[/cyan] Show this help
|
| 168 |
-
[cyan]/undo[/cyan] Undo last turn
|
| 169 |
-
[cyan]/compact[/cyan] Compact context window
|
| 170 |
-
[cyan]/model[/cyan] [id] Show available models or switch
|
| 171 |
-
[cyan]/yolo[/cyan] Toggle auto-approve mode
|
| 172 |
-
[cyan]/status[/cyan] Current model & turn count
|
| 173 |
-
[cyan]/quit[/cyan] Exit"""
|
| 174 |
|
| 175 |
|
| 176 |
def print_help() -> None:
|
|
@@ -195,14 +198,14 @@ def format_plan_display() -> str:
|
|
| 195 |
|
| 196 |
lines = []
|
| 197 |
for t in completed:
|
| 198 |
-
lines.append(f"
|
| 199 |
for t in in_progress:
|
| 200 |
-
lines.append(f"
|
| 201 |
for t in pending:
|
| 202 |
-
lines.append(f"
|
| 203 |
|
| 204 |
summary = f"[dim]{len(completed)}/{len(plan)} done[/dim]"
|
| 205 |
-
lines.append(f"
|
| 206 |
return "\n".join(lines)
|
| 207 |
|
| 208 |
|
|
|
|
| 18 |
|
| 19 |
_console = Console(theme=_THEME, highlight=False)
|
| 20 |
|
| 21 |
+
# Indent prefix for all agent output (aligns under the `>` prompt)
|
| 22 |
+
_I = " "
|
| 23 |
+
|
| 24 |
|
| 25 |
def get_console() -> Console:
|
| 26 |
return _console
|
|
|
|
| 40 |
{D} |___/|___/ |___/ |___/ {R}
|
| 41 |
"""
|
| 42 |
_console.print(art, highlight=False)
|
| 43 |
+
_console.print(f"{_I}[dim]π€ /help for commands Β· /quit to exit[/dim]\n")
|
| 44 |
|
| 45 |
|
| 46 |
# ββ Init progress ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 47 |
|
| 48 |
def print_init_done() -> None:
|
| 49 |
+
_console.print(f"{_I}[dim]Ready.[/dim]\n")
|
| 50 |
|
| 51 |
|
| 52 |
# ββ Tool calls βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 53 |
|
| 54 |
def print_tool_call(tool_name: str, args_preview: str) -> None:
|
| 55 |
+
_console.print(f"{_I}[tool.name]βΈ {tool_name}[/tool.name] [tool.args]{args_preview}[/tool.args]")
|
| 56 |
|
| 57 |
|
| 58 |
def print_tool_output(output: str, success: bool, truncate: bool = True) -> None:
|
| 59 |
if truncate:
|
| 60 |
output = _truncate(output, max_lines=10)
|
| 61 |
style = "tool.ok" if success else "tool.fail"
|
| 62 |
+
# Indent each line of tool output
|
| 63 |
+
indented = "\n".join(f"{_I} {line}" for line in output.split("\n"))
|
| 64 |
+
_console.print(f"[{style}]{indented}[/{style}]")
|
| 65 |
|
| 66 |
|
| 67 |
class SubAgentDisplay:
|
|
|
|
| 82 |
def clear(self) -> None:
|
| 83 |
"""Erase the display and reset state."""
|
| 84 |
if self._lines_on_screen > 0:
|
|
|
|
| 85 |
f = _console.file
|
| 86 |
for _ in range(self._lines_on_screen):
|
| 87 |
f.write("\033[A\033[K")
|
|
|
|
| 99 |
for i, desc in enumerate(visible):
|
| 100 |
dim = i < len(visible) - 1 # older calls are dimmer
|
| 101 |
if dim:
|
| 102 |
+
f.write(f"{_I} \033[2m{desc}\033[0m\n")
|
| 103 |
else:
|
| 104 |
+
f.write(f"{_I}\033[36mβΈ {desc}\033[0m\n")
|
| 105 |
f.flush()
|
| 106 |
self._lines_on_screen = len(visible)
|
| 107 |
|
|
|
|
| 114 |
if tool == "research":
|
| 115 |
if log == "Starting research sub-agent...":
|
| 116 |
_subagent_display.clear()
|
| 117 |
+
_console.print(f"{_I}[tool.name]βΈ research[/tool.name]")
|
| 118 |
elif log == "Research complete.":
|
| 119 |
_subagent_display.clear()
|
| 120 |
else:
|
| 121 |
_subagent_display.update(log)
|
| 122 |
else:
|
| 123 |
+
_console.print(f"{_I}[dim]{tool}: {log}[/dim]")
|
| 124 |
|
| 125 |
|
| 126 |
# ββ Messages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
def print_error(message: str) -> None:
|
| 135 |
+
_console.print(f"\n{_I}[bold red]Error:[/bold red] {message}")
|
| 136 |
|
| 137 |
|
| 138 |
def print_turn_complete() -> None:
|
| 139 |
+
pass # no separator β clean output
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def print_interrupted() -> None:
|
| 143 |
+
_console.print(f"\n{_I}[dim italic]interrupted[/dim italic]")
|
| 144 |
|
| 145 |
|
| 146 |
def print_compacted(old_tokens: int, new_tokens: int) -> None:
|
| 147 |
+
_console.print(f"{_I}[dim]context compacted: {old_tokens:,} β {new_tokens:,} tokens[/dim]")
|
| 148 |
|
| 149 |
|
| 150 |
# ββ Approval βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 152 |
def print_approval_header(count: int) -> None:
|
| 153 |
label = f"Approval required β {count} item{'s' if count != 1 else ''}"
|
| 154 |
_console.print()
|
| 155 |
+
_console.print(f"{_I}", Panel(f"[bold yellow]{label}[/bold yellow]", border_style="yellow", expand=False))
|
| 156 |
|
| 157 |
|
| 158 |
def print_approval_item(index: int, total: int, tool_name: str, operation: str) -> None:
|
| 159 |
+
_console.print(f"\n{_I}[bold]\\[{index}/{total}][/bold] [tool.name]{tool_name}[/tool.name] {operation}")
|
| 160 |
|
| 161 |
|
| 162 |
def print_yolo_approve(count: int) -> None:
|
| 163 |
+
_console.print(f"{_I}[bold yellow]yolo β[/bold yellow] auto-approved {count} item(s)")
|
| 164 |
|
| 165 |
|
| 166 |
# ββ Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 167 |
|
| 168 |
+
HELP_TEXT = f"""\
|
| 169 |
+
{_I}[bold]Commands[/bold]
|
| 170 |
+
{_I} [cyan]/help[/cyan] Show this help
|
| 171 |
+
{_I} [cyan]/undo[/cyan] Undo last turn
|
| 172 |
+
{_I} [cyan]/compact[/cyan] Compact context window
|
| 173 |
+
{_I} [cyan]/model[/cyan] [id] Show available models or switch
|
| 174 |
+
{_I} [cyan]/yolo[/cyan] Toggle auto-approve mode
|
| 175 |
+
{_I} [cyan]/status[/cyan] Current model & turn count
|
| 176 |
+
{_I} [cyan]/quit[/cyan] Exit"""
|
| 177 |
|
| 178 |
|
| 179 |
def print_help() -> None:
|
|
|
|
| 198 |
|
| 199 |
lines = []
|
| 200 |
for t in completed:
|
| 201 |
+
lines.append(f"{_I}[green]β[/green] [dim]{t['content']}[/dim]")
|
| 202 |
for t in in_progress:
|
| 203 |
+
lines.append(f"{_I}[yellow]βΈ[/yellow] {t['content']}")
|
| 204 |
for t in pending:
|
| 205 |
+
lines.append(f"{_I}[dim]β {t['content']}[/dim]")
|
| 206 |
|
| 207 |
summary = f"[dim]{len(completed)}/{len(plan)} done[/dim]"
|
| 208 |
+
lines.append(f"{_I}{summary}")
|
| 209 |
return "\n".join(lines)
|
| 210 |
|
| 211 |
|