Skip to content

Commit 756c0a0

Browse files
authored
Fix issues with subtasks attempting completion along with commands (RooCodeInc#3156)
1 parent 40ee5cf commit 756c0a0

File tree

10 files changed

+34
-22
lines changed

10 files changed

+34
-22
lines changed

.changeset/dull-flowers-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Fix auto-approvals

src/core/Cline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class Cline extends EventEmitter<ClineEvents> {
161161
private askResponse?: ClineAskResponse
162162
private askResponseText?: string
163163
private askResponseImages?: string[]
164-
private lastMessageTs?: number
164+
public lastMessageTs?: number
165165

166166
// Not private since it needs to be accessible by tools.
167167
consecutiveMistakeCount: number = 0

src/core/tools/attemptCompletionTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ export async function attemptCompletionTool(
7676
}
7777

7878
// Complete command message.
79-
const executionId = Date.now().toString()
80-
const didApprove = await askApproval("command", command, { id: executionId })
79+
const didApprove = await askApproval("command", command)
8180

8281
if (!didApprove) {
8382
return
8483
}
8584

85+
const executionId = cline.lastMessageTs?.toString() ?? Date.now().toString()
8686
const options: ExecuteCommandOptions = { executionId, command }
8787
const [userRejected, execCommandResult] = await executeCommand(cline, options)
8888

@@ -108,7 +108,7 @@ export async function attemptCompletionTool(
108108
}
109109

110110
// tell the provider to remove the current subtask and resume the previous task in the stack
111-
await cline.providerRef.deref()?.finishSubTask(lastMessage?.text ?? "")
111+
await cline.providerRef.deref()?.finishSubTask(result)
112112
return
113113
}
114114

src/core/tools/executeCommandTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export async function executeCommandTool(
4848

4949
cline.consecutiveMistakeCount = 0
5050

51-
const executionId = Date.now().toString()
5251
command = unescapeHtmlEntities(command) // Unescape HTML entities.
53-
const didApprove = await askApproval("command", command, { id: executionId })
52+
const didApprove = await askApproval("command", command)
5453

5554
if (!didApprove) {
5655
return
5756
}
5857

58+
const executionId = cline.lastMessageTs?.toString() ?? Date.now().toString()
5959
const clineProvider = await cline.providerRef.deref()
6060
const clineProviderState = await clineProvider?.getState()
6161
const { terminalOutputLineLimit = 500, terminalShellIntegrationDisabled = false } = clineProviderState ?? {}

src/exports/roo-code.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ type ClineMessage = {
353353
| undefined
354354
progressStatus?:
355355
| {
356-
id?: string | undefined
357356
icon?: string | undefined
358357
text?: string | undefined
359358
}
@@ -429,7 +428,6 @@ type RooCodeEvents = {
429428
| undefined
430429
progressStatus?:
431430
| {
432-
id?: string | undefined
433431
icon?: string | undefined
434432
text?: string | undefined
435433
}

src/exports/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ type ClineMessage = {
358358
| undefined
359359
progressStatus?:
360360
| {
361-
id?: string | undefined
362361
icon?: string | undefined
363362
text?: string | undefined
364363
}
@@ -438,7 +437,6 @@ type RooCodeEvents = {
438437
| undefined
439438
progressStatus?:
440439
| {
441-
id?: string | undefined
442440
icon?: string | undefined
443441
text?: string | undefined
444442
}

src/schemas/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ export type ClineSay = z.infer<typeof clineSaySchema>
817817
*/
818818

819819
export const toolProgressStatusSchema = z.object({
820-
id: z.string().optional(),
821820
icon: z.string().optional(),
822821
text: z.string().optional(),
823822
})

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ export const ChatRowContent = ({
985985
{icon}
986986
{title}
987987
</div>
988-
<CommandExecution executionId={message.progressStatus?.id} text={message.text} />
988+
<CommandExecution executionId={message.ts.toString()} text={message.text} />
989989
</>
990990
)
991991
case "use_mcp_server":

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
735735

736736
const isAutoApproved = useCallback(
737737
(message: ClineMessage | undefined) => {
738-
if (!autoApprovalEnabled || !message || message.type !== "ask") return false
738+
if (!autoApprovalEnabled || !message || message.type !== "ask") {
739+
return false
740+
}
739741

740742
if (message.ask === "browser_action_launch") {
741743
return alwaysAllowBrowser
@@ -749,7 +751,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
749751
return alwaysAllowExecute && isAllowedCommand(message)
750752
}
751753

752-
// For read/write operations, check if it's outside workspace and if we have permission for that
754+
// For read/write operations, check if it's outside workspace and if
755+
// we have permission for that.
753756
if (message.ask === "tool") {
754757
let tool: any = {}
755758

@@ -1114,13 +1117,26 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
11141117
}
11151118

11161119
const autoApprove = async () => {
1117-
if (isAutoApproved(lastMessage)) {
1120+
if (lastMessage?.ask && isAutoApproved(lastMessage)) {
1121+
// Note that `isAutoApproved` can only return true if
1122+
// lastMessage is an ask of type "browser_action_launch",
1123+
// "use_mcp_server", "command", or "tool".
1124+
11181125
// Add delay for write operations.
1119-
if (lastMessage?.ask === "tool" && isWriteToolAction(lastMessage)) {
1126+
if (lastMessage.ask === "tool" && isWriteToolAction(lastMessage)) {
11201127
await new Promise((resolve) => setTimeout(resolve, writeDelayMs))
11211128
}
11221129

1123-
handlePrimaryButtonClick()
1130+
vscode.postMessage({ type: "askResponse", askResponse: "yesButtonClicked" })
1131+
1132+
// This is copied from `handlePrimaryButtonClick`, which we used
1133+
// to call from `autoApprove`. I'm not sure how many of these
1134+
// things are actually needed.
1135+
setInputValue("")
1136+
setSelectedImages([])
1137+
setTextAreaDisabled(true)
1138+
setClineAsk(undefined)
1139+
setEnableButtons(false)
11241140
}
11251141
}
11261142
autoApprove()

webview-ui/src/components/chat/CommandExecution.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { cn } from "@src/lib/utils"
1414
import { Button } from "@src/components/ui"
1515

1616
interface CommandExecutionProps {
17-
executionId?: string
17+
executionId: string
1818
text?: string
1919
}
2020

@@ -36,10 +36,6 @@ export const CommandExecution = ({ executionId, text }: CommandExecutionProps) =
3636

3737
const onMessage = useCallback(
3838
(event: MessageEvent) => {
39-
if (!executionId) {
40-
return
41-
}
42-
4339
const message: ExtensionMessage = event.data
4440

4541
if (message.type === "commandExecutionStatus") {

0 commit comments

Comments
 (0)