@@ -24,8 +24,16 @@ CREATE TABLE IF NOT EXISTS gitmem_learnings (
2424 embedding vector(1536 ),
2525 project TEXT DEFAULT ' default' ,
2626 source_date DATE DEFAULT CURRENT_DATE ,
27+ source_linear_issue TEXT ,
28+ persona_name TEXT ,
29+ why_this_matters TEXT ,
30+ action_protocol TEXT ,
31+ self_check_criteria TEXT ,
2732 is_active BOOLEAN DEFAULT true,
2833 decay_multiplier FLOAT DEFAULT 1 .0 ,
34+ repeat_mistake BOOLEAN DEFAULT false,
35+ related_scar_id UUID,
36+ repeat_mistake_details JSONB,
2937 created_at TIMESTAMPTZ DEFAULT NOW(),
3038 updated_at TIMESTAMPTZ DEFAULT NOW()
3139);
@@ -50,9 +58,14 @@ CREATE TABLE IF NOT EXISTS gitmem_sessions (
5058 session_date DATE DEFAULT CURRENT_DATE ,
5159 agent TEXT DEFAULT ' Unknown' ,
5260 project TEXT DEFAULT ' default' ,
61+ linear_issue TEXT ,
62+ recording_path TEXT ,
63+ transcript_path TEXT ,
5364 decisions TEXT [] DEFAULT ' {}' ,
5465 open_threads TEXT [] DEFAULT ' {}' ,
5566 closing_reflection JSONB,
67+ close_compliance JSONB,
68+ rapport_summary TEXT ,
5669 embedding vector(1536 ),
5770 created_at TIMESTAMPTZ DEFAULT NOW(),
5871 updated_at TIMESTAMPTZ DEFAULT NOW()
@@ -74,6 +87,9 @@ CREATE TABLE IF NOT EXISTS gitmem_decisions (
7487 decision TEXT NOT NULL ,
7588 rationale TEXT NOT NULL ,
7689 alternatives_considered TEXT [] DEFAULT ' {}' ,
90+ personas_involved TEXT [] DEFAULT ' {}' ,
91+ docs_affected TEXT [] DEFAULT ' {}' ,
92+ linear_issue TEXT ,
7793 session_id UUID REFERENCES gitmem_sessions(id),
7894 project TEXT DEFAULT ' default' ,
7995 embedding vector(1536 ),
@@ -91,10 +107,15 @@ CREATE TABLE IF NOT EXISTS gitmem_scar_usage (
91107 scar_id UUID REFERENCES gitmem_learnings(id),
92108 session_id UUID REFERENCES gitmem_sessions(id),
93109 agent TEXT DEFAULT ' Unknown' ,
110+ issue_id TEXT ,
111+ issue_identifier TEXT ,
94112 reference_type TEXT CHECK (reference_type IN (' explicit' , ' implicit' , ' acknowledged' , ' refuted' , ' none' )),
95113 reference_context TEXT ,
96114 surfaced_at TIMESTAMPTZ ,
115+ acknowledged_at TIMESTAMPTZ ,
116+ referenced BOOLEAN ,
97117 execution_successful BOOLEAN ,
118+ variant_id UUID,
98119 created_at TIMESTAMPTZ DEFAULT NOW()
99120);
100121
@@ -104,6 +125,128 @@ CREATE INDEX IF NOT EXISTS idx_gitmem_scar_usage_scar
104125CREATE INDEX IF NOT EXISTS idx_gitmem_scar_usage_session
105126 ON gitmem_scar_usage (session_id);
106127
128+ -- ============================================================================
129+ -- Threads table (cross-session work tracking)
130+ -- ============================================================================
131+ CREATE TABLE IF NOT EXISTS gitmem_threads (
132+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
133+ thread_id TEXT NOT NULL UNIQUE,
134+ text TEXT NOT NULL ,
135+ status TEXT NOT NULL DEFAULT ' active' CHECK (status IN (' emerging' , ' active' , ' cooling' , ' dormant' , ' archived' , ' resolved' )),
136+ thread_class TEXT DEFAULT ' operational' CHECK (thread_class IN (' operational' , ' backlog' )),
137+ vitality_score FLOAT DEFAULT 1 .0 ,
138+ last_touched_at TIMESTAMPTZ DEFAULT NOW(),
139+ touch_count INT DEFAULT 1 ,
140+ resolved_at TIMESTAMPTZ ,
141+ resolution_note TEXT ,
142+ source_session UUID REFERENCES gitmem_sessions(id),
143+ resolved_by_session UUID REFERENCES gitmem_sessions(id),
144+ related_issues TEXT [] DEFAULT ' {}' ,
145+ domain TEXT [] DEFAULT ' {}' ,
146+ project TEXT DEFAULT ' default' ,
147+ metadata JSONB DEFAULT ' {}' ,
148+ embedding vector(1536 ),
149+ created_at TIMESTAMPTZ DEFAULT NOW(),
150+ updated_at TIMESTAMPTZ DEFAULT NOW()
151+ );
152+
153+ CREATE INDEX IF NOT EXISTS idx_gitmem_threads_status
154+ ON gitmem_threads (status);
155+
156+ CREATE INDEX IF NOT EXISTS idx_gitmem_threads_project
157+ ON gitmem_threads (project);
158+
159+ -- ============================================================================
160+ -- Knowledge triples (knowledge graph)
161+ -- ============================================================================
162+ CREATE TABLE IF NOT EXISTS knowledge_triples (
163+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
164+ subject TEXT NOT NULL ,
165+ predicate TEXT NOT NULL CHECK (predicate IN (' created_in' , ' influenced_by' , ' supersedes' , ' demonstrates' , ' affects_doc' , ' created_thread' , ' resolves_thread' , ' relates_to_thread' )),
166+ object TEXT NOT NULL ,
167+ event_time TIMESTAMPTZ DEFAULT NOW(),
168+ decay_weight FLOAT DEFAULT 1 .0 ,
169+ half_life_days INT DEFAULT 9999 ,
170+ decay_floor FLOAT DEFAULT 0 .1 ,
171+ source_type TEXT ,
172+ source_id UUID,
173+ source_linear_issue TEXT ,
174+ domain TEXT [] DEFAULT ' {}' ,
175+ project TEXT DEFAULT ' default' ,
176+ created_by TEXT ,
177+ created_at TIMESTAMPTZ DEFAULT NOW(),
178+ updated_at TIMESTAMPTZ DEFAULT NOW()
179+ );
180+
181+ CREATE INDEX IF NOT EXISTS idx_gitmem_triples_subject
182+ ON knowledge_triples (subject);
183+
184+ CREATE INDEX IF NOT EXISTS idx_gitmem_triples_project
185+ ON knowledge_triples (project);
186+
187+ -- ============================================================================
188+ -- Query metrics (performance tracking)
189+ -- ============================================================================
190+ CREATE TABLE IF NOT EXISTS gitmem_query_metrics (
191+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
192+ session_id UUID REFERENCES gitmem_sessions(id),
193+ agent TEXT ,
194+ tool_name TEXT NOT NULL ,
195+ query_text TEXT ,
196+ tables_searched TEXT [],
197+ latency_ms INT ,
198+ result_count INT ,
199+ similarity_scores FLOAT[],
200+ context_bytes INT ,
201+ phase_tag TEXT ,
202+ linear_issue TEXT ,
203+ memories_surfaced UUID[],
204+ metadata JSONB DEFAULT ' {}' ,
205+ created_at TIMESTAMPTZ DEFAULT NOW()
206+ );
207+
208+ -- ============================================================================
209+ -- Scar enforcement variants (A/B testing)
210+ -- ============================================================================
211+ CREATE TABLE IF NOT EXISTS scar_enforcement_variants (
212+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
213+ scar_id UUID NOT NULL REFERENCES gitmem_learnings(id),
214+ variant_type TEXT NOT NULL ,
215+ variant_config JSONB,
216+ metadata JSONB DEFAULT ' {}' ,
217+ created_at TIMESTAMPTZ DEFAULT NOW(),
218+ updated_at TIMESTAMPTZ DEFAULT NOW()
219+ );
220+
221+ -- ============================================================================
222+ -- Lite views (exclude embedding columns for reduced context)
223+ -- ============================================================================
224+ CREATE OR REPLACE VIEW gitmem_learnings_lite AS
225+ SELECT id, learning_type, title, description, severity, scar_type,
226+ counter_arguments, problem_context, solution_approach, applies_when,
227+ keywords, domain, project, source_date, source_linear_issue,
228+ persona_name, is_active, decay_multiplier, created_at, updated_at
229+ FROM gitmem_learnings;
230+
231+ CREATE OR REPLACE VIEW gitmem_sessions_lite AS
232+ SELECT id, session_title, session_date, agent, project, linear_issue,
233+ decisions, open_threads, closing_reflection, close_compliance,
234+ rapport_summary, created_at, updated_at
235+ FROM gitmem_sessions;
236+
237+ CREATE OR REPLACE VIEW gitmem_decisions_lite AS
238+ SELECT id, decision_date, title, decision, rationale,
239+ alternatives_considered, personas_involved, docs_affected,
240+ linear_issue, session_id, project, created_at
241+ FROM gitmem_decisions;
242+
243+ CREATE OR REPLACE VIEW gitmem_threads_lite AS
244+ SELECT id, thread_id, text , status, thread_class, vitality_score,
245+ last_touched_at, touch_count, resolved_at, resolution_note,
246+ source_session, resolved_by_session, related_issues, domain,
247+ project, metadata, created_at, updated_at
248+ FROM gitmem_threads;
249+
107250-- ============================================================================
108251-- Semantic search RPC function
109252-- ============================================================================
@@ -248,6 +391,10 @@ ALTER TABLE gitmem_learnings ENABLE ROW LEVEL SECURITY;
248391ALTER TABLE gitmem_sessions ENABLE ROW LEVEL SECURITY;
249392ALTER TABLE gitmem_decisions ENABLE ROW LEVEL SECURITY;
250393ALTER TABLE gitmem_scar_usage ENABLE ROW LEVEL SECURITY;
394+ ALTER TABLE gitmem_threads ENABLE ROW LEVEL SECURITY;
395+ ALTER TABLE knowledge_triples ENABLE ROW LEVEL SECURITY;
396+ ALTER TABLE gitmem_query_metrics ENABLE ROW LEVEL SECURITY;
397+ ALTER TABLE scar_enforcement_variants ENABLE ROW LEVEL SECURITY;
251398
252399-- Service role has full access (used by the MCP server)
253400CREATE POLICY " Service role full access" ON gitmem_learnings
@@ -262,6 +409,18 @@ CREATE POLICY "Service role full access" ON gitmem_decisions
262409CREATE POLICY " Service role full access" ON gitmem_scar_usage
263410 FOR ALL USING (auth .role () = ' service_role' );
264411
412+ CREATE POLICY " Service role full access" ON gitmem_threads
413+ FOR ALL USING (auth .role () = ' service_role' );
414+
415+ CREATE POLICY " Service role full access" ON knowledge_triples
416+ FOR ALL USING (auth .role () = ' service_role' );
417+
418+ CREATE POLICY " Service role full access" ON gitmem_query_metrics
419+ FOR ALL USING (auth .role () = ' service_role' );
420+
421+ CREATE POLICY " Service role full access" ON scar_enforcement_variants
422+ FOR ALL USING (auth .role () = ' service_role' );
423+
265424-- Block anonymous access
266425CREATE POLICY " Block anonymous access" ON gitmem_learnings
267426 FOR ALL USING (auth .role () != ' anon' );
@@ -275,6 +434,18 @@ CREATE POLICY "Block anonymous access" ON gitmem_decisions
275434CREATE POLICY " Block anonymous access" ON gitmem_scar_usage
276435 FOR ALL USING (auth .role () != ' anon' );
277436
437+ CREATE POLICY " Block anonymous access" ON gitmem_threads
438+ FOR ALL USING (auth .role () != ' anon' );
439+
440+ CREATE POLICY " Block anonymous access" ON knowledge_triples
441+ FOR ALL USING (auth .role () != ' anon' );
442+
443+ CREATE POLICY " Block anonymous access" ON gitmem_query_metrics
444+ FOR ALL USING (auth .role () != ' anon' );
445+
446+ CREATE POLICY " Block anonymous access" ON scar_enforcement_variants
447+ FOR ALL USING (auth .role () != ' anon' );
448+
278449-- ============================================================================
279450-- Auto-update timestamps
280451-- ============================================================================
0 commit comments