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): {promptFile} for custom commit agents, explicit {prompt} refusal on win32

review4f45206dbf1a
diff --git a/src/core/commit-message.test.ts b/src/core/commit-message.test.ts
index 2fef861e8..0fac5f68d 100644
--- a/src/core/commit-message.test.ts
+++ b/src/core/commit-message.test.ts
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import fs from 'fs'
import os from 'os'
import path from 'path'
-import { localAgentCwd, resolveBinary } from './commit-message'
+import { WINDOWS_INLINE_PROMPT_ERROR, localAgentCwd, planAgent, resolveBinary, runAgent } from './commit-message'
/**
* The 2026-08-05 report: "AI commit message" failed on every SSH project with
@@ -224,3 +224,88 @@ describe('AI naming account + error output', () => {
expect(env.PATH).toBe('/bin')
})
})
+
+/**
+ * `{prompt}` inlines the prompt as one argv element. On Windows an npm `.cmd` shim refuses a CR/LF
+ * argument outright and every CLI is capped by CreateProcess's command-line length, so that plan is
+ * refused with a sentence up front; `{promptFile}` (a private temp file's path) works everywhere.
+ */
+describe('planAgent — {prompt} / {promptFile}', () => {
+ let dir: string
+ const custom = (cmd: string) => ({ commitAgent: 'custom', commitAgentCommand: cmd }) as never
+ const PROMPT = 'Write a commit message.\nStaged diff:\n+ x'
+
+ beforeEach(() => {
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-plan-'))
+ })
+ afterEach(() => {
+ fs.rmSync(dir, { recursive: true, force: true })
+ })
+
+ const bin = (name: string): string => {
+ const p = path.join(dir, name)
+ fs.writeFileSync(p, '')
+ return p
+ }
+
+ it('writes {promptFile} as a private file, substitutes its path, and cleanup removes it', () => {
+ const agent = bin('agent')
+ const plan = planAgent(custom(`${agent} --file {promptFile}`), PROMPT, { tmpDir: dir })
+ if ('error' in plan) throw new Error(plan.error)
+ expect(plan.stdin).toBeNull()
+ expect(plan.args[0]).toBe('--file')
+ const file = plan.args[1]
+ expect(path.dirname(path.dirname(file))).toBe(dir)
+ expect(fs.readFileSync(file, 'utf8')).toBe(PROMPT)
+ if (process.platform !== 'win32') expect(fs.statSync(file).mode & 0o777).toBe(0o600)
+ plan.cleanup?.()
+ expect(fs.existsSync(path.dirname(file))).toBe(false)
+ })
+
+ it('keeps POSIX {prompt} inline and the default on stdin, unchanged', () => {
+ const agent = bin('agent')
+ expect(planAgent(custom(`${agent} -p {prompt}`), PROMPT, { platform: 'linux' })).toEqual({
+ bin: agent,
+ args: ['-p', PROMPT],
+ stdin: null
+ })
+ expect(planAgent(custom(`${agent} -p`), PROMPT, { platform: 'darwin' })).toEqual({
+ bin: agent,
+ args: ['-p'],
+ stdin: PROMPT
+ })
+ })
+
+ it('refuses {prompt} for a .cmd shim on win32 with an actionable sentence', () => {
+ const shim = bin('mycli.cmd')
+ expect(planAgent(custom(`${shim} {prompt}`), PROMPT, { platform: 'win32' })).toEqual({
+ error: WINDOWS_INLINE_PROMPT_ERROR
+ })
+ })
+
+ it('refuses {prompt} past the Windows command-line limit even for an .exe', () => {
+ const exe = bin('agent.exe')
+ const long = 'x'.repeat(40_000)
+ expect(planAgent(custom(`${exe} {prompt}`), long, { platform: 'win32' })).toEqual({
+ error: WINDOWS_INLINE_PROMPT_ERROR
+ })
+ expect(planAgent(custom(`${exe} {prompt}`), 'short', { platform: 'win32' })).toMatchObject({
+ args: ['short']
+ })
+ })
+
+ it('serves {promptFile} on win32 for the same .cmd shim', () => {
+ const shim = bin('mycli.cmd')
+ const plan = planAgent(custom(`${shim} --file {promptFile}`), PROMPT, { platform: 'win32', tmpDir: dir })
+ expect('error' in plan).toBe(false)
+ if (!('error' in plan)) plan.cleanup?.()
+ })
+
+ it.skipIf(process.platform === 'win32')('runAgent hands the file to a real CLI and removes it after', async () => {
+ const before = new Set(fs.readdirSync(os.tmpdir()).filter((n) => n.startsWith('nt-prompt-')))
+ const r = await runAgent('Fix the parser', dir, custom('cat {promptFile}'))
+ expect(r).toEqual({ ok: true, message: 'Fix the parser' })
+ const after = fs.readdirSync(os.tmpdir()).filter((n) => n.startsWith('nt-prompt-') && !before.has(n))
+ expect(after).toEqual([])
+ })
+})
diff --git a/src/core/commit-message.ts b/src/core/commit-message.ts
index 23cc16972..e5731e75b 100644
--- a/src/core/commit-message.ts
+++ b/src/core/commit-message.ts
@@ -149,17 +149,70 @@ interface Plan {
bin: string
args: string[]
stdin: string | null
+ /** Removes what the plan created ({promptFile}'s temp dir); call once the agent has exited. */
+ cleanup?: () => void
}
-function planAgent(settings: Settings, prompt: string): Plan | { error: string } {
+/** CreateProcess caps the whole command line at 32,767 UTF-16 units; keep headroom for quoting. */
+const WIN_CMDLINE_MAX = 32_000
+
+/** A Windows command line's length for `bin args…` as libuv quotes it: each element wrapped in
+ * quotes, every `"` and `\` possibly escaped — an upper bound, which is what a refusal needs. */
+function winCommandLineLength(bin: string, args: string[]): number {
+ const quoted = (a: string) => a.length + 3 + (a.match(/["\\]/g)?.length ?? 0)
+ return [bin, ...args].reduce((n, a) => n + quoted(a), 0)
+}
+
+/** Why a `{prompt}` plan cannot work on Windows — said up front, instead of the spawn failing with
+ * "Cannot safely execute Windows script" or a raw ENAMETOOLONG. */
+export const WINDOWS_INLINE_PROMPT_ERROR =
+ 'On Windows this command cannot receive a multi-line prompt as an argument (npm .cmd shim / command-line length limit). Remove {prompt} to send it on stdin, or use {promptFile}.'
+
+export interface PlanAgentOptions {
+ /** The platform to plan for (default `os.platform()`). */
+ platform?: NodeJS.Platform
+ /** Where {promptFile}'s private temp dir is made (default `os.tmpdir()`). */
+ tmpDir?: string
+}
+
+/** Exported for tests only. */
+export function planAgent(settings: Settings, prompt: string, opts: PlanAgentOptions = {}): Plan | { error: string } {
+ const platform = opts.platform ?? os.platform()
if (settings.commitAgent === 'custom') {
const tokens = tokenize(settings.commitAgentCommand)
if (tokens.length === 0) return { error: 'No custom commit command set (Settings → Commit messages).' }
const bin = resolveBinary(tokens[0])
if (!bin) return { error: `Command "${tokens[0]}" not found.` }
const rest = tokens.slice(1)
+ const inlineRefused = (args: string[]): boolean =>
+ platform === 'win32' &&
+ rest.includes('{prompt}') &&
+ (directExecutableInvocation(bin, args, { platform }) === null || winCommandLineLength(bin, args) > WIN_CMDLINE_MAX)
+ if (rest.includes('{promptFile}')) {
+ // The prompt as a FILE PATH: no argv quoting, no shim line-break refusal, no length limit —
+ // the one inline form that works for every CLI on every platform. A private dir per run
+ // (mkdtemp is 0700 on POSIX; Windows' per-user %TEMP% is already private), removed by
+ // `cleanup` after the agent exits.
+ const dir = fs.mkdtempSync(path.join(opts.tmpDir ?? os.tmpdir(), 'nt-prompt-'))
+ const file = path.join(dir, 'prompt.txt')
+ try {
+ fs.writeFileSync(file, prompt, { mode: 0o600 })
+ } catch (e) {
+ fs.rmSync(dir, { recursive: true, force: true })
+ return { error: `Could not write the prompt file: ${(e as Error).message}` }
+ }
+ const cleanup = () => fs.rmSync(dir, { recursive: true, force: true })
+ const args = rest.map((t) => (t === '{promptFile}' ? file : t === '{prompt}' ? prompt : t))
+ if (inlineRefused(args)) {
+ cleanup()
+ return { error: WINDOWS_INLINE_PROMPT_ERROR }
+ }
+ return { bin, args, stdin: null, cleanup }
+ }
if (rest.includes('{prompt}')) {
- return { bin, args: rest.map((t) => (t === '{prompt}' ? prompt : t)), stdin: null }
+ const args = rest.map((t) => (t === '{prompt}' ? prompt : t))
+ if (inlineRefused(args)) return { error: WINDOWS_INLINE_PROMPT_ERROR }
+ return { bin, args, stdin: null }
}
return { bin, args: rest, stdin: prompt }
}
@@ -323,7 +376,12 @@ export async function runAgent(
if ('error' in plan) return { ok: false, message: plan.error }
const spawnCwd = localAgentCwd(cwd, !!resolveGitRemote(cwd), os.homedir())
- const res = await spawnAgent(plan.bin, plan.args, spawnCwd, plan.stdin, env)
+ let res: Awaited<ReturnType<typeof spawnAgent>>
+ try {
+ res = await spawnAgent(plan.bin, plan.args, spawnCwd, plan.stdin, env)
+ } finally {
+ plan.cleanup?.()
+ }
const message = cleanMessage(res.stdout)
// A nonzero exit is a failure even when stdout has text: that text is the CLI's error message,
// never an answer. Same for a known error line on a zero exit.
diff --git a/src/renderer/components/settings/sections/CommitSection.tsx b/src/renderer/components/settings/sections/CommitSection.tsx
index c15bfbd79..554dea9fc 100644
--- a/src/renderer/components/settings/sections/CommitSection.tsx
+++ b/src/renderer/components/settings/sections/CommitSection.tsx
@@ -15,7 +15,7 @@ const ROWS = {
title: 'Commit agent',
keywords: ['commit', 'message', 'ai', 'claude', 'codex', 'generate']
},
- command: { title: 'Custom command', keywords: ['commit', 'custom', 'command'] },
+ command: { title: 'Custom command', keywords: ['commit', 'custom', 'command', 'prompt', 'promptFile'] },
extra: { title: 'Extra prompt', keywords: ['commit', 'prompt', 'conventional', 'gitmoji'] }
}
const ENTRIES = Object.values(ROWS)
@@ -65,6 +65,7 @@ export function CommitSection({ isActive }: { isActive: boolean }): React.JSX.El
<SearchableRow {...ROWS.command}>
<FieldRow
label="Command"
+ description="The prompt goes to the command's stdin by default. {prompt} passes it inline as one argument instead (not for npm .cmd shims on Windows, nor for diffs past the Windows command-line limit); {promptFile} passes the path of a private temp file holding it."
control={
<Input
className="w-72"