feat(memory): add JSON index and runtime memory_lookup/read/write tools

Gives Pyra an active memory brain: memory_index.json tracks summary +
keywords per file (like an inode table), and three built-in tools let
the AI look up, read, and overwrite memory mid-session. write_memory
accepts summary/keywords; update_index() merges the JSON index without
losing existing metadata.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-17 23:01:54 +02:00
parent ad024807bc
commit e56e9779ec
4 changed files with 163 additions and 7 deletions
+10 -2
View File
@@ -1,7 +1,7 @@
from pathlib import Path
from pyra.memory import _MEMORY_ROOT
from pyra.memory.index import update_index
from pyra.memory.index import update_index, update_json_entry
from pyra.security.boundaries import assert_safe_path
from pyra.utils.paths import safe_chmod
@@ -20,12 +20,20 @@ def _resolve_and_validate(name: str) -> Path:
return path
def write_memory(name: str, content: str) -> Path:
def write_memory(
name: str,
content: str,
summary: str = "",
keywords: list[str] | None = None,
) -> Path:
path = _resolve_and_validate(name)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
safe_chmod(path, 0o600)
update_index()
if summary or keywords:
rel_key = path.relative_to(_MEMORY_ROOT).as_posix()
update_json_entry(rel_key, summary, keywords or [])
return path