Skip to content

Commit fd11d56

Browse files
committed
Extract agent prompt construction into a shared utility function
- the message for agent should be written in markdown in sections '# Task' '# Output formatting', '# Query'. detach 'agentic_file_search_instructions' properly and into 'task instructions' and 'output formatting instructions', don't write markdown headings in `apps/editor/src/constants/instructions.ts` ├── README.md └── apps └── editor └── src ├── constants │ └── instructions.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 ├── types.ts └── utils.ts
1 parent 37a8139 commit fd11d56

9 files changed

Lines changed: 26 additions & 22 deletions

File tree

‎apps/editor/src/constants/instructions.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ These files contain the core greeting logic and module exports.`
8484
export const voice_input_instructions =
8585
'Respond with a transcription of the following audio recording or text "INAUDIBLE", and nothing else.'
8686

87-
export const agentic_file_search_instructions = `In the project, find the complete set of primary and structural file paths relevant to the query, and output strictly as a bulleted list of file paths without explanations or any other text (e.g., - path/to/file.ext).`
87+
export const agentic_file_search_task_instructions =
88+
'In the project, find the complete set of primary and structural file paths relevant to the query.'
89+
90+
export const agentic_file_search_format_instructions =
91+
'Output strictly as a bulleted list of file paths without explanations or any other text (e.g., - path/to/file.ext).'

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/antigravity.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
export const antigravity_agent: CodingAgent = {
65
id: 'antigravity',
@@ -10,7 +9,7 @@ export const antigravity_agent: CodingAgent = {
109
get_documentation_url: () => 'https://antigravity.google/docs/cli/headless/',
1110
get_args: (query: string) => [
1211
'-p',
13-
`${agentic_file_search_instructions}\n\n${query}`,
12+
build_agent_prompt(query),
1413
'--output-format',
1514
'stream-json',
1615
'--dangerously-skip-permissions'

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/claude.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
export const claude_agent: CodingAgent = {
65
id: 'claude',
@@ -11,7 +10,7 @@ export const claude_agent: CodingAgent = {
1110
get_args: (query: string) => [
1211
'--bare',
1312
'-p',
14-
`${agentic_file_search_instructions}\n\n${query}`,
13+
build_agent_prompt(query),
1514
'--output-format',
1615
'stream-json',
1716
'--verbose',

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/codex.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
export const codex_agent: CodingAgent = {
65
id: 'codex',
@@ -11,7 +10,7 @@ export const codex_agent: CodingAgent = {
1110
'https://learn.chatgpt.com/docs/non-interactive-mode',
1211
get_args: (query: string) => [
1312
'exec',
14-
`${agentic_file_search_instructions}\n\n${query}`,
13+
build_agent_prompt(query),
1514
'--json'
1615
],
1716
parse_stream_line: (parsed, report_progress) => {

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/cursor.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
export const cursor_agent: CodingAgent = {
65
id: 'cursor',
@@ -10,7 +9,7 @@ export const cursor_agent: CodingAgent = {
109
get_documentation_url: () => 'https://cursor.com/docs/cli/headless',
1110
get_args: (query: string) => [
1211
'-p',
13-
`${agentic_file_search_instructions}\n\n${query}`,
12+
build_agent_prompt(query),
1413
'--output-format',
1514
'stream-json',
1615
'--force'

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/grok.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
let accumulated_output = ''
65

@@ -14,7 +13,7 @@ export const grok_agent: CodingAgent = {
1413
accumulated_output = ''
1514
return [
1615
'-p',
17-
`${agentic_file_search_instructions}\n\n${query}`,
16+
build_agent_prompt(query),
1817
'--output-format',
1918
'streaming-json',
2019
'--always-approve',

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/muse.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
let accumulated_output = ''
65

@@ -16,7 +15,7 @@ export const muse_agent: CodingAgent = {
1615
'exec',
1716
'--json',
1817
'--yolo',
19-
`${agentic_file_search_instructions}\n\n${query}`
18+
build_agent_prompt(query)
2019
]
2120
},
2221
parse_stream_line: (parsed, report_progress) => {

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/agents/opencode.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { agentic_file_search_instructions } from '@/constants/instructions'
21
import { CodingAgent } from '../types'
3-
import { check_command_exists } from '../utils'
2+
import { build_agent_prompt, check_command_exists } from '../utils'
43

54
export const opencode_agent: CodingAgent = {
65
id: 'opencode',
@@ -10,7 +9,7 @@ export const opencode_agent: CodingAgent = {
109
get_documentation_url: () => 'https://opencode.ai/docs/cli/',
1110
get_args: (query: string) => [
1211
'run',
13-
`${agentic_file_search_instructions}\n\n${query}`,
12+
build_agent_prompt(query),
1413
'--format',
1514
'json',
1615
'--auto'

‎apps/editor/src/features/search-files/search-modes/perform-agent-search-mode/utils.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { execSync } from 'child_process'
22
import * as os from 'os'
3+
import {
4+
agentic_file_search_format_instructions,
5+
agentic_file_search_task_instructions
6+
} from '@/constants/instructions'
7+
8+
export const build_agent_prompt = (query: string) =>
9+
`# Task\n\n${agentic_file_search_task_instructions}\n\n# Output formatting\n\n${agentic_file_search_format_instructions}\n\n# Query\n\n${query}`
310

411
export const check_command_exists = (cmd: string): boolean => {
512
try {

0 commit comments

Comments
 (0)