The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(lsp): unknown lsp.package_manager fails closed; yarn uses the global --cwd form
teknium16cf2f066a861
diff --git a/agent/lsp/install.py b/agent/lsp/install.pyindex ecf069acf33..06341963ffc 100644--- a/agent/lsp/install.py+++ b/agent/lsp/install.py@@ -203,12 +203,14 @@ def _link_into_bin(target: Path) -> str:_NODE_PM_ARGV: Dict[str, Callable[[str], list]] = {"npm": lambda staging: ["install", "--prefix", staging, "--silent", "--no-fund", "--no-audit"],"pnpm": lambda staging: ["add", "--dir", staging],- "yarn": lambda staging: ["add", "--cwd", staging],+ # Global ``--cwd`` (before the command) is accepted by both Yarn Classic and Yarn Berry; Berry's+ # default PnP linker writes no ``node_modules/.bin``, so the staging dir needs ``nodeLinker: node-modules``.+ "yarn": lambda staging: ["--cwd", staging, "add"],}-def _node_package_manager() -> str:- """``lsp.package_manager`` from config (npm default); unknown values warn once and fall back to npm."""+def _node_package_manager() -> Optional[str]:+ """``lsp.package_manager`` from config (npm default); an unknown value fails closed (``None``)."""try:from hermes_cli.config import load_config_readonlylsp_cfg = load_config_readonly().get("lsp") or {}@@ -216,8 +218,9 @@ def _node_package_manager() -> str:return "npm"pm = str(lsp_cfg.get("package_manager") or "npm").strip().lower() if isinstance(lsp_cfg, dict) else "npm"if pm not in _NODE_PM_ARGV:- logger.warning("[install] lsp.package_manager=%r is not one of %s; using npm", pm, sorted(_NODE_PM_ARGV))- return "npm"+ # Fail closed: a typo must not silently bypass a pnpm/yarn supply-chain policy by running npm.+ logger.warning("[install] lsp.package_manager=%r is not one of %s; skipping install", pm, sorted(_NODE_PM_ARGV))+ return Nonereturn pm@@ -225,6 +228,8 @@ def _install_npm(pkg: str, bin_name: str, extra_pkgs: Optional[list] = None) ->"""Install with the configured Node package manager into ``<staging>`` and link``node_modules/.bin/<bin_name>`` into ``lsp/bin/``."""pm = _node_package_manager()+ if pm is None:+ return None# Managed Node first: $HERMES_HOME/node isn't on an arbitrary process's# PATH, so a bare which() would miss the Node that Hermes installed.pm_bin = find_node_executable(pm)diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 87ab39428b3..6bba90a2d7e 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -2251,8 +2251,9 @@ DEFAULT_CONFIG = {# first use; manual = only binaries on PATH; off = alias for manual."install_strategy": "auto",# Node package manager for the npm-recipe servers: npm | pnpm | yarn. Installs still land in- # <HERMES_HOME>/lsp/node_modules; a configured manager that is not installed skips the install- # (no silent fallback to npm) so a pnpm/yarn supply-chain policy is never bypassed.+ # <HERMES_HOME>/lsp/node_modules; a configured manager that is not installed, or an unknown+ # value, skips the install (no silent fallback to npm) so a pnpm/yarn supply-chain policy is+ # never bypassed."package_manager": "npm",# Idle seconds before a server is shut down (respawned on demand), so long- running# processes don't accumulate stale children (hundreds of MB + pipe FDs each) acrossdiff --git a/tests/agent/lsp/test_install_and_lint_fixes.py b/tests/agent/lsp/test_install_and_lint_fixes.pyindex e082b9b70e7..901171909a3 100644--- a/tests/agent/lsp/test_install_and_lint_fixes.py+++ b/tests/agent/lsp/test_install_and_lint_fixes.py@@ -184,13 +184,9 @@ def test_check_lint_returns_error_for_real_ts_type_errors(tmp_path):assert "TS2322" in lint.output-if __name__ == "__main__": # pragma: no cover- pytest.main([__file__, "-v"])--def test_lsp_package_manager_config_selects_installer_argv_and_never_falls_back_silently(tmp_path, monkeypatch):"""``lsp.package_manager`` picks the Node installer (staging-dir semantics kept); a configured manager- that is missing skips the install instead of quietly using npm; unknown values fall back to npm."""+ that is missing or unknown skips the install instead of quietly using npm (a typo must not bypass policy)."""from unittest.mock import MagicMockfrom agent.lsp import install as install_mod@@ -201,17 +197,24 @@ def test_lsp_package_manager_config_selects_installer_argv_and_never_falls_back_monkeypatch.setattr("hermes_cli.config.load_config_readonly", lambda: cfg)runs = []monkeypatch.setattr(install_mod.subprocess, "run", lambda cmd, **kw: (runs.append(cmd), MagicMock(returncode=0, stderr=""))[1])- present = {"npm": "/usr/bin/npm", "pnpm": "/usr/bin/pnpm"}+ present = {"npm": "/usr/bin/npm", "pnpm": "/usr/bin/pnpm", "yarn": "/usr/bin/yarn"}monkeypatch.setattr(install_mod, "find_node_executable", lambda name: present.get(name))cfg["lsp"] = {"package_manager": "pnpm"}install_mod._install_npm("pyright", "pyright-langserver")assert runs[-1] == ["/usr/bin/pnpm", "add", "--dir", staging, "pyright"]- cfg["lsp"] = {"package_manager": "bogus"} # unknown → npm, unchanged historical argv+ cfg["lsp"] = {"package_manager": "yarn"} # global --cwd: valid on Yarn Classic and Berryinstall_mod._install_npm("pyright", "pyright-langserver")- assert runs[-1] == ["/usr/bin/npm", "install", "--prefix", staging, "--silent", "--no-fund", "--no-audit", "pyright"]+ assert runs[-1] == ["/usr/bin/yarn", "--cwd", staging, "add", "pyright"]+ cfg["lsp"] = {"package_manager": "pnmp"} # unknown (typo) → fail closed, no npm run+ assert install_mod._install_npm("pyright", "pyright-langserver") is None+ del present["yarn"]cfg["lsp"] = {"package_manager": "yarn"} # configured but absent → no install, no npm runassert install_mod._install_npm("pyright", "pyright-langserver") is Noneassert len(runs) == 2+++if __name__ == "__main__": # pragma: no cover+ pytest.main([__file__, "-v"])diff --git a/website/docs/user-guide/features/lsp.md b/website/docs/user-guide/features/lsp.mdindex ded3125b6cd..f079bbda4ce 100644--- a/website/docs/user-guide/features/lsp.md+++ b/website/docs/user-guide/features/lsp.md@@ -195,9 +195,12 @@ lsp:# Node package manager for the npm-based servers: npm (default), pnpm# or yarn. Installs still land in <HERMES_HOME>/lsp/node_modules; a- # manager that is configured but not installed skips the install with- # a warning instead of silently using npm, so a pnpm/yarn supply-chain- # policy (minimumReleaseAge, allowBuilds, …) is never bypassed.+ # manager that is configured but not installed — or a value outside+ # npm|pnpm|yarn — skips the install with a warning instead of silently+ # using npm, so a pnpm/yarn supply-chain policy (minimumReleaseAge,+ # allowBuilds, …) is never bypassed. Yarn Berry (2+): its default PnP+ # linker writes no node_modules/.bin, so set `nodeLinker: node-modules`+ # in <HERMES_HOME>/lsp/.yarnrc.yml.package_manager: npm# How long an unused language-server client stays alive (seconds).