| # memory/database.py | |
| import sqlite3 | |
| import os | |
| # 1) Put your DB in /mnt/data so it survives rebuilds and is writable | |
| DB_DIR = "/mnt/data" | |
| DB_PATH = os.path.join(DB_DIR, "memory.db") | |
| def init_db(): | |
| """ | |
| Ensure the data directory and memory_logs table exist. | |
| """ | |
| # Make sure /mnt/data exists | |
| os.makedirs(DB_DIR, exist_ok=True) | |
| conn = sqlite3.connect(DB_PATH) | |
| c = conn.cursor() | |
| c.execute(""" | |
| CREATE TABLE IF NOT EXISTS memory_logs ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| agent TEXT, | |
| action TEXT, | |
| result TEXT, | |
| timestamp TEXT | |
| ) | |
| """) | |
| conn.commit() | |
| conn.close() | |
| def log_memory(agent: str, action: str, result: str): | |
| """ | |
| Insert a new log row into memory_logs. | |
| """ | |
| conn = sqlite3.connect(DB_PATH) | |
| c = conn.cursor() | |
| c.execute( | |
| """ | |
| INSERT INTO memory_logs (agent, action, result, timestamp) | |
| VALUES (?, ?, ?, datetime('now')) | |
| """, | |
| (agent, action, result) | |
| ) | |
| conn.commit() | |
| conn.close() | |