The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): no dependency consent for a pyproject that installs nothing
Teknium6f5955553692
diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 0eff3ec5851..5c0423a5ade 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -90,7 +90,7 @@ def _install_plugin_python_deps(deps = declaration.install_requirementsexcept Exception as exc:return False, _ConsentRefusal(f"invalid Python dependency declaration: {exc}", "manifest_invalid")- has_python = declaration.is_member+ has_python = declaration.installs_packageshas_package_json = (target / "package.json").is_file()if not has_python and not has_package_json:return True, None # no declared deps at alldiff --git a/hermes_cli/plugins_transaction.py b/hermes_cli/plugins_transaction.pyindex bbb5df4038f..fed4f0ca3a3 100644--- a/hermes_cli/plugins_transaction.py+++ b/hermes_cli/plugins_transaction.py@@ -76,7 +76,7 @@ def _refresh_declared_dependencies(target: Path, staged: Path, manifest: dict, *return # a disabled plugin's deps are admitted (and consented) by `hermes plugins enable`before, after = read_python_declaration(target), read_python_declaration(staged)added = tuple(spec for spec in after.install_requirements if spec not in before.install_requirements)- if not added and not (after.is_member and not before.is_member):+ if not added and not (after.installs_packages and not before.installs_packages):returnif not interactive:raise pc.PluginOperationError(diff --git a/pm/plugin_declarations.py b/pm/plugin_declarations.pyindex 210cabe36b2..2434bcb8974 100644--- a/pm/plugin_declarations.py+++ b/pm/plugin_declarations.py@@ -58,6 +58,9 @@ class PythonDeclaration:requirements: tuple[str, ...]manifest: dictrequires_python: str | None = None+ # The pyproject itself installs something: the plugin as a package, or extras/dependency groups+ # (``uv sync --all-packages`` installs a member's default groups as well as its dependencies).+ pyproject_installs: bool = False@propertydef external(self) -> bool:@@ -67,6 +70,12 @@ class PythonDeclaration:def install_requirements(self) -> tuple[str, ...]:return () if self.external else applicable_requirements(self.requirements)+ @property+ def installs_packages(self) -> bool:+ """Admission would put packages into the shared environment, the thing dependency consent+ is about. ``dependencies = []`` installs nothing, so it asks no more than no pyproject does."""+ return not self.external and (bool(self.install_requirements) or self.pyproject_installs)+@propertydef is_member(self) -> bool:return not self.external and (self.pyproject is not None or bool(self.install_requirements))@@ -144,7 +153,12 @@ def read_python_declaration(plugin_dir: Path) -> PythonDeclaration:requires_python = document.get("project", {}).get("requires-python")if requires_python is not None and not isinstance(requires_python, str):raise ValueError(f"invalid project.requires-python: {project}")- return PythonDeclaration(tuple(files), project, tuple(specs), manifest, requires_python)+ uv = document.get("tool", {}).get("uv", {})+ installs = ("build-system" in document or uv.get("package") is True+ or any(document.get("project", {}).get("optional-dependencies", {}).values())+ or any(document.get("dependency-groups", {}).values())+ or bool(uv.get("dev-dependencies")))+ return PythonDeclaration(tuple(files), project, tuple(specs), manifest, requires_python, installs)specs = []for key in ("pip_dependencies", "python_dependencies"):values = manifest.get(key, [])diff --git a/tests/hermes_cli/test_plugin_dependency_consent.py b/tests/hermes_cli/test_plugin_dependency_consent.pyindex 8ca46f3060a..7d78ce9b34b 100644--- a/tests/hermes_cli/test_plugin_dependency_consent.py+++ b/tests/hermes_cli/test_plugin_dependency_consent.py@@ -23,7 +23,8 @@ def test_install_only_requests_relevant_python_consent(admission_env, monkeypatc(source / 'package.json').write_text(json.dumps({'name': 'sidecar-plugin', 'version': '1.0.0'}), encoding='utf-8')if python_surface == 'pyproject':(source / 'pyproject.toml').write_text(- '[project]\nname="sidecar-plugin"\nversion="1.0"\nrequires-python=">=3.14"\n', encoding='utf-8')+ '[project]\nname="sidecar-plugin"\nversion="1.0"\nrequires-python=">=3.14"\n'+ 'dependencies=["never-install-without-consent==1"]\n', encoding='utf-8')env = {k: v for k, v in os.environ.items() if k not in {'GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE'}}for args in [('init', '-q'), ('add', '.'), ('-c', 'user.name=test', '-c', '[email protected]', 'commit', '-qm', 'fixture')]:subprocess.run(['git', *args], cwd=source, env=env, check=True, capture_output=True, timeout=30)@@ -45,6 +46,30 @@ def test_install_only_requests_relevant_python_consent(admission_env, monkeypatcassert 'dependency install skipped (non-interactive)' in output+def test_empty_python_dependencies_install_and_enable_without_consent(admission_env, monkeypatch, capsys): # health: allow F811 -- pytest injects the imported admission_env fixture by parameter name+ """``dependencies = []`` installs nothing, so a headless ``install --enable`` enables the plugin+ exactly like one without a pyproject instead of refusing at an empty consent question."""+ root, home = admission_env+ source = root / 'plugin-source'+ source.mkdir()+ (source / 'plugin.yaml').write_text(yaml.safe_dump({'name': 'no-deps-plugin'}), encoding='utf-8')+ (source / '__init__.py').write_text('def register(ctx):\n pass\n', encoding='utf-8')+ (source / 'pyproject.toml').write_text(+ '[project]\nname="no-deps-plugin"\nversion="1.0"\nrequires-python=">=3.11"\ndependencies=[]\n',+ encoding='utf-8')+ env = {k: v for k, v in os.environ.items() if k not in {'GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE'}}+ for args in [('init', '-q'), ('add', '.'), ('-c', 'user.name=test', '-c', '[email protected]', 'commit', '-qm', 'fixture')]:+ subprocess.run(['git', *args], cwd=source, env=env, check=True, capture_output=True, timeout=30)+ monkeypatch.setattr(plugins_cmd.sys.stdin, 'isatty', lambda: False)++ plugins_cmd.cmd_install(source.as_uri(), enable=True, allow_removed=True)++ enabled = yaml.safe_load((home / 'config.yaml').read_text(encoding='utf-8'))['plugins']['enabled']+ output = capsys.readouterr().out+ assert 'no-deps-plugin' in enabled, 'install completed but the plugin was not enabled; CLI output:\n' + output+ assert 'declares Python dependencies' not in output++def test_node_sidecar_question_stays_independent(tmp_path, monkeypatch):from pm import workspace@@ -119,6 +144,12 @@ def test_dashboard_install_publishes_a_plugin_the_config_already_selects(admissiresult = plugins_cmd.dashboard_install_plugin(source.as_uri(), force=False, enable=True)assert result['ok'], resultassert (home / 'plugins' / 'mem-twin' / 'plugin.yaml').is_file()+ # The forced replacement now declares a dependency: installing it is what the veto guards.+ (source / 'pyproject.toml').write_text(+ '[project]\nname="mem-twin"\nversion="1.1"\nrequires-python=">=3.11"\n'+ 'dependencies=["never-install-without-consent==1"]\n', encoding='utf-8')+ subprocess.run(['git', '-c', 'user.name=test', '-c', '[email protected]', 'commit', '-qam', 'deps'],+ cwd=source, env=env, check=True, capture_output=True, timeout=30)again = plugins_cmd.dashboard_install_plugin(source.as_uri(), force=True, enable=True)assert not again['ok'] and 'Reinstall declined' in again['error']@@ -135,7 +166,8 @@ def test_publish_assume_consent_skips_replacement_veto(tmp_path, monkeypatch):target.mkdir()(staged / 'plugin.yaml').write_text(yaml.safe_dump({'name': 'active-plugin'}), encoding='utf-8')(staged / 'pyproject.toml').write_text(- '[project]\nname="active-plugin"\nversion="1.0"\nrequires-python=">=3.11"\n', encoding='utf-8')+ '[project]\nname="active-plugin"\nversion="1.0"\nrequires-python=">=3.11"\n'+ 'dependencies=["never-install-without-consent==1"]\n', encoding='utf-8')monkeypatch.setattr(ws, 'enabled_plugin_dirs', lambda **kwargs: [target])syncs = []monkeypatch.setattr('pm.client.sync_venv', lambda **kwargs: syncs.append(kwargs))diff --git a/tests/pm/test_plugin_declarations.py b/tests/pm/test_plugin_declarations.pyindex 43d5230819c..f72ea653855 100644--- a/tests/pm/test_plugin_declarations.py+++ b/tests/pm/test_plugin_declarations.py@@ -98,3 +98,19 @@ def test_invalid_requirement_refused_at_declaration_boundary(tmp_path, modern):with pytest.raises(ValueError):read_python_declaration(tmp_path)assert path.read_bytes() == before++[email protected](("body", "installs"), [+ ("dependencies = []\n", False),+ ('dependencies = ["fixturedep>=1,<2"]\n', True),+ ('dependencies = []\n[build-system]\nrequires = ["setuptools"]\nbuild-backend = "setuptools.build_meta"\n', True),+ ('dependencies = []\n[dependency-groups]\ndev = ["fixturedep"]\n', True),+ ('dependencies = []\n[project.optional-dependencies]\nextra = ["fixturedep"]\n', True),+], ids=["empty", "dependencies", "buildable", "dependency-groups", "extras"])+def test_only_a_pyproject_that_installs_something_needs_dependency_consent(tmp_path, body, installs):+ """``dependencies = []`` puts nothing in the environment; a buildable plugin, extras and dependency+ groups (``uv sync --all-packages`` installs a member's default groups) still do."""+ (tmp_path / "plugin.yaml").write_text("name: probe\n", encoding="utf-8")+ (tmp_path / "pyproject.toml").write_text(+ '[project]\nname = "probe"\nversion = "1"\n' + body, encoding="utf-8")+ assert read_python_declaration(tmp_path).installs_packages is installs