Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(kimi): confirm ACP session model before prompting
Rui zhi79ed01247a26
diff --git a/docs/verification/README.md b/docs/verification/README.mdindex 846dfb102b..4b1c599eb0 100644--- a/docs/verification/README.md+++ b/docs/verification/README.md@@ -89,6 +89,7 @@ Use only mapped, tested commands:- [Codex browser routing and native search](codex-browser-routing.md)- [Codex helper event isolation](codex-helpers.md)- [Qwen model route selection](qwen-models.md)+- [Kimi subscription and Platform model selection](kimi-models.md)- [Team backups](team-backups.md)- [Sharing a whole team](team-sharing.md)- [The organization library](org-library.md)diff --git a/docs/verification/kimi-models.md b/docs/verification/kimi-models.mdnew file mode 100644index 0000000000..40209cce1d--- /dev/null+++ b/docs/verification/kimi-models.md@@ -0,0 +1,31 @@+# Kimi model selection++Kimi Code 2.5.3 accepts a global `-m` argument, but its ACP `session/new`+can still select the CLI's configured default. OpenMausBot selects the+`model` session config option after creating or restoring a session and+requires the returned value to match before sending a prompt. A rejected+or unconfirmed switch fails the turn instead of using another provider.++This applies to subscription models, configured Platform API models and+local model aliases. It does not change the CLI's saved default or credentials.+The CLI must support the ACP `model` config option; an unsupported switch+fails before sending a prompt.++Run the offline checks:++```sh+pnpm exec vitest run server/drivers/acp/kimi-model-selection.test.ts server/drivers/acp/kimi-device-auth.test.ts server/drivers/local-inject.test.ts server/drivers/acp/approval-matrix.test.ts server/drivers/acp/acp.test.ts+node --experimental-strip-types scripts/verify-kimi-models.ts+pnpm exec tsc -p tsconfig.server.json --noEmit+```++The driver tests use disposable homes and the repository's fake ACP CLI.+They verify selection before a prompt for new and restored sessions, the+actual provider used at prompt time, and no prompt after a rejected or+unconfirmed selection. The verification script launches an isolated harness+server and sends a chat through the standard control surface, covering both+successful selection and a CLI that acknowledges but ignores the switch.+It prints the server log path and RPC order, then closes the fixture.++These checks do not call Moonshot, use real credentials, verify API billing,+or prove a packaged desktop build has loaded the change.diff --git a/scripts/control-omb.ts b/scripts/control-omb.tsindex a164e20e26..1d4897927e 100644--- a/scripts/control-omb.ts+++ b/scripts/control-omb.ts@@ -289,7 +289,7 @@ export async function launchVerificationServer(enterprise?: { dir: string; licenseKey: string },room?: { scripted: boolean },/** Optional repository-owned fake providers for multi-engine setup checks. */- extraProviders: Array<"codex" | "cline" | "copilot" | "customAcp" | "opencode"> = [],+ extraProviders: Array<"codex" | "cline" | "copilot" | "customAcp" | "opencode" | "kimi"> = [],/** Programmatic tests only: an owned loopback Boat provider, never a live account. */boatFixtureApi?: string,/** Programmatic web UI qualification against the fixture's static server. */@@ -332,6 +332,10 @@ export async function launchVerificationServer(// A setup card's answers would be one more engine call at every new bot, taking replies a test scripts for its turns.features: { smartSetupChoices: false },instances: {+ ...(extraProviders.includes("kimi") ? { kimi: {+ driver: "kimiAgent", displayName: "Verification Kimi",+ config: { cli: fileURLToPath(new URL("../server/testing/fake-acp-cli.ts", import.meta.url)) },+ } } : {}),...(extraProviders.includes("codex") ? { codex: {driver: "codex", displayName: "Verification Codex", config: { cli: fileURLToPath(new URL("../server/testing/fake-codex-app-server.ts", import.meta.url)) },} } : {}),diff --git a/scripts/verify-kimi-models.ts b/scripts/verify-kimi-models.tsnew file mode 100644index 0000000000..71dc5ccef9--- /dev/null+++ b/scripts/verify-kimi-models.ts@@ -0,0 +1,59 @@+import assert from "node:assert/strict";+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { fileURLToPath, pathToFileURL } from "node:url";+import { launchVerificationServer, runControlOmb } from "./control-omb.ts";++const fixture = await launchVerificationServer(process.env, undefined, undefined, undefined, undefined, undefined, ["kimi"]);+const { url, dataDir } = fixture.info;+const control = (args: string[]) => runControlOmb([...args, "--url", url]) as Promise<any>;+const subscription = "kimi-code/kimi-for-coding";+const platform = "moonshot-cn/kimi-k2.6";+const evidence: unknown[] = [];+try {+ const root = join(dataDir, ".kimi-code");+ mkdirSync(join(root, "credentials"), { recursive: true });+ writeFileSync(join(root, "credentials/kimi-code.json"), "{}");+ writeFileSync(join(root, "config.toml"), `[models."${platform}"]\nprovider = "moonshot-cn"\nmodel = "kimi-k2.6"\n`);+ const dump = join(dataDir, "kimi-spawn.json");+ const methods = join(dataDir, "kimi-methods.json");+ const reject = join(dataDir, "reject-switch");+ const cli = join(dataDir, "fixture-kimi.ts");+ const fake = pathToFileURL(fileURLToPath(new URL("../server/testing/fake-acp-cli.ts", import.meta.url))).href;+ writeFileSync(cli, `#!/usr/bin/env node+import { existsSync } from "node:fs";+process.env.FAKE_ACP_MODELS = ${JSON.stringify(`${subscription},${platform}`)};+process.env.FAKE_ACP_DUMP = ${JSON.stringify(dump)};+process.env.FAKE_ACP_RPC_DUMP = ${JSON.stringify(methods)};+if (existsSync(${JSON.stringify(reject)})) process.env.FAKE_ACP_MODEL_STICKS = "1";+await import(${JSON.stringify(fake)});+`, { mode: 0o755 });+ const configured = await fetch(`${url}/api/instances/kimi`, {+ method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify({ cli }),+ });+ assert.equal(configured.status, 200, await configured.text());+ for (const blocked of [false, true]) {+ if (blocked) writeFileSync(reject, "1");+ const created = await control(["new-bot", "--name", blocked ? "Rejected Kimi switch" : "Platform Kimi"]);+ const id = created.bot.id;+ await control(["set-model", "--bot", id, "--instance", "kimi", "--model", platform]);+ await control(["send", "--bot", id, "--text", "Say hello."]);+ const result = await control(["wait", "--bot", id, "--timeout", "30"]);+ assert.equal(result.status, blocked ? "failed" : "settled");+ const rpc: string[] = JSON.parse(readFileSync(methods, "utf8"));+ assert(rpc.includes("session/set_config_option"));+ assert.equal(rpc.includes("session/prompt"), !blocked);+ if (!blocked) {+ assert(rpc.indexOf("session/set_config_option") < rpc.indexOf("session/prompt"));+ const prompts = readFileSync(`${dump}.prompts.jsonl`, "utf8").trim().split("\n").map((line) => JSON.parse(line));+ assert(prompts.every((prompt) => prompt.model === platform));+ const messages = await control(["messages", "--bot", id]);+ assert(messages.messages.some((message: { text?: string }) => message.text === "hello from fake acp"));+ }+ evidence.push({ blocked, status: result.status, rpc });+ }+ assert(existsSync(`${dump}.config.json`));+ console.log(JSON.stringify({ passed: true, logPath: fixture.info.logPath, evidence }, null, 2));+} finally {+ await fixture.close();+}diff --git a/server/drivers/acp/kimi-model-selection.test.ts b/server/drivers/acp/kimi-model-selection.test.tsnew file mode 100644index 0000000000..b3cff15046--- /dev/null+++ b/server/drivers/acp/kimi-model-selection.test.ts@@ -0,0 +1,86 @@+import { existsSync, mkdtempSync, readFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterEach, beforeEach, describe, expect, it } from "vitest";+import { ensureDirs } from "../../config.ts";+import type { ProviderInstance } from "../../contracts.ts";+import { removeTempDir } from "../../testing/cleanup.ts";+import { recordEvents, type EventRecorder } from "../../testing/events.ts";+import { KimiAgentDriver } from "./kimi.ts";++const FAKE_CLI = fileURLToPath(new URL("../../testing/fake-acp-cli.ts", import.meta.url));+const SUBSCRIPTION = "kimi-code/kimi-for-coding";+const PLATFORM = "moonshot-cn/kimi-k2.6";++describe("Kimi session model selection", () => {+ let scratch: string;+ let instance: ProviderInstance | undefined;+ let recorder: EventRecorder | undefined;++ beforeEach(() => {+ ensureDirs();+ scratch = mkdtempSync(join(tmpdir(), "omb-kimi-model-"));+ });++ afterEach(async () => {+ recorder?.stop();+ await instance?.dispose();+ await removeTempDir(scratch);+ });++ async function create(environment: Record<string, string> = {}) {+ instance = await KimiAgentDriver.create({+ instanceId: "kimi-model-fixture", displayName: "Kimi", enabled: true,+ config: { cli: FAKE_CLI, fullAuto: false },+ environment: {+ HOME: scratch, USERPROFILE: scratch, KIMI_CODE_HOME: join(scratch, ".kimi-code"),+ FAKE_ACP_MODELS: `${SUBSCRIPTION},${PLATFORM}`,+ FAKE_ACP_DUMP: join(scratch, "launch.json"),+ FAKE_ACP_RPC_DUMP: join(scratch, "rpc.json"),+ ...environment,+ },+ });+ recorder = recordEvents(instance.adapter);+ return { instance, recorder };+ }++ const methods = (): string[] => JSON.parse(readFileSync(join(scratch, "rpc.json"), "utf8"));+ const prompts = (): Array<{ model: string }> => {+ const path = join(scratch, "launch.json.prompts.jsonl");+ return existsSync(path) ? readFileSync(path, "utf8").trim().split("\n").map((line) => JSON.parse(line)) : [];+ };++ it.each([undefined, "saved-kimi-session"])("selects the Platform provider before prompting a new or restored session: %s", async (resumeCursor) => {+ const { instance, recorder } = await create();+ const { turnId } = await instance.adapter.sendTurn({ threadId: "kimi-chat", text: "hello", model: PLATFORM, resumeCursor });+ await expect(recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId))+ .resolves.toMatchObject({ ok: true });+ const rpc = methods();+ expect(rpc).toContain(resumeCursor ? "session/load" : "session/new");+ expect(rpc.indexOf("session/set_config_option")).toBeLessThan(rpc.indexOf("session/prompt"));+ expect(prompts()).toEqual([expect.objectContaining({ model: PLATFORM })]);+ expect(recorder.events).toContainEqual(expect.objectContaining({ type: "session.started", model: PLATFORM }));+ });++ it("does not prompt when Kimi acknowledges a switch but retains the subscription model", async () => {+ const { instance, recorder } = await create({ FAKE_ACP_MODEL_STICKS: "1" });+ const { turnId } = await instance.adapter.sendTurn({ threadId: "kimi-chat", text: "hello", model: PLATFORM });+ await expect(recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId))+ .resolves.toMatchObject({ ok: false });+ expect(methods()).toContain("session/set_config_option");+ expect(prompts()).toEqual([]);+ expect(recorder.events).toContainEqual(expect.objectContaining({+ type: "runtime.error", message: expect.stringContaining(`did not switch to ${PLATFORM}`),+ }));+ });++ it("does not prompt when the requested model is rejected", async () => {+ const { instance, recorder } = await create();+ const { turnId } = await instance.adapter.sendTurn({ threadId: "kimi-chat", text: "hello", model: "moonshot-cn/missing" });+ await expect(recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId))+ .resolves.toMatchObject({ ok: false });+ expect(methods()).not.toContain("session/prompt");+ expect(prompts()).toEqual([]);+ });+});diff --git a/server/drivers/acp/kimi.ts b/server/drivers/acp/kimi.tsindex 84ea06f50c..4508e8de90 100644--- a/server/drivers/acp/kimi.ts+++ b/server/drivers/acp/kimi.ts@@ -1,5 +1,5 @@-// Kimi Code: Moonshot's `kimi acp` on the Kimi Code subscription login-// (~/.kimi-code/credentials), not a Moonshot API key. Verified on kimi-code 0.29.1.+// Kimi Code 2.5.3 ignores the global -m option when opening an ACP session;+// its model config option selects both subscription and configured API providers.import { mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";import { homedir } from "node:os";import { join } from "node:path";@@ -560,6 +560,7 @@ const support: AcpSupport = {// -m is a global commander option and must precede `acp` (0.29.1).resolveTurnModel: (model, env) => (model ? ensureKimiInjectAlias(model, env) : model),+ selectModel: { configId: "model" },spawnArgs: (_config, turn) => {const model = turn.model;return [...(model ? ["-m", model] : []), "acp"];