package commands import ( "fmt" "os" "github.com/muyue/muyue/internal/config" "github.com/muyue/muyue/internal/desktop" "github.com/muyue/muyue/internal/profiler" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ Use: "muyue", Short: "Muyue is your AI-powered development companion", Long: `Muyue - A modern development environment with AI assistance, tool management, and seamless desktop integration.`, RunE: func(cmd *cobra.Command, args []string) error { cfg := loadOrSetupConfig() return desktop.Run(cfg, os.Args[1:]) }, } func Execute() error { return rootCmd.Execute() } func loadOrSetupConfig() *config.MuyueConfig { if !config.Exists() { fmt.Println("First time setup detected!") cfg, err := profiler.RunFirstTimeSetup() if err != nil { fmt.Fprintf(os.Stderr, "Setup error: %v\n", err) os.Exit(1) } for i := range cfg.AI.Providers { if cfg.AI.Providers[i].Active && cfg.AI.Providers[i].APIKey == "" { key, err := profiler.AskAPIKey(cfg.AI.Providers[i].Name) if err == nil && key != "" { cfg.AI.Providers[i].APIKey = key } } } if err := config.Save(cfg); err != nil { fmt.Fprintf(os.Stderr, "Save error: %v\n", err) os.Exit(1) } fmt.Println("\nSetup complete! Starting muyue...") return cfg } cfg, err := config.Load() if err != nil { fmt.Fprintf(os.Stderr, "Config load error: %v\n", err) os.Exit(1) } return cfg } func init() { rootCmd.PersistentFlags().Int("port", 8080, "HTTP port for the desktop server") rootCmd.PersistentFlags().Bool("no-open", false, "Don't open browser on startup") }