Memory: two files, no database
Thegan keeps durable facts across /new and process restarts without adding a dependency, without letting the context window grow, and without letting the always-injected layer drift. The whole thing is two plain files and one extra model call at the right moments.
Two tiers
| Tier | File | Visibility |
|---|---|---|
| core | core.md — curated, small | Injected into the system prompt every turn |
| log | log.jsonl — append-only, capped | Pulled in on demand via the memory tool |
Both formats are human-readable on purpose: you can cat, grep and edit them. Hand edits to core.md take effect on the next turn.
Three distillation points
The conversation lives in RAM and dies with the process, so there are exactly three moments where it can still be mined:
- Compaction — when the token threshold is crossed, the replaced span is distilled.
/new— the dropped history is distilled in the background, so the reply is instant./new forgetleaves no trace.- Shutdown — on SIGTERM or SIGINT the current history is distilled before exit.
Curation keeps the core small
The core is never rewritten inline. Distillation and /promote stage suggestions in core.proposed.md; an hourly systemd timer runs thegan --curate, which makes one model call to produce a fresh, deduplicated profile under the byte budget and writes it atomically. When nothing is staged it exits before any model call, so it costs nothing.
Bounds and failure modes
- Oversized profiles are truncated with a visible marker; a turn never fails because of it.
- The log rotates into
log.1.jsonl; pinned entries are kept. - Missing or corrupt files are treated as empty or skipped.
- All read-modify-write access runs under an exclusive file lock with atomic replace.
- Model-written memory is fenced as data, not instructions. Set
THEGAN_CURATE_AUTO=0to add an/approvecheckpoint.
Why not embeddings?
For a personal assistant with a few thousand entries, ranked multi-term substring search plus a curated core is enough — and it needs no extra service, stays inspectable, and can be replaced with a single rm.