sage-mem 2.29.1 → 2.30.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.29.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.30.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.
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.29.1`** —— 顶部 npm 徽章是动态权威。**契约基线:`1.0.0`** —— 第一个稳定版,公开承诺、能力边界与「明确做不到」的清单冻结在
17
+ **当前发布版本:`2.30.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 是最直接的反馈。
package/lib/client.js CHANGED
@@ -1741,7 +1741,8 @@ const StarmapRuntime = (function (require, _react) {
1741
1741
  const isStrArr = (v) => { if (!Array.isArray(v)) throw new Error("expected string array"); for (const x of v) isStr(x); };
1742
1742
  // 字段必须与宿主 `lib/typert.host.js` 的 fileSchema **同宽**(strict 会剥掉未声明字段):
1743
1743
  // 少了 tags / locked,列表页的「按标签筛」与「锁定」按钮就永远拿到 undefined。
1744
- const fileSchema = optionalFields(parseSchema({ "file": isStr, "type": isStr, "description": isStr, "size": isNum, "tags": isStrArr, "locked": isBool }), { "revision": isStr });
1744
+ // 2.30.0 加 `exposedBy`(可选):外部访问面板据此画勾选,不再自己算白名单判据。
1745
+ const fileSchema = optionalFields(parseSchema({ "file": isStr, "type": isStr, "description": isStr, "size": isNum, "tags": isStrArr, "locked": isBool }), { "revision": isStr, "exposedBy": isStr });
1745
1746
  const listSchema = { fields: fileSchema.fields, parse(v) { if (!Array.isArray(v)) throw new Error("expected array"); v.forEach((f) => fileSchema.parse(f)); return v; } };
1746
1747
  const readSchema = withOptional(parseSchema({ "name": isStr, "content": isStr }), ["revision"]);
1747
1748
  const writeSchema = optionalFields(parseSchema({ "ok": isBool, "file": isStr }), { "error": isStr, "code": isStr, "revision": isStr });
@@ -8258,31 +8259,21 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
8258
8259
  }
8259
8260
 
8260
8261
  /**
8261
- * 某个文件**现在是否在白名单里** —— 这是「意图」,不是「上一轮导出的结果」。
8262
+ * 某个文件**现在是否在白名单里** —— 直接读后端给的 `exposedBy`。
8262
8263
  *
8263
- * 为什么不能拿 `exposedNames` 当勾选态:那是导出**之后**的结果,最多要等 45 秒才更新。
8264
- * 用户点一下勾,界面半分钟内不动,看起来就是「点了没反应」(2026-12-04 实测两次)。
8265
- * 这里按 include / exclude / prefixes 现算,点完立刻变。
8264
+ * 2.30.0 起前端**不再自己算**:判据只有 `lib/mirror/policy.js` 的 `exposedByOf` 一处。
8265
+ * 之前那份复制品(按 include / exclude / prefixes / tags 现算)曾经漏掉 tags 维度、
8266
+ * 大小写口径也与后端不同 —— 症状是「勾着但没导出去」,或者反过来。
8266
8267
  *
8267
- * 三者优先级与后端 `lib/mirror/policy.js` 一致:排除 > 包含 > 前缀。
8268
+ * `exposedBy` 缺省(旧宿主不返回)时按 `'none'` 处理:宁可少勾,也不假装。
8268
8269
  */
8269
8270
  function isIncluded(name) {
8270
- if (!ext) return false;
8271
8271
  const n = String(name);
8272
- // 大小写不敏感 —— 与后端 `policy.js:246-247` 同口径。名单可能被手改过
8273
- // (`Project_Beta.md`),前端按精确全等判就会画出「勾着但实际没导」。
8274
- const lower = n.toLowerCase();
8275
- const inc = (ext.include || []).map(function (x) { return String(x).toLowerCase(); });
8276
- const exc = (ext.exclude || []).map(function (x) { return String(x).toLowerCase(); });
8277
- if (exc.indexOf(lower) >= 0) return false;
8278
- if (inc.indexOf(lower) >= 0) return true;
8279
- // 与后端 `lib/mirror/policy.js` 的 `isExposed` **同序**:排除 > 包含 > 前缀 > 标签。
8280
- // 前端**刻意不判 `enabled`** —— 关着的时候勾选是「打开后要导出什么」,不是「现在正在导出」。
8281
- if ((ext.prefixes || []).some(function (p) { return lower.indexOf(String(p).toLowerCase()) === 0; })) return true;
8282
8272
  const hit = (files || []).filter(function (f) { return String(f && f.file) === n; })[0];
8283
- const own = (hit && Array.isArray(hit.tags) ? hit.tags : []).map(function (t) { return String(t).toLowerCase(); });
8284
- if (own.length && (ext.tags || []).some(function (t) { return own.indexOf(String(t).toLowerCase()) >= 0; })) return true;
8285
- return false;
8273
+ if (!hit || typeof hit.exposedBy !== "string") return false;
8274
+ // ⚠️ `'exclude'` 表示「被显式排除」,不是「勾上」—— 只判 `!== 'none'` 会把它画成勾选态
8275
+ // (2026-12-04 实验室里抓到:一条被排除的记忆显示成勾着)。
8276
+ return hit.exposedBy !== "none" && hit.exposedBy !== "exclude";
8286
8277
  }
8287
8278
 
8288
8279
  /**
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, scanCheckpointOpen, scanMemoryFiles, scanStars, shadowsReserved } from './memory/scan.js'
16
+ import { MEMORY_ARCHIVE_DIR, addArchiveMeta, extractTitle, inspectDir, inspectMemoryEntry, readArchivedMeta, readVerified, listMemoryFiles, 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, revisionOf, writeSnapshot } from './memory/write-protocol.js'
@@ -118,25 +118,12 @@ export class MemoryGateway extends TypertRemoteService {
118
118
  }
119
119
 
120
120
  /** 列出 memory 目录全部记忆文件(文件名 + 类型 + 描述 + 大小 + 自定义标签 + 是否锁定)。 */
121
+ /**
122
+ * 列出记忆目录里的全部条目(2.30.0 搬到 `memory/list-files.js`:本文件卡 1000 行)。
123
+ * 字段与语义不变,多了 `exposedBy` —— 外部访问面板据此画勾选,不再自己算判据。
124
+ */
121
125
  async listFiles() {
122
- const [files, lockState] = await Promise.all([scanMemoryFiles(this.ctx, ''), readLockState(MEMORY_DIR)])
123
- // Q05:锁表坏了也照样列文件,但不假装「都没锁」;逐条 locked 只有布尔,未知只能靠日志。
124
- if (lockState.status === 'unknown') warnLog(this.ctx, `锁表不可读,列表里的锁定状态未知(不是「都没锁」):${lockState.reason}`)
125
- return files.map(f => {
126
- const meta = parseFrontmatter(f.content)
127
- return {
128
- file: f.file,
129
- type: meta.type || 'reference',
130
- description: meta.description || '',
131
- size: f.content.length,
132
- tags: meta.tags,
133
- // 2.21.0:删除确认必须能交回「我看到的是哪一版」。与 readFile 用同一个
134
- // 正文字节 sha256(write-protocol.revisionOf),名字不再是身份。
135
- revision: revisionOf(Buffer.from(f.content, 'utf8')),
136
- // 锁定状态跟着每条一起给:卡片上的「锁定 / 已锁定」按钮要据此渲染
137
- locked: lockState.status === 'unknown' ? false : lockState.locked.has(nameKey(f.file)),
138
- }
139
- })
126
+ return listMemoryFiles(this.ctx, MEMORY_DIR)
140
127
  }
141
128
 
142
129
  /**
@@ -12,7 +12,11 @@
12
12
 
13
13
  import { MAX_FILE_BYTES, MEMORY_DIR } from './config.js'
14
14
  import { parseBaseline, parseFrontmatter } from './frontmatter.js'
15
- import { isMemoryEntry, isReserved } from './naming.js'
15
+ import { isMemoryEntry, isReserved, nameKey } from './naming.js'
16
+ import { readExternalSettings } from '../settings.js'
17
+ import { readLockState } from './lock.js'
18
+ import { revisionOf } from './write-protocol.js'
19
+ import { exposedByOf } from '../mirror/policy.js'
16
20
  import { warnLog } from './util.js'
17
21
  import { createDirWatcher } from './watch.js'
18
22
  import { CHECKPOINT_FILE_NAME, TASKS_DIR_NAME, TODO_SECTION, itemsOf, normalizeTaskId, parseCheckpoint } from './checkpoint.js'
@@ -721,4 +725,51 @@ export async function scanCheckpointOpen(stateRoot) {
721
725
  const out = { ok: true, tasks, truncated: truncated || itemsTruncated }
722
726
  if (skipped > 0) out.skipped = skipped
723
727
  return out
724
- }
728
+ }
729
+ /**
730
+ * 列出记忆目录里的全部条目(2.30.0 从 `lib/index.js` 的 `MemoryGateway.listFiles` 搬来)。
731
+ *
732
+ * 为什么搬:组合根有「本地 import 条数 ≤ 20」的硬线,再加一条就 21 —— 而这里
733
+ * 本来就在组合根的 import 名单里,把函数挂过来不增加条数。
734
+ *
735
+ * 比原来多的一件事是 `exposedBy`:面板的勾选框不再自己算「这条在不在外部访问白名单里」,
736
+ * 而是直接用后端结论。判据只有 `mirror/policy.js` 的 `exposedByOf` 一处 ——
737
+ * 前端那份复制品曾经漏掉 `tags` 维度、大小写口径也不同。
738
+ *
739
+ * @param {object} ctx — 宿主上下文(只用 `warnLog`)
740
+ * @param {string} memoryDir — 记忆目录
741
+ * @returns {Promise<Array<object>>}
742
+ */
743
+ export async function listMemoryFiles(ctx, memoryDir) {
744
+ const [files, lockState, externalRead] = await Promise.all([
745
+ scanMemoryFiles(ctx, ''),
746
+ readLockState(memoryDir),
747
+ // 设置读不出来不该让列表整个失败:退化成「一条都不在白名单里」,面板仍能显示文件。
748
+ readExternalSettings().catch(() => ({ external: null, diagnostics: [] })),
749
+ ])
750
+ const external = externalRead && externalRead.external ? externalRead.external : null
751
+
752
+ // Q05:锁表坏了也照样列文件,但不假装「都没锁」;逐条 locked 只有布尔,未知只能靠日志。
753
+ if (lockState.status === 'unknown') {
754
+ warnLog(ctx, `锁表不可读,列表里的锁定状态未知(不是「都没锁」):${lockState.reason}`)
755
+ }
756
+
757
+ return files.map(f => {
758
+ const meta = parseFrontmatter(f.content)
759
+ return {
760
+ file: f.file,
761
+ type: meta.type || 'reference',
762
+ description: meta.description || '',
763
+ size: f.content.length,
764
+ tags: meta.tags,
765
+ // 2.21.0:删除确认必须能交回「我看到的是哪一版」。与 readFile 用同一个
766
+ // 正文字节 sha256(write-protocol.revisionOf),名字不再是身份。
767
+ revision: revisionOf(Buffer.from(f.content, 'utf8')),
768
+ // 锁定状态跟着每条一起给:卡片上的「锁定 / 已锁定」按钮要据此渲染
769
+ locked: lockState.status === 'unknown' ? false : lockState.locked.has(nameKey(f.file)),
770
+ // 2.30.0:`'exclude' | 'include' | 'prefix' | 'tag' | 'none'`。
771
+ // **不看总开关** —— 关着的时候面板仍要按「意图」把勾选画出来(2.29.0 定的语义)。
772
+ exposedBy: exposedByOf(f.file, meta.tags, external),
773
+ }
774
+ })
775
+ }
@@ -224,31 +224,54 @@ export function parseExternalPatch(external) {
224
224
  }
225
225
 
226
226
  /**
227
- * 一条记忆要不要被导出 —— **唯一判据**。
227
+ * 一条记忆**凭什么**算在白名单里 —— `'exclude' | 'include' | 'prefix' | 'tag' | 'none'`。
228
228
  *
229
- * 优先级(先命中先返回):逐条排除 > 逐条包含 > 前缀 > 标签 > 不暴露。
229
+ * 优先级(先命中先返回):逐条排除 > 逐条包含 > 前缀 > 标签 > 不在白名单。
230
230
  * `exclude` 压过一切是刻意的:面板上「取消勾选」必须能压过「`project_` 整类打开」,
231
231
  * 否则用户会看到一个关不掉的开关。
232
232
  *
233
+ * ⚠️ **本函数不看 `enabled`**。它回答的是「设置上算不算」,不是「现在导不导」。
234
+ * 面板的勾选框要的正是这个:总开关关着的时候,用户仍然可以先勾名单,打开即生效
235
+ * (2.29.0 定的语义)。「现在导不导」由 `isExposed` 负责。
236
+ *
233
237
  * @param {string} name — 文件名(`project_x.md`)
234
238
  * @param {string[]} [tags] — 该条 frontmatter 的 tags
235
239
  * @param {object} external — `resolveExternal` 的产物
240
+ * @returns {'exclude'|'include'|'prefix'|'tag'|'none'}
236
241
  */
237
- export function isExposed(name, tags, external) {
238
- if (!external || !external.enabled) return false
242
+ export function exposedByOf(name, tags, external) {
243
+ if (!external) return 'none'
239
244
  const file = String(name ?? '')
240
- if (file === '') return false
245
+ if (file === '') return 'none'
241
246
  // 前缀只是「看起来像」,名字本身还得是**单段 .md**:`project_../../etc/passwd` 以
242
247
  // `project_` 开头,但它不是一个记忆名。导出层拿到的名字来自 `scan.js`(已经过滤过),
243
248
  // 这道判定是给面板逐条勾选与将来的调用方兜底的 —— 判据只有一份,就别指望上游一定干净。
244
- if (!isPlainMdName(file)) return false
249
+ if (!isPlainMdName(file)) return 'none'
245
250
  const lower = file.toLowerCase()
246
- if ((external.exclude ?? []).some((n) => String(n).toLowerCase() === lower)) return false
247
- if ((external.include ?? []).some((n) => String(n).toLowerCase() === lower)) return true
248
- if ((external.prefixes ?? []).some((p) => lower.startsWith(String(p).toLowerCase()))) return true
251
+ if ((external.exclude ?? []).some((n) => String(n).toLowerCase() === lower)) return 'exclude'
252
+ if ((external.include ?? []).some((n) => String(n).toLowerCase() === lower)) return 'include'
253
+ if ((external.prefixes ?? []).some((p) => lower.startsWith(String(p).toLowerCase()))) return 'prefix'
249
254
  const own = (Array.isArray(tags) ? tags : []).map((t) => String(t).toLowerCase())
250
- if (own.length && (external.tags ?? []).some((t) => own.includes(String(t).toLowerCase()))) return true
251
- return false
255
+ if (own.length && (external.tags ?? []).some((t) => own.includes(String(t).toLowerCase()))) return 'tag'
256
+ return 'none'
257
+ }
258
+
259
+ /**
260
+ * 一条记忆**现在**要不要被导出 —— **唯一判据**。
261
+ *
262
+ * 2026-12-04 起它只是 `exposedByOf` + 总开关:原因与「导不导」共用同一张优先级表,
263
+ * 不再各写一遍。面板也不再自己算(`listFiles` 会把 `exposedBy` 一起给出去)。
264
+ *
265
+ * @param {string} name — 文件名(`project_x.md`)
266
+ * @param {string[]} [tags] — 该条 frontmatter 的 tags
267
+ * @param {object} external — `resolveExternal` 的产物
268
+ */
269
+ export function isExposed(name, tags, external) {
270
+ if (!external || !external.enabled) return false
271
+ const why = exposedByOf(name, tags, external)
272
+ // ⚠️ `'exclude'` 也是**不暴露** —— 它表示「这条被显式排除了」。
273
+ // 只写 `!== 'none'` 会把「被排除」判成「暴露」(2026-12-04 由 `mirror-policy-test` 抓到)。
274
+ return why !== 'none' && why !== 'exclude'
252
275
  }
253
276
 
254
277
  /**
@@ -74,6 +74,10 @@ export const fileSchema = z.object({
74
74
  // 锁定状态(拒绝归档)跟着每条一起给 —— strict 会把没声明的字段剥掉,
75
75
  // 不在这里声明,卡片上的「锁定 / 已锁定」按钮就永远拿到 undefined。
76
76
  'locked': z.boolean().readonly(),
77
+ // 2.30.0:这条在外部访问白名单里的去向 —— 'exclude' | 'include' | 'prefix' | 'tag' | 'none'。
78
+ // 字段**可选**(additive 契约:只加不改)。面板据此画勾选,不再自己算判据 ——
79
+ // 前端那份复制品曾经漏掉 tags 维度,大小写口径也与后端不同。
80
+ 'exposedBy': z.string().readonly().optional(),
77
81
  }).readonly()
78
82
 
79
83
  export const listResultSchema = z.array(fileSchema)
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.29.1",
4
+ "version": "2.30.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "icon": "./icon.png",