Skip to content

Commit 69da8f1

Browse files
committed
Move checkpoint metadata and associated history/tasks to workspace-scoped global storage with migration, cleanup, and atomic file writes
- current behavior: checkpoints of the history are stored in a state key. Expected behavior: checkpoint metadata is stored in 'global workspace storage' - [Pasted text] - this state should never be reached. The history feature should not work in such case. - should hold checkpoints-workspace-id in `apps/editor/src/constants/state-keys.ts` - 'completed tasks' should, just like 'response history', be stored in the checkpoint's dedicated folder - checkpoints should not use `apps/editor/src/utils/global-workspace-storage.ts` but unique logic: each workspace has unique hashed folder in [global storage]/checkpoints. In it you save into metadata.json, and place diffs and other data in [global storage]/checkpoints/[checkpoint timestamp] folder. `apps/editor/src/migrations/migrate-checkpoints-to-global-storage.ts` wasn't yet applied and can be modified. - when saving checkpoint, scan `checkpoints` directory for workspace folders (hashed ones) that were updated earlier than CHECKPOINT_LIFESPAN, and remove them - current behavior: pinned checkpoints are immune to checkpoints lifespan. expected behavior: they're not - workspaces have too long hashes, shorten to 16 characters. don't run migration for this. - isn't folder name repeated and redundant? - assess correctness of migration `apps/editor/src/migrations/migrate-checkpoints-to-global-storage.ts` [Changes] - for checkpoints, should run garbage collection only once - upon extension activation - [Pasted text] - this should also be done to ranges.json, tasks.json, saved-contexts.json and commit-message-details.json - we don't like 'checkpoint as any' [Pasted text] - [Pasted text] - migration should handle this (edit the one we already have) └── apps └── editor ├── package.json └── src ├── commands │ ├── apply-response-command │ │ └── utils │ │ └── preview-handler.ts │ ├── code-at-cursor-command │ │ └── code-at-cursor-commands.ts │ ├── generate-commit-message-commands │ │ └── actions │ │ ├── get-prompt-data.ts │ │ └── run-generate-action.ts │ ├── history-command │ │ ├── actions │ │ │ ├── clear-all-checkpoints.ts │ │ │ ├── create-temporary-checkpoint.ts │ │ │ ├── delete-checkpoint-with-undo.ts │ │ │ ├── restore-checkpoint.ts │ │ │ ├── toggle-checkpoint-pin.ts │ │ │ └── update-checkpoint-description.ts │ │ ├── history-command.ts │ │ └── index.ts │ ├── restore-context-command │ │ └── actions │ │ └── restore-from-workspace-state.ts │ ├── save-context-command │ │ └── actions │ │ └── save-to-workspace-state.ts │ └── set-ranges-command.ts ├── constants │ ├── state-keys.ts │ └── values.ts ├── context │ └── providers │ └── workspace │ └── workspace-provider.ts ├── extension.ts ├── features │ ├── agentic-search │ │ └── agentic-search.ts │ ├── checkpoints │ │ ├── actions │ │ │ ├── accept-checkpoint.ts │ │ │ ├── create-checkpoint.ts │ │ │ ├── delete-checkpoint.ts │ │ │ ├── get-checkpoints.ts │ │ │ └── index.ts │ │ ├── types │ │ │ ├── checkpoint.ts │ │ │ └── index.ts │ │ └── utils │ │ ├── checkpoints-metadata.ts │ │ ├── get-checkpoint-path.ts │ │ ├── get-checkpoints-storage-key.ts │ │ ├── get-incremented-description.ts │ │ └── index.ts │ └── context-restoration │ └── utils │ └── global-storage-utils.ts ├── migrations │ ├── index.ts │ ├── migrate-checkpoints-to-global-storage.ts │ ├── migrate-commit-message-details-filename.ts │ └── migrate-ranges-to-global-storage.ts ├── utils │ ├── commit-message-details.ts │ ├── global-workspace-storage.ts │ └── workspace-snapshot.ts └── views └── prompt └── backend ├── message-handlers │ ├── handle-delete-task.ts │ ├── handle-get-tasks.ts │ ├── handle-open-prompt-image.ts │ ├── handle-open-prompt-pasted-text.ts │ ├── handle-open-website.ts │ ├── handle-paste-url.ts │ ├── handle-save-prompt-image.ts │ ├── handle-save-prompt-pasted-text.ts │ └── handle-save-tasks.ts ├── prompt-view-provider.ts └── utils ├── persistent-prompt-storage.ts └── symbols ├── image │ └── replace-image-symbol.ts ├── pasted-text │ └── replace-pasted-text-symbol.ts └── website └── replace-website-symbol.ts
1 parent 2b1f02e commit 69da8f1

