From 3d7edfa6d4c3288502c28534c2d76e8f3deb6360 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Wed, 12 Nov 2025 22:07:44 -0700 Subject: [PATCH 1/2] feat: add Windows Git Bash support to bash tool Add platform detection and Git Bash integration for Windows: - Detect Windows platform using process.platform - Search for Git Bash in common installation paths - Use taskkill for process tree termination on Windows - Maintain backward compatibility with Unix/Linux/Mac systems - Add helpful error message if Git Bash not found on Windows --- packages/coding-agent/src/tools/bash.ts | 92 +++++++++++++++++++++---- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/packages/coding-agent/src/tools/bash.ts b/packages/coding-agent/src/tools/bash.ts index aa27943e..bc7bcee0 100644 --- a/packages/coding-agent/src/tools/bash.ts +++ b/packages/coding-agent/src/tools/bash.ts @@ -1,6 +1,83 @@ import type { AgentTool } from "@mariozechner/pi-ai"; import { Type } from "@sinclair/typebox"; import { spawn } from "child_process"; +import { existsSync } from "fs"; + +/** + * Find Git Bash installation on Windows + * Searches common installation paths + */ +function findGitBash(): string | null { + if (process.platform !== "win32") { + return null; + } + + const paths = ["C:\\Program Files\\Git\\bin\\bash.exe", "C:\\Program Files (x86)\\Git\\bin\\bash.exe"]; + + // Also check ProgramFiles environment variables + const programFiles = process.env.ProgramFiles; + if (programFiles) { + paths.push(`${programFiles}\\Git\\bin\\bash.exe`); + } + + const programFilesX86 = process.env["ProgramFiles(x86)"]; + if (programFilesX86) { + paths.push(`${programFilesX86}\\Git\\bin\\bash.exe`); + } + + for (const path of paths) { + if (existsSync(path)) { + return path; + } + } + + return null; +} + +/** + * Get shell configuration based on platform + */ +function getShellConfig(): { shell: string; args: string[] } { + if (process.platform === "win32") { + const gitBash = findGitBash(); + if (!gitBash) { + throw new Error( + "Git Bash not found. Please install Git for Windows from https://git-scm.com/download/win and ensure it's installed with Git Bash support.", + ); + } + return { shell: gitBash, args: ["-c"] }; + } + return { shell: "sh", args: ["-c"] }; +} + +/** + * Kill a process and all its children + */ +function killProcessTree(pid: number): void { + if (process.platform === "win32") { + // Use taskkill on Windows to kill process tree + try { + spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { + stdio: "ignore", + detached: true, + }); + } catch (e) { + // Ignore errors if taskkill fails + } + } else { + // Use SIGKILL on Unix/Linux/Mac + try { + process.kill(-pid, "SIGKILL"); + } catch (e) { + // Fallback to killing just the child if process group kill fails + try { + process.kill(pid, "SIGKILL"); + } catch (e2) { + // Process already dead + } + } + } +} const bashSchema = Type.Object({ command: Type.String({ description: "Bash command to execute" }), @@ -19,7 +96,8 @@ export const bashTool: AgentTool = { signal?: AbortSignal, ) => { return new Promise((resolve, _reject) => { - const child = spawn("sh", ["-c", command], { + const { shell, args } = getShellConfig(); + const child = spawn(shell, [...args, command], { detached: true, stdio: ["ignore", "pipe", "pipe"], }); @@ -115,17 +193,7 @@ export const bashTool: AgentTool = { // Handle abort signal - kill entire process tree const onAbort = () => { if (child.pid) { - // Kill the entire process group (negative PID kills all processes in the group) - try { - process.kill(-child.pid, "SIGKILL"); - } catch (e) { - // Fallback to killing just the child if process group kill fails - try { - child.kill("SIGKILL"); - } catch (e2) { - // Process already dead - } - } + killProcessTree(child.pid); } }; From 81052d9b4252063dd359ecf0f3e25183058987dd Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 13 Nov 2025 22:03:00 +0100 Subject: [PATCH 2/2] Improve Git Bash not found error message - List the specific paths that are checked - Make it clear that default installation path should be used --- packages/coding-agent/src/tools/bash.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/src/tools/bash.ts b/packages/coding-agent/src/tools/bash.ts index bc7bcee0..b1ffd9bb 100644 --- a/packages/coding-agent/src/tools/bash.ts +++ b/packages/coding-agent/src/tools/bash.ts @@ -41,8 +41,10 @@ function getShellConfig(): { shell: string; args: string[] } { if (process.platform === "win32") { const gitBash = findGitBash(); if (!gitBash) { + const paths = ["C:\\Program Files\\Git\\bin\\bash.exe", "C:\\Program Files (x86)\\Git\\bin\\bash.exe"]; + const pathList = paths.map((p) => ` - ${p}`).join("\n"); throw new Error( - "Git Bash not found. Please install Git for Windows from https://git-scm.com/download/win and ensure it's installed with Git Bash support.", + `Git Bash not found in standard installation locations:\n${pathList}\n\nPlease install Git for Windows from https://git-scm.com/download/win using the default installation path.`, ); } return { shell: gitBash, args: ["-c"] };