fix: Codex 自动压缩不触发 —— 接管时链接模型目录(绝对路径)进 config.toml (hot 1.5.83)

This commit is contained in:
mac
2026-08-16 12:45:32 +08:00
parent e9a261482c
commit 1b687c01e9
50 changed files with 10885 additions and 1161 deletions
+30 -15
View File
@@ -3,11 +3,19 @@
const fs = require("fs");
const path = require("path");
const os = require("os");
const codexDataDir = require("./codex_data_dir");
const CODEX_HOME = path.join(os.homedir(), ".codex");
const CONFIG_PATH = path.join(CODEX_HOME, "config.toml");
const DEFAULT_CODEX_HOME = path.join(os.homedir(), ".codex");
const ENABLED_FILE = "enabled-plugins.toml"; // 备份包里记录启用状态的文件名
function getCodexHome() {
try { return codexDataDir.get(); } catch { return DEFAULT_CODEX_HOME; }
}
function getConfigPath() {
return path.join(getCodexHome(), "config.toml");
}
// 打包时【绝对排除】的隐私 / 垃圾文件(就算勾了也不会被打包上传)
const BLOCKLIST_NAMES = new Set([
"auth.json",
@@ -172,8 +180,9 @@ function configPluginHeaders(text) {
// 把选中插件在本机的启用状态,写进备份包的 enabled-plugins.toml。返回记录的 keys。
function writeEnabledFile(selected, staging) {
const srcText = fs.existsSync(CONFIG_PATH)
? fs.readFileSync(CONFIG_PATH, "utf-8")
const configPath = getConfigPath();
const srcText = fs.existsSync(configPath)
? fs.readFileSync(configPath, "utf-8")
: "";
const enabledNow = configPluginHeaders(srcText);
const keys = selected
@@ -308,9 +317,10 @@ function packageItems(selected, staging, log) {
function enablePluginsInConfig(keys, log) {
keys = keys.filter((k) => k);
if (!keys.length) return;
fs.mkdirSync(path.dirname(CONFIG_PATH), { recursive: true });
let text = fs.existsSync(CONFIG_PATH)
? fs.readFileSync(CONFIG_PATH, "utf-8")
const configPath = getConfigPath();
fs.mkdirSync(path.dirname(configPath), { recursive: true });
let text = fs.existsSync(configPath)
? fs.readFileSync(configPath, "utf-8")
: "";
const existing = configPluginHeaders(text);
const toAdd = keys.filter((k) => !existing.has(k));
@@ -319,9 +329,9 @@ function enablePluginsInConfig(keys, log) {
return;
}
// 备份
if (fs.existsSync(CONFIG_PATH)) {
const bak = CONFIG_PATH + ".bak-exporter"; // config.toml.bak-exporter
fs.copyFileSync(CONFIG_PATH, bak);
if (fs.existsSync(configPath)) {
const bak = configPath + ".bak-exporter"; // config.toml.bak-exporter
fs.copyFileSync(configPath, bak);
log(` 已备份 config.toml -> ${path.basename(bak)}`);
}
if (text && !text.endsWith("\n")) {
@@ -333,14 +343,15 @@ function enablePluginsInConfig(keys, log) {
blocks.push("enabled = true");
blocks.push("");
}
fs.writeFileSync(CONFIG_PATH, text + blocks.join("\n"), "utf-8");
fs.writeFileSync(configPath, text + blocks.join("\n"), "utf-8");
log(` 已在 config.toml 启用 ${toAdd.length} 个插件:${toAdd.join(", ")}`);
}
// 把选中的(来自 clone 的)项拷回 ~/.codex,并可选地在 config.toml 里启用插件。
function restoreItems(selected, log, enable = true) {
const codexHome = getCodexHome();
for (const it of selected) {
const dst = path.join(CODEX_HOME, it.rel);
const dst = path.join(codexHome, it.rel);
fs.mkdirSync(path.dirname(dst), { recursive: true });
log(` 还原 ${it.category}: ${it.name} -> ${dst}`);
copyClean(it.path, dst);
@@ -352,9 +363,8 @@ function restoreItems(selected, log, enable = true) {
log("还原完成 ✅ 重启 codex 生效");
}
module.exports = {
CODEX_HOME,
CONFIG_PATH,
const api = {
getCodexHome,
ENABLED_FILE,
humanSize,
dirSize,
@@ -366,3 +376,8 @@ module.exports = {
enablePluginsInConfig,
restoreItems,
};
Object.defineProperty(api, "CODEX_HOME", { enumerable: true, get: getCodexHome });
Object.defineProperty(api, "CONFIG_PATH", { enumerable: true, get: getConfigPath });
module.exports = api;