sage-mem 2.14.0 → 2.15.1

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.14.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
15
+ **Current release: `2.15.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
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.
@@ -464,15 +464,18 @@ The two things are moved **differently**, spelled out:
464
464
 
465
465
  ⚠️ **The premise is that the shape matches.** The four-type division and the frontmatter are sage-mem's own conventions: if your memories in CC were already "one Markdown file per memory + frontmatter" (which is what ours were at the time), just copy them over; **if they were not** (if they were all piled into a single `CLAUDE.md`, say), you need to organize them first — and that job can perfectly well be handed to an agent: have it read the old material and lay it out as files under the four types.
466
466
 
467
- ## To-do Board (experimental · since 2.11.0; ticking means moving since 2.11.1)
467
+ ## To-do Board (experimental · since 2.11.0; wrapped up in 2.15.0)
468
468
 
469
469
  `project_session-state.md` in the memory directory has always been a to-do list you keep for yourself: injected into every session, but you still have to open the file to see what is left. 2.11.0 puts it in the **right sidebar**: Settings → Memory management → Lab → enable "To-do board", and the sidebar's Start page gains a card that opens a tab.
470
470
 
471
471
  - **Ticking = moving**: a finished item is removed from its group and appended to the "Done, pending deletion" block (created at the end of the file on first use); un-ticking moves it back to the end of its original group. "Clear all" is what actually deletes rows.
472
- - **Edit it**: add an item at the end of a group, edit one in place, undo / redo two steps.
472
+ - **Edit it**: add an item at the end of a group, edit one in place, undo / redo **3–5 steps** (5 by default).
473
+ - **See only what is open**: the default filter is "Open" (legacy `- [x]` lines appear under "All"; the pending-deletion block always shows, since it is a queue). Each group remembers whether it was expanded.
474
+ - **Wrap-up has a button**: **"Move to log"** on the pending-deletion block appends the rows to `session-log.md` and removes them from the list — log first, list second, verbatim text, already-logged rows skipped, **not undoable**.
475
+ - **See work owed elsewhere**: the 未完成 (open-work) section of `tasks/*/WORKING.md` is aggregated into a **read-only** block (never merged back).
473
476
  - **The file is still the only truth**: the board does line-level surgery only; edit the file with any tool and the board follows within 4 seconds.
474
477
  - **Hot**: flipping the switch takes effect immediately, no restart (unlike MMR).
475
- - **Off by default**; no drag-and-drop ordering, no automatic `session-log` archiving — moving those pending-deletion rows into the log is the agent's job at wrap-up. Details in `docs/todo-board.md`.
478
+ - **Off by default**; no drag-and-drop ordering. Details in `docs/todo-board.md`.
476
479
 
477
480
  ## Initial memory: scaffold the library with an agent (2.12.0; moved to Lab in 2.12.1)
478
481
 
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.14.0`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.15.1`** —— 顶部 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 是最直接的反馈。
@@ -464,15 +464,18 @@ sage-mem 给记忆目录的写入加了**版本守卫**:写入前记下当前
464
464
 
465
465
  ⚠️ **前提是形状对得上。** 四类划分与 frontmatter 是 sage-mem 自己的约定:如果你在 CC 里的记忆本来就是「一条一个 Markdown + frontmatter」(我们当时是这种),拷过来即可;**如果不是**(比如都堆在一个 `CLAUDE.md` 里),需要先整理一遍 —— 这活儿正好可以交给一个 agent 做:让它读旧语料,按四类落成文件。
466
466
 
467
- ## 待办清单看板(实验性 · 2.11.0 起,2.11.1 勾选改「搬家」)
467
+ ## 待办清单看板(实验性 · 2.11.0 起;2.15.0 收尾)
468
468
 
469
- 记忆目录里的 `project_session-state.md` 一直是「给自己看的代办清单」——每场会话都会注入,人却要打开文件才知道还剩什么。2.11.0 把它搬进**右侧栏**:设置 → 记忆管理 → 实验性 → 打开「待办清单看板」,右侧栏「开始」页就会多一张卡片,点开是一个页签。
469
+ 记忆目录里的 `project_session_state.md` 一直是「给自己看的代办清单」——每场会话都会注入,人却要打开文件才知道还剩什么。2.11.0 把它搬进**右侧栏**:设置 → 记忆管理 → 实验性 → 打开「待办清单看板」,右侧栏「开始」页就会多一张卡片,点开是一个页签。
470
470
 
471
471
  - **勾选 = 搬家**:完成项从原组删掉、搬进「已完成,待删除」块(文件里还没这一块就自动在末尾建),取消完成再搬回原组末尾;「清空全部」才真删。
472
- - **改得动**:每组底部加一条、点卡片行内改一句;撤销 / 重做各两步。
472
+ - **改得动**:每组底部加一条、点卡片行内改一句;撤销 / 重做 **3–5 步可配**(默认 5)。
473
+ - **一眼只看没做完的**:默认「未完成」档(老文件里遗留的 `- [x]` 行要点「全部」才出现,「已完成,待删除」块始终在——它是队列);每组的展开状态会记住。
474
+ - **收尾有按钮**:待删除块上的**「搬进流水」**把条目写进 `session-log.md` 再从清单删掉——先写流水再删行、正文照抄、已记过的跳过、**不可撤销**。
475
+ - **看得见别的文件里欠着的活**:`tasks/*/WORKING.md` 的「未完成」节汇总成一条**只读**区块(不合并写入)。
473
476
  - **文件仍是唯一真相**:看板只做行级手术,其余字节原样;你用任何编辑器改它,看板 4 秒内跟上。
474
477
  - **热的**:拨开关立刻生效,不用重启(与 MMR 不同)。
475
- - **默认关闭**;不做拖拽排序、不代写 `session-log` 留档 —— 把「待删除」搬进流水是 agent 收尾时的活。细节见 `docs/todo-board.md`。
478
+ - **默认关闭**;不做拖拽排序。细节见 `docs/todo-board.md`。
476
479
 
477
480
  ## 初始记忆:让 agent 建个骨架(2.12.0,2.12.1 挪到「实验性」)
478
481
 
package/lib/client.js CHANGED
@@ -2105,6 +2105,16 @@ const StarmapRuntime = (function (require, _react) {
2105
2105
  result: { mode: "strict", typeSymbol: "sage-mem/types#AuditReport", schema: objCodec, create: () => objCodec },
2106
2106
  sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
2107
2107
  },
2108
+ {
2109
+ id: "sage-mem#memory/checkpoints",
2110
+ service: "memory",
2111
+ namespace: "memory",
2112
+ method: "checkpoints",
2113
+ invocation: { kind: "direct" },
2114
+ parameters: [],
2115
+ result: { mode: "strict", typeSymbol: "sage-mem/types#Checkpoints", schema: objCodec, create: () => objCodec },
2116
+ sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
2117
+ },
2108
2118
  {
2109
2119
  id: "sage-mem#memory/openMemoryDir",
2110
2120
  service: "memory",
@@ -2862,6 +2872,22 @@ const StarmapRuntime = (function (require, _react) {
2862
2872
  ".smem-todo-add{padding-top:2px;}",
2863
2873
  ".smem-todo-add-input{width:100%;font-size:12px;}",
2864
2874
  ".smem-todo-empty{font-size:11.5px;color:var(--dsw-alias-label-secondary);padding:4px 0;}",
2875
+ // 2.15.0:筛选 + 撤销步数那一行;步数选择器要窄,别把右栏撑开。
2876
+ ".smem-todo-tools{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:0 0 2px;}",
2877
+ ".smem-todo-tools > span[data-spring]{flex:1;}",
2878
+ ".smem-todo-filter{border:1px solid transparent;border-radius:6px;padding:1px 6px;}",
2879
+ ".smem-todo-filter-on{border-color:var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-l2);color:var(--dsw-alias-label-primary);}",
2880
+ ".smem-todo-depth{display:inline-flex;align-items:center;gap:4px;font-size:11.5px;color:var(--dsw-alias-label-secondary);}",
2881
+ ".smem-todo-depth-select{width:auto;padding:0 2px;font-size:11.5px;}",
2882
+ // 「搬进流水」是待删除块的主动作(清空是丢弃、这条是留档),给品牌色。
2883
+ ".smem-todo-archive{font-weight:600;}",
2884
+ // 检查点聚合块:只读、来源是别的文件 —— 用虚线边框和正文色区分开。
2885
+ ".smem-todo-group-cp{border-style:dashed;}",
2886
+ ".smem-todo-cp-task{display:flex;flex-direction:column;gap:2px;padding:2px 0;}",
2887
+ ".smem-todo-cp-head{font-size:11.5px;font-weight:600;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;}",
2888
+ ".smem-todo-cp-items{display:flex;flex-direction:column;gap:2px;}",
2889
+ ".smem-todo-cp-item{font-size:12px;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere;padding-left:8px;border-left:2px solid var(--dsw-alias-border-l2);}",
2890
+ ".smem-todo-cp-note{font-size:11px;color:var(--dsw-alias-label-secondary);}",
2865
2891
  ".smem-todo-done-state{display:flex;flex-direction:column;gap:6px;padding:16px 12px;}",
2866
2892
  ".smem-todo-done-title{font-weight:600;}",
2867
2893
  ].join("\n");
@@ -4814,6 +4840,23 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
4814
4840
  "todo.err.noRemote": "宿主没有记忆 remote,读不了待办文件",
4815
4841
  "todo.err.read": "读不到待办文件:{error}",
4816
4842
  "todo.err.write": "写入被拒:{error}",
4843
+ "todo.err.noArchive": "宿主没有读写保留名的 remote(readRaw / writeRaw),搬不进流水",
4844
+ "todo.err.archive": "搬进流水失败:{error}",
4845
+ "todo.filter.open": "未完成",
4846
+ "todo.filter.openTitle": "只显示未完成(待删除块照旧显示:它是待清空的队列)",
4847
+ "todo.filter.all": "全部",
4848
+ "todo.filter.allTitle": "连旧文件里遗留的 - [x] 行一起显示",
4849
+ "todo.undoDepth.label": "撤销上限",
4850
+ "todo.undoDepth.option": "{n} 步",
4851
+ "todo.action.undoTitle": "撤销上一步(栈深 {depth} 步,只在本次页面里有效)",
4852
+ "todo.action.archive": "搬进流水({count})",
4853
+ "todo.action.archiveConfirm": "确认搬进流水({count})",
4854
+ "todo.action.archiveConfirm.title": "会写进 {file},并从清单删掉 {count} 行;这一步不可撤销",
4855
+ "todo.notice.archived": "已把 {count} 条搬进 {file},并从清单里删掉(这一步不可撤销)",
4856
+ "todo.notice.archivedDup": "这些条目在 {file} 里都已经有了,只删掉了清单里那几行",
4857
+ "todo.notice.archiveStale": "{count} 条已写进流水,但清单刚被别处改过:清单里那几行**没删**,刷新后再点一次即可(重复会被跳过)",
4858
+ "todo.cp.title": "检查点里的未完成(只读)",
4859
+ "todo.cp.note": "来自 tasks/*/WORKING.md 的「未完成」节。这里只显示,改动请回到那份检查点。",
4817
4860
  "todo.disabled.title": "待办看板已在「实验性」里关闭",
4818
4861
  "todo.disabled.hint": "打开:设置 → 记忆管理 → 实验性 → 待办清单看板",
4819
4862
  "todo.lab.title": "待办清单看板(实验性)",
@@ -5440,8 +5483,25 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
5440
5483
  "todo.err.noRemote": "This host exposes no memory remote, so the to-do file cannot be read",
5441
5484
  "todo.err.read": "Cannot read the to-do file: {error}",
5442
5485
  "todo.err.write": "Write rejected: {error}",
5486
+ "todo.err.noArchive": "This host exposes no readRaw / writeRaw remote, so the log cannot be appended",
5487
+ "todo.err.archive": "Could not move items into the log: {error}",
5488
+ "todo.filter.open": "Open",
5489
+ "todo.filter.openTitle": "Show open items only (the pending-deletion block stays: it is a queue to clear)",
5490
+ "todo.filter.all": "All",
5491
+ "todo.filter.allTitle": "Also show legacy - [x] lines left in the file",
5492
+ "todo.undoDepth.label": "Undo limit",
5493
+ "todo.undoDepth.option": "{n} steps",
5494
+ "todo.action.undoTitle": "Undo the last edit (stack depth {depth}; in-memory only)",
5495
+ "todo.action.archive": "Move to log ({count})",
5496
+ "todo.action.archiveConfirm": "Confirm move ({count})",
5497
+ "todo.action.archiveConfirm.title": "Appends to {file} and removes {count} line(s) from the list; this cannot be undone",
5498
+ "todo.notice.archived": "Moved {count} item(s) into {file} and removed them from the list (this cannot be undone)",
5499
+ "todo.notice.archivedDup": "Those items were already in {file}; only the list lines were removed",
5500
+ "todo.notice.archiveStale": "{count} item(s) were appended to the log, but the list changed elsewhere: its lines were NOT removed. Refresh and click again — duplicates are skipped.",
5443
5501
  "todo.disabled.title": "The to-do board is switched off in the lab settings",
5444
5502
  "todo.disabled.hint": "Turn it on: Settings → Memory management → Lab → To-do board",
5503
+ "todo.cp.title": "Open items in checkpoints (read-only)",
5504
+ "todo.cp.note": "From the open-work section of tasks/*/WORKING.md. Display only — edit the checkpoint itself.",
5445
5505
  "todo.lab.title": "To-do board (experimental)",
5446
5506
  "todo.lab.switch": "Enable the to-do board",
5447
5507
  "todo.lab.switch.title": "Adds a To-dos tab to the right sidebar",
@@ -9798,8 +9858,21 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9798
9858
  * **字面量写进文件,不跟界面语言走** —— 它是文件格式的一部分,不是 UI 文案。
9799
9859
  */
9800
9860
  const TODO_DONE_HEADING = "## 已完成,待删除";
9801
- /** 撤销 / 重做各留几步(用户要两步;再多会让人误以为能回滚一整天)。 */
9802
- const TODO_UNDO_DEPTH = 2;
9861
+ /**
9862
+ * 撤销 / 重做步数(2.15.0 起可配 3–5,默认 5)。
9863
+ * 栈本身**只在内存里**(关页面即失效);落 localStorage 的只有「用户选了几步」这个偏好。
9864
+ */
9865
+ const TODO_UNDO_DEFAULT = 5;
9866
+ const TODO_UNDO_MIN = 3;
9867
+ const TODO_UNDO_MAX = 5;
9868
+ /** 偏好键:撤销步数 / 各组展开状态。localStorage 本身就按 origin 隔离。 */
9869
+ const TODO_PREF_UNDO = "sage-mem.todo.undoDepth";
9870
+ const TODO_PREF_OPEN = "sage-mem.todo.openGroups";
9871
+ /** 筛选两档:默认只看未完成;`全部`才把旧文件里遗留的 `- [x]` 行也画出来。 */
9872
+ const TODO_FILTER_OPEN = "open";
9873
+ const TODO_FILTER_ALL = "all";
9874
+ /** 完成项留档的落点:跨会话流水(保留名,走 readRaw / writeRaw)。 */
9875
+ const TODO_LOG_FILE = "session-log.md";
9803
9876
 
9804
9877
  /** 开关状态(模块级:设置卡与页签共享)。 */
9805
9878
  let todoBoardEnabled = false;
@@ -9833,6 +9906,161 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9833
9906
  return s[0];
9834
9907
  }
9835
9908
 
9909
+ // ── 本地偏好(2.15.0):只存「用户怎么选的」,不存任何清单内容 ──────────
9910
+ //
9911
+ // 纪律与「不建自己的存储」一致:清单的唯一真相仍是那份 markdown。
9912
+ // 这里存的只有两件纯界面偏好 —— 撤销留几步、哪几组是展开的。
9913
+ // 读不到(隐私模式 / 配额满 / 无 DOM 的测试环境)一律按默认走,**不报错**。
9914
+
9915
+ function todoStore() {
9916
+ try {
9917
+ if (typeof localStorage === "undefined" || localStorage === null) return null;
9918
+ return localStorage;
9919
+ } catch (e) { return null; }
9920
+ }
9921
+
9922
+ function todoPrefGet(key) {
9923
+ const s = todoStore();
9924
+ if (!s || typeof s.getItem !== "function") return null;
9925
+ try { return s.getItem(key); } catch (e) { return null; }
9926
+ }
9927
+
9928
+ function todoPrefSet(key, value) {
9929
+ const s = todoStore();
9930
+ if (!s || typeof s.setItem !== "function") return;
9931
+ try { s.setItem(key, value); } catch (e) { /* 偏好丢了不影响主流程 */ }
9932
+ }
9933
+
9934
+ /** 撤销步数归一:非数字 / 越界都收进 [3, 5],坏值(含 null / 空串)回默认 5。 */
9935
+ function todoClampUndoDepth(n) {
9936
+ if (n === null || n === undefined || n === "") return TODO_UNDO_DEFAULT;
9937
+ const v = Math.round(Number(n));
9938
+ if (!Number.isFinite(v)) return TODO_UNDO_DEFAULT;
9939
+ return Math.min(TODO_UNDO_MAX, Math.max(TODO_UNDO_MIN, v));
9940
+ }
9941
+
9942
+ /** 组展开偏好的键:就是节标题原文(空标题用同一个兜底键)。 */
9943
+ function todoGroupKey(title) {
9944
+ return String(title == null ? "" : title);
9945
+ }
9946
+
9947
+ /**
9948
+ * 解析 `{组标题: true|false}` 偏好。坏 JSON、数组、别的类型一律当「没有偏好」——
9949
+ * 于是所有组回到默认(收起),而不是让整块看板因为一行坏数据打不开。
9950
+ * @returns {Object<string, boolean>}
9951
+ */
9952
+ function todoOpenMapParse(raw) {
9953
+ const out = Object.create(null);
9954
+ let value = null;
9955
+ try { value = JSON.parse(String(raw == null ? "" : raw)); } catch (e) { return out; }
9956
+ if (!value || typeof value !== "object" || Array.isArray(value)) return out;
9957
+ Object.keys(value).forEach(function (k) {
9958
+ if (value[k] === true || value[k] === false) out[k] = value[k];
9959
+ });
9960
+ return out;
9961
+ }
9962
+
9963
+ /** 序列化展开偏好(只留布尔值,别的键丢掉)。 */
9964
+ function todoOpenMapSerialize(map) {
9965
+ const out = {};
9966
+ Object.keys(map || {}).forEach(function (k) {
9967
+ if (map[k] === true || map[k] === false) out[k] = map[k];
9968
+ });
9969
+ try { return JSON.stringify(out); } catch (e) { return "{}"; }
9970
+ }
9971
+
9972
+ /**
9973
+ * 筛选:`open` 档只留未完成(待删除块里的条目照旧显示 —— 它是**队列**,
9974
+ * 不是「已完成的历史」,藏起来就没法清空 / 留档了)。
9975
+ */
9976
+ function todoFilterItems(items, filter) {
9977
+ const list = items || [];
9978
+ if (filter === TODO_FILTER_ALL) return list;
9979
+ return list.filter(function (it) { return !it.done || it.inDone; });
9980
+ }
9981
+
9982
+ /** 比较用的归一化正文:连续空白压成一个空格、去首尾。 */
9983
+ function todoLogKey(text) {
9984
+ return String(text == null ? "" : text).replace(/\s+/g, " ").trim();
9985
+ }
9986
+
9987
+ /** 流水里已经记过的条目正文(归一化后)。用于「重复点一次不会写两遍」。 */
9988
+ function todoLogKeys(logText) {
9989
+ const set = new Set();
9990
+ String(logText == null ? "" : logText).split(/\r?\n/).forEach(function (line) {
9991
+ const m = /^\s*[-*+]\s+(.*)$/.exec(line);
9992
+ if (m && m[1].trim() !== "") set.add(todoLogKey(m[1]));
9993
+ });
9994
+ return set;
9995
+ }
9996
+
9997
+ /** `YYYY-MM-DD HH:mm`(本地时区;流水的人读时间,不用 UTC)。 */
9998
+ function todoStamp(now) {
9999
+ const d = now instanceof Date ? now : new Date();
10000
+ const p = function (n) { return String(n).padStart(2, "0"); };
10001
+ return String(d.getFullYear()) + "-" + p(d.getMonth() + 1) + "-" + p(d.getDate()) +
10002
+ " " + p(d.getHours()) + ":" + p(d.getMinutes());
10003
+ }
10004
+
10005
+ /**
10006
+ * 把待删除块里的条目拼成一段流水(纯函数,不碰 IO、不改入参)。
10007
+ *
10008
+ * **逐字照抄条目正文**,不改写成概括 —— 2.14.0 做归档时那条纪律同样适用:
10009
+ * 概化过的流水半年后没人能据此复现。已经在流水里记过的(`existingKeys`)跳过,
10010
+ * 于是「上次写了一半」的失败可以安全重试。
10011
+ *
10012
+ * @param {Array<object>} items 待删除块里的条目(`text` 已剥掉 `[x]`)
10013
+ * @param {Date} now 时间戳
10014
+ * @param {Set<string>} [existingKeys] 流水里已有的正文键
10015
+ * @returns {{text: string, bodies: string[], count: number}}
10016
+ */
10017
+ function todoArchiveBlock(items, now, existingKeys) {
10018
+ const keys = existingKeys || new Set();
10019
+ const seen = new Set();
10020
+ const bodies = [];
10021
+ (items || []).forEach(function (it) {
10022
+ const body = String(it && it.text != null ? it.text : "").trim();
10023
+ if (body === "") return;
10024
+ const key = todoLogKey(body);
10025
+ if (keys.has(key) || seen.has(key)) return;
10026
+ seen.add(key);
10027
+ bodies.push(body);
10028
+ });
10029
+ if (bodies.length === 0) return { text: "", bodies: [], count: 0 };
10030
+ const head = "## " + todoStamp(now) + " · 待办收尾(" + String(bodies.length) + " 条)";
10031
+ const lines = [
10032
+ head,
10033
+ "",
10034
+ // ⚠️ 这两处字面量进的是**文件内容**(流水),不跟界面语言走 —— 与 TODO_DONE_HEADING 同理。
10035
+ "**来源**:`" + TODO_FILE + "` 的「已完成,待删除」块,由待办看板搬入(正文照抄)。",
10036
+ "",
10037
+ ].concat(bodies.map(function (b) { return "- " + b; }));
10038
+ return { text: lines.join("\n"), bodies: bodies, count: bodies.length };
10039
+ }
10040
+
10041
+ /**
10042
+ * 把一段流水接到已有内容末尾:保证「原有内容不动 + 空一行 + 新段 + 以换行结尾」。
10043
+ *
10044
+ * ⚠️ 按**行**拼,别在 `"\r\n"` 后面再补一个裸 `"\r"` —— CRLF 文件会被拼出
10045
+ * `"\r\n\r"` 这种既不是 CRLF 也不是 LF 的东西(2.15.0 的第一版就踩了这条)。
10046
+ */
10047
+ function todoSessionLogAppend(logText, blockText) {
10048
+ const src = String(logText == null ? "" : logText);
10049
+ const block = String(blockText == null ? "" : blockText);
10050
+ if (block === "") return src;
10051
+ const eol = todoEol(src);
10052
+ const out = src === "" ? [] : src.split("\n");
10053
+ // `split` 的末尾空串代表「文件以换行结尾」,不是一行内容。
10054
+ if (out.length > 0 && out[out.length - 1] === "") out.pop();
10055
+ const body = block.split("\n").filter(function (line, i, arr) {
10056
+ return !(line === "" && i === arr.length - 1);
10057
+ });
10058
+ if (out.length > 0) out.push(eol);
10059
+ body.forEach(function (line) { out.push(line + eol); });
10060
+ out.push("");
10061
+ return out.join("\n");
10062
+ }
10063
+
9836
10064
  // ── 解析:markdown → 节 + 条目(纯函数,不碰 IO)────────────────────
9837
10065
 
9838
10066
  /**
@@ -9941,7 +10169,10 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
9941
10169
  current.items.push(item);
9942
10170
  // 插入点 = 本条之后:节尾最后一条的下方,不会被后面的空行 / 下一节吃掉。
9943
10171
  current.insertAt = i + 1;
9944
- if (item.done) done += 1; else open += 1;
10172
+ // 2.15.1:**「长期约束」不算未完成**。那一节的标题自己写着「不是待办」,
10173
+ // 把它计入「N 条未完成」既骗人又和标题冲突(真机截图里 30 条里有 8 条是约束)。
10174
+ // 已完成计数不受影响:待删除块里的条目本来就是 done。
10175
+ if (item.done) done += 1; else if (current.kind !== "constraint") open += 1;
9945
10176
  lastItem = item;
9946
10177
  continue;
9947
10178
  }
@@ -10198,25 +10429,49 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10198
10429
  ]);
10199
10430
  }
10200
10431
 
10201
- /** 一组(一个 `##` 节):标题 + 计数 + 条目 + 新增框;待删除块另有「清空全部」。 */
10432
+ /** 一组(一个 `##` 节):标题 + 计数 + 条目 + 新增框;待删除块另有「清空 / 搬进流水」。 */
10202
10433
  function TodoSectionGroup(props) {
10203
10434
  const sec = props.section;
10204
10435
  const isDone = sec.kind === "done";
10205
10436
  // 2.11.1(用户 2026-11-17 反馈):**所有组默认收起**,一屏先看见「有几组、各组几条」,
10206
10437
  // 想看的组自己点开。原来只收「长期约束」,长清单照样一屏铺满。
10207
- const sCollapsed = react.useState(true);
10438
+ // 2.15.0:**记住用户点开过哪几组**(localStorage,按节标题)。默认仍收起。
10439
+ const key = todoGroupKey(sec.title);
10440
+ const sCollapsed = react.useState(function () {
10441
+ const map = props.openMap || {};
10442
+ return map[key] !== true;
10443
+ });
10208
10444
  const collapsed = sCollapsed[0], setCollapsed = sCollapsed[1];
10209
- // 上层「全部展开 / 全部收起」:allOpen 为 null 时不管(各组各管各的)。
10445
+ // 上层「全部展开 / 全部收起」:一次性动作,**不写偏好**(写了就变成「永远全展开」)。
10210
10446
  react.useEffect(function () {
10211
10447
  if (props.allOpen === null || props.allOpen === undefined) return;
10212
10448
  setCollapsed(!props.allOpen);
10213
10449
  }, [props.allOpen]);
10450
+ function toggleGroup() {
10451
+ // 点一下 = 把「收起」反过来;记进偏好的是**点击后的展开态**(不是「收起态」)。
10452
+ const nextOpen = collapsed;
10453
+ setCollapsed(!collapsed);
10454
+ if (typeof props.onGroupToggle === "function") props.onGroupToggle(key, nextOpen);
10455
+ }
10214
10456
  const sDraft = react.useState("");
10215
10457
  const draft = sDraft[0], setDraft = sDraft[1];
10458
+ // 2.15.1:「搬进流水」两步确认 —— 它不可撤销(流水那半撤不回来),
10459
+ // 点一下就把记忆流水写掉、清单行删掉,不该是一次误触就能完成的动作。
10460
+ const sConfirm = react.useState(false);
10461
+ const confirming = sConfirm[0], setConfirming = sConfirm[1];
10462
+ react.useEffect(function () {
10463
+ // 块被清空 / 换了一份文件时,别让确认态悬着。
10464
+ if (blockCountRaw() === 0) setConfirming(false);
10465
+ }, [props.doneCount, sec.items.length]);
10466
+ function blockCountRaw() {
10467
+ return typeof props.doneCount === "number" ? props.doneCount : sec.items.length;
10468
+ }
10216
10469
  const openCount = sec.items.filter(function (it) { return !it.done; }).length;
10217
10470
  const doneCount = sec.items.length - openCount;
10218
10471
  // 「清空全部」清的是**整个块**(不是当前筛出来的这几条),所以按钮上的数字要取块的真实条数。
10219
- const blockCount = typeof props.doneCount === "number" ? props.doneCount : sec.items.length;
10472
+ const blockCount = blockCountRaw();
10473
+ // 2.15.1:待删除块里没有「未完成」,别画那个永远是 0 的「0 / N」。
10474
+ const countText = isDone ? String(doneCount || blockCount) : String(openCount) + (doneCount > 0 ? " / " + String(doneCount) : "");
10220
10475
  return h("section", { className: "smem-todo-group" + (isDone ? " smem-todo-group-done" : "") }, [
10221
10476
  // 标题行是**行**不是按钮:右边还要放「清空全部」,按钮套按钮在浏览器里会互相吃掉。
10222
10477
  h("div", { key: "head", className: "smem-todo-group-head" }, [
@@ -10224,12 +10479,40 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10224
10479
  key: "toggle",
10225
10480
  type: "button",
10226
10481
  className: "smem-todo-group-toggle",
10227
- onClick: function () { setCollapsed(!collapsed); },
10482
+ onClick: toggleGroup,
10228
10483
  }, [
10229
10484
  h("span", { key: "chev", className: "smem-todo-chev" }, collapsed ? "▸" : "▾"),
10230
10485
  h("span", { key: "t", className: "smem-todo-group-title" }, sec.title || (isDone ? t("todo.doneGroup") : t(TODO_SECTION_FALLBACK))),
10231
- h("span", { key: "n", className: "smem-todo-count" }, String(openCount) + (doneCount > 0 ? " / " + String(doneCount) : "")),
10486
+ h("span", { key: "n", className: "smem-todo-count" }, countText),
10232
10487
  ]),
10488
+ isDone && blockCount > 0
10489
+ ? (confirming
10490
+ ? h("button", {
10491
+ key: "archiveConfirm",
10492
+ type: "button",
10493
+ className: "smem-todo-mini smem-todo-archive smem-todo-del",
10494
+ title: t("todo.action.archiveConfirm.title", { count: blockCount, file: TODO_LOG_FILE }),
10495
+ disabled: props.busy,
10496
+ onClick: function () { setConfirming(false); props.onArchive(sec); },
10497
+ }, t("todo.action.archiveConfirm", { count: blockCount }))
10498
+ : h("button", {
10499
+ key: "archive",
10500
+ type: "button",
10501
+ className: "smem-todo-mini smem-todo-archive",
10502
+ title: t("todo.action.archive", { count: blockCount, file: TODO_LOG_FILE }),
10503
+ disabled: props.busy,
10504
+ onClick: function () { setConfirming(true); },
10505
+ }, t("todo.action.archive", { count: blockCount, file: TODO_LOG_FILE })))
10506
+ : null,
10507
+ isDone && blockCount > 0 && confirming
10508
+ ? h("button", {
10509
+ key: "archiveCancel",
10510
+ type: "button",
10511
+ className: "smem-todo-mini",
10512
+ disabled: props.busy,
10513
+ onClick: function () { setConfirming(false); },
10514
+ }, t("todo.action.cancel"))
10515
+ : null,
10233
10516
  isDone && blockCount > 0
10234
10517
  ? h("button", {
10235
10518
  key: "clear",
@@ -10272,6 +10555,46 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10272
10555
  ]);
10273
10556
  }
10274
10557
 
10558
+ /**
10559
+ * 检查点聚合(2.15.0)—— **只读**。
10560
+ *
10561
+ * 把 `<状态根>/tasks/<id>/WORKING.md` 的「未完成」节并到清单上方显示。
10562
+ * **不合并写入**:那些条目在别的文件里、有自己的 revision 与写协议,
10563
+ * 看板只负责让人看见「还有哪些任务没收尾」,动手改仍然回到那份检查点。
10564
+ * 老宿主的 remote 上没有 `checkpoints`,于是整块不出现(不是显示一个空壳)。
10565
+ */
10566
+ function TodoCheckpointBlock(props) {
10567
+ const sOpen = react.useState(false);
10568
+ const open = sOpen[0], setOpen = sOpen[1];
10569
+ const tasks = props.tasks || [];
10570
+ return h("section", { className: "smem-todo-group smem-todo-group-cp" }, [
10571
+ h("div", { key: "head", className: "smem-todo-group-head" }, [
10572
+ h("button", {
10573
+ key: "toggle",
10574
+ type: "button",
10575
+ className: "smem-todo-group-toggle",
10576
+ title: t("todo.cp.title"),
10577
+ onClick: function () { setOpen(!open); },
10578
+ }, [
10579
+ h("span", { key: "chev", className: "smem-todo-chev" }, open ? "▾" : "▸"),
10580
+ h("span", { key: "t", className: "smem-todo-group-title" }, t("todo.cp.title")),
10581
+ h("span", { key: "n", className: "smem-todo-count" }, String(props.count || 0)),
10582
+ ]),
10583
+ ]),
10584
+ open ? h("div", { key: "list", className: "smem-todo-list" }, tasks.map(function (task) {
10585
+ const id = String(task && task.taskId ? task.taskId : "");
10586
+ const label = task && task.project ? String(task.project) + " · " + id : id;
10587
+ return h("div", { key: "t" + id, className: "smem-todo-cp-task" }, [
10588
+ h("div", { key: "h", className: "smem-todo-cp-head" }, label),
10589
+ h("div", { key: "i", className: "smem-todo-cp-items" }, (task.items || []).map(function (txt, i) {
10590
+ return h("div", { key: "x" + i, className: "smem-todo-cp-item" }, todoInline(String(txt)));
10591
+ })),
10592
+ ]);
10593
+ })) : null,
10594
+ open ? h("div", { key: "note", className: "smem-todo-cp-note" }, t("todo.cp.note")) : null,
10595
+ ]);
10596
+ }
10597
+
10275
10598
  /** 页签正文。承载全部读写状态(宿主只给 ctx / sessionId / 标准 hooks)。 */
10276
10599
  function TodoBoard(props) {
10277
10600
  const ctx = props.ctx;
@@ -10285,15 +10608,50 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10285
10608
  const sErr = react.useState(null); const err = sErr[0], setErr = sErr[1];
10286
10609
  const sNotice = react.useState(""); const notice = sNotice[0], setNotice = sNotice[1];
10287
10610
  const sBusy = react.useState(false); const busy = sBusy[0], setBusy = sBusy[1];
10288
- // 撤销 / 重做:两步栈,元素是写入前的 `{content, revision}`。只在内存里,不落盘。
10289
- // 任何**新**写入都清空 redoStack —— 从历史里分叉出去之后,原来那条「未来」就不成立了。
10611
+ // 撤销 / 重做:元素是写入前的 `{content, revision}`。栈**只在内存里**,
10612
+ // 深度 3–5 可配(偏好落 localStorage);任何**新**写入都清空 redoStack —— 历史分叉了。
10613
+ const sDepth = react.useState(function () { return todoClampUndoDepth(todoPrefGet(TODO_PREF_UNDO)); });
10614
+ const undoDepth = sDepth[0], setUndoDepth = sDepth[1];
10290
10615
  const sUndo = react.useState([]); const undoStack = sUndo[0], setUndoStack = sUndo[1];
10291
10616
  const sRedo = react.useState([]); const redoStack = sRedo[0], setRedoStack = sRedo[1];
10292
- // 「全部展开」是**一次性动作**而不是持久状态:默认 null(各组按自己的默认走 = 收起)。
10617
+ // 「全部展开」是**一次性动作**而不是持久状态:默认 null(各组按自己的默认走)。
10293
10618
  const sAll = react.useState(null); const allOpen = sAll[0], setAllOpen = sAll[1];
10619
+ // 各组展开偏好(2.15.0):`{节标题: true|false}`,点开/收起就写回 localStorage。
10620
+ const sOpenMap = react.useState(function () { return todoOpenMapParse(todoPrefGet(TODO_PREF_OPEN)); });
10621
+ const openMap = sOpenMap[0], setOpenMap = sOpenMap[1];
10622
+ // 筛选:默认只看未完成(旧文件里遗留的 `- [x]` 行要先点「全部」才出现)。
10623
+ const sFilter = react.useState(TODO_FILTER_OPEN); const filter = sFilter[0], setFilter = sFilter[1];
10294
10624
  // 搜索:只过滤**显示**,绝不改文件;有查询时匹配的组强制展开,没匹配的组整组隐掉。
10295
10625
  const sQuery = react.useState(""); const rawQuery = sQuery[0], setQuery = sQuery[1];
10296
10626
  const query = String(rawQuery).trim().toLowerCase();
10627
+ // 检查点聚合(2.15.0,只读):老宿主没有 memory/checkpoints,读到就藏起来。
10628
+ const sCps = react.useState(null); const checkpoints = sCps[0], setCheckpoints = sCps[1];
10629
+
10630
+ /** 读一次检查点(宿主没这个方法就保持 null,界面上整块不出现)。 */
10631
+ const loadCheckpoints = react.useCallback(function () {
10632
+ if (!remote || typeof remote.checkpoints !== "function") return;
10633
+ Promise.resolve(remote.checkpoints()).then(function (res) {
10634
+ const data = unwrap(res);
10635
+ if (!data || data.ok === false) { setCheckpoints(null); return; }
10636
+ setCheckpoints(Array.isArray(data.tasks) ? data.tasks : []);
10637
+ }, function () { /* 读不到就不显示,别在清单旁边堆一条错误 */ });
10638
+ }, [remote]);
10639
+
10640
+ function toggleGroupPref(title, next) {
10641
+ const map = Object.assign({}, openMap);
10642
+ map[title] = next;
10643
+ setOpenMap(map);
10644
+ todoPrefSet(TODO_PREF_OPEN, todoOpenMapSerialize(map));
10645
+ }
10646
+
10647
+ /** 改撤销步数:写偏好 + 立刻把两份栈裁到新深度(否则旧的深栈还能退回去)。 */
10648
+ function changeDepth(n) {
10649
+ const next = todoClampUndoDepth(n);
10650
+ setUndoDepth(next);
10651
+ todoPrefSet(TODO_PREF_UNDO, String(next));
10652
+ setUndoStack(function (prev) { return prev.slice(-next); });
10653
+ setRedoStack(function (prev) { return prev.slice(-next); });
10654
+ }
10297
10655
 
10298
10656
  /** 读一次文件。`quiet` = 轮询调用(出错不弹条,避免每 4 秒闪一次)。 */
10299
10657
  const load = react.useCallback(function (quiet) {
@@ -10332,6 +10690,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10332
10690
  return function () { clearInterval(id); };
10333
10691
  }, [visible, enabled, load]);
10334
10692
 
10693
+ // 检查点聚合(只读):进页签读一次;点刷新再读(别的会话可能刚写过 WORKING.md)。
10694
+ react.useEffect(function () { loadCheckpoints(); }, [loadCheckpoints]);
10695
+
10335
10696
  /**
10336
10697
  * 一次写入:带上读到的 revision(盘上变了宿主回 stale_revision,我们只重读、不覆盖)。
10337
10698
  * @param {string} label 回执文案(已翻译)
@@ -10355,7 +10716,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10355
10716
  setErr(r.error || t("todo.err.write", { error: String(r.code || "error") }));
10356
10717
  return;
10357
10718
  }
10358
- setUndoStack(function (prev) { return prev.concat([snapshot]).slice(-TODO_UNDO_DEPTH); });
10719
+ setUndoStack(function (prev) { return prev.concat([snapshot]).slice(-undoDepth); });
10359
10720
  setRedoStack([]);
10360
10721
  setNotice(out.degraded ? t("todo.notice.degraded") : label);
10361
10722
  return load(false);
@@ -10430,13 +10791,75 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10430
10791
  mutate(t("todo.notice.cleared", { count: out.count }), out.next);
10431
10792
  }
10432
10793
 
10794
+ /**
10795
+ * 「搬进流水」:把待删除块里的条目搬进跨会话流水(2.15.0)。
10796
+ *
10797
+ * 两次写盘,顺序是刻意的:**先追加流水、再从清单删行**。反过来做,第二步失败就真丢条目;
10798
+ * 这样失败最多在流水里留一份重复,而重复由正文去重挡住(所以重试是安全的)。
10799
+ * 也正因为流水那半没法撤回,搬完**清空撤销栈** —— 留着一个「撤销」只会骗人。
10800
+ */
10801
+ async function onArchive(section) {
10802
+ const items = (section && section.items) || [];
10803
+ if (items.length === 0) return;
10804
+ if (!remote || typeof remote.readRaw !== "function" || typeof remote.writeRaw !== "function") {
10805
+ setErr(t("todo.err.noArchive"));
10806
+ return;
10807
+ }
10808
+ const revision = doc.revision;
10809
+ const fileContent = doc.content;
10810
+ setBusy(true); setErr(null); setNotice("");
10811
+ let logged = 0;
10812
+ try {
10813
+ let content = "";
10814
+ let logRev = null;
10815
+ const log = unwrap(await remote.readRaw(TODO_LOG_FILE));
10816
+ if (log && log.ok === false) {
10817
+ // 新库还没有流水:当空文件起头。别的读失败照旧报(别把「读坏了」当成「还没有」)。
10818
+ if (!/missing|not.?found|enoent/i.test(String(log.code || ""))) {
10819
+ throw new Error(log.error || String(log.code || "error"));
10820
+ }
10821
+ } else {
10822
+ content = (log && log.content) || "";
10823
+ logRev = log && typeof log.revision === "string" ? log.revision : null;
10824
+ }
10825
+ const block = todoArchiveBlock(items, new Date(), todoLogKeys(content));
10826
+ if (block.count > 0) {
10827
+ const next = todoSessionLogAppend(content, block.text);
10828
+ const out = await remote.writeRaw(TODO_LOG_FILE, next, logRev ? { expectedRevision: logRev } : undefined);
10829
+ const r = out && (out.result || out);
10830
+ if (r && r.ok === false) throw new Error(r.error || String(r.code || "error"));
10831
+ logged = block.count;
10832
+ }
10833
+ const nextTodo = todoRemove(fileContent, items.map(function (it) { return it.line; }));
10834
+ const out2 = await writeWithFallback(remote, "writeFile", [TODO_FILE, nextTodo], revision ? { expectedRevision: revision } : undefined, null);
10835
+ const r2 = out2 && (out2.result || out2);
10836
+ if (r2 && r2.ok === false) {
10837
+ if (r2.code === "stale_revision") {
10838
+ setNotice(t("todo.notice.archiveStale", { count: logged }));
10839
+ await load(false);
10840
+ return;
10841
+ }
10842
+ throw new Error(r2.error || String(r2.code || "error"));
10843
+ }
10844
+ setUndoStack([]); setRedoStack([]);
10845
+ setNotice(logged > 0
10846
+ ? t("todo.notice.archived", { count: logged, file: TODO_LOG_FILE })
10847
+ : t("todo.notice.archivedDup", { file: TODO_LOG_FILE }));
10848
+ await load(false);
10849
+ } catch (e) {
10850
+ setErr(t("todo.err.archive", { error: String((e && e.message) || e) }));
10851
+ } finally {
10852
+ setBusy(false);
10853
+ }
10854
+ }
10855
+
10433
10856
  function onUndo() {
10434
10857
  if (undoStack.length === 0) return;
10435
10858
  const target = undoStack[undoStack.length - 1];
10436
10859
  const point = currentPoint();
10437
10860
  writeSnapshot(target, t("todo.notice.undo"), function () {
10438
10861
  setUndoStack(function (prev) { return prev.slice(0, -1); });
10439
- setRedoStack(function (prev) { return prev.concat([point]).slice(-TODO_UNDO_DEPTH); });
10862
+ setRedoStack(function (prev) { return prev.concat([point]).slice(-undoDepth); });
10440
10863
  });
10441
10864
  }
10442
10865
 
@@ -10446,7 +10869,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10446
10869
  const point = currentPoint();
10447
10870
  writeSnapshot(target, t("todo.notice.redone"), function () {
10448
10871
  setRedoStack(function (prev) { return prev.slice(0, -1); });
10449
- setUndoStack(function (prev) { return prev.concat([point]).slice(-TODO_UNDO_DEPTH); });
10872
+ setUndoStack(function (prev) { return prev.concat([point]).slice(-undoDepth); });
10450
10873
  });
10451
10874
  }
10452
10875
 
@@ -10459,22 +10882,36 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10459
10882
 
10460
10883
  const parsed = doc && doc.parsed ? doc.parsed : parseTodoList("");
10461
10884
  const missing = doc && doc.missing;
10885
+ // 两道过滤,顺序固定:先按「未完成 / 全部」筛条目,再按搜索词筛。都只影响**显示**。
10462
10886
  // 匹配口径:标题 + 正文 + 续行里任一处包含子串(大小写不敏感;不解释正则,免得用户被自己的输入坑)。
10463
- const sections = query === "" ? parsed.sections : parsed.sections
10887
+ const filtered = parsed.sections
10464
10888
  .map(function (sec) {
10465
- const hit = sec.items.filter(function (it) {
10889
+ const kept = todoFilterItems(sec.items, filter);
10890
+ const hit = query === "" ? kept : kept.filter(function (it) {
10466
10891
  const hay = ((it.title || "") + " " + it.text + " " + (it.cont || "")).toLowerCase();
10467
10892
  return hay.indexOf(query) >= 0;
10468
10893
  });
10469
- return { sec: sec, hit: hit };
10894
+ return { sec: sec, kept: kept, hit: hit };
10895
+ })
10896
+ .filter(function (row) {
10897
+ // 空组:搜索时整组隐掉;只筛「未完成」时,普通组没剩条目也隐掉
10898
+ // (否则一屏「▸ 组名 0 / 3」的空壳),待删除块例外 —— 见 todoFilterItems 的注释。
10899
+ if (row.sec.kind === "done") return true;
10900
+ if (row.hit.length > 0) return true;
10901
+ return row.sec.items.length === 0 && query === "";
10470
10902
  })
10471
- .filter(function (row) { return row.hit.length > 0; })
10472
10903
  .map(function (row) { return Object.assign({}, row.sec, { items: row.hit }); });
10904
+ const sections = filtered;
10473
10905
  const matchCount = sections.reduce(function (n, sec) { return n + sec.items.length; }, 0);
10474
10906
  const stats = t("todo.stat", { open: parsed.open, done: parsed.done, sections: parsed.sections.length });
10475
10907
  // 「清空全部」清的是整个待删除块,数字取块的真实条数(搜索过滤后也一样)。
10476
10908
  const doneBlock = parsed.sections.find(function (sec) { return sec.kind === "done"; });
10477
10909
  const doneBlockCount = doneBlock ? doneBlock.items.length : 0;
10910
+ // 检查点区块的条目总数(只读,来自 tasks/*/WORKING.md)。
10911
+ const cpTasks = (checkpoints || []).filter(function (task) {
10912
+ return task && Array.isArray(task.items) && task.items.length > 0;
10913
+ });
10914
+ const cpCount = cpTasks.reduce(function (n, task) { return n + task.items.length; }, 0);
10478
10915
 
10479
10916
  return h("div", { className: "smem-todo" }, [
10480
10917
  h("div", { key: "head", className: "smem-todo-head" }, [
@@ -10482,7 +10919,7 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10482
10919
  h("span", { key: "sp", "data-spring": "" }),
10483
10920
  h("button", {
10484
10921
  key: "u", type: "button", className: "smem-todo-icon-btn",
10485
- title: t("todo.action.undo"), "aria-label": t("todo.action.undo"),
10922
+ title: t("todo.action.undoTitle", { depth: undoDepth }), "aria-label": t("todo.action.undo"),
10486
10923
  disabled: busy || undoStack.length === 0,
10487
10924
  onClick: onUndo,
10488
10925
  }, todoArrowIcon("undo")),
@@ -10493,7 +10930,35 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10493
10930
  onClick: onRedo,
10494
10931
  }, todoArrowIcon("redo")),
10495
10932
  h("button", { key: "a", type: "button", className: "smem-link smem-todo-mini", onClick: function () { setAllOpen(allOpen === true ? false : true); } }, allOpen === true ? t("todo.collapseAll") : t("todo.expandAll")),
10496
- h("button", { key: "r", type: "button", className: "smem-link smem-todo-mini", disabled: busy, onClick: function () { load(false); } }, t("todo.refresh")),
10933
+ h("button", { key: "r", type: "button", className: "smem-link smem-todo-mini", disabled: busy, onClick: function () { load(false); loadCheckpoints(); } }, t("todo.refresh")),
10934
+ ]),
10935
+ // 第二行:筛选 + 撤销步数。右栏很窄,搜索框单独一行。
10936
+ h("div", { key: "tools", className: "smem-todo-tools" }, [
10937
+ h("button", {
10938
+ key: "f1", type: "button",
10939
+ className: "smem-todo-mini smem-todo-filter" + (filter === TODO_FILTER_OPEN ? " smem-todo-filter-on" : ""),
10940
+ title: t("todo.filter.openTitle"), "aria-pressed": filter === TODO_FILTER_OPEN,
10941
+ onClick: function () { setFilter(TODO_FILTER_OPEN); },
10942
+ }, t("todo.filter.open")),
10943
+ h("button", {
10944
+ key: "f2", type: "button",
10945
+ className: "smem-todo-mini smem-todo-filter" + (filter === TODO_FILTER_ALL ? " smem-todo-filter-on" : ""),
10946
+ title: t("todo.filter.allTitle"), "aria-pressed": filter === TODO_FILTER_ALL,
10947
+ onClick: function () { setFilter(TODO_FILTER_ALL); },
10948
+ }, t("todo.filter.all")),
10949
+ h("span", { key: "sp2", "data-spring": "" }),
10950
+ h("label", { key: "dep", className: "smem-todo-depth" }, [
10951
+ h("span", { key: "l", className: "smem-todo-depth-label" }, t("todo.undoDepth.label")),
10952
+ h("select", {
10953
+ key: "sel",
10954
+ className: "smem-input smem-todo-depth-select",
10955
+ value: String(undoDepth),
10956
+ disabled: busy,
10957
+ onChange: function (e) { changeDepth(e.target.value); },
10958
+ }, [TODO_UNDO_MIN, TODO_UNDO_MIN + 1, TODO_UNDO_MAX].map(function (n) {
10959
+ return h("option", { key: "o" + n, value: String(n) }, t("todo.undoDepth.option", { n: n }));
10960
+ })),
10961
+ ]),
10497
10962
  ]),
10498
10963
  // 搜索框放统计条下面一行:右栏很窄,塞进同一行会把按钮挤没。
10499
10964
  h("div", { key: "search", className: "smem-todo-search-row" }, [
@@ -10509,6 +10974,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10509
10974
  ]),
10510
10975
  err ? h("div", { key: "err", className: "smem-err" }, "⚠ " + err) : null,
10511
10976
  notice ? h("div", { key: "ok", className: "smem-ok" }, "✓ " + notice) : null,
10977
+ cpCount > 0
10978
+ ? h(TodoCheckpointBlock, { key: "cp", tasks: cpTasks, count: cpCount })
10979
+ : null,
10512
10980
  missing
10513
10981
  ? h("div", { key: "miss", className: "smem-todo-empty" }, t("todo.empty.file", { file: TODO_FILE }))
10514
10982
  : (query !== "" && sections.length === 0
@@ -10517,8 +10985,11 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10517
10985
  return h(TodoSectionGroup, {
10518
10986
  key: "s" + i, section: sec, busy: busy, allOpen: query === "" ? allOpen : true,
10519
10987
  doneCount: doneBlockCount,
10988
+ openMap: openMap,
10989
+ onGroupToggle: toggleGroupPref,
10520
10990
  onToggle: function (it, d) { onToggle(it, d, sec.title); },
10521
- onAdd: onAdd, onEdit: onEdit, onDelete: onDelete, onClearDone: onClearDone,
10991
+ onAdd: onAdd, onEdit: onEdit, onDelete: onDelete,
10992
+ onClearDone: onClearDone, onArchive: onArchive,
10522
10993
  });
10523
10994
  }))),
10524
10995
  ]);
