refactor(setup): reuse unresolved registration status projection (#15742)

This commit is contained in:
Vincent Koc
2026-12-02 10:38:11 +08:00
committed by GitHub
parent d81ec9193f
commit cd2f4dd985
+74 -108
View File
@@ -271,17 +271,33 @@ export const readClientRegistrationInspections = async (
...(readOnlyRegistration ? { readOnlyRegistration: true } : {}),
});
};
const recordUnavailable = (
state: "missing" | "invalid" | "manual" | "unknown",
{
path = client.configPath,
scope,
message = remediation(client, path, scope),
}: {
readonly path?: string;
readonly scope?: ClientRegistrationScope | undefined;
readonly message?: string;
} = {},
): void =>
record({
client: client.name,
config_path: path,
...(scope === undefined ? {} : { scope }),
command: [],
command_identity: "unknown",
state,
remediation: message,
});
const selected = options.selectedClientIds?.includes(client.name) === true;
// An unresolved location leaves this client's registration unknown, never
// absent; diagnostics and maintenance still cover every other client.
if (client.configPathError !== undefined) {
record({
client: client.name,
config_path: client.configPath,
command: [],
command_identity: "unknown",
state: "unknown",
remediation: client.configPathError,
recordUnavailable("unknown", {
message: client.configPathError,
});
continue;
}
@@ -312,13 +328,9 @@ export const readClientRegistrationInspections = async (
const manualRemediation = manualRegistrationRemediation(client.name);
if (client.format === "unsupported") {
if (manualRemediation !== undefined)
record({
client: client.name,
config_path: client.markerPath ?? client.configPath,
command: [],
command_identity: "unknown",
state: "manual",
remediation: manualRemediation,
recordUnavailable("manual", {
path: client.markerPath ?? client.configPath,
message: manualRemediation,
});
continue;
}
@@ -342,25 +354,17 @@ export const readClientRegistrationInspections = async (
managed.error.cleanupFailure !== undefined
)
throw managed.error.cleanupFailure;
record({
client: client.name,
config_path: managed.error.path,
command: [],
command_identity: "unknown",
state: "invalid",
remediation: managed.error.detail,
recordUnavailable("invalid", {
path: managed.error.path,
message: managed.error.detail,
});
continue;
}
const controlled = claudeCodeMcpBlock(managed.value, undefined);
if (controlled !== undefined) {
record({
client: client.name,
config_path: controlled.path,
command: [],
command_identity: "unknown",
state: "manual",
remediation: controlled.reason,
recordUnavailable("manual", {
path: controlled.path,
message: controlled.reason,
});
continue;
}
@@ -371,30 +375,25 @@ export const readClientRegistrationInspections = async (
project,
);
if (!configuration.ok) {
const { error } = configuration;
if (
options.resources === undefined &&
configuration.error.cleanupFailure !== undefined
error.cleanupFailure !== undefined
)
throw configuration.error.cleanupFailure;
record({
client: client.name,
config_path: configuration.error.path,
...(configuration.error.scope === "project"
? { scope: "project" }
: {}),
command: [],
command_identity: "unknown",
state:
configuration.error.kind === "unresolved" ||
configuration.error.kind === "unknown_project_root"
? "unknown"
: "invalid",
remediation:
configuration.error.scope === "project" &&
configuration.error.kind !== "unknown_project_root"
? `${configuration.error.detail} REA setup writes only user-level configuration and does not modify project-scoped configuration at ${configuration.error.path}. Repair or remove ${configuration.error.path}, then rerun rea doctor.`
: configuration.error.detail,
});
throw error.cleanupFailure;
recordUnavailable(
error.kind === "unresolved" || error.kind === "unknown_project_root"
? "unknown"
: "invalid",
{
path: error.path,
scope: error.scope === "project" ? "project" : undefined,
message:
error.scope === "project" && error.kind !== "unknown_project_root"
? `${error.detail} REA setup writes only user-level configuration and does not modify project-scoped configuration at ${error.path}. Repair or remove ${error.path}, then rerun rea doctor.`
: error.detail,
},
);
continue;
}
caution = configuration.value.upperLayerCaution;
@@ -415,25 +414,17 @@ export const readClientRegistrationInspections = async (
qwen.error.cleanupFailure !== undefined
)
throw qwen.error.cleanupFailure;
record({
client: client.name,
config_path: qwen.error.path,
command: [],
command_identity: "unknown",
state: "invalid",
remediation: qwen.error.detail,
recordUnavailable("invalid", {
path: qwen.error.path,
message: qwen.error.detail,
});
continue;
}
qwenBlock = qwenMcpRegistrationBlock(qwen.value);
if (qwen.value.exclusion !== undefined && qwenBlock !== undefined) {
record({
client: client.name,
config_path: qwen.value.exclusion.path,
command: [],
command_identity: "unknown",
state: "manual",
remediation: qwenBlock,
recordUnavailable("manual", {
path: qwen.value.exclusion.path,
message: qwenBlock,
});
continue;
}
@@ -468,9 +459,10 @@ export const readClientRegistrationInspections = async (
selected || client.registrationApplicability !== true;
if (parsed === undefined) {
if (reportsAbsence)
record(
unavailableStatus(client, "missing", configPath, selectedScope),
);
recordUnavailable("missing", {
path: configPath,
scope: selectedScope,
});
continue;
}
const raw = effectiveClientServer(parsed, PRODUCT_IDENTITY.mcpServerKey);
@@ -493,14 +485,10 @@ export const readClientRegistrationInspections = async (
policy.error.cleanupFailure !== undefined
)
throw policy.error.cleanupFailure;
record({
client: client.name,
config_path: configPath,
...(selectedScope === undefined ? {} : { scope: selectedScope }),
command: [],
command_identity: "unknown",
state: "invalid",
remediation: policy.error.detail,
recordUnavailable("invalid", {
path: configPath,
scope: selectedScope,
message: policy.error.detail,
});
continue;
}
@@ -513,21 +501,18 @@ export const readClientRegistrationInspections = async (
? dshDocument(parsed.document).editabilityError
: undefined;
if (editabilityError !== undefined) {
record({
client: client.name,
config_path: configPath,
...(selectedScope === undefined ? {} : { scope: selectedScope }),
command: [],
command_identity: "unknown",
state: "invalid",
remediation: editabilityError.message,
recordUnavailable("invalid", {
path: configPath,
scope: selectedScope,
message: editabilityError.message,
});
continue;
}
if (reportsAbsence)
record(
unavailableStatus(client, "missing", configPath, selectedScope),
);
recordUnavailable("missing", {
path: configPath,
scope: selectedScope,
});
continue;
}
const effectiveClient: SetupClient =
@@ -814,14 +799,10 @@ export const readClientRegistrationInspections = async (
cause instanceof RegularFileCleanupFailure
)
throw cause;
record(
unavailableStatus(
client,
isEnoentError(cause) ? "missing" : "invalid",
selectedConfigPath,
selectedScope,
),
);
recordUnavailable(isEnoentError(cause) ? "missing" : "invalid", {
path: selectedConfigPath,
scope: selectedScope,
});
}
}
return inspections.sort((left, right) =>
@@ -1126,21 +1107,6 @@ const packageLauncherRemediation = (
return `This project-scoped registration in ${launcher.path} ${packageDetail}. ${repair} Restart the client after making the change.`;
};
const unavailableStatus = (
client: SetupClient,
state: "missing" | "invalid",
configPath: string = client.configPath,
scope?: ClientRegistrationScope,
): ClientRegistrationStatus => ({
client: client.name,
config_path: configPath,
...(scope === undefined ? {} : { scope }),
command: [],
command_identity: "unknown",
state,
remediation: remediation(client, configPath, scope),
});
/** Product discovery follows targets; configuration evidence retains entry presence. */
const clientEvidencePresent = async (
client: SetupClient,