Skip to content

feat(kimi): support multiple web-auth accounts with custom labels - #2937

Open
jky1314 wants to merge 3 commits into
steipete:mainfrom
jky1314:feat/kimi-multi-account
Open

feat(kimi): support multiple web-auth accounts with custom labels#2937
jky1314 wants to merge 3 commits into
steipete:mainfrom
jky1314:feat/kimi-multi-account

Conversation

@jky1314

@jky1314 jky1314 commented Aug 14, 2026

Copy link
Copy Markdown

Summary

Enables Kimi's token-account system so users can add multiple web-auth (kimi-auth cookie) accounts and stack them in the menu bar, mirroring the existing Claude/MiniMax multi-account flow. Each account can carry a custom alias via ProviderTokenAccount.label. Monthly plan total (subscriptionBalance) is displayed; no token-cost computation is added for Kimi.

Changes

  • KimiProviderDescriptor: declare tokenAccountSupport with kimi-auth cookie header
  • KimiProviderImplementation:
    • sourceMode derives .web at fetch time while any saved token account exists — never persists an override, so removing the final account automatically falls back to the user's configured source
    • applyTokenAccountCookieSource only forces the cookie source to manual (per-account cookie headers); the usage source is left untouched
    • tokenAccountsVisibility keeps the multi-account editor visible before any account exists
  • KimiSettingsReader: expose KIMI_AUTH_TOKEN environment constant

Real behavior proof

Source-routing regression tests (fresh run):

✔ Test "active token accounts route Kimi refreshes through web without persisting source" with 3 test cases passed
✔ Test "adding account forces manual cookie source but preserves usage source" passed
✔ Suite KimiTokenAccountSourceRoutingTests passed

Covers: no accounts → configured source; account added → .web derived, persisted source untouched; final account removed → configured source restored.

Full suite: 88 Kimi tests + routing tests pass (122 tests total, 0 failures); release build + adhoc signing verified.

Notes

  • Accounts use the kimi-auth cookie value (JWT, ~1 year validity from the browser)
  • Follows the existing upstream multi-account architecture (Claude/MiniMax)
  • Usage source routing is derived from active accounts, preserving the user's stored preference (addresses review finding)

Register tokenAccountSupport for Kimi so multiple kimi-auth cookie
accounts can be added and stacked in the menu bar, mirroring the
Claude/MiniMax multi-account flow. Each account can carry a custom
alias via ProviderTokenAccount.label.

- KimiProviderDescriptor: declare tokenAccountSupport with kimi-auth cookie header
- KimiProviderImplementation: tokenAccountsVisibility + applyTokenAccountCookieSource
  (keeps the multi-account editor visible pre-account, forces web/manual cookie source)
- KimiSettingsReader: expose KIMI_AUTH_TOKEN constant

