Skip to content

Commit d15885e

Browse files
committed
Optimize multiroot workspace checkpoint handling, streamline git diff generation, and add a clear checkpoints migration
- [Pasted text] - we don't need compatibility fallbacks [Changes] - to make sure nothing breaks, create a migration removing all current checkpoints [Changes] └── apps └── editor └── src ├── commands │ └── history-command │ ├── actions │ │ ├── clear-all-checkpoints.ts │ │ ├── create-temporary-checkpoint.ts │ │ ├── delete-checkpoint-with-undo.ts │ │ ├── restore-checkpoint.ts │ │ ├── sync-workspace-from-dir.ts │ │ ├── toggle-checkpoint-pin.ts │ │ └── update-checkpoint-description.ts │ ├── history-command.ts │ ├── index.ts │ └── utils │ └── sync-directory.ts ├── extension.ts ├── features │ └── checkpoints │ ├── actions │ │ ├── create-checkpoint.ts │ │ ├── delete-checkpoint.ts │ │ ├── get-checkpoints.ts │ │ └── index.ts │ ├── types │ │ ├── checkpoint.ts │ │ └── index.ts │ └── utils │ ├── copy-optimised-recursively.ts │ ├── get-checkpoint-path.ts │ ├── get-incremented-description.ts │ ├── git-utils.ts │ └── index.ts └── migrations ├── index.ts ├── migrate-clear-all-checkpoints.ts ├── migrate-commit-message-details-filename.ts ├── migrate-configurations-to-api-configurations.ts ├── migrate-edit-context-to-edit-files-system-instructions.ts ├── migrate-prompt-templates-suffixes.ts └── migrate-prompt-templates-to-templates.ts
1 parent ccd1fc3 commit d15885e

8 files changed

Lines changed: 237 additions & 173 deletions

