Skip to content

Commit 808e4d0

Browse files
committed
Refactor checkpoint handling to rename and update the "Before response previewed" checkpoint to "Before response accepted" upon successful application of changes, and ensure UPDATE_LAST_USED_PRESET message sends the preset name
1 parent bae2c28 commit 808e4d0

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
delete_checkpoint
66
} from '../checkpoints-command/actions'
77
import { FileInPreview } from '@shared/types/file-in-preview'
8+
import { get_checkpoint_path } from '../checkpoints-command/utils'
89
import { PanelProvider } from '@/views/panel/backend/panel-provider'
910
import { dictionary } from '@shared/constants/dictionary'
1011
import { WorkspaceProvider } from '@/context/providers/workspace-provider'
@@ -272,14 +273,34 @@ export const apply_chat_response_command = (params: {
272273
CHECKPOINTS_STATE_KEY,
273274
[]
274275
) ?? []
275-
const checkpoint_to_update = checkpoints.find(
276+
const checkpoint_index = checkpoints.findIndex(
276277
(c) => c.timestamp == before_checkpoint!.timestamp
277278
)
278-
if (checkpoint_to_update) {
279+
if (checkpoint_index != -1) {
280+
const checkpoint_to_update = checkpoints[checkpoint_index]
281+
const old_timestamp = checkpoint_to_update.timestamp
282+
const new_timestamp = Date.now()
283+
const old_path = get_checkpoint_path(old_timestamp)
284+
const new_path = get_checkpoint_path(new_timestamp)
285+
try {
286+
await vscode.workspace.fs.rename(
287+
vscode.Uri.file(old_path),
288+
vscode.Uri.file(new_path)
289+
)
290+
checkpoint_to_update.timestamp = new_timestamp
291+
} catch (err) {
292+
console.error(
293+
`Failed to rename checkpoint directory for timestamp update:`,
294+
err
295+
)
296+
}
279297
checkpoint_to_update.title = 'Before response accepted'
280298
checkpoint_to_update.response_history = history_for_checkpoint
281299
checkpoint_to_update.response_preview_item_created_at =
282300
created_at_for_preview
301+
302+
checkpoints.sort((a, b) => b.timestamp - a.timestamp)
303+
283304
await params.context.workspaceState.update(
284305
CHECKPOINTS_STATE_KEY,
285306
checkpoints

‎packages/vscode/src/commands/checkpoints-command/actions/restore-checkpoint.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ export const restore_checkpoint = async (params: {
520520
params.websites_provider.load_checked_websites_state()
521521
}
522522

523+
await params.context.workspaceState.update(
524+
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
525+
undefined
526+
)
527+
523528
if (
524529
params.checkpoint.title == 'Before response accepted' &&
525530
params.checkpoint.response_preview_item_created_at &&
@@ -539,11 +544,6 @@ export const restore_checkpoint = async (params: {
539544
}
540545
}
541546

542-
await params.context.workspaceState.update(
543-
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
544-
undefined
545-
)
546-
547547
const message = params.options?.skip_confirmation
548548
? 'Successfully reverted changes.'
549549
: 'Checkpoint has been restored.'

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const Panel = () => {
197197
on_preset_edit={(preset) => {
198198
post_message(vscode, {
199199
command: 'UPDATE_LAST_USED_PRESET',
200-
preset_name: preset.name
200+
preset_name: preset.name!
201201
})
202202
set_updating_preset(preset)
203203
set_updated_preset(preset)

0 commit comments

Comments
 (0)