Files
accounted/supabase/migrations/20260517205000_pending_operations_agent_metadata.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

36 lines
1.5 KiB
SQL

-- Migration: pending_operations.agent_metadata — BFL audit hook for agent-staged ops
--
-- When the specialized accountant agent stages a write (categorize a
-- transaction, draft an invoice, propose a verifikation, …), we need to
-- record exactly what the model "knew" at that moment so the operation
-- is reconstructable years later under BFL 5 kap retention.
--
-- We extend the existing pending_operations table (do not invent a parallel
-- table — auditors look at one place). The new column is jsonb so the shape
-- can evolve without further migrations; the producer shape is:
--
-- {
-- "conversation_id": "<uuid>",
-- "intent_id": "transaction.categorization",
-- "model": "claude-sonnet-4-6",
-- "model_version": "<id from API response>",
-- "prompt_hash": "sha256:<hex of system prompt>",
-- "atoms_loaded": ["horizontal/swedish-vat", "vertical/konsult-it", ...],
-- "approved_by_user_id": "<uuid set on approval>"
-- }
--
-- Existing pending_operations rows have agent_metadata = NULL — only ops
-- staged by the agent loop populate it.
--
-- See dev_docs/specialized-agent-plan.md §5 (BFL audit) and §9 (chat loop).
ALTER TABLE public.pending_operations
ADD COLUMN agent_metadata jsonb;
-- Helpful for "show me everything Sonnet 4.6 staged" / per-conversation audits.
CREATE INDEX idx_pending_ops_agent_conversation
ON public.pending_operations ((agent_metadata->>'conversation_id'))
WHERE agent_metadata IS NOT NULL;
NOTIFY pgrst, 'reload schema';