No token cost computation is added; Kimi shows subscription balance only.
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b22119331

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +59 to +60
if settings.kimiUsageDataSource == .api {
settings.kimiUsageDataSource = .web

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Force token accounts onto the web source from Auto

When Kimi is left at its default .auto source, adding or selecting an account does not change the source here. UsageStore.makeFetchContext uses that base source directly, so an existing API key or Kimi CLI credential causes the earlier API/CLI strategy to succeed for every account; the cards then show the shared API/CLI quota rather than each saved cookie's web quota. The descriptor's new selectedAccountSourceModeResolver only affects CLI commands, not app refreshes, so this method must also switch .auto to .web while token accounts are active.

Useful? React with 👍 / 👎.

Token accounts are cookie-based. When usage source is Auto, the fetch
plan may resolve to API/CLI (shared quota) instead of each saved
cookie's web quota. Switch any non-web source to .web while token
accounts are active, matching the descriptor's web pipeline.
@jky1314

jky1314 commented Aug 14, 2026

Copy link
Copy Markdown
Author

Addressed: applyTokenAccountCookieSource now switches any non-web source (including .auto) to .web while token accounts are active, so cards show each saved cookie's web quota instead of the shared API/CLI quota. Fixed in 1b64988.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 14, 2026, 4:02 PM ET / 20:02 UTC.

ClawSweeper review

What this changes

The PR adds labeled Kimi web-cookie accounts, displays each account separately, and derives web-quota refresh routing while those accounts are active.

Merge readiness

Blocked until real behavior proof from a real setup is added - 4 items remain

The prior source-persistence blocker is fixed in the latest branch commit, but this new Kimi authentication/storage feature still needs maintainer sign-off and real multi-account runtime proof before merge.

Priority: P2
Reviewed head: 6b44f3bc81b8725ac254e8da07a04ae5d866100f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The scoped patch and regression tests look solid, but real multi-account behavior proof remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body shows fresh routing-test and build output, but no redacted after-fix evidence from multiple real Kimi accounts producing distinct usage cards. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body shows fresh routing-test and build output, but no redacted after-fix evidence from multiple real Kimi accounts producing distinct usage cards. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Updated source-routing repair: The branch derives the web source when saved Kimi accounts exist and otherwise returns the persisted Kimi source, addressing the earlier persistence finding.
Shared token-account integration: The descriptor registers Kimi as a cookie-header token-account provider and selects web routing for an account in CLI contexts.
Account isolation path: The existing shared cookie resolver replaces the selected account’s header in the per-fetch settings snapshot, so account refreshes do not rely on a shared manual cookie.
Findings None None.
Security None None.

How this fits together

CodexBar’s provider layer turns stored provider credentials and source preferences into refresh contexts, then renders usage cards in the menu bar. This change adds Kimi to the shared token-account path so each saved Kimi cookie can fetch an account-specific web quota.

flowchart LR
    A[Saved Kimi accounts] --> B[Settings snapshot]
    C[Configured Kimi source] --> D[Source routing]
    B --> D
    D --> E[Kimi web quota fetch]
    E --> F[Account usage cards]
    F --> G[Menu bar display]
Loading

Decision needed

Question Recommendation
Should CodexBar adopt persisted, labeled Kimi web-cookie accounts as a supported authentication mode? Approve after live proof: Accept the Kimi account mode once the contributor provides redacted evidence of distinct real account cards and the maintainer accepts the credential-storage behavior.

Why: VISION.md requires sign-off for new features and behavior affecting provider authentication or data storage; tests alone cannot make that product and privacy decision.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body shows fresh routing-test and build output, but no redacted after-fix evidence from multiple real Kimi accounts producing distinct usage cards. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - This introduces persisted long-lived Kimi web credentials and changes source routing while saved accounts exist, so maintainer approval and a real account-isolation check are needed before landing.
  • Complete next step (P2) - A maintainer must decide whether to support persisted Kimi multi-cookie authentication; contributor-supplied live proof is also required before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Implementation and regression coverage production +54/-5, tests +69 across 4 files The implementation is focused on Kimi’s existing descriptor/settings path and adds dedicated routing regression coverage.

Merge-risk options

Maintainer options:

  1. Require a redacted live account check (recommended)
    Before merge, show two real Kimi cookies producing separate labeled cards and confirm final-account removal restores the configured usage-source behavior.
  2. Decline the stored-cookie mode
    Pause or close the PR if maintainers do not want Kimi browser credentials persisted as a multi-account feature.

Technical review

Best possible solution:

If approved, land the shared-pattern Kimi account integration with redacted evidence that two real cookies produce distinct labeled usage cards and that removing the final account restores the configured usage route.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a bug reproduction: this PR proposes a new capability. Its supplied evidence covers source-routing tests, but not a real two-account Kimi run.

Is this the best way to solve the issue?

Unclear: the implementation follows the established token-account architecture and fixes the earlier routing concern, but maintainer approval and live proof are still required for this authentication feature.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 726604057412.

Labels

Label justifications:

  • P2: This is a bounded provider-auth feature with limited current-user blast radius but requires normal maintainer review.
  • merge-risk: 🚨 compatibility: Saved Kimi accounts intentionally override the active fetch route, so source-preference behavior needs upgrade-safe proof.
  • merge-risk: 🚨 auth-provider: The PR adds persisted Kimi web-cookie credential handling and per-account environment/cookie injection.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body shows fresh routing-test and build output, but no redacted after-fix evidence from multiple real Kimi accounts producing distinct usage cards. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the Kimi implementation and descriptor baseline to this release-owned commit, and recent provider-architecture work also covers the affected pattern. (role: current Kimi feature owner; confidence: high; commits: 62b5b5efa936, 770ec06d2fc4; files: Sources/CodexBar/Providers/Kimi/KimiProviderImplementation.swift, Sources/CodexBarCore/Providers/Kimi/KimiProviderDescriptor.swift)
  • harjoth: Recent Kimi quota-duration history provides adjacent domain context for validating account-specific quota rendering. (role: recent adjacent Kimi contributor; confidence: medium; commits: 281a123a5601; files: Sources/CodexBarCore/Providers/Kimi/KimiProviderDescriptor.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add redacted live evidence showing two Kimi cookies yield distinct labeled usage cards and the expected quota data.
  • Obtain maintainer sign-off for the persisted Kimi web-cookie account mode.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-14T19:34:57.125Z sha 1b64988 :: needs real behavior proof before merge. :: [P1] Preserve the configured Kimi source when accounts are removed

…urce

Address Codex review P1: adding/removing a Kimi token account no longer
overwrites the persisted usage source.

- sourceMode returns .web while any saved Kimi token account exists
  (derived at fetch time), and falls back to the user's configured
  source once the final account is removed.
- applyTokenAccountCookieSource now only forces the cookie source to
  manual (required for per-account cookie headers); it no longer
  persists kimiUsageDataSource.
- New KimiTokenAccountSourceRoutingTests cover add/remove routing for
  auto/api/web sources and verify the persisted source is untouched.

88 Kimi tests + new routing tests pass.
@jky1314

jky1314 commented Aug 14, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review — P1 addressed: web routing is now derived from active token accounts at fetch time (), never persisted; removing the final account restores the user's configured source. Regression tests added (add/remove for auto/api/web). Real behavior proof added to PR body.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant