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.

Merge pull request #7709 from janhq/fix/openclaw-runtime-error

Louis8c81f7363d9a
diff --git a/src-tauri/src/core/openclaw/cli.rs b/src-tauri/src/core/openclaw/cli.rs
index f0cd5a7cd..d74315acf 100644
--- a/src-tauri/src/core/openclaw/cli.rs
+++ b/src-tauri/src/core/openclaw/cli.rs
@@ -57,9 +57,9 @@ fn build_openclaw_command(args: &[&str]) -> tokio::process::Command {
cmd.env("BUN_INSTALL", dir);
}
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
#[cfg(target_os = "windows")]
{
@@ -82,9 +82,9 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {
Command::new(&openclaw_path)
};
cmd.arg("--version");
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
hide_window(&mut cmd);
let output = cmd.output().await;
@@ -99,9 +99,9 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {
let mut cmd = Command::new("openclaw");
cmd.arg("--version");
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
hide_window(&mut cmd);
let output = cmd.output().await;
diff --git a/src-tauri/src/core/openclaw/commands.rs b/src-tauri/src/core/openclaw/commands.rs
index 70b3d0428..c3f0d7386 100644
--- a/src-tauri/src/core/openclaw/commands.rs
+++ b/src-tauri/src/core/openclaw/commands.rs
@@ -86,9 +86,9 @@ fn build_openclaw_command(args: &[&str]) -> tokio::process::Command {
cmd.env("BUN_INSTALL", dir);
}
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
#[cfg(target_os = "windows")]
{
@@ -838,9 +838,9 @@ async fn stop_other_sandbox_instance(stop_docker: bool) {
cmd.args(["gateway", "stop"])
.stdout(Stdio::piped())
.stderr(Stdio::piped());
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
hide_window(&mut cmd);
cmd.output()
.await
@@ -851,9 +851,9 @@ async fn stop_other_sandbox_instance(stop_docker: bool) {
cmd.args(["gateway", "stop"])
.stdout(Stdio::piped())
.stderr(Stdio::piped());
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
hide_window(&mut cmd);
cmd.output()
.await
@@ -1259,8 +1259,6 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {
let pinned_package = format!("{}@{}", OPENCLAW_PACKAGE_NAME, OPENCLAW_VERSION);
- 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);
diff --git a/src-tauri/src/core/openclaw/mod.rs b/src-tauri/src/core/openclaw/mod.rs
index 83ccfa89d..122403b36 100644
--- a/src-tauri/src/core/openclaw/mod.rs
+++ b/src-tauri/src/core/openclaw/mod.rs
@@ -73,7 +73,7 @@ pub const MIN_BUN_VERSION: &str = "1.0";
/// OpenClaw runtime directory (where Bun and OpenClaw are installed)
pub fn get_openclaw_runtime_dir() -> Result<std::path::PathBuf, String> {
let base = get_openclaw_base_dir()?;
- let runtime_dir = base.join("runtime");
+ let runtime_dir = base.join("bunx");
if !runtime_dir.exists() {
std::fs::create_dir_all(&runtime_dir).map_err(|e| e.to_string())?;
}
@@ -112,77 +112,6 @@ pub fn resolve_bundled_bun() -> Option<std::path::PathBuf> {
None
}
-pub fn ensure_bun_node_shim() -> Result<(), String> {
- let bun_path = resolve_bundled_bun().ok_or("Bundled Bun not found")?;
- let runtime_dir = get_openclaw_runtime_dir()?;
- let runtime_bin = runtime_dir.join("bin");
- std::fs::create_dir_all(&runtime_bin).map_err(|e| e.to_string())?;
-
- let node_shim = if cfg!(target_os = "windows") {
- runtime_bin.join("node.exe")
- } else {
- runtime_bin.join("node")
- };
-
- #[cfg(unix)]
- {
- if node_shim.exists() || node_shim.symlink_metadata().is_ok() {
- if let Ok(target) = std::fs::read_link(&node_shim) {
- if target == bun_path {
- return Ok(());
- }
- }
- let _ = std::fs::remove_file(&node_shim);
- }
-
- // AppImage: copy instead of symlink (mount path is ephemeral)
- #[cfg(target_os = "linux")]
- {
- if std::env::var("APPIMAGE").is_ok() {
- std::fs::copy(&bun_path, &node_shim)
- .map_err(|e| format!("Failed to copy bun as node: {}", e))?;
- use std::os::unix::fs::PermissionsExt;
- let _ = std::fs::set_permissions(
- &node_shim,
- std::fs::Permissions::from_mode(0o755),
- );
- return Ok(());
- }
- }
-
- std::os::unix::fs::symlink(&bun_path, &node_shim)
- .map_err(|e| format!("Failed to create node->bun symlink: {}", e))?;
- }
-
- #[cfg(target_os = "windows")]
- {
- let bun_modified = std::fs::metadata(&bun_path)
- .and_then(|m| m.modified())
- .ok();
-
- for shim in &[node_shim, runtime_bin.join("bun.exe")] {
- let needs_copy = if shim.exists() {
- let shim_modified = std::fs::metadata(shim)
- .and_then(|m| m.modified())
- .ok();
- match (bun_modified, shim_modified) {
- (Some(b), Some(s)) => b > s,
- _ => true,
- }
- } else {
- true
- };
-
- if needs_copy {
- std::fs::copy(&bun_path, shim)
- .map_err(|e| format!("Failed to copy bun to {}: {}", shim.display(), e))?;
- }
- }
- }
-
- Ok(())
-}
-
pub const PATH_SEPARATOR: &str = if cfg!(target_os = "windows") { ";" } else { ":" };
/// Prepend bundled Bun dir and openclaw-runtime/bin to PATH.
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index 405349d0a..628c108de 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -27,9 +27,9 @@ async fn install_openclaw_globally() -> Result<(), String> {
.stdout(Stdio::piped())
.stderr(Stdio::piped());
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
#[cfg(target_os = "windows")]
{
@@ -65,8 +65,20 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
});
let mut cmd = if installed_bin.as_ref().map(|p| p.exists()).unwrap_or(false) {
- log::info!("Running openclaw from installed path: {:?}", installed_bin);
- tokio::process::Command::new(installed_bin.unwrap())
+ let bin = installed_bin.unwrap();
+ #[cfg(not(target_os = "windows"))]
+ let cmd = {
+ log::info!("Running openclaw via node from installed path: {:?}", bin);
+ let mut c = tokio::process::Command::new("node");
+ c.arg(&bin);
+ c
+ };
+ #[cfg(target_os = "windows")]
+ let cmd = {
+ log::info!("Running openclaw from installed path: {:?}", bin);
+ tokio::process::Command::new(&bin)
+ };
+ cmd
} else if let Some(bun) = super::resolve_bundled_bun() {
log::info!("openclaw not installed yet, falling back to bun x");
let mut c = tokio::process::Command::new(bun);
@@ -78,7 +90,6 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
};
cmd.args(args)
- .current_dir(config_dir)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
@@ -86,9 +97,9 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
cmd.env("BUN_INSTALL", dir);
}
- if let Some(new_path) = super::build_augmented_path() {
- cmd.env("PATH", new_path);
- }
+ // if let Some(new_path) = super::build_augmented_path() {
+ // cmd.env("PATH", new_path);
+ // }
#[cfg(target_os = "windows")]
{
@@ -114,10 +125,6 @@ impl Sandbox for DirectProcessSandbox {
}
async fn start(&self, config: &SandboxConfig) -> Result<SandboxHandle, String> {
- if let Err(e) = super::ensure_bun_node_shim() {
- log::warn!("Failed to ensure node shim: {}", e);
- }
-
let use_child_process = if cfg!(target_os = "windows") {
true
} else {