Skip to content

pick which accounts auto-rotation uses first - #32

Open
pedroapfilho wants to merge 1 commit into
RubricLab:mainfrom
pedroapfilho:account-order
Open

pedroapfilho wants to merge 1 commit into
RubricLab:mainfrom
pedroapfilho:account-order

Conversation

@pedroapfilho

Copy link
Copy Markdown
Contributor

Lets you choose which accounts auto-rotation uses first. Today it always switches to the account with the most room left, and there's no way to say "use my work account before my personal one".

Behavior

  • With an order set: when the active account crosses the threshold, tokenmaxx switches to the first account in your order that still has room. Room means healthy, with fresh usage, and under threshold − hysteresis. It no longer picks the emptiest account.
  • Moving back: when an earlier account in the order has room again (its window reset), tokenmaxx moves back to it once the cooldown has passed. This is a new rotation reason, automatic:preferred. The hysteresis gap means it only moves back once that account is well under the threshold, and the cooldown stops it switching back and forth.
  • Accounts left out go after the listed ones, sorted by label. An empty list clears the order.
  • No order set: behavior is exactly as today. Every existing selection test passes unchanged.
  • Unchanged: hard limits still ignore the cooldown, and spill accounts still hold through the threshold.

How you set it

tokenmaxx order claude work@acme.com personal@me.com   # these first, the rest after
tokenmaxx order claude                                  # print the current order
tokenmaxx order claude --reset                          # back to "most room"
  • Dashboard: [ and ] move the selected account in its provider's order. With an order set, account rows are listed in that order, and the panel title reads auto 90% · in order.
  • tokenmaxx list shows each account's place in the order.

Changes

  • domain.ts: Account gets an optional priority (integer, lower goes first). Existing stored accounts read fine without it.
  • selection.ts: candidates sort by order, then usage, then id, and there's a new preferred rotation for moving back. orderRank() is shared with the CLI and the dashboard.
  • manager.ts: new setAccountOrder(provider, accountIds). It re-evaluates auto-rotation right away, so a move back can happen immediately.
  • ipc.ts: new daemon method account/order, with requestAccountOrder.
  • cli.ts: the tokenmaxx order command, list shows order positions, and help text.
  • tui/dashboard.ts: row ordering, the [ / ] keys, and the in order marker.
  • README: a short section under Auto-rotation.

Tests

bun run check passes with 98 tests:

  • 7 new rotation tests: first account with room, skipping full ones, ordered before unordered, moving back, not moving back above the ceiling, the cooldown on moving back, and never moving later while below the threshold.
  • 3 tests for setAccountOrder: partial order, clearing, and rejecting an account from another provider.

I didn't run this against a live daemon or real accounts. The rotation paths are covered by unit tests only.

Notes

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