Skip to content

The agent that grows with you

feat(pm): per-extra platform gates — [tool.hermes.extras-platforms]

ethernet64a656408433
diff --git a/pm/extras.py b/pm/extras.py
index e157558b5a8..9a4b654ef0f 100644
--- a/pm/extras.py
+++ b/pm/extras.py
@@ -85,15 +85,86 @@ def _importable(anchor: str) -> bool:
def available(extra: str) -> bool:
- """Fast, side-effect-free: are all of this extra's anchors importable?"""
+ """Fast, side-effect-free: are all of this extra's anchors importable?
+ A platform-gated extra whose gate excludes this machine reads as
+ unavailable — the anchors are absent by design, not by accident."""
+ if not extra_supported(extra):
+ return False
return all(_importable(a) for a in _anchors(extra))
+def _platform_gates() -> dict[str, str]:
+ """The [tool.hermes.extras-platforms] table from pyproject.toml:
+ extra -> PEP 508 marker string. Cached per process."""
+ global _PLATFORM_GATES
+ if _PLATFORM_GATES is not None:
+ return _PLATFORM_GATES
+ import tomllib
+
+ from pm.paths import repo_root
+
+ gates: dict[str, str] = {}
+ try:
+ with (repo_root() / "pyproject.toml").open("rb") as f:
+ data = tomllib.load(f)
+ table = data.get("tool", {}).get("hermes", {}).get("extras-platforms", {})
+ if isinstance(table, dict):
+ gates = {str(k): str(v) for k, v in table.items()}
+ except (OSError, ValueError):
+ pass
+ _PLATFORM_GATES = gates
+ return gates
+
+
+_PLATFORM_GATES: dict[str, str] | None = None
+
+
+def extra_supported(extra: str) -> bool:
+ """Is this extra installable on THIS platform? True when the extra
+ carries no gate, or its marker matches the running platform. An
+ extra that IS present on this machine (anchors importable) is always
+ supported — an installed override beats the table (dev machines,
+ hand-synced venvs)."""
+ if all(_importable(a) for a in _anchors(extra)):
+ return True
+ marker = _platform_gates().get(extra)
+ if marker is None:
+ return True
+ import os
+ import platform
+ import sys
+
+ from packaging.markers import Marker
+
+ environment = {
+ "sys_platform": sys.platform,
+ "platform_system": platform.system(),
+ "platform_machine": platform.machine(),
+ "os_name": os.name,
+ }
+ try:
+ return bool(Marker(marker).evaluate(environment=environment))
+ except Exception:
+ # A malformed marker must never brick availability — treat as
+ # ungated and let the resolver be the authority.
+ return True
+
+
def ensure_import(extra: str) -> None:
"""Make an extra available: no-op when the anchor imports, otherwise
- sync the venv with the extra enabled. Raises InstallError on failure."""
+ sync the venv with the extra enabled. Raises InstallError on failure
+ — including when a platform gate excludes this machine."""
if available(extra):
return
+ if not extra_supported(extra):
+ from pm.package import InstallError
+
+ marker = _platform_gates().get(extra, "")
+ raise InstallError(
+ "venv",
+ f"extra {extra!r} is not supported on this platform "
+ f"(gate: {marker!r}); the adapter degrades without it",
+ )
from pm.ensure import sync_venv
sync_venv([extra])
diff --git a/pyproject.toml b/pyproject.toml
index 0610129e2e6..12c44439966 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -454,6 +454,21 @@ hermes = "hermes_cli.main:main"
hermes-agent = "run_agent:main"
hermes-acp = "acp_adapter.entry:main"
+# Per-extra platform gates (settled 2026-09-02): an extra listed here is
+# only installable on platforms matching the marker. pm consults this
+# table (pm.extras.extra_supported) — ensure_import/sync_venv refuse a
+# gated-off extra with a clear message instead of resolving it to an
+# empty set. The per-package markers inside the extra stay (uv's
+# resolver needs them for --all-extras); this table is the readable
+# single-authority for WHICH extra is supported WHERE.
+[tool.hermes.extras-platforms]
+# mautrix[encryption] → python-olm: linux-only wheels, no win/darwin build.
+matrix = "sys_platform == 'linux'"
+# grpcio (via google-cloud-pubsub) has no win_arm64 wheel.
+google-chat = "platform_machine != 'ARM64' or sys_platform != 'win32'"
+# qdrant-client → grpcio (via mem0ai) has no win_arm64 wheel.
+mem0 = "platform_machine != 'ARM64' or sys_platform != 'win32'"
+
[tool.uv]
override-dependencies = [
# discord.py's latest published version, 2.7.1, pins pynacl at <1.6. however, pynacl 1.5.0 has known vulnerabilities.
diff --git a/tests/pm/test_extras.py b/tests/pm/test_extras.py
index 717a0d8165e..d44e083aedf 100644
--- a/tests/pm/test_extras.py
+++ b/tests/pm/test_extras.py
@@ -17,6 +17,50 @@ import pm.extras as extras
ensure_mod = importlib.import_module("pm.ensure")
+# ---- per-extra platform gates ([tool.hermes.extras-platforms]) ----
+
+
+def test_extra_supported_ungated_extra_is_true():
+ extras._PLATFORM_GATES = None
+ assert extras.extra_supported("no-such-gate-for-this-one") is True
+
+
+def test_extra_supported_gate_excludes_platform(monkeypatch):
+ extras._PLATFORM_GATES = {"gated-extra": "sys_platform == 'linux'"}
+ try:
+ # On this Windows host the linux gate must read False — unless the
+ # anchors happen to be installed (installed-override beats table).
+ if sys.platform == "linux":
+ pytest.skip("host is linux — the linux gate is inclusive here")
+ assert extras.extra_supported("gated-extra") is False
+ finally:
+ extras._PLATFORM_GATES = None
+
+
+def test_extra_supported_installed_override_beats_gate(monkeypatch):
+ extras._PLATFORM_GATES = {"gated-extra": "sys_platform == 'linux'"}
+ try:
+ # anchors importable → supported even if the gate would exclude
+ monkeypatch.setitem(sys.modules, "gated_extra", SimpleNamespace())
+ assert extras.extra_supported("gated-extra") is True
+ finally:
+ extras._PLATFORM_GATES = None
+
+
+def test_ensure_import_raises_on_gated_off_extra(monkeypatch, synced):
+ extras._PLATFORM_GATES = {"gated-extra": "sys_platform == 'linux'"}
+ try:
+ if sys.platform == "linux":
+ pytest.skip("host is linux — gate is inclusive here")
+ monkeypatch.setattr(extras, "available", lambda e: False)
+ with pytest.raises(pm.InstallError) as exc:
+ extras.ensure_import("gated-extra")
+ assert "not supported on this platform" in str(exc.value)
+ assert synced == [] # never reached the venv sync
+ finally:
+ extras._PLATFORM_GATES = None
+
+
@pytest.fixture
def synced(monkeypatch):
calls: list[list[str]] = []