Skip to content

Commit 7fb1449

Browse files
authored
Merge branch 'main' into feat/inject-heat-enabled
2 parents dbfb1c0 + 8b6f416 commit 7fb1449

16 files changed

Lines changed: 487 additions & 38 deletions

‎README.md‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
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>
1313
<<<<<<< HEAD
14-
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1537%20passed-3E63DD?style=flat-square" alt="tests"></a>
14+
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1546%20passed-3E63DD?style=flat-square" alt="tests"></a>
1515
=======
16-
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1537%20passed-3E63DD?style=flat-square" alt="tests"></a>
16+
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-1546%20passed-3E63DD?style=flat-square" alt="tests"></a>
1717
>>>>>>> feat/serve-daemon
1818
<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>
1919
<a href="https://github.com/awesome-dsh-plugin/awesome-dsh-plugin"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="Awesome"></a>
@@ -162,6 +162,16 @@ npm i -g @modusensus/dsh-mneme
162162
dsh-mneme-serve # 默认 ~/.dsh/memory + 127.0.0.1:8790
163163
```
164164

165+
## 社区适配器
166+
167+
社区项目把 mneme 接入更多平台——它们不是本仓库的一部分,兼容性由各自维护者跟进:
168+
169+
| 项目 | 平台 | 说明 |
170+
|------|------|------|
171+
| [Mneme-Bridge](https://github.com/SternChiri/Mneme-Bridge) | DeepSeek 网页端 | 浏览器扩展 + 本地服务:网页端会话蒸馏进 mneme 记忆库、DSH 侧记忆按话题回注,两侧共享同一份记忆。embedded(挂载 lib)与 remote(standalone API,不开 DSH 时配合上面的 daemon)双模式 |
172+
173+
> 想被收录?在 [Discussions](https://github.com/slow-stack/mneme/discussions) 开帖介绍你的项目,或直接提 PR 补充本表。
174+
165175
## 文档
166176

167177
| 文档 | 路径 |
@@ -198,9 +208,9 @@ dsh-mneme-serve # 默认 ~/.dsh/memory + 127.0.0.1:8790
198208
```bash
199209
cd dsh-mneme && npm install
200210
<<<<<<< HEAD
201-
npm test # 1537 个测试
211+
npm test # 1546 个测试
202212
=======
203-
npm test # 1537 个测试
213+
npm test # 1546 个测试
204214
>>>>>>> feat/serve-daemon
205215
npm run stress # 三轴线压测
206216
npm run sync # src → lib 同步
@@ -359,6 +369,16 @@ npm i -g @modusensus/dsh-mneme
359369
dsh-mneme-serve # defaults: ~/.dsh/memory + 127.0.0.1:8790
360370
```
361371

372+
## Community adapters
373+
374+
Community projects that wire mneme into more platforms — not part of this repository; compatibility is tracked by their maintainers:
375+
376+
| Project | Platform | Description |
377+
|---------|----------|-------------|
378+
| [Mneme-Bridge](https://github.com/SternChiri/Mneme-Bridge) | DeepSeek web | Browser extension + local service: web chats are distilled into the mneme store and DSH memories are injected back by topic, so both sides share one memory. Embedded (mounts the lib) and remote (standalone API — pairs with the daemon above) modes |
379+
380+
> Want your project listed? Open a Discussion or send a PR adding a row to this table.
381+
362382
## Docs
363383

364384
| Doc | Path |
@@ -395,9 +415,9 @@ dsh-mneme-serve # defaults: ~/.dsh/memory + 127.0.0.1:8790
395415
```bash
396416
cd dsh-mneme && npm install
397417
<<<<<<< HEAD
398-
npm test # 1537 tests
418+
npm test # 1546 tests
399419
=======
400-
npm test # 1537 tests
420+
npm test # 1546 tests
401421
>>>>>>> feat/serve-daemon
402422
npm run stress # three-axis stress test
403423
npm run sync # src → lib sync

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## 🆕 新增
66

