feat: initial MALS implementation — Phase 1

This commit is contained in:
2026-03-20 07:59:43 -05:00
commit dc1258a5cc
28 changed files with 2972 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
"""Initial schema — agent_logs table with indexes.
Revision ID: 001
Revises:
Create Date: 2026-03-20
"""
from __future__ import annotations
from alembic import op
revision = "001"
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute("""
CREATE TABLE IF NOT EXISTS agent_logs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
-- Source
agent_id VARCHAR(64) NOT NULL,
session_key VARCHAR(256),
source VARCHAR(64) NOT NULL DEFAULT 'api',
-- Classification
level VARCHAR(16) NOT NULL DEFAULT 'info',
category VARCHAR(64),
-- Content
message TEXT NOT NULL,
metadata JSONB DEFAULT '{}',
-- Correlation
trace_id UUID,
parent_id UUID REFERENCES agent_logs(id),
-- Resolution tracking
resolved BOOLEAN NOT NULL DEFAULT false,
resolved_at TIMESTAMPTZ,
resolved_by VARCHAR(64)
)
""")
op.execute("""
CREATE INDEX IF NOT EXISTS idx_agent_logs_agent_time
ON agent_logs (agent_id, created_at DESC)
""")
op.execute("""
CREATE INDEX IF NOT EXISTS idx_agent_logs_level_time
ON agent_logs (level, created_at DESC)
WHERE level IN ('warn', 'error', 'critical')
""")
op.execute("""
CREATE INDEX IF NOT EXISTS idx_agent_logs_unresolved
ON agent_logs (created_at DESC)
WHERE resolved = false AND level IN ('warn', 'error', 'critical')
""")
op.execute("""
CREATE INDEX IF NOT EXISTS idx_agent_logs_metadata
ON agent_logs USING GIN (metadata)
""")
op.execute("""
CREATE INDEX IF NOT EXISTS idx_agent_logs_trace
ON agent_logs (trace_id)
WHERE trace_id IS NOT NULL
""")
def downgrade() -> None:
op.execute("DROP TABLE IF EXISTS agent_logs CASCADE")