| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 1 | package commands |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/spf13/cobra" |
| 7 | ) |
| 8 | |
| 9 | var cleanupClonesCmd = &cobra.Command{ |
| 10 | Use: "cleanup-clones", |
| 11 | Short: "Clean up all agent Git clones", |
| 12 | Long: `Remove all agent Git clone directories to free up disk space. |
| 13 | |
| 14 | This command will: |
| 15 | - Stop any running agents |
| 16 | - Remove all agent-specific Git clone directories |
| 17 | - Free up disk space used by clones |
| 18 | |
| 19 | Examples: |
| 20 | staff cleanup-clones`, |
| 21 | RunE: runCleanupClones, |
| 22 | } |
| 23 | |
| 24 | // Note: Command is added in root.go init() function |
| 25 | |
| 26 | func runCleanupClones(cmd *cobra.Command, args []string) error { |
| 27 | if agentManager == nil { |
| 28 | return fmt.Errorf("agent manager not initialized") |
| 29 | } |
| 30 | |
| 31 | // Stop all running agents first |
| 32 | fmt.Println("Stopping all running agents...") |
| 33 | for _, agent := range cfg.Agents { |
| 34 | if agentManager.IsAgentRunning(agent.Name) { |
| 35 | if err := agentManager.StopAgent(agent.Name); err != nil { |
| 36 | fmt.Printf("Warning: Failed to stop agent %s: %v\n", agent.Name, err) |
| 37 | } else { |
| 38 | fmt.Printf("Stopped agent: %s\n", agent.Name) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Cleanup all clones by closing the agent manager |
| 44 | // This will trigger the cleanup automatically |
| 45 | if err := agentManager.Close(); err != nil { |
| 46 | return fmt.Errorf("failed to cleanup agent clones: %w", err) |
| 47 | } |
| 48 | |
| 49 | fmt.Println("✅ All agent Git clones have been cleaned up successfully!") |
| 50 | fmt.Println("💡 Clones will be recreated automatically when agents start working on tasks") |
| iomodo | 50598c6 | 2025-07-27 22:06:32 +0400 | [diff] [blame] | 51 | |
| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 52 | return nil |
| iomodo | 50598c6 | 2025-07-27 22:06:32 +0400 | [diff] [blame] | 53 | } |