Skip to content

Commit 02c365c

Browse files
committed
chore: further enhance console UI
1 parent 6672b81 commit 02c365c

File tree

9 files changed

+84
-31
lines changed

9 files changed

+84
-31
lines changed

AgentCrew/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.7"
1+
__version__ = "0.7.8"

AgentCrew/modules/console/confirmation_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from rich.text import Text
99
from rich.panel import Panel
10+
from rich.box import HORIZONTALS
1011
from rich.console import Group
1112
import time
1213

@@ -65,6 +66,7 @@ def display_tool_confirmation_request(self, tool_info, message_handler):
6566
Panel(
6667
Group(*tool_texts_group),
6768
title=header,
69+
box=HORIZONTALS,
6870
title_align="left",
6971
border_style=RICH_STYLE_YELLOW,
7072
)

AgentCrew/modules/console/console_ui.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from .constants import (
1919
RICH_STYLE_GREEN,
20+
RICH_STYLE_BLUE,
2021
RICH_STYLE_YELLOW,
2122
RICH_STYLE_GREEN_BOLD,
2223
RICH_STYLE_YELLOW_BOLD,
@@ -86,7 +87,7 @@ def listen(self, event: str, data: Any = None):
8687
data
8788
) # data is the thinking chunk
8889
elif event == "user_message_created":
89-
self.console.print("\n")
90+
pass
9091
elif event == "response_chunk":
9192
_, assistant_response = data
9293
if (
@@ -298,6 +299,14 @@ def _handle_terminal_resize(self, signum, frame):
298299
self.message_handler.agent.get_model(),
299300
self.message_handler.tool_manager.get_effective_yolo_mode(),
300301
)
302+
303+
self.display_handlers.print_divider("👤 YOU: ")
304+
305+
prompt = Text(
306+
" ",
307+
style=RICH_STYLE_BLUE,
308+
)
309+
self.console.print(prompt, end="")
301310
self._is_resizing = False
302311

