File size: 1,264 Bytes
970fc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { statSync } from "node:fs";
import path from "node:path";
const isFile = (file) => {
  try {
    return statSync(file).isFile();
  } catch {
    return false;
  }
};
function codexLaunch(executable, { platform = process.platform, paths = path, fileExists = isFile, nodePath = process.execPath } = {}) {
  let file = paths.resolve(executable);
  if (platform === "win32" && /\.(cmd|bat)$/i.test(file)) {
    const parent = paths.dirname(file);
    const candidates = [
      paths.join(parent, "codex.exe"),
      paths.join(parent, "node_modules", "@openai", "codex", "bin", "codex.js"),
      paths.join(parent, "..", "@openai", "codex", "bin", "codex.js")
    ];
    file = candidates.find(fileExists);
    if (!file) throw Error("Cannot resolve this Windows Codex wrapper. Set EMBODI_CODEX to codex.exe or the installed @openai/codex/bin/codex.js entry.");
  }
  if (!fileExists(file)) throw Error("Codex executable not found. Install Codex or set EMBODI_CODEX to its executable.");
  return /\.(mjs|cjs|js)$/i.test(file) ? { file: nodePath, args: [file] } : { file, args: [] };
}
function codexAvailable(executable) {
  try {
    codexLaunch(executable);
    return true;
  } catch {
    return false;
  }
}
export {
  codexAvailable,
  codexLaunch
};