sage-mem 2.33.2 → 2.33.4

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.33.2`** — 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.33.4`** — 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.
@@ -178,7 +178,7 @@ The state directory (configuration, ledger, rollback points, conflict queue) def
178
178
 
179
179
  Every image below is **rendered from the UI code in this repository** (the same CSS, the same component tree; the data is demo data for illustration, not a real memory directory).
180
180
 
181
- Since 2.5.0 the panel has four tabs: Files | Timeline | Automation | Health; 2.9.0 adds a fifth, **Lab** — split by what you want to do, not by which data source feeds it: autodream and auto-archive are two cards on one "Automation" screen, conflicts and the audit are two cards on one "Health" screen. Editing opens a right-hand drawer, and every action that touches a file on disk asks in a modal dialog.
181
+ Since 2.5.0 the panel has four tabs: Files | Timeline | Automation | Health; 2.9.0 adds a fifth, **Lab**, and 2.25.0 a sixth, **External access** — split by what you want to do, not by which data source feeds it: autodream and auto-archive are two cards on one "Automation" screen, conflicts and the audit are two cards on one "Health" screen. Editing opens a right-hand drawer, and every action that touches a file on disk asks in a modal dialog.
182
182
 
183
183
  Since 1.9.0 the memory-management surface follows the harness language (**Settings → General → Language**); memory content itself stays in whatever language it was written in, 2.1.0 extended that to the autodream (run / settings / records) and auto-archive cards; the timeline / star-map screen is the only panel still Chinese until the next i18n batch.
184
184
 
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.33.2`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.33.4`** —— 顶部 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 是最直接的反馈。
@@ -178,7 +178,7 @@ SAGE_MEM_DIR=/path/to/your/memory
178
178
 
179
179
  下面每张图都是**从仓库里的界面代码渲染出来的**(同一份 CSS、同一棵组件树;数据是演示用的假数据,不是真实记忆目录)。
180
180
 
181
- 2.5.0 起面板是四个页签:文件列表 | 时间线 | 自动整理 | 库健康;2.9.0 加了第五个**实验性** —— 按「我要干什么」切,不按「数据从哪来」切:自动做梦与自动归档并成一屏的两张卡,冲突与体检也并成一屏的两张卡。编辑走右侧抽屉,凡是会动盘上文件的动作都先弹模态框问一句。
181
+ 2.5.0 起面板是四个页签:文件列表 | 时间线 | 自动整理 | 库健康;2.9.0 加了第五个**实验性**、2.25.0 加了第六个**外部访问** —— 按「我要干什么」切,不按「数据从哪来」切:自动做梦与自动归档并成一屏的两张卡,冲突与体检也并成一屏的两张卡。编辑走右侧抽屉,凡是会动盘上文件的动作都先弹模态框问一句。
182
182
 
183
183
  1.9.0 起,记忆管理这一块跟随宿主语言(**设置 → 通用 → 语言**);记忆内容本身保持它被写下时的语言,2.1.0 起扩展到自动做梦(运行 / 设置 / 记录)与自动归档两张卡;只剩时间线/星图那一屏仍是中文,等下一批 i18n。
184
184
 
@@ -29,7 +29,7 @@ import { createHash } from 'node:crypto'
29
29
  import { join } from 'node:path'
30
30
  import { hasFrontmatter, frontmatterField, parseFrontmatter, stripFrontmatterBlock } from '../memory/frontmatter.js'
31
31
  import { isIndexName, resolveIndexNames } from '../memory/index-file.js'
32
- import { isNonEntry, isReserved } from '../memory/naming.js'
32
+ import { isNonEntry, isReserved, nameKey } from '../memory/naming.js'
33
33
  import { classifySize, indexFindings, sizeText } from '../memory/size-policy.js'
34
34
  import { parseValidityTime } from '../memory/validity.js'
35
35
  import { SESSION_LOG_KEY, isPlainMdName } from '../shared/md-name.js'
@@ -108,8 +108,20 @@ export function parseFrontmatterLite(content) {
108
108
  }
109
109
  }
110
110
 
