Skip to content

Commit 63774be

Browse files
committed
Centralize edit format utilities and update intelligent update processing to use search and replace blocks
- rename 'conflict markers' to 'search replace' - For the intelligent update, we should request and apply 'search replace' blocks. That would speed-up the process. - intelligent_update_instructions should not directly use [Fragment] but duplicate and simplify for our needs - the intelligent update process should use intelligent_update_edit_format_instructions in "# System" paragraph. below place markdown separator "---" and intelligent_update_task_instructions. don't edit `apps/editor/src/constants/instructions.ts`
1 parent 32e52b8 commit 63774be

107 files changed

Lines changed: 91 additions & 49 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion

‎apps/editor/src/commands/apply-response-command/handlers/diff-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { exec } from 'child_process'
55
import { Logger } from '@shared/utils/logger'
66
import { OriginalFileState } from '../types/original-file-state'
77
import { create_safe_path } from '@/utils/path-sanitizer'
8-
import { apply_diff } from '../utils/edit-formats/diffs'
8+
import { apply_diff } from '../../../utils/edit-formats/diffs'
99
import { remove_directory_if_empty } from '../utils/file-operations'
1010
import { DiffItem } from '../utils/response-parser'
1111

‎apps/editor/src/commands/apply-response-command/handlers/search-replace-handler.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
handle_deleted_file_item,
1212
get_rename_source_info
1313
} from '../utils/file-operations'
14-
import { apply_conflict_markers_to_content } from '../utils/edit-formats/conflict-markers/apply-conflict-markers-to-content'
15-
import { parse_conflict_segments } from '../utils/edit-formats/conflict-markers/parse-conflict-segments'
14+
import { apply_search_replace_to_content } from '../../../utils/edit-formats/search-replace/apply-search-replace-to-content'
15+
import { parse_search_replace_segments } from '../../../utils/edit-formats/search-replace/parse-search-replace-segments'
1616

1717
export const handle_search_replace = async (params: {
1818
files: FileItem[]
@@ -109,9 +109,9 @@ export const handle_search_replace = async (params: {
109109
try {
110110
let new_content = rename_source_content
111111
if (has_markers) {
112-
new_content = apply_conflict_markers_to_content({
112+
new_content = apply_search_replace_to_content({
113113
original_content: rename_source_content,
114-
segments: parse_conflict_segments(file.content)
114+
segments: parse_search_replace_segments(file.content)
115115
})
116116
} else if (file.content != '') {
117117
new_content = file.content
@@ -147,9 +147,9 @@ export const handle_search_replace = async (params: {
147147
try {
148148
const document = await vscode.workspace.openTextDocument(safe_path)
149149
const original_content = document.getText()
150-
const current_content = apply_conflict_markers_to_content({
150+
const current_content = apply_search_replace_to_content({
151151
original_content,
152-
segments: parse_conflict_segments(file.content)
152+
segments: parse_search_replace_segments(file.content)
153153
})
154154

155155
if (current_content !== original_content) {
@@ -169,13 +169,13 @@ export const handle_search_replace = async (params: {
169169

170170
Logger.info({
171171
function_name: 'handle_search_replace',
172-
message: 'Applied conflict markers edit to file',
172+
message: 'Applied search replace edit to file',
173173
data: safe_path
174174
})
175175
} catch (error: any) {
176176
Logger.error({
177177
function_name: 'handle_search_replace',
178-
message: 'Failed to apply conflict markers edit',
178+
message: 'Failed to apply search replace edit',
179179
data: { file_path: safe_path, error }
180180
})
181181
failed_files.push(file)
@@ -189,7 +189,7 @@ export const handle_search_replace = async (params: {
189189

190190
let content_to_write = file.content
191191
if (has_markers) {
192-
const segments = parse_conflict_segments(file.content)
192+
const segments = parse_search_replace_segments(file.content)
193193
content_to_write = segments
194194
.map((s) =>
195195
s.type == 'common'
@@ -257,7 +257,7 @@ export const handle_search_replace = async (params: {
257257
} catch (error: any) {
258258
Logger.error({
259259
function_name: 'handle_search_replace',
260-
message: 'Error during conflict markers edit',
260+
message: 'Error during search replace edit',
261261
data: error
262262
})
263263
vscode.window.showErrorMessage(

‎apps/editor/src/commands/apply-response-command/handlers/truncated-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { dictionary } from '@shared/constants/dictionary'
66
import { create_safe_path, sanitize_file_name } from '@/utils/path-sanitizer'
77
import { FileItem } from '../utils/response-parser'
88
import { OriginalFileState } from '../types/original-file-state'
9-
import { process_truncated_content } from '../utils/edit-formats/truncations'
9+
import { process_truncated_content } from '../../../utils/edit-formats/truncations'
1010
import {
1111
cleanup_rename_source,
1212
handle_deleted_file_item,

‎apps/editor/src/commands/apply-response-command/response-processor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { handle_truncated_edit } from './handlers/truncated-handler'
2828
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
2929
import { natural_sort } from '@/utils/natural-sort'
3030
import { t } from '@/i18n'
31-
import { is_truncation_line } from './utils/edit-formats/truncations'
31+
import { is_truncation_line } from '../../utils/edit-formats/truncations'
3232
import {
3333
RelevantFileInPreview,
3434
ItemInPreview

‎apps/editor/src/commands/apply-response-command/utils/edit-formats/conflict-markers/apply-conflict-markers-to-content/index.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/edit-formats/conflict-markers/types.ts‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/relevant-files-parser/relevant-files-parser.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const parse_relevant_files = (params: {
1010
workspace_files: string[]
1111
}): RelevantFilesItem | null => {
1212
if (
13-
params.response.includes('### File:') ||
13+
params.response.includes('## File:') ||
1414
params.response.includes('### Created file:') ||
1515
params.response.includes('### Updated file:') ||
1616
params.response.includes('### Deleted file:') ||

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,25 @@ The variable is possibly not defined.
2525
2626
Find correct replacement text for the <missing_text> symbol.`
2727

28-
export const intelligent_update_instructions =
29-
'Refactor the file according to the attached changes without explanations or any other text. Print the file in FULL.'
28+
export const intelligent_update_task_instructions =
29+
'Refactor the file according to the attached changes without explanations or any other text.'
30+
31+
export const intelligent_update_edit_format_instructions = `Output a 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
46+
\`\`\``
3047

3148
export const commit_message_instructions =
3249
"Write a brief and precise summary for the changes, limited to a single sentence. Because the summary will be used for a commit message, don't use any markdown formatting and don't include a trailing dot. Use an imperative tone to ensure clarity and focus on the primary change or purpose."

‎apps/editor/src/context/providers/workspace/modules/token-calculator.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ export class TokenCalculator implements vscode.Disposable {
331331
}
332332

333333
if (is_binary) {
334-
return `### File: \`${display_path}\`\n\nBinary file\n\n`
334+
return `## File: \`${display_path}\`\n\nBinary file\n\n`
335335
} else {
336-
return `### File: \`${display_path}\`\n\n\`\`\`\n${text}\n\`\`\`\n\n`
336+
return `## File: \`${display_path}\`\n\n\`\`\`\n${text}\n\`\`\`\n\n`
337337
}
338338
}
339339

0 commit comments

Comments
 (0)