agent ctx-badge: seed Bus::last_usage from latest turn_stats row on startup

This commit is contained in:
müde 2026-05-18 18:00:48 +02:00
parent 8a3e8bfb7f
commit f827187341
4 changed files with 47 additions and 0 deletions

View file

@ -378,6 +378,15 @@ impl Bus {
self.emit(LiveEvent::ModelChanged { model: value });
}
/// Seed `last_usage` at startup without emitting a SSE event.
/// Used by the bin entrypoints to backfill from the most recent
/// `turn_stats` row so the per-agent web UI's `ctx-badge` paints
/// real numbers on cold load instead of staying empty until the
/// next turn finishes.
pub fn seed_usage(&self, usage: TokenUsage) {
*self.last_usage.lock().unwrap() = Some(usage);
}
/// Record the latest token usage from a completed turn.
pub fn record_usage(&self, usage: TokenUsage) {
*self.last_usage.lock().unwrap() = Some(usage);