Skip to content

Commit 3146f1f

Browse files
committed
Refactor perform agent search mode to use a modular structure with dedicated files for each coding agent
- place `apps/editor/src/features/search-files/search-modes/perform-agent-search-mode.ts` in a folder of the same name, create a shared interface for various logic blocks of each supported coding agent (this task is purely architectural) - when comparing to strings, use '==', not '===' - refer to 'agy' as 'antigravity' (id/filename, etc.) (command is still agy though) └── apps ├── browser │ └── src │ └── content-scripts │ └── send-prompt-content-script │ ├── chatbots │ │ ├── chatgpt.ts │ │ └── claude.ts │ ├── constants │ │ ├── apply-response-icon.ts │ │ └── dictionary.ts │ ├── types │ │ └── chatbot.ts │ └── utils │ ├── add-apply-response-button.ts │ ├── apply-response-styles.ts │ ├── logger.ts │ ├── report-initialization-error.ts │ └── show-response-ready-notification.ts └── editor └── src └── features └── search-files └── search-modes └── perform-agent-search-mode ├── agents │ ├── antigravity.ts │ ├── claude.ts │ ├── codex.ts │ └── opencode.ts ├── index.ts ├── types.ts └── utils.ts
1 parent 9cf2dc6 commit 3146f1f

7 files changed

