sage-mem 2.15.2 → 2.15.3

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.15.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.15.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
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.15.2`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.15.3`** —— 顶部 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 是最直接的反馈。
package/lib/client.js CHANGED
@@ -4837,6 +4837,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
4837
4837
  "todo.notice.stale": "文件刚被别处改过,已重新加载;这次改动没保存",
4838
4838
  "todo.notice.degraded": "宿主还是升级前的版本:这次写入没有版本校验,请确认内容正确",
4839
4839
  "todo.notice.undo": "已撤销上一步",
4840
+ "todo.notice.undoStale": "文件刚被别处改过,撤销 / 重做已作废(已重新加载)",
4840
4841
  "todo.err.noRemote": "宿主没有记忆 remote,读不了待办文件",
4841
4842
  "todo.err.read": "读不到待办文件:{error}",
4842
4843
  "todo.err.write": "写入被拒:{error}",
@@ -5482,6 +5483,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
5482
5483
  "todo.notice.stale": "The file changed elsewhere; reloaded. This edit was not saved.",
5483
5484
  "todo.notice.degraded": "Host predates this version: the write had no revision check — verify the content.",
5484
5485
  "todo.notice.undo": "Reverted the last edit",
5486
+ "todo.notice.undoStale": "The file changed elsewhere, so undo / redo was cancelled (reloaded)",
5485
5487
  "todo.err.noRemote": "This host exposes no memory remote, so the to-do file cannot be read",
5486
5488
  "todo.err.read": "Cannot read the to-do file: {error}",
5487
5489
  "todo.err.write": "Write rejected: {error}",
@@ -9935,6 +9937,19 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9935
9937
  try { s.setItem(key, value); } catch (e) { /* 偏好丢了不影响主流程 */ }
9936
9938
  }
9937
9939
 
9940
+ /**
9941
+ * 撤销 / 重做现在还能不能做(2.15.3)。
9942
+ *
9943
+ * 判据:盘上的 revision 必须仍是我们**自己写出的那一版**。否则中间有人(AI、另一个页签)
9944
+ * 改过文件,写回整份快照会把那些改动一起抹掉 —— 那比「撤销失败」严重得多。
9945
+ * 拿不到 revision(老宿主 / 读失败)时按旧行为放行:没有判据可用时,宁可让用户能退回一步。
9946
+ */
9947
+ function todoUndoAllowed(liveRevision, writtenRevision) {
9948
+ if (typeof writtenRevision !== "string" || writtenRevision === "") return true;
9949
+ if (typeof liveRevision !== "string" || liveRevision === "") return true;
9950
+ return liveRevision === writtenRevision;
9951
+ }
9952
+
9938
9953
  /** 撤销步数归一:非数字 / 越界都收进 [3, 5],坏值(含 null / 空串)回默认 5。 */
9939
9954
  function todoClampUndoDepth(n) {
9940
9955
  if (n === null || n === undefined || n === "") return TODO_UNDO_DEFAULT;
@@ -10616,6 +10631,10 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10616
10631
  const sErr = react.useState(null); const err = sErr[0], setErr = sErr[1];
10617
10632
  const sNotice = react.useState(""); const notice = sNotice[0], setNotice = sNotice[1];
10618
10633
  const sBusy = react.useState(false); const busy = sBusy[0], setBusy = sBusy[1];
10634
+ // 「我们自己写出的那一版」的 revision:撤销 / 重做只在文件仍停在这一版时才允许,
10635
+ // 否则整份快照会连别人(AI、另一个页签)期间的改动一起抹掉(2.15.3)。
10636
+ const sWritten = react.useState(null);
10637
+ const writtenRev = sWritten[0], setWrittenRev = sWritten[1];
10619
10638
  // 撤销 / 重做:元素是写入前的 `{content, revision}`。栈**只在内存里**,
10620
10639
  // 深度 3–5 可配(偏好落 localStorage);任何**新**写入都清空 redoStack —— 历史分叉了。
10621
10640
  const sDepth = react.useState(function () { return todoClampUndoDepth(todoPrefGet(TODO_PREF_UNDO)); });
@@ -10729,6 +10748,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10729
10748
  setErr(r.error || t("todo.err.write", { error: String(r.code || "error") }));
10730
10749
  return;
10731
10750
  }
10751
+ setWrittenRev(typeof r.revision === "string" ? r.revision : null);
10732
10752
  setUndoStack(function (prev) { return prev.concat([snapshot]).slice(-undoDepth); });
10733
10753
  setRedoStack([]);
10734
10754
  setNotice(out.degraded ? t("todo.notice.degraded") : label);
@@ -10746,6 +10766,12 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10746
10766
  */
10747
10767
  function writeSnapshot(target, label, onDone) {
10748
10768
  if (!target || typeof target.content !== "string") return;
10769
+ // 2.15.3:盘上已经不是我们写出的那一版 → 撤销 / 重做作废(否则会抹掉别人的改动)。
10770
+ if (!todoUndoAllowed(doc.revision, writtenRev)) {
10771
+ setNotice(t("todo.notice.undoStale"));
10772
+ load(false);
10773
+ return;
10774
+ }
10749
10775
  const revision = doc.revision;
10750
10776
  setBusy(true); setErr(null); setNotice("");
10751
10777
  writeWithFallback(remote, "writeFile", [TODO_FILE, target.content], revision ? { expectedRevision: revision } : undefined, null)
@@ -10757,6 +10783,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10757
10783
  return;
10758
10784
  }
10759
10785
  if (typeof onDone === "function") onDone();
10786
+ setWrittenRev(typeof r.revision === "string" ? r.revision : null);
10760
10787
  setNotice(label);
10761
10788
  return load(false);
10762
10789
  }, function (e) { setErr(String((e && e.message) || e)); })
@@ -11185,6 +11212,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
11185
11212
  PREF_UNDO: TODO_PREF_UNDO,
11186
11213
  PREF_OPEN: TODO_PREF_OPEN,
11187
11214
  clampDepth: todoClampUndoDepth,
11215
+ undoAllowed: todoUndoAllowed,
11188
11216
  filterItems: todoFilterItems,
11189
11217
  groupKey: todoGroupKey,
11190
11218
  openMapParse: todoOpenMapParse,
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.15.2",
4
+ "version": "2.15.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "icon": "./icon.png",