Skip to content

Commit 6f4f89f

Browse files
committed
Add search term prompting and improve navigation loops in agentic search
- agentic search should use [Fragment] instead of asking the user - should display the instructions for the user as a proper first step in the flow to confirm/edit, only then show available agents to select [Commit] - agentic search should copy the instructions, not use reference (as changing input box value incorrectly propagates into the provider) - esc key should move back if possible, not close - don't prevent outside clicks in the flow └── apps └── editor └── src ├── i18n │ └── translations │ └── views │ └── prompt │ └── handlers │ └── handle-agentic-search.ts └── views └── prompt └── backend ├── message-handlers │ └── handle-agentic-search │ ├── agentic-search.ts │ ├── agents │ │ ├── antigravity.ts │ │ ├── claude.ts │ │ ├── codex.ts │ │ ├── cursor.ts │ │ ├── grok.ts │ │ ├── muse.ts │ │ └── opencode.ts │ ├── handle-agentic-search.ts │ ├── index.ts │ ├── types.ts │ └── utils │ ├── build-agent-prompt.ts │ ├── check-command-exists.ts │ ├── format-duration.ts │ ├── get-progress-dots.ts │ ├── index.ts │ ├── prompt-for-search-term.ts │ └── show-search-results-quick-pick.ts └── prompt-view-provider.ts
1 parent 30e4703 commit 6f4f89f

5 files changed

