mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
fix(setup): honor KIRO_HOME for the Kiro user configuration (#15056)
* fix(setup): honor KIRO_HOME for the Kiro user configuration * fix(setup): fall back when KIRO_HOME is any filesystem root The ancestor check compared the selected root against home with path.relative, which returns an absolute path across drives, so a KIRO_HOME of D:\ or a UNC share root was accepted while Kiro itself falls back to ~/.kiro. Check the selected path against its own root separately, and document the override in the client configuration guide. * test(setup): clear KIRO_HOME from lifecycle test environments The client-location scrubber omitted KIRO_HOME, so lifecycle tests calling supportedClients/detectClients and systemUninstallHost with the default process.env could resolve a runner-exported KIRO_HOME outside their temporary home and touch the real Kiro registration. * fix(setup): resolve Kiro home aliases before selecting a profile * refactor(setup): use the captured host platform for Kiro path checks --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
8306fba960
commit
2ce4471c9f
5 files changed
+262
-11
No files matched your search
@@ -954,13 +954,13 @@ removal are covered by `tests/acceptance/setup/clineClientSetup.test.ts`.
|
||||
Setup, doctor, update, uninstall and `rea mcp add` share one definition for each
|
||||
of these clients. Setup offers a client when its directory exists.
|
||||
|
||||
| Client | `--client` | User configuration | Server table |
|
||||
| ----------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
|
||||
| Cline VS Code extension | `cline_vscode` | `<VS Code user directory>/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` | `mcpServers` |
|
||||
| Kiro | `kiro` | `~/.kiro/settings/mcp.json`, shared by the IDE and CLI | `mcpServers` |
|
||||
| Mastra Code | `mastracode` | `~/.mastracode/mcp.json` | `mcpServers` |
|
||||
| Zed | `zed` | `~/.config/zed/settings.json` on macOS, `%APPDATA%\Zed\settings.json` on Windows, `$XDG_CONFIG_HOME/zed/settings.json` on Linux | `context_servers` |
|
||||
| Amp | `amp` | `~/.config/amp/settings.json`, or `settings.jsonc` when that is the only one | `amp.mcpServers` |
|
||||
| Client | `--client` | User configuration | Server table |
|
||||
| ----------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
|
||||
| Cline VS Code extension | `cline_vscode` | `<VS Code user directory>/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` | `mcpServers` |
|
||||
| Kiro | `kiro` | `~/.kiro/settings/mcp.json`, or `$KIRO_HOME/settings/mcp.json` when `KIRO_HOME` is absolute and not a filesystem root, the home folder, or an ancestor of it; shared by the IDE and CLI | `mcpServers` |
|
||||
| Mastra Code | `mastracode` | `~/.mastracode/mcp.json` | `mcpServers` |
|
||||
| Zed | `zed` | `~/.config/zed/settings.json` on macOS, `%APPDATA%\Zed\settings.json` on Windows, `$XDG_CONFIG_HOME/zed/settings.json` on Linux | `context_servers` |
|
||||
| Amp | `amp` | `~/.config/amp/settings.json`, or `settings.jsonc` when that is the only one | `amp.mcpServers` |
|
||||
|
||||
The Cline extension keeps a separate settings file in each editor that runs
|
||||
it. `cline_vscode_insiders`, `cline_vscodium`, `cline_cursor` and
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
@@ -691,6 +691,164 @@ it.each([
|
||||
expect(client?.configPathError).toContain("FX_HOME");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "unset",
|
||||
env: {},
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "absolute KIRO_HOME",
|
||||
env: { KIRO_HOME: "/work/kiro-profile" },
|
||||
configPath: "/work/kiro-profile/settings/mcp.json",
|
||||
markerPath: "/work/kiro-profile",
|
||||
},
|
||||
{
|
||||
name: "trailing slash",
|
||||
env: { KIRO_HOME: "/work/kiro-profile/" },
|
||||
configPath: "/work/kiro-profile/settings/mcp.json",
|
||||
markerPath: "/work/kiro-profile",
|
||||
},
|
||||
{
|
||||
name: "folder inside home",
|
||||
env: { KIRO_HOME: "/home/alice/profile" },
|
||||
configPath: "/home/alice/profile/settings/mcp.json",
|
||||
markerPath: "/home/alice/profile",
|
||||
},
|
||||
{
|
||||
name: "sibling sharing a name prefix",
|
||||
env: { KIRO_HOME: "/home/al" },
|
||||
configPath: "/home/al/settings/mcp.json",
|
||||
markerPath: "/home/al",
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
env: { KIRO_HOME: "" },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "relative",
|
||||
env: { KIRO_HOME: "relative/kiro" },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "filesystem root",
|
||||
env: { KIRO_HOME: "/" },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "home folder",
|
||||
env: { KIRO_HOME: "/home/alice" },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "ancestor of home",
|
||||
env: { KIRO_HOME: "/home" },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
{
|
||||
name: "home alias through ..",
|
||||
env: { KIRO_HOME: "/home/alice/profile/.." },
|
||||
configPath: "/home/alice/.kiro/settings/mcp.json",
|
||||
markerPath: "/home/alice/.kiro",
|
||||
},
|
||||
])(
|
||||
"resolves the Kiro root Kiro reads ($name)",
|
||||
({ env, configPath, markerPath }) => {
|
||||
const [client] = supportedClients("/home/alice", "linux", env, {}, "kiro");
|
||||
expect(client).toMatchObject({ name: "kiro", configPath, markerPath });
|
||||
expect(client?.configPathError).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "absolute KIRO_HOME",
|
||||
env: { KIRO_HOME: "C:\\work\\kiro" },
|
||||
configPath: "C:\\work\\kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\work\\kiro",
|
||||
},
|
||||
{
|
||||
name: "forward slashes",
|
||||
env: { KIRO_HOME: "C:/work/kiro/" },
|
||||
configPath: "C:\\work\\kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\work\\kiro",
|
||||
},
|
||||
{
|
||||
name: "another drive",
|
||||
env: { KIRO_HOME: "D:\\kiro" },
|
||||
configPath: "D:\\kiro\\settings\\mcp.json",
|
||||
markerPath: "D:\\kiro",
|
||||
},
|
||||
{
|
||||
name: "drive root",
|
||||
env: { KIRO_HOME: "C:\\" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "root of another drive",
|
||||
env: { KIRO_HOME: "D:\\" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "UNC share root",
|
||||
env: { KIRO_HOME: "\\\\server\\share\\" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "folder under a UNC share",
|
||||
env: { KIRO_HOME: "\\\\server\\share\\kiro" },
|
||||
configPath: "\\\\server\\share\\kiro\\settings\\mcp.json",
|
||||
markerPath: "\\\\server\\share\\kiro",
|
||||
},
|
||||
{
|
||||
name: "home folder in another case",
|
||||
env: { KIRO_HOME: "c:\\users\\ALICE" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "ancestor of home",
|
||||
env: { KIRO_HOME: "C:\\Users" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "drive-less rooted path",
|
||||
env: { KIRO_HOME: "\\kiro" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
{
|
||||
name: "drive-relative path",
|
||||
env: { KIRO_HOME: "C:kiro" },
|
||||
configPath: "C:\\Users\\alice\\.kiro\\settings\\mcp.json",
|
||||
markerPath: "C:\\Users\\alice\\.kiro",
|
||||
},
|
||||
])(
|
||||
"resolves the Windows Kiro root Kiro reads ($name)",
|
||||
({ env, configPath, markerPath }) => {
|
||||
const [client] = supportedClients(
|
||||
"C:\\Users\\alice",
|
||||
"win32",
|
||||
env,
|
||||
{},
|
||||
"kiro",
|
||||
);
|
||||
expect(client).toMatchObject({ name: "kiro", configPath, markerPath });
|
||||
expect(client?.configPathError).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "legacy default",
|
||||
@@ -793,3 +951,32 @@ it("refuses a relative MCPORTER_CONFIG whose file depends on each command's dire
|
||||
error: { message: expect.stringContaining("MCPORTER_CONFIG is relative") },
|
||||
});
|
||||
});
|
||||
|
||||
it("selects the default Kiro configuration through aliases of home and its ancestor", async () => {
|
||||
const root = await createTestTempDirectory("rea-kiro-home-identity-");
|
||||
const home = join(root, "home");
|
||||
const homeAlias = join(root, "home-alias");
|
||||
const ancestorAlias = join(root, "ancestor-alias");
|
||||
const alternative = join(root, "alternative");
|
||||
await mkdir(home);
|
||||
await mkdir(alternative);
|
||||
const linkType = process.platform === "win32" ? "junction" : "dir";
|
||||
await symlink(home, homeAlias, linkType);
|
||||
await symlink(root, ancestorAlias, linkType);
|
||||
for (const selected of [homeAlias, ancestorAlias, alternative]) {
|
||||
const [client] = supportedClients(
|
||||
home,
|
||||
process.platform,
|
||||
{ KIRO_HOME: selected },
|
||||
{},
|
||||
"kiro",
|
||||
);
|
||||
expect(client?.configPath).toBe(
|
||||
join(
|
||||
selected === alternative ? alternative : join(home, ".kiro"),
|
||||
"settings",
|
||||
"mcp.json",
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { isAbsentClientConfigPath, isEnoentError } from "./ClientConfigPath.js";
|
||||
import type {
|
||||
ClientRegistrationConnectionProfile,
|
||||
@@ -5,7 +6,7 @@ import type {
|
||||
} from "./ClientRegistrationProfile.js";
|
||||
import { dirname, join, posix, resolve, win32 } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { lstatSync, statSync } from "node:fs";
|
||||
import { lstatSync, realpathSync, statSync } from "node:fs";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
absoluteCallerPath,
|
||||
@@ -705,6 +706,68 @@ export const fxLocation = ({
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Kiro's global root: an absolute `KIRO_HOME` moves it, including
|
||||
* `settings/mcp.json`. Kiro ignores the variable and falls back to `~/.kiro`
|
||||
* when it is relative (or drive-less on Windows), the filesystem root, the
|
||||
* home folder, or an ancestor of home, so REA does the same instead of
|
||||
* refusing the value.
|
||||
*/
|
||||
export const kiroLocation = ({
|
||||
home,
|
||||
platform,
|
||||
env,
|
||||
}: ClientPathContext): Result<ClientLocation, ClientPathFailure> => {
|
||||
const pathApi = platform === "win32" ? win32 : posix;
|
||||
const fallback = pathApi.join(home, ".kiro");
|
||||
const at = (directory: string): ClientLocation => ({
|
||||
configPath: pathApi.join(directory, "settings", "mcp.json"),
|
||||
markerPath: directory,
|
||||
});
|
||||
const value = env.KIRO_HOME;
|
||||
if (!value || clientPathDependence(value, platform) !== undefined)
|
||||
return ok(at(fallback));
|
||||
const normalized = pathApi.normalize(value);
|
||||
const root = pathApi.parse(normalized).root;
|
||||
const selected =
|
||||
normalized.length > root.length
|
||||
? normalized.replace(platform === "win32" ? /[\\/]+$/u : /\/+$/u, "")
|
||||
: normalized;
|
||||
const comparable = (path: string): string =>
|
||||
platform === "win32" ? path.toLowerCase() : path;
|
||||
const isRootOrAncestor = (directory: string, userHome: string): boolean => {
|
||||
const relativeHome = pathApi.relative(
|
||||
comparable(directory),
|
||||
comparable(userHome),
|
||||
);
|
||||
return (
|
||||
comparable(directory) === comparable(pathApi.parse(directory).root) ||
|
||||
relativeHome === "" ||
|
||||
(relativeHome !== ".." &&
|
||||
!relativeHome.startsWith(`..${pathApi.sep}`) &&
|
||||
!pathApi.isAbsolute(relativeHome))
|
||||
);
|
||||
};
|
||||
if (isRootOrAncestor(selected, home)) return ok(at(fallback));
|
||||
if (platform === HOST_PLATFORM.platform) {
|
||||
let inspecting = selected;
|
||||
try {
|
||||
const physicalDirectory = realpathSync.native(selected);
|
||||
inspecting = home;
|
||||
const physicalHome = realpathSync.native(home);
|
||||
if (isRootOrAncestor(physicalDirectory, physicalHome))
|
||||
return ok(at(fallback));
|
||||
} catch (cause: unknown) {
|
||||
if (!isEnoentError(cause))
|
||||
return err({
|
||||
path: inspecting,
|
||||
message: `Could not verify the Kiro profile path ${inspecting}: ${errorMessage(cause)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
return ok(at(selected));
|
||||
};
|
||||
|
||||
/**
|
||||
* Junie's home: `JUNIE_HOME` for Junie CLI, else `~/.junie`. add-mcp notes the
|
||||
* JetBrains plugin always reads `~/.junie`. Junie resolves a relative
|
||||
|
||||
@@ -57,6 +57,7 @@ import {
|
||||
MCPORTER_URL_FIELDS,
|
||||
ampLocation,
|
||||
fxLocation,
|
||||
kiroLocation,
|
||||
junieLocation,
|
||||
gooseLocation,
|
||||
gooseConfigPaths,
|
||||
@@ -1159,8 +1160,7 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [
|
||||
},
|
||||
// The IDE, CLI and web clients share the user file.
|
||||
displayName: "Kiro",
|
||||
configPath: [".kiro", "settings", "mcp.json"],
|
||||
markerPath: [".kiro"],
|
||||
location: kiroLocation,
|
||||
format: "json",
|
||||
}),
|
||||
defineClient({
|
||||
|
||||
Vendored
+1
@@ -39,6 +39,7 @@ const CLIENT_LOCATION_ENVIRONMENT = [
|
||||
"KILO_CONFIG_DIR",
|
||||
"KILO_DISABLE_PROJECT_CONFIG",
|
||||
"KIMI_CODE_HOME",
|
||||
"KIRO_HOME",
|
||||
"MCPORTER_CONFIG",
|
||||
"LOCALAPPDATA",
|
||||
"OMP_PROFILE",
|
||||
|
||||
Reference in new issue
Block a user