Skip to content

Commit daefaef

Browse files
committed
Refactor agentic CLI invocation to support distinct edit and ask terminal arguments and interactive completion handling
- cli in 'edit' should run in terminal (just like ask) and wait for it to close (like we wait before reloading window in update extension flow) before getting diff and applying - make 'execution mode' a required property - 'get integrated terminal args' should have 2 variants: 'get edit integrated terminal args', 'get ask integrated terminal args' (depending on the mode edit/ask). For now, make them mirror values. ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── code-at-cursor-command │ │ │ └── utils │ │ │ └── perform-code-at-cursor.ts │ │ └── generate-commit-message-commands │ │ └── actions │ │ └── run-generate-action.ts │ ├── features │ │ ├── agentic-search │ │ │ └── agentic-search.ts │ │ └── search-files │ │ └── search-modes │ │ └── perform-intelligent-search-mode.ts │ ├── utils │ │ ├── agentic-cli-invocation │ │ │ ├── agents │ │ │ │ ├── antigravity.ts │ │ │ │ ├── claude.ts │ │ │ │ ├── codex.ts │ │ │ │ ├── cursor.ts │ │ │ │ ├── devin.ts │ │ │ │ ├── grok.ts │ │ │ │ ├── index.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 │ │ └── update-extension.ts │ └── views │ └── prompt │ └── backend │ ├── message-handlers │ │ ├── handle-invoke-agentic-cli.ts │ │ ├── handle-patch-repair.ts │ │ └── handle-voice-input.ts │ └── prompt-view-provider.ts └── packages └── shared └── src └── types └── prompt-types.ts
1 parent 4692458 commit daefaef

15 files changed

Lines changed: 112 additions & 39 deletions

File tree

