Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(windows): fall back to the native command interpreter

Seth Wilson54f5ab684860
diff --git a/src/utils/platform.test.ts b/src/utils/platform.test.ts
index d7f01f56..125d867e 100644
--- a/src/utils/platform.test.ts
+++ b/src/utils/platform.test.ts
@@ -48,6 +48,19 @@ describe('resolveShell', () => {
expect(resolveShell({ MERCURY_SHELL: '/missing', SHELL: '/shell/sh' }, fileExists)).toBe('/shell/sh');
});
+ it('uses the Windows command interpreter, including paths with spaces', () => {
+ const comspec = 'C:\\Windows System\\System32\\cmd.exe';
+ expect(resolveShell({ ComSpec: comspec }, (path) => path === comspec, 'win32')).toBe(comspec);
+ expect(resolveShell({ COMSPEC: comspec }, (path) => path === comspec, 'win32')).toBe(comspec);
+ expect(resolveShell({ SHELL: '/missing/sh' }, () => false, 'win32')).toBe('cmd.exe');
+ expect(resolveShell({}, () => false, 'win32')).toBe('cmd.exe');
+ });
+
+ it('preserves explicit shell configuration on Windows', () => {
+ expect(resolveShell({ MERCURY_SHELL: '/custom/sh', ComSpec: 'cmd.exe' }, fileExists, 'win32'))
+ .toBe('/custom/sh');
+ });
+
it('uses the Termux prefix shell before /bin/sh', () => {
expect(resolveShell({ TERMUX_VERSION: '0.119', PREFIX: '/data/data/com.termux/files/usr' }, fileExists, 'linux'))
.toBe('/data/data/com.termux/files/usr/bin/sh');
diff --git a/src/utils/platform.ts b/src/utils/platform.ts
index 52d775db..b91bba0d 100644
--- a/src/utils/platform.ts
+++ b/src/utils/platform.ts
@@ -34,7 +34,9 @@ export function resolveShell(
if (isTermux(env, platform)) {
candidates.push(env.PREFIX ? posixPath.join(env.PREFIX, 'bin', 'sh') : undefined);
}
- candidates.push('/bin/sh');
+ const fallback = platform === 'win32' ? 'cmd.exe' : '/bin/sh';
+ if (platform === 'win32') candidates.push(env.ComSpec || env.COMSPEC);
+ candidates.push(fallback);
- return candidates.find((candidate) => candidate && fileExists(candidate)) || '/bin/sh';
+ return candidates.find((candidate) => candidate && fileExists(candidate)) || fallback;
}
diff --git a/src/web/api/workspace-ide.test.ts b/src/web/api/workspace-ide.test.ts
index f47d2292..036ff1ad 100644
--- a/src/web/api/workspace-ide.test.ts
+++ b/src/web/api/workspace-ide.test.ts
@@ -74,6 +74,37 @@ describe('workspace and git hardening', () => {
expect(subject).toBe(message);
});
+ it('runs terminal commands in a workspace path with spaces using the native shell', async () => {
+ const { default: ide } = await import('./workspace-ide.js');
+ const cwd = 'folder with spaces';
+ mkdirSync(join(repo, cwd));
+ const previousShell = process.env.SHELL;
+ const previousOverride = process.env.MERCURY_SHELL;
+ delete process.env.SHELL;
+ delete process.env.MERCURY_SHELL;
+ try {
+ const res = await ide.request('http://127.0.0.1/api/terminal/exec', {
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ command: 'echo mercury-terminal-ready', cwd }),
+ });
+ expect(res.status).toBe(200);
+ expect(await res.json()).toMatchObject({
+ success: true, exitCode: 0, cwd: join(repo, cwd),
+ output: expect.stringContaining('mercury-terminal-ready'),
+ });
+ const denied = await ide.request('http://127.0.0.1/api/terminal/exec', {
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ command: 'echo must-not-run', cwd: '..' }),
+ });
+ expect(denied.status).toBe(403);
+ } finally {
+ if (previousShell === undefined) delete process.env.SHELL;
+ else process.env.SHELL = previousShell;
+ if (previousOverride === undefined) delete process.env.MERCURY_SHELL;
+ else process.env.MERCURY_SHELL = previousOverride;
+ }
+ });
+
it('rejects an option-shaped branch and a path outside the workspace', async () => {
const { default: ide } = await import('./workspace-ide.js');
const checkout = await ide.request('http://127.0.0.1/api/git/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ branch: '--orphan=x' }) });