From 7093e58fe455ec00a6cab7b76fdf995ace30b954 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 29 Jan 2026 13:34:38 -0800 Subject: [PATCH] fix: capture accurate usage (#80) ### Explanation _No response_ ### Issue _No response_ ### Attestations - [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [ ] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Reviewed-on: https://git.nhcarrigan.com/nhcarrigan/hikari-desktop/pulls/80 Co-authored-by: Naomi Carrigan Co-committed-by: Naomi Carrigan --- src-tauri/src/wsl_bridge.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/wsl_bridge.rs b/src-tauri/src/wsl_bridge.rs index b1e8f31..75292f2 100644 --- a/src-tauri/src/wsl_bridge.rs +++ b/src-tauri/src/wsl_bridge.rs @@ -704,7 +704,7 @@ fn process_json_line( subtype, result, permission_denials, - usage: _, + usage, .. } => { let state = if subtype == "success" { @@ -713,6 +713,21 @@ fn process_json_line( CharacterState::Error }; + // Track token usage from Result messages if available + // This captures tokens from tool outputs and other operations + if let Some(usage_info) = usage { + // We need the model info to calculate cost properly + // For now, use the last known model from stats + let model = { + let stats_guard = stats.read(); + stats_guard.model.clone().unwrap_or_else(|| "claude-opus-4-20250514".to_string()) + }; + + let mut stats_guard = stats.write(); + stats_guard.add_usage(usage_info.input_tokens, usage_info.output_tokens, &model); + println!("Result message tokens - input: {}, output: {}", usage_info.input_tokens, usage_info.output_tokens); + } + // Always emit updated stats on result message (less frequent) // This includes the latest session duration let newly_unlocked = {