From e5e20a11540eb019a091386e43a14881a3b5781d Mon Sep 17 00:00:00 2001 From: Pnant <73925474+Panniantong@users.noreply.github.com> Date: Thu, 5 Mar 2026 10:32:02 +0800 Subject: [PATCH] fix(windows): use shutil.which() for npm subprocess calls (#73) Two subprocess.run(["npm", ...]) calls in undici installation were using bare command name, which fails on Windows where npm is installed as npm.cmd. Now resolves full path via shutil.which() first, consistent with all other subprocess calls. Co-authored-by: Panniantong --- agent_reach/cli.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/agent_reach/cli.py b/agent_reach/cli.py index 5209893..8bb3a41 100644 --- a/agent_reach/cli.py +++ b/agent_reach/cli.py @@ -410,14 +410,15 @@ def _install_system_deps(): print(" ⬜ xreach CLI requires Node.js (optional — Twitter reading still works via Jina)") # ── undici (proxy support for Node.js fetch) ── - if shutil.which("npm"): - npm_root = subprocess.run(["npm", "root", "-g"], capture_output=True, encoding="utf-8", errors="replace", timeout=5).stdout.strip() + npm_cmd = shutil.which("npm") + if npm_cmd: + npm_root = subprocess.run([npm_cmd, "root", "-g"], capture_output=True, encoding="utf-8", errors="replace", timeout=5).stdout.strip() undici_path = os.path.join(npm_root, "undici", "index.js") if npm_root else "" if os.path.exists(undici_path): print(" ✅ undici already installed (Node.js proxy support)") else: try: - subprocess.run(["npm", "install", "-g", "undici"], capture_output=True, encoding="utf-8", errors="replace", timeout=60) + subprocess.run([npm_cmd, "install", "-g", "undici"], capture_output=True, encoding="utf-8", errors="replace", timeout=60) print(" ✅ undici installed (Node.js proxy support)") except Exception: print(" ⬜ undici install failed (optional — xreach may not work behind proxies)")