# Kimi CLI Provider ## Overview The Kimi CLI provider drives Moonshot AI's coding agent CLI. There are **two incompatible TUIs** in the wild under the same `kimi` command name, and CAO supports both from one provider: | | **Legacy** โ€” `kimi-cli` (MoonshotAI) | **Kimi Code** โ€” `agent-core-v2` | |---|---|---| | Prompt | `โœจ` / `๐Ÿ’ซ` emoji, inline | boxed composer (`โ•ญโ”€ โ”‚ > โ”‚ โ•ฐโ”€`) | | Response bullet | `โ€ข` (U+2022) | `โ—` (U+25CF, colour 253) | | Reasoning style | grey 244 + italic | grey 244 + italic | | Working indicator | bare moon phase (`๐ŸŒ•`) | braille (`โ ™ workingโ€ฆ`) | | Idle tip | โ€” | rotating `๐ŸŒ• ยท Tip: โ€ฆ` row | | Agent profile | YAML, `extend: default` | Markdown, `${base_prompt}` | | MCP config | `--mcp-config ''` | **no flag** โ€” user-level `mcp.json` only | | Unattended flag | `--yolo` (auto-approves all confirmations) | `--auto` (Never Ask) | | Working directory | per-worker temp dir (`cd`) | the terminal's real cwd | | Concurrency | one instance per directory (lock) | no per-directory lock | | Timeout config | mutates `~/.kimi/config.toml` | launch-scoped `KIMI_MCP_*_TIMEOUT_MS` | Dialect selection is capability-based: CAO never infers a dialect from a version number. The CODE path was validated end-to-end against Kimi Code **0.43.1**. Compatibility handling also covers Kimi Code **2.3**'s `โฏ` submission marker and renamed workspace-trust choices. The original local compatibility checks against **2.3.3** exercised workspace trust and multi-turn requests with text and tool output; synthetic regression fixtures cover completion and extraction edge cases. These checks do not establish full 2.3 provider E2E coverage. A Kimi Code 2.0.0 install was only checked for the same capability flags in `--help`, not full 2.0.0 TUI/E2E support. ## Prerequisites - **Kimi CLI**: legacy โ€” `brew install kimi-cli` or `uv tool install kimi-cli`. Kimi Code โ€” installs itself under `~/.kimi-code/bin/kimi`. - **Authentication**: legacy โ€” `kimi login`. Kimi Code โ€” `kimi login` (device-code flow). - **tmux 3.3+** Verify installation: ```bash kimi --version ``` ## Quick Start ```bash # Authenticate kimi login # Launch with CAO cao launch --agents code_supervisor --provider kimi_cli ``` The dialect is detected automatically; no configuration selects it. ## Native Swarm Mode Kimi Code profiles can set `kimiSwarm: true` to enter native swarm mode before the first task, or `kimiSwarm: false` to skip automatic activation. Omission inherits the operator's `CAO_KIMI_SWARM_DEFAULT` setting, which is off unless explicitly enabled. This is a mode setting: it does not add `AgentSwarm` or any other tool to a native `tools` allowlist. A read-only profile keeps its existing runtime tool restrictions. `kimiSwarmMaxConcurrency` accepts integers from 1 to 10. The operator's bounded runtime policy defaults to 10 concurrent subagents per `AgentSwarm` batch, not 10 total subagents over the session and not a shared budget across CAO workers. A smaller limit captured from the launch shell is preserved. Setting `kimiSwarm: false` does not bypass that resource policy; tool-triggered swarms remain capped when their tool is available. The native Kimi 2.1.1 retry scheduler did not enforce its environment concurrency limit after provider rate limits. Enabling this policy therefore requires an executable whose retry path has been fixed and tested. Set `CAO_KIMI_SWARM_CAP_SHA256` on the CAO server to that executable's SHA256, and set `CAO_KIMI_SWARM_DEFAULT=1` to enable startup swarm by default. CAO verifies the actual launch-shell-resolved executable before every managed native launch and refuses a replacement that does not match. An explicit profile limit also requires verification. Unconfigured default-off launches retain their prior behavior without claiming an enforced cap. CAO runs `/swarm on` as a startup control command and requires Kimi's native activation confirmation before delivering work. It does not count this command or its status bullet as an executed task. Legacy Kimi CLI behavior is unchanged. For completion attribution, CAO retains the current generation's raw transcript in an anonymous spool, using at most 64 KiB before spilling to temporary disk. It closes the spool on the next dispatch, buffer-generation reset, or terminal cleanup. This preserves quoted and private-output ownership after the rolling buffer is cropped. Final-answer verification may temporarily read the complete generation, so very large turns require disk and transient memory proportional to that turn's output. If recording fails, CAO discards cached completion evidence and requires a new generation before trusting a final-answer proof. An active live panel takes precedence over an older recorded completion. ## Dialect Detection The provider probes the resolved `kimi` binary's `--help` **once per binary identity** and classifies it from its capability flags: | Dialect | Capability flags (any one) | |---|---| | Legacy | `--mcp-config`, `--mcp-config-file` | | Kimi Code | `--auto`, `--agent-file`, `--output-format` | Rules that matter: - **Never a version string.** A version string is a claim; an option table is a fact. Kimi Code and `kimi-cli` share the `kimi` command name and have shipped under overlapping version numbers. - **Whole-token matching.** `--agent` must not match `--agent-file`. - **Fail closed.** An unrecognised option table yields `UNKNOWN`, and the provider refuses to launch rather than guessing. - **Successful probes only are cached**, keyed on `(absolute path, st_mtime_ns, st_size)`. An `UNKNOWN` verdict must not become sticky โ€” a transient PATH problem at boot would otherwise disable the provider for the life of the process. - The probe runs **in the launch shell's environment** and its absolute binary path is reused verbatim for `exec`. Probing one PATH while tmux launches another is the PR #664 bug class. - **Nothing dynamic is ever quoted for the pane shell.** Both the probe program and the launch line are POSIX text, and POSIX quoting is not fish quoting: `shlex.quote` renders an embedded apostrophe as `'\''`, which `fish` ends early when a backslash precedes it (`Unexpected end of string`, exit 127), and `\\` means one backslash in `fish` but two in POSIX `sh`. CAO therefore writes the POSIX text to a script in a scratch directory whose path is drawn from a shell-safe alphabet, and types only a fixed, quote-free invocation (`/bin/sh