Skip to content

fix(sidebar): auto-collapse completed sub-agents in sidebar#2051

Open
donglovejava wants to merge 1 commit into
Hmbown:mainfrom
donglovejava:feat/auto-collapse-agents
Open

fix(sidebar): auto-collapse completed sub-agents in sidebar#2051
donglovejava wants to merge 1 commit into
Hmbown:mainfrom
donglovejava:feat/auto-collapse-agents

Conversation

@donglovejava
Copy link
Copy Markdown

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:

✓ explore foo         ← 2 lines per agent
  abc123 · 3 steps · 12.3s
✗ build failed        ← 2 lines per agent
  def456 · 7 steps · 45.6s
● analysis running    ← 2 lines per agent
  ghi789 · 2 steps · 5.1s · parsing output...

After:

✓ explore foo         ← 1 line (collapsed)
✗ build failed        ← 1 line (collapsed)
● analysis running    ← 2 lines (expanded: label + detail)
  ghi789 · 2 steps · 5.1s · parsing output...

File changed

crates/tui/src/tui/sidebar.rs — 5 lines added: is_completed check + early continue before the detail line.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1598 to +1608
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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant