11import { Anthropic } from "@anthropic-ai/sdk"
2+ import delay from "delay"
23import axios from "axios"
34import fs from "fs/promises"
45import os from "os"
@@ -23,7 +24,6 @@ import {
2324 modes ,
2425 CustomPrompts ,
2526 PromptComponent ,
26- enhance ,
2727 ModeConfig ,
2828 defaultModeSlug ,
2929 getModeBySlug ,
@@ -40,10 +40,7 @@ import { enhancePrompt } from "../../utils/enhance-prompt"
4040import { getCommitInfo , searchCommits , getWorkingState } from "../../utils/git"
4141import { ConfigManager } from "../config/ConfigManager"
4242import { CustomModesManager } from "../config/CustomModesManager"
43- import {
44- defaultTemplates ,
45- createPrompt
46- } from "../prompts/code-actions"
43+ import { enhance , codeActionPrompt } from "../../shared/support-prompt"
4744
4845import { ACTION_NAMES } from "../CodeActionProvider"
4946
@@ -189,17 +186,27 @@ export class ClineProvider implements vscode.WebviewViewProvider {
189186
190187 public static async handleCodeAction (
191188 promptType : keyof typeof ACTION_NAMES ,
192- params : Record < string , string | any [ ] >
189+ params : Record < string , string | any [ ] > ,
193190 ) : Promise < void > {
194- const visibleProvider = ClineProvider . getVisibleInstance ( )
191+ let visibleProvider = ClineProvider . getVisibleInstance ( )
192+
193+ // If no visible provider, try to show the sidebar view
194+ if ( ! visibleProvider ) {
195+ await vscode . commands . executeCommand ( "roo-cline.SidebarProvider.focus" )
196+ // Wait briefly for the view to become visible
197+ await delay ( 100 )
198+ visibleProvider = ClineProvider . getVisibleInstance ( )
199+ }
200+
201+ // If still no visible provider, return
195202 if ( ! visibleProvider ) {
196203 return
197204 }
198205
199- const { utilPrompt } = await visibleProvider . getState ( )
206+ const { customPrompts } = await visibleProvider . getState ( )
207+
208+ const prompt = codeActionPrompt . create ( promptType , params , customPrompts )
200209
201- const template = utilPrompt ?. [ promptType ] ?? defaultTemplates [ promptType ]
202- const prompt = createPrompt ( template , params )
203210 await visibleProvider . initClineWithTask ( prompt )
204211 }
205212
@@ -297,7 +304,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
297304 experimentalDiffStrategy,
298305 } = await this . getState ( )
299306
300- const modePrompt = customPrompts ?. [ mode ]
307+ const modePrompt = customPrompts ?. [ mode ] as PromptComponent
301308 const effectiveInstructions = [ globalInstructions , modePrompt ?. customInstructions ] . filter ( Boolean ) . join ( "\n\n" )
302309
303310 this . cline = new Cline (
@@ -325,7 +332,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
325332 experimentalDiffStrategy,
326333 } = await this . getState ( )
327334
328- const modePrompt = customPrompts ?. [ mode ]
335+ const modePrompt = customPrompts ?. [ mode ] as PromptComponent
329336 const effectiveInstructions = [ globalInstructions , modePrompt ?. customInstructions ] . filter ( Boolean ) . join ( "\n\n" )
330337
331338 this . cline = new Cline (
@@ -804,29 +811,49 @@ export class ClineProvider implements vscode.WebviewViewProvider {
804811
805812 await this . postStateToWebview ( )
806813 break
807- case "updateEnhancedPrompt" :
808- const existingPrompts = ( await this . getGlobalState ( "customPrompts" ) ) || { }
814+ case "updateSupportPrompt" :
815+ try {
816+ if ( Object . keys ( message ?. values ?? { } ) . length === 0 ) {
817+ return
818+ }
809819
810- const updatedPrompts = {
811- ...existingPrompts ,
812- enhance : message . text ,
820+ const existingPrompts = ( await this . getGlobalState ( "customPrompts" ) ) || { }
821+
822+ const updatedPrompts = {
823+ ...existingPrompts ,
824+ ...message . values ,
825+ }
826+
827+ await this . updateGlobalState ( "customPrompts" , updatedPrompts )
828+ await this . postStateToWebview ( )
829+ } catch ( error ) {
830+ console . error ( "Error update support prompt:" , error )
831+ vscode . window . showErrorMessage ( "Failed to update support prompt" )
813832 }
833+ break
834+ case "resetSupportPrompt" :
835+ try {
836+ if ( ! message ?. text ) {
837+ return
838+ }
839+
840+ const existingPrompts = ( ( await this . getGlobalState ( "customPrompts" ) ) || { } ) as Record <
841+ string ,
842+ any
843+ >
814844
815- await this . updateGlobalState ( "customPrompts" , updatedPrompts )
845+ const updatedPrompts = {
846+ ...existingPrompts ,
847+ }
816848
817- // Get current state and explicitly include customPrompts
818- const currentState = await this . getState ( )
849+ updatedPrompts [ message . text ] = undefined
819850
820- const stateWithPrompts = {
821- ...currentState ,
822- customPrompts : updatedPrompts ,
851+ await this . updateGlobalState ( "customPrompts" , updatedPrompts )
852+ await this . postStateToWebview ( )
853+ } catch ( error ) {
854+ console . error ( "Error reset support prompt:" , error )
855+ vscode . window . showErrorMessage ( "Failed to reset support prompt" )
823856 }
824-
825- // Post state with prompts
826- this . view ?. webview . postMessage ( {
827- type : "state" ,
828- state : stateWithPrompts ,
829- } )
830857 break
831858 case "updatePrompt" :
832859 if ( message . promptMode && message . customPrompt !== undefined ) {
0 commit comments