111
- /** 索引里一条相对链接的形态:`](file.md)` / `](file.md#L12)`。**唯一一份**。 */
112
- const INDEX_LINK_RE = /\]\(([^)]+\.md)(?:#[^)]*)?\)/g
111
+ /**
112
+ * 索引里一条相对链接的形态:`](file.md)` / `](file.md#L12)`。**唯一一份**。
113
+ *
114
+ * ⚠️ 必须带 `i`(2026-12-05 修):`\.md` 区分大小写时,索引里写 `[x](Project_A.MD)`
115
+ * 会**完全不算一条链接** —— 它不进 `indexEntries`、不进悬空判定,那个文件随后以
116
+ * 「漏索引」的形式出现在体检里(真链接被报成没链接)。
117
+ *
118
+ * 这条与仓库自己的判据不一致:`shared/md-name.js` 的 `MD_NAME_RE` 带 `/i`,注释写着
119
+ * 「扩展名大小写不敏感:文件系统(NTFS / APFS)就是如此,`a.MD` 必须与 `a.md` 同宽」。
120
+ * 索引链接是**同一个东西的另一种写法**,没有理由用另一把尺子。
121
+ *
122
+ * 大小写不敏感只影响扩展名那一段:`[^)]+` 是「除右括号外的任意字符」,`i` 不会让它多匹配。
123
+ */
124
+ const INDEX_LINK_RE = /\]\(([^)]+\.md)(?:#[^)]*)?\)/gi
113
125
 
114
126
  /**
115
127
  * 抽出 MEMORY.md 里的相对链接目标**与所在行号**(2.14.0:索引瘦身提案要指到具体行)。
@@ -173,7 +185,10 @@ async function readDirSnapshot(dir) {
173
185
  const index = resolveIndexNames(entries.filter((e) => e.isFile()).map((e) => e.name))
174
186
  const files = []
175
187
  for (const f of all) {
176
- if (AUDIT_SKIP_FILES.has(f.toLowerCase())) continue
188
+ // 按 nameKey 比:AUDIT_SKIP_FILES 收的是**规范名**(小写),而 f 来自 readdir。
189
+ // 判据是「名字相等」而不是「这个文件算不算记忆」—— 所以**不许**换成 isNonEntry:
190
+ // 那张表只有 session-log.md,故意比 NON_ENTRY_FILES 窄(见上面的注释)。
191
+ if (AUDIT_SKIP_FILES.has(nameKey(f))) continue
177
192
  /**
178
193
  * 与「列表 / 注入 / 模型工具」同一条闸门。
179
194
  *
@@ -311,13 +326,13 @@ export async function auditMemoryDir(dir, opts = {}) {
311
326
  const indexConflicts = indexVariants.length > 1 ? indexVariants.map((file) => ({ file })) : []
312
327
 
313
328
  const targets = indexTargets(indexText)
314
- const targetSet = new Set(targets.map((t) => t.toLowerCase()))
329
+ const targetSet = new Set(targets.map((t) => nameKey(t)))
315
330
  // 悬空判定用 `all`(含 session-log.md):索引万一真引用了它,那是索引的问题,
316
331
  // 不该因为「审计不检查 session-log」而被顺手放过。
317
- const allSet = new Set(all.map((f) => f.toLowerCase()))
332
+ const allSet = new Set(all.map((f) => nameKey(f)))
318
333
 
319
- const dangling = targets.filter((t) => !allSet.has(t.toLowerCase()))
320
- const unlisted = entries.filter((f) => !targetSet.has(f.toLowerCase()))
334
+ const dangling = targets.filter((t) => !allSet.has(nameKey(t)))
335
+ const unlisted = entries.filter((f) => !targetSet.has(nameKey(f)))
321
336
 
322
337
  const typeMismatch = []
323
338
  const crlf = []
@@ -374,7 +389,7 @@ export async function auditMemoryDir(dir, opts = {}) {
374
389
  * 会催用户去改一个本来正确的值。反过来漏报的代价只是少一句提醒。
375
390
  */
376
391
  const supersededPool = new Set()
377
- for (const n of all) supersededPool.add(n.toLowerCase())
392
+ for (const n of all) supersededPool.add(nameKey(n))
378
393
  for (const n of archiveKeys) supersededPool.add(n.toLowerCase())
379
394
 
380
395
  for (const f of readable) {
@@ -490,7 +505,7 @@ export async function auditMemoryDir(dir, opts = {}) {
490
505
  if (file) referencedArchive.add(file)
491
506
  }
492
507
  }
493
- const activeNames = new Set(entries.map((f) => f.toLowerCase()))
508
+ const activeNames = new Set(entries.map((f) => nameKey(f)))
494
509
  const orphans = []
495
510
  for (const a of archiveEntries) {
496
511
  const from = String(a.from ?? '').trim()
@@ -569,9 +584,9 @@ export async function auditMemoryDir(dir, opts = {}) {
569
584
  if (findings.level !== 'ok') {
570
585
  indexOversize.push({ file: indexFile, bytes: findings.bytes, longLines: findings.longLines.length })
571
586
  }
572
- const danglingLower = new Set(dangling.map((d) => d.toLowerCase()))
587
+ const danglingLower = new Set(dangling.map((d) => nameKey(d)))
573
588
  for (const link of indexLinks(indexText)) {
574
- if (!danglingLower.has(link.target.toLowerCase())) continue
589
+ if (!danglingLower.has(nameKey(link.target))) continue
575
590
  indexProposals.push({ kind: 'dangling', line: link.line, target: link.target })
576
591
  }
577
592
  const lines = indexText.split(/\r?\n/)
@@ -27,6 +27,8 @@
27
27
  * 判断留给模型(它在做梦时本来就有 tool 和上下文)。
28
28
  */
29
29
 
30
+ import { nameKey } from '../memory/naming.js'
31
+
30
32
  /** 候选条数的默认上限。给多了模型读不完,给少了覆盖不到。 */
31
33
  export const DEFAULT_RECONCILE_LIMIT = 5
32
34
 
@@ -62,7 +64,15 @@ export function pickReconcileCandidates({
62
64
  const rows = []
63
65
  for (const e of entries) {
64
66
  if (!e || typeof e.file !== 'string') continue
65
- const rec = ledger?.[e.file] ?? ledger?.[e.file.toLowerCase()]
67
+ /**
68
+ * 台账的键是 `nameKey`(写侧 `memory/access.js` 的 `record()`),查侧必须走**同一个基准**。
69
+ *
70
+ * 这里原来是 `ledger?.[e.file] ?? ledger?.[e.file.toLowerCase()]` —— 一条巧妙的补丁,
71
+ * 只遮住了「台账存小写、目录名带大写」这一半。反过来(台账是旧写法的大写、目录名小写)
72
+ * 就永远查不到,而它的症状是「这条记忆从没被注入过」:安静地不报,正好是「碰巧对」
73
+ * 最贵的地方。两侧同改之后,「碰巧」不再参与。
74
+ */
75
+ const rec = ledger?.[nameKey(e.file)]
66
76
  const injected = typeof rec?.injected === 'number' ? rec.injected : 0
67
77
  // 条件一:最近还被注入过(0 = 从没注入过,不算候选 —— 那种不叫「过时」,叫「没用上」)
68
78
  if (injected <= 0) continue
@@ -31,6 +31,7 @@ import { auditMemoryDir, formatAudit, parseFrontmatterLite } from './audit.js'
31
31
  import { archiveFactExtra, readTextForFacts, rewriteFactExtra } from './fact-probe.js'
32
32
  import { archiveMemory } from '../memory/archive.js'
33
33
  import { MAX_FILE_BYTES, STATE_ROOT } from '../memory/config.js'
34
+ import { nameKey } from '../memory/naming.js'
34
35
  import { INDEX_FILE_KEY, SESSION_LOG_KEY, isPlainMdName } from '../shared/md-name.js'
35
36
  import { stampHuman as localStamp } from '../shared/stamp.js'
36
37
  import { writeFileAtomic, warnLog } from '../memory/util.js'
@@ -89,9 +90,12 @@ export function safeMemoryPath(memoryDir, raw) {
89
90
  * 文件不存在时按原样返回(新建场景)。
90
91
  */
91
92
  async function resolveRealName(memoryDir, base) {
92
- const lower = base.toLowerCase()
93
+ // 两侧都走 `nameKey`(唯一名字基准):base 的每个调用点都已 `basename` 过(恒单段),
94
+ // 但仍按基准比 —— 这个函数产出的名字会进变更记录、快照清单与回滚路径,
95
+ // 判据分叉一次,回滚就会去快照里找一个不存在的名字(RB-9)。
96
+ const lower = nameKey(base)
93
97
  const entries = await readdir(memoryDir, { withFileTypes: true }).catch(() => [])
94
- const hit = entries.find((e) => e.isFile() && e.name.toLowerCase() === lower)
98
+ const hit = entries.find((e) => e.isFile() && nameKey(e.name) === lower)
95
99
  return hit ? hit.name : base
96
100
  }
97
101
 
@@ -117,7 +121,7 @@ async function scanEntries(memoryDir, ctx) {
117
121
  }
118
122
  const reservedIds = await reservedIdentitySet(memoryDir)
119
123
  const names = entries
120
- .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.md') && e.name.toLowerCase() !== SESSION_LOG_KEY)
124
+ .filter((e) => e.isFile() && nameKey(e.name).endsWith('.md') && nameKey(e.name) !== SESSION_LOG_KEY)
121
125
  .map((e) => e.name)
122
126
  const out = []
123
127
  for (const name of names) {
@@ -141,7 +145,7 @@ async function scanEntries(memoryDir, ctx) {
141
145
  out.push({
142
146
  file: name,
143
147
  // 索引不是一条记忆:标出来,否则模型会看到「MEMORY.md · reference」而困惑。
144
- type: name.toLowerCase() === INDEX_FILE_KEY ? '索引' : meta.type || 'reference',
148
+ type: nameKey(name) === INDEX_FILE_KEY ? '索引' : meta.type || 'reference',
145
149
  bytes: gate.size,
146
150
  mtimeMs: gate.mtimeMs,
147
151
  title: (h1 ? h1[1] : meta.name || '').trim(),
@@ -745,7 +749,7 @@ export function createToolRunner(opts) {
745
749
  * 手动入口(面板「建立索引骨架」)写出来的骨架本来也没有 frontmatter,
746
750
  * 两条写入路径不该对同一个文件给出两套规矩。
747
751
  */
748
- const isIndex = basename(full).toLowerCase() === INDEX_FILE_KEY
752
+ const isIndex = nameKey(full) === INDEX_FILE_KEY
749
753
  if (!isIndex && !/^---\r?\n/.test(a.content)) {
750
754
  return '错误:内容必须以 `---` 开头的 YAML frontmatter 起始。参考 list_memory 里已有文件的写法。'
751
755
  }
@@ -16,7 +16,7 @@ import { join } from 'node:path'
16
16
  import { parseFrontmatter, stripFrontmatterBlock } from '../memory/frontmatter.js'
17
17
  import { frontmatterField } from '../memory/frontmatter.js'
18
18
  import { ensureIndexEntry } from '../memory/index-file.js'
19
- import { RESERVED_FILES } from '../memory/config.js'
19
+ import { isReserved } from '../memory/naming.js'
20
20
  import { scanMemoryDirDetailed } from '../memory/scan.js'
21
21
  import { warnLog, writeFileExclusive } from '../memory/util.js'
22
22
  import { proposeFor } from './policy.js'
@@ -138,7 +138,13 @@ export function createIntakeMerger({ ctx, memoryDir, store }) {
138
138
  return { ok: false, action: proposal.action, targetFile: proposal.targetFile, error: proposal.reason }
139
139
  }
140
140
  // 用户声明的保护名(`reserved.json`)在真落盘前再兜一道:policy 只认识两个内置名。
141
- if (RESERVED_FILES.has(String(proposal.targetFile).toLowerCase())) {
141
+ //
142
+ // ⚠️ 2026-12-05 修:原来这里是 `RESERVED_FILES.has(String(targetFile).toLowerCase())` ——
143
+ // **直接小写,丢了 `basename`**。于是 `targetFile = '../MEMORY.md'` 比对的是 `'../memory.md'`,
144
+ // 不在 `RESERVED_FILES` 里 → 放行 → `join(memoryDir, '../MEMORY.md')` 写到目录外。
145
+ // `isReserved` 走 `nameKey`(`basename(...).toLowerCase()`),那半正是挡路径成分的。
146
+ // 第一道闸门现在放在 `proposeFor` 里(名字合法性),这里是第二道(保留名)。
147
+ if (isReserved(proposal.targetFile)) {
142
148
  return { ok: false, action: 'reject', targetFile: proposal.targetFile, error: '目标是保留名(索引 / 流水 / 用户声明的保护名),不接受外来写入' }
143
149
  }
144
150
 
@@ -198,6 +198,30 @@ export function proposeFor(submission, existingNames) {
198
198
  for (const n of existingNames ?? []) set.add(String(n).toLowerCase())
199
199
  const name = String(submission?.name ?? '')
200
200
  const targetFile = name.toLowerCase().endsWith('.md') ? name : `${name}.md`
201
+ // ⚠️ **名字合法性必须在这里再判一次**(2026-12-05 修)。
202
+ //
203
+ // `validateSubmission` 判过一次(`:131`),但那是**提交流程**。归并器的 approve 路径
204
+ // 是**从磁盘读 pending 文件**再走到这里(`merge.js:127`),中间不经过 validateSubmission ——
205
+ // 也就是说 pending 目录是它唯一信任的东西。实测(修前):
206
+ //
207
+ // name = '../MEMORY.md' → targetFile = '../MEMORY.md' → action = 'create'
208
+ //
209
+ // 于是 `join(memoryDir, '../MEMORY.md')` 落在记忆目录**外面**,先在父目录建临时文件、
210
+ // 再 link 成目标(`writeFileExclusive` 的写法),最后把这一条补进索引。
211
+ // 覆盖不了已有文件(`link` 撞名是 EEXIST),但「在目录外凭空创建一份文件」这件事
212
+ // 本身就不该发生 —— 而且它绕过的正是本文件 `:38` 那句「外来提交永远占不到这两个名字」的承诺。
213
+ //
214
+ // 判据用 `isPlainMdName`(与全库同一份,定义在 `shared/md-name.js`):它挡路径分隔符、
215
+ // `..`、点文件、NTFS 非法字符与保留设备名。**不要**在这里自己拼正则 —— 那是第 N 份手抄。
216
+ if (!isPlainMdName(targetFile)) {
217
+ return { action: 'reject', targetFile: '', reason: '名字不是合法的单段 .md 文件名(含路径成分 / 点文件 / 非法字符)—— 外来提交不接受' }
218
+ }
219
+ // 内置保留名:库里同一份判据是 `memory/naming.js` 的 `isReserved`,但它经 `nameKey`
220
+ // 依赖 `node:path`,而本文件是**纯策略层**(零 node 内建,`structure-test` 第 5 组盯着)。
221
+ // 走到这里 `targetFile` 已经是单段名了,直接小写比对与 `nameKey` 等价。
222
+ if (RESERVED_BUILTIN.has(targetFile.toLowerCase())) {
223
+ return { action: 'reject', targetFile, reason: '目标是内置保留名(索引 / 流水),不接受外来写入' }
224
+ }
201
225
  const exists = set.has(targetFile.toLowerCase())
202
226
  if (submission?.kind === 'new') {
203
227
  return exists
@@ -131,25 +131,44 @@ function scheduleLeaseRetry() {
131
131
  if (typeof leaseRetryTimer.unref === 'function') leaseRetryTimer.unref()
132
132
  }
133
133
 
134
+ /**
135
+ * 把一条增量并进已有条目 —— **合并语义只有这一份**。
136
+ *
137
+ * `injected` / `read` 取**较晚**的(它们是「最近一次」);`readRev` 跟着 `read` 走
138
+ * (谁把 `read` 推新,就用谁那份 revision)。
139
+ *
140
+ * 为什么单独一个函数:这套语义原先在四处各写一遍(内存累计、落盘合并、写失败重排队、
141
+ * 读盘归一)。四处少一处就会让同一个键在不同环节得到不同答案,而台账是自动归档阈值
142
+ * **唯一**的数据源 —— 那类偏差不会抛错,只会让某条记忆的闲置天数悄悄算错。
143
+ */
144
+ function mergePatch(cur, patch) {
145
+ const read = Math.max(cur.read ?? 0, patch.read ?? 0)
146
+ return {
147
+ injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
148
+ read,
149
+ readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
150
+ }
151
+ }
152
+
134
153
  /**
135
154
  * 把一次观测并进内存增量表。
136
155
  *
137
156
  * 为什么是「增量」而不是「整条时间戳」:v2 有四个字段,同一批里可能先记注入、再记读取。
138
157
  * 直接 `set(name, at)` 会让后写的把先写的**冲掉** —— 那正是旧版台账丢计时的那类问题。
139
158
  *
140
- * 各字段的合并语义**不一样**,写错就会丢数据:
141
- * - `injected` / `read`:取**较晚**的(它们是「最近一次」);
142
- * - `readRev`:跟着 `read` 走(谁把 `read` 推新,就用谁那份 revision)。
159
+ * ⚠️ **键一律走 `nameKey`**(`memory/naming.js` 的唯一名字基准),不存调用方给的原文。
160
+ * 存原文会有两个后果,都不是崩溃而是**静默失配**:
161
+ * - `MEMORY.MD` 与 `memory.md` 会各占一个键,而读侧(`reconcile` / `idleDays`)只会去查
162
+ * 其中一个 —— 名字带大写的那条记忆就永远「没被用过」;
163
+ * - 键可能带目录成分(`../MEMORY.md`),而回收死键那一步是
164
+ * `stat(join(memoryDir, key))` —— 那等于让一个外部字符串决定 stat 的目标。
165
+ * 两者都由 `nameKey` 的 `basename(...).toLowerCase()` 一并挡住。
143
166
  */
144
167
  function record(name, patch) {
145
168
  if (typeof name !== 'string' || !name) return
146
- const cur = pending.get(name) ?? {}
147
- const read = Math.max(cur.read ?? 0, patch.read ?? 0)
148
- pending.set(name, {
149
- injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
150
- read,
151
- readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
152
- })
169
+ const key = nameKey(name)
170
+ if (!key) return
171
+ pending.set(key, mergePatch(pending.get(key) ?? {}, patch))
153
172
  scheduleFlush()
154
173
  }
155
174
 
@@ -203,7 +222,16 @@ export async function readAccessLedger(file = ACCESS_LEDGER_FILE) {
203
222
  for (const [k, v] of Object.entries(src)) {
204
223
  if (typeof k !== 'string' || !k) continue
205
224
  if (!Number.isFinite(v) && !(v && typeof v === 'object' && !Array.isArray(v))) continue
206
- out[k] = ledgerEntry(v)
225
+ /**
226
+ * 键也归一(`nameKey`)—— 台账在磁盘上是**既有数据**,里面可能存着 `Project_X.md`
227
+ * 这种写法,也可能被人手改出带路径的键。返回原文会让它在内存里与写侧的新键并成两份,
228
+ * 而查侧只认其中一份(症状:那条记忆的闲置天数回落成 mtime)。
229
+ * 两条键撞到同一个 nameKey 时按同一套合并语义并成一条,不丢更晚的时间戳。
230
+ */
231
+ const key = nameKey(k)
232
+ if (!key) continue
233
+ const entry = ledgerEntry(v)
234
+ out[key] = out[key] ? mergePatch(out[key], entry) : entry
207
235
  }
208
236
  return out
209
237
  } catch {
@@ -227,7 +255,10 @@ async function currentMemoryNames(memoryDir) {
227
255
  let unknown = false
228
256
  const collect = async (dir) => {
229
257
  const entries = await readdir(dir, { withFileTypes: true })
230
- for (const e of entries) if (e.isFile() && isMemoryEntry(e.name)) out.add(e.name)
258
+ // 键按 `nameKey` 归一(与 `record` 写进去的键同一基准):台账的键是小写规范形,
259
+ // 而磁盘上的名字可能带大写(`Project_X.md`)。拿原文去比对会让这类键在大小写敏感的卷上
260
+ // 每一轮 flush 都被判成死键删掉 —— 计时就这么没了,且没有任何信号。
261
+ for (const e of entries) if (e.isFile() && isMemoryEntry(e.name)) out.add(nameKey(e.name))
231
262
  }
232
263
  // 记忆根目录:**任何**读失败(含 ENOENT)都算「不知道」。
233
264
  // 根目录不存在不等于「记忆都没了」,而是「这个路径根本不是记忆目录」——参数传错、
@@ -289,16 +320,11 @@ async function flushAccessLocked(memoryDir) {
289
320
  batch = pending
290
321
  pending = new Map()
291
322
  const onDisk = await readAccessLedger(file)
292
- // 逐字段合并(`readAccessLedger` 已经归一成 v2 条目,不用再分代)。
293
- // 语义与内存里的 `record` 一致:时间戳取较晚、`readRev` 跟 `read` 走。
323
+ // 逐字段合并(`readAccessLedger` 已经归一成 v2 条目、键也已按 nameKey 归一,不用再分代)。
324
+ // 语义与内存里的 `record` 一致:时间戳取较晚、`readRev` 跟 `read` 走 —— 同一套 `mergePatch`。
294
325
  for (const [name, patch] of batch) {
295
326
  const cur = onDisk[name] ?? { injected: 0, read: 0, readRev: '' }
296
- const read = Math.max(cur.read ?? 0, patch.read ?? 0)
297
- onDisk[name] = {
298
- injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
299
- read,
300
- readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
301
- }
327
+ onDisk[name] = mergePatch(cur, patch)
302
328
  }
303
329
  if (alive) {
304
330
  for (const key of Object.keys(onDisk)) {
@@ -323,13 +349,7 @@ async function flushAccessLocked(memoryDir) {
323
349
  } catch (err) {
324
350
  // 放回内存时**逐字段并回去**,不能整条覆盖 —— 否则失败重试会把期间新攒的字段冲掉。
325
351
  for (const [name, patch] of batch ?? []) {
326
- const cur = pending.get(name) ?? {}
327
- const read = Math.max(cur.read ?? 0, patch.read ?? 0)
328
- pending.set(name, {
329
- injected: Math.max(cur.injected ?? 0, patch.injected ?? 0),
330
- read,
331
- readRev: read > 0 && read === (patch.read ?? 0) && patch.readRev ? patch.readRev : (cur.readRev ?? ''),
332
- })
352
+ pending.set(name, mergePatch(pending.get(name) ?? {}, patch))
333
353
  }
334
354
  if (debugEnabled()) console.warn(`sage-mem: access ledger flush failed: ${err?.message ?? err}`)
335
355
  return { ok: false, error: err?.message ?? String(err) }
@@ -366,7 +386,9 @@ export function fileType(f) {
366
386
  export function idleDays(f, ledger = {}, now = Date.now()) {
367
387
  // 走 `injectedAt` 而不是直接读值:手写的 v1 台账(裸数字)与 v2 条目都能收,
368
388
  // 调用方不必分代 —— 归档候选的计算不该因为台账升了一代就整体失效。
369
- const seen = injectedAt(ledger?.[f?.file])
389
+ // 查表按 `nameKey`:台账的键是那个基准(见 `record`),这里拿原文查会漏掉名字带大写的条目,
390
+ // 于是它的闲置天数悄悄回落到 updated / mtime —— 自动归档阈值就此算错。
391
+ const seen = injectedAt(ledger?.[nameKey(f?.file ?? '')])
370
392
  const fromMeta = Date.parse(f?.updated || '')
371
393
  const base = Number.isFinite(seen)
372
394
  ? seen
@@ -18,7 +18,7 @@
18
18
  import { ARCHIVE_DIR_NAME, addArchiveMeta, inspectDir, inspectMemoryEntry, localStamp, readArchivedMeta, scanArchived, shadowsReserved, stripArchiveMeta } from './scan.js'
19
19
  import { isReserved, nameKey, safeName } from './naming.js'
20
20
  import { parseFrontmatter } from './frontmatter.js'
21
- import { revisionOf } from './chunks.js'
21
+ import { revisionOfText } from './chunks.js'
22
22
  import { retireTaken, returnSource, takeOverSource, writeFileAtomic, writeFileExclusive } from './util.js'
23
23
  import { readLockState } from './lock.js'
24
24
  import { ensureIndexEntry, dropIndexEntry } from './index-file.js'
@@ -386,7 +386,7 @@ export async function restoreMemory(memoryDir, name) {
386
386
  *
387
387
  * 身份由两半组成,缺一不可:
388
388
  * · `archived_rev`(每次归档新生成的随机标记)→ 同分钟重新归档也绝不复用;
389
- * · `revisionOf(去掉留痕的正文)`(sha256 前 12 位)→ 正文被改过(哪怕代次没变)立刻失配。
389
+ * · `revisionOfText(去掉留痕的正文)`(sha256 前 12 位)→ 正文被改过(哪怕代次没变)立刻失配。
390
390
  * 两半都在**盘上的字节**上算,调用方只能交回「它看见的那一份」的身份 ——
391
391
  * 服务端拿它核对,界面上的二次确认只是交互,不是判据。
392
392
  *
@@ -398,7 +398,7 @@ export async function restoreMemory(memoryDir, name) {
398
398
  export function archivedRevisionOf(content) {
399
399
  const src = String(content ?? '')
400
400
  const meta = readArchivedMeta(src)
401
- return `${meta.archivedRev || ''}@${revisionOf(stripArchiveMeta(src))}`
401
+ return `${meta.archivedRev || ''}@${revisionOfText(stripArchiveMeta(src))}`
402
402
  }
403
403
 
404
404
  /**
@@ -33,13 +33,26 @@ export const CHUNK_MAX_CHARS = 900
33
33
  export const CHUNK_MIN_CHARS = 60
34
34
 
35
35
  /**
36
- * 内容 revision:`sha256:<前 12 位>`。
36
+ * 内容 revision(**短展示形**):`sha256:<前 12 位>`,入参是**字符串正文**。
37
37
  *
38
38
  * 12 位十六进制 = 48 bit,对本场景(一份记忆目录内区分版本)绰绰有余,而短到能塞进
39
39
  * 注入的状态卡与工具响应里不心疼。**它只表示「内容变了」,不表示「更新了」** ——
40
40
  * 加一行注释也会换 revision,这不是错误信息,是「你之前读到的正文已经不是现在这份」。
41
+ *
42
+ * ── 为什么这个名字(2.33.4 改名,别改回去)──
43
+ * 仓库里有两个同源但**不能互换**的 revision:
44
+ * · 本函数 `revisionOfText(string)` → `sha256:<12 位>`,**展示 / 缓存域**(工具文本、检索缓存);
45
+ * · `memory/write-protocol.js` 的 `revisionOfBytes(Buffer)` → **64 位裸 hex**,**写守卫域**
46
+ * (`expectedRevision` / 删除确认)。
47
+ * 两者算的是**同一份字节的 sha256**:本函数的 12 位就是 `revisionOfBytes` 返回值的前 12 位。
48
+ * 唯一差别是**入参类型**与**截断方式**。改名前两个函数都叫 `revisionOf`,且都不校验入参类型 ——
49
+ * 把短形交回 `expectedRevision` 不会抛异常,只会得到一个「看起来正常、值却对不上」的字符串,
50
+ * 表现为一次永远失败或永不放过的版本守卫。名字里带上 `Text` / `Bytes`,搬错调用点就不再无声。
51
+ *
52
+ * @param {string} content — 正文(非字符串按空串算,见下方 `String(content ?? '')`)
53
+ * @returns {string} `sha256:<12 位十六进制>`
41
54
  */
42
- export function revisionOf(content) {
55
+ export function revisionOfText(content) {
43
56
  const hex = createHash('sha256').update(String(content ?? ''), 'utf8').digest('hex')
44
57
  return `sha256:${hex.slice(0, 12)}`
45
58
  }
@@ -69,7 +82,7 @@ export function frontmatterEndLine(lines) {
69
82
  export function chunkFile(f, knownRevision) {
70
83
  const file = String(f?.file ?? '')
71
84
  const content = String(f?.content ?? '')
72
- const revision = typeof knownRevision === 'string' && knownRevision ? knownRevision : revisionOf(content)
85
+ const revision = typeof knownRevision === 'string' && knownRevision ? knownRevision : revisionOfText(content)
73
86
  const lines = content.split(/\r?\n/)
74
87
  const from = frontmatterEndLine(lines)
75
88
  const out = []
@@ -18,7 +18,7 @@
18
18
  import { MEMORY_DIR } from './config.js'
19
19
  import { inspectMemoryEntry, readVerified, shadowsReserved } from './scan.js'
20
20
  import { safeName } from './naming.js'
21
- import { revisionOf } from './chunks.js'
21
+ import { revisionOfText } from './chunks.js'
22
22
  import { join } from 'node:path'
23
23
 
24
24
  /** 一屏默认给多少字节。4 KB ≈ 一屏可读正文,比一次注入的 60 KB 会话预算小一个量级。 */
@@ -233,7 +233,7 @@ export async function readSlice(req = {}) {
233
233
  // 读的是闸门检查过的同一个句柄(SEC-01):路径在检查与读取之间被换掉会返回 changed,
234
234
  // 而不是把没检查过的内容当记忆交出去。
235
235
  const content = await readVerified(full, gate, 'utf8')
236
- const revision = revisionOf(content)
236
+ const revision = revisionOfText(content)
237
237
  /**
238
238
  * 带了 revision 就一定校验,且**不返回任何内容 / 行号**:过期行号比「读不到」危险得多 ——
239
239
  * 调用方会以为自己在说「那份文件的第 40 行」,实际读到的是改过之后的第 40 行。
@@ -15,7 +15,7 @@ import { parseBaseline, parseFrontmatter } from './frontmatter.js'
15
15
  import { isMemoryEntry, isReserved, nameKey } from './naming.js'
16
16
  import { readExternalSettings } from '../settings.js'
17
17
  import { readLockState } from './lock.js'
18
- import { revisionOf } from './write-protocol.js'
18
+ import { revisionOfBytes } from './write-protocol.js'
19
19
  import { exposedByOf } from '../mirror/policy.js'
20
20
  import { warnLog } from './util.js'
21
21
  import { createDirWatcher } from './watch.js'
@@ -766,8 +766,8 @@ export async function listMemoryFiles(ctx, memoryDir) {
766
766
  size: f.content.length,
767
767
  tags: meta.tags,
768
768
  // 2.21.0:删除确认必须能交回「我看到的是哪一版」。与 readFile 用同一个
769
- // 正文字节 sha256(write-protocol.revisionOf),名字不再是身份。
770
- revision: revisionOf(Buffer.from(f.content, 'utf8')),
769
+ // 正文字节 sha256(write-protocol.revisionOfBytes),名字不再是身份。
770
+ revision: revisionOfBytes(Buffer.from(f.content, 'utf8')),
771
771
  // 锁定状态跟着每条一起给:卡片上的「锁定 / 已锁定」按钮要据此渲染
772
772
  locked: lockState.status === 'unknown' ? false : lockState.locked.has(nameKey(f.file)),
773
773
  // 2.30.0:`'exclude' | 'include' | 'prefix' | 'tag' | 'none'`。
@@ -14,7 +14,7 @@
14
14
  * 一篇文档的改动会影响所有词的 IDF。
15
15
  */
16
16
 
17
- import { chunkFile, revisionOf } from './chunks.js'
17
+ import { chunkFile, revisionOfText } from './chunks.js'
18
18
  import { buildStats, coverageOf, evidence, maxMatchedRun, queryTermsOf, scoreDoc, termFreq, tokenize, COVERAGE_WEIGHT } from './bm25.js'
19
19
  import { rankSummaries, score as summaryScore } from './retrieval.js'
20
20
  import { extractTitle } from './scan.js'
@@ -108,7 +108,7 @@ export function chunksOf(files) {
108
108
  const file = String(f?.file ?? '')
109
109
  const content = String(f?.content ?? '')
110
110
  if (!file) continue
111
- const revision = revisionOf(content)
111
+ const revision = revisionOfText(content)
112
112
  revisions.push(`${file}:${revision}`)
113
113
  const hit = chunkCache.get(file)
114
114
  if (hit && hit.revision === revision) {
@@ -255,7 +255,7 @@ export function summaryHits(query, files, limit = DEFAULT_LIMIT) {
255
255
  if (summaryScore(query, fileBase) > 0) matchedBy.push('filename')
256
256
  return {
257
257
  file: f.file,
258
- revision: revisionOf(String(f.content ?? '')),
258
+ revision: revisionOfText(String(f.content ?? '')),
259
259
  score: f.score,
260
260
  // 回落标签是 `summary` 而不是 `description`:`retrieval.js` 的打分是**三个字段去标点
261
261
  // 拼成一串**之后再算双字,所以跨字段边界也能产生命中(`description: '收尾待'` +
@@ -39,8 +39,20 @@ export const ERR_STALE_REVISION = 'stale_revision'
39
39
  /** 冲突码:`create`(createIfAbsent)撞上已有文件 —— 新建绝不覆盖已有内容。 */
40
40
  export const ERR_ALREADY_EXISTS = 'already_exists'
41
41
 
42
- /** 内容 revision:字节的 sha256。读与写必须用同一个算法,调用方原样回传。 */
43
- export function revisionOf(bytes) {
42
+ /**
43
+ * 内容 revision(**全长守卫形**):字节的 sha256,**64 位裸 hex**,入参是 `Buffer`。
44
+ * 读与写必须用同一个算法,调用方原样回传。
45
+ *
46
+ * ── 为什么这个名字(2.33.4 改名,别改回去)──
47
+ * `memory/chunks.js` 里还有一个同源函数 `revisionOfText(string)` → `sha256:<前 12 位>`,
48
+ * 用于**展示 / 缓存**(工具文本、检索缓存);本函数用于**写守卫域**
49
+ * (`opts.expectedRevision` 与删除确认)。两者的前 12 位十六进制是同一串,
50
+ * 也就是 `revisionOfText` 的值去掉 `sha256:` 前缀 —— 同源,但**入参类型不同、截断方式不同**,
51
+ * 两个值域**不可互换**。改名前两个都叫 `revisionOf` 且都不校验入参类型:把短形交给
52
+ * `expectedRevision` 不抛异常,只会得到一个值域不对的字符串(守卫要么永远拒绝、要么永不生效),
53
+ * 是典型的静默失配。名字里带 `Text` / `Bytes` 就是让这种搬错在调用点一眼可见。
54
+ */
55
+ export function revisionOfBytes(bytes) {
44
56
  return createHash('sha256').update(bytes).digest('hex')
45
57
  }
46
58
 
@@ -53,7 +65,7 @@ export function revisionOf(bytes) {
53
65
  */
54
66
  export async function readSnapshot(full, gate, name) {
55
67
  const bytes = await readVerified(full, gate, false)
56
- return { name, content: bytes.toString('utf8'), revision: revisionOf(bytes) }
68
+ return { name, content: bytes.toString('utf8'), revision: revisionOfBytes(bytes) }
57
69
  }
58
70
 
59
71
  /** 旧调用方的兼容提示(一次写入一行,不做去重 —— 谁漏传一眼就能在日志里翻到)。 */
@@ -215,7 +227,7 @@ export async function writeSnapshot(target, content, gate, opts, meta) {
215
227
  if (err?.code === 'EEXIST') return rejected(ERR_ALREADY_EXISTS, `sage-mem: ${name} 刚刚被别的写入建出来了,新建没有覆盖它`)
216
228
  return rejected('io_error', `sage-mem: 写入 ${name} 失败:${String(err?.message ?? err)}`)
217
229
  }
218
- return { ok: true, file: name, revision: revisionOf(Buffer.from(content, 'utf8')), created: true }
230
+ return { ok: true, file: name, revision: revisionOfBytes(Buffer.from(content, 'utf8')), created: true }
219
231
  }
220
232
 
221
233
  // ② 带 expectedRevision:盘上版本与调用方读到的不一致 → 拒绝,内容一个字节不动。
@@ -226,7 +238,7 @@ export async function writeSnapshot(target, content, gate, opts, meta) {
226
238
  }
227
239
  let current
228
240
  try {
229
- current = revisionOf(await readVerified(target, gate, false))
241
+ current = revisionOfBytes(await readVerified(target, gate, false))
230
242
  } catch (err) {
231
243
  return rejected(ERR_STALE_REVISION, `sage-mem: 读不到 ${name} 的当前版本(${err?.code ?? err}),没有写入`)
232
244
  }
@@ -247,7 +259,7 @@ export async function writeSnapshot(target, content, gate, opts, meta) {
247
259
  } catch (err) {
248
260
  return rejected('io_error', `sage-mem: 写入 ${name} 失败:${String(err?.message ?? err)}`)
249
261
  }
250
- return { ok: true, file: name, revision: revisionOf(Buffer.from(content, 'utf8')) }
262
+ return { ok: true, file: name, revision: revisionOfBytes(Buffer.from(content, 'utf8')) }
251
263
  }
252
264
 
253
265
  /**
@@ -327,7 +339,7 @@ export async function deleteMemoryFile(ctx, name, opts) {
327
339
 
328
340
  let actual
329
341
  try {
330
- actual = revisionOf(await readFile(taken.taken))
342
+ actual = revisionOfBytes(await readFile(taken.taken))
331
343
  } catch (err) {
332
344
  const back = await returnSource(taken.taken, full)
333
345
  return {
@@ -16,7 +16,7 @@
16
16
  import { mkdir, readdir, readFile, unlink } from 'node:fs/promises'
17
17
  import { join } from 'node:path'
18
18
  import { parseFrontmatter } from '../memory/frontmatter.js'
19
- import { revisionOf } from '../memory/write-protocol.js'
19
+ import { revisionOfBytes } from '../memory/write-protocol.js'
20
20
  import { scanMemoryDirDetailed } from '../memory/scan.js'
21
21
  import { warnLog, writeFileAtomic } from '../memory/util.js'
22
22
  import { stampHuman } from '../shared/stamp.js'
@@ -33,7 +33,7 @@ import {
33
33
  /** 增量账的格式版本。形状(不是加字段)变了才 +1。 */
34
34
  const STATE_VERSION = 1
35
35
 
36
- const shaOf = (text) => revisionOf(Buffer.from(text, 'utf8'))
36
+ const shaOf = (text) => revisionOfBytes(Buffer.from(text, 'utf8'))
37
37
 
38
38
  /**
39
39
  * 建一个导出器。
@@ -247,6 +247,16 @@ export function exposedByOf(name, tags, external) {
247
247
  // `project_` 开头,但它不是一个记忆名。导出层拿到的名字来自 `scan.js`(已经过滤过),
248
248
  // 这道判定是给面板逐条勾选与将来的调用方兜底的 —— 判据只有一份,就别指望上游一定干净。
249
249
  if (!isPlainMdName(file)) return 'none'
250
+ /**
251
+ * 下面这段的 `.toLowerCase()` 与 `nameKey`(`memory/naming.js` 的唯一基准)**等价,且有意不换**:
252
+ * 上一行已经用 `isPlainMdName` 把名字压成单段,剩下的差别只有大小写。
253
+ *
254
+ * 为什么不图字面统一:本文件是 `structure-test` 第 5 组点名的**纯逻辑层**
255
+ * (「纯函数:可对字符串断言、import 时不读环境」),而 `memory/naming.js` 会经
256
+ * `memory/config.js` 在 import 时读 `reserved.json` 与环境变量。为了换一个等价的函数,
257
+ * 把一个纯判据模块变成 import 就碰盘的模块 —— 代价比收益大,而且那种破坏不会让任何测试变红。
258
+ * 真要统一,方向是让 `nameKey` 搬到零依赖的 `shared/`,而不是让 policy 往上伸手。
259
+ */
250
260
  const lower = file.toLowerCase()
251
261
  if ((external.exclude ?? []).some((n) => String(n).toLowerCase() === lower)) return 'exclude'
252
262
  if ((external.include ?? []).some((n) => String(n).toLowerCase() === lower)) return 'include'
@@ -330,5 +340,7 @@ export function buildMirrorIndex(entries, { stamp } = {}) {
330
340
  * 可能留着上一轮导出、现在已经退出白名单的文件。
331
341
  */
332
342
  export function isMirrorReadableName(name) {
343
+ // `isPlainMdName` 在前:名字到这里已经是单段,`toLowerCase()` 与 `nameKey` 同义(理由见
344
+ // `exposedByOf` 里那段「有意不换」的注释)。
333
345
  return typeof name === 'string' && isPlainMdName(name) && !name.startsWith('.') && name.toLowerCase() !== MIRROR_INDEX_NAME.toLowerCase()
334
346
  }
package/lib/settings.js CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  liveExperimental,
26
26
  resolveExperimental,
27
27
  } from './memory/experimental.js'
28
+ import { nameKey } from './memory/naming.js'
28
29
  import { MAX_RAW_BYTES } from './shared/limits.js'
29
30
  import { INDEX_FILE_KEY, SESSION_LOG_KEY, isPlainMdName } from './shared/md-name.js'
30
31
  export { LIMIT_SPECS, MAX_RAW_BYTES }
@@ -342,7 +343,13 @@ export async function readSettingsSnapshot(ctx) {
342
343
  }
343
344
  // 模块加载时那份「用户声明的保护名」(RESERVED_FILES 里抠掉两个内置名)
344
345
  const activeExtra = [...RESERVED_FILES].filter((n) => n !== INDEX_FILE_KEY && n !== SESSION_LOG_KEY)
345
- const norm = (list) => JSON.stringify([...list].map((s) => String(s).toLowerCase()).sort())
346
+ /**
347
+ * 比「保护名单改没改」用的键:**走 `nameKey`**(唯一名字基准)。
348
+ * 两侧比的是记忆条目名,而 `RESERVED_FILES` 的成员本身就按 nameKey 归一存放
349
+ * (见 `memory/config.js` 的注释)—— 再写一遍 `.toLowerCase()` 就等于在比较处
350
+ * 立了第二份判据,`MEMORY.MD` 这类写法会在两处得到不同答案。
351
+ */
352
+ const norm = (list) => JSON.stringify([...list].map((s) => nameKey(s)).sort())
346
353
  const restartRequired =
347
354
  JSON.stringify(limits) !== JSON.stringify(pending.limits) ||
348
355
  // 2.11.0:实验性开关里带 `live: true` 的(如 todoBoard)由 client 半当场应用,
@@ -363,7 +370,8 @@ export async function readSettingsSnapshot(ctx) {
363
370
  // 1.8.0 / 2.7.0:客户端行为(界面入口三选一)。**不参与** restartRequired —— 改完立刻生效。
364
371
  ui: { ...ui, sidebarEntry: ui.entry !== 'settings' },
365
372
  // 生效的保护名单(含两个内置名)+ 用户声明的那部分原文(面板编辑的是后者)
366
- reserved: [...new Set([INDEX_FILE_KEY, SESSION_LOG_KEY, ...reservedExtra.map((s) => s.toLowerCase())])],
373
+ // 生效值一律按 `nameKey` 归一:模型 / 面板拿它去比名字时不必自己再折一次大小写。
374
+ reserved: [...new Set([INDEX_FILE_KEY, SESSION_LOG_KEY, ...reservedExtra.map((s) => nameKey(s))])],
367
375
  reservedExtra,
368
376
  // 2.25.0:外部访问(读侧)的生效值与诊断。面板据此显示开关 / 白名单 / 端口,
369
377
  // 诊断非空时说明「你保存的值有一部分没被采纳,原因是 X」。
@@ -188,6 +188,11 @@ export function isSafeSyncName(name) {
188
188
  if (n === '' || n.length > 200) return false
189
189
  if (n.includes('/') || n.includes('\\') || n.includes('\0')) return false
190
190
  if (n === '.' || n === '..') return false
191
+ /**
192
+ * 扩展名判定,**不是名字比较**:上面三行已经拒掉了 `/` `\` `\0` 与 `.` / `..`,
193
+ * 所以这里的 `.toLowerCase()` 与 `nameKey` 同义(本文件是零 import 的纯策略层,
194
+ * 不为了字面统一去拉 `memory/naming.js` —— 它会经 `memory/config.js` 在 import 时读盘)。
195
+ */
191
196
  if (!n.toLowerCase().endsWith('.md')) return false
192
197
  return true
193
198
  }
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.33.2",
4
+ "version": "2.33.4",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "icon": "./icon.png",
@@ -44,10 +44,10 @@
44
44
  "zod": "^4.4.3"
45
45
  },
46
46
  "devDependencies": {
47
- "@deepseek-ai/cordis": "4.0.4",
48
- "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1",
49
- "@deepseek-ai/dsh-skill-filesystem": "0.2.0-rc.1",
50
- "@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.1",
47
+ "@deepseek-ai/cordis": "4.1.0",
48
+ "@deepseek-ai/dsh-client-locale": "0.2.2-rc.5",
49
+ "@deepseek-ai/dsh-skill-filesystem": "0.2.2-rc.5",
50
+ "@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.5",
51
51
  "react": "^18.0.0"
52
52
  },
53
53
  "peerDependencies": {