Skip to content

Conversation

@PierrunoYT
Copy link
Contributor

@PierrunoYT PierrunoYT commented Sep 13, 2025

Problem Solved

The original issue was that heredoc syntax (<<'EOF') used in git commit commands only works in bash/Unix shells and fails on Windows Command Prompt, causing commit failures for Windows users.

Solution

This PR implements a comprehensive cross-platform commit helper that resolves heredoc issues and ensures consistent git commit behavior across all platforms.

Key Changes

🔧 Core Implementation

  • scripts/commit-helper.js - Main Node.js script with ES module support for cross-platform commits
  • scripts/commit.bat - Windows batch wrapper for easy CLI usage
  • scripts/commit.sh - Unix/Linux/macOS shell wrapper
  • common/src/util/git-cross-platform.ts - TypeScript utilities for programmatic use
  • scripts/COMMIT_HELPER_README.md - Comprehensive documentation

🤖 Agent Integration

  • Updated system prompts (backend/src/system-prompt/prompts.ts) to instruct agents to use the commit helper automatically
  • Updated git utilities (common/src/util/git.ts) to use the helper as the primary commit method
  • Removed all heredoc syntax from agent instructions

Features

  • Cross-platform compatibility: Works on Windows (cmd.exe, PowerShell), macOS, and Linux (bash, zsh, fish)
  • Automatic co-author attribution: Adds factory-droid[bot] to all commits
  • Multiline message support: Handles complex commit messages with proper formatting
  • Temporary file approach: Uses git commit -F to avoid shell escaping issues entirely
  • Fallback mechanisms: Multiple layers of error handling
  • Agent automation: Codebuff agents now automatically use the helper without manual intervention

🎯 Usage

Command Line

# Cross-platform
node scripts/commit-helper.js "Fix bug" "- Added error handling" "- Updated tests"

# Windows
scripts\commit.bat "Fix bug" "- Added error handling"  

# Unix/Linux/macOS
scripts/commit.sh "Fix bug" "- Added error handling"

Programmatic

import { commitChanges, commitChangesMultiline } from '../common/src/util/git-cross-platform'

commitChanges("Simple commit message")
commitChangesMultiline("Title", ["Body line 1", "Body line 2"])

🔍 Technical Details

The helper works by:

  1. Processing commit message arguments (single or multiline)
  2. Adding factory-droid co-author attribution automatically
  3. Writing the complete message to a temporary file
  4. Using git commit -F tempfile to avoid all shell parsing issues
  5. Cleaning up temporary files after commit

This approach eliminates:

  • Heredoc syntax requirements
  • Shell-specific escaping issues
  • Quote handling problems
  • Platform-specific command differences

Testing

  • ✅ Verified working on Windows Command Prompt
  • ✅ Verified working on PowerShell
  • ✅ Tested multiline commit creation
  • ✅ Confirmed automatic co-author attribution
  • ✅ Validated agent integration (agents now use helper automatically)
  • ✅ Created actual commits using the new system

🎉 Result

The heredoc issue is completely resolved! Codebuff agents now automatically use the cross-platform commit helper for all git commits, ensuring reliable operation across Windows, macOS, and Linux without any manual intervention required.

Users can now ask agents to commit changes and it will work seamlessly on any platform without heredoc syntax errors.

PierrunoYT and others added 2 commits September 13, 2025 20:38
- Created commit-helper.js with temp file approach
- Added Windows batch and Unix shell wrappers
- Created TypeScript utilities for programmatic use
- Resolves Windows Command Prompt heredoc syntax issues

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Modified system prompts to instruct agent to use commit-helper.js
- Updated git utilities to call commit helper as primary method
- Resolves automatic heredoc issue handling for agent commits

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@jahooma
Copy link
Contributor

jahooma commented Sep 13, 2025

I'm not sure how this is going to work if there's a script file to do the commit. The user's wouldn't have access to that unless it's bundled. The closest substitute might be a new tool for the llm to call, which is implemented in the npm-app. But I don't know if it's worth it to create a whole new tool.

Actually, you should just create a git committer agent that runs these commands via handleSteps. Try creating it with Bob the Agent Builder, giving it context on the scripts here.

@PierrunoYT PierrunoYT closed this Sep 13, 2025
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.

2 participants