Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): keep Vibe session totals and read all Kimi plan rows

leepokai3e2ae3a7baf7
diff --git a/host/src/usage/kimi.rs b/host/src/usage/kimi.rs
index 83373159..e1d9dc5e 100644
--- a/host/src/usage/kimi.rs
+++ b/host/src/usage/kimi.rs
@@ -10,6 +10,8 @@ use std::time::{Duration, Instant};
use super::Window;
const WAIT: Duration = Duration::from_secs(20);
+/// How long the screen stays unchanged after the first plan row before it is read.
+const SETTLE: Duration = Duration::from_millis(600);
pub(super) fn collect() -> Option<Vec<Window>> {
let bin = super::command::program("kimi")?;
@@ -64,9 +66,11 @@ fn capture(bin: &Path, dir: &Path) -> Option<String> {
let mut typed = 0_u8;
let mut trusted = false;
let mut answered = false;
+ let mut changed = Instant::now();
while started.elapsed() < WAIT {
while let Ok(chunk) = rx.try_recv() {
raw.extend_from_slice(&chunk);
+ changed = Instant::now();
}
if !answered && raw.windows(b"\x1b[6n".len()).any(|window| window == b"\x1b[6n") {
let _ = writer.write_all(b"\x1b[2;1R");
@@ -90,7 +94,8 @@ fn capture(bin: &Path, dir: &Path) -> Option<String> {
let _ = writer.flush();
typed = 2;
}
- if typed > 0 && done(&screen) {
+ // The plan rows can come over several writes: stop once the screen has stayed still a moment.
+ if typed > 0 && done(&screen) && changed.elapsed() >= SETTLE {
break;
}
std::thread::sleep(Duration::from_millis(100));
diff --git a/host/src/usage/vibe.rs b/host/src/usage/vibe.rs
index fc8272c1..ba2401a7 100644
--- a/host/src/usage/vibe.rs
+++ b/host/src/usage/vibe.rs
@@ -80,8 +80,9 @@ fn dated_usage(path: &Path, start: i64, end: i64) -> Option<(f64, f64)> {
}
let Ok(value) = serde_json::from_str::<Value>(line) else { continue };
let Some(record) = usage_record(&value) else { continue };
- saw = true;
+ // An undated line can't be placed in a day: it leaves the session total to `meta.json`.
let Some(at) = record.at else { continue };
+ saw = true;
if !(start..=end).contains(&at) {
continue;
}
@@ -242,6 +243,25 @@ mod tests {
assert_eq!(windows[1].text.as_deref(), Some("$0.25"));
}
+ #[test]
+ fn undated_usage_lines_leave_the_session_total() {
+ let now = chrono::Utc::now().timestamp_millis();
+ let start = local_midnight(now).unwrap();
+ let root = std::env::temp_dir().join(format!("codync-vibe-undated-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&root);
+ let dir = root
+ .join(chrono::DateTime::from_timestamp_millis(now).unwrap().format("session_%Y%m%d_%H%M%S").to_string());
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join("meta.json"), r#"{"stats":{"session_total_llm_tokens":40,"session_cost":2}}"#).unwrap();
+ std::fs::write(dir.join("messages.jsonl"), "{\"prompt_tokens\":10,\"completion_tokens\":5,\"cost\":0.25}\n")
+ .unwrap();
+ let windows = windows_in(&root, start, now);
+ let _ = std::fs::remove_dir_all(&root);
+ assert_eq!(windows[0].label, "Tokens · started today");
+ assert_eq!(windows[0].text.as_deref(), Some("40 tokens"));
+ assert_eq!(windows[1].text.as_deref(), Some("$2.00"));
+ }
+
#[test]
fn a_stamp_only_session_from_yesterday_adds_nothing() {
let now = chrono::NaiveDate::from_ymd_opt(2026, 10, 25)