Skip to content

feat(kimi): support Kimi Code application via thin adapter - #467

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

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

Conversation

@bytemain

@bytemain bytemain commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Add Kimi Code to the existing additive provider workflow. The adapter manages native config.toml providers/models and mcp.json; the Kimi CLI continues to own OAuth. Provider switching uses the common provider flow instead of a separate profile snapshot mechanism, and native writes avoid recursive locking.

Imported providers retain native provider attributes and model metadata, including the distinction between a local alias and the actual upstream model ID. Cross-provider alias collisions and invalid model selections are rejected before writes. CLI/TUI edits preserve unrelated metadata while removing superseded connection credentials from saved provider data. Native config/MCP writes use private permissions, and malformed MCP files are not overwritten.

Database compatibility has an explicit boundary: no tables, columns, or schema version changes are added. Provider JSON and shared MCP/skill definitions use existing database synchronization. Kimi enable flags are reconstructed from local native files/directories and do not automatically transfer to another machine. Original upstream farion1231/cc-switch at 36d950411e622129f285635f43c17e5f35462413 is schema 19 while this CLI is schema 18; returning an upgraded database is rejected by the CLI. This pre-existing fork-wide gap remains and requires coordinated schema alignment. See docs/kimi-sync-compatibility.md; this PR does not claim end-to-end latest-original/WebDAV compatibility.

Validation on the follow-up: 16 Kimi-filtered unit tests covering native and SQL round trips, reload/disable persistence, alias isolation (including quoted native aliases), malformed native model rejection, private permissions, malformed MCP preservation, and native-only/no-op/explicit-clear form edits; 2 existing future-schema rejection tests. Tests used isolated directories. Independent review completed. Modified Rust files and whitespace checks pass. Full cargo fmt --check still reports 14 unchanged files from the previous PR head; this follow-up does not reformat them.

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 7 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>
set_current_provider and set_default_model acquired kimi_write_lock
and then invoked write_prepared_config, which re-acquired the same
non-reentrant mutex. Replace with direct write_file_atomic while holding
the lock, eliminating the self-deadlock.

Signed-off-by: Ferris <ferris@mail.build>
Signed-off-by: Ferris <ferris@mail.build>
- Remove redundant RFC 8628 OAuth device flow implementation and service layer
- Strip custom 'config kimi profile' directory snapshot mechanism and quota crawler
- Simplify kimi_config.rs to thin adapter managing config.toml and mcp.json
- Align with Pi/Hermes additive application model and preserve clean concurrency locks

Signed-off-by: Ferris <ferris@mail.build>
@bytemain bytemain changed the title feat(kimi): support Kimi Code OAuth authentication and configuration profile switching feat(kimi): support Kimi Code application via thin adapter Sep 24, 2026
@bytemain

Copy link
Copy Markdown
Contributor Author

Hi @SaladDay, just following up on this PR!

We recently refactored and streamlined the implementation into a clean, minimal thin adapter (commit 8e623fa). It now focuses purely on:

  • Managing Moonshot Kimi Code providers, models, and default model in ~/.kimi-code/config.toml
  • Managing MCP servers in ~/.kimi-code/mcp.json
  • Aligning cleanly with the existing application architecture (similar to Pi and Hermes) without any extra custom OAuth or crawler layers
  • Comprehensive unit tests covering provider CRUD, model switching, and MCP integration

The branch is fully up to date with main, has no conflicts, and all tests pass cleanly. Whenever you have some time, could you please take a look and consider merging? Please let us know if any adjustments are needed. Thank you!

@SaladDay

Copy link
Copy Markdown
Owner

I'd like to know if implementing it through your solution can maintain consistency with the upstream cc-switch database, because we have synchronization requirements.

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