feat(segments): usage-session and usage-weekly from the local accounts cache - #18
Conversation
…ounts cache Two opt-in segments show the percent of usage REMAINING for the account this pane is actually running as: usage-session (the ~5-hour session window) and usage-weekly (the weekly window, the binding limit). They resolve the pane's account uuid from oauthAccount.accountUuid in the live CLAUDE_CONFIG_DIR state file — the same per-process signal auth-profile/auth-email already use, so concurrent panes under different accounts each report their own — and read the on-disk usage cache the @hasna/accounts warmer maintains at <accountsHome>/cache/usage/<uuid>.json. The read is synchronous and local: no cloud API call, so the segments work inside a launched, registry-stripped session and cost nothing per render. Headroom is derived the way accounts derives it: scoped windows are ignored, a window past its reset reads as fully replenished rather than as a stale high utilization, and an unclassified non-scoped window can only lower weekly headroom. When the account is unknown, or the cache is missing, stale (>15m), corrupt, keyed to another account, or an error entry (e.g. a provider 429), the segments render a neutral marker (5h -- / 7d --) instead of a wrong number. usage-weekly escalates yellow->red as headroom runs low and shows green while healthy. Both default off. Live-tested against the real cache on station01: 5h 92% / 7d 61% for session utilization 8 / weekly 39, and the neutral marker on a rate-limited (429) entry. Agent: agent-ceo
|
[REVIEW] GO — #18 @ 5dc1351 — lens: cache-correctness/pane-identity/no-leak, reviewer fable-usage-cache (1 of 1) Re-anchored on head 5dc1351 (unchanged during review). Verified against the live
Evidence: 206/206 tests pass, |
Ship the usage-session and usage-weekly segments: bump patch and cut the CHANGELOG Unreleased section to 0.0.7. Agent: agent-ceo
What
Adds two opt-in statusline segments that show usage remaining for the account this pane is actually running as:
usage-session— the ~5-hour session (hourly) window, e.g.5h 87%usage-weekly— the weekly window (the binding limit), e.g.7d 92%Owner request 2026-08-07: show hourly (session) and weekly usage left for the pane's own account.
How it reads the cache without the cloud API
statusline runs inside a launched, registry-stripped session, so it must not call the accounts cloud API. Instead:
oauthAccount.accountUuidin the liveCLAUDE_CONFIG_DIRstate file — the same per-process signalauth-profile/auth-emailalready use (0.0.6 per-pane identity), so concurrent panes under different accounts each report their own account, never a global "current" pointer.@hasna/accountswarmer maintains at<accountsHome>/cache/usage/<uuid>.json(accountsHome=ACCOUNTS_HOMEor~/.hasna/accounts). The read is a synchronousreadFileSync— nofetch, no cloud call — so it is safe in a stripped session and free per render.Headroom is derived the way
@hasna/accountsderives it: scoped windows are ignored; a window past its reset reads as fully replenished (100%) rather than a stale high utilization; an unclassified non-scoped window can only lower weekly headroom.Graceful degradation — never a crash, never a wrong number
The segments render a neutral marker (
5h —/7d —, dimmed) whenever usage is unavailable:429, which the warmer writes with nousagefield — observed live).usage-weeklyescalates yellow→red as headroom runs low and shows green while healthy, so the binding limit reads at a glance.Both segments are off by default (like
five-hour-limit/seven-day-limit); enable withstatusline enable usage-session usage-weekly.Tests (TDD — failing tests written first)
test/accounts.test.ts:sessionAccountUuid(reads/rejects uuid) andsessionUsage(session+weekly headroom, zero-remaining, rollover→100, no cache, stale refused with a fresh positive control, corrupt, uuid mismatch, no-uuid, 429 error entry).test/segments.test.ts:usage-session/usage-weeklyrender numbers, render0%, neutral marker with no cache, and weekly colour escalation.Live test (real system, no cloud)
Built
dist/cli.js, rendered against the real cache for this pane's own account (account090):🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.