v2 Phase 4: Session screen — today's tokens and equivalent cost
Daemon: compute_today_usage() sums today's Claude Code token usage across the local project transcripts (~/.claude/projects/**/*.jsonl), reading only files modified today so the scan stays cheap, and prices it with Anthropic list rates to show the equivalent API cost (the ccusage-style flex for subscription users). The compact fields tk (total tokens), tc (cost in cents) and tn (message count) piggyback onto the existing 60s BLE payload. Firmware: UsageData gains tokens_today (64-bit) / cost_cents_today / messages_today; parse_json reads tk/tc/tn; a new Session screen shows the cost as the hero with total tokens and message count below, refreshed from ui_update so it's current whenever opened. Wire SCREEN_SESSION to the real screen (was a stub). Verified end to end: daemon sends e.g. tk=105374109 tc=26838 tn=663. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -112,6 +112,9 @@ static bool parse_json(const char* json, UsageData* out) {
|
||||
out->weekly_reset_mins = doc["wr"] | -1;
|
||||
strlcpy(out->status, doc["st"] | "unknown", sizeof(out->status));
|
||||
out->ok = doc["ok"] | false;
|
||||
out->tokens_today = doc["tk"] | (long long)0;
|
||||
out->cost_cents_today = doc["tc"] | 0;
|
||||
out->messages_today = doc["tn"] | 0;
|
||||
out->valid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user