/**
 * Database Schema Definitions
 *
 * SQLite schema for code-buddy persistent storage including:
 * - Memories with vector embeddings
 * - Session history with costs
 * - Code embeddings for semantic search
 * - Tool statistics and learning
 * - Analytics and cost tracking
 */
export declare const SCHEMA_VERSION = 1;
export declare const SCHEMA_SQL = "\n-- Schema version tracking\nCREATE TABLE IF NOT EXISTS schema_version (\n  version INTEGER PRIMARY KEY,\n  applied_at TEXT DEFAULT CURRENT_TIMESTAMP\n);\n\n-- ============================================================================\n-- MEMORIES TABLE\n-- Stores persistent memories with embeddings for semantic search\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS memories (\n  id TEXT PRIMARY KEY,\n  type TEXT NOT NULL CHECK(type IN ('fact', 'preference', 'pattern', 'decision', 'context', 'summary', 'instruction', 'error', 'definition', 'convention')),\n  scope TEXT NOT NULL CHECK(scope IN ('user', 'project')),\n  project_id TEXT,\n  content TEXT NOT NULL,\n  embedding BLOB,  -- Float32Array as binary\n  importance REAL DEFAULT 0.5 CHECK(importance >= 0 AND importance <= 1),\n  access_count INTEGER DEFAULT 0,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  last_accessed TEXT DEFAULT CURRENT_TIMESTAMP,\n  expires_at TEXT,\n  metadata TEXT,  -- JSON for additional data\n  UNIQUE(scope, project_id, content)\n);\n\nCREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);\nCREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope, project_id);\nCREATE INDEX IF NOT EXISTS idx_memories_importance ON memories(importance DESC);\nCREATE INDEX IF NOT EXISTS idx_memories_last_accessed ON memories(last_accessed DESC);\n\n-- ============================================================================\n-- SESSIONS TABLE\n-- Stores conversation sessions with full history\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS sessions (\n  id TEXT PRIMARY KEY,\n  project_id TEXT,\n  project_path TEXT,\n  name TEXT,\n  model TEXT,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  updated_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  total_tokens_in INTEGER DEFAULT 0,\n  total_tokens_out INTEGER DEFAULT 0,\n  total_cost REAL DEFAULT 0,\n  message_count INTEGER DEFAULT 0,\n  tool_calls_count INTEGER DEFAULT 0,\n  is_archived INTEGER DEFAULT 0,\n  metadata TEXT  -- JSON\n);\n\nCREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project_id);\nCREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions(updated_at DESC);\n\n-- ============================================================================\n-- MESSAGES TABLE\n-- Individual messages within sessions\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS messages (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,\n  role TEXT NOT NULL CHECK(role IN ('user', 'assistant', 'system', 'tool')),\n  content TEXT,\n  tool_calls TEXT,  -- JSON array of tool calls\n  tool_call_id TEXT,\n  tokens INTEGER DEFAULT 0,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  metadata TEXT  -- JSON\n);\n\nCREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);\n\n-- ============================================================================\n-- CODE EMBEDDINGS TABLE\n-- Vector embeddings for code chunks\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS code_embeddings (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  project_id TEXT NOT NULL,\n  file_path TEXT NOT NULL,\n  chunk_index INTEGER NOT NULL,\n  chunk_text TEXT NOT NULL,\n  chunk_hash TEXT NOT NULL,\n  embedding BLOB NOT NULL,  -- Float32Array as binary\n  symbol_type TEXT,  -- function, class, interface, etc.\n  symbol_name TEXT,\n  start_line INTEGER,\n  end_line INTEGER,\n  language TEXT,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  updated_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  UNIQUE(project_id, file_path, chunk_index)\n);\n\nCREATE INDEX IF NOT EXISTS idx_code_embeddings_project ON code_embeddings(project_id);\nCREATE INDEX IF NOT EXISTS idx_code_embeddings_file ON code_embeddings(project_id, file_path);\nCREATE INDEX IF NOT EXISTS idx_code_embeddings_symbol ON code_embeddings(symbol_type, symbol_name);\n\n-- ============================================================================\n-- TOOL STATISTICS TABLE\n-- Tracks tool usage, success rates, and performance\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS tool_stats (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  tool_name TEXT NOT NULL,\n  project_id TEXT,\n  success_count INTEGER DEFAULT 0,\n  failure_count INTEGER DEFAULT 0,\n  total_time_ms INTEGER DEFAULT 0,\n  avg_time_ms REAL GENERATED ALWAYS AS (\n    CASE WHEN (success_count + failure_count) > 0\n    THEN total_time_ms * 1.0 / (success_count + failure_count)\n    ELSE 0 END\n  ) STORED,\n  cache_hits INTEGER DEFAULT 0,\n  cache_misses INTEGER DEFAULT 0,\n  last_used TEXT DEFAULT CURRENT_TIMESTAMP,\n  updated_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  UNIQUE(tool_name, project_id)\n);\n\nCREATE INDEX IF NOT EXISTS idx_tool_stats_name ON tool_stats(tool_name);\n\n-- ============================================================================\n-- REPAIR LEARNING TABLE\n-- Stores what repair strategies work for which error patterns\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS repair_learning (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  error_pattern TEXT NOT NULL,  -- Normalized error message pattern\n  error_type TEXT NOT NULL CHECK(error_type IN ('compile', 'runtime', 'test', 'lint', 'type')),\n  strategy TEXT NOT NULL,\n  context_hash TEXT,  -- Hash of surrounding code context\n  language TEXT,\n  framework TEXT,\n  success_count INTEGER DEFAULT 0,\n  failure_count INTEGER DEFAULT 0,\n  success_rate REAL GENERATED ALWAYS AS (\n    CASE WHEN (success_count + failure_count) > 0\n    THEN success_count * 1.0 / (success_count + failure_count)\n    ELSE 0 END\n  ) STORED,\n  avg_attempts REAL DEFAULT 1,\n  last_used TEXT DEFAULT CURRENT_TIMESTAMP,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  examples TEXT,  -- JSON array of successful fix examples\n  UNIQUE(error_pattern, strategy, context_hash)\n);\n\nCREATE INDEX IF NOT EXISTS idx_repair_learning_pattern ON repair_learning(error_pattern);\nCREATE INDEX IF NOT EXISTS idx_repair_learning_success ON repair_learning(success_rate DESC);\n\n-- ============================================================================\n-- ANALYTICS TABLE\n-- Daily aggregated usage statistics\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS analytics (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  date TEXT NOT NULL,\n  project_id TEXT,\n  model TEXT,\n  tokens_in INTEGER DEFAULT 0,\n  tokens_out INTEGER DEFAULT 0,\n  cost REAL DEFAULT 0,\n  requests INTEGER DEFAULT 0,\n  tool_calls INTEGER DEFAULT 0,\n  errors INTEGER DEFAULT 0,\n  avg_response_time_ms REAL DEFAULT 0,\n  cache_hit_rate REAL DEFAULT 0,\n  session_count INTEGER DEFAULT 0,\n  UNIQUE(date, project_id, model)\n);\n\nCREATE INDEX IF NOT EXISTS idx_analytics_date ON analytics(date DESC);\nCREATE INDEX IF NOT EXISTS idx_analytics_project ON analytics(project_id, date DESC);\n\n-- ============================================================================\n-- CONVENTIONS TABLE\n-- Learned coding conventions per project\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS conventions (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  project_id TEXT NOT NULL,\n  category TEXT NOT NULL,  -- naming, structure, style, testing, docs\n  pattern TEXT NOT NULL,\n  description TEXT,\n  confidence REAL DEFAULT 0.5 CHECK(confidence >= 0 AND confidence <= 1),\n  occurrences INTEGER DEFAULT 1,\n  examples TEXT,  -- JSON array of examples\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  updated_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  UNIQUE(project_id, category, pattern)\n);\n\nCREATE INDEX IF NOT EXISTS idx_conventions_project ON conventions(project_id);\nCREATE INDEX IF NOT EXISTS idx_conventions_confidence ON conventions(confidence DESC);\n\n-- ============================================================================\n-- CHECKPOINTS TABLE\n-- File checkpoints for undo/restore\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS checkpoints (\n  id TEXT PRIMARY KEY,\n  project_id TEXT NOT NULL,\n  description TEXT,\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  file_count INTEGER DEFAULT 0,\n  total_size INTEGER DEFAULT 0,\n  metadata TEXT  -- JSON\n);\n\nCREATE INDEX IF NOT EXISTS idx_checkpoints_project ON checkpoints(project_id, created_at DESC);\n\n-- ============================================================================\n-- CHECKPOINT FILES TABLE\n-- Individual file snapshots\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS checkpoint_files (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  checkpoint_id TEXT NOT NULL REFERENCES checkpoints(id) ON DELETE CASCADE,\n  file_path TEXT NOT NULL,\n  content TEXT,\n  content_hash TEXT,\n  existed INTEGER DEFAULT 1,\n  UNIQUE(checkpoint_id, file_path)\n);\n\nCREATE INDEX IF NOT EXISTS idx_checkpoint_files_checkpoint ON checkpoint_files(checkpoint_id);\n\n-- ============================================================================\n-- CACHE TABLE\n-- General-purpose cache with TTL\n-- ============================================================================\nCREATE TABLE IF NOT EXISTS cache (\n  key TEXT PRIMARY KEY,\n  value TEXT NOT NULL,\n  embedding BLOB,  -- Optional embedding for semantic cache\n  created_at TEXT DEFAULT CURRENT_TIMESTAMP,\n  expires_at TEXT,\n  hits INTEGER DEFAULT 0,\n  category TEXT  -- api, tool, search, etc.\n);\n\nCREATE INDEX IF NOT EXISTS idx_cache_expires ON cache(expires_at);\nCREATE INDEX IF NOT EXISTS idx_cache_category ON cache(category);\n";
export declare const MIGRATIONS: Record<number, string>;
export interface Memory {
    id: string;
    type: MemoryType;
    scope: 'user' | 'project';
    project_id?: string;
    content: string;
    embedding?: Float32Array;
    importance: number;
    access_count: number;
    created_at: string;
    last_accessed: string;
    expires_at?: string;
    metadata?: Record<string, unknown>;
}
export type MemoryType = 'fact' | 'preference' | 'pattern' | 'decision' | 'context' | 'summary' | 'instruction' | 'error' | 'definition' | 'convention';
export interface Session {
    id: string;
    project_id?: string;
    project_path?: string;
    name?: string;
    model?: string;
    created_at: string;
    updated_at: string;
    total_tokens_in: number;
    total_tokens_out: number;
    total_cost: number;
    message_count: number;
    tool_calls_count: number;
    is_archived: boolean;
    metadata?: Record<string, unknown>;
}
export interface Message {
    id?: number;
    session_id: string;
    role: 'user' | 'assistant' | 'system' | 'tool';
    content?: string;
    tool_calls?: unknown[];
    tool_call_id?: string;
    tokens?: number;
    created_at?: string;
    metadata?: Record<string, unknown>;
}
export interface CodeEmbedding {
    id?: number;
    project_id: string;
    file_path: string;
    chunk_index: number;
    chunk_text: string;
    chunk_hash: string;
    embedding: Float32Array;
    symbol_type?: string;
    symbol_name?: string;
    start_line?: number;
    end_line?: number;
    language?: string;
    created_at?: string;
    updated_at?: string;
}
export interface ToolStats {
    id?: number;
    tool_name: string;
    project_id?: string;
    success_count: number;
    failure_count: number;
    total_time_ms: number;
    avg_time_ms: number;
    cache_hits: number;
    cache_misses: number;
    last_used: string;
    updated_at: string;
}
export interface RepairLearning {
    id?: number;
    error_pattern: string;
    error_type: 'compile' | 'runtime' | 'test' | 'lint' | 'type';
    strategy: string;
    context_hash?: string;
    language?: string;
    framework?: string;
    success_count: number;
    failure_count: number;
    success_rate: number;
    avg_attempts: number;
    last_used: string;
    created_at: string;
    examples?: string[];
}
export interface Analytics {
    id?: number;
    date: string;
    project_id?: string;
    model?: string;
    tokens_in: number;
    tokens_out: number;
    cost: number;
    requests: number;
    tool_calls: number;
    errors: number;
    avg_response_time_ms: number;
    cache_hit_rate: number;
    session_count: number;
}
export interface Convention {
    id?: number;
    project_id: string;
    category: string;
    pattern: string;
    description?: string;
    confidence: number;
    occurrences: number;
    examples?: string[];
    created_at?: string;
    updated_at?: string;
}
export interface Checkpoint {
    id: string;
    project_id: string;
    description?: string;
    created_at: string;
    file_count: number;
    total_size: number;
    metadata?: Record<string, unknown>;
}
export interface CheckpointFile {
    id?: number;
    checkpoint_id: string;
    file_path: string;
    content?: string;
    content_hash?: string;
    existed: boolean;
}
