Skip to content

Commit 6cf57b2

Browse files
committed
Enhance agentic search with query persistence per instruction and customizable agent flags
- remember in state a pair: instructions and query. expected behavior: when agentic search open ups, and instructions are the same, restore query. Otherwise use instructions. - flags seem to be broken - highlight last edited agent └── apps └── editor ├── package.json └── src ├── constants │ └── state-keys.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 └── prompt-view-provider.ts
1 parent c12cfff commit 6cf57b2

3 files changed

Lines changed: 164 additions & 13 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,59 @@
989989
"type": "string",
990990
"scope": "resource"
991991
},
992+
"codeWebChat.agenticSearchInstructions": {
993+
"type": "string",
994+
"scope": "resource"
995+
},
996+
"codeWebChat.agenticSearchAntigravityFlags": {
997+
"type": "array",
998+
"scope": "resource",
999+
"items": {
1000+
"type": "string"
1001+
}
1002+
},
1003+
"codeWebChat.agenticSearchClaudeFlags": {
1004+
"type": "array",
1005+
"scope": "resource",
1006+
"items": {
1007+
"type": "string"
1008+
}
1009+
},
1010+
"codeWebChat.agenticSearchCodexFlags": {
1011+
"type": "array",
1012+
"scope": "resource",
1013+
"items": {
1014+
"type": "string"
1015+
}
1016+
},
1017+
"codeWebChat.agenticSearchCursorFlags": {
1018+
"type": "array",
1019+
"scope": "resource",
1020+
"items": {
1021+
"type": "string"
1022+
}
1023+
},
1024+
"codeWebChat.agenticSearchGrokFlags": {
1025+
"type": "array",
1026+
"scope": "resource",
1027+
"items": {
1028+
"type": "string"
1029+
}
1030+
},
1031+
"codeWebChat.agenticSearchMuseFlags": {
1032+
"type": "array",
1033+
"scope": "resource",
1034+
"items": {
1035+
"type": "string"
1036+
}
1037+
},
1038+
"codeWebChat.agenticSearchOpencodeFlags": {
1039+
"type": "array",
1040+
"scope": "resource",
1041+
"items": {
1042+
"type": "string"
1043+
}
1044+
},
9921045
"codeWebChat.editFilesSystemInstructions": {
9931046
"type": "string",
9941047
"scope": "resource"

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

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import * as path from 'path'
66
import * as fs from 'fs'
77
import {
88
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,
9-
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY
9+
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY,
10+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY
1011
} from '@/constants/state-keys'
1112
import { extract_paths_from_bullet_list } from '@/utils/extract-paths-from-bullet-list'
1213
import { get_all_workspace_files } from '@/context/helpers/get-all-workspace-files'
@@ -50,6 +51,7 @@ export const agentic_search = async (params: {
5051
extension_context: vscode.ExtensionContext
5152
websocket_manager: WebSocketManager
5253
query: string
54+
current_instructions: string
5355
}): Promise<
5456
| { selected_paths: string[]; matched_paths: string[]; title: string }
5557
| undefined
@@ -81,8 +83,19 @@ export const agentic_search = async (params: {
8183
continue
8284
}
8385

86+
await params.extension_context.workspaceState.update(
87+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
88+
{
89+
instructions: params.current_instructions,
90+
query
91+
}
92+
)
93+
8494
let go_back_to_query = false
8595

96+
let active_config_key: string | undefined
97+
let active_flag_index: number | undefined
98+
8699
while (true) {
87100
const available_agents = AGENTS.filter((a) => a.is_installed())
88101

@@ -175,17 +188,28 @@ export const agentic_search = async (params: {
175188
const agent_quick_pick = vscode.window.createQuickPick<AgentPickItem>()
176189
agent_quick_pick.items = build_agent_picks()
177190

178-
const last_used_agent =
179-
params.extension_context.workspaceState.get<string>(
180-
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY
181-
)
182-
if (last_used_agent) {
191+
if (active_config_key !== undefined && active_flag_index !== undefined) {
183192
const active_item = agent_quick_pick.items.find(
184-
(i) => i.cmd == last_used_agent
193+
(i) =>
194+
i.configKey === active_config_key &&
195+
i.flag_index === active_flag_index
185196
)
186197
if (active_item) {
187198
agent_quick_pick.activeItems = [active_item]
188199
}
200+
} else {
201+
const last_used_agent =
202+
params.extension_context.workspaceState.get<string>(
203+
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY
204+
)
205+
if (last_used_agent) {
206+
const active_item = agent_quick_pick.items.find(
207+
(i) => i.cmd == last_used_agent
208+
)
209+
if (active_item) {
210+
agent_quick_pick.activeItems = [active_item]
211+
}
212+
}
189213
}
190214

191215
agent_quick_pick.title = t(
@@ -199,7 +223,31 @@ export const agentic_search = async (params: {
199223

200224
const config_listener = vscode.workspace.onDidChangeConfiguration((e) => {
201225
if (e.affectsConfiguration('codeWebChat')) {
226+
const prev_active = agent_quick_pick.activeItems[0]
202227
agent_quick_pick.items = build_agent_picks()
228+
229+
if (
230+
active_config_key !== undefined &&
231+
active_flag_index !== undefined
232+
) {
233+
const item = agent_quick_pick.items.find(
234+
(i) =>
235+
i.configKey === active_config_key &&
236+
i.flag_index === active_flag_index
237+
)
238+
if (item) {
239+
agent_quick_pick.activeItems = [item]
240+
}
241+
} else if (prev_active) {
242+
const item = agent_quick_pick.items.find(
243+
(i) =>
244+
i.configKey === prev_active.configKey &&
245+
i.flag_index === prev_active.flag_index
246+
)
247+
if (item) {
248+
agent_quick_pick.activeItems = [item]
249+
}
250+
}
203251
}
204252
})
205253

@@ -248,6 +296,9 @@ export const agentic_search = async (params: {
248296
resolve({ action: 'add', configKey: e.item.configKey })
249297
agent_quick_pick.hide()
250298
} else if (e.button === delete_button) {
299+
active_config_key = e.item.configKey
300+
active_flag_index = -1
301+
251302
const config = vscode.workspace.getConfiguration('codeWebChat')
252303
const flags = config
253304
.get<string[]>(e.item.configKey, [])
@@ -274,6 +325,9 @@ export const agentic_search = async (params: {
274325
)
275326
.then((choice) => {
276327
if (choice === undo_action) {
328+
active_config_key = e.item.configKey
329+
active_flag_index = e.item.flag_index
330+
277331
const current_config =
278332
vscode.workspace.getConfiguration('codeWebChat')
279333
const current_flags = current_config
@@ -327,6 +381,9 @@ export const agentic_search = async (params: {
327381

328382
if (agent_selection_result.action === 'add') {
329383
const { configKey } = agent_selection_result
384+
active_config_key = configKey
385+
active_flag_index = -1
386+
330387
const new_flags = await vscode.window.showInputBox({
331388
title: t(
332389
'views.prompt.handlers.handle-agentic-search.agent.add-flags'
@@ -345,6 +402,9 @@ export const agentic_search = async (params: {
345402
const flags = config
346403
.get<string[]>(configKey, [])
347404
.filter((f) => f.trim() !== '')
405+
406+
active_flag_index = flags.length
407+
348408
await config.update(
349409
configKey,
350410
[...flags, new_flags],
@@ -356,6 +416,9 @@ export const agentic_search = async (params: {
356416

357417
if (agent_selection_result.action === 'edit') {
358418
const { configKey, index, value } = agent_selection_result
419+
active_config_key = configKey
420+
active_flag_index = index
421+
359422
const new_flags = await vscode.window.showInputBox({
360423
title: t(
361424
'views.prompt.handlers.handle-agentic-search.agent.edit-flags'
@@ -379,6 +442,7 @@ export const agentic_search = async (params: {
379442
new_flags_array[index] = new_flags
380443
} else {
381444
new_flags_array.splice(index, 1)
445+
active_flag_index = -1
382446
}
383447
await config.update(
384448
configKey,
@@ -495,10 +559,27 @@ export const agentic_search = async (params: {
495559

496560
const custom_args: string[] = []
497561
if (flags_string.trim()) {
498-
const regex = /([^\s'"]+)|"([^"]*)"|'([^']*)'/g
499-
let match
500-
while ((match = regex.exec(flags_string)) !== null) {
501-
custom_args.push(match[1] || match[2] || match[3])
562+
let current_arg = ''
563+
let in_single_quote = false
564+
let in_double_quote = false
565+
566+
for (let i = 0; i < flags_string.length; i++) {
567+
const char = flags_string[i]
568+
if (char === "'" && !in_double_quote) {
569+
in_single_quote = !in_single_quote
570+
} else if (char === '"' && !in_single_quote) {
571+
in_double_quote = !in_double_quote
572+
} else if (char === ' ' && !in_single_quote && !in_double_quote) {
573+
if (current_arg.length > 0) {
574+
custom_args.push(current_arg)
575+
current_arg = ''
576+
}
577+
} else {
578+
current_arg += char
579+
}
580+
}
581+
if (current_arg.length > 0) {
582+
custom_args.push(current_arg)
502583
}
503584
}
504585

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PromptViewProvider } from '../../prompt-view-provider'
33
import { Logger } from '@shared/utils/logger'
44
import { t } from '@/i18n'
55
import { agentic_search } from './agentic-search'
6+
import { LAST_AGENTIC_SEARCH_QUERY_STATE_KEY } from '@/constants/state-keys'
67

78
let agentic_search_in_progress = false
89

@@ -16,15 +17,31 @@ export const handle_agentic_search = async (
1617
return
1718
}
1819

19-
const query = prompt_view_provider.current_instructions
20+
const current_instructions = prompt_view_provider.current_instructions
21+
22+
const last_query_state =
23+
prompt_view_provider.extension_context.workspaceState.get<{
24+
instructions: string
25+
query: string
26+
}>(LAST_AGENTIC_SEARCH_QUERY_STATE_KEY)
27+
28+
let initial_query = current_instructions
29+
if (
30+
last_query_state &&
31+
typeof last_query_state === 'object' &&
32+
last_query_state.instructions === current_instructions
33+
) {
34+
initial_query = last_query_state.query
35+
}
2036

2137
agentic_search_in_progress = true
2238
try {
2339
const result = await agentic_search({
2440
workspace_provider: prompt_view_provider.workspace_provider,
2541
extension_context: prompt_view_provider.extension_context,
2642
websocket_manager: prompt_view_provider.websocket_server_instance,
27-
query
43+
query: initial_query,
44+
current_instructions
2845
})
2946

3047
if (!result || result === 'back') return

0 commit comments

Comments
 (0)