diff --git a/crates/gyandoot-agent/src/browser_manager.rs b/crates/gyandoot-agent/src/browser_manager.rs index 5d88102..8342de0 100644 --- a/crates/gyandoot-agent/src/browser_manager.rs +++ b/crates/gyandoot-agent/src/browser_manager.rs @@ -408,7 +408,7 @@ async fn trigger_daemon_start(npx: &str, session: &str) -> Result<(), String> { /// Find the daemon.js entrypoint in the globally installed camoufox-browser package. /// Tries: npm root -g → find dist/daemon.js -async fn find_daemon_js(npx: &str) -> Result { +async fn find_daemon_js(_npx: &str) -> Result { // Try `npm root -g` to find global node_modules let root_output = Command::new("npm") .args(&["root", "-g"]) diff --git a/install.sh b/install.sh index 11cd6af..968d482 100755 --- a/install.sh +++ b/install.sh @@ -260,16 +260,113 @@ install_binary() { err "Binary not found at $target_dir/$bin_name" fi - local install_dir="/usr/local/bin" - if [ ! -w "$install_dir" ]; then - info "Need sudo to install to $install_dir" - sudo cp "$target_dir/$bin_name" "$install_dir/$bin_name" - sudo chmod +x "$install_dir/$bin_name" - else - cp "$target_dir/$bin_name" "$install_dir/$bin_name" - chmod +x "$install_dir/$bin_name" + # ── Detect best install location per platform ───────────────────── + # Priority: + # 1. ~/.cargo/bin/ — always in PATH for Rust users, no sudo + # 2. /usr/local/bin/ — standard Unix location, may need sudo + # 3. Windows: use a standard PATH location or just warn + # + local os + os="$(uname -s)" + + local install_dir="" + local installed_to="" + + # Detect WSL (Windows Subsystem for Linux) + local is_wsl=false + if [ -f /proc/version ] && grep -qiE 'microsoft|wsl' /proc/version 2>/dev/null; then + is_wsl=true + fi + + case "$os" in + Darwin|Linux) + # Option A: ~/.cargo/bin/ (no sudo needed, always in PATH for Rust users) + if [ -d "$HOME/.cargo/bin" ] && echo "$PATH" | grep -q "$HOME/.cargo/bin"; then + install_dir="$HOME/.cargo/bin" + cp "$target_dir/$bin_name" "$install_dir/$bin_name" + chmod +x "$install_dir/$bin_name" + installed_to="$install_dir/$bin_name" + # Option B: /usr/local/bin/ (standard, may need sudo) + elif [ -d "/usr/local/bin" ]; then + if [ -w "/usr/local/bin" ]; then + install_dir="/usr/local/bin" + cp "$target_dir/$bin_name" "$install_dir/$bin_name" + chmod +x "$install_dir/$bin_name" + else + info "Need sudo to install to /usr/local/bin" + sudo cp "$target_dir/$bin_name" "/usr/local/bin/$bin_name" + sudo chmod +x "/usr/local/bin/$bin_name" + install_dir="/usr/local/bin" + fi + installed_to="$install_dir/$bin_name" + # Option C: ~/.local/bin/ (XDG, common on modern Linux) + elif [ -d "$HOME/.local/bin" ] && echo "$PATH" | grep -q "$HOME/.local/bin"; then + install_dir="$HOME/.local/bin" + cp "$target_dir/$bin_name" "$install_dir/$bin_name" + chmod +x "$install_dir/$bin_name" + installed_to="$install_dir/$bin_name" + else + # Fallback: just copy to ~/.cargo/bin and create it + mkdir -p "$HOME/.cargo/bin" + cp "$target_dir/$bin_name" "$HOME/.cargo/bin/$bin_name" + chmod +x "$HOME/.cargo/bin/$bin_name" + install_dir="$HOME/.cargo/bin" + installed_to="$install_dir/$bin_name" + if ! echo "$PATH" | grep -q "$HOME/.cargo/bin"; then + warn "$HOME/.cargo/bin is not in your PATH." + warn "Add this to your shell profile (~/.zshrc, ~/.bashrc, etc.):" + echo " export PATH=\"\$HOME/.cargo/bin:\$PATH\"" + fi + fi + ;; + CYGWIN*|MINGW*|MSYS*) + # Windows / Git Bash / MSYS2 + install_dir="/usr/local/bin" + cp "$target_dir/$bin_name" "$install_dir/$bin_name" + chmod +x "$install_dir/$bin_name" + installed_to="$install_dir/$bin_name" + warn "Windows detected. Make sure '$install_dir' is in your PATH." + ;; + *) + err "Unsupported OS: $os" + ;; + esac + + ok "Installed to $installed_to" + + # ── Verify it's usable via PATH ────────────────────────────────── + local cmd_path + cmd_path="$(command -v gyandoot 2>/dev/null || true)" + if [ -z "$cmd_path" ]; then + warn "'gyandoot' not found in PATH after install." + warn "The install directory may not be in your PATH." + warn "Try running with: $installed_to" + if [ -n "$install_dir" ]; then + case "$os" in + Darwin) + echo "" + echo " Add to your ~/.zshrc:" + echo " export PATH=\"$install_dir:\$PATH\"" + echo " Then: source ~/.zshrc" + ;; + Linux) + echo "" + echo " Add to your ~/.bashrc:" + echo " export PATH=\"$install_dir:\$PATH\"" + echo " Then: source ~/.bashrc" + ;; + esac + fi + elif [ "$cmd_path" != "$installed_to" ]; then + warn "There's ANOTHER 'gyandoot' at '$cmd_path' that takes priority over '$installed_to'." + warn "That binary is from a PREVIOUS installation and may be outdated." + warn "" + warn " ▶ To use the NEW version, run: $installed_to" + warn " ▶ Or remove the old one: sudo rm $cmd_path" + warn " ▶ Then 'gyandoot run' will pick up the new one." + else + ok "PATH resolves to the newly installed binary." fi - ok "Installed to $install_dir/$bin_name" } print_post_install() {