Update shell.py

adding windows support so shell commands run native without wsl
This commit is contained in:
Andrew 2025-03-14 16:37:32 -07:00 committed by GitHub
parent 46dd75a7e3
commit 05eb50bd97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import platform
import shutil
from typing import Dict, Union
from langchain_core.tools import tool
@ -15,6 +17,16 @@ from ra_aid.database.repositories.human_input_repository import get_human_input_
console = Console()
def _detect_shell():
"""Detect the appropriate shell to use based on the environment."""
if platform.system().lower().startswith("win"):
# Check if pwsh is available, otherwise fall back to powershell
if shutil.which("pwsh"):
return ["pwsh", "-c"]
else:
return ["powershell", "-c"]
else:
return ["/bin/bash", "-c"]
def _truncate_for_log(text: str, max_length: int = 300) -> str:
"""Truncate text for logging, adding [truncated] if necessary."""
@ -98,8 +110,9 @@ def run_shell_command(
try:
print()
shell_cmd = _detect_shell()
output, return_code = run_interactive_command(
["/bin/bash", "-c", command],
shell_cmd + [command],
expected_runtime_seconds=timeout,
)
print()
@ -131,4 +144,4 @@ def run_shell_command(
)
console.print(Panel(str(e), title="❌ Error", border_style="red"))
return {"output": str(e), "return_code": 1, "success": False}
return {"output": str(e), "return_code": 1, "success": False}