From bff44b8b59243a278eeb446118310e28afd94235 Mon Sep 17 00:00:00 2001 From: Tara Menon Date: Thu, 11 Jun 2026 21:49:06 +0530 Subject: [PATCH] Fix config loading priority: check ~/.config/ first on all platforms On macOS, dirs::config_dir() returns ~/Library/Application Support/, NOT ~/.config/. This caused the loader to skip the actual config file at ~/.config/gyandoot/config.toml and fall through to a stale ~/.gyandoot/config.yaml (which has no API keys). Fix: Check ~/.config/gyandoot/config.toml explicitly FIRST via home_dir(). This works identically on Linux and macOS. --- src/main.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f2f6e4..4a6cf41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -198,11 +198,26 @@ async fn cmd_run(profile_name: &str, platform: &str, prompt: Option<&str>) -> an /// Load agent config from user config files with fallback to defaults. /// /// Resolution order: -/// 1. `~/.config/gyandoot/config.toml` (XDG primary) -/// 2. `~/.gyandoot/config.yaml` (legacy) -/// 3. `AgentConfig::default()` (hardcoded defaults) +/// 1. `~/.config/gyandoot/config.toml` (primary — set up via `gyandoot setup` or `gyandoot init`) +/// 2. `~/.config/gyandoot/config.toml` via XDG (macOS: ~/Library/Application Support/) +/// 3. `~/.gyandoot/config.yaml` (legacy) +/// 4. `AgentConfig::default()` (hardcoded defaults) fn load_agent_config() -> gyandoot_core::config::AgentConfig { - // 1. Try XDG-style config: ~/.config/gyandoot/config.toml + // 1. Try ~/.config/gyandoot/config.toml (explicit — works on all platforms) + if let Some(home) = dirs::home_dir() { + let explicit_path = home.join(".config").join("gyandoot").join("config.toml"); + if explicit_path.exists() { + match gyandoot_core::config::ConfigLoader::from_file(&explicit_path) { + Ok(gyandoot_cfg) => { + tracing::info!("Loaded config from {}", explicit_path.display()); + return gyandoot_core::config::AgentConfig::from(gyandoot_cfg); + } + Err(e) => tracing::warn!("Failed to parse {}: {}", explicit_path.display(), e), + } + } + } + + // 2. Try XDG-style config (macOS: ~/Library/Application Support/) if let Some(cfg_dir) = dirs::config_dir() { let xdg_path = cfg_dir.join("gyandoot").join("config.toml"); if xdg_path.exists() { @@ -216,7 +231,7 @@ fn load_agent_config() -> gyandoot_core::config::AgentConfig { } } - // 2. Try legacy config: ~/.gyandoot/config.yaml + // 3. Try legacy config: ~/.gyandoot/config.yaml if let Some(home) = dirs::home_dir() { let legacy_path = home.join(".gyandoot").join("config.yaml"); if legacy_path.exists() {