| package commands |
| |
| import ( |
| "fmt" |
| |
| "github.com/spf13/cobra" |
| ) |
| |
| var cleanupClonesCmd = &cobra.Command{ |
| Use: "cleanup-clones", |
| Short: "Clean up all agent Git clones", |
| Long: `Remove all agent Git clone directories to free up disk space. |
| |
| This command will: |
| - Stop any running agents |
| - Remove all agent-specific Git clone directories |
| - Free up disk space used by clones |
| |
| Examples: |
| staff cleanup-clones`, |
| RunE: runCleanupClones, |
| } |
| |
| // Note: Command is added in root.go init() function |
| |
| func runCleanupClones(cmd *cobra.Command, args []string) error { |
| if agentManager == nil { |
| return fmt.Errorf("agent manager not initialized") |
| } |
| |
| // Stop all running agents first |
| fmt.Println("Stopping all running agents...") |
| for _, agent := range cfg.Agents { |
| if agentManager.IsAgentRunning(agent.Name) { |
| if err := agentManager.StopAgent(agent.Name); err != nil { |
| fmt.Printf("Warning: Failed to stop agent %s: %v\n", agent.Name, err) |
| } else { |
| fmt.Printf("Stopped agent: %s\n", agent.Name) |
| } |
| } |
| } |
| |
| // Cleanup all clones by closing the agent manager |
| // This will trigger the cleanup automatically |
| if err := agentManager.Close(); err != nil { |
| return fmt.Errorf("failed to cleanup agent clones: %w", err) |
| } |
| |
| fmt.Println("✅ All agent Git clones have been cleaned up successfully!") |
| fmt.Println("💡 Clones will be recreated automatically when agents start working on tasks") |
| |
| return nil |
| } |