@@ -532,7 +532,15 @@ <h4 class="text-sm font-bold text-black mb-2">Actions</h4>
532532 const result = await response . json ( ) ;
533533
534534 if ( window . workspaceManager && window . workspaceManager . currentState ) {
535+ // Store the agent file
535536 window . workspaceManager . currentState . addFile ( result . path , result . content ) ;
537+
538+ // Store agent name to path mapping in metadata (for easier removal)
539+ if ( ! window . workspaceManager . currentState . agentMappings ) {
540+ window . workspaceManager . currentState . agentMappings = { } ;
541+ }
542+ window . workspaceManager . currentState . agentMappings [ agentName ] = result . path ;
543+
536544 window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
537545 window . workspaceManager . render ( ) ;
538546 }
@@ -675,13 +683,51 @@ <h4 class="text-sm font-bold text-black mb-2">Actions</h4>
675683 try {
676684 if ( window . workspaceManager && window . workspaceManager . currentState ) {
677685 const state = window . workspaceManager . currentState ;
686+ let filesToRemove = [ ] ;
687+
688+ // First check if we have a stored mapping for this agent
689+ if ( state . agentMappings && state . agentMappings [ agentName ] ) {
690+ const mappedPath = state . agentMappings [ agentName ] ;
691+ if ( state . files [ mappedPath ] ) {
692+ filesToRemove . push ( mappedPath ) ;
693+ }
694+ // Clean up the mapping
695+ delete state . agentMappings [ agentName ] ;
696+ }
697+
698+ // If no mapping found, search for the agent file
699+ if ( filesToRemove . length === 0 ) {
700+ // Find files in .claude/agents/ directory that match this agent
701+ filesToRemove = Object . keys ( state . files ) . filter ( path => {
702+ return path . startsWith ( '.claude/agents/' ) &&
703+ path . toLowerCase ( ) . includes ( agentName . toLowerCase ( ) . replace ( / [ - \s ] / g, '_' ) ) ;
704+ } ) ;
705+
706+ // If still no match, try alternative path patterns
707+ if ( filesToRemove . length === 0 ) {
708+ const alternativePaths = [
709+ `.claude/agents/${ agentName } .md` ,
710+ `.claude/agents/${ agentName . replace ( / [ - \s ] / g, '_' ) } .md` ,
711+ `.claude/agents/${ agentName . replace ( / [ - \s ] / g, '-' ) } .md`
712+ ] ;
713+
714+ alternativePaths . forEach ( path => {
715+ if ( state . files [ path ] ) {
716+ filesToRemove . push ( path ) ;
717+ }
718+ } ) ;
719+ }
720+ }
678721
679- // Remove the specific agent file
680- const agentPath = `.gitrules/agents/${ agentName } .md` ;
681- if ( state . files [ agentPath ] ) {
682- delete state . files [ agentPath ] ;
722+ // Remove all found files
723+ if ( filesToRemove . length > 0 ) {
724+ filesToRemove . forEach ( path => {
725+ delete state . files [ path ] ;
726+ } ) ;
683727 window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
684728 window . workspaceManager . render ( ) ;
729+ } else {
730+ console . warn ( `No agent files found for: ${ agentName } ` ) ;
685731 }
686732 }
687733 } catch ( error ) {
0 commit comments