Repository navigation
Description
Summary
Proposal to add three related pieces to the TUI, all aimed at Start Plan and Coding Plan accounts used on headless servers:
- A
/quotaslash command that opens a balance card for the signed-in account. - An optional
ui.quotaStatuslinesetting that adds aquota <percent>%segment to the compact statusline (default off). - A
/model defaultshortcut that opens the existing Default model picker, which is currently reachable only through/settings-> Model providers.
Motivation
Start Plan and Coding Plan accounts show plan balances in the desktop app, but the TUI has no equivalent view. On headless servers over SSH there is no desktop, so checking remaining tokens today means the web console or external tooling. The default-model picker has the same discoverability problem from the other side: /model switches the session model transiently and prints "saved defaults unchanged", while the picker that persists the shared default sits behind /settings -> Model providers. On a Start Plan account whose individual-coding-plan default has no balance, every new session starts with a 1113 until the model is switched by hand.
Implementation (working on a local branch)
src/quota.ts: read-only credential reader (enc:v2:envwith key fingerprint verification, legacyenc:v1candidates, plaintext passthrough; keyring-protected records stay null), the shared OAuth session via the existingreadStartPlanSessionhook, abilling/balanceclient with the desktop billing-plane header set (X-Device-Midfrom the isolated telemetry state, UA/version/platform/channel/locale/timezone/OS, per-callx-request-id), and a pure parser forplans[]and per-model balance slots.QuotaView: card rendered inside the standard choice dialog; bars clamp 8-40 chars (context-status-viewformula); slots-driven rows render whatever models the plan carries; theme tints (accent, warning below 20%, error when exhausted); width-safe from 1 to 200 columns (visibleWidthasserted in tests).- Statusline:
quota <percent>%field behindui.quotaStatusline(default off), refreshed every five minutes with an unref'd timer, shows the lowest remaining slot. /model default: opens the existingshowModelProviderSettings()picker, sosetDefaultModel(already injected by sync-runtime and backed bysaveConfiguredDefault) becomes discoverable from/model. The transient-switch notice now points at it.- Docs: README features and model-default paragraph,
setting.example.json, CONFIGURATION.md and the zh-CN variant.
Validation
bun run typecheck,bun run test:unit(158/158, 15 new tests),bun run check,bun run check:tui,bun run build- all green.- Verified against a live global z.ai Start Plan account over a real PTY: the card renders the WEEKEND BUILD balances, and
/model defaultpersistsdefaultModelSelectiontoprovider_config.jsonand applies it to the running session.
Questions
- Naming:
/quotavs/usagevs/balance? - Should the statusline segment stay opt-in (my default: off), or be on by default for OAuth sessions?
- Any objection to reading the shared session token from the credentials file in the launcher process (read-only, same file the runtime owns)?
Happy to adjust scope or split pieces. Ready to open the PR from my fork once the direction looks right.
Activity
kingsword09 commentedon Nov 24, 2026
Could you try the current CI-passing preview and check whether
/quotaworks for you?This preview is built from commit
0fb8f125. In the TUI, run/quota. If you already have a ZCode OAuth session, it should reuse the existing credentials, including credentials stored in the OS keychain, without asking you to sign in again.Please let us know whether the balance card loads and shows the expected plan balances. If it reports no balances or an error, that result is helpful too.