fix(memory): profile-scoped memory isolation and clone support (#4845)

Three fixes for memory+profile isolation bugs:

1. memory_tool.py: Replace module-level MEMORY_DIR constant with
   get_memory_dir() function that calls get_hermes_home() dynamically.
   The old constant was cached at import time and could go stale if
   HERMES_HOME changed after import. Internal MemoryStore methods now
   call get_memory_dir() directly. MEMORY_DIR kept as backward-compat
   alias.

2. profiles.py: profile create --clone now copies MEMORY.md and USER.md
   from the source profile. These curated memory files are part of the
   agent's identity (same as SOUL.md) and should carry over on clone.

3. holographic plugin: initialize() now expands $HERMES_HOME and
   ${HERMES_HOME} in the db_path config value, so users can write
   'db_path: $HERMES_HOME/memory_store.db' and it resolves to the
   active profile directory, not the default home.

Tests updated to mock get_memory_dir() alongside the legacy MEMORY_DIR.
This commit is contained in:
Teknium 2026-04-03 13:10:11 -07:00 committed by GitHub
parent 4979d77a4a
commit 8a384628a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 17 deletions

View file

@ -93,6 +93,7 @@ class TestScanMemoryContent:
def store(tmp_path, monkeypatch):
"""Create a MemoryStore with temp storage."""
monkeypatch.setattr("tools.memory_tool.MEMORY_DIR", tmp_path)
monkeypatch.setattr("tools.memory_tool.get_memory_dir", lambda: tmp_path)
s = MemoryStore(memory_char_limit=500, user_char_limit=300)
s.load_from_disk()
return s
@ -186,6 +187,7 @@ class TestMemoryStoreRemove:
class TestMemoryStorePersistence:
def test_save_and_load_roundtrip(self, tmp_path, monkeypatch):
monkeypatch.setattr("tools.memory_tool.MEMORY_DIR", tmp_path)
monkeypatch.setattr("tools.memory_tool.get_memory_dir", lambda: tmp_path)
store1 = MemoryStore()
store1.load_from_disk()
@ -199,6 +201,7 @@ class TestMemoryStorePersistence:
def test_deduplication_on_load(self, tmp_path, monkeypatch):
monkeypatch.setattr("tools.memory_tool.MEMORY_DIR", tmp_path)
monkeypatch.setattr("tools.memory_tool.get_memory_dir", lambda: tmp_path)
# Write file with duplicates
mem_file = tmp_path / "MEMORY.md"
mem_file.write_text("duplicate entry\n§\nduplicate entry\n§\nunique entry")