feat: card-style status side panel (model, models run, LSP, MCP, tests, session log)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec1c4fb41a
commit
2166ef535b
3 files changed
+826
-145
No files matched your search
+132
-140
@@ -11,6 +11,7 @@ pub mod review;
|
||||
pub mod scroll;
|
||||
pub mod select;
|
||||
pub mod sessions;
|
||||
pub mod side;
|
||||
pub mod stats_view;
|
||||
pub mod status;
|
||||
pub mod theme;
|
||||
@@ -51,7 +52,7 @@ pub struct Setup {
|
||||
pub mouse: bool,
|
||||
pub yolo: bool,
|
||||
pub auto: bool,
|
||||
pub mcp: Vec<(String, bool)>,
|
||||
pub mcp: side::McpStatus,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
@@ -154,7 +155,11 @@ struct App {
|
||||
snap: Option<tokio::sync::watch::Receiver<Arc<hx_core::agent::Snap>>>,
|
||||
side: bool,
|
||||
lens_lines: Vec<String>,
|
||||
mcp: Vec<(String, bool)>,
|
||||
mcp: Vec<side::McpRow>,
|
||||
log: side::LogRing,
|
||||
consult: Option<side::Consult>,
|
||||
seen_subs: std::collections::HashMap<usize, String>,
|
||||
mode: &'static str,
|
||||
choose: Option<(
|
||||
choose::Choose,
|
||||
tokio::sync::oneshot::Sender<Option<Vec<String>>>,
|
||||
@@ -179,6 +184,58 @@ impl App {
|
||||
if sw.provider_changed {
|
||||
self.st.quota = None;
|
||||
}
|
||||
self.log.push("main", format!("model {}", self.st.model));
|
||||
}
|
||||
|
||||
fn sync_log(&mut self) {
|
||||
for s in self.state.subs.list() {
|
||||
let st = match s.sh.status() {
|
||||
hx_core::subagent::Status::Running => "started".to_string(),
|
||||
hx_core::subagent::Status::Done => {
|
||||
format!("done {}s", s.sh.elapsed().as_secs())
|
||||
}
|
||||
hx_core::subagent::Status::Failed(e) => format!("failed {e}"),
|
||||
hx_core::subagent::Status::Aborted => "aborted".into(),
|
||||
};
|
||||
let key = format!("{} {}", s.sh.model, st);
|
||||
if self.seen_subs.get(&s.sh.id) != Some(&key) {
|
||||
self.log.push(
|
||||
format!("{} {}", s.sh.kind, s.sh.model),
|
||||
st,
|
||||
);
|
||||
self.seen_subs.insert(s.sh.id, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_lens_log(&mut self, new: &[String]) {
|
||||
let state = |x: &str| {
|
||||
x.split_once(" @ ")
|
||||
.map(|(n, r)| (n.to_string(), r.rsplit_once(": ").map_or("", |p| p.1).to_string()))
|
||||
.unwrap_or_else(|| (x.to_string(), String::new()))
|
||||
};
|
||||
for x in new {
|
||||
let (n, s) = state(x);
|
||||
let old = self.lens_lines.iter().map(|o| state(o)).find(|o| o.0 == n);
|
||||
if old.as_ref().map(|o| &o.1) != Some(&s) && !s.is_empty() {
|
||||
self.log.push("lsp", format!("{n} {s}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_mcp(&mut self, new: Vec<side::McpRow>) {
|
||||
for m in &new {
|
||||
let old = self.mcp.iter().find(|o| o.name == m.name).map(|o| o.state);
|
||||
if old != Some(m.state) && m.state != side::McpState::Pending {
|
||||
let what = match (&m.state, &m.error) {
|
||||
(side::McpState::Failed, Some(e)) => format!("{} failed: {e}", m.name),
|
||||
(side::McpState::Failed, None) => format!("{} failed", m.name),
|
||||
_ => format!("{} up {} tools", m.name, m.tools),
|
||||
};
|
||||
self.log.push("mcp", what);
|
||||
}
|
||||
}
|
||||
self.mcp = new;
|
||||
}
|
||||
|
||||
fn ctx_max_from(&mut self, a: &Agent) {
|
||||
@@ -233,7 +290,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
mouse,
|
||||
yolo,
|
||||
auto,
|
||||
mcp,
|
||||
mcp: mcp_status,
|
||||
} = setup;
|
||||
let kbd = crossterm::terminal::supports_keyboard_enhancement().unwrap_or(false);
|
||||
let (tx, mut rx) = mpsc::unbounded_channel();
|
||||
@@ -350,12 +407,25 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
snap: Some(agent.snap()),
|
||||
side: true,
|
||||
lens_lines: vec![],
|
||||
mcp,
|
||||
mcp: vec![],
|
||||
log: Default::default(),
|
||||
consult: None,
|
||||
seen_subs: Default::default(),
|
||||
mode: if yolo {
|
||||
"yolo"
|
||||
} else if auto {
|
||||
"auto"
|
||||
} else {
|
||||
"ask"
|
||||
},
|
||||
state: agent.cx.state.clone(),
|
||||
sub_t: Default::default(),
|
||||
agents: None,
|
||||
};
|
||||
sessions::history(&mut app.t, &agent.session().messages());
|
||||
let first = mcp_status();
|
||||
app.sync_mcp(first);
|
||||
app.log.push("main", format!("model {}", app.st.model));
|
||||
if open_sessions {
|
||||
open_sessions_picker(&mut app);
|
||||
}
|
||||
@@ -601,15 +671,23 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
}
|
||||
t.apply(&ev);
|
||||
}
|
||||
_ = tick.tick(), if app.busy || subs_running(&app) => dirty = true,
|
||||
_ = tick.tick(), if app.busy || subs_running(&app) => {
|
||||
app.sync_log();
|
||||
dirty = true;
|
||||
}
|
||||
_ = lens_tick.tick() => {
|
||||
let to = std::time::Duration::from_millis(200);
|
||||
if let Ok(v) = tokio::time::timeout(to, lsp_status()).await {
|
||||
let s = status::lens_summary(&v);
|
||||
app.sync_lens_log(&v);
|
||||
app.lens_lines = v;
|
||||
dirty |= s != app.lens;
|
||||
app.lens = s;
|
||||
}
|
||||
let m = mcp_status();
|
||||
dirty |= m != app.mcp;
|
||||
app.sync_mcp(m);
|
||||
app.sync_log();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1806,14 +1884,32 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
f.render_widget(block, side);
|
||||
let mut ls = vec![
|
||||
spread_line(
|
||||
Span::styled("/lsp", th.accent().add_modifier(Modifier::BOLD)),
|
||||
Span::styled("/status", th.accent().add_modifier(Modifier::BOLD)),
|
||||
Span::styled("ctrl-l ×", th.dim()),
|
||||
body.width,
|
||||
),
|
||||
Line::default(),
|
||||
];
|
||||
ls.extend(side_lines(app, body.width as usize));
|
||||
f.render_widget(Paragraph::new(ls).wrap(Wrap { trim: false }), body);
|
||||
let lens = app
|
||||
.state
|
||||
.lens
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.clone();
|
||||
let subs = app.state.subs.list();
|
||||
ls.extend(side::lines(&side::View {
|
||||
st: &app.st,
|
||||
mode: app.mode,
|
||||
lens_lines: &app.lens_lines,
|
||||
lens: &lens,
|
||||
mcp: &app.mcp,
|
||||
subs: &subs,
|
||||
consult: app.consult.as_ref(),
|
||||
log: &app.log,
|
||||
w: body.width as usize,
|
||||
h: (body.height as usize).saturating_sub(2),
|
||||
}));
|
||||
f.render_widget(Paragraph::new(ls), body);
|
||||
app.areas.panel = Rect::default();
|
||||
m
|
||||
}
|
||||
@@ -1953,128 +2049,6 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
}
|
||||
}
|
||||
|
||||
const SIDE_DIAGS: usize = 8;
|
||||
const SIDE_TESTS: usize = 6;
|
||||
|
||||
fn side_lines(app: &App, w: usize) -> Vec<Line<'static>> {
|
||||
let th = theme::t();
|
||||
let sec = |label: String| {
|
||||
Line::styled(
|
||||
th.rule(&label, w)
|
||||
.replacen(th.sym.rule, "", 1)
|
||||
.trim_start()
|
||||
.to_string(),
|
||||
th.dim(),
|
||||
)
|
||||
};
|
||||
let mut l = vec![];
|
||||
if app.lens_lines.is_empty() {
|
||||
l.push(Line::styled("no servers started", th.dim()));
|
||||
}
|
||||
for x in &app.lens_lines {
|
||||
let (name, state) = match x.split_once(" @ ") {
|
||||
Some((n, r)) => (n.to_string(), r.rsplit_once(": ").map_or("", |p| p.1)),
|
||||
None => (x.clone(), ""),
|
||||
};
|
||||
let (mark, st, word) = if state.starts_with("running") {
|
||||
(th.sym.done, th.ok(), "ready")
|
||||
} else if state.is_empty() {
|
||||
(th.sym.info, th.dim(), "")
|
||||
} else if state == "stopped" {
|
||||
(th.sym.off, th.dim(), "stopped")
|
||||
} else {
|
||||
(th.sym.err, th.err(), state)
|
||||
};
|
||||
l.push(Line::from(vec![
|
||||
Span::styled(format!("{mark} "), st),
|
||||
Span::styled(
|
||||
format!("{name:<16}"),
|
||||
if word.is_empty() {
|
||||
th.sec()
|
||||
} else {
|
||||
th.plain()
|
||||
},
|
||||
),
|
||||
Span::styled(format!(" {word}"), th.sec()),
|
||||
]));
|
||||
}
|
||||
let view = app
|
||||
.state
|
||||
.lens
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.clone();
|
||||
if !view.diags.is_empty() {
|
||||
l.push(Line::default());
|
||||
l.push(sec(format!("diagnostics {}", view.diags.len())));
|
||||
let mut ds = view.diags.clone();
|
||||
ds.sort_by_key(|d| (!d.error, d.file.clone(), d.line));
|
||||
for d in ds.iter().take(SIDE_DIAGS) {
|
||||
let (mark, st) = if d.error {
|
||||
(th.sym.err, th.err())
|
||||
} else {
|
||||
(th.sym.warn, th.warn())
|
||||
};
|
||||
let file = d.file.rsplit('/').next().unwrap_or(&d.file);
|
||||
l.push(Line::from(vec![
|
||||
Span::styled(format!("{mark} "), st),
|
||||
Span::styled(format!("{file}:{}:{}", d.line, d.col), th.plain()),
|
||||
]));
|
||||
l.push(Line::styled(format!(" {}", d.message), th.sec()));
|
||||
}
|
||||
if ds.len() > SIDE_DIAGS {
|
||||
l.push(Line::styled(
|
||||
format!(" {} {} more", th.sym.ellipsis, ds.len() - SIDE_DIAGS),
|
||||
th.dim(),
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(ts) = &view.tests {
|
||||
let mut ts = ts.clone();
|
||||
ts.sort_by_key(|t| t.1);
|
||||
l.push(Line::default());
|
||||
l.push(sec(format!("affected tests {}", ts.len())));
|
||||
for (n, ok) in ts.iter().take(SIDE_TESTS) {
|
||||
l.push(Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{} ", if *ok { th.sym.ok } else { th.sym.err }),
|
||||
if *ok { th.ok() } else { th.err() },
|
||||
),
|
||||
Span::styled(n.clone(), th.plain()),
|
||||
]));
|
||||
}
|
||||
if ts.len() > SIDE_TESTS {
|
||||
l.push(Line::styled(
|
||||
format!(" {} {} more", th.sym.ellipsis, ts.len() - SIDE_TESTS),
|
||||
th.dim(),
|
||||
));
|
||||
}
|
||||
}
|
||||
let u = &app.st.usage;
|
||||
let tot = u.input_tokens + u.cache_read_tokens + u.cache_write_tokens;
|
||||
l.push(Line::default());
|
||||
l.push(sec("context".into()));
|
||||
let mut ctx = format!("{}k / {}k", app.st.ctx_tokens / 1000, app.st.ctx_max / 1000);
|
||||
if let Some(p) = (100 * u.cache_read_tokens).checked_div(tot) {
|
||||
ctx += &format!(" {} cache {p}%", th.sym.info);
|
||||
}
|
||||
l.push(Line::styled(ctx, th.sec()));
|
||||
if !app.mcp.is_empty() {
|
||||
l.push(Line::default());
|
||||
l.push(sec("mcp".into()));
|
||||
l.extend(app.mcp.iter().map(|(n, ok)| {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{} ", if *ok { th.sym.done } else { th.sym.err }),
|
||||
if *ok { th.ok() } else { th.err() },
|
||||
),
|
||||
Span::styled(n.clone(), th.plain()),
|
||||
])
|
||||
}));
|
||||
}
|
||||
l
|
||||
}
|
||||
|
||||
fn skills_list(specs: &[CmdSpec], dirs: &[std::path::PathBuf]) -> String {
|
||||
let sk: Vec<String> = specs
|
||||
.iter()
|
||||
@@ -2322,7 +2296,23 @@ mod tests {
|
||||
#[test]
|
||||
fn side_panel_only_on_wide_terminals() {
|
||||
let mut app = test_app();
|
||||
app.mcp = vec![("git".into(), true), ("db".into(), false)];
|
||||
app.mcp = vec![
|
||||
side::McpRow {
|
||||
name: "git".into(),
|
||||
state: side::McpState::Ok,
|
||||
tools: 3,
|
||||
prompts: 0,
|
||||
error: None,
|
||||
},
|
||||
side::McpRow {
|
||||
name: "db".into(),
|
||||
state: side::McpState::Failed,
|
||||
tools: 0,
|
||||
prompts: 0,
|
||||
error: Some("refused".into()),
|
||||
},
|
||||
];
|
||||
app.log.push("lsp", "rust-analyzer running");
|
||||
app.lens_lines = vec!["rust-analyzer @ /p: running".into()];
|
||||
*app.state.lens.lock().unwrap() = hx_core::LensView {
|
||||
diags: vec![hx_core::Diag {
|
||||
@@ -2336,23 +2326,21 @@ mod tests {
|
||||
};
|
||||
let s = screen(&mut app, 160, 50);
|
||||
assert!(
|
||||
s.contains("diagnostics 1 ┈") && s.contains("⚠ codemode.rs:88:13"),
|
||||
"{s}"
|
||||
);
|
||||
assert!(
|
||||
s.contains("affected tests 2 ┈") && s.contains("✗ a::bad"),
|
||||
s.contains("LSP") && s.contains("⚠ codemode.rs:88 unused variable"),
|
||||
"{s}"
|
||||
);
|
||||
assert!(s.contains("TESTS") && s.contains("✗ a::bad"), "{s}");
|
||||
let bad = s.find("✗ a::bad").unwrap();
|
||||
assert!(bad < s.find("✓ a::ok").unwrap(), "failures first");
|
||||
assert!(
|
||||
s.contains("/lsp") && s.contains("● rust-analyzer ready"),
|
||||
s.contains("/status") && s.contains("● rust-analyzer") && s.contains("ready"),
|
||||
"{s}"
|
||||
);
|
||||
assert!(s.contains("mcp ┈") && s.contains("✗ db"), "{s}");
|
||||
assert!(!screen(&mut app, 80, 24).contains("/lsp"));
|
||||
assert!(s.contains("MCP") && s.contains("✗ db"), "{s}");
|
||||
assert!(s.contains("MODEL") && s.contains("SESSION LOG"), "{s}");
|
||||
assert!(!screen(&mut app, 80, 24).contains("/status"));
|
||||
app.side = false;
|
||||
assert!(!screen(&mut app, 160, 50).contains("/lsp"));
|
||||
assert!(!screen(&mut app, 160, 50).contains("/status"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2647,6 +2635,10 @@ mod tests {
|
||||
side: true,
|
||||
lens_lines: vec![],
|
||||
mcp: vec![],
|
||||
log: Default::default(),
|
||||
consult: None,
|
||||
seen_subs: Default::default(),
|
||||
mode: "ask",
|
||||
state: Default::default(),
|
||||
sub_t: Default::default(),
|
||||
agents: None,
|
||||
|
||||
Reference in new issue
Block a user