feat: add previous account switch - #133
Conversation
@loongphy/codex-auth-darwin-arm64
@loongphy/codex-auth-darwin-x64
@loongphy/codex-auth-linux-arm64
@loongphy/codex-auth-linux-x64
@loongphy/codex-auth-win32-arm64
@loongphy/codex-auth-win32-x64
@loongphy/codex-auth
commit: |
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — all three changed code paths (explicit switch, auto-replacement after remove, drift correction) consistently use the correct setter variant, and the one-time normalisation rewrite for existing schema-4 files terminates correctly after the field is written. The centralisation of previous-account tracking in setActiveAccountKey is correct: same-account activations are a no-op for the previous field, drift-correction calls the Preserving variant so user-initiated history is never silently overwritten, and the removal path explicitly clears previous only when the removed account matches it. Memory ownership in handleSwitchPrevious is sound — the key is duped before activateAccountByKey frees the original through setActiveAccountKey. The schema normalisation trigger correctly distinguishes Zig null (key absent) from JSON null (key present-but-null), so subsequent loads do not re-trigger the rewrite. Test coverage is thorough, including the active==previous edge case after removal. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["CLI args parsed"] --> B{"opts.target"}
B -- ".query" --> C["handleSwitchQuery"]
B -- ".previous" --> D["handleSwitchPrevious"]
B -- ".picker" --> E["picker / live flow"]
D --> F{"previous_active_account_key?"}
F -- "null" --> G["error: no previous account"]
F -- "has key" --> H{"key in accounts list?"}
H -- "no" --> I["error: previous account unavailable"]
H -- "yes" --> J{"active == previous?"}
J -- "yes" --> G
J -- "no" --> K["activateAccountByKey -> setActiveAccountKey"]
K --> L["saveRegistry -> printSwitchedAccount"]
Reviews (3): Last reviewed commit: "fix: reject previous switch to active ac..." | Re-trigger Greptile |
Summary
codex-auth -andcodex-auth switch -.previous_active_account_keyin registry schema 4 and normalize schema 4 files missing it.Validation
HOME=/tmp/previous-account-switch zig build run -- listHOME=/tmp/previous-account-switch zig build testgit diff --checkRisks
previous_active_account_keywhile staying onschema_version = 4because this schema has not shipped yet.PR Loop Status