Skip to content

Commit 6cbcf6e

Browse files
committed
Add ask mode support to the CLI target
- to 'cli' target, add 'ask' prompt type (don't handle yet) - when in 'ask' CLI prompt type, invoke into the integrated terminal, not in headless mode, with changed command: e.g. `codex "[propt]"` instead of `codex exec "[propt]"` ├── apps │ └── editor │ └── src │ ├── constants │ │ └── instructions.ts │ ├── extension.ts │ ├── utils │ │ └── headless-cli-invocation │ │ ├── agents │ │ │ ├── antigravity.ts │ │ │ ├── claude.ts │ │ │ ├── codex.ts │ │ │ ├── cursor.ts │ │ │ ├── grok.ts │ │ │ ├── index.ts │ │ │ ├── muse.ts │ │ │ └── opencode.ts │ │ ├── index.ts │ │ ├── invoke-headless-cli.ts │ │ ├── types.ts │ │ └── utils │ │ ├── check-command-exists.ts │ │ ├── format-duration.ts │ │ └── get-progress-dots.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-copy-prompt.ts │ │ │ ├── handle-get-cli-prompt-type.ts │ │ │ ├── handle-invoke-headless-cli.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ ├── handle-save-cli-prompt-type.ts │ │ │ └── utils │ │ │ └── build-cli-prompt.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Home │ │ │ └── Home.tsx │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.tsx │ │ │ ├── components │ │ │ │ └── Header │ │ │ │ └── Header.tsx │ │ │ ├── hooks │ │ │ │ └── use-keyboard-shortcuts.ts │ │ │ └── prompt-type-labels.ts │ │ └── hooks │ │ └── use-prompt │ │ ├── hooks │ │ │ └── use-instructions.ts │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages └── shared └── src └── types └── prompt-types.ts
1 parent 3f0be3f commit 6cbcf6e

17 files changed

Lines changed: 136 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,27 @@ _Multi-purpose: explanations, code reviews, you name it._
207207

208208
</details>
209209

210+
<details>
211+
<summary>CLI</summary>
212+
213+
```
214+
# Files
215+
216+
- `[SELECTED FILE PATH 1]`
217+
- `[SELECTED FILE PATH 2]`
218+
219+
# Requirements
220+
221+
* This is a read-only session.
222+
* Read all attached files using their project-relative paths in full, and nothing else.
223+
224+
# Task
225+
226+
[INSTRUCTIONS]
227+
```
228+
229+
</details>
230+
210231
### 📄 Code at cursor
211232

212233
_TAB completions from SOTA reasoning models._

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

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

72-
export const cli_requirements = `- This is a read-only session.
72+
export const cli_edit_requirements = `- This is a read-only session.
7373
- Read all attached files using their project-relative paths in full, and nothing else.
7474
- Formulate response adhering to the output formatting, in plain text.`
75+
76+
export const cli_ask_requirements = `- This is a read-only session.
77+
- Read all attached files using their project-relative paths in full, and nothing else.`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ export const antigravity_agent: CodingAgent = {
1111
cmd: 'agy',
1212
is_installed: () => check_command_exists('agy'),
1313
get_documentation_url: () => 'https://antigravity.google/docs/cli/headless/',
14-
get_args: (prompt: string) => [
14+
get_edit_args: (prompt: string) => [
1515
'-p',
1616
prompt,
1717
'--output-format',
1818
'stream-json',
1919
'--dangerously-skip-permissions'
2020
],
21+
get_ask_args: (prompt: string) => ['-p', prompt],
2122
parse_stream_line: (parsed, report_progress) => {
2223
if (parsed.event == 'step_update' && parsed.step_update) {
2324
const step = parsed.step_update

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const claude_agent: CodingAgent = {
2727
cmd: 'claude',
2828
is_installed: () => check_command_exists('claude'),
2929
get_documentation_url: () => 'https://code.claude.com/docs/en/headless',
30-
get_args: (prompt: string) => [
30+
get_edit_args: (prompt: string) => [
3131
'-p',
3232
prompt,
3333
'--output-format',
@@ -37,6 +37,7 @@ export const claude_agent: CodingAgent = {
3737
'--permission-mode',
3838
'auto'
3939
],
40+
get_ask_args: (prompt: string) => ['-p', prompt],
4041
parse_stream_line: (parsed, report_progress) => {
4142
if (parsed.type == 'stream_event' && parsed.event) {
4243
if (

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const codex_agent: CodingAgent = {
1212
is_installed: () => check_command_exists('codex'),
1313
get_documentation_url: () =>
1414
'https://learn.chatgpt.com/docs/non-interactive-mode',
15-
get_args: (prompt: string) => ['exec', prompt, '--json'],
15+
get_edit_args: (prompt: string) => ['exec', prompt, '--json'],
16+
get_ask_args: (prompt: string) => [prompt],
1617
parse_stream_line: (parsed, report_progress) => {
1718
if (parsed.type == 'item.started' && parsed.item) {
1819
const item = parsed.item

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ export const cursor_agent: CodingAgent = {
77
cmd: 'agent',
88
is_installed: () => check_command_exists('agent'),
99
get_documentation_url: () => 'https://cursor.com/docs/cli/headless',
10-
get_args: (prompt: string) => [
10+
get_edit_args: (prompt: string) => [
1111
'-p',
1212
prompt,
1313
'--output-format',
1414
'stream-json',
1515
'--force'
1616
],
17+
get_ask_args: (prompt: string) => ['-p', prompt],
1718
parse_stream_line: (parsed, report_progress) => {
1819
if (parsed.type == 'tool_call') {
1920
if (parsed.subtype == 'started' || !parsed.subtype) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const grok_agent: CodingAgent = {
99
cmd: 'grok',
1010
is_installed: () => check_command_exists('grok'),
1111
get_documentation_url: () => 'https://docs.x.ai/build/cli/headless-scripting',
12-
get_args: (prompt: string) => {
12+
get_edit_args: (prompt: string) => {
1313
accumulated_output = ''
1414
return [
1515
'-p',
@@ -20,6 +20,7 @@ export const grok_agent: CodingAgent = {
2020
'--no-auto-update'
2121
]
2222
},
23+
get_ask_args: (prompt: string) => ['-p', prompt],
2324
parse_stream_line: (parsed, report_progress) => {
2425
if (parsed.type === 'tool_call' && parsed.tool) {
2526
report_progress(parsed.tool)

‎apps/editor/src/utils/headless-cli-invocation/agents/muse.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export const muse_agent: CodingAgent = {
1313
is_installed: () => check_command_exists('muse'),
1414
get_documentation_url: () =>
1515
'https://dev.meta.ai/docs/muse-code/extending#headless',
16-
get_args: (prompt: string) => {
16+
get_edit_args: (prompt: string) => {
1717
accumulated_output = ''
1818
return ['exec', '--json', '--yolo', prompt]
1919
},
20+
get_ask_args: (prompt: string) => [prompt],
2021
parse_stream_line: (parsed, report_progress) => {
2122
const payload = parsed.payload || parsed
2223
let action_name = ''

‎apps/editor/src/utils/headless-cli-invocation/agents/opencode.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ export const opencode_agent: CodingAgent = {
1111
cmd: 'opencode',
1212
is_installed: () => check_command_exists('opencode'),
1313
get_documentation_url: () => 'https://opencode.ai/docs/cli/',
14-
get_args: (prompt: string) => ['run', prompt, '--format', 'json', '--auto'],
14+
get_edit_args: (prompt: string) => [
15+
'run',
16+
prompt,
17+
'--format',
18+
'json',
19+
'--auto'
20+
],
21+
get_ask_args: (prompt: string) => [prompt],
1522
parse_stream_line: (parsed, report_progress) => {
1623
let action_name = ''
1724
if (parsed.type == 'tool_use' && parsed.part?.tool) {

‎apps/editor/src/utils/headless-cli-invocation/invoke-headless-cli.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode'
2+
import * as os from 'os'
23
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
34
import { t } from '@/i18n'
45
import { spawn } from 'child_process'
@@ -24,6 +25,7 @@ export const invoke_headless_cli = async (params: {
2425
last_selected_workspace_state_key: string
2526
config_key_prefix: string
2627
show_back_button?: boolean
28+
cli_prompt_type?: 'edit-files' | 'ask-about-files'
2729
}): Promise<
2830
{ agent_output: string; selected_root: string } | undefined | 'back'
2931
> => {
@@ -506,6 +508,32 @@ export const invoke_headless_cli = async (params: {
506508
}
507509
}
508510

511+
if (params.cli_prompt_type === 'ask-about-files') {
512+
const final_prompt = await params.build_prompt(selected_root!)
513+
const base_args = agent_info.get_ask_args
514+
? agent_info.get_ask_args(final_prompt)
515+
: [final_prompt]
516+
const args = [...base_args, ...custom_args]
517+
518+
const quote_arg = (arg: string) => {
519+
if (os.platform() === 'win32') {
520+
return `"${arg.replace(/"/g, '""')}"`
521+
} else {
522+
return `'${arg.replace(/'/g, "'\\''")}'`
523+
}
524+
}
525+
526+
const command = [executable, ...args.map(quote_arg)].join(' ')
527+
const terminal = vscode.window.createTerminal({
528+
name: `${agent_info.label} (Ask)`,
529+
cwd: selected_root
530+
})
531+
terminal.show()
532+
terminal.sendText(command)
533+
534+
return { agent_output: '', selected_root: selected_root! }
535+
}
536+
509537
let agent_output = ''
510538
let raw_stream_output = ''
511539
let is_cancelled = false
@@ -529,7 +557,7 @@ export const invoke_headless_cli = async (params: {
529557
return
530558
}
531559

532-
const base_args = agent_info.get_args(final_prompt)
560+
const base_args = agent_info.get_edit_args(final_prompt)
533561
const args = [...base_args, ...custom_args]
534562

535563
return new Promise<void>((resolve, reject) => {

0 commit comments

Comments
 (0)