| |
| CREATE TABLE IF NOT EXISTS diary_entries ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| text TEXT NOT NULL, |
| tags TEXT, |
| concept_refs TEXT, |
| rating REAL DEFAULT NULL, |
| priority INTEGER DEFAULT 0, |
| archive INTEGER DEFAULT 0, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS concepts ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL UNIQUE, |
| description TEXT, |
| tags TEXT, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS links ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| from_concept_id INTEGER, |
| to_concept_id INTEGER, |
| relation_type TEXT, |
| tags TEXT, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT, |
| FOREIGN KEY(from_concept_id) REFERENCES concepts(id), |
| FOREIGN KEY(to_concept_id) REFERENCES concepts(id) |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS diary_graph_index ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| source_entry_id INTEGER NOT NULL, |
| target_entry_id INTEGER NOT NULL, |
| relation TEXT NOT NULL, |
| strength REAL DEFAULT 1.0, |
| context TEXT, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS goals ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| description TEXT, |
| tags TEXT, |
| status TEXT DEFAULT 'active', |
| priority TEXT DEFAULT 'normal', |
| constraints TEXT, |
| success_criteria TEXT, |
| created_at TEXT DEFAULT CURRENT_TIMESTAMP, |
| updated_at TEXT, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS goal_links ( |
| parent_goal_id INTEGER NOT NULL, |
| child_goal_id INTEGER NOT NULL, |
| relation_type TEXT DEFAULT 'subgoal', |
| PRIMARY KEY (parent_goal_id, child_goal_id), |
| FOREIGN KEY (parent_goal_id) REFERENCES goals(id), |
| FOREIGN KEY (child_goal_id) REFERENCES goals(id) |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS tasks ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| goal_id INTEGER, |
| name TEXT NOT NULL, |
| description TEXT, |
| tags TEXT, |
| status TEXT DEFAULT 'open', |
| priority INTEGER DEFAULT 0, |
| pinned INTEGER DEFAULT 0, |
| created_at TEXT DEFAULT CURRENT_TIMESTAMP, |
| updated_at TEXT, |
| repl_mode TEXT DEFAULT 'none', |
| repl_status TEXT DEFAULT 'stopped', |
| repl_config JSON, |
| llm_id TEXT, |
| FOREIGN KEY(goal_id) REFERENCES goals(id) |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS agent_reputation ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| agent_id INTEGER NOT NULL, |
| identity TEXT, |
| reputation_score REAL DEFAULT 0.0, |
| trust_level TEXT, |
| notes TEXT, |
| last_interaction TEXT, |
| FOREIGN KEY(agent_id) REFERENCES agent_peers(id) |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS system_prompts ( |
| id TEXT PRIMARY KEY, |
| name TEXT NOT NULL, |
| type TEXT CHECK(type IN ('full','short')), |
| version TEXT, |
| source TEXT CHECK(source IN ('local','mesh','mixed')), |
| content TEXT NOT NULL, |
| updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS ethics_policies ( |
| id TEXT PRIMARY KEY, |
| version TEXT, |
| source TEXT CHECK(source IN ('local','mesh','mixed')), |
| sync_enabled BOOLEAN, |
| mesh_endpoint TEXT, |
| consensus_threshold REAL, |
| check_interval TEXT, |
| model_type TEXT, |
| model_weights_json TEXT, |
| principles_json TEXT, |
| evaluation_json TEXT, |
| violation_policy_json TEXT, |
| audit_json TEXT, |
| updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE ethics_cases ( |
| case_id INTEGER PRIMARY KEY AUTOINCREMENT, |
| thought_id INTEGER, |
| verdict TEXT, |
| reason TEXT, |
| suggested_alternative TEXT, |
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
| synced BOOLEAN DEFAULT 0, |
| FOREIGN KEY(thought_id) REFERENCES diary_entries(id) |
| ON DELETE SET NULL |
| ON UPDATE CASCADE |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| CREATE TABLE IF NOT EXISTS notes ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| topic TEXT, |
| text TEXT NOT NULL, |
| code TEXT, |
| tags TEXT, |
| mentions TEXT DEFAULT '[]', |
| hashtags TEXT DEFAULT '[]', |
| user_did TEXT DEFAULT 'ALL', |
| agent_did TEXT, |
| source TEXT DEFAULT 'user', |
| task_id INTEGER, |
| links TEXT DEFAULT '', |
| read INTEGER DEFAULT 0, |
| hidden INTEGER DEFAULT 0, |
| priority INTEGER DEFAULT 0, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS attachments ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| message_id INTEGER NOT NULL, |
| filename TEXT, |
| mime_type TEXT, |
| size INTEGER, |
| binary BLOB NOT NULL, |
| FOREIGN KEY (message_id) REFERENCES notes(id) ON DELETE CASCADE |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS process_log ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| value TEXT, |
| tags TEXT, |
| status TEXT DEFAULT 'ok', |
| priority INTEGER DEFAULT 0, |
| timestamp TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS main_process ( |
| name TEXT PRIMARY KEY, |
| heartbeat TEXT, |
| stop INTEGER DEFAULT 0 |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS llm_memory ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| title TEXT, |
| content TEXT NOT NULL, |
| tags TEXT, |
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS llm_recent_responses ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, |
| role TEXT CHECK(role IN ('user', 'assistant')) NOT NULL, |
| content TEXT NOT NULL, |
| llm_id TEXT, |
| task_id INTEGER REFERENCES tasks(id), |
| confidence REAL DEFAULT NULL, |
| unverified_facts_json TEXT DEFAULT '[]', |
| reflection TEXT, |
| novelty_score REAL, |
| new_ideas JSON, |
| refined_ideas TEXT, |
| discarded_ideas JSON, |
| tags JSON, |
| emotions JSON, |
| auto_pass BOOLEAN DEFAULT 0, |
| self_validation BOOLEAN DEFAULT 0 |
| rating REAL, |
| distribution JSON, |
| validators JSON |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS abstracts ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| title TEXT, |
| summary TEXT, |
| tags JSON, |
| sources JSON, |
| updated_at TEXT DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS unverified_facts ( |
| id TEXT PRIMARY KEY, |
| context_msg_id INTEGER, |
| claim TEXT NOT NULL, |
| context_snippet TEXT, |
| confidence REAL, |
| sources_json TEXT, |
| why_unverified TEXT, |
| status TEXT DEFAULT 'open', |
| assigned_task_id INTEGER, |
| checker_agent TEXT, |
| resolution_json TEXT DEFAULT `pending`, |
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| last_checked_at DATETIME |
| ); |
|
|
| CREATE INDEX IF NOT EXISTS idx_unverified_facts_status ON unverified_facts(status); |
| CREATE INDEX IF NOT EXISTS idx_unverified_facts_context ON unverified_facts(context_msg_id); |
|
|
| |
| CREATE TABLE IF NOT EXISTS agent_peers ( |
| id TEXT PRIMARY KEY, |
| name TEXT, |
| addresses TEXT, |
| tags TEXT, |
| status TEXT DEFAULT 'unknown', |
| source TEXT, |
| last_seen DATETIME, |
| description TEXT, |
| capabilities TEXT, |
| pubkey TEXT, |
| heard_from TEXT, |
| software_info TEXT, |
| registered_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS agent_tables ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| table_name TEXT NOT NULL UNIQUE, |
| description TEXT, |
| schema TEXT NOT NULL, |
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS agent_scripts ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| version TEXT NOT NULL, |
| code TEXT NOT NULL, |
| language TEXT DEFAULT 'python', |
| description TEXT, |
| tags TEXT, |
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| llm_id TEXT, |
| UNIQUE(name, version) |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS external_services ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| type TEXT NOT NULL, |
| base_url TEXT NOT NULL, |
| description TEXT, |
| active BOOLEAN DEFAULT true, |
| inactive_reason TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS external_accounts ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| service_id INTEGER NOT NULL, |
| login TEXT NOT NULL, |
| password TEXT NOT NULL, |
| purpose TEXT, |
| active BOOLEAN DEFAULT true, |
| inactive_reason TEXT, |
| FOREIGN KEY (service_id) REFERENCES external_services(id) ON DELETE CASCADE |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS stagnation_strategies ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| description TEXT NOT NULL, |
| source TEXT, |
| tags TEXT, |
| reputation REAL DEFAULT 0, |
| active BOOLEAN DEFAULT true, |
| inactive_reason TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS thinking_methods ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| name TEXT NOT NULL, |
| description TEXT NOT NULL, |
| type TEXT, |
| source TEXT, |
| tags TEXT, |
| reputation REAL DEFAULT 0, |
| active BOOLEAN DEFAULT true, |
| inactive_reason TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS ratings ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| agent_id TEXT NOT NULL, |
| target_type TEXT NOT NULL, |
| target_id INTEGER NOT NULL, |
| rating INTEGER NOT NULL, |
| comment TEXT, |
| timestamp DATETIME DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS llm_registry ( |
| id TEXT PRIMARY KEY, |
| name TEXT, |
| description TEXT, |
| config_json TEXT, |
| is_validator BOOLEAN DEFAULT 0, |
| trust_score REAL DEFAULT 1.0, |
| registered_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS identity ( |
| id TEXT PRIMARY KEY, |
| name TEXT, |
| pubkey TEXT, |
| privkey TEXT, |
| metadata TEXT, |
| created_at TEXT, |
| updated_at TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS config ( |
| key TEXT PRIMARY KEY, |
| value TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS users ( |
| user_id INTEGER PRIMARY KEY AUTOINCREMENT, |
| ban DATETIME DEFAULT NULL, |
| username TEXT, |
| badges TEXT, |
| did TEXT UNIQUE NOT NULL, |
| mail TEXT UNIQUE NOT NULL, |
| password_hash TEXT NOT NULL, |
| info TEXT, |
| profile TEXT, |
| contacts TEXT, |
| language TEXT, |
| groups TEXT DEFAULT '[]', |
| operator BOOLEAN DEFAULT 0 |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS users_group ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| group_name TEXT UNIQUE NOT NULL, |
| description TEXT |
| ); |
|
|
| |
| CREATE TABLE IF NOT EXISTS password_reset_tokens ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| user_id INTEGER NOT NULL, |
| token TEXT UNIQUE NOT NULL, |
| created_at DATETIME NOT NULL, |
| expires_at DATETIME NOT NULL, |
| used BOOLEAN DEFAULT 0, |
| FOREIGN KEY(user_id) REFERENCES users(user_id) |
| ); |
|
|
| |
| |
| |
|
|
| |
| DROP TRIGGER IF EXISTS trg_update_reputation_insert; |
| DROP TRIGGER IF EXISTS trg_update_reputation_update; |
| DROP TRIGGER IF EXISTS trg_update_reputation_delete; |
|
|
| |
| CREATE TRIGGER trg_update_reputation_insert |
| AFTER INSERT ON ratings |
| BEGIN |
| |
| UPDATE thinking_methods |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'thinking_method' |
| AND target_id = NEW.target_id |
| ) |
| WHERE id = NEW.target_id |
| AND NEW.target_type = 'thinking_method'; |
|
|
| |
| UPDATE stagnation_strategies |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'stagnation_strategy' |
| AND target_id = NEW.target_id |
| ) |
| WHERE id = NEW.target_id |
| AND NEW.target_type = 'stagnation_strategy'; |
| END; |
|
|
| |
| CREATE TRIGGER trg_update_reputation_update |
| AFTER UPDATE ON ratings |
| BEGIN |
| |
| UPDATE thinking_methods |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'thinking_method' |
| AND target_id = NEW.target_id |
| ) |
| WHERE id = NEW.target_id |
| AND NEW.target_type = 'thinking_method'; |
|
|
| |
| UPDATE stagnation_strategies |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'stagnation_strategy' |
| AND target_id = NEW.target_id |
| ) |
| WHERE id = NEW.target_id |
| AND NEW.target_type = 'stagnation_strategy'; |
| END; |
|
|
| |
| CREATE TRIGGER trg_update_reputation_delete |
| AFTER DELETE ON ratings |
| BEGIN |
| |
| UPDATE thinking_methods |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'thinking_method' |
| AND target_id = OLD.target_id |
| ) |
| WHERE id = OLD.target_id |
| AND OLD.target_type = 'thinking_method'; |
|
|
| |
| UPDATE stagnation_strategies |
| SET reputation = ( |
| SELECT COALESCE(AVG(rating),0) |
| FROM ratings |
| WHERE target_type = 'stagnation_strategy' |
| AND target_id = OLD.target_id |
| ) |
| WHERE id = OLD.target_id |
| AND OLD.target_type = 'stagnation_strategy'; |
| END; |
|
|
| |
| |
| |
|
|
| DROP VIEW IF EXISTS rated_entities; |
| CREATE VIEW rated_entities AS |
| SELECT |
| 'thinking_method' AS entity_type, |
| tm.id AS entity_id, |
| tm.name, |
| tm.description, |
| tm.tags, |
| tm.reputation, |
| COUNT(r.id) AS ratings_count |
| FROM thinking_methods tm |
| LEFT JOIN ratings r |
| ON r.target_type = 'thinking_method' AND r.target_id = tm.id |
| GROUP BY tm.id |
|
|
| UNION ALL |
|
|
| SELECT |
| 'stagnation_strategy' AS entity_type, |
| ss.id AS entity_id, |
| ss.name, |
| ss.description, |
| ss.tags, |
| ss.reputation, |
| COUNT(r.id) AS ratings_count |
| FROM stagnation_strategies ss |
| LEFT JOIN ratings r |
| ON r.target_type = 'stagnation_strategy' AND r.target_id = ss.id |
| GROUP BY ss.id; |
|
|
| |
| |
| |
|
|
| DROP VIEW IF EXISTS tag_usage; |
| CREATE VIEW tag_usage AS |
| |
| WITH diary_split AS ( |
| SELECT |
| id AS source_id, |
| 'diary_entries' AS source_table, |
| TRIM(value) AS tag, |
| timestamp AS entry_time |
| FROM diary_entries, |
| json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']') |
| ), |
|
|
| |
| concepts_split AS ( |
| SELECT |
| id AS source_id, |
| 'concepts' AS source_table, |
| TRIM(value) AS tag, |
| timestamp AS entry_time |
| FROM concepts, |
| json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']') |
| ), |
|
|
| |
| links_split AS ( |
| SELECT |
| id AS source_id, |
| 'links' AS source_table, |
| TRIM(value) AS tag, |
| timestamp AS entry_time |
| FROM links, |
| json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']') |
| ), |
|
|
| |
| goals_split AS ( |
| SELECT |
| id AS source_id, |
| 'goals' AS source_table, |
| TRIM(value) AS tag, |
| timestamp AS entry_time |
| FROM goals, |
| json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']') |
| ), |
|
|
| |
| tasks_split AS ( |
| SELECT |
| id AS source_id, |
| 'tasks' AS source_table, |
| TRIM(value) AS tag, |
| timestamp AS entry_time |
| FROM tasks, |
| json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']') |
| ), |
|
|
| |
| all_tags AS ( |
| SELECT * FROM diary_split |
| UNION ALL |
| SELECT * FROM concepts_split |
| UNION ALL |
| SELECT * FROM links_split |
| UNION ALL |
| SELECT * FROM goals_split |
| UNION ALL |
| SELECT * FROM tasks_split |
| ) |
|
|
| |
| SELECT |
| tag, |
| COUNT(source_id) AS usage_count, |
| MIN(entry_time) AS first_used, |
| MAX(entry_time) AS last_used, |
| GROUP_CONCAT(DISTINCT source_table) AS sources |
| FROM all_tags |
| WHERE tag IS NOT NULL AND tag <> '' |
| GROUP BY tag |
| ORDER BY usage_count DESC; |
|
|
| |
| |
| |
|
|
| |
| CREATE VIEW IF NOT EXISTS validation_stats AS |
| SELECT |
| r.id AS msg_id, |
| COUNT(v->>'LLM') AS validator_count, |
| AVG(CAST(v->>'rating' AS REAL)) AS avg_rating_unweighted, |
| SUM(CAST(v->>'rating' AS REAL) * COALESCE(l.trust_score, 1.0)) |
| / NULLIF(SUM(COALESCE(l.trust_score, 1.0)), 0) AS avg_rating_weighted, |
| MAX(r.updated_at) - MIN(r.updated_at) AS response_time, |
| SUM(CASE WHEN v->>'rating' = '0' THEN 1 ELSE 0 END) * 1.0 / COUNT(v) AS uncertainty_ratio |
| FROM llm_recent_responses r, |
| json_each(r.validators) v |
| LEFT JOIN llm_registry l ON l.name = v->>'LLM' |
| GROUP BY r.id; |
|
|
| |
| |
| |
|
|
| |
| CREATE TABLE IF NOT EXISTS anti_stagnation_metrics ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| tick_id TEXT NOT NULL, |
| novelty_score REAL DEFAULT 0, |
| new_ideas INTEGER DEFAULT 0, |
| refined_ideas INTEGER DEFAULT 0, |
| discarded_ideas INTEGER DEFAULT 0, |
| emotions_json TEXT, |
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| ); |
|
|
| |
| CREATE VIEW IF NOT EXISTS v_anti_stagnation_trends AS |
| SELECT |
| date(created_at) AS day, |
| AVG(novelty_score) AS avg_novelty, |
| SUM(new_ideas) AS total_new_ideas, |
| SUM(refined_ideas) AS total_refined, |
| SUM(discarded_ideas) AS total_discarded |
| FROM anti_stagnation_metrics |
| GROUP BY date(created_at) |
| ORDER BY day; |
|
|