whale-memory-core 0.23.0 → 0.25.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.
@@ -74,6 +74,20 @@ export function sqliteAvailable() {
74
74
  // ---------------------------------------------------------------- 表结构
75
75
 
76
76
  export function ensureSchema(db) {
77
+ // 建表必须一次成。DDL 逐条自动提交的话,第一次建库时进程被杀(或盘满)会留下"有 records、没 events"
78
+ // 的半截库,之后读路径会永远报缺表。SQLite 的 DDL 在事务里可以整组回滚,包一层就好。
79
+ db.exec('BEGIN IMMEDIATE')
80
+ try {
81
+ createTables(db)
82
+ db.exec('COMMIT')
83
+ } catch (error) {
84
+ // 回滚本身也可能失败(连接已坏):不能盖掉真正的错误
85
+ try { db.exec('ROLLBACK') } catch { }
86
+ throw error
87
+ }
88
+ }
89
+
90
+ function createTables(db) {
77
91
  db.exec(`CREATE TABLE IF NOT EXISTS records (
78
92
  id TEXT PRIMARY KEY,
79
93
  day TEXT NOT NULL,
@@ -18,6 +18,12 @@ import path from 'node:path'
18
18
  import { AsyncLocalStorage } from 'node:async_hooks'
19
19
  import { DB_FILE, requireSqlite, openDatabase, insertRecord, insertEvent, recordExists, readEvents, readRecords, kindOf } from '../sqlite-store.js'
20
20
 
21
+ // 回滚本身失败时(盘满、连接已坏这类)不能把真正的错误盖掉:包一层,原错误优先。
22
+ // 这是 crash-drills 的复审发现:ROLLBACK 没包 try 时,SQLITE_FULL 之类的二次失败会顶掉原始错误。
23
+ function rollbackQuiet(db, sql = 'ROLLBACK') {
24
+ try { db.exec(sql) } catch { }
25
+ }
26
+
21
27
  export class SqliteBackend {
22
28
  #als = new AsyncLocalStorage()
23
29
  #tail = Promise.resolve()
@@ -73,8 +79,8 @@ export class SqliteBackend {
73
79
  db.exec('RELEASE ' + sp)
74
80
  return result
75
81
  } catch (error) {
76
- db.exec('ROLLBACK TO ' + sp)
77
- db.exec('RELEASE ' + sp)
82
+ rollbackQuiet(db, 'ROLLBACK TO ' + sp)
83
+ rollbackQuiet(db, 'RELEASE ' + sp)
78
84
  throw error
79
85
  }
80
86
  }
@@ -84,7 +90,7 @@ export class SqliteBackend {
84
90
  db.exec('COMMIT')
85
91
  return result
86
92
  } catch (error) {
87
- db.exec('ROLLBACK')
93
+ rollbackQuiet(db)
88
94
  throw error
89
95
  }
90
96
  }
@@ -174,8 +180,8 @@ export class SqliteBackend {
174
180
  db.exec('RELEASE ' + sp)
175
181
  return result
176
182
  } catch (error) {
177
- db.exec('ROLLBACK TO ' + sp)
178
- db.exec('RELEASE ' + sp)
183
+ rollbackQuiet(db, 'ROLLBACK TO ' + sp)
184
+ rollbackQuiet(db, 'RELEASE ' + sp)
179
185
  throw error
180
186
  }
181
187
  }
@@ -187,7 +193,7 @@ export class SqliteBackend {
187
193
  db.exec('COMMIT')
188
194
  return result
189
195
  } catch (error) {
190
- db.exec('ROLLBACK')
196
+ rollbackQuiet(db)
191
197
  throw error
192
198
  }
193
199
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whale-memory-core",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "description": "Self-layer autobiographical memory core: then / later, append-only. Vault, evidence and consolidation live in the QQ Agent plugin.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -17,6 +17,10 @@
17
17
  "types": "./lib/action-source.d.ts",
18
18
  "default": "./lib/action-source.js"
19
19
  },
20
+ "./hybrid-recall": {
21
+ "types": "./lib/hybrid-recall.d.ts",
22
+ "default": "./lib/hybrid-recall.js"
23
+ },
20
24
  "./self-experience": {
21
25
  "types": "./lib/self-experience.d.ts",
22
26
  "default": "./lib/self-experience.js"