Skip to content

Commit 3d3ecd0

Browse files
committed
fix(execute_command): show a parse-rejected command and its error in chat
When parseCommand rejects a command (for example an unterminated quote from a response the provider cut off), ExecuteCommandTool returned before askApproval. The command row that handlePartial had streamed stayed partial, often with empty text, and the error only appeared as a red-dot tooltip. Now the tool fills that row with the full command, marks it complete and answered, and posts a visible error saying the command was not run and why. The model still gets the same tool error. See also Zoo-Code-Org#1820.
1 parent 3c52ed6 commit 3d3ecd0

20 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎src/core/tools/ExecuteCommandTool.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ export function resolveAgentTimeoutMs(timeoutSeconds: number | null | undefined)
7676
return process.env.ROO_CLI_RUNTIME === "1" ? 0 : requestedAgentTimeout
7777
}
7878

79+
/**
80+
* Fills in and completes the command row that `handlePartial` streamed.
81+
* Without this, a command rejected before `askApproval` leaves that row
82+
* partial with whatever text it had last, often empty (see #1820).
83+
*/
84+
async function finalizeStreamingCommandRow(task: Task, command: string): Promise<void> {
85+
const last = task.clineMessages.at(-1)
86+
if (last?.type !== "ask" || last.ask !== "command" || !last.partial) {
87+
return
88+
}
89+
last.text = command
90+
last.isAnswered = true
91+
await task.completePartialMessage(last)
92+
}
93+
7994
// Fire-and-forget: some call sites are synchronous terminal callbacks that cannot await,
8095
// and postMessageToWebview swallows its own errors, so void is enough.
8196
function postCommandExecutionStatus(provider: ClineProvider | undefined, status: CommandExecutionStatus): void {
@@ -115,6 +130,7 @@ export class ExecuteCommandTool extends BaseTool<"execute_command"> {
115130
// command, rather than receiving a generic denial from the approval dialog.
116131
const { parseError } = parseCommand(canonicalCommand)
117132
if (parseError !== null) {
133+
await finalizeStreamingCommandRow(task, canonicalCommand)
118134
const executionId = task.lastMessageTs?.toString() ?? Date.now().toString()
119135
const provider = await task.providerRef.deref()
120136
const errorStatus: CommandExecutionStatus = {
@@ -123,6 +139,7 @@ export class ExecuteCommandTool extends BaseTool<"execute_command"> {
123139
message: parseError.message,
124140
}
125141
postCommandExecutionStatus(provider, errorStatus)
142+
await task.say("error", t("tools:executeCommand.parseRejected", { error: parseError.message }))
126143
task.didToolFailInCurrentTurn = true
127144
pushToolResult(formatResponse.toolError(parseError.message))
128145
return

‎src/core/tools/__tests__/executeCommandTool.spec.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe("executeCommandTool", () => {
7979
mockCline = {
8080
ask: vitest.fn().mockResolvedValue(undefined),
8181
say: vitest.fn().mockResolvedValue(undefined),
82+
clineMessages: [],
8283
sayAndCreateMissingParamError: vitest.fn().mockResolvedValue("Missing parameter error"),
8384
consecutiveMistakeCount: 0,
8485
didRejectTool: false,
@@ -231,6 +232,42 @@ describe("executeCommandTool", () => {
231232
}),
232233
)
233234
expect(mockAskApproval).not.toHaveBeenCalled()
235+
expect(mockCline.say).toHaveBeenCalledWith("error", "executeCommand.parseRejected")
236+
})
237+
238+
it("completes the streamed command row with the rejected command", async () => {
239+
const streamedRow = { type: "ask", ask: "command", ts: 1, text: "", partial: true }
240+
mockCline.clineMessages = [streamedRow]
241+
mockCline.completePartialMessage = vitest.fn().mockResolvedValue(undefined)
242+
const command = "git commit -m 'unterminated"
243+
mockToolUse.params.command = command
244+
mockToolUse.nativeArgs = { command }
245+
246+
await executeCommandTool.handle(mockCline as unknown as Task, mockToolUse, {
247+
askApproval: mockAskApproval as unknown as AskApproval,
248+
handleError: mockHandleError as unknown as HandleError,
249+
pushToolResult: mockPushToolResult as unknown as PushToolResult,
250+
})
251+
252+
expect(streamedRow).toMatchObject({ text: command, isAnswered: true })
253+
expect(mockCline.completePartialMessage).toHaveBeenCalledWith(streamedRow)
254+
})
255+
256+
it("leaves a non-command last row alone on a parse error", async () => {
257+
const otherRow = { type: "say", say: "text", ts: 1, text: "hi", partial: true }
258+
mockCline.clineMessages = [otherRow]
259+
mockCline.completePartialMessage = vitest.fn().mockResolvedValue(undefined)
260+
mockToolUse.params.command = 'echo "unterminated'
261+
mockToolUse.nativeArgs = { command: 'echo "unterminated' }
262+
263+
await executeCommandTool.handle(mockCline as unknown as Task, mockToolUse, {
264+
askApproval: mockAskApproval as unknown as AskApproval,
265+
handleError: mockHandleError as unknown as HandleError,
266+
pushToolResult: mockPushToolResult as unknown as PushToolResult,
267+
})
268+
269+
expect(otherRow.text).toBe("hi")
270+
expect(mockCline.completePartialMessage).not.toHaveBeenCalled()
234271
})
235272

236273
it("posts fallback status when retrying a pre-submission shell integration failure", async () => {

‎src/i18n/locales/ca/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/de/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/en/tools.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"approval": "Searching for '{{query}}' in codebase..."
1616
},
1717
"executeCommand": {
18+
"parseRejected": "The command was not run because it could not be parsed: {{error}}",
1819
"destructiveCommandGuard": {
1920
"blocked": "Destructive Command Guard blocked this command.",
2021
"blockedWithReason": "Destructive Command Guard blocked this command. Message from DCG: {{reason}}",

‎src/i18n/locales/es/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/fr/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/hi/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/id/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/it/tools.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)