feat(usage_limits): add extra usage, per-model rendering, pace tracking, and sub-field renderers#152
Open
nh13 wants to merge 7 commits intostephenleo:mainfrom
Open
Conversation
Add five new optional format-string fields to UsageLimitsConfig: extra_usage_format, opus_format, sonnet_format, cowork_format, and oauth_apps_format. These allow users to customize the display of extra usage and per-model 7-day breakdown sections.
… and test dedup - Derive Default on UsageLimitsData to eliminate ~26 copy-paste struct constructions across tests (saves ~312 lines of None boilerplate) - Unify format_time_until + format_time_until_epoch into format_reset(epoch, now) - Extract resolve_epoch() for single-pass ISO→epoch resolution - Compute now_epoch() once in format_output, pass to calculate_pace + format_reset - Add sample_data() and now_secs() test helpers - Remove redundant section-divider comments and assert messages - Add doc comments to per-model format config fields - Fix lazy allocation pattern for default_fmt in per-model loop
Per-model format strings (opus_format, sonnet_format, etc.) now support
the {pace} placeholder, consistent with five_hour_format and
seven_day_format. Previously {pace} would leak through as a literal
string. Also removes redundant now_secs() test helper in favor of
the production now_epoch() function.
…ve indicator
- Extract resolve_data() to share data-fetch logic across renderers;
merge stdin 5h/7d (always freshest) with cache/OAuth per-model/extra
- Add negative cache marker (30s cooldown) to avoid hammering OAuth
on repeated failures
- Add sub-field renderers: per_model, opus, sonnet, cowork, oauth_apps,
extra_usage — each usable as an independent $cship.usage_limits.* token
- Add {active} placeholder in extra_usage_format: renders ⚡ when 5h or
7d is at 100% (actively consuming extra credits), 💤 otherwise
- Convert extra usage credits from cents to dollars in {used}/{limit}
- Extract format_single_model() and model_entries() helpers to reduce
duplication between format_output and individual model renderers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extra_usagefrom the OAuth API (enabled flag, monthly limit, used credits, utilization) and render it with a configurableextra_usage_format. Credits are converted from cents to dollars for{used}/{limit}placeholders.opus_format,sonnet_format, etc.){pace}placeholder in all format strings shows signed headroom vs linear consumption (e.g.+20%,-15%)$cship.usage_limits.opus,$cship.usage_limits.extra_usage, etc.) so users can compose their statusline layout freely — e.g. put per-model on a separate line from the main 5h/7d display{active}indicator: extra usage format supports an{active}placeholder — renders ⚡ when 5h or 7d is at 100% (actively consuming extra credits), 💤 otherwiserate_limitsalways provides the freshest 5h/7d values; cache/OAuth provides per-model and extra usage. The two are merged so the statusline shows both real-time utilization and the full breakdown.Related: #150 (sub-field renderers address independent formatting of composite sub-values for usage_limits)
Test plan
cargo fmt— passescargo clippy -- -D warnings— passescargo test— 346 unit + 66 integration tests pass (includes new tests for extra usage, per-model, pace, {active}, negative cache, hybrid resolve, and backwards-compat)cargo build --release— builds successfully