Skip to content

feat(runtime): support Start Plan through shared OAuth sessions - #251

Merged
kingsword09 merged 1 commit into
mainfrom
feat/start-plan-shared-session
Nov 1, 2026
Merged

kingsword09 merged 1 commit into
mainfrom
feat/start-plan-shared-session

Conversation

@kingsword09

@kingsword09 kingsword09 commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Enable the bundled account:zai-start-plan and account:bigmodel-start-plan providers in standalone CLI/TUI mode using the existing shared ZCode OAuth session. Signing in once can supply both Coding Plan and Start Plan requests; there is no separate Start Plan login.

The official runtime still constructs, signs and sends model requests. This change adds no dependencies and does not reimplement its transport or prompts.

Relationship to #248 / #249

This is a follow-up implementation of the feature investigated in #248 and proposed in #249. Thank you @Erencv for tracing the standalone catalog gates, identifying the required zcodejwttoken credential, and validating the upstream request path.

The feature direction and JWT selection agree with #249. This implementation adapts the account plumbing to the existing shared-OAuth reader:

  • Keep Start Plan separate from Coding Plan identity/auth-source records instead of aliasing identity keys. Desktop-only sessions therefore do not need a CLI Coding Plan identity.
  • Branch into Start Plan request authentication before Coding Plan project-token resolution. A Start Plan request never needs a project token that it would subsequently discard.
  • Fail explicitly for missing, malformed, expired or server-rejected JWTs; never substitute a Coding Plan key or silently fall back to paid-plan credentials.
  • Accept JWTs without an optional exp claim. A read-only local check found this shape in an actual OAuth session; synthetic regression fixtures cover it without committing real credentials. Present exp/nbf claims are still checked, and the server remains authoritative.

Refs #248 and #249; neither is automatically closed by this PR.

Implementation

  • Add src/start-plan.ts to read only the active OAuth family's profile and JWT, verify snapshot consistency, honor cancellation, and scope retries to the same provider/account/token.
  • Extend the standalone catalog with access-mode metadata while keeping login's unique Coding Plan provider selection unchanged.
  • Compute Start Plan account-provider availability from the shared session independently of Coding Plan credentials. Actual grants, model access and remaining quota remain server decisions.
  • Add the early Start Plan request branch and export its helpers through the existing runtime bridge.
  • Register an optional, atomic, idempotent runtime patch with exact-shape guards and postcondition checks; include it in runtime validation.
  • Document one-login behavior and the distinction between OAuth and manually supplied Coding Plan API keys in English and Chinese.

Compatibility / scope

  • Existing Coding Plan login, manual API keys, default-model persistence, custom providers and host-owned authentication remain unchanged.
  • An existing shared Desktop OAuth session can authorize Start Plan without a second CLI login.
  • A manually supplied Coding Plan API key is not itself a ZCode account session; Start Plan requires an OAuth/Desktop session.
  • This does not add a new browser sign-in or change the existing Coding Plan onboarding flow. It uses the session saved by the existing OAuth flow or Desktop.
  • Subsequent requests follow the active shared account. A retry cannot switch account or JWT mid-turn; an unchanged rejected JWT is not retried as a paid-plan key.
  • Local provider availability is not a claim that the account has an active Start Plan grant.

Validation

  • bun run typecheck
  • bun run sync:local against Desktop 3.17.1 / runtime 0.17.1
  • bun scripts/check-runtime.ts
  • bun run test:all: 74 unit + 15 TUI + 52 runtime + 17 Node tests (158 total)
  • Live Start Plan smoke test: the maintainer confirmed locally that Start Plan works with their account. This records the manual usage verification, not an independent audit of billing or quota deductions.

Tests cover patch drift/ambiguity/partial application, both account families, Desktop-only sessions, one OAuth login authorizing both plan types, stale manual identities, missing/expired/rejected/no-exp JWTs, account changes/logout, scope-safe retries and cancellation. Native-runtime tests use isolated credential stores and mock or disabled HTTP, not a real account's inference quota.

The first full-suite attempt hit a TUI terminal-exit startup timeout. Its isolated rerun (4 tests) and the complete suite rerun both passed; no TUI code was changed for that timeout.

Reuse the existing ZCode account session for standalone Start Plan providers without aliasing Coding Plan identities, exchanging project tokens, or falling back to paid credentials. Guard account changes, cancellation and rejected sessions, and support JWTs without optional expiry claims.

Follow up on #248 and #249; thanks to Erencv for investigating the standalone gates and identifying the ZCode JWT credential.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

pkg-pr-new preview for commit ff5a28be3d0876d7cd3c3d3123eded06ee15d3db.

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

Full repository URL

This preview uses the selected commit. PR updates publish automatically after CI succeeds; kingsword09 can also request a preview with /pkg-pr-new.

Workflow logs

@kingsword09
kingsword09 merged commit 934934a into main Nov 1, 2026
5 checks passed
@kingsword09
kingsword09 deleted the feat/start-plan-shared-session branch November 1, 2026 02:20
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