@@ -21,7 +21,7 @@ import { t } from "../../i18n"
21
21
class ShellIntegrationError extends Error { }
22
22
23
23
export async function executeCommandTool (
24
- cline : Task ,
24
+ task : Task ,
25
25
block : ToolUse ,
26
26
askApproval : AskApproval ,
27
27
handleError : HandleError ,
@@ -33,25 +33,25 @@ export async function executeCommandTool(
33
33
34
34
try {
35
35
if ( block . partial ) {
36
- await cline . ask ( "command" , removeClosingTag ( "command" , command ) , block . partial ) . catch ( ( ) => { } )
36
+ await task . ask ( "command" , removeClosingTag ( "command" , command ) , block . partial ) . catch ( ( ) => { } )
37
37
return
38
38
} else {
39
39
if ( ! command ) {
40
- cline . consecutiveMistakeCount ++
41
- cline . recordToolError ( "execute_command" )
42
- pushToolResult ( await cline . sayAndCreateMissingParamError ( "execute_command" , "command" ) )
40
+ task . consecutiveMistakeCount ++
41
+ task . recordToolError ( "execute_command" )
42
+ pushToolResult ( await task . sayAndCreateMissingParamError ( "execute_command" , "command" ) )
43
43
return
44
44
}
45
45
46
- const ignoredFileAttemptedToAccess = cline . rooIgnoreController ?. validateCommand ( command )
46
+ const ignoredFileAttemptedToAccess = task . rooIgnoreController ?. validateCommand ( command )
47
47
48
48
if ( ignoredFileAttemptedToAccess ) {
49
- await cline . say ( "rooignore_error" , ignoredFileAttemptedToAccess )
49
+ await task . say ( "rooignore_error" , ignoredFileAttemptedToAccess )
50
50
pushToolResult ( formatResponse . toolError ( formatResponse . rooIgnoreError ( ignoredFileAttemptedToAccess ) ) )
51
51
return
52
52
}
53
53
54
- cline . consecutiveMistakeCount = 0
54
+ task . consecutiveMistakeCount = 0
55
55
56
56
command = unescapeHtmlEntities ( command ) // Unescape HTML entities.
57
57
const didApprove = await askApproval ( "command" , command )
@@ -60,14 +60,15 @@ export async function executeCommandTool(
60
60
return
61
61
}
62
62
63
- const executionId = cline . lastMessageTs ?. toString ( ) ?? Date . now ( ) . toString ( )
64
- const clineProvider = await cline . providerRef . deref ( )
65
- const clineProviderState = await clineProvider ?. getState ( )
63
+ const executionId = task . lastMessageTs ?. toString ( ) ?? Date . now ( ) . toString ( )
64
+ const provider = await task . providerRef . deref ( )
65
+ const providerState = await provider ?. getState ( )
66
+
66
67
const {
67
68
terminalOutputLineLimit = 500 ,
68
69
terminalOutputCharacterLimit = DEFAULT_TERMINAL_OUTPUT_CHARACTER_LIMIT ,
69
70
terminalShellIntegrationDisabled = false ,
70
- } = clineProviderState ?? { }
71
+ } = providerState ?? { }
71
72
72
73
// Get command execution timeout from VSCode configuration (in seconds)
73
74
const commandExecutionTimeoutSeconds = vscode . workspace
@@ -96,26 +97,26 @@ export async function executeCommandTool(
96
97
}
97
98
98
99
try {
99
- const [ rejected , result ] = await executeCommand ( cline , options )
100
+ const [ rejected , result ] = await executeCommand ( task , options )
100
101
101
102
if ( rejected ) {
102
- cline . didRejectTool = true
103
+ task . didRejectTool = true
103
104
}
104
105
105
106
pushToolResult ( result )
106
107
} catch ( error : unknown ) {
107
108
const status : CommandExecutionStatus = { executionId, status : "fallback" }
108
- clineProvider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
109
- await cline . say ( "shell_integration_warning" )
109
+ provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
110
+ await task . say ( "shell_integration_warning" )
110
111
111
112
if ( error instanceof ShellIntegrationError ) {
112
- const [ rejected , result ] = await executeCommand ( cline , {
113
+ const [ rejected , result ] = await executeCommand ( task , {
113
114
...options ,
114
115
terminalShellIntegrationDisabled : true ,
115
116
} )
116
117
117
118
if ( rejected ) {
118
- cline . didRejectTool = true
119
+ task . didRejectTool = true
119
120
}
120
121
121
122
pushToolResult ( result )
@@ -143,7 +144,7 @@ export type ExecuteCommandOptions = {
143
144
}
144
145
145
146
export async function executeCommand (
146
- cline : Task ,
147
+ task : Task ,
147
148
{
148
149
executionId,
149
150
command,
@@ -154,16 +155,16 @@ export async function executeCommand(
154
155
commandExecutionTimeout = 0 ,
155
156
} : ExecuteCommandOptions ,
156
157
) : Promise < [ boolean , ToolResponse ] > {
157
- // Convert milliseconds back to seconds for display purposes
158
+ // Convert milliseconds back to seconds for display purposes.
158
159
const commandExecutionTimeoutSeconds = commandExecutionTimeout / 1000
159
160
let workingDir : string
160
161
161
162
if ( ! customCwd ) {
162
- workingDir = cline . cwd
163
+ workingDir = task . cwd
163
164
} else if ( path . isAbsolute ( customCwd ) ) {
164
165
workingDir = customCwd
165
166
} else {
166
- workingDir = path . resolve ( cline . cwd , customCwd )
167
+ workingDir = path . resolve ( task . cwd , customCwd )
167
168
}
168
169
169
170
try {
@@ -180,7 +181,7 @@ export async function executeCommand(
180
181
let shellIntegrationError : string | undefined
181
182
182
183
const terminalProvider = terminalShellIntegrationDisabled ? "execa" : "vscode"
183
- const clineProvider = await cline . providerRef . deref ( )
184
+ const provider = await task . providerRef . deref ( )
184
185
185
186
let accumulatedOutput = ""
186
187
const callbacks : RooTerminalCallbacks = {
@@ -192,14 +193,14 @@ export async function executeCommand(
192
193
terminalOutputCharacterLimit ,
193
194
)
194
195
const status : CommandExecutionStatus = { executionId, status : "output" , output : compressedOutput }
195
- clineProvider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
196
+ provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
196
197
197
198
if ( runInBackground ) {
198
199
return
199
200
}
200
201
201
202
try {
202
- const { response, text, images } = await cline . ask ( "command_output" , "" )
203
+ const { response, text, images } = await task . ask ( "command_output" , "" )
203
204
runInBackground = true
204
205
205
206
if ( response === "messageResponse" ) {
@@ -214,29 +215,30 @@ export async function executeCommand(
214
215
terminalOutputLineLimit ,
215
216
terminalOutputCharacterLimit ,
216
217
)
217
- cline . say ( "command_output" , result )
218
+
219
+ task . say ( "command_output" , result )
218
220
completed = true
219
221
} ,
220
222
onShellExecutionStarted : ( pid : number | undefined ) => {
221
223
console . log ( `[executeCommand] onShellExecutionStarted: ${ pid } ` )
222
224
const status : CommandExecutionStatus = { executionId, status : "started" , pid, command }
223
- clineProvider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
225
+ provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
224
226
} ,
225
227
onShellExecutionComplete : ( details : ExitCodeDetails ) => {
226
228
const status : CommandExecutionStatus = { executionId, status : "exited" , exitCode : details . exitCode }
227
- clineProvider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
229
+ provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
228
230
exitDetails = details
229
231
} ,
230
232
}
231
233
232
234
if ( terminalProvider === "vscode" ) {
233
235
callbacks . onNoShellIntegration = async ( error : string ) => {
234
- TelemetryService . instance . captureShellIntegrationError ( cline . taskId )
236
+ TelemetryService . instance . captureShellIntegrationError ( task . taskId )
235
237
shellIntegrationError = error
236
238
}
237
239
}
238
240
239
- const terminal = await TerminalRegistry . getOrCreateTerminal ( workingDir , ! ! customCwd , cline . taskId , terminalProvider )
241
+ const terminal = await TerminalRegistry . getOrCreateTerminal ( workingDir , ! ! customCwd , task . taskId , terminalProvider )
240
242
241
243
if ( terminal instanceof Terminal ) {
242
244
terminal . terminal . show ( true )
@@ -248,20 +250,17 @@ export async function executeCommand(
248
250
}
249
251
250
252
const process = terminal . runCommand ( command , callbacks )
251
- cline . terminalProcess = process
253
+ task . terminalProcess = process
252
254
253
- // Implement command execution timeout (skip if timeout is 0)
255
+ // Implement command execution timeout (skip if timeout is 0).
254
256
if ( commandExecutionTimeout > 0 ) {
255
257
let timeoutId : NodeJS . Timeout | undefined
256
258
let isTimedOut = false
257
259
258
260
const timeoutPromise = new Promise < void > ( ( _ , reject ) => {
259
261
timeoutId = setTimeout ( ( ) => {
260
262
isTimedOut = true
261
- // Try to abort the process
262
- if ( cline . terminalProcess ) {
263
- cline . terminalProcess . abort ( )
264
- }
263
+ task . terminalProcess ?. abort ( )
265
264
reject ( new Error ( `Command execution timed out after ${ commandExecutionTimeout } ms` ) )
266
265
} , commandExecutionTimeout )
267
266
} )
@@ -270,17 +269,10 @@ export async function executeCommand(
270
269
await Promise . race ( [ process , timeoutPromise ] )
271
270
} catch ( error ) {
272
271
if ( isTimedOut ) {
273
- // Handle timeout case
274
272
const status : CommandExecutionStatus = { executionId, status : "timeout" }
275
- clineProvider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
276
-
277
- // Add visual feedback for timeout
278
- await cline . say (
279
- "error" ,
280
- t ( "common:errors:command_timeout" , { seconds : commandExecutionTimeoutSeconds } ) ,
281
- )
282
-
283
- cline . terminalProcess = undefined
273
+ provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
274
+ await task . say ( "error" , t ( "common:errors:command_timeout" , { seconds : commandExecutionTimeoutSeconds } ) )
275
+ task . terminalProcess = undefined
284
276
285
277
return [
286
278
false ,
@@ -292,14 +284,15 @@ export async function executeCommand(
292
284
if ( timeoutId ) {
293
285
clearTimeout ( timeoutId )
294
286
}
295
- cline . terminalProcess = undefined
287
+
288
+ task . terminalProcess = undefined
296
289
}
297
290
} else {
298
- // No timeout - just wait for the process to complete
291
+ // No timeout - just wait for the process to complete.
299
292
try {
300
293
await process
301
294
} finally {
302
- cline . terminalProcess = undefined
295
+ task . terminalProcess = undefined
303
296
}
304
297
}
305
298
@@ -316,7 +309,7 @@ export async function executeCommand(
316
309
317
310
if ( message ) {
318
311
const { text, images } = message
319
- await cline . say ( "user_feedback" , text , images )
312
+ await task . say ( "user_feedback" , text , images )
320
313
321
314
return [
322
315
true ,
0 commit comments