Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/loopal-tui/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod text_width;
pub mod topology_overlay;
pub mod unified_status;
mod unified_status_goal;
mod unified_status_label;

/// Shared dim-grey color used for separators and inactive panel decoration.
pub const DIM_SEPARATOR: ratatui::style::Color = ratatui::style::Color::Rgb(60, 60, 60);
32 changes: 17 additions & 15 deletions crates/loopal-tui/src/views/unified_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use loopal_session::state::SessionState;
use loopal_view_state::AgentConversation;

use super::unified_status_goal::append_goal_indicator;
use super::unified_status_label::{ActivityInputs, pick_label};
use crate::app::App;

pub const SPINNER: &[&str] = &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
Expand Down Expand Up @@ -99,22 +100,22 @@ fn status_icon_and_label(
elapsed: std::time::Duration,
is_active: bool,
) -> (String, Style, &'static str) {
let spin = || spinner_frame(elapsed).to_string();
if conv.thinking_active {
(spin(), Style::default().fg(Color::Magenta), "Thinking")
} else if !conv.streaming_text.is_empty() {
(spin(), Style::default().fg(Color::Green), "Streaming")
} else if conv.pending_permission.is_some() {
("●".into(), Style::default().fg(Color::Yellow), "Waiting")
} else if !active_agent_idle(app, state) {
(spin(), Style::default().fg(Color::Cyan), "Working")
} else if has_live_subagents(app) {
(spin(), Style::default().fg(Color::Blue), "Agents")
} else if is_active {
(spin(), Style::default().fg(Color::Cyan), "Working")
let inputs = ActivityInputs {
thinking: conv.thinking_active,
compacting: conv.compact_banner.is_some(),
streaming: !conv.streaming_text.is_empty(),
pending_permission: conv.pending_permission.is_some(),
agent_idle: active_agent_idle(app, state),
has_subagents: has_live_subagents(app),
recently_or_active: is_active,
};
let (use_spinner, color, label) = pick_label(&inputs);
let icon = if use_spinner {
spinner_frame(elapsed).to_string()
} else {
("●".into(), Style::default().fg(Color::DarkGray), "Idle")
}
"●".to_string()
};
(icon, Style::default().fg(color), label)
}

pub fn spinner_frame(elapsed: std::time::Duration) -> &'static str {
Expand All @@ -126,6 +127,7 @@ fn is_agent_active(app: &App, state: &SessionState, conv: &AgentConversation) ->
!active_agent_idle(app, state)
|| !conv.streaming_text.is_empty()
|| conv.thinking_active
|| conv.compact_banner.is_some()
|| has_live_subagents(app)
|| conv.is_recently_active(ACTIVITY_GRACE)
}
Expand Down
132 changes: 132 additions & 0 deletions crates/loopal-tui/src/views/unified_status_label.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use ratatui::style::Color;

pub(crate) struct ActivityInputs {
pub thinking: bool,
pub compacting: bool,
pub streaming: bool,
pub pending_permission: bool,
pub agent_idle: bool,
pub has_subagents: bool,
pub recently_or_active: bool,
}

pub(crate) fn pick_label(i: &ActivityInputs) -> (bool, Color, &'static str) {
if i.thinking {
(true, Color::Magenta, "Thinking")
} else if i.compacting {
(true, Color::Cyan, "Compacting")
} else if i.streaming {
(true, Color::Green, "Streaming")
} else if i.pending_permission {
(false, Color::Yellow, "Waiting")
} else if !i.agent_idle {
(true, Color::Cyan, "Working")
} else if i.has_subagents {
(true, Color::Blue, "Agents")
} else if i.recently_or_active {
(true, Color::Cyan, "Working")
} else {
(false, Color::DarkGray, "Idle")
}
}

#[cfg(test)]
mod tests {
use super::*;

fn base() -> ActivityInputs {
ActivityInputs {
thinking: false,
compacting: false,
streaming: false,
pending_permission: false,
agent_idle: true,
has_subagents: false,
recently_or_active: false,
}
}

#[test]
fn idle_when_nothing_active() {
let (spin, color, label) = pick_label(&base());
assert_eq!((spin, color, label), (false, Color::DarkGray, "Idle"));
}

#[test]
fn compacting_when_banner_present_and_agent_idle() {
let i = ActivityInputs {
compacting: true,
..base()
};
let (spin, color, label) = pick_label(&i);
assert_eq!(label, "Compacting");
assert_eq!(color, Color::Cyan);
assert!(spin, "compacting must animate the spinner");
}

#[test]
fn thinking_outranks_compacting() {
let i = ActivityInputs {
thinking: true,
compacting: true,
..base()
};
assert_eq!(pick_label(&i).2, "Thinking");
}

#[test]
fn compacting_outranks_streaming() {
let i = ActivityInputs {
compacting: true,
streaming: true,
..base()
};
assert_eq!(pick_label(&i).2, "Compacting");
}

#[test]
fn streaming_when_only_streaming() {
let i = ActivityInputs {
streaming: true,
..base()
};
assert_eq!(pick_label(&i).2, "Streaming");
}

#[test]
fn waiting_uses_dot_not_spinner() {
let i = ActivityInputs {
pending_permission: true,
..base()
};
let (spin, color, label) = pick_label(&i);
assert_eq!((spin, color, label), (false, Color::Yellow, "Waiting"));
}

#[test]
fn working_when_backend_not_idle() {
let i = ActivityInputs {
agent_idle: false,
..base()
};
assert_eq!(pick_label(&i).2, "Working");
}

#[test]
fn agents_when_subagents_live() {
let i = ActivityInputs {
has_subagents: true,
..base()
};
assert_eq!(pick_label(&i).2, "Agents");
}

#[test]
fn working_during_activity_grace() {
let i = ActivityInputs {
recently_or_active: true,
..base()
};
assert_eq!(pick_label(&i).2, "Working");
}
}
Loading