Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): let npm-based agents start on Windows

leepokai7747a37829a0
diff --git a/host/src/agent/registry.rs b/host/src/agent/registry.rs
index 7b7e7772..ce9cf958 100644
--- a/host/src/agent/registry.rs
+++ b/host/src/agent/registry.rs
@@ -204,7 +204,8 @@ async fn prepare_npx(package: &str, name: &str, progress: &impl Fn(&str)) -> Res
let _ = tokio::fs::remove_dir_all(&dir).await;
progress(&format!("Downloading {name}…"));
let install = tokio::process::Command::new(shell::program("npm"))
- .args(["exec", "--yes", "--package", package, "-c", "true"])
+ // `exit 0`, not `true`: on Windows npm runs `-c` in cmd.exe, which has no `true`.
+ .args(["exec", "--yes", "--package", package, "-c", "exit 0"])
// Away from any project, so npx doesn't settle for a local node_modules.
.current_dir(crate::service::data_dir())
.stdin(std::process::Stdio::null())
@@ -212,7 +213,7 @@ async fn prepare_npx(package: &str, name: &str, progress: &impl Fn(&str)) -> Res
.output();
let failure = match tokio::time::timeout(Duration::from_secs(20 * 60), install).await {
Ok(Ok(out)) if out.status.success() => return Ok(()),
- Ok(Ok(out)) => String::from_utf8_lossy(&out.stderr).trim().lines().last().unwrap_or_default().to_owned(),
+ Ok(Ok(out)) => npm_error(&String::from_utf8_lossy(&out.stderr)).to_owned(),
Ok(Err(e)) => format!("{e}"),
Err(_) => "timed out".to_owned(),
};
@@ -220,6 +221,12 @@ async fn prepare_npx(package: &str, name: &str, progress: &impl Fn(&str)) -> Res
bail!("couldn't download {name} with npm: {failure}")
}
+/// The line of npm's stderr that says what went wrong: its own `npm notice` lines (a newer npm
+/// is out) come after the error.
+fn npm_error(stderr: &str) -> &str {
+ stderr.lines().map(str::trim).rfind(|l| !l.is_empty() && !l.starts_with("npm notice")).unwrap_or_default()
+}
+
/// `npm config get cache`, asked once.
async fn npm_cache() -> Result<&'static Path> {
static DIR: tokio::sync::OnceCell<PathBuf> = tokio::sync::OnceCell::const_new();
@@ -372,6 +379,15 @@ mod tests {
assert_eq!(npx_cmd(&npx).acp(), expected);
}
+ #[test]
+ fn npm_errors_skip_its_update_notice() {
+ let stderr = "'true' is not recognized as an internal or external command\n\
+ npm notice New major version of npm available! 10.9.2 -> 11.6.2\n\
+ npm notice To update run: npm install -g [email protected]\n";
+ assert_eq!(npm_error(stderr), "'true' is not recognized as an internal or external command");
+ assert_eq!(npm_error(""), "");
+ }
+
#[test]
fn npx_hash_matches_npm() {
// ~/.npm/_npx/317ff93dc6c5b519 after `npx -y @agentclientprotocol/[email protected]`.