@childclm/codexx 0.1.0 → 0.1.2
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.
- package/package.json +1 -1
- package/src/index.js +134 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -97,6 +97,14 @@ function loadSettings() {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
function fileExists(p) {
|
|
101
|
+
try {
|
|
102
|
+
return fs.existsSync(p);
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
function loadProject(cwd = process.cwd()) {
|
|
101
109
|
const { root, projectFile } = getProjectPaths(cwd);
|
|
102
110
|
return readJson(projectFile, {
|
|
@@ -129,13 +137,131 @@ function saveProjectSessionsMeta(data, cwd = process.cwd()) {
|
|
|
129
137
|
|
|
130
138
|
function detectCodex() {
|
|
131
139
|
const settings = loadSettings();
|
|
132
|
-
return settings.codexCommand || "codex";
|
|
140
|
+
return String(settings.codexCommand || "codex").trim().replace(/^"(.*)"$/, "$1");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function resolveWindowsCodexCandidates() {
|
|
144
|
+
const candidates = [];
|
|
145
|
+
const appData = process.env.APPDATA || path.join(HOME, "AppData", "Roaming");
|
|
146
|
+
const npmRoot = path.join(appData, "npm");
|
|
147
|
+
const localShims = [
|
|
148
|
+
path.join(npmRoot, "codex.exe"),
|
|
149
|
+
path.join(npmRoot, "codex.cmd"),
|
|
150
|
+
path.join(npmRoot, "codex"),
|
|
151
|
+
];
|
|
152
|
+
candidates.push(...localShims);
|
|
153
|
+
|
|
154
|
+
const finder = spawnSync("where", ["codex.exe"], { encoding: "utf8" });
|
|
155
|
+
const foundExe = (finder.stdout || "")
|
|
156
|
+
.trim()
|
|
157
|
+
.split(/\r?\n/)
|
|
158
|
+
.filter(Boolean);
|
|
159
|
+
candidates.push(...foundExe);
|
|
160
|
+
|
|
161
|
+
const foundCmd = spawnSync("where", ["codex.cmd"], { encoding: "utf8" });
|
|
162
|
+
const cmdHits = (foundCmd.stdout || "")
|
|
163
|
+
.trim()
|
|
164
|
+
.split(/\r?\n/)
|
|
165
|
+
.filter(Boolean);
|
|
166
|
+
candidates.push(...cmdHits);
|
|
167
|
+
|
|
168
|
+
const directVendorParent = path.join(
|
|
169
|
+
npmRoot,
|
|
170
|
+
"node_modules",
|
|
171
|
+
"@openai",
|
|
172
|
+
"codex",
|
|
173
|
+
"node_modules",
|
|
174
|
+
);
|
|
175
|
+
if (fileExists(directVendorParent)) {
|
|
176
|
+
try {
|
|
177
|
+
const dirs = fs.readdirSync(directVendorParent);
|
|
178
|
+
for (const dir of dirs) {
|
|
179
|
+
if (!dir.includes("codex-win32-")) continue;
|
|
180
|
+
const vendorRoot = path.join(directVendorParent, dir, "vendor");
|
|
181
|
+
if (!fileExists(vendorRoot)) continue;
|
|
182
|
+
const vendorDirs = fs.readdirSync(vendorRoot);
|
|
183
|
+
for (const vendorDir of vendorDirs) {
|
|
184
|
+
const exePath = path.join(vendorRoot, vendorDir, "bin", "codex.exe");
|
|
185
|
+
candidates.push(exePath);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return [...new Set(candidates)].filter(Boolean);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function resolveCodexCommand() {
|
|
195
|
+
const configured = detectCodex();
|
|
196
|
+
if (path.isAbsolute(configured) && fileExists(configured)) {
|
|
197
|
+
return configured;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (process.platform === "win32") {
|
|
201
|
+
const candidates = [];
|
|
202
|
+
if (configured && configured !== "codex") {
|
|
203
|
+
candidates.push(configured);
|
|
204
|
+
if (!path.extname(configured)) {
|
|
205
|
+
candidates.push(`${configured}.exe`, `${configured}.cmd`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
candidates.push(...resolveWindowsCodexCandidates());
|
|
209
|
+
|
|
210
|
+
for (const candidate of candidates) {
|
|
211
|
+
if (candidate && fileExists(candidate)) {
|
|
212
|
+
return candidate;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return configured;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const finder = spawnSync("which", [configured], { encoding: "utf8" });
|
|
219
|
+
const found = (finder.stdout || "").trim().split(/\r?\n/)[0] || "";
|
|
220
|
+
return found || configured;
|
|
133
221
|
}
|
|
134
222
|
|
|
135
223
|
function codexPath() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
224
|
+
return resolveCodexCommand();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function buildCodexLaunch(cmd, args) {
|
|
228
|
+
const ext = path.extname(cmd).toLowerCase();
|
|
229
|
+
if (process.platform !== "win32") {
|
|
230
|
+
return {
|
|
231
|
+
command: cmd,
|
|
232
|
+
args,
|
|
233
|
+
shell: false,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (ext === ".ps1") {
|
|
238
|
+
return {
|
|
239
|
+
command: "powershell.exe",
|
|
240
|
+
args: [
|
|
241
|
+
"-NoProfile",
|
|
242
|
+
"-ExecutionPolicy",
|
|
243
|
+
"Bypass",
|
|
244
|
+
"-File",
|
|
245
|
+
cmd,
|
|
246
|
+
...args,
|
|
247
|
+
],
|
|
248
|
+
shell: false,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (ext === ".cmd" || ext === ".bat") {
|
|
253
|
+
return {
|
|
254
|
+
command: "cmd.exe",
|
|
255
|
+
args: ["/d", "/s", "/c", cmd, ...args],
|
|
256
|
+
shell: false,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
command: cmd,
|
|
262
|
+
args,
|
|
263
|
+
shell: false,
|
|
264
|
+
};
|
|
139
265
|
}
|
|
140
266
|
|
|
141
267
|
function clearScreen() {
|
|
@@ -353,11 +479,13 @@ function buildCodexEnv(provider) {
|
|
|
353
479
|
|
|
354
480
|
function runCodex(args, env, cwd = process.cwd()) {
|
|
355
481
|
return new Promise((resolve, reject) => {
|
|
356
|
-
const cmd =
|
|
357
|
-
const
|
|
482
|
+
const cmd = resolveCodexCommand();
|
|
483
|
+
const launch = buildCodexLaunch(cmd, args);
|
|
484
|
+
const child = spawn(launch.command, launch.args, {
|
|
358
485
|
cwd,
|
|
359
486
|
stdio: "inherit",
|
|
360
487
|
env: { ...process.env, ...env },
|
|
488
|
+
shell: launch.shell,
|
|
361
489
|
});
|
|
362
490
|
child.on("error", reject);
|
|
363
491
|
child.on("exit", (code) => resolve(code ?? 0));
|