Skip to content

Commit 2139237

Browse files
authored
Merge pull request #531 from slow-stack/feat/530-prompt-stance
feat(prompt): 蒸馏与总览补「立场纪律 / 叙述纪律」(#530)
2 parents f9aef0b + ecb07ae commit 2139237

8 files changed

Lines changed: 178 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-3E63DD?style=flat-square" alt="license"></a>
1111
<a href="https://github.com/slow-stack/mneme/actions"><img src="https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml?style=flat-square&label=CI" alt="CI"></a>
1212
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-22%2B-3E63DD?style=flat-square&logo=nodedotjs&logoColor=white" alt="node"></a>
13-
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-2541%20passed-3E63DD?style=flat-square" alt="tests"></a>
13+
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-2547%20passed-3E63DD?style=flat-square" alt="tests"></a>
1414
<a href="https://codecov.io/gh/slow-stack/mneme"><img src="https://img.shields.io/codecov/c/github/slow-stack/mneme/main?style=flat-square" alt="coverage"></a>
1515
<a href="https://github.com/awesome-dsh-plugin/awesome-dsh-plugin"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="Awesome"></a>
1616
</p>
@@ -270,7 +270,7 @@ dsh-mneme-serve # 默认 ~/.dsh/memory + 127.0.0.1:8790
270270

271271
```bash
272272
cd dsh-mneme && npm install
273-
npm test # 2541 个测试
273+
npm test # 2547 个测试
274274
npm run stress # 三轴线压测
275275
npm run sync # src → lib 同步
276276
```
@@ -550,7 +550,7 @@ Community projects that wire mneme into more platforms — not part of this repo
550550

551551
```bash
552552
cd dsh-mneme && npm install
553-
npm test # 2541 tests
553+
npm test # 2547 tests
554554
npm run stress # three-axis stress test
555555
npm run sync # src → lib sync
556556
```

‎dsh-mneme/CHANGELOG.md‎

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

33
## [Unreleased]
44

5+
## 🆕 新增
6+
7+
- **蒸馏与总览的提示词第一次对「谄媚」开口:写入侧补「立场纪律」与「叙述纪律」(#530,承接 #380)**:`preInjectGate` 把防谄媚做在**注入面**(E12 实测谄媚率 26.9% → 2.5%),代价是它只是最后一道门、而且默认关;而落到库里**之前**的两个写作环节——蒸馏(`src/lang.js` 的 `summary` / `codingSummary`)与总览(`dreamSummary`)——对谄媚一字未提。这两处写出的内容**完全不过** `writeAdmission`(`src/write-admission.js:285` 的 `if (!sessionKey) return verdict;`,而 `sessionKey` 唯一来源是 `src/tools.js:187` 的 `memory_save` 路径,蒸馏与 dream 写入都不带),所以提示词是唯一能施加约束的地方。**① 立场纪律**(`summary` 与 `codingSummary` 中英各一份)四条:只记事实/偏好/决策/约束、不记对用户本人性格能力情绪品行的评价(无论褒贬);转录三种角色可信度不同——`用户:` 是用户陈述,`助手:` 与 `子会话交付:` 的结论是推断不是事实,除非用户明确采纳否则不写成记忆,确需保留要在 content 里注明是推断;用户陈述与助手推断冲突时以用户陈述为准、冲突如实写进 content 而不替用户裁决;`importance` 只看事实对后续工作的影响面,用户的满意/赞许/情绪都不是抬高它的理由。开头那句「**与上条原则冲突时以本条为准**」不是修辞:「偏好照常记录」与「不记评价」表面有张力,没有优先级条款模型会靠丢弃合法偏好来解张力。**② 叙述纪律**(`dreamSummary` 中英各一份):只写记忆里已写明的事实与偏好,不给用户添性格/能力/情绪评价,不把助手自己的判断写成「用户认为」,某条记忆本身带褒贬口气时只取事实内核。放它的理由是总览是个**放大器**——`src/dream.js:1562` 的落库判据只有 `summaryText.trim()`(无长度、形状、内容判据),`:1568` 固定 `importance:5` + `type:"summary"`,于是 `src/service.js:1696-1706` 进 priority 0 最高注入档、且 `type=summary` 在 `service.js:1665-1671` 的池过滤里**跳过 importanceThreshold**:池里一条谄媚条目会被复述进总览、常驻注入、每轮都见。**两处都必须插在字面量内部且排在 JSON 输出形状之前**——`src/summarize.js:825` 在提示词之后拼 `STR.distillTimeAnchor`(「据此换算 occurred_at」),规则接在锚点之后就变成「先按时间换算、再谈记什么」,指令优先级反了。**规则 b 里那半句「工具输出、报错、命令结果直接给出的技术结论豁免」不能删**:`pitfall` / `constraint` 的内容本来就是工具给出的技术结论,没有豁免就等于把编码回溯功能一并否掉,这是全文最容易被后人顺手删掉的高危句,已单独立锁。**不加配置开关**:仓库既有的 opt-in 开关没有一个是否提示词文本键(全是「要不要跑某条路径」),本批零新增 LLM 调用、零新增配置键,加开关要连带白名单 + schema + 旗标计数锁,而默认关 = 默认无保护,恰好放弃要防的东西——先例是 v0.9.3 的转录围栏(#493)无条件上线。**`preInjectGate` 的池刻意不套围栏**(本轮只补一条「为什么」注释):它的 system 契约把 user 形状写死成「你将收到一个 JSON 对象」,套围栏会让提示词与载荷互相矛盾,而判定池靠 `JSON.parse` 取 `m#i` 局部序号;`JSON.stringify` 本就结构性转义引号与花括号(实测 roundtrip 一致),围栏反而让伪造闭合标记从 1 次变 2 次——不增加防护只增加攻击面,该路径的真防线是整池 wipeout fail-open 加「判定结果绝不进模型上下文」。**明确不在本批**(写进 issue 与本文,别读成「防谄媚已闭环」):巩固 merge 会整段重写正文(`src/dream/decisions.js:627-629` 走 `service.update`),而护栏类型表 `ARCHIVE_GUARDED_TYPES` 不含 `project` / `decision` / `history` / `summary`——正是「对用户的评价」最常落的类型,谄媚在那里从「搬运」升级成「改写放大」且源条目随即归档;`consolidation` 的「合并后取最高」、`conflict` 的「更可信」判据、`pattern` 从夸赞炼人格三处同类;`importance` 单调不减是代码保证(`src/service.js:1443` 的 `Math.max`),规则 d 救不回已被抬到 5 的存量行;给 `quality-filter` 加确定性立场信号这条路是死的(`service.js:1598` 的 `importanceExempt >= 4` 正好豁免谄媚最可能落的那一档);`codingSummary` 缺 type 枚举锁是既有缺陷(`summarize.js:100` 的 `VALID` 只认 7 个 type,自造分类会被静默丢弃且失败路径不推进游标导致同窗口重放),建议独立小 PR。**提示词测试只锁形状不锁行为**:`test/prompt-stance.test.js` 能断言「文本里有这条约束、位置对」,锁不了「模型是否遵守」——后者要 LLM 在环加预注册判据(E12 那类),本轮不做,**不得把本批写成「已验证降低谄媚率」**。新用例 6 条:中英成对、位置锁、工具豁免条款在场、散文契约不破(`doesNotMatch(/JSON 数组|JSON array/)`,总览要的是散文)、总览落库判据不放宽(空串仍 `summary:false` 且旧总览存活)。改动只碰提示词字面量与一条注释,既有锁一条未改。
8+
59
## [0.9.5] - 2026-10-30
610

711
## 🆕 新增

‎dsh-mneme/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
66
[![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
77
[![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
8-
[![tests](https://img.shields.io/badge/tests-2541%20passed-success)](https://github.com/slow-stack/mneme)
8+
[![tests](https://img.shields.io/badge/tests-2547%20passed-success)](https://github.com/slow-stack/mneme)
99
[![CI](https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml)](https://github.com/slow-stack/mneme/actions)
1010
[![node](https://img.shields.io/badge/node-22%2B-blue)](https://nodejs.org)
1111
[![npm downloads](https://img.shields.io/npm/d18m/@modusensus/dsh-mneme.svg?color=blue&label=downloads)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
@@ -717,7 +717,7 @@ src/
717717
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
718718
└── index.js # 插件接线
719719
lib/ # src 的同步分发产物(npm run sync,prepack 钩子在发布时自动跑;一致性由 scripts/check-sync.js 在 CI 与 release.yml 校验——它只查不同步;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
720-
test/ # 2541 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
720+
test/ # 2547 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
721721
scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压测 · sync-lib.js 同步 · check-sync.js 发布闸门 · benchmark-recall.js / benchmark-embed.js / benchmark-rerank.js 基准 · sync-test-badge.mjs 测试徽章 · build-runtime-manifest.mjs 运行时清单
722722
```
723723
@@ -726,7 +726,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
726726
```bash
727727
cd dsh-mneme
728728
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
729-
npm test # 运行 2541 个测试
729+
npm test # 运行 2547 个测试
730730
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
731731
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
732732
```

0 commit comments

Comments
 (0)