From 6459e5286a7f793ef7a5b3733afa1874c5b95828 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Sun, 12 Apr 2026 11:31:45 +0800 Subject: [PATCH] fix(acp): use XDG paths for opencode config/cache instead of platform-native dirs --- src-tauri/src/acp/opencode_plugins.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/acp/opencode_plugins.rs b/src-tauri/src/acp/opencode_plugins.rs index df10bd7..7341735 100644 --- a/src-tauri/src/acp/opencode_plugins.rs +++ b/src-tauri/src/acp/opencode_plugins.rs @@ -47,12 +47,32 @@ pub struct PluginInstallEvent { } /// Well-known paths for opencode configuration and cache. +/// +/// OpenCode follows XDG conventions on all platforms: +/// config: $XDG_CONFIG_HOME/opencode or ~/.config/opencode +/// cache: $XDG_CACHE_HOME/opencode or ~/.cache/opencode +/// +/// We must NOT use `dirs::config_dir()` / `dirs::cache_dir()` because on +/// macOS those return ~/Library/Application Support and ~/Library/Caches, +/// while opencode always uses the XDG paths. fn opencode_config_path() -> Option { - dirs::config_dir().map(|d| d.join("opencode").join("opencode.json")) + xdg_config_home().map(|d| d.join("opencode").join("opencode.json")) } fn opencode_cache_dir() -> Option { - dirs::cache_dir().map(|d| d.join("opencode")) + xdg_cache_home().map(|d| d.join("opencode")) +} + +fn xdg_config_home() -> Option { + std::env::var_os("XDG_CONFIG_HOME") + .map(PathBuf::from) + .or_else(|| dirs::home_dir().map(|h| h.join(".config"))) +} + +fn xdg_cache_home() -> Option { + std::env::var_os("XDG_CACHE_HOME") + .map(PathBuf::from) + .or_else(|| dirs::home_dir().map(|h| h.join(".cache"))) } /// Check whether a project directory contains any opencode configuration file.