File tree

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

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Logger } from '@shared/utils/logger'
1616
export const create_temporary_checkpoint = async (
1717
workspace_provider: WorkspaceProvider
1818
): Promise<Checkpoint | undefined> => {
19-
const workspace_folders = vscode.workspace.workspaceFolders
19+
const workspace_folders = vscode.workspace.workspaceFolders!
2020

2121
const folder_git_statuses = await Promise.all(
2222
workspace_folders.map((folder) => is_git_repository(folder))
@@ -35,38 +35,59 @@ export const create_temporary_checkpoint = async (
3535
const git_data: Record<string, any> = {}
3636
let uses_git = false
3737

38-
for (const [index, folder] of workspace_folders.entries()) {
39-
const has_git = folder_git_statuses[index]
38+
await Promise.all(
39+
workspace_folders.map(async (folder, index) => {
40+
const has_git = folder_git_statuses[index]
41+
const folder_key = `${index}-${folder.name}`
4042

41-
if (has_git) {
42-
uses_git = true
43-
const git_info = await get_git_info(folder)
44-
const diff = await get_git_diff(folder)
43+
if (has_git) {
44+
uses_git = true
45+
const git_info = await get_git_info(folder)
46+
const diff = await get_git_diff(folder)
4547

46-
if (git_info && diff !== null) {
47-
const folder_name = folder.name
48-
git_data[folder_name] = {
49-
branch: git_info.branch,
50-
commit_hash: git_info.commit_hash,
51-
folder_name
52-
}
48+
if (git_info && diff !== null) {
49+
git_data[folder_key] = {
50+
branch: git_info.branch,
51+
commit_hash: git_info.commit_hash,
52+
folder_name: folder_key
53+
}
54+
55+
const diff_file_path = path.join(
56+
checkpoint_dir_path,
57+
`${folder_key}.diff`
58+
)
59+
await vscode.workspace.fs.writeFile(
60+
vscode.Uri.file(diff_file_path),
61+
Buffer.from(diff, 'utf8')
62+
)
63+
} else {
64+
Logger.warn({
65+
function_name: 'create_temporary_checkpoint',
66+
message: `Failed to get git information for repository in ${folder.name}. Falling back to file copy.`
67+
})
68+
const dest_folder_path =
69+
workspace_folders.length > 1
70+
? path.join(checkpoint_dir_path, folder_key)
71+
: checkpoint_dir_path
72+
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
73+
if (workspace_folders.length > 1) {
74+
await vscode.workspace.fs.createDirectory(dest_folder_uri)
75+
}
5376

54-
const diff_file_path = path.join(
55-
checkpoint_dir_path,
56-
`${folder_name}.diff`
57-
)
58-
await vscode.workspace.fs.writeFile(
59-
vscode.Uri.file(diff_file_path),
60-
Buffer.from(diff, 'utf8')
61-
)
77+
const entries = await vscode.workspace.fs.readDirectory(folder.uri)
78+
for (const [name] of entries) {
79+
await copy_optimised_recursively(
80+
vscode.Uri.joinPath(folder.uri, name),
81+
vscode.Uri.joinPath(dest_folder_uri, name),
82+
folder.uri.fsPath,
83+
workspace_provider
84+
)
85+
}
86+
}
6287
} else {
63-
Logger.warn({
64-
function_name: 'create_temporary_checkpoint',
65-
message: `Failed to get git information for repository in ${folder.name}. Falling back to file copy.`
66-
})
6788
const dest_folder_path =
6889
workspace_folders.length > 1
69-
? path.join(checkpoint_dir_path, folder.name)
90+
? path.join(checkpoint_dir_path, folder_key)
7091
: checkpoint_dir_path
7192
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
7293
if (workspace_folders.length > 1) {
@@ -83,27 +104,8 @@ export const create_temporary_checkpoint = async (
83104
)
84105
}
85106
}
86-
} else {
87-
const dest_folder_path =
88-
workspace_folders.length > 1
89-
? path.join(checkpoint_dir_path, folder.name)
90-
: checkpoint_dir_path
91-
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
92-
if (workspace_folders.length > 1) {
93-
await vscode.workspace.fs.createDirectory(dest_folder_uri)
94-
}
95-
96-
const entries = await vscode.workspace.fs.readDirectory(folder.uri)
97-
for (const [name] of entries) {
98-
await copy_optimised_recursively(
99-
vscode.Uri.joinPath(folder.uri, name),
100-
vscode.Uri.joinPath(dest_folder_uri, name),
101-
folder.uri.fsPath,
102-
workspace_provider
103-
)
104-
}
105-
}
106-
}
107+
})
108+
)
107109

108110
const active_tabs: CheckpointTab[] = []
109111
const tab_groups = vscode.window.tabGroups.all

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ export const restore_checkpoint = async (params: {
168168
if (params.checkpoint.uses_git && params.checkpoint.git_data) {
169169
const workspace_folders = vscode.workspace.workspaceFolders!
170170

171-
for (const folder of workspace_folders) {
172-
const folder_name = folder.name
173-
const git_info = params.checkpoint.git_data[folder_name]
171+
for (let index = 0; index < workspace_folders.length; index++) {
172+
const folder = workspace_folders[index]
173+
const folder_key = `${index}-${folder.name}`
174+
const git_info = params.checkpoint.git_data[folder_key]
174175

175176
if (git_info) {
176177
const current_git_info = await get_git_info(folder)
@@ -218,7 +219,7 @@ export const restore_checkpoint = async (params: {
218219

219220
const diff_file_path = path.join(
220221
checkpoint_dir_path,
221-
`${folder_name}.diff`
222+
`${git_info.folder_name}.diff`
222223
)
223224

224225
let diff = ''
@@ -319,7 +320,7 @@ export const restore_checkpoint = async (params: {
319320

320321
const diff_file_path = path.join(
321322
checkpoint_dir_path,
322-
`${folder_name}.diff`
323+
`${git_info.folder_name}.diff`
323324
)
324325

325326
let diff = ''
@@ -413,10 +414,13 @@ export const restore_checkpoint = async (params: {
413414
}
414415
}
415416
} else {
416-
const source_folder_uri =
417-
workspace_folders.length > 1
418-
? vscode.Uri.joinPath(checkpoint_dir_uri, folder.name)
419-
: checkpoint_dir_uri
417+
let source_folder_uri = checkpoint_dir_uri
418+
if (workspace_folders.length > 1) {
419+
source_folder_uri = vscode.Uri.joinPath(
420+
checkpoint_dir_uri,
421+
folder_key
422+
)
423+
}
420424
try {
421425
await vscode.workspace.fs.stat(source_folder_uri)
422426
await sync_directory({

‎apps/editor/src/commands/history-command/actions/sync-workspace-from-dir.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ export const sync_workspace_from_dir = async (params: {
1414
params.source_dir_uri
1515
)
1616
const source_folders = new Map(source_entries)
17-
for (const folder of workspace_folders) {
18-
const source_folder_type = source_folders.get(folder.name)
19-
if (source_folder_type == vscode.FileType.Directory) {
17+
for (let index = 0; index < workspace_folders.length; index++) {
18+
const folder = workspace_folders[index]
19+
const folder_key = `${index}-${folder.name}`
20+
21+
if (
22+
source_folders.has(folder_key) &&
23+
source_folders.get(folder_key) == vscode.FileType.Directory
24+
) {
2025
const source_folder_uri = vscode.Uri.joinPath(
2126
params.source_dir_uri,
22-
folder.name
27+
folder_key
2328
)
2429
await sync_directory({
2530
source_dir: source_folder_uri,

‎apps/editor/src/extension.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
migrate_edit_context_to_edit_files_system_instructions,
1010
migrate_prompt_templates_suffixes,
1111
migrate_commit_message_details_filename,
12-
migrate_prompt_templates_to_templates
12+
migrate_prompt_templates_to_templates,
13+
migrate_clear_all_checkpoints
1314
} from './migrations'
1415
import {
1516
apply_response_command,
@@ -70,6 +71,8 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
7071
await migrate_commit_message_details_filename(extension_context)
7172
// 16 August 2026
7273
await migrate_prompt_templates_to_templates(extension_context)
74+
// 10 September 2026
75+
await migrate_clear_all_checkpoints(extension_context)
7376
}
7477

7578
await migrations()

‎apps/editor/src/features/checkpoints/actions/create-checkpoint.ts‎

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -101,38 +101,61 @@ export const create_checkpoint = async (params: {
101101
const git_data: Record<string, any> = {}
102102
let uses_git = false
103103

104-
for (const [index, folder] of workspace_folders.entries()) {
105-
const has_git = folder_git_statuses[index]
106-
107-
if (has_git) {
108-
uses_git = true
109-
const git_info = await get_git_info(folder)
110-
const diff = await get_git_diff(folder)
111-
112-
if (git_info && diff !== null) {
113-
const folder_name = folder.name
114-
git_data[folder_name] = {
115-
branch: git_info.branch,
116-
commit_hash: git_info.commit_hash,
117-
folder_name
104+
await Promise.all(
105+
workspace_folders.map(async (folder, index) => {
106+
const has_git = folder_git_statuses[index]
107+
const folder_key = `${index}-${folder.name}`
108+
109+
if (has_git) {
110+
uses_git = true
111+
const git_info = await get_git_info(folder)
112+
const diff = await get_git_diff(folder)
113+
114+
if (git_info && diff !== null) {
115+
git_data[folder_key] = {
116+
branch: git_info.branch,
117+
commit_hash: git_info.commit_hash,
118+
folder_name: folder_key
119+
}
120+
121+
const diff_file_path = path.join(
122+
checkpoint_dir_path,
123+
`${folder_key}.diff`
124+
)
125+
await vscode.workspace.fs.writeFile(
126+
vscode.Uri.file(diff_file_path),
127+
Buffer.from(diff, 'utf8')
128+
)
129+
} else {
130+
Logger.warn({
131+
function_name: 'create_checkpoint',
132+
message: `Failed to get git information for repository in ${folder.name}. Falling back to file copy.`
133+
})
134+
const dest_folder_path =
135+
workspace_folders.length > 1
136+
? path.join(checkpoint_dir_path, folder_key)
137+
: checkpoint_dir_path
138+
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
139+
if (workspace_folders.length > 1) {
140+
await vscode.workspace.fs.createDirectory(dest_folder_uri)
141+
}
142+
143+
const entries = await vscode.workspace.fs.readDirectory(
144+
folder.uri
145+
)
146+
for (const [name] of entries) {
147+
await copy_optimised_recursively(
148+
vscode.Uri.joinPath(folder.uri, name),
149+
vscode.Uri.joinPath(dest_folder_uri, name),
150+
folder.uri.fsPath,
151+
params.workspace_provider
152+
)
153+
}
118154
}
119-
120-
const diff_file_path = path.join(
121-
checkpoint_dir_path,
122-
`${folder_name}.diff`
123-
)
124-
await vscode.workspace.fs.writeFile(
125-
vscode.Uri.file(diff_file_path),
126-
Buffer.from(diff, 'utf8')
127-
)
128155
} else {
129-
Logger.warn({
130-
function_name: 'create_checkpoint',
131-
message: `Failed to get git information for repository in ${folder.name}. Falling back to file copy.`
132-
})
133156
const dest_folder_path =
134157
workspace_folders.length > 1
135-
? path.join(checkpoint_dir_path, folder.name)
158+
? path.join(checkpoint_dir_path, folder_key)
136159
: checkpoint_dir_path
137160
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
138161
if (workspace_folders.length > 1) {
@@ -149,27 +172,8 @@ export const create_checkpoint = async (params: {
149172
)
150173
}
151174
}
152-
} else {
153-
const dest_folder_path =
154-
workspace_folders.length > 1
155-
? path.join(checkpoint_dir_path, folder.name)
156-
: checkpoint_dir_path
157-
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
158-
if (workspace_folders.length > 1) {
159-
await vscode.workspace.fs.createDirectory(dest_folder_uri)
160-
}
161-
162-
const entries = await vscode.workspace.fs.readDirectory(folder.uri)
163-
for (const [name] of entries) {
164-
await copy_optimised_recursively(
165-
vscode.Uri.joinPath(folder.uri, name),
166-
vscode.Uri.joinPath(dest_folder_uri, name),
167-
folder.uri.fsPath,
168-
params.workspace_provider
169-
)
170-
}
171-
}
172-
}
175+
})
176+
)
173177

174178
let checkpoints = await get_checkpoints(params.extension_context)
175179

0 commit comments

Comments
 (0)