Skip to content

The agent that grows with you

refactor(memory): compact retaindb queue bootstrap/overlay and byterover config loader/schemas

Teknium38a5c8672993
diff --git a/plugins/memory/byterover/__init__.py b/plugins/memory/byterover/__init__.py
index 54f741fad1a..f40dfd43c1c 100644
--- a/plugins/memory/byterover/__init__.py
+++ b/plugins/memory/byterover/__init__.py
@@ -41,15 +41,13 @@ def _load_plugin_config() -> Dict[str, Any]:
"""Read ``memory.byterover``; fall back to legacy ``memory.provider_config`` (early docs used it)."""
try:
from hermes_cli.config import load_config
-
memory_config = load_config().get("memory", {})
- if isinstance(memory_config, dict):
- for key in ("byterover", "provider_config"):
- block = memory_config.get(key, {})
- if isinstance(block, dict) and (block or key == "provider_config"):
- return dict(block)
except Exception:
- pass
+ return {}
+ for key in ("byterover", "provider_config") if isinstance(memory_config, dict) else ():
+ block = memory_config.get(key, {})
+ if isinstance(block, dict) and (block or key == "provider_config"):
+ return dict(block)
return {}
@@ -112,16 +110,13 @@ def _schema(name: str, description: str, arg: str = "", arg_desc: str = "") -> d
QUERY_SCHEMA = _schema(
- "brv_query",
- "Search ByteRover's persistent knowledge tree for relevant context. Returns memories, project knowledge, "
+ "brv_query", "Search ByteRover's persistent knowledge tree for relevant context. Returns memories, project knowledge, "
"architectural decisions, and patterns from previous sessions. Use for any question where past context would help.",
"query", "What to search for.")
CURATE_SCHEMA = _schema(
- "brv_curate",
- "Store important information in ByteRover's persistent knowledge tree. Use for architectural decisions, bug fixes, "
+ "brv_curate", "Store important information in ByteRover's persistent knowledge tree. Use for architectural decisions, bug fixes, "
"user preferences, project patterns — anything worth remembering across sessions. ByteRover's LLM automatically "
- "categorizes and organizes the memory.",
- "content", "The information to remember.")
+ "categorizes and organizes the memory.", "content", "The information to remember.")
STATUS_SCHEMA = _schema("brv_status", "Check ByteRover status — CLI version, context tree stats, cloud sync state.")
@@ -158,12 +153,8 @@ class ByteRoverMemoryProvider(MemoryProvider):
def system_prompt_block(self) -> str:
if not _resolve_brv_path():
return ""
- return (
- "# ByteRover Memory\n"
- "Active. Persistent knowledge tree with hierarchical context.\n"
- "Use brv_query to search past knowledge, brv_curate to store "
- "important facts, brv_status to check state."
- )
+ return ("# ByteRover Memory\nActive. Persistent knowledge tree with hierarchical context.\n"
+ "Use brv_query to search past knowledge, brv_curate to store important facts, brv_status to check state.")
def _query(self, query: str) -> dict:
return _run_brv(["query", "--", query.strip()[:5000]], timeout=_QUERY_TIMEOUT, cwd=self._cwd)
diff --git a/plugins/memory/retaindb/__init__.py b/plugins/memory/retaindb/__init__.py
index 9d6e7a73cc7..41a36990adc 100644
--- a/plugins/memory/retaindb/__init__.py
+++ b/plugins/memory/retaindb/__init__.py
@@ -126,8 +126,7 @@ class _Client:
def _raw(self, method: str, path: str, **kwargs) -> Any:
"""Non-JSON request (multipart upload / binary download); raises on HTTP error."""
resp = self._http(method, path, json_body=False, **kwargs)
- resp.raise_for_status()
- return resp
+ return resp.raise_for_status() or resp
@staticmethod
def _with_fallback(primary: Callable[[], dict], fallback: Callable[[], dict]) -> dict:
@@ -195,14 +194,11 @@ class _WriteQueue:
self._local = threading.local() # one cached connection per thread, all tracked in _connections
self._connections: set[sqlite3.Connection] = set()
self._connections_lock, self._shutdown_lock, self._shutdown = threading.Lock(), threading.Lock(), False
- conn = self._execute(
- "CREATE TABLE IF NOT EXISTS pending (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT, "
- "session_id TEXT, messages_json TEXT, created_at TEXT, last_error TEXT)"
- ).connection
+ conn = self._execute("CREATE TABLE IF NOT EXISTS pending (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT, "
+ "session_id TEXT, messages_json TEXT, created_at TEXT, last_error TEXT)").connection
self._thread.start()
- for row_id, user_id, session_id, msgs_json in conn.execute( # replay rows left from a previous crash
- "SELECT id, user_id, session_id, messages_json FROM pending ORDER BY id ASC LIMIT 200"
- ).fetchall():
+ replay = conn.execute("SELECT id, user_id, session_id, messages_json FROM pending ORDER BY id ASC LIMIT 200").fetchall()
+ for row_id, user_id, session_id, msgs_json in replay: # rows left from a previous crash
self._q.put((row_id, user_id, session_id, json.loads(msgs_json)))
def _get_conn(self) -> sqlite3.Connection:
@@ -293,14 +289,11 @@ def _build_overlay(profile: dict, query_result: dict, local_entries: list[str] |
out.append(c)
return out
- profile_items = _dedupe((profile or {}).get("memories"))
- query_items = _dedupe((query_result or {}).get("results"))
+ profile_items, query_items = _dedupe((profile or {}).get("memories")), _dedupe((query_result or {}).get("results"))
if not profile_items and not query_items:
return ""
- return "\n".join(
- ["[RetainDB Context]", "Profile:"] + ([f"- {i}" for i in profile_items] or ["- None"])
- + ["Relevant memories:"] + ([f"- {i}" for i in query_items] or ["- None"])
- )
+ return "\n".join(["[RetainDB Context]", "Profile:"] + ([f"- {i}" for i in profile_items] or ["- None"])
+ + ["Relevant memories:"] + ([f"- {i}" for i in query_items] or ["- None"]))
# Agent self-model keys -> prefetch line formatter, in display order.
@@ -361,11 +354,8 @@ class RetainDBMemoryProvider(MemoryProvider):
def system_prompt_block(self) -> str:
project = self._client.project if self._client else "retaindb"
- return (
- f"# RetainDB Memory\nActive. Project: {project}.\n"
- "Use retaindb_search to find memories, retaindb_remember to store facts, "
- "retaindb_profile for a user overview, retaindb_context for current-task context."
- )
+ return (f"# RetainDB Memory\nActive. Project: {project}.\nUse retaindb_search to find memories, retaindb_remember to store facts, "
+ "retaindb_profile for a user overview, retaindb_context for current-task context.")
# Background prefetch (fires at turn-end, consumed next turn-start)