File size: 1,089 Bytes
f617fe9
 
c9c8879
95dba9d
 
f617fe9
 
 
c9c8879
 
f617fe9
 
 
 
 
 
95dba9d
df6f5ec
 
 
f617fe9
 
 
 
df6f5ec
c28b1fc
 
c9c8879
 
 
df6f5ec
f617fe9
 
 
95dba9d
df6f5ec
 
f617fe9
 
 
 
c9c8879
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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()