Skip to content

The agent that grows with you

fix(tools): resolve the Nous identity for share_auth profiles in the connector gate

brooklyn!a760186cec37
diff --git a/tests/tools/test_managed_tool_gateway.py b/tests/tools/test_managed_tool_gateway.py
index 71ac04b6bcd..1f96ed1c8ba 100644
--- a/tests/tools/test_managed_tool_gateway.py
+++ b/tests/tools/test_managed_tool_gateway.py
@@ -208,3 +208,32 @@ def test_default_bearer_gate_accepts_both_deployed_hosts_only():
"http://tool-gateway.nousresearch.com/api/vendorx/generations",
):
assert not managed_gateway_auth.is_managed_nous_gateway_url(untrusted)
+
+
+def test_read_nous_provider_state_falls_back_to_global_root_for_share_auth_profiles(tmp_path, monkeypatch):
+ # A profile created with ``share_auth`` has no auth.json of its own; it signs in with the
+ # root identity. The connector gate must see that identity, or manage_connections vanishes
+ # from the profile's tool list while every other credential reader still works.
+ root = tmp_path / ".hermes"
+ profile = root / "profiles" / "hermes-setup"
+ profile.mkdir(parents=True)
+ (root / "auth.json").write_text(json.dumps({
+ "version": 1,
+ "providers": {"nous": {"auth_method": "anonymous", "access_token": "tok"}},
+ }))
+ monkeypatch.setenv("HERMES_HOME", str(profile))
+ monkeypatch.setenv("HERMES_GUEST_ONBOARDING", "1")
+ monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
+
+ import hermes_constants
+ from hermes_cli import auth as auth_mod
+
+ monkeypatch.setattr(hermes_constants, "get_default_hermes_root", lambda: root)
+ monkeypatch.setattr(auth_mod, "get_hermes_home", lambda: profile)
+ monkeypatch.setattr(auth_mod, "_global_auth_store_cache", None)
+ monkeypatch.setattr(auth_mod, "_auth_file_path", lambda: profile / "auth.json")
+
+ state = managed_tool_gateway._read_nous_provider_state()
+
+ assert state is not None
+ assert state["auth_method"] == "anonymous"
diff --git a/tools/managed_tool_gateway.py b/tools/managed_tool_gateway.py
index 5c303c57aec..79b022decf3 100644
--- a/tools/managed_tool_gateway.py
+++ b/tools/managed_tool_gateway.py
@@ -40,13 +40,16 @@ def auth_json_path():
def _read_nous_provider_state() -> Optional[dict]:
"""The profile's Nous state, or None. A free-tier identity counts only while the free tier is on:
with ``nous.guest: false`` it is invisible here, so no cached or refreshed token of it is ever
- attached to a request."""
+ attached to a request.
+
+ Resolves through the same profile-then-global-root fallback every other credential reader
+ uses: a profile created with ``share_auth`` has no ``auth.json`` of its own and signs in with
+ the root identity. Reading only ``HERMES_HOME/auth.json`` made that profile look signed out to
+ the connector gate alone, so ``manage_connections`` vanished from its tool list."""
try:
- path = auth_json_path()
- if not path.is_file():
- return None
- providers = json.loads(path.read_text(encoding="utf-8-sig")).get("providers", {})
- nous_provider = providers.get("nous", {}) if isinstance(providers, dict) else None
+ from hermes_cli.auth import get_provider_auth_state
+
+ nous_provider = get_provider_auth_state("nous")
if not isinstance(nous_provider, dict):
return None
from hermes_cli.anon_auth import guest_enabled, is_guest_state