Skip to content

Add Kimi Code (MoonshotAI) as an ACP provider#4098

Open
Emmanuek5 wants to merge 10 commits into
pingdotgg:mainfrom
Emmanuek5:feat/kimi-provider
Open

Add Kimi Code (MoonshotAI) as an ACP provider#4098
Emmanuek5 wants to merge 10 commits into
pingdotgg:mainfrom
Emmanuek5:feat/kimi-provider

Conversation

@Emmanuek5

@Emmanuek5 Emmanuek5 commented Jul 17, 2026

Copy link
Copy Markdown

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 existing
ACP integration path rather than introducing new transport machinery.

Server (apps/server):

  • New driver stack: KimiDriver, KimiProvider, KimiAdapter,
    KimiAcpSupport, KimiTextGeneration, registered in builtInDrivers.
  • Models are discovered from the ACP session's model config 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, and
    git text generation — not as an opaque config-validation error.
  • T3 runtime modes map onto 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, since the installer does not add kimi to PATH on Windows; the
    resolved path is threaded through so spawns don't re-scan PATH.
  • Version-probe timeout is 15s: the CLI is a large single binary whose cold
    start on Windows can far exceed its ~1s warm latency.
  • Self-update wired to kimi upgrade.

Contracts (packages/contracts): KimiSettings (binary path + KIMI_CODE_HOME
home 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, the
official 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 ACP
text-generation core (StandardAcpTextGeneration), the CLI status-probe
scaffold (providerStatusProbe), and the shared model-selection helper
(AcpModelSelection). Cursor's private extension protocol now registers
through 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 PATH scans, 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 kimi 0.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 typecheck and vp check are clean; all
provider tests pass except a set of pre-existing Windows-only failures
(POSIX #!/bin/sh mock binaries that cannot spawn on Windows), which fail
identically 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

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note: this is a new-provider PR (~1.9k lines), which is larger than the
"small, focused" bar in CONTRIBUTING.md. Opened knowing it may be closed
or deferred. Kept as a draft while the demo video is added.

Note

Add Kimi Code (MoonshotAI) as a full ACP provider

  • Introduces the kimi provider end-to-end: settings schema, server driver, adapter, provider status probe, and text generation via a shared makeStandardAcpTextGeneration helper.
  • Adds KimiAcpSupport utilities for binary resolution (PATH, well-known install path, or configured path), spawn input construction with optional KIMI_CODE_HOME, model/mode selection, and auth-required error detection.
  • Session startup fails fast with a user-facing error when the Kimi CLI is logged out (empty model catalog); mode is always applied from runtimeMode/interactionMode.
  • Refactors CursorAdapter and GrokProvider onto the new StandardAcpAdapter and runCliProviderStatusProbe shared infrastructure consumed by the Kimi driver.
  • Adds UI support: KimiIcon, provider picker entry with "new" badge, settings form, custom model placeholder, and display name

Macroscope 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 upgrade maintenance, and web settings/picker/icon wiring. Kimi-specific behavior includes mapping T3 runtime modes to Kimi mode config, resolving the CLI via ~/.kimi-code/bin when not on PATH, and treating an empty model catalog (or auth ACP errors) as signed-out with a clear kimi login message—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 onto providerStatusProbe; Grok and Kimi text generation share StandardAcpTextGeneration; Grok/Kimi model switches share applyAcpModelSelectionIfChanged. Registry and provider tests are updated to include kimi among 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.

Emmanuek5 and others added 2 commits July 17, 2026 15:18
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>
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d2cb48d9-c10a-4df8-91b2-0c5107baf76f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Jul 17, 2026
Comment thread apps/server/src/provider/Layers/KimiProvider.ts
Comment thread apps/server/src/provider/Drivers/KimiDriver.ts Outdated
… 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>

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread apps/server/src/provider/Drivers/KimiDriver.ts Outdated
Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
@Emmanuek5

Copy link
Copy Markdown
Author
2026-07-17.20-55-27.mp4

Emmanuek5 and others added 4 commits July 17, 2026 21:40
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
@Emmanuek5
Emmanuek5 marked this pull request as ready for review July 18, 2026 03:52
Copilot AI review requested due to automatic review settings July 18, 2026 03:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Comment on lines +1002 to +1006
return yield* new ProviderAdapterRequestError({
provider: PROVIDER,
method: "cursor/ask_question",
detail: `Unknown pending user-input request: ${requestId}`,
});
Comment thread apps/server/src/provider/Layers/KimiAdapter.ts
Comment thread apps/server/src/provider/Layers/StandardAcpAdapter.ts
Comment thread apps/server/src/provider/acp/KimiAcpSupport.ts
Comment thread apps/server/src/textGeneration/StandardAcpTextGeneration.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Emmanuek5 and others added 2 commits July 18, 2026 05:18
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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7e9ff0f. Configure here.

ccdwyer added a commit to ccdwyer/t3code that referenced this pull request Jul 18, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants