sage-mem 2.22.0 → 2.23.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.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.22.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
15
+ **Current release: `2.23.1`** — 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.22.0`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.23.1`** —— 顶部 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 是最直接的反馈。
@@ -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, use: 0, readRev: '' }
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` / `use` / `readRev` 是 0.9.18 才有的字段:**只记不参与排序**(决定 D3)。
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, use: 0, readRev: '' }
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, use, readRev} }`。
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` 一致:时间戳取较晚、`use` 累加、`readRev` 跟 `read` 走。
291
+ // 语义与内存里的 `record` 一致:时间戳取较晚、`readRev` 跟 `read` 走。
300
292
  for (const [name, patch] of batch) {
301
- const cur = onDisk[name] ?? { injected: 0, read: 0, use: 0, readRev: '' }
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/),存在就保留,不存在才回收。use 是次数不是时间,
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}`)
@@ -27,9 +27,36 @@ export function isNonEntry(raw) {
27
27
  return NON_ENTRY_FILES.has(nameKey(raw))
28
28
  }
29
29
 
30
+ /**
31
+ * 同步冲突副本:**不是记忆条目**。
32
+ *
33
+ * 为什么必须单独认:任何同步工具撞到「两边都改了」都会在同一个目录里落一份副本,
34
+ * 而副本的名字仍以 `.md` 结尾 —— 只按后缀判断的旧判据会把它当正常记忆读进去、
35
+ * 参与检索、参与注入。3.0 调研 §2.1 用仓库自己的函数实测过:
36
+ * `isMemoryEntry('x.sync-conflict-….md')` 返回 true。
37
+ *
38
+ * 认的模式都带**具体来源的专有标记**,不按「像不像副本」猜:
39
+ * - Syncthing:`<name>.sync-conflict-YYYYMMDD-HHMMSS-XXXXX.md`
40
+ * - Dropbox:`<name> (conflicted copy …).md`
41
+ * - 资源管理器中文 / 英文:`<name> - 副本.md`、`<name> - Copy.md`
42
+ *
43
+ * **故意不认** `x (1).md` 这种纯编号:太宽,会把正常按序号命名的文件误伤;
44
+ * 也不认 `~$x.md`(那是 Word 锁文件,不以 .md 结尾的场景更多)。
45
+ */
46
+ export function isConflictCopy(raw) {
47
+ const n = nameKey(raw)
48
+ return (
49
+ n.includes('.sync-conflict-') ||
50
+ n.includes('conflicted copy') ||
51
+ n.includes(' - 副本') ||
52
+ n.includes(' - copy')
53
+ )
54
+ }
55
+
30
56
  /** 目录扫描过滤:这个名字算不算一条记忆条目。 */
31
57
  export function isMemoryEntry(name) {
32
- return /\.md$/i.test(String(name ?? '')) && !isNonEntry(name)
58
+ const s = String(name ?? '')
59
+ return /\.md$/i.test(s) && !isNonEntry(s) && !isConflictCopy(s)
33
60
  }
34
61
 
35
62
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sage-mem",
3
3
  "description": "Cross-session memory for DeepSeek Harness — plain markdown files, no database, no worker.",
4
- "version": "2.22.0",
4
+ "version": "2.23.1",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "icon": "./icon.png",