Skip to content

feat: list show reset credits#144

Merged
Loongphy merged 4 commits into
Loongphy:mainfrom
johnknott:reset-credits
Jul 2, 2026
Merged

feat: list show reset credits#144
Loongphy merged 4 commits into
Loongphy:mainfrom
johnknott:reset-credits

Conversation

@johnknott

@johnknott johnknott commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

This PR shows available ChatGPT reset credits in codex-auth list.

It adds a RESET CREDITS column backed by rate_limit_reset_credits.available_count.

Credit consumption remains handled by codex-cli's /usage.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a RESET CREDITS column to the list command output, parsing rate_limit_reset_credits.available_count from the ChatGPT usage API and surfacing the banked reset-credit count in the accounts table. It also adds width-adjustment logic for the new sixth column and updates parsing, equality, and clone functions for RateLimitSnapshot.

  • Adds reset_credits: ?i64 to RateLimitSnapshot with null default, wires it through parseUsageResponse, parseUsage (registry round-trip), and cloneRateLimitSnapshot/rateLimitSnapshotEqual.
  • Inserts a new RESET CREDITS column (index 2) in writeAccountsTableWithUsageOverrides, shifting the previous 5H/WEEKLY/LAST ACTIVITY indices up by one and adding the corresponding adjustListWidths reduction block.
  • Adds a test that a snapshot with only rate_limit_reset_credits (and no rate-limit windows) is preserved rather than discarded, and a table test verifying the column renders correctly.

Confidence Score: 5/5

Safe to merge — all changed paths are additive and self-contained, existing behaviour is unchanged for accounts without reset-credit data, and the new early-return guard in parseUsageResponse is covered by a dedicated test.

The change adds a new nullable field with a null default, so all existing stored snapshots deserialise cleanly without modification. The width-adjustment function now reduces all six columns, parsing round-trips correctly between the nested API format and the flat registry format, and two new test cases cover the most important edge cases.

No files require special attention.

Important Files Changed

Filename Overview
src/tui/table.zig Adds RESET CREDITS as widths[2]; shifts 5H/WEEKLY/LAST ACTIVITY to widths[3-5]; updates adjustListWidths with a new reduction block for each of the 6 columns.
src/api/usage.zig Adds parseResetCredits to extract available_count from the nested API object; guards the no-windows discard early-return to also pass through snapshots that carry only reset_credits.
src/registry/common.zig Adds reset_credits: ?i64 = null to RateLimitSnapshot, propagates it through cloneRateLimitSnapshot and rateLimitSnapshotEqual.
tests/api_usage_test.zig Adds two new tests covering reset_credits parsing and the early-return guard change.
tests/tui_table_test.zig Adds a table test for the new RESET CREDITS column and correctly updates the usage-override failure test expectation from >=2 to >=3.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant CLI as codex-auth list
    participant API as ChatGPT Usage API
    participant Parse as parseUsageResponse
    participant Snap as RateLimitSnapshot
    participant Table as writeAccountsTable

    CLI->>API: GET /usage
    API-->>Parse: "{ rate_limit_reset_credits: { available_count: N }, rate_limit: {...} }"
    Parse->>Parse: parseResetCredits(rate_limit_reset_credits)
    Parse->>Snap: "snapshot.reset_credits = N"
    Note over Snap: preserved even when primary/secondary windows are null
    Snap-->>CLI: stored in registry as reset_credits: N
    CLI->>Table: writeAccountsTableWithUsageOverrides(reg, ...)
    Table->>Table: resetCreditsCellAlloc(usage, override)
    Table-->>CLI: ACCOUNT  PLAN  RESET CREDITS  5H  WEEKLY  LAST ACTIVITY
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant CLI as codex-auth list
    participant API as ChatGPT Usage API
    participant Parse as parseUsageResponse
    participant Snap as RateLimitSnapshot
    participant Table as writeAccountsTable

    CLI->>API: GET /usage
    API-->>Parse: "{ rate_limit_reset_credits: { available_count: N }, rate_limit: {...} }"
    Parse->>Parse: parseResetCredits(rate_limit_reset_credits)
    Parse->>Snap: "snapshot.reset_credits = N"
    Note over Snap: preserved even when primary/secondary windows are null
    Snap-->>CLI: stored in registry as reset_credits: N
    CLI->>Table: writeAccountsTableWithUsageOverrides(reg, ...)
    Table->>Table: resetCreditsCellAlloc(usage, override)
    Table-->>CLI: ACCOUNT  PLAN  RESET CREDITS  5H  WEEKLY  LAST ACTIVITY
Loading

Reviews (2): Last reviewed commit: "docs: clarify reset credits list output" | Re-trigger Greptile

Comment thread src/workflows/preflight.zig Outdated
Comment thread src/cli/table_layout.zig Outdated
@Loongphy

Copy link
Copy Markdown
Owner

Thanks, this is useful. I think we should narrow the scope of this PR.

For now, I think we only need to surface the available count in list. I would not add it to other account-selection surfaces in this PR, and the column label should be RESET CREDITS.

I would prefer not to add the reset command to codex-auth. The official CLI/TUI can own the reset-consumption flow later, so I do not think we need to implement it here as well. There is already follow-up work on the Codex side: openai/codex#27915 (comment)

@johnknott

johnknott commented Jun 18, 2026 via email

Copy link
Copy Markdown
Contributor Author

@Loongphy

Copy link
Copy Markdown
Owner

Codex CLI supported reset credits: https://github.com/openai/codex/releases/tag/rust-v0.142.0

@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@463a95f

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@463a95f

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@463a95f

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@463a95f

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@463a95f

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@463a95f

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@463a95f

commit: 463a95f

@Loongphy Loongphy changed the title Show and consume rate limit reset credits feat: list show reset credits Jul 2, 2026
@Loongphy Loongphy merged commit 22d87d1 into Loongphy:main Jul 2, 2026
13 checks passed
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.

2 participants