Execute shell commands in foreground or background. Automatically detects OS and uses appropriate shell: - Windows: PowerShell - Unix/Linux/macOS: bash
| 215 | |
| 216 | |
| 217 | class BashTool(Tool): |
| 218 | """Execute shell commands in foreground or background. |
| 219 | |
| 220 | Automatically detects OS and uses appropriate shell: |
| 221 | - Windows: PowerShell |
| 222 | - Unix/Linux/macOS: bash |
| 223 | """ |
| 224 | |
| 225 | def __init__(self, workspace_dir: str | None = None): |
| 226 | """Initialize BashTool with OS-specific shell detection. |
| 227 | |
| 228 | Args: |
| 229 | workspace_dir: Working directory for command execution. |
| 230 | If provided, all commands run in this directory. |
| 231 | If None, commands run in the process's cwd. |
| 232 | """ |
| 233 | self.is_windows = platform.system() == "Windows" |
| 234 | self.shell_name = "PowerShell" if self.is_windows else "bash" |
| 235 | self.workspace_dir = workspace_dir |
| 236 | |
| 237 | @property |
| 238 | def name(self) -> str: |
| 239 | return "bash" |
| 240 | |
| 241 | @property |
| 242 | def description(self) -> str: |
| 243 | shell_examples = { |
| 244 | "Windows": """Execute PowerShell commands in foreground or background. |
| 245 | |
| 246 | For terminal operations like git, npm, docker, etc. DO NOT use for file operations - use specialized tools. |
| 247 | |
| 248 | Parameters: |
| 249 | - command (required): PowerShell command to execute |
| 250 | - timeout (optional): Timeout in seconds (default: 120, max: 600) for foreground commands |
| 251 | - run_in_background (optional): Set true for long-running commands (servers, etc.) |
| 252 | |
| 253 | Tips: |
| 254 | - Quote file paths with spaces: cd "My Documents" |
| 255 | - Chain dependent commands with semicolon: git add . ; git commit -m "msg" |
| 256 | - Use absolute paths instead of cd when possible |
| 257 | - For background commands, monitor with bash_output and terminate with bash_kill |
| 258 | |
| 259 | Examples: |
| 260 | - git status |
| 261 | - npm test |
| 262 | - python -m http.server 8080 (with run_in_background=true)""", |
| 263 | "Unix": """Execute bash commands in foreground or background. |
| 264 | |
| 265 | For terminal operations like git, npm, docker, etc. DO NOT use for file operations - use specialized tools. |
| 266 | |
| 267 | Parameters: |
| 268 | - command (required): Bash command to execute |
| 269 | - timeout (optional): Timeout in seconds (default: 120, max: 600) for foreground commands |
| 270 | - run_in_background (optional): Set true for long-running commands (servers, etc.) |
| 271 | |
| 272 | Tips: |
| 273 | - Quote file paths with spaces: cd "My Documents" |
| 274 | - Chain dependent commands with &&: git add . && git commit -m "msg" |
no outgoing calls