2026-02-28 19:56:23 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
2026-02-28 20:52:03 +00:00
|
|
|
"path/filepath"
|
2026-02-28 19:56:23 +00:00
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-28 20:52:03 +00:00
|
|
|
func Load() {
|
2026-03-01 12:08:49 +00:00
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
// Fall back to current directory if home not found
|
|
|
|
|
home = "."
|
|
|
|
|
}
|
2026-02-28 20:52:03 +00:00
|
|
|
configPath := filepath.Join(home, ".config", "grokkit")
|
|
|
|
|
|
|
|
|
|
viper.SetConfigName("config")
|
|
|
|
|
viper.SetConfigType("toml")
|
|
|
|
|
viper.AddConfigPath(configPath)
|
|
|
|
|
viper.AddConfigPath(".")
|
2026-02-28 22:59:16 +00:00
|
|
|
viper.AutomaticEnv()
|
2026-02-28 20:52:03 +00:00
|
|
|
|
|
|
|
|
viper.SetDefault("default_model", "grok-4")
|
|
|
|
|
viper.SetDefault("temperature", 0.7)
|
|
|
|
|
|
2026-03-01 12:08:49 +00:00
|
|
|
// Config file is optional, so we ignore read errors
|
2026-02-28 22:59:16 +00:00
|
|
|
_ = viper.ReadInConfig()
|
2026-02-28 20:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetModel(flagModel string) string {
|
|
|
|
|
if flagModel != "" {
|
|
|
|
|
if alias := viper.GetString("aliases." + flagModel); alias != "" {
|
|
|
|
|
return alias
|
|
|
|
|
}
|
|
|
|
|
return flagModel
|
|
|
|
|
}
|
|
|
|
|
return viper.GetString("default_model")
|
2026-02-28 22:59:16 +00:00
|
|
|
}
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
|
|
|
|
|
func GetTemperature() float64 {
|
|
|
|
|
return viper.GetFloat64("temperature")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetTimeout() int {
|
|
|
|
|
timeout := viper.GetInt("timeout")
|
|
|
|
|
if timeout <= 0 {
|
|
|
|
|
return 60 // Default 60 seconds
|
|
|
|
|
}
|
|
|
|
|
return timeout
|
|
|
|
|
}
|