fix(update): share parsed client activation with maintenance
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
clientServerForcedEnabled,
|
clientServerForcedEnabled,
|
||||||
clientServerListedDisabled,
|
clientServerListedDisabled,
|
||||||
effectiveClientServer,
|
effectiveClientServer,
|
||||||
|
type ClientConfigurationDocument,
|
||||||
} from "./ClientConfigurationDocument.js";
|
} from "./ClientConfigurationDocument.js";
|
||||||
import { access } from "node:fs/promises";
|
import { access } from "node:fs/promises";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
@@ -74,24 +75,48 @@ const registrationSchema = z
|
|||||||
})
|
})
|
||||||
.passthrough();
|
.passthrough();
|
||||||
|
|
||||||
/** Inspect supported client registrations without reading their environment. */
|
interface ClientRegistrationReadOptions {
|
||||||
|
readonly platform?: NodeJS.Platform;
|
||||||
|
readonly environment?: NodeJS.ProcessEnv;
|
||||||
|
readonly resources?: ArtifactResourceScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Registration facts shared by diagnostics and update maintenance. */
|
||||||
|
export interface ClientRegistrationInspection {
|
||||||
|
readonly status: ClientRegistrationStatus;
|
||||||
|
readonly activation: "enabled" | "disabled" | "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Project diagnostics from the same inspection used to select maintenance. */
|
||||||
export const readClientRegistrationStatuses = async (
|
export const readClientRegistrationStatuses = async (
|
||||||
home: string,
|
home: string,
|
||||||
currentCommandPath: string = resolve(process.argv[1] ?? "unknown"),
|
currentCommandPath: string = resolve(process.argv[1] ?? "unknown"),
|
||||||
options: {
|
options: ClientRegistrationReadOptions = {},
|
||||||
readonly platform?: NodeJS.Platform;
|
): Promise<readonly ClientRegistrationStatus[]> =>
|
||||||
readonly environment?: NodeJS.ProcessEnv;
|
(
|
||||||
readonly resources?: ArtifactResourceScope;
|
await readClientRegistrationInspections(home, currentCommandPath, options)
|
||||||
} = {},
|
).map(({ status }) => status);
|
||||||
): Promise<readonly ClientRegistrationStatus[]> => {
|
|
||||||
const statuses: ClientRegistrationStatus[] = [];
|
/** Parse effective registrations and their client-specific activation once. */
|
||||||
|
export const readClientRegistrationInspections = async (
|
||||||
|
home: string,
|
||||||
|
currentCommandPath: string = resolve(process.argv[1] ?? "unknown"),
|
||||||
|
options: ClientRegistrationReadOptions = {},
|
||||||
|
): Promise<readonly ClientRegistrationInspection[]> => {
|
||||||
|
const inspections: ClientRegistrationInspection[] = [];
|
||||||
|
const record = (
|
||||||
|
status: ClientRegistrationStatus,
|
||||||
|
activation: ClientRegistrationInspection["activation"] = "unknown",
|
||||||
|
): void => {
|
||||||
|
inspections.push({ status, activation });
|
||||||
|
};
|
||||||
for (const client of supportedClients(
|
for (const client of supportedClients(
|
||||||
home,
|
home,
|
||||||
options.platform,
|
options.platform,
|
||||||
options.environment,
|
options.environment,
|
||||||
)) {
|
)) {
|
||||||
if (client.configPathError !== undefined) {
|
if (client.configPathError !== undefined) {
|
||||||
statuses.push({
|
record({
|
||||||
client: client.name,
|
client: client.name,
|
||||||
config_path: client.configPath,
|
config_path: client.configPath,
|
||||||
command: [],
|
command: [],
|
||||||
@@ -104,7 +129,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
const manualRemediation = manualRegistrationRemediation(client.name);
|
const manualRemediation = manualRegistrationRemediation(client.name);
|
||||||
if (client.format === "unsupported") {
|
if (client.format === "unsupported") {
|
||||||
if (manualRemediation !== undefined)
|
if (manualRemediation !== undefined)
|
||||||
statuses.push({
|
record({
|
||||||
client: client.name,
|
client: client.name,
|
||||||
config_path: client.markerPath ?? client.configPath,
|
config_path: client.markerPath ?? client.configPath,
|
||||||
command: [],
|
command: [],
|
||||||
@@ -119,7 +144,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
options.resources,
|
options.resources,
|
||||||
);
|
);
|
||||||
if (!files.ok) {
|
if (!files.ok) {
|
||||||
statuses.push({
|
record({
|
||||||
client: client.name,
|
client: client.name,
|
||||||
config_path: client.configPath,
|
config_path: client.configPath,
|
||||||
command: [],
|
command: [],
|
||||||
@@ -130,9 +155,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
}
|
}
|
||||||
const parsed = effectiveClientConfiguration(files.value);
|
const parsed = effectiveClientConfiguration(files.value);
|
||||||
if (parsed === undefined) {
|
if (parsed === undefined) {
|
||||||
statuses.push(
|
record(unavailableStatus(client.name, client.configPath, "missing"));
|
||||||
unavailableStatus(client.name, client.configPath, "missing"),
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const policy = await readClientPolicyBlock(
|
const policy = await readClientPolicyBlock(
|
||||||
@@ -142,7 +165,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
options.resources,
|
options.resources,
|
||||||
);
|
);
|
||||||
if (!policy.ok) {
|
if (!policy.ok) {
|
||||||
statuses.push({
|
record({
|
||||||
client: client.name,
|
client: client.name,
|
||||||
config_path: client.configPath,
|
config_path: client.configPath,
|
||||||
command: [],
|
command: [],
|
||||||
@@ -159,7 +182,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
? dshDocument(parsed.document).editabilityError
|
? dshDocument(parsed.document).editabilityError
|
||||||
: undefined;
|
: undefined;
|
||||||
if (editabilityError !== undefined) {
|
if (editabilityError !== undefined) {
|
||||||
statuses.push({
|
record({
|
||||||
client: client.name,
|
client: client.name,
|
||||||
config_path: client.configPath,
|
config_path: client.configPath,
|
||||||
command: [],
|
command: [],
|
||||||
@@ -168,9 +191,7 @@ export const readClientRegistrationStatuses = async (
|
|||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
statuses.push(
|
record(unavailableStatus(client.name, client.configPath, "missing"));
|
||||||
unavailableStatus(client.name, client.configPath, "missing"),
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const registration = parseRegistration(raw, client);
|
const registration = parseRegistration(raw, client);
|
||||||
@@ -178,21 +199,18 @@ export const readClientRegistrationStatuses = async (
|
|||||||
registration.command,
|
registration.command,
|
||||||
...registration.args,
|
...registration.args,
|
||||||
];
|
];
|
||||||
statuses.push(
|
const activation = registrationActivation(registration, client, parsed);
|
||||||
|
record(
|
||||||
configuredStatus(
|
configuredStatus(
|
||||||
client.name,
|
client.name,
|
||||||
client.configPath,
|
client.configPath,
|
||||||
command,
|
command,
|
||||||
registrationAligned(
|
activation === "enabled" &&
|
||||||
registration,
|
registrationAligned(
|
||||||
client,
|
registration,
|
||||||
currentCommandPath,
|
client,
|
||||||
options.platform ?? process.platform,
|
currentCommandPath,
|
||||||
clientServerForcedEnabled(parsed, PRODUCT_IDENTITY.mcpServerKey),
|
options.platform ?? process.platform,
|
||||||
) &&
|
|
||||||
!clientServerListedDisabled(
|
|
||||||
parsed,
|
|
||||||
PRODUCT_IDENTITY.mcpServerKey,
|
|
||||||
) &&
|
) &&
|
||||||
(parsed.dialect !== "dsh" || dshDocument(parsed.document).ready) &&
|
(parsed.dialect !== "dsh" || dshDocument(parsed.document).ready) &&
|
||||||
policyBlock === undefined
|
policyBlock === undefined
|
||||||
@@ -200,9 +218,10 @@ export const readClientRegistrationStatuses = async (
|
|||||||
: "stale",
|
: "stale",
|
||||||
policyBlock,
|
policyBlock,
|
||||||
),
|
),
|
||||||
|
activation,
|
||||||
);
|
);
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
statuses.push(
|
record(
|
||||||
unavailableStatus(
|
unavailableStatus(
|
||||||
client.name,
|
client.name,
|
||||||
client.configPath,
|
client.configPath,
|
||||||
@@ -211,26 +230,31 @@ export const readClientRegistrationStatuses = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return statuses.sort((left, right) =>
|
return inspections.sort((left, right) =>
|
||||||
compareUnicodeCodePoints(left.client, right.client),
|
compareUnicodeCodePoints(left.status.client, right.status.client),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const registrationActivation = (
|
||||||
|
registration: z.output<typeof registrationSchema>,
|
||||||
|
client: SetupClient,
|
||||||
|
parsed: ClientConfigurationDocument,
|
||||||
|
): "enabled" | "disabled" =>
|
||||||
|
(client.format !== "grok" && registration.disabled === true) ||
|
||||||
|
(registration.enabled === false &&
|
||||||
|
!clientServerForcedEnabled(parsed, PRODUCT_IDENTITY.mcpServerKey)) ||
|
||||||
|
(client.format === "zcode" && registration.enable === false) ||
|
||||||
|
clientServerListedDisabled(parsed, PRODUCT_IDENTITY.mcpServerKey)
|
||||||
|
? "disabled"
|
||||||
|
: "enabled";
|
||||||
|
|
||||||
const registrationAligned = (
|
const registrationAligned = (
|
||||||
registration: z.output<typeof registrationSchema>,
|
registration: z.output<typeof registrationSchema>,
|
||||||
client: SetupClient,
|
client: SetupClient,
|
||||||
currentCommandPath: string,
|
currentCommandPath: string,
|
||||||
platform: NodeJS.Platform,
|
platform: NodeJS.Platform,
|
||||||
forcedEnabled = false,
|
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const command = [registration.command, ...registration.args];
|
const command = [registration.command, ...registration.args];
|
||||||
if (
|
|
||||||
(client.format !== "grok" && registration.disabled === true) ||
|
|
||||||
(registration.enabled === false && !forcedEnabled) ||
|
|
||||||
// ZCode's native flag is `enable`; other dialects leave that field opaque.
|
|
||||||
(client.format === "zcode" && registration.enable === false)
|
|
||||||
)
|
|
||||||
return false;
|
|
||||||
if (!isOwnedClientRegistrationCommand(command, currentCommandPath))
|
if (!isOwnedClientRegistrationCommand(command, currentCommandPath))
|
||||||
return false;
|
return false;
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1,19 +1,10 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
|
||||||
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
|
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
|
||||||
import { readClientRegistrationStatuses } from "./ClientRegistrationStatus.js";
|
import { readClientRegistrationInspections } from "./ClientRegistrationStatus.js";
|
||||||
import {
|
|
||||||
clientServerForcedEnabled,
|
|
||||||
clientServerListedDisabled,
|
|
||||||
effectiveClientServer,
|
|
||||||
parseClientConfiguration,
|
|
||||||
} from "./ClientConfigurationDocument.js";
|
|
||||||
import { supportedClients } from "./SupportedClients.js";
|
|
||||||
import { existingSkillDestinations } from "./SetupSkill.js";
|
import { existingSkillDestinations } from "./SetupSkill.js";
|
||||||
import type { SetupAction } from "./SetupTypes.js";
|
import type { SetupAction } from "./SetupTypes.js";
|
||||||
import type { Result } from "../domain/result.js";
|
import type { Result } from "../domain/result.js";
|
||||||
import { readRegularFileText } from "./RegularFileRead.js";
|
|
||||||
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
||||||
|
|
||||||
/** Existing REA integrations selected for maintenance, without discovering new targets. */
|
/** Existing REA integrations selected for maintenance, without discovering new targets. */
|
||||||
@@ -61,41 +52,23 @@ export const existingMaintenanceScope = async (
|
|||||||
environment: Readonly<NodeJS.ProcessEnv>,
|
environment: Readonly<NodeJS.ProcessEnv>,
|
||||||
resources?: ArtifactResourceScope,
|
resources?: ArtifactResourceScope,
|
||||||
): Promise<MaintenanceScope> => {
|
): Promise<MaintenanceScope> => {
|
||||||
const registrations = await readClientRegistrationStatuses(home, entryPoint, {
|
const registrations = await readClientRegistrationInspections(
|
||||||
environment,
|
home,
|
||||||
...(resources === undefined ? {} : { resources }),
|
entryPoint,
|
||||||
});
|
{
|
||||||
const supported = supportedClients(home, process.platform, environment);
|
environment,
|
||||||
|
...(resources === undefined ? {} : { resources }),
|
||||||
|
},
|
||||||
|
);
|
||||||
const clients: string[] = [];
|
const clients: string[] = [];
|
||||||
for (const registration of registrations) {
|
for (const { status: registration, activation } of registrations) {
|
||||||
if (
|
if (
|
||||||
|
activation !== "enabled" ||
|
||||||
(registration.state !== "aligned" && registration.state !== "stale") ||
|
(registration.state !== "aligned" && registration.state !== "stale") ||
|
||||||
!isOwnedClientRegistrationCommand(registration.command, entryPoint)
|
!isOwnedClientRegistrationCommand(registration.command, entryPoint)
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
const client = supported.find(({ name }) => name === registration.client);
|
clients.push(registration.client);
|
||||||
if (client === undefined) continue;
|
|
||||||
const parsed = parseClientConfiguration(
|
|
||||||
await readRegularFileText(
|
|
||||||
client.configPath,
|
|
||||||
resources === undefined ? {} : { resources },
|
|
||||||
),
|
|
||||||
client.format,
|
|
||||||
);
|
|
||||||
const enabled = z
|
|
||||||
.object({
|
|
||||||
enabled: z.boolean().optional(),
|
|
||||||
disabled: z.boolean().optional(),
|
|
||||||
})
|
|
||||||
.parse(effectiveClientServer(parsed, PRODUCT_IDENTITY.mcpServerKey));
|
|
||||||
// Root disable lists override enabled entries and OMP's force-on allowlist.
|
|
||||||
if (
|
|
||||||
(enabled.enabled !== false ||
|
|
||||||
clientServerForcedEnabled(parsed, PRODUCT_IDENTITY.mcpServerKey)) &&
|
|
||||||
enabled.disabled !== true &&
|
|
||||||
!clientServerListedDisabled(parsed, PRODUCT_IDENTITY.mcpServerKey)
|
|
||||||
)
|
|
||||||
clients.push(client.name);
|
|
||||||
}
|
}
|
||||||
const skillDestinations = await existingSkillDestinations(
|
const skillDestinations = await existingSkillDestinations(
|
||||||
home,
|
home,
|
||||||
|
|||||||
@@ -126,6 +126,41 @@ describe("OMP integration maintenance", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("maintenance activation and layered configuration", () => {
|
||||||
|
it("leaves a natively disabled ZCode registration outside maintenance", async () => {
|
||||||
|
const configPath = await writeClient(
|
||||||
|
"zcode",
|
||||||
|
JSON.stringify({
|
||||||
|
mcp: {
|
||||||
|
servers: {
|
||||||
|
rea: { command: entryPoint, args: ["mcp"], enable: false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const original = await readFile(configPath, "utf8");
|
||||||
|
await expect(
|
||||||
|
existingMaintenanceScope(home, entryPoint, process.env),
|
||||||
|
).resolves.toMatchObject({ clients: [] });
|
||||||
|
expect(await readFile(configPath, "utf8")).toBe(original);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("selects an enabled registration inherited through layered OpenCode files", async () => {
|
||||||
|
const directory = join(home, ".config", "opencode");
|
||||||
|
await mkdir(directory, { recursive: true });
|
||||||
|
await writeFile(
|
||||||
|
join(directory, "opencode.json"),
|
||||||
|
JSON.stringify({
|
||||||
|
mcp: { rea: { type: "local", command: [entryPoint, "mcp"] } },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await writeClient("opencode", JSON.stringify({ theme: "user-selected" }));
|
||||||
|
await expect(
|
||||||
|
existingMaintenanceScope(home, entryPoint, process.env),
|
||||||
|
).resolves.toMatchObject({ clients: ["opencode"] });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("existing REA integration maintenance", () => {
|
describe("existing REA integration maintenance", () => {
|
||||||
it("selects owned registrations while preserving unconfigured, foreign, and disabled choices", async () => {
|
it("selects owned registrations while preserving unconfigured, foreign, and disabled choices", async () => {
|
||||||
await writeClient("codex", staleCodex);
|
await writeClient("codex", staleCodex);
|
||||||
|
|||||||
Reference in New Issue
Block a user