Skip to content

Commit a409dd2

Browse files
committed
Replace XML-style formatting with Markdown in commit message prompts
- because markdown is preferred over XML, you should change how you attach files when getting a commit message - in commit message generation, it's not necessary to include "# Files" heading
1 parent 3af20c0 commit a409dd2

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎apps/editor/src/features/commit-messages/utils/build-commit-message-prompt.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const build_commit_message_prompt = async (
1313

1414
const file_diffs = diff.split(/^diff --git /m).filter((d) => d.trim() != '')
1515

16-
let changes_content = '<files>\n'
16+
let changes_content = ''
1717
for (const file_diff_content of file_diffs) {
1818
const full_file_diff = 'diff --git ' + file_diff_content
1919
const lines = full_file_diff.split('\n')
@@ -91,12 +91,19 @@ export const build_commit_message_prompt = async (
9191
}
9292
}
9393

94-
changes_content += `<file path="${file_path}" status="${status}"`
95-
if (old_path_attr) {
96-
changes_content += ` old_path="${old_path_attr}"`
94+
if (status == 'created') {
95+
changes_content += `### New file: \`${file_path}\`\n\n`
96+
} else if (status == 'deleted') {
97+
changes_content += `### Deleted file: \`${file_path}\`\n\n`
98+
} else if (status == 'renamed') {
99+
changes_content += `### Renamed file: \`${old_path_attr}\` (old) \`${file_path}\` (new)\n\n`
100+
} else {
101+
changes_content += `### Updated file: \`${file_path}\`\n\n`
102+
}
103+
104+
if (final_diff_content.trimEnd()) {
105+
changes_content += `\`\`\`diff\n${final_diff_content.trimEnd()}\n\`\`\`\n\n`
97106
}
98-
changes_content += '>\n'
99-
changes_content += `<![CDATA[\n${final_diff_content.trimEnd()}\n]]>\n`
100107

101108
if (!is_deleted && file_path && !is_binary) {
102109
try {
@@ -113,17 +120,13 @@ export const build_commit_message_prompt = async (
113120
if (full_content && !full_content.includes('\0')) {
114121
const full_content_tokens = Math.ceil(full_content.length / 4)
115122
if (full_content_tokens <= MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE) {
116-
changes_content += `<![CDATA[\n${full_content.trimEnd()}\n]]>\n`
123+
changes_content += `\`\`\`\n${full_content.trimEnd()}\n\`\`\`\n\n`
117124
}
118125
}
119126
} catch (err) {}
120127
}
121-
122-
changes_content += `</file>\n`
123128
}
124129
}
125130

126-
changes_content += '</files>'
127-
128-
return `${commit_message_prompt}\n${changes_content}\n${commit_message_prompt}`
131+
return `${commit_message_prompt}\n\n${changes_content}${commit_message_prompt}`
129132
}

‎apps/editor/src/utils/git-repository-utils.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,23 @@ export const prepare_staged_changes = async (params: {
239239
)
240240
const is_too_large = file_tokens > MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE
241241

242-
let file_xml = `<file path="${relative_path}" status="${status}">\n`
243-
file_xml += `<![CDATA[\n${final_diff_content.trimEnd()}\n]]>\n`
242+
let file_md = ''
243+
if (status == 'created') {
244+
file_md = `### New file: \`${relative_path}\`\n\n`
245+
} else if (status == 'deleted') {
246+
file_md = `### Deleted file: \`${relative_path}\`\n\n`
247+
} else {
248+
file_md = `### Updated file: \`${relative_path}\`\n\n`
249+
}
250+
251+
if (final_diff_content.trimEnd()) {
252+
file_md += `\`\`\`diff\n${final_diff_content.trimEnd()}\n\`\`\`\n\n`
253+
}
244254
if (!is_deleted && full_content && !is_too_large) {
245-
file_xml += `<![CDATA[\n${full_content.trimEnd()}\n]]>\n`
255+
file_md += `\`\`\`\n${full_content.trimEnd()}\n\`\`\`\n\n`
246256
}
247-
file_xml += `</file>\n`
248257

249-
const token_count = Math.ceil(file_xml.length / 4)
258+
const token_count = Math.ceil(file_md.length / 4)
250259
const description_parts = []
251260

252261
if (!is_too_large) {

0 commit comments

Comments
 (0)