codex-lens 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { join, dirname } from "node:path";
4
- import { platform, arch } from "node:os";
5
- import { chmodSync, statSync } from "node:fs";
4
+ import { platform, arch, homedir } from "node:os";
5
+ import { chmodSync, statSync, existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
6
6
  const __filename = fileURLToPath(import.meta.url);
7
7
  const __dirname = dirname(__filename);
8
8
  let ptyProcess = null;
@@ -67,16 +67,35 @@ function fixSpawnHelperPermissions() {
67
67
  } catch {
68
68
  }
69
69
  }
70
+ function setupCodexConfig(proxyPort) {
71
+ const codexDir = join(homedir(), ".codex");
72
+ const configPath = join(codexDir, "config.toml");
73
+ if (!existsSync(codexDir)) {
74
+ mkdirSync(codexDir, { recursive: true });
75
+ }
76
+ let config = "";
77
+ if (existsSync(configPath)) {
78
+ config = readFileSync(configPath, "utf-8");
79
+ }
80
+ const baseUrl = `http://127.0.0.1:${proxyPort}`;
81
+ const configLine = `openai_base_url = "${baseUrl}"`;
82
+ if (config.includes("openai_base_url")) {
83
+ config = config.replace(/openai_base_url\s*=\s*"[^"]*"/, configLine);
84
+ } else {
85
+ config = config.trimEnd() + "\n" + configLine + "\n";
86
+ }
87
+ writeFileSync(configPath, config);
88
+ }
70
89
  async function spawnCodex(codexBinary, projectRoot, proxyPort) {
71
90
  if (ptyProcess) {
72
91
  killPty();
73
92
  }
74
93
  const pty = await getPty();
75
94
  fixSpawnHelperPermissions();
95
+ setupCodexConfig(proxyPort);
76
96
  const shell = platform() === "win32" ? "powershell.exe" : "bash";
77
97
  const args = platform() === "win32" ? ["-NoExit", "-Command", `Set-Location "${projectRoot}"; & "${codexBinary}"`] : [];
78
98
  const env = { ...process.env };
79
- env.OPENAI_BASE_URL = `http://127.0.0.1:${proxyPort}`;
80
99
  if (platform() === "win32") {
81
100
  env.WINPTY = "1";
82
101
  }