fix(setup): recognize shared CLI launcher aliases (#4803)
This commit is contained in:
1 parent
d38f099692
commit
c1fe0d653d
4 files changed
+135
-25
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { realpathSync } from "node:fs";
|
||||
import { isAbsolute, resolve } from "node:path";
|
||||
import { valid } from "semver";
|
||||
|
||||
@@ -115,6 +116,19 @@ const isOwnedPackageReference = (packageReference: string): boolean => {
|
||||
/** Check that one parsed command points to REA's MCP entry point. */
|
||||
export type ClientRegistrationCommandIdentity = "owned" | "foreign" | "unknown";
|
||||
|
||||
/** POSIX bin links can name the same dispatcher without changing stored commands. */
|
||||
const sameEntrypointPath = (candidate: string, current: string): boolean => {
|
||||
if (!isAbsolute(candidate) || !isAbsolute(current)) return false;
|
||||
if (resolve(candidate) === current) return true;
|
||||
// Windows package bins are command shims, not links to the dispatcher.
|
||||
if (process.platform === "win32") return false;
|
||||
try {
|
||||
return realpathSync(candidate) === realpathSync(current);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/** Classify only what the command and current executable identity establish. */
|
||||
export const classifyClientRegistrationCommand = (
|
||||
command: readonly string[],
|
||||
@@ -164,7 +178,7 @@ export const isOwnedClientRegistrationCommand = (
|
||||
isAbsolute(command[0] ?? "") &&
|
||||
isAbsolute(command[1] ?? "") &&
|
||||
resolve(command[0] ?? "") === resolve(process.execPath) &&
|
||||
resolve(command[1] ?? "") === currentCommandPath
|
||||
sameEntrypointPath(command[1] ?? "", currentCommandPath)
|
||||
)
|
||||
return true;
|
||||
|
||||
@@ -175,7 +189,7 @@ export const isOwnedClientRegistrationCommand = (
|
||||
(isAbsolute(executable) &&
|
||||
currentCommandPath !== undefined &&
|
||||
currentCommandPath.length > 0 &&
|
||||
resolve(executable) === currentCommandPath)
|
||||
sameEntrypointPath(executable, currentCommandPath))
|
||||
)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
type ClientConfigurationDocument,
|
||||
} from "./ClientConfigurationDocument.js";
|
||||
import { access } from "node:fs/promises";
|
||||
import { isAbsolute, resolve } from "node:path";
|
||||
import { isAbsolute } from "node:path";
|
||||
|
||||
import { z } from "zod";
|
||||
import { valid } from "semver";
|
||||
@@ -403,27 +403,11 @@ const registrationAligned = ({
|
||||
})
|
||||
)
|
||||
return "aligned";
|
||||
if (
|
||||
currentCommandPath !== undefined &&
|
||||
currentCommandPath.length > 0 &&
|
||||
command.length === 3 &&
|
||||
command[2] === "mcp" &&
|
||||
isAbsolute(command[0] ?? "") &&
|
||||
isAbsolute(command[1] ?? "") &&
|
||||
resolve(command[0] ?? "") === resolve(process.execPath) &&
|
||||
resolve(command[1] ?? "") === currentCommandPath
|
||||
)
|
||||
return "aligned";
|
||||
if (
|
||||
currentCommandPath !== undefined &&
|
||||
currentCommandPath.length > 0 &&
|
||||
command.length === 2 &&
|
||||
command[1] === "mcp" &&
|
||||
isAbsolute(command[0] ?? "") &&
|
||||
resolve(command[0] ?? "") === currentCommandPath
|
||||
)
|
||||
return "aligned";
|
||||
return "stale";
|
||||
// Other owned package references remain stale until pinned to this version.
|
||||
if (clientRegistrationPackageReference(command) !== undefined) return "stale";
|
||||
// The identity owner already established an exact direct launcher match.
|
||||
// A bare command still depends on the client's PATH, so cannot prove alignment.
|
||||
return isAbsolute(command[0] ?? "") ? "aligned" : "stale";
|
||||
};
|
||||
|
||||
const parseRegistration = (
|
||||
|
||||
Reference in new issue
Block a user