sage-mem 2.33.4 → 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.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
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)
@@ -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.4`** —— 顶部 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
  - [权限与隐私](#权限与隐私)
@@ -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
  // 注册失败 ≠ 注入失败。出声一次,然后什么也不做。
@@ -546,6 +546,9 @@ export function createToolRunner(opts) {
546
546
  onDisk,
547
547
  note: '自动做梦写入时版本已变化:有人在这份记忆被读入之后改过它',
548
548
  tool: 'write_memory',
549
+ // 3.0.0:这条冲突是**自动做梦**造的(不是同步、也不是人手工碰上的)——
550
+ // 面板靠它分来源,`kind` 分不开(与同步的 `external_change` 同名同义)。
551
+ origin: 'autodream',
549
552
  at: new Date().toISOString(),
550
553
  })
551
554
  // 同一件事只留一条:否则每一趟重试都会给队列添一份副本(见 hasSameOpenConflict)。
@@ -909,6 +912,8 @@ export function createToolRunner(opts) {
909
912
  onDisk,
910
913
  note,
911
914
  tool: 'report_contradiction',
915
+ // 3.0.0:矛盾是做梦过程中(模型整理时)发现的 → 来源记为 autodream。
916
+ origin: 'autodream',
912
917
  at: new Date().toISOString(),
913
918
  })
914
919
  const pair = `${basename(oldFull)} ↔ ${basename(newFull)}`