sage-mem 2.22.0 → 2.23.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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/memory/access.js +7 -18
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
**Cross-session memory for DeepSeek Harness — plain markdown files, no database, no worker.**
|
|
14
14
|
|
|
15
|
-
**Current release: `2.
|
|
15
|
+
**Current release: `2.23.0`** — the npm badge above is the dynamic source of truth. **Contract baseline: `1.0.0`** — the first stable release, whose public commitments, the capability boundaries and the list of things it explicitly cannot do are frozen in the
|
|
16
16
|
[frozen contract](https://github.com/gezi-wen/sage-mem/blob/main/docs/1.0.0-contract.md).
|
|
17
17
|
|
|
18
18
|
If it is useful to you, a Star is the most direct feedback.
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
> File-based cross-session memory for DeepSeek Harness — every memory is a plain markdown file you can open, edit and delete. No database, no worker, no port.
|
|
16
16
|
|
|
17
|
-
**当前发布版本:`2.
|
|
17
|
+
**当前发布版本:`2.23.0`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
|
|
18
18
|
[契约冻结](https://github.com/gezi-wen/sage-mem/blob/main/docs/1.0.0-contract.md)。
|
|
19
19
|
|
|
20
20
|
如果它对你有用,给个 Star 是最直接的反馈。
|
package/lib/memory/access.js
CHANGED
|
@@ -55,17 +55,16 @@ export const ACCESS_SCHEMA_VERSION = 2
|
|
|
55
55
|
* 旧格式的裸数字语义是「最近一次被注入」,正好对应 v2 的 `injected`。
|
|
56
56
|
*/
|
|
57
57
|
export function ledgerEntry(value) {
|
|
58
|
-
if (Number.isFinite(value)) return { injected: value, read: 0,
|
|
58
|
+
if (Number.isFinite(value)) return { injected: value, read: 0, readRev: '' }
|
|
59
59
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
60
60
|
return {
|
|
61
61
|
injected: Number.isFinite(value.injected) ? value.injected : 0,
|
|
62
|
-
// `read` / `
|
|
62
|
+
// `read` / `readRev` 是 0.9.18 才有的字段:**只记不参与排序**(决定 D3)。
|
|
63
63
|
read: Number.isFinite(value.read) ? value.read : 0,
|
|
64
|
-
use: Number.isFinite(value.use) ? value.use : 0,
|
|
65
64
|
readRev: typeof value.readRev === 'string' ? value.readRev : '',
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
return { injected: 0, read: 0,
|
|
67
|
+
return { injected: 0, read: 0, readRev: '' }
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
/** 条目里「最近一次被注入」的时间戳(0 = 没有)。`idleDays` 与归档候选都走它。 */
|
|
@@ -138,7 +137,6 @@ function scheduleLeaseRetry() {
|
|
|
138
137
|
*
|
|
139
138
|
* 各字段的合并语义**不一样**,写错就会丢数据:
|
|
140
139
|
* - `injected` / `read`:取**较晚**的(它们是「最近一次」);
|
|
141
|
-
* - `use`:**累加**(它是「采用了几次」,不是时间戳);
|
|
142
140
|
* - `readRev`:跟着 `read` 走(谁把 `read` 推新,就用谁那份 revision)。
|
|
143
141
|
*/
|
|
144
142
|
function record(name, patch) {
|
|
@@ -149,7 +147,6 @@ function record(name, patch) {
|
|
|
149
147
|
injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
|
|
150
148
|
read,
|
|
151
149
|
readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
|
|
152
|
-
use: (cur.use ?? 0) + (patch.use ?? 0),
|
|
153
150
|
})
|
|
154
151
|
scheduleFlush()
|
|
155
152
|
}
|
|
@@ -174,11 +171,6 @@ export function recordRead(name, revision, at = Date.now()) {
|
|
|
174
171
|
record(name, { read: at, readRev: typeof revision === 'string' ? revision : '' })
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
/** 记一次「明确采用」的增量。自报数据,**只记不参与排序**。 */
|
|
178
|
-
export function recordUse(name) {
|
|
179
|
-
record(name, { use: 1 })
|
|
180
|
-
}
|
|
181
|
-
|
|
182
174
|
function scheduleFlush() {
|
|
183
175
|
if (flushTimer) return
|
|
184
176
|
const wait = Math.max(0, ACCESS_FLUSH_INTERVAL_MS - (Date.now() - lastFlushAt))
|
|
@@ -191,7 +183,7 @@ function scheduleFlush() {
|
|
|
191
183
|
}
|
|
192
184
|
|
|
193
185
|
/**
|
|
194
|
-
* 读盘上的台账,**归一成一种形状**:`{ 文件名 → {injected, read,
|
|
186
|
+
* 读盘上的台账,**归一成一种形状**:`{ 文件名 → {injected, read, readRev} }`。
|
|
195
187
|
*
|
|
196
188
|
* 读不到 / JSON 坏 / 不是对象 / 两代格式都不是 → 一律当空台账(降级成「不知道」,
|
|
197
189
|
* 而不是把已有数据判成损坏丢掉 —— 它是自动归档阈值唯一的数据源)。
|
|
@@ -296,23 +288,21 @@ async function flushAccessLocked(memoryDir) {
|
|
|
296
288
|
pending = new Map()
|
|
297
289
|
const onDisk = await readAccessLedger(file)
|
|
298
290
|
// 逐字段合并(`readAccessLedger` 已经归一成 v2 条目,不用再分代)。
|
|
299
|
-
// 语义与内存里的 `record` 一致:时间戳取较晚、`
|
|
291
|
+
// 语义与内存里的 `record` 一致:时间戳取较晚、`readRev` 跟 `read` 走。
|
|
300
292
|
for (const [name, patch] of batch) {
|
|
301
|
-
const cur = onDisk[name] ?? { injected: 0, read: 0,
|
|
293
|
+
const cur = onDisk[name] ?? { injected: 0, read: 0, readRev: '' }
|
|
302
294
|
const read = Math.max(cur.read ?? 0, patch.read ?? 0)
|
|
303
295
|
onDisk[name] = {
|
|
304
296
|
injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
|
|
305
297
|
read,
|
|
306
298
|
readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
|
|
307
|
-
use: (cur.use ?? 0) + (patch.use ?? 0),
|
|
308
299
|
}
|
|
309
300
|
}
|
|
310
301
|
if (alive) {
|
|
311
302
|
for (const key of Object.keys(onDisk)) {
|
|
312
303
|
if (alive.has(key)) continue
|
|
313
304
|
// alive 是抢锁前的快照:这期间别的实例可能刚建了同名文件。持锁后再按单文件
|
|
314
|
-
// 确认一次(根目录 + archive/),存在就保留,不存在才回收。
|
|
315
|
-
// 这里根本不用它当判据。
|
|
305
|
+
// 确认一次(根目录 + archive/),存在就保留,不存在才回收。
|
|
316
306
|
const exists = await stat(join(memoryDir, key)).then(
|
|
317
307
|
() => true,
|
|
318
308
|
(err) => err?.code !== 'ENOENT',
|
|
@@ -337,7 +327,6 @@ async function flushAccessLocked(memoryDir) {
|
|
|
337
327
|
injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
|
|
338
328
|
read,
|
|
339
329
|
readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
|
|
340
|
-
use: (cur.use ?? 0) + (patch.use ?? 0),
|
|
341
330
|
})
|
|
342
331
|
}
|
|
343
332
|
if (debugEnabled()) console.warn(`sage-mem: access ledger flush failed: ${err?.message ?? err}`)
|
package/package.json
CHANGED