Skip to content

fix(kimi): resolve dynamic OAuth credential filename from config.toml - #1972

Open
2389400626lh-ops wants to merge 1 commit into
getagentseal:mainfrom
2389400626lh-ops:fix/kimi-dynamic-credential-path
Open

2389400626lh-ops wants to merge 1 commit into
getagentseal:mainfrom
2389400626lh-ops:fix/kimi-dynamic-credential-path

Conversation

@2389400626lh-ops

Copy link
Copy Markdown

Summary

Fixes #1950

Kimi Code CLI 2.8.1 (especially on Windows) writes its OAuth credential key to ~/.kimi-code/config.toml under [providers."managed:kimi-code".oauth] and stores the credential JSON at ~/.kimi-code/credentials/kimi-code-env-<environment-id>.json rather than the hardcoded kimi-code.json.

This change updates both the CLI (src/quota/kimi.ts) and Electron (app/electron/quota/kimi.ts) Kimi quota fetchers to:

  • Resolve KIMI_CODE_HOME dynamically at call time (falling back to ~/.kimi-code).
  • Parse [providers."managed:kimi-code".oauth].key from <kimiHome>/config.toml and validate the derived filename to reject path traversal, separators, or NUL bytes.
  • Fall back to legacy credentials/kimi-code.json and then discover credentials/kimi-code-env-*.json (preferring a fresh token over an expired one).
  • Continue reading all credential files through readSecureFile to preserve symlink, size, and POSIX permission checks, while keeping explicit credentialPath overrides backward compatible.

Testing

  • Added tests/quota-kimi.test.ts covering config.toml parsing, path traversal rejection, KIMI_CODE_HOME resolution on disk, kimi-code-env-*.json fallback (fresh vs expired), and legacy kimi-code.json.
  • Extended app/electron/quota/kimi.test.ts for dynamic OAuth credential resolution.
  • Verified locally on Windows (Node 24):
    • npx vitest run tests/quota-kimi.test.ts tests/quota-providers.test.ts app/electron/quota/kimi.test.ts (57/57 passed)
    • npx tsc --noEmit (passed)
    • npm run build:cli (passed)

This branch has not been deployed

No deployments
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.

Bug: Kimi Code quota detection fails on Windows due to hardcoded OAuth credential filename

1 participant