File size: 1,323 Bytes
8efdc48 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | """Local, inspectable memory. Profiles are user-controlled, not hidden model training data."""
import sqlite3, json
from pathlib import Path
SCHEMA='''CREATE TABLE IF NOT EXISTS memories(id INTEGER PRIMARY KEY, kind TEXT NOT NULL, text TEXT NOT NULL, created_at TEXT DEFAULT CURRENT_TIMESTAMP, consent INTEGER NOT NULL DEFAULT 0); CREATE TABLE IF NOT EXISTS plans(id INTEGER PRIMARY KEY, title TEXT, plan_json TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'proposed', created_at TEXT DEFAULT CURRENT_TIMESTAMP);'''
class MemoryStore:
def __init__(self,path='ares.sqlite3'):self.db=sqlite3.connect(path);self.db.executescript(SCHEMA)
def add(self,kind,text,consent=False):
if not consent:raise PermissionError('Explicit user consent is required to retain memory.')
self.db.execute('INSERT INTO memories(kind,text,consent) VALUES(?,?,1)',(kind,text));self.db.commit()
def search(self,q,limit=8):return self.db.execute('SELECT id,kind,text FROM memories WHERE text LIKE ? ORDER BY id DESC LIMIT ?',('%'+q+'%',limit)).fetchall()
def propose_plan(self,title,steps):
self.db.execute('INSERT INTO plans(title,plan_json) VALUES(?,?)',(title,json.dumps({'steps':steps,'requires_approval':True})));self.db.commit()
def approve(self,id):self.db.execute("UPDATE plans SET status='approved' WHERE id=?",(id,));self.db.commit()
|