2026-07-13 05:42:17 +07:00
|
|
|
//! Workflow status panel rendering — agent cards with state badges.
|
2026-07-16 07:42:03 +07:00
|
|
|
use super::theme::Theme;
|
2026-07-20 09:04:57 +07:00
|
|
|
use crate::state::AgentState;
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::layout::Rect;
|
2026-07-16 07:42:03 +07:00
|
|
|
use ratatui::style::{Color, Modifier, Style};
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::text::{Line, Span};
|
2026-07-13 05:42:17 +07:00
|
|
|
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::Frame;
|
2026-07-20 15:53:20 +07:00
|
|
|
use tracing::{debug, instrument};
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-13 05:42:17 +07:00
|
|
|
fn state_icon(state: AgentState) -> &'static str {
|
2026-07-13 05:23:38 +07:00
|
|
|
match state {
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Idle => "○",
|
|
|
|
|
AgentState::Running => "▶",
|
2026-07-13 05:23:38 +07:00
|
|
|
AgentState::Completed => "✓",
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Failed => "✗",
|
2026-07-13 05:23:38 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 05:42:17 +07:00
|
|
|
fn state_label(state: AgentState) -> &'static str {
|
|
|
|
|
match state {
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Idle => "Idle",
|
|
|
|
|
AgentState::Running => "Running",
|
2026-07-13 05:42:17 +07:00
|
|
|
AgentState::Completed => "Done",
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Failed => "Failed",
|
2026-07-13 05:42:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn state_color(state: AgentState) -> Color {
|
|
|
|
|
match state {
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Idle => Theme::TEXT_DIM,
|
|
|
|
|
AgentState::Running => Theme::WARNING,
|
2026-07-13 05:42:17 +07:00
|
|
|
AgentState::Completed => Theme::SUCCESS,
|
2026-07-16 07:42:03 +07:00
|
|
|
AgentState::Failed => Theme::ERROR,
|
2026-07-13 05:42:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-20 15:53:20 +07:00
|
|
|
/// Render the workflow status panel showing agent cards and a header.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: render titled block → split into header (command hint + status)
|
|
|
|
|
/// and body (agent cards with icon/name/label/duration, or session stats
|
|
|
|
|
/// when no workflow is running).
|
|
|
|
|
#[instrument(skip_all)]
|
2026-07-16 07:42:03 +07:00
|
|
|
pub fn draw_workflow_panel(
|
|
|
|
|
frame: &mut Frame,
|
|
|
|
|
area: Rect,
|
2026-07-20 09:04:57 +07:00
|
|
|
state: &crate::state::AppStateRest,
|
2026-07-16 07:42:03 +07:00
|
|
|
) {
|
2026-07-20 15:53:20 +07:00
|
|
|
debug!("draw_workflow_panel — rendering workflow panel");
|
2026-07-12 17:49:34 +07:00
|
|
|
use ratatui::layout::{Constraint, Direction, Layout};
|
|
|
|
|
|
2026-07-16 07:42:03 +07:00
|
|
|
let title = Span::styled(
|
|
|
|
|
" Workflow ",
|
|
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::PRIMARY)
|
|
|
|
|
.add_modifier(Modifier::BOLD),
|
|
|
|
|
);
|
2026-07-13 05:42:17 +07:00
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
let block = Block::default()
|
|
|
|
|
.borders(Borders::ALL)
|
2026-07-13 05:42:17 +07:00
|
|
|
.border_style(Style::default().fg(Theme::BORDER))
|
|
|
|
|
.title(title);
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
let inner = block.inner(area);
|
|
|
|
|
frame.render_widget(block, area);
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
let chunks = Layout::default()
|
|
|
|
|
.direction(Direction::Vertical)
|
2026-07-16 07:42:03 +07:00
|
|
|
.constraints([Constraint::Length(3), Constraint::Min(4)])
|
2026-07-12 17:49:34 +07:00
|
|
|
.split(inner);
|
2026-07-11 20:21:59 +07:00
|
|
|
|
2026-07-20 09:04:57 +07:00
|
|
|
// Header area
|
2026-07-13 05:42:17 +07:00
|
|
|
let mut header_lines: Vec<Line> = Vec::new();
|
2026-07-14 08:12:37 +07:00
|
|
|
header_lines.push(Line::from(vec![
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
"/workflow run ",
|
|
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::PRIMARY)
|
|
|
|
|
.add_modifier(Modifier::BOLD),
|
|
|
|
|
),
|
2026-07-14 08:12:37 +07:00
|
|
|
Span::styled("<prompt>", Style::default().fg(Theme::TEXT_DIM)),
|
|
|
|
|
]));
|
|
|
|
|
header_lines.push(Line::from(vec![
|
|
|
|
|
Span::styled("Status: ", Style::default().fg(Theme::TEXT_DIM)),
|
|
|
|
|
if state.turn_in_flight() {
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
"● Running",
|
|
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::WARNING)
|
|
|
|
|
.add_modifier(Modifier::BOLD),
|
|
|
|
|
)
|
2026-07-14 08:12:37 +07:00
|
|
|
} else {
|
|
|
|
|
Span::styled("● Idle", Style::default().fg(Theme::SUCCESS))
|
|
|
|
|
},
|
|
|
|
|
Span::raw(" "),
|
|
|
|
|
Span::styled(
|
2026-07-16 07:42:03 +07:00
|
|
|
format!(
|
|
|
|
|
"Agents: {} | Findings: {}",
|
2026-07-14 08:12:37 +07:00
|
|
|
state.workflow_engine.agents.len(),
|
|
|
|
|
state.workflow_engine.findings.len(),
|
2026-07-13 05:42:17 +07:00
|
|
|
),
|
2026-07-14 08:12:37 +07:00
|
|
|
Style::default().fg(Theme::TEXT_DIM),
|
|
|
|
|
),
|
|
|
|
|
]));
|
2026-07-13 05:42:17 +07:00
|
|
|
|
2026-07-13 05:23:38 +07:00
|
|
|
let header = Paragraph::new(header_lines);
|
2026-07-12 17:49:34 +07:00
|
|
|
frame.render_widget(header, chunks[0]);
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-20 09:04:57 +07:00
|
|
|
// Body: agent cards
|
2026-07-12 17:49:34 +07:00
|
|
|
if state.workflow_engine.agents.is_empty() {
|
|
|
|
|
let session_lines = build_session_lines(state);
|
|
|
|
|
let placeholder = Paragraph::new(session_lines).wrap(Wrap { trim: false });
|
|
|
|
|
frame.render_widget(placeholder, chunks[1]);
|
2026-07-12 03:14:52 +07:00
|
|
|
} else {
|
2026-07-13 05:42:17 +07:00
|
|
|
let mut card_lines: Vec<Line> = Vec::new();
|
|
|
|
|
for agent in &state.workflow_engine.agents {
|
2026-07-20 09:04:57 +07:00
|
|
|
let color = state_color(agent.state);
|
|
|
|
|
let icon = state_icon(agent.state);
|
|
|
|
|
let label = state_label(agent.state);
|
2026-07-13 05:42:17 +07:00
|
|
|
|
2026-07-20 09:04:57 +07:00
|
|
|
let duration_str = match (agent.started_at, agent.completed_at) {
|
2026-07-12 17:49:34 +07:00
|
|
|
(Some(s), Some(e)) => format!(" {}ms", e.saturating_sub(s)),
|
2026-07-16 07:42:03 +07:00
|
|
|
(Some(_), None) => " (running)".to_string(),
|
|
|
|
|
_ => String::new(),
|
2026-07-12 17:49:34 +07:00
|
|
|
};
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-13 05:42:17 +07:00
|
|
|
card_lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(
|
2026-07-13 08:12:02 +07:00
|
|
|
format!(" {icon} "),
|
2026-07-13 05:42:17 +07:00
|
|
|
Style::default().fg(color).add_modifier(Modifier::BOLD),
|
|
|
|
|
),
|
|
|
|
|
Span::styled(
|
2026-07-20 17:22:09 +07:00
|
|
|
format!(" {}", agent.display_name),
|
2026-07-16 07:42:03 +07:00
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::TEXT)
|
|
|
|
|
.add_modifier(Modifier::BOLD),
|
2026-07-13 05:42:17 +07:00
|
|
|
),
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(format!(" [{label}]"), Style::default().fg(color)),
|
|
|
|
|
Span::styled(duration_str, Style::default().fg(Theme::TEXT_DIM)),
|
2026-07-13 05:42:17 +07:00
|
|
|
]));
|
|
|
|
|
|
2026-07-20 09:04:57 +07:00
|
|
|
if let Some(ref err) = agent.error {
|
2026-07-13 05:42:17 +07:00
|
|
|
card_lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" ⚠ ", Style::default().fg(Theme::ERROR)),
|
|
|
|
|
Span::styled(err.clone(), Style::default().fg(Theme::ERROR)),
|
|
|
|
|
]));
|
2026-07-20 09:04:57 +07:00
|
|
|
} else if let Some(ref prog) = agent.progress {
|
2026-07-15 02:14:10 +07:00
|
|
|
for line in prog.lines().take(2) {
|
|
|
|
|
card_lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" ", Style::default()),
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
line.to_string(),
|
|
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::TEXT_DIM)
|
|
|
|
|
.add_modifier(Modifier::ITALIC),
|
|
|
|
|
),
|
2026-07-15 02:14:10 +07:00
|
|
|
]));
|
|
|
|
|
}
|
2026-07-13 05:42:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let list = Paragraph::new(card_lines);
|
2026-07-12 17:49:34 +07:00
|
|
|
frame.render_widget(list, chunks[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-20 15:53:20 +07:00
|
|
|
/// Build placeholder lines for the workflow panel body when no agents are running.
|
|
|
|
|
///
|
|
|
|
|
/// Shows session stats (message count, tool calls, pending queue, bash jobs)
|
|
|
|
|
/// or a "(no active session)" fallback.
|
|
|
|
|
#[instrument(skip(state))]
|
2026-07-20 09:04:57 +07:00
|
|
|
fn build_session_lines(state: &crate::state::AppStateRest) -> Vec<Line<'static>> {
|
2026-07-12 17:49:34 +07:00
|
|
|
let mut lines: Vec<Line<'static>> = Vec::new();
|
|
|
|
|
lines.push(Line::from(Span::styled(
|
|
|
|
|
" No workflow running.",
|
2026-07-13 05:42:17 +07:00
|
|
|
Style::default().fg(Theme::TEXT_DIM),
|
2026-07-12 17:49:34 +07:00
|
|
|
)));
|
|
|
|
|
lines.push(Line::from(Span::raw("")));
|
|
|
|
|
|
|
|
|
|
if let Some(ref rt) = state.session_runtime {
|
2026-07-16 07:42:03 +07:00
|
|
|
let tool_count = rt.tool_call_results.len();
|
|
|
|
|
let pending = rt.pending_tool_queue.len();
|
|
|
|
|
let bash_count = rt.bash_jobs.len();
|
|
|
|
|
let msg_count = rt.messages.len();
|
2026-07-12 17:49:34 +07:00
|
|
|
|
|
|
|
|
lines.push(Line::from(vec![
|
2026-07-13 05:42:17 +07:00
|
|
|
Span::styled(" Messages ", Style::default().fg(Theme::TEXT_DIM)),
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
msg_count.to_string(),
|
|
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::INFO)
|
|
|
|
|
.add_modifier(Modifier::BOLD),
|
|
|
|
|
),
|
2026-07-12 17:49:34 +07:00
|
|
|
]));
|
|
|
|
|
lines.push(Line::from(vec![
|
2026-07-13 05:42:17 +07:00
|
|
|
Span::styled(" Tool calls", Style::default().fg(Theme::TEXT_DIM)),
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
format!(" {tool_count}"),
|
|
|
|
|
Style::default().fg(Theme::SUCCESS),
|
|
|
|
|
),
|
2026-07-12 17:49:34 +07:00
|
|
|
]));
|
|
|
|
|
if pending > 0 {
|
|
|
|
|
lines.push(Line::from(vec![
|
2026-07-13 05:42:17 +07:00
|
|
|
Span::styled(" Pending ", Style::default().fg(Theme::TEXT_DIM)),
|
2026-07-13 08:12:02 +07:00
|
|
|
Span::styled(format!(" {pending}"), Style::default().fg(Theme::WARNING)),
|
2026-07-12 17:49:34 +07:00
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
if bash_count > 0 {
|
|
|
|
|
lines.push(Line::from(vec![
|
2026-07-13 05:42:17 +07:00
|
|
|
Span::styled(" Bash jobs ", Style::default().fg(Theme::TEXT_DIM)),
|
2026-07-16 07:42:03 +07:00
|
|
|
Span::styled(
|
|
|
|
|
format!(" {bash_count}"),
|
|
|
|
|
Style::default().fg(Theme::WARNING),
|
|
|
|
|
),
|
2026-07-12 17:49:34 +07:00
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lines.push(Line::from(Span::styled(
|
|
|
|
|
" (no active session)",
|
2026-07-13 05:42:17 +07:00
|
|
|
Style::default().fg(Theme::TEXT_DIM),
|
2026-07-12 17:49:34 +07:00
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines.push(Line::from(Span::raw("")));
|
|
|
|
|
lines.push(Line::from(Span::styled(
|
2026-07-15 00:20:41 +07:00
|
|
|
" The Hive is dormant. Complex tasks will stir it.",
|
2026-07-16 07:42:03 +07:00
|
|
|
Style::default()
|
|
|
|
|
.fg(Theme::TEXT_DIM)
|
|
|
|
|
.add_modifier(Modifier::ITALIC),
|
2026-07-12 17:49:34 +07:00
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
lines
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|