Lines changed: 116 additions & 15 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agentic-search.ts‎

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { extract_paths_from_bullet_list } from '@/utils/extract-paths-from-bulle
1212
import { get_all_workspace_files } from '@/context/helpers/get-all-workspace-files'
1313
import { Logger } from '@shared/utils/logger'
1414
import { show_search_results_quick_pick } from './utils/show-search-results-quick-pick'
15+
import { prompt_for_search_term } from './utils/prompt-for-search-term'
1516
import { antigravity_agent } from './agents/antigravity'
1617
import { claude_agent } from './agents/claude'
1718
import { codex_agent } from './agents/codex'
@@ -57,10 +58,29 @@ export const agentic_search = async (params: {
5758
}
5859

5960
const output_channel = get_output_channel()
60-
const query = params.query
61+
let query = params.query
6162

6263
while (true) {
63-
const available_agents = AGENTS.filter((a) => a.is_installed())
64+
const query_result = await prompt_for_search_term(query)
65+
66+
if (query_result.back) {
67+
return 'back'
68+
}
69+
70+
if (query_result.value === undefined) {
71+
return undefined
72+
}
73+
74+
query = query_result.value
75+
76+
if (query.trim() == '') {
77+
continue
78+
}
79+
80+
let go_back_to_query = false
81+
82+
while (true) {
83+
const available_agents = AGENTS.filter((a) => a.is_installed())
6484

6585
if (available_agents.length == 0) {
6686
vscode.window.showInformationMessage(
@@ -160,7 +180,7 @@ export const agentic_search = async (params: {
160180
agent_quick_pick.placeholder = t(
161181
'views.prompt.handlers.handle-agentic-search.agent.select-agent-placeholder'
162182
)
163-
agent_quick_pick.buttons = [close_button]
183+
agent_quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
164184
agent_quick_pick.ignoreFocusOut = true
165185

166186
const config_listener = vscode.workspace.onDidChangeConfiguration(
@@ -183,7 +203,11 @@ export const agentic_search = async (params: {
183203
let is_resolved = false
184204

185205
agent_quick_pick.onDidTriggerButton((button) => {
186-
if (button === close_button) {
206+
if (button === vscode.QuickInputButtons.Back) {
207+
is_resolved = true
208+
resolve('back')
209+
agent_quick_pick.hide()
210+
} else if (button === close_button) {
187211
is_resolved = true
188212
resolve(undefined)
189213
agent_quick_pick.hide()
@@ -272,7 +296,7 @@ export const agentic_search = async (params: {
272296

273297
agent_quick_pick.onDidHide(() => {
274298
if (!is_resolved) {
275-
resolve(undefined)
299+
resolve('back')
276300
}
277301
config_listener.dispose()
278302
agent_quick_pick.dispose()
@@ -282,7 +306,12 @@ export const agentic_search = async (params: {
282306
}
283307
)
284308

285-
if (!agent_selection_result || agent_selection_result === 'back') {
309+
if (agent_selection_result === 'back') {
310+
go_back_to_query = true
311+
break
312+
}
313+
314+
if (!agent_selection_result) {
286315
return undefined
287316
}
288317

@@ -557,11 +586,13 @@ export const agentic_search = async (params: {
557586
vscode.window.showErrorMessage(
558587
t('views.prompt.handlers.handle-agentic-search.error.failed', { error: String(err) })
559588
)
560-
return undefined
589+
go_back_to_query = true
590+
break
561591
}
562592

563593
if (is_cancelled) {
564-
return undefined
594+
go_back_to_query = true
595+
break
565596
}
566597

567598
const duration = format_duration(Date.now() - start_time)
@@ -573,7 +604,8 @@ export const agentic_search = async (params: {
573604
vscode.window.showInformationMessage(
574605
t('views.prompt.handlers.handle-agentic-search.info.no-files')
575606
)
576-
return undefined
607+
go_back_to_query = true
608+
break
577609
}
578610

579611
const all_workspace_files = await get_all_workspace_files({
@@ -605,7 +637,8 @@ export const agentic_search = async (params: {
605637
vscode.window.showInformationMessage(
606638
t('views.prompt.handlers.handle-agentic-search.info.no-files')
607639
)
608-
return undefined
640+
go_back_to_query = true
641+
break
609642
}
610643

611644
let should_go_back_to_workspace = false
@@ -658,5 +691,12 @@ export const agentic_search = async (params: {
658691
break
659692
}
660693

694+
if (go_back_to_query) {
695+
continue
696+
}
697+
698+
break
699+
}
700+
661701
return undefined
662702
}

‎apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/handle-agentic-search.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export const handle_agentic_search = async (
1717
}
1818

1919
const query = prompt_view_provider.current_instructions
20-
if (query.trim() === '') {
21-
vscode.window.showErrorMessage(t('feature.search-files.validation-empty'))
22-
return
23-
}
2420

2521
agentic_search_in_progress = true
2622
try {

‎apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/utils/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './build-agent-prompt'
22
export * from './check-command-exists'
33
export * from './format-duration'
44
export * from './get-progress-dots'
5+
export * from './prompt-for-search-term'
56
export * from './show-search-results-quick-pick'
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as vscode from 'vscode'
2+
import { t } from '@/i18n'
3+
4+
export const prompt_for_search_term = async (
5+
initial_search_term: string,
6+
on_change?: (value: string) => void
7+
): Promise<{ value: string | undefined; back?: boolean }> => {
8+
const close_button = {
9+
iconPath: new vscode.ThemeIcon('close'),
10+
tooltip: t('common.close')
11+
}
12+
13+
const input_box = vscode.window.createInputBox()
14+
input_box.title = t('views.prompt.handlers.handle-agentic-search.title')
15+
input_box.prompt = t('feature.search-files.prompt.intelligent')
16+
input_box.placeholder = t('feature.search-files.placeholder')
17+
input_box.value = initial_search_term
18+
input_box.buttons = [close_button]
19+
20+
return new Promise<{ value: string | undefined; back?: boolean }>(
21+
(resolve) => {
22+
let is_resolved = false
23+
const disposables: vscode.Disposable[] = []
24+
25+
disposables.push(
26+
input_box.onDidTriggerButton((button) => {
27+
if (button === close_button) {
28+
is_resolved = true
29+
resolve({ value: undefined })
30+
input_box.hide()
31+
}
32+
}),
33+
input_box.onDidAccept(() => {
34+
const value = input_box.value.trim()
35+
if (value.length == 0) {
36+
input_box.validationMessage = t(
37+
'feature.search-files.validation-empty'
38+
)
39+
return
40+
}
41+
is_resolved = true
42+
resolve({ value })
43+
input_box.hide()
44+
}),
45+
input_box.onDidChangeValue(() => {
46+
if (input_box.value.trim().length > 0) {
47+
input_box.validationMessage = undefined
48+
}
49+
if (on_change) {
50+
on_change(input_box.value)
51+
}
52+
}),
53+
input_box.onDidHide(() => {
54+
if (!is_resolved) {
55+
resolve({ value: undefined })
56+
}
57+
disposables.forEach((d) => d.dispose())
58+
input_box.dispose()
59+
})
60+
)
61+
input_box.show()
62+
}
63+
)
64+
}

‎apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/utils/show-search-results-quick-pick.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const show_search_results_quick_pick = async (params: {
121121
quick_pick.onDidHide(() => {
122122
if (is_showing_folder_quick_pick) return
123123
if (!is_resolved) {
124-
resolve('back')
124+
resolve(params.show_back_button ? 'back' : undefined)
125125
}
126126
quick_pick.dispose()
127127
})

0 commit comments

Comments
 (0)