pi-hermes-memory 0.6.8 → 0.6.9
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/package.json +1 -1
- package/src/store/db.ts +54 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hermes-memory",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "🧠 Persistent memory + 🔍 session search + 🛡️ secret scanning for Pi. SQLite FTS5 search across every conversation, auto-consolidation, memory aging, procedural skills. 272 tests. Ported from Hermes agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
package/src/store/db.ts
CHANGED
|
@@ -51,9 +51,11 @@ export class DatabaseManager {
|
|
|
51
51
|
db.exec(SCHEMA_SQL);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// Extra safety: always ensure
|
|
55
|
-
//
|
|
54
|
+
// Extra safety: always ensure legacy memories columns exist, then migrate
|
|
55
|
+
// legacy CHECK(target IN ('memory','user')) constraints to include 'failure'.
|
|
56
56
|
this.ensureMemoriesColumns(db);
|
|
57
|
+
this.migrateLegacyMemoriesTargetConstraint(db);
|
|
58
|
+
this.rebuildMemoryFts(db);
|
|
57
59
|
|
|
58
60
|
return db;
|
|
59
61
|
}
|
|
@@ -85,6 +87,56 @@ export class DatabaseManager {
|
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
private migrateLegacyMemoriesTargetConstraint(db: Database.Database): void {
|
|
91
|
+
const tableSqlRow = db.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name='memories'").get() as { sql?: string } | undefined;
|
|
92
|
+
const tableSql = tableSqlRow?.sql ?? '';
|
|
93
|
+
if (!tableSql) return;
|
|
94
|
+
|
|
95
|
+
// Legacy schema allowed only memory/user. New schema must allow failure too.
|
|
96
|
+
const hasLegacyTargetCheck = /target\s+TEXT\s+NOT\s+NULL\s+CHECK\s*\(\s*target\s+IN\s*\(\s*'memory'\s*,\s*'user'\s*\)\s*\)/i.test(tableSql);
|
|
97
|
+
if (!hasLegacyTargetCheck) return;
|
|
98
|
+
|
|
99
|
+
const tx = db.transaction(() => {
|
|
100
|
+
db.exec('PRAGMA foreign_keys = OFF');
|
|
101
|
+
|
|
102
|
+
db.exec(`
|
|
103
|
+
CREATE TABLE memories_new (
|
|
104
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
105
|
+
project TEXT,
|
|
106
|
+
target TEXT NOT NULL CHECK (target IN ('memory', 'user', 'failure')),
|
|
107
|
+
category TEXT CHECK (category IN ('failure', 'correction', 'insight', 'preference', 'convention', 'tool-quirk')),
|
|
108
|
+
content TEXT NOT NULL,
|
|
109
|
+
failure_reason TEXT,
|
|
110
|
+
tool_state TEXT,
|
|
111
|
+
corrected_to TEXT,
|
|
112
|
+
created DATE NOT NULL,
|
|
113
|
+
last_referenced DATE NOT NULL
|
|
114
|
+
);
|
|
115
|
+
`);
|
|
116
|
+
|
|
117
|
+
db.exec(`
|
|
118
|
+
INSERT INTO memories_new (id, project, target, category, content, failure_reason, tool_state, corrected_to, created, last_referenced)
|
|
119
|
+
SELECT id, project, target, category, content, failure_reason, tool_state, corrected_to, created, last_referenced
|
|
120
|
+
FROM memories;
|
|
121
|
+
`);
|
|
122
|
+
|
|
123
|
+
db.exec('DROP TABLE memories');
|
|
124
|
+
db.exec('ALTER TABLE memories_new RENAME TO memories');
|
|
125
|
+
|
|
126
|
+
db.exec('PRAGMA foreign_keys = ON');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
tx();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private rebuildMemoryFts(db: Database.Database): void {
|
|
133
|
+
const ftsTable = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='memory_fts'").get() as { name?: string } | undefined;
|
|
134
|
+
if (!ftsTable) return;
|
|
135
|
+
|
|
136
|
+
// Keep FTS index consistent after table rebuild/migrations.
|
|
137
|
+
db.exec("INSERT INTO memory_fts(memory_fts) VALUES('rebuild')");
|
|
138
|
+
}
|
|
139
|
+
|
|
88
140
|
/**
|
|
89
141
|
* Close the database connection.
|
|
90
142
|
*/
|