Skip to content

Conversation

@hassoncs
Copy link
Contributor

@hassoncs hassoncs commented Oct 10, 2025

Introduce the runInBackground parameter for the execute_command tool. This allows commands to be executed without requiring user interaction, which is beneficial for long-running processes such as development servers or build tasks.

The changes include:

  • Adding the runInBackground parameter to the tool definition and prompt.
  • Modifying the executeCommand function to handle the runInBackground flag, ensuring commands proceed without user approval when set to true.
  • Implementing comprehensive unit and integration tests to verify the new functionality.

Discussions:
#2917
#2196

I opened the same thing on the Roo side since we haven't sent them anything in a while:
RooCodeInc/Roo-Code#8607

@changeset-bot
Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: ec779d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hassoncs hassoncs force-pushed the exec-cmd-in-background branch 15 times, most recently from 91b286f to 357b1f3 Compare October 15, 2025 20:10
@hassoncs
Copy link
Contributor Author

I updated this after discussing this with Hannes on the Roo side. I added more code in order to help the agent manage the running terminal processes. I couldn't think of a better way to do this other than adding a new tool, terminal_ctrl.

I thought about maybe adding new parameters to the execute command tool to allow it to send the signal, but that didn't seem very clean either. So, this solution seems to work, but I don't really love the fact that we had to add a tool :-/.

At first, I tried capturing the PIDs of the processes, but it's difficult to get the PID of the built-in VS Code terminal commands. You end up getting the shell process ID, which cannot be killed using the regular kill command, which is what the agent tries to do if you don't give it a new tool. So by giving it a tool, we can kill the process similar to the kill button that exists in the UI today. Essentially, this PR gives the agent the ability to click its own buttons in order to continue processes in the background and to kill things later.

Test plan:
I confirmed that the agent can run multiple long-running terminal commands, kill them arbitrarily, and still have visibility into running terminals when dispatching new tasks in orchestrator mode.

@hassoncs hassoncs marked this pull request as ready for review October 15, 2025 20:21
@hassoncs hassoncs force-pushed the exec-cmd-in-background branch 8 times, most recently from c86597e to 3db34a7 Compare October 22, 2025 17:54
@hassoncs hassoncs force-pushed the exec-cmd-in-background branch 2 times, most recently from 327f3da to 641b8fc Compare October 24, 2025 11:32
@hassoncs hassoncs changed the title feat(tools): add runInBackground option to execute_command tool Add support for background terminal command execution Oct 24, 2025
@hassoncs hassoncs requested a review from kevinvandijk October 24, 2025 12:37
@hassoncs hassoncs requested a review from pandemicsyn October 24, 2025 14:45
@hassoncs hassoncs force-pushed the exec-cmd-in-background branch 4 times, most recently from 34a1ff3 to e9eacb3 Compare October 29, 2025 18:10
- Add `run_in_background` parameter to `execute_command` tool for automatic background execution
- Introduce new `terminal_ctrl` tool for killing processes in terminals
- Update environment details to include terminal ID information for process management
- Refactor tests to focus on kill command generation logic

BREAKING CHANGE: New tool parameters and tools added, may require updates to tool usage patterns

Add change markers

Rename to terminalKill tool

Simplify and revert runInBackground

feat(terminal): refactor listener management for background execution

Adjust listener cleanup logic in terminal processes to support background command execution. Move listener removal from continue() to complete() and abort() methods, and add comprehensive tests for background behavior.

feat(terminal): enable background command execution

Commands now run in detached background processes, allowing long-running tasks to execute without blocking the UI. The terminal integration has been refactored to support non-blocking execution while maintaining output monitoring and proper cleanup.

feat(terminal): add kill requested tracking for terminals

- Add `killRequested` property to `RooTerminal` interface and `BaseTerminal` class
- Set flag to true when kill is initiated and reset on completion or error
- Update environment details to display terminal status as "Killing" or "Active

feat(terminal): introduce process termination tool and optimize execution control

Implement terminal_kill tool for managing active processes with required parameters. Enhance executeCommandTool to prioritize explicit background execution preferences. Streamline ExecaTerminalProcess configuration documentation.

fix(terminal): correct block name formatting in terminal kill case

Remove extra apostrophe from block name string in terminal_kill case to fix formatting inconsistency. Add kilocode_change markers to track modifications in terminal-related code.

feat(terminal): add terminal process kill functionality and background execution support

- Add `runInBackground` and `terminalId` fields to command execution status schema
- Implement `killTerminal` method in TerminalRegistry for targeted process termination
- Refactor terminal kill tool to use registry method and simplify logic
- Update webview message handling to pass terminal ID for operations
- Enhance UI components to display background execution status and kill actions
- Add support for aborting specific terminals via terminal ID

BREAKING CHANGE: Terminal operation handling now requires optional terminalId parameter for targeted control
@hassoncs hassoncs force-pushed the exec-cmd-in-background branch from e9eacb3 to 711233b Compare October 29, 2025 18:12
- Add kilocode_change markers to terminal schema fields and environment details
- Implement terminal_kill tool UI in ChatRow component with proper markers
- Remove isOrganization prop from payment_required_prompt handling
- Add `run_in_background` parameter to execute_command tool for running commands asynchronously
- Implement terminal_kill tool with improved parameter validation for killing terminal processes
- Update tool registry and execution logic to support new functionality
…ound execution

- Add terminal kill functionality with terminalId support in Task and TerminalRegistry
- Improve background execution cleanup and error handling in ExecaTerminalProcess
- Update terminal kill tool to verify terminal existence and process status
- Enhance UI components for background execution indicators and abort controls
- Add comprehensive tests for race conditions and edge cases in terminal processes
- Refactor terminal process lifecycle management for better reliability

BREAKING CHANGE: Terminal kill tool now requires terminalId parameter for targeted process termination
@hassoncs hassoncs force-pushed the exec-cmd-in-background branch from 8b70cd6 to b4379c4 Compare November 4, 2025 21:34
…nalProcess

- Move 'completed' event emission before removing listeners to ensure proper notification
- Remove unused variables and dead code for cleaner implementation
- Enhance test suite with comprehensive async handling and additional test cases for error scenarios, abort behavior, and background execution

Closes background execution refinements for terminal processes.
@hassoncs
Copy link
Contributor Author

hassoncs commented Nov 7, 2025

No rush on this, but this branch seems to be working pretty well. I've been testing it locally, and I think the code is decently good, so it should be ready for review when anyone has a moment! cc @pandemicsyn / @chrarnoldus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants