Skip to content

Commit 678f775

Browse files
committed
Refactor agentic search utilities into separate files, relocate shared quick-pick functions to the global utils directory, and clean up leftover agent mode configurations from search files
- remove unused translations - agentic search should not depend on 'search files' feature. Make necessary code duplications, as needed. - place all utils in `apps/editor/src/commands/agentic-search-command/utils` - move shared utils to `apps/editor/src/utils` - the beginning input field should not have back arrow (as it's first item in the flow) - adjust state key names used by `apps/editor/src/commands/agentic-search-command/agentic-search-command.ts` (the command was derived from search files command and is now standalone) ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── agentic-search-command │ │ │ ├── agentic-search-command.ts │ │ │ ├── agentic-search.ts │ │ │ ├── agents │ │ │ │ ├── antigravity.ts │ │ │ │ ├── claude.ts │ │ │ │ ├── codex.ts │ │ │ │ ├── cursor.ts │ │ │ │ ├── grok.ts │ │ │ │ ├── muse.ts │ │ │ │ └── opencode.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 │ │ │ └── utils.ts │ │ └── search-files-commands │ │ ├── index.ts │ │ ├── search-files-commands.ts │ │ └── utils │ │ ├── get-target-folder-path.ts │ │ └── prompt-for-provided-results.ts │ ├── constants │ │ ├── instructions.ts │ │ └── state-keys.ts │ ├── context │ │ ├── helpers │ │ │ └── get-all-workspace-files.ts │ │ └── providers │ │ └── workspace │ │ └── workspace-provider.ts │ ├── features │ │ └── search-files │ │ ├── index.ts │ │ ├── search-files.ts │ │ ├── search-modes │ │ │ ├── perform-intelligent-search-mode.ts │ │ │ ├── perform-keywords-search-mode.ts │ │ │ └── perform-phrase-search-mode.ts │ │ └── utils │ │ ├── analyze-files.ts │ │ ├── check-matches-condition.ts │ │ ├── create-search-regex.ts │ │ ├── prompt-for-config.ts │ │ ├── prompt-for-intelligent-search-results.ts │ │ ├── prompt-for-keywords-match-mode.ts │ │ ├── prompt-for-keywords-target.ts │ │ ├── prompt-for-search-mode.ts │ │ ├── prompt-for-search-results.ts │ │ ├── prompt-for-search-term.ts │ │ ├── prompt-for-shrink-mode.ts │ │ ├── search-files-by-intelligent.ts │ │ ├── search-files-by-keywords.ts │ │ ├── search-files-by-phrase.ts │ │ └── show-search-results-quick-pick.ts │ ├── i18n │ │ ├── index.ts │ │ └── translations │ │ ├── commands │ │ │ └── search-files.ts │ │ └── features │ │ └── search-files.ts │ └── utils │ ├── ascii-tree │ │ ├── ascii-tree.ts │ │ ├── index.ts │ │ └── utils.ts │ ├── cleanup-api-response │ │ ├── cleanup-api-response.spec.ts │ │ ├── cleanup-api-response.ts │ │ ├── index.ts │ │ └── test-cases │ │ ├── extract-code-block-surrounded-by-text │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── extract-markdown-with-surrounding-text │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── keep-think-block-not-at-start │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── markdown-block │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── plain-text │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-doctype │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-file-tags │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-files-tags │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-markdown-wrapper │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-markdown-wrapper-with-lang │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-think-block-at-start │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-think-block-with-newlines │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ ├── remove-thought-block-at-start │ │ │ ├── expected.txt │ │ │ └── input.txt │ │ └── trim-whitespace │ │ ├── expected.txt │ │ └── input.txt │ ├── extract-paths-from-bullet-list.ts │ ├── group-quick-pick-items.ts │ ├── handle-parent-folder-result.ts │ ├── is-binary.ts │ ├── map-files-to-quick-pick-items.ts │ └── show-parent-folder-quick-pick.ts └── packages └── shared └── src └── utils ├── display-token-count.ts └── logger.ts
1 parent cba3ac0 commit 678f775

18 files changed

Lines changed: 350 additions & 569 deletions

‎apps/editor/src/commands/agentic-search-command/agentic-search.ts‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { spawn } from 'child_process'
55
import * as path from 'path'
66
import * as fs from 'fs'
77
import {
8-
LAST_SELECTED_WORKSPACE_IN_AGENT_SEARCH_STATE_KEY,
9-
LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY,
10-
LAST_USED_SEARCH_FILES_AGENT_STATE_KEY
8+
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,
9+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
10+
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY
1111
} from '@/constants/state-keys'
1212
import { extract_paths_from_bullet_list } from '@/utils/extract-paths-from-bullet-list'
1313
import { get_all_workspace_files } from '@/context/helpers/get-all-workspace-files'
1414
import { Logger } from '@shared/utils/logger'
15-
import { show_search_results_quick_pick } from '@/features/search-files/utils/show-search-results-quick-pick'
16-
import { prompt_for_search_term } from '@/features/search-files/utils/prompt-for-search-term'
15+
import { show_search_results_quick_pick } from './utils/show-search-results-quick-pick'
16+
import { prompt_for_search_term } from './utils/prompt-for-search-term'
1717
import { antigravity_agent } from './agents/antigravity'
1818
import { claude_agent } from './agents/claude'
1919
import { codex_agent } from './agents/codex'
@@ -64,20 +64,18 @@ export const agentic_search = async (params: {
6464
{
6565
while (true) {
6666
const initial_query =
67-
local_queries[LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY] !== undefined
68-
? local_queries[LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY]
67+
local_queries[LAST_AGENTIC_SEARCH_QUERY_STATE_KEY] !== undefined
68+
? local_queries[LAST_AGENTIC_SEARCH_QUERY_STATE_KEY]
6969
: params.extension_context.workspaceState.get<string>(
70-
LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY
70+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY
7171
) || ''
7272

7373
const query_result = await prompt_for_search_term(
7474
initial_query,
75-
'agent',
76-
undefined,
7775
(value) => {
78-
local_queries[LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY] = value
76+
local_queries[LAST_AGENTIC_SEARCH_QUERY_STATE_KEY] = value
7977
params.extension_context.workspaceState.update(
80-
LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY,
78+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
8179
value
8280
)
8381
}
@@ -97,9 +95,9 @@ export const agentic_search = async (params: {
9795
continue
9896
}
9997

100-
local_queries[LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY] = query
98+
local_queries[LAST_AGENTIC_SEARCH_QUERY_STATE_KEY] = query
10199
await params.extension_context.workspaceState.update(
102-
LAST_SEARCH_FILES_AGENT_QUERY_STATE_KEY,
100+
LAST_AGENTIC_SEARCH_QUERY_STATE_KEY,
103101
query
104102
)
105103

@@ -191,7 +189,7 @@ export const agentic_search = async (params: {
191189

192190
const last_used_agent =
193191
params.extension_context.workspaceState.get<string>(
194-
LAST_USED_SEARCH_FILES_AGENT_STATE_KEY
192+
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY
195193
)
196194
if (last_used_agent) {
197195
const active_item = agent_quick_pick.items.find(
@@ -397,7 +395,7 @@ export const agentic_search = async (params: {
397395
const flags_string = agent_selection_result.flag_value
398396

399397
await params.extension_context.workspaceState.update(
400-
LAST_USED_SEARCH_FILES_AGENT_STATE_KEY,
398+
LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY,
401399
selected_agent_cmd
402400
)
403401

@@ -417,7 +415,7 @@ export const agentic_search = async (params: {
417415

418416
const last_selected_root =
419417
params.extension_context.workspaceState.get<string>(
420-
LAST_SELECTED_WORKSPACE_IN_AGENT_SEARCH_STATE_KEY
418+
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY
421419
)
422420
const active_item =
423421
picks.find((p) => p.root == last_selected_root) || picks[0]
@@ -483,7 +481,7 @@ export const agentic_search = async (params: {
483481

484482
selected_root = res
485483
await params.extension_context.workspaceState.update(
486-
LAST_SELECTED_WORKSPACE_IN_AGENT_SEARCH_STATE_KEY,
484+
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,
487485
selected_root
488486
)
489487
}
@@ -677,14 +675,12 @@ export const agentic_search = async (params: {
677675
| undefined
678676

679677
while (true) {
680-
const selected_items = (await show_search_results_quick_pick({
678+
const selected_items = await show_search_results_quick_pick({
681679
matched_items: absolute_paths.map((path) => ({ path })),
682-
unmatched_checked_paths: [],
683680
workspace_provider: params.workspace_provider,
684681
title: t('command.agentic-search.results'),
685-
show_back_button: true,
686-
hide_search_in_results_button: true
687-
})) as any
682+
show_back_button: true
683+
})
688684

689685
if (selected_items == 'back') {
690686
should_go_back_to_workspace = true

‎apps/editor/src/commands/agentic-search-command/utils.ts‎

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode'
2+
import {
3+
ai_file_search_format_instructions,
4+
agentic_search_task_instructions
5+
} from '@/constants/instructions'
6+
7+
export const build_agent_prompt = (query: string) => {
8+
const config = vscode.workspace.getConfiguration('codeWebChat')
9+
const task_instructions =
10+
config.get<string>('agenticSearchInstructions') ||
11+
agentic_search_task_instructions
12+
13+
return `# Task\n\n${task_instructions}\n\n# Output formatting\n\n${ai_file_search_format_instructions}\n\n# Query\n\n${query}`
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { execSync } from 'child_process'
2+
import * as os from 'os'
3+
4+
export const check_command_exists = (cmd: string): boolean => {
5+
try {
6+
const is_windows = os.platform() == 'win32'
7+
execSync(`${is_windows ? 'where' : 'command -v'} ${cmd}`, {
8+
stdio: 'ignore'
9+
})
10+
return true
11+
} catch (e) {
12+
return false
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const format_duration = (ms: number): string => {
2+
const total_seconds = Math.round(ms / 1000)
3+
const hours = Math.floor(total_seconds / 3600)
4+
const minutes = Math.floor((total_seconds % 3600) / 60)
5+
const seconds = total_seconds % 60
6+
7+
const parts = []
8+
if (hours > 0) parts.push(`${hours}h`)
9+
if (minutes > 0 || (hours > 0 && seconds > 0)) parts.push(`${minutes}m`)
10+
if (seconds > 0 || (hours === 0 && minutes === 0)) parts.push(`${seconds}s`)
11+
12+
return parts.join(' ')
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const get_progress_dots = (action_count: number): string => {
2+
const cycle = (action_count - 1) % 3
3+
if (cycle === 0) return '...'
4+
if (cycle === 1) return '....'
5+
return '..'
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from './build-agent-prompt'
2+
export * from './check-command-exists'
3+
export * from './format-duration'
4+
export * from './get-progress-dots'
5+
export * from './prompt-for-search-term'
6+
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('feature.search-files.title.agent')
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.ignoreFocusOut = true
19+
input_box.buttons = [close_button]
20+
21+
return new Promise<{ value: string | undefined; back?: boolean }>(
22+
(resolve) => {
23+
let is_resolved = false
24+
const disposables: vscode.Disposable[] = []
25+
26+
disposables.push(
27+
input_box.onDidTriggerButton((button) => {
28+
if (button === close_button) {
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+
}

0 commit comments

Comments
 (0)