Don't load user's shell env on app startup (#4681)
Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@ description.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
goose = { path = "../goose" }
|
||||
mcp-core = { path = "../mcp-core" }
|
||||
mcp-server = { path = "../mcp-server" }
|
||||
rmcp = { version = "0.6.0", features = ["server", "client", "transport-io", "macros"] }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{env, process::Stdio};
|
||||
use goose::config::get_config_dir;
|
||||
use std::{env, ffi::OsString, process::Stdio};
|
||||
|
||||
#[cfg(unix)]
|
||||
#[allow(unused_imports)] // False positive: trait is used for process_group method
|
||||
@@ -8,30 +9,23 @@ use std::os::unix::process::CommandExt;
|
||||
pub struct ShellConfig {
|
||||
pub executable: String,
|
||||
pub args: Vec<String>,
|
||||
#[allow(dead_code)]
|
||||
pub envs: Vec<(OsString, OsString)>,
|
||||
}
|
||||
|
||||
impl Default for ShellConfig {
|
||||
fn default() -> Self {
|
||||
if cfg!(windows) {
|
||||
// Detect the default shell on Windows
|
||||
#[cfg(windows)]
|
||||
{
|
||||
Self::detect_windows_shell()
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
// This branch should never be taken on non-Windows
|
||||
// but we need it for compilation
|
||||
Self {
|
||||
executable: "cmd".to_string(),
|
||||
args: vec!["/c".to_string()],
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Use bash on Unix/macOS (keep existing behavior)
|
||||
#[cfg(windows)]
|
||||
{
|
||||
Self::detect_windows_shell()
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let bash_env = get_config_dir().join(".bash_env").into_os_string();
|
||||
Self {
|
||||
executable: "bash".to_string(),
|
||||
args: vec!["-c".to_string()],
|
||||
envs: vec![(OsString::from("BASH_ENV"), bash_env)],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +44,7 @@ impl ShellConfig {
|
||||
"-NonInteractive".to_string(),
|
||||
"-Command".to_string(),
|
||||
],
|
||||
envs: vec![],
|
||||
}
|
||||
} else if let Ok(ps_path) = which::which("powershell") {
|
||||
// Windows PowerShell 5.1
|
||||
@@ -60,12 +55,14 @@ impl ShellConfig {
|
||||
"-NonInteractive".to_string(),
|
||||
"-Command".to_string(),
|
||||
],
|
||||
envs: vec![],
|
||||
}
|
||||
} else {
|
||||
// Fall back to cmd.exe
|
||||
Self {
|
||||
executable: "cmd".to_string(),
|
||||
args: vec!["/c".to_string()],
|
||||
envs: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +116,18 @@ enum SecretStorage {
|
||||
// Global instance
|
||||
static GLOBAL_CONFIG: OnceCell<Config> = OnceCell::new();
|
||||
|
||||
pub fn get_config_dir() -> PathBuf {
|
||||
choose_app_strategy(APP_STRATEGY.clone())
|
||||
.expect("goose requires a home dir")
|
||||
.config_dir()
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
// choose_app_strategy().config_dir()
|
||||
// - macOS/Linux: ~/.config/goose/
|
||||
// - Windows: ~\AppData\Roaming\Block\goose\config\
|
||||
let config_dir = choose_app_strategy(APP_STRATEGY.clone())
|
||||
.expect("goose requires a home dir")
|
||||
.config_dir();
|
||||
let config_dir = get_config_dir();
|
||||
|
||||
std::fs::create_dir_all(&config_dir).expect("Failed to create config directory");
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ pub mod signup_openrouter;
|
||||
pub mod signup_tetrate;
|
||||
|
||||
pub use crate::agents::ExtensionConfig;
|
||||
pub use base::{Config, ConfigError, APP_STRATEGY};
|
||||
pub use base::{get_config_dir, Config, ConfigError, APP_STRATEGY};
|
||||
pub use custom_providers::CustomProviderConfig;
|
||||
pub use experiments::ExperimentManager;
|
||||
pub use extensions::{ExtensionConfigManager, ExtensionEntry};
|
||||
|
||||
Reference in New Issue
Block a user