@@ -497,30 +497,33 @@ const convert_code_block_to_new_file_diff = (params: {
497497 }
498498}
499499
500- const process_text_for_deleted_files = ( params : {
500+ const process_text_for_file_operations = ( params : {
501501 lines : string [ ]
502502 is_single_root : boolean
503503} ) : DiffOrTextBlock [ ] => {
504504 const items : DiffOrTextBlock [ ] = [ ]
505505 let current_text_lines : string [ ] = [ ]
506506
507507 const deleted_file_header_regex = / ^ # # # \s + D e l e t e d f i l e : \s * ` ( [ ^ ` ] + ) ` /
508+ const renamed_file_header_regex =
509+ / ^ # # # \s + R e n a m e d f i l e : \s * ` ( [ ^ ` ] + ) ` \s * \( o l d \) \s * ` ( [ ^ ` ] + ) ` \s * \( n e w \) /
508510
509511 for ( const line of params . lines ) {
510512 const trimmed_line = line . trim ( )
511513 if ( trimmed_line === '<files>' || trimmed_line === '</files>' ) {
512514 continue
513515 }
514- const match = trimmed_line . match ( deleted_file_header_regex )
516+ const deleted_match = trimmed_line . match ( deleted_file_header_regex )
517+ const renamed_match = trimmed_line . match ( renamed_file_header_regex )
515518
516- if ( match && match [ 1 ] ) {
519+ if ( deleted_match && deleted_match [ 1 ] ) {
517520 const text_content = current_text_lines . join ( '\n' ) . trim ( )
518521 if ( text_content ) {
519522 items . push ( { type : 'text' , content : text_content } )
520523 }
521524 current_text_lines = [ ]
522525
523- const raw_file_path = normalize_path ( match [ 1 ] )
526+ const raw_file_path = normalize_path ( deleted_match [ 1 ] )
524527 const { workspace_name, relative_path } = extract_workspace_and_path ( {
525528 raw_file_path,
526529 is_single_root_folder_workspace : params . is_single_root
@@ -532,6 +535,41 @@ const process_text_for_deleted_files = (params: {
532535 workspace_name,
533536 content
534537 } )
538+ } else if ( renamed_match && renamed_match [ 1 ] && renamed_match [ 2 ] ) {
539+ const text_content = current_text_lines . join ( '\n' ) . trim ( )
540+ if ( text_content ) {
541+ items . push ( { type : 'text' , content : text_content } )
542+ }
543+ current_text_lines = [ ]
544+
545+ const raw_old_path = normalize_path ( renamed_match [ 1 ] )
546+ const raw_new_path = normalize_path ( renamed_match [ 2 ] )
547+
548+ const old_info = extract_workspace_and_path ( {
549+ raw_file_path : raw_old_path ,
550+ is_single_root_folder_workspace : params . is_single_root
551+ } )
552+ const new_info = extract_workspace_and_path ( {
553+ raw_file_path : raw_new_path ,
554+ is_single_root_folder_workspace : params . is_single_root
555+ } )
556+
557+ const content = `--- a/${ old_info . relative_path } \n+++ b/${ old_info . relative_path } \n`
558+
559+ const patch : Diff = {
560+ type : 'diff' ,
561+ file_path : old_info . relative_path ,
562+ workspace_name : old_info . workspace_name ,
563+ new_file_path : new_info . relative_path ,
564+ content
565+ }
566+ if (
567+ new_info . workspace_name &&
568+ new_info . workspace_name !== old_info . workspace_name
569+ ) {
570+ patch . workspace_name = new_info . workspace_name
571+ }
572+ items . push ( patch )
535573 } else {
536574 current_text_lines . push ( line )
537575 }
@@ -709,7 +747,7 @@ const extract_all_code_block_patches = (params: {
709747
710748 if ( block . type == 'diff' || block . type == 'patch' ) {
711749 const text_before_lines = lines . slice ( last_block_end + 1 , block . start )
712- const preceding_items = process_text_for_deleted_files ( {
750+ const preceding_items = process_text_for_file_operations ( {
713751 lines : text_before_lines ,
714752 is_single_root : params . is_single_root
715753 } )
@@ -747,7 +785,7 @@ const extract_all_code_block_patches = (params: {
747785 block . start
748786 )
749787 items . push (
750- ...process_text_for_deleted_files ( {
788+ ...process_text_for_file_operations ( {
751789 lines : text_before_lines ,
752790 is_single_root : params . is_single_root
753791 } )
@@ -774,7 +812,7 @@ const extract_all_code_block_patches = (params: {
774812 if ( patch ) {
775813 const text_before_lines = lines . slice ( last_block_end + 1 , block . start )
776814 items . push (
777- ...process_text_for_deleted_files ( {
815+ ...process_text_for_file_operations ( {
778816 lines : text_before_lines ,
779817 is_single_root : params . is_single_root
780818 } )
@@ -805,7 +843,7 @@ const extract_all_code_block_patches = (params: {
805843 if ( last_block_end < lines . length - 1 ) {
806844 const remaining_lines = lines . slice ( last_block_end + 1 )
807845 items . push (
808- ...process_text_for_deleted_files ( {
846+ ...process_text_for_file_operations ( {
809847 lines : remaining_lines ,
810848 is_single_root : params . is_single_root
811849 } )
0 commit comments