Skip to content

Commit ea4f571

Browse files
canvrnoyt3treespashpashpashCline Evaluation0xToshii
authored
[PROTOBUS] checkpoints checkpointRestore (RooCodeInc#3046)
* restoreTask protobus * changeset * changeset correction * type safety change * Fix Non-UTF-8 File Handling: Improve Encoding Detection to Prevent Garbled Text and Binary Misclassification (RooCodeInc#2347) * Fix Non-UTF-8 File Handling: Improve Encoding Detection to Prevent Garbled Text and Binary Misclassification * update package-lock.json * update * update * fix * fix * fix * ENG 526/Fix: Versioned Auto Approve settings (RooCodeInc#3014) * added verisoning for autoApprove settings * removed lines from source branch * rebase * changeset * one small change * activating extension with evals.env (RooCodeInc#3041) Co-authored-by: Cline Evaluation <[email protected]> * ripping out test build flag (RooCodeInc#3043) Co-authored-by: Cline Evaluation <[email protected]> * cleaning up evals.env logic in extension.ts (RooCodeInc#3045) Co-authored-by: Cline Evaluation <[email protected]> * ENG-516 Slash commands (RooCodeInc#3044) * scroll * menu * changeset * nit * What's yer path? (RooCodeInc#3047) * update extension imports to use aliasing * changeset * ENG-484 Enhance fixWithCline command execution by focusing chat input (RooCodeInc#3028) * Enhance fixWithCline command execution by focusing chat input and adding a delay before processing the fixWithCline command. * feat: add OpenRouter base URL and balance display component * feat: add OpenRouter base URL and balance display component * feat: add OpenRouter base URL and balance display component * new_task prompt (RooCodeInc#3049) * prompt * changeset * words * prettier * Added metadata --------- Co-authored-by: yt3trees <[email protected]> Co-authored-by: pashpashpash <[email protected]> Co-authored-by: Cline Evaluation <[email protected]> Co-authored-by: Toshii <[email protected]> Co-authored-by: Evan <[email protected]> Co-authored-by: nomaven <[email protected]>
1 parent 8cddbcf commit ea4f571

File tree

12 files changed

+288
-70
lines changed

12 files changed

+288
-70
lines changed

.changeset/weak-emus-joke.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+
protobus migration for checkpointRestore

proto/checkpoints.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ import "common.proto";
66

77
service CheckpointsService {
88
rpc checkpointDiff(Int64Request) returns (Empty);
9+
rpc checkpointRestore(CheckpointRestoreRequest) returns (Empty);
910
}
1011

12+
message CheckpointRestoreRequest {
13+
Metadata metadata = 1;
14+
int64 number = 2;
15+
string restore_type = 3;
16+
optional int64 offset = 4;
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Controller } from ".."
2+
import { ClineCheckpointRestore } from "../../../shared/WebviewMessage"
3+
import { CheckpointRestoreRequest } from "../../../shared/proto/checkpoints"
4+
import { Empty } from "../../../shared/proto/common"
5+
import pWaitFor from "p-wait-for"
6+
7+
export async function checkpointRestore(controller: Controller, request: CheckpointRestoreRequest): Promise<Empty> {
8+
await controller.cancelTask() // we cannot alter message history say if the task is active, as it could be in the middle of editing a file or running a command, which expect the ask to be responded to rather than being superseded by a new message eg add deleted_api_reqs
9+
10+
if (request.number) {
11+
// wait for messages to be loaded
12+
await pWaitFor(() => controller.task?.isInitialized === true, {
13+
timeout: 3_000,
14+
}).catch(() => {
15+
console.error("Failed to init new cline instance")
16+
})
17+
18+
// NOTE: cancelTask awaits abortTask, which awaits diffViewProvider.revertChanges, which reverts any edited files, allowing us to reset to a checkpoint rather than running into a state where the revertChanges function is called alongside or after the checkpoint reset
19+
await controller.task?.restoreCheckpoint(request.number, request.restoreType as ClineCheckpointRestore, request.offset)
20+
}
21+
return {}
22+
}

src/core/controller/checkpoints/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type CheckpointsMethodHandler = ServiceMethodHandler
99
export const registerMethod = checkpointsService.registerMethod
1010

1111
// Export the request handler
12-
export const handleCheckpointsDiffServiceRequest = checkpointsService.handleRequest
12+
export const handleCheckpointsServiceRequest = checkpointsService.handleRequest
1313

1414
// Register all checkpoints methods
1515
registerAllMethods()

src/core/controller/checkpoints/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// Import all method implementations
55
import { registerMethod } from "./index"
66
import { checkpointDiff } from "./checkpointDiff"
7+
import { checkpointRestore } from "./checkpointRestore"
78

89
// Register all checkpoints service methods
910
export function registerAllMethods(): void {
1011
// Register each method with the registry
1112
registerMethod("checkpointDiff", checkpointDiff)
13+
registerMethod("checkpointRestore", checkpointRestore)
1214
}

src/core/controller/grpc-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Controller } from "./index"
22
import { handleBrowserServiceRequest } from "./browser/index"
3-
import { handleCheckpointsDiffServiceRequest } from "./checkpoints"
3+
import { handleCheckpointsServiceRequest } from "./checkpoints"
44
import { handleMcpServiceRequest } from "./mcp"
55

66
/**
@@ -36,7 +36,7 @@ export class GrpcHandler {
3636
}
3737
case "cline.CheckpointsService":
3838
return {
39-
message: await handleCheckpointsDiffServiceRequest(this.controller, method, message),
39+
message: await handleCheckpointsServiceRequest(this.controller, method, message),
4040
request_id: requestId,
4141
}
4242
case "cline.McpService":

src/core/controller/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -460,21 +460,6 @@ export class Controller {
460460
case "openMention":
461461
openMention(message.text)
462462
break
463-
case "checkpointRestore": {
464-
await this.cancelTask() // we cannot alter message history say if the task is active, as it could be in the middle of editing a file or running a command, which expect the ask to be responded to rather than being superseded by a new message eg add deleted_api_reqs
465-
// cancel task waits for any open editor to be reverted and starts a new cline instance
466-
if (message.number) {
467-
// wait for messages to be loaded
468-
await pWaitFor(() => this.task?.isInitialized === true, {
469-
timeout: 3_000,
470-
}).catch(() => {
471-
console.error("Failed to init new cline instance")
472-
})
473-
// NOTE: cancelTask awaits abortTask, which awaits diffViewProvider.revertChanges, which reverts any edited files, allowing us to reset to a checkpoint rather than running into a state where the revertChanges function is called alongside or after the checkpoint reset
474-
await this.task?.restoreCheckpoint(message.number, message.text! as ClineCheckpointRestore, message.offset)
475-
}
476-
break
477-
}
478463
case "taskCompletionViewChanges": {
479464
if (message.number) {
480465
await this.task?.presentMultifileDiff(message.number, true)

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export interface WebviewMessage {
4242
| "browserSettings"
4343
| "browserRelaunchResult"
4444
| "togglePlanActMode"
45-
| "checkpointRestore"
4645
| "taskCompletionViewChanges"
4746
| "openExtensionSettings"
4847
| "requestVsCodeLmModels"

src/shared/proto/checkpoints.ts

Lines changed: 167 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useState, useRef, forwardRef, useCallback } from "react"
22
import Thumbnails from "@/components/common/Thumbnails"
33
import { highlightText } from "./TaskHeader"
4-
import { vscode } from "@/utils/vscode"
54
import DynamicTextArea from "react-textarea-autosize"
65
import { useExtensionState } from "@/context/ExtensionStateContext"
6+
import { CheckpointsServiceClient } from "@/services/grpc-client"
7+
import { ClineCheckpointRestore } from "@shared/WebviewMessage"
78

89
interface UserMessageProps {
910
text?: string
@@ -35,24 +36,27 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, messageTs, send
3536
}
3637
}, [isEditing])
3738

38-
const handleRestoreWorkspace = (type: string) => {
39+
const handleRestoreWorkspace = async (type: ClineCheckpointRestore) => {
3940
const delay = type === "task" ? 500 : 1000 // Delay for task and workspace restore
4041
setIsEditing(false)
4142

4243
if (text === editedText) {
4344
return
4445
}
4546

46-
vscode.postMessage({
47-
type: "checkpointRestore",
48-
number: messageTs,
49-
text: type,
50-
offset: 1,
51-
})
52-
53-
setTimeout(() => {
54-
sendMessageFromChatRow?.(editedText, images || [])
55-
}, delay)
47+
try {
48+
await CheckpointsServiceClient.checkpointRestore({
49+
number: messageTs,
50+
restoreType: type,
51+
offset: 1,
52+
})
53+
54+
setTimeout(() => {
55+
sendMessageFromChatRow?.(editedText, images || [])
56+
}, delay)
57+
} catch (err) {
58+
console.error("Checkpoint restore error:", err)
59+
}
5660
}
5761

5862
const handleBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
@@ -146,10 +150,10 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, messageTs, send
146150

147151
// Reusable button component for restore actions
148152
interface RestoreButtonProps {
149-
type: string
153+
type: ClineCheckpointRestore
150154
label: string
151155
isPrimary: boolean
152-
onClick: (type: string) => void
156+
onClick: (type: ClineCheckpointRestore) => void
153157
title?: string
154158
}
155159

0 commit comments

Comments
 (0)