import asyncio from SimpleLLMFunc import tool from .common import print_tool_output EXECUTE_COMMAND_TIMEOUT_SECONDS = 600 def _build_command_failure_message(result) -> str: parts = [f"Command failed with exit code {result.returncode}."] stdout = result.stdout.strip() stderr = result.stderr.strip() if stdout: parts.append(f"STDOUT:\n{stdout}") if stderr: parts.append(f"STDERR:\n{stderr}") return "\n\n".join(parts) def _build_command_timeout_message(exc) -> str: parts = [ f"Command timed out after {EXECUTE_COMMAND_TIMEOUT_SECONDS} seconds.", "The process may be stuck, waiting for input, or simply taking too long.", ] stdout = (exc.stdout or "").strip() stderr = (exc.stderr or "").strip() if stdout: parts.append(f"Partial STDOUT:\n{stdout}") if stderr: parts.append(f"Partial STDERR:\n{stderr}") return "\n\n".join(parts) @tool( name="execute_command", description="Execute a system command in shell and return the output.", ) async def execute_command(command: str) -> str: """Execute a system command in shell and return the output. Args: command: The system command to execute, recommended commands are uv run python