From d02ef66c89f73b8ad315722071235e5a6774a59c Mon Sep 17 00:00:00 2001 From: 0okay <45843383+0okay@users.noreply.github.com> Date: Sun, 18 Jan 2026 23:14:03 +0800 Subject: [PATCH] Refactor connection logic for Windows and hash calculationfix(cli): fix windows daemon startup and port calculation inconsistency (#79) --- cli/src/connection.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/connection.rs b/cli/src/connection.rs index 9b73f0b..1430061 100644 --- a/cli/src/connection.rs +++ b/cli/src/connection.rs @@ -104,7 +104,9 @@ fn get_port_for_session(session: &str) -> u16 { for c in session.chars() { hash = ((hash << 5).wrapping_sub(hash)).wrapping_add(c as i32); } - 49152 + ((hash.abs() as u16) % 16383) + // Correct logic: first take absolute modulo, then cast to u16 + // Using unsigned_abs() to safely handle i32::MIN + 49152 + ((hash.unsigned_abs() as u32 % 16383) as u16) } #[cfg(unix)] @@ -235,13 +237,10 @@ pub fn ensure_daemon( { use std::os::windows::process::CommandExt; - // On Windows, use cmd.exe to run node to ensure proper PATH resolution. - // This handles cases where node.exe isn't directly in PATH but node.cmd is. - // Pass the entire command as a single string to /c to handle paths with spaces. - let cmd_string = format!("node \"{}\"", daemon_path.display()); - let mut cmd = Command::new("cmd"); - cmd.arg("/c") - .arg(&cmd_string) + // On Windows, call node directly. Command::new handles PATH resolution (node.exe or node.cmd) + // and automatically quotes arguments containing spaces. + let mut cmd = Command::new("node"); + cmd.arg(daemon_path) .env("AGENT_BROWSER_DAEMON", "1") .env("AGENT_BROWSER_SESSION", session);