@@ -18,8 +18,10 @@ import {
1818import { process_chat_response , CommandArgs } from './response-processor'
1919import { Checkpoint } from '../checkpoints-command/types'
2020import { CHECKPOINTS_STATE_KEY } from '@/constants/state-keys'
21+ import { ResponseHistoryItem } from '@shared/types/response-history-item'
2122
2223let in_progress = false
24+ let placeholder_created_at_for_update : number | undefined
2325
2426export const apply_chat_response_command = (
2527 context : vscode . ExtensionContext ,
@@ -52,28 +54,33 @@ export const apply_chat_response_command = (
5254 return
5355 }
5456
55- if ( in_progress ) {
56- panel_provider . send_message ( {
57- command : 'NEW_RESPONSE_RECEIVED' ,
58- response : chat_response ,
59- raw_instructions : args ?. raw_instructions
60- } )
61- }
62-
6357 if ( in_progress && ! response_preview_promise_resolve ) {
6458 // Running intelligent update before response preview...
6559 return
6660 }
67- in_progress = true
6861
6962 if ( response_preview_promise_resolve ) {
7063 // Previewing response...
64+ const history = panel_provider . response_history
65+
66+ const new_item : ResponseHistoryItem = {
67+ response : chat_response ,
68+ raw_instructions : args ?. raw_instructions ,
69+ created_at : Date . now ( )
70+ }
71+
72+ history . push ( new_item )
73+ panel_provider . send_message ( {
74+ command : 'RESPONSE_HISTORY' ,
75+ history
76+ } )
7177 const choice = await vscode . window . showInformationMessage (
7278 dictionary . warning_message . PREVIEW_ONGOING ,
7379 'Switch'
7480 )
7581
7682 if ( choice == 'Switch' ) {
83+ placeholder_created_at_for_update = new_item . created_at
7784 response_preview_promise_resolve ( { accepted_files : [ ] } )
7885 if ( ongoing_review_cleanup_promise ) {
7986 await ongoing_review_cleanup_promise
@@ -84,6 +91,7 @@ export const apply_chat_response_command = (
8491 }
8592 }
8693
94+ in_progress = true
8795 let before_checkpoint : Checkpoint | undefined
8896 try {
8997 before_checkpoint = await create_checkpoint (
@@ -104,6 +112,7 @@ export const apply_chat_response_command = (
104112 )
105113
106114 if ( review_data ) {
115+ let created_at_for_preview = args ?. created_at
107116 if ( ! args ?. files_with_content ) {
108117 let total_lines_added = 0
109118 let total_lines_removed = 0
@@ -168,24 +177,58 @@ export const apply_chat_response_command = (
168177 is_checked : true
169178 } )
170179 }
180+ const history = panel_provider . response_history
181+
182+ if ( placeholder_created_at_for_update ) {
183+ const item_to_update = history . find (
184+ ( i ) => i . created_at === placeholder_created_at_for_update
185+ )
186+ if ( item_to_update ) {
187+ item_to_update . files = files_for_history
188+ item_to_update . lines_added = total_lines_added
189+ item_to_update . lines_removed = total_lines_removed
190+ }
191+ created_at_for_preview = placeholder_created_at_for_update
192+ placeholder_created_at_for_update = undefined
193+ } else {
194+ const item_to_update =
195+ args ?. created_at &&
196+ history . find ( ( i ) => i . created_at === args . created_at )
197+
198+ if ( item_to_update ) {
199+ item_to_update . files = files_for_history
200+ item_to_update . lines_added = total_lines_added
201+ item_to_update . lines_removed = total_lines_removed
202+ } else {
203+ created_at_for_preview = Date . now ( )
204+ const new_item : ResponseHistoryItem = {
205+ response : review_data . chat_response ,
206+ raw_instructions : args ?. raw_instructions ,
207+ created_at : created_at_for_preview ,
208+ lines_added : total_lines_added ,
209+ lines_removed : total_lines_removed ,
210+ files : files_for_history
211+ }
212+
213+ history . push ( new_item )
214+ }
215+ }
171216
172217 panel_provider . send_message ( {
173- command : 'NEW_RESPONSE_RECEIVED' ,
174- response : review_data . chat_response ,
175- raw_instructions : args ?. raw_instructions ,
176- lines_added : total_lines_added ,
177- lines_removed : total_lines_removed ,
178- files : files_for_history
218+ command : 'RESPONSE_HISTORY' ,
219+ history
179220 } )
180221 }
181222
223+ const history_for_checkpoint = [ ...panel_provider . response_history ]
182224 const changes_accepted = await preview_handler ( {
183225 original_states : review_data . original_states ,
184226 chat_response : review_data . chat_response ,
185227 panel_provider,
186228 context,
187229 original_editor_state : args ?. original_editor_state ,
188- raw_instructions : args ?. raw_instructions
230+ raw_instructions : args ?. raw_instructions ,
231+ created_at : created_at_for_preview
189232 } )
190233
191234 if ( changes_accepted ) {
@@ -200,6 +243,9 @@ export const apply_chat_response_command = (
200243 )
201244 if ( checkpoint_to_update ) {
202245 checkpoint_to_update . title = 'Before changes approved'
246+ checkpoint_to_update . response_history = history_for_checkpoint
247+ checkpoint_to_update . response_preview_item_created_at =
248+ created_at_for_preview
203249 await context . workspaceState . update (
204250 CHECKPOINTS_STATE_KEY ,
205251 checkpoints
0 commit comments