Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienos.com/blob/main/crates/site-builder/src/components/dash.rs # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / crates / site-builder / src / components / dash.rs` 374 lines · 16723 bytes Raw Blame History 1 //! /dash/: Drake's one-screen dashboard. How much model quota is left on 2 //! every account the agents run on, the Spark's own pulse, how much work is 3 //! open, and which model each omp role and subagent uses. 4 //! 5 //! The Spark writes two files to the `data/now` branch (`~/.local/bin/dash-snapshot`, 6 //! called by `now-publish`) and the pages workflow lays them into `public/data/`: 7 //! 8 //! * `accounts.tsv`: `checkedutc`, then one row per limit: 9 //! `limit, provider, account number, plan, window (5h|week), label, percent used, 10 //! resets utc, ok|exhausted`. Accounts are numbered per provider; the 11 //! publisher never writes an email, account id, org or project name. 12 //! * `routing.tsv`: `role|agent|seat, name, model selector`. 13 //! 14 //! The publisher refuses to write a file holding an identifier. As a second 15 //! guard, every field read here passes `word`: a row with an email-, domain- 16 //! or UUID-shaped field is dropped whole, and markup characters are removed. 17 18 use std::fs; 19 use std::path::Path; 20 21 use maud::{html, Markup}; 22 23 use super::boxlink::{foot_labelled, Target}; 24 use super::now::{fmt_utc, parse_utc, Now}; 25 26 pub const TITLE: &str = "Dashboard | AienOS"; 27 pub const DESCRIPTION: &str = "One screen: model quota left on every account the agents run on, the Spark's pulse, open work, and which model each role uses."; 28 pub const URL: &str = "https://www.aienos.com/dash/"; 29 30 pub const ACCOUNTS_PATH: &str = "public/data/accounts.tsv"; 31 pub const ROUTING_PATH: &str = "public/data/routing.tsv"; 32 /// The quota and routing readings are not committed anywhere a visitor can 33 /// open, so their cards link the source that reads and renders them. 34 const DASH_SOURCE: &str = "https://interplane.io/drakestapleton/aienos.com/blob/main/crates/site-builder/src/components/dash.rs"; 35 const PULSE_URL: &str = "https://interplane.io/drakestapleton/aienos.com/blob/main/public/data/now-pulse.tsv"; 36 const LEDGER_URL: &str = crate::components::now::LEDGER_URL; 37 38 /// Providers the page shows, in display order. 39 const PROVIDERS: [&str; 4] = ["Anthropic", "OpenAI Codex", "Google Antigravity", "xAI Grok"]; 40 /// A quota reading older than this, at build time, is called out as old. 41 const STALE_S: i64 = 2 * 3600; 42 43 #[derive(Debug, Clone, PartialEq)] 44 pub struct Limit { 45 pub window: String, 46 pub label: String, 47 pub used_pct: u32, 48 pub resets_utc: String, 49 pub exhausted: bool, 50 } 51 52 #[derive(Debug, Clone, PartialEq)] 53 pub struct Account { 54 pub provider: &'static str, 55 pub n: u32, 56 pub plan: String, 57 pub limits: Vec, 58 } 59 60 #[derive(Debug, Clone, Default, PartialEq)] 61 pub struct Quota { 62 pub checked_utc: Option, 63 pub accounts: Vec, 64 } 65 66 #[derive(Debug, Clone, Default, PartialEq)] 67 pub struct Routing { 68 pub roles: Vec<(String, String)>, 69 pub agents: Vec<(String, String)>, 70 pub seats: Vec<(String, String)>, 71 } 72 73 pub struct Dash { 74 pub quota: Quota, 75 pub routing: Routing, 76 } 77 78 /// True when a field looks like an identifier that must never be published: 79 /// anything with `@`, a UUID-shaped run (8 hex, hyphen, 4 hex), or a token 80 /// that ends in a mail domain (`name.com`). 81 fn looks_private(s: &str) -> bool { 82 if s.contains('@') { 83 return true; 84 } 85 let b = s.as_bytes(); 86 let uuid = (0..b.len().saturating_sub(12)).any(|i| { 87 b[i..i + 8].iter().all(u8::is_ascii_hexdigit) && b[i + 8] == b'-' && b[i + 9..i + 13].iter().all(u8::is_ascii_hexdigit) 88 }); 89 let domain = s.split(|c: char| !(c.is_ascii_alphanumeric() || c == '.' || c == '-')).any(|tok| { 90 let tok = tok.to_ascii_lowercase(); 91 ["com", "org", "net", "io", "ai", "dev", "co", "us"].iter().any(|tld| { 92 tok.strip_suffix(tld).and_then(|t| t.strip_suffix('.')).is_some_and(|host| host.chars().any(|c| c.is_ascii_alphabetic())) 93 }) 94 }); 95 uuid || domain 96 } 97 98 /// A published field, or None when it looks like an identifier (the whole 99 /// row is then dropped). Kept characters: letters, digits and ` .:_/&()+-`, 100 /// at most 48 of them, so no markup and no separators. 101 fn word(s: &str) -> Option { 102 if looks_private(s) { 103 return None; 104 } 105 Some(s.chars().filter(|c| c.is_ascii_alphanumeric() || " .:_/&()+-".contains(*c)).take(48).collect::().trim().to_string()) 106 } 107 108 pub fn parse_accounts(tsv: &str) -> Quota { 109 let mut q = Quota::default(); 110 for line in tsv.lines() { 111 let f: Vec<&str> = line.split('\t').collect(); 112 match f.as_slice() { 113 ["checked", t, ..] => q.checked_utc = parse_utc(t).map(fmt_utc), 114 ["limit", provider, n, plan, window, label, used, resets, state, ..] => { 115 let Some(provider) = PROVIDERS.iter().copied().find(|p| p == provider) else { continue }; 116 let (Ok(n), Ok(used)) = (n.trim().parse::(), used.trim().parse::()) else { continue }; 117 let window = match *window { 118 "5h" | "week" => window.to_string(), 119 _ => continue, 120 }; 121 let (Some(label), Some(plan)) = (word(label), word(plan)) else { continue }; 122 let limit = Limit { 123 window, 124 label, 125 used_pct: used.round().clamp(0.0, 100.0) as u32, 126 resets_utc: parse_utc(resets).map(fmt_utc).unwrap_or_default(), 127 exhausted: *state == "exhausted", 128 }; 129 match q.accounts.iter_mut().find(|a| a.provider == provider && a.n == n) { 130 Some(a) => a.limits.push(limit), 131 None => q.accounts.push(Account { provider, n, plan, limits: vec![limit] }), 132 } 133 } 134 _ => {} 135 } 136 } 137 q.accounts.sort_by_key(|a| (PROVIDERS.iter().position(|p| *p == a.provider), a.n)); 138 for a in &mut q.accounts { 139 // Five-hour windows first, then the week; the publisher's order within each. 140 a.limits.sort_by_key(|l| l.window != "5h"); 141 } 142 q 143 } 144 145 pub fn parse_routing(tsv: &str) -> Routing { 146 let mut r = Routing::default(); 147 for line in tsv.lines() { 148 let f: Vec<&str> = line.split('\t').collect(); 149 let [kind, name, model, ..] = f.as_slice() else { continue }; 150 let (Some(name), Some(model)) = (word(name), word(model)) else { continue }; 151 if name.is_empty() || model.is_empty() { 152 continue; 153 } 154 let pair = (name, model); 155 match *kind { 156 "role" => r.roles.push(pair), 157 "agent" => r.agents.push(pair), 158 "seat" => r.seats.push(pair), 159 _ => {} 160 } 161 } 162 // Every advisor seat names its own model, which wins over the `advisor` 163 // role; showing the role then would name a model no reviewer uses. 164 if !r.seats.is_empty() { 165 r.roles.retain(|(name, _)| name != "advisor"); 166 } 167 r 168 } 169 170 /// Load from the laid-in files. Either may be absent; the page says so. 171 pub fn load() -> Dash { 172 Dash { 173 quota: fs::read_to_string(Path::new(ACCOUNTS_PATH)).map(|s| parse_accounts(&s)).unwrap_or_default(), 174 routing: fs::read_to_string(Path::new(ROUTING_PATH)).map(|s| parse_routing(&s)).unwrap_or_default(), 175 } 176 } 177 178 /// "2026-10-31T16:00Z" as "Oct 31 16:00". 179 fn short_utc(s: &str) -> String { 180 const MONTHS: [&str; 12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 181 let Some((date, time)) = s.trim_end_matches('Z').split_once('T') else { return s.to_string() }; 182 let mut d = date.split('-').skip(1); 183 match (d.next().and_then(|m| m.parse::().ok()), d.next()) { 184 (Some(m @ 1..=12), Some(day)) => format!("{} {} {}", MONTHS[m - 1], day.trim_start_matches('0'), time), 185 _ => s.to_string(), 186 } 187 } 188 189 fn limit_row(l: &Limit, provider: &str) -> Markup { 190 let left = 100 - l.used_pct; 191 // Inside the Anthropic card "Claude 5 Hour" says nothing "5 Hour" does not. 192 let label = if provider == "Anthropic" { l.label.strip_prefix("Claude ").unwrap_or(&l.label) } else { &l.label }; 193 html! { 194 div.dash-limit.dash-out[l.exhausted || left == 0] { 195 span class="dash-limit-k" { (label) } 196 meter class="dash-meter" min="0" max="100" low="30" high="70" optimum="100" value=(left) { (left) "% left" } 197 span class="dash-limit-v mono" { (left) "%" } 198 span class="dash-limit-r mono" { 199 @if !l.resets_utc.is_empty() { (short_utc(&l.resets_utc)) } 200 } 201 } 202 } 203 } 204 205 fn provider_card(provider: &str, accounts: &[&Account]) -> Markup { 206 html! { 207 article class="dash-card" { 208 h2 class="dash-h" { (provider) " " span class="dash-h-note" { "% left" } } 209 @for a in accounts { 210 div class="dash-acct" { 211 div class="dash-acct-h" { 212 "Account " (a.n) 213 @if !a.plan.is_empty() { span class="dash-plan" { (a.plan) } } 214 } 215 @for l in &a.limits { (limit_row(l, provider)) } 216 } 217 } 218 (foot_labelled(DASH_SOURCE, "Source on the forge", Target::Source)) 219 } 220 } 221 } 222 223 fn pairs(title: &str, rows: &[(String, String)]) -> Markup { 224 html! { 225 div class="dash-pairs" { 226 h3 class="dash-pairs-h" { (title) } 227 @if rows.is_empty() { 228 p class="dash-none" { "Not published." } 229 } @else { 230 dl { 231 @for (k, v) in rows { 232 dt { (k) } 233 dd class="mono" { (v) } 234 } 235 } 236 } 237 } 238 } 239 } 240 241 pub fn render_dash_page(d: &Dash, now: &Now) -> Markup { 242 let built = parse_utc(&now.built_utc); 243 let checked = d.quota.checked_utc.clone(); 244 let stale = built.zip(checked.as_deref().and_then(parse_utc)).is_some_and(|(b, c)| b - c > STALE_S); 245 let open = now.items.iter().filter(|i| i.status == "open").count(); 246 let for_drake = now.items.iter().filter(|i| i.status == "open" && i.owner_kind == "operator").count(); 247 let settled_day = now 248 .items 249 .iter() 250 .filter(|i| (i.status == "done" || i.status == "dropped") && (0..86_400).contains(&i.age_s)) 251 .count(); 252 let answering: Vec<&str> = now.models.iter().filter(|m| m.state == "answering").map(|m| m.name.as_str()).collect(); 253 let pulse = |k: &str| now.pulse.iter().find(|p| p.key == k).map(|p| p.value.clone()); 254 html! { 255 article class="dash container" { 256 header class="dash-top" { 257 h1 class="dash-title" { "Dashboard" } 258 p class="dash-meta mono" { 259 "quota read " (checked.as_deref().map(short_utc).unwrap_or_else(|| "never".into())) 260 " · built " (short_utc(&now.built_utc)) " UTC" 261 } 262 } 263 @if stale { 264 p class="dash-warn" { "This is the last quota reading the Spark published; nothing newer has arrived since." } 265 } 266 div class="dash-flow" { 267 @if d.quota.accounts.is_empty() { 268 article class="dash-card" { 269 h2 class="dash-h" { "Quota" } 270 p class="dash-none" { "No quota reading has been published yet." } 271 (foot_labelled(DASH_SOURCE, "Source on the forge", Target::Source)) 272 } 273 } 274 @for p in PROVIDERS { 275 @let accts: Vec<&Account> = d.quota.accounts.iter().filter(|a| a.provider == p).collect(); 276 @if !accts.is_empty() { (provider_card(p, &accts)) } 277 } 278 article class="dash-card" { 279 h2 class="dash-h" { "Spark" } 280 dl class="dash-kv" { 281 dt { "Serving" } dd { @if answering.is_empty() { "nothing answered" } @else { (answering.join(", ")) } } 282 @for k in ["memory free", "disk free", "wall power"] { 283 @if let Some(v) = pulse(k) { dt { (k) } dd { (v) } } 284 } 285 } 286 (foot_labelled(PULSE_URL, "Pulse on the forge", Target::Evidence)) 287 } 288 article class="dash-card" { 289 h2 class="dash-h" { a href="/now/" { "Work" } } 290 dl class="dash-kv" { 291 dt { "Open" } dd { (open) } 292 dt { "Waiting on Drake" } dd { (for_drake) } 293 dt { "Settled, last day" } dd { (settled_day) } 294 dt { "Ledger written" } dd { (short_utc(&now.ledger_written_utc)) } 295 } 296 (foot_labelled(LEDGER_URL, "Ledger on the forge", Target::Evidence)) 297 } 298 article class="dash-card" { 299 h2 class="dash-h" { "Which model does what" } 300 (pairs("Roles", &d.routing.roles)) 301 (pairs("Subagents", &d.routing.agents)) 302 (pairs("Advisor seats", &d.routing.seats)) 303 (foot_labelled(DASH_SOURCE, "Source on the forge", Target::Source)) 304 } 305 } 306 } 307 } 308 } 309 310 #[cfg(test)] 311 mod tests { 312 use super::*; 313 314 const ACCOUNTS: &str = "checked\t2026-10-26T12:32Z\n\ 315 limit\tOpenAI Codex\t2\tplus\tweek\t7 days\t0\t2026-11-02T12:21Z\tok\n\ 316 limit\tAnthropic\t2\t\tweek\tClaude 7 Day\t100\t2026-10-31T16:00Z\texhausted\n\ 317 limit\tAnthropic\t2\t\t5h\tClaude 5 Hour\t0.4\t\tok\n\ 318 limit\tAnthropic\t1\t\t5h\tClaude 5 Hour\t1\t2026-10-26T17:00Z\tok\n\ 319 limit\tOpenAI Codex\t1\tpro\tweek\t7 days\t250\t2026-11-02T12:28Z\tok\n\ 320 limit\tSomeone Else\t1\t\tweek\tx\t5\t\tok\n\ 321 limit\tAnthropic\t1\t\tmonth\tClaude Month\t5\t\tok\n\ 322 limit\tAnthropic\t1\t\tweek\tClaude 7 Day\tlots\t\tok\n"; 323 324 #[test] 325 fn accounts_group_in_provider_order_and_bound_their_numbers() { 326 let q = parse_accounts(ACCOUNTS); 327 assert_eq!(q.checked_utc.as_deref(), Some("2026-10-26T12:32Z")); 328 let order: Vec<(&str, u32)> = q.accounts.iter().map(|a| (a.provider, a.n)).collect(); 329 assert_eq!(order, [("Anthropic", 1), ("Anthropic", 2), ("OpenAI Codex", 1), ("OpenAI Codex", 2)]); 330 // An unknown provider, an unknown window and an unreadable percent are dropped. 331 assert_eq!(q.accounts[0].limits.len(), 1); 332 // The five-hour window comes first even when the publisher wrote it second. 333 let a2 = &q.accounts[1]; 334 assert_eq!(a2.limits.iter().map(|l| l.window.as_str()).collect::>(), ["5h", "week"]); 335 assert!(a2.limits[1].exhausted); 336 assert_eq!(a2.limits[1].used_pct, 100); 337 assert_eq!(q.accounts[2].limits[0].used_pct, 100, "percent is clamped"); 338 assert_eq!(q.accounts[3].plan, "plus"); 339 } 340 341 #[test] 342 fn rows_carrying_an_identifier_are_dropped_whole() { 343 let leaks = [ 344 "limit\tAnthropic\t1\tdrake@example.com\tweek\tClaude 7 Day\t5\t\tok", 345 "limit\tAnthropic\t2\t\tweek\tdhgmonkey94 at gmail.com\t5\t\tok", 346 "limit\txAI Grok\t1\t\tweek\tCredits `79011004`-5560-4db9\t5\t\tok", 347 "limit\tOpenAI Codex\t1\tpro\tweek\tdrakeexample.org\t5\t\tok", 348 ]; 349 for row in leaks { 350 assert!(parse_accounts(row).accounts.is_empty(), "kept: {row}"); 351 } 352 let q = parse_accounts("limit\tAnthropic\t1\t\tweek\t7 Day\t5\t\tok\n"); 353 assert_eq!(q.accounts[0].limits[0].label, "b7 Day/b", "markup characters are removed"); 354 let r = parse_routing("role\tdefault\tme@example.com/model\nrole\tsmol\topenai-codex/gpt-6.1-sol\n"); 355 assert_eq!(r.roles, [("smol".into(), "openai-codex/gpt-6.1-sol".into())], "model ids with dots survive"); 356 } 357 358 #[test] 359 fn routing_sorts_rows_by_kind_and_hides_an_advisor_role_the_seats_override() { 360 let r = parse_routing("role\tdefault\tanthropic/claude-opus-5-5\nrole\tadvisor\topenai-codex/gpt-6.1-sol\nagent\tscout\tdeepseek/deepseek-flash\nseat\tWitness\tdeepseek/deepseek-flash:max\nbogus\tx\ty\nrole\t\tz\n"); 361 assert_eq!(r.roles, [("default".into(), "anthropic/claude-opus-5-5".into())]); 362 assert_eq!(r.agents.len(), 1); 363 assert_eq!(r.seats[0].0, "Witness"); 364 let no_seats = parse_routing("role\tadvisor\topenai-codex/gpt-6.1-sol\n"); 365 assert_eq!(no_seats.roles.len(), 1, "with no seats the advisor role is the model in use"); 366 } 367 368 #[test] 369 fn short_times_read_as_month_day_and_clock() { 370 assert_eq!(short_utc("2026-10-31T16:00Z"), "Oct 31 16:00"); 371 assert_eq!(short_utc("2026-11-02T04:00Z"), "Nov 2 04:00"); 372 assert_eq!(short_utc("never"), "never"); 373 } 374 }