Skip to content

Conversation

@PierrunoYT
Copy link
Contributor

@PierrunoYT PierrunoYT commented Sep 11, 2025

Summary

Fixes #274 - Git commit fails on Windows PowerShell due to heredoc syntax issues and improper shell detection.

This PR provides a comprehensive two-part solution to resolve cross-platform terminal execution issues:

Root Cause Analysis

The issue had two components:

  1. Shell Detection: Terminal commands on Windows always defaulted to cmd.exe, ignoring the actual shell (PowerShell)
  2. Heredoc Syntax: Bash heredoc syntax (<<'EOF') doesn't work in any Windows shell (cmd.exe or PowerShell)

Part 1: Cross-Platform Commit Helper

  • Add scripts/commit-helper.ts: Cross-platform commit script using temporary files instead of heredocs
  • Add npm script: "commit": "bun scripts/commit-helper.ts" for easy access via npm run commit "message"
  • Update system prompt: Modified backend/src/system-prompt/prompts.ts to instruct AI agents to use the commit helper
  • Replace platform-specific instructions: Single helper approach instead of separate Unix/Windows instructions

Part 2: PowerShell Detection Fix

  • Fix npm-app/src/terminal/background.ts: Add proper shell detection using detectShell()
  • Fix sdk/src/tools/run-terminal-command.ts: Apply same detection logic to SDK
  • Correct shell arguments: Use -Command for PowerShell and /c for cmd.exe
  • Import detection utility: Utilize existing detectShell() function

How it works

Commit Helper:

  • Validates git repository state and staged changes
  • Writes commit messages to temporary files (cross-platform compatible)
  • Uses git commit -F tempfile to read the message
  • Handles multi-line messages correctly on Windows, macOS, and Linux
  • Provides proper error handling and cleanup

Shell Detection:

  • Detects whether user is running PowerShell or cmd.exe on Windows
  • Routes commands to the appropriate shell with correct arguments
  • Maintains compatibility with existing Unix shell handling

Usage

npm run commit "Your multi-line commit message here

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>"

Benefits

  • Eliminates heredoc failures: AI agents no longer use problematic heredoc syntax
  • Proper shell routing: Commands execute in the correct shell environment
  • Cross-platform consistency: Works reliably across all operating systems
  • Maintains functionality: Existing commands continue to work as expected
  • Future-proof: Handles both current and future shell detection scenarios

This comprehensive solution ensures AI agents can create proper multi-line commits regardless of the operating system or shell environment.

🤖 Generated with Claude Code

Resolves the issue where git commit commands with heredoc syntax fail on Windows
systems. The heredoc approach (<<'EOF') only works in bash/Unix shells and causes
"pathspec '<<'EOF'' did not match any file(s)" errors on Windows.

Changes:
- Add scripts/commit-helper.ts: Cross-platform script using temporary files
- Add npm script "commit" for easy access: npm run commit "message"
- Update system prompt to instruct AI agents to use commit helper
- Replace platform-specific heredoc instructions with single helper approach

The commit helper validates git repository state, handles multi-line messages
correctly, and works consistently across Windows, macOS, and Linux.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
@PierrunoYT PierrunoYT force-pushed the fix/cross-platform-commit-helper branch from f5af7b7 to e9adfb4 Compare September 11, 2025 16:53
PierrunoYT and others added 2 commits September 11, 2025 19:03
Fixes the root cause of issue CodebuffAI#274 where git commit commands fail on Windows
PowerShell. The previous implementation always defaulted to cmd.exe on Windows,
ignoring the actual shell in use.

Changes:
- Add shell detection to background.ts and SDK run-terminal-command.ts
- Use detectShell() to differentiate between PowerShell and cmd.exe
- Apply correct shell arguments: -Command for PowerShell, /c for cmd.exe
- Import and utilize existing detectShell utility

This fix ensures commands are executed in the correct shell environment,
resolving shell-specific syntax issues. Works alongside the commit helper
script to provide complete cross-platform compatibility.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
@PierrunoYT PierrunoYT closed this Sep 13, 2025
@PierrunoYT PierrunoYT deleted the fix/cross-platform-commit-helper branch September 13, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git Commit fails on Windows Powershell

1 participant