303312
def start_streaming_response(self, agent_name: str):
@@ -424,7 +433,7 @@ def start(self):
424433
)
425434
self.input_handler.stop()
426435
raise SystemExit(0)
427-
if user_input.strip() == "/list":
436+
elif user_input.strip() == "/list":
428437
conversations = self.message_handler.list_conversations()
429438
self.conversation_handler.update_cached_conversations(
430439
conversations
@@ -526,8 +535,11 @@ def start(self):
526535
self.command_handlers.handle_edit_config_command()
527536
continue
528537

538+
elif user_input.startswith("/voice"):
539+
self.input_handler._stop_input_thread()
540+
self.voice_recording = True
529541
# Start loading animation while waiting for response
530-
if (
542+
elif (
531543
not user_input.startswith("/")
532544
or user_input.startswith("/file ")
533545
or user_input.startswith("/consolidate ")
@@ -537,10 +549,6 @@ def start(self):
537549
):
538550
self.start_loading_animation()
539551

540-
if user_input.startswith("/voice"):
541-
self.input_handler._stop_input_thread()
542-
self.voice_recording = True
543-
544552
# Process user input and commands
545553
should_exit, was_cleared = asyncio.run(
546554
self.message_handler.process_user_input(user_input)

AgentCrew/modules/console/display_handlers.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datetime import datetime
1111
from typing import Dict, Any, List
1212
from rich.console import Group
13+
from rich.box import HORIZONTALS, SQUARE
1314
from rich.markdown import Markdown
1415
from rich.text import Text
1516
from rich.panel import Panel
@@ -22,6 +23,7 @@
2223
RICH_STYLE_GRAY,
2324
RICH_STYLE_YELLOW_BOLD,
2425
RICH_STYLE_GREEN_BOLD,
26+
RICH_STYLE_BLUE_BOLD,
2527
RICH_STYLE_FILE_ACCENT_BOLD,
2628
RICH_STYLE_WHITE,
2729
CODE_THEME,
@@ -75,11 +77,12 @@ def display_message(self, message: Text):
7577
def display_user_message(self, message: str):
7678
header = Text(
7779
"👤 YOU:",
78-
style=RICH_STYLE_GREEN_BOLD,
80+
style=RICH_STYLE_BLUE_BOLD,
7981
)
8082
user_panel = Panel(
8183
Text(message),
8284
title=header,
85+
box=HORIZONTALS,
8386
title_align="left",
8487
border_style=RICH_STYLE_BLUE,
8588
)
@@ -93,6 +96,7 @@ def display_assistant_message(self, agent_name: str, message: str):
9396
assistant_panel = Panel(
9497
Markdown(message, code_theme=CODE_THEME),
9598
title=header,
99+
box=HORIZONTALS,
96100
title_align="left",
97101
border_style=RICH_STYLE_GREEN,
98102
)
@@ -102,6 +106,14 @@ def display_divider(self):
102106
"""Display a divider line."""
103107
pass
104108

109+
def print_divider(self, title=""):
110+
"""Display a divider line."""
111+
title_length = len(title) + 1 if title else 0
112+
self.console.print(
113+
" ─" + title + ("─" * (self.console.width - title_length - 3)) + " ",
114+
style=RICH_STYLE_BLUE,
115+
)
116+
105117
def display_debug_info(self, debug_info):
106118
"""Display debug information."""
107119
self.console.print(Text("Current messages:", style=RICH_STYLE_YELLOW))
@@ -248,7 +260,7 @@ def display_token_usage(
248260
f"Total: {input_tokens + output_tokens:,} | Cost: ${total_cost:.4f} | Total: {session_cost:.4f}",
249261
style=RICH_STYLE_YELLOW,
250262
)
251-
self.console.print(Panel(token_info))
263+
self.console.print(Panel(token_info, box=HORIZONTALS))
252264
self.display_divider()
253265

254266
def display_added_files(self):
@@ -263,10 +275,6 @@ def display_added_files(self):
263275
def print_welcome_message(self, version: str):
264276
"""Print the welcome message for the chat."""
265277
welcome_messages = Group(
266-
Text(
267-
"🎮 Welcome to AgentCrew v" + version + " interactive chat!",
268-
style=RICH_STYLE_YELLOW_BOLD,
269-
),
270278
Text("Press Ctrl+C twice to exit.", style=RICH_STYLE_GRAY),
271279
Text("Type '/exit' or '/quit' to end the session.", style=RICH_STYLE_GRAY),
272280
Text(
@@ -353,7 +361,16 @@ def print_welcome_message(self, version: str):
353361
),
354362
)
355363

356-
self.console.print(Panel(welcome_messages))
364+
self.console.print(
365+
Panel(
366+
welcome_messages,
367+
box=SQUARE,
368+
title=Text(
369+
"🎮 Welcome to AgentCrew v" + version + " interactive chat!",
370+
style=RICH_STYLE_YELLOW_BOLD,
371+
),
372+
)
373+
)
357374
self.display_divider()
358375

359376
def print_prompt_prefix(

AgentCrew/modules/console/input_handler.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,28 @@ def _(event):
179179
self.message_handler.agent.get_model(),
180180
self.message_handler.tool_manager.get_effective_yolo_mode(),
181181
)
182-
prompt = Text("👤 YOU: ", style=RICH_STYLE_BLUE)
183-
self.console.print(prompt, end="")
184182
time.sleep(0.2)
185183
self.clear_buffer()
184+
prompt = Text(" ", style=RICH_STYLE_BLUE)
185+
self.console.print(prompt, end="")
186186

187187
@kb.add(Keys.Backspace)
188188
def _(event):
189189
if not event.current_buffer.text:
190190
prompt = Text(
191-
"👤 YOU: " if not self.is_message_processing else "",
191+
" " if not self.is_message_processing else "",
192192
style=RICH_STYLE_BLUE,
193193
)
194-
self.console.print("", end="\r")
195-
self.console.print(prompt, end="")
194+
if not self.is_message_processing:
195+
import sys
196+
197+
sys.stdout.write("\x1b[1A") # cursor up one line
198+
sys.stdout.write("\x1b[2K")
199+
sys.stdout.write("\r")
200+
self.display_handlers.print_divider("👤 YOU: ")
201+
self.console.print(prompt, end="")
202+
else:
203+
self.console.print("", end="\r")
196204
else:
197205
event.current_buffer.delete_before_cursor()
198206

@@ -244,7 +252,9 @@ def _(event):
244252
def clear_buffer(self):
245253
if self._current_prompt_session:
246254
self._current_prompt_session.app.current_buffer.reset()
247-
self._current_prompt_session.message = HTML("<ansiblue>👤 YOU:</ansiblue> ")
255+
if not self.is_message_processing:
256+
self.display_handlers.print_divider("👤 YOU: ")
257+
self._current_prompt_session.message = HTML(" ")
248258
self._current_prompt_session.app.invalidate()
249259

250260
def get_choice_input(self, message: str, values: list[str], default=None) -> str:
@@ -301,11 +311,9 @@ def _input_thread_worker(self):
301311
)
302312
self._current_prompt_session = session
303313

304-
prompt_text = (
305-
HTML("<ansiblue>👤 YOU:</ansiblue> ")
306-
if not self.is_message_processing
307-
else ""
308-
)
314+
if not self.is_message_processing:
315+
self.display_handlers.print_divider("👤 YOU: ")
316+
prompt_text = HTML(" ") if not self.is_message_processing else ""
309317
user_input = session.prompt(prompt_text)
310318

311319
self.message_handler.history_manager.reset_position()
@@ -393,6 +401,8 @@ def get_user_input(self):
393401
if user_input is None:
394402
continue
395403

404+
self.display_handlers.print_divider()
405+
396406
if user_input == "__EXIT__":
397407
self.console.print(
398408
Text(
@@ -417,7 +427,6 @@ def get_user_input(self):
417427
)
418428
return ""
419429
else:
420-
self.display_handlers.display_divider()
421430
return user_input
422431

423432
except queue.Empty:

AgentCrew/modules/console/tool_display.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Dict
99
from rich.console import Group
1010
from rich.panel import Panel
11+
from rich.box import HORIZONTALS
1112
from rich.text import Text
1213

1314
from .constants import (
@@ -90,6 +91,7 @@ def display_tool_use(self, tool_use: Dict):
9091
Panel(
9192
Group(*tool_texts_group),
9293
title=header,
94+
box=HORIZONTALS,
9395
title_align="left",
9496
)
9597
)
@@ -124,7 +126,12 @@ def display_tool_result(self, data: Dict):
124126
tool_texts_group.append(result_line)
125127

126128
self.console.print(
127-
Panel(Group(*tool_texts_group), title=header, title_align="left")
129+
Panel(
130+
Group(*tool_texts_group),
131+
box=HORIZONTALS,
132+
title=header,
133+
title_align="left",
134+
)
128135
)
129136

130137
def display_tool_error(self, data: Dict):
@@ -145,6 +152,7 @@ def display_tool_error(self, data: Dict):
145152
self.console.print(
146153
Panel(
147154
Group(*tool_texts_group),
155+
box=HORIZONTALS,
148156
title=header,
149157
title_align="left",
150158
border_style=RICH_STYLE_RED,

AgentCrew/modules/console/ui_effects.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import itertools
1111
import random
1212
from rich.live import Live
13+
from rich.box import HORIZONTALS
1314
from rich.markdown import Markdown
1415
from rich.panel import Panel
1516

@@ -66,6 +67,10 @@ def _loading_animation(self, stop_event):
6667
time.sleep(0.1) # Control animation speed
6768
live.update("") # Clear the live display when done
6869
live.stop() # Stop the live display
70+
import sys
71+
72+
sys.stdout.write("\x1b[1A") # cursor up one line
73+
sys.stdout.write("\x1b[2K")
6974

7075
def start_loading_animation(self):
7176
"""Start the loading animation."""
@@ -95,7 +100,9 @@ def start_streaming_response(self, agent_name: str):
95100

96101
header = Text(f"🤖 {agent_name.upper()}:", style=RICH_STYLE_GREEN_BOLD)
97102

98-
live_panel = Panel("", title=header, border_style=RICH_STYLE_GREEN)
103+
live_panel = Panel(
104+
"", title=header, box=HORIZONTALS, border_style=RICH_STYLE_GREEN
105+
)
99106

100107
self.live = Live(
101108
live_panel,
@@ -151,6 +158,7 @@ def update_live_display(self, chunk: str):
151158
live_panel = Panel(
152159
Markdown("\n".join(lines), code_theme=CODE_THEME),
153160
title=header,
161+
box=HORIZONTALS,
154162
subtitle=subtitle,
155163
title_align="left",
156164
border_style=RICH_STYLE_GREEN,
@@ -195,6 +203,7 @@ def finish_response(self, response: str):
195203
assistant_panel = Panel(
196204
Markdown(markdown_formatted_response, code_theme=CODE_THEME),
197205
title=header,
206+
box=HORIZONTALS,
198207
title_align="left",
199208
border_style=RICH_STYLE_GREEN,
200209
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentcrew-ai"
3-
version = "0.7.7"
3+
version = "0.7.8"
44
requires-python = ">=3.12"
55
classifiers = [
66
"Programming Language :: Python :: 3",

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)