memory / journal.py — MemoryJournal

FIFO work queue consumed by the dream consolidator.

Storage

JSON at path/memory_journal.json; atomic temp + os.replace; threading.RLock.

Schema

[
  { "type": "post_mortem" | "failure" | str, "data": {...} },
  ...
]

API

MethodPurpose
__init__(path, max_capacity=50)Bind path, set FIFO cap.
append(item_type, data)Enqueue. Tail-evict on overflow.
pop_all() / drain()Atomically read + clear (used by dream).
push_front(items)Re-queue items at head if dream couldn't process them; preserves order, drops new appends if needed.
load()Read current journal without clearing.