Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop: on Windows, a Codex installed by npm is found as its own program (#38)

youyouhdhdd7dd930dc980
diff --git a/.changeset/codex-npm-program.md b/.changeset/codex-npm-program.md
new file mode 100644
index 0000000..56a4fd2
--- /dev/null
+++ b/.changeset/codex-npm-program.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+On Windows, a Codex installed by npm is found as its own program: the folder it is in had changed, and what was used instead — the package's Node script — cannot be started the way the chat starts Codex.
diff --git a/apps/desktop/src/agent-installation.mjs b/apps/desktop/src/agent-installation.mjs
index 813b59b..168a718 100644
--- a/apps/desktop/src/agent-installation.mjs
+++ b/apps/desktop/src/agent-installation.mjs
@@ -133,7 +133,8 @@ const scriptFirst = (rel) => (/\.(?:c|m)?js$/i.test(rel) ? 0 : /\.exe$/i.test(re
/**
* What a `.cmd` shim runs (Windows): the package's script or program, which can be started without a shell (a `.cmd`
* cannot be). Yarn's shim runs another shim, which is read in turn. Codex's script only starts its own program, so
- * the program itself, for this machine's chip. Null when the shim says nothing that is there.
+ * the program itself, for this machine's chip; when there is none, not the script (the chat starts Codex as a shell
+ * command, which a script is not): the shim it came from instead. Null when the shim says nothing that is there.
*/
export function cmdTarget(cmd, depth = 0) {
let text = '';
@@ -151,8 +152,18 @@ export function cmdTarget(cmd, depth = 0) {
if (/[\\/]@openai[\\/]codex[\\/]/i.test(target) && /\.js$/i.test(target)) {
const triple = process.arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
const pkg = target.replace(/[\\/]bin[\\/][^\\/]+$/, '');
- const exe = [join(pkg, 'vendor', triple, 'codex', 'codex.exe'), join(pkg, 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'codex', 'codex.exe')].find(existsFile);
+ /* the platform package it installs beside its script, or one folder up when that was hoisted, and the one it
+ ships itself: `bin`, as the package's own script says, `codex` in older ones */
+ const exe = [
+ join(pkg, 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'bin', 'codex.exe'),
+ join(pkg, '..', `codex-win32-${process.arch}`, 'vendor', triple, 'bin', 'codex.exe'),
+ join(pkg, 'vendor', triple, 'bin', 'codex.exe'),
+ join(pkg, 'vendor', triple, 'codex', 'codex.exe'),
+ join(pkg, 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'codex', 'codex.exe'),
+ ].find(existsFile);
if (exe) return exe;
+ /* a shell command cannot start the script, so the shim it came from (null here) is used instead */
+ continue;
}
if (existsFile(target)) return target;
}
diff --git a/apps/desktop/src/agent-installation.test.mjs b/apps/desktop/src/agent-installation.test.mjs
index c0d7e41..88f8846 100644
--- a/apps/desktop/src/agent-installation.test.mjs
+++ b/apps/desktop/src/agent-installation.test.mjs
@@ -55,12 +55,31 @@ test("npm's shim as it is written today: what it runs, never the node.exe it che
});
test("Codex's npm shim: its own program for this machine's chip, not the script that starts it", () => {
+ const triple = process.arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
+ /* where the package puts the program: in the platform package it installs, beside its script or hoisted one folder
+ up (`bin`, as the package's own script says), or in itself (`bin`, and `codex` in older ones) */
+ const layouts = [
+ ['node_modules', '@openai', 'codex', 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'bin', 'codex.exe'],
+ ['node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'bin', 'codex.exe'],
+ ['node_modules', '@openai', 'codex', 'vendor', triple, 'bin', 'codex.exe'],
+ ['node_modules', '@openai', 'codex', 'vendor', triple, 'codex', 'codex.exe'],
+ ['node_modules', '@openai', 'codex', 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'codex', 'codex.exe'],
+ ];
+ for (const layout of layouts) {
+ const npm = mkdtempSync(join(tmpdir(), 'of-npm-'));
+ put(join(npm, 'node_modules', '@openai', 'codex', 'bin', 'codex.js'));
+ const exe = put(join(npm, ...layout));
+ put(join(npm, 'codex.cmd'), npmShim('node_modules\\@openai\\codex\\bin\\codex.js'));
+ assert.equal(cmdTarget(join(npm, 'codex.cmd')), exe, layout.join('/'));
+ }
+});
+
+test("Codex's shim with no program of its own: the shim itself, never its script, which a shell command cannot start", () => {
const npm = mkdtempSync(join(tmpdir(), 'of-npm-'));
put(join(npm, 'node_modules', '@openai', 'codex', 'bin', 'codex.js'));
- const triple = process.arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
- const exe = put(join(npm, 'node_modules', '@openai', 'codex', 'node_modules', '@openai', `codex-win32-${process.arch}`, 'vendor', triple, 'codex', 'codex.exe'));
put(join(npm, 'codex.cmd'), npmShim('node_modules\\@openai\\codex\\bin\\codex.js'));
- assert.equal(cmdTarget(join(npm, 'codex.cmd')), exe);
+ assert.equal(cmdTarget(join(npm, 'codex.cmd')), null);
+ assert.equal(findExecutable('codex', [], { PATH: npm }, { win: true }), join(npm, 'codex.cmd'));
});
test("pnpm's shim (%~dp0, node.exe beside it or not) and Yarn's, which runs another shim", () => {