diff --git a/docs/getting-started/client-configuration.md b/docs/getting-started/client-configuration.md index 7f126db34d..ffb5421a04 100644 --- a/docs/getting-started/client-configuration.md +++ b/docs/getting-started/client-configuration.md @@ -935,6 +935,29 @@ relative additional entry depends on Goose's working directory, so REA refuses it. Goose reads its configuration at startup; restart it after setup. +## Kilo Code + +For [Kilo Code](https://kilo.ai/docs/automate/mcp/using-in-kilo-code), setup +and `rea mcp add` write `mcp.rea` into the last user-scope file Kilo loads. +Kilo's config root is `$XDG_CONFIG_HOME/kilo` when `XDG_CONFIG_HOME` is set, +otherwise `~/.config/kilo`, on every OS including Windows. Kilo reads that +root's `config.json`, `kilo.json`, `kilo.jsonc`, `opencode.json` and +`opencode.jsonc`, then the `KILO_CONFIG` file, then `~/.kilocode`, `~/.kilo` and +`KILO_CONFIG_DIR`, each for `kilo.jsonc`, `kilo.json`, `opencode.jsonc` and +`opencode.json`. When none of those files exists, setup creates `kilo.json` in +the root (or in an empty `KILO_CONFIG_DIR`). A relative Kilo path depends on +Kilo's working directory, so REA refuses it. The entry is +`{ "type": "local", "command": [exe, ...args], "enabled": true }`, plus +`environment` only when it is non-empty. `rea mcp add` preserves an existing +`enabled: false`; `rea setup` sets `enabled: true`. +`KILO_CONFIG_CONTENT` is Kilo's highest layer and is never edited (see +[installation](installation.md)); project registration with `rea mcp add` is in +the [CLI guide](cli.md). Kilo also reads its legacy extension MCP files +(`mcpServers` in the VS Code extension's `mcp_settings.json`, and the project +`.kilocode/mcp.json` and `.kilo/mcp.json`) at the lowest precedence, below any +`kilo.json` layer. REA neither inspects nor removes them, so a `rea` entry added +there by hand stays in effect after uninstall. + ## WorkBuddy For [WorkBuddy](https://www.workbuddy.cn/docs/workbuddy/From-Beginner-to-Expert-Guide/Function-Description/MCP-Guide), setup writes `mcpServers.rea` into the diff --git a/src/application/KiloClientLocation.ts b/src/application/KiloClientLocation.ts index a627b7f4cc..0f78f2f200 100644 --- a/src/application/KiloClientLocation.ts +++ b/src/application/KiloClientLocation.ts @@ -175,14 +175,16 @@ export const kiloDefaultLocation = ( const explicit = kiloExplicitFile(context); const custom = kiloExplicitDirectory(context); const homes = kiloHomePaths(context); + // The row is planned for its platform, which tests choose apart from the host. + const pathApi = context.root.platform === "win32" ? win32 : posix; return { - configPath: join(root, "kilo.json"), + configPath: pathApi.join(root, "kilo.json"), configPaths: [ - ...KILO_GLOBAL_FILES.map((name) => join(root, name)), + ...KILO_GLOBAL_FILES.map((name) => pathApi.join(root, name)), ...(explicit === undefined ? [] : [explicit]), ...[...homes, ...(custom === undefined ? [] : [custom])].flatMap( (directory) => - KILO_DIRECTORY_FILES.map((name) => join(directory, name)), + KILO_DIRECTORY_FILES.map((name) => pathApi.join(directory, name)), ), ], markerPath: root, diff --git a/tests/boundary/filesystem/kiloClientLocation.test.ts b/tests/boundary/filesystem/kiloClientLocation.test.ts index d0e1d3252c..9c19f8b9ae 100644 --- a/tests/boundary/filesystem/kiloClientLocation.test.ts +++ b/tests/boundary/filesystem/kiloClientLocation.test.ts @@ -1,7 +1,8 @@ import { registerMcpClientsOnHost } from "../../fixtures/mcpRegistration.js"; import { HOST_PLATFORM } from "../../../src/platform/HostPlatform.js"; import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; -import { join } from "node:path"; +import { join, posix, win32 } from "node:path"; +import { parse as parseJsonc } from "jsonc-parser"; import { afterEach, beforeEach, expect, it, vi } from "vitest"; import { readEffectiveClientRegistrationConfiguration } from "../../../src/application/ClientConfigurationFiles.js"; @@ -66,6 +67,63 @@ it("writes Kilo's kilo.json in its config root until another layer exists", asyn }); }); +it.each([ + ["win32", "C:\\Users\\x", win32], + ["darwin", "/Users/x", posix], +] as const)( + "defaults Kilo's file to .config/kilo/kilo.json on %s without XDG_CONFIG_HOME", + (hostPlatform, home, pathModule) => { + const row = supportedClients(home, hostPlatform, {}).find( + ({ name }) => name === "kilo", + ); + expect(row?.configPath).toBe( + pathModule.join(home, ".config", "kilo", "kilo.json"), + ); + }, +); + +it("keeps comments, settings and other servers through setup and uninstall of kilo.jsonc", async () => { + const home = await createTestTempDirectory("rea-kilo-jsonc-"); + const root = join(home, ".config", "kilo"); + await mkdir(root, { recursive: true }); + const target = join(root, "kilo.jsonc"); + await writeFile( + target, + `{ + // line comment + "theme": "dark", /* block comment */ + "mcp": { "other": { "type": "local", "command": ["x"] } } +} +`, + ); + const row = await kiloRow(home); + if (row === undefined) throw new Error("Kilo row is missing"); + expect(row.configPath).toBe(target); + expect(await configureClientConfiguration(row, {}, command)).toMatchObject({ + status: "configured", + }); + const preserved = async () => { + const text = await readFile(target, "utf8"); + expect(text).toContain("// line comment"); + expect(text).toContain("/* block comment */"); + const parsed = parseJsonc(text) as { + theme?: string; + mcp: Record; + }; + expect(parsed.theme).toBe("dark"); + expect(parsed.mcp.other).toEqual({ type: "local", command: ["x"] }); + return parsed; + }; + expect((await preserved()).mcp.rea).toMatchObject({ + type: "local", + command, + enabled: true, + }); + const { kilo } = await uninstallKilo(home, {}); + expect(kilo?.status).toBe("removed"); + expect((await preserved()).mcp).not.toHaveProperty("rea"); +}); + it("selects the last present Kilo layer, as rea mcp add does", async () => { const home = await createTestTempDirectory("rea-kilo-layers-"); const root = join(home, ".config", "kilo");