@@ -283,11 +283,20 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
283283 // Switch to new context
284284 workspaceManager . switchContext ( contextId ) ;
285285
286+ // Initialize the state to activate the agents category and check the specific agent
287+ const state = workspaceManager . getState ( ) ;
288+ if ( state ) {
289+ // Activate the agents category
290+ state . setActionCategoryState ( 'agents' , true ) ;
291+ // Mark the specific agent as checked
292+ state . setActionItemState ( 'agents' , agentName , true ) ;
293+ }
294+
286295 // Install agent using the same function as workspace sidebar
287296 installAgentInContext ( agentName ) ;
288297
289- // Show workspace
290- showWorkspace ( ) ;
298+ // Show workspace with agents section in focus
299+ showWorkspace ( 'agents' , agentName ) ;
291300 } else {
292301 console . error ( 'Failed to create new context' ) ;
293302 }
@@ -309,11 +318,20 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
309318 // Switch to new context
310319 workspaceManager . switchContext ( contextId ) ;
311320
321+ // Initialize the state to activate the MCPs category and check the specific MCP
322+ const state = workspaceManager . getState ( ) ;
323+ if ( state ) {
324+ // Activate the MCPs category
325+ state . setActionCategoryState ( 'mcps' , true ) ;
326+ // Mark the specific MCP as checked
327+ state . setActionItemState ( 'mcps' , mcpName , true ) ;
328+ }
329+
312330 // Install MCP using the same function as workspace sidebar
313331 installMCPInContext ( mcpName ) ;
314332
315- // Show workspace
316- showWorkspace ( ) ;
333+ // Show workspace with MCPs section in focus
334+ showWorkspace ( 'mcps' , mcpName ) ;
317335 } else {
318336 console . error ( 'Failed to create new context' ) ;
319337 }
@@ -335,11 +353,20 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
335353 // Switch to new context
336354 workspaceManager . switchContext ( contextId ) ;
337355
356+ // Initialize the state to activate the rules category and check the specific rule
357+ const state = workspaceManager . getState ( ) ;
358+ if ( state ) {
359+ // Activate the rules category
360+ state . setActionCategoryState ( 'rules' , true ) ;
361+ // Mark the specific rule as checked
362+ state . setActionItemState ( 'rules' , ruleName , true ) ;
363+ }
364+
338365 // Insert rule text directly into editor
339366 insertRuleInContext ( ruleName ) ;
340367
341- // Show workspace
342- showWorkspace ( ) ;
368+ // Show workspace with rules section in focus
369+ showWorkspace ( 'rules' , ruleName ) ;
343370 } else {
344371 console . error ( 'Failed to create new context' ) ;
345372 }
@@ -353,11 +380,21 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
353380 if ( response . ok ) {
354381 const result = await response . json ( ) ;
355382
356- // Add to virtual workspace
357- if ( window . workspaceManager && window . workspaceManager . currentState ) {
358- window . workspaceManager . currentState . addFile ( result . path , result . content ) ;
359- window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
360- window . workspaceManager . render ( ) ;
383+ if ( window . workspaceManager ) {
384+ const state = window . workspaceManager . getState ( ) ;
385+ if ( state ) {
386+ // Store agent name to path mapping in metadata (for easier removal)
387+ if ( ! state . agentMappings ) {
388+ state . agentMappings = { } ;
389+ }
390+ state . agentMappings [ agentName ] = result . path ;
391+
392+ // Mark the agent as checked in action state
393+ state . setActionItemState ( 'agents' , agentName , true ) ;
394+ }
395+
396+ // Use includeFile which properly handles saving and rendering
397+ window . workspaceManager . includeFile ( result . path , result . content , true ) ;
361398 }
362399 } else {
363400 const error = await response . json ( ) ;
@@ -394,11 +431,14 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
394431 if ( response . ok ) {
395432 const result = await response . json ( ) ;
396433
397- // Add to virtual workspace
398- if ( window . workspaceManager && window . workspaceManager . currentState ) {
399- window . workspaceManager . currentState . addFile ( result . path , result . content ) ;
400- window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
401- window . workspaceManager . render ( ) ;
434+ if ( window . workspaceManager ) {
435+ const state = window . workspaceManager . getState ( ) ;
436+ if ( state && ! result . was_removed ) {
437+ // Mark the MCP as checked in action state
438+ state . setActionItemState ( 'mcps' , mcpName , true ) ;
439+ }
440+ // Use includeFile which properly handles saving and rendering
441+ window . workspaceManager . includeFile ( result . path , result . content , true ) ;
402442 }
403443 } else {
404444 const error = await response . json ( ) ;
@@ -429,11 +469,14 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
429469 const ruleContent = result . content . trim ( ) ;
430470 const newContent = currentContent + ( currentContent ? '\n' : '' ) + ruleContent ;
431471
432- // Add to virtual workspace
433- if ( window . workspaceManager && window . workspaceManager . currentState ) {
434- window . workspaceManager . currentState . addFile ( 'CLAUDE.md' , newContent ) ;
435- window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
436- window . workspaceManager . render ( ) ;
472+ if ( window . workspaceManager ) {
473+ const state = window . workspaceManager . getState ( ) ;
474+ if ( state ) {
475+ // Mark the rule as checked in action state
476+ state . setActionItemState ( 'rules' , ruleName , true ) ;
477+ }
478+ // Use includeFile which properly handles saving and rendering
479+ window . workspaceManager . includeFile ( 'CLAUDE.md' , newContent , true ) ;
437480 }
438481 } else {
439482 const error = await response . json ( ) ;
@@ -444,8 +487,8 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
444487 }
445488}
446489
447- // Show workspace with fade transition
448- function showWorkspace ( ) {
490+ // Show workspace with fade transition and focus on specific section
491+ function showWorkspace ( focusSection = null , focusItem = null ) {
449492 const quickActionsSection = document . getElementById ( 'quick-actions-section' ) ;
450493 const workspaceSection = document . querySelector ( '.workspace-container' ) ;
451494 const backButtonContainer = document . getElementById ( 'back-btn-container' ) ;
@@ -488,6 +531,11 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
488531
489532 // Clear the editor and set focus
490533 clearEditorAndFocus ( ) ;
534+
535+ // Expand the relevant section if specified
536+ if ( focusSection ) {
537+ expandWorkspaceSection ( focusSection , focusItem ) ;
538+ }
491539 } , 50 ) ;
492540 } , 300 ) ;
493541}
@@ -539,6 +587,52 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
539587 }
540588}
541589
590+ // Expand the relevant workspace section and show it in priority
591+ function expandWorkspaceSection ( sectionType , itemName ) {
592+ // Wait a bit for the workspace to be fully rendered
593+ setTimeout ( ( ) => {
594+ // First restore the action states to ensure UI is in sync
595+ if ( window . restoreActionStates ) {
596+ window . restoreActionStates ( ) ;
597+ }
598+
599+ // Then wait a bit more for the UI to update before interacting
600+ setTimeout ( ( ) => {
601+ if ( sectionType === 'agents' ) {
602+ // Make sure the dropdown data is loaded for agents
603+ if ( window . loadDropdownData ) {
604+ window . loadDropdownData ( 'agents' ) ;
605+ }
606+ } else if ( sectionType === 'mcps' ) {
607+ // Make sure the dropdown data is loaded for MCPs
608+ if ( window . loadDropdownData ) {
609+ window . loadDropdownData ( 'mcps' ) ;
610+ }
611+ } else if ( sectionType === 'rules' ) {
612+ // Make sure the dropdown data is loaded for rules
613+ if ( window . loadDropdownData ) {
614+ window . loadDropdownData ( 'rules' ) ;
615+ }
616+ }
617+
618+ // Scroll to the workspace actions panel to show it in priority
619+ const workspaceActions = document . querySelector ( '.workspace-actions' ) ;
620+ if ( workspaceActions ) {
621+ // Get the position of the workspace actions panel
622+ const rect = workspaceActions . getBoundingClientRect ( ) ;
623+ const currentScrollTop = window . pageYOffset ;
624+ const actionsTop = currentScrollTop + rect . top ;
625+ const navbarHeight = 64 ; // h-16 = 64px
626+ const buffer = 20 ; // Small buffer below navbar
627+ const targetScrollTop = Math . max ( 0 , actionsTop - navbarHeight - buffer ) ;
628+
629+ // Smooth scroll to the actions panel
630+ window . scrollTo ( { top : targetScrollTop , behavior : 'smooth' } ) ;
631+ }
632+ } , 100 ) ;
633+ } , 200 ) ;
634+ }
635+
542636// Hide workspace with fade transition
543637function hideWorkspace ( ) {
544638 const quickActionsSection = document . getElementById ( 'quick-actions-section' ) ;
0 commit comments