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.
This commit is contained in:
2026-06-11 21:49:06 +05:30
parent fb01b2595a
commit bff44b8b59

View File

@@ -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. /// Load agent config from user config files with fallback to defaults.
/// ///
/// Resolution order: /// Resolution order:
/// 1. `~/.config/gyandoot/config.toml` (XDG primary) /// 1. `~/.config/gyandoot/config.toml` (primary — set up via `gyandoot setup` or `gyandoot init`)
/// 2. `~/.gyandoot/config.yaml` (legacy) /// 2. `~/.config/gyandoot/config.toml` via XDG (macOS: ~/Library/Application Support/)
/// 3. `AgentConfig::default()` (hardcoded defaults) /// 3. `~/.gyandoot/config.yaml` (legacy)
/// 4. `AgentConfig::default()` (hardcoded defaults)
fn load_agent_config() -> gyandoot_core::config::AgentConfig { 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() { if let Some(cfg_dir) = dirs::config_dir() {
let xdg_path = cfg_dir.join("gyandoot").join("config.toml"); let xdg_path = cfg_dir.join("gyandoot").join("config.toml");
if xdg_path.exists() { 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() { if let Some(home) = dirs::home_dir() {
let legacy_path = home.join(".gyandoot").join("config.yaml"); let legacy_path = home.join(".gyandoot").join("config.yaml");
if legacy_path.exists() { if legacy_path.exists() {