@meowlynxsea/koi 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/dist/schema.sql +171 -0
  2. package/package.json +2 -2
@@ -0,0 +1,171 @@
1
+ -- ============================================================
2
+ -- Cat's Context Engine — Database Schema (bun:sqlite)
3
+ -- ============================================================
4
+
5
+ CREATE TABLE IF NOT EXISTS _schema_version (
6
+ version INTEGER PRIMARY KEY,
7
+ applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
8
+ );
9
+
10
+ -- 节点表:概念实体,UUID 跨版本不变
11
+ CREATE TABLE IF NOT EXISTS nodes (
12
+ uuid TEXT PRIMARY KEY,
13
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
14
+ );
15
+
16
+ -- 根节点:所有顶层路径的 parent_uuid
17
+ INSERT OR IGNORE INTO nodes (uuid) VALUES ('00000000-0000-0000-0000-000000000000');
18
+
19
+ -- 记忆表:节点的内容版本
20
+ CREATE TABLE IF NOT EXISTS memories (
21
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
22
+ node_uuid TEXT REFERENCES nodes(uuid),
23
+ content TEXT NOT NULL,
24
+ deprecated INTEGER DEFAULT 0,
25
+ migrated_to INTEGER,
26
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
27
+ );
28
+
29
+ -- 边表:父→子关系,携带元数据
30
+ CREATE TABLE IF NOT EXISTS edges (
31
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
32
+ parent_uuid TEXT NOT NULL REFERENCES nodes(uuid),
33
+ child_uuid TEXT NOT NULL REFERENCES nodes(uuid),
34
+ name TEXT NOT NULL,
35
+ priority INTEGER DEFAULT 0,
36
+ disclosure TEXT,
37
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
38
+ UNIQUE(parent_uuid, child_uuid)
39
+ );
40
+
41
+ -- 路径表:URI 路由缓存 (namespace, domain, path) → edge
42
+ CREATE TABLE IF NOT EXISTS paths (
43
+ rowid INTEGER PRIMARY KEY AUTOINCREMENT,
44
+ namespace TEXT NOT NULL DEFAULT '',
45
+ domain TEXT NOT NULL DEFAULT 'code',
46
+ path TEXT NOT NULL,
47
+ edge_id INTEGER REFERENCES edges(id),
48
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
49
+ UNIQUE(namespace, domain, path)
50
+ );
51
+
52
+ -- 词汇表关键词绑定
53
+ CREATE TABLE IF NOT EXISTS glossary_keywords (
54
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
55
+ keyword TEXT NOT NULL,
56
+ node_uuid TEXT NOT NULL REFERENCES nodes(uuid) ON DELETE CASCADE,
57
+ namespace TEXT NOT NULL DEFAULT '',
58
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
59
+ UNIQUE(keyword, node_uuid, namespace)
60
+ );
61
+
62
+ -- 上下文向量表:用于混合搜索(关键词 + 语义)
63
+ CREATE TABLE IF NOT EXISTS context_vectors (
64
+ rowid INTEGER PRIMARY KEY AUTOINCREMENT,
65
+ namespace TEXT NOT NULL DEFAULT '',
66
+ domain TEXT NOT NULL DEFAULT 'code',
67
+ path TEXT NOT NULL,
68
+ node_uuid TEXT NOT NULL REFERENCES nodes(uuid) ON DELETE CASCADE,
69
+ memory_id INTEGER NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
70
+ uri TEXT NOT NULL,
71
+ content TEXT NOT NULL,
72
+ disclosure TEXT,
73
+ search_terms TEXT NOT NULL DEFAULT '',
74
+ priority INTEGER NOT NULL DEFAULT 0,
75
+ embedding BLOB,
76
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
77
+ UNIQUE(namespace, domain, path)
78
+ );
79
+
80
+ -- FTS5 全文索引(关键词搜索)
81
+ CREATE VIRTUAL TABLE IF NOT EXISTS context_vectors_fts USING fts5(
82
+ namespace, domain, path, uri, content, disclosure, search_terms,
83
+ content='context_vectors',
84
+ content_rowid='rowid'
85
+ );
86
+
87
+ -- 辅助索引
88
+ CREATE INDEX IF NOT EXISTS idx_memories_node ON memories(node_uuid, deprecated);
89
+ CREATE INDEX IF NOT EXISTS idx_edges_parent ON edges(parent_uuid);
90
+ CREATE INDEX IF NOT EXISTS idx_edges_child ON edges(child_uuid);
91
+ CREATE INDEX IF NOT EXISTS idx_paths_ns_domain ON paths(namespace, domain);
92
+ CREATE INDEX IF NOT EXISTS idx_glossary_kw ON glossary_keywords(keyword, namespace);
93
+
94
+ -- Code-Memory 关联表
95
+ CREATE TABLE IF NOT EXISTS code_links (
96
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
97
+ memory_node_uuid TEXT NOT NULL REFERENCES nodes(uuid) ON DELETE CASCADE,
98
+ code_node_uuid TEXT NOT NULL REFERENCES nodes(uuid) ON DELETE CASCADE,
99
+ namespace TEXT NOT NULL DEFAULT '',
100
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
101
+ UNIQUE(memory_node_uuid, code_node_uuid, namespace)
102
+ );
103
+
104
+ CREATE INDEX IF NOT EXISTS idx_code_links_memory ON code_links(memory_node_uuid, namespace);
105
+ CREATE INDEX IF NOT EXISTS idx_code_links_code ON code_links(code_node_uuid, namespace);
106
+ CREATE INDEX IF NOT EXISTS idx_context_vectors_node ON context_vectors(node_uuid, namespace);
107
+
108
+ -- ============================================================
109
+ -- Phase 1: Brain Memory System — Associative, Evidential, Dynamic
110
+ -- ============================================================
111
+
112
+ -- 联想网络:替代简陋的 code_links,支持类型、权重、Hebbian 学习
113
+ CREATE TABLE IF NOT EXISTS associative_edges (
114
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
115
+ source_uuid TEXT NOT NULL REFERENCES nodes(uuid),
116
+ target_uuid TEXT NOT NULL REFERENCES nodes(uuid),
117
+ edge_type TEXT NOT NULL DEFAULT 'associates',
118
+ weight REAL DEFAULT 0.5,
119
+ confidence REAL DEFAULT 1.0,
120
+ evidence TEXT,
121
+ activation_count INTEGER DEFAULT 0,
122
+ last_activated_at DATETIME,
123
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
124
+ UNIQUE(source_uuid, target_uuid, edge_type)
125
+ );
126
+ CREATE INDEX IF NOT EXISTS idx_assoc_source ON associative_edges(source_uuid, edge_type, weight);
127
+ CREATE INDEX IF NOT EXISTS idx_assoc_target ON associative_edges(target_uuid, edge_type, weight);
128
+ CREATE INDEX IF NOT EXISTS idx_assoc_activated ON associative_edges(last_activated_at);
129
+
130
+ -- 概念证据:concept 必须指向支撑它的 code/episode
131
+ CREATE TABLE IF NOT EXISTS concept_evidence (
132
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
133
+ concept_node_uuid TEXT NOT NULL REFERENCES nodes(uuid),
134
+ evidence_node_uuid TEXT NOT NULL REFERENCES nodes(uuid),
135
+ evidence_type TEXT NOT NULL DEFAULT 'signature_match',
136
+ strength REAL DEFAULT 1.0,
137
+ verified_at DATETIME,
138
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
139
+ UNIQUE(concept_node_uuid, evidence_node_uuid, evidence_type)
140
+ );
141
+ CREATE INDEX IF NOT EXISTS idx_ce_concept ON concept_evidence(concept_node_uuid, strength);
142
+ CREATE INDEX IF NOT EXISTS idx_ce_evidence ON concept_evidence(evidence_node_uuid);
143
+
144
+ -- 节点激活状态:决定工作记忆准入
145
+ CREATE TABLE IF NOT EXISTS node_activation (
146
+ node_uuid TEXT PRIMARY KEY REFERENCES nodes(uuid),
147
+ baseline_activation REAL DEFAULT 0.0,
148
+ current_activation REAL DEFAULT 0.0,
149
+ total_activation_count INTEGER DEFAULT 0,
150
+ last_activated_at DATETIME,
151
+ last_decayed_at DATETIME,
152
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
153
+ );
154
+
155
+ -- 情景记忆:记录"什么时候、在什么情境下"想起了某个记忆
156
+ CREATE TABLE IF NOT EXISTS memory_episodes (
157
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
158
+ node_uuid TEXT NOT NULL REFERENCES nodes(uuid),
159
+ episode_type TEXT NOT NULL,
160
+ trigger_uri TEXT,
161
+ trigger_text TEXT,
162
+ working_memory_snapshot TEXT,
163
+ embedding BLOB,
164
+ activation_strength REAL DEFAULT 1.0,
165
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
166
+ );
167
+ CREATE INDEX IF NOT EXISTS idx_episodes_node ON memory_episodes(node_uuid, created_at);
168
+ CREATE INDEX IF NOT EXISTS idx_episodes_type ON memory_episodes(episode_type, created_at);
169
+
170
+ -- Schema version marker
171
+ INSERT OR IGNORE INTO _schema_version (version) VALUES (1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meowlynxsea/koi",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "A coding agent built on Pi SDK with TUI + Bun runtime",
5
5
  "module": "src/main.tsx",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "scripts": {
35
35
  "dev": "bun run src/main.tsx",
36
36
  "postinstall": "bun run scripts/postinstall.ts",
37
- "build": "bun build src/main.tsx --outdir dist --target bun && cp node_modules/@opentui/core/parser.worker.js dist/ && cp -r node_modules/@opentui/core/assets dist/opentui-assets && mkdir -p dist/cce-frontend && cp -r src/cce/web/frontend/dist/* dist/cce-frontend/ && mkdir -p dist/onnx-bin/napi-v3/darwin/arm64 && cp node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/* dist/onnx-bin/napi-v3/darwin/arm64/ && bun run scripts/postbuild.ts",
37
+ "build": "bun build src/main.tsx --outdir dist --target bun && cp node_modules/@opentui/core/parser.worker.js dist/ && cp -r node_modules/@opentui/core/assets dist/opentui-assets && mkdir -p dist/cce-frontend && cp -r src/cce/web/frontend/dist/* dist/cce-frontend/ && mkdir -p dist/onnx-bin/napi-v3/darwin/arm64 && cp node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/* dist/onnx-bin/napi-v3/darwin/arm64/ && cp src/cce/core/schema.sql dist/ && bun run scripts/postbuild.ts",
38
38
  "check": "tsc --noEmit",
39
39
  "lint": "eslint src/",
40
40
  "lint:fix": "eslint src/ --fix"