Skip to content

Commit 22cc637

Browse files
committed
Extract bullet list path parsing into a shared utility function for reuse across search modes
- in `apps/editor/src/features/search-files/search-modes/perform-agent-search-mode`, don't use #Fragment(apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/perform-agent-search-mode.ts:11:10-11:33), instead extract from a bullet list, ideally create a shared util with the command that also extracts from bullet list - paths returned by agent in `apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/perform-agent-search-mode.ts` never include root-folder name prefix - add missing translations #Fragment(apps/editor/src/i18n/translations/features/search-files.ts:1262:3-1266:4) └── apps └── editor └── src ├── commands │ └── apply-response-command │ ├── apply-response-command.ts │ ├── response-processor.ts │ └── utils │ └── response-parser │ ├── index.ts │ ├── parsers │ │ ├── index.ts │ │ └── intelligent-file-search-results-parser │ │ ├── index.ts │ │ └── intelligent-file-search-results-parser.ts │ └── response-parser.ts ├── features │ └── search-files │ └── search-modes │ └── perform-agent-search-mode │ ├── agents │ │ ├── antigravity.ts │ │ ├── claude.ts │ │ ├── codex.ts │ │ ├── cursor.ts │ │ ├── grok.ts │ │ ├── muse.ts │ │ └── opencode.ts │ ├── index.ts │ ├── perform-agent-search-mode.ts │ ├── types.ts │ └── utils.ts ├── i18n │ └── translations │ └── features │ └── search-files.ts └── utils ├── extract-paths-from-bullet-list.ts └── is-binary.ts
1 parent d431ed2 commit 22cc637

5 files changed

Lines changed: 790 additions & 788 deletions

File tree

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/intelligent-file-search-results-parser/intelligent-file-search-results-parser.ts‎

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { extract_paths_from_bullet_list } from '@/utils/extract-paths-from-bullet-list'
2+
13
export type IntelligentFileSearchResultsItem = {
24
type: 'intelligent-file-search-results'
35
file_paths: string[]
@@ -29,60 +31,10 @@ export const parse_intelligent_file_search_results = (params: {
2931
folder_path = folder_match[1]
3032
}
3133

32-
const found_paths = new Set<string>()
33-
const lines = params.response.split('\n')
34-
for (const line of lines) {
35-
const trimmed = line.trim()
36-
if (trimmed.startsWith('-') || trimmed.startsWith('*')) {
37-
let path_str = trimmed.substring(1).trim()
38-
if (path_str.startsWith('`') && path_str.endsWith('`')) {
39-
path_str = path_str.substring(1, path_str.length - 1).trim()
40-
}
41-
if (path_str) {
42-
found_paths.add(path_str.replace(/[.?!]+$/, ''))
43-
}
44-
}
45-
}
46-
47-
const matched_files_with_index = new Map<string, number>()
48-
49-
for (const original_p of found_paths) {
50-
let p = original_p
51-
if (p.startsWith('./')) {
52-
p = p.substring(2)
53-
} else if (p.startsWith('/')) {
54-
p = p.substring(1)
55-
}
56-
while (p.startsWith('/')) {
57-
p = p.substring(1)
58-
}
59-
60-
if (!p || p === '.' || p === '..') continue
61-
62-
let idx = params.response.indexOf(original_p)
63-
if (idx == -1) {
64-
idx = params.response.indexOf(p)
65-
}
66-
const safe_idx = idx != -1 ? idx : Infinity
67-
68-
for (const file of params.workspace_files) {
69-
if (file === p || file.endsWith('/' + p)) {
70-
const current_idx = matched_files_with_index.get(file) ?? Infinity
71-
matched_files_with_index.set(file, Math.min(current_idx, safe_idx))
72-
}
73-
}
74-
}
75-
76-
const valid_paths = Array.from(matched_files_with_index.keys()).sort(
77-
(a, b) => {
78-
const idx_a = matched_files_with_index.get(a) ?? Infinity
79-
const idx_b = matched_files_with_index.get(b) ?? Infinity
80-
if (idx_a == idx_b) {
81-
return a.localeCompare(b)
82-
}
83-
return idx_a - idx_b
84-
}
85-
)
34+
const valid_paths = extract_paths_from_bullet_list({
35+
text: params.response,
36+
workspace_files: params.workspace_files
37+
})
8638

8739
if (valid_paths.length == 0) {
8840
return null

0 commit comments

Comments
 (0)