Skip to content

Commit a24da59

Browse files
committed
Switch intelligent update edit format from search-replace blocks to unified diff patches
- should use diffs not search/replace as the first try in the intelligent update └── apps └── editor └── src ├── commands │ └── apply-response-command │ └── handlers │ ├── diff-handler.ts │ ├── fast-replace-handler.ts │ ├── restore-preview-handler.ts │ ├── search-replace-handler.ts │ └── truncated-handler.ts ├── constants │ └── instructions.ts └── views └── prompt └── backend └── message-handlers ├── handle-fix-all-failed-files.ts ├── handle-intelligent-update-file-in-preview.ts └── utils └── intelligent-update-utils.ts
1 parent 5296ee8 commit a24da59

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎apps/editor/src/constants/instructions.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@ Find correct replacement text for the <missing_text> symbol.`
2828
export const intelligent_update_task_instructions =
2929
'Formatting issues in the attached changes prevent us from applying them. Please edit the file correctly without adding explanations or extra text.'
3030

31-
export const intelligent_update_edit_format_instructions = `Respond strictly with a single markdown code block showing the original and updated code snippets with Git-style merge conflict syntax. Example:
32-
33-
\`\`\`python
34-
<<<<<<< SEARCH
35-
GREETING = "Welcome everyone!"
36-
=======
37-
WISHES = "Have a nice day!"
38-
>>>>>>> REPLACE
39-
<<<<<<< SEARCH
40-
def show_greeting():
41-
print(GREETING)
42-
=======
43-
def show_wishes():
44-
print(WISHES)
45-
>>>>>>> REPLACE
31+
export const intelligent_update_edit_format_instructions = `Respond strictly with a single markdown code block containing a standard unified diff patch. Example:
32+
33+
\`\`\`diff
34+
--- a/example.py
35+
+++ b/example.py
36+
@@ -1,5 +1,5 @@
37+
-GREETING = "Welcome everyone!"
38+
+WISHES = "Have a nice day!"
39+
40+
-def show_greeting():
41+
- print(GREETING)
42+
+def show_wishes():
43+
+ print(WISHES)
4644
\`\`\``
4745

4846
export const intelligent_update_fallback_edit_format_instructions = `Print the updated file in FULL (from cover to cover).`

‎apps/editor/src/views/prompt/backend/message-handlers/utils/intelligent-update-utils.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import {
2020
show_configuration_quick_pick,
2121
map_api_configuration_to_item
2222
} from '@/utils/show-configuration-quick-pick'
23-
import { apply_search_replace_to_content } from '@/utils/changes-integration/search-replace-processor/apply-search-replace-to-content'
24-
import { parse_search_replace_segments } from '@/utils/changes-integration/search-replace-processor/parse-search-replace-segments'
23+
import { apply_diff } from '@/utils/changes-integration/diff-processor'
2524

2625
export const get_intelligent_update_config = async (
2726
model_providers_manager: ModelProvidersManager,
@@ -185,15 +184,20 @@ export const process_file = async (params: {
185184
let final_content = cleaned_content
186185
if (!params.use_fallback_edit_format) {
187186
try {
188-
final_content = apply_search_replace_to_content({
189-
original_content: params.file_content,
190-
segments: parse_search_replace_segments(cleaned_content)
187+
const ext = params.file_path.split('.').pop()?.toLowerCase()
188+
const use_strict_whitespace =
189+
ext == 'py' || ext == 'yaml' || ext == 'yml'
190+
191+
final_content = apply_diff({
192+
original_code: params.file_content,
193+
diff_patch: cleaned_content,
194+
use_strict_whitespace
191195
})
192196
} catch (error: any) {
193197
Logger.warn({
194198
function_name: 'process_file',
195199
message:
196-
'Failed to apply search-replace blocks, retrying with fallback edit format',
200+
'Failed to apply diff patch, retrying with fallback edit format',
197201
data: { error, file_path: params.file_path }
198202
})
199203

0 commit comments

Comments
 (0)