‎apps/editor/src/commands/code-at-cursor-command/utils/perform-code-at-cursor.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ export const perform_code_at_cursor = async (params: {
374374
extension_context: params.extension_context,
375375
build_prompt: async () => cli_prompt,
376376
notification_title: t('command.code-at-cursor-command.progress.title'),
377+
execution_mode: 'headless',
377378
last_selected_workspace_state_key:
378379
LAST_SELECTED_WORKSPACE_FOR_CODE_AT_CURSOR_STATE_KEY,
379380
agent_state_key: LAST_USED_AGENT_FOR_CODE_AT_CURSOR_STATE_KEY,

‎apps/editor/src/commands/generate-commit-message-commands/actions/run-generate-action.ts‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ export const run_generate_action = async (params: {
191191
if (additional_tokens > 0) {
192192
items.push({
193193
label: include_files_and_context_label,
194-
description: `+${display_token_count(
195-
additional_tokens
196-
)}`,
194+
description: `+${display_token_count(additional_tokens)}`,
197195
id: 'attach'
198196
})
199197
}
@@ -353,11 +351,15 @@ export const run_generate_action = async (params: {
353351
prompt_without_context.api_prompt.length / 4
354352
)
355353
const additional_tokens = prompt_with_context
356-
? Math.ceil(prompt_with_context.api_prompt.length / 4) - skip_tokens
354+
? Math.ceil(prompt_with_context.api_prompt.length / 4) -
355+
skip_tokens
357356
: 0
358-
const can_go_back_to_context = setting === 'ask' && (additional_tokens > 0 || diffs_only_tokens < skip_tokens)
359-
360-
const show_back_btn_here = show_back_button || can_go_back_to_context
357+
const can_go_back_to_context =
358+
setting === 'ask' &&
359+
(additional_tokens > 0 || diffs_only_tokens < skip_tokens)
360+
361+
const show_back_btn_here =
362+
show_back_button || can_go_back_to_context
361363

362364
quick_pick.ignoreFocusOut = show_back_btn_here
363365

@@ -367,7 +369,9 @@ export const run_generate_action = async (params: {
367369
}
368370

369371
quick_pick.buttons = [
370-
...(show_back_btn_here ? [vscode.QuickInputButtons.Back] : []),
372+
...(show_back_btn_here
373+
? [vscode.QuickInputButtons.Back]
374+
: []),
371375
close_button
372376
]
373377

@@ -411,7 +415,8 @@ export const run_generate_action = async (params: {
411415
prompt_without_context.api_prompt.length / 4
412416
)
413417
const additional_tokens = prompt_with_context
414-
? Math.ceil(prompt_with_context.api_prompt.length / 4) - skip_tokens
418+
? Math.ceil(prompt_with_context.api_prompt.length / 4) -
419+
skip_tokens
415420
: 0
416421
if (
417422
setting === 'ask' &&
@@ -516,7 +521,8 @@ export const run_generate_action = async (params: {
516521
const last_selected_name =
517522
params.extension_context.workspaceState.get<string>(
518523
recents_key
519-
) ?? params.extension_context.globalState.get<string>(recents_key)
524+
) ??
525+
params.extension_context.globalState.get<string>(recents_key)
520526

521527
const result = await show_configurations_quick_pick({
522528
items: valid_web_configurations,
@@ -580,6 +586,7 @@ export const run_generate_action = async (params: {
580586
notification_title: t(
581587
'command.generate-commit-message-command.progress.title'
582588
),
589+
execution_mode: 'headless',
583590
last_selected_workspace_state_key:
584591
LAST_SELECTED_WORKSPACE_FOR_COMMIT_MESSAGE_STATE_KEY,
585592
agent_state_key: LAST_USED_AGENT_FOR_COMMIT_MESSAGE_STATE_KEY,
@@ -596,7 +603,10 @@ export const run_generate_action = async (params: {
596603

597604
if (!invoke_cli_result) {
598605
if (was_empty_stage) {
599-
await vscode.commands.executeCommand('git.unstageAll', repository)
606+
await vscode.commands.executeCommand(
607+
'git.unstageAll',
608+
repository
609+
)
600610
}
601611
return
602612
}
@@ -613,7 +623,9 @@ export const run_generate_action = async (params: {
613623

614624
if (!response_text.trim()) {
615625
vscode.window.showErrorMessage(
616-
t('command.generate-commit-message-command.error.empty-response')
626+
t(
627+
'command.generate-commit-message-command.error.empty-response'
628+
)
617629
)
618630
current_action = undefined
619631
step = 'action'
@@ -623,10 +635,11 @@ export const run_generate_action = async (params: {
623635
commit_message = response_text
624636
action_completed = true
625637
} else if (action === 'manual') {
626-
commit_message = params.extension_context.workspaceState.get<string>(
627-
LAST_ACCEPTED_COMMIT_MESSAGE_STATE_KEY,
628-
''
629-
)
638+
commit_message =
639+
params.extension_context.workspaceState.get<string>(
640+
LAST_ACCEPTED_COMMIT_MESSAGE_STATE_KEY,
641+
''
642+
)
630643
action_completed = true
631644
} else {
632645
const api_configuration_data =
@@ -646,7 +659,10 @@ export const run_generate_action = async (params: {
646659

647660
if (!api_configuration_data) {
648661
if (was_empty_stage) {
649-
await vscode.commands.executeCommand('git.unstageAll', repository)
662+
await vscode.commands.executeCommand(
663+
'git.unstageAll',
664+
repository
665+
)
650666
}
651667
return
652668
}

‎apps/editor/src/features/agentic-search/agentic-search.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const agentic_search = async (params: {
7878
workspace_provider: params.workspace_provider,
7979
extension_context: params.extension_context,
8080
notification_title: t('feature.agentic-search.title.agentic-search'),
81+
execution_mode: 'headless',
8182
agent_state_key: LAST_USED_AGENTIC_SEARCH_AGENT_STATE_KEY,
8283
last_selected_workspace_state_key:
8384
LAST_SELECTED_WORKSPACE_IN_AGENTIC_SEARCH_STATE_KEY,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ export const perform_intelligent_search_mode = async (params: {
426426
extension_context: params.extension_context,
427427
build_prompt: async () => cli_prompt,
428428
notification_title: t('common.title.intelligent-search'),
429+
execution_mode: 'headless',
429430
last_selected_workspace_state_key:
430431
LAST_SELECTED_WORKSPACE_FOR_INTELLIGENT_SEARCH_STATE_KEY,
431432
agent_state_key: LAST_USED_AGENT_FOR_INTELLIGENT_SEARCH_STATE_KEY,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const antigravity_agent: CodingAgent = {
1919
'stream-json',
2020
'--dangerously-skip-permissions'
2121
],
22-
get_integrated_terminal_args: () => [],
22+
get_edit_integrated_terminal_args: () => [],
23+
get_ask_integrated_terminal_args: () => [],
2324
get_post_integrated_terminal_args: () => ['--continue'],
2425
parse_stream_line: (parsed, report_progress) => {
2526
if (parsed.event === 'step_update' && parsed.step_update) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export const claude_agent: CodingAgent = {
3434
'--print',
3535
'--output-format',
3636
'stream-json',
37-
'--verbose',
3837
'--include-partial-messages',
3938
'--permission-mode',
40-
'auto'
39+
'dontAsk'
4140
],
42-
get_integrated_terminal_args: () => ['--permission-mode', 'auto'],
41+
get_edit_integrated_terminal_args: () => ['--permission-mode', 'acceptEdits'],
42+
get_ask_integrated_terminal_args: () => ['--permission-mode', 'dontAsk'],
4343
parse_stream_line: (parsed, report_progress) => {
4444
if (parsed.type === 'stream_event' && parsed.event) {
4545
if (

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ export const codex_agent: CodingAgent = {
2121
'workspace-write',
2222
'--skip-git-repo-check'
2323
],
24-
get_integrated_terminal_args: () => [
24+
get_edit_integrated_terminal_args: () => [
25+
'exec',
26+
'--skip-git-repo-check',
27+
'--sandbox',
28+
'workspace-write'
29+
],
30+
get_ask_integrated_terminal_args: () => [
2531
'exec',
2632
'--skip-git-repo-check',
2733
'--sandbox',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const cursor_agent: CodingAgent = {
1515
is_installed: () => check_command_exists('agent'),
1616
get_documentation_url: () => AGENTS[agent_name].docs_url,
1717
get_isolated_dir_args: () => ['--force', '--output-format', 'stream-json'],
18-
get_integrated_terminal_args: () => ['--force'],
18+
get_edit_integrated_terminal_args: () => ['--force'],
19+
get_ask_integrated_terminal_args: () => ['--force'],
1920
get_post_integrated_terminal_args: () => ['--continue', '--trust'],
2021
parse_stream_line: (parsed, report_progress) => {
2122
if (parsed.type === 'tool_call') {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const devin_agent: CodingAgent = {
1515
'--respect-workspace-trust',
1616
'false'
1717
],
18-
get_integrated_terminal_args: () => [],
18+
get_edit_integrated_terminal_args: () => [],
19+
get_ask_integrated_terminal_args: () => [],
1920
get_prompt_file_args: (temp_prompt_path: string) => [
2021
'--prompt-file',
2122
temp_prompt_path

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const opencode_agent: CodingAgent = {
2121
'--auto',
2222
params.cwd
2323
],
24-
get_integrated_terminal_args: (params) => ['run', '--auto', params.cwd],
24+
get_edit_integrated_terminal_args: (params) => ['run', '--auto', params.cwd],
25+
get_ask_integrated_terminal_args: (params) => ['run', '--auto', params.cwd],
2526
get_post_integrated_terminal_args: () => ['--continue'],
2627
parse_stream_line: (parsed, report_progress) => {
2728
let action_name = ''

0 commit comments

Comments
 (0)