Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(windows): run PowerShell by its absolute System32 path

reviewbdb41ff0c85d
diff --git a/src/core/dev-ports-win32.test.ts b/src/core/dev-ports-win32.test.ts
index e2789c0d7..26071fa98 100644
--- a/src/core/dev-ports-win32.test.ts
+++ b/src/core/dev-ports-win32.test.ts
@@ -11,7 +11,7 @@ import {
parseWinNetTcpListeners,
WIN32_DEV_PORTS_SCRIPT
} from './dev-ports'
-import { powershellArgs, POWERSHELL_EXE } from './win32-powershell'
+import { powershellArgs, powershellExe } from './win32-powershell'
import type { SessionHostListing } from './session-host-client'
const PROCS_JSON = JSON.stringify([
@@ -133,7 +133,7 @@ describe('collectWin32DevPorts / collectLocalDevPorts(win32)', () => {
return probe('nettcp', NETTCP_JSON)
}
})
- expect(calls).toEqual([{ bin: POWERSHELL_EXE, args: powershellArgs(WIN32_DEV_PORTS_SCRIPT) }])
+ expect(calls).toEqual([{ bin: powershellExe(), args: powershellArgs(WIN32_DEV_PORTS_SCRIPT) }])
expect(r.ok).toBe(true)
expect(r.nodes.web?.[0].port).toBe(5173)
})
diff --git a/src/core/dev-ports.ts b/src/core/dev-ports.ts
index f5269c0e1..1e39964e3 100644
--- a/src/core/dev-ports.ts
+++ b/src/core/dev-ports.ts
@@ -28,7 +28,7 @@ import { fencedListPanesCommand, parseFencedPanes } from './session-memory-remot
import { TMUX_SOCKET } from './tmux-naming'
import { RMT_TMUX_SOCKET } from './remote-ssh/control-master'
import type { SessionHostListing } from './session-host-client'
-import { cimRows, powershellArgs, POWERSHELL_EXE } from './win32-powershell'
+import { cimRows, powershellArgs, powershellExe } from './win32-powershell'
const runAsync = promisify(execFile)
@@ -559,7 +559,7 @@ export async function collectWin32DevPorts(
.map((row) => ({ session: row.name, panePid: row.pid, command: '' }))
if (panes.length === 0) return { ok: true, nodes: {} }
try {
- return parseWin32DevPortsProbe(await exec(POWERSHELL_EXE, powershellArgs(WIN32_DEV_PORTS_SCRIPT)), panes)
+ return parseWin32DevPortsProbe(await exec(powershellExe(), powershellArgs(WIN32_DEV_PORTS_SCRIPT)), panes)
} catch {
return fail('unreachable')
}
diff --git a/src/core/session-memory-session-host.test.ts b/src/core/session-memory-session-host.test.ts
index 618381bf6..85faa444e 100644
--- a/src/core/session-memory-session-host.test.ts
+++ b/src/core/session-memory-session-host.test.ts
@@ -8,7 +8,7 @@ import {
WIN32_PROCESS_TABLE_SCRIPT,
type ProcEntry
} from './session-memory'
-import { cimRows, powershellArgs, POWERSHELL_EXE } from './win32-powershell'
+import { cimRows, powershellArgs, powershellExe } from './win32-powershell'
import type { SessionHostListing } from './session-host-client'
import { sessionName } from './tmux-naming'
@@ -65,7 +65,7 @@ describe('parseWin32ProcessTable', () => {
return '{"ProcessId":7,"ParentProcessId":1,"WorkingSetSize":1024}'
})
expect(table).toEqual([P(7, 1, 1)])
- expect(calls).toEqual([{ bin: POWERSHELL_EXE, args: powershellArgs(WIN32_PROCESS_TABLE_SCRIPT) }])
+ expect(calls).toEqual([{ bin: powershellExe(), args: powershellArgs(WIN32_PROCESS_TABLE_SCRIPT) }])
await expect(
win32ProcessTable(async () => {
throw new Error('exit 1')
@@ -109,7 +109,7 @@ describe('collectSessionHostMemory', () => {
return JSON.stringify([{ ProcessId: 100, ParentProcessId: 1, WorkingSetSize: 4 * 1024 * 1024 }])
}
})
- expect(bins).toEqual([POWERSHELL_EXE])
+ expect(bins).toEqual([powershellExe()])
expect(r.rows[0]).toMatchObject({ session: 'nt-a', totalMb: 4 })
})
diff --git a/src/core/session-memory.ts b/src/core/session-memory.ts
index 197383110..f1faff46e 100644
--- a/src/core/session-memory.ts
+++ b/src/core/session-memory.ts
@@ -16,7 +16,7 @@ import type { MemInfo, SessionMemoryRow, SessionMemoryReport } from '../shared/t
import { TMUX_SOCKET } from './tmux-naming'
import { RMT_TMUX_SOCKET } from './remote-ssh/control-master'
import type { SessionHostListing } from './session-host-client'
-import { cimRows, powershellArgs, POWERSHELL_EXE } from './win32-powershell'
+import { cimRows, powershellArgs, powershellExe } from './win32-powershell'
export type { MemInfo, SessionMemoryRow, SessionMemoryReport }
@@ -496,7 +496,7 @@ export async function win32ProcessTable(
exec: (bin: string, args: string[]) => Promise<string>
): Promise<ProcEntry[] | null> {
try {
- return parseWin32ProcessTable(await exec(POWERSHELL_EXE, powershellArgs(WIN32_PROCESS_TABLE_SCRIPT)))
+ return parseWin32ProcessTable(await exec(powershellExe(), powershellArgs(WIN32_PROCESS_TABLE_SCRIPT)))
} catch {
return null
}
diff --git a/src/core/win32-powershell.test.ts b/src/core/win32-powershell.test.ts
new file mode 100644
index 000000000..4b953d04e
--- /dev/null
+++ b/src/core/win32-powershell.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest'
+import { cimRows, powershellExe } from './win32-powershell'
+
+describe('powershellExe', () => {
+ it('is an ABSOLUTE System32 path — never a bare name Windows would resolve against the cwd first', () => {
+ expect(powershellExe({ SystemRoot: 'D:\\Win' })).toBe(
+ 'D:\\Win\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
+ )
+ expect(powershellExe({ WINDIR: 'E:\\W' })).toBe('E:\\W\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')
+ expect(powershellExe({})).toBe('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')
+ })
+})
+
+describe('cimRows', () => {
+ it('accepts an object, an array and empty output; rejects anything else', () => {
+ expect(cimRows('{"a":1}')).toEqual([{ a: 1 }])
+ expect(cimRows('[{"a":1},{"a":2}]')).toHaveLength(2)
+ expect(cimRows(' ')).toEqual([])
+ expect(cimRows('[{"a":1}')).toBeNull()
+ expect(cimRows('3')).toBeNull()
+ })
+})
diff --git a/src/core/win32-powershell.ts b/src/core/win32-powershell.ts
index f5dd49971..01c01f152 100644
--- a/src/core/win32-powershell.ts
+++ b/src/core/win32-powershell.ts
@@ -2,8 +2,18 @@
// dev-server ports' listeners). Pure argv + parsing; the subprocess itself always runs through the
// caller's injectable exec seam, so every consumer stays testable on any CI host.
-/** Windows PowerShell 5.1 ships with every supported Windows; `pwsh` is optional and not assumed. */
-export const POWERSHELL_EXE = 'powershell.exe'
+/**
+ * Windows PowerShell 5.1 ships with every supported Windows at this exact path; `pwsh` is optional
+ * and not assumed. ABSOLUTE, never a bare `powershell.exe`: Windows' executable search tries the
+ * CURRENT DIRECTORY before PATH, so a bare name run from a user-writable cwd (the Server Edition's
+ * working directory, say) would execute whatever `powershell.exe` sits there — and a GUI-launched
+ * app's PATH may not carry the PowerShell directory at all. Same resolution as
+ * `session-host-runtime.ts`'s process query and pty-manager's shell fallback.
+ */
+export function powershellExe(env: NodeJS.ProcessEnv = process.env): string {
+ const systemRoot = env.SystemRoot || env.WINDIR || 'C:\\Windows'
+ return `${systemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
+}
/**
* Argv for one unattended script. `-NoProfile`: a user profile can take seconds and print into the