Merge pull request #133 from andrewdkennedy1/detect-shell-env

Update shell.py for native windows support
This commit is contained in:
Andrew I. Christianson 2025-03-14 20:32:11 -04:00 committed by GitHub
commit a3dfb81840
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 typing import Dict, Union
from langchain_core.tools import tool from langchain_core.tools import tool
@ -15,6 +17,16 @@ from ra_aid.database.repositories.human_input_repository import get_human_input_
console = Console() 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: def _truncate_for_log(text: str, max_length: int = 300) -> str:
"""Truncate text for logging, adding [truncated] if necessary.""" """Truncate text for logging, adding [truncated] if necessary."""
@ -98,8 +110,9 @@ def run_shell_command(
try: try:
print() print()
shell_cmd = _detect_shell()
output, return_code = run_interactive_command( output, return_code = run_interactive_command(
["/bin/bash", "-c", command], shell_cmd + [command],
expected_runtime_seconds=timeout, expected_runtime_seconds=timeout,
) )
print() print()