| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | |
| 7 | "parrot/internal/config" |
| 8 | "parrot/internal/llm" |
| 9 | |
| 10 | "github.com/spf13/cobra" |
| 11 | ) |
| 12 | |
| 13 | var statusCmd = &cobra.Command{ |
| 14 | Use: "status", |
| 15 | Short: "Show parrot configuration and backend status", |
| 16 | Long: "Display current configuration, available backends, and their status", |
| 17 | Run: showStatus, |
| 18 | } |
| 19 | |
| 20 | func init() { |
| 21 | rootCmd.AddCommand(statusCmd) |
| 22 | } |
| 23 | |
| 24 | func showStatus(cmd *cobra.Command, args []string) { |
| 25 | fmt.Println("🦜 Parrot Status Report") |
| 26 | fmt.Println("━━━━━━━━━━━━━━━━━━━━━━") |
| 27 | |
| 28 | // Load configuration |
| 29 | cfg, err := config.LoadConfig() |
| 30 | if err != nil { |
| 31 | fmt.Printf("❌ Configuration Error: %v\n", err) |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | // Show configuration source |
| 36 | fmt.Println("\n📁 Configuration:") |
| 37 | configFound := false |
| 38 | for _, path := range config.GetConfigPaths() { |
| 39 | if _, err := os.Stat(path); err == nil { |
| 40 | fmt.Printf(" ✅ Loaded from: %s\n", path) |
| 41 | configFound = true |
| 42 | break |
| 43 | } |
| 44 | } |
| 45 | if !configFound { |
| 46 | fmt.Println(" ℹ️ Using default configuration (no config file found)") |
| 47 | } |
| 48 | |
| 49 | // General settings |
| 50 | fmt.Printf(" • Personality: %s\n", cfg.General.Personality) |
| 51 | fmt.Printf(" • Debug mode: %t\n", cfg.General.Debug) |
| 52 | fmt.Printf(" • Fallback only: %t\n", cfg.General.FallbackMode) |
| 53 | |
| 54 | // Initialize LLM manager to get status |
| 55 | manager := llm.NewLLMManager(cfg) |
| 56 | status := manager.GetStatus() |
| 57 | |
| 58 | // API Backend Status |
| 59 | fmt.Println("\n🌐 API Backend:") |
| 60 | if status["api_enabled"].(bool) { |
| 61 | fmt.Printf(" • Enabled: ✅\n") |
| 62 | fmt.Printf(" • Provider: %s\n", status["api_provider"]) |
| 63 | fmt.Printf(" • Model: %s\n", status["api_model"]) |
| 64 | if status["api_available"].(bool) { |
| 65 | fmt.Printf(" • Status: ✅ Available\n") |
| 66 | } else { |
| 67 | fmt.Printf(" • Status: ❌ Unavailable (check API key/endpoint)\n") |
| 68 | } |
| 69 | } else { |
| 70 | fmt.Printf(" • Enabled: ❌ (no API key configured)\n") |
| 71 | } |
| 72 | |
| 73 | // Local Backend Status |
| 74 | fmt.Println("\n🖥️ Local Backend:") |
| 75 | if status["local_enabled"].(bool) { |
| 76 | fmt.Printf(" • Enabled: ✅\n") |
| 77 | fmt.Printf(" • Provider: %s\n", status["local_provider"]) |
| 78 | fmt.Printf(" • Model: %s\n", status["local_model"]) |
| 79 | if status["local_available"].(bool) { |
| 80 | fmt.Printf(" • Status: ✅ Available\n") |
| 81 | } else { |
| 82 | fmt.Printf(" • Status: ❌ Unavailable (check if Ollama is running)\n") |
| 83 | } |
| 84 | } else { |
| 85 | fmt.Printf(" • Enabled: ❌\n") |
| 86 | } |
| 87 | |
| 88 | // Fallback Status |
| 89 | fmt.Println("\n🔄 Fallback Backend:") |
| 90 | fmt.Printf(" • Status: ✅ Always available\n") |
| 91 | |
| 92 | // Show active backend priority |
| 93 | fmt.Println("\n⚡ Backend Priority:") |
| 94 | if cfg.General.FallbackMode { |
| 95 | fmt.Println(" 1. 🔄 Fallback (forced)") |
| 96 | } else { |
| 97 | priority := 1 |
| 98 | if status["api_enabled"].(bool) { |
| 99 | if status["api_available"].(bool) { |
| 100 | fmt.Printf(" %d. 🌐 API (ready)\n", priority) |
| 101 | } else { |
| 102 | fmt.Printf(" %d. 🌐 API (unavailable)\n", priority) |
| 103 | } |
| 104 | priority++ |
| 105 | } |
| 106 | if status["local_enabled"].(bool) { |
| 107 | if status["local_available"].(bool) { |
| 108 | fmt.Printf(" %d. 🖥️ Local (ready)\n", priority) |
| 109 | } else { |
| 110 | fmt.Printf(" %d. 🖥️ Local (unavailable)\n", priority) |
| 111 | } |
| 112 | priority++ |
| 113 | } |
| 114 | fmt.Printf(" %d. 🔄 Fallback (always)\n", priority) |
| 115 | } |
| 116 | |
| 117 | // Configuration hints |
| 118 | fmt.Println("\n💡 Quick Setup:") |
| 119 | if !status["api_enabled"].(bool) { |
| 120 | fmt.Println(" • Set API key: export PARROT_API_KEY=\"your-key-here\"") |
| 121 | } |
| 122 | if !status["local_available"].(bool) && status["local_enabled"].(bool) { |
| 123 | fmt.Printf(" • Install model: ollama pull %s\n", status["local_model"]) |
| 124 | } |
| 125 | |
| 126 | fmt.Println("\n 📖 Use 'parrot config' to create a configuration file") |
| 127 | } |