linksee-memory 0.12.0 → 0.12.1
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/README.md +1007 -1004
- package/dist/db/migrate.js +28 -28
- package/dist/db/schema.sql +461 -461
- package/dist/lib/drift-anchors.js +3 -3
- package/dist/lib/drift-detection.js +20 -20
- package/dist/lib/drift-view.js +16 -16
- package/dist/lib/guard.js +28 -28
- package/dist/lib/map-import.js +17 -17
- package/dist/lib/truth-engine.js +13 -13
- package/dist/mcp/prompts.js +58 -58
- package/dist/mcp/resources.js +7 -7
- package/dist/mcp/sampling.js +20 -20
- package/dist/mcp/server.js +130 -130
- package/package.json +96 -95
package/dist/db/migrate.js
CHANGED
|
@@ -70,11 +70,11 @@ export function runMigrations(db) {
|
|
|
70
70
|
// v3 → v4: rebuild memories_fts with trigram tokenizer for JP/CJK support.
|
|
71
71
|
// Only runs when upgrading an existing DB from schema v1-3.
|
|
72
72
|
if (currentVersion > 0 && currentVersion < 4) {
|
|
73
|
-
db.exec(`
|
|
74
|
-
DROP TRIGGER IF EXISTS trg_memories_fts_ai;
|
|
75
|
-
DROP TRIGGER IF EXISTS trg_memories_fts_ad;
|
|
76
|
-
DROP TRIGGER IF EXISTS trg_memories_fts_au;
|
|
77
|
-
DROP TABLE IF EXISTS memories_fts;
|
|
73
|
+
db.exec(`
|
|
74
|
+
DROP TRIGGER IF EXISTS trg_memories_fts_ai;
|
|
75
|
+
DROP TRIGGER IF EXISTS trg_memories_fts_ad;
|
|
76
|
+
DROP TRIGGER IF EXISTS trg_memories_fts_au;
|
|
77
|
+
DROP TABLE IF EXISTS memories_fts;
|
|
78
78
|
`);
|
|
79
79
|
}
|
|
80
80
|
// v4 → v5: add normalized_name column BEFORE schema.sql runs,
|
|
@@ -118,9 +118,9 @@ export function runMigrations(db) {
|
|
|
118
118
|
db.exec('ALTER TABLE memories ADD COLUMN thread_id TEXT');
|
|
119
119
|
}
|
|
120
120
|
// Backfill thread_id from content JSON session_id for existing memories
|
|
121
|
-
db.exec(`
|
|
122
|
-
UPDATE memories SET thread_id = json_extract(content, '$.session_id')
|
|
123
|
-
WHERE thread_id IS NULL AND json_valid(content) AND json_extract(content, '$.session_id') IS NOT NULL
|
|
121
|
+
db.exec(`
|
|
122
|
+
UPDATE memories SET thread_id = json_extract(content, '$.session_id')
|
|
123
|
+
WHERE thread_id IS NULL AND json_valid(content) AND json_extract(content, '$.session_id') IS NOT NULL
|
|
124
124
|
`);
|
|
125
125
|
}
|
|
126
126
|
// v8 → v9: ProjectCoreNode — extend drift_anchors into the Current Truth Map node.
|
|
@@ -221,12 +221,12 @@ function migrateV5EntityNormalization(db) {
|
|
|
221
221
|
}
|
|
222
222
|
})();
|
|
223
223
|
// 4. Auto-merge duplicate entities (same kind + normalized_name)
|
|
224
|
-
const dupes = db.prepare(`
|
|
225
|
-
SELECT kind, normalized_name, GROUP_CONCAT(id) as ids
|
|
226
|
-
FROM entities
|
|
227
|
-
WHERE normalized_name IS NOT NULL
|
|
228
|
-
GROUP BY kind, normalized_name
|
|
229
|
-
HAVING COUNT(*) > 1
|
|
224
|
+
const dupes = db.prepare(`
|
|
225
|
+
SELECT kind, normalized_name, GROUP_CONCAT(id) as ids
|
|
226
|
+
FROM entities
|
|
227
|
+
WHERE normalized_name IS NOT NULL
|
|
228
|
+
GROUP BY kind, normalized_name
|
|
229
|
+
HAVING COUNT(*) > 1
|
|
230
230
|
`).all();
|
|
231
231
|
if (dupes.length > 0) {
|
|
232
232
|
console.log(`[linksee-memory] v5 migration: merging ${dupes.length} duplicate entity clusters`);
|
|
@@ -247,12 +247,12 @@ function mergeEntityCluster(db, ids) {
|
|
|
247
247
|
if (ids.length < 2)
|
|
248
248
|
return;
|
|
249
249
|
// Score each entity: prefer most memories, then has canonical_key, then lowest id
|
|
250
|
-
const rows = db.prepare(`
|
|
251
|
-
SELECT e.id, e.name, e.canonical_key, COUNT(m.id) as mem_count
|
|
252
|
-
FROM entities e LEFT JOIN memories m ON m.entity_id = e.id
|
|
253
|
-
WHERE e.id IN (${ids.map(() => '?').join(',')})
|
|
254
|
-
GROUP BY e.id
|
|
255
|
-
ORDER BY mem_count DESC, (e.canonical_key IS NOT NULL) DESC, e.id ASC
|
|
250
|
+
const rows = db.prepare(`
|
|
251
|
+
SELECT e.id, e.name, e.canonical_key, COUNT(m.id) as mem_count
|
|
252
|
+
FROM entities e LEFT JOIN memories m ON m.entity_id = e.id
|
|
253
|
+
WHERE e.id IN (${ids.map(() => '?').join(',')})
|
|
254
|
+
GROUP BY e.id
|
|
255
|
+
ORDER BY mem_count DESC, (e.canonical_key IS NOT NULL) DESC, e.id ASC
|
|
256
256
|
`).all(...ids);
|
|
257
257
|
const keep = rows[0];
|
|
258
258
|
const mergeIds = rows.slice(1).map(r => r.id);
|
|
@@ -273,16 +273,16 @@ function mergeEntityCluster(db, ids) {
|
|
|
273
273
|
db.prepare('UPDATE events SET entity_id = ? WHERE entity_id = ?').run(keep.id, mid);
|
|
274
274
|
// Reassign edges (both directions)
|
|
275
275
|
// Handle UNIQUE constraint: delete duplicates first
|
|
276
|
-
db.prepare(`
|
|
277
|
-
DELETE FROM edges WHERE from_id = ? AND EXISTS (
|
|
278
|
-
SELECT 1 FROM edges e2 WHERE e2.from_id = ? AND e2.to_id = edges.to_id AND e2.relation = edges.relation
|
|
279
|
-
)
|
|
276
|
+
db.prepare(`
|
|
277
|
+
DELETE FROM edges WHERE from_id = ? AND EXISTS (
|
|
278
|
+
SELECT 1 FROM edges e2 WHERE e2.from_id = ? AND e2.to_id = edges.to_id AND e2.relation = edges.relation
|
|
279
|
+
)
|
|
280
280
|
`).run(mid, keep.id);
|
|
281
281
|
db.prepare('UPDATE edges SET from_id = ? WHERE from_id = ?').run(keep.id, mid);
|
|
282
|
-
db.prepare(`
|
|
283
|
-
DELETE FROM edges WHERE to_id = ? AND EXISTS (
|
|
284
|
-
SELECT 1 FROM edges e2 WHERE e2.to_id = ? AND e2.from_id = edges.from_id AND e2.relation = edges.relation
|
|
285
|
-
)
|
|
282
|
+
db.prepare(`
|
|
283
|
+
DELETE FROM edges WHERE to_id = ? AND EXISTS (
|
|
284
|
+
SELECT 1 FROM edges e2 WHERE e2.to_id = ? AND e2.from_id = edges.from_id AND e2.relation = edges.relation
|
|
285
|
+
)
|
|
286
286
|
`).run(mid, keep.id);
|
|
287
287
|
db.prepare('UPDATE edges SET to_id = ? WHERE to_id = ?').run(keep.id, mid);
|
|
288
288
|
// Reassign consolidations
|