import os from "node:os";
import path from "node:path";
export function resolveCodexDir() {
    const codexHome = cleanEnvPath(process.env.CODEX_HOME);
    if (codexHome) {
        return codexHome;
    }
    const home = resolveUserHomeDir();
    return home ? path.join(home, ".codex") : null;
}
function resolveUserHomeDir() {
    const home = cleanEnvPath(process.env.HOME);
    if (home) {
        return home;
    }
    const userProfile = cleanEnvPath(process.env.USERPROFILE);
    if (userProfile) {
        return userProfile;
    }
    const homeDrive = cleanEnvPath(process.env.HOMEDRIVE);
    const homePath = cleanEnvPath(process.env.HOMEPATH);
    if (homeDrive && homePath) {
        return path.join(homeDrive, homePath);
    }
    const osHome = cleanEnvPath(os.homedir());
    return osHome || null;
}
function cleanEnvPath(value) {
    const trimmed = value?.trim();
    return trimmed ? trimmed : null;
}
