(params: ExecuteCommandParams, task: Task, callbacks: ToolCallbacks)
| 64 | readonly name = "execute_command" as const |
| 65 | |
| 66 | async execute(params: ExecuteCommandParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 67 | const { command, cwd: customCwd, timeout: timeoutSeconds } = params |
| 68 | const { handleError, pushToolResult, askApproval } = callbacks |
| 69 | |
| 70 | try { |
| 71 | if (!command) { |
| 72 | task.consecutiveMistakeCount++ |
| 73 | task.recordToolError("execute_command") |
| 74 | pushToolResult(await task.sayAndCreateMissingParamError("execute_command", "command")) |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | const canonicalCommand = unescapeHtmlEntities(command) |
| 79 | |
| 80 | const ignoredFileAttemptedToAccess = task.rooIgnoreController?.validateCommand(canonicalCommand) |
| 81 | |
| 82 | if (ignoredFileAttemptedToAccess) { |
| 83 | await task.say("rooignore_error", ignoredFileAttemptedToAccess) |
| 84 | pushToolResult(formatResponse.rooIgnoreError(ignoredFileAttemptedToAccess)) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | task.consecutiveMistakeCount = 0 |
| 89 | |
| 90 | // Detect shell syntax errors (unterminated quotes, unclosed heredocs) before |
| 91 | // presenting the command for approval. Surfacing this as a tool error gives |
| 92 | // the agent a precise, actionable message so it can retry with a corrected |
| 93 | // command, rather than receiving a generic denial from the approval dialog. |
| 94 | const { parseError } = parseCommand(canonicalCommand) |
| 95 | if (parseError !== null) { |
| 96 | const executionId = task.lastMessageTs?.toString() ?? Date.now().toString() |
| 97 | const provider = await task.providerRef.deref() |
| 98 | const errorStatus: CommandExecutionStatus = { |
| 99 | executionId, |
| 100 | status: "error", |
| 101 | message: parseError.message, |
| 102 | } |
| 103 | provider?.postMessageToWebview({ type: "commandExecutionStatus", text: JSON.stringify(errorStatus) }) |
| 104 | task.didToolFailInCurrentTurn = true |
| 105 | pushToolResult(formatResponse.toolError(parseError.message)) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | const didApprove = await askApproval("command", canonicalCommand) |
| 110 | |
| 111 | if (!didApprove) { |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | const executionId = task.lastMessageTs?.toString() ?? Date.now().toString() |
| 116 | const provider = await task.providerRef.deref() |
| 117 | const providerState = await provider?.getState() |
| 118 | |
| 119 | const { terminalShellIntegrationDisabled = true } = providerState ?? {} |
| 120 | |
| 121 | // Get command execution timeout from VSCode configuration (in seconds) |
| 122 | const commandExecutionTimeoutSeconds = vscode.workspace |
| 123 | .getConfiguration(Package.name) |
nothing calls this directly
no test coverage detected