[PROTOBUS] checkpoints checkpointRestore (#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 (#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 (#3014) * added verisoning for autoApprove settings * removed lines from source branch * rebase * changeset * one small change * activating extension with evals.env (#3041) Co-authored-by: Cline Evaluation <cline@example.com> * ripping out test build flag (#3043) Co-authored-by: Cline Evaluation <cline@example.com> * cleaning up evals.env logic in extension.ts (#3045) Co-authored-by: Cline Evaluation <cline@example.com> * ENG-516 Slash commands (#3044) * scroll * menu * changeset * nit * What's yer path? (#3047) * update extension imports to use aliasing * changeset * ENG-484 Enhance fixWithCline command execution by focusing chat input (#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 (#3049) * prompt * changeset * words * prettier * Added metadata --------- Co-authored-by: yt3trees <57471763+yt3trees@users.noreply.github.com> Co-authored-by: pashpashpash <nik@cline.bot> Co-authored-by: Cline Evaluation <cline@example.com> Co-authored-by: Toshii <94262432+0xToshii@users.noreply.github.com> Co-authored-by: Evan <58194240+celestial-vault@users.noreply.github.com> Co-authored-by: nomaven <arafat.da.khan@gmail.com>
This commit is contained in:
12 files changed
+287
-69
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
protobus migration for checkpointRestore
|
||||
@@ -6,5 +6,12 @@ import "common.proto";
|
||||
|
||||
service CheckpointsService {
|
||||
rpc checkpointDiff(Int64Request) returns (Empty);
|
||||
rpc checkpointRestore(CheckpointRestoreRequest) returns (Empty);
|
||||
}
|
||||
|
||||
message CheckpointRestoreRequest {
|
||||
Metadata metadata = 1;
|
||||
int64 number = 2;
|
||||
string restore_type = 3;
|
||||
optional int64 offset = 4;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Controller } from ".."
|
||||
import { ClineCheckpointRestore } from "../../../shared/WebviewMessage"
|
||||
import { CheckpointRestoreRequest } from "../../../shared/proto/checkpoints"
|
||||
import { Empty } from "../../../shared/proto/common"
|
||||
import pWaitFor from "p-wait-for"
|
||||
|
||||
export async function checkpointRestore(controller: Controller, request: CheckpointRestoreRequest): Promise<Empty> {
|
||||
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
|
||||
|
||||
if (request.number) {
|
||||
// wait for messages to be loaded
|
||||
await pWaitFor(() => controller.task?.isInitialized === true, {
|
||||
timeout: 3_000,
|
||||
}).catch(() => {
|
||||
console.error("Failed to init new cline instance")
|
||||
})
|
||||
|
||||
// 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
|
||||
await controller.task?.restoreCheckpoint(request.number, request.restoreType as ClineCheckpointRestore, request.offset)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export type CheckpointsMethodHandler = ServiceMethodHandler
|
||||
export const registerMethod = checkpointsService.registerMethod
|
||||
|
||||
// Export the request handler
|
||||
export const handleCheckpointsDiffServiceRequest = checkpointsService.handleRequest
|
||||
export const handleCheckpointsServiceRequest = checkpointsService.handleRequest
|
||||
|
||||
// Register all checkpoints methods
|
||||
registerAllMethods()
|
||||
@@ -4,9 +4,11 @@
|
||||
// Import all method implementations
|
||||
import { registerMethod } from "./index"
|
||||
import { checkpointDiff } from "./checkpointDiff"
|
||||
import { checkpointRestore } from "./checkpointRestore"
|
||||
|
||||
// Register all checkpoints service methods
|
||||
export function registerAllMethods(): void {
|
||||
// Register each method with the registry
|
||||
registerMethod("checkpointDiff", checkpointDiff)
|
||||
registerMethod("checkpointRestore", checkpointRestore)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Controller } from "./index"
|
||||
import { handleBrowserServiceRequest } from "./browser/index"
|
||||
import { handleCheckpointsDiffServiceRequest } from "./checkpoints"
|
||||
import { handleCheckpointsServiceRequest } from "./checkpoints"
|
||||
import { handleMcpServiceRequest } from "./mcp"
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ export class GrpcHandler {
|
||||
}
|
||||
case "cline.CheckpointsService":
|
||||
return {
|
||||
message: await handleCheckpointsDiffServiceRequest(this.controller, method, message),
|
||||
message: await handleCheckpointsServiceRequest(this.controller, method, message),
|
||||
request_id: requestId,
|
||||
}
|
||||
case "cline.McpService":
|
||||
|
||||
@@ -460,21 +460,6 @@ export class Controller {
|
||||
case "openMention":
|
||||
openMention(message.text)
|
||||
break
|
||||
case "checkpointRestore": {
|
||||
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
|
||||
// cancel task waits for any open editor to be reverted and starts a new cline instance
|
||||
if (message.number) {
|
||||
// wait for messages to be loaded
|
||||
await pWaitFor(() => this.task?.isInitialized === true, {
|
||||
timeout: 3_000,
|
||||
}).catch(() => {
|
||||
console.error("Failed to init new cline instance")
|
||||
})
|
||||
// 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
|
||||
await this.task?.restoreCheckpoint(message.number, message.text! as ClineCheckpointRestore, message.offset)
|
||||
}
|
||||
break
|
||||
}
|
||||
case "taskCompletionViewChanges": {
|
||||
if (message.number) {
|
||||
await this.task?.presentMultifileDiff(message.number, true)
|
||||
|
||||
@@ -42,7 +42,6 @@ export interface WebviewMessage {
|
||||
| "browserSettings"
|
||||
| "browserRelaunchResult"
|
||||
| "togglePlanActMode"
|
||||
| "checkpointRestore"
|
||||
| "taskCompletionViewChanges"
|
||||
| "openExtensionSettings"
|
||||
| "requestVsCodeLmModels"
|
||||
|
||||
@@ -5,10 +5,127 @@
|
||||
// source: checkpoints.proto
|
||||
|
||||
/* eslint-disable */
|
||||
import { Empty, Int64Request } from "./common"
|
||||
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"
|
||||
import { Empty, Int64Request, Metadata } from "./common"
|
||||
|
||||
export const protobufPackage = "cline"
|
||||
|
||||
export interface CheckpointRestoreRequest {
|
||||
metadata?: Metadata | undefined
|
||||
number: number
|
||||
restoreType: string
|
||||
offset?: number | undefined
|
||||
}
|
||||
|
||||
function createBaseCheckpointRestoreRequest(): CheckpointRestoreRequest {
|
||||
return { metadata: undefined, number: 0, restoreType: "", offset: undefined }
|
||||
}
|
||||
|
||||
export const CheckpointRestoreRequest: MessageFns<CheckpointRestoreRequest> = {
|
||||
encode(message: CheckpointRestoreRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||
if (message.metadata !== undefined) {
|
||||
Metadata.encode(message.metadata, writer.uint32(10).fork()).join()
|
||||
}
|
||||
if (message.number !== 0) {
|
||||
writer.uint32(16).int64(message.number)
|
||||
}
|
||||
if (message.restoreType !== "") {
|
||||
writer.uint32(26).string(message.restoreType)
|
||||
}
|
||||
if (message.offset !== undefined) {
|
||||
writer.uint32(32).int64(message.offset)
|
||||
}
|
||||
return writer
|
||||
},
|
||||
|
||||
decode(input: BinaryReader | Uint8Array, length?: number): CheckpointRestoreRequest {
|
||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input)
|
||||
let end = length === undefined ? reader.len : reader.pos + length
|
||||
const message = createBaseCheckpointRestoreRequest()
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32()
|
||||
switch (tag >>> 3) {
|
||||
case 1: {
|
||||
if (tag !== 10) {
|
||||
break
|
||||
}
|
||||
|
||||
message.metadata = Metadata.decode(reader, reader.uint32())
|
||||
continue
|
||||
}
|
||||
case 2: {
|
||||
if (tag !== 16) {
|
||||
break
|
||||
}
|
||||
|
||||
message.number = longToNumber(reader.int64())
|
||||
continue
|
||||
}
|
||||
case 3: {
|
||||
if (tag !== 26) {
|
||||
break
|
||||
}
|
||||
|
||||
message.restoreType = reader.string()
|
||||
continue
|
||||
}
|
||||
case 4: {
|
||||
if (tag !== 32) {
|
||||
break
|
||||
}
|
||||
|
||||
message.offset = longToNumber(reader.int64())
|
||||
continue
|
||||
}
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break
|
||||
}
|
||||
reader.skip(tag & 7)
|
||||
}
|
||||
return message
|
||||
},
|
||||
|
||||
fromJSON(object: any): CheckpointRestoreRequest {
|
||||
return {
|
||||
metadata: isSet(object.metadata) ? Metadata.fromJSON(object.metadata) : undefined,
|
||||
number: isSet(object.number) ? globalThis.Number(object.number) : 0,
|
||||
restoreType: isSet(object.restoreType) ? globalThis.String(object.restoreType) : "",
|
||||
offset: isSet(object.offset) ? globalThis.Number(object.offset) : undefined,
|
||||
}
|
||||
},
|
||||
|
||||
toJSON(message: CheckpointRestoreRequest): unknown {
|
||||
const obj: any = {}
|
||||
if (message.metadata !== undefined) {
|
||||
obj.metadata = Metadata.toJSON(message.metadata)
|
||||
}
|
||||
if (message.number !== 0) {
|
||||
obj.number = Math.round(message.number)
|
||||
}
|
||||
if (message.restoreType !== "") {
|
||||
obj.restoreType = message.restoreType
|
||||
}
|
||||
if (message.offset !== undefined) {
|
||||
obj.offset = Math.round(message.offset)
|
||||
}
|
||||
return obj
|
||||
},
|
||||
|
||||
create<I extends Exact<DeepPartial<CheckpointRestoreRequest>, I>>(base?: I): CheckpointRestoreRequest {
|
||||
return CheckpointRestoreRequest.fromPartial(base ?? ({} as any))
|
||||
},
|
||||
fromPartial<I extends Exact<DeepPartial<CheckpointRestoreRequest>, I>>(object: I): CheckpointRestoreRequest {
|
||||
const message = createBaseCheckpointRestoreRequest()
|
||||
message.metadata =
|
||||
object.metadata !== undefined && object.metadata !== null ? Metadata.fromPartial(object.metadata) : undefined
|
||||
message.number = object.number ?? 0
|
||||
message.restoreType = object.restoreType ?? ""
|
||||
message.offset = object.offset ?? undefined
|
||||
return message
|
||||
},
|
||||
}
|
||||
|
||||
export type CheckpointsServiceDefinition = typeof CheckpointsServiceDefinition
|
||||
export const CheckpointsServiceDefinition = {
|
||||
name: "CheckpointsService",
|
||||
@@ -22,5 +139,54 @@ export const CheckpointsServiceDefinition = {
|
||||
responseStream: false,
|
||||
options: {},
|
||||
},
|
||||
checkpointRestore: {
|
||||
name: "checkpointRestore",
|
||||
requestType: CheckpointRestoreRequest,
|
||||
requestStream: false,
|
||||
responseType: Empty,
|
||||
responseStream: false,
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
} as const
|
||||
|
||||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined
|
||||
|
||||
export type DeepPartial<T> = T extends Builtin
|
||||
? T
|
||||
: T extends globalThis.Array<infer U>
|
||||
? globalThis.Array<DeepPartial<U>>
|
||||
: T extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: T extends {}
|
||||
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||
: Partial<T>
|
||||
|
||||
type KeysOfUnion<T> = T extends T ? keyof T : never
|
||||
export type Exact<P, I extends P> = P extends Builtin
|
||||
? P
|
||||
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never }
|
||||
|
||||
function longToNumber(int64: { toString(): string }): number {
|
||||
const num = globalThis.Number(int64.toString())
|
||||
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
||||
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER")
|
||||
}
|
||||
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
|
||||
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER")
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
function isSet(value: any): boolean {
|
||||
return value !== null && value !== undefined
|
||||
}
|
||||
|
||||
export interface MessageFns<T> {
|
||||
encode(message: T, writer?: BinaryWriter): BinaryWriter
|
||||
decode(input: BinaryReader | Uint8Array, length?: number): T
|
||||
fromJSON(object: any): T
|
||||
toJSON(message: T): unknown
|
||||
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T
|
||||
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import React, { useState, useRef, forwardRef, useCallback } from "react"
|
||||
import Thumbnails from "@/components/common/Thumbnails"
|
||||
import { highlightText } from "./TaskHeader"
|
||||
import { vscode } from "@/utils/vscode"
|
||||
import DynamicTextArea from "react-textarea-autosize"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import { CheckpointsServiceClient } from "@/services/grpc-client"
|
||||
import { ClineCheckpointRestore } from "@shared/WebviewMessage"
|
||||
|
||||
interface UserMessageProps {
|
||||
text?: string
|
||||
@@ -35,7 +36,7 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, messageTs, send
|
||||
}
|
||||
}, [isEditing])
|
||||
|
||||
const handleRestoreWorkspace = (type: string) => {
|
||||
const handleRestoreWorkspace = async (type: ClineCheckpointRestore) => {
|
||||
const delay = type === "task" ? 500 : 1000 // Delay for task and workspace restore
|
||||
setIsEditing(false)
|
||||
|
||||
@@ -43,16 +44,19 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, messageTs, send
|
||||
return
|
||||
}
|
||||
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: type,
|
||||
offset: 1,
|
||||
})
|
||||
try {
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType: type,
|
||||
offset: 1,
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
sendMessageFromChatRow?.(editedText, images || [])
|
||||
}, delay)
|
||||
setTimeout(() => {
|
||||
sendMessageFromChatRow?.(editedText, images || [])
|
||||
}, delay)
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
const handleBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
|
||||
@@ -146,10 +150,10 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, messageTs, send
|
||||
|
||||
// Reusable button component for restore actions
|
||||
interface RestoreButtonProps {
|
||||
type: string
|
||||
type: ClineCheckpointRestore
|
||||
label: string
|
||||
isPrimary: boolean
|
||||
onClick: (type: string) => void
|
||||
onClick: (type: ClineCheckpointRestore) => void
|
||||
title?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useCallback, useRef, useState, useEffect } from "react"
|
||||
import { useEvent } from "react-use"
|
||||
import styled from "styled-components"
|
||||
import { ExtensionMessage } from "@shared/ExtensionMessage"
|
||||
import { ClineCheckpointRestore } from "@shared/WebviewMessage"
|
||||
import { CheckpointsServiceClient } from "@/services/grpc-client"
|
||||
import { vscode } from "@/utils/vscode"
|
||||
import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
|
||||
@@ -60,31 +61,46 @@ export const CheckmarkControl = ({ messageTs, isCheckpointCheckedOut }: Checkmar
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleRestoreTask = () => {
|
||||
const handleRestoreTask = async () => {
|
||||
setRestoreTaskDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "task",
|
||||
})
|
||||
try {
|
||||
const restoreType: ClineCheckpointRestore = "task"
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType,
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore task error:", err)
|
||||
setRestoreTaskDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRestoreWorkspace = () => {
|
||||
const handleRestoreWorkspace = async () => {
|
||||
setRestoreWorkspaceDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "workspace",
|
||||
})
|
||||
try {
|
||||
const restoreType: ClineCheckpointRestore = "workspace"
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType,
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore workspace error:", err)
|
||||
setRestoreWorkspaceDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRestoreBoth = () => {
|
||||
const handleRestoreBoth = async () => {
|
||||
setRestoreBothDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "taskAndWorkspace",
|
||||
})
|
||||
try {
|
||||
const restoreType: ClineCheckpointRestore = "taskAndWorkspace"
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType,
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore both error:", err)
|
||||
setRestoreBothDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
|
||||
@@ -45,31 +45,43 @@ export const CheckpointOverlay = ({ messageTs }: CheckpointOverlayProps) => {
|
||||
|
||||
useEvent("message", handleMessage)
|
||||
|
||||
const handleRestoreTask = () => {
|
||||
const handleRestoreTask = async () => {
|
||||
setRestoreTaskDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "task" satisfies ClineCheckpointRestore,
|
||||
})
|
||||
try {
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType: "task",
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore task error:", err)
|
||||
setRestoreTaskDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRestoreWorkspace = () => {
|
||||
const handleRestoreWorkspace = async () => {
|
||||
setRestoreWorkspaceDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "workspace" satisfies ClineCheckpointRestore,
|
||||
})
|
||||
try {
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType: "workspace",
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore workspace error:", err)
|
||||
setRestoreWorkspaceDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRestoreBoth = () => {
|
||||
const handleRestoreBoth = async () => {
|
||||
setRestoreBothDisabled(true)
|
||||
vscode.postMessage({
|
||||
type: "checkpointRestore",
|
||||
number: messageTs,
|
||||
text: "taskAndWorkspace" satisfies ClineCheckpointRestore,
|
||||
})
|
||||
try {
|
||||
await CheckpointsServiceClient.checkpointRestore({
|
||||
number: messageTs,
|
||||
restoreType: "taskAndWorkspace",
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Checkpoint restore both error:", err)
|
||||
setRestoreBothDisabled(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
|
||||
Reference in new issue
Block a user