docs/diagrams/memory-system-flow.mmd
flowchart TD A[Incoming text message or voice transcript] --> B{memory.enabled} B -- no --> N0[Skip journaling and durable retrieval] B -- yes --> C[memory.ingestMessage queue] C --> D[processIngestMessage] D --> E[Append line to memory/YYYY-MM-DD.md] E --> F[queueMemoryRefresh debounce] F --> G[refresh memory/MEMORY.md snapshot]
H[Reply / automation / voice generation] --> I[Load fact profiles for participants]
H --> J[Retrieve relevant conversation windows]
H --> K[Retrieve guidance facts<br/>always include]
H --> L[Retrieve behavioral facts<br/>only when relevant]
I --> M[Assemble prompt memory slice]
J --> M
K --> M
L --> M
N[memory_write tool] --> O[rememberDirectiveLineDetailed]
P[Session-end micro-reflection] --> O
Q[Daily reflection] --> O
O --> R[Grounding + safety checks]
R --> S[store.addMemoryFact in memory_facts]
S --> T[ensureFactVector<br/>upsert memory_fact_vectors_native]
S --> U[archiveOldFactsForSubject]
T --> F
U --> F
V[Dashboard or model durable lookup] --> W[memory.searchDurableFacts]
W --> X[Hybrid lexical + semantic ranking]
X --> Y[Return ranked durable facts]
G -. operator-facing only .-> Z[Dashboard /api/memory view]
G -. not prompt input .-> AA[Runtime prompts use SQLite-backed facts + conversation history]
