Skip to content

feat: add reset --json output and --credit card selection - #203

Merged
Loongphy merged 1 commit into
mainfrom
feat/reset-json-cli
Nov 13, 2026
Merged

Loongphy merged 1 commit into
mainfrom
feat/reset-json-cli

Conversation

@Loongphy

Copy link
Copy Markdown
Owner

Summary

codex-auth reset <selector> gains two flags:

  • --json: emits a machine-readable success document {schema_version, command: "reset", redeemed, outcome, remaining_credits, next_expires_at} where remaining_credits/next_expires_at describe the stored card list after the consume (already_redeemed counts as success). Failures reuse the shared JSON error envelope with codes account_not_found, ambiguous_query (with candidates), no_reset_credit, reset_credit_not_found, nothing_to_reset, reset_failed, registry_error, and usage.
  • --credit <id> (and --credit=<id>): redeems the available card whose id matches instead of the soonest-expiring one. Works in both text and JSON paths; an id naming no available card fails before any request.

The workflow splits into interactive and JSON handlers sharing card selection (selectCardIndex/nextCardIndex), preserving the UUID v4 redeem_request_id idempotency key, the account-scoped consume auth, and all existing text messages/error names. already_redeemed remains a success in both paths.

Test plan

  • zig build clean; zig fmt clean on changed files.
  • zig build test -Dtest-filter=reset: 17 parser tests + 13 integration tests pass, covering --json, both --credit forms, missing/duplicate values, unknown flags, the success document fields, --credit card selection shifting next_expires_at, and every new error code.
  • zig build test test-helpers: full suite passes.
  • ReleaseSafe e2e: zig build -Doptimize=ReleaseSafe test-helpers into an isolated prefix, then the reset integration tests and a manual run against a seeded mock CODEX_HOME + tests/fake_curl.zig backend — success docs, named-card consume (verified in requests.log), reset_credit_not_found, account_not_found, and JSON usage errors all confirmed; no real account data touched.
  • Local Greptile review: 1 P2 finding (--credit swallowing a following --json) fixed and re-reviewed clean (confidence 5, no comments).

codex-auth reset gains a --json contract mirroring switch/remove: a
success document with the redeemed account, outcome, remaining_credits,
and next_expires_at, plus JSON error documents (account_not_found,
ambiguous_query, no_reset_credit, reset_credit_not_found,
nothing_to_reset, reset_failed, registry_error, usage). --credit <id>
redeems a named available card instead of the soonest-expiring one, in
both text and JSON paths.
@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

Greptile CLI Reused the Greptile CLI review of b9694f6 by Loongphy. The code matches this PR, so no new review ran.

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

Adds --credit and --json to reset.

  • Reset can redeem a specific available credit card.
  • Reset can return its result as a machine-readable document.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["reset arguments"] --> B["Resolve one account"]
  B --> C["Collect available credits"]
  C --> D{"--credit supplied?"}
  D -->|Yes| E["Match credit ID"]
  D -->|No| F["Choose earliest expiry"]
  E --> G["Consume selected credit"]
  F --> G
  G --> H{"--json supplied?"}
  H -->|Yes| I["JSON result or error"]
  H -->|No| J["Human summary or error"]
Loading

Reviews (1) · Last reviewed commit: "feat: add reset --json output and --cred..." · Reviewed by Greptile

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

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

@loongphy/codex-auth-darwin-x64

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

@loongphy/codex-auth-linux-arm64

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

@loongphy/codex-auth-linux-x64

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

@loongphy/codex-auth-win32-arm64

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

@loongphy/codex-auth-win32-x64

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

@loongphy/codex-auth

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

commit: b9694f6

@Loongphy
Loongphy merged commit f7a6cdf into main Nov 13, 2026
13 checks passed
@Loongphy
Loongphy deleted the feat/reset-json-cli branch November 13, 2026 12:29
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