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

launch the resolved executable, not the bare name, in spawnCommandSession

[._.]/ Adam Eivy1be8237b4271
diff --git a/server/services/shell.js b/server/services/shell.js
index 4642eb4e30..9bdeb7bc59 100644
--- a/server/services/shell.js
+++ b/server/services/shell.js
@@ -459,15 +459,24 @@ export function spawnCommandSession(command, args = [], options = {}) {
// provider's own bin dir. Same pre-flight `tuiPromptRunner` and the CoS
// runner's `/spawn-tui` do; `basename` keeps the resolved path, which can
// embed the local account name, out of the message.
- if (!findCommandOnPath(command, { env: childEnv, cwd })) {
+ const executable = findCommandOnPath(command, { env: childEnv, cwd });
+ if (!executable) {
throw new Error(`Command executable unavailable: ${basename(command)} is not on the PATH for this session. Install it or update the configured command.`);
}
- // Windows resolves a bare name to its `.cmd`/`.bat` shim and must launch it
- // through cmd.exe (never the user's shell — that wrapper runs no profile);
- // on POSIX both steps are no-ops and the binary is spawned directly. Same
- // helper the CoS runner's /spawn-tui uses, so the two direct-PTY paths can't
- // drift on escaping.
- const { command: ptyCommand, args: ptyArgs } = prepareCliSpawn(command, args, childEnv);
+ // Launch the path the pre-flight actually RESOLVED, not the bare name — the
+ // CoS runner's /spawn-tui does the same, and for the same reason. The two
+ // resolvers do not agree on Windows: `findCommandOnPath` unquotes a PATH
+ // entry, maps an empty one to cwd, resolves relative entries, and searches
+ // all of PATHEXT, while `prepareCliSpawn`'s own lookup does none of that. Re-
+ // resolving the bare name could therefore fall through to a bare
+ // extensionless `claude`, which ConPTY cannot launch — a blank PTY and a bare
+ // exit-1, the exact failure this pre-flight exists to prevent.
+ //
+ // prepareCliSpawn still runs: a resolved `.cmd`/`.bat` shim must launch
+ // through cmd.exe (never the user's shell — that wrapper runs no profile),
+ // and it owns the shared argument-escaping contract. On POSIX it is a no-op
+ // and the binary is spawned directly.
+ const { command: ptyCommand, args: ptyArgs } = prepareCliSpawn(executable, args, childEnv);
console.log(`🐚 Creating command session ${sessionId.slice(0, 8)} (${basename(command)})`);
const ptyProcess = pty.spawn(ptyCommand, ptyArgs, {
diff --git a/server/services/shell.test.js b/server/services/shell.test.js
index 0fe7624e94..4c50ba0b2f 100644
--- a/server/services/shell.test.js
+++ b/server/services/shell.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
-import { dirname } from 'path';
+import { basename, dirname } from 'path';
let ptyInstances = [];
let spawnImpl;
@@ -633,6 +633,22 @@ describe('spawnCommandSession', () => {
expect(ptyInstances[0].write).not.toHaveBeenCalled();
});
+ it('launches the RESOLVED path, not the bare name it was given', () => {
+ // The pre-flight's resolution has to be the one that launches. Handing the
+ // bare name onward lets prepareCliSpawn re-resolve under different rules —
+ // on Windows it does not unquote a PATH entry, map an empty one to cwd,
+ // resolve a relative one, or search all of PATHEXT — so a name the guard
+ // just accepted can fall through to a bare extensionless command that
+ // ConPTY cannot launch: a blank PTY and a bare exit-1, which is the exact
+ // failure the pre-flight exists to prevent. The CoS runner's /spawn-tui
+ // feeds prepareCliSpawn its resolved `executable` for the same reason.
+ shell.spawnCommandSession(basename(REAL_BIN), [], {
+ cwd: '/tmp/ws',
+ env: { PATH: REAL_BIN_DIR },
+ });
+ expect(vi.mocked(defaultSpawn).mock.calls[0][0]).toBe(REAL_BIN);
+ });
+
it('resolves the command against the CHILD PATH before spawning, and names it when missing', () => {
// A PTY has no shell to print "command not found" — on POSIX node-pty forks
// and `execvp` fails in the CHILD, which exits 1 with an empty screen. So a