55 CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
66} from '../../../constants/state-keys'
77import { WorkspaceProvider } from '../../../context/providers/workspace/workspace-provider'
8- import type { Checkpoint , CheckpointTab } from '../types'
8+ import type { Checkpoint , CheckpointTab , CheckpointTrigger } from '../types'
99import { get_checkpoints } from './get-checkpoints'
1010import {
1111 copy_optimised_recursively ,
@@ -24,29 +24,30 @@ import { dictionary } from '@shared/constants/dictionary'
2424import { response_preview_promise_resolve } from '../../apply-chat-response-command/utils/preview'
2525import { remove_old_checkpoints } from './get-checkpoints'
2626
27- export const create_checkpoint = async (
28- workspace_provider : WorkspaceProvider ,
29- context : vscode . ExtensionContext ,
30- panel_provider : PanelProvider ,
31- title : string = 'Created by user' ,
27+ export const create_checkpoint = async ( params : {
28+ workspace_provider : WorkspaceProvider
29+ context : vscode . ExtensionContext
30+ panel_provider : PanelProvider
31+ trigger ?: CheckpointTrigger
3232 description ?: string
33- ) : Promise < Checkpoint | undefined > => {
33+ } ) : Promise < Checkpoint | undefined > => {
3434 try {
35+ const trigger = params . trigger ?? 'manual'
3536 const are_automatic_checkpoints_disabled = vscode . workspace
3637 . getConfiguration ( 'codeWebChat' )
3738 . get < boolean > ( 'areAutomaticCheckpointsDisabled' , false )
38- const is_automatic_checkpoint = title != 'Created by user '
39+ const is_automatic_checkpoint = trigger != 'manual '
3940
4041 if ( are_automatic_checkpoints_disabled && is_automatic_checkpoint ) {
4142 Logger . info ( {
4243 function_name : 'create_checkpoint' ,
4344 message : 'Automatic checkpoint creation is disabled. Skipping.' ,
44- data : { title }
45+ data : { trigger }
4546 } )
4647 return undefined
4748 }
4849
49- const operation_in_progress = context . workspaceState . get < number > (
50+ const operation_in_progress = params . context . workspaceState . get < number > (
5051 CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
5152 )
5253 if (
@@ -59,7 +60,7 @@ export const create_checkpoint = async (
5960 return undefined
6061 }
6162
62- const old_temp_checkpoint = context . workspaceState . get < Checkpoint > (
63+ const old_temp_checkpoint = params . context . workspaceState . get < Checkpoint > (
6364 TEMPORARY_CHECKPOINT_STATE_KEY
6465 )
6566 if ( old_temp_checkpoint ) {
@@ -77,7 +78,7 @@ export const create_checkpoint = async (
7778 data : error
7879 } )
7980 }
80- await context . workspaceState . update (
81+ await params . context . workspaceState . update (
8182 TEMPORARY_CHECKPOINT_STATE_KEY ,
8283 undefined
8384 )
@@ -91,7 +92,7 @@ export const create_checkpoint = async (
9192 let new_checkpoint : Checkpoint | undefined
9293
9394 const create_checkpoint_task = async ( ) => {
94- await context . workspaceState . update (
95+ await params . context . workspaceState . update (
9596 CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY ,
9697 Date . now ( )
9798 )
@@ -147,7 +148,7 @@ export const create_checkpoint = async (
147148 vscode . Uri . joinPath ( folder . uri , name ) ,
148149 vscode . Uri . joinPath ( dest_folder_uri , name ) ,
149150 folder . uri . fsPath ,
150- workspace_provider
151+ params . workspace_provider
151152 )
152153 }
153154 }
@@ -167,20 +168,20 @@ export const create_checkpoint = async (
167168 vscode . Uri . joinPath ( folder . uri , name ) ,
168169 vscode . Uri . joinPath ( dest_folder_uri , name ) ,
169170 folder . uri . fsPath ,
170- workspace_provider
171+ params . workspace_provider
171172 )
172173 }
173174 }
174175 }
175176
176- let checkpoints = await get_checkpoints ( context )
177+ let checkpoints = await get_checkpoints ( params . context )
177178
178179 // Remove checkpoints older than 48 hours
179180 checkpoints = await remove_old_checkpoints ( checkpoints )
180181
181182 const final_description = get_incremented_description (
182- title ,
183- description ,
183+ trigger ,
184+ params . description ,
184185 checkpoints
185186 )
186187
@@ -200,25 +201,28 @@ export const create_checkpoint = async (
200201 }
201202
202203 const checkpoint_object : Checkpoint = {
203- title ,
204+ trigger ,
204205 timestamp,
205206 description : final_description ,
206207 uses_git,
207208 git_data : Object . keys ( git_data ) . length > 0 ? git_data : undefined ,
208- checked_files : workspace_provider . get_all_checked_paths ( ) ,
209+ checked_files : params . workspace_provider . get_all_checked_paths ( ) ,
209210 active_tabs
210211 }
211212
212- if ( title == 'Created by user ' && ! response_preview_promise_resolve ) {
213+ if ( trigger == 'manual ' && ! response_preview_promise_resolve ) {
213214 checkpoint_object . response_history = [
214- ...panel_provider . response_history
215+ ...params . panel_provider . response_history
215216 ]
216217 }
217218
218219 checkpoints . unshift ( checkpoint_object )
219- await context . workspaceState . update ( CHECKPOINTS_STATE_KEY , checkpoints )
220- await panel_provider . send_checkpoints ( )
221- await context . workspaceState . update (
220+ await params . context . workspaceState . update (
221+ CHECKPOINTS_STATE_KEY ,
222+ checkpoints
223+ )
224+ await params . panel_provider . send_checkpoints ( )
225+ await params . context . workspaceState . update (
222226 CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY ,
223227 undefined
224228 )
@@ -231,7 +235,7 @@ export const create_checkpoint = async (
231235 try {
232236 timer = setTimeout ( ( ) => {
233237 did_show_modal = true
234- panel_provider . send_message ( {
238+ params . panel_provider . send_message ( {
235239 command : 'SHOW_PROGRESS' ,
236240 title : 'Creating checkpoint...'
237241 } )
@@ -241,7 +245,7 @@ export const create_checkpoint = async (
241245 } finally {
242246 if ( timer ) clearTimeout ( timer )
243247 if ( did_show_modal ) {
244- panel_provider . send_message ( {
248+ params . panel_provider . send_message ( {
245249 command : 'HIDE_PROGRESS'
246250 } )
247251 }
@@ -251,7 +255,7 @@ export const create_checkpoint = async (
251255 vscode . window . showErrorMessage (
252256 `Failed to create checkpoint: ${ err . message } `
253257 )
254- await context . workspaceState . update (
258+ await params . context . workspaceState . update (
255259 CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY ,
256260 undefined
257261 )
0 commit comments