@@ -123,171 +123,161 @@ export const handle_fix_all_failed_files = async (
123123 } )
124124 . filter ( ( item ) => item . instructions && item . safe_path )
125125
126- const max_concurrency =
127- files_to_process . length > 0 ? files_to_process . length : 1
128-
129- // Process in batches
130- for ( let i = 0 ; i < files_to_process . length ; i += max_concurrency ) {
131- const batch = files_to_process . slice ( i , i + max_concurrency )
132- await Promise . all (
133- batch . map ( async ( { file_state, instructions, safe_path } ) => {
134- if ( ! safe_path ) return
126+ await Promise . all (
127+ files_to_process . map ( async ( { file_state, instructions, safe_path } ) => {
128+ if ( ! safe_path ) return
129+
130+ const file_path = file_state . file_path
131+ const workspace_name = file_state . workspace_name
132+
133+ const cancel_token_source = axios . CancelToken . source ( )
134+ panel_provider . intelligent_update_cancel_token_sources . push ( {
135+ source : cancel_token_source ,
136+ file_path,
137+ workspace_name
138+ } )
135139
136- const file_path = file_state . file_path
137- const workspace_name = file_state . workspace_name
140+ panel_provider . send_message ( {
141+ command : 'UPDATE_FILE_PROGRESS' ,
142+ file_path,
143+ workspace_name,
144+ is_applying : true ,
145+ apply_status : 'waiting'
146+ } )
138147
139- const cancel_token_source = axios . CancelToken . source ( )
140- panel_provider . intelligent_update_cancel_token_sources . push ( {
141- source : cancel_token_source ,
148+ const on_thinking_chunk = ( ) => {
149+ panel_provider . send_message ( {
150+ command : 'UPDATE_FILE_PROGRESS' ,
142151 file_path,
143- workspace_name
152+ workspace_name,
153+ is_applying : true ,
154+ apply_status : 'thinking'
144155 } )
156+ }
157+
158+ const original_file_size = file_state . content . length
159+ const estimated_total_tokens = Math . ceil ( original_file_size / 4 )
160+
161+ const on_chunk = ( tokens_per_second : number , total_tokens : number ) => {
162+ let progress = 0
163+ if ( estimated_total_tokens > 0 ) {
164+ progress = Math . min (
165+ Math . round ( ( total_tokens / estimated_total_tokens ) * 100 ) ,
166+ 100
167+ )
168+ }
145169
146170 panel_provider . send_message ( {
147171 command : 'UPDATE_FILE_PROGRESS' ,
148172 file_path,
149173 workspace_name,
150174 is_applying : true ,
151- apply_status : 'waiting'
175+ apply_status : 'receiving' ,
176+ apply_progress : progress ,
177+ apply_tokens_per_second : tokens_per_second
152178 } )
179+ }
153180
154- const on_thinking_chunk = ( ) => {
155- panel_provider . send_message ( {
156- command : 'UPDATE_FILE_PROGRESS' ,
157- file_path,
158- workspace_name,
159- is_applying : true ,
160- apply_status : 'thinking'
161- } )
162- }
163-
164- const original_file_size = file_state . content . length
165- const estimated_total_tokens = Math . ceil ( original_file_size / 4 )
181+ const on_retry_attempt = ( ) => {
182+ panel_provider . send_message ( {
183+ command : 'UPDATE_FILE_PROGRESS' ,
184+ file_path,
185+ workspace_name,
186+ is_applying : true ,
187+ apply_status : 'thinking'
188+ } )
189+ }
166190
167- const on_chunk = ( tokens_per_second : number , total_tokens : number ) => {
168- let progress = 0
169- if ( estimated_total_tokens > 0 ) {
170- progress = Math . min (
171- Math . round ( ( total_tokens / estimated_total_tokens ) * 100 ) ,
172- 100
173- )
174- }
191+ const on_retry = ( ) => {
192+ panel_provider . send_message ( {
193+ command : 'UPDATE_FILE_PROGRESS' ,
194+ file_path,
195+ workspace_name,
196+ is_applying : true ,
197+ apply_status : 'retrying'
198+ } )
199+ }
175200
176- panel_provider . send_message ( {
177- command : 'UPDATE_FILE_PROGRESS' ,
178- file_path,
179- workspace_name,
180- is_applying : true ,
181- apply_status : 'receiving' ,
182- apply_progress : progress ,
183- apply_tokens_per_second : tokens_per_second
184- } )
185- }
201+ try {
202+ const updated_content = await process_file ( {
203+ endpoint_url : endpoint_url ,
204+ api_key : api_provider . api_key ,
205+ provider : api_provider ,
206+ model : intelligent_update_config . model ,
207+ temperature : intelligent_update_config . temperature ,
208+ reasoning_effort : intelligent_update_config . reasoning_effort ,
209+ file_path : file_path ,
210+ file_content : file_state . content ,
211+ instruction : instructions ,
212+ cancel_token : cancel_token_source . token ,
213+ on_chunk,
214+ on_thinking_chunk,
215+ on_retry_attempt,
216+ on_retry
217+ } )
186218
187- const on_retry_attempt = ( ) => {
219+ if ( updated_content ) {
188220 panel_provider . send_message ( {
189221 command : 'UPDATE_FILE_PROGRESS' ,
190222 file_path,
191223 workspace_name,
192224 is_applying : true ,
193- apply_status : 'thinking'
225+ apply_status : 'done' ,
226+ apply_progress : 100
194227 } )
195- }
196228
197- const on_retry = ( ) => {
198- panel_provider . send_message ( {
199- command : 'UPDATE_FILE_PROGRESS' ,
200- file_path,
201- workspace_name,
202- is_applying : true ,
203- apply_status : 'retrying'
204- } )
205- }
229+ const original_ends_with_newline = file_state . content . endsWith ( '\n' )
230+ const updated_ends_with_newline = updated_content . endsWith ( '\n' )
206231
207- try {
208- const updated_content = await process_file ( {
209- endpoint_url : endpoint_url ,
210- api_key : api_provider . api_key ,
211- provider : api_provider ,
212- model : intelligent_update_config . model ,
213- temperature : intelligent_update_config . temperature ,
214- reasoning_effort : intelligent_update_config . reasoning_effort ,
215- file_path : file_path ,
216- file_content : file_state . content ,
217- instruction : instructions ,
218- cancel_token : cancel_token_source . token ,
219- on_chunk,
220- on_thinking_chunk,
221- on_retry_attempt,
222- on_retry
223- } )
232+ let final_content = updated_content
233+ if ( original_ends_with_newline && ! updated_ends_with_newline ) {
234+ final_content = updated_content + '\n'
235+ } else if ( ! original_ends_with_newline && updated_ends_with_newline ) {
236+ final_content = updated_content . slice ( 0 , - 1 )
237+ }
224238
225- if ( updated_content ) {
226- panel_provider . send_message ( {
227- command : 'UPDATE_FILE_PROGRESS' ,
239+ if ( set_file_applied_with_intelligent_update ) {
240+ set_file_applied_with_intelligent_update ( {
228241 file_path,
229- workspace_name,
230- is_applying : true ,
231- apply_status : 'done' ,
232- apply_progress : 100
233- } )
234-
235- const original_ends_with_newline = file_state . content . endsWith ( '\n' )
236- const updated_ends_with_newline = updated_content . endsWith ( '\n' )
237-
238- let final_content = updated_content
239- if ( original_ends_with_newline && ! updated_ends_with_newline ) {
240- final_content = updated_content + '\n'
241- } else if (
242- ! original_ends_with_newline &&
243- updated_ends_with_newline
244- ) {
245- final_content = updated_content . slice ( 0 , - 1 )
246- }
247-
248- if ( set_file_applied_with_intelligent_update ) {
249- set_file_applied_with_intelligent_update ( {
250- file_path,
251- workspace_name
252- } )
253- }
254-
255- await vscode . workspace . fs . writeFile (
256- vscode . Uri . file ( safe_path ) ,
257- Buffer . from ( final_content , 'utf8' )
258- )
259- }
260- } catch ( error : any ) {
261- if (
262- ! axios . isCancel ( error ) &&
263- error . message != 'User cancelled the operation'
264- ) {
265- Logger . error ( {
266- function_name : 'handle_fix_all_failed_files' ,
267- message : 'Error during process_file' ,
268- data : { error, file_path }
242+ workspace_name
269243 } )
270244 }
271- } finally {
272- panel_provider . send_message ( {
273- command : 'UPDATE_FILE_PROGRESS' ,
274- file_path,
275- workspace_name,
276- is_applying : false
245+
246+ await vscode . workspace . fs . writeFile (
247+ vscode . Uri . file ( safe_path ) ,
248+ Buffer . from ( final_content , 'utf8' )
249+ )
250+ }
251+ } catch ( error : any ) {
252+ if (
253+ ! axios . isCancel ( error ) &&
254+ error . message != 'User cancelled the operation'
255+ ) {
256+ Logger . error ( {
257+ function_name : 'handle_fix_all_failed_files' ,
258+ message : 'Error during process_file' ,
259+ data : { error, file_path }
277260 } )
261+ }
262+ } finally {
263+ panel_provider . send_message ( {
264+ command : 'UPDATE_FILE_PROGRESS' ,
265+ file_path,
266+ workspace_name,
267+ is_applying : false
268+ } )
278269
279- const index =
280- panel_provider . intelligent_update_cancel_token_sources . findIndex (
281- ( s ) => s . source === cancel_token_source
282- )
283- if ( index > - 1 ) {
284- panel_provider . intelligent_update_cancel_token_sources . splice (
285- index ,
286- 1
287- )
288- }
270+ const index =
271+ panel_provider . intelligent_update_cancel_token_sources . findIndex (
272+ ( s ) => s . source === cancel_token_source
273+ )
274+ if ( index > - 1 ) {
275+ panel_provider . intelligent_update_cancel_token_sources . splice (
276+ index ,
277+ 1
278+ )
289279 }
290- } )
291- )
292- }
280+ }
281+ } )
282+ )
293283}
0 commit comments