Skip to content

Commit e9cab99

Browse files
committed
feat(memory): document 型记忆——注册校验/摘要+指针落库/supersede 记账(#230)
写入权分离:document 全文归 agent(管线零读零写零改),库里只存摘要 + doc_path + evidence 三样;memory_register_document 为唯一铸造口 (src/document.js 内聚块,service barrel 出口,同 recallStats 先例)。 - 注册校验:~ 展开后绝对路径 + 存在 + 非空常规文件;evidence 与库求交, 合法子集落库 + evidence_degraded 标记(SIGNAL_TAGS 保全),全捏造整单拒绝 - C2 比对去重(minSim 0.92):同 doc_path/同标题 = 显式出新版 → supersede (旧行归档 + 指针注记 + content_history 存旧摘要,旧文件不删);仅向量 近重复 = 拒绝并指路,不越 C1 矛盾检测替 agent 裁决 - store 新增 doc_path 列(幂等迁移);toApiList 条件透出(普通行 DTO 同形); memory_get 渲染亮出文件路径 - flag 三处落:documentMemoryEnabled(默认关 + lightMode 强制关 + 面板 记忆增强组)+ documentInjectBudget(1-5 默认 2) - 注入档位合并拍板(#164 评审线):叙述条解禁进注入落次优先档(受 dreamNarrativeEnabled 约束),document 摘要行同档 + 预算封顶; dream/sleep 五候选池排除 document(互不代管);heat 免疫(λ=0) - 写入权分离双保险:saveWithDedupe/updateMemory 拒绝铸造或改入 document, standalone API 数据面 400 document-requires-register - MCP 六件套不动(memory_list 枚举平价同步 +document);注册接口面归 #231 测试:test/document.test.js 14 例;全量 1190 例 0 失败;check-sync 平价绿。
1 parent 20f7243 commit e9cab99

27 files changed

Lines changed: 1231 additions & 60 deletions

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## 🆕 新增
66

7+
- **document 型记忆——agent 产长文档入库为指针行(issue #230)**:写入权分离——全文归 agent(管线零读零写零改),库里只存摘要 + doc_path + evidence 三样;新工具 `memory_register_document({path,title,summary,tags,importance,evidence})` 作唯一铸造口(内聚块 `src/document.js`,service barrel 出口):注册校验(~ 展开后绝对路径、存在 + 非空常规文件、evidence 与库求交——合法子集落库 + `evidence_degraded` 系统标记、全捏造整单拒绝);C2 vector 档比对(minSim 0.92 复用 #127 档语义;同 doc_path/同标题 = 出新版显式 supersede——旧行归档 + `[superseded by <id>]` 指针注记 + content_history 存旧摘要,旧文件不删;仅向量近重复而路径标题都不同 = 拒绝并指路,不越 C1 矛盾检测替 agent 裁决);store 新增 doc_path 列(幂等迁移),toApiList 条件透出 doc_path(普通行 DTO 逐字节同形),memory_get 渲染亮出文件路径;`documentMemoryEnabled`(默认关,白名单 + lightMode 强制关,面板「记忆增强」组第三处落位)+ `documentInjectBudget`(1–5 默认 2);注入档位合并拍板(#164 评审线,#230 内一次落地):叙述条(source=narrative)从纯按需解禁进注入落次优先档(受 dreamNarrativeEnabled 约束,语义/检索路径不变),document 摘要行同档 + 独立预算封顶(超预算跳过由后续候选补位),dream/sleep 五个候选池排除 document(互不代管),heat 免疫(λ=0,指针行不衰减);写入权分离守卫双保险(saveWithDedupe / updateMemory 拒绝铸造或改入 document,standalone API 数据面给 400 `document-requires-register`),MCP 六件套 memory_list 枚举平价同步 +document(注册工具不进 MCP,接口面归 #231)。
8+
79
- **注入命中留痕与注入命中率(issue #217 增量,2026-09-19 口径确认)**:注入终选集落一行 `mode='inject'` 审计(candidates 存实际注入条目,跟随 `recallRecordDefault` 不设新配置键;`heatEnabled=false` 时照写——留痕与消费解耦);recall-stats 新增注入口径(轮数 / 注入条数 / 槽位填充率 `slotFillRate`,注入候选计入 Top-N 与僵尸零曝光判定);面板「记忆复用」卡追加注入段(窗口内无注入行时省略)。
810

911
## 🐛 修复

‎dsh-mneme/bin/dsh-mneme-mcp.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ const previewOf = (content) => {
145145

146146
const MEMORY_TYPE_ENUM = ["preference", "project", "decision", "history", "rejected_solution", "pitfall", "constraint"];
147147

148+
// #230:memory_list 的过滤枚举比 save/update 宽一档——document 指针行可被
149+
// 列出(agent 需要按类型找到注册过的外档),但不进 save/update(铸造口唯一
150+
// = registerDocument;MCP 暂不镜像该工具,接口面归 #231)。
151+
const MEMORY_TYPE_LIST_ENUM = [...MEMORY_TYPE_ENUM, "document"];
152+
148153
const TOOL_SAVE_DESCRIPTION =
149154
"Persist one memory entry for future sessions (user preferences, project state, decisions). " +
150155
"Call this when the user states a durable preference, a project decision is made, or a lesson is learned. " +
@@ -240,7 +245,10 @@ async function runGet(config, args) {
240245
assertOk(res, [200]);
241246
const m = res.json;
242247
if (!m || !m.id) throw new Error("memory not found");
243-
return `${m.title}\nID: ${m.id} | type: ${m.type} | importance: ${m.importance}${MEMORY_PROVENANCE(m)}\n\n${m.content}`;
248+
// #230:document 指针行把文件路径亮在首行,与 src/tools.js 的 memory_get
249+
// render 逐字对齐。
250+
const doc = m.doc_path ? ` | doc: ${m.doc_path}` : "";
251+
return `${m.title}\nID: ${m.id} | type: ${m.type} | importance: ${m.importance}${doc}${MEMORY_PROVENANCE(m)}\n\n${m.content}`;
244252
}
245253

246254
async function runUpdate(config, args) {
@@ -320,7 +328,7 @@ export const MCP_TOOLS = [
320328
inputSchema: {
321329
type: "object",
322330
properties: {
323-
type: typeEnumSchema("Filter by type; omit for all"),
331+
type: { type: "string", enum: MEMORY_TYPE_LIST_ENUM, description: "Filter by type; omit for all. 'document' (#230) = agent-registered document pointer rows" },
324332
limit: intSchema("Page size (default 50)"),
325333
offset: intSchema("Page offset (default 0)"),
326334
include_archived: boolSchema("Include archived (hidden) entries so they can be found and restored (default false)"),

‎dsh-mneme/lib/api-standalone.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ async function handlePutBody(res, service, logger, id, text) {
166166
sendJson(res, 404, { error: "not-found" });
167167
return;
168168
}
169+
if (patch.type === "document" && existing.type !== "document") {
170+
// #230 写入权分离:type 不许改入 document(铸造口唯一),干净 400。
171+
sendJson(res, 400, { error: "document-requires-register" });
172+
return;
173+
}
169174
// 内容被改写时旧版本先入档(human_override),与内部面板写路径一致。
170175
if (patch.content !== undefined && patch.content !== existing.content) {
171176
const history = Array.isArray(existing.content_history) ? existing.content_history : [];
@@ -353,6 +358,12 @@ export function createStandaloneApi({ service, store, config = {}, logger, setti
353358
sendJson(res, 400, { error: "invalid-type" });
354359
return;
355360
}
361+
if (body.type === "document") {
362+
// #230 写入权分离:document 行铸造口唯一(registerDocument)。
363+
// 这里给干净 400,不让它落进 saveWithDedupe 的守卫变 500。
364+
sendJson(res, 400, { error: "document-requires-register" });
365+
return;
366+
}
356367
if (typeof body.title !== "string" || !body.title.trim()) {
357368
sendJson(res, 400, { error: "missing-title" });
358369
return;

‎dsh-mneme/lib/client.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ window.__ModuleLoader__.load({
292292
"memory.tab.rejected_solution": "被否决方案",
293293
"memory.tab.pitfall": "踩坑记录",
294294
"memory.tab.constraint": "工程约束",
295+
"memory.tab.document": "文档",
295296
"memory.features.title": "功能开关",
296297
"memory.features.desc": "按需启停后端能力,改动保存后重启 DSH 生效。",
297298
"memory.features.group.core": "核心",
@@ -324,6 +325,8 @@ window.__ModuleLoader__.load({
324325
"memory.features.rerankEnabled.hint": "本地重排模型对召回结果精排,更慢更准",
325326
"memory.features.heatEnabled": "热度衰减",
326327
"memory.features.heatEnabled.hint": "按遗忘曲线给记忆降温:久未访问热度越低,参与注入排序与睡眠降级判定",
328+
"memory.features.documentMemoryEnabled": "document 型记忆",
329+
"memory.features.documentMemoryEnabled.hint": "agent 产长文档入库为指针行:注册校验(文件存在 + evidence 求交)、摘要 + 路径落库、去重与 supersede 记账;全文归 agent 按需读,注入只带摘要行(默认关)",
327330
"memory.features.resilientModelDownload": "模型下载断点续传",
328331
"memory.features.resilientModelDownload.hint": "模型文件下载中断后从已下载部分续传并自动重试,失败会记录中断位置;关闭后回到一次性下载",
329332
"memory.features.searchSemanticDedup": "语义去重",
@@ -652,6 +655,7 @@ window.__ModuleLoader__.load({
652655
"memory.tab.rejected_solution": "Rejected solutions",
653656
"memory.tab.pitfall": "Pitfalls",
654657
"memory.tab.constraint": "Constraints",
658+
"memory.tab.document": "Documents",
655659
"memory.features.title": "Features",
656660
"memory.features.desc": "Toggle backend capabilities. Changes take effect after restarting DSH.",
657661
"memory.features.group.core": "Core",
@@ -684,6 +688,8 @@ window.__ModuleLoader__.load({
684688
"memory.features.rerankEnabled.hint": "Rerank recalled results with a local model — slower, more precise",
685689
"memory.features.heatEnabled": "Heat decay",
686690
"memory.features.heatEnabled.hint": "Decay memory heat since last access; feeds injection ranking and sleep demotion",
691+
"memory.features.documentMemoryEnabled": "Document memory",
692+
"memory.features.documentMemoryEnabled.hint": "Register agent-authored documents as pointer rows: existence + evidence validation, summary + path stored, dedupe + supersede bookkeeping; the full text stays agent-owned and is read on demand; injection carries the summary row only (off by default)",
687693
"memory.features.resilientModelDownload": "Resumable model downloads",
688694
"memory.features.resilientModelDownload.hint": "Resume model file downloads from received bytes and retry on failure; failures log where they stopped",
689695
"memory.features.searchSemanticDedup": "Semantic dedup",
@@ -1769,7 +1775,7 @@ window.__ModuleLoader__.load({
17691775
// 属调优噪音,按对齐结论留在配置文件,不上 UI。
17701776
const FEATURE_GROUPS = [
17711777
{ key: "group.core", items: ["autoInject", "autoSummarize", "hotMemoryEnabled", "memoryQualityFilter.enabled", "llmAudit.enabled"] },
1772-
{ key: "group.enhance", items: ["entityExtractionEnabled", "codingRetrospect", "rerankEnabled", "resilientModelDownload", "searchSemanticDedup", "bm25SearchEnabled", "heatEnabled"] },
1778+
{ key: "group.enhance", items: ["entityExtractionEnabled", "codingRetrospect", "rerankEnabled", "resilientModelDownload", "searchSemanticDedup", "bm25SearchEnabled", "heatEnabled", "documentMemoryEnabled"] },
17731779
{ key: "group.dream", items: ["autoDream", "sleepModeEnabled"] },
17741780
// v0.8.0 A4(issue #17):作用域隔离组——标注总开关 + 严格硬过滤。
17751781
{ key: "group.scope", items: ["scopeEnabled", "strictScope"] }

‎dsh-mneme/lib/config.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ export const Config = z.object({
145145
dreamNarrativeEnabled: z.boolean().default(false),
146146
// 成簇门槛:共享同一 tag 的记忆 ≥ 此值才合成叙述条。
147147
dreamNarrativeMinCluster: z.natural().min(2).max(20).default(3),
148+
// document 型记忆(#164/#230,opt-in):agent 产长文档的指针行——注册校验
149+
// (文件存在 + 路径合法 + evidence 求交)、摘要 + doc_path 落库、C2 比对
150+
// 去重、supersede 记账。全文归 agent,管线零触碰;默认关=行为与此前一致;
151+
// lightMode 强制关闭。
152+
documentMemoryEnabled: z.boolean().default(false),
153+
// document 摘要行的注入预算(#230 拍板):次优先档内最多注入的 document
154+
// 行数,超预算跳过由后续候选补位。只约束注入,不约束检索。
155+
documentInjectBudget: z.natural().min(1).max(5).default(2),
148156
// 隐式 keep(v0.4.4):LLM 未提及的 snapshot 记忆自动补 {action:"keep"},
149157
// 避免"未覆盖即全拒"白白浪费整轮 run。设为 false 时保留旧的严格校验
150158
// (未覆盖即拒绝整单)。
@@ -515,6 +523,8 @@ const LIGHT_MODE_OFF = [
515523
"entityRecallEnabled",
516524
// 轻量模式不开叙述条(额外 LLM 调用;#164 对齐,opt-in)。
517525
"dreamNarrativeEnabled",
526+
// 轻量模式不开 document 指针行(#230,opt-in:注册/注入/检索增强全随闸)。
527+
"documentMemoryEnabled",
518528
// 轻量模式不开热计算(heat 属于重型增强;关掉后 sleep 降级也退回纯时间分层)。
519529
"heatEnabled"
520530
];

0 commit comments

Comments
 (0)