Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 499511e

Browse files
committed
feat: implement Process Management Tool integration (#430)
- Add 5 new process management commands: launch-process, list-processes, kill-process, read-process-output, write-process-input - Implement ProcessStateManager service for managing process lifecycle - Add ProcessInfo data classes for process state tracking - Integrate with existing InsCommand architecture - Add comprehensive example files for all new commands - Support background/foreground execution, timeout control, environment variables - Provide process input/output streaming capabilities - Include proper error handling and resource cleanup Resolves #430
1 parent c965cf9 commit 499511e

File tree

15 files changed

+1498
-0
lines changed

15 files changed

+1498
-0
lines changed

PROCESS_TOOLS_README.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# Process Management Tools
2+
3+
This document describes the new process management tools integrated into the AutoDev IntelliJ plugin, implementing issue #430.
4+
5+
## Overview
6+
7+
The Process Management Tools provide a comprehensive API for managing external processes within IntelliJ IDEA, inspired by Cursor's tool schema approach. These tools allow you to launch, monitor, control, and interact with external processes seamlessly.
8+
9+
## Available Commands
10+
11+
### 1. Launch Process (`/launch-process`)
12+
13+
Launch a new process with specified command and options.
14+
15+
**Syntax:**
16+
```
17+
/launch-process:[options]
18+
```bash
19+
command to execute
20+
```
21+
22+
**Options:**
23+
- `--wait` - Wait for process completion before returning
24+
- `--timeout=N` - Set timeout in seconds (default: 30)
25+
- `--working-dir=PATH` - Set working directory
26+
- `--env=KEY=VALUE` - Set environment variables
27+
- `--show-terminal` - Show process in terminal
28+
29+
**Examples:**
30+
31+
Launch and wait:
32+
```
33+
/launch-process:--wait --timeout=60
34+
```bash
35+
./gradlew build
36+
```
37+
38+
Launch in background:
39+
```
40+
/launch-process:
41+
```bash
42+
npm run dev
43+
```
44+
45+
### 2. List Processes (`/list-processes`)
46+
47+
List all active and terminated processes.
48+
49+
**Syntax:**
50+
```
51+
/list-processes:[options]
52+
```
53+
54+
**Options:**
55+
- `--include-terminated` or `--all` - Include terminated processes
56+
- `--max-results=N` - Limit number of results (default: 50)
57+
58+
**Example:**
59+
```
60+
/list-processes:--all --max-results=20
61+
```
62+
63+
### 3. Kill Process (`/kill-process`)
64+
65+
Terminate a running process by its process ID.
66+
67+
**Syntax:**
68+
```
69+
/kill-process:PROCESS_ID [--force]
70+
```
71+
72+
**Options:**
73+
- `--force` - Force kill the process
74+
75+
**Example:**
76+
```
77+
/kill-process:proc_1234567890_1 --force
78+
```
79+
80+
### 4. Read Process Output (`/read-process-output`)
81+
82+
Read stdout and stderr output from a process.
83+
84+
**Syntax:**
85+
```
86+
/read-process-output:PROCESS_ID [options]
87+
```
88+
89+
**Options:**
90+
- `--stdout-only` - Read only stdout
91+
- `--stderr-only` - Read only stderr
92+
- `--no-stdout` - Exclude stdout
93+
- `--no-stderr` - Exclude stderr
94+
- `--max-bytes=N` - Limit output size (default: 10000)
95+
96+
**Example:**
97+
```
98+
/read-process-output:proc_1234567890_1 --max-bytes=5000
99+
```
100+
101+
### 5. Write Process Input (`/write-process-input`)
102+
103+
Write input data to a running process's stdin.
104+
105+
**Syntax:**
106+
```
107+
/write-process-input:PROCESS_ID [--no-newline]
108+
```text
109+
input data
110+
```
111+
112+
**Options:**
113+
- `--no-newline` - Don't append newline to input
114+
115+
**Example:**
116+
```
117+
/write-process-input:proc_1234567890_1
118+
```
119+
hello world
120+
```
121+
122+
## Architecture
123+
124+
### Core Components
125+
126+
1. **ProcessInfo** - Data class containing process information
127+
2. **ProcessStateManager** - Service for managing process states and lifecycle
128+
3. **ProcessStatus** - Enum representing process states (RUNNING, COMPLETED, FAILED, KILLED, TIMED_OUT)
129+
4. **InsCommand Implementations** - Individual command implementations for each tool
130+
131+
### Process Lifecycle
132+
133+
```
134+
Launch → Running → [Input/Output Operations] → Terminated
135+
```
136+
137+
### Integration Points
138+
139+
- **IntelliJ Process Management APIs** - Leverages existing IntelliJ process handling
140+
- **DevIns Language** - Integrated with the existing command system
141+
- **Tool Registry** - Registered as standard built-in commands
142+
143+
## Usage Patterns
144+
145+
### 1. Build and Test Workflow
146+
147+
```
148+
# Launch build process
149+
/launch-process:--wait --timeout=300
150+
```bash
151+
./gradlew clean build
152+
```
153+
154+
# Check if any processes are still running
155+
/list-processes
156+
157+
# Read build output if needed
158+
/read-process-output:proc_xxx
159+
```
160+
161+
### 2. Development Server Management
162+
163+
```
164+
# Start development server in background
165+
/launch-process:--env=NODE_ENV=development
166+
```bash
167+
npm run dev
168+
```
169+
170+
# List running processes
171+
/list-processes
172+
173+
# Kill server when done
174+
/kill-process:proc_xxx
175+
```
176+
177+
### 3. Interactive Process Communication
178+
179+
```
180+
# Launch interactive process
181+
/launch-process:
182+
```bash
183+
python3 -i
184+
```
185+
186+
# Send commands to Python REPL
187+
/write-process-input:proc_xxx
188+
```
189+
print("Hello from AutoDev!")
190+
```
191+
192+
# Read output
193+
/read-process-output:proc_xxx
194+
```
195+
196+
## Error Handling
197+
198+
- **Process Not Found** - Commands validate process existence
199+
- **Permission Errors** - Proper error messages for access issues
200+
- **Timeout Handling** - Configurable timeouts with clear feedback
201+
- **Resource Cleanup** - Automatic cleanup of terminated processes
202+
203+
## Security Considerations
204+
205+
- **Command Validation** - Input sanitization for shell commands
206+
- **Working Directory Restrictions** - Limited to project scope
207+
- **Environment Variable Control** - Controlled environment variable access
208+
- **Process Isolation** - Processes run in isolated contexts
209+
210+
## Future Enhancements
211+
212+
- **Process Groups** - Support for managing related processes
213+
- **Output Streaming** - Real-time output streaming for long-running processes
214+
- **Process Dependencies** - Define process startup dependencies
215+
- **Resource Monitoring** - CPU and memory usage tracking
216+
- **Persistent State** - Process state persistence across IDE sessions
217+
218+
## Implementation Details
219+
220+
The implementation follows the existing AutoDev architecture:
221+
222+
- **BuiltinCommand** entries for each tool
223+
- **InsCommand** implementations for execution logic
224+
- **InsCommandFactory** registration for command creation
225+
- **Service-level** process state management
226+
- **Example files** for documentation and auto-completion
227+
228+
All process management operations are implemented as Kotlin coroutines for non-blocking execution and integrate seamlessly with IntelliJ's existing process management APIs.

core/src/main/kotlin/cc/unitmesh/devti/command/dataprovider/BuiltinCommand.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,46 @@ enum class BuiltinCommand(
171171
false,
172172
enableInSketch = false
173173
),
174+
LAUNCH_PROCESS(
175+
"launch-process",
176+
"Launch a new process with specified command and options. Supports background execution, timeout control, and environment variable configuration. Returns process ID for management and monitoring. Essential for running external tools and scripts.",
177+
AllIcons.Actions.Execute,
178+
true,
179+
true,
180+
enableInSketch = false
181+
),
182+
LIST_PROCESSES(
183+
"list-processes",
184+
"List all active and terminated processes managed by the system. Shows process status, command, working directory, and execution times. Use for monitoring running processes and debugging execution issues.",
185+
AllIcons.General.TodoDefault,
186+
false,
187+
false,
188+
enableInSketch = false
189+
),
190+
KILL_PROCESS(
191+
"kill-process",
192+
"Terminate a running process by its process ID. Supports both graceful termination and force kill options. Use when processes need to be stopped or are consuming excessive resources.",
193+
AllIcons.Actions.Suspend,
194+
true,
195+
true,
196+
enableInSketch = false
197+
),
198+
READ_PROCESS_OUTPUT(
199+
"read-process-output",
200+
"Read stdout and stderr output from a running or completed process. Supports streaming output and output size limits. Essential for monitoring process execution and debugging.",
201+
AllIcons.Actions.Show,
202+
true,
203+
true,
204+
enableInSketch = false
205+
),
206+
WRITE_PROCESS_INPUT(
207+
"write-process-input",
208+
"Write input data to a running process's stdin. Supports interactive process communication and automation of command-line tools. Use for processes that require user input or commands.",
209+
AllIcons.Actions.Edit,
210+
true,
211+
true,
212+
enableInSketch = false
213+
),
174214
;
175215

176216
companion object {

0 commit comments

Comments
 (0)