Skip to content

feat(kimi): support Kimi Code OAuth authentication and configuration profile switching - #467

Open
bytemain wants to merge 9 commits into
SaladDay:mainfrom
bytemain:feat/kimi-oauth-config-switch
Open

bytemain wants to merge 9 commits into
SaladDay:mainfrom
bytemain:feat/kimi-oauth-config-switch

Conversation

@bytemain

Copy link
Copy Markdown

Summary

Adds support for Moonshot AI's Kimi Code (kimi-code) authentication and environment profile switching to cc-switch-cli:

  1. RFC 8628 Device Authorization Flow:

    • Endpoint: https://auth.kimi.com/api/oauth/device_authorization & https://auth.kimi.com/api/oauth/token
    • Client ID: 17e5f671-d194-4dfb-9706-5516cb48c098
    • User profile endpoint: https://api.kimi.com/coding/v1/me
    • Supports auto-refreshing expired tokens and syncing active account credentials directly into native ~/.kimi-code/credentials/kimi-code.json.
  2. Unified Multi-Provider CLI Auth:

    • Extended cc-switch auth commands with --provider <codex_oauth|kimi_oauth> (defaults to codex_oauth).
    • Supports status, list, login, default, remove, logout for both Codex and Kimi OAuth accounts.
  3. Kimi Code Configuration & Profile Switching:

    • New cc-switch config kimi command family:
      • path: print Kimi Code home directory (~/.kimi-code or overridden by KIMI_CODE_HOME).
      • status: inspect whether Kimi Code home, config, credentials, and active profile exist.
      • profile list: list saved environment profiles and active selection.
      • profile save <name>: snapshot config.toml, tui.toml, and credentials under profiles/<name>.
      • profile switch <name>: atomically switch active profile into ~/.kimi-code.
      • profile remove <name>: remove an existing profile snapshot.

Testing

  • Added unit tests in src/proxy/providers/kimi_oauth_auth.rs:
    • test_manager_initial_state
    • test_manager_save_and_load
    • test_set_default_account
    • test_remove_account_rehomes_default_account
  • Added unit tests in src/kimi_config.rs:
    • test_write_and_read_native_credentials
    • test_profile_save_and_switch
  • Added unit tests in src/services/auth.rs:
    • kimi_auth_status_marks_default_account
  • Added CLI parser tests in src/cli/mod.rs:
    • parses_auth_status_kimi_provider_subcommand
    • parses_config_kimi_path_and_profile_subcommands
  • All tests pass via cargo test kimi and cargo test auth::.

Signed-off-by: Ferris ferris@mail.build

…profile switching

- Implement RFC 8628 device flow for Moonshot AI Kimi Code (client id 17e5f671-d194-4dfb-9706-5516cb48c098)
- Add KimiOAuthManager and KimiOAuthService to manage accounts and sync to native ~/.kimi-code
- Extend AuthService and cc-switch auth commands with --provider kimi_oauth
- Add cc-switch config kimi profile management to snapshot and switch native Kimi Code profiles atomically

Signed-off-by: Ferris <ferris@mail.build>
@SaladDay

Copy link
Copy Markdown
Owner

Please give me some time to review, thank you for your contribution

…or authorization_pending

Signed-off-by: Ferris <ferris@mail.build>
…tatus

Signed-off-by: Ferris <ferris@mail.build>
…status

Signed-off-by: Ferris <ferris@mail.build>
…uota inspection

- Resolve and display account nicknames in Kimi profile lists and status views
- Add '-q/--quota' to 'config kimi profile list' for parallel 5-hour quota and reset countdown inspection across all profiles
- Support 'config kimi status <profile>' and 'config kimi status --all' for inspecting profile statuses without switching
- Automatically refresh expired access tokens when querying saved profile quotas

Signed-off-by: Ferris <ferris@mail.build>
@bytemain
bytemain force-pushed the feat/kimi-oauth-config-switch branch from aecabb4 to ca3a5f3 Compare September 17, 2026 15:57
bytemain and others added 4 commits September 18, 2026 00:04
- Prevent test runners from overwriting user's active native credentials
- Guard default account sync during test runs
- Provide safe isolated fallback path for get_kimi_config_dir during testing

Signed-off-by: Ferris <ferris@mail.build>
…tokens in quota list

Signed-off-by: Ferris <ferris@mail.build>
Signed-off-by: Ferris <ferris@mail.build>
- Add AppType::Kimi alongside Claude, Codex, Gemini, OpenCode, Hermes, OpenClaw, Pi
- Implement TOML provider, model, and MCP editing for ~/.kimi-code/config.toml
- Support additive provider management and model aliases for Kimi Code
- Wire AppType::Kimi across TUI, CLI commands, settings, and services
- Add comprehensive unit and integration tests for Kimi provider configuration

Signed-off-by: Ferris <ferris@mail.build>
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.

2 participants