Skip to content

The agent that grows with you

refactor(honcho): compact cli helpers and provider bodies (no behavior change)

Teknium93ee1c0e388e
diff --git a/plugins/memory/honcho/__init__.py b/plugins/memory/honcho/__init__.py
index 10166bc5d99..db508e7edfe 100644
--- a/plugins/memory/honcho/__init__.py
+++ b/plugins/memory/honcho/__init__.py
@@ -1,11 +1,8 @@
"""Honcho memory plugin — MemoryProvider for Honcho AI-native memory.
Cross-session user modeling with dialectic Q&A, semantic search, peer cards and
-persistent conclusions via the Honcho SDK. Five tools (profile, search, reasoning,
-context, conclude) are exposed through the MemoryProvider interface.
-
-Config chain: $HERMES_HOME/honcho.json (profile-scoped) -> ~/.honcho/config.json
-(legacy global) -> environment variables.
+persistent conclusions; five tools (profile, search, reasoning, context, conclude).
+Config chain: $HERMES_HOME/honcho.json -> ~/.honcho/config.json -> env vars.
"""
from __future__ import annotations
@@ -22,12 +19,7 @@ from agent.memory_provider import MemoryProvider, is_trivial_prompt
from plugins.memory.honcho.client import spawn_context_thread
from plugins.memory.honcho.dialectic import DialecticMixin
from plugins.memory.honcho.tool_schemas import ( # noqa: F401 — re-exported
- ALL_TOOL_SCHEMAS,
- CONCLUDE_SCHEMA,
- CONTEXT_SCHEMA,
- PROFILE_SCHEMA,
- REASONING_SCHEMA,
- SEARCH_SCHEMA,
+ ALL_TOOL_SCHEMAS, CONCLUDE_SCHEMA, CONTEXT_SCHEMA, PROFILE_SCHEMA, REASONING_SCHEMA, SEARCH_SCHEMA,
)
from tools.registry import tool_error
@@ -119,8 +111,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
self._sync_thread: Optional[threading.Thread] = None
self._memwrite_thread: Optional[threading.Thread] = None
self._recall_mode = "hybrid" # "context", "tools", or "hybrid"
-
- # Base context cache — refreshed on context_cadence, not frozen
+ # Base context cache — refreshed on context_cadence, not frozen.
self._base_context_cache: Optional[str] = None
self._base_context_lock = threading.Lock()
@@ -135,11 +126,11 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
self._reasoning_heuristic: bool = True # scale base level by query length
self._reasoning_level_cap: str = "high" # ceiling for auto-selected level
self._last_context_turn = self._last_dialectic_turn = -999
-
- # Liveness state
- self._prefetch_thread_started_at: float = 0.0 # monotonic ts of current thread
- self._prefetch_result_fired_at: int = -999 # turn the pending result was fired at
- self._dialectic_empty_streak: int = 0 # consecutive empty returns
+ # Liveness: monotonic start of the current prefetch thread, the turn the pending
+ # result was fired at, and consecutive empty dialectic returns (drives backoff).
+ self._prefetch_thread_started_at: float = 0.0
+ self._prefetch_result_fired_at: int = -999
+ self._dialectic_empty_streak: int = 0
# Tools-only mode may defer session initialization until a tool call.
self._session_initialized = False
@@ -150,8 +141,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
# Init auth failures live here because the failed manager is discarded.
self._init_auth_failure: Optional[str] = None
self._init_auth_notice_emitted = False
- # Cron and flush contexts disable the plugin entirely.
- self._cron_skipped = False
+ self._cron_skipped = False # cron and flush contexts disable the plugin entirely
@property
def name(self) -> str:
@@ -166,7 +156,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return False
def save_config(self, values, hermes_home):
- """Write config to $HERMES_HOME/honcho.json (Honcho SDK native format)."""
+ """Merge ``values`` into $HERMES_HOME/honcho.json (Honcho SDK native format)."""
from pathlib import Path
from utils import atomic_json_write
from plugins.memory.honcho.client import _read_config
@@ -230,15 +220,12 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
# Session creation can block on Honcho/DB outages, so context/hybrid startup
# fails open in a background thread. Tools-only mode has an explicit contract:
# init_on_session_start=False stays lazy until the first tool call, True is eager.
- if self._recall_mode == "tools":
- if cfg.init_on_session_start:
- self._ensure_session()
- else:
- logger.debug("Honcho tools-only mode — deferring session init until first tool call")
- return
-
- self._start_session_init_background(wait_timeout=0.1)
-
+ if self._recall_mode != "tools":
+ self._start_session_init_background(wait_timeout=0.1)
+ elif cfg.init_on_session_start:
+ self._ensure_session()
+ else:
+ logger.debug("Honcho tools-only mode — deferring session init until first tool call")
except ImportError:
logger.debug("honcho-ai package not installed — plugin inactive")
except Exception as e:
@@ -247,15 +234,10 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
def _resolve_session_key(self, cfg, session_id: str, **kwargs) -> str:
"""Resolve the Honcho session key without touching the network."""
- return (
- cfg.resolve_session_name(
- session_title=kwargs.get("session_title"),
- session_id=session_id,
- gateway_session_key=kwargs.get("gateway_session_key"),
- )
- or session_id
- or "hermes-default"
- )
+ return cfg.resolve_session_name(
+ session_title=kwargs.get("session_title"), session_id=session_id,
+ gateway_session_key=kwargs.get("gateway_session_key"),
+ ) or session_id or "hermes-default"
def _can_start_init(self) -> bool:
return not (self._cron_skipped or self._session_initialized) and bool(self._config) and self._lazy_init_kwargs is not None
@@ -270,12 +252,6 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return self._manager is not None
try:
self._do_session_init(self._config, self._lazy_init_session_id or "hermes-default", **dict(init_kwargs))
- self._lazy_init_kwargs = None
- self._lazy_init_session_id = None
- if self._init_auth_failure is not None:
- self._init_auth_failure = None
- self._init_auth_notice_emitted = False
- return True
except Exception as e:
self._manager = None
self._session_initialized = False
@@ -285,7 +261,12 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
self._init_auth_failure = str(e)
detail = "authentication rejected"
logger.warning("Honcho %s session init failed: %s", label, detail)
- return False
+ return False
+ self._lazy_init_kwargs = self._lazy_init_session_id = None
+ if self._init_auth_failure is not None:
+ self._init_auth_failure = None
+ self._init_auth_notice_emitted = False
+ return True
def _start_session_init_background(self, *, wait_timeout: float = 0.0) -> None:
"""Start session initialization in a daemon thread so a slow/down Honcho can't
@@ -296,9 +277,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
with self._init_lock:
if not self._can_start_init() or (self._init_thread and self._init_thread.is_alive()):
return
- self._init_thread = spawn_context_thread(
- lambda: self._run_session_init("background"), name="honcho-session-init",
- )
+ self._init_thread = spawn_context_thread(lambda: self._run_session_init("background"), name="honcho-session-init")
self._init_thread.start()
if wait_timeout > 0:
self._init_thread.join(timeout=wait_timeout)
@@ -317,9 +296,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
from plugins.memory.honcho.session import HonchoSessionManager
self._manager = HonchoSessionManager(
- honcho=get_honcho_client(cfg),
- config=cfg,
- context_tokens=cfg.context_tokens,
+ honcho=get_honcho_client(cfg), config=cfg, context_tokens=cfg.context_tokens,
runtime_user_peer_name=kwargs.get("user_id") or None,
runtime_user_peer_name_alt=kwargs.get("user_id_alt") or None,
)
@@ -334,10 +311,8 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
# Per-session strategy creates a fresh Honcho session every run, so a per-run
# MEMORY.md/USER.md/SOUL.md upload would flood the backend with duplicates.
if cfg.session_strategy == "per-session":
- logger.debug(
- "Honcho memory file migration skipped: per-session strategy creates a fresh session per run (%s)",
- self._session_key,
- )
+ logger.debug("Honcho memory file migration skipped: per-session strategy creates a fresh session per run (%s)",
+ self._session_key)
elif not session.messages:
try:
from hermes_constants import get_hermes_home
@@ -350,10 +325,8 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
# which needs the first substantive user message.
if self._recall_mode in {"context", "hybrid"}:
if self._query_rewriter is None or not self._query_rewrite_enabled:
- self._spawn_dialectic(
- _PREWARM_QUERY, thread_name="honcho-prewarm-dialectic", fired_at=0,
- log_label="dialectic prewarm", use_query_rewrite=False,
- )
+ self._spawn_dialectic(_PREWARM_QUERY, thread_name="honcho-prewarm-dialectic", fired_at=0,
+ log_label="dialectic prewarm", use_query_rewrite=False)
logger.debug("Honcho dialectic prewarm started for session: %s", self._session_key)
else:
logger.debug("Honcho generic dialectic prewarm skipped: awaiting first user message")
@@ -361,17 +334,13 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
self._session_initialized = True
def _session_ready(self) -> bool:
- """Whether the manager/session key can be used safely.
-
- Background init sets ``_manager`` before get-or-create completes, so
- ``_session_initialized`` is the real guard; tests/legacy construction may inject
- a ready manager without the flag — allow that only with no init thread in flight.
- """
+ """Whether the manager/session key can be used safely. Background init sets
+ ``_manager`` before get-or-create completes, so ``_session_initialized`` is the real
+ guard; tests/legacy construction may inject a ready manager without the flag —
+ allowed only with no init thread in flight."""
if not self._manager or not self._session_key:
return False
- if self._session_initialized:
- return True
- return not (self._init_thread and self._init_thread.is_alive())
+ return self._session_initialized or not (self._init_thread and self._init_thread.is_alive())
def _writes_enabled(self) -> bool:
"""``saveMessages`` is the operator's hard write gate for every Honcho mutation path."""
@@ -389,8 +358,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
def _format_first_turn_context(self, ctx: dict) -> str:
"""Format the prefetch context dict into a readable system prompt block."""
- parts = [f"## {header}\n{ctx.get(key, '')}" for key, header in _CONTEXT_SECTIONS if ctx.get(key, "")]
- return "\n\n".join(parts)
+ return "\n\n".join(f"## {header}\n{ctx.get(key, '')}" for key, header in _CONTEXT_SECTIONS if ctx.get(key, ""))
def system_prompt_block(self) -> str:
"""Static mode header + tool instructions (prompt-cache friendly).
@@ -402,9 +370,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
def _first_turn_wait(self, base: float) -> float:
"""Turn-1 wait budget: a short request timeout may tighten, but never expand, it."""
request_timeout = getattr(self._config, "timeout", None)
- if request_timeout is not None:
- base = min(base, max(0.0, request_timeout))
- return max(0.0, base)
+ return max(0.0, base if request_timeout is None else min(base, max(0.0, request_timeout)))
def _fetch_base_context_layer(self, query: str, first_turn_base_deadline: float | None) -> str:
"""Layer 1: representation + card. The first fetch gets the remaining turn-1 budget;
@@ -479,9 +445,8 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
if self._cron_skipped or self._recall_mode == "tools":
return ""
- first_turn_base_deadline = (
- time.monotonic() + self._first_turn_wait(self._FIRST_TURN_BASE_TIMEOUT) if self._turn_count <= 1 else None
- )
+ first_turn_base_deadline = (time.monotonic() + self._first_turn_wait(self._FIRST_TURN_BASE_TIMEOUT)
+ if self._turn_count <= 1 else None)
if not self._session_ready():
# Only turn 1 may wait for session init; later turns fail open.
@@ -519,12 +484,10 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return ""
self._init_auth_notice_emitted = True
msg = self._init_auth_failure
- return (
- "[Honcho memory status] Authentication with the Honcho memory backend has expired and automatic "
- f"token refresh failed, so memory sync and recall are paused. Reason: {msg}\n"
- "Tell the user (once) that Honcho memory is paused and that running 'hermes honcho setup' "
- "to re-authenticate will restore it."
- )
+ return ("[Honcho memory status] Authentication with the Honcho memory backend has expired and automatic "
+ f"token refresh failed, so memory sync and recall are paused. Reason: {msg}\n"
+ "Tell the user (once) that Honcho memory is paused and that running 'hermes honcho setup' "
+ "to re-authenticate will restore it.")
def _truncate_to_budget(self, text: str) -> str:
"""Truncate text to the context_tokens budget (≈4 chars/token) at a word boundary."""
@@ -535,9 +498,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return text
truncated = text[:budget_chars]
last_space = truncated.rfind(" ")
- if last_space > budget_chars * 0.8:
- truncated = truncated[:last_space]
- return truncated + " …"
+ return (truncated[:last_space] if last_space > budget_chars * 0.8 else truncated) + " …"
def queue_prefetch(self, query: str, *, session_id: str = "") -> None:
"""Fire background prefetch threads for the upcoming turn.
@@ -568,16 +529,11 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
# backend doesn't retry every turn forever.
effective = self._effective_cadence()
if (self._turn_count - self._last_dialectic_turn) < effective:
- logger.debug(
- "Honcho dialectic prefetch skipped: effective cadence %d "
- "(base %d, empty streak %d), turns since last: %d",
- effective, self._dialectic_cadence, self._dialectic_empty_streak,
- self._turn_count - self._last_dialectic_turn,
- )
+ logger.debug("Honcho dialectic prefetch skipped: effective cadence %d (base %d, empty streak %d), turns since last: %d",
+ effective, self._dialectic_cadence, self._dialectic_empty_streak,
+ self._turn_count - self._last_dialectic_turn)
return
- self._spawn_dialectic(
- query, thread_name="honcho-prefetch", fired_at=self._turn_count, log_label="prefetch",
- )
+ self._spawn_dialectic(query, thread_name="honcho-prefetch", fired_at=self._turn_count, log_label="prefetch")
# Shared with the core prefetch gate so the two classifiers can never drift apart.
_is_trivial_prompt = staticmethod(is_trivial_prompt)
@@ -597,9 +553,8 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return [content]
prefix = "[continued] "
- chunks = []
- remaining = content
- first = True
+ chunks: list[str] = []
+ remaining, first = content, True
while remaining:
effective = limit if first else limit - len(prefix)
if len(remaining) <= effective:
@@ -677,10 +632,8 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
return
if not self._writes_enabled() or not self._ready_or_kick_init():
return
- self._memwrite_thread = self._spawn_write(
- lambda: self._manager.create_conclusion(self._session_key, content),
- "honcho-memwrite", "Honcho memory mirror failed: %s",
- )
+ self._memwrite_thread = self._spawn_write(lambda: self._manager.create_conclusion(self._session_key, content),
+ "honcho-memwrite", "Honcho memory mirror failed: %s")
def on_session_end(self, messages: List[Dict[str, Any]]) -> None:
"""Flush all pending messages to Honcho on session end."""
@@ -711,27 +664,19 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
cfg = self._config
reasons: List[str] = []
kind = "user" if peer == "user" else "ai"
- if cfg is not None and not (
- getattr(cfg, f"{kind}_observe_me", True) or getattr(cfg, f"{kind}_observe_others", True)
- ):
+ if cfg is not None and not (getattr(cfg, f"{kind}_observe_me", True) or getattr(cfg, f"{kind}_observe_others", True)):
reasons.append(f"observation is disabled for peer '{peer}' (user_observe_me/ai_observe_me in config)")
cadence, turn = self._dialectic_cadence, self._turn_count
if turn < max(2, cadence):
- reasons.append(
- f"this session has only {turn} turn(s); peer cards accumulate as the dialectic "
- f"layer reasons over conversation history (cadence every {cadence} turn(s))"
- )
+ reasons.append(f"this session has only {turn} turn(s); peer cards accumulate as the dialectic "
+ f"layer reasons over conversation history (cadence every {cadence} turn(s))")
if not reasons:
- reasons.append(
- "peer card has no facts yet — Honcho's dialectic layer builds this over time from "
- "observed turns; self-hosted Honcho < 3.x does not support peer cards at all"
- )
+ reasons.append("peer card has no facts yet — Honcho's dialectic layer builds this over time from "
+ "observed turns; self-hosted Honcho < 3.x does not support peer cards at all")
return {
"result": "No profile facts available yet.",
- "hint": (
- "This is not an error. " + "; ".join(reasons)
- + ". Try honcho_reasoning for a synthesized answer, or honcho_search to query raw conversation excerpts."
- ),
+ "hint": ("This is not an error. " + "; ".join(reasons)
+ + ". Try honcho_reasoning for a synthesized answer, or honcho_search to query raw conversation excerpts."),
}
def _tool_profile(self, args: dict) -> str:
@@ -752,9 +697,7 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
if not query:
return tool_error("Missing required parameter: query")
max_tokens = min(int(args.get("max_tokens", 800)), 2000)
- result = self._manager.search_context(
- self._session_key, query, max_tokens=max_tokens, peer=args.get("peer", "user"),
- )
+ result = self._manager.search_context(self._session_key, query, max_tokens=max_tokens, peer=args.get("peer", "user"))
return json.dumps({"result": result or "No relevant context found."})
def _tool_reasoning(self, args: dict) -> str:
@@ -764,14 +707,11 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
if not query:
return tool_error("Missing required parameter: query")
try:
+ # Explicit reasoning bypasses the automatic-injection cap, and surfaces
+ # timeouts/server errors as errors rather than an indistinguishable "no result".
result = self._manager.dialectic_query(
- self._session_key, query,
- reasoning_level=args.get("reasoning_level"),
- peer=args.get("peer", "user"),
- # Explicit reasoning bypasses the automatic-injection cap, and surfaces
- # timeouts/server errors as errors rather than an indistinguishable "no result".
- apply_injection_cap=False,
- raise_errors=True,
+ self._session_key, query, reasoning_level=args.get("reasoning_level"),
+ peer=args.get("peer", "user"), apply_injection_cap=False, raise_errors=True,
)
except HonchoAuthError:
raise # rendered by handle_tool_call's auth-specific handler
@@ -791,11 +731,9 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
ctx = self._manager.get_session_context(self._session_key, peer=args.get("peer", "user"))
if not ctx:
return json.dumps({"result": "No context available yet."})
- parts = [
- f"## {header}\n{ctx[key]}"
- for key, header in (("summary", "Summary"), ("representation", "Representation"), ("card", "Card"))
- if ctx.get(key)
- ]
+ parts = [f"## {header}\n{ctx[key]}"
+ for key, header in (("summary", "Summary"), ("representation", "Representation"), ("card", "Card"))
+ if ctx.get(key)]
if ctx.get("recent_messages"):
msg_str = "\n".join(f" [{m['role']}] {m['content'][:200]}" for m in ctx["recent_messages"][-5:])
parts.append(f"## Recent messages\n{msg_str}")
@@ -881,6 +819,4 @@ def register(ctx) -> None:
"""Register Honcho as a memory provider plugin."""
from plugins.memory.query_rewrite import rewrite_memory_query
- ctx.register_memory_provider(
- HonchoMemoryProvider(query_rewriter=rewrite_memory_query)
- )
+ ctx.register_memory_provider(HonchoMemoryProvider(query_rewriter=rewrite_memory_query))
diff --git a/plugins/memory/honcho/cli.py b/plugins/memory/honcho/cli.py
index 4303fe84d59..0612d4fbc1e 100644
--- a/plugins/memory/honcho/cli.py
+++ b/plugins/memory/honcho/cli.py
@@ -1,7 +1,4 @@
-"""CLI commands for Honcho integration management.
-
-Handles: hermes honcho setup | status | sessions | map | peer
-"""
+"""``hermes honcho`` subcommands: setup wizard, status, peers, sessions, identity, migrate."""
from __future__ import annotations
@@ -29,6 +26,9 @@ _CLONE_KEYS = _INHERITED_KEYS[:3] + ("sessionPeerPrefix",) + _INHERITED_KEYS[3:]
"pinUserPeer", "userPeerAliases", "runtimePeerPrefix",
)
_IDENTITY_MAPPING_KEYS = ("pinPeerName", "pinUserPeer", "userPeerAliases", "runtimePeerPrefix")
+# Setup-wizard answer -> identity-mapping shape ("2"/pooled answers are handled inline).
+_SHAPE_CHOICES = {"1": "single", "me": "single", "just-me": "single", "3": "multi", "others": "multi",
+ "e": "raw", "edit": "raw", "raw": "raw"}
_MODES = {
"hybrid": "auto-injected context + Honcho tools available (default)",
"context": "auto-injected context only, Honcho tools hidden",
@@ -48,33 +48,27 @@ _profile_override: str | None = None
def _host_key() -> str:
- """Return the active Honcho host key, derived from the current Hermes profile."""
+ """Active Honcho host key (``--target-profile`` override, else the active profile)."""
if _profile_override:
- if _profile_override in {"default", "custom"}:
- return HOST
- return profile_host_key(_profile_override)
+ return HOST if _profile_override in {"default", "custom"} else profile_host_key(_profile_override)
return resolve_active_host()
def _config_path() -> Path:
- """Return the active Honcho config path for reading (instance-local or global)."""
+ """Active Honcho config path for reading (instance-local, default profile, or global)."""
return resolve_config_path()
def _local_config_path() -> Path:
- """Instance-local write path ($HERMES_HOME/honcho.json). The global
- ~/.honcho/config.json is only a read fallback for cross-app interop."""
+ """Instance-local write path; ~/.honcho/config.json is only a read fallback for cross-app interop."""
return get_hermes_home() / "honcho.json"
def _read_config() -> dict:
- path = _config_path()
- if path.exists():
- try:
- return json.loads(path.read_text(encoding="utf-8"))
- except Exception:
- pass
- return {}
+ try:
+ return json.loads(_config_path().read_text(encoding="utf-8"))
+ except Exception:
+ return {}
def _write_config(cfg: dict, path: Path | None = None) -> None:
@@ -115,18 +109,15 @@ def _save(cfg: dict) -> None:
def _default_block_and_key(cfg: dict) -> tuple[dict, bool]:
"""(default host block, whether an API key is configured at root or env)."""
- default_block = cfg_get(cfg, "hosts", HOST, default={})
- has_key = bool(cfg.get("apiKey") or os.environ.get("HONCHO_API_KEY"))
- return default_block, has_key
+ return cfg_get(cfg, "hosts", HOST, default={}), bool(cfg.get("apiKey") or os.environ.get("HONCHO_API_KEY"))
def _resolve_api_key(cfg: dict) -> str:
- """Resolve API key with host -> root -> env fallback. A self-hosted ``baseUrl``
- without a key yields ``"local"`` so credential guards accept it: the URL is
- scheme-validated (http/https) so ``baseUrl: true`` can't pass, while schemeless
- host:port shapes (legacy ``localhost:8000``) still pass — the SDK rejects them."""
- host_key = _host_block(cfg, _host_key()).get("apiKey")
- key = host_key or cfg.get("apiKey", "") or os.environ.get("HONCHO_API_KEY", "")
+ """API key with host -> root -> env fallback. A self-hosted ``baseUrl`` without a key
+ yields ``"local"`` so credential guards accept it: the URL must be http/https (so
+ ``baseUrl: true`` can't pass) or a schemeless host:port (legacy ``localhost:8000``;
+ the SDK rejects those itself)."""
+ key = _host_block(cfg, _host_key()).get("apiKey") or cfg.get("apiKey", "") or os.environ.get("HONCHO_API_KEY", "")
if key:
return key
base_url = (cfg.get("baseUrl") or cfg.get("base_url") or os.environ.get("HONCHO_BASE_URL", "") or "").strip()
@@ -164,7 +155,7 @@ def _yes(answer: str) -> bool:
# ── Honcho connection ──────────────────────────────────────────────────────
def _connect(host: str | None, *, reset: bool = False):
- """(hcfg, client) for ``host``; imports are lazy so tests can patch client.*."""
+ """(hcfg, client) for ``host``; lazy imports so tests can patch client.*."""
from plugins.memory.honcho.client import HonchoClientConfig, get_honcho_client, reset_honcho_client
if reset:
reset_honcho_client()
@@ -260,9 +251,7 @@ def _sync_profiles(verbose: bool) -> int:
return 0
created = skipped = 0
- for p in profiles:
- if p.name == "default":
- continue
+ for p in (p for p in profiles if p.name != "default"):
if clone_honcho_for_profile(p.name):
say(f" + {p.name} -> {profile_host_key(p.name)}")
created += 1
@@ -328,12 +317,9 @@ def _resolve_effective_identity_mapping(cfg: dict, hermes_host: dict) -> tuple[b
host, mirroring ``HonchoClientConfig.from_global_config`` precedence (root-level
overrides; ``pinUserPeer`` beats ``pinPeerName``) so setup classifies the shape
the gateway actually runs with. ``*_from_root`` lets writes skip inherited values."""
- pin = False
- for val in (hermes_host.get("pinUserPeer"), hermes_host.get("pinPeerName"),
- cfg.get("pinUserPeer"), cfg.get("pinPeerName")):
- if val is not None:
- pin = bool(val)
- break
+ pin_sources = (hermes_host.get("pinUserPeer"), hermes_host.get("pinPeerName"),
+ cfg.get("pinUserPeer"), cfg.get("pinPeerName"))
+ pin = bool(next((v for v in pin_sources if v is not None), False))
def _inherit(key):
if key in hermes_host:
@@ -470,8 +456,7 @@ def _setup_identity_mapping(cfg: dict, hermes_host: dict, current_peer: str) ->
pooled = _prompt(" Keep my own memory pooled across platforms? (Y/n)", default="y").strip().lower()
shape = "hybrid" if pooled in {"y", "yes", ""} else "multi"
else:
- shape = {"1": "single", "me": "single", "just-me": "single", "3": "multi", "others": "multi",
- "e": "raw", "edit": "raw", "raw": "raw"}.get(choice, "skip")
+ shape = _SHAPE_CHOICES.get(choice, "skip")
# Un-pinning without aliasing strands the pooled peerName history; steer toward pooling.
if current_pin and shape == "multi":
@@ -534,10 +519,8 @@ def _ensure_sdk_installed() -> bool:
if result.ok:
print(" Installed.\n")
return True
- if result.blocked:
- print(f" Cannot install: {result.reason}\n")
- else:
- print(f" Install failed:\n{(result.stderr or '').strip()}\n Run manually: uv pip install 'honcho-ai==2.2.0'\n")
+ print(f" Cannot install: {result.reason}\n" if result.blocked else
+ f" Install failed:\n{(result.stderr or '').strip()}\n Run manually: uv pip install 'honcho-ai==2.2.0'\n")
return False
@@ -681,8 +664,8 @@ def _setup_cloud_auth(cfg: dict, hermes_host: dict, write_path: Path) -> bool:
default_method = "device"
else:
print(" (no usable local browser detected — browser sign-in may need an SSH tunnel to 127.0.0.1:8765)")
- prompt_label = "oauth, device, or apikey?" if device_available else "OAuth or API key?"
- method = _prompt(prompt_label, default=default_method).strip().lower()
+ method = _prompt("oauth, device, or apikey?" if device_available else "OAuth or API key?",
+ default=default_method).strip().lower()
if device_available and method in {"device", "d"}:
return _setup_device_login(hermes_host, write_path, open_browser=can_browse and not is_remote)
@@ -988,8 +971,7 @@ def _show_peer_cards(hcfg, client) -> None:
card = mgr.get_peer_card(session_key)
if card:
print(f"\n User peer card ({len(card)} facts):")
- for fact in card[:10]:
- print(f" - {fact}")
+ print("\n".join(f" - {fact}" for fact in card[:10]))
if len(card) > 10:
print(f" ... and {len(card) - 10} more")
ai_text = mgr.get_ai_representation(session_key).get("representation", "")
@@ -1053,8 +1035,7 @@ def cmd_sessions(args) -> None:
def cmd_map(args) -> None:
"""Map current directory to a Honcho session name."""
if not args.session_name:
- cmd_sessions(args)
- return
+ return cmd_sessions(args)
session_name = args.session_name.strip()
if not session_name:
print(" Session name cannot be empty.\n")
@@ -1076,10 +1057,7 @@ def cmd_map(args) -> None:
def cmd_peer(args) -> None:
"""Show or update peer names and dialectic reasoning level."""
cfg = _read_config()
- user_name = getattr(args, "user", None)
- ai_name = getattr(args, "ai", None)
- reasoning = getattr(args, "reasoning", None)
-
+ user_name, ai_name, reasoning = (getattr(args, k, None) for k in ("user", "ai", "reasoning"))
if user_name is None and ai_name is None and reasoning is None:
hermes = _active_block(cfg)
print(f"""
@@ -1102,8 +1080,7 @@ Honcho peers
_set_field(cfg, "aiPeer", ai_name.strip(), f"AI peer -> {ai_name.strip()}")
if reasoning is not None:
if reasoning not in REASONING_LEVELS:
- print(f" Invalid reasoning level '{reasoning}'. Options: {', '.join(REASONING_LEVELS)}")
- return
+ return print(f" Invalid reasoning level '{reasoning}'. Options: {', '.join(REASONING_LEVELS)}")
_set_field(cfg, "dialecticReasoningLevel", reasoning, f"Dialectic reasoning level -> {reasoning}")
_save(cfg)
@@ -1144,8 +1121,7 @@ def cmd_strategy(args) -> None:
def cmd_tokens(args) -> None:
"""Show or set token budget settings."""
cfg = _read_config()
- context = getattr(args, "context", None)
- dialectic = getattr(args, "dialectic", None)
+ context, dialectic = getattr(args, "context", None), getattr(args, "dialectic", None)
if context is None and dialectic is None:
hermes = _active_block(cfg)
print(f"""
@@ -1198,11 +1174,8 @@ def cmd_identity(args) -> None:
print(f" Honcho authentication failed: {e}\n")
return
print(f"\nUser peer ({hcfg.peer_name or 'not set'})\n" + RULE)
- if user_card:
- for fact in user_card:
- print(f" {fact}")
- else:
- print(" No user peer card yet. Send a few messages to build one.")
+ print("\n".join(f" {fact}" for fact in user_card) if user_card
+ else " No user peer card yet. Send a few messages to build one.")
print(f"\nAI peer ({hcfg.ai_peer})\n" + RULE)
print(ai_rep.get("representation") or ai_rep.get("card")
or " No representation built yet.\n Run 'hermes honcho identity <file>' to seed one.")
@@ -1223,12 +1196,10 @@ Honcho identity management
p = Path(file_path).expanduser()
if not p.exists():
- print(f" File not found: {p}\n")
- return
+ return print(f" File not found: {p}\n")
content = p.read_text(encoding="utf-8").strip()
if not content:
- print(f" File is empty: {p}\n")
- return
+ return print(f" File is empty: {p}\n")
if mgr.seed_ai_identity(session_key, content, source=p.name):
print(f" Seeded AI peer identity from {p.name} into session '{session_key}'\n"
f" Honcho will incorporate this into {hcfg.ai_peer}'s representation over time.\n")
@@ -1309,14 +1280,11 @@ Step 1 Create a Honcho account
print("\nStep 2 Detected OpenClaw memory files\n")
if user_files or agent_files:
- if user_files:
- print(f" User memory ({len(user_files)} file(s)) — will go to Honcho user peer:")
- for f in user_files:
- print(f" {f}")
- if agent_files:
- print(f" Agent identity ({len(agent_files)} file(s)) — will go to Honcho AI peer:")
- for f in agent_files:
- print(f" {f}")
+ for files, label in ((user_files, "User memory"), (agent_files, "Agent identity")):
+ if files:
+ peer = "user" if files is user_files else "AI"
+ print(f" {label} ({len(files)} file(s)) — will go to Honcho {peer} peer:")
+ print("\n".join(f" {f}" for f in files))
else:
print(" No OpenClaw native memory files found in cwd or ~/.openclaw/.\n"
" If your files are elsewhere, copy them here before continuing,\n"
@@ -1365,8 +1333,7 @@ Step 4 Seed AI identity files → Honcho AI peer
_offer(" Seed AI identity from all detected files now?", _migrate_seed, agent_files)
else:
print(" Run 'hermes honcho setup' first, then seed manually:")
- for f in agent_files:
- print(f" hermes honcho identity {f}")
+ print("\n".join(f" hermes honcho identity {f}" for f in agent_files))
else:
print(" No agent identity files detected.\n To seed manually: hermes honcho identity <path/to/SOUL.md>")