use std::path::Path;
use crate::session::{self, CurrentSession};
pub fn run(tool: &str, bytes: &str) -> i32 {
run_with_dir(tool, bytes, &session::sessions_dir())
}
pub fn run_with_dir(tool: &str, bytes: &str, sessions_dir: &Path) -> i32 {
let tokens = bytes.parse::<u64>().unwrap_or(0) / 4;
let mut current = match CurrentSession::load(sessions_dir) {
Some(s) => s,
None => return 0, };
current.total_tokens += tokens;
current.save(sessions_dir);
let event = format!(
"{{\"type\":\"tool\",\"tool\":\"{}\",\"tokens_est\":{},\"ts\":{}}}",
crate::json_util::escape_str(tool),
tokens,
session::unix_now(),
);
session::append_event(sessions_dir, ¤t.session_file, &event);
0
}