feat(B-0423): memory/ reindexer — heap→stack MEMORY.md promotion (Aaron 2026-05-12)#2787
Conversation
Implements the architectural fix from B-0423 backlog item: the MEMORY.md serialization-point anti-pattern. What it does: - Scans memory/*.md, parses frontmatter from every file - Sorts by created date (newest first) - Renders top-100 as stack entries in MEMORY.md - Acknowledges remaining N as heap (accessible by direct path) - Idempotent via --check mode How it composes with the architecture: - Memory files commit without synchronous MEMORY.md paired-edit (eliminates serialization point) - This tool runs on cadence (callable from autonomous-loop) to keep MEMORY.md current without blocking commits - Stack/heap framing in preamble tells readers what they're looking at — newest-N indexed, rest browsable by path Aaron 2026-05-12 architectural input: - "memory.md for me is like stack and floating memories not yet in there but with recent timestamps are heap both easily accesable" - "also lets your autodream do the reindexing" - "but needs to run more often than anthorpic alows on theri base" The autonomous-loop cron (firing every minute) is the high-cadence mechanism. AutoDream-via-autonomous-loop is the architectural fix; this tool is the implementation. Test coverage: - parseFrontmatter handles simple key:value, folded scalars, quoted strings, missing frontmatter Initial run on current state: 1060 memory files, top-100 indexed, 960 acknowledged as heap. Composes with feedback_aaron_thousand_brains_theory_match... (four-property substrate test — this tool's design is lock-free / wait-free / weight-free / DST-compatible). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a Bun/TypeScript reindexer to regenerate memory/MEMORY.md from the memory/ heap (B-0423), with --check support and initial unit tests for frontmatter parsing.
Changes:
- Introduces
tools/memory/reindex-memory-md.tsto scanmemory/*.md, sort by date, and render a truncated “stack” index intomemory/MEMORY.md. - Adds
--checkmode for idempotency validation (exit 2 when stale). - Adds
bun:testcoverage forparseFrontmatter().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tools/memory/reindex-memory-md.ts | New CLI tool to rebuild memory/MEMORY.md from memory-file frontmatter. |
| tools/memory/reindex-memory-md.test.ts | Unit tests for the frontmatter parser used by the reindexer. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc1c00019a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const MAX_STACK_ENTRIES = 100; | ||
|
|
||
| function renderIndex(entries: MemoryEntry[]): string { | ||
| const now = new Date().toISOString().slice(0, 10); |
There was a problem hiding this comment.
Remove wall-clock date from deterministic index rendering
renderIndex embeds new Date().toISOString().slice(0, 10) into the generated file, so --check will flip to STALE whenever the UTC date changes even if no memory entries changed. That breaks the stated idempotent-check behavior and forces daily churn commits unrelated to actual index drift; the rendered content should be derived from repository state, not wall-clock time.
Useful? React with 👍 / 👎.
| const date = fm.created || dateFromFilename(filename); | ||
| entries.push({ filename, fm, date, mtime: 0 }); | ||
| } | ||
| entries.sort((a, b) => b.date.localeCompare(a.date)); |
There was a problem hiding this comment.
Add deterministic tie-breaker for same-date entries
The sort compares only date, but many memory files can share the same date, so equal-date ordering falls back to readdir() order. Because directory enumeration order is not guaranteed across environments, two runs can emit different MEMORY.md ordering for the same inputs, creating noisy diffs and false --check failures. Add a stable secondary key (for example, filename) when dates are equal.
Useful? React with 👍 / 👎.
Summary
Implements the architectural fix from B-0423: the MEMORY.md
serialization-point anti-pattern.
Aaron 2026-05-12 architectural input:
What the tool does
Architectural composition
Eliminates the MEMORY.md serialization-point. Memory files can
commit without synchronous MEMORY.md paired-edit. This tool catches
the index up on cadence via the autonomous-loop cron.
Matches the 4-property substrate test (scale-free / lock-free /
weight-free / DST).
Initial run
Test plan
🤖 Generated with Claude Code