26 files changed

Lines changed: 516 additions & 191 deletions

‎apps/editor/src/commands/history-command/actions/clear-all-checkpoints.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import * as vscode from 'vscode'
2-
import {
3-
CHECKPOINTS_STATE_KEY,
4-
TEMPORARY_CHECKPOINT_STATE_KEY
5-
} from '@/constants/state-keys'
2+
import { TEMPORARY_CHECKPOINT_STATE_KEY } from '@/constants/state-keys'
63
import { get_checkpoint_path } from '@/features/checkpoints/utils'
74
import { get_checkpoints } from '@/features/checkpoints/actions'
85
import { Logger } from '@shared/utils/logger'
96
import type { Checkpoint } from '@/features/checkpoints/types'
107
import { t } from '@/i18n'
8+
import { save_checkpoints_metadata } from '@/features/checkpoints/utils/checkpoints-metadata'
119

1210
export const clear_all_checkpoints = async (
1311
extension_context: vscode.ExtensionContext
@@ -61,10 +59,8 @@ export const clear_all_checkpoints = async (
6159
TEMPORARY_CHECKPOINT_STATE_KEY,
6260
undefined
6361
)
64-
await extension_context.workspaceState.update(
65-
CHECKPOINTS_STATE_KEY,
66-
checkpoints_to_keep
67-
)
62+
63+
await save_checkpoints_metadata(extension_context, checkpoints_to_keep)
6864
}
6965
await vscode.window.withProgress(
7066
{

‎apps/editor/src/commands/history-command/actions/delete-checkpoint-with-undo.ts‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as vscode from 'vscode'
2-
import { CHECKPOINTS_STATE_KEY } from '@/constants/state-keys'
32
import type { Checkpoint } from '@/features/checkpoints/types'
43
import { get_checkpoint_path } from '@/features/checkpoints/utils'
54
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
65
import { t } from '@/i18n'
76
import { get_error_message } from '@/utils/get-error-message'
7+
import {
8+
load_checkpoints_metadata,
9+
save_checkpoints_metadata
10+
} from '@/features/checkpoints/utils/checkpoints-metadata'
811

912
export type ActiveDeleteOperation = {
1013
finalize: () => Promise<void>
@@ -26,19 +29,14 @@ export const delete_checkpoint_with_undo = async (params: {
2629
params.set_active_operation(null)
2730
}
2831

29-
const checkpoints =
30-
params.extension_context.workspaceState.get<Checkpoint[]>(
31-
CHECKPOINTS_STATE_KEY,
32-
[]
33-
) ?? []
32+
const checkpoints = await load_checkpoints_metadata(params.extension_context)
3433

3534
const updated_checkpoints = checkpoints.filter(
3635
(c) => c.timestamp !== params.checkpoint.timestamp
3736
)
38-
await params.extension_context.workspaceState.update(
39-
CHECKPOINTS_STATE_KEY,
40-
updated_checkpoints
41-
)
37+
38+
await save_checkpoints_metadata(params.extension_context, updated_checkpoints)
39+
4240
params.on_did_update_checkpoints?.(updated_checkpoints)
4341

4442
const finalize = async () => {
@@ -77,19 +75,18 @@ export const delete_checkpoint_with_undo = async (params: {
7775
current_active_op.timestamp === operation.timestamp
7876
) {
7977
if (choice === undo_action) {
80-
const current_checkpoints =
81-
params.extension_context.workspaceState.get<Checkpoint[]>(
82-
CHECKPOINTS_STATE_KEY,
83-
[]
84-
) ?? []
78+
const current_checkpoints = await load_checkpoints_metadata(
79+
params.extension_context
80+
)
8581

8682
current_checkpoints.push(params.checkpoint)
8783
current_checkpoints.sort((a, b) => b.timestamp - a.timestamp)
8884

89-
await params.extension_context.workspaceState.update(
90-
CHECKPOINTS_STATE_KEY,
85+
await save_checkpoints_metadata(
86+
params.extension_context,
9187
current_checkpoints
9288
)
89+
9390
params.on_did_update_checkpoints?.(current_checkpoints)
9491

9592
params.on_before_show_message?.()

‎apps/editor/src/commands/history-command/actions/restore-checkpoint.ts‎

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ongoing_preview_cleanup_promise } from '@/commands/apply-response-comma
2222
import { CommitMessageDetails } from '@/utils/commit-message-details'
2323
import { t } from '@/i18n'
2424
import { get_error_message } from '@/utils/get-error-message'
25+
import { ResponseHistoryItem } from '@shared/types/response-history-item'
2526

2627
export const restore_checkpoint = async (params: {
2728
checkpoint: Checkpoint
@@ -58,32 +59,11 @@ export const restore_checkpoint = async (params: {
5859
})
5960
}
6061

61-
let open_files: {
62-
uri: vscode.Uri
63-
viewColumn: vscode.ViewColumn
64-
isActive: boolean
65-
}[] = []
66-
67-
if (params.checkpoint.active_tabs) {
68-
open_files = params.checkpoint.active_tabs.map((tab) => ({
69-
uri: vscode.Uri.parse(tab.uri),
70-
viewColumn: tab.view_column as vscode.ViewColumn,
71-
isActive: tab.is_active && tab.is_group_active
72-
}))
73-
} else {
74-
const tab_groups = vscode.window.tabGroups.all
75-
for (const group of tab_groups) {
76-
for (const tab of group.tabs) {
77-
if (tab.input instanceof vscode.TabInputText) {
78-
open_files.push({
79-
uri: (tab.input as vscode.TabInputText).uri,
80-
viewColumn: group.viewColumn,
81-
isActive: tab.isActive && group.isActive
82-
})
83-
}
84-
}
85-
}
86-
}
62+
const open_files = (params.checkpoint.active_tabs ?? []).map((tab) => ({
63+
uri: vscode.Uri.parse(tab.uri),
64+
viewColumn: tab.view_column as vscode.ViewColumn,
65+
isActive: tab.is_active && tab.is_group_active
66+
}))
8767

8868
let temp_checkpoint: Checkpoint | undefined
8969
try {
@@ -176,12 +156,24 @@ export const restore_checkpoint = async (params: {
176156
progress
177157
)
178158

179-
if (params.checkpoint.response_history) {
180-
params.prompt_view_provider.response_history =
181-
params.checkpoint.response_history
159+
let loaded_history: ResponseHistoryItem[] = []
160+
try {
161+
const history_file_path = vscode.Uri.joinPath(
162+
vscode.Uri.file(checkpoint_dir_path),
163+
'response-history.json'
164+
)
165+
const history_data =
166+
await vscode.workspace.fs.readFile(history_file_path)
167+
loaded_history = JSON.parse(new TextDecoder().decode(history_data))
168+
} catch {
169+
// Ignore if file doesn't exist
170+
}
171+
172+
if (loaded_history.length > 0) {
173+
params.prompt_view_provider.response_history = loaded_history
182174
params.prompt_view_provider.send_message({
183175
command: 'RESPONSE_HISTORY',
184-
history: params.checkpoint.response_history
176+
history: loaded_history
185177
})
186178
} else {
187179
params.prompt_view_provider.response_history = []
@@ -191,18 +183,31 @@ export const restore_checkpoint = async (params: {
191183
})
192184
}
193185

194-
if (params.checkpoint.completed_tasks) {
195-
params.prompt_view_provider.completed_tasks =
196-
params.checkpoint.completed_tasks
186+
let loaded_completed_tasks: string[] | undefined
187+
try {
188+
const completed_tasks_file_path = vscode.Uri.joinPath(
189+
vscode.Uri.file(checkpoint_dir_path),
190+
'completed-tasks.json'
191+
)
192+
const completed_tasks_data = await vscode.workspace.fs.readFile(
193+
completed_tasks_file_path
194+
)
195+
loaded_completed_tasks = JSON.parse(
196+
new TextDecoder().decode(completed_tasks_data)
197+
)
198+
} catch {}
199+
200+
if (loaded_completed_tasks !== undefined) {
201+
params.prompt_view_provider.completed_tasks = loaded_completed_tasks
197202
await params.extension_context.workspaceState.update(
198203
COMPLETED_TASKS_STATE_KEY,
199-
params.checkpoint.completed_tasks
204+
loaded_completed_tasks
200205
)
201206
params.prompt_view_provider.send_message({
202207
command: 'COMPLETED_TASKS',
203-
completed_tasks: params.checkpoint.completed_tasks
208+
completed_tasks: loaded_completed_tasks
204209
})
205-
} else {
210+
} else if (params.checkpoint.trigger !== 'temporary') {
206211
params.prompt_view_provider.completed_tasks = []
207212
await params.extension_context.workspaceState.update(
208213
COMPLETED_TASKS_STATE_KEY,
@@ -243,13 +248,11 @@ export const restore_checkpoint = async (params: {
243248
} catch {}
244249
}
245250

246-
if (params.checkpoint.selected_files) {
247-
await params.extension_context.workspaceState.update(
248-
CONTEXT_SELECTED_PATHS_STATE_KEY,
249-
params.checkpoint.selected_files
250-
)
251-
params.workspace_provider.load_selected_files_state()
252-
}
251+
await params.extension_context.workspaceState.update(
252+
CONTEXT_SELECTED_PATHS_STATE_KEY,
253+
params.checkpoint.selected_files
254+
)
255+
params.workspace_provider.load_selected_files_state()
253256

254257
params.prompt_view_provider.send_token_count()
255258

@@ -261,9 +264,9 @@ export const restore_checkpoint = async (params: {
261264
if (
262265
params.checkpoint.trigger === 'response-accepted' &&
263266
params.checkpoint.response_preview_item_created_at &&
264-
params.checkpoint.response_history
267+
loaded_history.length > 0
265268
) {
266-
const item_to_preview = params.checkpoint.response_history.find(
269+
const item_to_preview = loaded_history.find(
267270
(item) =>
268271
item.created_at ==
269272
params.checkpoint.response_preview_item_created_at
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import * as vscode from 'vscode'
2-
import { CHECKPOINTS_STATE_KEY } from '@/constants/state-keys'
3-
import type { Checkpoint } from '@/features/checkpoints/types'
42
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
3+
import {
4+
load_checkpoints_metadata,
5+
save_checkpoints_metadata
6+
} from '@/features/checkpoints/utils/checkpoints-metadata'
57

68
export const toggle_checkpoint_pin = async (params: {
79
extension_context: vscode.ExtensionContext
810
timestamp: number
911
prompt_view_provider: PromptViewProvider
1012
}) => {
11-
const checkpoints =
12-
params.extension_context.workspaceState.get<Checkpoint[]>(
13-
CHECKPOINTS_STATE_KEY,
14-
[]
15-
) ?? []
13+
const checkpoints = await load_checkpoints_metadata(params.extension_context)
14+
1615
const checkpoint_to_update = checkpoints.find(
1716
(c) => c.timestamp === params.timestamp
1817
)
1918
if (checkpoint_to_update) {
2019
checkpoint_to_update.is_pinned = !checkpoint_to_update.is_pinned
21-
await params.extension_context.workspaceState.update(
22-
CHECKPOINTS_STATE_KEY,
23-
checkpoints
24-
)
20+
await save_checkpoints_metadata(params.extension_context, checkpoints)
2521
}
2622
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import * as vscode from 'vscode'
2-
import { CHECKPOINTS_STATE_KEY } from '@/constants/state-keys'
3-
import type { Checkpoint } from '@/features/checkpoints/types'
42
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
3+
import {
4+
load_checkpoints_metadata,
5+
save_checkpoints_metadata
6+
} from '@/features/checkpoints/utils/checkpoints-metadata'
57

68
export const update_checkpoint_description = async (params: {
79
extension_context: vscode.ExtensionContext
810
timestamp: number
911
description: string
1012
prompt_view_provider: PromptViewProvider
1113
}) => {
12-
const checkpoints =
13-
params.extension_context.workspaceState.get<Checkpoint[]>(
14-
CHECKPOINTS_STATE_KEY,
15-
[]
16-
) ?? []
14+
const checkpoints = await load_checkpoints_metadata(params.extension_context)
15+
1716
const checkpoint_to_update = checkpoints.find(
1817
(c) => c.timestamp === params.timestamp
1918
)
2019
if (checkpoint_to_update) {
2120
checkpoint_to_update.description = params.description
22-
await params.extension_context.workspaceState.update(
23-
CHECKPOINTS_STATE_KEY,
24-
checkpoints
25-
)
21+
await save_checkpoints_metadata(params.extension_context, checkpoints)
2622
}
2723
}

0 commit comments

Comments
 (0)