Skip to content

Commit 0150cb3

Browse files
committed
Allow navigating back from prompt input and support back navigation in agentic CLI prompt builders
- reorder quick picks. Current: [query] -> [list of agents] -> [root folder?]. Expected: [list of agents] -> [root folder?] -> [query] - don't show back arrow on the first 'agents' quick pick, show back arrow on the input query └── apps └── editor └── src ├── commands │ └── agentic-search-command │ ├── agentic-search-command.ts │ └── index.ts ├── constants │ └── state-keys.ts ├── features │ └── agentic-search │ ├── agentic-search-state.ts │ ├── agentic-search.ts │ ├── index.ts │ └── utils │ ├── build-agent-prompt.ts │ ├── index.ts │ └── prompt-for-search-term.ts ├── i18n │ └── translations │ ├── common.ts │ └── utils │ └── agentic-cli-invocation.ts ├── utils │ └── agentic-cli-invocation │ ├── agents │ │ ├── antigravity.ts │ │ ├── claude.ts │ │ ├── codex.ts │ │ ├── cursor.ts │ │ ├── grok.ts │ │ ├── index.ts │ │ └── opencode.ts │ ├── index.ts │ ├── invoke-agentic-cli.ts │ ├── types.ts │ └── utils │ ├── check-command-exists.ts │ ├── format-duration.ts │ ├── generate-diff-markdown.ts │ └── get-progress-dots.ts └── views └── prompt └── backend └── message-handlers └── handle-agentic-search.ts
1 parent 0618fac commit 0150cb3

3 files changed

Lines changed: 76 additions & 43 deletions

File tree

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

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,6 @@ export const agentic_search = async (params: {
3838
let query = params.query
3939

4040
while (true) {
41-
const query_result = await prompt_for_search_term(query)
42-
43-
if (query_result.back) {
44-
return 'back'
45-
}
46-
47-
if (query_result.value === undefined) {
48-
return undefined
49-
}
50-
51-
query = query_result.value
52-
53-
if (query.trim() == '') {
54-
continue
55-
}
56-
57-
await params.extension_context.workspaceState.update(
58-
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
59-
{
60-
instructions: params.current_instructions,
61-
query
62-
}
63-
)
64-
6541
const result = await invoke_agentic_cli({
6642
workspace_provider: params.workspace_provider,
6743
extension_context: params.extension_context,
@@ -70,28 +46,56 @@ export const agentic_search = async (params: {
7046
last_selected_workspace_state_key:
7147
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,
7248
default_agent_key: 'isDefaultForAgenticSearch',
73-
show_back_button: true,
49+
show_back_button: false,
7450
build_prompt: async () => {
75-
const { instructions: processed_queries, skill_definitions } =
76-
await replace_symbols({
77-
instructions: [query],
78-
extension_context: params.extension_context,
79-
workspace_provider: params.workspace_provider,
80-
image_as_paths: true
51+
while (true) {
52+
const query_result = await prompt_for_search_term(query, {
53+
show_back_button: true
8154
})
8255

83-
const processed_query = processed_queries[0]
56+
if (query_result.back) {
57+
return 'back'
58+
}
59+
60+
if (query_result.value === undefined) {
61+
return undefined
62+
}
63+
64+
query = query_result.value
65+
66+
if (query.trim() == '') {
67+
continue
68+
}
69+
70+
await params.extension_context.workspaceState.update(
71+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
72+
{
73+
instructions: params.current_instructions,
74+
query
75+
}
76+
)
8477

85-
const final_query = skill_definitions
86-
? `${processed_query}\n\n${skill_definitions}`
87-
: processed_query
78+
const { instructions: processed_queries, skill_definitions } =
79+
await replace_symbols({
80+
instructions: [query],
81+
extension_context: params.extension_context,
82+
workspace_provider: params.workspace_provider,
83+
image_as_paths: true
84+
})
8885

89-
return build_agent_prompt(final_query)
86+
const processed_query = processed_queries[0]
87+
88+
const final_query = skill_definitions
89+
? `${processed_query}\n\n${skill_definitions}`
90+
: processed_query
91+
92+
return build_agent_prompt(final_query)
93+
}
9094
}
9195
})
9296

9397
if (result === 'back') {
94-
continue
98+
return 'back'
9599
}
96100

97101
if (!result) {

‎apps/editor/src/features/agentic-search/utils/prompt-for-search-term.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { t } from '@/i18n'
33

44
export const prompt_for_search_term = async (
55
initial_search_term: string,
6-
on_change?: (value: string) => void
6+
options?: {
7+
on_change?: (value: string) => void
8+
show_back_button?: boolean
9+
}
710
): Promise<{ value: string | undefined; back?: boolean }> => {
811
const close_button = {
912
iconPath: new vscode.ThemeIcon('close'),
@@ -15,7 +18,14 @@ export const prompt_for_search_term = async (
1518
input_box.prompt = t('feature.search-files.prompt.intelligent')
1619
input_box.placeholder = t('common.action.search')
1720
input_box.value = initial_search_term
18-
input_box.buttons = [close_button]
21+
22+
const buttons: vscode.QuickInputButton[] = []
23+
if (options?.show_back_button) {
24+
buttons.push(vscode.QuickInputButtons.Back)
25+
}
26+
buttons.push(close_button)
27+
28+
input_box.buttons = buttons
1929
input_box.ignoreFocusOut = true
2030

2131
return new Promise<{ value: string | undefined; back?: boolean }>(
@@ -25,7 +35,11 @@ export const prompt_for_search_term = async (
2535

2636
disposables.push(
2737
input_box.onDidTriggerButton((button) => {
28-
if (button === close_button) {
38+
if (button === vscode.QuickInputButtons.Back) {
39+
is_resolved = true
40+
resolve({ value: undefined, back: true })
41+
input_box.hide()
42+
} else if (button === close_button) {
2943
is_resolved = true
3044
resolve({ value: undefined })
3145
input_box.hide()
@@ -47,8 +61,8 @@ export const prompt_for_search_term = async (
4761
if (input_box.value.trim().length > 0) {
4862
input_box.validationMessage = undefined
4963
}
50-
if (on_change) {
51-
on_change(input_box.value)
64+
if (options?.on_change) {
65+
options.on_change(input_box.value)
5266
}
5367
}),
5468
input_box.onDidHide(() => {

‎apps/editor/src/utils/agentic-cli-invocation/invoke-agentic-cli.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const get_output_channel = () => {
2424
export const invoke_agentic_cli = async (params: {
2525
workspace_provider: WorkspaceProvider
2626
extension_context: vscode.ExtensionContext
27-
build_prompt: (selected_root: string) => Promise<string>
27+
build_prompt: (selected_root: string) => Promise<string | 'back' | undefined>
2828
notification_title: string
2929
last_selected_workspace_state_key: string
3030
agent_state_key?: string
@@ -519,6 +519,21 @@ export const invoke_agentic_cli = async (params: {
519519

520520
const final_prompt = await params.build_prompt(selected_root!)
521521

522+
if (final_prompt === 'back') {
523+
if (roots.length === 1 || params.isolate_in_temp_dir) {
524+
go_back_to_agent = true
525+
show_quick_pick = true
526+
current_agent_config_name = undefined
527+
break
528+
} else {
529+
continue
530+
}
531+
}
532+
533+
if (final_prompt === undefined) {
534+
return undefined
535+
}
536+
522537
const temp_prompt_path = path.join(
523538
os.tmpdir(),
524539
`cwc-prompt-${Date.now()}-${Math.floor(Math.random() * 1000)}.md`

0 commit comments

Comments
 (0)