Skip to content

Commit 4f4779d

Browse files
committed
Add optional additional instructions prompt to agentic search
- agentic search from the prompt view, after selecting agent, show input field: 'additional instructions'. Append them to the query. - preserve typed additional instructions in workspace state, even when going back to the list of agents └── apps └── editor └── src ├── constants │ └── state-keys.ts ├── features │ └── agentic-search │ ├── agentic-search.ts │ ├── index.ts │ └── utils │ ├── build-agent-prompt.ts │ ├── index.ts │ ├── prompt-for-additional-instructions.ts │ └── prompt-for-search-term.ts ├── i18n │ └── translations │ └── features │ ├── agentic-search.ts │ └── index.ts ├── utils │ └── agentic-cli-invocation │ └── invoke-agentic-cli.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ └── handle-agentic-search.ts │ └── prompt-view-provider.ts ├── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ ├── MainView.tsx │ │ └── components │ │ └── PromptAttachments │ │ └── PromptAttachments.tsx │ ├── Prompt.tsx │ ├── hooks │ │ └── use-prompt │ │ └── use-prompt.ts │ └── i18n │ └── translations │ └── selected-files.ts └── types └── messages.ts
1 parent b297bc8 commit 4f4779d

7 files changed

Lines changed: 164 additions & 13 deletions

File tree

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export const LAST_SEARCH_SELECTED_FILES_FOR_CONTEXT_MODE_STATE_KEY =
111111
'last-search-selected-files-for-context-mode'
112112

113113
export const LAST_AGENTIC_SEARCH_QUERY_STATE_KEY = 'last-agentic-search-query'
114+
export const LAST_AGENTIC_SEARCH_ADDITIONAL_INSTRUCTIONS_STATE_KEY =
115+
'last-agentic-search-additional-instructions'
114116
export const LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY =
115117
'last-selected-workspace-in-agentic-search'
116118
export const LAST_SELECTED_WORKSPACE_IN_AGENTIC_CLI_STATE_KEY =

