Skip to content

feat: add Kimi CLI (Moonshot AI) support#888

Open
he-yufeng wants to merge 5 commits intoslopus:mainfrom
he-yufeng:feat/kimi-cli-support
Open

feat: add Kimi CLI (Moonshot AI) support#888
he-yufeng wants to merge 5 commits intoslopus:mainfrom
he-yufeng:feat/kimi-cli-support

Conversation

@he-yufeng
Copy link

@he-yufeng he-yufeng commented Mar 19, 2026

Summary

Adds Kimi CLI (7k+ stars) from Moonshot AI as a first-class provider alongside Claude, Codex, and Gemini. This PR wires kimi through every layer of the system — authentication, daemon spawning, session tracking, mobile app modes, and terminal UI.

Changes by layer

CLI Authentication (commands/connect/)

  • happy connect kimi — interactive API key prompt with sk- prefix validation
  • Stores Moonshot API key in Happy cloud via registerVendorToken('moonshot', ...)
  • Saves API key locally to ~/.kimi/config.json (mirrors Gemini's local credential sync)
  • Shows kimi status in happy connect status
  • New authenticateKimi.ts + KimiAuthTokens type

CLI Entry Point (index.ts)

  • happy kimi subcommand → delegates to ACP runner with kimi-specific defaults
  • Fetches Moonshot API key from Happy cloud on startup (same pattern as Gemini OAuth)
  • Help text updated

Daemon (daemon/run.ts)

  • Agent type union extended with 'kimi'
  • Command switch, tmux agent resolution, and direct-spawn mode all handle kimi
  • MOONSHOT_API_KEY token passthrough for daemon-spawned sessions

Session & Profile System

  • BackendFlavor union includes 'kimi' (createSessionMetadata.ts)
  • resolveSessionFlavor() returns 'kimi' instead of generic 'acp' (runAcp.ts)
  • Profile compatibility schema + validateProfileForAgent support kimi (persistence.ts)
  • API vendor token types include 'moonshot' (api.ts)

Kimi Module Skeleton (kimi/)

  • constants.tsMOONSHOT_API_KEY_ENV, KIMI_MODEL_ENV, DEFAULT_KIMI_MODEL
  • types.tsKimiMode interface (permission mode + model)

Terminal UI (ui/ink/KimiDisplay.tsx)

  • 170-line ink component based on the Codex display pattern
  • Message buffer rendering, model label, Ctrl-C double-tap exit confirmation

Mobile App (happy-app/)

  • getKimiPermissionModes() — default + yolo
  • getKimiModelModes() — kimi-latest fallback
  • Wired into getHardcodedPermissionModes, getHardcodedModelModes, getAvailablePermissionModes, getDefaultModelKey

What's NOT in this PR

Full native agent integration (runKimi.ts with conversation history, reasoning processor, diff tracking) requires kimi-cli to support the ACP protocol (--experimental-acp). This PR establishes the complete framework that the native module will plug into.

Files changed (15 files, +428 lines)

Package File Change
happy-cli commands/connect.ts Add kimi vendor + local credential save
happy-cli commands/connect/authenticateKimi.ts New — API key prompt
happy-cli commands/connect/types.ts Add KimiAuthTokens
happy-cli index.ts Register happy kimi + cloud token fetch
happy-cli daemon/run.ts Agent type, command switch, token handling
happy-cli agent/acp/runAcp.ts Kimi session flavor
happy-cli api/api.ts Moonshot vendor token types
happy-cli persistence.ts Profile compatibility schema
happy-cli utils/createSessionMetadata.ts BackendFlavor union
happy-cli kimi/constants.ts New — env vars, defaults
happy-cli kimi/types.ts New — KimiMode interface
happy-cli ui/ink/KimiDisplay.tsx New — terminal UI component
happy-app components/modelModeOptions.ts Permission/model modes + defaults

Test plan

  • happy connect kimi → prompts for API key, stores in cloud + local
  • happy connect status → shows Moonshot Kimi connection status
  • happy kimi → attempts to launch kimi CLI via ACP
  • happy --help → lists kimi in available commands
  • Mobile app shows kimi permission/model mode pickers

he-yufeng and others added 5 commits March 19, 2026 20:53
…tracking

Adds initial integration for Kimi CLI (github.com/MoonshotAI/kimi-cli,
7k+ stars) so users can authenticate and run Kimi through Happy.

Changes:
- `happy connect kimi` — stores Moonshot API key in Happy cloud via
  the same vendor-token flow used by Codex/Claude/Gemini. Prompts for
  MOONSHOT_API_KEY (sk-...) and registers it under the 'moonshot'
  vendor key. Also shows in `happy connect status`.
- `happy kimi` command — registered in the CLI entry point, delegates
  to the generic ACP runner with kimi-specific defaults. Requires
  kimi-cli to be installed and in PATH.
- authenticateKimi.ts — interactive API key prompt with basic format
  validation (sk- prefix check).
- KimiAuthTokens type added to connect/types.ts.
- BackendFlavor union extended with 'kimi' for session metadata.
- Help text updated to list kimi alongside codex/gemini.

Full native kimi integration (dedicated runKimi module with ink UI,
conversation history, permission handling) is left for a follow-up
once the kimi-cli ACP protocol details are finalized.
Addresses gaps found in gap analysis — kimi was only registered in
the CLI entry point and connect command, but missing from several
internal subsystems:

- daemon/run.ts: add 'kimi' to agent type union, command switch,
  tmux agent resolution, and MOONSHOT_API_KEY token handling
- agent/acp/runAcp.ts: return 'kimi' flavor instead of generic 'acp'
  so sessions are properly tagged
- persistence.ts: add kimi to ProfileCompatibilitySchema and
  validateProfileForAgent so profiles can enable/disable kimi
- api/api.ts: add 'moonshot' to registerVendorToken/getVendorToken
  type signatures
- index.ts: fetch Moonshot API key from Happy cloud on startup
  (mirrors how Gemini fetches its OAuth token)
Fills in the remaining integration gaps so kimi is a proper
first-class provider rather than a thin ACP wrapper:

CLI package:
- kimi/constants.ts: MOONSHOT_API_KEY_ENV, KIMI_MODEL_ENV, defaults
- kimi/types.ts: KimiMode interface (permission + model)
- ui/ink/KimiDisplay.tsx: terminal UI component (based on Codex display
  pattern — message buffer, Ctrl-C double-tap exit, model label)
- connect.ts: save API key to ~/.kimi/config.json on `happy connect kimi`
  (mirrors Gemini's local credential sync)

Mobile app:
- modelModeOptions.ts: add getKimiPermissionModes (default + yolo),
  getKimiModelModes (kimi-latest fallback), wire into
  getHardcodedPermissionModes / getHardcodedModelModes /
  getAvailablePermissionModes / getDefaultModelKey
Replace made-up 'kimi-latest' with actual model IDs from
platform.moonshot.ai: kimi-k2.5 (default), kimi-k2-thinking,
and kimi-k2-thinking-turbo.
- kimi-cli uses 'kimi acp' subcommand, not --experimental-acp (that's Gemini)
- Fix comment: config.json is Happy's credential cache, not read by kimi-cli
@devibec
Copy link

devibec commented Mar 20, 2026

Why not use kimi through opencode?

@he-yufeng
Copy link
Author

Good question! kimi-cli is Moonshot AI's first-party CLI agent (like Claude Code is to Anthropic, or Gemini CLI is to Google). It has features specific to the Kimi ecosystem — 256K native context, Kimi-specific tool integrations, and the ACP protocol.

OpenCode is a great tool, but it's a third-party agent that connects to Kimi's API as one of many providers. Happy already has dedicated support for Claude Code, Codex, and Gemini CLI (all first-party tools), so adding kimi-cli follows the same pattern: native integration for each vendor's own agent.

Users who already use kimi-cli in their workflow would want to manage it from Happy, the same way Claude Code users do today.

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