@@ -10,6 +10,12 @@ import {
1010 EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE ,
1111 EDIT_FORMAT_INSTRUCTIONS_DIFF
1212} from '@/constants/edit-format-instructions'
13+ import {
14+ code_at_cursor_instructions_for_panel ,
15+ find_relevant_files_instructions ,
16+ find_relevant_files_format_for_panel
17+ } from '@/constants/instructions'
18+ import { FIND_RELEVANT_FILES_SHRINK_SOURCE_CODE_STATE_KEY } from '@/constants/state-keys'
1319import { replace_symbols } from '@/views/panel/backend/utils/symbols/replace-symbols'
1420import { PromptBuilder } from '@/utils/prompt-builder'
1521
@@ -47,9 +53,11 @@ export const handle_preview_web_configuration = async (
4753 const workspace_folder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath
4854 const relative_path = active_path ! . replace ( workspace_folder + '/' , '' )
4955
50- const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
51- const system_instructions =
52- config . get < string > ( 'chatCodeCompletionsInstructions' ) || ''
56+ const main_instructions = code_at_cursor_instructions_for_panel ( {
57+ file_path : relative_path ,
58+ row : position . line ,
59+ column : position . character
60+ } )
5361
5462 const {
5563 instruction : processed_completion_instructions ,
@@ -72,13 +80,23 @@ export const handle_preview_web_configuration = async (
7280 content : `${ text_before_cursor } ${ missing_text_tag } ${ text_after_cursor } `
7381 } ,
7482 skill_definitions,
75- system_instructions
83+ system_instructions : main_instructions
7684 } )
7785 text_to_send = full_prompt
7886 } else if ( panel_provider . web_prompt_type != 'code-at-cursor' ) {
87+ const shrink_source_code =
88+ panel_provider . context . workspaceState . get < boolean > (
89+ FIND_RELEVANT_FILES_SHRINK_SOURCE_CODE_STATE_KEY ,
90+ false
91+ )
92+
7993 const collected =
8094 panel_provider . web_prompt_type != 'without-files'
81- ? await files_collector . collect_files ( { } )
95+ ? await files_collector . collect_files ( {
96+ shrink :
97+ panel_provider . web_prompt_type == 'find-relevant-files' &&
98+ shrink_source_code
99+ } )
82100 : { other_files : '' , recent_files : '' }
83101 const context_text = collected . other_files + collected . recent_files
84102
@@ -91,6 +109,7 @@ export const handle_preview_web_configuration = async (
91109 } )
92110
93111 let formatted_system_instructions = ''
112+ let user_instructions = processed_instructions
94113 if ( panel_provider . web_prompt_type == 'edit-files' ) {
95114 const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
96115 const instructions_key = {
@@ -110,13 +129,21 @@ export const handle_preview_web_configuration = async (
110129 if ( edit_format_instructions ) {
111130 formatted_system_instructions = `# System\n\n${ edit_format_instructions } `
112131 }
132+ } else if ( panel_provider . web_prompt_type == 'find-relevant-files' ) {
133+ formatted_system_instructions = find_relevant_files_format_for_panel
134+
135+ const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
136+ const base_instructions =
137+ config . get < string > ( 'findRelevantFilesInstructions' ) ||
138+ find_relevant_files_instructions
139+ user_instructions = `${ base_instructions } \n\n${ processed_instructions } `
113140 }
114141
115142 const { full_prompt : built_prompt } = PromptBuilder . build_prompt ( {
116143 context_text,
117144 skill_definitions,
118145 system_instructions : formatted_system_instructions ,
119- user_instructions : processed_instructions
146+ user_instructions
120147 } )
121148 text_to_send = built_prompt
122149 } else {
0 commit comments