Commit ef35af8
authored
refactor(rc-7): split AccountManager into state/persistence/rotation/recovery services (#122)
Splits the 40+-method god-class in lib/accounts.ts into four cohesive domain services per RC-7:
- lib/accounts/state.ts: AccountState owns the mutable account registry, per-family cursors + active indices, toast debounce, and auth-failure counters. Provides the narrow surface (initializeFromStorage, getAccountsSnapshot, removeAccount, isAccountCoolingDown, etc.) that the other services mutate through.
- lib/accounts/persistence.ts: AccountPersistence owns debounced disk saves, pendingSave coalescing, and the one-shot shutdown-flush registration. Lifecycle semantics from PR #110 preserved exactly.
- lib/accounts/rotation.ts: AccountRotation owns selection (round-robin + hybrid), health/token-bucket wiring, rate-limit and cooldown bookkeeping, and getMinWaitTime.
- lib/accounts/recovery.ts: AccountRecovery owns the per-refresh-token auth-failure ledger (serialized promise chain from PR #108), Codex CLI cross-process hydration, and merge-safe removal of all accounts sharing a refresh token.
lib/accounts.ts becomes a slim orchestrator (308 lines, down from 1129) that composes the four services and preserves the public API by delegation. Every method that previously existed on AccountManager is still callable with the same signature and behavior; no test edits were required.
Line counts after split: accounts.ts 308, state.ts 432, persistence.ts 149, rotation.ts 266, recovery.ts 239. Rate-limits sibling module untouched.
Verification: npm run typecheck, npm run lint, npm test (2121/2121 pass), npm run build all succeed.
Audit refs: docs/audits/07-refactoring-plan.md#rc-7, docs/audits/16-code-health.md, docs/audits/13-phased-roadmap.md1 parent 6c1598b commit ef35af8
5 files changed
Lines changed: 1405 additions & 949 deletions
0 commit comments