Skip to content

Add /quota balance card, optional quota statusline segment, and /model default #293

Open

Description

@rakxdev

Summary

Proposal to add three related pieces to the TUI, all aimed at Start Plan and Coding Plan accounts used on headless servers:

  1. A /quota slash command that opens a balance card for the signed-in account.
  2. An optional ui.quotaStatusline setting that adds a quota <percent>% segment to the compact statusline (default off).
  3. A /model default shortcut 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:env with key fingerprint verification, legacy enc:v1 candidates, plaintext passthrough; keyring-protected records stay null), the shared OAuth session via the existing readStartPlanSession hook, a billing/balance client with the desktop billing-plane header set (X-Device-Mid from the isolated telemetry state, UA/version/platform/channel/locale/timezone/OS, per-call x-request-id), and a pure parser for plans[] and per-model balance slots.
  • QuotaView: card rendered inside the standard choice dialog; bars clamp 8-40 chars (context-status-view formula); 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 (visibleWidth asserted in tests).
  • Statusline: quota <percent>% field behind ui.quotaStatusline (default off), refreshed every five minutes with an unref'd timer, shows the lowest remaining slot.
  • /model default: opens the existing showModelProviderSettings() picker, so setDefaultModel (already injected by sync-runtime and backed by saveConfiguredDefault) 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 default persists defaultModelSelection to provider_config.json and applies it to the running session.

Questions

  • Naming: /quota vs /usage vs /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

  1. kingsword09 commented on Nov 24, 2026

    @kingsword09
    Owner

    Could you try the current CI-passing preview and check whether /quota works for you?

    npx --yes https://pkg.pr.new/zcode-app-cli@0fb8f12

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions