The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(pm): auto-pickup scan + legacy pip_dependencies bridge
ethernet86dee7e074a0
diff --git a/hermes_cli/memory_setup.py b/hermes_cli/memory_setup.pyindex 7931c8912a7..81957b72ef3 100644--- a/hermes_cli/memory_setup.py+++ b/hermes_cli/memory_setup.py@@ -18,17 +18,31 @@ from hermes_cli.secret_prompt import masked_secret_prompt_CANCELLED = -1-def _provider_extras(provider_name: str, manifest: dict) -> list[str]:+def _provider_extras(provider_name: str, manifest: dict, plugin_dir=None) -> list[str]:"""The pyproject extras a provider needs on THIS install.``plugin.yaml``'s ``extra:`` names the baseline. Hindsight's``local_embedded`` mode needs the daemon+embedder wheel on top(hindsight-local, #70636) — mode lives in its config file, which the- manifest can't express."""+ manifest can't express.++ A provider manifest with legacy ``pip_dependencies`` (no ``extra:``,+ no pyproject of its own — the third-party plugin shape, e.g. a+ directory-installed external provider) is bridged: pm materializes+ the specs into a generated pyproject.toml, and the provider becomes+ a workspace member installed by the venv sync. Returns [] either+ way — no EXTRA to sync, the union carries the deps."""extras = []declared = manifest.get("extra")if isinstance(declared, str) and declared:extras.append(declared)+ elif plugin_dir is not None and manifest.get("pip_dependencies"):+ try:+ from pm.workspace import materialize_legacy_pyproject++ materialize_legacy_pyproject(Path(plugin_dir))+ except Exception:+ pass# hindsight local_embedded needs hindsight-all, whose protobuf floor# conflicts with mem0/modal — it cannot be a venv extra. It stays a# provider-owned install until plugin side-venvs land (plan step 5).@@ -121,7 +135,7 @@ def _install_dependencies(provider_name: str, *, force: bool = False) -> None:except Exception:return- extras = _provider_extras(provider_name, meta)+ extras = _provider_extras(provider_name, meta, plugin_dir=plugin_dir)if not extras:returndiff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.pyindex e9a5895ae7c..fabab2bddaf 100644--- a/hermes_cli/plugins.py+++ b/hermes_cli/plugins.py@@ -807,10 +807,18 @@ def _parse_manifest_v2_fields(data: Mapping, key: str) -> Dict[str, Any]:)out["requires_plugins"] = deps- # python_dependencies — declared pip requirement strings. Validated and- # surfaced ONLY; never auto-installed (isolation design deferred).+ # python_dependencies — declared pip requirement strings, installed via+ # the pm workspace union (plugins install / pm sync). pip_dependencies+ # is the legacy key for the same thing: parsed identically, warned.pydeps: List[str] = []- raw_pydeps = data.get("python_dependencies")+ legacy_pydeps = data.get("pip_dependencies")+ if legacy_pydeps:+ logger.warning(+ "Plugin %s: 'pip_dependencies' is deprecated — declare a "+ "pyproject.toml (or 'python_dependencies') instead; the pm "+ "bridge materializes it either way", key,+ )+ raw_pydeps = data.get("python_dependencies") or legacy_pydepsif raw_pydeps is not None and not isinstance(raw_pydeps, list):logger.warning("Plugin %s: python_dependencies must be a list of requirement "@@ -5138,18 +5146,29 @@ class PluginManager:)def _warn_python_dependencies(self, manifest: PluginManifest) -> None:- """Surface declared pip dependencies (#64165).-- python_dependencies is a declaration seam ONLY: Hermes validates and- prints the requirements with an install hint but NEVER auto-installs- them. The isolation design (constraints installs vs. vendored dirs- vs. conflict-detection-and-refusal) is an explicitly deferred- follow-up — see the round-2 review on #64165 and #15220.+ """Bridge declared plugin pip deps onto the pm workspace union+ (#64165's install seam, settled 2026-09-02).++ ``python_dependencies`` (and legacy ``pip_dependencies`` — parsed+ identically) are materialized into a generated pyproject.toml in+ the plugin dir and installed by the pm venv-sync step through the+ generated workspace root: one lock, conflict = loud refusal. The+ materialization is idempotent and never runs when lazy installs+ are disabled — then this remains a presence-check with a manual+ hint (the frozen-bundle posture)."""deps = manifest.python_dependenciesif not deps:returnkey = manifest.key or manifest.name+ plugin_dir = manifest.path+ if plugin_dir:+ try:+ from pm.workspace import materialize_legacy_pyproject++ materialize_legacy_pyproject(Path(plugin_dir))+ except Exception:+ logger.debug("Plugin %s: legacy pyproject bridge failed", key, exc_info=True)missing: List[str] = []for req in deps:# Best-effort presence probe on the distribution name.@@ -5163,12 +5182,12 @@ class PluginManager:except Exception:continueif missing:- logger.warning(+ logger.info("Plugin %s declares Python dependencies that are not "- "installed: %s. Hermes does not install plugin dependencies "- "automatically; install them yourself, e.g.: pip install %s",+ "installed yet: %s. The pm venv sync installs them "+ "through the workspace union; to install now, run: "+ "hermes pm install",key, ", ".join(missing),- " ".join(f"'{m}'" for m in missing),)else:logger.debug(diff --git a/pm/workspace.py b/pm/workspace.pyindex faece715b9b..30d2d3a86bb 100644--- a/pm/workspace.py+++ b/pm/workspace.py@@ -133,6 +133,87 @@ def enabled_member_dirs() -> list[Path]:return member_dirs+def materialize_legacy_pyproject(plugin_dir: Path) -> Optional[Path]:+ """Bridge: a plugin declaring legacy ``pip_dependencies`` /+ ``python_dependencies`` in plugin.yaml, with no pyproject.toml of its+ own, gets one MATERIALIZED — the same specs, same workspace-union+ install path. Never when lazy installs are off (the sync refuses+ separately); idempotent (regenerating is a no-op when specs match)."""+ manifest = plugin_dir / "plugin.yaml"+ if not manifest.is_file():+ return None+ generated = plugin_dir / "pyproject.toml"+ if generated.is_file():+ # A USER-owned pyproject is the modern plugin shape — nothing to+ # bridge. One WE generated earlier is still bridgeable (spec+ # changes must rewrite it); the GENERATED header marks ours.+ try:+ existing = generated.read_text(encoding="utf-8-sig")+ except OSError:+ return None+ if "GENERATED by pm" not in existing:+ return None++ try:+ import re++ text = manifest.read_text(encoding="utf-8-sig")+ except OSError:+ return None++ specs: list[str] = []+ for key in ("pip_dependencies", "python_dependencies"):+ block = re.search(+ rf"^\s*{key}:\s*\n((?:[ \t]+- [^\n]+\n?)*)", text, re.MULTILINE+ )+ if not block:+ continue+ for line in block.group(1).splitlines():+ item = line.strip()+ if item.startswith("- "):+ spec = item[2:].strip().strip("'\"")+ if spec:+ specs.append(spec)++ if not specs:+ return None++ name = plugin_dir.name+ body = (+ "# GENERATED by pm from plugin.yaml pip_dependencies — the legacy\n"+ "# bridge (settled 2026-09-02). Migrate to a real pyproject.toml +\n"+ "# uv.lock; this file is rewritten when the manifest changes.\n"+ "[project]\n"+ f'name = "{name}"\n'+ 'version = "0.0.0"\n'+ 'requires-python = ">=3.11"\n'+ f'dependencies = [{", ".join(repr(s) for s in specs)}]\n'+ )+ if generated.is_file():+ try:+ if generated.read_text(encoding="utf-8-sig") == body:+ return generated # already current+ except OSError:+ pass+ generated.write_text(body, encoding="utf-8")+ return generated+++def scan_plugin(plugin_dir: Path) -> dict:+ """Auto-pickup scan of one plugin dir: which dep surfaces it declares.+ Priority (settled): pyproject (python), package.json (node sidecar),+ packages.py (pm store binaries), legacy manifest deps (bridge)."""+ found: dict = {+ "pyproject": (plugin_dir / "pyproject.toml").is_file(),+ "package_json": (plugin_dir / "package.json").is_file(),+ "packages_py": (plugin_dir / "packages.py").is_file(),+ "legacy_deps": _is_member_candidate(plugin_dir)+ and not (plugin_dir / "pyproject.toml").is_file(),+ "dir": plugin_dir,+ }+ return found++def lock_and_sync(plugin_dirs: list[Path],extras: Optional[list[str]] = None,diff --git a/tests/pm/test_workspace.py b/tests/pm/test_workspace.pyindex adf4a43aa69..8e32ecdfd50 100644--- a/tests/pm/test_workspace.py+++ b/tests/pm/test_workspace.py@@ -135,6 +135,80 @@ def test_enabled_member_dirs_finds_pyproject_and_legacy_plugins(tmp_path, monkeyassert names == {"modern-plug", "legacy-plug"}+def test_materialize_legacy_pyproject_from_pip_dependencies(tmp_path):+ plug = tmp_path / "legacy-plug"+ plug.mkdir()+ (plug / "plugin.yaml").write_text(+ "name: legacy-plug\n"+ "version: 1.0.0\n"+ "pip_dependencies:\n"+ " - \"mcp>=2,<3\"\n"+ " - 'click==8.1.7'\n",+ encoding="utf-8",+ )++ generated = ws.materialize_legacy_pyproject(plug)+ assert generated is not None and generated.is_file()+ text = generated.read_text(encoding="utf-8")+ assert "GENERATED by pm" in text+ assert 'name = "legacy-plug"' in text+ assert "'mcp>=2,<3'" in text+ assert "'click==8.1.7'" in text++ # idempotent: regenerating with same specs is byte-identical+ again = ws.materialize_legacy_pyproject(plug)+ assert again.read_text(encoding="utf-8") == text++ # spec change rewrites+ (plug / "plugin.yaml").write_text(+ "name: legacy-plug\npip_dependencies:\n - \"requests>=2\"\n",+ encoding="utf-8",+ )+ ws.materialize_legacy_pyproject(plug)+ assert "'requests>=2'" in generated.read_text(encoding="utf-8")+++def test_materialize_skips_modern_and_depless_plugins(tmp_path):+ # modern plugin: has its own pyproject — untouched+ modern = tmp_path / "modern"+ modern.mkdir()+ (modern / "pyproject.toml").write_text("[project]\n", encoding="utf-8")+ (modern / "plugin.yaml").write_text(+ "name: modern\npython_dependencies:\n - \"x\"\n", encoding="utf-8"+ )+ assert ws.materialize_legacy_pyproject(modern) is None+ assert '[project]' == (modern / "pyproject.toml").read_text(encoding="utf-8").strip()++ # dep-less plugin: nothing to bridge+ plain = tmp_path / "plain"+ plain.mkdir()+ (plain / "plugin.yaml").write_text("name: plain\n", encoding="utf-8")+ assert ws.materialize_legacy_pyproject(plain) is None++ # no manifest at all+ empty = tmp_path / "empty"+ empty.mkdir()+ assert ws.materialize_legacy_pyproject(empty) is None+++def test_scan_plugin_classifies_dep_surfaces(tmp_path):+ full = tmp_path / "full-plug"+ full.mkdir()+ for name in ("pyproject.toml", "package.json", "packages.py", "plugin.yaml"):+ (full / name).write_text("x\n", encoding="utf-8")+ scan = ws.scan_plugin(full)+ assert scan["pyproject"] and scan["package_json"] and scan["packages_py"]+ assert not scan["legacy_deps"]++ legacy = tmp_path / "legacy-plug"+ legacy.mkdir()+ (legacy / "plugin.yaml").write_text(+ "name: legacy\npip_dependencies:\n - \"x>=1\"\n", encoding="utf-8"+ )+ scan = ws.scan_plugin(legacy)+ assert scan["legacy_deps"] and not scan["pyproject"]++def test_enabled_member_dirs_survives_unreadable_roots(tmp_path, monkeypatch):# an OSError mid-scan (dangling junction etc.) must not lose other rootsgood = tmp_path / "good-plugins"