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.

fix: openclaw direct run does not have dashboard bundled

Louis27636b32aafa
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index c8c985f5c..a80863a30 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -4,25 +4,75 @@ use super::sandbox::{IsolationTier, Sandbox, SandboxConfig, SandboxHandle, Sandb
pub struct DirectProcessSandbox;
-/// Build a command for openclaw. On Unix, uses bun as explicit interpreter
-/// to bypass shebang resolution. On Windows, runs openclaw.exe directly.
+/// Returns the BUN_INSTALL directory (`~/.jan/.bunx`), creating it if needed.
+fn get_bunx_dir() -> Option<std::path::PathBuf> {
+ let dir = dirs::home_dir()?.join(".jan").join(".bunx");
+ if let Err(e) = std::fs::create_dir_all(&dir) {
+ log::warn!("Failed to create BUN_INSTALL dir {:?}: {}", dir, e);
+ }
+ Some(dir)
+}
+
+/// Installs openclaw globally into the BUN_INSTALL dir using `bun add -g openclaw`.
+/// After this, the binary lives at `$BUN_INSTALL/bin/openclaw[.exe]`.
+async fn install_openclaw_globally() -> Result<(), String> {
+ let bun_path = super::resolve_bundled_bun().ok_or("Bundled bun not found")?;
+ let bunx_dir = get_bunx_dir().ok_or("Could not resolve home directory")?;
+
+ log::info!("Installing openclaw globally into {:?}", bunx_dir);
+
+ let mut cmd = tokio::process::Command::new(&bun_path);
+ cmd.args(["add", "-g", "openclaw"])
+ .env("BUN_INSTALL", &bunx_dir)
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped());
+
+ if let Some(new_path) = super::build_augmented_path() {
+ cmd.env("PATH", new_path);
+ }
+
+ #[cfg(target_os = "windows")]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x08000000);
+ }
+
+ let output = cmd.output().await.map_err(|e| format!("Failed to run bun add -g openclaw: {}", e))?;
+ log::info!("bun add -g openclaw stdout: {}", String::from_utf8_lossy(&output.stdout).trim());
+ log::info!("bun add -g openclaw stderr: {}", String::from_utf8_lossy(&output.stderr).trim());
+
+ if !output.status.success() {
+ return Err(format!(
+ "bun add -g openclaw failed: {}",
+ String::from_utf8_lossy(&output.stderr).trim()
+ ));
+ }
+
+ Ok(())
+}
+
+/// Build a command that runs the globally-installed openclaw binary from BUN_INSTALL/bin/.
+/// Falls back to `bun x openclaw` if the installed binary is not found.
fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio::process::Command {
- let openclaw_path = super::get_openclaw_bin_path().ok();
- let use_installed_binary = openclaw_path
- .as_ref()
- .map(|p| p.exists())
- .unwrap_or(false);
- let bun_path = super::resolve_bundled_bun();
- let use_bun_interpreter = !cfg!(target_os = "windows")
- && use_installed_binary
- && bun_path.is_some();
-
- let mut cmd = if use_bun_interpreter {
- let mut c = tokio::process::Command::new(bun_path.unwrap());
- c.arg(openclaw_path.unwrap());
+ let bunx_dir = get_bunx_dir();
+
+ let installed_bin = bunx_dir.as_ref().map(|d| {
+ if cfg!(target_os = "windows") {
+ d.join("bin").join("openclaw.exe")
+ } else {
+ d.join("bin").join("openclaw")
+ }
+ });
+
+ 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())
+ } 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);
+ c.arg("x");
+ c.arg("openclaw");
c
- } else if use_installed_binary {
- tokio::process::Command::new(openclaw_path.unwrap())
} else {
tokio::process::Command::new("openclaw")
};
@@ -32,6 +82,10 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
.stdout(Stdio::piped())
.stderr(Stdio::piped());
+ if let Some(dir) = bunx_dir {
+ cmd.env("BUN_INSTALL", dir);
+ }
+
if let Some(new_path) = super::build_augmented_path() {
cmd.env("PATH", new_path);
}
@@ -88,7 +142,12 @@ impl Sandbox for DirectProcessSandbox {
};
if !use_child_process {
- let mut cmd = build_openclaw_command(&["gateway", "start"], &config.config_dir);
+ 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);
}