Skip to content

Commit c479109

Browse files
committed
Introduce a headless CLI target mode for prompt execution by refactoring agentic search logic into a reusable feature and updating UI components to support CLI interactions
- add new target: 'CLI', similarly to 'API', has only 'edit files' prompt type. for now, don't show any configurations and make the handler just log into the console 'invoked'. - translate [Fragment] - rename 'make cli call' to 'invoke headless cli' - because we will want to be able to invoke cli agents from other places, create a feature in `apps/editor/src/features` called 'headless cli invocation' and move appropriate generic logic off `apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search` - when invoking headless cli from `apps/editor/src/views/prompt/backend/message-handlers/handle-invoke-headless-cli/handle-invoke-headless-cli.ts`: 1) in `# Files` list file paths, e.g. [Pasted text] 2) append section: [Pasted text](save as cli_requirements in `apps/editor/src/constants/instructions.ts`) below `# Output formatting` - agent selector triggered from `apps/editor/src/views/prompt/backend/message-handlers/handle-invoke-headless-cli/handle-invoke-headless-cli.ts` should not have back arrow - move [Fragment] to translations - remove notification 'agent finished in...' - add translations [Fragment] - in prompt field: on 'submit' in CLI target, show 'Invoke CLI' tooltip - [Pasted text] - in CLI target, 'send with...' should be the only available 'submitting' option - should not show last choice on 'cli' target - when there is no last choice, use 'send with ellipsis' in tooltip - allow previewing/copying CLI prompt ├── apps │ └── editor │ └── src │ ├── commands │ │ └── apply-response-command │ │ └── response-processor │ │ └── response-processor.ts │ ├── constants │ │ ├── instructions.ts │ │ └── state-keys.ts │ ├── features │ │ ├── context-restoration │ │ │ └── index.ts │ │ └── 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 │ ├── i18n │ │ └── translations │ │ ├── commands │ │ │ └── apply-response-command.ts │ │ ├── features │ │ │ ├── checkpoints.ts │ │ │ ├── context-restoration.ts │ │ │ ├── index.ts │ │ │ └── search-files.ts │ │ ├── services │ │ │ ├── prompt-view-api-calls-manager.ts │ │ │ └── websocket-manager.ts │ │ └── views │ │ └── prompt │ │ └── handlers │ │ ├── handle-agentic-search.ts │ │ ├── handle-autofill.ts │ │ ├── handle-copy-prompt.ts │ │ ├── handle-delete-task.ts │ │ ├── handle-hash-sign-quick-pick.ts │ │ ├── handle-invoke-headless-cli.ts │ │ ├── handle-make-api-call.ts │ │ ├── handle-patch-repair.ts │ │ ├── handle-select-edit-format-instructions.ts │ │ ├── handle-template-quick-pick.ts │ │ ├── handle-undo.ts │ │ ├── handle-voice-input.ts │ │ ├── index.ts │ │ └── utils │ │ ├── index.ts │ │ └── symbols │ │ ├── git │ │ │ ├── index.ts │ │ │ └── replace-git-symbols.ts │ │ └── index.ts │ ├── services │ │ └── prompt-view-api-calls-manager.ts │ ├── utils │ │ └── prompt-builder.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-agentic-search │ │ │ │ ├── agentic-search.ts │ │ │ │ ├── handle-agentic-search.ts │ │ │ │ ├── index.ts │ │ │ │ └── utils │ │ │ │ ├── build-agent-prompt.ts │ │ │ │ ├── index.ts │ │ │ │ └── prompt-for-search-term.ts │ │ │ ├── handle-autofill.ts │ │ │ ├── handle-copy-prompt.ts │ │ │ ├── handle-get-cli-prompt-type.ts │ │ │ ├── handle-invoke-headless-cli.ts │ │ │ ├── handle-make-api-call.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ ├── handle-preview-web-configuration.ts │ │ │ ├── handle-save-api-prompt-type.ts │ │ │ ├── handle-save-cli-prompt-type.ts │ │ │ ├── handle-save-web-prompt-type.ts │ │ │ ├── handle-template-quick-pick.ts │ │ │ ├── index.ts │ │ │ └── utils │ │ │ ├── build-cli-prompt.ts │ │ │ ├── build-prompt-payload.ts │ │ │ └── patch-repair-utils.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ └── preview-text-in-temp-file.ts │ ├── frontend │ │ ├── Home │ │ │ ├── Home.tsx │ │ │ └── hooks │ │ │ └── use-keyboard-shortcuts.ts │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.tsx │ │ │ ├── components │ │ │ │ └── Header │ │ │ │ └── Header.tsx │ │ │ ├── hooks │ │ │ │ ├── use-invocation-counts.ts │ │ │ │ ├── use-keyboard-shortcuts.ts │ │ │ │ └── use-last-choice-tooltip.ts │ │ │ └── prompt-type-labels.ts │ │ ├── Prompt.tsx │ │ ├── hooks │ │ │ ├── use-api-configuration-editing.ts │ │ │ └── use-prompt │ │ │ ├── hooks │ │ │ │ └── use-instructions.ts │ │ │ └── use-prompt.ts │ │ └── i18n │ │ └── translations │ │ ├── home.ts │ │ └── prompt-field.ts │ └── types │ └── messages.ts └── packages ├── shared │ └── src │ └── types │ ├── mode.ts │ └── prompt-types.ts └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.stories.tsx ├── PromptField.tsx └── hooks └── use-keyboard-shortcuts.ts
1 parent 076002b commit c479109

