Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dashboard/plugin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,8 @@ def _honcho_config_payload(config: Optional[Dict[str, Any]] = None) -> Dict[str,
"_import_error": None,
}
try:
from plugins.memory.honcho.client import HonchoClientConfig, resolve_config_path # type: ignore
_honcho_client = _honcho_client_module()
HonchoClientConfig, resolve_config_path = _honcho_client.HonchoClientConfig, _honcho_client.resolve_config_path

cfg = HonchoClientConfig.from_global_config()
path = resolve_config_path()
Expand Down Expand Up @@ -1102,7 +1103,7 @@ def _honcho_payload(
base["error"] = "Honcho API key or base URL is not configured. Run 'hermes honcho setup' or set HONCHO_API_KEY / HONCHO_BASE_URL."
return base
try:
from plugins.memory.honcho.client import get_honcho_client # type: ignore
get_honcho_client = _honcho_client_module().get_honcho_client

client = get_honcho_client(cfg)
user_peer_id = str(honcho_cfg["user_peer"] or "user")
Expand Down Expand Up @@ -2009,6 +2010,15 @@ async def fetch_contents(client: Any) -> Dict[str, Any]:
return base


def _honcho_client_module() -> Any:
"""Honcho client module from whichever copy is installed (core or catalog plugin)."""
memory = importlib.import_module("plugins.memory")
resolver = getattr(memory, "import_provider_module", None)
if callable(resolver):
return resolver("honcho", "client")
return importlib.import_module("plugins.memory.honcho.client")


def _make_hindsight_provider() -> Any:
memory = importlib.import_module("plugins.memory")
resolver = getattr(memory, "import_provider_module", None)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_plugin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,38 @@ def test_honcho_payload_hides_api_key_and_fetches_peer_context(monkeypatch, tmp_
assert ("context", "hermes", {"target": "hermes", "search_query": "xraysight", "search_top_k": 5}) in calls


def test_honcho_payload_resolves_externally_installed_provider(monkeypatch, tmp_path):
"""Honcho installed as a catalog plugin is not importable as plugins.memory.honcho.

Hermes loads it under a synthetic namespace and exposes it through
plugins.memory.import_provider_module, the same resolver used for Hindsight.
"""
(tmp_path / "config.yaml").write_text("memory:\n provider: honcho\n", encoding="utf-8")
(tmp_path / "honcho.json").write_text(json.dumps({"apiKey": "honcho-secret"}), encoding="utf-8")
calls = []
install_fake_honcho_client(monkeypatch, tmp_path, calls)
external_client = sys.modules["plugins.memory.honcho.client"]
external_client.__name__ = "_hermes_user_memory.honcho__source_test.client"
monkeypatch.delitem(sys.modules, "plugins.memory.honcho")
monkeypatch.delitem(sys.modules, "plugins.memory.honcho.client")
resolved = []

def import_provider_module(name, submodule=None):
resolved.append((name, submodule))
return external_client

sys.modules["plugins.memory"].import_provider_module = import_provider_module

module = load_plugin_api(monkeypatch, tmp_path)
payload = module._honcho_payload(limit=5)

assert payload["error"] is None
assert payload["provider_configured"] is True
assert payload["user"]["card"] == ["Card fact for xraysight"]
assert ("honcho", "client") in resolved
assert "honcho-secret" not in json.dumps(payload)


def test_honcho_snapshot_and_status_include_provider_without_secrets(monkeypatch, tmp_path):
(tmp_path / "config.yaml").write_text("memory:\n provider: honcho\n", encoding="utf-8")
(tmp_path / "honcho.json").write_text(json.dumps({"apiKey": "honcho-secret"}), encoding="utf-8")
Expand Down
Loading