cortex-mcp 2.7.1 → 2.7.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.
- package/dist/db/database.js +54 -3
- package/dist/db/memory-store.js +36 -8
- package/package.json +1 -1
package/dist/db/database.js
CHANGED
|
@@ -44,7 +44,7 @@ exports.CognitiveDatabase = void 0;
|
|
|
44
44
|
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const fs = __importStar(require("fs"));
|
|
47
|
-
const SCHEMA_VERSION =
|
|
47
|
+
const SCHEMA_VERSION = 2;
|
|
48
48
|
const SCHEMA_SQL = `
|
|
49
49
|
-- ═══ SETTINGS ═══
|
|
50
50
|
PRAGMA journal_mode=WAL;
|
|
@@ -219,9 +219,60 @@ class CognitiveDatabase {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
migrate(fromVersion) {
|
|
222
|
-
|
|
223
|
-
//
|
|
222
|
+
console.log(`[cortex-mcp] Migrating database from schema v${fromVersion} to v${SCHEMA_VERSION}...`);
|
|
223
|
+
// ─── Migration to v2: Add missing columns added after v1.0.4 ─────────────
|
|
224
|
+
if (fromVersion < 2) {
|
|
225
|
+
const existingCols = this.db.pragma('table_info(memory_units)').map((c) => c.name);
|
|
226
|
+
// created_at — required by git-hooks, undo_last, memory ordering
|
|
227
|
+
if (!existingCols.includes('created_at')) {
|
|
228
|
+
this.db.exec('ALTER TABLE memory_units ADD COLUMN created_at INTEGER NOT NULL DEFAULT 0');
|
|
229
|
+
// Back-fill with timestamp value for existing rows
|
|
230
|
+
this.db.exec('UPDATE memory_units SET created_at = timestamp WHERE created_at = 0');
|
|
231
|
+
console.log('[cortex-mcp] Migration: added created_at column');
|
|
232
|
+
}
|
|
233
|
+
// access_count — required by memory ranker
|
|
234
|
+
if (!existingCols.includes('access_count')) {
|
|
235
|
+
this.db.exec('ALTER TABLE memory_units ADD COLUMN access_count INTEGER DEFAULT 0');
|
|
236
|
+
console.log('[cortex-mcp] Migration: added access_count column');
|
|
237
|
+
}
|
|
238
|
+
// last_accessed — required by touch()
|
|
239
|
+
if (!existingCols.includes('last_accessed')) {
|
|
240
|
+
this.db.exec('ALTER TABLE memory_units ADD COLUMN last_accessed INTEGER');
|
|
241
|
+
console.log('[cortex-mcp] Migration: added last_accessed column');
|
|
242
|
+
}
|
|
243
|
+
// confidence — required by confidence decay
|
|
244
|
+
if (!existingCols.includes('confidence')) {
|
|
245
|
+
this.db.exec('ALTER TABLE memory_units ADD COLUMN confidence REAL DEFAULT 0.5');
|
|
246
|
+
console.log('[cortex-mcp] Migration: added confidence column');
|
|
247
|
+
}
|
|
248
|
+
// importance — required by context builder ordering
|
|
249
|
+
if (!existingCols.includes('importance')) {
|
|
250
|
+
this.db.exec('ALTER TABLE memory_units ADD COLUMN importance REAL DEFAULT 0.5');
|
|
251
|
+
console.log('[cortex-mcp] Migration: added importance column');
|
|
252
|
+
}
|
|
253
|
+
// tags — required by pin/unpin
|
|
254
|
+
if (!existingCols.includes('tags')) {
|
|
255
|
+
this.db.exec("ALTER TABLE memory_units ADD COLUMN tags TEXT DEFAULT '[]'");
|
|
256
|
+
console.log('[cortex-mcp] Migration: added tags column');
|
|
257
|
+
}
|
|
258
|
+
// Ensure FTS table exists (may be missing in very old DBs)
|
|
259
|
+
const hasFTS = this.db
|
|
260
|
+
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='memory_fts'")
|
|
261
|
+
.get();
|
|
262
|
+
if (!hasFTS) {
|
|
263
|
+
this.db.exec(`
|
|
264
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(
|
|
265
|
+
id UNINDEXED, intent, action, reason, impact, tags,
|
|
266
|
+
content='memory_units', content_rowid='rowid',
|
|
267
|
+
tokenize='porter unicode61'
|
|
268
|
+
);
|
|
269
|
+
INSERT INTO memory_fts(memory_fts) VALUES('rebuild');
|
|
270
|
+
`);
|
|
271
|
+
console.log('[cortex-mcp] Migration: rebuilt FTS index');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
224
274
|
this.db.prepare('UPDATE schema_version SET version = ?').run(SCHEMA_VERSION);
|
|
275
|
+
console.log(`[cortex-mcp] Database migration complete. Schema is now v${SCHEMA_VERSION}.`);
|
|
225
276
|
}
|
|
226
277
|
/** Get the raw database connection for direct queries */
|
|
227
278
|
get connection() {
|
package/dist/db/memory-store.js
CHANGED
|
@@ -205,14 +205,42 @@ class MemoryStore {
|
|
|
205
205
|
}
|
|
206
206
|
/** Full-text search via FTS5 */
|
|
207
207
|
searchFTS(query, limit = 20) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
208
|
+
// Sanitize: remove FTS5 special characters that cause syntax errors
|
|
209
|
+
const sanitized = query
|
|
210
|
+
.replace(/["*():^~]/g, ' ') // strip FTS5 operators
|
|
211
|
+
.replace(/\b(AND|OR|NOT)\b/g, ' ') // strip boolean keywords
|
|
212
|
+
.replace(/\s+/g, ' ')
|
|
213
|
+
.trim();
|
|
214
|
+
// If nothing left after sanitization, return empty
|
|
215
|
+
if (!sanitized)
|
|
216
|
+
return [];
|
|
217
|
+
try {
|
|
218
|
+
const rows = this.db
|
|
219
|
+
.prepare(`SELECT m.*, fts.rank FROM memory_fts fts JOIN memory_units m ON m.id = fts.id WHERE memory_fts MATCH ? AND m.is_active = 1 ORDER BY fts.rank LIMIT ?`)
|
|
220
|
+
.all(sanitized, limit);
|
|
221
|
+
return rows.map((row) => ({
|
|
222
|
+
memory: this.rowToMemory(row),
|
|
223
|
+
score: -row.rank, // FTS5 rank is negative (lower = better)
|
|
224
|
+
matchMethod: 'fts',
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
// FTS failed (index corrupt or tricky query) — fall back to LIKE search
|
|
229
|
+
try {
|
|
230
|
+
const likeQuery = `%${sanitized.split(' ').filter(Boolean)[0] || sanitized}%`;
|
|
231
|
+
const rows = this.db
|
|
232
|
+
.prepare(`SELECT * FROM memory_units WHERE is_active = 1 AND (intent LIKE ? OR action LIKE ? OR reason LIKE ?) LIMIT ?`)
|
|
233
|
+
.all(likeQuery, likeQuery, likeQuery, limit);
|
|
234
|
+
return rows.map((row) => ({
|
|
235
|
+
memory: this.rowToMemory(row),
|
|
236
|
+
score: 0.5,
|
|
237
|
+
matchMethod: 'fts',
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
216
244
|
}
|
|
217
245
|
// ═══ VECTOR SEARCH (JS cosine similarity — M1 fallback) ═══
|
|
218
246
|
/** Store a vector embedding */
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "cortex-mcp",
|
|
3
3
|
"displayName": "Cortex MCP Server",
|
|
4
4
|
"description": "Persistent memory for AI coding assistants. Injects context from past sessions into every LLM request.",
|
|
5
|
-
"version": "2.7.
|
|
5
|
+
"version": "2.7.3",
|
|
6
6
|
"publisher": "cortex",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"engines": {
|