blob: 88467bea41f7d8fca46b5aca69b975219b2bb9f7 [file] [log] [blame]
user5a7d60d2025-07-27 21:22:04 +04001package commands
2
3import (
4 "fmt"
5
6 "github.com/spf13/cobra"
7)
8
9var 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
14This command will:
15- Stop any running agents
16- Remove all agent-specific Git clone directories
17- Free up disk space used by clones
18
19Examples:
20 staff cleanup-clones`,
21 RunE: runCleanupClones,
22}
23
24// Note: Command is added in root.go init() function
25
26func 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")
iomodo50598c62025-07-27 22:06:32 +040051
user5a7d60d2025-07-27 21:22:04 +040052 return nil
iomodo50598c62025-07-27 22:06:32 +040053}