50 files changed

Lines changed: 1545 additions & 951 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ Whenever showing a new, updated, renamed, or deleted file, provide a brief expla
162162

163163
</details>
164164

165+
<details>
166+
<summary>CLI</summary>
167+
168+
```
169+
# Files
170+
171+
- `[SELECTED FILE PATH 1]`
172+
- `[SELECTED FILE PATH 2]`
173+
174+
# Output formatting
175+
176+
[EDIT FORMAT INSTRUCTIONS]
177+
178+
# Requirements
179+
180+
* This is a read-only session.
181+
* Read all attached files using their project-relative paths in full, and nothing else.
182+
* Formulate response adhering to the output formatting, in plain text.
183+
184+
# Task
185+
186+
[INSTRUCTIONS]
187+
```
188+
189+
</details>
190+
165191
### 📄 Asking
166192

167193
_Multi-purpose: explanations, code reviews, you name it._

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ These files contain the core greeting logic and module exports.`
6868

6969
export const voice_input_instructions =
7070
'Respond with a transcription of the following audio recording or text "INAUDIBLE", and nothing else.'
71+
72+
export const cli_requirements = `- This is a read-only session.
73+
- Read all attached files using their project-relative paths in full, and nothing else.
74+
- Formulate response adhering to the output formatting, in plain text.`

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY =
3131
export const EDIT_FORMAT_STATE_KEY = 'edit-format'
3232
export const WEB_TARGET_STATE_KEY = 'web-target'
3333
export const API_TARGET_STATE_KEY = 'api-target'
34+
export const CLI_TARGET_STATE_KEY = 'cli-target'
3435
export const PROMPT_VIEW_TARGET_STATE_KEY = 'prompt-view-target'
3536

3637
export const INSTRUCTIONS_EDIT_FILES_STATE_KEY = 'instructions-edit-files'

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/antigravity.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/antigravity.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { CodingAgent } from '../types'
2-
import {
3-
build_agent_prompt,
4-
check_command_exists,
5-
get_progress_dots
6-
} from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
3+
import { get_progress_dots } from '../utils/get-progress-dots'
74

85
let last_action_name = ''
96
let action_count = 0
@@ -14,9 +11,9 @@ export const antigravity_agent: CodingAgent = {
1411
cmd: 'agy',
1512
is_installed: () => check_command_exists('agy'),
1613
get_documentation_url: () => 'https://antigravity.google/docs/cli/headless/',
17-
get_args: (query: string) => [
14+
get_args: (prompt: string) => [
1815
'-p',
19-
build_agent_prompt(query),
16+
prompt,
2017
'--output-format',
2118
'stream-json',
2219
'--dangerously-skip-permissions'

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/claude.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/claude.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { CodingAgent } from '../types'
2-
import {
3-
build_agent_prompt,
4-
check_command_exists,
5-
get_progress_dots
6-
} from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
3+
import { get_progress_dots } from '../utils/get-progress-dots'
74

85
let last_action_name = ''
96
let action_count = 0
@@ -30,9 +27,9 @@ export const claude_agent: CodingAgent = {
3027
cmd: 'claude',
3128
is_installed: () => check_command_exists('claude'),
3229
get_documentation_url: () => 'https://code.claude.com/docs/en/headless',
33-
get_args: (query: string) => [
30+
get_args: (prompt: string) => [
3431
'-p',
35-
build_agent_prompt(query),
32+
prompt,
3633
'--output-format',
3734
'stream-json',
3835
'--verbose',

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/codex.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/codex.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { CodingAgent } from '../types'
2-
import {
3-
build_agent_prompt,
4-
check_command_exists,
5-
get_progress_dots
6-
} from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
3+
import { get_progress_dots } from '../utils/get-progress-dots'
74

85
let last_action_name = ''
96
let action_count = 0
@@ -15,7 +12,7 @@ export const codex_agent: CodingAgent = {
1512
is_installed: () => check_command_exists('codex'),
1613
get_documentation_url: () =>
1714
'https://learn.chatgpt.com/docs/non-interactive-mode',
18-
get_args: (query: string) => ['exec', build_agent_prompt(query), '--json'],
15+
get_args: (prompt: string) => ['exec', prompt, '--json'],
1916
parse_stream_line: (parsed, report_progress) => {
2017
if (parsed.type == 'item.started' && parsed.item) {
2118
const item = parsed.item

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/cursor.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/cursor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { CodingAgent } from '../types'
2-
import { build_agent_prompt, check_command_exists } from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
33

44
export const cursor_agent: CodingAgent = {
55
id: 'cursor',
66
label: 'Cursor',
77
cmd: 'agent',
88
is_installed: () => check_command_exists('agent'),
99
get_documentation_url: () => 'https://cursor.com/docs/cli/headless',
10-
get_args: (query: string) => [
10+
get_args: (prompt: string) => [
1111
'-p',
12-
build_agent_prompt(query),
12+
prompt,
1313
'--output-format',
1414
'stream-json',
1515
'--force'

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/grok.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/grok.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CodingAgent } from '../types'
2-
import { build_agent_prompt, check_command_exists } from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
33

44
let accumulated_output = ''
55

@@ -9,11 +9,11 @@ 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: (query: string) => {
12+
get_args: (prompt: string) => {
1313
accumulated_output = ''
1414
return [
1515
'-p',
16-
build_agent_prompt(query),
16+
prompt,
1717
'--output-format',
1818
'streaming-json',
1919
'--always-approve',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { antigravity_agent } from './antigravity'
2+
import { claude_agent } from './claude'
3+
import { codex_agent } from './codex'
4+
import { cursor_agent } from './cursor'
5+
import { opencode_agent } from './opencode'
6+
import { grok_agent } from './grok'
7+
import { muse_agent } from './muse'
8+
9+
export const HEADLESS_CLI_AGENTS = [
10+
antigravity_agent,
11+
codex_agent,
12+
claude_agent,
13+
cursor_agent,
14+
grok_agent,
15+
muse_agent,
16+
opencode_agent
17+
]

apps/editor/src/views/prompt/backend/message-handlers/handle-agentic-search/agents/muse.ts renamed to apps/editor/src/features/headless-cli-invocation/agents/muse.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { CodingAgent } from '../types'
2-
import {
3-
build_agent_prompt,
4-
check_command_exists,
5-
get_progress_dots
6-
} from '../utils'
2+
import { check_command_exists } from '../utils/check-command-exists'
3+
import { get_progress_dots } from '../utils/get-progress-dots'
74

85
let accumulated_output = ''
96
let last_action_name = ''
@@ -16,9 +13,9 @@ export const muse_agent: CodingAgent = {
1613
is_installed: () => check_command_exists('muse'),
1714
get_documentation_url: () =>
1815
'https://dev.meta.ai/docs/muse-code/extending#headless',
19-
get_args: (query: string) => {
16+
get_args: (prompt: string) => {
2017
accumulated_output = ''
21-
return ['exec', '--json', '--yolo', build_agent_prompt(query)]
18+
return ['exec', '--json', '--yolo', prompt]
2219
},
2320
parse_stream_line: (parsed, report_progress) => {
2421
const payload = parsed.payload || parsed

0 commit comments

Comments
 (0)