@@ -26,8 +26,8 @@ import {
2626import { TOOL_GROUPS , GROUP_DISPLAY_NAMES , ToolGroup } from "../../../../src/shared/tool-groups"
2727import { vscode } from "../../utils/vscode"
2828
29- // Get all available groups from GROUP_DISPLAY_NAMES
30- const availableGroups = Object . keys ( TOOL_GROUPS ) as ToolGroup [ ]
29+ // Get all available groups that should show in prompts view
30+ const availableGroups = ( Object . keys ( TOOL_GROUPS ) as ToolGroup [ ] ) . filter ( ( group ) => ! TOOL_GROUPS [ group ] . alwaysAvailable )
3131
3232type PromptsViewProps = {
3333 onDone : ( ) => void
@@ -65,6 +65,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
6565 const [ isToolsEditMode , setIsToolsEditMode ] = useState ( false )
6666 const [ isCreateModeDialogOpen , setIsCreateModeDialogOpen ] = useState ( false )
6767 const [ activeSupportTab , setActiveSupportTab ] = useState < SupportPromptType > ( "ENHANCE" )
68+ const [ selectedModeTab , setSelectedModeTab ] = useState < string > ( mode )
6869
6970 // Direct update functions
7071 const updateAgentPrompt = useCallback (
@@ -110,26 +111,23 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
110111 text : slug ,
111112 } )
112113 } , [ ] )
113-
114- // Handle mode switching with explicit state initialization
114+ // Handle mode tab selection without actually switching modes
115115 const handleModeSwitch = useCallback (
116116 ( modeConfig : ModeConfig ) => {
117- if ( modeConfig . slug === mode ) return // Prevent unnecessary updates
118-
119- // First switch the mode
120- switchMode ( modeConfig . slug )
117+ if ( modeConfig . slug === selectedModeTab ) return // Prevent unnecessary updates
121118
122- // Exit tools edit mode when switching modes
119+ // Update selected tab and reset tools edit mode
120+ setSelectedModeTab ( modeConfig . slug )
123121 setIsToolsEditMode ( false )
124122 } ,
125- [ mode , switchMode , setIsToolsEditMode ] ,
123+ [ selectedModeTab , setIsToolsEditMode ] ,
126124 )
127125
128126 // Helper function to get current mode's config
129127 const getCurrentMode = useCallback ( ( ) : ModeConfig | undefined => {
130- const findMode = ( m : ModeConfig ) : boolean => m . slug === mode
128+ const findMode = ( m : ModeConfig ) : boolean => m . slug === selectedModeTab
131129 return customModes ?. find ( findMode ) || modes . find ( findMode )
132- } , [ mode , customModes , modes ] )
130+ } , [ selectedModeTab , customModes , modes ] )
133131
134132 // Helper function to safely access mode properties
135133 const getModeProperty = < T extends keyof ModeConfig > (
@@ -155,6 +153,11 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
155153 }
156154 } , [ isCreateModeDialogOpen ] )
157155
156+ // Keep selected tab in sync with actual mode
157+ useEffect ( ( ) => {
158+ setSelectedModeTab ( mode )
159+ } , [ mode ] )
160+
158161 // Helper function to generate a unique slug from a name
159162 const generateSlug = useCallback ( ( name : string , attempt = 0 ) : string => {
160163 const baseSlug = name
@@ -184,22 +187,13 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
184187 groups : newModeGroups ,
185188 }
186189 updateCustomMode ( newModeSlug , newMode )
187- switchMode ( newModeSlug )
188190 setIsCreateModeDialogOpen ( false )
189191 setNewModeName ( "" )
190192 setNewModeSlug ( "" )
191193 setNewModeRoleDefinition ( "" )
192194 setNewModeCustomInstructions ( "" )
193195 setNewModeGroups ( availableGroups )
194- } , [
195- newModeName ,
196- newModeSlug ,
197- newModeRoleDefinition ,
198- newModeCustomInstructions ,
199- newModeGroups ,
200- updateCustomMode ,
201- switchMode ,
202- ] )
196+ } , [ newModeName , newModeSlug , newModeRoleDefinition , newModeCustomInstructions , newModeGroups , updateCustomMode ] )
203197
204198 const isNameOrSlugTaken = useCallback (
205199 ( name : string , slug : string ) => {
@@ -479,7 +473,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
479473 padding : "4px 0" ,
480474 } } >
481475 { modes . map ( ( modeConfig ) => {
482- const isActive = mode === modeConfig . slug
476+ const isActive = selectedModeTab === modeConfig . slug
483477 return (
484478 < button
485479 key = { modeConfig . slug }
@@ -507,20 +501,22 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
507501
508502 < div style = { { marginBottom : "20px" } } >
509503 { /* Only show name and delete for custom modes */ }
510- { mode && findModeBySlug ( mode , customModes ) && (
504+ { selectedModeTab && findModeBySlug ( selectedModeTab , customModes ) && (
511505 < div style = { { display : "flex" , gap : "12px" , marginBottom : "16px" } } >
512506 < div style = { { flex : 1 } } >
513507 < div style = { { fontWeight : "bold" , marginBottom : "4px" } } > Name</ div >
514508 < div style = { { display : "flex" , gap : "8px" } } >
515509 < VSCodeTextField
516- value = { getModeProperty ( findModeBySlug ( mode , customModes ) , "name" ) ?? "" }
510+ value = {
511+ getModeProperty ( findModeBySlug ( selectedModeTab , customModes ) , "name" ) ?? ""
512+ }
517513 onChange = { ( e : Event | React . FormEvent < HTMLElement > ) => {
518514 const target =
519515 ( e as CustomEvent ) ?. detail ?. target ||
520516 ( ( e as any ) . target as HTMLInputElement )
521- const customMode = findModeBySlug ( mode , customModes )
517+ const customMode = findModeBySlug ( selectedModeTab , customModes )
522518 if ( customMode ) {
523- updateCustomMode ( mode , {
519+ updateCustomMode ( selectedModeTab , {
524520 ...customMode ,
525521 name : target . value ,
526522 } )
@@ -534,7 +530,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
534530 onClick = { ( ) => {
535531 vscode . postMessage ( {
536532 type : "deleteCustomMode" ,
537- slug : mode ,
533+ slug : selectedModeTab ,
538534 } )
539535 } } >
540536 < span className = "codicon codicon-trash" > </ span >
@@ -552,7 +548,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
552548 marginBottom : "4px" ,
553549 } } >
554550 < div style = { { fontWeight : "bold" } } > Role Definition</ div >
555- { ! findModeBySlug ( mode , customModes ) && (
551+ { ! findModeBySlug ( selectedModeTab , customModes ) && (
556552 < VSCodeButton
557553 appearance = "icon"
558554 onClick = { ( ) => {
@@ -578,24 +574,28 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
578574 </ div >
579575 < VSCodeTextArea
580576 value = { ( ( ) => {
581- const customMode = findModeBySlug ( mode , customModes )
582- const prompt = customModePrompts ?. [ mode ] as PromptComponent
583- return customMode ?. roleDefinition ?? prompt ?. roleDefinition ?? getRoleDefinition ( mode )
577+ const customMode = findModeBySlug ( selectedModeTab , customModes )
578+ const prompt = customModePrompts ?. [ selectedModeTab ] as PromptComponent
579+ return (
580+ customMode ?. roleDefinition ??
581+ prompt ?. roleDefinition ??
582+ getRoleDefinition ( selectedModeTab )
583+ )
584584 } ) ( ) }
585585 onChange = { ( e ) => {
586586 const value =
587587 ( e as CustomEvent ) ?. detail ?. target ?. value ||
588588 ( ( e as any ) . target as HTMLTextAreaElement ) . value
589- const customMode = findModeBySlug ( mode , customModes )
589+ const customMode = findModeBySlug ( selectedModeTab , customModes )
590590 if ( customMode ) {
591591 // For custom modes, update the JSON file
592- updateCustomMode ( mode , {
592+ updateCustomMode ( selectedModeTab , {
593593 ...customMode ,
594594 roleDefinition : value . trim ( ) || "" ,
595595 } )
596596 } else {
597597 // For built-in modes, update the prompts
598- updateAgentPrompt ( mode , {
598+ updateAgentPrompt ( selectedModeTab , {
599599 roleDefinition : value . trim ( ) || undefined ,
600600 } )
601601 }
@@ -760,25 +760,25 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
760760 </ div >
761761 < VSCodeTextArea
762762 value = { ( ( ) => {
763- const customMode = findModeBySlug ( mode , customModes )
764- const prompt = customModePrompts ?. [ mode ] as PromptComponent
763+ const customMode = findModeBySlug ( selectedModeTab , customModes )
764+ const prompt = customModePrompts ?. [ selectedModeTab ] as PromptComponent
765765 return customMode ?. customInstructions ?? prompt ?. customInstructions ?? ""
766766 } ) ( ) }
767767 onChange = { ( e ) => {
768768 const value =
769769 ( e as CustomEvent ) ?. detail ?. target ?. value ||
770770 ( ( e as any ) . target as HTMLTextAreaElement ) . value
771- const customMode = findModeBySlug ( mode , customModes )
771+ const customMode = findModeBySlug ( selectedModeTab , customModes )
772772 if ( customMode ) {
773773 // For custom modes, update the JSON file
774- updateCustomMode ( mode , {
774+ updateCustomMode ( selectedModeTab , {
775775 ...customMode ,
776776 customInstructions : value . trim ( ) || undefined ,
777777 } )
778778 } else {
779779 // For built-in modes, update the prompts
780- const existingPrompt = customModePrompts ?. [ mode ] as PromptComponent
781- updateAgentPrompt ( mode , {
780+ const existingPrompt = customModePrompts ?. [ selectedModeTab ] as PromptComponent
781+ updateAgentPrompt ( selectedModeTab , {
782782 ...existingPrompt ,
783783 customInstructions : value . trim ( ) || undefined ,
784784 } )
0 commit comments