Skip to content

Commit 8d8452e

Browse files
authored
[PROTOBUS] Move askResponse to protobus (RooCodeInc#3539)
* askResponse protobus migration * Standalone script updated
1 parent 6c18d51 commit 8d8452e

File tree

11 files changed

+258
-56
lines changed

11 files changed

+258
-56
lines changed

.changeset/nervous-jokes-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
askResponse protobus migration

proto/task.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ service TaskService {
2525
rpc deleteNonFavoritedTasks(EmptyRequest) returns (DeleteNonFavoritedTasksResults);
2626
// Gets filtered task history
2727
rpc getTaskHistory(GetTaskHistoryRequest) returns (TaskHistoryArray);
28+
// Sends a response to a previous ask operation
29+
rpc askResponse(AskResponseRequest) returns (Empty);
2830
}
2931

3032
// Request message for creating a new task
@@ -89,3 +91,11 @@ message TaskItem {
8991
int32 cache_writes = 9;
9092
int32 cache_reads = 10;
9193
}
94+
95+
// Request for ask response operation
96+
message AskResponseRequest {
97+
Metadata metadata = 1;
98+
string response_type = 2;
99+
string text = 3;
100+
repeated string images = 4;
101+
}

src/core/controller/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ export class Controller {
323323
const browserSession = new BrowserSession(this.context, browserSettings)
324324
await browserSession.relaunchChromeDebugMode(this)
325325
break
326-
case "askResponse":
327-
this.task?.handleWebviewAskResponse(message.askResponse!, message.text, message.images)
328-
break
329326
case "didShowAnnouncement":
330327
await updateGlobalState(this.context, "lastShownAnnouncementId", this.latestAnnouncementId)
331328
await this.postStateToWebview()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Controller } from ".."
2+
import { Empty } from "../../../shared/proto/common"
3+
import { AskResponseRequest } from "../../../shared/proto/task"
4+
import { ClineAskResponse } from "../../../shared/WebviewMessage"
5+
6+
/**
7+
* Handles a response from the webview for a previous ask operation
8+
*
9+
* @param controller The controller instance
10+
* @param request The request containing response type, optional text and optional images
11+
* @returns Empty response
12+
*/
13+
export async function askResponse(controller: Controller, request: AskResponseRequest): Promise<Empty> {
14+
try {
15+
if (!controller.task) {
16+
console.warn("askResponse: No active task to receive response")
17+
return Empty.create()
18+
}
19+
20+
// Map the string responseType to the ClineAskResponse enum
21+
let responseType: ClineAskResponse
22+
switch (request.responseType) {
23+
case "yesButtonClicked":
24+
responseType = "yesButtonClicked"
25+
break
26+
case "noButtonClicked":
27+
responseType = "noButtonClicked"
28+
break
29+
case "messageResponse":
30+
responseType = "messageResponse"
31+
break
32+
default:
33+
console.warn(`askResponse: Unknown response type: ${request.responseType}`)
34+
return Empty.create()
35+
}
36+
37+
// Call the task's handler for webview responses
38+
await controller.task.handleWebviewAskResponse(responseType, request.text, request.images)
39+
40+
return Empty.create()
41+
} catch (error) {
42+
console.error("Error in askResponse handler:", error)
43+
throw error
44+
}
45+
}

src/core/controller/task/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Import all method implementations
55
import { registerMethod } from "./index"
6+
import { askResponse } from "./askResponse"
67
import { cancelTask } from "./cancelTask"
78
import { clearTask } from "./clearTask"
89
import { deleteNonFavoritedTasks } from "./deleteNonFavoritedTasks"
@@ -16,6 +17,7 @@ import { toggleTaskFavorite } from "./toggleTaskFavorite"
1617
// Register all task service methods
1718
export function registerAllMethods(): void {
1819
// Register each method with the registry
20+
registerMethod("askResponse", askResponse)
1921
registerMethod("cancelTask", cancelTask)
2022
registerMethod("clearTask", clearTask)
2123
registerMethod("deleteNonFavoritedTasks", deleteNonFavoritedTasks)

src/services/test/TestServer.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { execa } from "execa"
55
import { Logger } from "@services/logging/Logger"
66
import { WebviewProvider } from "@core/webview"
77
import { AutoApprovalSettings } from "@shared/AutoApprovalSettings"
8+
import { TaskServiceClient } from "webview-ui/src/services/grpc-client"
89
import {
910
getWorkspacePath,
1011
validateWorkspacePath,
@@ -15,7 +16,6 @@ import {
1516
import { updateGlobalState, getAllExtensionState, updateApiConfiguration, storeSecret } from "@core/storage/state"
1617
import { ClineAsk, ExtensionMessage } from "@shared/ExtensionMessage"
1718
import { ApiProvider } from "@shared/api"
18-
import { WebviewMessage } from "@shared/WebviewMessage"
1919
import { HistoryItem } from "@shared/HistoryItem"
2020
import { getSavedClineMessages, getSavedApiConversationHistory } from "@core/storage/disk"
2121

@@ -515,8 +515,8 @@ export function createMessageCatcher(webviewProvider: WebviewProvider): vscode.D
515515
const askText = message.partialMessage.text
516516

517517
// Automatically respond to different types of asks
518-
setTimeout(() => {
519-
autoRespondToAsk(webviewProvider, askType, askText)
518+
setTimeout(async () => {
519+
await autoRespondToAsk(webviewProvider, askType, askText)
520520
}, 100) // Small delay to ensure the message is processed first
521521
}
522522

@@ -538,65 +538,64 @@ export function createMessageCatcher(webviewProvider: WebviewProvider): vscode.D
538538
* @param askType The type of ask message
539539
* @param askText The text content of the ask message
540540
*/
541-
function autoRespondToAsk(webviewProvider: WebviewProvider, askType: ClineAsk, askText?: string): void {
541+
async function autoRespondToAsk(webviewProvider: WebviewProvider, askType: ClineAsk, askText?: string): Promise<void> {
542542
if (!webviewProvider.controller) {
543543
return
544544
}
545545

546546
Logger.log(`Auto-responding to ask type: ${askType}`)
547547

548-
// Create a response message based on the ask type
549-
const response: WebviewMessage = {
550-
type: "askResponse",
551-
askResponse: "yesButtonClicked", // Default to approving most actions
552-
}
548+
// Default to approving most actions
549+
let responseType = "yesButtonClicked"
550+
let responseText: string | undefined
551+
let responseImages: string[] | undefined
553552

554553
// Handle specific ask types differently if needed
555554
switch (askType) {
556555
case "followup":
557556
// For follow-up questions, provide a generic response
558-
response.askResponse = "messageResponse"
559-
response.text = "I can't answer any questions right now, use your best judgment."
557+
responseType = "messageResponse"
558+
responseText = "I can't answer any questions right now, use your best judgment."
560559
break
561560

562561
case "api_req_failed":
563562
// Always retry API requests
564-
response.askResponse = "yesButtonClicked" // "Retry" button
563+
responseType = "yesButtonClicked" // "Retry" button
565564
break
566565

567566
case "completion_result":
568567
// Accept the completion
569-
response.askResponse = "messageResponse"
570-
response.text = "Task completed successfully."
568+
responseType = "messageResponse"
569+
responseText = "Task completed successfully."
571570
break
572571

573572
case "mistake_limit_reached":
574573
// Provide guidance to continue
575-
response.askResponse = "messageResponse"
576-
response.text = "Try breaking down the task into smaller steps."
574+
responseType = "messageResponse"
575+
responseText = "Try breaking down the task into smaller steps."
577576
break
578577

579578
case "auto_approval_max_req_reached":
580579
// Reset the count to continue
581-
response.askResponse = "yesButtonClicked" // "Reset and continue" button
580+
responseType = "yesButtonClicked" // "Reset and continue" button
582581
break
583582

584583
case "resume_task":
585584
case "resume_completed_task":
586585
// Resume the task
587-
response.askResponse = "messageResponse"
586+
responseType = "messageResponse"
588587
break
589588

590589
case "new_task":
591590
// Decline creating a new task to keep the current task running
592-
response.askResponse = "messageResponse"
593-
response.text = "Continue with the current task."
591+
responseType = "messageResponse"
592+
responseText = "Continue with the current task."
594593
break
595594

596595
case "plan_mode_respond":
597596
// Respond to plan mode with a message to toggle to Act mode
598-
response.askResponse = "messageResponse"
599-
response.text = "PLAN_MODE_TOGGLE_RESPONSE" // Special marker to toggle to Act mode
597+
responseType = "messageResponse"
598+
responseText = "PLAN_MODE_TOGGLE_RESPONSE" // Special marker to toggle to Act mode
600599

601600
// Automatically toggle to Act mode after responding
602601
setTimeout(async () => {
@@ -616,8 +615,16 @@ function autoRespondToAsk(webviewProvider: WebviewProvider, askType: ClineAsk, a
616615
}
617616

618617
// Send the response message
619-
webviewProvider.controller.handleWebviewMessage(response)
620-
Logger.log(`Auto-responded to ${askType} with ${response.askResponse}`)
618+
try {
619+
await TaskServiceClient.askResponse({
620+
responseType,
621+
text: responseText,
622+
images: responseImages,
623+
})
624+
Logger.log(`Auto-responded to ${askType} with ${responseType}`)
625+
} catch (error) {
626+
Logger.log(`Error sending askResponse: ${error}`)
627+
}
621628
}
622629

623630
/**

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface WebviewMessage {
1414
| "newTask"
1515
| "condense"
1616
| "reportBug"
17-
| "askResponse"
1817
| "didShowAnnouncement"
1918
| "resetState"
2019
| "openInBrowser"
@@ -66,7 +65,6 @@ export interface WebviewMessage {
6665
// | "relaunchChromeDebugMode"
6766
text?: string
6867
disabled?: boolean
69-
askResponse?: ClineAskResponse
7068
apiConfiguration?: ApiConfiguration
7169
images?: string[]
7270
bool?: boolean

src/shared/proto/task.ts

Lines changed: 126 additions & 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)