fix(doctor): detect agent-browser in the Hermes-managed node bin so setup-browser installs aren't reported as missing (#53192)

`hermes acp --setup-browser` installs agent-browser into the Hermes-managed
node prefix (~/.hermes/node/bin/agent-browser), which isn't necessarily on
PATH. doctor only checked PROJECT_ROOT/node_modules and PATH (shutil.which),
so it false-negatived with "agent-browser not installed" even though the
binary was present and runnable. Mirror dep_ensure._has_hermes_agent_browser()
by also checking HERMES_HOME/node/bin and the legacy
HERMES_HOME/node_modules/.bin path, each gated by agent_browser_runnable().

Tested with tests/hermes_cli/test_doctor.py (added positive + not-runnable
cases) and pytest tests/hermes_cli/test_doctor.py -q (66 passed).
This commit is contained in:
Ubuntu 2026-06-27 02:02:51 +08:00 committed by Teknium
parent 7d3075d0d5
commit 1cec6afdfc
2 changed files with 79 additions and 0 deletions

View file

@ -1813,12 +1813,24 @@ def run_doctor(args):
agent_browser_path = PROJECT_ROOT / "node_modules" / "agent-browser"
agent_browser_ok = False
_which_ab = shutil.which("agent-browser")
# `hermes acp --setup-browser` installs agent-browser into the
# Hermes-managed node prefix, which isn't necessarily on PATH. Mirror
# dep_ensure._has_hermes_agent_browser() so doctor and dep_ensure agree
# on what "installed" means; otherwise doctor false-negatives (#53192).
_managed_ab = HERMES_HOME / "node" / "bin" / "agent-browser"
_legacy_ab = HERMES_HOME / "node_modules" / ".bin" / "agent-browser"
if agent_browser_path.exists():
check_ok("agent-browser (Node.js)", "(browser automation)")
agent_browser_ok = True
elif _which_ab and agent_browser_runnable(_which_ab):
check_ok("agent-browser", "(browser automation)")
agent_browser_ok = True
elif _managed_ab.is_file() and agent_browser_runnable(str(_managed_ab)):
check_ok("agent-browser", "(browser automation)")
agent_browser_ok = True
elif _legacy_ab.is_file() and agent_browser_runnable(str(_legacy_ab)):
check_ok("agent-browser", "(browser automation)")
agent_browser_ok = True
elif _which_ab:
# Found on PATH but won't run — almost always a dangling global
# symlink left behind by agent-browser's npm postinstall after a