diff --git a/Cargo.lock b/Cargo.lock index c505614db7c1..d9ae84083856 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2833,6 +2833,7 @@ dependencies = [ "tracing-subscriber", "utoipa", "uuid", + "winreg 0.55.0", ] [[package]] @@ -5395,7 +5396,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "winreg 0.50.0", ] [[package]] @@ -8332,6 +8333,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winreg" +version = "0.55.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97" +dependencies = [ + "cfg-if", + "windows-sys 0.59.0", +] + [[package]] name = "winsafe" version = "0.0.19" diff --git a/crates/goose-server/Cargo.toml b/crates/goose-server/Cargo.toml index eefd68f938fc..cc00f91146c2 100644 --- a/crates/goose-server/Cargo.toml +++ b/crates/goose-server/Cargo.toml @@ -40,6 +40,10 @@ reqwest = { version = "0.12.9", features = ["json", "rustls-tls", "blocking", "m tokio-util = "0.7.15" uuid = { version = "1.11", features = ["v4"] } serde_path_to_error = "0.1.20" +winreg = { version = "0.55.0", optional = true } + +[target.'cfg(windows)'.dependencies] +winreg = { version = "0.55.0" } [[bin]] name = "goosed" diff --git a/crates/goose-server/src/routes/extension.rs b/crates/goose-server/src/routes/extension.rs index 5fec1a3599e7..05e0d1e0488a 100644 --- a/crates/goose-server/src/routes/extension.rs +++ b/crates/goose-server/src/routes/extension.rs @@ -32,12 +32,44 @@ async fn add_extension( // If this is a Stdio extension that uses npx, check for Node.js installation #[cfg(target_os = "windows")] + use winreg::enums::{HKEY_LOCAL_MACHINE, KEY_READ}; + use winreg::RegKey; if let ExtensionConfig::Stdio { cmd, .. } = &request.config { if cmd.ends_with("npx.cmd") || cmd.ends_with("npx") { // Check if Node.js is installed in standard locations - let node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe").exists() + let mut node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe").exists() || std::path::Path::new(r"C:\Program Files (x86)\nodejs\node.exe").exists(); + // Also check Windows registry: HKEY_LOCAL_MACHINE\\SOFTWARE\\Node.js InstallPath + if !node_exists { + // Try 64-bit view first, then 32-bit. Use open_subkey_with_flags to avoid WOW64 redirection issues. + let install_path_from_reg: Option = (|| { + let hk_local_machine = RegKey::predef(HKEY_LOCAL_MACHINE); + // Common keys to try + let keys = vec![ + "SOFTWARE\\Node.js", + "SOFTWARE\\WOW6432Node\\Node.js", + ]; + for k in keys.iter() { + if let Ok(subkey) = hk_local_machine.open_subkey_with_flags(k, KEY_READ) { + if let Ok(val) = subkey.get_value::("InstallPath") { + if !val.trim().is_empty() { + return Some(val); + } + } + } + } + None + })(); + + if let Some(path_str) = install_path_from_reg { + let node_path = std::path::Path::new(&path_str).join("node.exe"); + if node_path.exists() { + node_exists = true; + } + } + } + if !node_exists { // Get the directory containing npx.cmd let cmd_path = std::path::Path::new(&cmd); @@ -47,7 +79,7 @@ async fn add_extension( let install_script = script_dir.join("install-node.cmd"); if install_script.exists() { - eprintln!("Installing Node.js..."); + eprintln!("Node.js not found on the system, installing Node.js..."); let output = std::process::Command::new(&install_script) .arg("https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi") .output() @@ -72,12 +104,12 @@ async fn add_extension( eprintln!("Node.js installation completed"); } else { eprintln!( - "Node.js installer script not found at: {}", + "Node.js not found on the system, and Node.js installer script not found at: {}", install_script.display() ); return Ok(Json(ExtensionResponse { error: true, - message: Some("Node.js installer script not found".to_string()), + message: Some("Node.js not found on the system, and Node.js installer script not found".to_string()), })); } }