/** * Database Schema * * SQLite + sqlite-vec schema for AI context storage. * Supports vector embeddings, knowledge graph, and sync state. */ export declare const SCHEMA_VERSION = "1.6.0"; /** * Core database schema SQL */ export declare const SCHEMA_SQL = "\n-- Schema version tracking\nCREATE TABLE IF NOT EXISTS schema_version (\n version TEXT PRIMARY KEY,\n applied_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- Core context storage\nCREATE TABLE IF NOT EXISTS context_items (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL CHECK (type IN ('workflow', 'agent', 'command', 'code', 'commit', 'knowledge', 'config', 'doc', 'tool_config')),\n name TEXT NOT NULL,\n content TEXT NOT NULL,\n metadata JSON,\n file_path TEXT,\n content_hash TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- Indexes for context_items\nCREATE INDEX IF NOT EXISTS idx_context_items_type ON context_items(type);\nCREATE INDEX IF NOT EXISTS idx_context_items_name ON context_items(name);\nCREATE INDEX IF NOT EXISTS idx_context_items_file_path ON context_items(file_path);\nCREATE INDEX IF NOT EXISTS idx_context_items_content_hash ON context_items(content_hash);\n\n-- Knowledge graph with typed relations\nCREATE TABLE IF NOT EXISTS knowledge_graph (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n source_id TEXT NOT NULL,\n target_id TEXT NOT NULL,\n relation_type TEXT NOT NULL CHECK (relation_type IN (\n 'uses', 'implements', 'depends_on', 'references', 'tests',\n 'documents', 'extends', 'contains', 'calls', 'imports',\n 'configures', 'authenticates', 'validates', 'transforms'\n )),\n weight REAL DEFAULT 1.0,\n metadata JSON,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n FOREIGN KEY (source_id) REFERENCES context_items(id) ON DELETE CASCADE,\n FOREIGN KEY (target_id) REFERENCES context_items(id) ON DELETE CASCADE,\n UNIQUE(source_id, target_id, relation_type)\n);\n\n-- Indexes for knowledge_graph\nCREATE INDEX IF NOT EXISTS idx_kg_source ON knowledge_graph(source_id);\nCREATE INDEX IF NOT EXISTS idx_kg_target ON knowledge_graph(target_id);\nCREATE INDEX IF NOT EXISTS idx_kg_relation ON knowledge_graph(relation_type);\n\n-- Git commits tracking\nCREATE TABLE IF NOT EXISTS git_commits (\n sha TEXT PRIMARY KEY,\n message TEXT NOT NULL,\n author_name TEXT,\n author_email TEXT,\n timestamp TEXT NOT NULL,\n files_changed JSON,\n stats JSON,\n created_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- Indexes for git_commits\nCREATE INDEX IF NOT EXISTS idx_git_commits_timestamp ON git_commits(timestamp);\nCREATE INDEX IF NOT EXISTS idx_git_commits_author ON git_commits(author_email);\n\n-- AI tool configurations (claude, cline, copilot, etc.)\nCREATE TABLE IF NOT EXISTS ai_tool_configs (\n id TEXT PRIMARY KEY,\n tool_name TEXT NOT NULL,\n config_path TEXT NOT NULL,\n content TEXT NOT NULL,\n content_hash TEXT,\n last_sync TEXT NOT NULL DEFAULT (datetime('now')),\n status TEXT DEFAULT 'synced' CHECK (status IN ('synced', 'pending', 'conflict', 'error')),\n metadata JSON\n);\n\n-- Indexes for ai_tool_configs\nCREATE INDEX IF NOT EXISTS idx_ai_tool_configs_tool ON ai_tool_configs(tool_name);\nCREATE INDEX IF NOT EXISTS idx_ai_tool_configs_status ON ai_tool_configs(status);\n\n-- Sync state for shadow file generation and tool sync\nCREATE TABLE IF NOT EXISTS sync_state (\n id TEXT PRIMARY KEY,\n tool TEXT NOT NULL,\n content_hash TEXT,\n last_sync TEXT NOT NULL DEFAULT (datetime('now')),\n file_path TEXT,\n status TEXT DEFAULT 'synced' CHECK (status IN ('synced', 'pending', 'conflict', 'error')),\n metadata JSON,\n k0ntext_version TEXT,\n user_modified INTEGER DEFAULT 0,\n last_checked TEXT\n);\n\n-- Indexes for sync_state\nCREATE INDEX IF NOT EXISTS idx_sync_state_tool ON sync_state(tool);\nCREATE INDEX IF NOT EXISTS idx_sync_state_status ON sync_state(status);\nCREATE INDEX IF NOT EXISTS idx_sync_state_version ON sync_state(k0ntext_version);\nCREATE INDEX IF NOT EXISTS idx_sync_state_user_modified ON sync_state(user_modified);\n\n-- Generated files tracking for modification detection and backup management\nCREATE TABLE IF NOT EXISTS generated_files (\n id TEXT PRIMARY KEY,\n tool TEXT NOT NULL,\n file_path TEXT NOT NULL,\n content_hash TEXT NOT NULL,\n backup_path TEXT,\n generated_at TEXT NOT NULL DEFAULT (datetime('now')),\n last_verified_at TEXT,\n user_modified INTEGER DEFAULT 0,\n metadata JSON\n);\n\n-- Indexes for generated_files\nCREATE INDEX IF NOT EXISTS idx_generated_files_tool ON generated_files(tool);\nCREATE INDEX IF NOT EXISTS idx_generated_files_hash ON generated_files(content_hash);\nCREATE INDEX IF NOT EXISTS idx_generated_files_path ON generated_files(file_path);\n\n-- Embedding queue for async processing\nCREATE TABLE IF NOT EXISTS embedding_queue (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n context_id TEXT NOT NULL,\n status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'completed', 'failed')),\n error_message TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n processed_at TEXT,\n FOREIGN KEY (context_id) REFERENCES context_items(id) ON DELETE CASCADE\n);\n\n-- Index for embedding_queue\nCREATE INDEX IF NOT EXISTS idx_embedding_queue_status ON embedding_queue(status);\n\n-- Analytics and usage tracking\nCREATE TABLE IF NOT EXISTS usage_analytics (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n query TEXT,\n tool_name TEXT,\n result_count INTEGER,\n latency_ms INTEGER,\n timestamp TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- Index for analytics\nCREATE INDEX IF NOT EXISTS idx_analytics_timestamp ON usage_analytics(timestamp);\nCREATE INDEX IF NOT EXISTS idx_analytics_tool ON usage_analytics(tool_name);\n\n-- Performance metrics tracking\nCREATE TABLE IF NOT EXISTS performance_metrics (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n metric_name TEXT NOT NULL,\n metric_value REAL NOT NULL,\n metric_unit TEXT,\n recorded_at TEXT NOT NULL DEFAULT (datetime('now')),\n metadata JSON\n);\n\n-- Index for performance metrics\nCREATE INDEX IF NOT EXISTS idx_performance_metrics_name ON performance_metrics(metric_name);\nCREATE INDEX IF NOT EXISTS idx_performance_metrics_timestamp ON performance_metrics(recorded_at);\n"; /** * sqlite-vec virtual table schema * Note: This is created separately after loading the extension */ export declare const VECTOR_SCHEMA_SQL = "\n-- Vector embeddings using sqlite-vec\n-- Dimension: 1536 for OpenRouter text-embedding-3-small compatible models\nCREATE VIRTUAL TABLE IF NOT EXISTS embeddings USING vec0(\n context_id TEXT PRIMARY KEY,\n embedding FLOAT[1536]\n);\n"; /** * Relationship types in the knowledge graph */ export declare const RELATION_TYPES: readonly ["uses", "implements", "depends_on", "references", "tests", "documents", "extends", "contains", "calls", "imports", "configures", "authenticates", "validates", "transforms"]; export type RelationType = typeof RELATION_TYPES[number]; /** * Context item types - extended to include docs and tool configs */ export declare const CONTEXT_TYPES: readonly ["workflow", "agent", "command", "code", "commit", "knowledge", "config", "doc", "tool_config"]; export type ContextType = typeof CONTEXT_TYPES[number]; /** * Sync status types */ export declare const SYNC_STATUSES: readonly ["synced", "pending", "conflict", "error"]; export type SyncStatus = typeof SYNC_STATUSES[number]; /** * Supported AI tools */ export declare const AI_TOOLS: readonly ["claude", "copilot", "cline", "antigravity", "windsurf", "aider", "continue", "cursor", "gemini"]; export type AITool = typeof AI_TOOLS[number]; /** * AI tool folder mappings */ export declare const AI_TOOL_FOLDERS: Record; /** * Template sync schema SQL * Tracks template versions and file states for .claude/ directory sync */ export declare const TEMPLATE_SCHEMA_SQL = "\n-- Template manifests tracking (dual storage: DB + file)\nCREATE TABLE IF NOT EXISTS template_manifests (\n id TEXT PRIMARY KEY,\n k0ntext_version TEXT NOT NULL,\n template_version TEXT NOT NULL,\n manifest TEXT NOT NULL,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- Index for template manifests\nCREATE INDEX IF NOT EXISTS idx_template_manifests_version ON template_manifests(template_version);\n\n-- Template file version tracking\nCREATE TABLE IF NOT EXISTS template_files (\n id TEXT PRIMARY KEY,\n relative_path TEXT NOT NULL UNIQUE,\n template_hash TEXT NOT NULL,\n template_version TEXT NOT NULL,\n user_modified INTEGER DEFAULT 0,\n last_synced_at TEXT,\n synced_at TEXT NOT NULL DEFAULT (datetime('now')),\n original_hash TEXT,\n metadata JSON\n);\n\n-- Indexes for template files\nCREATE INDEX IF NOT EXISTS idx_template_files_path ON template_files(relative_path);\nCREATE INDEX IF NOT EXISTS idx_template_files_version ON template_files(template_version);\nCREATE INDEX IF NOT EXISTS idx_template_files_user_modified ON template_files(user_modified);\nCREATE INDEX IF NOT EXISTS idx_template_files_hash ON template_files(template_hash);\n"; /** * Template manifest record from database */ export interface TemplateManifestRecord { id: string; k0ntextVersion: string; templateVersion: string; manifest: string; createdAt: string; updatedAt: string; } /** * Template file record from database */ export interface TemplateFileRecord { id: string; relativePath: string; templateHash: string; templateVersion: string; userModified: boolean; lastSyncedAt?: string; syncedAt: string; originalHash?: string; metadata?: Record; } /** * Template subdirectories (synced from package) */ export declare const TEMPLATE_SUBDIRS: readonly ["commands", "agents", "schemas", "standards", "tools", "automation"]; export type TemplateSubdir = typeof TEMPLATE_SUBDIRS[number]; /** * Excluded template subdirectories (user-specific) */ export declare const EXCLUDED_TEMPLATE_SUBDIRS: readonly ["context", "indexes"]; //# sourceMappingURL=schema.d.ts.map