Skip to content

Commit 4ca3b5e

Browse files
committed
Refactor agentic CLI prompt delivery to stream via stdin or prompt file instead of command-line arguments and remove prompt size limits
- should not use [Fragment] - always include all files - "# Files" section of the constructed markdown can be enormous, in case of CLI, we should pass the prompt as temp-saved md file - "# Files" section of the constructed markdown can be enormous, in case of CLI, we should pass the prompt as temp-saved md file [Pasted text] - should not write [Fragment] in two places - when asking codex, command should be such: cat '/var/....md' | codex exec --skip-git-repo-check --sandbox read-only (note we changed how we pass prompt [Changes]) - prompt in args should be always omited because we use stdin - in case of opencode, once ask runs, run `opencode --continue` - browse the web to fix [Fragment] - cursor agent cannot pipe but: [Pasted text] - cursor's tool names in notification are incorrect [Pasted text] - remove muse code - open code requires --dir [cwd] argument [Website] - merge [Fragment] into a single key - assess correctness of args in case of 'claude' [Pasted text] ├── apps │ ├── browser │ │ └── create-firefox-build.ts │ └── editor │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ └── utils │ │ │ └── preview │ │ │ └── build-history-files.ts │ │ └── generate-commit-message-commands │ │ └── utils │ │ └── build-commit-message-prompt.ts │ ├── constants │ │ ├── agents.ts │ │ ├── instructions.ts │ │ └── values.ts │ ├── features │ │ └── agentic-search │ │ ├── agentic-search.ts │ │ └── utils │ │ └── build-agent-prompt.ts │ ├── utils │ │ ├── agentic-cli-invocation │ │ │ ├── agents │ │ │ │ ├── antigravity.ts │ │ │ │ ├── claude.ts │ │ │ │ ├── codex.ts │ │ │ │ ├── cursor.ts │ │ │ │ ├── grok.ts │ │ │ │ ├── index.ts │ │ │ │ ├── muse.ts │ │ │ │ └── opencode.ts │ │ │ ├── index.ts │ │ │ ├── invoke-agentic-cli.ts │ │ │ ├── types.ts │ │ │ └── utils │ │ │ ├── check-command-exists.ts │ │ │ ├── format-duration.ts │ │ │ ├── generate-diff-markdown.ts │ │ │ └── get-progress-dots.ts │ │ ├── build-user-content.ts │ │ └── prompt-builder.ts │ └── views │ └── prompt │ └── backend │ └── message-handlers │ ├── handle-autofill.ts │ ├── handle-copy-prompt.ts │ ├── handle-invoke-agentic-cli.ts │ ├── handle-preview-prompt.ts │ └── utils │ ├── build-cli-prompt.ts │ └── build-prompt-payload.ts └── packages └── shared └── tsconfig.build.json
1 parent 4718bcf commit 4ca3b5e

14 files changed

Lines changed: 128 additions & 302 deletions

