fix(setup): resolve the configuration MSIX Claude Desktop reads (#2426)
* fix(setup): resolve the configuration MSIX Claude Desktop reads On Windows, setup, doctor and uninstall always used %APPDATA%\Claude\claude_desktop_config.json. The MSIX build of Claude Desktop (package family Claude_pzs8sxrjxfjjc) virtualizes AppData writes and reads its package-private copy under %LOCALAPPDATA%\Packages\<family>\LocalCache\Roaming\Claude once it exists. Setup from an ordinary process therefore wrote a file the app never reads, and doctor reported that file healthy. Resolve the Claude Desktop location once, in supportedClients(): the private copy when it exists, else the AppData file the package still reads, else a new private copy. An unrecognized Claude_* publisher or unreadable package storage is reported instead of falling back to AppData. Compare one of the package's private files with its AppData path through realpath.native to learn whether the running package started this process. From that redirected view, or when no file can be compared, setup and uninstall refuse to change Claude Desktop's configuration, because the running app rewrites it from memory. From a redirected view they also refuse writes under %APPDATA% and %LOCALAPPDATA% for other clients and skills, which would land in the package's private storage. Setup refuses to register a launcher stored in any MSIX package's private storage, discloses which file the package reads, and tells the user to quit Claude Desktop fully on every platform. Configuration fails with target_changed if the package switched to its private copy after the plan was shown. Uninstall removes REA from both files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(setup): record the verified MSIX Claude Desktop registration On the Windows 11 host with the MSIX build 2.31226.1.0, setup from an ordinary terminal with the app quit wrote the package-private copy. After the app restarted, the entry persisted, doctor reported it aligned, and Claude Desktop's MCP log showed REA starting and answering tools/list. Uninstall against the real app remains unverified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style(setup): format MSIX review corrections * fix(setup): carry the admitted legacy path through uninstall removal clientRegistrationRemoval returned a removeLegacy boolean, and removeClient recomputed the legacy path separately, so TypeScript could not prove the path existed when removeLegacy was true and `tsc --noEmit` failed in Uninstall.ts. The decision now returns the admitted legacy path itself; preflight and removal consume that one value. The alias regression matched new-destination children with a "/" separator while building paths with path.join, so it failed on Windows. It now uses path.sep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(setup): split MSIX Claude Desktop lifecycle cases under the function length limit The uninstall cases pushed the registration lifecycle describe past the 150-line lint limit. Group them separately, with the AppData registration case kept among the registration cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
morluto
parent
5996d8160f
commit
fd65e278be
@@ -7,6 +7,8 @@ import {
|
||||
resolveHermesClientHome,
|
||||
} from "./HermesClientHome.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
import { resolveWindowsClaudeDesktopLocation } from "./ClaudeDesktopConfigLocation.js";
|
||||
import type { MsixPackageView } from "./MsixPackageStorage.js";
|
||||
|
||||
/** One supported client configuration location. */
|
||||
export interface SetupClient {
|
||||
@@ -29,6 +31,10 @@ export interface SetupClient {
|
||||
/** Same-scope fallback ZCode stops loading after its first native server. */
|
||||
readonly zcodeFallbackPath?: string;
|
||||
readonly markerPath?: string;
|
||||
/** MSIX package storage that decides which configuration the client reads. */
|
||||
readonly msixPackage?: MsixPackageView;
|
||||
/** A running client can rewrite its configuration from memory. */
|
||||
readonly quitBeforeSetup?: boolean;
|
||||
readonly format?:
|
||||
| "json"
|
||||
| "toml"
|
||||
@@ -61,12 +67,35 @@ interface ClientPathContext {
|
||||
readonly env: Readonly<NodeJS.ProcessEnv>;
|
||||
}
|
||||
|
||||
interface ClientDefinition {
|
||||
/** One resolved configuration location and its detection evidence. */
|
||||
interface ClientLocation {
|
||||
readonly configPath: string;
|
||||
readonly markerPath: string;
|
||||
readonly msixPackage?: MsixPackageView;
|
||||
}
|
||||
|
||||
type ClientDefinition = ClientDefinitionBase &
|
||||
(
|
||||
| {
|
||||
readonly configPath: ClientPath;
|
||||
readonly markerPath: ClientPath;
|
||||
readonly location?: undefined;
|
||||
}
|
||||
| {
|
||||
/** Resolve configuration and marker together when they share probes. */
|
||||
readonly location: (
|
||||
context: ClientPathContext,
|
||||
) => Result<ClientLocation, ClientPathFailure>;
|
||||
readonly configPath?: undefined;
|
||||
readonly markerPath?: undefined;
|
||||
}
|
||||
);
|
||||
|
||||
interface ClientDefinitionBase {
|
||||
readonly name: string;
|
||||
readonly displayName: string;
|
||||
readonly configPath: ClientPath;
|
||||
readonly markerPath: ClientPath;
|
||||
readonly format: NonNullable<SetupClient["format"]>;
|
||||
readonly quitBeforeSetup?: boolean;
|
||||
readonly zcodeFallbackPath?: (context: ClientPathContext) => string;
|
||||
readonly skillPath?: ClientPath;
|
||||
readonly configPaths?: (context: ClientPathContext) => readonly string[];
|
||||
@@ -111,16 +140,20 @@ const traeUserDirectory = ({
|
||||
return join(xdgConfigHome({ home, platform, env }), "Trae", "User");
|
||||
};
|
||||
|
||||
const claudeDesktopDirectory = ({
|
||||
home,
|
||||
platform,
|
||||
env,
|
||||
}: ClientPathContext): string => {
|
||||
if (platform === "win32")
|
||||
return join(env.APPDATA ?? join(home, "AppData", "Roaming"), "Claude");
|
||||
if (platform === "linux")
|
||||
return join(xdgConfigHome({ home, platform, env }), "Claude");
|
||||
return join(home, "Library", "Application Support", "Claude");
|
||||
/** Windows packaging decides which file Claude Desktop reads; see its resolver. */
|
||||
const claudeDesktopLocation = (
|
||||
context: ClientPathContext,
|
||||
): Result<ClientLocation, ClientPathFailure> => {
|
||||
if (context.platform === "win32")
|
||||
return resolveWindowsClaudeDesktopLocation(context.home, context.env);
|
||||
const directory =
|
||||
context.platform === "linux"
|
||||
? join(xdgConfigHome(context), "Claude")
|
||||
: join(context.home, "Library", "Application Support", "Claude");
|
||||
return ok({
|
||||
configPath: join(directory, "claude_desktop_config.json"),
|
||||
markerPath: directory,
|
||||
});
|
||||
};
|
||||
|
||||
const claudeCodeConfigDirectory = ({ home, env }: ClientPathContext): string =>
|
||||
@@ -211,6 +244,55 @@ export const manualRegistrationRemediation = (
|
||||
? GROK_BOT_MANUAL_REGISTRATION_REMEDIATION
|
||||
: undefined;
|
||||
|
||||
/**
|
||||
* Facts a setup plan must disclose so an approved registration persists:
|
||||
* which file an MSIX package reads, and that a running client can overwrite it.
|
||||
*/
|
||||
export const registrationPersistenceDetail = (
|
||||
client: SetupClient,
|
||||
): string | undefined => {
|
||||
const name = client.displayName ?? client.name;
|
||||
const msix = client.msixPackage;
|
||||
const packageDetail =
|
||||
msix === undefined
|
||||
? undefined
|
||||
: client.configPath === msix.privateConfigPath
|
||||
? `${name} is installed as MSIX package ${msix.packageFamilyName}, which reads this package-private file instead of ${msix.appDataConfigPath}.`
|
||||
: `${name} is installed as MSIX package ${msix.packageFamilyName}, which reads this file until it saves its own copy at ${msix.privateConfigPath}.`;
|
||||
const quitDetail =
|
||||
client.quitBeforeSetup === true
|
||||
? `Quit ${name} fully before approving; closing its window is not enough. A running ${name} can rewrite this file from memory and drop the registration. Start it again after setup.`
|
||||
: undefined;
|
||||
const details = [packageDetail, quitDetail].filter(
|
||||
(detail): detail is string => detail !== undefined,
|
||||
);
|
||||
return details.length === 0 ? undefined : details.join(" ");
|
||||
};
|
||||
|
||||
/**
|
||||
* Why this process must not change an MSIX client's configuration. A process
|
||||
* the running app started sees its redirected AppData, and the app would
|
||||
* overwrite the change from memory; an unknown view cannot rule that out.
|
||||
*/
|
||||
export const registrationWriteBlocker = (
|
||||
client: SetupClient,
|
||||
operation: "setup" | "uninstall",
|
||||
): string | undefined => {
|
||||
const msix = client.msixPackage;
|
||||
if (msix === undefined || msix.processView === "direct") return undefined;
|
||||
const name = client.displayName ?? client.name;
|
||||
return msix.processView === "redirected"
|
||||
? `This process was started from ${name}'s MSIX package ${msix.packageFamilyName}: its AppData is redirected into that package, so ${name} is running and would overwrite ${msix.privateConfigPath} from memory. Quit ${name} fully, then rerun ${operation} from a terminal that ${name} did not start.`
|
||||
: `REA cannot tell whether ${name}'s MSIX package ${msix.packageFamilyName} started this process, because none of its files under ${dirname(msix.privateConfigPath)} could be compared with ${dirname(msix.appDataConfigPath)}. A running ${name} would overwrite the change. Open ${name} once if it has never run, quit it fully, then rerun ${operation} from a terminal that ${name} did not start.`;
|
||||
};
|
||||
|
||||
/** The MSIX package view, if any, that redirects this process's AppData writes. */
|
||||
export const appDataRedirection = (
|
||||
clients: readonly SetupClient[],
|
||||
): MsixPackageView | undefined =>
|
||||
clients.find(({ msixPackage }) => msixPackage?.processView === "redirected")
|
||||
?.msixPackage;
|
||||
|
||||
const OMP_PROFILE_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/u;
|
||||
const OMP_RESERVED_PROFILE =
|
||||
/^(?:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\..*)?$/iu;
|
||||
@@ -408,9 +490,8 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [
|
||||
{
|
||||
name: "claude_desktop",
|
||||
displayName: "Claude Desktop",
|
||||
configPath: (context: ClientPathContext) =>
|
||||
join(claudeDesktopDirectory(context), "claude_desktop_config.json"),
|
||||
markerPath: claudeDesktopDirectory,
|
||||
location: claudeDesktopLocation,
|
||||
quitBeforeSetup: true,
|
||||
format: "json",
|
||||
},
|
||||
{
|
||||
@@ -627,6 +708,19 @@ const resolvePath = (
|
||||
return typeof resolved === "string" ? ok(resolved) : resolved;
|
||||
};
|
||||
|
||||
const resolveLocation = (
|
||||
definition: ClientDefinition,
|
||||
context: ClientPathContext,
|
||||
): Result<ClientLocation, ClientPathFailure> => {
|
||||
if (definition.location !== undefined) return definition.location(context);
|
||||
const config = resolvePath(definition.configPath, context);
|
||||
if (!config.ok) return config;
|
||||
const marker = resolvePath(definition.markerPath, context);
|
||||
return marker.ok
|
||||
? ok({ configPath: config.value, markerPath: marker.value })
|
||||
: marker;
|
||||
};
|
||||
|
||||
/** Describe every client location that setup, doctor, or uninstall may inspect. */
|
||||
export const supportedClients = (
|
||||
home: string,
|
||||
@@ -637,27 +731,16 @@ export const supportedClients = (
|
||||
const definitions: readonly ClientDefinition[] = SUPPORTED_CLIENT_DEFINITIONS;
|
||||
return definitions.map((definition) => {
|
||||
try {
|
||||
const config = resolvePath(definition.configPath, context);
|
||||
const marker = config.ok
|
||||
? resolvePath(definition.markerPath, context)
|
||||
: config;
|
||||
if (!config.ok)
|
||||
const location = resolveLocation(definition, context);
|
||||
if (!location.ok)
|
||||
return {
|
||||
name: definition.name,
|
||||
displayName: definition.displayName,
|
||||
format: definition.format,
|
||||
configPath: config.error.path,
|
||||
configPathError: config.error.message,
|
||||
configPath: location.error.path,
|
||||
configPathError: location.error.message,
|
||||
};
|
||||
if (!marker.ok)
|
||||
return {
|
||||
name: definition.name,
|
||||
displayName: definition.displayName,
|
||||
format: definition.format,
|
||||
configPath: marker.error.path,
|
||||
configPathError: marker.error.message,
|
||||
};
|
||||
const configPath = config.value;
|
||||
const { configPath, markerPath, msixPackage } = location.value;
|
||||
return {
|
||||
name: definition.name,
|
||||
displayName: definition.displayName,
|
||||
@@ -675,7 +758,11 @@ export const supportedClients = (
|
||||
...(definition.zcodeFallbackPath === undefined
|
||||
? {}
|
||||
: { zcodeFallbackPath: definition.zcodeFallbackPath(context) }),
|
||||
markerPath: marker.value,
|
||||
markerPath,
|
||||
...(msixPackage === undefined ? {} : { msixPackage }),
|
||||
...(definition.quitBeforeSetup === true
|
||||
? { quitBeforeSetup: true }
|
||||
: {}),
|
||||
format: definition.format,
|
||||
};
|
||||
} catch (cause: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user