3636 deadline REAL,
3737 checkpoint_ref TEXT,
3838 parent_decision_id TEXT,
39- timeline_id TEXT
39+ timeline_id TEXT,
40+ metadata TEXT NOT NULL DEFAULT '{}'
4041);
4142CREATE INDEX IF NOT EXISTS idx_decisions_status ON decisions(status, created_at DESC);
4243CREATE INDEX IF NOT EXISTS idx_decisions_project ON decisions(project_id, status);
4344CREATE INDEX IF NOT EXISTS idx_decisions_user ON decisions(user_id, status);
4445"""
4546
46- _JSON_FIELDS = ("options" , "answer" )
47+ _JSON_FIELDS = ("options" , "answer" , "metadata" )
4748
4849
4950def _row_to_decision (row , description ) -> dict :
@@ -57,6 +58,22 @@ def _row_to_decision(row, description) -> dict:
5758class DecisionStore (BaseStore ):
5859 SCHEMA = DECISIONS_SCHEMA
5960
61+ async def _post_init (self ) -> None :
62+ # `metadata` was added after the initial decisions ship. Guarded ALTER
63+ # so existing databases gain it without a destructive migration (SQLite
64+ # lacks ADD COLUMN IF NOT EXISTS before 3.37). Mirrors board_audit.py.
65+ cols = {
66+ row [1 ]
67+ for row in await (
68+ await self ._db .execute ("PRAGMA table_info(decisions)" )
69+ ).fetchall ()
70+ }
71+ if "metadata" not in cols :
72+ await self ._db .execute (
73+ "ALTER TABLE decisions ADD COLUMN metadata TEXT NOT NULL DEFAULT '{}'"
74+ )
75+ await self ._db .commit ()
76+
6077 async def create (
6178 self ,
6279 from_agent : str ,
@@ -72,6 +89,7 @@ async def create(
7289 parent_decision_id : str | None = None ,
7390 checkpoint_ref : str | None = None ,
7491 timeline_id : str | None = None ,
92+ metadata : dict | None = None ,
7593 ) -> dict :
7694 if type not in DECISION_TYPES :
7795 raise ValueError (f"invalid decision type: { type !r} " )
@@ -83,11 +101,12 @@ async def create(
83101 """INSERT INTO decisions
84102 (id, from_agent, project_id, user_id, question, type, options, context,
85103 priority, status, created_at, deadline, parent_decision_id,
86- checkpoint_ref, timeline_id)
87- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?, ?)""" ,
104+ checkpoint_ref, timeline_id, metadata )
105+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?, ?, ? )""" ,
88106 (did , from_agent , project_id , user_id , question , type ,
89107 json .dumps (options or []), context , priority , now , deadline ,
90- parent_decision_id , checkpoint_ref , timeline_id ),
108+ parent_decision_id , checkpoint_ref , timeline_id ,
109+ json .dumps (metadata or {})),
91110 )
92111 await self ._db .commit ()
93112 return await self .get (did )
0 commit comments