Skip to content

Commit a7d4557

Browse files
committed
Add configurable agentic file search instructions and improve related formatting
- similarly to 'intelligent file search instructions', add configuration option: 'agentic file search instructions' - '# Output formatting' heading should be a part of the original file, not `apps/editor/src/constants/instructions.ts`. place search term under # Query heading - '# Output formatting' heading should be a part of the original file, not `apps/editor/src/constants/instructions.ts` └── apps ├── browser │ └── src │ └── types │ └── messages.ts └── editor ├── package.json └── src ├── constants │ └── instructions.ts ├── features │ └── search-files │ ├── search-modes │ │ ├── perform-agent-search-mode │ │ │ ├── agents │ │ │ │ ├── antigravity.ts │ │ │ │ ├── claude.ts │ │ │ │ ├── codex.ts │ │ │ │ ├── cursor.ts │ │ │ │ ├── grok.ts │ │ │ │ ├── muse.ts │ │ │ │ └── opencode.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ └── perform-intelligent-search-mode.ts │ └── utils │ └── search-files-by-intelligent.ts └── views ├── chats │ └── types │ └── messages.ts ├── prompt │ ├── backend │ │ └── message-handlers │ │ └── index.ts │ ├── frontend │ │ └── Home │ │ └── Home.tsx │ └── types │ └── messages.ts ├── settings │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-get-intelligent-file-search-instructions.ts │ │ │ ├── handle-update-intelligent-file-search-instructions.ts │ │ │ └── index.ts │ │ └── settings-view-provider.ts │ ├── frontend │ │ ├── Home │ │ │ ├── Home.tsx │ │ │ └── sections │ │ │ └── GeneralSection.tsx │ │ ├── Settings.tsx │ │ ├── hooks │ │ │ └── use-settings.ts │ │ └── i18n │ │ └── translations │ │ └── general.ts │ └── types │ └── messages.ts └── shared └── types └── messages.ts
1 parent a9b22fa commit a7d4557

18 files changed

Lines changed: 229 additions & 18 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,10 @@
10351035
"type": "string",
10361036
"scope": "resource"
10371037
},
1038+
"codeWebChat.agenticFileSearchInstructions": {
1039+
"type": "string",
1040+
"scope": "resource"
1041+
},
10381042
"codeWebChat.editFilesSystemInstructions": {
10391043
"type": "string",
10401044
"scope": "resource"

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export const code_at_cursor_instructions_for_chatbots = (params: {
55
file_path: string
66
row: number
77
column: number
8-
}) => `# Output formatting
9-
10-
Your response must begin with a markdown heading identifying the file and the cursor position, followed by a markdown code block containing the replacement text, followed by a brief explanation. The heading must be: "### Code at cursor: \`${
8+
}) => `Your response must begin with a markdown heading identifying the file and the cursor position, followed by a markdown code block containing the replacement text, followed by a brief explanation. The heading must be: "### Code at cursor: \`${
119
params.file_path
1210
}\` (${params.row + 1}:${
1311
params.column + 1
@@ -53,11 +51,9 @@ export const commit_message_format = `Your response must begin with "**Commit me
5351
**Commit message:** Bump version to 1.0.1`
5452

5553
export const intelligent_file_search_instructions =
56-
'Find a complete set of files relevant to the following query. Include the primary files as well as any structural files.'
57-
58-
export const intelligent_file_search_format = `# Output formatting
54+
'In the project, find the complete set of primary and structural files relevant to the query.'
5955

60-
Your response must contain paths of relevant files enclosed in "intelligent-file-search-results" and "file-path" XML tags. Don't send anything else. Example:
56+
export const intelligent_file_search_format = `Your response must contain paths of relevant files enclosed in "intelligent-file-search-results" and "file-path" XML tags. Don't send anything else. Example:
6157
6258
<intelligent-file-search-results>
6359
<file-path>src/index.ts</file-path>
@@ -67,9 +63,7 @@ Your response must contain paths of relevant files enclosed in "intelligent-file
6763

6864
export const intelligent_file_search_format_for_prompt_view = (
6965
metadata?: string
70-
) => `# Output formatting
71-
72-
Your response must begin with "**Intelligent file search results${
66+
) => `Your response must begin with "**Intelligent file search results${
7367
metadata || ''
7468
}:**", then list paths one under another, followed by a brief explanation. Example:
7569
@@ -85,7 +79,7 @@ export const voice_input_instructions =
8579
'Respond with a transcription of the following audio recording or text "INAUDIBLE", and nothing else.'
8680

8781
export const agentic_file_search_task_instructions =
88-
'In the project, find the complete set of primary and structural file paths relevant to the query.'
82+
'In the project, find the complete set of primary and structural files relevant to the query.'
8983

9084
export const agentic_file_search_format_instructions =
9185
'Output strictly as a bulleted list of file paths without explanations or any other text (e.g., - path/to/file.ext).'

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/utils.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
import * as vscode from 'vscode'
12
import { execSync } from 'child_process'
23
import * as os from 'os'
34
import {
45
agentic_file_search_format_instructions,
56
agentic_file_search_task_instructions
67
} from '@/constants/instructions'
78

8-
export const build_agent_prompt = (query: string) =>
9-
`# Task\n\n${agentic_file_search_task_instructions}\n\n# Output formatting\n\n${agentic_file_search_format_instructions}\n\n# Query\n\n${query}`
9+
export const build_agent_prompt = (query: string) => {
10+
const config = vscode.workspace.getConfiguration('codeWebChat')
11+
const task_instructions =
12+
config.get<string>('agenticFileSearchInstructions') ||
13+
agentic_file_search_task_instructions
14+
15+
return `# Task\n\n${task_instructions}\n\n# Output formatting\n\n${agentic_file_search_format_instructions}\n\n# Query\n\n${query}`
16+
}
1017

