mielin_cli/types/
agent.rs1use crate::output::MultiFormatDisplay;
4use comfy_table::{presets::UTF8_FULL, Cell, Color, ContentArrangement, Table};
5use serde::Serialize;
6
7#[derive(Debug, Serialize)]
8pub struct AgentInfo {
9 pub id: String,
10 pub state: String,
11 pub node: String,
12 pub dna_hash: String,
13 pub memory_mb: f64,
14 pub uptime: String,
15}
16
17#[derive(Debug, Serialize)]
18pub struct AgentList {
19 pub agents: Vec<AgentInfo>,
20 pub total: usize,
21}
22
23impl MultiFormatDisplay for AgentList {
24 fn to_table(&self) -> Table {
25 let mut table = Table::new();
26 table
27 .load_preset(UTF8_FULL)
28 .set_content_arrangement(ContentArrangement::Dynamic)
29 .set_header(vec![
30 Cell::new("ID").fg(Color::Cyan),
31 Cell::new("STATE").fg(Color::Cyan),
32 Cell::new("NODE").fg(Color::Cyan),
33 Cell::new("DNA").fg(Color::Cyan),
34 Cell::new("MEMORY").fg(Color::Cyan),
35 Cell::new("UPTIME").fg(Color::Cyan),
36 ]);
37
38 for agent in &self.agents {
39 let state_color = match agent.state.as_str() {
40 "Running" => Color::Green,
41 "Paused" => Color::Yellow,
42 "Error" => Color::Red,
43 "Migrating" => Color::Blue,
44 _ => Color::White,
45 };
46
47 table.add_row(vec![
48 Cell::new(&agent.id[..8]),
49 Cell::new(&agent.state).fg(state_color),
50 Cell::new(&agent.node[..8]),
51 Cell::new(&agent.dna_hash[..8]),
52 Cell::new(format!("{:.1} MB", agent.memory_mb)),
53 Cell::new(&agent.uptime),
54 ]);
55 }
56
57 table
58 }
59
60 fn to_quiet(&self) -> String {
61 self.agents
62 .iter()
63 .map(|a| a.id.clone())
64 .collect::<Vec<_>>()
65 .join("\n")
66 }
67}