






















@@ -1,12 +1,29 @@
1+import { existsSync } from "node:fs";
2+import path from "node:path";
13import { modelSelectionShouldEnsureCodexPlugin } from "../agents/openai-codex-routing.js";
24import type { OpenClawConfig } from "../config/types.openclaw.js";
5+import type { PluginInstallRecord } from "../config/types.plugins.js";
6+import { enablePluginInConfig } from "../plugins/enable.js";
7+import { loadInstalledPluginIndexInstallRecords } from "../plugins/installed-plugin-index-records.js";
38import type { RuntimeEnv } from "../runtime.js";
9+import { resolveUserPath } from "../utils.js";
410import type { WizardPrompter } from "../wizard/prompts.js";
511612const CODEX_RUNTIME_PLUGIN_ID = "codex";
713const CODEX_RUNTIME_PLUGIN_LABEL = "Codex";
814const CODEX_RUNTIME_PLUGIN_NPM_SPEC = "@openclaw/codex";
91516+function isInstalledRecordPresentOnDisk(
17+record: PluginInstallRecord | undefined,
18+env: NodeJS.ProcessEnv,
19+): boolean {
20+const installPath = record?.installPath?.trim();
21+if (!installPath) {
22+return false;
23+}
24+return existsSync(path.join(resolveUserPath(installPath, env), "package.json"));
25+}
26+1027export type CodexRuntimePluginInstallResult = {
1128cfg: OpenClawConfig;
1229required: boolean;
@@ -34,6 +51,27 @@ export async function ensureCodexRuntimePluginForModelSelection(params: {
3451if (!selectedModelShouldEnsureCodexRuntimePlugin({ cfg: params.cfg, model: params.model })) {
3552return { cfg: params.cfg, required: false, installed: false };
3653}
54+const existingRecords = await loadInstalledPluginIndexInstallRecords({ env: process.env });
55+if (isInstalledRecordPresentOnDisk(existingRecords[CODEX_RUNTIME_PLUGIN_ID], process.env)) {
56+const repair = await repairCodexRuntimePluginInstallForModelSelection({
57+cfg: params.cfg,
58+model: params.model,
59+env: process.env,
60+});
61+for (const change of repair.changes) {
62+params.runtime.log?.(change);
63+}
64+for (const warning of repair.warnings) {
65+params.runtime.log?.(`Codex update warning: ${warning}`);
66+}
67+const enableResult = enablePluginInConfig(params.cfg, CODEX_RUNTIME_PLUGIN_ID);
68+return {
69+cfg: enableResult.enabled ? enableResult.config : params.cfg,
70+required: true,
71+installed: true,
72+status: "installed",
73+};
74+}
3775const { ensureOnboardingPluginInstalled } = await import("./onboarding-plugin-install.js");
3876const result = await ensureOnboardingPluginInstalled({
3977cfg: params.cfg,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。