Skip to content

Commit 330a11f

Browse files
committed
Add documentation for the execute_command tool and its functionality
1 parent 911b782 commit 330a11f

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# execute_command
2+
3+
The `execute_command` tool runs CLI commands on the user's system. It allows Roo to perform system operations, install dependencies, build projects, start servers, and execute other terminal-based tasks needed to accomplish user objectives.
4+
5+
## Parameters
6+
7+
The tool accepts these parameters:
8+
9+
- `command` (required): The CLI command to execute. Must be valid for the user's operating system.
10+
- `cwd` (optional): The working directory to execute the command in. If not provided, the current working directory is used.
11+
12+
## What It Does
13+
14+
This tool executes terminal commands directly on the user's system, enabling a wide range of operations from file manipulations to running development servers. Commands run in managed terminal instances with real-time output capture, integrated with VS Code's terminal system for optimal performance and security.
15+
16+
## When is it used?
17+
18+
- When installing project dependencies (npm install, pip install, etc.)
19+
- When building or compiling code (make, npm run build, etc.)
20+
- When starting development servers or running applications
21+
- When initializing new projects (git init, npm init, etc.)
22+
- When performing file operations beyond what other tools provide
23+
- When running tests or linting operations
24+
- When needing to execute specialized commands for specific technologies
25+
26+
## Key Features
27+
28+
- Integrates with VS Code shell API for reliable terminal execution
29+
- Reuses terminal instances when possible through a registry system
30+
- Captures command output line by line with real-time feedback
31+
- Supports long-running commands that continue in the background
32+
- Allows specification of custom working directories
33+
- Maintains terminal history and state across command executions
34+
- Handles complex command chains appropriate for the user's shell
35+
- Provides detailed command completion status and exit code interpretation
36+
- Supports interactive terminal applications with user feedback loop
37+
- Shows terminals during execution for transparency
38+
- Validates commands for security using shell-quote parsing
39+
- Blocks potentially dangerous subshell execution patterns
40+
- Integrates with RooIgnore system for file access control
41+
- Handles terminal escape sequences for clean output
42+
43+
## Limitations
44+
45+
- Command access may be restricted by RooIgnore rules and security validations
46+
- Commands with elevated permission requirements may need user configuration
47+
- Behavior may vary across operating systems for certain commands
48+
- Very long-running commands may require specific handling
49+
- File paths should be properly escaped according to the OS shell rules
50+
- Not all terminal features may work with remote development scenarios
51+
52+
## How It Works
53+
54+
When the `execute_command` tool is invoked, it follows this process:
55+
56+
1. **Command Validation and Security Checks**:
57+
- Parses the command using shell-quote to identify components
58+
- Validates against security restrictions (subshell usage, restricted files)
59+
- Checks against RooIgnore rules for file access permissions
60+
- Ensures the command meets system security requirements
61+
62+
2. **Terminal Management**:
63+
- Gets or creates a terminal through TerminalRegistry
64+
- Sets up the working directory context
65+
- Prepares event listeners for output capture
66+
- Shows the terminal for user visibility
67+
68+
3. **Command Execution and Monitoring**:
69+
- Executes via VS Code's shellIntegration API
70+
- Captures output with escape sequence processing
71+
- Throttles output handling (100ms intervals)
72+
- Monitors for command completion or errors
73+
- Detects "hot" processes like compilers for special handling
74+
75+
4. **Result Processing**:
76+
- Strips ANSI/VS Code escape sequences for clean output
77+
- Interprets exit codes with detailed signal information
78+
- Updates working directory tracking if changed by command
79+
- Provides command status with appropriate context
80+
81+
## Terminal Implementation Details
82+
83+
The tool uses a sophisticated terminal management system:
84+
85+
1. **First Priority: Terminal Reuse**
86+
- The TerminalRegistry tries to reuse existing terminals when possible
87+
- This reduces proliferation of terminal instances and improves performance
88+
- Terminal state (working directory, history) is preserved across commands
89+
90+
2. **Second Priority: Security Validation**
91+
- Commands are parsed using shell-quote for component analysis
92+
- Dangerous patterns like `$(...)` and backticks are blocked
93+
- Commands are checked against RooIgnore rules for file access control
94+
- A prefix-based allowlist system validates command patterns
95+
96+
3. **Performance Optimizations**
97+
- Output is processed in 100ms throttled intervals to prevent UI overload
98+
- Zero-copy buffer management uses index-based tracking for efficiency
99+
- Special handling for compilation and "hot" processes
100+
- Platform-specific optimizations for Windows PowerShell
101+
102+
4. **Error and Signal Handling**
103+
- Exit codes are mapped to detailed signal information (SIGTERM, SIGKILL, etc.)
104+
- Core dump detection for critical failures
105+
- Working directory changes are tracked and handled automatically
106+
- Clean recovery from terminal disconnection scenarios
107+
108+
## Examples When Used
109+
110+
- When setting up a new project, Roo runs initialization commands like `npm init -y` followed by installing dependencies.
111+
- When building a web application, Roo executes build commands like `npm run build` to compile assets.
112+
- When deploying code, Roo runs git commands to commit and push changes to a repository.
113+
- When troubleshooting, Roo executes diagnostic commands to gather system information.
114+
- When starting a development server, Roo launches the appropriate server command (e.g., `npm start`).
115+
- When running tests, Roo executes the test runner command for the project's testing framework.
116+
117+
## Usage Examples
118+
119+
Running a simple command in the current directory:
120+
```
121+
<execute_command>
122+
<command>npm run dev</command>
123+
</execute_command>
124+
```
125+
126+
Installing dependencies for a project:
127+
```
128+
<execute_command>
129+
<command>npm install express mongodb mongoose dotenv</command>
130+
</execute_command>
131+
```
132+
133+
Running multiple commands in sequence:
134+
```
135+
<execute_command>
136+
<command>mkdir -p src/components && touch src/components/App.js</command>
137+
</execute_command>
138+
```
139+
140+
Executing a command in a specific directory:
141+
```
142+
<execute_command>
143+
<command>git status</command>
144+
<cwd>./my-project</cwd>
145+
</execute_command>
146+
```
147+
148+
Building and then starting a project:
149+
```
150+
<execute_command>
151+
<command>npm run build && npm start</command>
152+
</execute_command>
153+
```

0 commit comments

Comments
 (0)