|
| 1 | +-- /usr/share/mios/surrealdb/schema-init.surql |
| 2 | +-- |
| 3 | +-- Unified AI-surface schemas. Operator directive 2026-05-18: |
| 4 | +-- "unify all AI Surfaces!!" -- every MiOS agent (OWUI pipe, |
| 5 | +-- hermes, mios-daemon, future OpenCode) reads/writes the same |
| 6 | +-- tables. The DB is the SHARED GROUND TRUTH; agents don't |
| 7 | +-- fabricate state from context window. |
| 8 | +-- |
| 9 | +-- Idempotent (DEFINE ... if not exists). Re-running is safe. |
| 10 | + |
| 11 | +USE NS mios; |
| 12 | +USE DB mios; |
| 13 | + |
| 14 | +-- agent: registry row per AI surface in the stack. |
| 15 | +DEFINE TABLE agent SCHEMAFULL PERMISSIONS NONE; |
| 16 | +DEFINE FIELD name ON agent TYPE string; |
| 17 | +DEFINE FIELD role ON agent TYPE string; -- router / refine / orchestrator / micro / critic / nudger / ... |
| 18 | +DEFINE FIELD model ON agent TYPE option<string>; |
| 19 | +DEFINE FIELD endpoint ON agent TYPE option<string>; |
| 20 | +DEFINE FIELD device ON agent TYPE option<string>; -- cpu / nvidia / amd-igpu / intel-igpu |
| 21 | +DEFINE FIELD pid ON agent TYPE option<int>; |
| 22 | +DEFINE FIELD started_at ON agent TYPE option<datetime>; |
| 23 | +DEFINE FIELD last_seen ON agent TYPE option<datetime>; |
| 24 | +DEFINE FIELD enabled ON agent TYPE bool DEFAULT true; |
| 25 | +DEFINE INDEX agent_name_unique ON agent COLUMNS name UNIQUE; |
| 26 | + |
| 27 | +-- session: one row per chat / cron run / delegate spawn. |
| 28 | +DEFINE TABLE session SCHEMAFULL PERMISSIONS NONE; |
| 29 | +DEFINE FIELD started_at ON session TYPE datetime; |
| 30 | +DEFINE FIELD ended_at ON session TYPE option<datetime>; |
| 31 | +DEFINE FIELD platform ON session TYPE string; -- owui / cron / cli / mcp |
| 32 | +DEFINE FIELD chat_id ON session TYPE option<string>; |
| 33 | +DEFINE FIELD model ON session TYPE option<string>; |
| 34 | +DEFINE FIELD operator ON session TYPE option<string>; |
| 35 | +DEFINE FIELD turn_count ON session TYPE int DEFAULT 0; |
| 36 | +DEFINE FIELD outcome ON session TYPE option<string>;-- success / partial / error / abandoned |
| 37 | +DEFINE INDEX session_chat ON session COLUMNS chat_id; |
| 38 | + |
| 39 | +-- tool_call: one row per dispatched verb. Source of truth for |
| 40 | +-- "did the agent actually run X?" -- replaces text-parsing the |
| 41 | +-- raw hermes stream. |
| 42 | +DEFINE TABLE tool_call SCHEMAFULL PERMISSIONS NONE; |
| 43 | +DEFINE FIELD session ON tool_call TYPE record<session>; |
| 44 | +DEFINE FIELD ts ON tool_call TYPE datetime; |
| 45 | +DEFINE FIELD tool ON tool_call TYPE string; |
| 46 | +DEFINE FIELD args ON tool_call TYPE object; |
| 47 | +DEFINE FIELD result_preview ON tool_call TYPE option<string>; |
| 48 | +DEFINE FIELD success ON tool_call TYPE option<bool>; |
| 49 | +DEFINE FIELD latency_ms ON tool_call TYPE option<int>; |
| 50 | +DEFINE FIELD dispatched_by ON tool_call TYPE option<record<agent>>; |
| 51 | +DEFINE INDEX tool_call_ts ON tool_call COLUMNS ts; |
| 52 | +DEFINE INDEX tool_call_tool ON tool_call COLUMNS tool; |
| 53 | + |
| 54 | +-- memory: durable cross-session memory. Operator + agents both |
| 55 | +-- write here; agents query before fabricating. |
| 56 | +DEFINE TABLE memory SCHEMAFULL PERMISSIONS NONE; |
| 57 | +DEFINE FIELD ts ON memory TYPE datetime; |
| 58 | +DEFINE FIELD kind ON memory TYPE string; -- user / feedback / project / reference |
| 59 | +DEFINE FIELD subject ON memory TYPE string; -- short topic key |
| 60 | +DEFINE FIELD body ON memory TYPE string; |
| 61 | +DEFINE FIELD source ON memory TYPE option<record<agent>>; |
| 62 | +DEFINE FIELD tags ON memory TYPE array<string> DEFAULT []; |
| 63 | +-- Optional vector embedding for semantic recall. Dim = nomic-embed |
| 64 | +-- size 768; agents that don't embed can leave it null. |
| 65 | +DEFINE FIELD embedding ON memory TYPE option<array<float>>; |
| 66 | +DEFINE INDEX memory_subject ON memory COLUMNS subject; |
| 67 | +DEFINE INDEX memory_kind ON memory COLUMNS kind; |
| 68 | + |
| 69 | +-- event: append-only observability stream (launch verifier hits, |
| 70 | +-- refusal pattern matches, classify summaries, critic verdicts, |
| 71 | +-- ...). Per-thread streams instead of polling state.json. |
| 72 | +DEFINE TABLE event SCHEMAFULL PERMISSIONS NONE; |
| 73 | +DEFINE FIELD ts ON event TYPE datetime; |
| 74 | +DEFINE FIELD source ON event TYPE string; -- agent name |
| 75 | +DEFINE FIELD kind ON event TYPE string; -- launch_failure / classify / nudge / refusal / critic_verdict / ... |
| 76 | +DEFINE FIELD severity ON event TYPE string DEFAULT 'info'; -- info / warn / high |
| 77 | +DEFINE FIELD summary ON event TYPE string; |
| 78 | +DEFINE FIELD payload ON event TYPE option<object>; |
| 79 | +DEFINE INDEX event_ts ON event COLUMNS ts; |
| 80 | +DEFINE INDEX event_source ON event COLUMNS source; |
| 81 | +DEFINE INDEX event_kind ON event COLUMNS kind; |
| 82 | + |
| 83 | +-- kanban_shadow: live mirror of hermes-side kanban.db (operator |
| 84 | +-- + non-hermes agents can read without opening the SQLite file). |
| 85 | +-- mios-daemon task_collector_loop populates on its 5-min cadence. |
| 86 | +DEFINE TABLE kanban_shadow SCHEMAFULL PERMISSIONS NONE; |
| 87 | +DEFINE FIELD hermes_task_id ON kanban_shadow TYPE string; |
| 88 | +DEFINE FIELD title ON kanban_shadow TYPE string; |
| 89 | +DEFINE FIELD status ON kanban_shadow TYPE string; |
| 90 | +DEFINE FIELD priority ON kanban_shadow TYPE option<string>; |
| 91 | +DEFINE FIELD tags ON kanban_shadow TYPE array<string> DEFAULT []; |
| 92 | +DEFINE FIELD synced_at ON kanban_shadow TYPE datetime; |
| 93 | +DEFINE INDEX kanban_shadow_task ON kanban_shadow COLUMNS hermes_task_id UNIQUE; |
| 94 | + |
| 95 | +-- scratch: shared-mutable note surface (operator + agents both |
| 96 | +-- write). Free-form; agents can leave one-line context notes for |
| 97 | +-- their successors. |
| 98 | +DEFINE TABLE scratch SCHEMAFULL PERMISSIONS NONE; |
| 99 | +DEFINE FIELD ts ON scratch TYPE datetime; |
| 100 | +DEFINE FIELD source ON scratch TYPE string; |
| 101 | +DEFINE FIELD topic ON scratch TYPE string; |
| 102 | +DEFINE FIELD body ON scratch TYPE string; |
| 103 | +DEFINE FIELD ttl_at ON scratch TYPE option<datetime>; -- agent-defined expiry |
| 104 | +DEFINE INDEX scratch_topic ON scratch COLUMNS topic; |
| 105 | + |
| 106 | +-- doc: index entry per .md doc surface (mios-docs-index output |
| 107 | +-- shadow). Lets agents semantic-search docs without re-walking |
| 108 | +-- the filesystem on every turn. |
| 109 | +DEFINE TABLE doc SCHEMAFULL PERMISSIONS NONE; |
| 110 | +DEFINE FIELD path ON doc TYPE string; |
| 111 | +DEFINE FIELD description ON doc TYPE option<string>; |
| 112 | +DEFINE FIELD size ON doc TYPE int; |
| 113 | +DEFINE FIELD updated_at ON doc TYPE datetime; |
| 114 | +DEFINE FIELD embedding ON doc TYPE option<array<float>>; |
| 115 | +DEFINE INDEX doc_path_unique ON doc COLUMNS path UNIQUE; |
0 commit comments