7+
- **standalone API `GET /context`(issue #370,#363 承诺)**:把宿主注入管线开放为端点——Mneme-Bridge 这类网页端桥接可以删掉自建的 pins 启发式了。`GET /context?q&topK&threshold&agent_scope&workspace_scope` 返回 `injectCandidates` 全语义(优先级分层 / 编码门控 / heat / scope 软加权 / hybrid 语义路 / pin 前置)+ 画像 + 规则的结构化聚合 `{profile, rules, items, pinnedCount}`,不含渲染文本(语言 / 时间前缀 / 热记忆是宿主会话概念,调用方自渲染)。与宿主注入的两点 HTTP 面差异:查询向量即时嵌入——首次调用即走语义路,不等异步 prefetch(宿主注入渲染必须同步,inject.js Bug4);不做跨轮轮换(daemon 无会话状态,调用方自管)。`threshold` 是 importance 阈值(默认 3,与 `/search` 的相似度 threshold 同名不同义);scope 两参全缺 = 不解析(软加权与 strictScope 硬过滤都不触发,与宿主会话身份取不到时同构),任一给出则缺维按 fail-closed。recall_runs 记账随 `injectCandidates` 内建(#217 曝光型访问事件,`mode='inject'` 与检索命中同表分账)——宿主注入同样记,端点自动同口径。`/search` 顺手补 scope 透传(`searchMemories` 本就收参、8790 此前没有入口;不传参数行为逐字节不变);`createStandaloneApi` 新增可选 `embedder` 注入(宿主与 `dsh-mneme-serve` 各传 semantic 装配的同一实例),缺省时 `/context` 降级规则 + BM25 档,嵌入失败同理绝不 500。宿主外部访问与 daemon 同享该路由;测试锁形状(四键)、空 q 规则档、threshold 语义、pin 前置、scope 硬过滤、嵌入接线与失败降级,daemon 侧全链路含 recall_runs 分账锁。
78
- **daemon 向量检索(PR2,#363)**:`dsh-mneme-serve` 的 `/search` 接入完整语义管线——embedder/reranker 装配与 boot 自动回填从 `index.js` **纯搬移**至 `src/semantic.js`(宿主与 daemon 共用同一份,调用时序契约原样;`backfillMissingEmbeddings` 经 index.js barrel 再出口,测试调用方零改动),daemon 侧新增 `createVectorIndex` 接线与 `--embed` 参数:`local`(默认,自管 runtime/嵌入模型缺失时经 `provisionRuntime` download 档自动取件,可用 `DSH_MNEME_RUNTIME_TARBALL_DIR`/`DSH_MNEME_RUNTIME_MIRROR` 换离线/镜像来源;失败降级关键词并打可操作日志)、`ollama`、`openai`(读宿主面板 vector-config)、`off`。向量轴有注入假 embedder 的回归锁;`createServeRuntime` 因此转为 async、语义键默认值在 `daemonSemanticCfg` 逐键锚定 config.js。
89
- **独立服务 daemon(`dsh-mneme-serve`,#363)**:mneme 现在能在 DSH 宿主之外常驻——`src/serve.js` 的 `createServeRuntime` 用最小装配(store → settings → mirror → service → maintenance → standalone API,每步锚定 index.js 装配行号)把数据面跑成独立进程,第三方集成(网页端桥接等)不必为挂载记忆库而保持 DSH 开机。第一期刻意无 LLM:巩固(autoDream)与蒸馏结构性不在 daemon 内,这是与宿主「单写者」的机械保证,不靠用户自觉。token 与 DSH 面板/CLI 共用同一 kv 凭证,端口/主机解析链与外部访问一致;`createStandaloneApi` 新增 `strictPort` 选项——daemon 的配置端口被占即报错退出而非顺延(第三方把 URL 写死,静默换端口等于坏),不传该选项的宿主旁路行为不变。`/search` 照常落 recall_runs,第三方检索的复用统计不缺数。多进程共存(daemon 与宿主同库互写互读)有专门回归锁;已知限制(双进程去重竞态、镜像双写、版本偏斜)见 docs/DAEMON.md。
910
- **`injectHeatEnabled`(issue #218 / E5 效用考卷,opt-in 默认关)**:注入侧 heat 拆出独立开关——E5 实测 heat 乘进注入排序在真实年龄混合下饿死老约束(现行量级 ≡ 拟合参数,importance-only 遵从 +12.7pp),默认关后 `heatEnabled` 开启时注入乘数恒 1(与 heat 关闭逐字节一致),显式开启恢复旧序;召回侧时钟与 sleep 降级联判不受影响。

‎dsh-mneme/README.md‎

Lines changed: 16 additions & 5 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-1537%20passed-success)](https://github.com/slow-stack/mneme)
8+
[![tests](https://img.shields.io/badge/tests-1546%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)
@@ -465,7 +465,8 @@ dsh web
465465
| `POST` | `/memories` | 新增记忆 `{type,title,content,importance?,tags?,source?,sensitivity?,occurred_at?,agent_scope?,workspace_scope?}`;响应含 `action: created\|merged` |
466466
| `PUT` | `/memories/:id` | 局部更新 `{title?,content?,type?,importance?,tags?,reason?,agent_scope?,workspace_scope?}`;content 改写按 human_override 入档 |
467467
| `DELETE` | `/memories/:id` | 删除记忆 |
468-
| `GET` | `/search?q&mode=keyword\|vector\|hybrid\|auto&topK&occurred_from&occurred_to` | 搜索(关键词 / 向量 / hybrid=向量领位关键词补位 / 自动) |
468+
| `GET` | `/search?q&mode=keyword\|vector\|hybrid\|auto&topK&occurred_from&occurred_to&agent_scope&workspace_scope` | 搜索(关键词 / 向量 / hybrid=向量领位关键词补位 / 自动)。scope 两参声明调用方身份(不传 = 不解析,行为与旧版一致;任一给出则 strictScope 硬过滤与 A2 软加权随之生效) |
469+
| `GET` | `/context?q&topK&threshold&agent_scope&workspace_scope` | 注入候选一站式聚合(issue #370,#363 承诺):宿主注入管线 `injectCandidates` 全语义(优先级分层 / 编码门控 / heat / scope 软加权 / hybrid 语义路 / pin 前置)+ 画像 + 规则,返回 `{profile, rules, items, pinnedCount}` 结构化条目,不含渲染文本。`threshold` 是 **importance 阈值**(默认 3,与 `/search` 的相似度阈值同名不同义);`topK` 默认 5(对齐宿主 `maxInjectedItems`);scope 语义与 `/search` 同口径;跨轮轮换 / 热记忆 / 时间前缀不含(调用方自管);recall_runs 注入分账与宿主注入同口径(#217 `mode='inject'`) |
469470
| `POST` | `/bootstrap` | 冷启动(v0.8.4):从仓库目录反向构建初始记忆,body `{dir}` 必填;幂等((type,title,scope) 去重 + `_overwrite` 原地刷新),零 LLM、必有产出 |
470471

471472
### curl 示例
@@ -517,7 +518,7 @@ dsh-mneme config show # 查看当前配置(toke
517518

518519
### 独立服务(daemon,`dsh-mneme-serve`)
519520

520-
不启动 DSH 也能让记忆库对外服务:`dsh-mneme-serve` 在宿主之外组装同一套 lib,把数据面跑成常驻进程(路由与鉴权与「独立外部 API」完全同源)。适用场景:第三方集成(如 [Mneme Bridge](https://github.com/slow-stack/mneme/discussions/363) 这类网页端桥接)需要长期挂载记忆库,而 DSH 不必一直开着。
521+
不启动 DSH 也能让记忆库对外服务:`dsh-mneme-serve` 在宿主之外组装同一套 lib,把数据面跑成常驻进程(路由与鉴权与「独立外部 API」完全同源)。适用场景:第三方集成(如 [Mneme-Bridge](https://github.com/SternChiri/Mneme-Bridge) 这类网页端桥接,见下方[社区适配器](#社区适配器))需要长期挂载记忆库,而 DSH 不必一直开着。
521522

522523
```bash
523524
dsh-mneme-serve # 默认 ~/.dsh/memory + 8790
@@ -557,6 +558,16 @@ Claude Code 挂载示例(项目根 `.mcp.json`;token 在面板「设置 →
557558

558559
未全局安装 npm 包时,把 `command` 换成 `npx`、加 `args: ["-p", "@modusensus/dsh-mneme", "dsh-mneme-mcp"]` 即可。
559560

561+
## 社区适配器
562+
563+
以下项目由社区维护,把 mneme 接入第三方平台或宿主。它们不是本仓库的一部分,兼容性由各自维护者跟进——升级 mneme 后如遇接口变更,请优先查看对应项目的 release note。
564+
565+
| 项目 | 平台 | 说明 |
566+
|------|------|------|
567+
| [Mneme-Bridge](https://github.com/SternChiri/Mneme-Bridge) | DeepSeek 网页端 | 浏览器扩展(MV3)+ 本地 Node 服务:网页端会话蒸馏进 mneme 记忆库,DSH 侧记忆按话题回注网页对话,两侧共享同一份记忆。embedded(直接挂载 mneme lib)与 remote(standalone API,推荐配合 [`dsh-mneme-serve`](docs/DAEMON.md))双模式 |
568+
569+
> 想被收录?在 [Discussions](https://github.com/slow-stack/mneme/discussions) 开帖介绍你的项目,或直接提 PR 补充本表。
570+
560571
## 🏗️ 架构
561572

562573
```
@@ -601,7 +612,7 @@ src/
601612
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
602613
└── index.js # 插件接线
603614
lib/ # src 的同步分发产物(npm run sync;发布前由 root prepack 的 check-sync.js 校验一致性;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
604-
test/ # 1537 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
615+
test/ # 1546 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
605616
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 运行时清单
606617
```
607618
@@ -610,7 +621,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
610621
```bash
611622
cd dsh-mneme
612623
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
613-
npm test # 运行 1537 个测试
624+
npm test # 运行 1546 个测试
614625
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
615626
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
616627
```

‎dsh-mneme/docs/DAEMON.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
daemon 是**数据面**,不是第二个宿主:
88

9-
- **有**:存储(SQLite)、检索(关键词 + BM25 + 向量,`/search` 统一召回,与宿主共用 `src/semantic.js` 同一套装配)、镜像同步与人改合并、`/maintenance/reclaim`、`/bootstrap`、recall_runs 检索回执。
9+
- **有**:存储(SQLite)、检索(关键词 + BM25 + 向量,`/search` 统一召回,与宿主共用 `src/semantic.js` 同一套装配)、注入候选(`/context`,issue #370,与宿主注入管线同一份 `injectCandidates`)、镜像同步与人改合并、`/maintenance/reclaim`、`/bootstrap`、recall_runs 检索/注入回执。
1010
- **没有(第一期,无 LLM)**:巩固(autoDream)、蒸馏(autoSummarize)、实体抽取、sleep、注入/工具/面板路由。前两者是**结构性缺失**而非开关——daemon 装配里没有 LLM 句柄,巩固只属于 DSH 宿主进程。这就是 daemon 与宿主「单写者」的机械保证(AGENTS.md externalApi/autoDream 单侧纪律的 daemon 版),不依赖用户自觉。
1111

1212
与宿主装配(`src/index.js` apply)的关系:`src/serve.js` 只搬数据面那一半,每步注释锚定 index.js 来源行号;刻意不抽公共装配函数(apply 其余环节与宿主 ctx 纠缠,防御段纪律「最后动或不动」)。装配漂移风险由 `test/serve-bin.test.js` 的多进程共存用例兜底(两进程真开同一个库互写互读)。
1313

1414
## 2. 对外接口
1515

16-
路由面 = `src/api-standalone.js` 全表(health/status/profile/rules/memories 读写/search/maintenance/bootstrap),鉴权同源(Bearer + timingSafeEqual,`GET /health` 免鉴权)。**零新路由**;唯一新选项是 `strictPort`(见 §4)。
16+
路由面 = `src/api-standalone.js` 全表(health/status/profile/rules/memories 读写/search/context/maintenance/bootstrap),鉴权同源(Bearer + timingSafeEqual,`GET /health` 免鉴权)。daemon 自身零新路由;#370 的 `/context` 落在 api-standalone 工厂里,宿主外部访问与 daemon 自动同享(参数、scope 语义与 recall_runs 注入分账见包 README 路由表)。daemon 侧唯一自有选项是 `strictPort`(见 §4)。
1717

1818
CLI:
1919

@@ -31,10 +31,10 @@ dsh-mneme-serve [--memory-dir <dir>] [--port <n>] [--host <addr>] [--embed <prov
3131

3232
## 3. 内部文件
3333

34-
- `src/serve.js` — `createServeRuntime({memoryDir, port, host, logger, strictPort, embed, embedder, reranker})`:装配链 createStore → createSettings → createMirror → createService(最小 config)→ recoverMirror → 人改镜像合并闭包 → vectorIndex + semantic → recall recorder → createMaintenance → createStandaloneApi,每步锚定 index.js 行号。返回 `{api, store, service, settings, maintenance, semantic, tokenExisted, dispose}`;第三方可 import 它自行托管生命周期(bin 只是薄壳),`embedder/reranker` 参数供注入自管嵌入。
34+
- `src/serve.js` — `createServeRuntime({memoryDir, port, host, logger, strictPort, embed, embedder, reranker})`:装配链 createStore → createSettings → createMirror → createService(最小 config)→ recoverMirror → 人改镜像合并闭包 → vectorIndex + semantic → recall recorder → createMaintenance → createStandaloneApi(带 `embedder: embedder ?? semantic?.embedder ?? null`,供 `/context` 查询嵌入),每步锚定 index.js 行号。返回 `{api, store, service, settings, maintenance, semantic, tokenExisted, dispose}`;第三方可 import 它自行托管生命周期(bin 只是薄壳),`embedder/reranker` 参数供注入自管嵌入。
3535
- `src/semantic.js` — embedder/reranker 装配 + boot 自动回填,**纯搬移自 index.js**(PR2),宿主与 daemon 共用同一份;`backfillMissingEmbeddings` 经 index.js barrel 再出口(测试照旧从 index.js import)。
3636
- `bin/dsh-mneme-serve.mjs` — CLI 壳。独立成 bin 而非 cli.mjs 子命令:CONTRIBUTING 禁止给 cli.mjs 加 import;命名循 dsh-mneme-mcp 先例。
37-
- `src/api-standalone.js` 的 `strictPort` 选项 — 唯一的数据面改动,默认关闭。
37+
- `src/api-standalone.js` 的 `strictPort` 选项 — daemon 自己引入的唯一数据面改动,默认关闭(daemon 侧显式传 true)。#370 起该工厂另增 `/context` 路由与可选 `embedder` 注入,宿主外部访问同享。
3838

3939
## 4. 已知坑
4040

0 commit comments

Comments
 (0)