2026-07-12 11:28:39 +07:00
|
|
|
//! Workflow status panel rendering.
|
|
|
|
|
//!
|
|
|
|
|
//! Flow: `draw_workflow_panel` reads `state.session_runtime` and
|
|
|
|
|
//! `state.workflow_engine` and renders a compact `List` of counters
|
|
|
|
|
//! (messages, completed/pending tool calls, active bash jobs, agents,
|
|
|
|
|
//! findings) plus the current auto-run phase.
|
|
|
|
|
//!
|
|
|
|
|
//! Why: shows a placeholder panel when there is no active session
|
|
|
|
|
//! runtime, and only emits rows for counters that are nonzero, to keep
|
|
|
|
|
//! the panel compact during simple single-turn sessions.
|
|
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
use ratatui::layout::Rect;
|
|
|
|
|
use ratatui::style::{Style, Modifier};
|
|
|
|
|
use ratatui::text::{Line, Span};
|
|
|
|
|
use ratatui::widgets::{Block, Borders, List, ListItem};
|
|
|
|
|
use ratatui::Frame;
|
|
|
|
|
use super::theme::Theme;
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// Render the workflow status panel summarizing the active session runtime.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: bail out with a "No active session" placeholder if
|
|
|
|
|
/// `state.session_runtime` is None → otherwise build a list of status
|
|
|
|
|
/// lines (message count, completed/pending tool calls, active bash jobs,
|
|
|
|
|
/// agent/finding counts, auto-run phase) → render as a List widget.
|
|
|
|
|
///
|
|
|
|
|
/// Why: rows for pending tool queue, bash jobs, agents, and findings are
|
|
|
|
|
/// only shown when their count is nonzero, to keep the panel compact
|
|
|
|
|
/// during simple single-turn sessions.
|
|
|
|
|
///
|
|
|
|
|
/// Return: nothing; draws directly into `frame` at `area`.
|
2026-07-11 13:16:10 +07:00
|
|
|
pub fn draw_workflow_panel(frame: &mut Frame, area: Rect, state: &crate::app::state::rest::AppStateRest) {
|
|
|
|
|
let block = Block::default()
|
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
.border_style(Style::default().fg(Theme::BORDER))
|
|
|
|
|
.title(" Workflow ");
|
|
|
|
|
|
|
|
|
|
let session_runtime = match &state.session_runtime {
|
|
|
|
|
Some(r) => r,
|
|
|
|
|
None => {
|
|
|
|
|
let empty = Block::default().borders(Borders::ALL).title(" Workflow ");
|
|
|
|
|
let paragraph = ratatui::widgets::Paragraph::new(Line::from(Span::raw("No active session")))
|
|
|
|
|
.block(empty);
|
|
|
|
|
frame.render_widget(paragraph, area);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let tool_count = session_runtime.tool_call_results.len();
|
|
|
|
|
let pending_count = session_runtime.pending_tool_queue.len();
|
|
|
|
|
let bash_count = session_runtime.bash_jobs.len();
|
2026-07-11 20:21:59 +07:00
|
|
|
|
|
|
|
|
let agent_count = state.workflow_engine.agents.len();
|
|
|
|
|
let findings_count = state.workflow_engine.findings.len();
|
2026-07-11 13:16:10 +07:00
|
|
|
|
|
|
|
|
let mut items = Vec::new();
|
|
|
|
|
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Messages: {}", session_runtime.messages.len()),
|
|
|
|
|
Style::default().fg(Theme::TEXT),
|
|
|
|
|
))));
|
|
|
|
|
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Tool calls completed: {}", tool_count),
|
|
|
|
|
Style::default().fg(Theme::SUCCESS),
|
|
|
|
|
))));
|
|
|
|
|
|
|
|
|
|
if pending_count > 0 {
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Pending tool queue: {}", pending_count),
|
|
|
|
|
Style::default().fg(Theme::WARNING),
|
|
|
|
|
))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if bash_count > 0 {
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Active bash jobs: {}", bash_count),
|
|
|
|
|
Style::default().fg(Theme::WARNING),
|
|
|
|
|
))));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-11 20:21:59 +07:00
|
|
|
if agent_count > 0 {
|
2026-07-11 13:16:10 +07:00
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
2026-07-11 20:21:59 +07:00
|
|
|
format!(" Agents: {}", agent_count),
|
2026-07-11 13:16:10 +07:00
|
|
|
Style::default().fg(Theme::INFO),
|
|
|
|
|
))));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-11 20:21:59 +07:00
|
|
|
if findings_count > 0 {
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Findings: {}", findings_count),
|
|
|
|
|
Style::default().fg(Theme::WARNING),
|
|
|
|
|
))));
|
|
|
|
|
}
|
2026-07-11 13:16:10 +07:00
|
|
|
|
2026-07-12 03:14:52 +07:00
|
|
|
let phase_status = if state.turn_in_flight() {
|
|
|
|
|
"Auto-running"
|
|
|
|
|
} else {
|
|
|
|
|
"Awaiting input"
|
2026-07-11 13:16:10 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
items.push(ListItem::new(Line::from(Span::styled(
|
|
|
|
|
format!(" Phase: {}", phase_status),
|
|
|
|
|
Style::default().fg(Theme::PRIMARY),
|
|
|
|
|
))));
|
|
|
|
|
|
|
|
|
|
let list = List::new(items)
|
|
|
|
|
.block(block)
|
|
|
|
|
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
|
|
|
|
|
|
|
|
|
|
frame.render_widget(list, area);
|
|
|
|
|
}
|