Skip to content

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
nh13:nh13/feat-usage-limits-extra-and-per-model
Open

feat(usage_limits): add extra usage, per-model rendering, pace tracking, and sub-field renderers#152
nh13 wants to merge 7 commits intostephenleo:mainfrom
nh13:nh13/feat-usage-limits-extra-and-per-model

Conversation

@nh13
Copy link
Copy Markdown

@nh13 nh13 commented Apr 10, 2026

Summary

  • Extra usage rendering: parse extra_usage from the OAuth API (enabled flag, monthly limit, used credits, utilization) and render it with a configurable extra_usage_format. Credits are converted from cents to dollars for {used}/{limit} placeholders.
  • Per-model 7-day breakdowns: parse and render per-model utilization (opus, sonnet, cowork, oauth_apps) with configurable format strings (opus_format, sonnet_format, etc.)
  • Pace tracking: {pace} placeholder in all format strings shows signed headroom vs linear consumption (e.g. +20%, -15%)
  • Sub-field renderers: each section is available as an independent token ($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), 💤 otherwise
  • Hybrid data resolution: stdin rate_limits always 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.
  • Negative cache: 30-second cooldown marker after OAuth failures prevents hammering the API on repeated render cycles

Related: #150 (sub-field renderers address independent formatting of composite sub-values for usage_limits)

I don't want to overwhelm with a large PR — I just found these useful for my own workflow and thought others might benefit too. Happy to split this up or adjust the approach if you'd prefer something different.

Test plan

  • cargo fmt — passes
  • cargo clippy -- -D warnings — passes
  • cargo 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

nh13 added 7 commits April 10, 2026 13:01
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant