grokkit/config/config.go
Greg Gauthier ce878f058f
All checks were successful
CI / Test (pull_request) Successful in 36s
CI / Lint (pull_request) Successful in 26s
CI / Build (pull_request) Successful in 20s
feat(workon): enhance command with IDE integration and README updates
- Add colorized output for success/error messages
- Change custom message flag from -m to -M
- Implement branch prefixing (feature/ or fix/)
- Add config for workon.model and workon.ide
- Update README.md index on task completion
- Integrate IDE opening if configured
- Refine error handling and logging
2026-03-31 22:04:33 +01:00

86 lines
2.4 KiB
Go

package config
import (
"os"
"path/filepath"
"github.com/spf13/viper"
)
// Load initializes the configuration from Viper
func Load() {
home, err := os.UserHomeDir()
if err != nil {
// Fall back to current directory if home not found
home = "."
}
configPath := filepath.Join(home, ".config", "grokkit")
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(configPath)
viper.AddConfigPath(".")
viper.AutomaticEnv()
viper.SetDefault("default_model", "grok-4")
viper.SetDefault("temperature", 0.7)
viper.SetDefault("log_level", "info")
viper.SetDefault("timeout", 60)
viper.SetDefault("commands.agent.model", "grok-4")
viper.SetDefault("commands.chat.model", "grok-4")
viper.SetDefault("commands.commit.model", "grok-4")
viper.SetDefault("commands.commitmsg.model", "grok-4")
viper.SetDefault("commands.edit.model", "grok-4")
viper.SetDefault("commands.history.model", "grok-4")
viper.SetDefault("commands.lint.model", "grok-4-1-fast-non-reasoning")
viper.SetDefault("commands.prdescribe.model", "grok-4")
viper.SetDefault("commands.review.model", "grok-4")
viper.SetDefault("commands.docs.model", "grok-4")
viper.SetDefault("commands.query.model", "grok-4-1-fast-non-reasoning")
viper.SetDefault("commands.workon.model", "grok-4-1-fast-non-reasoning")
viper.SetDefault("commands.workon.ide", "")
// Config file is optional, so we ignore read errors
_ = viper.ReadInConfig()
}
// GetModel returns the model to use for a specific command, considering flags and aliases
func GetModel(commandName string, flagModel string) string {
if flagModel != "" {
if alias := viper.GetString("aliases." + flagModel); alias != "" {
return alias
}
return flagModel
}
cmdModel := viper.GetString("commands." + commandName + ".model")
if cmdModel != "" {
return cmdModel
}
return viper.GetString("default_model")
}
// GetTemperature returns the temperature from the configuration
func GetTemperature() float64 {
return viper.GetFloat64("temperature")
}
// GetTimeout returns the timeout from the configuration
func GetTimeout() int {
timeout := viper.GetInt("timeout")
if timeout <= 0 {
return 60 // Default 60 seconds
}
return timeout
}
// GetIDECommand returns the configured IDE command for workon, or empty string if unset.
func GetIDECommand() string {
return viper.GetString("commands.workon.ide")
}
// GetLogLevel returns the log level from the configuration
func GetLogLevel() string {
return viper.GetString("log_level")
}