Skip to content

Commit 1309886

Browse files
committed
Remove fallback edit format and retry logic from intelligent file updates
- should not use 'search replace' edit format as a first-try run. Instead request whole file immediately. └── apps └── editor └── src ├── utils │ └── send-llm-message.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 c19649b commit 1309886

4 files changed

Lines changed: 10 additions & 66 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ def show_wishes():
4545
>>>>>>> REPLACE
4646
\`\`\``
4747

48-
export const intelligent_update_fallback_edit_format_instructions = `Print the updated file in FULL (from cover to cover).`
49-
5048
export const commit_message_instructions =
5149
"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."
5250

‎apps/editor/src/views/prompt/backend/message-handlers/handle-fix-all-failed-files.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,9 @@ export const handle_fix_all_failed_files = async (params: {
165165
const original_file_size = file_state.content.length
166166
const estimated_total_tokens = Math.ceil(original_file_size / 4)
167167

168-
const on_chunk = (
169-
tokens_per_second: number,
170-
total_tokens: number,
171-
using_fallback: boolean
172-
) => {
168+
const on_chunk = (tokens_per_second: number, total_tokens: number) => {
173169
let progress: number | undefined
174-
if (using_fallback && estimated_total_tokens > 0) {
170+
if (estimated_total_tokens > 0) {
175171
progress = Math.min(
176172
Math.round((total_tokens / estimated_total_tokens) * 100),
177173
100

‎apps/editor/src/views/prompt/backend/message-handlers/handle-intelligent-update-file-in-preview.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,9 @@ export const handle_intelligent_update_file_in_preview = async (
154154
const original_file_size = file_state.content.length
155155
const estimated_total_tokens = Math.ceil(original_file_size / 4)
156156

157-
const on_chunk = (
158-
tokens_per_second: number,
159-
total_tokens: number,
160-
using_fallback: boolean
161-
) => {
157+
const on_chunk = (tokens_per_second: number, total_tokens: number) => {
162158
let progress: number | undefined
163-
if (using_fallback && estimated_total_tokens > 0) {
159+
if (estimated_total_tokens > 0) {
164160
progress = Math.min(
165161
Math.round((total_tokens / estimated_total_tokens) * 100),
166162
100

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

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ import { LAST_USED_INTELLIGENT_UPDATE_CONFIG_ID_STATE_KEY } from '@/constants/st
99
import { Logger } from '@shared/utils/logger'
1010
import { send_llm_message } from '@/utils/send-llm-message'
1111
import { cleanup_api_response } from '@/utils/cleanup-api-response'
12-
import {
13-
intelligent_update_task_instructions,
14-
intelligent_update_edit_format_instructions,
15-
intelligent_update_fallback_edit_format_instructions
16-
} from '@/constants/instructions'
12+
import { intelligent_update_task_instructions } from '@/constants/instructions'
1713
import { t } from '@/i18n'
1814
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1915
import {
2016
show_configuration_quick_pick,
2117
map_api_configuration_to_item
2218
} 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/apply-search-replace-to-content'
24-
import { parse_search_replace_segments } from '@/utils/changes-integration/search-replace-processor/parse-search-replace-segments'
2519

2620
export const get_intelligent_update_config = async (
2721
model_providers_manager: ModelProvidersManager,
@@ -109,28 +103,18 @@ export const process_file = async (params: {
109103
file_content: string
110104
instruction: string
111105
abort_signal?: AbortSignal
112-
on_chunk?: (
113-
tokens_per_second: number,
114-
total_tokens: number,
115-
using_fallback: boolean
116-
) => void
106+
on_chunk?: (tokens_per_second: number, total_tokens: number) => void
117107
on_thinking_chunk?: (text: string) => void
118-
use_fallback_edit_format?: boolean
119108
}): Promise<string> => {
120109
Logger.info({
121110
function_name: 'process_file',
122111
message: 'start',
123112
data: {
124-
file_path: params.file_path,
125-
use_fallback_format: params.use_fallback_edit_format
113+
file_path: params.file_path
126114
}
127115
})
128116

129-
const edit_format_instructions = params.use_fallback_edit_format
130-
? intelligent_update_fallback_edit_format_instructions
131-
: intelligent_update_edit_format_instructions
132-
133-
const content = `# File\n\n${params.file_content}\n\n# Output formatting\n\n${edit_format_instructions}\n\n# Task\n\n${intelligent_update_task_instructions}\n\n# Changes\n\n${params.instruction}`
117+
const content = `# File\n\n${params.file_content}\n\n# Task\n\n${intelligent_update_task_instructions}\n\n# Changes\n\n${params.instruction}`
134118

135119
const messages = [
136120
{
@@ -156,14 +140,7 @@ export const process_file = async (params: {
156140
api_key: params.api_key,
157141
body,
158142
abort_signal: params.abort_signal,
159-
on_chunk: params.on_chunk
160-
? (tokens_per_second, total_tokens) =>
161-
params.on_chunk!(
162-
tokens_per_second,
163-
total_tokens,
164-
!!params.use_fallback_edit_format
165-
)
166-
: undefined,
143+
on_chunk: params.on_chunk,
167144
on_thinking_chunk: params.on_thinking_chunk,
168145
rethrow_error: true
169146
})
@@ -182,30 +159,7 @@ export const process_file = async (params: {
182159
content: refactored_content
183160
})
184161

185-
let final_content = cleaned_content
186-
if (!params.use_fallback_edit_format) {
187-
try {
188-
const segments = parse_search_replace_segments(cleaned_content)
189-
final_content = apply_search_replace_to_content({
190-
original_content: params.file_content,
191-
segments
192-
})
193-
} catch (error: any) {
194-
Logger.warn({
195-
function_name: 'process_file',
196-
message:
197-
'Failed to apply search replace block, retrying with fallback edit format',
198-
data: { error, file_path: params.file_path }
199-
})
200-
201-
if (!params.abort_signal?.aborted) {
202-
return await process_file({
203-
...params,
204-
use_fallback_edit_format: true
205-
})
206-
}
207-
}
208-
}
162+
const final_content = cleaned_content
209163

210164
Logger.info({
211165
function_name: 'process_file',

0 commit comments

Comments
 (0)