@@ -7,11 +7,10 @@ import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provi
77import { Logger } from '@shared/utils/logger'
88import { dictionary } from '@shared/constants/dictionary'
99
10- const build_changes_markdown = (
10+ const build_changes_xml = (
1111 diff : string ,
1212 cwd : string ,
13- diff_base : string ,
14- branch_name : string
13+ diff_base : string
1514) : string => {
1615 // Split diff into per-file sections. Each section starts with 'diff --git '.
1716 const file_diffs = diff . split ( / ^ d i f f - - g i t / m) . filter ( ( d ) => d . trim ( ) != '' )
@@ -47,7 +46,7 @@ const build_changes_markdown = (
4746 }
4847
4948 if ( file_path ) {
50- changes_content += `\n\n### File: \` ${ file_path } \`\n \n`
49+ changes_content += `<file path=" ${ file_path } "> \n`
5150
5251 let file_content = ''
5352 try {
@@ -62,24 +61,21 @@ const build_changes_markdown = (
6261 // In this case, the original content is correctly an empty string.
6362 if ( ! is_deleted ) {
6463 Logger . warn ( {
65- function_name : 'build_changes_markdown ' ,
64+ function_name : 'build_changes_xml ' ,
6665 message : `Could not get file content from git base ${ diff_base } for path ${ file_path } . Assuming it's a new file.` ,
6766 data : e
6867 } )
6968 }
7069 }
7170 if ( file_content ) {
72- const lang = path . extname ( file_path ) . slice ( 1 )
73- changes_content += `The original state of the file for reference:\n\n\`\`\`${ lang } \n${ file_content } \n\`\`\`\n\n`
71+ changes_content += `<archive>\n<![CDATA[\n${ file_content } \n]]>\n</archive>\n`
7472 }
75- changes_content += `**New changes:**\n\n\`\`\`diff\n${ full_file_diff } \`\`\`\n`
73+ changes_content += `<changes>\n<![CDATA[\n${ full_file_diff } \n]]>\n</changes>\n`
74+ changes_content += `</file>\n`
7675 }
7776 }
7877
79- if ( changes_content ) {
80- return `\n\n# Changes against ${ branch_name } branch${ changes_content } \n---\n\n`
81- }
82- return ''
78+ return changes_content
8379}
8480
8581export const replace_changes_symbol = async ( params : {
@@ -159,11 +155,10 @@ export const replace_changes_symbol = async (params: {
159155 )
160156 }
161157
162- const replacement_text = build_changes_markdown (
158+ const replacement_text = build_changes_xml (
163159 diff ,
164160 target_folder . uri . fsPath ,
165- diff_base ,
166- branch_name
161+ diff_base
167162 )
168163 return params . instruction . replace (
169164 new RegExp ( `\\s*#Changes:${ branch_spec } \\s*` , 'g' ) ,
@@ -234,11 +229,10 @@ export const replace_changes_symbol = async (params: {
234229 )
235230 }
236231
237- const replacement_text = build_changes_markdown (
232+ const replacement_text = build_changes_xml (
238233 diff ,
239234 repository . rootUri . fsPath ,
240- diff_base ,
241- branch_name
235+ diff_base
242236 )
243237 return params . instruction . replace (
244238 new RegExp ( `\\s*#Changes:${ branch_name } \\s*` , 'g' ) ,
@@ -261,7 +255,7 @@ export const replace_changes_symbol = async (params: {
261255 }
262256}
263257
264- const build_commit_changes_markdown = (
258+ const build_commit_changes_xml = (
265259 diff : string ,
266260 cwd : string ,
267261 commit_hash : string ,
@@ -310,27 +304,25 @@ const build_commit_changes_markdown = (
310304 } )
311305 } catch ( e ) {
312306 Logger . error ( {
313- function_name : 'build_commit_changes_markdown ' ,
307+ function_name : 'build_commit_changes_xml ' ,
314308 message : `Could not read file for diff from commit: ${ file_path } ` ,
315309 data : e
316310 } )
317311 }
318312 }
319313
320- changes_content += `### File: \` ${ file_path } \`\n \n`
321- changes_content += `**Changes:**\n\n\`\`\`diff\n ${ full_file_diff } \`\`\` \n`
314+ changes_content += `<file path=" ${ file_path } "> \n`
315+ changes_content += `<![CDATA[\n ${ full_file_diff } \n]]> \n`
322316 if ( file_content ) {
323- const lang = path . extname ( file_path ) . slice ( 1 )
324- changes_content += `\nFull file for reference:\n\n\`\`\`${ lang } \n${ file_content } \n\`\`\`\n`
317+ changes_content += `<![CDATA[\n${ file_content } \n]]>\n`
325318 }
319+ changes_content += `</file>\n`
326320 }
327321 }
328322
329323 if ( changes_content ) {
330- const message_section = commit_message
331- ? `**Message:** ${ commit_message } \n\n`
332- : ''
333- return `\n\n# Commit\n\n${ message_section } ${ changes_content } \n---\n\n`
324+ const safe_message = ( commit_message || '' ) . replace ( / " / g, '"' )
325+ return `<commit message="${ safe_message } ">\n${ changes_content } </commit>\n`
334326 }
335327 return ''
336328}
@@ -379,7 +371,7 @@ export const replace_commit_symbol = async (params: {
379371 continue
380372 }
381373
382- const replacement_text = build_commit_changes_markdown (
374+ const replacement_text = build_commit_changes_xml (
383375 diff ,
384376 target_folder . uri . fsPath ,
385377 commit_hash ,
0 commit comments