Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
Revert "feat: remove all node & npm dependency, always use bun (#7692)"
Louis5fefa135e2d6
diff --git a/src-tauri/src/core/openclaw/cli.rs b/src-tauri/src/core/openclaw/cli.rsindex cc9156e92..f0cd5a7cd 100644--- a/src-tauri/src/core/openclaw/cli.rs+++ b/src-tauri/src/core/openclaw/cli.rs@@ -119,15 +119,25 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {}async fn check_runtime_version() -> Option<String> {- let bun_path = super::resolve_bundled_bun()?;- let mut cmd = Command::new(&bun_path);+ if let Some(bun_path) = super::resolve_bundled_bun() {+ let mut cmd = Command::new(&bun_path);+ cmd.arg("--version");+ hide_window(&mut cmd);+ let output = cmd.output().await.ok()?;++ if output.status.success() {+ let version = String::from_utf8_lossy(&output.stdout).trim().to_string();+ return Some(format!("bun {}", version));+ }+ }++ let mut cmd = Command::new("node");cmd.arg("--version");hide_window(&mut cmd);let output = cmd.output().await.ok()?;if output.status.success() {- let version = String::from_utf8_lossy(&output.stdout).trim().to_string();- Some(format!("bun {}", version))+ Some(String::from_utf8_lossy(&output.stdout).trim().to_string())} else {None}@@ -224,6 +234,7 @@ pub async fn stop_gateway() -> Result<(), String> {let _ = cmd.output().await;};kill("bun.exe").await;+ kill("node.exe").await;kill("openclaw.exe").await;}diff --git a/src-tauri/src/core/openclaw/commands.rs b/src-tauri/src/core/openclaw/commands.rsindex 3a374b131..d6e9bfe03 100644--- a/src-tauri/src/core/openclaw/commands.rs+++ b/src-tauri/src/core/openclaw/commands.rs@@ -478,7 +478,7 @@ pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>)gateway_running: false,device_paired: false,error: result.error,- message: Some("Bundled Bun runtime not found. Please reinstall Jan.".to_string()),+ message: Some("Please install Bun or Node.js 22+ and OpenClaw manually".to_string()),});}Err(e) => {@@ -489,7 +489,7 @@ pub async fn openclaw_setup_for_channels(state: tauri::State<'_, OpenClawState>)gateway_running: false,device_paired: false,error: Some(e),- message: Some("Bundled Bun runtime not found. Please reinstall Jan.".to_string()),+ message: Some("Please install Bun or Node.js 22+ and OpenClaw manually".to_string()),});}}@@ -707,10 +707,44 @@ async fn restart_gateway_cli() -> Result<(), String> {tokio::time::sleep(std::time::Duration::from_secs(1)).await;- let mut cmd = openclaw_command(&["gateway", "run", "--force"]).await;- cmd.stdout(Stdio::piped()).stderr(Stdio::piped());- if let Err(e) = cmd.spawn() {- log::warn!("Failed to spawn openclaw gateway: {}", e);+ // Re-register service with --runtime bun when bundled Bun is available.+ // On Windows this requires admin (schtasks) and may fail.+ let install_args: Vec<&str> = if super::resolve_bundled_bun().is_some() {+ vec!["gateway", "install", "--runtime", "bun"]+ } else {+ vec!["gateway", "install"]+ };+ let install_output = openclaw_command(&install_args).await+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .output()+ .await;+ let service_installed = install_output+ .as_ref()+ .map(|o| o.status.success())+ .unwrap_or(false);++ if service_installed {+ let output = openclaw_command(&["gateway", "start"]).await+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .output()+ .await+ .map_err(|e| format!("Failed to start gateway: {}", e))?;++ if !output.status.success() {+ let stderr = String::from_utf8_lossy(&output.stderr);+ log::warn!("Gateway start failed: {}", stderr);+ }+ } else {+ // Service registration failed (e.g. Windows without admin).+ // Spawn `openclaw gateway` as a foreground child process.+ log::info!("Service install unavailable, restarting gateway as child process");+ let mut cmd = openclaw_command(&["gateway"]).await;+ cmd.stdout(Stdio::piped()).stderr(Stdio::piped());+ if let Err(e) = cmd.spawn() {+ log::warn!("Failed to spawn openclaw gateway: {}", e);+ }}Ok(())}@@ -813,6 +847,7 @@ async fn stop_other_sandbox_instance(stop_docker: bool) {let _ = cmd.output().await;};kill("bun.exe").await;+ kill("node.exe").await;kill("openclaw.exe").await;}}@@ -990,17 +1025,20 @@ async fn ensure_gateway_bind_lan() {}}-/// Check if bundled Bun is available and meets version requirements.+/// Check if bundled Bun or Node.js is installed and meets version requirements.#[tauri::command]pub async fn openclaw_check_dependencies() -> NodeCheckResult {+ // First try: bundled Bunif let Some(bun_path) = super::resolve_bundled_bun() {let mut cmd = tokio::process::Command::new(&bun_path);cmd.arg("--version");hide_window(&mut cmd);+ let output = cmd.output().await;- if let Ok(output) = cmd.output().await {+ if let Ok(output) = output {if output.status.success() {let version_output = String::from_utf8_lossy(&output.stdout).trim().to_string();+ // Bun returns version like "1.2.3", prepend "bun " for claritylet version_with_runtime = format!("bun {}", version_output);let version_str = version_output.trim_start_matches('v');@@ -1009,6 +1047,7 @@ pub async fn openclaw_check_dependencies() -> NodeCheckResult {.next().and_then(|v| v.parse().ok());+ // Bun 1.0+ meets requirementslet meets_requirements = major_version.map(|v| v >= 1).unwrap_or(false);return NodeCheckResult {@@ -1026,12 +1065,58 @@ pub async fn openclaw_check_dependencies() -> NodeCheckResult {}}- NodeCheckResult {- installed: false,- version: None,- major_version: None,- meets_requirements: false,- error: Some("Bundled Bun runtime not found".to_string()),+ // Fallback: check for Node.js+ let mut node_cmd = Command::new("node");+ node_cmd.arg("--version");+ hide_window(&mut node_cmd);+ let output = node_cmd.output().await;++ match output {+ Ok(output) => {+ if output.status.success() {+ let version_output = String::from_utf8_lossy(&output.stdout).trim().to_string();+ let version_str = version_output.trim_start_matches('v');++ let major_version: Option<u32> = version_str+ .split('.')+ .next()+ .and_then(|v| v.parse().ok());++ let meets_requirements = major_version+ .map(|v| v >= 22)+ .unwrap_or(false);++ let version_clone = version_output.clone();+ NodeCheckResult {+ installed: true,+ version: Some(version_clone),+ major_version,+ meets_requirements,+ error: if !meets_requirements {+ Some(format!("Node.js version 22 is required, found {}", version_str))+ } else {+ None+ },+ }+ } else {+ NodeCheckResult {+ installed: false,+ version: None,+ major_version: None,+ meets_requirements: false,+ error: Some("Could not find a JavaScript runtime (Bun or Node.js)".to_string()),+ }+ }+ }+ Err(e) => {+ NodeCheckResult {+ installed: false,+ version: None,+ major_version: None,+ meets_requirements: false,+ error: Some(format!("Could not find a JavaScript runtime: {}", e)),+ }+ }}}@@ -1127,7 +1212,7 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {return Ok(InstallResult {success: false,version: None,- error: node_check.error.or_else(|| Some("Bundled Bun runtime not found".to_string())),+ error: node_check.error.or_else(|| Some("A JavaScript runtime (Bun or Node.js) is required but not found".to_string())),});}@@ -1143,18 +1228,27 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {let _ = super::ensure_bun_node_shim();- let bun_path = super::resolve_bundled_bun()- .ok_or_else(|| "Bundled Bun runtime not found".to_string())?;- let runtime_dir = super::get_openclaw_runtime_dir()?;- let mut cmd = tokio::process::Command::new(&bun_path);- cmd.args(["install", "-g", &pinned_package])- .env("BUN_INSTALL", runtime_dir.to_string_lossy().as_ref())- .stdout(Stdio::piped())- .stderr(Stdio::piped());- hide_window(&mut cmd);- let output = cmd.output()- .await- .map_err(|e| format!("Failed to run bun install: {}", e))?;+ let output = if let Some(bun_path) = super::resolve_bundled_bun() {+ let runtime_dir = super::get_openclaw_runtime_dir()?;+ let mut cmd = tokio::process::Command::new(&bun_path);+ cmd.args(["install", "-g", &pinned_package])+ .env("BUN_INSTALL", runtime_dir.to_string_lossy().as_ref())+ .stdout(Stdio::piped())+ .stderr(Stdio::piped());+ hide_window(&mut cmd);+ cmd.output()+ .await+ .map_err(|e| format!("Failed to run bun install: {}", e))?+ } else {+ let mut cmd = Command::new("npm");+ cmd.args(["install", "-g", &pinned_package])+ .stdout(Stdio::piped())+ .stderr(Stdio::piped());+ hide_window(&mut cmd);+ cmd.output()+ .await+ .map_err(|e| format!("Failed to run npm install: {}", e))?+ };if !output.status.success() {// Parse error output for better error messages@@ -1923,7 +2017,8 @@ pub async fn openclaw_enable();};- // Step 1: Detect sandbox type FIRST (before runtime check)+ // Step 1: Detect sandbox type FIRST (before Node.js check)+ // This is important because for Docker, Node.js runs inside containerlet detected = crate::core::openclaw::sandbox::detect_sandbox().await;let sandbox_name = detected.name().to_string();let tier = detected.isolation_tier();@@ -1951,12 +2046,12 @@ pub async fn openclaw_enable(error: None,}} else {- // For direct process, bundled Bun must be available+ // For direct process, a JS runtime (bundled Bun or Node.js) must be availablelet check = openclaw_check_dependencies().await;if !check.installed {return Err(serde_json::to_string(&EnableError {code: EnableErrorCode::RuntimeNotFound,- message: "Bundled Bun runtime not found. Please reinstall Jan.".to_string(),+ message: "Could not find a JavaScript runtime. Bundled Bun was not found, and Node.js 22+ is not installed.".to_string(),recovery: vec![RecoveryOption {label: "Retry".to_string(),action: RecoveryAction::Retry,@@ -2048,14 +2143,14 @@ pub async fn openclaw_enable());}- // Check runtime (bundled Bun, required for direct process)+ // Check runtime (bundled Bun or Node.js, required for direct process)let node_check = openclaw_check_dependencies().await;if !node_check.installed {return Err(serde_json::to_string(&EnableError {code: EnableErrorCode::RuntimeNotFound,message: format!("Docker image unavailable and no JavaScript runtime found. \- Original error: {}. Bundled Bun runtime not found.",+ Original error: {}. Bundled Bun was not found and Node.js 22+ is not installed.",e),recovery: vec![RecoveryOption {@@ -2071,7 +2166,7 @@ pub async fn openclaw_enable(code: EnableErrorCode::RuntimeVersionTooLow,message: format!("Docker image unavailable and runtime version too low. \- Original error: {}. Bun 1.0+ required.",+ Original error: {}. Bun 1.0+ or Node.js 22+ required.",e),recovery: vec![RecoveryOption {@@ -2083,7 +2178,7 @@ pub async fn openclaw_enable(.unwrap_or_else(|_| "Runtime version too low".to_string()));}- // Now install via bun+ // Now install via bun/npmemit("installing", 45, "Installing OpenClaw...", sandbox_info.as_deref());let install_result = openclaw_install().await?;if !install_result.success {@@ -2386,7 +2481,7 @@ pub async fn openclaw_start(state: State<'_, OpenClawState>) -> Result<(), Strinif !is_docker {let node_check = openclaw_check_dependencies().await;if !node_check.installed || !node_check.meets_requirements {- return Err(node_check.error.unwrap_or_else(|| "Bundled Bun runtime not found".to_string()));+ return Err(node_check.error.unwrap_or_else(|| "JavaScript runtime requirements not met (Bun or Node.js 22+)".to_string()));}}diff --git a/src-tauri/src/core/openclaw/models.rs b/src-tauri/src/core/openclaw/models.rsindex 81d52fb38..1eab056d8 100644--- a/src-tauri/src/core/openclaw/models.rs+++ b/src-tauri/src/core/openclaw/models.rs@@ -185,7 +185,7 @@ pub struct OpenClawStatus {pub installed: bool,/// Whether the gateway is runningpub running: bool,- /// Runtime version (if installed)+ /// Runtime version (Bun or Node.js, if installed)pub runtime_version: Option<String>,/// Installed OpenClaw version (if installed)pub openclaw_version: Option<String>,@@ -201,12 +201,12 @@ pub struct OpenClawStatus {pub isolation_tier: Option<String>,}-/// Runtime check result+/// Node.js check result#[derive(Debug, Clone, Serialize, Deserialize)]pub struct NodeCheckResult {- /// Whether the runtime is installed+ /// Whether Node.js is installedpub installed: bool,- /// Runtime version (if installed)+ /// Node.js version (if installed)pub version: Option<String>,/// Major version numberpub major_version: Option<u32>,diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rsindex 5edcb4ad0..5e2d981b8 100644--- a/src-tauri/src/core/openclaw/sandbox_direct.rs+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs@@ -118,53 +118,106 @@ impl Sandbox for DirectProcessSandbox {log::warn!("Failed to ensure node shim: {}", e);}- if let Err(e) = install_openclaw_globally().await {- log::warn!("openclaw global install failed, will attempt to run anyway: {}", e);- }+ let use_child_process = if cfg!(target_os = "windows") {+ true+ } else {+ let install_args = if super::resolve_bundled_bun().is_some() {+ vec!["gateway", "install", "--runtime", "bun"]+ } else {+ vec!["gateway", "install"]+ };+ let mut install_cmd = build_openclaw_command(&install_args.iter().map(|s| *s).collect::<Vec<_>>(), &config.config_dir);+ match install_cmd.output().await {+ Ok(output) if output.status.success() => false,+ Ok(output) => {+ let stderr = String::from_utf8_lossy(&output.stderr);+ log::error!("gateway install failed: {}", stderr.trim());+ true+ }+ Err(e) => {+ log::error!("Failed to run gateway install: {}", e);+ true+ }+ }+ };- let mut cmd = build_openclaw_command(&["gateway", "start"], &config.config_dir);- for (key, value) in &config.env_vars {- cmd.env(key, value);- }+ if !use_child_process {+ if let Err(e) = install_openclaw_globally().await {+ log::warn!("openclaw global install failed, will attempt to run anyway: {}", e);+ }- let mut child = cmd- .spawn()- .map_err(|e| format!("Failed to spawn openclaw gateway: {}", e))?;+ let mut cmd =+ build_openclaw_command(&["gateway", "start"], &config.config_dir);+ for (key, value) in &config.env_vars {+ cmd.env(key, value);+ }- if let Some(stdout) = child.stdout.take() {- tokio::spawn(async move {- use tokio::io::{AsyncBufReadExt, BufReader};- let mut lines = BufReader::new(stdout).lines();- while let Ok(Some(line)) = lines.next_line().await {- log::info!("openclaw stdout: {}", line);- }- });- }- if let Some(stderr) = child.stderr.take() {++ let mut child = cmd+ .spawn()+ .map_err(|e| format!("Failed to spawn openclaw gateway: {}", e))?;++ // Drain stdout and stderr in background so the pipes don't block+ if let Some(stdout) = child.stdout.take() {+ tokio::spawn(async move {+ use tokio::io::{AsyncBufReadExt, BufReader};+ let mut lines = BufReader::new(stdout).lines();+ while let Ok(Some(line)) = lines.next_line().await {+ log::info!("openclaw stdout: {}", line);+ }+ });+ }+ if let Some(stderr) = child.stderr.take() {+ tokio::spawn(async move {+ use tokio::io::{AsyncBufReadExt, BufReader};+ let mut lines = BufReader::new(stderr).lines();+ while let Ok(Some(line)) = lines.next_line().await {+ log::info!("openclaw stderr: {}", line);+ }+ });+ }++ // Log when the process exits+ let pid = child.id();tokio::spawn(async move {- use tokio::io::{AsyncBufReadExt, BufReader};- let mut lines = BufReader::new(stderr).lines();- while let Ok(Some(line)) = lines.next_line().await {- log::info!("openclaw stderr: {}", line);+ // We can't await the child here since we've already moved it into the handle,+ // so poll the port instead as a proxy for the process being alive.+ loop {+ tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;+ let alive = tokio::net::TcpStream::connect(+ format!("127.0.0.1:{}", super::OPENCLAW_PORT)+ ).await.is_ok();+ if !alive {+ log::warn!("openclaw gateway process (pid {:?}) appears to have exited", pid);+ break;+ }}});- }- let pid = child.id();- tokio::spawn(async move {- loop {- tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;- let alive = tokio::net::TcpStream::connect(- format!("127.0.0.1:{}", super::OPENCLAW_PORT)- ).await.is_ok();- if !alive {- log::warn!("openclaw gateway process (pid {:?}) appears to have exited", pid);- break;- }+ Ok(SandboxHandle::Process(child))+ } else {+ log::info!("Starting gateway as child process");+ let mut cmd = build_openclaw_command(&["gateway"], &config.config_dir);+ cmd.stdin(Stdio::null())+ .stdout(Stdio::null())+ .stderr(Stdio::null());+ #[cfg(target_os = "windows")]+ {+ use std::os::windows::process::CommandExt;+ // CREATE_NO_WINDOW only — DETACHED_PROCESS conflicts and can+ // cause Windows to allocate a visible console for the child.+ cmd.creation_flags(0x08000000);}- });+ for (key, value) in &config.env_vars {+ cmd.env(key, value);+ }++ let child = cmd+ .spawn()+ .map_err(|e| format!("Failed to spawn openclaw gateway: {}", e))?;- Ok(SandboxHandle::Process(child))+ Ok(SandboxHandle::Process(child))+ }}async fn stop(&self, handle: &mut SandboxHandle) -> Result<(), String> {@@ -215,6 +268,7 @@ impl Sandbox for DirectProcessSandbox {let _ = cmd.output().await;};kill("bun.exe").await;+ kill("node.exe").await;kill("openclaw.exe").await;}}