Skip to content

Commit 4323ceb

Browse files
fix: 蒸馏不再采集私有推理块(CWE-200,CodeRabbit #76 评审)+ bump v0.7.14
- collectMessages 原把 assistant/message 的 reasoning block 作「助手思考」送进蒸馏上下文,生成的记忆可能沉淀模型私有思考链 - 现只采集公开 text 块;私有 reasoning 不进记忆库(同步 CODING_SUMMARY_PROMPT/注释措辞) - 新增回归测试:reasoning 不进蒸馏上下文、公开文本照常蒸馏 - 617 测试全绿;CHANGELOG/README 补 v0.7.14 Co-Authored-By: Anans-Ivresse <[email protected]>
1 parent 3d48786 commit 4323ceb

7 files changed

Lines changed: 59 additions & 20 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [0.7.14] - 2026-09-08
4+
5+
### 修复
6+
7+
- **蒸馏不再采集私有推理块(安全,CWE-200)**:`collectMessages` 原会把 `assistant/message` 里的 `reasoning` block 作为「助手思考」送进蒸馏上下文,生成的记忆可能沉淀模型私有思考链;现只采集公开 `text` 块,私有推理不进记忆库。CodeRabbit 评审(PR #76)指出后修复。
8+
9+
### 测试
10+
11+
- 617 全绿(+1:私有 reasoning 块不进入蒸馏上下文,公开文本照常蒸馏)。
12+
313
## [0.7.13] - 2026-09-08
414

515
### 新增

‎dsh-mneme/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ v0.3.0 起新增**记忆基因**层:从记忆里抽取**命名实体**、**带
241241

242242
| 版本 | 亮点 |
243243
|------|------|
244-
| **v0.7.13** | 编码记忆蒸馏(`codingRetrospect` 默认关):完整转录(用户+助手思考/回复+工具调用/结果+代码执行)提炼原子记忆,新增 `rejected_solution`/`pitfall`/`constraint` 三类型,编码任务 `codingBoostFactor` 加权(cap 5)+ 智能调速器(蒸馏全局串行队列 + 429 指数退避自动重试)+ 原子记忆语义保留(宁可拆多条不合并丢细节,`distillMaxChars` 默认 24000)+ 修复 v0.7.12 CI 回归(恢复 c8 覆盖率);616 测试全绿 |
244+
| **v0.7.14** | 安全修复(CWE-200):蒸馏不再把助手 `reasoning` 私有推理块送进蒸馏上下文(只采公开 `text`,防止记忆沉淀私有思考链);617 测试全绿 |
245+
| **v0.7.13** | 编码记忆蒸馏(`codingRetrospect` 默认关):完整转录(用户+助手回答+工具调用/结果+代码执行)提炼原子记忆,新增 `rejected_solution`/`pitfall`/`constraint` 三类型,编码任务 `codingBoostFactor` 加权(cap 5)+ 智能调速器(蒸馏全局串行队列 + 429 指数退避自动重试)+ 原子记忆语义保留(宁可拆多条不合并丢细节,`distillMaxChars` 默认 24000)+ 修复 v0.7.12 CI 回归(恢复 c8 覆盖率);616 测试全绿 |
245246
| **v0.7.12** | 独立外部 API(插件自带 HTTP 服务 `127.0.0.1:8790` Bearer 鉴权,生态集成)+ 零依赖 CLI `dsh-mneme`(status/list/search/get/add/delete/config)+ 轻量模式 lightMode(简化预设、面板一键切换)+ 设置面板新卡片(运行模式/外部访问 API);612 测试全绿 |
246247
| **v0.7.11** | 记忆库面板改版:按月分页+无限滚动(`limit=500` 静默丢失→100 条/页分页,total 常显)、搜索全局化(关键词/语义走服务端命中全库)、30s 静默刷新 + 状态子页(记忆/实体/向量索引/LLM 消耗四卡)+ 删除两步确认 + 重要性过滤芯片 + 内联 Lucide 图标;bundle 默认开启实体抽取;Issue #72 最大化窗口图谱节点裁剪修复(力导向全程 viewBox 用户单位)+ Issue #59 autoSummarize 从不执行修复(snapshotEvents 垫片);双语 README;595 测试全绿 |
247248
| **v0.7.10** | Web 面板体验升级:记忆类型色点体系(筛选/时间树/详情三处贯穿)+ 图谱画布平移/滚轮缩放/重置视图(补齐 `cursor: grab` 暗示却缺失的交互)+ 设置页 Claude 风格分区重排(编号规则行、悬停删除、口语化文案)+ 侧边栏入口同标签冲突修复(可见性过滤 + 渲染验证 + 多候选重试)+ 详情 meta 精排(来源截断、相对时间)+ 新增只读 `GET /api/dsh-mneme/entities` 实体清单端点(19→20 条路由);815 测试全绿 |

‎dsh-mneme/lib/summarize.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内
88
// 编码记忆蒸馏 prompt(codingRetrospect 开启时启用):在通用记忆之外,额外提取
99
// 三类编码专属记忆,专治重复踩坑 / 遗忘被否决方案 / 丢失工程约束。字段仍沿用
1010
// title/content 单列结构(store 无结构化字段),信息浓缩进 content。
11-
const CODING_SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手思考/回答、工具调用与结果),提炼值得跨会话记住的原子记忆。
11+
const CODING_SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。
1212
原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。
1313
只输出 JSON 数组,每项形如 {"type":"preference|project|decision|history|rejected_solution|pitfall|constraint","title":"简短标题","content":"保留原始细节的一句话","importance":1-5}。
1414
若对话涉及编码/调试,可额外提取编码类记忆:
@@ -91,18 +91,22 @@ function toProtocolChunk(chunk) {
9191
// check below.
9292
//
9393
// codingRetrospect: the distill context is the FULL turn transcript —
94-
// user prompts plus assistant thinking/replies, tool calls + results and code
94+
// user prompts plus assistant public replies, tool calls + results and code
9595
// dispatch output — so the summarizer can see tool errors and extract pitfall
9696
// root causes, not just what the user typed. The same filtering stays: only
9797
// source.kind === "user" prompts enter (plugin/machine content is excluded).
9898
// The result is a single text transcript passed to the LLM as one user message
9999
// (SUMMARY_PROMPT already says "根据下面的会话内容").
100+
//
101+
// Privacy: assistant `reasoning` (private thought) blocks are deliberately NOT
102+
// collected — distilled memories must never sink private reasoning chains.
103+
// Only public text blocks (type "text") reach the summarizer.
100104
function collectMessages(session, maxChars = 8000) {
101105
// DSH 0.1.2-rc.1 起 Session 改用 snapshotEvents(),兼容旧版 .events
102106
const events = session.snapshotEvents?.() ?? session.events ?? [];
103107
const lines = [];
104108
// 兼容严格形状 [{type:"text",text}] 与宽松形状 ["字符串", ...](lib-smoke 用例
105-
// 直接传字符串数组)。text 之外按需抽 thinking/reasoning 块。
109+
// 直接传字符串数组)。只取公开文本块;reasoning 私有推理块不进蒸馏上下文。
106110
const textOf = (content) => {
107111
if (typeof content === "string") return content;
108112
if (!Array.isArray(content)) return "";
@@ -127,11 +131,7 @@ function collectMessages(session, maxChars = 8000) {
127131
const blocks = Array.isArray(msg?.content) ? msg.content : [];
128132
const text = textOf(blocks);
129133
if (text.trim()) lines.push(`助手:${text}`);
130-
const thinking = blocks
131-
.map((b) => (typeof b === "string" ? "" : (b && b.type === "reasoning" && typeof b.text === "string" ? b.text : "")))
132-
.filter((s) => s)
133-
.join("\n");
134-
if (thinking.trim()) lines.push(`助手思考:${thinking}`);
134+
// 私有推理块(reasoning)刻意不采集:蒸馏记忆不得沉淀模型私有思考链。
135135
break;
136136
}
137137
case "tool/call": {

‎dsh-mneme/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dsh-mneme/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@modusensus/dsh-mneme",
33
"description": "Cross-session memory plugin for DeepSeek Harness with autoDream consolidation: SQLite store, Markdown mirrors, 7 model tools, automatic injection, session summarization, user profile/rules, custom slash commands, vector (semantic) search, and a Web GUI panel",
4-
"version": "0.7.13",
4+
"version": "0.7.14",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

‎dsh-mneme/src/summarize.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内
88
// 编码记忆蒸馏 prompt(codingRetrospect 开启时启用):在通用记忆之外,额外提取
99
// 三类编码专属记忆,专治重复踩坑 / 遗忘被否决方案 / 丢失工程约束。字段仍沿用
1010
// title/content 单列结构(store 无结构化字段),信息浓缩进 content。
11-
const CODING_SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手思考/回答、工具调用与结果),提炼值得跨会话记住的原子记忆。
11+
const CODING_SUMMARY_PROMPT = `你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。
1212
原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。
1313
只输出 JSON 数组,每项形如 {"type":"preference|project|decision|history|rejected_solution|pitfall|constraint","title":"简短标题","content":"保留原始细节的一句话","importance":1-5}。
1414
若对话涉及编码/调试,可额外提取编码类记忆:
@@ -91,18 +91,22 @@ function toProtocolChunk(chunk) {
9191
// check below.
9292
//
9393
// codingRetrospect: the distill context is the FULL turn transcript —
94-
// user prompts plus assistant thinking/replies, tool calls + results and code
94+
// user prompts plus assistant public replies, tool calls + results and code
9595
// dispatch output — so the summarizer can see tool errors and extract pitfall
9696
// root causes, not just what the user typed. The same filtering stays: only
9797
// source.kind === "user" prompts enter (plugin/machine content is excluded).
9898
// The result is a single text transcript passed to the LLM as one user message
9999
// (SUMMARY_PROMPT already says "根据下面的会话内容").
100+
//
101+
// Privacy: assistant `reasoning` (private thought) blocks are deliberately NOT
102+
// collected — distilled memories must never sink private reasoning chains.
103+
// Only public text blocks (type "text") reach the summarizer.
100104
function collectMessages(session, maxChars = 8000) {
101105
// DSH 0.1.2-rc.1 起 Session 改用 snapshotEvents(),兼容旧版 .events
102106
const events = session.snapshotEvents?.() ?? session.events ?? [];
103107
const lines = [];
104108
// 兼容严格形状 [{type:"text",text}] 与宽松形状 ["字符串", ...](lib-smoke 用例
105-
// 直接传字符串数组)。text 之外按需抽 thinking/reasoning 块。
109+
// 直接传字符串数组)。只取公开文本块;reasoning 私有推理块不进蒸馏上下文。
106110
const textOf = (content) => {
107111
if (typeof content === "string") return content;
108112
if (!Array.isArray(content)) return "";
@@ -127,11 +131,7 @@ function collectMessages(session, maxChars = 8000) {
127131
const blocks = Array.isArray(msg?.content) ? msg.content : [];
128132
const text = textOf(blocks);
129133
if (text.trim()) lines.push(`助手:${text}`);
130-
const thinking = blocks
131-
.map((b) => (typeof b === "string" ? "" : (b && b.type === "reasoning" && typeof b.text === "string" ? b.text : "")))
132-
.filter((s) => s)
133-
.join("\n");
134-
if (thinking.trim()) lines.push(`助手思考:${thinking}`);
134+
// 私有推理块(reasoning)刻意不采集:蒸馏记忆不得沉淀模型私有思考链。
135135
break;
136136
}
137137
case "tool/call": {

‎dsh-mneme/test/summarize.test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,34 @@ test("distills full transcript (tool calls, results, code output) with atomic-me
293293
assert.ok(calls[0].messages[0].content[0].text.includes("原子记忆"));
294294
});
295295

296+
test("distill excludes private assistant reasoning blocks from the transcript", async () => {
297+
const { events, calls } = setup();
298+
const handler = events.find((e) => e.name === "session/event").fn;
299+
const session = {
300+
id: "s12",
301+
requestHeader: () => ({ config: { provider: "deepseek", model: "deepseek-chat" } }),
302+
events: [
303+
userMessage("解释一下这段代码"),
304+
{
305+
type: "assistant/message",
306+
data: {
307+
message: {
308+
content: [
309+
{ type: "reasoning", text: "私有推理:内部权衡过程不该进记忆" },
310+
{ type: "text", text: "这段代码有死循环,第 3 行 while 条件恒真。" }
311+
]
312+
}
313+
}
314+
},
315+
{ seq: 3, type: "turn/end" }
316+
]
317+
};
318+
await handler(session, { seq: 3, type: "turn/end" });
319+
const transcript = JSON.stringify(calls[0].messages);
320+
assert.ok(transcript.includes("有死循环,第 3 行"), "public assistant text still distills");
321+
assert.ok(!transcript.includes("私有推理"), "private reasoning must never enter the distill context");
322+
});
323+
296324
test("codingRetrospect stores coding memory types in the coding memory type set", async () => {
297325
const { events, store, calls } = setup({ codingRetrospect: true }, {
298326
stream() {

0 commit comments

Comments
 (0)