use eclipse_core::router::{describe_hops, Hop, RoleRoute, RouteInfo};
use eclipse_core::usage::{TurnUsage, UsageTotals};
use std::time::Instant;
use crate::ui::Style;
pub struct Status {
pub model: String,
pub endpoint: String,
pub profile: Option<String>,
pub workspace: String,
pub session: Option<String>,
pub budget: usize,
pub window: usize,
pub keep: usize,
pub last: Option<TurnUsage>,
pub context_tokens: Option<usize>,
pub totals: UsageTotals,
pub started: Instant,
pub approvals: bool,
pub max_iterations: usize,
pub concurrency: usize,
pub routes: Vec<RouteInfo>,
pub pinned: bool,
pub roles: Vec<RoleRoute>,
pub last_hops: Vec<Hop>,
pub effort: Option<eclipse_core::reasoning::InForce>,
pub judged: bool,
}
pub fn roles_line(roles: &[RoleRoute]) -> Option<String> {
let set: Vec<String> = roles
.iter()
.filter(|r| r.set || r.pinned)
.map(|r| r.to_string())
.collect();
(!set.is_empty()).then(|| set.join(", "))
}
pub fn chain_line(routes: &[RouteInfo], pinned: bool) -> String {
let names: Vec<&str> = routes.iter().map(|r| r.name.as_str()).collect();
let line = names.join(" \u{2192} ");
if pinned {
format!("{line} (pinned, no fallback)")
} else {
line
}
}
impl Status {
pub fn new(model: &str, endpoint: &str, budget: usize, workspace: String) -> Self {
Self {
model: model.to_string(),
endpoint: endpoint.to_string(),
profile: None,
workspace,
session: None,
budget,
window: 0,
keep: 0,
last: None,
context_tokens: None,
totals: UsageTotals::default(),
started: Instant::now(),
approvals: false,
max_iterations: 0,
concurrency: 1,
routes: Vec::new(),
pinned: false,
roles: Vec::new(),
last_hops: Vec::new(),
effort: None,
judged: false,
}
}
pub fn record_hops(&mut self, hops: Vec<Hop>) {
let moved = !self.last_hops.is_empty();
let answered = match hops.last() {
Some(h) => self.routes.iter().find(|r| r.name == h.to),
None if moved => self.routes.first(),
None => None,
};
if let Some(r) = answered {
self.model = r.model.clone();
self.endpoint = endpoint_host(&r.endpoint);
}
self.last_hops = hops;
}
fn shows_routes(&self) -> bool {
self.pinned || self.routes.len() > 1
}
pub fn record(&mut self, usage: TurnUsage) {
self.totals.add(&usage);
self.last = Some(usage);
}
pub fn context_used(&self) -> Option<usize> {
self.last
.as_ref()
.and_then(|u| u.prompt_tokens)
.map(|t| t as usize)
.or(self.context_tokens)
.filter(|t| *t > 0)
}
pub fn record_with_context(
&mut self,
usage: TurnUsage,
context_tokens: usize,
budget_tokens: usize,
) {
self.context_tokens = (context_tokens > 0).then_some(context_tokens);
if budget_tokens > 0 {
self.budget = budget_tokens;
}
self.record(usage);
}
pub fn denominator(&self) -> usize {
if self.window > 0 {
self.window
} else {
self.budget
}
}
pub fn reading(&self) -> eclipse_core::contextbar::Reading {
eclipse_core::contextbar::Reading::new(
self.context_used().map(|c| c as u64),
self.denominator(),
self.marker_share(),
)
}
pub fn marker_share(&self) -> Option<f64> {
if self.window == 0 || self.budget == 0 || self.budget >= self.window {
return None;
}
Some(self.budget as f64 / self.window as f64)
}
}
pub fn loop_line(turns: usize, concurrency: usize) -> String {
format!(
"{turns} turn{} · tools {}",
if turns == 1 { "" } else { "s" },
match concurrency {
0 | 1 => "one at a time".to_string(),
n => format!("{n} at a time"),
}
)
}
pub fn short_session(id: &str) -> String {
let tail: String = id
.chars()
.rev()
.take(8)
.collect::<Vec<_>>()
.into_iter()
.rev()
.collect();
if id.chars().count() > 8 {
format!("…{tail}")
} else {
id.to_string()
}
}
pub fn budget_line(budget: usize, window: usize, keep: usize) -> String {
let tail = match keep {
0 => String::new(),
1 => " · keeps the newest turn verbatim".to_string(),
n => format!(" · keeps last {n} turns verbatim"),
};
match (budget, window) {
(0, 0) => "no budget set".to_string(),
(0, w) => format!("window {} · compaction off", short_tokens(w as u64)),
(b, w) if w > b => format!(
"budget {} of {} window · compacts at {:.0}%{tail}",
short_tokens(b as u64),
short_tokens(w as u64),
b as f64 / w as f64 * 100.0
),
(b, 0) => format!("budget {} · window unknown", short_tokens(b as u64)),
(b, w) => format!(
"budget {} of {} window",
short_tokens(b as u64),
short_tokens(w as u64)
),
}
}
pub use eclipse_core::contextbar::{bar_marked, short_tokens, MARKER};
fn marked_bar(style: &Style, share: f64, marker: f64, width: usize) -> String {
let bar = bar_marked(share, marker, width);
let mut out = String::new();
for (i, piece) in bar.split(MARKER).enumerate() {
if i > 0 {
out.push_str(&style.red(&MARKER.to_string()));
}
out.push_str(&style.amber(piece));
}
out
}
pub fn short_duration(ms: u64) -> String {
match ms {
0..=9_999 => format!("{:.1}s", ms as f64 / 1000.0),
10_000..=59_999 => format!("{:.0}s", ms as f64 / 1000.0),
60_000..=3_599_999 => {
let secs = ms / 1000;
format!("{}m{:02}s", secs / 60, secs % 60)
}
_ => {
let mins = ms / 60_000;
format!("{}h{:02}m", mins / 60, mins % 60)
}
}
}
fn opt<T: std::fmt::Display>(v: Option<T>) -> String {
v.map(|x| x.to_string()).unwrap_or_else(|| "--".to_string())
}
impl Status {
pub fn line(&self, style: &Style) -> String {
let mut parts: Vec<String> = Vec::new();
parts.push(style.bold(&self.model));
let reading = self.reading();
let piece = reading.pieces(12);
let mut ctx = format!("ctx {}", style.dim(&piece.numbers));
if !piece.bar.is_empty() {
ctx.push(' ');
ctx.push_str(&marked_bar(
style,
reading.share().unwrap_or(0.0),
reading.marker.unwrap_or(0.0),
12,
));
}
if let Some(percent) = &piece.percent {
ctx.push(' ');
ctx.push_str(&style.dim(percent));
}
if reading.passed() {
ctx.push_str(&style.dim(&format!(
" · compacts at {:.0}%",
reading.marker.unwrap_or(0.0) * 100.0
)));
}
parts.push(ctx);
if let Some(effort) = &self.effort {
parts.push(if effort.session {
style.amber(&format!("effort {}", effort.label))
} else {
style.dim(&format!("effort {}", effort.label))
});
}
if let Some(last) = &self.last {
if let Some(ms) = last.ttft_ms {
parts.push(style.dim(&format!("first {}", short_duration(ms))));
}
parts.push(style.dim(&short_duration(last.latency_ms)));
if let Some(tps) = last.tokens_per_sec() {
parts.push(style.dim(&format!("↑{:.0} t/s", tps)));
}
match (last.cached_tokens, last.prompt_tokens) {
(Some(c), Some(p)) if p > 0 => parts.push(style.dim(&format!(
"⚡{} ({:.0}%)",
short_tokens(c),
c as f64 / p as f64 * 100.0
))),
(Some(c), _) => parts.push(style.dim(&format!("⚡{}", short_tokens(c)))),
_ => {}
}
}
if self.totals.turns > 1 {
parts.push(style.dim(&format!(
"Σ ↑{} · ↓{}",
short_tokens(self.totals.prompt_tokens),
short_tokens(self.totals.completion_tokens)
)));
}
parts.push(style.dim(&short_duration(self.started.elapsed().as_millis() as u64)));
if self.approvals {
parts.push(style.amber("approvals: auto"));
}
parts.push(style.dim(&self.workspace_short()));
parts.join(&style.dim(" · "))
}
fn workspace_short(&self) -> String {
match std::env::var_os("HOME").and_then(|h| h.into_string().ok()) {
Some(home) if !home.is_empty() && self.workspace.starts_with(&home) => {
format!("~{}", &self.workspace[home.len()..])
}
_ => self.workspace.clone(),
}
}
pub fn detail(&self, style: &Style) -> String {
let mut out = String::new();
let mut row = |k: &str, v: String| {
if !out.is_empty() {
out.push('\n');
}
out.push_str(&format!(" {} {v}", style.dim(&format!("{k:<13}"))));
};
row("model", style.bold(&self.model));
row("endpoint", self.endpoint.clone());
if self.shows_routes() {
row("routes", chain_line(&self.routes, self.pinned));
for r in &self.routes {
row(
"",
format!("{}: {} @ {}", r.name, r.model, endpoint_host(&r.endpoint)),
);
}
}
if let Some(roles) = roles_line(&self.roles) {
row("roles", roles);
}
if let Some(hops) = describe_hops(&self.last_hops) {
row("last hop", hops.trim_start_matches("route: ").to_string());
}
row(
"profile",
self.profile.clone().unwrap_or_else(|| "default".into()),
);
row("context", budget_line(self.budget, self.window, self.keep));
if let Some(effort) = &self.effort {
row("reasoning", effort.sentence());
}
if self.max_iterations > 0 {
row("loop", loop_line(self.max_iterations, self.concurrency));
}
row(
"session",
self.session.clone().unwrap_or_else(|| "new".into()),
);
row("workspace", self.workspace.clone());
let t = &self.totals;
row(
"this process",
format!(
"{} request(s) · ↑{} prompt · ↓{} generated{}",
t.turns,
short_tokens(t.prompt_tokens),
short_tokens(t.completion_tokens),
match t.cache_ratio() {
Some(r) => format!(" · cache {:.0}%", r * 100.0),
None => String::new(),
}
),
);
if let Some(last) = &self.last {
row(
"last request",
format!(
"prompt {} ({} cached) · {} generated · {} prefill · {} decode · {} wall{}",
opt(last.prompt_tokens),
opt(last.cached_tokens),
opt(last.completion_tokens),
last.prompt_ms
.map(short_duration)
.unwrap_or_else(|| "--".into()),
last.completion_ms
.map(short_duration)
.unwrap_or_else(|| "--".into()),
short_duration(last.latency_ms),
match (last.tokens_per_sec(), last.ttft_ms) {
(Some(tps), Some(ttft)) => {
format!(" · {tps:.1} t/s · first token {}", short_duration(ttft))
}
(Some(tps), None) => format!(" · {tps:.1} t/s"),
_ => String::new(),
}
),
);
}
out
}
}
fn endpoint_host(url: &str) -> String {
url.split("://")
.last()
.unwrap_or(url)
.split('/')
.next()
.unwrap_or(url)
.to_string()
}
fn emit(out: &mut String, style: &Style, label: &str, value: &str) {
out.push_str(&format!(
" {} {value}\n",
style.amber(&format!("{label:<10}"))
));
}
fn wrap(text: &str, width: usize) -> Vec<String> {
let mut lines = Vec::new();
let mut line = String::new();
for piece in text.split(", ") {
if !line.is_empty() && line.chars().count() + 2 + piece.chars().count() > width {
lines.push(std::mem::take(&mut line));
}
if !line.is_empty() {
line.push_str(", ");
}
line.push_str(piece);
}
if !line.is_empty() {
lines.push(line);
}
if lines.is_empty() {
lines.push(String::new());
}
lines
}
pub struct Panel {
pub version: String,
pub model: String,
pub endpoint: String,
pub profile: Option<String>,
pub workspace: String,
pub session: Option<String>,
pub budget: usize,
pub window: usize,
pub keep: usize,
pub max_iterations: usize,
pub concurrency: usize,
pub stream: bool,
pub approvals: bool,
pub routes: Vec<RouteInfo>,
pub pinned: bool,
pub roles: Vec<RoleRoute>,
pub tools: Vec<String>,
pub plugins: Vec<String>,
pub plugin_problems: Vec<String>,
}
impl Panel {
pub fn render(&self, style: &Style) -> String {
let rule = style.dim(&"─".repeat(72));
let mut out = String::new();
out.push_str(&format!(
"\n {} {}\n",
style.amber("◐"),
style.bold(&format!("eclipse {}", self.version))
));
out.push_str(&format!(
" {}\n\n",
style.dim(&format!(
"{} · {} · {}{}",
self.model,
self.endpoint,
if self.stream { "stream" } else { "no stream" },
match &self.profile {
Some(p) => format!(" · profile {p}"),
None => String::new(),
}
))
));
out.push_str(&format!("{rule}\n"));
if self.pinned || self.routes.len() > 1 {
emit(
&mut out,
style,
"routes",
&chain_line(&self.routes, self.pinned),
);
for r in &self.routes {
out.push_str(&format!(" {}{}: {}\n", " ".repeat(11), r.name, r.model));
}
}
if let Some(roles) = roles_line(&self.roles) {
emit(&mut out, style, "roles", &roles);
}
if !self.tools.is_empty() {
let body = format!("({}) {}", self.tools.len(), self.tools.join(", "));
let mut lines = wrap(&body, 76);
let head = lines.remove(0);
emit(&mut out, style, "tools", &head);
for extra in lines {
out.push_str(&format!(" {}{extra}\n", " ".repeat(11)));
}
}
if !self.plugins.is_empty() {
emit(&mut out, style, "plugins", &self.plugins.join(", "));
}
for problem in &self.plugin_problems {
emit(&mut out, style, "", &style.yellow(problem));
}
emit(
&mut out,
style,
"context",
&budget_line(self.budget, self.window, self.keep),
);
if self.max_iterations > 0 {
emit(
&mut out,
style,
"loop",
&loop_line(self.max_iterations, self.concurrency),
);
}
let approvals = if self.approvals {
style.amber("auto")
} else {
"ask".to_string()
};
emit(&mut out, style, "approvals", &approvals);
emit(&mut out, style, "workspace", &self.workspace);
emit(
&mut out,
style,
"session",
self.session.as_deref().unwrap_or("new"),
);
out.push_str(&format!("{rule}\n"));
out.push_str(&format!(
" {}\n\n",
style.dim(&format!(
"{} tools{} · /help for commands · Ctrl-C stops a run, Ctrl-D exits",
self.tools.len(),
if self.plugins.is_empty() {
String::new()
} else {
format!(" · {} plugins", self.plugins.len())
}
))
));
out
}
}
#[cfg(test)]
mod tests {
use super::*;
fn plain() -> Style {
Style::plain()
}
fn flat(s: &str) -> String {
s.split_whitespace().collect::<Vec<_>>().join(" ")
}
fn chain() -> Vec<RouteInfo> {
["local", "big", "cloud"]
.iter()
.map(|n| RouteInfo {
name: (*n).to_string(),
model: format!("{n}-model"),
endpoint: format!("http://{n}:8080/v1"),
})
.collect()
}
#[test]
fn the_effort_in_force_is_on_the_line_and_is_read_from_the_dial() {
use eclipse_core::reasoning::Dial;
let style = Style::plain();
let mut s = Status::new("m", "h:1", 1000, "/w".into());
assert!(
!s.line(&style).contains("effort"),
"nothing known, nothing claimed: {}",
s.line(&style)
);
let dial = Dial::new(Some("low".into()));
s.effort = Some(dial.in_force_report(None));
let line = flat(&s.line(&style));
assert!(line.contains("effort low"), "{line}");
dial.set_session(Some("high".into()));
s.effort = Some(dial.in_force_report(None));
let line = flat(&s.line(&style));
assert!(line.contains("effort high"), "{line}");
assert!(
s.effort.as_ref().unwrap().session,
"and the line knows the session is why"
);
let detail = flat(&s.detail(&style));
assert!(
detail.contains("reasoning high (this session; config.toml says low)"),
"{detail}"
);
}
#[test]
fn status_shows_the_chain_with_the_model_each_route_serves() {
let mut s = Status::new("local-model", "local:8080", 1000, "/w".into());
s.routes = chain();
let detail = flat(&s.detail(&plain()));
assert!(
detail.contains("routes local \u{2192} big \u{2192} cloud"),
"{detail}"
);
assert!(detail.contains("big: big-model @ big:8080"), "{detail}");
}
#[test]
fn status_says_what_hopped_after_a_run_and_nothing_before_one() {
let mut s = Status::new("m", "h:1", 1000, "/w".into());
s.routes = chain();
assert!(!s.detail(&plain()).contains("last hop"));
s.last_hops = vec![Hop {
from: "local".into(),
to: "big".into(),
reason: "timeout".into(),
}];
let detail = flat(&s.detail(&plain()));
assert!(
detail.contains("last hop local \u{2192} big (timeout)"),
"{detail}"
);
}
#[test]
fn a_lone_default_route_is_not_worth_a_row() {
let mut s = Status::new("m", "h:1", 1000, "/w".into());
s.routes = chain().into_iter().take(1).collect();
assert!(!s.detail(&plain()).contains("routes"));
}
#[test]
fn a_pinned_route_is_shown_as_pinned_with_no_fallback() {
let mut s = Status::new("m", "h:1", 1000, "/w".into());
s.routes = chain().into_iter().take(1).collect();
s.pinned = true;
let detail = flat(&s.detail(&plain()));
assert!(
detail.contains("routes local (pinned, no fallback)"),
"{detail}"
);
}
fn roles(aux: Option<&str>) -> Vec<RoleRoute> {
eclipse_core::router::role_table(aux, None, "local", false)
}
#[test]
fn the_panel_names_the_approval_mode_and_the_readout_only_mentions_auto() {
let mut s = Status::new("m", "h:1", 1000, "/w".into());
assert!(
!s.line(&plain()).contains("approvals"),
"an ordinary session stays as quiet as it was: {}",
s.line(&plain())
);
s.approvals = true;
assert!(
s.line(&plain()).contains("approvals: auto"),
"{}",
s.line(&plain())
);
s.approvals = false;
assert!(!s.line(&plain()).contains("approvals"));
let mut panel = Panel {
version: "0".into(),
model: "m".into(),
endpoint: "h:1".into(),
profile: None,
workspace: "/w".into(),
session: None,
budget: 1000,
window: 0,
keep: 0,
max_iterations: 0,
concurrency: 0,
stream: true,
approvals: true,
routes: vec![],
pinned: false,
roles: vec![],
tools: vec![],
plugins: vec![],
plugin_problems: vec![],
};
assert!(
flat(&panel.render(&plain())).contains("approvals auto"),
"{}",
panel.render(&plain())
);
let coloured = Style::coloured();
assert!(
panel.render(&coloured).contains("\u{1b}[38;5;214mauto"),
"amber while automatic: {:?}",
panel.render(&coloured)
);
panel.approvals = false;
let said = panel.render(&plain());
assert!(flat(&said).contains("approvals ask"), "{said}");
assert!(!said.contains("\u{1b}[38;5;214mauto"), "{said}");
}
#[test]
fn status_and_the_panel_name_the_roles_that_have_a_route_and_say_nothing_when_none_does() {
let mut s = Status::new("m", "h:1", 1000, "/w".into());
s.routes = chain();
s.roles = roles(Some("cheap"));
assert!(
flat(&s.detail(&plain())).contains("roles judgement \u{2192} cheap"),
"{}",
s.detail(&plain())
);
s.roles = roles(None);
assert!(!s.detail(&plain()).contains("roles"));
let mut panel = Panel {
version: "0".into(),
model: "m".into(),
endpoint: "h:1".into(),
profile: None,
workspace: "/w".into(),
session: None,
budget: 0,
window: 0,
keep: 0,
max_iterations: 10,
concurrency: 1,
stream: true,
approvals: false,
routes: chain(),
pinned: false,
roles: roles(Some("cheap")),
tools: Vec::new(),
plugins: Vec::new(),
plugin_problems: Vec::new(),
};
assert!(
flat(&panel.render(&plain())).contains("roles judgement \u{2192} cheap"),
"{}",
panel.render(&plain())
);
panel.roles = roles(None);
assert!(!panel.render(&plain()).contains("roles"));
}
#[test]
fn the_roles_row_lists_only_the_roles_with_a_route_of_their_own() {
let both = eclipse_core::router::role_table(Some("cheap"), Some("big"), "local", false);
assert_eq!(
roles_line(&both).unwrap(),
"judgement \u{2192} cheap, delegate \u{2192} big"
);
let delegate_only = eclipse_core::router::role_table(None, Some("big"), "local", false);
assert_eq!(roles_line(&delegate_only).unwrap(), "delegate \u{2192} big");
assert_eq!(roles_line(&roles(None)), None);
}
#[test]
fn a_pinned_run_says_its_roles_are_pinned_rather_than_configured() {
let pinned = eclipse_core::router::role_table(Some("cheap"), Some("big"), "local", true);
assert_eq!(
roles_line(&pinned).unwrap(),
"judgement \u{2192} local (pinned), delegate \u{2192} local (pinned)"
);
assert!(pinned.iter().all(|r| !r.set && r.pinned));
}
#[test]
fn the_startup_panel_shows_the_chain_when_there_is_one() {
let panel = Panel {
version: "0".into(),
model: "local-model".into(),
endpoint: "http://local:8080/v1".into(),
profile: None,
workspace: "/w".into(),
session: None,
budget: 0,
window: 0,
keep: 0,
max_iterations: 10,
concurrency: 1,
stream: true,
approvals: false,
routes: chain(),
pinned: false,
roles: Vec::new(),
tools: Vec::new(),
plugins: Vec::new(),
plugin_problems: Vec::new(),
};
let shown = flat(&panel.render(&plain()));
assert!(
shown.contains("routes local \u{2192} big \u{2192} cloud"),
"{shown}"
);
assert!(shown.contains("cloud: cloud-model"), "{shown}");
}
#[test]
fn the_model_follows_the_route_that_answered_and_returns_when_a_run_does_not_hop() {
let mut s = Status::new("local-model", "local:8080", 1000, "/w".into());
s.routes = chain();
s.record_hops(vec![Hop {
from: "local".into(),
to: "big".into(),
reason: "timeout".into(),
}]);
assert_eq!(
(s.model.as_str(), s.endpoint.as_str()),
("big-model", "big:8080")
);
s.record_hops(Vec::new());
assert_eq!(
(s.model.as_str(), s.endpoint.as_str()),
("local-model", "local:8080")
);
assert!(s.last_hops.is_empty());
}
#[test]
fn the_policy_line_names_the_threshold_and_what_is_kept() {
assert_eq!(
budget_line(278_528, 327_680, 20),
"budget 279K of 328K window · compacts at 85% · keeps last 20 turns verbatim"
);
assert_eq!(
budget_line(0, 327_680, 20),
"window 328K · compaction off",
"compact_at = 0 says so rather than hiding behind `no budget set`"
);
assert_eq!(budget_line(0, 0, 0), "no budget set");
assert_eq!(
budget_line(200_000, 0, 0),
"budget 200K · window unknown",
"a rail with no window is stated as such"
);
assert_eq!(
budget_line(131_072, 131_072, 1),
"budget 131K of 131K window"
);
}
#[test]
fn durations_read_like_a_person_wrote_them() {
assert_eq!(short_duration(0), "0.0s");
assert_eq!(short_duration(8330), "8.3s");
assert_eq!(short_duration(42_000), "42s");
assert_eq!(short_duration(95_000), "1m35s");
assert_eq!(short_duration(3_700_000), "1h01m");
}
#[test]
fn a_fresh_status_admits_it_knows_nothing() {
let s = Status::new("m", "h/v1", 1000, "/w".into());
let line = s.line(&plain());
assert!(line.contains("ctx --/1.0K"), "{line}");
assert!(!line.contains("t/s"), "no speed before a turn: {line}");
assert!(!line.contains("⚡"), "no cache claim before a turn: {line}");
}
#[test]
fn the_line_shows_context_fill_speed_and_cache() {
let mut s = Status::new("inkling-2-mini", "127.0.0.1:18045", 327_680, "/w".into());
s.record(TurnUsage {
prompt_tokens: Some(23_100),
completion_tokens: Some(120),
total_tokens: Some(23_220),
cached_tokens: Some(19_000),
prompt_ms: Some(400),
completion_ms: Some(8_000),
latency_ms: 8_400,
ttft_ms: Some(900),
});
let line = s.line(&plain());
assert!(line.contains("23.1K/328K"), "{line}");
let percent = format!(
"{}%",
(23100.0_f64 / 327_680.0_f64 * 100.0_f64).round() as i64
);
assert!(line.contains(&percent), "expected {percent} in {line}");
assert!(line.contains("8.4s"), "{line}");
assert!(line.contains("↑15 t/s"), "120 tokens in 8 s: {line}");
assert!(line.contains("⚡19.0K (82%)"), "{line}");
assert!(line.contains("first 0.9s"), "{line}");
}
#[test]
fn a_silent_server_shows_dashes_not_zeros() {
let mut s = Status::new("m", "h", 0, "/w".into());
s.record(TurnUsage {
latency_ms: 1200,
..Default::default()
});
let line = s.line(&plain());
assert!(line.contains("ctx --"), "{line}");
assert!(line.contains("1.2s"), "{line}");
assert!(!line.contains("0 t/s"), "no invented speed: {line}");
}
#[test]
fn totals_appear_once_there_is_more_than_one_turn() {
let mut s = Status::new("m", "h", 1000, "/w".into());
let u = TurnUsage {
prompt_tokens: Some(100),
completion_tokens: Some(10),
..Default::default()
};
s.record(u.clone());
assert!(!s.line(&plain()).contains("Σ"));
s.record(u);
let line = s.line(&plain());
assert!(line.contains("Σ ↑200 · ↓20"), "{line}");
}
#[test]
fn the_panel_lists_tools_plugins_and_problems() {
let panel = Panel {
version: "0.1.0".into(),
model: "m".into(),
endpoint: "127.0.0.1:18045/v1".into(),
profile: Some("work".into()),
workspace: "/w".into(),
session: None,
budget: 327_680,
window: 0,
keep: 0,
max_iterations: 10,
concurrency: 3,
stream: true,
approvals: false,
routes: vec![],
roles: vec![],
pinned: false,
tools: vec!["read_file".into(), "shell".into()],
plugins: vec!["git-tools 0.1.0".into()],
plugin_problems: vec!["plugin `broken`: api 99".into()],
};
let text = panel.render(&plain());
assert!(text.contains("eclipse 0.1.0"), "{text}");
assert!(text.contains("profile work"), "{text}");
assert!(text.contains("(2) read_file, shell"), "{text}");
assert!(text.contains("git-tools 0.1.0"), "{text}");
assert!(
text.contains("api 99"),
"problems are shown, not hidden: {text}"
);
assert!(flat(&text).contains("budget 328K"), "{text}");
assert!(flat(&text).contains("session new"), "{text}");
}
#[test]
fn the_panel_omits_empty_sections() {
let panel = Panel {
version: "0.1.0".into(),
model: "m".into(),
endpoint: "h".into(),
profile: None,
workspace: "/w".into(),
session: Some("s1".into()),
budget: 0,
window: 0,
keep: 0,
max_iterations: 0,
concurrency: 1,
stream: false,
approvals: false,
routes: vec![],
roles: vec![],
pinned: false,
tools: vec![],
plugins: vec![],
plugin_problems: vec![],
};
let text = panel.render(&plain());
assert!(!text.contains("plugins"), "{text}");
assert!(text.contains("no stream"), "{text}");
assert!(text.contains("no budget set"), "{text}");
assert!(
!text.contains("loop"),
"an unknown budget is left out, never invented: {text}"
);
assert!(flat(&text).contains("session s1"), "{text}");
}
#[test]
fn the_detail_view_reports_timings_it_actually_has() {
let mut s = Status::new("m", "h/v1", 1000, "/w".into());
s.record(TurnUsage {
prompt_tokens: Some(1000),
completion_tokens: Some(50),
total_tokens: Some(1050),
cached_tokens: Some(900),
prompt_ms: Some(250),
completion_ms: Some(2000),
latency_ms: 2400,
ttft_ms: Some(300),
});
let text = s.detail(&plain());
assert!(text.contains("prompt 1000 (900 cached)"), "{text}");
assert!(text.contains("cache 90%"), "session cache ratio: {text}");
assert!(text.contains("25.0 t/s"), "{text}");
assert!(text.contains("first token 0.3s"), "{text}");
}
#[test]
fn the_workspace_is_home_relative() {
let home = std::env::var("HOME").unwrap_or_default();
let mut s = Status::new("m", "h", 0, format!("{home}/projects/x"));
s.record(TurnUsage::default());
if !home.is_empty() {
assert!(
s.line(&plain()).contains("~/projects/x"),
"{}",
s.line(&plain())
);
}
}
#[test]
fn the_loop_line_names_the_budget_and_the_gate() {
assert_eq!(loop_line(10, 1), "10 turns · tools one at a time");
assert_eq!(loop_line(1, 4), "1 turn · tools 4 at a time");
assert_eq!(loop_line(3, 0), "3 turns · tools one at a time");
}
}