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: running bun PR wrapper of openclaw on Window

Vanalite658809c72118
diff --git a/src-tauri/src/core/openclaw/cli.rs b/src-tauri/src/core/openclaw/cli.rs
index 2bb604344..0205e7c28 100644
--- a/src-tauri/src/core/openclaw/cli.rs
+++ b/src-tauri/src/core/openclaw/cli.rs
@@ -1,33 +1,22 @@
-//! CLI-specific functions for OpenClaw management
-//!
-//! These functions are designed to be called from the CLI without
-//! requiring Tauri's State management.
-
use std::process::Stdio;
use tokio::process::Command;
use super::models::OpenClawStatus;
use super::{get_openclaw_config_dir, get_openclaw_config_path, OPENCLAW_PORT};
-/// Apply common Windows settings to prevent console window popups.
#[cfg(target_os = "windows")]
fn hide_window(cmd: &mut Command) {
use std::os::windows::process::CommandExt;
- cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ cmd.creation_flags(0x08000000);
}
#[cfg(not(target_os = "windows"))]
fn hide_window(_cmd: &mut Command) {}
-/// Helper to build a command with resolved openclaw path and PATH injection.
-///
-/// When bundled Bun is available, uses `bun <openclaw_path> <args>` to avoid
-/// shebang resolution issues (old system node, missing node shim, etc.).
+/// Build a command for openclaw. On Unix, uses bun as explicit interpreter
+/// to bypass shebang resolution. On Windows, runs openclaw.exe directly.
fn build_openclaw_command(args: &[&str]) -> Command {
- // Ensure node shim points to bundled Bun (for shebang resolution fallback)
- if let Err(e) = super::ensure_bun_node_shim() {
- log::debug!("Node shim not created (will fall back to system node): {}", e);
- }
+ let _ = super::ensure_bun_node_shim();
let openclaw_path = super::get_openclaw_bin_path().ok();
let use_installed_binary = openclaw_path
@@ -35,9 +24,11 @@ fn build_openclaw_command(args: &[&str]) -> Command {
.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();
- if use_installed_binary && bun_path.is_some() {
- // Best path: run bun explicitly as the interpreter for the openclaw script
+ if use_bun_interpreter {
let mut cmd = Command::new(bun_path.unwrap());
cmd.arg(openclaw_path.unwrap());
if let Some(new_path) = super::build_augmented_path() {
@@ -55,7 +46,6 @@ fn build_openclaw_command(args: &[&str]) -> Command {
hide_window(&mut cmd);
cmd
} else {
- // Fallback: bare "openclaw" (user installed via npm or has it in PATH)
let mut cmd = Command::new("openclaw");
if let Some(new_path) = super::build_augmented_path() {
cmd.env("PATH", new_path);
@@ -66,14 +56,12 @@ fn build_openclaw_command(args: &[&str]) -> Command {
}
}
-/// Check if OpenClaw is installed (standalone version for CLI)
async fn check_openclaw_installed() -> Result<Option<String>, String> {
- // Try the installed openclaw binary in the runtime directory
if let Ok(openclaw_path) = super::get_openclaw_bin_path() {
if openclaw_path.exists() {
- // Use bun as explicit interpreter when available (avoids shebang issues)
- let mut cmd = if let Some(bun_path) = super::resolve_bundled_bun() {
- let mut c = Command::new(bun_path);
+ let bun_path = super::resolve_bundled_bun();
+ let mut cmd = if !cfg!(target_os = "windows") && bun_path.is_some() {
+ let mut c = Command::new(bun_path.unwrap());
c.arg(&openclaw_path);
c
} else {
@@ -95,7 +83,6 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {
}
}
- // Fallback: bare "openclaw" (user installed via npm)
let mut cmd = Command::new("openclaw");
cmd.arg("--version");
if let Some(new_path) = super::build_augmented_path() {
@@ -117,9 +104,7 @@ async fn check_openclaw_installed() -> Result<Option<String>, String> {
}
}
-/// Check if a JS runtime (Bun or Node.js) is available
async fn check_runtime_version() -> Option<String> {
- // First try bundled Bun
if let Some(bun_path) = super::resolve_bundled_bun() {
let mut cmd = Command::new(&bun_path);
cmd.arg("--version");
@@ -132,7 +117,6 @@ async fn check_runtime_version() -> Option<String> {
}
}
- // Fall back to Node.js
let mut cmd = Command::new("node");
cmd.arg("--version");
hide_window(&mut cmd);
@@ -145,18 +129,15 @@ async fn check_runtime_version() -> Option<String> {
}
}
-/// Check if a port is available
async fn check_port_available(port: u16) -> bool {
let addr = format!("127.0.0.1:{}", port);
tokio::net::TcpListener::bind(&addr).await.is_ok()
}
-/// Check if OpenClaw gateway is running by checking if port is in use
async fn check_gateway_running() -> bool {
!check_port_available(OPENCLAW_PORT).await
}
-/// Get OpenClaw status (standalone version for CLI)
pub async fn get_status() -> Result<OpenClawStatus, String> {
let openclaw_version = check_openclaw_installed().await?;
let runtime_version = check_runtime_version().await;
@@ -175,14 +156,11 @@ pub async fn get_status() -> Result<OpenClawStatus, String> {
})
}
-/// Start the OpenClaw gateway (standalone version for CLI)
pub async fn start_gateway() -> Result<(), String> {
- // Check if already running
if check_gateway_running().await {
return Err("OpenClaw gateway is already running".to_string());
}
- // Check if config exists
let config_path = get_openclaw_config_path()?;
if !config_path.exists() {
return Err("OpenClaw is not configured. Run 'jan openclaw configure' first.".to_string());
@@ -190,7 +168,6 @@ pub async fn start_gateway() -> Result<(), String> {
let config_dir = get_openclaw_config_dir()?;
- // Start OpenClaw gateway as a detached process using resolved path
let mut child = build_openclaw_command(&["gateway", "start"])
.current_dir(&config_dir)
.stdout(Stdio::null())
@@ -198,19 +175,15 @@ pub async fn start_gateway() -> Result<(), String> {
.spawn()
.map_err(|e| format!("Failed to start OpenClaw: {}", e))?;
- // Wait a moment for startup
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
- // Check if it started successfully
match child.try_wait() {
Ok(Some(status)) => {
if !status.success() {
return Err("OpenClaw gateway failed to start".to_string());
}
}
- Ok(None) => {
- // Process is still running, which is expected
- }
+ Ok(None) => {}
Err(e) => {
return Err(format!("Failed to check gateway status: {}", e));
}
@@ -219,9 +192,7 @@ pub async fn start_gateway() -> Result<(), String> {
Ok(())
}
-/// Stop the OpenClaw gateway (standalone version for CLI)
pub async fn stop_gateway() -> Result<(), String> {
- // Try to stop using resolved openclaw command
let output = build_openclaw_command(&["gateway", "stop"])
.output()
.await;
@@ -232,7 +203,6 @@ pub async fn stop_gateway() -> Result<(), String> {
}
}
- // Fallback: try to kill the process by name
#[cfg(unix)]
{
let mut cmd = Command::new("pkill");
@@ -246,7 +216,7 @@ pub async fn stop_gateway() -> Result<(), String> {
let kill = |im: &'static str| async move {
let mut cmd = Command::new("taskkill");
cmd.args(["/F", "/IM", im]);
- cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ cmd.creation_flags(0x08000000);
let _ = cmd.output().await;
};
kill("bun.exe").await;
@@ -254,7 +224,6 @@ pub async fn stop_gateway() -> Result<(), String> {
kill("openclaw.exe").await;
}
- // Verify it's stopped
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
if check_gateway_running().await {
@@ -264,14 +233,8 @@ pub async fn stop_gateway() -> Result<(), String> {
Ok(())
}
-/// Restart the OpenClaw gateway (standalone version for CLI)
pub async fn restart_gateway() -> Result<(), String> {
- // Stop first (ignore errors if not running)
let _ = stop_gateway().await;
-
- // Wait a moment
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
-
- // Start
start_gateway().await
}
diff --git a/src-tauri/src/core/openclaw/commands.rs b/src-tauri/src/core/openclaw/commands.rs
index 534564171..47485803a 100644
--- a/src-tauri/src/core/openclaw/commands.rs
+++ b/src-tauri/src/core/openclaw/commands.rs
@@ -42,15 +42,8 @@ async fn is_docker_container_running() -> bool {
.unwrap_or(false)
}
-/// Build a `Command` that routes through `docker exec` when the container is running,
-/// or falls back to a bare `openclaw` command for users who installed via npm.
-///
-/// Resolution order for direct process mode:
-/// 1. Installed binary at `~/.jan/openclaw-runtime/bin/openclaw` (fast, no download)
-/// 2. Bare `openclaw` command (assumes user installed it globally via npm)
-///
-/// In both cases, PATH is augmented with the bundled Bun directory and runtime bin
-/// directory (which contains a `node` shim pointing to Bun for shebang resolution).
+/// Build a `Command` for openclaw: docker exec when container is running,
+/// otherwise direct process with bun interpreter (Unix) or native exe (Windows).
async fn openclaw_command(args: &[&str]) -> Command {
if is_docker_container_running().await {
let mut cmd = Command::new("docker");
@@ -66,10 +59,7 @@ async fn openclaw_command(args: &[&str]) -> Command {
hide_window(&mut cmd);
cmd
} else {
- // Ensure node shim points to bundled Bun (for shebang resolution fallback)
- if let Err(e) = super::ensure_bun_node_shim() {
- log::debug!("Node shim not created (will fall back to system node): {}", e);
- }
+ let _ = super::ensure_bun_node_shim();
let openclaw_path = super::get_openclaw_bin_path().ok();
let use_installed_binary = openclaw_path
@@ -77,11 +67,11 @@ async fn openclaw_command(args: &[&str]) -> Command {
.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();
- // When bundled Bun is available, use it as the explicit interpreter for
- // the openclaw script. This bypasses shebang resolution entirely — avoids
- // issues with old system node or missing node shim.
- let mut cmd = if use_installed_binary && bun_path.is_some() {
+ let mut cmd = if use_bun_interpreter {
let mut c = Command::new(bun_path.unwrap());
c.arg(openclaw_path.unwrap());
if let Some(new_path) = super::build_augmented_path() {
@@ -97,7 +87,6 @@ async fn openclaw_command(args: &[&str]) -> Command {
c.args(args);
c
} else {
- // Fallback: bare "openclaw" (user installed via npm or has it in PATH)
let mut c = Command::new("openclaw");
if let Some(new_path) = super::build_augmented_path() {
c.env("PATH", new_path);
@@ -1094,14 +1083,9 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {
let pinned_package = format!("{}@{}", OPENCLAW_PACKAGE_NAME, OPENCLAW_VERSION);
- // Ensure node shim exists before install (openclaw scripts use #!/usr/bin/env node)
- if let Err(e) = super::ensure_bun_node_shim() {
- log::warn!("Failed to create node shim before install: {}", e);
- }
+ let _ = super::ensure_bun_node_shim();
- // Try bundled Bun first, then fall back to npm
let output = if let Some(bun_path) = super::resolve_bundled_bun() {
- // Use bundled Bun with custom install directory
let runtime_dir = super::get_openclaw_runtime_dir()?;
let mut cmd = tokio::process::Command::new(&bun_path);
cmd.args(["install", "-g", &pinned_package])
@@ -1113,7 +1097,6 @@ pub async fn openclaw_install() -> Result<InstallResult, String> {
.await
.map_err(|e| format!("Failed to run bun install: {}", e))?
} else {
- // Fall back to npm
let mut cmd = Command::new("npm");
cmd.args(["install", "-g", &pinned_package])
.stdout(Stdio::piped())
diff --git a/src-tauri/src/core/openclaw/mod.rs b/src-tauri/src/core/openclaw/mod.rs
index 5bee601e7..5d8eed228 100644
--- a/src-tauri/src/core/openclaw/mod.rs
+++ b/src-tauri/src/core/openclaw/mod.rs
@@ -78,21 +78,15 @@ pub fn get_openclaw_bin_path() -> Result<std::path::PathBuf, String> {
Ok(bin_path)
}
-/// Resolve the bundled Bun path.
+/// Resolve the bundled Bun path. Returns None if unavailable.
///
-/// Platform-specific resolution:
-/// - **macOS / Windows**: Tauri `externalBin` places `bun` (or `bun.exe`) next to the
-/// main executable — same directory as `std::env::current_exe().parent()`.
-/// - **Linux (deb)**: Bun is installed to `/usr/bin/bun` via the deb package's `files`
-/// mapping, not as an `externalBin`. So we also check `/usr/bin/bun`.
-/// - **Linux (AppImage)**: The binary may be next to the executable inside the
-/// AppImage mount, so the `exe_path.parent()` check covers it.
-///
-/// Returns None if bun doesn't exist or can't run on this machine.
+/// Resolution order:
+/// 1. Next to executable (macOS, Windows, dev mode)
+/// 2. `$APPDIR/usr/bin/bun` (Linux AppImage — exe is in usr/lib/, bun is in usr/bin/)
+/// 3. `/usr/bin/bun` (Linux deb)
pub fn resolve_bundled_bun() -> Option<std::path::PathBuf> {
let bun_name = if cfg!(target_os = "windows") { "bun.exe" } else { "bun" };
- // 1. Check next to the executable (macOS, Windows, Linux AppImage, dev mode)
if let Ok(exe_path) = std::env::current_exe() {
if let Some(bin_path) = exe_path.parent() {
let candidate = bin_path.join(bun_name);
@@ -105,9 +99,18 @@ pub fn resolve_bundled_bun() -> Option<std::path::PathBuf> {
}
}
- // 2. Linux deb: bun is installed to /usr/bin/bun via package files mapping
#[cfg(target_os = "linux")]
{
+ if let Ok(appdir) = std::env::var("APPDIR") {
+ let candidate = std::path::PathBuf::from(&appdir).join("usr").join("bin").join("bun");
+ if candidate.exists() {
+ let s = candidate.to_string_lossy().to_string();
+ if jan_utils::system::can_override_npx(s) {
+ return Some(candidate);
+ }
+ }
+ }
+
let system_bun = std::path::PathBuf::from("/usr/bin/bun");
if system_bun.exists() {
let s = system_bun.to_string_lossy().to_string();
@@ -120,12 +123,8 @@ pub fn resolve_bundled_bun() -> Option<std::path::PathBuf> {
None
}
-/// Ensure a `node` symlink (or copy on Windows) exists in the runtime bin directory
-/// pointing to the bundled Bun binary. This is critical because:
-/// - `openclaw gateway install` registers a launchd/systemd service
-/// - The service plist hardcodes the absolute path to `node` (resolved via shebang)
-/// - If bun's directory is first in PATH and contains a `node` symlink, the service
-/// will use bun as its runtime instead of requiring a separate Node.js installation
+/// Create a `node` shim (symlink on Unix, copy on Windows) pointing to bundled Bun.
+/// Used as fallback for shebang resolution in service files.
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()?;
@@ -140,25 +139,21 @@ pub fn ensure_bun_node_shim() -> Result<(), String> {
#[cfg(unix)]
{
- // Check if shim already exists and points to the correct bun binary
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(());
}
}
- // Stale or non-symlink — remove and recreate
let _ = std::fs::remove_file(&node_shim);
}
- // Linux AppImage: mount path is ephemeral (/tmp/.mount_JanXXX/), so copy
- // instead of symlinking to ensure the shim survives after AppImage unmounts.
+ // 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 (AppImage): {}", e))?;
- // Ensure executable permission on the copy
+ .map_err(|e| format!("Failed to copy bun as node: {}", e))?;
use std::os::unix::fs::PermissionsExt;
let _ = std::fs::set_permissions(
&node_shim,
@@ -174,8 +169,6 @@ pub fn ensure_bun_node_shim() -> Result<(), String> {
#[cfg(target_os = "windows")]
{
- // Windows symlinks require elevated privileges; copy instead.
- // Re-copy if bun.exe is newer than our node.exe copy.
let needs_copy = if node_shim.exists() {
let bun_modified = std::fs::metadata(&bun_path)
.and_then(|m| m.modified())
@@ -200,12 +193,9 @@ pub fn ensure_bun_node_shim() -> Result<(), String> {
Ok(())
}
-/// Platform-aware PATH separator (";" on Windows, ":" elsewhere).
pub const PATH_SEPARATOR: &str = if cfg!(target_os = "windows") { ";" } else { ":" };
-/// Build a new PATH string by prepending the bundled Bun directory and the
-/// openclaw-runtime/bin directory to the current PATH. Returns None if no
-/// extra entries are available.
+/// Prepend bundled Bun dir and openclaw-runtime/bin to PATH.
pub fn build_augmented_path() -> Option<String> {
let mut path_entries = Vec::new();
if let Some(bun_path) = resolve_bundled_bun() {
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index 00f2dedd2..23db4b12e 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -2,14 +2,10 @@ use std::process::Stdio;
use super::sandbox::{IsolationTier, Sandbox, SandboxConfig, SandboxHandle, SandboxStatus};
-/// Tier 0 fallback: runs OpenClaw as a direct process on the host.
-/// This preserves the exact current behavior — no isolation.
pub struct DirectProcessSandbox;
-/// Helper to build a command with resolved openclaw path and PATH injection.
-///
-/// When bundled Bun is available, uses `bun <openclaw_path> <args>` to avoid
-/// shebang resolution issues (old system node, missing node shim, etc.).
+/// Build a command for openclaw. On Unix, uses bun as explicit interpreter
+/// to bypass shebang resolution. On Windows, runs openclaw.exe directly.
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
@@ -17,18 +13,17 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
.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_installed_binary && bun_path.is_some() {
- // Best path: run bun explicitly as the interpreter for the openclaw script.
- // This bypasses shebang resolution entirely — no dependency on `node` in PATH.
+ let mut cmd = if use_bun_interpreter {
let mut c = tokio::process::Command::new(bun_path.unwrap());
c.arg(openclaw_path.unwrap());
c
} else if use_installed_binary {
- // Bun not available, run openclaw script directly (relies on shebang → system node)
tokio::process::Command::new(openclaw_path.unwrap())
} else {
- // Fallback: bare "openclaw" (user installed via npm or has it in PATH)
tokio::process::Command::new("openclaw")
};
@@ -37,16 +32,14 @@ fn build_openclaw_command(args: &[&str], config_dir: &std::path::Path) -> tokio:
.stdout(Stdio::piped())
.stderr(Stdio::piped());
- // Augment PATH with bundled Bun and runtime bin for shebang resolution
if let Some(new_path) = super::build_augmented_path() {
cmd.env("PATH", new_path);
}
- // On Windows, prevent console window popups
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
- cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ cmd.creation_flags(0x08000000);
}
cmd
@@ -67,18 +60,11 @@ impl Sandbox for DirectProcessSandbox {
}
async fn start(&self, config: &SandboxConfig) -> Result<SandboxHandle, String> {
- // Ensure node shim exists so `gateway install` hardcodes the correct runtime path.
- // This is the most critical call site: the service plist/unit file generated here
- // will contain the absolute path to `node` (resolved via #!/usr/bin/env node shebang).
- // Our shim makes that resolve to bundled Bun instead of system Node.js.
if let Err(e) = super::ensure_bun_node_shim() {
- log::warn!("Failed to ensure node shim before gateway install: {}", e);
+ log::warn!("Failed to ensure node shim: {}", e);
}
- // Ensure the gateway service is installed (registers launchd on macOS).
- // Pass --runtime bun when bundled Bun is available so the service plist/unit
- // hardcodes the bun binary path instead of resolving to system node.
- log::info!("DirectProcessSandbox: ensuring gateway service is installed");
+ // Install gateway service with --runtime bun when available
let install_args = if super::resolve_bundled_bun().is_some() {
vec!["gateway", "install", "--runtime", "bun"]
} else {
@@ -86,25 +72,17 @@ impl Sandbox for DirectProcessSandbox {
};
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() {
- log::info!("gateway install succeeded: {}", String::from_utf8_lossy(&output.stdout).trim());
- } else {
- let stderr = String::from_utf8_lossy(&output.stderr);
- let stdout = String::from_utf8_lossy(&output.stdout);
- log::error!("gateway install failed (exit {}): stdout={}, stderr={}", output.status, stdout.trim(), stderr.trim());
- }
+ Ok(output) if !output.status.success() => {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ log::error!("gateway install failed: {}", stderr.trim());
}
Err(e) => {
log::error!("Failed to run gateway install: {}", e);
}
+ _ => {}
}
- // Start OpenClaw gateway via CLI
- // 'openclaw gateway start' starts a daemon and exits immediately
- log::info!("DirectProcessSandbox: starting gateway service");
let mut cmd = build_openclaw_command(&["gateway", "start"], &config.config_dir);
-
for (key, value) in &config.env_vars {
cmd.env(key, value);
}
@@ -116,37 +94,22 @@ impl Sandbox for DirectProcessSandbox {
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
- let stdout = String::from_utf8_lossy(&output.stdout);
- log::error!(
- "openclaw gateway start failed: stdout={}, stderr={}",
- stdout,
- stderr
- );
return Err(format!("Failed to start OpenClaw gateway: {}", stderr));
}
- // The gateway runs as a daemon — we track it by port, not by child PID.
- // Return a Named handle so stop() knows which mechanism to use.
Ok(SandboxHandle::Named("direct-process".to_string()))
}
async fn stop(&self, _handle: &mut SandboxHandle) -> Result<(), String> {
- log::info!("DirectProcessSandbox: stopping gateway");
-
- // Try the clean CLI stop first using resolved path
let mut stopped_via_cli = false;
let config_dir = super::get_openclaw_config_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
let mut stop_cmd = build_openclaw_command(&["gateway", "stop"], &config_dir);
if let Ok(mut child) = stop_cmd.spawn() {
if let Ok(status) = child.wait().await {
- if status.success() {
- log::info!("openclaw gateway stop command succeeded");
- stopped_via_cli = true;
- }
+ stopped_via_cli = status.success();
}
}
- // Fallback: kill by process name
if !stopped_via_cli {
#[cfg(any(target_os = "macos", target_os = "linux"))]
{
@@ -159,11 +122,10 @@ impl Sandbox for DirectProcessSandbox {
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
- // Kill both bun.exe and node.exe processes running openclaw
let kill = |im: &'static str| async move {
let mut cmd = tokio::process::Command::new("taskkill");
cmd.args(["/F", "/IM", im]);
- cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ cmd.creation_flags(0x08000000);
let _ = cmd.output().await;
};
kill("bun.exe").await;
@@ -176,7 +138,6 @@ impl Sandbox for DirectProcessSandbox {
}
async fn status(&self, _handle: &SandboxHandle) -> Result<SandboxStatus, String> {
- // Check if the gateway is responding on its port
match tokio::net::TcpStream::connect(format!("127.0.0.1:{}", super::OPENCLAW_PORT)).await {
Ok(_) => Ok(SandboxStatus::Running),
Err(_) => Ok(SandboxStatus::Stopped),
@@ -184,11 +145,6 @@ impl Sandbox for DirectProcessSandbox {
}
async fn logs(&self, _handle: &SandboxHandle, _lines: usize) -> Result<Vec<String>, String> {
- // Direct process logs go to the system's service manager (launchd, etc.)
- // or /tmp/openclaw/. We don't capture them in-process.
- Ok(vec![
- "Log capture not available in direct process mode. Check /tmp/openclaw/ for logs."
- .to_string(),
- ])
+ Ok(vec!["Check /tmp/openclaw/ for logs.".to_string()])
}
}