@@ -4,7 +4,9 @@ import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
44import {
55 LAST_APPLIED_CHANGES_STATE_KEY ,
66 LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY ,
7- LAST_USED_PATCH_REPAIR_ACTION_STATE_KEY
7+ LAST_USED_PATCH_REPAIR_ACTION_STATE_KEY ,
8+ LAST_SELECTED_WORKSPACE_FOR_PATCH_REPAIR_STATE_KEY ,
9+ LAST_USED_AGENT_FOR_PATCH_REPAIR_STATE_KEY
810} from '@/constants/state-keys'
911import { OriginalFileState } from '@/commands/apply-response-command/types/original-file-state'
1012import { parse_response } from '@/commands/apply-response-command/utils/response-parser'
@@ -23,9 +25,11 @@ import { show_configurations_quick_pick } from '@/utils/show-configurations-quic
2325import { get_last_used_web_configuration_key } from '@/constants/state-keys'
2426import {
2527 patch_repair_format_instructions ,
26- patch_repair_task_instructions
28+ patch_repair_task_instructions ,
29+ cli_edit_ask_requirements
2730} from '@/constants/instructions'
2831import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
32+ import { invoke_agentic_cli } from '@/utils/agentic-cli-invocation'
2933
3034export const handle_patch_repair = async ( params : {
3135 prompt_view_provider : PromptViewProvider
@@ -157,6 +161,10 @@ export const handle_patch_repair = async (params: {
157161 label : t ( 'common.action.send-request' ) ,
158162 id : 'make-api'
159163 } ,
164+ {
165+ label : t ( 'common.action.invoke-agent' ) ,
166+ id : 'invoke-agent'
167+ } ,
160168 ...( params . prompt_view_provider . websocket_server_instance . is_connected_with_browser ( )
161169 ? [
162170 {
@@ -235,6 +243,74 @@ export const handle_patch_repair = async (params: {
235243 return
236244 }
237245
246+ if ( action == 'invoke-agent' ) {
247+ let cli_prompt = ''
248+ for ( const item of files_to_process ) {
249+ const backticks = item . file_state . content . includes ( '```' ) ? '````' : '```'
250+ const display_path =
251+ ! is_single_root_folder_workspace && item . file_state . workspace_name
252+ ? `${ item . file_state . workspace_name } /${ item . file_state . file_path } `
253+ : item . file_state . file_path
254+ cli_prompt += `# File: \`${ display_path } \`\n\n${ backticks } \n${ item . file_state . content } \n${ backticks } \n\n${ item . instructions } \n\n`
255+ }
256+ cli_prompt += `# Output formatting\n\n`
257+ cli_prompt += `${ patch_repair_format_instructions } \n\n`
258+ cli_prompt += `# Requirements\n\n- ${ cli_edit_ask_requirements . preloaded_context } \n- ${ cli_edit_ask_requirements . restrict_shell_commands } \n\n`
259+ cli_prompt += `# Task\n\n${ patch_repair_task_instructions } `
260+
261+ const config_codeWebChat = vscode . workspace . getConfiguration ( 'codeWebChat' )
262+ const agent_configs = config_codeWebChat . get < any [ ] > ( 'agents' , [ ] ) || [ ]
263+ const default_agent = agent_configs . find (
264+ ( c : any ) => c . isDefaultForPatchRepair
265+ )
266+
267+ const use_quick_pick = ! default_agent
268+ const cli_configuration_name = default_agent
269+ ? default_agent . name
270+ : undefined
271+
272+ const invoke_cli_result = await invoke_agentic_cli ( {
273+ workspace_provider : params . prompt_view_provider . workspace_provider ,
274+ extension_context : params . prompt_view_provider . extension_context ,
275+ build_prompt : async ( ) => cli_prompt ,
276+ notification_title : 'Patch Repair' ,
277+ last_selected_workspace_state_key :
278+ LAST_SELECTED_WORKSPACE_FOR_PATCH_REPAIR_STATE_KEY ,
279+ last_used_agent_config_name :
280+ params . prompt_view_provider . extension_context . workspaceState . get < string > (
281+ LAST_USED_AGENT_FOR_PATCH_REPAIR_STATE_KEY
282+ ) ,
283+ cli_configuration_name,
284+ use_quick_pick,
285+ on_agent_selected : ( name ) => {
286+ params . prompt_view_provider . extension_context . workspaceState . update (
287+ LAST_USED_AGENT_FOR_PATCH_REPAIR_STATE_KEY ,
288+ name
289+ )
290+ params . prompt_view_provider . extension_context . globalState . update (
291+ LAST_USED_AGENT_FOR_PATCH_REPAIR_STATE_KEY ,
292+ name
293+ )
294+ } ,
295+ show_back_button : true ,
296+ isolate_in_temp_dir : true ,
297+ agent_args_type : 'isolated-dir'
298+ } )
299+
300+ if ( invoke_cli_result === 'back' ) {
301+ return handle_patch_repair ( { ...params , show_quick_pick : true } )
302+ }
303+
304+ if ( ! invoke_cli_result ) {
305+ return
306+ }
307+
308+ await vscode . commands . executeCommand ( 'codeWebChat.applyResponse' , {
309+ response : invoke_cli_result . agent_output
310+ } )
311+ return
312+ }
313+
238314 if ( action == 'copy' ) {
239315 let chatbot_prompt = ''
240316 for ( const item of files_to_process ) {
0 commit comments