Skip to content

Commit c0e73a6

Browse files
committed
Add a configurable setting for find relevant files instructions and update the settings UI to support customizing them
- in 'General > context' add the ability to override 'find relevant files instructions'
1 parent a2d8521 commit c0e73a6

16 files changed

Lines changed: 221 additions & 8 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,10 @@
924924
"type": "string",
925925
"scope": "resource"
926926
},
927+
"codeWebChat.findRelevantFilesInstructions": {
928+
"type": "string",
929+
"scope": "resource"
930+
},
927931
"codeWebChat.editFilesSystemInstructions": {
928932
"type": "string",
929933
"scope": "resource"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const commit_message_instructions =
3333
"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."
3434

3535
export const find_relevant_files_instructions =
36-
'Find a complete set of files relevant to the following query (include the primary files as well as any structural files):'
36+
'Find a complete set of files relevant to the following query. Include the primary files as well as any structural files.'
3737

3838
export const find_relevant_files_format = `# System
3939

‎apps/editor/src/features/search-files/utils/fetch-relevant-files-from-api.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export const fetch_relevant_files_from_api = async (
2626
}
2727
xml_files += `</files>`
2828

29-
const part2 = `${find_relevant_files_format}\n\n${find_relevant_files_instructions}\n\n${instructions}`
29+
const config = vscode.workspace.getConfiguration('codeWebChat')
30+
const base_instructions =
31+
config.get<string>('findRelevantFilesInstructions') ||
32+
find_relevant_files_instructions
33+
34+
const part2 = `${find_relevant_files_format}\n\n${base_instructions}\n\n${instructions}`
3035
const user_content = build_user_content({
3136
model_provider,
3237
part1: xml_files,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ export const handle_copy_prompt = async (params: {
152152
}
153153
} else if (is_in_find_relevant_files_prompt_type) {
154154
formatted_system_instructions = find_relevant_files_format_for_panel
155-
user_instructions = `${find_relevant_files_instructions}\n\n${processed_instructions}`
155+
156+
const config = vscode.workspace.getConfiguration('codeWebChat')
157+
const base_instructions =
158+
config.get<string>('findRelevantFilesInstructions') ||
159+
find_relevant_files_instructions
160+
user_instructions = `${base_instructions}\n\n${processed_instructions}`
156161
}
157162

158163
const { full_prompt: text } = PromptBuilder.build_prompt({

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,17 @@ export const handle_find_relevant_files = async (
216216

217217
const endpoint_url = model_provider.base_url
218218

219+
const config = vscode.workspace.getConfiguration('codeWebChat')
220+
const base_instructions =
221+
config.get<string>('findRelevantFilesInstructions') ||
222+
find_relevant_files_instructions
223+
219224
const { part1, part2 } = PromptBuilder.build_prompt({
220225
other_files: collected.other_files,
221226
recent_files: collected.recent_files,
222227
skill_definitions,
223228
system_instructions: find_relevant_files_format_for_panel,
224-
user_instructions: `${find_relevant_files_instructions}\n\n${processed_instructions}`
229+
user_instructions: `${base_instructions}\n\n${processed_instructions}`
225230
})
226231

227232
const user_content = build_user_content({

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ export const handle_send_to_browser = async (params: {
183183
}
184184
} else if (params.panel_provider.web_prompt_type == 'find-relevant-files') {
185185
formatted_system_instructions = find_relevant_files_format_for_panel
186-
user_instructions = `${find_relevant_files_instructions}\n\n${processed_instructions}`
186+
187+
const config = vscode.workspace.getConfiguration('codeWebChat')
188+
const base_instructions =
189+
config.get<string>('findRelevantFilesInstructions') ||
190+
find_relevant_files_instructions
191+
user_instructions = `${base_instructions}\n\n${processed_instructions}`
187192
}
188193

189194
const { full_prompt: text } = PromptBuilder.build_prompt({
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { find_relevant_files_instructions } from '@/constants/instructions'
4+
5+
export const handle_get_find_relevant_files_instructions = async (
6+
provider: SettingsProvider
7+
): Promise<void> => {
8+
const config = vscode.workspace.getConfiguration('codeWebChat')
9+
const instructions =
10+
config.get<string>('findRelevantFilesInstructions') ||
11+
find_relevant_files_instructions
12+
provider.postMessage({
13+
command: 'FIND_RELEVANT_FILES_INSTRUCTIONS',
14+
instructions
15+
})
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as vscode from 'vscode'
2+
import { find_relevant_files_instructions } from '@/constants/instructions'
3+
import { UpdateFindRelevantFilesInstructionsMessage } from '../../types/messages'
4+
5+
export const handle_update_find_relevant_files_instructions = async (
6+
message: UpdateFindRelevantFilesInstructionsMessage
7+
): Promise<void> => {
8+
await vscode.workspace
9+
.getConfiguration('codeWebChat')
10+
.update(
11+
'findRelevantFilesInstructions',
12+
message.instructions == '' ||
13+
message.instructions == find_relevant_files_instructions
14+
? undefined
15+
: message.instructions,
16+
vscode.ConfigurationTarget.Global
17+
)
18+
}

‎apps/editor/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from './handle-get-find-relevant-files-instructions'
2+
export * from './handle-update-find-relevant-files-instructions'
13
export * from './handle-add-model-provider'
24
export * from './handle-update-model-provider'
35
export * from './handle-get-model-providers'

‎apps/editor/src/views/settings/backend/settings-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import {
5757
handle_reorder_api_configurations,
5858
handle_pick_model_provider,
5959
handle_pick_api_model,
60-
handle_pick_api_reasoning_effort
60+
handle_pick_api_reasoning_effort,
61+
handle_get_find_relevant_files_instructions,
62+
handle_update_find_relevant_files_instructions
6163
} from './message-handlers'
6264
import { config_web_configuration_to_ui_format } from '@/utils/web-configuration-format-converters'
6365
import { webview_html } from '@/views/shared/utils/webview-html'
@@ -147,6 +149,12 @@ export class SettingsProvider {
147149
await handle_update_model_provider(this, message)
148150
} else if (message.command == 'GET_API_CONFIGURATIONS') {
149151
await handle_get_api_configurations(this)
152+
} else if (message.command == 'GET_FIND_RELEVANT_FILES_INSTRUCTIONS') {
153+
await handle_get_find_relevant_files_instructions(this)
154+
} else if (
155+
message.command == 'UPDATE_FIND_RELEVANT_FILES_INSTRUCTIONS'
156+
) {
157+
await handle_update_find_relevant_files_instructions(message)
150158
} else if (message.command == 'SET_DEFAULT_API_CONFIGURATION') {
151159
await handle_set_default_api_configuration(
152160
this,
@@ -275,6 +283,7 @@ export class SettingsProvider {
275283
void handle_get_model_providers(this)
276284
void handle_get_api_configurations(this)
277285
void handle_get_edit_files_system_instructions(this)
286+
void handle_get_find_relevant_files_instructions(this)
278287
void handle_get_edit_format_instructions(this)
279288
void handle_get_context_size_warning_threshold(this)
280289
void handle_get_commit_message_instructions(this)

0 commit comments

Comments
 (0)