From 932d596466838806f111afc3c24e7122d1b8b873 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 8 Mar 2026 04:36:23 -0700 Subject: [PATCH] feat: enhance systemd unit and install script for browser dependencies Updated the systemd unit generation to include the virtual environment and node modules in the PATH, improving the execution context for the hermes CLI. Additionally, added support for installing Playwright and its dependencies on Arch/Manjaro systems in the install script, ensuring a smoother setup process for browser tools. --- hermes_cli/gateway.py | 8 ++++++++ scripts/install.sh | 27 +++++++++++++++++++++++++++ tools/browser_tool.py | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index b2f5f57d..b89db974 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -157,6 +157,12 @@ def generate_systemd_unit() -> str: import shutil python_path = get_python_path() working_dir = str(PROJECT_ROOT) + venv_dir = str(PROJECT_ROOT / "venv") + venv_bin = str(PROJECT_ROOT / "venv" / "bin") + node_bin = str(PROJECT_ROOT / "node_modules" / ".bin") + + # Build a PATH that includes the venv, node_modules, and standard system dirs + sane_path = f"{venv_bin}:{node_bin}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" hermes_cli = shutil.which("hermes") or f"{python_path} -m hermes_cli.main" return f"""[Unit] @@ -168,6 +174,8 @@ Type=simple ExecStart={python_path} -m hermes_cli.main gateway run --replace ExecStop={hermes_cli} gateway stop WorkingDirectory={working_dir} +Environment="PATH={sane_path}" +Environment="VIRTUAL_ENV={venv_dir}" Restart=on-failure RestartSec=10 KillMode=mixed diff --git a/scripts/install.sh b/scripts/install.sh index 5a6f7f73..b4a9716b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -829,6 +829,33 @@ install_node_deps() { log_warn "npm install failed (browser tools may not work)" } log_success "Node.js dependencies installed" + + # Install Playwright browser + system dependencies. + # Playwright's install-deps only supports apt/dnf/zypper natively. + # For Arch/Manjaro we install the system libs via pacman first. + log_info "Installing browser engine (Playwright Chromium)..." + case "$DISTRO" in + arch|manjaro) + if command -v pacman &> /dev/null; then + log_info "Arch/Manjaro detected — installing Chromium system dependencies via pacman..." + if command -v sudo &> /dev/null && sudo -n true 2>/dev/null; then + sudo NEEDRESTART_MODE=a pacman -S --noconfirm --needed \ + nss atk at-spi2-core cups libdrm libxkbcommon mesa pango cairo alsa-lib >/dev/null 2>&1 || true + elif [ "$(id -u)" -eq 0 ]; then + pacman -S --noconfirm --needed \ + nss atk at-spi2-core cups libdrm libxkbcommon mesa pango cairo alsa-lib >/dev/null 2>&1 || true + else + log_warn "Cannot install browser deps without sudo. Run manually:" + log_warn " sudo pacman -S nss atk at-spi2-core cups libdrm libxkbcommon mesa pango cairo alsa-lib" + fi + fi + cd "$INSTALL_DIR" && npx playwright install chromium 2>/dev/null || true + ;; + *) + cd "$INSTALL_DIR" && npx playwright install --with-deps chromium 2>/dev/null || true + ;; + esac + log_success "Browser engine installed" fi # Install WhatsApp bridge dependencies diff --git a/tools/browser_tool.py b/tools/browser_tool.py index 2ea0c28f..e1bd3223 100644 --- a/tools/browser_tool.py +++ b/tools/browser_tool.py @@ -815,6 +815,13 @@ def _run_browser_command( level = logging.WARNING if result.returncode != 0 else logging.DEBUG logger.log(level, "browser '%s' stderr: %s", command, result.stderr.strip()[:500]) + # Log empty output as warning — common sign of broken agent-browser + if not result.stdout.strip() and result.returncode == 0: + logger.warning("browser '%s' returned empty stdout with rc=0. " + "cmd=%s stderr=%s", + command, " ".join(cmd_parts[:4]) + "...", + (result.stderr or "")[:200]) + # Parse JSON output if result.stdout.strip(): try: