Terminate a running background bash shell.
| 533 | |
| 534 | |
| 535 | class BashKillTool(Tool): |
| 536 | """Terminate a running background bash shell.""" |
| 537 | |
| 538 | @property |
| 539 | def name(self) -> str: |
| 540 | return "bash_kill" |
| 541 | |
| 542 | @property |
| 543 | def description(self) -> str: |
| 544 | return """Kills a running background bash shell by its ID. |
| 545 | |
| 546 | - Takes a bash_id parameter identifying the shell to kill |
| 547 | - Attempts graceful termination (SIGTERM) first, then forces (SIGKILL) if needed |
| 548 | - Returns the final status and any remaining output before termination |
| 549 | - Cleans up all resources associated with the shell |
| 550 | - Use this tool when you need to terminate a long-running shell |
| 551 | - Shell IDs can be found using the bash tool with run_in_background=true |
| 552 | |
| 553 | Example: bash_kill(bash_id="abc12345")""" |
| 554 | |
| 555 | @property |
| 556 | def parameters(self) -> dict[str, Any]: |
| 557 | return { |
| 558 | "type": "object", |
| 559 | "properties": { |
| 560 | "bash_id": { |
| 561 | "type": "string", |
| 562 | "description": "The ID of the background shell to terminate. Shell IDs are returned when starting a command with run_in_background=true.", |
| 563 | }, |
| 564 | }, |
| 565 | "required": ["bash_id"], |
| 566 | } |
| 567 | |
| 568 | async def execute(self, bash_id: str) -> BashOutputResult: |
| 569 | """Terminate a background shell process. |
| 570 | |
| 571 | Args: |
| 572 | bash_id: The unique identifier of the background shell to terminate |
| 573 | |
| 574 | Returns: |
| 575 | BashOutputResult with termination status and remaining output |
| 576 | """ |
| 577 | |
| 578 | try: |
| 579 | # Get remaining output before termination |
| 580 | bg_shell = BackgroundShellManager.get(bash_id) |
| 581 | if bg_shell: |
| 582 | remaining_lines = bg_shell.get_new_output() |
| 583 | else: |
| 584 | remaining_lines = [] |
| 585 | |
| 586 | # Terminate through manager (handles all cleanup) |
| 587 | bg_shell = await BackgroundShellManager.terminate(bash_id) |
| 588 | |
| 589 | # Get remaining output |
| 590 | stdout = "\n".join(remaining_lines) if remaining_lines else "" |
| 591 | |
| 592 | return BashOutputResult( |
no outgoing calls