Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 11 additions & 47 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { searchAndReplaceTool } from "./tools/searchAndReplaceTool"
import { listCodeDefinitionNamesTool } from "./tools/listCodeDefinitionNamesTool"
import { searchFilesTool } from "./tools/searchFilesTool"
import { browserActionTool } from "./tools/browserActionTool"
import { executeCommandTool } from "./tools/executeCommandTool"

export type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
type UserContent = Array<Anthropic.Messages.ContentBlockParam>
Expand Down Expand Up @@ -181,7 +182,7 @@ export class Cline extends EventEmitter<ClineEvents> {
private presentAssistantMessageHasPendingUpdates = false
private userMessageContent: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []
private userMessageContentReady = false
private didRejectTool = false
didRejectTool = false
private didAlreadyUseTool = false
private didCompleteReadingStream = false

Expand Down Expand Up @@ -1618,52 +1619,15 @@ export class Cline extends EventEmitter<ClineEvents> {
break
}
case "execute_command": {
const command: string | undefined = block.params.command
const customCwd: string | undefined = block.params.cwd
try {
if (block.partial) {
await this.ask("command", removeClosingTag("command", command), block.partial).catch(
() => {},
)
break
} else {
if (!command) {
this.consecutiveMistakeCount++
pushToolResult(
await this.sayAndCreateMissingParamError("execute_command", "command"),
)
break
}

const ignoredFileAttemptedToAccess = this.rooIgnoreController?.validateCommand(command)
if (ignoredFileAttemptedToAccess) {
await this.say("rooignore_error", ignoredFileAttemptedToAccess)
pushToolResult(
formatResponse.toolError(
formatResponse.rooIgnoreError(ignoredFileAttemptedToAccess),
),
)

break
}

this.consecutiveMistakeCount = 0

const didApprove = await askApproval("command", command)
if (!didApprove) {
break
}
const [userRejected, result] = await this.executeCommandTool(command, customCwd)
if (userRejected) {
this.didRejectTool = true
}
pushToolResult(result)
break
}
} catch (error) {
await handleError("executing command", error)
break
}
await executeCommandTool(
this,
block,
askApproval,
handleError,
pushToolResult,
removeClosingTag,
)
break
}
case "use_mcp_tool": {
const server_name: string | undefined = block.params.server_name
Expand Down
52 changes: 52 additions & 0 deletions src/core/tools/executeCommandTool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Cline } from "../Cline"
import { ToolUse } from "../assistant-message"
import { AskApproval, HandleError, PushToolResult, RemoveClosingTag } from "./types"
import { formatResponse } from "../prompts/responses"

export async function executeCommandTool(
cline: Cline,
block: ToolUse,
askApproval: AskApproval,
handleError: HandleError,
pushToolResult: PushToolResult,
removeClosingTag: RemoveClosingTag,
) {
const command: string | undefined = block.params.command
const customCwd: string | undefined = block.params.cwd
try {
if (block.partial) {
await cline.ask("command", removeClosingTag("command", command), block.partial).catch(() => {})
return
} else {
if (!command) {
cline.consecutiveMistakeCount++
pushToolResult(await cline.sayAndCreateMissingParamError("execute_command", "command"))
return
}

const ignoredFileAttemptedToAccess = cline.rooIgnoreController?.validateCommand(command)
if (ignoredFileAttemptedToAccess) {
await cline.say("rooignore_error", ignoredFileAttemptedToAccess)
pushToolResult(formatResponse.toolError(formatResponse.rooIgnoreError(ignoredFileAttemptedToAccess)))

return
}

cline.consecutiveMistakeCount = 0

const didApprove = await askApproval("command", command)
if (!didApprove) {
return
}
const [userRejected, result] = await cline.executeCommandTool(command, customCwd)
if (userRejected) {
cline.didRejectTool = true
}
pushToolResult(result)
return
}
} catch (error) {
await handleError("executing command", error)
return
}
}