Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: remove all node & npm dependency, always use bun (#7692)

Nghia Doan13194e87aa6b
diff --git a/src-tauri/src/core/openclaw/cli.rs b/src-tauri/src/core/openclaw/cli.rs
index 0205e7c28..c69ccd4f9 100644
--- a/src-tauri/src/core/openclaw/cli.rs
+++ b/src-tauri/src/core/openclaw/cli.rs
@@ -105,25 +105,15 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {
}
async fn check_runtime_version() -> Option<String> {
- 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");
+ let 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() {
- Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
+ let version = String::from_utf8_lossy(&output.stdout).trim().to_string();
+ Some(format!("bun {}", version))
} else {
None
}
@@ -220,7 +210,6 @@ 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.rs
index d6e9bfe03..3a374b131 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("Please install Bun or Node.js 22+ and OpenClaw manually".to_string()),
+ message: Some("Bundled Bun runtime not found. Please reinstall Jan.".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("Please install Bun or Node.js 22+ and OpenClaw manually".to_string()),
+ message: Some("Bundled Bun runtime not found. Please reinstall Jan.".to_string()),
});
}
}
@@ -707,44 +707,10 @@ async fn restart_gateway_cli() -> Result<(), String> {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
- // 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);
- }
+ 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);
}
Ok(())
}
@@ -847,7 +813,6 @@ 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;
}
}
@@ -1025,20 +990,17 @@ async fn ensure_gateway_bind_lan() {
}
}
-/// Check if bundled Bun or Node.js is installed and meets version requirements.
+/// Check if bundled Bun is available and meets version requirements.
#[tauri::command]
pub async fn openclaw_check_dependencies() -> NodeCheckResult {
- // First try: bundled Bun
if 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) = output {
+ if let Ok(output) = cmd.output().await {
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 clarity
let version_with_runtime = format!("bun {}", version_output);
let version_str = version_output.trim_start_matches('v');
@@ -1047,7 +1009,6 @@ pub async fn openclaw_check_dependencies() -> NodeCheckResult {
.next()
.and_then(|v| v.parse().ok());
- // Bun 1.0+ meets requirements
let meets_requirements = major_version.map(|v| v >= 1).unwrap_or(false);
return NodeCheckResult {
@@ -1065,58 +1026,12 @@ pub async fn openclaw_check_dependencies() -> NodeCheckResult {
}
}
- // 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)),
- }
- }
+ NodeCheckResult {
+ installed: false,
+ version: None,
+ major_version: None,
+ meets_requirements: false,
+ error: Some("Bundled Bun runtime not found".to_string()),
}
}
@@ -1212,7 +1127,7 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {
return Ok(InstallResult {
success: false,
version: None,
- error: node_check.error.or_else(|| Some("A JavaScript runtime (Bun or Node.js) is required but not found".to_string())),
+ error: node_check.error.or_else(|| Some("Bundled Bun runtime not found".to_string())),
});
}
@@ -1228,27 +1143,18 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {
let _ = super::ensure_bun_node_shim();
- 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))?
- };
+ 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))?;
if !output.status.success() {
// Parse error output for better error messages
@@ -2017,8 +1923,7 @@ pub async fn openclaw_enable(
);
};
- // Step 1: Detect sandbox type FIRST (before Node.js check)
- // This is important because for Docker, Node.js runs inside container
+ // Step 1: Detect sandbox type FIRST (before runtime check)
let detected = crate::core::openclaw::sandbox::detect_sandbox().await;
let sandbox_name = detected.name().to_string();
let tier = detected.isolation_tier();
@@ -2046,12 +1951,12 @@ pub async fn openclaw_enable(
error: None,
}
} else {
- // For direct process, a JS runtime (bundled Bun or Node.js) must be available
+ // For direct process, bundled Bun must be available
let check = openclaw_check_dependencies().await;
if !check.installed {
return Err(serde_json::to_string(&EnableError {
code: EnableErrorCode::RuntimeNotFound,
- message: "Could not find a JavaScript runtime. Bundled Bun was not found, and Node.js 22+ is not installed.".to_string(),
+ message: "Bundled Bun runtime not found. Please reinstall Jan.".to_string(),
recovery: vec![RecoveryOption {
label: "Retry".to_string(),
action: RecoveryAction::Retry,
@@ -2143,14 +2048,14 @@ pub async fn openclaw_enable(
));
}
- // Check runtime (bundled Bun or Node.js, required for direct process)
+ // Check runtime (bundled Bun, 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 was not found and Node.js 22+ is not installed.",
+ Original error: {}. Bundled Bun runtime not found.",
e
),
recovery: vec![RecoveryOption {
@@ -2166,7 +2071,7 @@ pub async fn openclaw_enable(
code: EnableErrorCode::RuntimeVersionTooLow,
message: format!(
"Docker image unavailable and runtime version too low. \
- Original error: {}. Bun 1.0+ or Node.js 22+ required.",
+ Original error: {}. Bun 1.0+ required.",
e
),
recovery: vec![RecoveryOption {
@@ -2178,7 +2083,7 @@ pub async fn openclaw_enable(
.unwrap_or_else(|_| "Runtime version too low".to_string()));
}
- // Now install via bun/npm
+ // Now install via bun
emit("installing", 45, "Installing OpenClaw...", sandbox_info.as_deref());
let install_result = openclaw_install().await?;
if !install_result.success {
@@ -2481,7 +2386,7 @@ pub async fn openclaw_start(state: State<'_, OpenClawState>) -> Result<(), Strin
if !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(|| "JavaScript runtime requirements not met (Bun or Node.js 22+)".to_string()));
+ return Err(node_check.error.unwrap_or_else(|| "Bundled Bun runtime not found".to_string()));
}
}
diff --git a/src-tauri/src/core/openclaw/models.rs b/src-tauri/src/core/openclaw/models.rs
index 1eab056d8..81d52fb38 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 running
pub running: bool,
- /// Runtime version (Bun or Node.js, if installed)
+ /// Runtime version (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>,
}
-/// Node.js check result
+/// Runtime check result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeCheckResult {
- /// Whether Node.js is installed
+ /// Whether the runtime is installed
pub installed: bool,
- /// Node.js version (if installed)
+ /// Runtime version (if installed)
pub version: Option<String>,
/// Major version number
pub major_version: Option<u32>,
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index 2effec80b..f452eeaa9 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -118,106 +118,54 @@ impl Sandbox for DirectProcessSandbox {
log::warn!("Failed to ensure node shim: {}", 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
- }
- }
- };
-
- 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 cmd =
- build_openclaw_command(&["gateway", "run", "--force"], &config.config_dir);
- for (key, value) in &config.env_vars {
- cmd.env(key, value);
- }
+ if let Err(e) = install_openclaw_globally().await {
+ log::warn!("openclaw global install failed, will attempt to run anyway: {}", e);
+ }
+ let mut cmd =
+ build_openclaw_command(&["gateway", "run", "--force"], &config.config_dir);
+ for (key, value) in &config.env_vars {
+ cmd.env(key, value);
+ }
- let mut child = cmd
- .spawn()
- .map_err(|e| format!("Failed to spawn openclaw gateway: {}", e))?;
+ 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();
+ if let Some(stdout) = child.stdout.take() {
tokio::spawn(async move {
- // 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;
- }
+ 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);
+ }
+ });
+ }
- 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 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;
+ }
}
+ });
- 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> {
@@ -268,7 +216,6 @@ impl Sandbox for DirectProcessSandbox {
let _ = cmd.output().await;
};
kill("bun.exe").await;
- kill("node.exe").await;
kill("openclaw.exe").await;
}
}