sage-mem 2.29.1 → 2.31.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 +3 -7
- package/README.md +3 -7
- package/lib/client.js +45 -21
- package/lib/index.js +6 -19
- package/lib/memory/scan.js +53 -2
- package/lib/mirror/mcp.js +6 -0
- package/lib/mirror/policy.js +34 -11
- package/lib/typert/schemas.js +4 -0
- package/package.json +1 -1
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
|
+
**Current release: `2.31.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.
|
|
@@ -898,13 +898,9 @@ Or manually delete the `sage-mem` dependency from the profile's `package.json` a
|
|
|
898
898
|
- **`interpolate: false` on the recall context** (2.4.2): a memory body containing double braces made the host throw `malformed prompt variable reference` while assembling the prompt, so the turn failed before the model even started — it looked like "sometimes it chats, sometimes any question fails", depending on which memories that turn happened to recall.
|
|
899
899
|
- **A short-circuit gate in the recall chain** (2.4.3): `system-prompt/assemble` fires on every step, and the old implementation ran the whole "scan → summary scoring → body BM25 → signature" chain before deduplicating. The decision inputs are all available before scoring.
|
|
900
900
|
- **The "open memory folder" entry** (2.4.0): no more hunting for the path in a file manager.
|
|
901
|
-
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** —
|
|
902
|
-
- **Everything is a plugin, plus Cordis's service / event / fiber model** — file-based memory therefore needs no worker, port, or database;
|
|
903
|
-
- **`ctx.systemPrompt.section` and `agent/pre-step`** — injection and the pre-compaction reminder land on the right seams, instead of a prompt line saying "remember to read the files";
|
|
904
|
-
- **The typert remote protocol** — the type-safe channel between panel and host; the delete guard in 2.21.0 and the rollback guard in 2.22.0 both rely on it to carry "the version you confirmed" over to the host side;
|
|
905
|
-
- **The official docs (AGENTS.md / cordis-api / persistence)** — plugin authors can verify for themselves instead of guessing.
|
|
901
|
+
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** — the host; everything is a plugin.
|
|
906
902
|
|
|
907
|
-
|
|
903
|
+
The list above follows the order in which each contribution entered the repository. Corrections and omissions are welcome — please open an issue.
|
|
908
904
|
|
|
909
905
|
## Related Projects
|
|
910
906
|
|
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.
|
|
17
|
+
**当前发布版本:`2.31.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 是最直接的反馈。
|
|
@@ -903,13 +903,9 @@ dsh plugin --profile web remove sage-mem
|
|
|
903
903
|
- **注入段声明 `interpolate: false`**(2.4.2):记忆正文里出现双大括号,宿主组装 prompt 时抛 `malformed prompt variable reference`,模型还没开始跑整轮就失败 —— 表现成「有时能聊、有时一提问就挂」,取决于这一轮召回到了哪些记忆。
|
|
904
904
|
- **注入链的短路闸门**(2.4.3):`system-prompt/assemble` 每个 step 都派发,旧实现每一步都把「扫描 → 摘要打分 → 正文 BM25 → 算签名」整条跑完再判重;而判据其实在打分之前就全拿得到。
|
|
905
905
|
- **「打开记忆文件夹」入口**(2.4.0):记忆目录不必再去文件管理器里翻路径。
|
|
906
|
-
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** ——
|
|
907
|
-
- **一切皆插件 + Cordis 的 service / event / fiber** —— 文件式记忆因此不必自带 worker、端口或数据库;
|
|
908
|
-
- **`ctx.systemPrompt.section` 与 `agent/pre-step`** —— 注入与压缩前提醒能挂在正确的接缝上,而不是靠 prompt 里写「记得读文件」;
|
|
909
|
-
- **typert 远程协议** —— 面板与宿主之间那条类型安全的通道;2.21.0 的删除守卫、2.22.0 的回滚守卫都靠它把「你确认过的那一版」带到宿主侧;
|
|
910
|
-
- **官方文档(AGENTS.md / cordis-api / persistence)** —— 让插件作者能自己查证,而不是猜。
|
|
906
|
+
- **[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)** —— 宿主,一切皆插件。
|
|
911
907
|
|
|
912
|
-
|
|
908
|
+
以上按代码进入仓库的顺序排列。文档若有遗漏或错误,欢迎开 issue 指出。
|
|
913
909
|
|
|
914
910
|
## 相关项目
|
|
915
911
|
|
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
|
-
|
|
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 });
|
|
@@ -4390,6 +4391,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
4390
4391
|
"ext.endpoint.on": "在听 {url}",
|
|
4391
4392
|
"ext.endpoint.off": "未启动",
|
|
4392
4393
|
"ext.endpoint.readFailed": "读不到状态:{error}",
|
|
4394
|
+
"ext.guide.copy": "复制接入片段",
|
|
4395
|
+
"ext.guide.copied": "已复制 —— 贴进 CLAUDE.md / AGENTS.md / .cursorrules 即可",
|
|
4396
|
+
"ext.guide.body": "## 记忆库(sage-mem)`n`n本机有一个**只读**的记忆库端点:`http://127.0.0.1:{port}/mcp`(MCP 协议)。四个工具:`memory_list` / `memory_search` / `memory_read` / `memory_submit`。`n`n**什么时候用**:`n- 开工前先 `memory_list`,看有哪些已知的项目记忆;`n- 用户提到项目名、模块名或历史决定时,先 `memory_search` 这个词 —— 库里可能已经有当初为什么那样定的记录;`n- 结论落定后再 `memory_submit`;不要提交过程流水与未确认的猜测。`n`n引用时带 name(如 `project_xxx.md`),不要假设文件路径 —— 端点不提供路径。",
|
|
4393
4397
|
"ext.endpoint.error": "起不来:{error}",
|
|
4394
4398
|
"ext.lastExport": "最近一轮:{time} · 写 {written} / 未变 {unchanged} / 删 {deleted}",
|
|
4395
4399
|
"ext.lastExport.never": "最近一轮:还没有导出过",
|
|
@@ -5129,6 +5133,9 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
5129
5133
|
"ext.endpoint.on": "listening on {url}",
|
|
5130
5134
|
"ext.endpoint.off": "not running",
|
|
5131
5135
|
"ext.endpoint.readFailed": "status unavailable: {error}",
|
|
5136
|
+
"ext.guide.copy": "Copy integration snippet",
|
|
5137
|
+
"ext.guide.copied": "Copied — paste it into CLAUDE.md / AGENTS.md / .cursorrules",
|
|
5138
|
+
"ext.guide.body": "## Memory library (sage-mem)`n`nA **read-only** memory endpoint runs on this machine: `http://127.0.0.1:{port}/mcp` (MCP). Four tools: `memory_list` / `memory_search` / `memory_read` / `memory_submit`.`n`n**When to use it**:`n- Before starting work, call `memory_list` to see which project memories already exist;`n- When the user names a project, module, or past decision, `memory_search` that term first — the library may already record why it was decided that way;`n- Call `memory_submit` once a conclusion is settled; do not submit process chatter or unconfirmed guesses.`n`nCite by name (e.g. `project_xxx.md`); do not assume file paths — the endpoint does not expose them.",
|
|
5132
5139
|
"ext.endpoint.error": "failed to start: {error}",
|
|
5133
5140
|
"ext.lastExport": "Last export: {time} · {written} written / {unchanged} unchanged / {deleted} deleted",
|
|
5134
5141
|
"ext.lastExport.never": "Last export: never ran",
|
|
@@ -8258,31 +8265,21 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
8258
8265
|
}
|
|
8259
8266
|
|
|
8260
8267
|
/**
|
|
8261
|
-
* 某个文件**现在是否在白名单里** ——
|
|
8268
|
+
* 某个文件**现在是否在白名单里** —— 直接读后端给的 `exposedBy`。
|
|
8262
8269
|
*
|
|
8263
|
-
*
|
|
8264
|
-
*
|
|
8265
|
-
*
|
|
8270
|
+
* 2.30.0 起前端**不再自己算**:判据只有 `lib/mirror/policy.js` 的 `exposedByOf` 一处。
|
|
8271
|
+
* 之前那份复制品(按 include / exclude / prefixes / tags 现算)曾经漏掉 tags 维度、
|
|
8272
|
+
* 大小写口径也与后端不同 —— 症状是「勾着但没导出去」,或者反过来。
|
|
8266
8273
|
*
|
|
8267
|
-
*
|
|
8274
|
+
* `exposedBy` 缺省(旧宿主不返回)时按 `'none'` 处理:宁可少勾,也不假装。
|
|
8268
8275
|
*/
|
|
8269
8276
|
function isIncluded(name) {
|
|
8270
|
-
if (!ext) return false;
|
|
8271
8277
|
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
8278
|
const hit = (files || []).filter(function (f) { return String(f && f.file) === n; })[0];
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8279
|
+
if (!hit || typeof hit.exposedBy !== "string") return false;
|
|
8280
|
+
// ⚠️ `'exclude'` 表示「被显式排除」,不是「勾上」—— 只判 `!== 'none'` 会把它画成勾选态
|
|
8281
|
+
// (2026-12-04 实验室里抓到:一条被排除的记忆显示成勾着)。
|
|
8282
|
+
return hit.exposedBy !== "none" && hit.exposedBy !== "exclude";
|
|
8286
8283
|
}
|
|
8287
8284
|
|
|
8288
8285
|
/**
|
|
@@ -8497,6 +8494,20 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
8497
8494
|
status && status.mirrorDir
|
|
8498
8495
|
? h("div", { className: "smem-autodream-note", key: "dir" }, t("ext.dir", { dir: status.mirrorDir }))
|
|
8499
8496
|
: null,
|
|
8497
|
+
// 2.31.0:MCP 是客户端驱动的,端点推不进对方的上下文 —— 能做的「被动」只有
|
|
8498
|
+
// 连接时的 instructions 与「用户把它贴进规则文件」。这一行给的是后者。
|
|
8499
|
+
h("div", { className: "smem-row", key: "guide" }, [
|
|
8500
|
+
h("button", {
|
|
8501
|
+
type: "button", className: "smem-btn smem-btn-xs",
|
|
8502
|
+
title: t("ext.guide.copied"),
|
|
8503
|
+
onClick: function () {
|
|
8504
|
+
Promise.resolve(copyPromptText(externalGuideText(ext && ext.port))).then(function (ok) {
|
|
8505
|
+
if (ok === true) setNotice(t("ext.guide.copied"));
|
|
8506
|
+
else setErr(t("ext.intake.err.noClipboard"));
|
|
8507
|
+
}, function () { setErr(t("ext.intake.err.noClipboard")); });
|
|
8508
|
+
},
|
|
8509
|
+
}, t("ext.guide.copy")),
|
|
8510
|
+
]),
|
|
8500
8511
|
status && Array.isArray(status.errors) && status.errors.length > 0
|
|
8501
8512
|
? h("div", { className: "smem-err", key: "errs" }, "⚠ " + status.errors.join(" · "))
|
|
8502
8513
|
: null,
|
|
@@ -8515,7 +8526,20 @@ h("span", { key: "sep", className: "smem-actions-sep", "aria-hidden": "true" }),
|
|
|
8515
8526
|
notice ? h("div", { className: "smem-ok", key: "ok" }, "✓ " + notice) : null,
|
|
8516
8527
|
]);
|
|
8517
8528
|
}
|
|
8518
|
-
|
|
8529
|
+
/**
|
|
8530
|
+
* 「接入片段」的正文(2.31.0)—— 一段可以直接贴进别的 agent 规则文件的文字。
|
|
8531
|
+
*
|
|
8532
|
+
* 为什么要这个东西:MCP 是**客户端驱动**的,端点没法把记忆推进对方的上下文。
|
|
8533
|
+
* 能做的「被动」只有两档 —— ① 连接时给的 `instructions`(我们已经在用),
|
|
8534
|
+
* ② 用户把它贴进 CLAUDE.md / AGENTS.md / .cursorrules 这类规则文件。
|
|
8535
|
+
* 这一条走的是第二档:不是自动化,是把「什么时候该查记忆」写进对方每一轮都读的地方。
|
|
8536
|
+
*
|
|
8537
|
+
* 只拼文本、不碰网络也不碰磁盘 —— 复制由调用方用 `copyPromptText` 做(它带降级)。
|
|
8538
|
+
*/
|
|
8539
|
+
function externalGuideText(port) {
|
|
8540
|
+
const p = Number(port) > 0 ? Math.trunc(Number(port)) : 7461;
|
|
8541
|
+
return t("ext.guide.body", { port: String(p) });
|
|
8542
|
+
}
|
|
8519
8543
|
/**
|
|
8520
8544
|
* 「外部来件」卡(2.26.0 写侧)—— 别的 agent 提交过来的东西,一条一条等人批。
|
|
8521
8545
|
*
|
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
|
-
|
|
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
|
/**
|
package/lib/memory/scan.js
CHANGED
|
@@ -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
|
+
}
|
package/lib/mirror/mcp.js
CHANGED
|
@@ -88,6 +88,12 @@ const INSTRUCTIONS = [
|
|
|
88
88
|
'可用工具:memory_list(有哪些)/ memory_search(按关键词找)/ memory_read(读全文)/ memory_submit(提交一条记忆或修改建议)。',
|
|
89
89
|
'引用某条记忆时请带上它的 name(如 project_xxx.md),不要假设文件路径 —— 这里不提供路径。',
|
|
90
90
|
'',
|
|
91
|
+
'## 什么时候该用(这三条比工具说明更重要)',
|
|
92
|
+
'- **开工前先看一眼**:接手一个项目或一段不熟悉的上下文时,先 `memory_list` 或 `memory_search` 项目名,比从零猜快得多。',
|
|
93
|
+
'- **听到专有名词先搜**:用户提到某个项目名、模块名、历史决定时,先 `memory_search` 这个词 —— 库里可能已经有当初为什么那样定的记录。',
|
|
94
|
+
'- **结论落定后再提交**:发现自己确认了一条可复用的结论(约定、坑、为什么这么选),用 `memory_submit` 提交;**不要**把过程流水、半成品猜测、或用户没同意的方案提交上来。',
|
|
95
|
+
'- 库里没有的,就说没有。**不要**根据文件名编内容。',
|
|
96
|
+
'',
|
|
91
97
|
'## memory_submit 的格式',
|
|
92
98
|
'- 提交**不会**直接写入用户的记忆库:它进入归并队列,由用户逐条批准。',
|
|
93
99
|
'- kind=new:必填 source / name / description / type / body;type 只能是 project 或 reference,且 name 要以对应的 project_ / reference_ 开头。正文不要自带 frontmatter。',
|
package/lib/mirror/policy.js
CHANGED
|
@@ -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
|
|
238
|
-
if (!external
|
|
242
|
+
export function exposedByOf(name, tags, external) {
|
|
243
|
+
if (!external) return 'none'
|
|
239
244
|
const file = String(name ?? '')
|
|
240
|
-
if (file === '') return
|
|
245
|
+
if (file === '') return 'none'
|
|
241
246
|
// 前缀只是「看起来像」,名字本身还得是**单段 .md**:`project_../../etc/passwd` 以
|
|
242
247
|
// `project_` 开头,但它不是一个记忆名。导出层拿到的名字来自 `scan.js`(已经过滤过),
|
|
243
248
|
// 这道判定是给面板逐条勾选与将来的调用方兜底的 —— 判据只有一份,就别指望上游一定干净。
|
|
244
|
-
if (!isPlainMdName(file)) return
|
|
249
|
+
if (!isPlainMdName(file)) return 'none'
|
|
245
250
|
const lower = file.toLowerCase()
|
|
246
|
-
if ((external.exclude ?? []).some((n) => String(n).toLowerCase() === lower)) return
|
|
247
|
-
if ((external.include ?? []).some((n) => String(n).toLowerCase() === lower)) return
|
|
248
|
-
if ((external.prefixes ?? []).some((p) => lower.startsWith(String(p).toLowerCase()))) return
|
|
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
|
|
251
|
-
return
|
|
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
|
/**
|
package/lib/typert/schemas.js
CHANGED
|
@@ -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