kongbrain 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +385 -0
- package/openclaw.plugin.json +66 -0
- package/package.json +65 -0
- package/src/acan.ts +309 -0
- package/src/causal.ts +237 -0
- package/src/cognitive-check.ts +330 -0
- package/src/config.ts +64 -0
- package/src/context-engine.ts +487 -0
- package/src/daemon-manager.ts +148 -0
- package/src/daemon-types.ts +65 -0
- package/src/embeddings.ts +77 -0
- package/src/errors.ts +43 -0
- package/src/graph-context.ts +989 -0
- package/src/hooks/after-tool-call.ts +99 -0
- package/src/hooks/before-prompt-build.ts +44 -0
- package/src/hooks/before-tool-call.ts +86 -0
- package/src/hooks/llm-output.ts +173 -0
- package/src/identity.ts +218 -0
- package/src/index.ts +435 -0
- package/src/intent.ts +190 -0
- package/src/memory-daemon.ts +495 -0
- package/src/orchestrator.ts +348 -0
- package/src/prefetch.ts +200 -0
- package/src/reflection.ts +280 -0
- package/src/retrieval-quality.ts +266 -0
- package/src/schema.surql +387 -0
- package/src/skills.ts +343 -0
- package/src/soul.ts +936 -0
- package/src/state.ts +119 -0
- package/src/surreal.ts +1371 -0
- package/src/tools/core-memory.ts +120 -0
- package/src/tools/introspect.ts +329 -0
- package/src/tools/recall.ts +102 -0
- package/src/wakeup.ts +318 -0
- package/src/workspace-migrate.ts +752 -0
package/src/schema.surql
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
-- KongBrain conversation graph schema
|
|
2
|
+
-- Run against ns:kong db:memory
|
|
3
|
+
-- Aligned with 5-pillar model: Agent, Project, Task, Artifact, Concept
|
|
4
|
+
|
|
5
|
+
-- ============================================================
|
|
6
|
+
-- PILLAR 1: Agent
|
|
7
|
+
-- ============================================================
|
|
8
|
+
DEFINE TABLE IF NOT EXISTS agent SCHEMALESS;
|
|
9
|
+
DEFINE FIELD IF NOT EXISTS name ON agent TYPE string;
|
|
10
|
+
DEFINE FIELD IF NOT EXISTS model ON agent TYPE option<string>;
|
|
11
|
+
DEFINE FIELD IF NOT EXISTS created_at ON agent TYPE datetime DEFAULT time::now();
|
|
12
|
+
|
|
13
|
+
-- ============================================================
|
|
14
|
+
-- PILLAR 2: Project
|
|
15
|
+
-- ============================================================
|
|
16
|
+
DEFINE TABLE IF NOT EXISTS project SCHEMALESS;
|
|
17
|
+
DEFINE FIELD IF NOT EXISTS name ON project TYPE string;
|
|
18
|
+
DEFINE FIELD IF NOT EXISTS status ON project TYPE string DEFAULT "active";
|
|
19
|
+
DEFINE FIELD IF NOT EXISTS tags ON project TYPE option<array>;
|
|
20
|
+
DEFINE FIELD IF NOT EXISTS created_at ON project TYPE datetime DEFAULT time::now();
|
|
21
|
+
|
|
22
|
+
-- ============================================================
|
|
23
|
+
-- PILLAR 3: Task (sessions are tasks)
|
|
24
|
+
-- ============================================================
|
|
25
|
+
DEFINE TABLE IF NOT EXISTS task SCHEMALESS;
|
|
26
|
+
DEFINE FIELD IF NOT EXISTS description ON task TYPE option<string>;
|
|
27
|
+
DEFINE FIELD IF NOT EXISTS status ON task TYPE string DEFAULT "in_progress";
|
|
28
|
+
DEFINE FIELD IF NOT EXISTS summary ON task TYPE option<string>;
|
|
29
|
+
DEFINE FIELD IF NOT EXISTS friction ON task TYPE float DEFAULT 0.0;
|
|
30
|
+
DEFINE FIELD IF NOT EXISTS created_at ON task TYPE datetime DEFAULT time::now();
|
|
31
|
+
DEFINE FIELD IF NOT EXISTS updated_at ON task TYPE datetime DEFAULT time::now();
|
|
32
|
+
|
|
33
|
+
-- ============================================================
|
|
34
|
+
-- PILLAR 4: Artifact
|
|
35
|
+
-- ============================================================
|
|
36
|
+
DEFINE TABLE IF NOT EXISTS artifact SCHEMALESS;
|
|
37
|
+
DEFINE FIELD IF NOT EXISTS path ON artifact TYPE string;
|
|
38
|
+
DEFINE FIELD IF NOT EXISTS type ON artifact TYPE string;
|
|
39
|
+
DEFINE FIELD IF NOT EXISTS description ON artifact TYPE option<string>;
|
|
40
|
+
DEFINE FIELD IF NOT EXISTS content_hash ON artifact TYPE option<string>;
|
|
41
|
+
DEFINE FIELD IF NOT EXISTS embedding ON artifact TYPE option<array<float>>;
|
|
42
|
+
DEFINE FIELD IF NOT EXISTS tags ON artifact TYPE option<array>;
|
|
43
|
+
DEFINE FIELD IF NOT EXISTS created_at ON artifact TYPE datetime DEFAULT time::now();
|
|
44
|
+
DEFINE INDEX IF NOT EXISTS artifact_vec_idx ON artifact FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
45
|
+
|
|
46
|
+
-- ============================================================
|
|
47
|
+
-- PILLAR 5: Concept (semantic knowledge nodes)
|
|
48
|
+
-- ============================================================
|
|
49
|
+
DEFINE TABLE IF NOT EXISTS concept SCHEMALESS;
|
|
50
|
+
DEFINE FIELD IF NOT EXISTS content ON concept TYPE string;
|
|
51
|
+
DEFINE FIELD IF NOT EXISTS embedding ON concept TYPE option<array<float>>;
|
|
52
|
+
DEFINE FIELD IF NOT EXISTS stability ON concept TYPE float DEFAULT 1.0;
|
|
53
|
+
DEFINE FIELD IF NOT EXISTS confidence ON concept TYPE float DEFAULT 1.0;
|
|
54
|
+
DEFINE FIELD IF NOT EXISTS access_count ON concept TYPE int DEFAULT 0;
|
|
55
|
+
DEFINE FIELD IF NOT EXISTS tags ON concept TYPE option<array>;
|
|
56
|
+
DEFINE FIELD IF NOT EXISTS source ON concept TYPE option<string>;
|
|
57
|
+
DEFINE FIELD IF NOT EXISTS created_at ON concept TYPE datetime DEFAULT time::now();
|
|
58
|
+
DEFINE FIELD IF NOT EXISTS last_accessed ON concept TYPE option<datetime>;
|
|
59
|
+
DEFINE INDEX IF NOT EXISTS concept_vec_idx ON concept FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
60
|
+
|
|
61
|
+
-- ============================================================
|
|
62
|
+
-- Conversation turns (the workhorse table)
|
|
63
|
+
-- ============================================================
|
|
64
|
+
DEFINE TABLE IF NOT EXISTS turn SCHEMALESS;
|
|
65
|
+
DEFINE FIELD IF NOT EXISTS session_id ON turn TYPE string;
|
|
66
|
+
DEFINE FIELD IF NOT EXISTS role ON turn TYPE string;
|
|
67
|
+
DEFINE FIELD IF NOT EXISTS text ON turn TYPE string;
|
|
68
|
+
-- Migration: ensure embedding is optional (SurrealDB 3.0 HNSW requires this for nullable embeddings)
|
|
69
|
+
REMOVE FIELD IF EXISTS embedding ON turn;
|
|
70
|
+
DEFINE FIELD embedding ON turn TYPE option<array<float>>;
|
|
71
|
+
DEFINE FIELD IF NOT EXISTS timestamp ON turn TYPE datetime DEFAULT time::now();
|
|
72
|
+
DEFINE FIELD IF NOT EXISTS created_at ON turn TYPE datetime DEFAULT time::now();
|
|
73
|
+
DEFINE FIELD IF NOT EXISTS token_count ON turn TYPE option<int>;
|
|
74
|
+
DEFINE FIELD IF NOT EXISTS tool_name ON turn TYPE option<string>;
|
|
75
|
+
DEFINE FIELD IF NOT EXISTS model ON turn TYPE option<string>;
|
|
76
|
+
DEFINE FIELD IF NOT EXISTS usage ON turn TYPE option<object>;
|
|
77
|
+
DEFINE INDEX IF NOT EXISTS turn_vec_idx ON turn FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
78
|
+
DEFINE INDEX IF NOT EXISTS turn_session_idx ON turn FIELDS session_id;
|
|
79
|
+
-- Migration: backfill created_at from timestamp for existing turns
|
|
80
|
+
UPDATE turn SET created_at = timestamp WHERE created_at IS NONE AND timestamp IS NOT NONE;
|
|
81
|
+
|
|
82
|
+
-- Identity chunks (agent persona / identity)
|
|
83
|
+
DEFINE TABLE IF NOT EXISTS identity_chunk SCHEMALESS;
|
|
84
|
+
DEFINE FIELD IF NOT EXISTS agent_id ON identity_chunk TYPE string;
|
|
85
|
+
DEFINE FIELD IF NOT EXISTS source ON identity_chunk TYPE string;
|
|
86
|
+
DEFINE FIELD IF NOT EXISTS chunk_index ON identity_chunk TYPE int;
|
|
87
|
+
DEFINE FIELD IF NOT EXISTS text ON identity_chunk TYPE string;
|
|
88
|
+
DEFINE FIELD IF NOT EXISTS embedding ON identity_chunk TYPE option<array<float>>;
|
|
89
|
+
DEFINE FIELD IF NOT EXISTS importance ON identity_chunk TYPE float DEFAULT 0.5;
|
|
90
|
+
DEFINE INDEX IF NOT EXISTS identity_vec_idx ON identity_chunk FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
91
|
+
|
|
92
|
+
-- Sessions (lightweight, links to task for 5-pillar integration)
|
|
93
|
+
DEFINE TABLE IF NOT EXISTS session SCHEMALESS;
|
|
94
|
+
DEFINE FIELD IF NOT EXISTS agent_id ON session TYPE string DEFAULT "default";
|
|
95
|
+
DEFINE FIELD IF NOT EXISTS started_at ON session TYPE datetime DEFAULT time::now();
|
|
96
|
+
DEFINE FIELD IF NOT EXISTS last_active ON session TYPE datetime DEFAULT time::now();
|
|
97
|
+
DEFINE FIELD IF NOT EXISTS turn_count ON session TYPE int DEFAULT 0;
|
|
98
|
+
DEFINE FIELD IF NOT EXISTS total_input_tokens ON session TYPE int DEFAULT 0;
|
|
99
|
+
DEFINE FIELD IF NOT EXISTS total_output_tokens ON session TYPE int DEFAULT 0;
|
|
100
|
+
|
|
101
|
+
-- Long-term memory (episodic → consolidated)
|
|
102
|
+
DEFINE TABLE IF NOT EXISTS memory SCHEMALESS;
|
|
103
|
+
DEFINE FIELD IF NOT EXISTS text ON memory TYPE string;
|
|
104
|
+
DEFINE FIELD IF NOT EXISTS embedding ON memory TYPE option<array<float>>;
|
|
105
|
+
DEFINE FIELD IF NOT EXISTS importance ON memory TYPE float DEFAULT 0.5;
|
|
106
|
+
DEFINE FIELD IF NOT EXISTS confidence ON memory TYPE float DEFAULT 1.0;
|
|
107
|
+
DEFINE FIELD IF NOT EXISTS access_count ON memory TYPE int DEFAULT 0;
|
|
108
|
+
DEFINE FIELD IF NOT EXISTS category ON memory TYPE string DEFAULT "general";
|
|
109
|
+
DEFINE FIELD IF NOT EXISTS source ON memory TYPE option<string>;
|
|
110
|
+
DEFINE FIELD IF NOT EXISTS created_at ON memory TYPE datetime DEFAULT time::now();
|
|
111
|
+
DEFINE FIELD IF NOT EXISTS last_accessed ON memory TYPE option<datetime>;
|
|
112
|
+
DEFINE FIELD IF NOT EXISTS status ON memory TYPE option<string> DEFAULT "active";
|
|
113
|
+
UPDATE memory SET status = "active" WHERE status IS NONE;
|
|
114
|
+
DEFINE FIELD IF NOT EXISTS resolved_at ON memory TYPE option<datetime>;
|
|
115
|
+
DEFINE FIELD IF NOT EXISTS resolved_by ON memory TYPE option<string>;
|
|
116
|
+
DEFINE INDEX IF NOT EXISTS memory_vec_idx ON memory FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
117
|
+
|
|
118
|
+
-- ============================================================
|
|
119
|
+
-- GRAPH EDGES: Turn-level
|
|
120
|
+
-- ============================================================
|
|
121
|
+
DEFINE TABLE IF NOT EXISTS responds_to TYPE RELATION IN turn OUT turn;
|
|
122
|
+
DEFINE TABLE IF NOT EXISTS tool_result_of TYPE RELATION IN turn OUT turn;
|
|
123
|
+
DEFINE TABLE IF NOT EXISTS part_of TYPE RELATION IN turn OUT session;
|
|
124
|
+
DEFINE TABLE IF NOT EXISTS mentions TYPE RELATION IN turn OUT concept;
|
|
125
|
+
|
|
126
|
+
-- ============================================================
|
|
127
|
+
-- GRAPH EDGES: 5-Pillar Relations
|
|
128
|
+
-- ============================================================
|
|
129
|
+
DEFINE TABLE IF NOT EXISTS performed TYPE RELATION IN agent OUT task;
|
|
130
|
+
DEFINE TABLE IF NOT EXISTS owns TYPE RELATION IN agent OUT project;
|
|
131
|
+
DEFINE TABLE IF NOT EXISTS task_part_of TYPE RELATION IN task OUT project;
|
|
132
|
+
DEFINE TABLE IF NOT EXISTS session_task TYPE RELATION IN session OUT task;
|
|
133
|
+
DEFINE TABLE IF NOT EXISTS produced TYPE RELATION IN task OUT artifact;
|
|
134
|
+
DEFINE TABLE IF NOT EXISTS derived_from TYPE RELATION IN concept OUT task;
|
|
135
|
+
DEFINE TABLE IF NOT EXISTS relevant_to TYPE RELATION IN concept OUT project;
|
|
136
|
+
DEFINE TABLE IF NOT EXISTS used_in TYPE RELATION IN artifact OUT project;
|
|
137
|
+
|
|
138
|
+
-- ============================================================
|
|
139
|
+
-- GRAPH EDGES: Knowledge Relations (from KG research)
|
|
140
|
+
-- ============================================================
|
|
141
|
+
-- Semantic hierarchy
|
|
142
|
+
DEFINE TABLE IF NOT EXISTS narrower TYPE RELATION IN concept OUT concept;
|
|
143
|
+
DEFINE TABLE IF NOT EXISTS broader TYPE RELATION IN concept OUT concept;
|
|
144
|
+
DEFINE TABLE IF NOT EXISTS related_to TYPE RELATION IN concept OUT concept;
|
|
145
|
+
|
|
146
|
+
-- Episodic causality & corroboration
|
|
147
|
+
DEFINE TABLE IF NOT EXISTS caused_by TYPE RELATION IN memory OUT memory;
|
|
148
|
+
DEFINE TABLE IF NOT EXISTS supports TYPE RELATION IN memory OUT memory;
|
|
149
|
+
DEFINE TABLE IF NOT EXISTS contradicts TYPE RELATION IN memory OUT memory;
|
|
150
|
+
DEFINE TABLE IF NOT EXISTS describes TYPE RELATION IN memory OUT memory;
|
|
151
|
+
|
|
152
|
+
-- Cross-pillar links
|
|
153
|
+
DEFINE TABLE IF NOT EXISTS about_concept TYPE RELATION IN memory OUT concept;
|
|
154
|
+
DEFINE TABLE IF NOT EXISTS artifact_mentions TYPE RELATION IN artifact OUT concept;
|
|
155
|
+
|
|
156
|
+
-- ============================================================
|
|
157
|
+
-- RETRIEVAL QUALITY TRACKING
|
|
158
|
+
-- ============================================================
|
|
159
|
+
-- Each record captures one retrieval event and its outcome signals
|
|
160
|
+
DEFINE TABLE IF NOT EXISTS retrieval_outcome SCHEMALESS;
|
|
161
|
+
DEFINE FIELD IF NOT EXISTS session_id ON retrieval_outcome TYPE string;
|
|
162
|
+
DEFINE FIELD IF NOT EXISTS turn_id ON retrieval_outcome TYPE string;
|
|
163
|
+
DEFINE FIELD IF NOT EXISTS memory_id ON retrieval_outcome TYPE string;
|
|
164
|
+
DEFINE FIELD IF NOT EXISTS memory_table ON retrieval_outcome TYPE string;
|
|
165
|
+
DEFINE FIELD IF NOT EXISTS retrieval_score ON retrieval_outcome TYPE float;
|
|
166
|
+
-- Quality signals
|
|
167
|
+
DEFINE FIELD IF NOT EXISTS utilization ON retrieval_outcome TYPE float DEFAULT 0.0;
|
|
168
|
+
DEFINE FIELD IF NOT EXISTS tool_success ON retrieval_outcome TYPE option<bool>;
|
|
169
|
+
DEFINE FIELD IF NOT EXISTS context_tokens ON retrieval_outcome TYPE int DEFAULT 0;
|
|
170
|
+
DEFINE FIELD IF NOT EXISTS was_neighbor ON retrieval_outcome TYPE bool DEFAULT false;
|
|
171
|
+
DEFINE FIELD IF NOT EXISTS query_embedding ON retrieval_outcome TYPE option<array<float>>;
|
|
172
|
+
DEFINE FIELD IF NOT EXISTS llm_relevance ON retrieval_outcome TYPE option<float>;
|
|
173
|
+
DEFINE FIELD IF NOT EXISTS llm_relevant ON retrieval_outcome TYPE option<bool>;
|
|
174
|
+
DEFINE FIELD IF NOT EXISTS llm_reason ON retrieval_outcome TYPE option<string>;
|
|
175
|
+
DEFINE FIELD IF NOT EXISTS created_at ON retrieval_outcome TYPE datetime DEFAULT time::now();
|
|
176
|
+
DEFINE INDEX IF NOT EXISTS ro_session_idx ON retrieval_outcome FIELDS session_id;
|
|
177
|
+
DEFINE INDEX IF NOT EXISTS ro_memory_idx ON retrieval_outcome FIELDS memory_id;
|
|
178
|
+
DEFINE INDEX IF NOT EXISTS ro_turn_idx ON retrieval_outcome FIELDS turn_id;
|
|
179
|
+
|
|
180
|
+
-- ============================================================
|
|
181
|
+
-- ISMAR-GENT: Orchestrator Metrics
|
|
182
|
+
-- ============================================================
|
|
183
|
+
DEFINE TABLE IF NOT EXISTS orchestrator_metrics SCHEMALESS;
|
|
184
|
+
DEFINE FIELD IF NOT EXISTS session_id ON orchestrator_metrics TYPE string;
|
|
185
|
+
DEFINE FIELD IF NOT EXISTS turn_index ON orchestrator_metrics TYPE int;
|
|
186
|
+
DEFINE FIELD IF NOT EXISTS intent ON orchestrator_metrics TYPE string;
|
|
187
|
+
DEFINE FIELD IF NOT EXISTS intent_confidence ON orchestrator_metrics TYPE float;
|
|
188
|
+
DEFINE FIELD IF NOT EXISTS complexity ON orchestrator_metrics TYPE string;
|
|
189
|
+
DEFINE FIELD IF NOT EXISTS thinking_level ON orchestrator_metrics TYPE string;
|
|
190
|
+
DEFINE FIELD IF NOT EXISTS tool_limit ON orchestrator_metrics TYPE int;
|
|
191
|
+
DEFINE FIELD IF NOT EXISTS token_budget ON orchestrator_metrics TYPE int;
|
|
192
|
+
DEFINE FIELD IF NOT EXISTS actual_tool_calls ON orchestrator_metrics TYPE int;
|
|
193
|
+
DEFINE FIELD IF NOT EXISTS actual_tokens_in ON orchestrator_metrics TYPE int DEFAULT 0;
|
|
194
|
+
DEFINE FIELD IF NOT EXISTS actual_tokens_out ON orchestrator_metrics TYPE int DEFAULT 0;
|
|
195
|
+
DEFINE FIELD IF NOT EXISTS preflight_ms ON orchestrator_metrics TYPE float;
|
|
196
|
+
DEFINE FIELD IF NOT EXISTS turn_duration_ms ON orchestrator_metrics TYPE float;
|
|
197
|
+
DEFINE FIELD IF NOT EXISTS steering_candidates ON orchestrator_metrics TYPE int DEFAULT 0;
|
|
198
|
+
DEFINE FIELD IF NOT EXISTS fast_path ON orchestrator_metrics TYPE bool DEFAULT false;
|
|
199
|
+
DEFINE FIELD IF NOT EXISTS created_at ON orchestrator_metrics TYPE datetime DEFAULT time::now();
|
|
200
|
+
DEFINE INDEX IF NOT EXISTS om_session_idx ON orchestrator_metrics FIELDS session_id;
|
|
201
|
+
|
|
202
|
+
-- ============================================================
|
|
203
|
+
-- MEMORY SUBSTRATE: Compaction Checkpoints
|
|
204
|
+
-- ============================================================
|
|
205
|
+
DEFINE TABLE IF NOT EXISTS compaction_checkpoint SCHEMALESS;
|
|
206
|
+
DEFINE FIELD IF NOT EXISTS session_id ON compaction_checkpoint TYPE string;
|
|
207
|
+
DEFINE FIELD IF NOT EXISTS msg_range_start ON compaction_checkpoint TYPE int;
|
|
208
|
+
DEFINE FIELD IF NOT EXISTS msg_range_end ON compaction_checkpoint TYPE int;
|
|
209
|
+
DEFINE FIELD IF NOT EXISTS status ON compaction_checkpoint TYPE string; -- pending | complete | failed
|
|
210
|
+
DEFINE FIELD IF NOT EXISTS memory_id ON compaction_checkpoint TYPE option<string>;
|
|
211
|
+
DEFINE FIELD IF NOT EXISTS created_at ON compaction_checkpoint TYPE datetime DEFAULT time::now();
|
|
212
|
+
|
|
213
|
+
-- ============================================================
|
|
214
|
+
-- MEMORY SUBSTRATE: Utility Cache (fast historical utility lookups)
|
|
215
|
+
-- ============================================================
|
|
216
|
+
DEFINE TABLE IF NOT EXISTS memory_utility_cache SCHEMALESS;
|
|
217
|
+
DEFINE FIELD IF NOT EXISTS memory_id ON memory_utility_cache TYPE string;
|
|
218
|
+
DEFINE FIELD IF NOT EXISTS avg_utilization ON memory_utility_cache TYPE float;
|
|
219
|
+
DEFINE FIELD IF NOT EXISTS retrieval_count ON memory_utility_cache TYPE int;
|
|
220
|
+
DEFINE FIELD IF NOT EXISTS last_updated ON memory_utility_cache TYPE datetime DEFAULT time::now();
|
|
221
|
+
DEFINE INDEX IF NOT EXISTS muc_mid_idx ON memory_utility_cache FIELDS memory_id UNIQUE;
|
|
222
|
+
|
|
223
|
+
-- ============================================================
|
|
224
|
+
-- MEMORY SUBSTRATE: Turn Archive (cold storage for old turns)
|
|
225
|
+
-- ============================================================
|
|
226
|
+
DEFINE TABLE IF NOT EXISTS turn_archive SCHEMALESS;
|
|
227
|
+
|
|
228
|
+
-- Summarizes edge
|
|
229
|
+
DEFINE TABLE IF NOT EXISTS summarizes TYPE RELATION;
|
|
230
|
+
|
|
231
|
+
-- ============================================================
|
|
232
|
+
-- COGNITIVE: Causal Chain Metadata
|
|
233
|
+
-- ============================================================
|
|
234
|
+
DEFINE TABLE IF NOT EXISTS causal_chain SCHEMALESS;
|
|
235
|
+
DEFINE FIELD IF NOT EXISTS session_id ON causal_chain TYPE string;
|
|
236
|
+
DEFINE FIELD IF NOT EXISTS trigger_memory ON causal_chain TYPE string;
|
|
237
|
+
DEFINE FIELD IF NOT EXISTS outcome_memory ON causal_chain TYPE string;
|
|
238
|
+
DEFINE FIELD IF NOT EXISTS chain_type ON causal_chain TYPE string DEFAULT "debug"; -- debug | refactor | feature | fix
|
|
239
|
+
DEFINE FIELD IF NOT EXISTS success ON causal_chain TYPE bool DEFAULT true;
|
|
240
|
+
DEFINE FIELD IF NOT EXISTS confidence ON causal_chain TYPE float DEFAULT 0.5;
|
|
241
|
+
DEFINE FIELD IF NOT EXISTS description ON causal_chain TYPE option<string>;
|
|
242
|
+
DEFINE FIELD IF NOT EXISTS created_at ON causal_chain TYPE datetime DEFAULT time::now();
|
|
243
|
+
DEFINE INDEX IF NOT EXISTS cc_session_idx ON causal_chain FIELDS session_id;
|
|
244
|
+
DEFINE INDEX IF NOT EXISTS cc_confidence_idx ON causal_chain FIELDS confidence;
|
|
245
|
+
|
|
246
|
+
-- ============================================================
|
|
247
|
+
-- COGNITIVE: Skill Library (Procedural Memory)
|
|
248
|
+
-- ============================================================
|
|
249
|
+
DEFINE TABLE IF NOT EXISTS skill SCHEMALESS;
|
|
250
|
+
DEFINE FIELD IF NOT EXISTS name ON skill TYPE string;
|
|
251
|
+
DEFINE FIELD IF NOT EXISTS description ON skill TYPE string;
|
|
252
|
+
DEFINE FIELD IF NOT EXISTS embedding ON skill TYPE option<array<float>>;
|
|
253
|
+
DEFINE FIELD IF NOT EXISTS preconditions ON skill TYPE option<string>;
|
|
254
|
+
DEFINE FIELD IF NOT EXISTS steps ON skill TYPE option<array>;
|
|
255
|
+
DEFINE FIELD IF NOT EXISTS postconditions ON skill TYPE option<string>;
|
|
256
|
+
DEFINE FIELD IF NOT EXISTS success_count ON skill TYPE int DEFAULT 1;
|
|
257
|
+
DEFINE FIELD IF NOT EXISTS failure_count ON skill TYPE int DEFAULT 0;
|
|
258
|
+
DEFINE FIELD IF NOT EXISTS avg_duration_ms ON skill TYPE float DEFAULT 0.0;
|
|
259
|
+
DEFINE FIELD IF NOT EXISTS last_used ON skill TYPE option<datetime>;
|
|
260
|
+
DEFINE FIELD IF NOT EXISTS created_at ON skill TYPE datetime DEFAULT time::now();
|
|
261
|
+
DEFINE INDEX IF NOT EXISTS skill_vec_idx ON skill FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
262
|
+
|
|
263
|
+
DEFINE TABLE IF NOT EXISTS skill_from_task TYPE RELATION IN skill OUT task;
|
|
264
|
+
DEFINE TABLE IF NOT EXISTS skill_uses_concept TYPE RELATION IN skill OUT concept;
|
|
265
|
+
|
|
266
|
+
-- ============================================================
|
|
267
|
+
-- COGNITIVE: Metacognitive Reflection
|
|
268
|
+
-- ============================================================
|
|
269
|
+
DEFINE TABLE IF NOT EXISTS reflection SCHEMALESS;
|
|
270
|
+
DEFINE FIELD IF NOT EXISTS session_id ON reflection TYPE string;
|
|
271
|
+
DEFINE FIELD IF NOT EXISTS text ON reflection TYPE string;
|
|
272
|
+
DEFINE FIELD IF NOT EXISTS embedding ON reflection TYPE option<array<float>>;
|
|
273
|
+
DEFINE FIELD IF NOT EXISTS category ON reflection TYPE string DEFAULT "efficiency"; -- failure_pattern | efficiency | approach_strategy
|
|
274
|
+
DEFINE FIELD IF NOT EXISTS severity ON reflection TYPE string DEFAULT "minor"; -- minor | moderate | critical
|
|
275
|
+
DEFINE FIELD IF NOT EXISTS importance ON reflection TYPE float DEFAULT 7.0;
|
|
276
|
+
DEFINE FIELD IF NOT EXISTS access_count ON reflection TYPE int DEFAULT 0;
|
|
277
|
+
DEFINE FIELD IF NOT EXISTS created_at ON reflection TYPE datetime DEFAULT time::now();
|
|
278
|
+
DEFINE INDEX IF NOT EXISTS reflection_vec_idx ON reflection FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
279
|
+
|
|
280
|
+
DEFINE TABLE IF NOT EXISTS reflects_on TYPE RELATION IN reflection OUT session;
|
|
281
|
+
|
|
282
|
+
-- ============================================================
|
|
283
|
+
-- SUBAGENT: Tracking spawned subagents
|
|
284
|
+
-- ============================================================
|
|
285
|
+
DEFINE TABLE IF NOT EXISTS subagent SCHEMALESS;
|
|
286
|
+
DEFINE FIELD IF NOT EXISTS parent_session_id ON subagent TYPE string;
|
|
287
|
+
DEFINE FIELD IF NOT EXISTS child_session_id ON subagent TYPE option<string>;
|
|
288
|
+
DEFINE FIELD IF NOT EXISTS mode ON subagent TYPE string; -- full | incognito
|
|
289
|
+
DEFINE FIELD IF NOT EXISTS task ON subagent TYPE string;
|
|
290
|
+
DEFINE FIELD IF NOT EXISTS status ON subagent TYPE string DEFAULT "running"; -- running | completed | error
|
|
291
|
+
DEFINE FIELD IF NOT EXISTS incognito_id ON subagent TYPE option<string>;
|
|
292
|
+
DEFINE FIELD IF NOT EXISTS summary ON subagent TYPE option<string>;
|
|
293
|
+
DEFINE FIELD IF NOT EXISTS created_at ON subagent TYPE datetime DEFAULT time::now();
|
|
294
|
+
DEFINE INDEX IF NOT EXISTS sub_parent_idx ON subagent FIELDS parent_session_id;
|
|
295
|
+
|
|
296
|
+
DEFINE TABLE IF NOT EXISTS spawned TYPE RELATION IN session OUT subagent;
|
|
297
|
+
|
|
298
|
+
-- ============================================================
|
|
299
|
+
-- CONSTITUTIVE MEMORY: Monologue Trace
|
|
300
|
+
-- ============================================================
|
|
301
|
+
-- ============================================================
|
|
302
|
+
-- TIERED MEMORY: Core Memory (Tier 0 + Tier 1)
|
|
303
|
+
-- ============================================================
|
|
304
|
+
-- Tier 0: Always loaded every turn, never scored or evicted.
|
|
305
|
+
-- Tier 1: Session-pinned, loaded at session start, stays until session ends.
|
|
306
|
+
-- No vector index — these are loaded in full via SELECT, not similarity search.
|
|
307
|
+
DEFINE TABLE IF NOT EXISTS core_memory SCHEMALESS;
|
|
308
|
+
DEFINE FIELD IF NOT EXISTS text ON core_memory TYPE string;
|
|
309
|
+
DEFINE FIELD IF NOT EXISTS category ON core_memory TYPE string DEFAULT "general";
|
|
310
|
+
DEFINE FIELD IF NOT EXISTS priority ON core_memory TYPE int DEFAULT 50;
|
|
311
|
+
DEFINE FIELD IF NOT EXISTS tier ON core_memory TYPE int DEFAULT 0;
|
|
312
|
+
DEFINE FIELD IF NOT EXISTS active ON core_memory TYPE bool DEFAULT true;
|
|
313
|
+
DEFINE FIELD IF NOT EXISTS session_id ON core_memory TYPE option<string>;
|
|
314
|
+
DEFINE FIELD IF NOT EXISTS created_at ON core_memory TYPE datetime DEFAULT time::now();
|
|
315
|
+
DEFINE FIELD IF NOT EXISTS updated_at ON core_memory TYPE datetime DEFAULT time::now();
|
|
316
|
+
DEFINE INDEX IF NOT EXISTS cm_tier_idx ON core_memory FIELDS tier;
|
|
317
|
+
DEFINE INDEX IF NOT EXISTS cm_category_idx ON core_memory FIELDS category;
|
|
318
|
+
|
|
319
|
+
DEFINE TABLE IF NOT EXISTS monologue SCHEMAFULL;
|
|
320
|
+
DEFINE FIELD IF NOT EXISTS session_id ON monologue TYPE string;
|
|
321
|
+
DEFINE FIELD IF NOT EXISTS category ON monologue TYPE string;
|
|
322
|
+
DEFINE FIELD IF NOT EXISTS content ON monologue TYPE string;
|
|
323
|
+
DEFINE FIELD IF NOT EXISTS embedding ON monologue TYPE option<array<float>>;
|
|
324
|
+
DEFINE FIELD IF NOT EXISTS timestamp ON monologue TYPE datetime DEFAULT time::now();
|
|
325
|
+
DEFINE INDEX IF NOT EXISTS monologue_session ON monologue FIELDS session_id;
|
|
326
|
+
DEFINE INDEX IF NOT EXISTS monologue_category ON monologue FIELDS category;
|
|
327
|
+
DEFINE INDEX IF NOT EXISTS monologue_vec_idx ON monologue FIELDS embedding HNSW DIMENSION 1024 DIST COSINE;
|
|
328
|
+
|
|
329
|
+
-- Fibonacci resurfacing: proactive memory that fades over time
|
|
330
|
+
-- Memories flagged as surfaceable get a next_surface_at timestamp.
|
|
331
|
+
-- Each time they're surfaced and ignored, fib_index increments (longer gaps).
|
|
332
|
+
-- If user engages, fib_index resets to 0 (memory is alive again).
|
|
333
|
+
DEFINE FIELD IF NOT EXISTS surfaceable ON memory TYPE option<bool> DEFAULT false;
|
|
334
|
+
DEFINE FIELD IF NOT EXISTS next_surface_at ON memory TYPE option<datetime>;
|
|
335
|
+
DEFINE FIELD IF NOT EXISTS fib_index ON memory TYPE option<int> DEFAULT 0;
|
|
336
|
+
DEFINE FIELD IF NOT EXISTS surface_count ON memory TYPE option<int> DEFAULT 0;
|
|
337
|
+
DEFINE FIELD IF NOT EXISTS last_surfaced ON memory TYPE option<datetime>;
|
|
338
|
+
DEFINE FIELD IF NOT EXISTS last_engaged ON memory TYPE option<datetime>;
|
|
339
|
+
-- Index for efficient due-memory queries
|
|
340
|
+
DEFINE INDEX IF NOT EXISTS memory_surface_idx ON memory FIELDS surfaceable, next_surface_at;
|
|
341
|
+
DEFINE FIELD IF NOT EXISTS surface_outcome ON memory TYPE option<string>;
|
|
342
|
+
|
|
343
|
+
-- Soul: graduated identity document (singleton soul:kongbrain)
|
|
344
|
+
DEFINE TABLE IF NOT EXISTS soul SCHEMAFULL;
|
|
345
|
+
DEFINE FIELD IF NOT EXISTS agent_id ON soul TYPE string;
|
|
346
|
+
DEFINE FIELD IF NOT EXISTS working_style ON soul TYPE array<string>;
|
|
347
|
+
DEFINE FIELD IF NOT EXISTS emotional_dimensions ON soul TYPE array<object>;
|
|
348
|
+
DEFINE FIELD IF NOT EXISTS self_observations ON soul TYPE array<string>;
|
|
349
|
+
DEFINE FIELD IF NOT EXISTS earned_values ON soul TYPE array<object>;
|
|
350
|
+
DEFINE FIELD IF NOT EXISTS revisions ON soul TYPE array<object> DEFAULT [];
|
|
351
|
+
DEFINE FIELD IF NOT EXISTS created_at ON soul TYPE datetime DEFAULT time::now();
|
|
352
|
+
DEFINE FIELD IF NOT EXISTS updated_at ON soul TYPE datetime DEFAULT time::now();
|
|
353
|
+
|
|
354
|
+
-- Maturity stage: tracks stage transitions for progress notifications
|
|
355
|
+
DEFINE TABLE IF NOT EXISTS maturity_stage SCHEMALESS;
|
|
356
|
+
DEFINE FIELD IF NOT EXISTS stage ON maturity_stage TYPE string;
|
|
357
|
+
DEFINE FIELD IF NOT EXISTS volume_score ON maturity_stage TYPE float;
|
|
358
|
+
DEFINE FIELD IF NOT EXISTS quality_score ON maturity_stage TYPE float;
|
|
359
|
+
DEFINE FIELD IF NOT EXISTS met_count ON maturity_stage TYPE int;
|
|
360
|
+
DEFINE FIELD IF NOT EXISTS created_at ON maturity_stage TYPE datetime DEFAULT time::now();
|
|
361
|
+
|
|
362
|
+
-- Graduation events: tracks when soul graduation occurred for user notification
|
|
363
|
+
DEFINE TABLE IF NOT EXISTS graduation_event SCHEMALESS;
|
|
364
|
+
DEFINE FIELD IF NOT EXISTS session_id ON graduation_event TYPE string;
|
|
365
|
+
DEFINE FIELD IF NOT EXISTS acknowledged ON graduation_event TYPE bool DEFAULT false;
|
|
366
|
+
DEFINE FIELD IF NOT EXISTS acknowledged_at ON graduation_event TYPE option<datetime>;
|
|
367
|
+
DEFINE FIELD IF NOT EXISTS acknowledged_session ON graduation_event TYPE option<string>;
|
|
368
|
+
DEFINE FIELD IF NOT EXISTS quality_score ON graduation_event TYPE float;
|
|
369
|
+
DEFINE FIELD IF NOT EXISTS volume_score ON graduation_event TYPE float;
|
|
370
|
+
DEFINE FIELD IF NOT EXISTS stage ON graduation_event TYPE string;
|
|
371
|
+
DEFINE FIELD IF NOT EXISTS created_at ON graduation_event TYPE datetime DEFAULT time::now();
|
|
372
|
+
|
|
373
|
+
-- ============================================================
|
|
374
|
+
-- MIGRATIONS (must run after table definitions)
|
|
375
|
+
-- ============================================================
|
|
376
|
+
-- Drop old 768d HNSW indexes (now 1024d with BGE-M3)
|
|
377
|
+
REMOVE INDEX IF EXISTS turn_vec_idx ON turn;
|
|
378
|
+
REMOVE INDEX IF EXISTS identity_vec_idx ON identity_chunk;
|
|
379
|
+
REMOVE INDEX IF EXISTS concept_vec_idx ON concept;
|
|
380
|
+
REMOVE INDEX IF EXISTS memory_vec_idx ON memory;
|
|
381
|
+
REMOVE INDEX IF EXISTS artifact_vec_idx ON artifact;
|
|
382
|
+
-- Clear stale 768d embeddings (incompatible with new 1024d model)
|
|
383
|
+
UPDATE turn SET embedding = NONE WHERE embedding != NONE AND array::len(embedding) = 768;
|
|
384
|
+
UPDATE identity_chunk SET embedding = NONE WHERE embedding != NONE AND array::len(embedding) = 768;
|
|
385
|
+
UPDATE concept SET embedding = NONE WHERE embedding != NONE AND array::len(embedding) = 768;
|
|
386
|
+
UPDATE memory SET embedding = NONE WHERE embedding != NONE AND array::len(embedding) = 768;
|
|
387
|
+
UPDATE artifact SET embedding = NONE WHERE embedding != NONE AND array::len(embedding) = 768;
|