scripts: use capnp store instead of reading markdown directly

Add store_helpers.py with shared helpers that call poc-memory commands
(list-keys, render, journal-tail) instead of globbing ~/.claude/memory/*.md
and parsing section headers.

All 9 Python scripts updated: get_semantic_keys(), get_topic_file_index(),
get_recent_journal(), parse_journal_entries(), read_journal_range(),
collect_topic_stems(), and file preview rendering now go through the store.

This completes the clean switch — no script reads archived markdown files.
This commit is contained in:
ProofOfConcept 2026-02-28 23:32:47 -05:00
parent f20ea4f827
commit d14710e477
10 changed files with 324 additions and 297 deletions

View file

@ -81,17 +81,9 @@ def get_health() -> dict:
def get_topic_file_index() -> dict[str, list[str]]:
"""Build index of topic files and their section headers."""
index = {}
for md in sorted(MEMORY_DIR.glob("*.md")):
name = md.name
headers = []
for line in md.read_text().split('\n'):
if line.startswith('## '):
slug = re.sub(r'[^a-z0-9-]', '', line[3:].lower().replace(' ', '-'))
headers.append(slug)
index[name] = headers
return index
"""Build index of topic files and their section headers from the store."""
from store_helpers import get_topic_file_index as _get_index
return _get_index()
def get_graph_structure() -> str:
@ -123,12 +115,14 @@ def build_crosslink_prompt(round_num: int) -> str:
graph = get_graph_structure()
status = get_status()
# Read a sample of files for context
# Read a sample of files from the store
from store_helpers import render as _render
file_previews = ""
for f in sorted(MEMORY_DIR.glob("*.md"))[:30]:
content = f.read_text()
preview = '\n'.join(content.split('\n')[:8])[:400]
file_previews += f"\n--- {f.name} ---\n{preview}\n"
for fname in sorted(index.keys())[:30]:
content = _render(fname)
if content:
preview = '\n'.join(content.split('\n')[:8])[:400]
file_previews += f"\n--- {fname} ---\n{preview}\n"
return f"""You are a cross-link discovery agent (round {round_num}).
@ -210,13 +204,13 @@ Output ONLY the JSON array."""
def build_newfile_prompt(round_num: int) -> str:
"""Build prompt for connecting the new split files."""
# Read the new reflection files
# Read the new reflection files from the store
from store_helpers import render as _render
new_files = {}
for name in ['reflections-reading.md', 'reflections-dreams.md', 'reflections-zoom.md',
'verus-proofs.md']:
path = MEMORY_DIR / name
if path.exists():
content = path.read_text()
content = _render(name)
if content:
new_files[name] = content[:2000]
# Read existing files they should connect to
@ -224,9 +218,8 @@ def build_newfile_prompt(round_num: int) -> str:
for name in ['differentiation.md', 'cognitive-modes.md', 'language-theory.md',
'discoveries.md', 'inner-life.md', 'design-context-window.md',
'design-consolidate.md', 'experiments-on-self.md']:
path = MEMORY_DIR / name
if path.exists():
content = path.read_text()
content = _render(name)
if content:
target_files[name] = content[:1500]
graph = get_graph_structure()