mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fa03d9b913
* refactor: consolidate coercion helpers * fix: remove duplicate coercion imports * fix: preserve serialized coercion guard * chore: ratchet coercion helper carve-outs * fix(test): keep gauntlet subprocess startup lean * fix: preserve imported session timestamp semantics * fix: preserve catalog timestamp string semantics * chore: align plugin SDK surface ratchet * fix: preserve trajectory and SDK string contracts * fix(test): preserve QA record assertion semantics * fix: complete standalone record guard rename * refactor(cron): use canonical string coercion * fix(acpx): preserve Pi timestamp parsing * test(channels): adapt custody test harnesses * test(telegram): classify media harness as test support * test(acpx): split timestamp contract coverage * test(channels): support generated custody contracts * chore: ban the full coercion helper name set Extends the declaration guard to all eleven consolidated helper names and renames the cron schedule-identity readNumber wrapper to readScheduleInteger so the banned generic name cannot regrow. * fix(scripts): repair release-validation guard drift and lint cause Restores the renamed isJsonRecord guard in assertTrustedWorkflowHarness after main added isRecord call sites in parallel, and attaches the caught YAML error as the thrown error cause (preserve-caught-error was red on main). * fix: preserve Claude timestamp string semantics * fix: preserve persisted timestamp string semantics * fix: preserve date-first timestamp contracts * fix(openai): harden delegation failure formatting * chore: close coercion helper guard gaps * test(openai): model non-error delegation rejection * chore: refresh plugin SDK API contract * fix(tasks): use canonical string field reader * fix(ai): use canonical provider error field coercion * fix(browser): migrate native bootstrap coercion * docs(plugin-sdk): clarify text record export compatibility * fix(gateway): normalize approval execution identity * test(outbound): isolate message action poll harness
134 lines
4.9 KiB
TypeScript
134 lines
4.9 KiB
TypeScript
/**
|
|
* Doctor contract hooks for Codex plugin config and state migrations.
|
|
*/
|
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import { asNullableRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
|
type LegacyConfigRule = {
|
|
path: string[];
|
|
message: string;
|
|
match: (value: unknown) => boolean;
|
|
};
|
|
|
|
function hasRetiredDynamicToolsProfile(value: unknown): boolean {
|
|
return Object.hasOwn(asNullableRecord(value) ?? {}, "codexDynamicToolsProfile");
|
|
}
|
|
|
|
function hasLegacyPluginDestructivePolicy(value: unknown): boolean {
|
|
const codexPlugins = asNullableRecord(value);
|
|
if (!codexPlugins) {
|
|
return false;
|
|
}
|
|
if (codexPlugins.allow_destructive_actions === "on-request") {
|
|
return true;
|
|
}
|
|
const plugins = asNullableRecord(codexPlugins.plugins);
|
|
return Object.values(plugins ?? {}).some(
|
|
(plugin) => asNullableRecord(plugin)?.allow_destructive_actions === "on-request",
|
|
);
|
|
}
|
|
|
|
function hasRetiredOnFailureApprovalPolicy(value: unknown): boolean {
|
|
return asNullableRecord(value)?.approvalPolicy === "on-failure";
|
|
}
|
|
|
|
/** Legacy Codex config keys that doctor should report or repair. */
|
|
export const legacyConfigRules: LegacyConfigRule[] = [
|
|
{
|
|
path: ["plugins", "entries", "codex", "config"],
|
|
message:
|
|
'plugins.entries.codex.config.codexDynamicToolsProfile is retired; Codex app-server always keeps Codex-native workspace tools native. Run "openclaw doctor --fix".',
|
|
match: hasRetiredDynamicToolsProfile,
|
|
},
|
|
{
|
|
path: ["plugins", "entries", "codex", "config", "codexPlugins"],
|
|
message:
|
|
'plugins.entries.codex.config.codexPlugins.allow_destructive_actions="on-request" was renamed to "auto". Run "openclaw doctor --fix".',
|
|
match: hasLegacyPluginDestructivePolicy,
|
|
},
|
|
{
|
|
path: ["plugins", "entries", "codex", "config", "appServer"],
|
|
message:
|
|
'plugins.entries.codex.config.appServer.approvalPolicy="on-failure" was retired by Codex 0.143; use "on-request". Run "openclaw doctor --fix".',
|
|
match: hasRetiredOnFailureApprovalPolicy,
|
|
},
|
|
];
|
|
|
|
/**
|
|
* Removes retired Codex plugin config keys while preserving unrelated config.
|
|
*/
|
|
export function normalizeCompatibilityConfig({ cfg }: { cfg: OpenClawConfig }): {
|
|
config: OpenClawConfig;
|
|
changes: string[];
|
|
} {
|
|
const rawEntry = asNullableRecord(cfg.plugins?.entries?.codex);
|
|
const rawPluginConfig = asNullableRecord(rawEntry?.config);
|
|
const rawCodexPlugins = asNullableRecord(rawPluginConfig?.codexPlugins);
|
|
const rawAppServer = asNullableRecord(rawPluginConfig?.appServer);
|
|
const shouldRemoveDynamicToolsProfile =
|
|
rawPluginConfig !== null && hasRetiredDynamicToolsProfile(rawPluginConfig);
|
|
const shouldRewriteDestructivePolicy = hasLegacyPluginDestructivePolicy(rawCodexPlugins);
|
|
const shouldRewriteApprovalPolicy = hasRetiredOnFailureApprovalPolicy(rawAppServer);
|
|
if (
|
|
!rawPluginConfig ||
|
|
(!shouldRemoveDynamicToolsProfile &&
|
|
!shouldRewriteDestructivePolicy &&
|
|
!shouldRewriteApprovalPolicy)
|
|
) {
|
|
return { config: cfg, changes: [] };
|
|
}
|
|
|
|
const nextConfig = structuredClone(cfg) as OpenClawConfig & {
|
|
plugins?: Record<string, unknown>;
|
|
};
|
|
const nextPlugins = asNullableRecord(nextConfig.plugins);
|
|
const nextEntries = asNullableRecord(nextPlugins?.entries);
|
|
const nextEntry = asNullableRecord(nextEntries?.codex);
|
|
const nextPluginConfig = asNullableRecord(nextEntry?.config);
|
|
if (!nextPluginConfig) {
|
|
return { config: cfg, changes: [] };
|
|
}
|
|
|
|
const changes: string[] = [];
|
|
if (shouldRemoveDynamicToolsProfile) {
|
|
delete nextPluginConfig.codexDynamicToolsProfile;
|
|
changes.push(
|
|
"Removed retired plugins.entries.codex.config.codexDynamicToolsProfile; Codex app-server always keeps Codex-native workspace tools native.",
|
|
);
|
|
}
|
|
|
|
if (shouldRewriteDestructivePolicy) {
|
|
const nextCodexPlugins = asNullableRecord(nextPluginConfig.codexPlugins);
|
|
if (nextCodexPlugins?.allow_destructive_actions === "on-request") {
|
|
nextCodexPlugins.allow_destructive_actions = "auto";
|
|
}
|
|
const nextPluginPolicies = asNullableRecord(nextCodexPlugins?.plugins);
|
|
for (const plugin of Object.values(nextPluginPolicies ?? {})) {
|
|
const nextPlugin = asNullableRecord(plugin);
|
|
if (nextPlugin?.allow_destructive_actions === "on-request") {
|
|
nextPlugin.allow_destructive_actions = "auto";
|
|
}
|
|
}
|
|
changes.push(
|
|
'Renamed plugins.entries.codex.config.codexPlugins allow_destructive_actions="on-request" values to "auto".',
|
|
);
|
|
}
|
|
|
|
if (shouldRewriteApprovalPolicy) {
|
|
const nextAppServer = asNullableRecord(nextPluginConfig.appServer);
|
|
if (nextAppServer?.approvalPolicy === "on-failure") {
|
|
nextAppServer.approvalPolicy = "on-request";
|
|
}
|
|
changes.push(
|
|
'Renamed plugins.entries.codex.config.appServer.approvalPolicy="on-failure" to "on-request".',
|
|
);
|
|
}
|
|
|
|
return {
|
|
config: nextConfig,
|
|
changes,
|
|
};
|
|
}
|
|
|
|
export { stateMigrations } from "./src/migration/session-binding-sidecars.js";
|