‎apps/editor/src/features/agentic-search/agentic-search.ts‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { t } from '@/i18n'
77
import {
88
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,
99
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY,
10-
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY
10+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
11+
LAST_AGENTIC_SEARCH_ADDITIONAL_INSTRUCTIONS_STATE_KEY
1112
} from '@/constants/state-keys'
1213
import { extract_paths_from_bullet_list } from '@/utils/extract-paths-from-bullet-list'
1314
import { get_all_workspace_files } from '@/context/helpers/get-all-workspace-files'
1415
import { show_search_results_quick_pick } from '@/features/search-files/utils/show-search-results-quick-pick'
1516
import { prompt_for_search_term } from './utils/prompt-for-search-term'
17+
import { prompt_for_additional_instructions } from './utils/prompt-for-additional-instructions'
1618
import { build_agent_prompt } from './utils/build-agent-prompt'
1719
import { replace_symbols } from '@/views/prompt/backend/utils/symbols/replace-symbols'
1820
import { search_files } from '@/features/search-files'
@@ -90,15 +92,55 @@ export const agentic_search = async (params: {
9092
target_folder: params.folder_path,
9193
build_prompt: async () => {
9294
while (true) {
95+
let current_query = query
96+
9397
if (
9498
first_run &&
9599
params.skip_prompt_if_not_empty &&
96100
query.trim() !== ''
97101
) {
102+
const last_additional =
103+
params.extension_context.workspaceState.get<string>(
104+
LAST_AGENTIC_SEARCH_ADDITIONAL_INSTRUCTIONS_STATE_KEY
105+
) || ''
106+
const additional_instructions_result =
107+
await prompt_for_additional_instructions({
108+
show_back_button: true,
109+
initial_value: last_additional,
110+
on_change: (value) => {
111+
params.extension_context.workspaceState.update(
112+
LAST_AGENTIC_SEARCH_ADDITIONAL_INSTRUCTIONS_STATE_KEY,
113+
value
114+
)
115+
}
116+
})
117+
118+
if (additional_instructions_result.back) {
119+
return 'back'
120+
}
121+
122+
if (additional_instructions_result.value === undefined) {
123+
return undefined
124+
}
125+
98126
first_run = false
127+
128+
if (additional_instructions_result.value.trim() !== '') {
129+
current_query = `${query}\n\nAdditional instructions:\n${additional_instructions_result.value}`
130+
}
99131
} else {
100132
const query_result = await prompt_for_search_term(query, {
101-
show_back_button: true
133+
show_back_button: true,
134+
on_change: (value) => {
135+
query = value
136+
params.extension_context.workspaceState.update(
137+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
138+
{
139+
instructions: params.current_instructions,
140+
query: value
141+
}
142+
)
143+
}
102144
})
103145

104146
if (query_result.back) {
@@ -109,23 +151,25 @@ export const agentic_search = async (params: {
109151
return undefined
110152
}
111153

154+
first_run = false
155+
112156
query = query_result.value
157+
current_query = query
113158
}
114-
first_run = false
115159

116-
if (query.trim() === '') {
160+
if (current_query.trim() === '') {
117161
continue
118162
}
119163

120164
await params.extension_context.workspaceState.update(
121165
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
122166
{
123167
instructions: params.current_instructions,
124-
query
168+
query: current_query
125169
}
126170
)
127171

128-
const instructions_to_process = [query]
172+
const instructions_to_process = [current_query]
129173
if (params.completed_tasks) {
130174
instructions_to_process.push(...params.completed_tasks)
131175
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './build-agent-prompt'
22
export * from './prompt-for-search-term'
3+
export * from './prompt-for-additional-instructions'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as vscode from 'vscode'
2+
import { t } from '@/i18n'
3+
4+
export const prompt_for_additional_instructions = async (options?: {
5+
show_back_button?: boolean
6+
initial_value?: string
7+
on_change?: (value: string) => void
8+
}): Promise<{ value: string | undefined; back?: boolean }> => {
9+
const close_button = {
10+
iconPath: new vscode.ThemeIcon('close'),
11+
tooltip: t('common.close')
12+
}
13+
14+
const input_box = vscode.window.createInputBox()
15+
input_box.title = t('feature.agentic-search.title.agentic-search')
16+
input_box.prompt = t('feature.agentic-search.prompt.additional-instructions')
17+
input_box.placeholder = t(
18+
'feature.agentic-search.placeholder.additional-instructions'
19+
)
20+
input_box.value = ''
21+
22+
if (options?.initial_value) {
23+
input_box.value = options.initial_value
24+
}
25+
26+
const buttons: vscode.QuickInputButton[] = []
27+
if (options?.show_back_button) {
28+
buttons.push(vscode.QuickInputButtons.Back)
29+
}
30+
buttons.push(close_button)
31+
32+
input_box.buttons = buttons
33+
input_box.ignoreFocusOut = true
34+
35+
return new Promise<{ value: string | undefined; back?: boolean }>(
36+
(resolve) => {
37+
let is_resolved = false
38+
const disposables: vscode.Disposable[] = []
39+
40+
disposables.push(
41+
input_box.onDidTriggerButton((button) => {
42+
if (button === vscode.QuickInputButtons.Back) {
43+
is_resolved = true
44+
resolve({ value: undefined, back: true })
45+
input_box.hide()
46+
} else if (button === close_button) {
47+
is_resolved = true
48+
resolve({ value: undefined })
49+
input_box.hide()
50+
}
51+
}),
52+
input_box.onDidChangeValue(() => {
53+
if (options?.on_change) {
54+
options.on_change(input_box.value)
55+
}
56+
}),
57+
input_box.onDidAccept(() => {
58+
const value = input_box.value.trim()
59+
is_resolved = true
60+
resolve({ value })
61+
input_box.hide()
62+
}),
63+
input_box.onDidHide(() => {
64+
if (!is_resolved) {
65+
resolve({ value: undefined })
66+
}
67+
disposables.forEach((d) => d.dispose())
68+
input_box.dispose()
69+
})
70+
)
71+
input_box.show()
72+
}
73+
)
74+
}

‎apps/editor/src/i18n/translations/features/agentic-search.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,41 @@ export const translations = {
1616
cs: 'Agentní vyhledávání',
1717
hu: 'Ügynökkeresés',
1818
bg: 'Агентно търсене'
19+
},
20+
'feature.agentic-search.prompt.additional-instructions': {
21+
en: 'Additional instructions',
22+
pl: 'Dodatkowe instrukcje',
23+
'zh-cn': '附加说明',
24+
ja: '追加の指示',
25+
'zh-tw': '附加說明',
26+
de: 'Zusätzliche Anweisungen',
27+
es: 'Instrucciones adicionales',
28+
fr: 'Instructions supplémentaires',
29+
'pt-br': 'Instruções adicionais',
30+
ru: 'Дополнительные инструкции',
31+
ko: '추가 지침',
32+
it: 'Istruzioni aggiuntive',
33+
tr: 'Ek talimatlar',
34+
cs: 'Další instrukce',
35+
hu: 'További utasítások',
36+
bg: 'Допълнителни инструкции'
37+
},
38+
'feature.agentic-search.placeholder.additional-instructions': {
39+
en: 'Any extra instructions for the search',
40+
pl: 'Dodatkowe instrukcje dla tego wyszukiwania',
41+
'zh-cn': '搜索的任何额外说明',
42+
ja: '検索に関する追加の指示',
43+
'zh-tw': '搜尋的任何額外說明',
44+
de: 'Zusätzliche Anweisungen für die Suche',
45+
es: 'Cualquier instrucción adicional para la búsqueda',
46+
fr: 'Toute instruction supplémentaire pour la recherche',
47+
'pt-br': 'Quaisquer instruções extras para a pesquisa',
48+
ru: 'Любые дополнительные инструкции для поиска',
49+
ko: '검색에 대한 추가 지침',
50+
it: 'Eventuali istruzioni aggiuntive per la ricerca',
51+
tr: 'Arama için ek talimatlar',
52+
cs: 'Jakékoli další instrukce pro vyhledávání',
53+
hu: 'További utasítások a kereséshez',
54+
bg: 'Допълнителни инструкции за търсенето'
1955
}
2056
} as const

‎packages/ui/src/components/editor/settings-view/DefaultConfigurationSelector/DefaultConfigurationSelector.module.scss‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
color: var(--vscode-foreground);
66
}
77

8-
.model {
9-
white-space: nowrap;
10-
overflow: hidden;
11-
text-overflow: ellipsis;
12-
}
13-
148
.description {
159
opacity: var(--dimmed-opacity);
1610
white-space: nowrap;

‎packages/ui/src/components/editor/settings-view/DefaultConfigurationSelector/DefaultConfigurationSelector.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const DefaultConfigurationSelector: React.FC<
4848
title={props.title}
4949
description={
5050
<div className={styles.info}>
51-
<span className={styles.model}>{selected_config.model}</span>
51+
<span>{selected_config.model}</span>
5252
{selected_config.description && (
5353
<span className={styles.description}>
5454
{selected_config.description}

0 commit comments

Comments
 (0)