-- Notes an agent writes for itself and reads back later, across threads. -- -- Off unless a project turns it on, for the same reason threads are: llmgw -- stores no message content unless somebody decided it should. NULL means this -- project keeps no notes. The number is hours, and is required to turn it on, -- because a store with no expiry is a transcript kept forever by omission. ALTER TABLE projects ADD COLUMN memory_retention_hours INTEGER; CREATE TABLE memory_notes ( id INTEGER PRIMARY KEY AUTOINCREMENT, -- Scoped to a project and checked in SQL on every read, like threads. project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE, -- A namespace inside the project, so two agents sharing a key do not read -- each other's notes. agent_id TEXT NOT NULL, key TEXT NOT NULL, text TEXT NOT NULL, -- Normalised to ",a,b," so a tag matches whole, never as part of another. tags TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, -- Touched on every write, so retention measures how long a note has gone -- unrefreshed rather than how old it is. updated_at INTEGER NOT NULL, UNIQUE (project_id, agent_id, key) ); CREATE INDEX memory_notes_by_updated ON memory_notes(updated_at); -- Full-text search over the fields an agent would search by. An external -- content table, so the text is stored once. CREATE VIRTUAL TABLE memory_notes_fts USING fts5( key, text, tags, content = 'memory_notes', content_rowid = 'id' ); CREATE TRIGGER memory_notes_ai AFTER INSERT ON memory_notes BEGIN INSERT INTO memory_notes_fts(rowid, key, text, tags) VALUES (new.id, new.key, new.text, new.tags); END; CREATE TRIGGER memory_notes_ad AFTER DELETE ON memory_notes BEGIN INSERT INTO memory_notes_fts(memory_notes_fts, rowid, key, text, tags) VALUES ('delete', old.id, old.key, old.text, old.tags); END; CREATE TRIGGER memory_notes_au AFTER UPDATE ON memory_notes BEGIN INSERT INTO memory_notes_fts(memory_notes_fts, rowid, key, text, tags) VALUES ('delete', old.id, old.key, old.text, old.tags); INSERT INTO memory_notes_fts(rowid, key, text, tags) VALUES (new.id, new.key, new.text, new.tags); END;