1118
export const check_command_exists = (cmd: string): boolean => {
1219
try {

‎apps/editor/src/features/search-files/search-modes/perform-intelligent-search-mode.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export const perform_intelligent_search_mode = async (params: {
276276
const format_instructions =
277277
intelligent_file_search_format_for_prompt_view(metadata)
278278

279-
const chatbot_prompt = `# Files\n\n${md_files}# Task\n\n${base_instructions}\n\n${search_term}\n\n${format_instructions}`
279+
const chatbot_prompt = `# Files\n\n${md_files}# Task\n\n${base_instructions}\n\n# Output formatting\n\n${format_instructions}\n\n# Query\n\n${search_term}`
280280

281281
if (action == 'copy') {
282282
await vscode.env.clipboard.writeText(chatbot_prompt)

‎apps/editor/src/features/search-files/utils/search-files-by-intelligent.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const search_files_by_intelligent = async (
3131
config.get<string>('intelligentFileSearchInstructions') ||
3232
intelligent_file_search_instructions
3333

34-
const part2 = `${intelligent_file_search_format}\n\n${base_instructions}\n\n${instructions}`
34+
const part2 = `# Task\n\n${base_instructions}\n\n# Output formatting\n\n${intelligent_file_search_format}\n\n# Query\n\n${instructions}`
3535
const user_content = build_user_content({
3636
model_provider,
3737
part1: xml_files,
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 { SettingsViewProvider } from '@/views/settings/backend/settings-view-provider'
3+
import { agentic_file_search_task_instructions } from '@/constants/instructions'
4+
5+
export const handle_get_agentic_file_search_instructions = async (
6+
provider: SettingsViewProvider
7+
): Promise<void> => {
8+
const config = vscode.workspace.getConfiguration('codeWebChat')
9+
const instructions =
10+
config.get<string>('agenticFileSearchInstructions') ||
11+
agentic_file_search_task_instructions
12+
provider.postMessage({
13+
command: 'AGENTIC_FILE_SEARCH_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 { agentic_file_search_task_instructions } from '@/constants/instructions'
3+
import { UpdateAgenticFileSearchInstructionsMessage } from '../../types/messages'
4+
5+
export const handle_update_agentic_file_search_instructions = async (
6+
message: UpdateAgenticFileSearchInstructionsMessage
7+
): Promise<void> => {
8+
await vscode.workspace
9+
.getConfiguration('codeWebChat')
10+
.update(
11+
'agenticFileSearchInstructions',
12+
message.instructions == '' ||
13+
message.instructions == agentic_file_search_task_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,5 +1,7 @@
11
export * from './handle-get-intelligent-file-search-instructions'
22
export * from './handle-update-intelligent-file-search-instructions'
3+
export * from './handle-get-agentic-file-search-instructions'
4+
export * from './handle-update-agentic-file-search-instructions'
35
export * from './handle-get-templates'
46
export * from './handle-update-templates'
57
export * from './handle-create-template'

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ import {
6262
handle_pick_api_reasoning_effort,
6363
handle_get_intelligent_file_search_instructions,
6464
handle_update_intelligent_file_search_instructions,
65+
handle_get_agentic_file_search_instructions,
66+
handle_update_agentic_file_search_instructions,
6567
handle_get_templates,
6668
handle_update_templates,
6769
handle_create_template,
@@ -180,6 +182,14 @@ export class SettingsViewProvider {
180182
message.command == 'UPDATE_INTELLIGENT_FILE_SEARCH_INSTRUCTIONS'
181183
) {
182184
await handle_update_intelligent_file_search_instructions(message)
185+
} else if (
186+
message.command == 'GET_AGENTIC_FILE_SEARCH_INSTRUCTIONS'
187+
) {
188+
await handle_get_agentic_file_search_instructions(this)
189+
} else if (
190+
message.command == 'UPDATE_AGENTIC_FILE_SEARCH_INSTRUCTIONS'
191+
) {
192+
await handle_update_agentic_file_search_instructions(message)
183193
} else if (message.command == 'SET_DEFAULT_API_CONFIGURATION') {
184194
await handle_set_default_api_configuration(
185195
this,
@@ -327,6 +337,7 @@ export class SettingsViewProvider {
327337
void handle_get_api_configurations(this)
328338
void handle_get_edit_files_system_instructions(this)
329339
void handle_get_intelligent_file_search_instructions(this)
340+
void handle_get_agentic_file_search_instructions(this)
330341
void handle_get_commit_message_instructions(this)
331342
void handle_get_attach_ascii_tree_of_context(this)
332343
void handle_get_use_context_files_in_commit_message_prompt(this)

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { use_translation, TranslationKey } from '../i18n/use-translation'
1616
import { WebConfigurationsSection } from './sections/WebConfigurationsSection'
1717
import { commit_message_instructions as default_commit_message_instructions } from '@/constants/instructions'
1818
import { intelligent_file_search_instructions as default_intelligent_file_search_instructions } from '@/constants/instructions'
19+
import { agentic_file_search_task_instructions as default_agentic_file_search_instructions } from '@/constants/instructions'
1920
import { default_system_instructions } from '@shared/constants/default-system-instructions'
2021
import { GROUP_TITLE_HEIGHT, SECTION_HEADER_HEIGHT } from '@ui/constants/sizes'
2122

@@ -108,6 +109,7 @@ type Props = {
108109
defaults: Record<ApiFeature, string | null>
109110
edit_files_system_instructions: string
110111
intelligent_file_search_instructions: string
112+
agentic_file_search_instructions: string
111113
commit_message_instructions: string
112114
synchronize_edit_format_between_targets: boolean
113115
attach_ascii_tree_of_context: 'ask' | 'always' | 'never'
@@ -146,6 +148,7 @@ type Props = {
146148
) => void
147149
on_edit_files_system_instructions_change: (instructions: string) => void
148150
on_intelligent_file_search_instructions_change: (instructions: string) => void
151+
on_agentic_file_search_instructions_change: (instructions: string) => void
149152
on_automatic_checkpoints_toggle: (disabled: boolean) => void
150153
on_checkpoint_lifespan_change: (hours: number | undefined) => void
151154
on_gemini_user_id_change: (id: number | null) => void
@@ -225,6 +228,10 @@ export const Home: React.FC<Props> = (props) => {
225228
intelligent_file_search_instructions,
226229
set_intelligent_file_search_instructions
227230
] = useState('')
231+
const [
232+
agentic_file_search_instructions,
233+
set_agentic_file_search_instructions
234+
] = useState('')
228235
const [edit_files_instructions, set_edit_files_instructions] = useState('')
229236

230237
const get_has_warning = (id: NavItem): boolean => {
@@ -402,6 +409,12 @@ export const Home: React.FC<Props> = (props) => {
402409
)
403410
}, [props.intelligent_file_search_instructions])
404411

412+
useEffect(() => {
413+
set_agentic_file_search_instructions(
414+
props.agentic_file_search_instructions || ''
415+
)
416+
}, [props.agentic_file_search_instructions])
417+
405418
useEffect(() => {
406419
set_edit_files_instructions(props.edit_files_system_instructions || '')
407420
}, [props.edit_files_system_instructions])
@@ -623,6 +636,37 @@ export const Home: React.FC<Props> = (props) => {
623636
default_intelligent_file_search_instructions
624637
)
625638
}}
639+
agentic_file_search_instructions={
640+
agentic_file_search_instructions
641+
}
642+
set_agentic_file_search_instructions={
643+
set_agentic_file_search_instructions
644+
}
645+
on_agentic_file_search_instructions_blur={() => {
646+
props.on_agentic_file_search_instructions_change(
647+
agentic_file_search_instructions
648+
)
649+
if (
650+
agentic_file_search_instructions == '' &&
651+
props.agentic_file_search_instructions ==
652+
default_agentic_file_search_instructions
653+
) {
654+
set_agentic_file_search_instructions(
655+
default_agentic_file_search_instructions
656+
)
657+
}
658+
}}
659+
default_agentic_file_search_instructions={
660+
default_agentic_file_search_instructions
661+
}
662+
on_restore_agentic_file_search_instructions={() => {
663+
set_agentic_file_search_instructions(
664+
default_agentic_file_search_instructions
665+
)
666+
props.on_agentic_file_search_instructions_change(
667+
default_agentic_file_search_instructions
668+
)
669+
}}
626670
on_open_external_url={props.on_open_external_url}
627671
templates={props.templates}
628672
on_update_templates={props.on_update_templates}

0 commit comments

Comments
 (0)