sage-mem 2.27.1 → 2.29.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.27.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
15
+ **Current release: `2.29.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.
@@ -647,6 +647,30 @@ The remote side runs a single `find … -exec sha256sum {} +`; transport uses th
647
647
 
648
648
  The **baseline** lives in `<state root>/sync/base.json`, **local only, never synced**. Without it you can only compare two sides blindly, which cannot tell "I changed it" from "it was always different". Once the differences are handled, run with `updateBase: true` to record the current state as the new baseline.
649
649
 
650
+ ## Cross-device pull: fetch it in one ssh round trip (2.28.0)
651
+
652
+ `memory_sync_pull` moves files where **one side changed and the other did not** into the local main library. It **defaults to a dry run** - omit `apply` and nothing is touched:
653
+
654
+ ```
655
+ memory_sync_pull({}) // dry run: report only, no content fetched, no writes, baseline untouched
656
+ memory_sync_pull({ apply: true }) // execute
657
+ ```
658
+
659
+ | Class | What happens |
660
+ |---|---|
661
+ | remote new | created, plus one index line |
662
+ | remote changed only | local original **backed up first**, then overwritten under a version guard |
663
+ | both changed / both added with different content / locally deleted but remotely changed | **nothing is overwritten**: both bodies go into one conflict record, the remote body is kept in `<state root>/sync/incoming/` |
664
+ | local new / remote deleted / local deleted / inconsistent | reported only - **deletion is never automated** |
665
+
666
+ Three hard limits:
667
+
668
+ - **At most 50 files per run.** When the local library is nearly empty every remote file classifies as "remote new", which amounts to a first full migration - use `scp -r` explicitly for that.
669
+ - **Conflict items never advance the baseline.** Otherwise the next check would classify them as "local changed only" and the difference would become invisible. The cost is that the same conflict keeps being reported; the queue does not grow a duplicate (deduplicated by "is this the same conflict").
670
+ - **Pulled files get a fresh mtime.** They just arrived from the other machine, so counting them as fresh is fair.
671
+
672
+ 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.
673
+
650
674
  ## Configuration Reference
651
675
 
652
676
  ### 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.27.1`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.29.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 是最直接的反馈。
@@ -649,6 +649,30 @@ sage-mem 给记忆目录的写入加了**版本守卫**:写入前记下当前
649
649
 
650
650
  **基线**落在 `<状态根>/sync/base.json`,**只在本机、不同步**。没有它就只能两边硬比,分不清「我改的」和「本来就不一样」。差异处理完之后,用 `updateBase: true` 跑一次,把现状记成新基线。
651
651
 
652
+ ## 跨设备拉取:一次 ssh 搬回来(2.28.0)
653
+
654
+ `memory_sync_pull` 把「一侧动过、另一侧没动」的文件搬进本机主库。**默认预演** —— `apply` 不传就只看不动:
655
+
656
+ ```
657
+ memory_sync_pull({}) // 预演:出清单,不拉正文、不写盘、不动基线
658
+ memory_sync_pull({ apply: true }) // 执行
659
+ ```
660
+
661
+ | 类别 | 会做什么 |
662
+ |---|---|
663
+ | 远端新增 | 新建,并补一行索引 |
664
+ | 仅远端改 | **先备份**本地原件,再带版本守卫覆盖 |
665
+ | 两侧都改 / 两侧各自新增且不同 / 本地已删远端改过 | **谁都不覆盖**:两份正文进一条冲突记录,远端原件另存 `<状态根>/sync/incoming/` |
666
+ | 本地新增 / 远端已删 / 本地已删 / 数据不一致 | 只报告 —— **永不删除任何文件** |
667
+
668
+ 三条硬约束:
669
+
670
+ - **单次最多 50 个文件**。本地库基本为空时远端全量都会被判「远端新增」,那等同于整库首次搬迁 —— 那种事请用 `scp -r` 明确做一次。
671
+ - **冲突项不推进基线**。否则下次检查会判成「仅本地改」,这个差异就再也看不见了。代价是每次检查都会再报同一条;队列里不会重复建(同一条冲突按「是不是同一件事」去重)。
672
+ - **被搬文件的 mtime 会刷新成现在**。它们刚从另一台机器过来,算新鲜是合理的。
673
+
674
+ 远端正文**一次 ssh 全部取回**(`长度行 + 原样字节`,按字节切),不是每个文件一次往返 —— 在慢链路上这条差别就是「能用」与「超时」的差别。`~` 开头的远端目录也可以直接写。
675
+
652
676
  ## 配置参考
653
677
 
654
678
  ### 环境变量
@@ -19,12 +19,20 @@
19
19
  * 是行不通的 —— 必须走 `ctx.inject`。
20
20
  */
21
21
  import { createMemoryTools } from '../tools/memory-tools.js'
22
- import { createSyncTool } from '../tools/sync-tool.js'
22
+ import { createSyncPullTool, createSyncTool } from '../tools/sync-tool.js'
23
23
  import { readSyncSettings } from '../settings.js'
24
24
  import { warnLog } from '../memory/util.js'
25
25
 
26
- export function mountMemoryTools(ctx) {
26
+ /**
27
+ * @param {object} ctx
28
+ * @param {{memory?: object}} [opts] — 2.28.0 追加:网关注入(`writeFile`)。
29
+ * 为什么走参数而不是 `ctx.get('memory')`:组合根构造 `MemoryGateway` 时**正在**注册
30
+ * 这个服务,此时用 `ctx.get` 读自己会拿到 undefined 或半成品;把 `this` 直接传进来
31
+ * 是唯一没有时序歧义的做法。
32
+ */
33
+ export function mountMemoryTools(ctx, opts = {}) {
27
34
  const state = { ready: false }
35
+ const memory = opts && typeof opts === 'object' ? opts.memory : null
28
36
  try {
29
37
  if (typeof ctx.inject === 'function') {
30
38
  ctx.inject(['tools'], (inner) => {
@@ -38,6 +46,14 @@ export function mountMemoryTools(ctx) {
38
46
  // 2.27.0:跨设备只读检查。与检索工具同一个注册窗口 —— 它不参与注入链,
39
47
  // 少一个工具只是「模型少一条看差异的路」,不影响记忆照常注入。
40
48
  inner.tools.register(createSyncTool({ readSettings: readSyncSettings }))
49
+ // 2.28.0:拉取。写入通道拿不到时**照样注册** —— 预演(不写盘)仍然可用,
50
+ // 真动手时才在工具里报 `unsupported`。少注册会让「看一眼有没有差异」也没得看。
51
+ inner.tools.register(createSyncPullTool({
52
+ readSettings: readSyncSettings,
53
+ writeMemory: typeof memory?.writeFile === 'function'
54
+ ? (name, content, writeOpts) => memory.writeFile(name, content, writeOpts)
55
+ : undefined,
56
+ }))
41
57
  state.ready = true
42
58
  } catch (err) {
43
59
  // 注册失败 ≠ 注入失败。出声一次,然后什么也不做。