MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/ExecuteCommandTool.ts:66–197  ·  view source on GitHub ↗
(params: ExecuteCommandParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 15

unescapeHtmlEntitiesFunction · 0.90
parseCommandFunction · 0.90
pushToolResultFunction · 0.85
askApprovalFunction · 0.85
resolveAgentTimeoutMsFunction · 0.85
executeCommandInTerminalFunction · 0.85
handleErrorFunction · 0.85
recordToolErrorMethod · 0.80
sayMethod · 0.80
postMessageToWebviewMethod · 0.80

Tested by

no test coverage detected