refactor: migrate monolithic crate to Cargo Workspace with Clean Architecture
Transform the single binary crate into a 9-crate workspace monorepo: - Root Cargo.toml as [workspace] manager with resolver = "2" - zesdex-entities: Domain entity types (session, settings, store, message, etc.) - zesdex-utils: Pure utility functions (error, logger, pagination, slug, clipboard) - zesdex-dto: Data Transfer Objects for LLM provider API communication - zesdex-ipc: Unix-socket IPC layer (client/server/framing/protocol) - zesdex-iam: Identity & Access Management (Clean Architecture: domain/application/infrastructure) - zesdex-cms: Content Management (Clean Architecture: domain/application/infrastructure) - zesdex-middleware: HTTP middleware (Auth, CORS, Rate Limiting) - zesdex-libs: Composition root (AppContext, DB init, JWT, Argon2) - zesdex-backend: Main binary entry point + seed/migrate binaries - DevOps: Dockerfile, docker-compose, Nix (flake/shell/default), CI/CD updates - Remove dead root src/ and src-misc/ directories All crate re-exports maintain backward compatibility with original crate::model::*, crate::dto::*, crate::ipc::* module paths. Feature crates enforce strict layer separation: domain -> application -> infrastructure with generic trait-based dependency injection.
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
//! Workflow status panel rendering — agent cards with state badges.
|
||||
//!
|
||||
//! Flow: `draw_workflow_panel` reads `state.workflow_engine` and renders a
|
||||
//! panel showing agent statuses, findings count, session counters, and
|
||||
//! usage hints.
|
||||
//!
|
||||
//! Design: agents are shown as compact cards with state-colored badges,
|
||||
//! including hive-mind nodes (named by their system-assigned designation,
|
||||
//! e.g. `"Node-0-1"`).
|
||||
use super::theme::Theme;
|
||||
use crate::app::workflow::engine::AgentState;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::style::{Color, Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
|
||||
use ratatui::Frame;
|
||||
|
||||
/// Icons for agent states.
|
||||
fn state_icon(state: AgentState) -> &'static str {
|
||||
match state {
|
||||
AgentState::Idle => "○",
|
||||
AgentState::Running => "▶",
|
||||
AgentState::Completed => "✓",
|
||||
AgentState::Failed => "✗",
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the human-readable label for an agent's lifecycle state.
|
||||
fn state_label(state: AgentState) -> &'static str {
|
||||
match state {
|
||||
AgentState::Idle => "Idle",
|
||||
AgentState::Running => "Running",
|
||||
AgentState::Completed => "Done",
|
||||
AgentState::Failed => "Failed",
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the TUI color associated with an agent's lifecycle state.
|
||||
fn state_color(state: AgentState) -> Color {
|
||||
match state {
|
||||
AgentState::Idle => Theme::TEXT_DIM,
|
||||
AgentState::Running => Theme::WARNING,
|
||||
AgentState::Completed => Theme::SUCCESS,
|
||||
AgentState::Failed => Theme::ERROR,
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the workflow status panel.
|
||||
pub fn draw_workflow_panel(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
state: &crate::app::state::rest::AppStateRest,
|
||||
) {
|
||||
use ratatui::layout::{Constraint, Direction, Layout};
|
||||
|
||||
let title = Span::styled(
|
||||
" Workflow ",
|
||||
Style::default()
|
||||
.fg(Theme::PRIMARY)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Theme::BORDER))
|
||||
.title(title);
|
||||
|
||||
let inner = block.inner(area);
|
||||
frame.render_widget(block, area);
|
||||
|
||||
// Split inner into header and body
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Length(3), Constraint::Min(4)])
|
||||
.split(inner);
|
||||
|
||||
// ── Header area ──────────────────────────────────────────────────────
|
||||
let mut header_lines: Vec<Line> = Vec::new();
|
||||
|
||||
header_lines.push(Line::from(vec![
|
||||
Span::styled(
|
||||
"/workflow run ",
|
||||
Style::default()
|
||||
.fg(Theme::PRIMARY)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
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() {
|
||||
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::TEXT_DIM),
|
||||
),
|
||||
]));
|
||||
|
||||
let header = Paragraph::new(header_lines);
|
||||
frame.render_widget(header, chunks[0]);
|
||||
|
||||
// ── Body: agent cards ────────────────────────────────────────────────
|
||||
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]);
|
||||
} else {
|
||||
let mut card_lines: Vec<Line> = Vec::new();
|
||||
for agent in &state.workflow_engine.agents {
|
||||
let color = state_color(agent.status.state);
|
||||
let icon = state_icon(agent.status.state);
|
||||
let label = state_label(agent.status.state);
|
||||
|
||||
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(),
|
||||
};
|
||||
|
||||
// Agent card header
|
||||
card_lines.push(Line::from(vec![
|
||||
Span::styled(
|
||||
format!(" {icon} "),
|
||||
Style::default().fg(color).add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(
|
||||
format!(" {}", agent.name),
|
||||
Style::default()
|
||||
.fg(Theme::TEXT)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(format!(" [{label}]"), Style::default().fg(color)),
|
||||
Span::styled(duration_str, Style::default().fg(Theme::TEXT_DIM)),
|
||||
]));
|
||||
|
||||
// Agent details (progress / error)
|
||||
if let Some(ref err) = agent.status.error {
|
||||
card_lines.push(Line::from(vec![
|
||||
Span::styled(" ⚠ ", Style::default().fg(Theme::ERROR)),
|
||||
Span::styled(err.clone(), Style::default().fg(Theme::ERROR)),
|
||||
]));
|
||||
} else if let Some(ref prog) = agent.status.progress {
|
||||
for line in prog.lines().take(2) {
|
||||
card_lines.push(Line::from(vec![
|
||||
Span::styled(" ", Style::default()),
|
||||
Span::styled(
|
||||
line.to_string(),
|
||||
Style::default()
|
||||
.fg(Theme::TEXT_DIM)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
),
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let list = Paragraph::new(card_lines);
|
||||
frame.render_widget(list, chunks[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Build compact session info lines for the placeholder view when no workflow is running.
|
||||
///
|
||||
/// Flow: build lines showing message count, tool call count, pending jobs,
|
||||
/// and bash jobs from the session runtime, or a "no active session" placeholder.
|
||||
///
|
||||
/// Return: a `Vec<Line>` suitable for rendering in the workflow panel body.
|
||||
fn build_session_lines(state: &crate::app::state::rest::AppStateRest) -> Vec<Line<'static>> {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
|
||||
lines.push(Line::from(Span::styled(
|
||||
" No workflow running.",
|
||||
Style::default().fg(Theme::TEXT_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::TEXT_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::TEXT_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::TEXT_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::TEXT_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::TEXT_DIM),
|
||||
)));
|
||||
}
|
||||
|
||||
lines.push(Line::from(Span::raw("")));
|
||||
lines.push(Line::from(Span::styled(
|
||||
" The Hive is dormant. Complex tasks will stir it.",
|
||||
Style::default()
|
||||
.fg(Theme::TEXT_DIM)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
)));
|
||||
|
||||
lines
|
||||
}
|
||||
Reference in New Issue
Block a user