Skip to content

Commit 8a777bd

Browse files
committed
Merge branch 'main' into chore/239-distill-window-metrics
2 parents 300eb84 + 84c6f50 commit 8a777bd

6 files changed

Lines changed: 82 additions & 12 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-1611%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-1615%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>
@@ -207,7 +207,7 @@ dsh-mneme-serve # 默认 ~/.dsh/memory + 127.0.0.1:8790
207207

208208
```bash
209209
cd dsh-mneme && npm install
210-
npm test # 1611 个测试
210+
npm test # 1615 个测试
211211
npm run stress # 三轴线压测
212212
npm run sync # src → lib 同步
213213
```
@@ -414,7 +414,7 @@ Community projects that wire mneme into more platforms — not part of this repo
414414

415415
```bash
416416
cd dsh-mneme && npm install
417-
npm test # 1611 tests
417+
npm test # 1615 tests
418418
npm run stress # three-axis stress test
419419
npm run sync # src → lib sync
420420
```

‎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-1611%20passed-success)](https://github.com/slow-stack/mneme)
8+
[![tests](https://img.shields.io/badge/tests-1615%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)
@@ -613,7 +613,7 @@ src/
613613
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
614614
└── index.js # 插件接线
615615
lib/ # src 的同步分发产物(npm run sync;发布前由 root prepack 的 check-sync.js 校验一致性;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
616-
test/ # 1611 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
616+
test/ # 1615 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
617617
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 运行时清单
618618
```
619619
@@ -622,7 +622,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
622622
```bash
623623
cd dsh-mneme
624624
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
625-
npm test # 运行 1611 个测试
625+
npm test # 运行 1615 个测试
626626
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
627627
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
628628
```

‎dsh-mneme/lib/service.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import { createBM25Index } from "./search/bm25.js";
1313
import { adaptiveThreshold } from "./search/adaptive.js";
1414
import { anchorSeeds, normalizePath, cascadeDepths, HOP_QUOTA } from "./graph/anchoring.js";
1515

16-
const INJECT_TYPES = new Set(["preference", "project", "decision", "summary", "rejected_solution", "pitfall", "constraint"]);
16+
// Issue #369:蒸馏白名单(src/summarize.js 的 VALID)产得出 history,注入白名单
17+
// 原先不收——本机活跃库实测 378/1820(20.8%)因此永不可自动注入,而它们在同一库
18+
// 的 recall_runs `auto` 模式里被按需检索过 328 次:不是垃圾数据,只是进不了注入池。
19+
// 收编后候选池 1362 → 1713(+25.8%),按 top_k=5 粗算约多占 1 席;重要度闸门对
20+
// history 一视同仁(见 injectCandidates 的 importance >= threshold),低于闸门照旧出局。
21+
// pattern 一并收编:它只由手工写入(实测 40 条全 source=manual),却已被 dreamMergeGuard
22+
// 列为长保留受保护类型(docs/CONFIGURATION.md)——巩固层当资产护住、注入面一次不给看,
23+
// 是同一条口径的两头不一致。
24+
const INJECT_TYPES = new Set(["preference", "project", "decision", "summary", "rejected_solution", "pitfall", "constraint", "history", "pattern"]);
1725

1826
// document 摘要行(#230):仅 documentMemoryEnabled 开启时进注入候选。独立
1927
// 集合而非常改共享 Set——INJECT_TYPES 本身是「类型可注入」的静态事实,flag
@@ -1634,9 +1642,14 @@ export function createService({ store, mirror, config, onWrite, logger, document
16341642
} catch { /* vector unavailable: fall through to the recall cache */ }
16351643
}
16361644
if (!semanticItems.length && lastSemanticRecall?.query === q && lastSemanticRecall.items?.length) {
1645+
// CodeRabbit on #404:这条回填分支此前独漏重要度门槛——向量路(上方)与
1646+
// BM25 路(下方 :1655 注释「门控与向量路径一致(含 importance 阈值)」)
1647+
// 都带着它。#369 收编 history 后缺口会被放大:库里低于闸门的行(实测
1648+
// history 378 条中有 27 条 i<=2)走一次检索进缓存就能绕开门槛占注入位。
16371649
for (const m of lastSemanticRecall.items) {
16381650
if (m && !m.archived && injectTypes.has(m.type) && !m.forgotten &&
1639-
(m.source !== "narrative" || allowNarrative) && codingGate(m)) semanticItems.push(m);
1651+
(m.source !== "narrative" || allowNarrative) && codingGate(m) &&
1652+
(m.type === "summary" || m.type === "preference" || m.importance >= threshold)) semanticItems.push(m);
16401653
}
16411654
}
16421655
// Issue #198:首轮(无向量、无缓存召回)的同步兜底——BM25 词法召回领位。

‎dsh-mneme/src/service.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import { createBM25Index } from "./search/bm25.js";
1313
import { adaptiveThreshold } from "./search/adaptive.js";
1414
import { anchorSeeds, normalizePath, cascadeDepths, HOP_QUOTA } from "./graph/anchoring.js";
1515

16-
const INJECT_TYPES = new Set(["preference", "project", "decision", "summary", "rejected_solution", "pitfall", "constraint"]);
16+
// Issue #369:蒸馏白名单(src/summarize.js 的 VALID)产得出 history,注入白名单
17+
// 原先不收——本机活跃库实测 378/1820(20.8%)因此永不可自动注入,而它们在同一库
18+
// 的 recall_runs `auto` 模式里被按需检索过 328 次:不是垃圾数据,只是进不了注入池。
19+
// 收编后候选池 1362 → 1713(+25.8%),按 top_k=5 粗算约多占 1 席;重要度闸门对
20+
// history 一视同仁(见 injectCandidates 的 importance >= threshold),低于闸门照旧出局。
21+
// pattern 一并收编:它只由手工写入(实测 40 条全 source=manual),却已被 dreamMergeGuard
22+
// 列为长保留受保护类型(docs/CONFIGURATION.md)——巩固层当资产护住、注入面一次不给看,
23+
// 是同一条口径的两头不一致。
24+
const INJECT_TYPES = new Set(["preference", "project", "decision", "summary", "rejected_solution", "pitfall", "constraint", "history", "pattern"]);
1725

1826
// document 摘要行(#230):仅 documentMemoryEnabled 开启时进注入候选。独立
1927
// 集合而非常改共享 Set——INJECT_TYPES 本身是「类型可注入」的静态事实,flag
@@ -1634,9 +1642,14 @@ export function createService({ store, mirror, config, onWrite, logger, document
16341642
} catch { /* vector unavailable: fall through to the recall cache */ }
16351643
}
16361644
if (!semanticItems.length && lastSemanticRecall?.query === q && lastSemanticRecall.items?.length) {
1645+
// CodeRabbit on #404:这条回填分支此前独漏重要度门槛——向量路(上方)与
1646+
// BM25 路(下方 :1655 注释「门控与向量路径一致(含 importance 阈值)」)
1647+
// 都带着它。#369 收编 history 后缺口会被放大:库里低于闸门的行(实测
1648+
// history 378 条中有 27 条 i<=2)走一次检索进缓存就能绕开门槛占注入位。
16371649
for (const m of lastSemanticRecall.items) {
16381650
if (m && !m.archived && injectTypes.has(m.type) && !m.forgotten &&
1639-
(m.source !== "narrative" || allowNarrative) && codingGate(m)) semanticItems.push(m);
1651+
(m.source !== "narrative" || allowNarrative) && codingGate(m) &&
1652+
(m.type === "summary" || m.type === "preference" || m.importance >= threshold)) semanticItems.push(m);
16401653
}
16411654
}
16421655
// Issue #198:首轮(无向量、无缓存召回)的同步兜底——BM25 词法召回领位。

‎dsh-mneme/test/inject-recall.test.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,42 @@ test("slotFillRate = 注入条数 / (轮数 × 槽位数)", () => {
103103
assert.equal(stats.injection.slotFillRate, 3 / 4);
104104
store.close();
105105
});
106+
107+
// #369:history 曾被注入白名单挡在门外(蒸馏产得出、注入收不进)。这两条断言分
108+
// 别锁「收编生效」与「重要度闸门对 history 不豁免」——后者一旦失效,短流水账会
109+
// 直接挤掉决策类条目,那才是这个改动真正的风险面。
110+
test("#369: history 进注入候选池", () => {
111+
const { service } = setup();
112+
service.saveWithDedupe({ type: "history", title: "切到暗色主题", content: "用户本次会话把界面切成暗色主题", importance: 4 });
113+
const titles = service.injectCandidates({ maxItems: 5 }).map((m) => m.title);
114+
assert.ok(titles.includes("切到暗色主题"), "importance>=3 的 history 应进注入候选");
115+
});
116+
117+
test("#369: 低于重要度闸门的 history 不得例外放行", () => {
118+
const { service } = setup();
119+
service.saveWithDedupe({ type: "history", title: "打开过一次终端", content: "用户中途打开过一次终端", importance: 2 });
120+
const titles = service.injectCandidates({ maxItems: 5 }).map((m) => m.title);
121+
assert.ok(!titles.includes("打开过一次终端"), "history 不是 summary/preference,闸门照样生效");
122+
});
123+
124+
// pattern 只由手工写入,却已被 dreamMergeGuard 列为长保留受保护类型——巩固层当资产
125+
// 护住、注入面一次不给看是同一条口径的两头不一致。这条锁它进池。
126+
test("#369: 手写的 pattern 进注入候选池", () => {
127+
const { service } = setup();
128+
service.saveWithDedupe({ type: "pattern", title: "重复字符串先抽共用模块", content: "多处重复的截断逻辑先收拢成共用模块,再改调用方", importance: 5 });
129+
const titles = service.injectCandidates({ maxItems: 5 }).map((m) => m.title);
130+
assert.ok(titles.includes("重复字符串先抽共用模块"), "importance>=3 的 pattern 应进注入候选");
131+
});
132+
133+
// CodeRabbit on PR #404:语义缓存回填分支曾独漏重要度门槛(向量路与 BM25 路都带)。
134+
// 一正一反:反向锁「低于闸门的行走缓存也不许进池」,正向锁「达标的照常进池」,
135+
// 免得断言退化成常量真;缓存没被灌进来时正向那条会先红,用例不会空压。
136+
test("#369: 语义缓存回填同样受重要度闸门约束", async () => {
137+
const { service } = setup();
138+
const low = service.saveWithDedupe({ type: "history", title: "终端开了一次", content: "用户中途打开过一次终端做检查", importance: 2 });
139+
const high = service.saveWithDedupe({ type: "history", title: "终端方案定案", content: "用户终端接入方案已定案并验证", importance: 4 });
140+
await service.searchMemories("终端", { mode: "keyword", useRerank: false, recordRecall: false });
141+
const ids = service.injectCandidates({ query: "终端", maxItems: 5 }).map((m) => m.id);
142+
assert.ok(ids.includes(high.memory.id), "i4 的 history 应经缓存回填进池(正向对照)");
143+
assert.equal(ids.includes(low.memory.id), false, "低于闸门的行不得借语义缓存绕开门槛");
144+
});

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ test("injectCandidates returns preferences + high-importance items within limit"
5353
const types = candidates.map((c) => c.type);
5454
assert.ok(types.includes("preference"), "preferences included");
5555
assert.ok(types.includes("project"), "high-importance project included");
56-
assert.ok(!types.includes("history"), "history excluded by default");
56+
// #369:history 曾被注入白名单挡在门外,现按「注入侧收编」进池(理由与实测数字
57+
// 见 src/service.js 的 INJECT_TYPES 注释)。这里从「锁排除」改成「锁收编」——
58+
// 白名单日后若被收窄,这条会红,而不是静默把两成条目关回不可注入。
59+
assert.ok(types.includes("history"), "history included since #369");
5760
assert.ok(candidates.length <= 5, "respects maxItems");
5861
});
5962

@@ -220,7 +223,9 @@ test("Bug4: injectCandidates with an empty query keeps the legacy rule-based sel
220223
assert.deepEqual(noQuery.map((c) => c.id), legacy.map((c) => c.id), "empty query behaves identically to the old logic");
221224
assert.deepEqual(blankQuery.map((c) => c.id), legacy.map((c) => c.id), "whitespace-only query degrades too");
222225
assert.equal(legacy[0].type, "summary", "summary still leads");
223-
assert.ok(!legacy.some((c) => c.type === "history"), "history still excluded");
226+
// #369 收编后 history 可进池;本用例的重心是「空查询与旧规则路逐字节同序」,
227+
// 这条只确认收编没有撼动优先级分层——summary 仍打头。
228+
assert.ok(legacy.some((c) => c.type === "history"), "history included since #369");
224229
});
225230

226231
test("Bug4: injectCandidates ignores the query when hybridInject is disabled", () => {

0 commit comments

Comments
 (0)