Skip to content

Commit 0009ecb

Browse files
committed
Extract workspace snapshot creation and restoration logic into a shared utility module used by checkpoints and agentic search
- 'agentic search' sometimes edits some files, to prevent it: use similar approach to creating and restoring checkpoint (but don't use checkpoint feature but shared util from `apps/editor/src/features/checkpoints/utils` - make sure checkpoint creation also use this snapshotting util) [Accuracy boost] - utils shared between features [Changes] should be moved to `apps/editor/src/utils` └── apps └── editor └── src ├── commands │ ├── agentic-search-command │ │ ├── agentic-search-command.ts │ │ └── index.ts │ ├── apply-response-command │ │ └── apply-response-command.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 ├── constants │ └── state-keys.ts ├── context │ └── providers │ └── workspace │ └── workspace-provider.ts ├── extension.ts ├── features │ ├── agentic-search │ │ ├── agentic-search-state.ts │ │ ├── agentic-search.ts │ │ ├── index.ts │ │ └── utils │ │ ├── build-agent-prompt.ts │ │ ├── index.ts │ │ └── prompt-for-search-term.ts │ └── checkpoints │ ├── actions │ │ ├── accept-checkpoint.ts │ │ ├── create-checkpoint.ts │ │ ├── delete-checkpoint.ts │ │ ├── get-checkpoints.ts │ │ └── index.ts │ ├── types │ │ ├── checkpoint.ts │ │ └── index.ts │ └── utils │ ├── get-checkpoint-path.ts │ ├── get-incremented-description.ts │ └── index.ts ├── utils │ ├── ascii-tree │ │ ├── ascii-tree.ts │ │ ├── index.ts │ │ └── utils.ts │ ├── copy-optimised-recursively.ts │ ├── files-collector.ts │ ├── get-error-message.ts │ ├── git-utils.ts │ ├── sync-directory.ts │ ├── sync-workspace-from-dir.ts │ └── workspace-snapshot.ts └── views └── prompt └── backend └── message-handlers └── handle-agentic-search.ts
1 parent a28a4e4 commit 0009ecb

10 files changed

Lines changed: 522 additions & 535 deletions

File tree

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

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import * as path from 'path'
21
import * as vscode from 'vscode'
32
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
43
import type { Checkpoint, CheckpointTab } from '@/features/checkpoints/types'
5-
import {
6-
copy_optimised_recursively,
7-
get_checkpoint_path
8-
} from '@/features/checkpoints/utils'
9-
import {
10-
get_git_diff,
11-
get_git_info,
12-
is_git_repository
13-
} from '@/features/checkpoints/utils/git-utils'
14-
import { Logger } from '@shared/utils/logger'
4+
import { get_checkpoint_path } from '@/features/checkpoints/utils'
5+
import { create_workspace_snapshot } from '@/utils/workspace-snapshot'
6+
import { is_git_repository } from '@/utils/git-utils'
157

168
export const create_temporary_checkpoint = async (
179
workspace_provider: WorkspaceProvider,
@@ -27,85 +19,14 @@ export const create_temporary_checkpoint = async (
2719
return undefined
2820
}
2921

30-
await vscode.workspace.saveAll()
3122
const timestamp = Date.now()
3223
const checkpoint_dir_path = get_checkpoint_path(timestamp, extension_context)
3324
const checkpoint_dir_uri = vscode.Uri.file(checkpoint_dir_path)
3425
await vscode.workspace.fs.createDirectory(checkpoint_dir_uri)
3526

36-
const git_data: Record<string, any> = {}
37-
let uses_git = false
38-
39-
await Promise.all(
40-
workspace_folders.map(async (folder, index) => {
41-
const has_git = folder_git_statuses[index]
42-
const folder_key = `${index}-${folder.name}`
43-
44-
if (has_git) {
45-
uses_git = true
46-
const git_info = await get_git_info(folder)
47-
const diff = await get_git_diff(folder)
48-
49-
if (git_info && diff !== null) {
50-
git_data[folder_key] = {
51-
branch: git_info.branch,
52-
commit_hash: git_info.commit_hash,
53-
folder_name: folder_key
54-
}
55-
56-
const diff_file_path = path.join(
57-
checkpoint_dir_path,
58-
`${folder_key}.diff`
59-
)
60-
await vscode.workspace.fs.writeFile(
61-
vscode.Uri.file(diff_file_path),
62-
Buffer.from(diff, 'utf8')
63-
)
64-
} else {
65-
Logger.warn({
66-
function_name: 'create_temporary_checkpoint',
67-
message: `Failed to get git information for repository in ${folder.name}. Falling back to file copy.`
68-
})
69-
const dest_folder_path =
70-
workspace_folders.length > 1
71-
? path.join(checkpoint_dir_path, folder_key)
72-
: checkpoint_dir_path
73-
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
74-
if (workspace_folders.length > 1) {
75-
await vscode.workspace.fs.createDirectory(dest_folder_uri)
76-
}
77-
78-
const entries = await vscode.workspace.fs.readDirectory(folder.uri)
79-
for (const [name] of entries) {
80-
await copy_optimised_recursively(
81-
vscode.Uri.joinPath(folder.uri, name),
82-
vscode.Uri.joinPath(dest_folder_uri, name),
83-
folder.uri.fsPath,
84-
workspace_provider
85-
)
86-
}
87-
}
88-
} else {
89-
const dest_folder_path =
90-
workspace_folders.length > 1
91-
? path.join(checkpoint_dir_path, folder_key)
92-
: checkpoint_dir_path
93-
const dest_folder_uri = vscode.Uri.file(dest_folder_path)
94-
if (workspace_folders.length > 1) {
95-
await vscode.workspace.fs.createDirectory(dest_folder_uri)
96-
}
97-
98-
const entries = await vscode.workspace.fs.readDirectory(folder.uri)
99-
for (const [name] of entries) {
100-
await copy_optimised_recursively(
101-
vscode.Uri.joinPath(folder.uri, name),
102-
vscode.Uri.joinPath(dest_folder_uri, name),
103-
folder.uri.fsPath,
104-
workspace_provider
105-
)
106-
}
107-
}
108-
})
27+
const snapshot_data = await create_workspace_snapshot(
28+
checkpoint_dir_path,
29+
workspace_provider
10930
)
11031

11132
const active_tabs: CheckpointTab[] = []
@@ -126,8 +47,8 @@ export const create_temporary_checkpoint = async (
12647
const new_checkpoint: Checkpoint = {
12748
timestamp,
12849
trigger: 'temporary',
129-
uses_git,
130-
git_data: Object.keys(git_data).length > 0 ? git_data : undefined,
50+
uses_git: snapshot_data.uses_git,
51+
git_data: snapshot_data.git_data,
13152
selected_files: workspace_provider.get_all_selected_paths(),
13253
active_tabs
13354
}

0 commit comments

Comments
 (0)