Lines changed: 373 additions & 203 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { agentic_file_search_instructions } from '@/constants/instructions'
2+
import { CodingAgent } from '../types'
3+
import { check_command_exists } from '../utils'
4+
5+
export const antigravity_agent: CodingAgent = {
6+
id: 'antigravity',
7+
label: 'Antigravity',
8+
cmd: 'agy',
9+
executable: 'agy',
10+
is_installed: () => check_command_exists('agy'),
11+
get_documentation_url: () => 'https://antigravity.google/docs/cli/headless/',
12+
get_args: (query: string) => [
13+
'-p',
14+
`${agentic_file_search_instructions}\n\n${query}`,
15+
'--output-format',
16+
'stream-json',
17+
'--dangerously-skip-permissions'
18+
],
19+
parse_stream_line: (parsed, report_progress) => {
20+
if (parsed.event == 'step_update' && parsed.step_update) {
21+
const step = parsed.step_update
22+
if (step.step_type == 'tool') {
23+
const tool_name = step.tool_name || step.tool_info?.name
24+
if (tool_name) {
25+
let msg = `Using ${tool_name.replace(/_/g, ' ')}...`
26+
const params = step.tool_info?.parameters
27+
28+
if (params) {
29+
if (
30+
tool_name == 'run_command' &&
31+
(params.CommandLine || params.command)
32+
) {
33+
msg = `Running: ${params.CommandLine || params.command}`
34+
} else if (tool_name == 'read_file' && params.path) {
35+
msg = `Reading: ${params.path}`
36+
} else if (
37+
(tool_name == 'write_file' || tool_name == 'write_to_file') &&
38+
params.path
39+
) {
40+
msg = `Writing: ${params.path}`
41+
} else if (tool_name == 'list_directory' && params.path) {
42+
msg = `Listing: ${params.path}`
43+
} else if (
44+
tool_name == 'search_files' &&
45+
(params.query || params.pattern)
46+
) {
47+
msg = `Searching: ${params.query || params.pattern}`
48+
}
49+
}
50+
51+
if (msg.length > 60) {
52+
msg = msg.substring(0, 57) + '...'
53+
}
54+
report_progress(msg)
55+
}
56+
} else if (step.subagent_info?.subagents?.length > 0) {
57+
const subagent = step.subagent_info.subagents[0]
58+
report_progress(
59+
`Delegating to ${subagent.role || subagent.type_name}...`
60+
)
61+
} else if (step.step_type == 'agent_response') {
62+
report_progress('Synthesizing results...')
63+
}
64+
} else if (parsed.event == 'result' && parsed.result) {
65+
return { output: parsed.result.response || '' }
66+
}
67+
},
68+
parse_final_output: (parsed, current_output) => {
69+
if (parsed.event == 'result' && parsed.result) {
70+
return parsed.result.response || ''
71+
} else if (parsed.response) {
72+
return parsed.response || ''
73+
}
74+
return current_output
75+
}
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { agentic_file_search_instructions } from '@/constants/instructions'
2+
import { CodingAgent } from '../types'
3+
import { check_command_exists } from '../utils'
4+
5+
export const claude_agent: CodingAgent = {
6+
id: 'claude',
7+
label: 'Claude Code',
8+
cmd: 'claude',
9+
executable: 'claude',
10+
is_installed: () => check_command_exists('claude'),
11+
get_documentation_url: () => 'https://code.claude.com/docs/en/headless',
12+
get_args: (query: string) => [
13+
'--bare',
14+
'-p',
15+
`${agentic_file_search_instructions}\n\n${query}`,
16+
'--output-format',
17+
'stream-json',
18+
'--verbose',
19+
'--permission-mode',
20+
'auto',
21+
'--include-partial-messages'
22+
],
23+
parse_stream_line: (parsed, report_progress) => {
24+
if (parsed.type == 'stream_event' && parsed.event) {
25+
if (
26+
parsed.event.type == 'content_block_start' &&
27+
parsed.event.content_block?.type == 'tool_use'
28+
) {
29+
const tool_name = parsed.event.content_block.name
30+
if (tool_name) {
31+
report_progress(`Using ${tool_name.replace(/_/g, ' ')}...`)
32+
}
33+
}
34+
} else if (parsed.type == 'result' && parsed.result) {
35+
return {
36+
output:
37+
typeof parsed.result == 'string'
38+
? parsed.result
39+
: parsed.result.text || ''
40+
}
41+
} else if (parsed.result) {
42+
return {
43+
output:
44+
typeof parsed.result == 'string'
45+
? parsed.result
46+
: parsed.result.text || ''
47+
}
48+
}
49+
},
50+
parse_final_output: (parsed, current_output) => {
51+
if (parsed.type == 'result' && parsed.result) {
52+
return typeof parsed.result == 'string'
53+
? parsed.result
54+
: parsed.result.text || ''
55+
} else if (parsed.result) {
56+
return typeof parsed.result == 'string'
57+
? parsed.result
58+
: parsed.result.text || ''
59+
}
60+
return current_output
61+
}
62+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { agentic_file_search_instructions } from '@/constants/instructions'
2+
import { CodingAgent } from '../types'
3+
import { check_command_exists } from '../utils'
4+
5+
export const codex_agent: CodingAgent = {
6+
id: 'codex',
7+
label: 'Codex',
8+
cmd: 'codex',
9+
executable: 'codex',
10+
is_installed: () => check_command_exists('codex'),
11+
get_documentation_url: () =>
12+
'https://learn.chatgpt.com/docs/non-interactive-mode',
13+
get_args: (query: string) => [
14+
'exec',
15+
`${agentic_file_search_instructions}\n\n${query}`,
16+
'--json'
17+
],
18+
parse_stream_line: (parsed, report_progress) => {
19+
if (parsed.type == 'item.started' && parsed.item) {
20+
const item = parsed.item
21+
let msg = ''
22+
if (item.type == 'command_execution' && item.command) {
23+
msg = `Running: ${item.command}`
24+
} else if (item.type) {
25+
msg = `Running ${item.type.replace(/_/g, ' ')}...`
26+
}
27+
if (msg) {
28+
if (msg.length > 60) {
29+
msg = msg.substring(0, 57) + '...'
30+
}
31+
report_progress(msg)
32+
}
33+
} else if (parsed.type == 'item.completed' && parsed.item) {
34+
if (parsed.item.type == 'agent_message' && parsed.item.text) {
35+
return { output: parsed.item.text }
36+
}
37+
}
38+
},
39+
parse_final_output: (parsed, current_output) => {
40+
if (
41+
parsed.type == 'item.completed' &&
42+
parsed.item?.type == 'agent_message' &&
43+
parsed.item.text
44+
) {
45+
return parsed.item.text
46+
}
47+
return current_output
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { agentic_file_search_instructions } from '@/constants/instructions'
2+
import { CodingAgent } from '../types'
3+
import { check_command_exists } from '../utils'
4+
5+
export const opencode_agent: CodingAgent = {
6+
id: 'opencode',
7+
label: 'OpenCode',
8+
cmd: 'opencode',
9+
executable: 'opencode',
10+
is_installed: () => check_command_exists('opencode'),
11+
get_documentation_url: () => 'https://github.com/opencode/opencode',
12+
get_args: (query: string) => [
13+
'run',
14+
`${agentic_file_search_instructions}\n\n${query}`,
15+
'--format',
16+
'json',
17+
'--auto'
18+
],
19+
parse_stream_line: (parsed, report_progress) => {
20+
if (parsed.type == 'tool_call' && parsed.tool) {
21+
report_progress(`Using ${parsed.tool}...`)
22+
} else if (parsed.type == 'result' && parsed.result) {
23+
return {
24+
output:
25+
typeof parsed.result == 'string'
26+
? parsed.result
27+
: parsed.result.text || ''
28+
}
29+
} else if (parsed.text) {
30+
return { output: parsed.text }
31+
} else if (parsed.output) {
32+
return {
33+
output:
34+
typeof parsed.output == 'string'
35+
? parsed.output
36+
: parsed.output.text || ''
37+
}
38+
}
39+
},
40+
parse_final_output: (parsed, current_output) => {
41+
if (parsed.type == 'result' && parsed.result) {
42+
return typeof parsed.result == 'string'
43+
? parsed.result
44+
: parsed.result.text || ''
45+
} else if (parsed.text) {
46+
return parsed.text
47+
} else if (parsed.output) {
48+
return typeof parsed.output == 'string'
49+
? parsed.output
50+
: parsed.output.text || ''
51+
}
52+
return current_output
53+
}
54+
}

0 commit comments

Comments
 (0)