From de801589db2a527c20d98ad07117c0c228b9f35f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 03:29:36 +0000 Subject: [PATCH] fix: resolve config not loading from ~/.docscontext/ or config.yml The config loader only searched ~/.DocsContext/ (case-sensitive on Linux) and restricted to .yaml extension via SetConfigType. Users creating ~/.docscontext/config.yml would silently fall back to ollama defaults. - Add ~/.docscontext/ as primary config search path (lowercase, conventional) - Remove SetConfigType("yaml") so Viper finds both .yaml and .yml - Add slog warnings when no config file is found, showing searched paths - Log which config file was loaded and the resolved LLM provider https://claude.ai/code/session_011Ryet7uu9j6VyzNGmUuaaj --- cmd/root.go | 2 +- internal/config/config.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 0ae16a7..13521ac 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,7 +33,7 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default ~/.DocsContext/config.yaml)") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default ~/.docscontext/config.yaml or ~/.DocsContext/config.yaml)") rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Log level: debug, info, warn, error") } diff --git a/internal/config/config.go b/internal/config/config.go index f7b2f6c..4bda3a0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "log/slog" "os" "path/filepath" "strings" @@ -95,13 +96,14 @@ func Load(cfgFile string) (*Config, error) { v.SetDefault("server.port", 8080) // Config file + defaultCfgDirLower := filepath.Join(home, ".docscontext") if cfgFile != "" { v.SetConfigFile(cfgFile) } else { + v.AddConfigPath(defaultCfgDirLower) v.AddConfigPath(defaultCfgDir) v.AddConfigPath(".") v.SetConfigName("config") - v.SetConfigType("yaml") } // Env overrides @@ -110,9 +112,15 @@ func Load(cfgFile string) (*Config, error) { v.AutomaticEnv() if err := v.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + slog.Warn("no config file found, using defaults", + "searched_paths", []string{defaultCfgDirLower, defaultCfgDir, "."}, + "expected_names", "config.yaml or config.yml") + } else { return nil, fmt.Errorf("reading config: %w", err) } + } else { + slog.Info("loaded config file", "path", v.ConfigFileUsed()) } var cfg Config @@ -120,6 +128,8 @@ func Load(cfgFile string) (*Config, error) { return nil, fmt.Errorf("unmarshaling config: %w", err) } + slog.Info("resolved LLM config", "provider", cfg.LLM.Provider) + // Expand home dir if strings.HasPrefix(cfg.DataDir, "~/") { cfg.DataDir = filepath.Join(home, cfg.DataDir[2:])