fix(sidebar): auto-collapse completed sub-agents in sidebar#2051
fix(sidebar): auto-collapse completed sub-agents in sidebar#2051donglovejava wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the subagent_panel_lines function in crates/tui/src/tui/sidebar.rs to skip additional processing for sub-agents that have completed their execution (i.e., status is not 'running'). The review feedback recommends refactoring the logic to avoid redundant calls to as_str() and simplifying the status check by removing the intermediate is_completed variable for better conciseness and efficiency.
| let is_completed = !matches!(row.status.as_str(), "running"); | ||
| let (marker, color) = agent_status_marker(row.status.as_str()); | ||
| let label = format!("{marker} {} {}", row.role, row.name); | ||
| lines.push(Line::from(Span::styled( | ||
| truncate_line_to_width(&label, content_width.max(1)), | ||
| Style::default().fg(color), | ||
| ))); | ||
|
|
||
| if is_completed { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
The current implementation calls row.status.as_str() twice and uses the matches! macro for a simple string comparison. This can be refactored for better readability and minor efficiency by storing the status slice and using a direct inequality check. Additionally, the variable is_completed is only used once and can be replaced by a direct check on the status to make the code more concise. Note that while the PR description uses the term 'completed', checking for != "running" correctly covers all terminal states (done, failed, interrupted, canceled) as intended.
| let is_completed = !matches!(row.status.as_str(), "running"); | |
| let (marker, color) = agent_status_marker(row.status.as_str()); | |
| let label = format!("{marker} {} {}", row.role, row.name); | |
| lines.push(Line::from(Span::styled( | |
| truncate_line_to_width(&label, content_width.max(1)), | |
| Style::default().fg(color), | |
| ))); | |
| if is_completed { | |
| continue; | |
| } | |
| let status = row.status.as_str(); | |
| let (marker, color) = agent_status_marker(status); | |
| let label = format!("{marker} {} {}", row.role, row.name); | |
| lines.push(Line::from(Span::styled( | |
| truncate_line_to_width(&label, content_width.max(1)), | |
| Style::default().fg(color), | |
| ))); | |
| if status != "running" { | |
| continue; | |
| } | |
Summary
Auto-collapse completed sub-agents in the Agents sidebar panel. Non-running agents now show only a single line (label), freeing vertical space for active agents.
Problem
Completed/failed/interrupted/cancelled sub-agents each occupied 2 lines in the sidebar (label + detail line), wasting space that could be used for running agents or other content. With many agents, the sidebar became unnecessarily crowded.
Solution
In
subagent_panel_lines(), check the agent status before rendering the detail line. If the agent is not running (i.e. completed, failed, interrupted, cancelled), skip the detail line entirely and only render the single-line label.Before:
After:
File changed
crates/tui/src/tui/sidebar.rs— 5 lines added:is_completedcheck + earlycontinuebefore the detail line.