#!/bin/bash
# Wrapper script to call Windows PowerShell 'agent' from Git Bash
# This allows Ralph scripts to use 'cursor-agent' command on Windows

if command -v cursor-agent &> /dev/null; then
    # Native cursor-agent exists (Linux/Mac)
    exec cursor-agent "$@"
elif command -v agent &> /dev/null && [[ "$OSTYPE" != "msys" && "$OSTYPE" != "win32" && -z "$WINDIR" ]]; then
    # agent exists and we're not on Windows
    exec agent "$@"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" || -n "$WINDIR" ]]; then
    # Windows: use PowerShell to call agent
    # Convert Unix-style paths to Windows paths if needed
    args=()
    for arg in "$@"; do
        # Convert /e/opennotion to E:\opennotion for PowerShell
        if [[ "$arg" =~ ^/[a-zA-Z]/ ]]; then
            drive=$(echo "$arg" | cut -c2 | tr '[:lower:]' '[:upper:]')
            path_part=$(echo "$arg" | cut -c3- | tr '/' '\\')
            args+=("${drive}:\\${path_part}")
        else
            args+=("$arg")
        fi
    done
    
    # Call PowerShell agent with arguments
    powershell -Command "& agent $*"
else
    echo "Error: cursor-agent not found" >&2
    exit 1
fi

