Files
MuyueWorkspace/internal/config/config.go
Augustin 1be4fc061f
All checks were successful
CI / build (push) Successful in 1m45s
feat: smart setup wizard - sort choices by system detection
- Editors sorted by install status + platform relevance
- Languages sorted by detected runtimes/tools on system
- AI providers sorted by platform + local ollama detection
- Added Cursor, Zed editors; Dart/Flutter, Zig languages
- Added Ollama and OpenAI as provider options
- Installed tools show "(installed)" label in editor list

💘 Generated with Crush

Assisted-by: GLM-5.1 via Crush <crush@charm.land>
2026-04-20 00:02:20 +02:00

180 lines
3.6 KiB
Go

package config
import (
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
type Profile struct {
Name string `yaml:"name"`
Pseudo string `yaml:"pseudo"`
Email string `yaml:"email"`
Languages []string `yaml:"languages"`
Preferences struct {
Editor string `yaml:"editor"`
Shell string `yaml:"shell"`
Theme string `yaml:"theme"`
DefaultAI string `yaml:"default_ai"`
AutoUpdate bool `yaml:"auto_update"`
CheckOnStart bool `yaml:"check_on_start"`
} `yaml:"preferences"`
}
type AIProvider struct {
Name string `yaml:"name"`
APIKey string `yaml:"api_key,omitempty"`
BaseURL string `yaml:"base_url,omitempty"`
Model string `yaml:"model"`
Active bool `yaml:"active"`
}
type ToolConfig struct {
Name string `yaml:"name"`
Installed bool `yaml:"installed"`
Version string `yaml:"version"`
AutoUpdate bool `yaml:"auto_update"`
}
type MuyueConfig struct {
Version string `yaml:"version"`
Profile Profile `yaml:"profile"`
AI struct {
Providers []AIProvider `yaml:"providers"`
} `yaml:"ai"`
Tools []ToolConfig `yaml:"tools"`
BMAD struct {
Installed bool `yaml:"installed"`
Version string `yaml:"version"`
Global bool `yaml:"global"`
} `yaml:"bmad"`
Terminal struct {
CustomPrompt bool `yaml:"custom_prompt"`
PromptTheme string `yaml:"prompt_theme"`
} `yaml:"terminal"`
}
func ConfigDir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
dir := filepath.Join(home, ".muyue")
return dir, nil
}
func ConfigPath() (string, error) {
dir, err := ConfigDir()
if err != nil {
return "", err
}
return filepath.Join(dir, "config.yaml"), nil
}
func Exists() bool {
path, err := ConfigPath()
if err != nil {
return false
}
_, err = os.Stat(path)
return err == nil
}
func Load() (*MuyueConfig, error) {
path, err := ConfigPath()
if err != nil {
return nil, err
}
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("reading config: %w", err)
}
var cfg MuyueConfig
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parsing config: %w", err)
}
return &cfg, nil
}
func Save(cfg *MuyueConfig) error {
dir, err := ConfigDir()
if err != nil {
return err
}
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("creating config dir: %w", err)
}
path := filepath.Join(dir, "config.yaml")
data, err := yaml.Marshal(cfg)
if err != nil {
return fmt.Errorf("marshaling config: %w", err)
}
if err := os.WriteFile(path, data, 0600); err != nil {
return fmt.Errorf("writing config: %w", err)
}
return nil
}
func Default() *MuyueConfig {
cfg := &MuyueConfig{
Version: "0.1.0",
Profile: Profile{
Name: "",
Pseudo: "muyue",
Languages: []string{},
},
}
cfg.Profile.Preferences.DefaultAI = "minimax"
cfg.Profile.Preferences.AutoUpdate = true
cfg.Profile.Preferences.CheckOnStart = true
cfg.Profile.Preferences.Theme = "charm"
cfg.AI.Providers = []AIProvider{
{
Name: "minimax",
Model: "MiniMax-M2.7",
BaseURL: "https://api.minimax.io/v1",
Active: true,
},
{
Name: "zai",
Model: "glm",
Active: false,
},
{
Name: "anthropic",
Model: "claude-sonnet-4-20250514",
Active: false,
},
{
Name: "openai",
Model: "gpt-4o",
BaseURL: "https://api.openai.com/v1",
Active: false,
},
{
Name: "ollama",
Model: "llama3",
BaseURL: "http://localhost:11434/api",
Active: false,
},
}
cfg.BMAD.Global = true
cfg.Terminal.CustomPrompt = true
cfg.Terminal.PromptTheme = "zerotwo"
return cfg
}