sage-mem 2.33.3 → 3.0.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 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.3`** — 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: `3.0.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.
@@ -37,6 +37,8 @@ If it is useful to you, a Star is the most direct feedback.
37
37
  - [Incoming submissions](#incoming-submissions-other-agents-can-submit-only-you-let-them-in-2260)
38
38
  - [Cross-device check](#cross-device-check-see-clearly-before-touching-anything-2270)
39
39
  - [Cross-device pull](#cross-device-pull-fetch-it-in-one-ssh-round-trip-2280)
40
+ - [Cross-device push](#cross-device-push-send-what-changed-locally-300)
41
+ - [Cross-device differences](#cross-device-differences-arbitration-300)
40
42
  - [Configuration Reference](#configuration-reference)
41
43
  - [Stability and Versioning Policy](#stability-and-versioning-policy)
42
44
  - [Permissions and Privacy](#permissions-and-privacy)
@@ -178,7 +180,7 @@ The state directory (configuration, ledger, rollback points, conflict queue) def
178
180
 
179
181
  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
182
 
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.
183
+ 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
184
 
183
185
  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
186
 
@@ -685,6 +687,41 @@ Three hard limits:
685
687
 
686
688
  Remote bodies are fetched in **a single ssh call** (`length line + raw bytes`, split by byte count), not one round trip per file - on a slow link that is the difference between "usable" and "timed out". Remote paths starting with `~` work as written.
687
689
 
690
+ ## Cross-device push: send what changed locally (3.0.0)
691
+
692
+ `memory_sync_push` is the mirror image of pull: it pushes files where **the local side changed and the remote did not**. It **defaults to a dry run** as well:
693
+
694
+ ```
695
+ memory_sync_push({}) // dry run: report only, not a single byte sent
696
+ memory_sync_push({ confirm: true, apply: true }) // the first push to this device
697
+ memory_sync_push({ apply: true }) // afterwards no confirmation needed
698
+ ```
699
+
700
+ | Class | What happens |
701
+ |---|---|
702
+ | local new | **exclusive create** on the remote - a name collision turns into a conflict instead of an overwrite |
703
+ | local changed only | the remote's current revision is re-checked, the old file is backed up to `<state root>/backup/<ts>/` on the remote, then overwritten |
704
+ | both changed / both added with different content | **not a single byte is written remotely**; both bodies go into one conflict record |
705
+ | remote new / remote changed / any deletion | left alone - remote-side changes belong to pull, and **deletion is never automated in either direction** |
706
+
707
+ Three gates stand in front of every write: a `.sage-mem/` state root **next to** the remote memory directory (that is what sage-mem creates, not just any markdown folder), an `instance.json` inside it whose `deviceId` can be read, and **this device being confirmed**. The first push (or a remote that was reinstalled or swapped libraries) must pass `confirm: true` explicitly; the confirmation lives in the **local** `<state root>/sync/push-baseline.json` and is never written to the remote - writing to the remote is exactly what that gate exists to prevent.
708
+
709
+ The whole batch goes over a single ssh call (`STAGE n` + interleaved headers/bodies + `COMMIT`), bodies on stdin, the script on the command line. The remote stages everything into `incoming/` and verifies each sha256 first; only after `COMMIT` does it touch the memory directory - a dropped connection means nothing landed.
710
+
711
+ ## Cross-device differences: arbitration (3.0.0)
712
+
713
+ When pull or push finds "both sides changed", neither picks a winner - it leaves a record instead. Those records now have one home: **External access -> Cross-device differences** (only cross-device origins are listed; conflicts created by autodream stay under "Library health -> Conflict queue", the two are never mixed).
714
+
715
+ Each record shows which remote, which file, and a **line-by-line comparison** (single column, line granularity, 3 lines of context around each block; above 2000 lines on either side no diff is attempted and it tells you to read the file directly). Three actions:
716
+
717
+ | Action | What gets written | Baseline |
718
+ |---|---|---|
719
+ | Keep local | the local version is pushed to the remote (backup first; a mismatched remote revision is refused) | advanced to the local version |
720
+ | Keep remote | the remote version is written locally (under a version guard) | advanced to the remote version |
721
+ | Merge by hand | **nothing at all**, the record is just marked resolved | untouched |
722
+
723
+ `Keep local` / `Keep remote` both overwrite a real file, so both ask for confirmation. If arbitration fails (the remote moved again, the write is refused) the record stays open and the baseline does not move - the next check still reports it instead of pretending it is fixed.
724
+
688
725
  ## Configuration Reference
689
726
 
690
727
  ### Environment Variables
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.3`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`3.0.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 是最直接的反馈。
@@ -39,6 +39,8 @@
39
39
  - [外部来件](#外部来件别的-agent-能提交进不进库你说了算2260)
40
40
  - [跨设备检查](#跨设备检查先看清楚再动手2270)
41
41
  - [跨设备拉取](#跨设备拉取一次-ssh-搬回来2280)
42
+ - [跨设备推送](#跨设备推送把本地动过的推出去3000)
43
+ - [跨设备差异](#跨设备差异裁决3000)
42
44
  - [配置参考](#配置参考)
43
45
  - [稳定性与版本策略](#稳定性与版本策略)
44
46
  - [权限与隐私](#权限与隐私)
@@ -178,7 +180,7 @@ SAGE_MEM_DIR=/path/to/your/memory
178
180
 
179
181
  下面每张图都是**从仓库里的界面代码渲染出来的**(同一份 CSS、同一棵组件树;数据是演示用的假数据,不是真实记忆目录)。
180
182
 
181
- 2.5.0 起面板是四个页签:文件列表 | 时间线 | 自动整理 | 库健康;2.9.0 加了第五个**实验性** —— 按「我要干什么」切,不按「数据从哪来」切:自动做梦与自动归档并成一屏的两张卡,冲突与体检也并成一屏的两张卡。编辑走右侧抽屉,凡是会动盘上文件的动作都先弹模态框问一句。
183
+ 2.5.0 起面板是四个页签:文件列表 | 时间线 | 自动整理 | 库健康;2.9.0 加了第五个**实验性**、2.25.0 加了第六个**外部访问** —— 按「我要干什么」切,不按「数据从哪来」切:自动做梦与自动归档并成一屏的两张卡,冲突与体检也并成一屏的两张卡。编辑走右侧抽屉,凡是会动盘上文件的动作都先弹模态框问一句。
182
184
 
183
185
  1.9.0 起,记忆管理这一块跟随宿主语言(**设置 → 通用 → 语言**);记忆内容本身保持它被写下时的语言,2.1.0 起扩展到自动做梦(运行 / 设置 / 记录)与自动归档两张卡;只剩时间线/星图那一屏仍是中文,等下一批 i18n。
184
186
 
@@ -687,6 +689,41 @@ memory_sync_pull({ apply: true }) // 执行
687
689
 
688
690
  远端正文**一次 ssh 全部取回**(`长度行 + 原样字节`,按字节切),不是每个文件一次往返 —— 在慢链路上这条差别就是「能用」与「超时」的差别。`~` 开头的远端目录也可以直接写。
689
691
 
692
+ ## 跨设备推送:把本地动过的推出去(3.0.0)
693
+
694
+ `memory_sync_push` 是拉取的反向:把「本地动过、远端没动」的文件推过去。**默认同样只预演**:
695
+
696
+ ```
697
+ memory_sync_push({}) // 预演:出清单,一个字节都不发
698
+ memory_sync_push({ confirm: true, apply: true }) // 第一次向这台设备推送
699
+ memory_sync_push({ apply: true }) // 之后不必再确认
700
+ ```
701
+
702
+ | 类别 | 会做什么 |
703
+ |---|---|
704
+ | 本地新增 | 远端**排他新建** —— 同名已存在就转成冲突,不覆盖 |
705
+ | 仅本地改 | 先核对远端当前版本,旧文件备份到远端 `<状态根>/backup/<ts>/`,再覆盖 |
706
+ | 两侧都改 / 两侧各自新增且不同 | **远端一个字节都不写**,两份正文进一条冲突记录 |
707
+ | 远端新增 / 远端改 / 任何删除 | 不处理 —— 远端新增归拉取,**删除两个方向都不自动执行** |
708
+
709
+ 写之前过三道门:远端记忆目录**旁边**有 `.sage-mem/` 状态根(那是 sage-mem 建的,不是随便一个 markdown 目录)、里面的 `instance.json` 读得出 `deviceId`、**这台设备确认过**。第一次推送(或远端重装、换了库)必须显式带 `confirm: true`;确认痕迹记在**本机**的 `<状态根>/sync/push-baseline.json`,不写远端 —— 写远端正是这道门要拦的事。
710
+
711
+ 一次 ssh 灌完整批正文(`STAGE n` + 头/正文交替 + `COMMIT`),正文走 stdin、脚本走命令行。远端先把全部正文收进 `incoming/` 并逐条核 sha256,读到 `COMMIT` 才动记忆目录 —— 断线等于什么都没进去。
712
+
713
+ ## 跨设备差异:裁决(3.0.0)
714
+
715
+ 拉取与推送遇到「两边都动过」都不会替你选,而是留一条记录。它们现在有统一出口:**外部访问 → 跨设备差异**(只列跨设备来源的那些;autodream 造的冲突仍在「库健康 → 冲突队列」里,两处不混)。
716
+
717
+ 每条给出:哪台远端、哪个文件、一份**逐行对比**(单栏、行级、差异块前后各 3 行上下文;任一侧超过 2000 行就不做 diff,直接告诉你用 `read_memory` 分别看)。三个动作:
718
+
719
+ | 动作 | 写什么 | 基线 |
720
+ |---|---|---|
721
+ | 留本地 | 本地版推到远端(覆盖前先备份;远端版本对不上就拒绝) | 推进到本地版 |
722
+ | 留远端 | 远端版写本地(带版本守卫) | 推进到远端版 |
723
+ | 手工合并 | **一个字节都不写**,只把记录标成已裁决 | 不动 |
724
+
725
+ `留本地` / `留远端` 都会覆盖一份真实文件,所以都有二次确认。裁决失败(远端又变了、写不进去)时记录保持待裁决、基线不动 —— 下次检查还会报,而不是假装修好了。
726
+
690
727
  ## 配置参考
691
728
 
692
729
  ### 环境变量
@@ -19,7 +19,7 @@
19
19
  * 是行不通的 —— 必须走 `ctx.inject`。
20
20
  */
21
21
  import { createMemoryTools } from '../tools/memory-tools.js'
22
- import { createSyncPullTool, createSyncTool } from '../tools/sync-tool.js'
22
+ import { createSyncPullTool, createSyncPushTool, createSyncTool } from '../tools/sync-tool.js'
23
23
  import { readSyncSettings } from '../settings.js'
24
24
  import { warnLog } from '../memory/util.js'
25
25
 
@@ -54,6 +54,9 @@ export function mountMemoryTools(ctx, opts = {}) {
54
54
  ? (name, content, writeOpts) => memory.writeFile(name, content, writeOpts)
55
55
  : undefined,
56
56
  }))
57
+ // 3.0.0:推送。**不需要写入通道** —— 它写的是远端(经 ssh),本机只写状态目录下的
58
+ // 基线 / 冲突 / 身份,那些都走自己的 IO。所以它没有「拿不到通道就降级」这一档。
59
+ inner.tools.register(createSyncPushTool({ readSettings: readSyncSettings }))
57
60
  state.ready = true
58
61
  } catch (err) {
59
62
  // 注册失败 ≠ 注入失败。出声一次,然后什么也不做。
@@ -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(),
@@ -542,6 +546,9 @@ export function createToolRunner(opts) {
542
546
  onDisk,
543
547
  note: '自动做梦写入时版本已变化:有人在这份记忆被读入之后改过它',
544
548
  tool: 'write_memory',
549
+ // 3.0.0:这条冲突是**自动做梦**造的(不是同步、也不是人手工碰上的)——
550
+ // 面板靠它分来源,`kind` 分不开(与同步的 `external_change` 同名同义)。
551
+ origin: 'autodream',
545
552
  at: new Date().toISOString(),
546
553
  })
547
554
  // 同一件事只留一条:否则每一趟重试都会给队列添一份副本(见 hasSameOpenConflict)。
@@ -745,7 +752,7 @@ export function createToolRunner(opts) {
745
752
  * 手动入口(面板「建立索引骨架」)写出来的骨架本来也没有 frontmatter,
746
753
  * 两条写入路径不该对同一个文件给出两套规矩。
747
754
  */
748
- const isIndex = basename(full).toLowerCase() === INDEX_FILE_KEY
755
+ const isIndex = nameKey(full) === INDEX_FILE_KEY
749
756
  if (!isIndex && !/^---\r?\n/.test(a.content)) {
750
757
  return '错误:内容必须以 `---` 开头的 YAML frontmatter 起始。参考 list_memory 里已有文件的写法。'
751
758
  }
@@ -905,6 +912,8 @@ export function createToolRunner(opts) {
905
912
  onDisk,
906
913
  note,
907
914
  tool: 'report_contradiction',
915
+ // 3.0.0:矛盾是做梦过程中(模型整理时)发现的 → 来源记为 autodream。
916
+ origin: 'autodream',
908
917
  at: new Date().toISOString(),
909
918
  })
910
919
  const pair = `${basename(oldFull)} ↔ ${basename(newFull)}`