fix: bootstrap explicit CODEX_HOME for ccsxp

This commit is contained in:
Tam Nhu Tran committed 2026-04-01 00:03:10 -04:00
1 parent 014a844844
commit b6717c5529
2 files changed
+84

No files matched your search

+32
View File
@@ -83,6 +83,32 @@ function normalizeCodexReasoningOverride(value: string | number | undefined): st
);
}
function ensureExplicitCodexHomeDir(env: NodeJS.ProcessEnv): string | undefined {
const codexHome = env.CODEX_HOME?.trim();
if (!codexHome) {
return undefined;
}
try {
fs.mkdirSync(codexHome, { recursive: true });
} catch (err) {
const error = err as NodeJS.ErrnoException;
if (error.code !== 'EEXIST') {
return `[X] Unable to initialize CODEX_HOME (${error.code || 'unknown'}): ${codexHome}`;
}
}
try {
if (!fs.statSync(codexHome).isDirectory()) {
return `[X] CODEX_HOME path is not a directory: ${codexHome}`;
}
return undefined;
} catch (err) {
const error = err as NodeJS.ErrnoException;
return `[X] Unable to access CODEX_HOME (${error.code || 'unknown'}): ${codexHome}`;
}
}
export class CodexAdapter implements TargetAdapter {
readonly type: TargetType = 'codex';
readonly displayName = 'Codex CLI';
@@ -207,6 +233,12 @@ export class CodexAdapter implements TargetAdapter {
return exitWithCleanup(1);
}
const codexHomeInitError = ensureExplicitCodexHomeDir(env);
if (codexHomeInitError) {
console.error(codexHomeInitError);
return exitWithCleanup(1);
}
const isWindows = process.platform === 'win32';
const isPowerShellScript = isWindows && /\.ps1$/i.test(codexPath);
const needsShell = isWindows && /\.(cmd|bat)$/i.test(codexPath);