2026-07-12 11:28:39 +07:00
|
|
|
//! Workflow status panel rendering.
|
|
|
|
|
//!
|
2026-07-12 17:49:34 +07:00
|
|
|
//! Flow: `draw_workflow_panel` reads `state.workflow_engine` and renders a
|
|
|
|
|
//! rich panel showing agent statuses, findings count, session counters,
|
|
|
|
|
//! and usage hints.
|
2026-07-12 11:28:39 +07:00
|
|
|
//!
|
2026-07-13 05:23:38 +07:00
|
|
|
//! Division-aware: when the workflow is a company pipeline, shows the
|
|
|
|
|
//! division pipeline header with visual arrows between stages.
|
2026-07-12 11:28:39 +07:00
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::layout::Rect;
|
|
|
|
|
use ratatui::style::{Style, Modifier};
|
|
|
|
|
use ratatui::text::{Line, Span};
|
2026-07-12 17:49:34 +07:00
|
|
|
use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, Wrap};
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::Frame;
|
|
|
|
|
use super::theme::Theme;
|
2026-07-12 17:49:34 +07:00
|
|
|
use crate::app::workflow::engine::AgentState;
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-13 05:23:38 +07:00
|
|
|
/// Icons for division states in the company pipeline.
|
|
|
|
|
fn div_icon(state: AgentState) -> &'static str {
|
|
|
|
|
match state {
|
|
|
|
|
AgentState::Idle => "○",
|
|
|
|
|
AgentState::Running => "▶",
|
|
|
|
|
AgentState::Completed => "✓",
|
|
|
|
|
AgentState::Failed => "✗",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Detect if the current workflow looks like a company pipeline by
|
|
|
|
|
/// checking agent names for division keywords.
|
|
|
|
|
fn is_company_pipeline(agents: &[crate::app::workflow::engine::WorkflowAgent]) -> bool {
|
|
|
|
|
if agents.is_empty() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Company pipeline agents have names like "Strategy", "Engineering", etc.
|
|
|
|
|
let division_keywords = ["Strategy", "Engineering", "Quality", "Security", "Documentation"];
|
|
|
|
|
agents.iter().any(|a| {
|
|
|
|
|
division_keywords.iter().any(|k| a.name.contains(k))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
/// Render the workflow status panel.
|
2026-07-11 13:16:10 +07:00
|
|
|
pub fn draw_workflow_panel(frame: &mut Frame, area: Rect, state: &crate::app::state::rest::AppStateRest) {
|
2026-07-12 17:49:34 +07:00
|
|
|
use ratatui::layout::{Constraint, Direction, Layout};
|
|
|
|
|
|
2026-07-13 05:23:38 +07:00
|
|
|
let is_company = is_company_pipeline(&state.workflow_engine.agents);
|
|
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
let block = Block::default()
|
|
|
|
|
.borders(Borders::ALL)
|
2026-07-12 17:49:34 +07:00
|
|
|
.border_style(Style::default().fg(Theme::PRIMARY))
|
2026-07-13 05:23:38 +07:00
|
|
|
.title({
|
|
|
|
|
if is_company {
|
|
|
|
|
Span::styled(" 🏢 Company Pipeline ", Style::default().fg(Theme::PRIMARY).add_modifier(Modifier::BOLD))
|
|
|
|
|
} else {
|
|
|
|
|
Span::styled(" ⚙ Workflow ", Style::default().fg(Theme::PRIMARY).add_modifier(Modifier::BOLD))
|
|
|
|
|
}
|
|
|
|
|
});
|
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
|
|
|
// Split inner into header (hints) and body (agent list / status)
|
|
|
|
|
let chunks = Layout::default()
|
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
|
.constraints([
|
|
|
|
|
Constraint::Length(3), // header / hints
|
|
|
|
|
Constraint::Min(4), // agent list or placeholder
|
|
|
|
|
])
|
|
|
|
|
.split(inner);
|
2026-07-11 20:21:59 +07:00
|
|
|
|
2026-07-13 05:23:38 +07:00
|
|
|
// ── Header ─────────────────────────────────────────────────────────
|
|
|
|
|
let mut header_lines = vec![];
|
|
|
|
|
|
|
|
|
|
if is_company {
|
|
|
|
|
// Show the division pipeline header with visual arrows
|
|
|
|
|
let agents = &state.workflow_engine.agents;
|
|
|
|
|
let mut pipeline_spans: Vec<Span> = Vec::new();
|
|
|
|
|
for (i, agent) in agents.iter().enumerate() {
|
|
|
|
|
if i > 0 {
|
|
|
|
|
pipeline_spans.push(Span::styled(" → ", Style::default().fg(Theme::DIM)));
|
|
|
|
|
}
|
|
|
|
|
let icon = div_icon(agent.status.state);
|
|
|
|
|
let (color, modif) = match agent.status.state {
|
|
|
|
|
AgentState::Idle => (Theme::DIM, Modifier::empty()),
|
|
|
|
|
AgentState::Running => (Theme::WARNING, Modifier::BOLD),
|
|
|
|
|
AgentState::Completed => (Theme::SUCCESS, Modifier::BOLD),
|
|
|
|
|
AgentState::Failed => (Theme::ERROR, Modifier::BOLD),
|
|
|
|
|
};
|
|
|
|
|
pipeline_spans.push(Span::styled(
|
|
|
|
|
format!("{} {} ", icon, agent.name.chars().take(12).collect::<String>()),
|
|
|
|
|
Style::default().fg(color).add_modifier(modif),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
header_lines.push(Line::from(pipeline_spans));
|
|
|
|
|
header_lines.push(Line::from(vec![
|
|
|
|
|
Span::styled("Status: ", Style::default().fg(Theme::DIM)),
|
|
|
|
|
if state.turn_in_flight() {
|
|
|
|
|
Span::styled("● Pipeline Running", Style::default().fg(Theme::WARNING).add_modifier(Modifier::BOLD))
|
|
|
|
|
} else {
|
|
|
|
|
Span::styled("● Pipeline Complete", Style::default().fg(Theme::SUCCESS))
|
|
|
|
|
},
|
|
|
|
|
Span::raw(" "),
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("Divisions: {} Findings: {}",
|
|
|
|
|
state.workflow_engine.agents.len(),
|
|
|
|
|
state.workflow_engine.findings.len(),
|
|
|
|
|
),
|
|
|
|
|
Style::default().fg(Theme::DIM),
|
|
|
|
|
),
|
|
|
|
|
]));
|
|
|
|
|
} else {
|
|
|
|
|
header_lines.push(Line::from(vec![
|
2026-07-12 17:49:34 +07:00
|
|
|
Span::styled("/workflow run ", Style::default().fg(Theme::PRIMARY).add_modifier(Modifier::BOLD)),
|
|
|
|
|
Span::styled("<prompt>", Style::default().fg(Theme::DIM)),
|
|
|
|
|
Span::styled(" · Esc to close", Style::default().fg(Theme::DIM)),
|
2026-07-13 05:23:38 +07:00
|
|
|
]));
|
|
|
|
|
header_lines.push(Line::from(vec![
|
2026-07-12 17:49:34 +07:00
|
|
|
Span::styled("Status: ", Style::default().fg(Theme::DIM)),
|
|
|
|
|
if state.turn_in_flight() {
|
|
|
|
|
Span::styled("● Running", Style::default().fg(Theme::WARNING).add_modifier(Modifier::BOLD))
|
|
|
|
|
} else {
|
|
|
|
|
Span::styled("● Idle", Style::default().fg(Theme::SUCCESS))
|
|
|
|
|
},
|
|
|
|
|
Span::raw(" "),
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("Agents: {} Findings: {}",
|
|
|
|
|
state.workflow_engine.agents.len(),
|
|
|
|
|
state.workflow_engine.findings.len(),
|
|
|
|
|
),
|
|
|
|
|
Style::default().fg(Theme::DIM),
|
|
|
|
|
),
|
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-13 05:23:38 +07:00
|
|
|
// ── Body: agent/division list ──────────────────────────────────────
|
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-12 17:49:34 +07:00
|
|
|
let items: Vec<ListItem> = state.workflow_engine.agents.iter().map(|agent| {
|
|
|
|
|
let (state_str, state_color) = match agent.status.state {
|
2026-07-13 05:23:38 +07:00
|
|
|
AgentState::Idle => ("○ Idle", Theme::DIM),
|
|
|
|
|
AgentState::Running => ("▶ Running…", Theme::WARNING),
|
|
|
|
|
AgentState::Completed => ("✓ Done", Theme::SUCCESS),
|
|
|
|
|
AgentState::Failed => ("✗ Failed", Theme::ERROR),
|
2026-07-12 17:49:34 +07:00
|
|
|
};
|
|
|
|
|
let duration_str = match (agent.status.started_at, agent.status.completed_at) {
|
|
|
|
|
(Some(s), Some(e)) => format!(" {}ms", e.saturating_sub(s)),
|
|
|
|
|
(Some(_), None) => " (running)".to_string(),
|
|
|
|
|
_ => String::new(),
|
|
|
|
|
};
|
|
|
|
|
ListItem::new(Line::from(vec![
|
|
|
|
|
Span::styled(
|
2026-07-13 05:23:38 +07:00
|
|
|
format!(" {:12} ", state_str),
|
2026-07-12 17:49:34 +07:00
|
|
|
Style::default().fg(state_color).add_modifier(Modifier::BOLD),
|
|
|
|
|
),
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!("{}{}", agent.name, duration_str),
|
|
|
|
|
Style::default().fg(Theme::TEXT),
|
|
|
|
|
),
|
|
|
|
|
if let Some(ref err) = agent.status.error {
|
|
|
|
|
Span::styled(format!(" — {}", err), Style::default().fg(Theme::ERROR))
|
2026-07-13 05:33:04 +07:00
|
|
|
} else if let Some(ref prog) = agent.status.progress {
|
|
|
|
|
Span::styled(
|
|
|
|
|
format!(" ({})", prog),
|
|
|
|
|
Style::default().fg(Theme::DIM),
|
|
|
|
|
)
|
2026-07-12 17:49:34 +07:00
|
|
|
} else {
|
|
|
|
|
Span::raw("")
|
|
|
|
|
},
|
|
|
|
|
]))
|
|
|
|
|
}).collect();
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
let list = List::new(items)
|
|
|
|
|
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
|
|
|
|
|
frame.render_widget(list, chunks[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
/// Build a compact list of session counters for the placeholder view.
|
|
|
|
|
fn build_session_lines(state: &crate::app::state::rest::AppStateRest) -> Vec<Line<'static>> {
|
|
|
|
|
let mut lines: Vec<Line<'static>> = Vec::new();
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 17:49:34 +07:00
|
|
|
lines.push(Line::from(Span::styled(
|
|
|
|
|
" No workflow running.",
|
|
|
|
|
Style::default().fg(Theme::DIM),
|
|
|
|
|
)));
|
|
|
|
|
lines.push(Line::from(Span::raw("")));
|
|
|
|
|
|
|
|
|
|
if let Some(ref rt) = state.session_runtime {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" Messages ", Style::default().fg(Theme::DIM)),
|
|
|
|
|
Span::styled(msg_count.to_string(), Style::default().fg(Theme::INFO).add_modifier(Modifier::BOLD)),
|
|
|
|
|
]));
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" Tool calls", Style::default().fg(Theme::DIM)),
|
|
|
|
|
Span::styled(format!(" {}", tool_count), Style::default().fg(Theme::SUCCESS)),
|
|
|
|
|
]));
|
|
|
|
|
if pending > 0 {
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" Pending ", Style::default().fg(Theme::DIM)),
|
|
|
|
|
Span::styled(format!(" {}", pending), Style::default().fg(Theme::WARNING)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
if bash_count > 0 {
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::styled(" Bash jobs ", Style::default().fg(Theme::DIM)),
|
|
|
|
|
Span::styled(format!(" {}", bash_count), Style::default().fg(Theme::WARNING)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lines.push(Line::from(Span::styled(
|
|
|
|
|
" (no active session)",
|
|
|
|
|
Style::default().fg(Theme::DIM),
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines.push(Line::from(Span::raw("")));
|
|
|
|
|
lines.push(Line::from(Span::styled(
|
2026-07-13 05:23:38 +07:00
|
|
|
" Complex tasks auto-delegate to the company pipeline.",
|
2026-07-12 17:49:34 +07:00
|
|
|
Style::default().fg(Theme::DIM).add_modifier(Modifier::ITALIC),
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
lines
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|