Fix attempt_completion tool if it has a command that fails or is rejected

This commit is contained in:
Saoud Rizwan
2024-07-27 13:11:53 -04:00
parent 35a6ecbca2
commit 14bbf3a9e5

View File

@@ -490,7 +490,7 @@ export class ClaudeDev {
}
}
async executeCommand(command: string): Promise<string> {
async executeCommand(command: string, returnEmptyStringOnSuccess: boolean = false): Promise<string> {
const { response, text } = await this.ask("command", command)
if (response !== "yesButtonTapped") {
if (response === "textResponse" && text) {
@@ -508,6 +508,10 @@ export class ClaudeDev {
this.say("command_output", line) // stream output to user in realtime
result += `${line}\n`
}
// for attemptCompletion, we don't want to return the command output
if (returnEmptyStringOnSuccess) {
return ""
}
return `Command executed successfully. Output:\n${result}`
} catch (e) {
const error = e as any
@@ -529,7 +533,11 @@ export class ClaudeDev {
if (command) {
await this.say("completion_result", resultToSend)
// TODO: currently we don't handle if this command fails, it could be useful to let claude know and retry
await this.executeCommand(command)
const commandResult = await this.executeCommand(command, true)
// if we received non-empty string, the command was rejected or failed
if (commandResult) {
return commandResult
}
resultToSend = ""
}
const { response, text } = await this.ask("completion_result", resultToSend) // this prompts webview to show 'new task' button, and enable text input (which would be the 'text' here)