refactor(mcp): share client configuration presence checks (#15708)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 00:54:42 +00:00
1 parent c40e85a9cf
commit 98c7ee53a0
1 file changed
+11 -30
+11 -30
View File
@@ -596,7 +596,10 @@ export const clineVscodeSettingsDirectory = clineSettingsDirectory("Code");
/** Flathub's Zed (`dev.zed.Zed`) gets this XDG_CONFIG_HOME inside its sandbox. */
const ZED_FLATPAK_CONFIG = [".var", "app", "dev.zed.Zed", "config"] as const;
const directoryPresent = (path: string): Result<boolean, ClientPathFailure> => {
const clientPathPresent = (
path: string,
client: string,
): Result<boolean, ClientPathFailure> => {
try {
lstatSync(path);
return ok(true);
@@ -604,7 +607,7 @@ const directoryPresent = (path: string): Result<boolean, ClientPathFailure> => {
if (isEnoentError(cause)) return ok(false);
return err({
path,
message: `Cannot determine whether ${path} exists: ${errorMessage(cause)}. Repair its access before configuring Zed.`,
message: `Cannot determine whether ${path} exists: ${errorMessage(cause)}. Repair its access before configuring ${client}.`,
});
}
};
@@ -664,10 +667,10 @@ export const zedLocation = ({
}
const native = join(absoluteXdgConfigHome({ home, env }), "zed");
const sandboxed = join(home, ...ZED_FLATPAK_CONFIG, "zed");
const flatpak = directoryPresent(sandboxed);
const flatpak = clientPathPresent(sandboxed, "Zed");
if (!flatpak.ok) return flatpak;
if (!flatpak.value) return ok(at(native));
const nativePresent = directoryPresent(native);
const nativePresent = clientPathPresent(native, "Zed");
if (!nativePresent.ok) return nativePresent;
if (!nativePresent.value) return ok(at(sandboxed));
// XDG_CONFIG_HOME or a link may make both names one folder.
@@ -681,21 +684,6 @@ export const zedLocation = ({
});
};
const regularPathPresent = (
path: string,
): Result<boolean, ClientPathFailure> => {
try {
lstatSync(path);
return ok(true);
} catch (cause: unknown) {
if (isEnoentError(cause)) return ok(false);
return err({
path,
message: `Cannot determine whether ${path} exists: ${errorMessage(cause)}. Repair its access before configuring MCPorter.`,
});
}
};
/**
* MCPorter's home layer (`listConfigLayerPaths`): a non-empty
* `MCPORTER_CONFIG` is the only file it loads; otherwise the first existing of
@@ -738,7 +726,7 @@ export const mcporterLocation = ({
],
);
for (const candidate of candidates) {
const present = regularPathPresent(candidate);
const present = clientPathPresent(candidate, "MCPorter");
if (!present.ok) return present;
// The loaded file's folder is the evidence, even when it is the legacy one.
if (present.value)
@@ -792,16 +780,9 @@ export const ampLocation = ({
const candidates = AMP_SETTINGS_FILES.map((name) => join(directory, name));
const present: string[] = [];
for (const candidate of candidates) {
try {
lstatSync(candidate);
present.push(candidate);
} catch (cause: unknown) {
if (!isEnoentError(cause))
return err({
path: candidate,
message: `Cannot determine whether ${candidate} exists: ${errorMessage(cause)}. Repair its access before configuring Amp.`,
});
}
const found = clientPathPresent(candidate, "Amp");
if (!found.ok) return found;
if (found.value) present.push(candidate);
}
if (present.length > 1)
return err({