refactor(codex): give the CODEX_HOME lookup its own module

This commit is contained in:
2026-09-08 16:24:17 +07:00
parent aef7ec130b
commit 57849d2f75
3 changed files with 92 additions and 5 deletions
+2 -5
View File
@@ -33,6 +33,7 @@
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const { getCodexHome } = require("./codex-home");
// `*** Update File: <path>` lines inside an apply_patch heredoc.
const PATCH_FILE_RE = /^\*\*\* (Add|Update|Delete) File: (.+)$/gm;
@@ -98,10 +99,6 @@ function eventsFromPayload(payload) {
return [{ tool_name: "Bash", tool_input: { command: commandFromPayload(payload, text) } }];
}
function codexHome() {
return process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
}
/** Every rollout journal under sessions/, newest mtime first, capped at MAX_FILES. */
function rolloutFiles() {
const out = [];
@@ -126,7 +123,7 @@ function rolloutFiles() {
}
}
};
walk(path.join(codexHome(), "sessions"), 0);
walk(path.join(getCodexHome(), "sessions"), 0);
return out.sort((a, b) => b.mtime - a.mtime).slice(0, MAX_FILES);
}