Add one-shot automatic switch#148
Conversation
|
I need it to automate switching completely without always "knowing" the exact account which has still free limits left... Hope you'll be able to merge it. thanks |
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — the new auto-switch path is additive, well-tested, and the tiebreaker fix in the live picker is straightforward and verified by a new unit test. All changed code paths are exercised by new unit, behavior, and integration tests. The core activate/save/print pipeline is the same pattern already used by the query path. The tiebreaker fix in picker_auto.zig is a one-line correction from No files require special attention. The minor eligibility asymmetry between picker_auto.zig and account_ops.zig (unknown usage treated differently) is worth confirming is intentional but does not affect correctness. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[codex-auth switch --auto] --> B{Parse flags}
B -- "--auto + --live" --> E1[UsageError: cannot combine]
B -- "--auto + query/dash" --> E2[UsageError: does not support --auto]
B -- valid --> C{api_mode?}
C -- skip_api --> D1[loadStoredSwitchSelectionDisplay]
C -- default/force_api --> D2[loadSwitchSelectionDisplay foreground API refresh]
D1 --> F[selectAutoSwitchAccountIndexByLimitsWithUsageOverrides]
D2 --> F
F -- skip active account --> G{eligible accounts?}
G -- account has usage override/error --> H[skip]
G -- rem_5h == 0 or rem_week == 0 --> H
G -- both > 0 --> I[compare: earliest 5h reset tiebreak: longest weekly runway]
I --> J{any candidate found?}
J -- no --> E3[printNoAutoSwitchCandidateError error.NoAutoSwitchCandidate]
J -- yes --> K[activateAccountByKey]
K --> L[saveRegistry]
L --> M[printSwitchedAccount]
M --> N[exit 0]
%%{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"}}}%%
flowchart TD
A[codex-auth switch --auto] --> B{Parse flags}
B -- "--auto + --live" --> E1[UsageError: cannot combine]
B -- "--auto + query/dash" --> E2[UsageError: does not support --auto]
B -- valid --> C{api_mode?}
C -- skip_api --> D1[loadStoredSwitchSelectionDisplay]
C -- default/force_api --> D2[loadSwitchSelectionDisplay foreground API refresh]
D1 --> F[selectAutoSwitchAccountIndexByLimitsWithUsageOverrides]
D2 --> F
F -- skip active account --> G{eligible accounts?}
G -- account has usage override/error --> H[skip]
G -- rem_5h == 0 or rem_week == 0 --> H
G -- both > 0 --> I[compare: earliest 5h reset tiebreak: longest weekly runway]
I --> J{any candidate found?}
J -- no --> E3[printNoAutoSwitchCandidateError error.NoAutoSwitchCandidate]
J -- yes --> K[activateAccountByKey]
K --> L[saveRegistry]
L --> M[printSwitchedAccount]
M --> N[exit 0]
Reviews (2): Last reviewed commit: "fix(auto-switch): prefer longer weekly r..." | Re-trigger Greptile |
…test Address Greptile review on PR Loongphy#148: - Flip weekly-reset tiebreaker to prefer the later reset (more remaining weekly runway) in both account_ops and picker_auto selection paths. - Add unit test locking the tiebreaker direction and a shell-level integration test covering the full `switch --auto` activate/save/print path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closes #147
Adds codex-auth switch --auto for one-shot automatic switching.
Behavior:
Verification: