Add Kimi Code (MoonshotAI) as an ACP provider#4098
Conversation
Adds a sixth built-in provider driver ("kimi") for the Kimi Code CLI,
which speaks the Agent Client Protocol over stdio (`kimi acp`).
Server:
- KimiDriver / KimiProvider / KimiAdapter / KimiAcpSupport /
KimiTextGeneration, registered in builtInDrivers.
- Models are discovered Cursor-style from the ACP session's "model"
config option; an empty option list is Kimi's logged-out signal and
is surfaced as "run kimi login" from both the status probe and the
session/text-generation paths.
- T3 runtime modes map to Kimi's native mode config option
(full access -> yolo, supervised -> default, plan -> plan).
- Binary resolution falls back to the well-known ~/.kimi-code/bin
install path (the installer does not add it to PATH on Windows);
the resolved path is threaded through so spawns skip re-scanning.
- Version probe timeout is 15s: the CLI is a large single binary and
cold starts on Windows can far exceed its ~1s warm latency.
- Self-update wired to `kimi upgrade`.
- Extracted shared makeStandardAcpAdapter / makeStandardAcpTextGeneration
bases from the Cursor adapter and Grok text generation; both drivers
now delegate to them unchanged.
Contracts: KimiSettings (binaryPath + KIMI_CODE_HOME home isolation),
settings patch wiring, model defaults and display names.
Web: provider registration (settings form, model picker, icons with the
official Kimi mark, custom-model placeholders for kimi and grok), and
legacy composer provider arrays now include grok and kimi.
Verified live against kimi 0.26.0: pairing, model discovery (5 models),
and full agent turns with tool calls.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review follow-ups on the Kimi provider (behavior-preserving except the auth-message fix, which is the point): Fixes: - A logged-out Kimi (empty model option list) now fails session start and git text generation with the "run kimi login" message instead of an opaque client-side "expected one of <empty>" config-validation error. - resolveKimiBinaryPath's PATH scan result is threaded through the driver so adapter/text-gen/status-probe spawns skip re-scanning. - findKimiModelConfigOption matches by id only (like the generic write path); requiring the category tag could split-brain discovery vs writes. - Narrowed the Kimi mapError method tag to the single RPC it uses. - Added the missing kimi (and grok) custom-model input placeholders. Refactors (byte-identical behavior; extractions the review called for): - StandardAcpAdapter.ts: the provider-agnostic ACP adapter core, moved out of CursorAdapter.ts. Cursor's private extension protocol is now supplied through a generic registerExtensions hook instead of a Cursor-named boolean; Cursor and Kimi are thin wirings over the shared base. - StandardAcpTextGeneration.ts: the shared ACP text-generation core, moved out of GrokTextGeneration.ts; Grok and Kimi delegate to it. - providerStatusProbe.ts: the shared CLI status-probe + version-advisory scaffold, used by Kimi and Grok (Cursor's probe left as-is to avoid behavior risk). All per-provider message strings preserved exactly. - AcpModelSelection.ts: shared applyAcpModelSelectionIfChanged, used by the Grok and Kimi model-selection helpers. All 5 pre-existing Windows test failures (POSIX mock-binary spawns) are unchanged; typecheck and vp check are clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… path - Status probe no longer reports "run kimi login" when the ACP response carries no model config option at all (incompatible/malformed CLI); only an empty option list (the signed-out signal) maps to unauthenticated. Generalize the shared status-probe scaffold's discovery-result type so Kimi can carry the distinction; Grok is unchanged. - Provider maintenance (`kimi upgrade`) now runs an absolute executable path resolved with the instance environment, so upgrade no longer fails command-not-found when the CLI is only reachable via the instance PATH. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Effect service conventions: one finding — Effect.catchTag used to recover a single known tag. The check's conventions require Effect.catchTags even for a single tag.
Posted via Macroscope — Effect Service Conventions
Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
2026-07-17.20-55-27.mp4 |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
# Conflicts: # apps/server/src/provider/Layers/CursorAdapter.ts # apps/server/src/provider/Layers/GrokProvider.ts # apps/server/src/textGeneration/GrokTextGeneration.ts
There was a problem hiding this comment.
Pull request overview
Adds Kimi Code (MoonshotAI) as a new built-in provider driver (kimi) across contracts, server provider/runtime plumbing, and the web UI. The implementation reuses the existing ACP-over-stdio path and introduces shared ACP cores to reduce duplication across ACP-backed providers.
Changes:
- Introduces the Kimi provider end-to-end (settings schema, driver, adapter, provider status probing, and git text-generation).
- Refactors ACP-backed implementations onto shared foundations (
StandardAcpAdapter,StandardAcpTextGeneration,providerStatusProbe,AcpModelSelection). - Wires Kimi into the web UI (provider registration, icons, model placeholders, and model-selection behavior/tests).
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/contracts/src/settings.ts | Adds KimiSettings and wires it into ServerSettings + patch schema. |
| packages/contracts/src/settings.test.ts | Extends settings decoding test coverage for the new kimi provider defaults. |
| packages/contracts/src/model.ts | Adds Kimi defaults (model + git text generation model) and display name. |
| apps/web/src/session-logic.ts | Registers Kimi as an available provider option in the UI. |
| apps/web/src/modelSelection.test.ts | Ensures instance-scoped model selection includes Kimi custom models. |
| apps/web/src/lib/contextWindow.ts | Adds “Kimi Code” display formatting for provider context. |
| apps/web/src/composerDraftStore.ts | Extends legacy model-option normalization/migration to include grok + kimi. |
| apps/web/src/components/settings/ProviderModelsSection.tsx | Adds custom-model placeholders for Grok and Kimi. |
| apps/web/src/components/settings/providerDriverMeta.ts | Registers Kimi in the settings UI metadata (label/icon/schema). |
| apps/web/src/components/Icons.tsx | Adds the KimiIcon SVG. |
| apps/web/src/components/chat/providerIconUtils.ts | Maps kimi to KimiIcon for chat/provider rendering. |
| apps/server/src/textGeneration/TextGeneration.ts | Extends TextGenerationProvider union to include kimi. |
| apps/server/src/textGeneration/StandardAcpTextGeneration.ts | New shared ACP text-generation core used by ACP-backed providers. |
| apps/server/src/textGeneration/KimiTextGeneration.ts | Implements Kimi git text generation via StandardAcpTextGeneration. |
| apps/server/src/textGeneration/GrokTextGeneration.ts | Refactors Grok text generation to delegate to StandardAcpTextGeneration. |
| apps/server/src/provider/Services/KimiAdapter.ts | Adds the Kimi adapter shape contract (naming anchor). |
| apps/server/src/provider/providerStatusProbe.ts | Adds shared CLI status-probe scaffolding + advisory enrichment helper. |
| apps/server/src/provider/Layers/StandardAcpAdapter.ts | New shared ACP adapter core used by Cursor/Kimi (and future ACP providers). |
| apps/server/src/provider/Layers/ProviderRegistry.test.ts | Updates provider registry tests to include kimi. |
| apps/server/src/provider/Layers/ProviderInstanceRegistryLive.test.ts | Extends multi-driver registry test slice to include the Kimi driver. |
| apps/server/src/provider/Layers/KimiProvider.ts | Implements Kimi provider snapshot logic, status probe, discovery, and enrichment. |
| apps/server/src/provider/Layers/KimiProvider.test.ts | Adds unit tests for Kimi snapshot/discovery/status behavior. |
| apps/server/src/provider/Layers/KimiAdapter.ts | Implements Kimi ACP adapter using StandardAcpAdapter. |
| apps/server/src/provider/Layers/KimiAdapter.test.ts | Adds basic adapter construction/validation tests for Kimi. |
| apps/server/src/provider/Layers/GrokProvider.ts | Refactors Grok provider status probing/enrichment onto shared helpers. |
| apps/server/src/provider/Layers/CursorAdapter.ts | Refactors Cursor ACP adapter onto StandardAcpAdapter and registers extensions via hook. |
| apps/server/src/provider/Drivers/KimiDriver.ts | Adds the Kimi driver instance bundle (adapter/text-gen/snapshot/maintenance). |
| apps/server/src/provider/builtInDrivers.ts | Registers KimiDriver in the built-in driver list and env union. |
| apps/server/src/provider/acp/KimiAcpSupport.ts | Adds ACP support helpers for Kimi (binary resolution, spawn env, model/mode selection). |
| apps/server/src/provider/acp/KimiAcpSupport.test.ts | Adds unit tests for Kimi ACP support helpers. |
| apps/server/src/provider/acp/GrokAcpSupport.ts | Refactors Grok model switching to use shared applyAcpModelSelectionIfChanged. |
| apps/server/src/provider/acp/AcpModelSelection.ts | Adds shared “switch model only if changed” helper. |
| apps/server/src/provider/acp/AcpCoreRuntimeEvents.ts | Exports AcpAdapterRawSource for use by the shared adapter core. |
| .gitignore | Ignores .gradle/ caches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ); | ||
|
|
||
| const generateCommitMessage: TextGeneration.TextGeneration["Service"]["generateCommitMessage"] = | ||
| Effect.fn("GrokTextGeneration.generateCommitMessage")(function* (input) { |
| }); | ||
|
|
||
| const generatePrContent: TextGeneration.TextGeneration["Service"]["generatePrContent"] = | ||
| Effect.fn("GrokTextGeneration.generatePrContent")(function* (input) { |
| }); | ||
|
|
||
| const generateBranchName: TextGeneration.TextGeneration["Service"]["generateBranchName"] = | ||
| Effect.fn("GrokTextGeneration.generateBranchName")(function* (input) { |
| }); | ||
|
|
||
| const generateThreadTitle: TextGeneration.TextGeneration["Service"]["generateThreadTitle"] = | ||
| Effect.fn("GrokTextGeneration.generateThreadTitle")(function* (input) { |
| return yield* new ProviderAdapterRequestError({ | ||
| provider: PROVIDER, | ||
| method: "cursor/ask_question", | ||
| detail: `Unknown pending user-input request: ${requestId}`, | ||
| }); |
ApprovabilityVerdict: Needs human review This PR adds a new ACP provider (Kimi Code) and refactors core ACP adapter infrastructure, representing significant new runtime capability. Multiple unresolved review comments identify potential bugs including misleading trace spans and overly broad auth error detection that could show incorrect error messages. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05c522eda6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cwd: process.cwd(), | ||
| clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" }, | ||
| }); | ||
| yield* acp.start(); |
There was a problem hiding this comment.
Handle Kimi auth-required probe failures
The official Kimi ACP docs say authenticate returns authRequired (-32000) when the user is not logged in, so in that signed-out case this acp.start() fails before getConfigOptions can run. That means the empty-catalog unauthenticated branch is never reached and runCliProviderStatusProbe reports a generic ACP startup failure with auth: unknown instead of telling users to run kimi login; catch the Kimi auth-required error here (or in the probe) and build the unauthenticated snapshot directly. See https://www.kimi.com/code/docs/en/kimi-code-cli/reference/kimi-acp.html#stable-agent-side--ide--agent-10--12.
Useful? React with 👍 / 👎.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- StandardAcpTextGeneration: rename remaining "GrokTextGeneration.*" Effect span labels to "StandardAcpTextGeneration.*" so traces are accurate for every provider (Copilot). - StandardAcpAdapter: respondToUserInput reported the Cursor-specific "cursor/ask_question" method in the provider-agnostic adapter; use the neutral "respondToUserInput" operation name (Copilot, cursor bot). - KimiAdapter: run the empty-catalog signed-out check unconditionally during session configuration instead of only when a model selection is present, so a logged-out session surfaces "run kimi login" at session start rather than an opaque config error (macroscope, cursor bot). - resolveKimiAcpModeId: map auto-accept-edits to yolo (unrestricted) like full-access, mirroring the Cursor ACP path; only approval-required stays supervised, so auto-accept users stop hitting approval prompts (cursor bot). - KimiProvider discovery: catch the ACP auth-required error (-32000) so a signed-out CLI that rejects the handshake before the catalog can be read still reports unauthenticated instead of a generic startup failure (codex). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7e9ff0f. Configure here.
| */ | ||
| export function isKimiAuthRequiredAcpError(error: EffectAcpErrors.AcpError): boolean { | ||
| return error._tag === "AcpRequestError" && error.code === KIMI_AUTH_REQUIRED_ACP_CODE; | ||
| } |
There was a problem hiding this comment.
Auth detection matches any -32000
Medium Severity
isKimiAuthRequiredAcpError treats every AcpRequestError with code -32000 as signed-out. That code is a generic JSON-RPC server-error slot, while makeKimiAuthRequiredError already tags auth with data.reason: "auth_required". Discovery then maps any matching failure to catalogEmpty: true, so Settings can show “run kimi login” for non-auth -32000 handshake/startup failures and hide the real fault.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7e9ff0f. Configure here.
Ports three robustness gaps from the competing Kimi PR (pingdotgg#4098) into this provider, adapted to the Grok-mirroring architecture: 1. resolveKimiBinaryPath — when `kimi` is not on PATH (the Windows installer does not add it), fall back to ~/.kimi-code/bin/kimi[.exe] before giving up, so a Windows user with no explicit binaryPath no longer gets a spurious "not installed". An explicit binaryPath stays authoritative. Requires FileSystem/Path, provided at every call site (KimiAdapter, KimiDriver, KimiTextGeneration, provider status probe). 2. Version-probe timeout 4s -> 15s — Kimi is a large single binary; cold starts on Windows can far exceed the warm-path latency and were failing the probe. 3. Signed-out UX — classifyKimiSessionModels distinguishes an EMPTY ACP model list (signed out -> "run `kimi login`", auth unauthenticated) from a MISSING model option (incompatible CLI), instead of silently falling back to a built-in model that fails on first use. Reviewed by grok-4.5, kimi-k3, and gpt-5.6-sol against the three changes. Claude-Session: https://claude.ai/code/session_01QGeRY5z128NxiM6Buz7ZQV


What Changed
Adds Kimi Code (MoonshotAI) as a sixth built-in provider driver (
kimi),alongside Codex, Claude, Cursor, Grok, and OpenCode. Kimi Code speaks the
Agent Client Protocol over stdio (
kimi acp), so it reuses the existingACP integration path rather than introducing new transport machinery.
Server (
apps/server):KimiDriver,KimiProvider,KimiAdapter,KimiAcpSupport,KimiTextGeneration, registered inbuiltInDrivers.modelconfig option(Cursor-style). An empty option list is Kimi's signed-out signal and is
surfaced as "run
kimi login" from the status probe, session start, andgit text generation — not as an opaque config-validation error.
modeconfig option(full access →
yolo, supervised →default, plan →plan).~/.kimi-code/bininstallpath, since the installer does not add
kimitoPATHon Windows; theresolved path is threaded through so spawns don't re-scan
PATH.start on Windows can far exceed its ~1s warm latency.
kimi upgrade.Contracts (
packages/contracts):KimiSettings(binary path +KIMI_CODE_HOMEhome isolation for multi-account use), settings-patch wiring, model defaults,
and display names — all schema-only, mirroring the existing providers.
Web (
apps/web): provider registration (settings form, model picker, theofficial Kimi icon), and custom-model input placeholders.
Refactors that fell out of review (behavior-preserving): extracted the
provider-agnostic ACP adapter core (
StandardAcpAdapter), the shared ACPtext-generation core (
StandardAcpTextGeneration), the CLI status-probescaffold (
providerStatusProbe), and the shared model-selection helper(
AcpModelSelection). Cursor's private extension protocol now registersthrough a generic hook instead of a Cursor-named flag; Cursor and Grok
delegate to the shared bases unchanged.
Why
The provider layer is explicitly pluggable and already hosts five drivers;
Kimi Code is a straightforward addition on the existing ACP path. Adding it
surfaced three small correctness/UX issues (opaque logged-out error,
redundant
PATHscans, a brittle model-option lookup) which are fixed here,and the shared-base extractions remove three near-identical ~150-line copies
that adding a sixth ACP-style provider would otherwise have grown.
Verified live against
kimi0.26.0 on Windows: pairing, model discovery(K2.7 Coding / Highspeed, K3, Kimi for Coding / Highspeed), and full agent
turns with tool calls.
vp run typecheckandvp checkare clean; allprovider tests pass except a set of pre-existing Windows-only failures
(POSIX
#!/bin/shmock binaries that cannot spawn on Windows), which failidentically before and after this change.
UI Changes
Adds the Kimi Code provider to Settings → Providers and the model picker
(monochrome Kimi mark, theme-adaptive like the other provider icons).
A short video of provider setup, model discovery, and a live turn will be
added to this PR.
Checklist
Note
Add Kimi Code (MoonshotAI) as a full ACP provider
kimiprovider end-to-end: settings schema, server driver, adapter, provider status probe, and text generation via a sharedmakeStandardAcpTextGenerationhelper.KimiAcpSupportutilities for binary resolution (PATH, well-known install path, or configured path), spawn input construction with optionalKIMI_CODE_HOME, model/mode selection, and auth-required error detection.runtimeMode/interactionMode.CursorAdapterandGrokProvideronto the newStandardAcpAdapterandrunCliProviderStatusProbeshared infrastructure consumed by the Kimi driver.KimiIcon, provider picker entry with "new" badge, settings form, custom model placeholder, and display nameMacroscope summarized 7e9ff0f.
Note
Medium Risk
Large surface area: new external CLI integration plus a major Cursor adapter extraction; regressions would affect live ACP sessions and provider health/auth messaging, though tests cover Kimi paths and registry bootstrapping.
Overview
Introduces Kimi Code (
kimi acp) as a sixth built-in provider: driver, health probe with ACP model discovery, adapter sessions, git text generation,kimi upgrademaintenance, and web settings/picker/icon wiring. Kimi-specific behavior includes mapping T3 runtime modes to Kimimodeconfig, resolving the CLI via~/.kimi-code/binwhen not onPATH, and treating an empty model catalog (or auth ACP errors) as signed-out with a clearkimi loginmessage—not a generic config failure.Refactors (intended behavior-preserving): Cursor’s adapter shrinks onto new
makeStandardAcpAdapter, with Cursor-only extensions registered via a generic hook; Grok’s provider check and advisory enrichment move ontoproviderStatusProbe; Grok and Kimi text generation shareStandardAcpTextGeneration; Grok/Kimi model switches shareapplyAcpModelSelectionIfChanged. Registry and provider tests are updated to includekimiamong shipped drivers.Also ignores
.gradle/in.gitignore.Reviewed by Cursor Bugbot for commit 7e9ff0f. Bugbot is set up for automated code reviews on this repo. Configure here.