Skip to content

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

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

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

Conversation

@bytemain

@bytemain bytemain commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Streamlines Kimi Code (kimi-code) integration in cc-switch by adopting the additive application model (aligned with Pi and Hermes) and eliminating redundant complexity:

  1. Thin Adapter (kimi_config.rs):

    • Manages ~/.kimi-code/config.toml ([providers], [models], default_model) and ~/.kimi-code/mcp.json.
    • Supports additive provider switching, default model management, and MCP server synchronization.
    • Preserves atomic file writes (write_file_atomic) with safe permission handling and zero cross-test pollution.
  2. Deadlock Elimination:

    • Resolved recursive mutex lock acquisition where set_current_provider and set_default_model acquired kimi_write_lock() and re-entered write_prepared_config().
    • Directly executes atomic writes within the locked scope.
  3. Occam's Razor Simplification:

    • Stripped custom RFC 8628 Device OAuth flow (kimi_oauth_auth.rs, services/kimi_oauth.rs): Kimi CLI manages its own official authentication.
    • Removed isolated config kimi profile directory snapshot mechanism and quota crawler (config_kimi.rs): standardizes on cc-switch's universal provider switcher.
    • Net diff reduced from +3,914 lines across 67 files to a clean, maintainable ~1,400 line addition focused on core provider/MCP lifecycle.

Testing

  • Unit tests:
    • kimi_config::tests::test_kimi_provider_crud_and_mcp: full provider CRUD and MCP sync round-trip.
    • kimi_config::tests::test_kimi_set_default_model: default model selection and configuration serialization.
    • proxy::providers::claude::tests::kimi_anthropic_tool_history_injects_missing_thinking.
    • services::local_env_check::tests::local_tool_specs_include_all_supported_clis.
  • Full regression suite verified against services::provider, cli::tests, services::auth, and mcp.

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
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