Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): drop .cmd/.bat shim matching — only .exe is spawnable

Adam Eivy86d2f485df9b
diff --git a/server/cos-runner/allowedCommands.js b/server/cos-runner/allowedCommands.js
index 22a3117ac3..ae4f876a23 100644
--- a/server/cos-runner/allowedCommands.js
+++ b/server/cos-runner/allowedCommands.js
@@ -32,10 +32,12 @@ export function isAllowedCommand(command) {
// Extract base command name from full path (e.g., /usr/bin/claude -> claude)
// Uses path.basename for correct handling on both Unix and Windows
let baseName = basename(command);
- // Normalize for Windows: strip a trailing shim extension (.exe / .cmd / .bat,
- // case-insensitive) so an npm/bun global-bin shim path (e.g. opencode.cmd,
- // claude.cmd) matches its bare allowlist entry — mirrors the basename +
- // extension normalization the OpenCode arg builders use (isOpencodeCommand).
- baseName = baseName.replace(/\.(exe|cmd|bat)$/i, '');
+ // Normalize for Windows: strip trailing .exe (case-insensitive). Only .exe —
+ // .cmd/.bat npm shims are deliberately NOT accepted because the spawn path runs
+ // `spawn(cmd, args, { shell: false })`, which cannot execute a shim batch file;
+ // accepting them here would only move the failure to spawn time.
+ if (baseName.toLowerCase().endsWith('.exe')) {
+ baseName = baseName.slice(0, -4);
+ }
return ALLOWED_COMMANDS.has(baseName);
}
diff --git a/server/cos-runner/allowedCommands.test.js b/server/cos-runner/allowedCommands.test.js
index 698904d0bd..7b3f110936 100644
--- a/server/cos-runner/allowedCommands.test.js
+++ b/server/cos-runner/allowedCommands.test.js
@@ -25,17 +25,6 @@ describe('isAllowedCommand', () => {
expect(isAllowedCommand('opencode')).toBe(true);
expect(isAllowedCommand('/opt/homebrew/bin/opencode')).toBe(true);
});
-
- it('allows Windows npm/bun shim extensions (.cmd / .bat) for allowed commands', () => {
- // Bare + forward-slash forms parse the same on POSIX and Windows. (A full
- // backslash path like C:\\...\\opencode.cmd only splits via path.basename on
- // a Windows host — the existing claude.exe case documents that limitation.)
- expect(isAllowedCommand('opencode.cmd')).toBe(true);
- expect(isAllowedCommand('claude.bat')).toBe(true);
- expect(isAllowedCommand('/c/npm/opencode.cmd')).toBe(true);
- // still rejects a non-allowlisted command regardless of shim extension
- expect(isAllowedCommand('rm.cmd')).toBe(false);
- });
});
describe('Windows .exe stripping', () => {
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index 9cfc3440e4..3284410037 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -20,15 +20,17 @@ export const resolveCliModel = (model) => isCodexConfiguredDefault(model) ? null
/**
* True when a provider command points at the OpenCode binary — matching the bare
* `opencode` on PATH OR an absolute/relative path to it (`/opt/homebrew/bin/opencode`,
- * common when the service PATH can't resolve the CLI), and a Windows `.exe`/`.cmd`/`.bat`
- * shim. The OpenCode arg-builder branches key on this rather than `command === 'opencode'`
- * so a path-configured provider isn't misrouted into the Claude-style invocation.
+ * common when the service PATH can't resolve the CLI), with an optional Windows `.exe`
+ * suffix. The OpenCode arg-builder branches key on this rather than `command === 'opencode'`
+ * so a path-configured provider isn't misrouted into the Claude-style invocation. Only
+ * `.exe` is stripped (not `.cmd`/`.bat`), matching the runner allowlist and the
+ * `shell: false` spawn path — a batch shim isn't directly spawnable.
* @param {string|null|undefined} command
* @returns {boolean}
*/
export function isOpencodeCommand(command) {
if (typeof command !== 'string' || command === '') return false;
- const base = command.split(/[\\/]/).pop().toLowerCase().replace(/\.(exe|cmd|bat)$/, '');
+ const base = command.split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '');
return base === 'opencode';
}
diff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.js
index 972907692d..453fd70a11 100644
--- a/server/lib/providerModels.test.js
+++ b/server/lib/providerModels.test.js
@@ -31,18 +31,19 @@ describe('providerModels', () => {
});
describe('isOpencodeCommand', () => {
- it('matches the bare binary and path/extension variants', () => {
+ it('matches the bare binary, a path, and a Windows .exe', () => {
expect(isOpencodeCommand('opencode')).toBe(true);
expect(isOpencodeCommand('/opt/homebrew/bin/opencode')).toBe(true);
expect(isOpencodeCommand('./bin/opencode')).toBe(true);
expect(isOpencodeCommand('C:\\tools\\opencode.exe')).toBe(true);
- expect(isOpencodeCommand('opencode.cmd')).toBe(true);
});
- it('rejects other commands and non-strings', () => {
+ it('rejects other commands, batch shims, and non-strings', () => {
expect(isOpencodeCommand('claude')).toBe(false);
expect(isOpencodeCommand('/usr/bin/codex')).toBe(false);
expect(isOpencodeCommand('opencode-wrapper')).toBe(false);
+ // .cmd/.bat shims aren't directly spawnable (shell:false), so not matched
+ expect(isOpencodeCommand('opencode.cmd')).toBe(false);
expect(isOpencodeCommand('')).toBe(false);
expect(isOpencodeCommand(null)).toBe(false);
expect(isOpencodeCommand(undefined)).toBe(false);
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index e7a83d54f6..77c4b82a17 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -106,10 +106,10 @@ vi.mock('../lib/providerModels.js', () => ({
resolveBedrockCliModel: vi.fn((m) => m),
// Mirror the real opencode-command basename match (fully unit-tested in
// providerModels.test.js).
- isOpencodeCommand: vi.fn((c) => typeof c === 'string' && c.split(/[\\/]/).pop().toLowerCase().replace(/\.(exe|cmd|bat)$/, '') === 'opencode'),
+ isOpencodeCommand: vi.fn((c) => typeof c === 'string' && c.split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '') === 'opencode'),
// Mirror the real ollama/ namespacing for opencode providers (fully unit-
// tested in providerModels.test.js).
- prefixOpencodeModel: vi.fn((p, m) => (typeof p?.command === 'string' && p.command.split(/[\\/]/).pop().toLowerCase().replace(/\.(exe|cmd|bat)$/, '') === 'opencode' && p?.ollamaBacked === true && m && !String(m).startsWith('ollama/')) ? `ollama/${m}` : m),
+ prefixOpencodeModel: vi.fn((p, m) => (typeof p?.command === 'string' && p.command.split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, '') === 'opencode' && p?.ollamaBacked === true && m && !String(m).startsWith('ollama/')) ? `ollama/${m}` : m),
// Mirror hasModelFlag (real impl unit-tested in providerModels.test.js).
hasModelFlag: vi.fn((a) => Array.isArray(a) && a.some((x) => x === '--model' || x === '-m' || (typeof x === 'string' && (x.startsWith('--model=') || x.startsWith('-m=')))))
}));