Skip to content

Commit 7922443

Browse files
committed
feat: edit/delete user message
1 parent c792662 commit 7922443

File tree

7 files changed

+291
-557
lines changed

7 files changed

+291
-557
lines changed

src/core/checkpoints/__tests__/checkpoint.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ describe("Checkpoint functionality", () => {
317317
},
318318
]
319319
mockCheckpointService.getDiff.mockResolvedValue(mockChanges)
320-
mockCheckpointService.getCheckpoints = vi.fn(() => ["commit1", "commit2"])
321320
await checkpointDiff(mockTask, {
322321
ts: 4,
323322
commitHash: "commit1",
@@ -343,7 +342,6 @@ describe("Checkpoint functionality", () => {
343342
},
344343
]
345344
mockCheckpointService.getDiff.mockResolvedValue(mockChanges)
346-
mockCheckpointService.getCheckpoints = vi.fn(() => ["commit1", "commit2"])
347345

348346
await checkpointDiff(mockTask, {
349347
ts: 4,

src/core/checkpoints/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,16 @@ export async function checkpointDiff(task: Task, { ts, previousCommitHash, commi
271271
TelemetryService.instance.captureCheckpointDiffed(task.taskId)
272272

273273
let prevHash = commitHash
274-
let nextHash: string | undefined
275-
276-
const checkpoints = typeof service.getCheckpoints === "function" ? service.getCheckpoints() : []
277-
const idx = checkpoints.indexOf(commitHash)
278-
279-
if (idx !== -1 && idx < checkpoints.length - 1) {
280-
nextHash = checkpoints[idx + 1]
281-
} else {
282-
nextHash = undefined
274+
let nextHash: string | undefined = undefined
275+
276+
if (mode !== "full") {
277+
const checkpoints = task.clineMessages.filter(({ say }) => say === "checkpoint_saved").map(({ text }) => text!)
278+
const idx = checkpoints.indexOf(commitHash)
279+
if (idx !== -1 && idx < checkpoints.length - 1) {
280+
nextHash = checkpoints[idx + 1]
281+
} else {
282+
nextHash = undefined
283+
}
283284
}
284285

285286
try {

src/core/webview/webviewMessageHandler.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export const webviewMessageHandler = async (
110110
const { messageIndex } = findMessageIndices(messageTs, currentCline)
111111
if (messageIndex !== -1) {
112112
// Find the last checkpoint before this message
113-
const checkpoints = currentCline.clineMessages
114-
.filter((msg) => msg.say === "checkpoint_saved" && msg.ts < messageTs)
115-
.sort((a, b) => b.ts - a.ts)
113+
const checkpoints = currentCline.clineMessages.filter(
114+
(msg) => msg.say === "checkpoint_saved" && msg.ts > messageTs,
115+
)
116116

117117
hasCheckpoint = checkpoints.length > 0
118118
} else {
@@ -153,19 +153,19 @@ export const webviewMessageHandler = async (
153153
// If checkpoint restoration is requested, find and restore to the last checkpoint before this message
154154
if (restoreCheckpoint) {
155155
// Find the last checkpoint before this message
156-
const checkpoints = currentCline.clineMessages
157-
.filter((msg) => msg.say === "checkpoint_saved" && msg.ts < messageTs)
158-
.sort((a, b) => b.ts - a.ts)
156+
const checkpoints = currentCline.clineMessages.filter(
157+
(msg) => msg.say === "checkpoint_saved" && msg.ts > messageTs,
158+
)
159159

160-
const lastCheckpoint = checkpoints[0]
160+
const nextCheckpoint = checkpoints[0]
161161

162-
if (lastCheckpoint && lastCheckpoint.text) {
162+
if (nextCheckpoint && nextCheckpoint.text) {
163163
await handleCheckpointRestoreOperation({
164164
provider,
165165
currentCline,
166166
messageTs: targetMessage.ts!,
167167
messageIndex,
168-
checkpoint: { hash: lastCheckpoint.text },
168+
checkpoint: { hash: nextCheckpoint.text },
169169
operation: "delete",
170170
})
171171
} else {
@@ -221,9 +221,9 @@ export const webviewMessageHandler = async (
221221
const { messageIndex } = findMessageIndices(messageTs, currentCline)
222222
if (messageIndex !== -1) {
223223
// Find the last checkpoint before this message
224-
const checkpoints = currentCline.clineMessages
225-
.filter((msg) => msg.say === "checkpoint_saved" && msg.ts < messageTs)
226-
.sort((a, b) => b.ts - a.ts)
224+
const checkpoints = currentCline.clineMessages.filter(
225+
(msg) => msg.say === "checkpoint_saved" && msg.ts > messageTs,
226+
)
227227

228228
hasCheckpoint = checkpoints.length > 0
229229
} else {
@@ -274,19 +274,19 @@ export const webviewMessageHandler = async (
274274
// If checkpoint restoration is requested, find and restore to the last checkpoint before this message
275275
if (restoreCheckpoint) {
276276
// Find the last checkpoint before this message
277-
const checkpoints = currentCline.clineMessages
278-
.filter((msg) => msg.say === "checkpoint_saved" && msg.ts < messageTs)
279-
.sort((a, b) => b.ts - a.ts)
277+
const checkpoints = currentCline.clineMessages.filter(
278+
(msg) => msg.say === "checkpoint_saved" && msg.ts > messageTs,
279+
)
280280

281-
const lastCheckpoint = checkpoints[0]
281+
const nextCheckpoint = checkpoints[0]
282282

283-
if (lastCheckpoint && lastCheckpoint.text) {
283+
if (nextCheckpoint && nextCheckpoint.text) {
284284
await handleCheckpointRestoreOperation({
285285
provider,
286286
currentCline,
287287
messageTs: targetMessage.ts!,
288288
messageIndex,
289-
checkpoint: { hash: lastCheckpoint.text },
289+
checkpoint: { hash: nextCheckpoint.text },
290290
operation: "edit",
291291
editData: {
292292
editedContent,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { appendImages } from "@src/utils/imageUtils"
4646
import { McpExecution } from "./McpExecution"
4747
import { ChatTextArea } from "./ChatTextArea"
4848
import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
49+
import { useSelectedModel } from "../ui/hooks/useSelectedModel"
4950

5051
interface ChatRowProps {
5152
message: ClineMessage
@@ -115,8 +116,8 @@ export const ChatRowContent = ({
115116
}: ChatRowContentProps) => {
116117
const { t } = useTranslation()
117118

118-
const { mcpServers, alwaysAllowMcp, currentCheckpoint, mode } = useExtensionState()
119-
119+
const { mcpServers, alwaysAllowMcp, currentCheckpoint, mode, apiConfiguration } = useExtensionState()
120+
const { info: model } = useSelectedModel(apiConfiguration)
120121
const [reasoningCollapsed, setReasoningCollapsed] = useState(true)
121122
const [isDiffErrorExpanded, setIsDiffErrorExpanded] = useState(false)
122123
const [showCopySuccess, setShowCopySuccess] = useState(false)
@@ -1184,7 +1185,7 @@ export const ChatRowContent = ({
11841185
setSelectedImages={setEditImages}
11851186
onSend={handleSaveEdit}
11861187
onSelectImages={handleSelectImages}
1187-
shouldDisableImages={false}
1188+
shouldDisableImages={!model?.supportsImages}
11881189
mode={editMode}
11891190
setMode={setEditMode}
11901191
modeShortcutText=""

0 commit comments

Comments
 (0)