feat(quota): show Codex limit resets in the Plan tab, hover card and CLI

The Plan tab row #724 added showed a count and an expiry. It now also shows how
many of those credits can be applied right now and when the most recent one
landed, which is what a user deciding whether to push through or throttle back
actually needs. The same sentence appears in the agent-tab quota hover card and
in `codeburn quota`.

One formatter produces it, mirrored line for line in Swift and TypeScript, down
to the compact-age rules — deliberately not RelativeDateTimeFormatter or
Intl.RelativeTimeFormat, because the two surfaces have to print the same
characters, and a locale-aware formatter would not. `codeburn quota` grows a
`notes` channel for provider facts that are not a window; only Codex sets it, so
every other provider's output is byte-identical to before.

The CLI reads the credits off the `rate_limit_reset_credits` block of the usage
response it already fetches and never calls the companion endpoint, so it prints
the count without the grant and expiry captions that only the per-credit list
carries.

Refs #725. No new polling loop and no new data source: this reads fields from a
response already fetched on the existing cadence.
This commit is contained in:
ozymandiashh 2026-09-12 23:31:31 +03:00 • committed by iamtoruk
parent 79d1482951
commit 6be422ac52
7 changed files with 317 additions and 16 deletions

View file

@ -151,10 +151,28 @@ Composite tiers (`enterprise_cbp_usage_based`, `self_serve_business_usage_based`
### Reset credits
`rate_limit_reset_credits` is carried inline on the usage payload
(`available_count`). The dedicated `GET /wham/rate-limit-reset-credits`
endpoint is only called when the inline block is absent. It is the sole source
of per-credit `expires_at` values, so the "next expires" caption is omitted on
the inline path.
(`available_count`, and sometimes `applicable_available_count` — how many can be
applied right now). The dedicated `GET /wham/rate-limit-reset-credits` endpoint
is only called when the inline block is absent or non-zero. It is the sole
source of the per-credit list — `id`, `reset_type`, `status`, `granted_at`,
`expires_at` — so the "next expires" caption and the "latest grant" caption are
both omitted on the inline path.
**Banked resets.** OpenAI sometimes grants an account an extra reset out of
band. A credit whose identity (`id`, else its raw `granted_at`) has not been
seen before is a new grant, and the menubar notifies once per credit. The seen
set lives in `codex-banked-resets.json` in the CodeBurn cache directory, written
the same way `subscription-snapshots.json` is. Rules that matter: the first
observation is a baseline, a disappearing credit was spent and is not an event,
and an absent or malformed credits payload is *no opinion* — never an empty
account — so a failed fetch cannot cause a re-announcement on reconnect. The CLI
reads the same inventory from the inline block only; it never calls the
companion endpoint.
Nothing in the payload distinguishes a granted-but-not-yet-usable credit from a
usable one: there is no `available_at`, no pending status, and `granted_at` has
only ever been observed in the past. The earliest warning CodeBurn can give from
this source is therefore "it just landed", not "it lands at 5pm".
## When fixing a bug here