@@ -10688,9 +11159,26 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
10688
11159
  // 只给 `test/todo-board-test.mjs` 用,运行期没有任何代码读它(宿主只认 apply / inject)。
10689
11160
  exports.todoBoardInternals = {
10690
11161
  FILE: TODO_FILE,
11162
+ LOG_FILE: TODO_LOG_FILE,
10691
11163
  TAB_KIND: TODO_TAB_KIND,
10692
11164
  DONE_HEADING: TODO_DONE_HEADING,
10693
- UNDO_DEPTH: TODO_UNDO_DEPTH,
11165
+ UNDO_MIN: TODO_UNDO_MIN,
11166
+ UNDO_MAX: TODO_UNDO_MAX,
11167
+ UNDO_DEFAULT: TODO_UNDO_DEFAULT,
11168
+ FILTER_OPEN: TODO_FILTER_OPEN,
11169
+ FILTER_ALL: TODO_FILTER_ALL,
11170
+ PREF_UNDO: TODO_PREF_UNDO,
11171
+ PREF_OPEN: TODO_PREF_OPEN,
11172
+ clampDepth: todoClampUndoDepth,
11173
+ filterItems: todoFilterItems,
11174
+ groupKey: todoGroupKey,
11175
+ openMapParse: todoOpenMapParse,
11176
+ openMapSerialize: todoOpenMapSerialize,
11177
+ logKey: todoLogKey,
11178
+ logKeys: todoLogKeys,
11179
+ stamp: todoStamp,
11180
+ archiveBlock: todoArchiveBlock,
11181
+ logAppend: todoSessionLogAppend,
10694
11182
  parse: parseTodoList,
10695
11183
  titleOf: todoItemTitle,
10696
11184
  bullet: todoBullet,
package/lib/index.js CHANGED
@@ -13,7 +13,7 @@ import { INDEX_FILE_KEY, SESSION_LOG_KEY, isPlainMdName } from './shared/md-name
13
13
  import { parseAliases, parseBaseline, parseBaselinePriority, parseFrontmatter, parseTags } from './memory/frontmatter.js'
14
14
  import { ageDays, bigrams, score, selectBaseline, selectRelevant } from './memory/retrieval.js'
15
15
  import { isReserved, nameKey, safeName } from './memory/naming.js'
16
- import { MEMORY_ARCHIVE_DIR, addArchiveMeta, extractTitle, inspectDir, inspectMemoryEntry, readArchivedMeta, readVerified, scanArchived, scanMemoryFiles, scanStars, shadowsReserved } from './memory/scan.js'
16
+ import { MEMORY_ARCHIVE_DIR, addArchiveMeta, extractTitle, inspectDir, inspectMemoryEntry, readArchivedMeta, readVerified, scanArchived, scanCheckpointOpen, scanMemoryFiles, scanStars, shadowsReserved } from './memory/scan.js'
17
17
  import { listConflicts, patchConflict, readConflict, removeConflict, summarizeConflict } from './memory/conflicts.js'
18
18
  import { invalidateMemory, undoMemoryInvalidation } from './memory/arbitrate.js'
19
19
  import { prepareWrite, readSnapshot, writeSnapshot } from './memory/write-protocol.js'
@@ -343,6 +343,17 @@ export class MemoryGateway extends TypertRemoteService {
343
343
  return auditMemoryDir(MEMORY_DIR)
344
344
  }
345
345
 
346
+ /**
347
+ * 任务检查点里「未完成」的条目(2.15.0 · 待办看板用,只读)。
348
+ *
349
+ * 只扫 `<状态根>/tasks/<id>/WORKING.md`,按 `TODO_SECTION` 取条目;
350
+ * 不写、不合并 —— 那些文件有自己的 revision 与写协议(`writeCheckpoint`)。
351
+ * 状态根不接受界面传入(跟 `openMemoryDir` 同一条纪律:别把「读任意路径」变成能力)。
352
+ */
353
+ async checkpoints() {
354
+ return scanCheckpointOpen(STATE_ROOT)
355
+ }
356
+
346
357
  /**
347
358
  * 用系统文件管理器打开记忆目录(设置页「打开记忆文件夹」)。
348
359
  *
@@ -601,6 +612,7 @@ markRemote(MemoryGateway, 'readArchived', 'readArchived')
601
612
  markRemote(MemoryGateway, 'writeArchived', 'writeArchived')
602
613
  markRemote(MemoryGateway, 'deleteArchived', 'deleteArchived')
603
614
  markRemote(MemoryGateway, 'audit', 'audit')
615
+ markRemote(MemoryGateway, 'checkpoints', 'checkpoints')
604
616
  markRemote(MemoryGateway, 'openMemoryDir', 'openMemoryDir')
605
617
  markRemote(MemoryGateway, 'checkUpdate', 'checkUpdate')
606
618
  markRemote(MemoryGateway, 'setLocked', 'setLocked')
@@ -247,7 +247,8 @@ const SUB_LABEL_RE = /^(?:目标|约束|限制|备注)\s*[::]?\s*$/
247
247
  * 下标只在渲染模板(顺序即模板顺序)里用。
248
248
  */
249
249
  const DONE_SECTION = '已完成与证据'
250
- const TODO_SECTION = '未完成'
250
+ /** 2.15.0:待办看板要按**名字**取这一节的条目(`lib/memory/checkpoints.js` 只读复用)。 */
251
+ export const TODO_SECTION = '未完成'
251
252
 
252
253
  /**
253
254
  * 节内容的「实义行」:剥掉列表标记与子标签,再滤掉空行与占位符。
@@ -268,7 +269,7 @@ function significantLines(text) {
268
269
  * 把节内容切成条目:bullet(`-` / `*` / `1.`)各算一条,**不以 bullet 开头的行并入上一条**
269
270
  * (同一件事的证据常常写在换行的续行里,切开会把证据判丢)。节内的小标题不算条目。
270
271
  */
271
- function itemsOf(text) {
272
+ export function itemsOf(text) {
272
273
  const items = []
273
274
  for (const raw of String(text ?? '').split(/\r?\n/)) {
274
275
  const line = raw.trim()
@@ -15,6 +15,7 @@ import { parseBaseline, parseFrontmatter } from './frontmatter.js'
15
15
  import { isMemoryEntry, isReserved } from './naming.js'
16
16
  import { warnLog } from './util.js'
17
17
  import { createDirWatcher } from './watch.js'
18
+ import { CHECKPOINT_FILE_NAME, TASKS_DIR_NAME, TODO_SECTION, itemsOf, normalizeTaskId, parseCheckpoint } from './checkpoint.js'
18
19
  import { lstat, open, readFile, readdir } from 'node:fs/promises'
19
20
  import { join } from 'node:path'
20
21
 
@@ -645,3 +646,58 @@ export async function scanStars(ctx, includeArchived = false) {
645
646
  if (includeArchived !== true) return active
646
647
  return [...active, ...(await scanArchived(ctx))]
647
648
  }
649
+
650
+ /** 最多列几个任务检查点(面板一屏放得下,也免得一次读几百份文件)。 */
651
+ export const CHECKPOINT_TASK_LIMIT = 12
652
+ /** 每个任务最多列几条「未完成」(这是提示,不是完整清单 —— 全文在那份检查点里)。 */
653
+ export const CHECKPOINT_ITEM_LIMIT = 20
654
+ /** 单份检查点的读取上限:正常 64 KB 就该拆了,超过这个数一律不读。 */
655
+ const CHECKPOINT_READ_LIMIT = 256 * 1024
656
+
657
+ /**
658
+ * 扫一遍所有任务检查点,收集「未完成」条目(2.15.0 · 待办看板只读聚合)。
659
+ *
660
+ * 待办看板除了那份 `project_session-state.md`,还要让人看见别的文件里欠着的活 ——
661
+ * `<状态根>/tasks/<taskId>/WORKING.md` 的「未完成」节就是那种东西。三条纪律:
662
+ * 1. **只读**。不写、不合并、不改任何检查点 —— 那些文件各有自己的 revision 与写协议
663
+ * (`writeCheckpoint`),看板不是它们的作者。
664
+ * 2. **失败就跳过那一条**,不让整块聚合失败(一个坏文件不该让看板空掉)。
665
+ * 3. **坏检查点不显示**:`malformedReason` 非空就不算待办 —— 与 `readCheckpoint`
666
+ * 同一条判据(读不出来的东西比读不到更危险)。
667
+ *
668
+ * @param {string} [stateRoot] 状态根(调用方传 `STATE_ROOT`)
669
+ * @returns {Promise<{ok: boolean, tasks: Array<{taskId: string, project: string, revision: number, items: string[]}>,
670
+ * truncated: boolean, error?: string}>} **绝不抛**
671
+ */
672
+ export async function scanCheckpointOpen(stateRoot) {
673
+ const dir = join(typeof stateRoot === 'string' && stateRoot !== '' ? stateRoot : '.', TASKS_DIR_NAME)
674
+ let entries = []
675
+ try {
676
+ entries = await readdir(dir, { withFileTypes: true })
677
+ } catch (err) {
678
+ // 没有 tasks 目录是**正常状态**(从没用过检查点),不是错误。
679
+ if (err && err.code === 'ENOENT') return { ok: true, tasks: [], truncated: false }
680
+ return { ok: false, tasks: [], truncated: false, error: String((err && err.message) || err) }
681
+ }
682
+ const ids = entries
683
+ .filter((e) => e && typeof e.isDirectory === 'function' && e.isDirectory() && normalizeTaskId(e.name) !== null)
684
+ .map((e) => e.name)
685
+ .sort()
686
+ const truncated = ids.length > CHECKPOINT_TASK_LIMIT
687
+ const tasks = []
688
+ for (const id of ids.slice(0, CHECKPOINT_TASK_LIMIT)) {
689
+ let text = ''
690
+ try {
691
+ text = await readFile(join(dir, id, CHECKPOINT_FILE_NAME), 'utf8')
692
+ } catch (err) {
693
+ continue // 目录里没有 WORKING.md、或者读不了:跳过这一条
694
+ }
695
+ if (text.length > CHECKPOINT_READ_LIMIT) continue
696
+ const parsed = parseCheckpoint(text)
697
+ if (parsed.malformedReason !== '') continue
698
+ const items = itemsOf(parsed.sections[TODO_SECTION] || '').slice(0, CHECKPOINT_ITEM_LIMIT)
699
+ if (items.length === 0) continue
700
+ tasks.push({ taskId: id, project: parsed.project, revision: parsed.revision, items })
701
+ }
702
+ return { ok: true, tasks, truncated }
703
+ }
@@ -649,6 +649,15 @@ const conflictRemoveResultSchema = z.object({
649
649
  'code': z.string().readonly().optional(),
650
650
  'error': z.string().readonly().optional(),
651
651
  }).readonly()
652
+ // 2.15.0:任务检查点里「未完成」的条目(待办看板只读聚合)。
653
+ const checkpointTaskSchema = z.object({
654
+ 'taskId': z.string().readonly(), 'project': z.string().readonly(),
655
+ 'revision': z.number().readonly(), 'items': z.array(z.string().readonly()).readonly(),
656
+ }).readonly()
657
+ const checkpointsResultSchema = z.object({
658
+ 'ok': z.boolean().readonly(), 'truncated': z.boolean().readonly(),
659
+ 'tasks': z.array(checkpointTaskSchema).readonly(), 'error': z.string().readonly().optional(),
660
+ }).readonly()
652
661
 
653
662
  export const TYPERT = {
654
663
  package: 'sage-mem',
@@ -785,6 +794,14 @@ export const TYPERT = {
785
794
  result: { mode: 'strict', typeSymbol: 'sage-mem/types#ArchiveResult', schema: archiveResultSchema, create: () => archiveResultSchema },
786
795
  sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
787
796
  },
797
+ {
798
+ // 2.15.0:待办看板把各任务检查点里的「未完成」并进视野(只读,不写回)。
799
+ id: 'sage-mem#memory/checkpoints',
800
+ service: 'memory', namespace: 'memory', method: 'checkpoints',
801
+ invocation: { kind: 'direct' }, parameters: [],
802
+ result: { mode: 'strict', typeSymbol: 'sage-mem/types#Checkpoints', schema: checkpointsResultSchema, create: () => checkpointsResultSchema },
803
+ sourceLocation: { "file": "lib/index.js", "line": 1, "column": 1 },
804
+ },
788
805
  {
789
806
  id: 'sage-mem#memory/audit',
790
807
  service: 'memory',
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.14.0",
4
+ "version": "2.15.1",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "icon": "./icon.png",
@@ -140,6 +140,7 @@ metadata:
140
140
  你的义务,三句:
141
141
 
142
142
  1. **别让它堆积。** 下次读写这个文件、或会话收尾写 `session-log.md` 时,把「已完成,待删除」里的行搬进流水留档,再从 `project_session_state.md` 删掉。
143
+ (2.15.0 起看板上有一颗「搬进流水」:用户自己点也能完成同一件事 —— 正文照抄、已记过的跳过。**看到它搬过就别再搬一遍**:以流水里已有的正文为准。)
143
144
  2. **只动那些行。** 绝不自行删除「已完成,待删除」以外、用户没勾选的条目。
144
145
  3. **改它只做行级替换 / 删除。** 不重排、不重建 frontmatter、不顺手「整理」别的节。
145
146