Skip to content

Commit d1d57b6

Browse files
committed
Remove context validation check and convert git symbol replacements to XML format
1 parent 3f09c4d commit d1d57b6

3 files changed

Lines changed: 21 additions & 42 deletions

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ export const dictionary = {
127127
NO_EDITOR_OPEN: 'No editor is open.',
128128
CANNOT_COPY_PROMPT_IN_CODE_COMPLETION_WITH_SELECTION:
129129
'Cannot copy prompt in code completion mode with an active selection.',
130-
CANNOT_COPY_PROMPT_IN_EDIT_CONTEXT_WITHOUT_CONTEXT:
131-
'Cannot copy prompt in the edit context mode without any files in context.',
132130
CANNOT_COPY_PROMPT_IN_CODE_COMPLETION_WITHOUT_EDITOR:
133131
'Cannot copy prompt in code completion mode without an active editor.',
134132
CONTEXT_CANNOT_BE_EMPTY: 'Context cannot be empty.',

‎packages/vscode/src/views/panel/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,6 @@ export const handle_copy_prompt = async (params: {
9595
no_context: params.panel_provider.web_prompt_type == 'no-context'
9696
})
9797

98-
if (
99-
params.panel_provider.web_prompt_type == 'edit-context' &&
100-
!context_text
101-
) {
102-
vscode.window.showWarningMessage(
103-
dictionary.warning_message
104-
.CANNOT_COPY_PROMPT_IN_EDIT_CONTEXT_WITHOUT_CONTEXT
105-
)
106-
return
107-
}
108-
10998
const instructions = replace_selection_placeholder(final_instruction)
11099

111100
let processed_instructions = instructions

‎packages/vscode/src/views/panel/backend/utils/replace-git-symbols.ts‎

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provi
77
import { Logger } from '@shared/utils/logger'
88
import { 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(/^diff --git /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

8581
export 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, '&quot;')
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

Comments
 (0)