File tree

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const AGENTS = {
2323
flags_placeholder: ''
2424
},
2525
Cursor: {
26-
docs_url: 'https://cursor.com/docs/cli/headless',
26+
docs_url: 'https://cursor.com/docs/cli/reference/parameters',
2727
homepage_url: 'https://cursor.com/cli',
2828
flags_placeholder: ''
2929
},
@@ -32,11 +32,6 @@ export const AGENTS = {
3232
homepage_url: 'https://x.ai/build',
3333
flags_placeholder: ''
3434
},
35-
'Muse Code': {
36-
docs_url: 'https://dev.meta.ai/docs/muse-code/extending#headless',
37-
homepage_url: 'https://dev.meta.ai/docs/muse-code',
38-
flags_placeholder: ''
39-
},
4035
OpenCode: {
4136
docs_url: 'https://opencode.ai/docs/cli/',
4237
homepage_url: 'https://opencode.ai/',

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ export const voice_input_instructions =
7070
'Respond with a transcription of the following audio recording or text "INAUDIBLE", and nothing else.'
7171

7272
export const cli_edit_ask_requirements = {
73-
preloaded_files: 'All project files are shown in [files](#files) section.',
74-
read_files:
75-
'You must start by looking at [files](#files) section for unread files (### Unread file: `[PROJECT-RELATIVE PATH]`) and read them one-by-one.',
76-
read_images:
77-
'If [task](#task) section includes *.png image paths, read them.',
78-
restrict_tool_calls:
79-
'Any further tool calling (including grep, ls, git, etc. command executions) is FORBIDDEN.',
73+
preloaded_context:
74+
"All project's files were preloaded to [files](#files) section. If [task](#task) section includes *.png image paths, read them. Looking for other files is FORBIDDEN.",
75+
restrict_tool_calls: 'Running furher tools or shell commands is FORBIDDEN.',
8076
restrict_tool_calls_with_exceptions:
81-
'Any further tool calling (including grep, ls, git, etc. command executions) is FORBIDDEN, with exceptions: strictly file creations, deletions or updates to complete the [task](#task).'
77+
'You may only perform file operations (create, update, delete) required to complete the [task](#task); running any other tools or shell commands is FORBIDDEN.'
8278
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ export const MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE = 1000
44
export const GIT_LOG_SINCE_DURATION = '6 months ago'
55
export const SYMBOL_CACHE_DURATION = 5 * 60 * 1000
66

7-
export const MAX_CLI_PROMPT_TOTAL_INLINED_CHARS = 20000
8-
export const MAX_CLI_PROMPT_FILE_INLINED_CHARS = 1000
9-
107
export const DIFF_PLACEHOLDERS = {
118
FILE_CREATED: 'File created',
129
FILE_DELETED: 'File deleted',

‎apps/editor/src/utils/agentic-cli-invocation/agents/antigravity.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ export const antigravity_agent: CodingAgent = {
1414
cmd: 'agy',
1515
is_installed: () => check_command_exists('agy'),
1616
get_documentation_url: () => AGENTS[agent_name].docs_url,
17-
get_edit_args: (prompt: string) => [
18-
'-p',
19-
prompt,
17+
get_edit_args: () => [
2018
'--output-format',
2119
'stream-json',
2220
'--dangerously-skip-permissions'
2321
],
24-
get_ask_args: (prompt: string) => [
25-
'-i',
26-
prompt,
22+
get_ask_args: () => [
2723
'--mode',
2824
'plan'
2925
],
26+
get_post_ask_args: () => ['--continue'],
3027
parse_stream_line: (parsed, report_progress) => {
3128
if (parsed.event == 'step_update' && parsed.step_update) {
3229
const step = parsed.step_update

‎apps/editor/src/utils/agentic-cli-invocation/agents/claude.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ export const claude_agent: CodingAgent = {
3030
cmd: 'claude',
3131
is_installed: () => check_command_exists('claude'),
3232
get_documentation_url: () => AGENTS[agent_name].docs_url,
33-
get_edit_args: (prompt: string) => [
34-
'-p',
35-
prompt,
33+
get_edit_args: () => [
34+
'--print',
3635
'--output-format',
3736
'stream-json',
3837
'--verbose',
3938
'--include-partial-messages',
40-
'--permission-mode',
41-
'auto'
39+
'--dangerously-skip-permissions'
4240
],
43-
get_ask_args: (prompt: string) => [
44-
prompt,
41+
get_ask_args: () => [
4542
'--permission-mode',
4643
'plan'
4744
],

‎apps/editor/src/utils/agentic-cli-invocation/agents/codex.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ export const codex_agent: CodingAgent = {
1414
cmd: 'codex',
1515
is_installed: () => check_command_exists('codex'),
1616
get_documentation_url: () => AGENTS[agent_name].docs_url,
17-
get_edit_args: (prompt: string) => [
17+
get_edit_args: () => [
1818
'exec',
19-
prompt,
2019
'--json',
2120
'--sandbox',
2221
'workspace-write',
2322
'--skip-git-repo-check'
2423
],
25-
get_ask_args: (prompt: string) => [prompt, '--sandbox', 'read-only'],
24+
get_ask_args: () => [
25+
'exec',
26+
'--skip-git-repo-check',
27+
'--sandbox',
28+
'read-only'
29+
],
30+
// get_post_ask_args: () => ['continue'], // Broken on their end
2631
parse_stream_line: (parsed, report_progress) => {
2732
if (parsed.type == 'item.started' && parsed.item) {
2833
const item = parsed.item

‎apps/editor/src/utils/agentic-cli-invocation/agents/cursor.ts‎

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { CodingAgent } from '../types'
22
import { check_command_exists } from '../utils/check-command-exists'
3+
import { get_progress_dots } from '../utils/get-progress-dots'
34
import { AGENTS } from '../../../constants/agents'
45

6+
let last_action_name = ''
7+
let action_count = 0
8+
59
const agent_name = 'Cursor'
610

711
export const cursor_agent: CodingAgent = {
@@ -10,76 +14,47 @@ export const cursor_agent: CodingAgent = {
1014
cmd: 'agent',
1115
is_installed: () => check_command_exists('agent'),
1216
get_documentation_url: () => AGENTS[agent_name].docs_url,
13-
get_edit_args: (prompt: string) => [
14-
'-p',
15-
prompt,
16-
'--output-format',
17-
'stream-json',
18-
'--force'
19-
],
20-
get_ask_args: (prompt: string) => [
21-
prompt,
22-
'--mode',
23-
'ask'
24-
],
17+
get_edit_args: () => ['--force', '--output-format', 'stream-json'],
18+
get_ask_args: () => ['--force'],
19+
get_post_ask_args: () => ['--continue', '--trust'],
2520
parse_stream_line: (parsed, report_progress) => {
2621
if (parsed.type == 'tool_call') {
2722
if (parsed.subtype == 'started' || !parsed.subtype) {
2823
const tool_call = parsed.tool_call
2924
if (tool_call) {
30-
let msg = ''
31-
if (tool_call.readToolCall?.args?.path) {
32-
msg = tool_call.readToolCall.args.path
33-
} else if (tool_call.writeToolCall?.args?.path) {
34-
msg = tool_call.writeToolCall.args.path
35-
} else {
36-
const key = Object.keys(tool_call)[0]
37-
if (key) {
38-
const call = tool_call[key]
39-
const args = call?.args
40-
const raw_name = key.replace(/ToolCall$/, '')
41-
const formatted_name = raw_name
42-
.replace(/([A-Z])/g, '_$1')
43-
.toLowerCase()
44-
.replace(/^_/, '')
45-
46-
if (
47-
(formatted_name.includes('run') ||
48-
formatted_name.includes('command') ||
49-
formatted_name.includes('bash')) &&
50-
(args?.command || args?.cmd || args?.CommandLine)
51-
) {
52-
msg = args.command || args.cmd || args.CommandLine
53-
} else if (
54-
(formatted_name.includes('search') ||
55-
formatted_name.includes('grep') ||
56-
formatted_name.includes('find')) &&
57-
(args?.query || args?.pattern)
58-
) {
59-
msg = args.query || args.pattern
60-
} else if (formatted_name.includes('list') && args?.path) {
61-
msg = args.path
62-
} else if (args?.path) {
63-
msg = args.path
64-
} else {
65-
msg = key
66-
}
67-
}
25+
let action_name = ''
26+
const key = Object.keys(tool_call)[0]
27+
if (key) {
28+
const raw_name = key.replace(/ToolCall$/, '')
29+
action_name = raw_name
30+
.replace(/([A-Z])/g, ' $1')
31+
.toLowerCase()
32+
.trim()
6833
}
6934

70-
if (msg) {
71-
report_progress(msg)
35+
if (action_name) {
36+
if (action_name === last_action_name) {
37+
action_count++
38+
} else {
39+
last_action_name = action_name
40+
action_count = 1
41+
}
42+
report_progress(`${action_name}${get_progress_dots(action_count)}`)
7243
}
7344
}
7445
}
7546
} else if (parsed.type == 'result' && parsed.result) {
47+
last_action_name = ''
48+
action_count = 0
7649
return {
7750
output:
7851
typeof parsed.result == 'string'
7952
? parsed.result
8053
: parsed.result.text || parsed.result.response || ''
8154
}
8255
} else if (parsed.result) {
56+
last_action_name = ''
57+
action_count = 0
8358
return {
8459
output:
8560
typeof parsed.result == 'string'
@@ -89,6 +64,8 @@ export const cursor_agent: CodingAgent = {
8964
} else if (parsed.type == 'assistant' && parsed.message) {
9065
const is_delta = parsed.timestamp_ms && !parsed.model_call_id
9166
if (!is_delta) {
67+
last_action_name = ''
68+
action_count = 0
9269
if (Array.isArray(parsed.message.content)) {
9370
const text = parsed.message.content
9471
.map((item: any) =>
@@ -107,6 +84,8 @@ export const cursor_agent: CodingAgent = {
10784
}
10885
},
10986
parse_final_output: (parsed, current_output) => {
87+
last_action_name = ''
88+
action_count = 0
11089
if (parsed.type == 'result' && parsed.result) {
11190
return typeof parsed.result == 'string'
11291
? parsed.result

‎apps/editor/src/utils/agentic-cli-invocation/agents/grok.ts‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,12 @@ export const grok_agent: CodingAgent = {
1212
cmd: 'grok',
1313
is_installed: () => check_command_exists('grok'),
1414
get_documentation_url: () => AGENTS[agent_name].docs_url,
15-
get_edit_args: (prompt: string) => {
16-
accumulated_output = ''
17-
return [
18-
'-p',
19-
prompt,
20-
'--output-format',
21-
'streaming-json',
22-
'--always-approve',
23-
]
24-
},
25-
get_ask_args: (prompt: string) => {
26-
accumulated_output = ''
27-
return [
28-
'-p',
29-
prompt,
30-
'--sandbox',
31-
'read-only',
32-
]
33-
},
15+
get_prompt_file_args: (temp_prompt_path) => [
16+
'--prompt-file',
17+
temp_prompt_path
18+
],
19+
get_edit_args: () => ['--yolo', '--output-format', 'streaming-json'],
20+
// get_post_ask_args: () => ['continue'], // Broken on their end
3421
parse_stream_line: (parsed, report_progress) => {
3522
if (parsed.type === 'tool_call' && parsed.tool) {
3623
report_progress(parsed.tool)

‎apps/editor/src/utils/agentic-cli-invocation/agents/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import { codex_agent } from './codex'
44
import { cursor_agent } from './cursor'
55
import { opencode_agent } from './opencode'
66
import { grok_agent } from './grok'
7-
import { muse_agent } from './muse'
87

98
export const CLI_AGENTS = [
109
antigravity_agent,
1110
codex_agent,
1211
claude_agent,
1312
cursor_agent,
1413
grok_agent,
15-
muse_agent,
1614
opencode_agent
1715
]

0 commit comments

Comments
 (0)