the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: install opencode and kilo integrations under XDG_CONFIG_HOME (#5585)
Can Celik2713feb56e9c
diff --git a/src/integration/env.rs b/src/integration/env.rsindex bec9e23bf..e4da34824 100644--- a/src/integration/env.rs+++ b/src/integration/env.rs@@ -24,6 +24,7 @@ pub(crate) const GROK_CONFIG_DIR_ENV_VAR: &str = "GROK_CONFIG_DIR";/// `$GROK_HOME/config.toml` and `$GROK_HOME/auth.json`).pub(crate) const GROK_HOME_ENV_VAR: &str = "GROK_HOME";pub(crate) const HERMES_HOME_ENV_VAR: &str = "HERMES_HOME";+pub(crate) const OPENCODE_CONFIG_DIR_ENV_VAR: &str = "OPENCODE_CONFIG_DIR";pub(crate) fn apply_pane_base_env(cmd: &mut CommandBuilder) {cmd.env(crate::api::SOCKET_PATH_ENV_VAR, crate::api::socket_path());@@ -123,8 +124,21 @@ pub(crate) fn expand_tilde_path(path: PathBuf) -> io::Result<PathBuf> {Ok(path)}+fn xdg_config_dir() -> io::Result<PathBuf> {+ match std::env::var_os("XDG_CONFIG_HOME").filter(|value| !value.is_empty()) {+ Some(value) => Ok(PathBuf::from(value)),+ None => Ok(home_dir()?.join(".config")),+ }+}+pub(crate) fn opencode_dir() -> io::Result<PathBuf> {- Ok(home_dir()?.join(".config/opencode"))+ if let Some(value) =+ std::env::var_os(OPENCODE_CONFIG_DIR_ENV_VAR).filter(|value| !value.is_empty())+ {+ return Ok(PathBuf::from(value));+ }++ Ok(xdg_config_dir()?.join("opencode"))}pub(crate) fn opencode_state_dir() -> io::Result<PathBuf> {@@ -136,7 +150,7 @@ pub(crate) fn opencode_state_dir() -> io::Result<PathBuf> {}pub(crate) fn kilo_dir() -> io::Result<PathBuf> {- Ok(home_dir()?.join(".config/kilo"))+ Ok(xdg_config_dir()?.join("kilo"))}pub(crate) fn hermes_dir() -> io::Result<PathBuf> {diff --git a/src/integration/tests.rs b/src/integration/tests.rsindex 147daff83..e8c89a629 100644--- a/src/integration/tests.rs+++ b/src/integration/tests.rs@@ -135,6 +135,7 @@ fn clear_integration_path_env() {std::env::remove_var(CODEX_HOME_ENV_VAR);std::env::remove_var(COPILOT_HOME_ENV_VAR);std::env::remove_var(KIMI_CODE_HOME_ENV_VAR);+ std::env::remove_var("OPENCODE_CONFIG_DIR");std::env::remove_var("XDG_CONFIG_HOME");std::env::remove_var("XDG_STATE_HOME");#[cfg(windows)]@@ -182,6 +183,10 @@ fn assert_kimi_hook(fn unique_base() -> PathBuf {clear_integration_path_env();+ unique_base_without_clearing_env()+}++fn unique_base_without_clearing_env() -> PathBuf {std::env::temp_dir().join(format!("herdr-integration-install-test-{}-{}",std::process::id(),@@ -2456,6 +2461,137 @@ fn install_droid_errors_when_config_dir_missing() {let _ = fs::remove_dir_all(base);}+struct ConfigPathEnvGuard(Vec<(&'static str, Option<std::ffi::OsString>)>);++impl ConfigPathEnvGuard {+ fn new() -> Self {+ Self(+ [+ "HOME",+ "OPENCODE_CONFIG_DIR",+ "XDG_CONFIG_HOME",+ "XDG_STATE_HOME",+ ]+ .into_iter()+ .map(|key| (key, std::env::var_os(key)))+ .collect(),+ )+ }+}++impl Drop for ConfigPathEnvGuard {+ fn drop(&mut self) {+ for (key, value) in &self.0 {+ match value {+ Some(value) => std::env::set_var(key, value),+ None => std::env::remove_var(key),+ }+ }+ }+}++#[test]+fn config_dirs_follow_xdg_and_opencode_override_precedence() {+ let _lock = integration_env_lock();+ let _env = ConfigPathEnvGuard::new();+ let base = unique_base_without_clearing_env();+ std::env::remove_var("OPENCODE_CONFIG_DIR");+ std::env::remove_var("XDG_CONFIG_HOME");+ let home = base.join("home");+ let xdg = base.join("xdg");+ let custom = base.join("custom");+ std::env::set_var("HOME", &home);++ assert_eq!(opencode_dir().unwrap(), home.join(".config/opencode"));+ assert_eq!(kilo_dir().unwrap(), home.join(".config/kilo"));++ std::env::set_var("XDG_CONFIG_HOME", "");+ std::env::set_var("OPENCODE_CONFIG_DIR", "");+ assert_eq!(opencode_dir().unwrap(), home.join(".config/opencode"));+ assert_eq!(kilo_dir().unwrap(), home.join(".config/kilo"));++ std::env::set_var("XDG_CONFIG_HOME", &xdg);+ assert_eq!(opencode_dir().unwrap(), xdg.join("opencode"));+ assert_eq!(kilo_dir().unwrap(), xdg.join("kilo"));++ std::env::set_var("OPENCODE_CONFIG_DIR", &custom);+ assert_eq!(opencode_dir().unwrap(), custom);+ assert_eq!(kilo_dir().unwrap(), xdg.join("kilo"));++ std::env::remove_var("XDG_CONFIG_HOME");+ assert_eq!(opencode_dir().unwrap(), custom);++ std::env::set_var("OPENCODE_CONFIG_DIR", "~/literal-opencode");+ assert_eq!(opencode_dir().unwrap(), PathBuf::from("~/literal-opencode"));++ std::env::remove_var("OPENCODE_CONFIG_DIR");+ std::env::set_var("XDG_CONFIG_HOME", "~/literal-xdg");+ assert_eq!(+ opencode_dir().unwrap(),+ PathBuf::from("~/literal-xdg/opencode")+ );+ assert_eq!(kilo_dir().unwrap(), PathBuf::from("~/literal-xdg/kilo"));+}++#[test]+fn install_opencode_and_kilo_use_xdg_config_home() {+ let _lock = integration_env_lock();+ let _env = ConfigPathEnvGuard::new();+ let base = unique_base_without_clearing_env();+ std::env::remove_var("OPENCODE_CONFIG_DIR");+ let home = base.join("home");+ let xdg = base.join("xdg");+ fs::create_dir_all(xdg.join("opencode")).unwrap();+ fs::create_dir_all(xdg.join("kilo")).unwrap();+ std::env::set_var("HOME", &home);+ std::env::set_var("XDG_CONFIG_HOME", &xdg);+ std::env::set_var("XDG_STATE_HOME", base.join("state"));++ let opencode = install_opencode().unwrap();+ let kilo = install_kilo().unwrap();+ assert_eq!(+ opencode.plugin_path,+ xdg.join("opencode/plugins")+ .join(OPENCODE_PLUGIN_INSTALL_NAME)+ );+ assert_eq!(+ kilo.plugin_path,+ xdg.join("kilo/plugin").join(KILO_PLUGIN_INSTALL_NAME)+ );+ assert!(opencode.plugin_path.is_file());+ assert!(opencode.tui_plugin_path.is_file());+ assert!(kilo.plugin_path.is_file());+ assert!(!home.join(".config").exists());++ let statuses = installed_integration_statuses();+ for (target, path) in [+ (+ crate::api::schema::IntegrationTarget::Opencode,+ &opencode.plugin_path,+ ),+ (+ crate::api::schema::IntegrationTarget::Kilo,+ &kilo.plugin_path,+ ),+ ] {+ let status = statuses+ .iter()+ .find(|status| status.target == target)+ .unwrap();+ assert_eq!(&status.path, path);+ assert_eq!(status.state, IntegrationStatusKind::Current);+ }++ let removed_opencode = uninstall_opencode().unwrap();+ let removed_kilo = uninstall_kilo().unwrap();+ assert_eq!(removed_opencode.plugin_path, opencode.plugin_path);+ assert_eq!(removed_kilo.plugin_path, kilo.plugin_path);+ assert!(removed_opencode.removed_plugin);+ assert!(removed_kilo.removed_plugin);++ let _ = fs::remove_dir_all(base);+}+#[test]fn install_opencode_writes_server_and_tui_plugins() {let _lock = integration_env_lock();