Skip to content

Commit fd013c1

Browse files
committed
Refactor system instructions format by placing format instructions before custom instructions
1 parent 2207694 commit fd013c1

4 files changed

Lines changed: 50 additions & 14 deletions

File tree

‎apps/editor/src/commands/find-relevant-files-command.ts‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,49 @@ export const find_relevant_files_command = (
5656
LAST_FIND_RELEVANT_FILES_QUERY_STATE_KEY
5757
) || ''
5858

59+
const close_button = {
60+
iconPath: new vscode.ThemeIcon('close'),
61+
tooltip: t('common.close')
62+
}
63+
5964
while (true) {
60-
const instructions = await vscode.window.showInputBox({
61-
title: t('command.find-relevant-files.input.title'),
62-
prompt: t('command.find-relevant-files.input.prompt'),
63-
placeHolder: t('command.find-relevant-files.input.placeholder'),
64-
value: initial_instructions
65-
})
65+
const input_box = vscode.window.createInputBox()
66+
input_box.title = t('command.find-relevant-files.input.title')
67+
input_box.prompt = t('command.find-relevant-files.input.prompt')
68+
input_box.placeholder = t(
69+
'command.find-relevant-files.input.placeholder'
70+
)
71+
input_box.value = initial_instructions
72+
input_box.buttons = [close_button]
73+
74+
const instructions = await new Promise<string | undefined>(
75+
(resolve) => {
76+
let is_resolved = false
77+
const disposables: vscode.Disposable[] = []
78+
79+
disposables.push(
80+
input_box.onDidTriggerButton((button) => {
81+
if (button === close_button) {
82+
resolve(undefined)
83+
input_box.hide()
84+
}
85+
}),
86+
input_box.onDidAccept(() => {
87+
is_resolved = true
88+
resolve(input_box.value)
89+
input_box.hide()
90+
}),
91+
input_box.onDidHide(() => {
92+
if (!is_resolved) {
93+
resolve(undefined)
94+
}
95+
disposables.forEach((d) => d.dispose())
96+
input_box.dispose()
97+
})
98+
)
99+
input_box.show()
100+
}
101+
)
66102

67103
if (!instructions) {
68104
return
@@ -252,7 +288,7 @@ export const find_relevant_files_command = (
252288
config_find_relevant_files_instructions ||
253289
find_relevant_files_instructions
254290

255-
const system_instructions_xml = `${instructions_to_use}\n${find_relevant_files_format}`
291+
const system_instructions_xml = `${find_relevant_files_format}\n${instructions_to_use}`
256292
const part2 = `${system_instructions_xml}\n${instructions}`
257293

258294
const user_content = build_user_content({
@@ -389,10 +425,6 @@ export const find_relevant_files_command = (
389425
)
390426
quick_pick.ignoreFocusOut = true
391427

392-
const close_button = {
393-
iconPath: new vscode.ThemeIcon('close'),
394-
tooltip: t('common.close')
395-
}
396428
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
397429

398430
const selected = await new Promise<
@@ -445,6 +477,10 @@ export const find_relevant_files_command = (
445477
continue
446478
}
447479

480+
if (!selected) {
481+
return
482+
}
483+
448484
if (selected) {
449485
const selected_paths = selected.map((item) => item.file_path)
450486
const unchecked_paths = absolute_paths.filter(

‎apps/editor/src/views/panel/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const handle_copy_prompt = async (params: {
158158
const instructions_to_use =
159159
config_find_relevant_files_instructions ||
160160
find_relevant_files_instructions
161-
system_instructions_xml = `${instructions_to_use}\n${find_relevant_files_format_for_panel}`
161+
system_instructions_xml = `${find_relevant_files_format_for_panel}\n${instructions_to_use}`
162162
}
163163

164164
const text = context_text

‎apps/editor/src/views/panel/backend/message-handlers/handle-find-relevant-files.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export const handle_find_relevant_files = async (
362362
const instructions_to_use =
363363
config_find_relevant_files_instructions ||
364364
find_relevant_files_instructions
365-
const system_instructions_xml = `${instructions_to_use}\n${find_relevant_files_format_for_panel}`
365+
const system_instructions_xml = `${find_relevant_files_format_for_panel}\n${instructions_to_use}`
366366

367367
const part1 = `<files>\n${collected.other_files}`
368368
const part2 = `${collected.recent_files}</files>\n${skill_definitions}${system_instructions_xml}\n${processed_instructions}`

‎apps/editor/src/views/panel/backend/message-handlers/handle-send-to-browser.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const handle_send_to_browser = async (params: {
203203
const instructions_to_use =
204204
config_find_relevant_files_instructions ||
205205
find_relevant_files_instructions
206-
system_instructions_xml = `${instructions_to_use}\n${find_relevant_files_format_for_panel}`
206+
system_instructions_xml = `${find_relevant_files_format_for_panel}\n${instructions_to_use}`
207207
}
208208

209209
return {

0 commit comments

Comments
 (0)