fix(setup): describe the inspected OpenCode registration dialect

The approval plan uses the dialect configuration inspection parsed, so a native OpenCode server table is not described as rewriting enabled.
This commit is contained in:
Cursor Agent
2026-10-12 21:37:33 -04:00
committed by xeropresence
parent fb3fa1dc5f
commit 4eb3b5335a
9 changed files with 52 additions and 15 deletions
@@ -1618,7 +1618,7 @@ export const describeClientRegistrationRetention = (
? removed
: `Setup replaces ${replaced.join(" and ")}. ${removed}`;
const legacy =
dialect === "opencode"
dialect === "opencode_v2"
? " A legacy OpenCode entry moved into the native server table keeps only its environment."
: "";
return `On an existing local command entry, other user fields are kept. ${replacement} When that entry is remote, its other fields are replaced.${legacy}`;
+7 -1
View File
@@ -254,15 +254,21 @@ describe("setup approval disclosure", () => {
format: "opencode",
},
];
host.clientInspections.set("opencode", {
status: "update",
dialect: "opencode_v2",
});
const result = await runSetup(
{ ...options(false), dryRun: true, clientIds: ["opencode"] },
host,
);
expect(result.plannedActions[0]?.detail).toContain(
const detail = result.plannedActions[0]?.detail ?? "";
expect(detail).toContain(
"A legacy OpenCode entry moved into the native server table keeps only its environment.",
);
expect(detail).not.toContain(`enabled with ${JSON.stringify(true)}`);
});
});
+15 -6
View File
@@ -18,6 +18,7 @@ import {
serializeClientConfiguration,
withClientServers,
type ClientConfigurationDocument,
type ClientRegistrationDialect,
} from "./ClientConfigurationDocument.js";
import { dshDocument, DshCordisDocument } from "./DshCordisPatch.js";
import { constants as fsConstants } from "node:fs";
@@ -361,7 +362,7 @@ export const inspectClientConfiguration = async (
throwCleanupFailure(fallback.error);
return { status: "invalid", remediation: fallback.error.detail };
}
return { status: "create" };
return { status: "create", dialect: clientRegistrationDialect(client) };
}
return {
status: "invalid",
@@ -391,12 +392,17 @@ export const inspectClientConfiguration = async (
parsed,
);
if (registrationCurrent(parsed, desired))
return { status: "already_current" };
return { status: "already_current", dialect: parsed.dialect };
const fallback = await readZcodeFallbackServers(client, parsed);
if (!fallback.ok) {
throwCleanupFailure(fallback.error);
return { status: "invalid", remediation: fallback.error.detail };
}
return {
status: "update",
backupPath: `${client.configPath}.rea.backup`,
dialect: parsed.dialect,
};
} catch (cause: unknown) {
if (cause instanceof RegularFileCleanupFailure) throw cause;
// Malformed configuration is reported with the invalid remediation.
@@ -407,12 +413,15 @@ export const inspectClientConfiguration = async (
"The existing configuration is malformed. Repair it before setup applies any other changes.",
};
}
return {
status: "update",
backupPath: `${client.configPath}.rea.backup`,
};
};
const clientRegistrationDialect = (
client: SetupClient,
): ClientRegistrationDialect =>
client.format === undefined || client.format === "unsupported"
? "json"
: client.format;
const isMissing = (cause: unknown): boolean =>
cause instanceof Error && "code" in cause && cause.code === "ENOENT";
+14 -4
View File
@@ -1,6 +1,9 @@
import { join } from "node:path";
import { describeClientRegistrationRetention } from "./ClientConfigurationDocument.js";
import {
describeClientRegistrationRetention,
type ClientRegistrationDialect,
} from "./ClientConfigurationDocument.js";
import { isOwnedClientRegistrationCommand } from "./ClientRegistrationIdentity.js";
import {
linuxHopperInstallDisclosure,
@@ -179,6 +182,9 @@ export const planSetupActions = async (input: {
inspection.backupPath !== undefined
? { backupPath: inspection.backupPath }
: {}),
...(inspection.dialect === undefined
? {}
: { dialect: inspection.dialect }),
},
]
: [],
@@ -217,6 +223,7 @@ const setupPlan = (input: {
readonly client: SetupClient;
readonly operation: "create" | "update";
readonly backupPath?: string;
readonly dialect?: ClientRegistrationDialect;
}[];
readonly providerEnvironment: SetupProviderEnvironment;
readonly linuxPackageFamily?: LinuxPackageFamily;
@@ -254,7 +261,7 @@ const setupPlan = (input: {
: []),
...input.clients
.filter(({ client }) => client.format !== "unsupported")
.map(({ client, operation, backupPath }): SetupAction => ({
.map(({ client, operation, backupPath, dialect }): SetupAction => ({
id: `configure_client:${client.name}`,
kind: "configure_client",
label: client.displayName ?? client.name,
@@ -264,6 +271,7 @@ const setupPlan = (input: {
name: client.name,
label: client.displayName ?? client.name,
format: client.format,
...(dialect === undefined ? {} : { dialect }),
},
input.command,
input.providerEnvironment,
@@ -312,6 +320,7 @@ const clientConfigurationDetail = (
readonly name: string;
readonly label: string;
readonly format: SetupClient["format"];
readonly dialect?: ClientRegistrationDialect;
},
command: readonly string[],
environment: SetupProviderEnvironment,
@@ -321,9 +330,10 @@ const clientConfigurationDetail = (
.sort(([left], [right]) => compareUnicodeCodePoints(left, right))
.map(([name, value]) => `${name}=${value}`);
const dialect =
client.format === undefined || client.format === "unsupported"
client.dialect ??
(client.format === undefined || client.format === "unsupported"
? "json"
: client.format;
: client.format);
const retainedFields = describeClientRegistrationRetention(
client.name,
dialect,
+8 -1
View File
@@ -1,3 +1,4 @@
import type { ClientRegistrationDialect } from "./ClientConfigurationDocument.js";
import type { DoctorReport, DoctorScope, runDoctor } from "./Doctor.js";
import type { LinuxDistribution } from "./LinuxHopper.js";
import type { SkillDestination, SkillInstallResult } from "./SetupSkill.js";
@@ -30,10 +31,16 @@ export type ClientConfigurationResult =
/** Read-only state used to block unsafe setup plans before any mutation. */
export type ClientConfigurationInspection =
| { readonly status: "already_current" }
| {
readonly status: "already_current";
/** Dialect the registration writer will use when this file is parsed. */
readonly dialect?: ClientRegistrationDialect;
}
| {
readonly status: "create" | "update";
readonly backupPath?: string;
/** Dialect the registration writer will use for this file. */
readonly dialect?: ClientRegistrationDialect;
}
| {
readonly status: "invalid";
@@ -50,6 +50,7 @@ describe.each([
expect(await inspectClientConfiguration(client, {}, command)).toEqual({
status: "update",
backupPath: `${client.configPath}.rea.backup`,
dialect: client.format,
});
expect(await clientConfigurationAligned(client, {}, command)).toBe(false);
expect(await configureClientConfiguration(client, {}, command)).toEqual({
@@ -73,6 +74,7 @@ describe.each([
expect(await clientConfigurationAligned(client, {}, command)).toBe(true);
expect(await inspectClientConfiguration(client, {}, command)).toEqual({
status: "already_current",
dialect: client.format,
});
expect(
await readClientRegistrationStatuses(home, currentCommandPath, {
@@ -174,6 +176,7 @@ it.each(["", "\n \n", "\uFEFF"])(
expect(await inspectClientConfiguration(client, {}, command)).toEqual({
status: "update",
backupPath: `${client.configPath}.rea.backup`,
dialect: "json",
});
expect(await configureClientConfiguration(client, {}, command)).toEqual({
status: "configured",
@@ -184,6 +187,7 @@ it.each(["", "\n \n", "\uFEFF"])(
});
expect(await inspectClientConfiguration(client, {}, command)).toEqual({
status: "already_current",
dialect: "json",
});
},
);
@@ -68,7 +68,7 @@ it.each([
);
expect(
await inspectClientConfiguration(client, providers, command),
).toEqual({ status: "already_current" });
).toEqual({ status: "already_current", dialect: format });
expect(
await configureClientConfiguration(client, providers, command),
).toEqual({ status: "unchanged" });
@@ -102,6 +102,7 @@ it.each([
expect(await clientConfigurationAligned(client, {}, command)).toBe(true);
expect(await inspectClientConfiguration(client, {}, command)).toEqual({
status: "already_current",
dialect,
});
expect(await configureClientConfiguration(client, {}, command)).toEqual({
status: "unchanged",
@@ -281,7 +281,7 @@ describe("Pi strict JSON parsing", () => {
});
expect(
await inspectClientConfiguration(client, {}, NPX_REGISTRATION_COMMAND),
).toEqual({ status: "create" });
).toEqual({ status: "create", dialect: "pi" });
expect(
await configureClientConfiguration(client, {}, NPX_REGISTRATION_COMMAND),
).toMatchObject({ status: "configured" });