diff --git a/plugins/memory/honcho/cli.py b/plugins/memory/honcho/cli.py index 74412ee3d0..537b60e15d 100644 --- a/plugins/memory/honcho/cli.py +++ b/plugins/memory/honcho/cli.py @@ -1088,7 +1088,8 @@ def _seen_gateway_accounts(db_path: Path) -> list[dict]: )).fetchall() except sqlite3.OperationalError: rows = [r + (None,) for r in conn.execute(query.format(profiles_col="")).fetchall()] - except sqlite3.Error: + except sqlite3.Error as e: + print(f" (state.db unreadable: {e}; the accounts list is unavailable)", file=sys.stderr) return [] accounts = [] @@ -1196,14 +1197,13 @@ def _api_peer_detail(client, peer_id: str) -> str: def _classify_workspace_peers( peer_ids: list[str], cfg: dict, accounts: list[dict], - aliases: dict, prefix: str, + aliases: dict, prefix: str, profile_rows: list[tuple[str, str, dict]], ) -> dict[str, str]: """Label workspace peers from local config; 'unrecognized' when honest.""" labels: dict[str, str] = {} active_host = _host_key() root_peer = cfg.get("peerName") or "" - profile_rows = _all_profile_host_configs() hermes_hosts = {hostk for _, hostk, _ in profile_rows} for name, hostk, block in profile_rows: pn = block.get("peerName") or root_peer @@ -1241,10 +1241,10 @@ def _classify_workspace_peers( } -def _sibling_resolutions(cfg: dict, acct: dict) -> dict[str, str]: +def _sibling_resolutions(cfg: dict, acct: dict, profile_rows: list[tuple[str, str, dict]]) -> dict[str, str]: """Resolved peer per profile for one account (profile name → peer).""" out = {} - for name, _hostk, block in _all_profile_host_configs(): + for name, _hostk, block in profile_rows: pin, aliases, prefix, _, _ = _resolve_effective_identity_mapping(cfg, block) out[name] = _resolution_base(_preview_peer_resolution( acct["user_id"], pin=pin, aliases=aliases, prefix=prefix, @@ -1256,7 +1256,7 @@ def _sibling_resolutions(cfg: dict, acct: dict) -> dict[str, str]: def _render_peers_map_view( workspace: str, ws_peers: list[str] | None, labels: dict, - accounts: list[dict], cfg: dict, *, + accounts: list[dict], cfg: dict, profile_rows: list[tuple[str, str, dict]], *, pin: bool, working: dict, prefix: str, peer_name: str, ) -> None: if ws_peers is None: @@ -1292,7 +1292,7 @@ def _render_peers_map_view( mine = _resolution_base(resolved) marker = "" if ws_peers is None else (" ✓" if mine in known else " ○ new") diverging = { - n: v for n, v in _sibling_resolutions(cfg, acct).items() + n: v for n, v in _sibling_resolutions(cfg, acct, profile_rows).items() if n != active_profile and v != mine } div = " ≠ " + ", ".join(f"{n}→{v}" for n, v in sorted(diverging.items())) if diverging else "" @@ -1403,10 +1403,12 @@ def cmd_peers_map(args) -> None: or hermes_host.get("workspace") or cfg.get("workspace") or host ) ws_peers = _api_workspace_peers(client) + # list_profiles() parses every profile's config.yaml; one scan serves every row and re-render. + profile_rows = _all_profile_host_configs() def show() -> dict[str, str]: - labels = _classify_workspace_peers(ws_peers or [], cfg, accounts, working, prefix) - _render_peers_map_view(workspace, ws_peers, labels, accounts, cfg, + labels = _classify_workspace_peers(ws_peers or [], cfg, accounts, working, prefix, profile_rows) + _render_peers_map_view(workspace, ws_peers, labels, accounts, cfg, profile_rows, pin=pin, working=working, prefix=prefix, peer_name=peer_name) return labels diff --git a/tests/honcho_plugin/test_peers_map.py b/tests/honcho_plugin/test_peers_map.py index f6b68622f3..e2c7f6ca6a 100644 --- a/tests/honcho_plugin/test_peers_map.py +++ b/tests/honcho_plugin/test_peers_map.py @@ -284,15 +284,15 @@ class TestSaveScope: def test_classify_workspace_peers_labels_from_local_config(monkeypatch): monkeypatch.setattr(honcho_cli, "_host_key", lambda: "hermes") - monkeypatch.setattr(honcho_cli, "_all_profile_host_configs", lambda: [ + rows = [ ("default", "hermes", {"peerName": "eri", "aiPeer": "hermetika"}), ("dreamer", "hermes.dreamer", {"aiPeer": "dreamer-ai"}), - ]) + ] cfg = {"peerName": "eri", "hosts": {"claude_code": {"aiPeer": "clawd"}}} accounts = [{"platform": "telegram", "user_id": "7654321", "user_id_alt": ""}] labels = honcho_cli._classify_workspace_peers( ["eri", "hermetika", "dreamer-ai", "clawd", "7654321", "tg_7654321", "friend", "user-default-root", "meow"], - cfg, accounts, {"999": "friend"}, "tg_", + cfg, accounts, {"999": "friend"}, "tg_", rows, ) assert labels == { "eri": "your peer (peerName)",