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(core): commit-agent binary lookup — absolute Windows paths, POSIX-only fallbacks, gate ordering

Erik Zwep56406ff408e3
diff --git a/src/core/commit-message.test.ts b/src/core/commit-message.test.ts
index 433adecaf..25776b0f6 100644
--- a/src/core/commit-message.test.ts
+++ b/src/core/commit-message.test.ts
@@ -1,6 +1,8 @@
-import { afterEach, describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import fs from 'fs'
import os from 'os'
-import { localAgentCwd } from './commit-message'
+import path from 'path'
+import { localAgentCwd, resolveBinary } from './commit-message'
/**
* The 2026-08-05 report: "AI commit message" failed on every SSH project with
@@ -96,3 +98,40 @@ describe('runAgent — where the agent is actually spawned', () => {
expect(await spawnCwdFor('/root/nodeterm', true)).toBe(os.homedir())
})
})
+
+/**
+ * `resolveBinary` decides which CLI "AI commit message" and "Name with AI" spawn. It was POSIX-only
+ * in two ways at once on Windows: `startsWith('/')` never recognised an absolute path there, and the
+ * hardcoded fallbacks are extensionless POSIX paths that no Windows install can match.
+ */
+describe('resolveBinary', () => {
+ let dir: string
+
+ beforeEach(() => {
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-resolve-bin-'))
+ })
+ afterEach(() => {
+ fs.rmSync(dir, { recursive: true, force: true })
+ })
+
+ it('accepts an absolute path that exists, and rejects one that does not', () => {
+ // The regression: on Windows this argument is `C:\…`, which `startsWith('/')` never matched, so
+ // an absolute custom command fell through to the bare-name branch and was rejected there for
+ // containing `:` and `\`.
+ const bin = path.join(dir, 'agent.exe')
+ fs.writeFileSync(bin, '', { mode: 0o755 })
+ expect(resolveBinary(bin)).toBe(bin)
+ expect(resolveBinary(path.join(dir, 'absent.exe'))).toBeNull()
+ })
+
+ it('refuses a relative path — only a bare name or an absolute path may be spawned', () => {
+ // Anything that is not a bare binary name stays well out of injection territory.
+ expect(resolveBinary('../../evil')).toBeNull()
+ expect(resolveBinary('sub/dir/agent')).toBeNull()
+ expect(resolveBinary('agent; rm -rf /')).toBeNull()
+ })
+
+ it('answers null for a bare name that is nowhere', () => {
+ expect(resolveBinary('nt-definitely-not-installed')).toBeNull()
+ })
+})
diff --git a/src/core/commit-message.ts b/src/core/commit-message.ts
index 02c44d3db..7d929b79d 100644
--- a/src/core/commit-message.ts
+++ b/src/core/commit-message.ts
@@ -1,6 +1,7 @@
import { execFile, spawn } from 'child_process'
import fs from 'fs'
import os from 'os'
+import path from 'path'
import { promisify } from 'util'
import type { GitResult, Settings } from '../shared/types'
import { findInPathString, shellPathNow } from './exec-path'
@@ -14,16 +15,37 @@ const TIMEOUT_MS = 120_000
const bytes = (s: string) => Buffer.byteLength(s, 'utf-8')
-/** Resolve a CLI binary to an absolute path (GUI apps don't inherit the shell PATH). */
-function resolveBinary(name: string): string | null {
- if (name.startsWith('/')) return fs.existsSync(name) ? name : null
- const candidates = [
- `${os.homedir()}/.local/bin/${name}`,
- `${os.homedir()}/.claude/local/${name}`,
- `/opt/homebrew/bin/${name}`,
- `/usr/local/bin/${name}`,
- `/usr/bin/${name}`
- ]
+/** Resolve a CLI binary to an absolute path (GUI apps don't inherit the shell PATH).
+ * Exported for tests only — every caller is in this module. */
+export function resolveBinary(name: string): string | null {
+ // `path.isAbsolute`, not `startsWith('/')`. A Windows absolute path (`C:\Tools\agent.exe`, or a
+ // UNC `\\server\share\agent.exe`) does not start with `/`, so it missed this branch, fell
+ // through to the bare-name path below, and was then rejected by that branch's charset gate for
+ // containing `:` and `\`. The effect was that a custom commit agent could not be given as a full
+ // path on Windows at all.
+ if (path.isAbsolute(name)) return fs.existsSync(name) ? name : null
+ // `name` comes from a user setting (the custom commit agent), so anything that is not a bare
+ // binary name is refused here — BEFORE it is interpolated into the paths below. It used to be
+ // checked only after that loop, which let a name like `../../evil` normalize out of the
+ // directories the loop is meant to confine it to (`~/.local/bin/../../evil` is `~/evil`). Same
+ // rule as before, applied where it actually confines.
+ if (!/^[A-Za-z0-9._-]+$/.test(name)) return null
+ // GUI apps inherit a minimal PATH, so these user-install locations are checked BEFORE the PATH
+ // walk — deliberately, and left in that order here. They are POSIX paths without a file
+ // extension, which on Windows can only ever match an extensionless file: never the real
+ // `<name>.exe`/`<name>.cmd`, and possibly something `spawn()` cannot execute at all (a shell
+ // script, say). Skipped there rather than left to misfire; the PATH walk below is the one that
+ // can actually answer on Windows.
+ const candidates =
+ os.platform() === 'win32'
+ ? []
+ : [
+ `${os.homedir()}/.local/bin/${name}`,
+ `${os.homedir()}/.claude/local/${name}`,
+ `/opt/homebrew/bin/${name}`,
+ `/usr/local/bin/${name}`,
+ `/usr/bin/${name}`
+ ]
for (const c of candidates) {
try {
if (fs.existsSync(c)) return c
@@ -32,10 +54,7 @@ function resolveBinary(name: string): string | null {
}
}
// Resolve via PATH without a shell OR a subprocess: walk the cached login-shell PATH from
- // exec-path.ts (the inherited GUI PATH misses user-installed bins). `name` comes from a user
- // setting (custom commit agent) — reject anything that isn't a bare binary name to keep it
- // well out of injection territory.
- if (!/^[A-Za-z0-9._-]+$/.test(name)) return null
+ // exec-path.ts (the inherited GUI PATH misses user-installed bins).
return findInPathString(name, shellPathNow() ?? process.env.PATH)
}