@cup319/mmpl 2.8.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +30 -268
  2. package/install.js +90 -0
  3. package/mmpl-v3.0.0-linux-x86_64.tar.gz +0 -0
  4. package/mmpl-v3.0.0-windows-x86_64.zip +0 -0
  5. package/package.json +20 -30
  6. package/run.js +15 -0
  7. package/dist/auto-context-NUQFETSY.js +0 -248
  8. package/dist/auto-context-NUQFETSY.js.map +0 -1
  9. package/dist/checkpoint-ABRNCBCA.js +0 -68
  10. package/dist/checkpoint-ABRNCBCA.js.map +0 -1
  11. package/dist/chunk-2H7UOFLK.js +0 -11
  12. package/dist/chunk-2H7UOFLK.js.map +0 -1
  13. package/dist/chunk-CHVFXR24.js +0 -19
  14. package/dist/chunk-CHVFXR24.js.map +0 -1
  15. package/dist/chunk-JL66S7P7.js +0 -151
  16. package/dist/chunk-JL66S7P7.js.map +0 -1
  17. package/dist/chunk-SSDURI3I.js +0 -46
  18. package/dist/chunk-SSDURI3I.js.map +0 -1
  19. package/dist/index.js +0 -21994
  20. package/dist/index.js.map +0 -1
  21. package/dist/mermaid-injector-ROQAAM7B.js +0 -171
  22. package/dist/mermaid-injector-ROQAAM7B.js.map +0 -1
  23. package/dist/observability-6AMQYVCF.js +0 -100
  24. package/dist/observability-6AMQYVCF.js.map +0 -1
  25. package/dist/offload-engine-BF5IXXBH.js +0 -10
  26. package/dist/offload-engine-BF5IXXBH.js.map +0 -1
  27. package/dist/persona-generator-NZQVIVDA.js +0 -228
  28. package/dist/persona-generator-NZQVIVDA.js.map +0 -1
  29. package/dist/pipeline-manager-IJ2JLUMK.js +0 -485
  30. package/dist/pipeline-manager-IJ2JLUMK.js.map +0 -1
  31. package/dist/scene-builder-TLVG23BJ.js +0 -296
  32. package/dist/scene-builder-TLVG23BJ.js.map +0 -1
  33. package/dist/scene-index-SU6GMVDL.js +0 -178
  34. package/dist/scene-index-SU6GMVDL.js.map +0 -1
  35. package/dist/symbolic-A4XAGBBB.js +0 -502
  36. package/dist/symbolic-A4XAGBBB.js.map +0 -1
package/README.md CHANGED
@@ -1,288 +1,50 @@
1
- # MMPL MCP
1
+ # @cup319/mmpl
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@cup319/mmpl)](https://www.npmjs.com/package/@cup319/mmpl)
4
- [![license](https://img.shields.io/npm/l/@cup319/mmpl)](https://cnb.cool/cnb-t/mmpl/-/blob/main/LICENSE)
5
-
6
- 基于 DuckDB 的向量记忆系统,具备完整的记忆生命周期管理,以常驻 HTTP MCP Server 形式运行(v2.5.1+,多 client 共享单进程,避免 DuckDB 文件锁冲突)。���
7
-
8
- ## 核心特性
9
-
10
- - **9 个精简工具**:write、search、list、manage、evolve、compress、palace、symbol、stats
11
- - **模型自动下载**:首次启动自动从 HuggingFace 下载 ONNX 模型(默认 all-MiniLM-L6-v2,90MB,384维)
12
- - **跨平台支持**:Windows + Linux,自动适配路径和信号处理
13
- - **记忆生命周期**:Active → Infrequent → Archived → Permanent(含衰减、强化、SM-2 间隔复习)
14
- - **混��检索**:BM25(FTS5)+ 向量(HNSW)+ 场景 + 用户画像
15
- - **L0-L3 分层管道**:原始记录 → 原子事实 → 场景块 → 用户画像
16
- - **符号压缩**:任务工具调用对 → Mermaid 符号图 + 钻取回放
17
- - **可选 LLM 分析**:重要性评分、类型分类、实体抽取、情感分析
18
-
19
- ## 安装
20
-
21
- ### 方式一:全局安装(推荐,自带 `mmpl` 命令)
3
+ MMPL (Memory Palace) — DuckDB 向量记忆 MCP Server(单二进制,Rust 实现)。
22
4
 
23
5
  ```bash
24
6
  npm install -g @cup319/mmpl
7
+ mmpl # 启动 → http://127.0.0.1:7680/mcp
25
8
  ```
26
9
 
27
- 装完即可直接用 `mmpl` 命令启动 server(详见下文「快速上手」)。
10
+ - 零 node_modules 原生依赖(二进制在 postinstall 从 CNB Release 下载)
11
+ - Streamable HTTP MCP(多 client 共享单进程,DuckDB 独占无锁冲突)
12
+ - 9 工具:`memory_write` / `memory_search` / `memory_list` / `memory_manage` / `memory_stats` / `memory_evolve` / `memory_compress` / `memory_palace` / `memory_symbol`
13
+ - BM25(jieba + DuckDB FTS5)+ ONNX 语义向量(bge-small-zh)+ RRF 三路融合 + SM-2 强化
14
+ - **v0.5.1 起出厂默认 = 知识库模式**(stability_days=30 / review_boost=0.5,无复习半衰期 ~20.8 天)
15
+ - SIGTERM 优雅关停
28
16
 
29
- ### 方式二:项目内安装
17
+ ## 记忆保持怎么配?
30
18
 
31
- ```bash
32
- npm install @cup319/mmpl
33
- ```
19
+ | 想要 | 做法 |
20
+ |---|---|
21
+ | **全部永久** | MCP 里执行一次 `memory_manage action=forgetting_disable`(自动持久化,重启生效);或环境变量 `MMPL_FORGET=0` |
22
+ | **单条永久** | `memory_write action=encode input="…" permanent=true`;已有条目 `reinforce_action=promote_to_permanent` |
23
+ | **换个场景档** | 启动时 `MMPL_PROFILE=code|vocab|assistant|lab`(默认 `knowledge`) |
34
24
 
35
- 安装后入口在 `node_modules/@cup319/mmpl/dist/index.js`。作为 MCP Server 使用时,在 client 配置中指向这个路径,或用 `node ./node_modules/@cup319/mmpl/dist/index.js` 启动。
25
+ 场景档位一览:`knowledge`(默认, S=30/boost=0.5) / `code`(S=7/boost=1) / `vocab`(S=0.5/boost=2 背单词) / `assistant`(S=1/boost=1) / `lab`(S=0.01 观察遗忘)。
36
26
 
37
- ### 方式三:从源码构建
27
+ 背英语单词:`MMPL_PROFILE=vocab` 启动,词条 `memory_write encode` 录入 → `memory_search` 自测(命中即算一次复习)→ 记得 `reinforce confirm`(稳定期 0.5→1.5→2.5 天递增)、忘了 `reinforce deny` → `mode=deep` 定期捞半忘词强化。详见仓库 `rust/README.md`。
38
28
 
39
- ```bash
40
- git clone https://cnb.cool/cnb-t/mmpl.git
41
- cd mmpl
42
- npm install
43
- npm run build # 产物在 dist/index.js
44
- node dist/index.js
45
- ```
46
-
47
- ## 快速上手(5 分钟教程)
29
+ 环境变量:`DB_PATH`(默认 `data/memory.duckdb`)/ `HOST` / `PORT`(默认 7680)/ `MCP_PATH`(默认 `/mcp`)/ `MMPL_PROFILE` / `MMPL_FORGET` / `MMPL_STABILITY_DAYS` / `MMPL_REVIEW_BOOST` / `MMPL_ONNX` / `MMPL_MODEL`(v0.5.2 起四档:`base` 默认 / `small` / `m3` / `qwen3`)。
48
30
 
49
- 这一节带你从零跑通:安装 → 启动 → 连接 client → 写入/检索第一条记忆。
31
+ ## Hermes Agent 插件接入
50
32
 
51
- > **前置条件**:Node.js ≥ 20。首次启动会从 HuggingFace 自动下载 ONNX 模型(默认 `all-MiniLM-L6-v2`,~90MB,国内网络会自动切到 `hf-mirror.com` 镜像)。
52
-
53
- ### Step 1:启动 server
54
-
55
- 全局安装后,任意终端执行:
33
+ MMPL 可作为 [Hermes Agent](https://hermes-agent.nousresearch.com) 的**原生 MemoryProvider 插件**(与 holographic 等并列的记忆后端):插件源码在仓库 `integrations/hermes/` 目录,纯 HTTP 客户端、零 Python 依赖,把上面 9 个 MCP 工具透传给 Agent 并自动沉淀对话。
56
34
 
57
35
  ```bash
58
- mmpl
59
- # 等价于:node ./node_modules/@cup319/mmpl/dist/index.js
60
- ```
61
-
62
- 看到类似输出即成功(首启会多花 5–10 秒加载 ONNX 模型):
63
-
64
- ```
65
- MMPL (Memory Palace) MCP Server v2.7.0 listening on http://127.0.0.1:7680/mcp
66
- ```
67
-
68
- > **重要**:mmpl 只有 HTTP 一种模式,**没有 stdio、没有 CLI flag**。所有配置(host/port/path、DB 路径、模型路径、LLM key)都走环境变量。多个 client 共享这同一个进程,**不要起第二个 server**——DuckDB 文件是单进程独占的。
69
-
70
- ### Step 2:验证 server 活着
71
-
72
- ```bash
73
- curl http://127.0.0.1:7680/
74
- # {"status":"ok","server":"mmpl","sessions":0}
75
- ```
76
-
77
- ### Step 3:在 client 里连接
78
-
79
- ZCode (`~/.zcode/cli/config.json`):
80
-
81
- ```json
82
- {
83
- "mcp": {
84
- "servers": {
85
- "mmpl": { "type": "http", "url": "http://127.0.0.1:7680/mcp" }
86
- }
87
- }
88
- }
89
- ```
90
-
91
- Claude Desktop / Claude Code(`claude_desktop_config.json` 或 `~/.claude.json`):
92
-
93
- ```json
94
- {
95
- "mcpServers": {
96
- "mmpl": { "type": "http", "url": "http://127.0.0.1:7680/mcp" }
97
- }
98
- }
99
- ```
100
-
101
- 重连 client 后,`sessions` 会 +1:
102
-
103
- ```bash
104
- curl http://127.0.0.1:7680/
105
- # {"status":"ok","server":"mmpl","sessions":1}
106
- ```
107
-
108
- ### Step 4:写入第一条记忆
109
-
110
- 在连接好的 client 里让 AI 调用 `memory_write`(以 encode 模式写入一条 fact):
111
-
112
- ```jsonc
113
- // 工具名: memory_write
114
- {
115
- "action": "encode",
116
- "input": "用户的本地时区是 Asia/Shanghai (UTC+8),工作时间 09:00-18:00。",
117
- "type": "preference",
118
- "tags": ["timezone", "work-hours"]
119
- }
120
- ```
121
-
122
- 返回 `memory_id` 即写入成功。
123
-
124
- ### Step 5:检索记忆
125
-
126
- ```jsonc
127
- // 工具名: memory_search
128
- {
129
- "mode": "quick",
130
- "query": "用户在哪个时区?几点上班?"
131
- }
132
- ```
133
-
134
- 会命中刚才写入的那条,返回内容及相似度评分。`mode` 可选 `quick` / `deep` / `hybrid` / `keyword`。
135
-
136
- ### Step 6:看统计
137
-
138
- ```jsonc
139
- // 工具名: memory_stats
140
- { "type": "summary" }
141
- ```
142
-
143
- 到这里你已经跑通了完整闭环。9 个工具的完整说明见下文「工具一览」。
144
-
145
- > **常驻保活**:HTTP server 自身不会自我守护。Windows 推荐 `nssm install MMPL node D:\path\to\dist\index.js`,Linux/macOS 推荐 `systemd` 或 `pm2 start dist/index.js --name mmpl`。
146
-
147
- ## 配置
148
-
149
- ### 部署:常驻 HTTP MCP Server(推荐 — 多 client 共享)
36
+ # 1. 拷贝插件
37
+ mkdir -p $HERMES_HOME/plugins/mmpl
38
+ cp integrations/hermes/__init__.py integrations/hermes/plugin.yaml $HERMES_HOME/plugins/mmpl/
150
39
 
151
- v2.5.1 起,mmpl 默认作为 **Streamable HTTP MCP server** 运行:一个常驻进程独占 DuckDB,被多个 MCP client(ZCode / Claude Desktop / IDE 等)共享。这从根本上避免了 stdio 模式下多 client 各自 spawn 进程、争抢同一个 `.duckdb` 文件导致的 `Connection closed` 错误。
40
+ # 2. config.yaml:
41
+ # memory: { provider: mmpl }
42
+ # plugins:
43
+ # mmpl: { url: "http://127.0.0.1:7680/mcp", top_k: 5 }
152
44
 
153
- 启动命令见上文「快速上手 · Step 1」。完整启动示例(带环境变量):
154
-
155
- ```bash
156
- EMBEDDING_PROVIDER=onnx \
157
- DB_PATH=./data/memory.duckdb \
158
- ONNX_MODEL_PATH=./models/all-MiniLM-L6-v2.onnx \
159
- ANALYZER_API_URL=https://api.z.ai/api/paas/v4/chat/completions \
160
- ANALYZER_API_KEY=<your-api-key> \
161
- ANALYZER_MODEL=glm-4-flash \
162
- node ./node_modules/@cup319/mmpl/dist/index.js
163
- # 或全局安装后直接:mmpl
164
- ```
165
-
166
- client 配置(每个 client 一份,只填 URL)见「快速上手 · Step 3」。
167
-
168
- **Health check(确认 server 活着)**
169
-
170
- ```bash
171
- curl http://127.0.0.1:7680/
172
- # {"status":"ok","server":"mmpl","sessions":3}
173
- ```
174
-
175
- **常驻进程管理(可选)**
176
-
177
- HTTP server 启动后不自我守护,靠外部保活:
178
-
179
- - **Windows**: `nssm install MemoryPalace node D:\path\to\dist\index.js`,或用 Task Scheduler
180
- - **Linux/macOS**: systemd unit 或 `pm2 start dist/index.js --name mmpl`
181
-
182
- > server 默认只绑 `127.0.0.1`(本机访问)。多 client 共享时**不要**起第二个 server 进程——DuckDB 文件是单进程独占的,第二个进程会启动失败;多个 client 都连同一个 HTTP URL 即可。
183
-
184
- ### ZCode 集成:常驻 + 无弹窗(开箱即用)
185
-
186
- 如果你在 ZCode 里用 mmpl,推荐用仓库自带的部署示例 [`examples/zcode-deploy/`](./examples/zcode-deploy/)。它通过 SessionStart/Stop hook 实现:
187
-
188
- - **常驻运行**:server 启动一次后一直留在后台,切换 ZCode session 不重启(避免每次等 5–10s ONNX 加载)
189
- - **无 node.exe 黑窗**:所有 `spawn` 配 `windowsHide: true`(修复了 Windows 上启动时弹 `C:\...\node.exe` 窗口的问题)
190
- - **日志落盘**:server 的 stdout/stderr 重定向到 `.mmpl-server.log`,排查启动失败有据可查
191
-
192
- 一键安装:
193
-
194
- ```bash
195
- # 1. 准备部署目录
196
- mkdir D:\mmpl-deploy && cd D:\mmpl-deploy
197
- npm init -y && npm install @cup319/mmpl
198
- # 2. 复制示例脚本
199
- cp /path/to/examples/zcode-deploy/*.mjs .
200
- # 3. 按示例 README 配置 ~/.zcode/cli/config.json 的 hook
201
- ```
202
-
203
- 完整步骤、配置示例、运行机制、弹窗 bug 修复历史详见 [`examples/zcode-deploy/README.md`](./examples/zcode-deploy/README.md)。
204
-
205
- > **澄清**:`@cup319/mmpl` npm 包本身不 spawn 子进程,**不存在弹窗问题**。弹窗只发生在用 `start-mmpl.mjs` 包装启动时(该脚本 spawn 子进程的方式在 Windows 上需要 `windowsHide`),示例脚本已修复。
206
-
207
- ### 遗留:stdio 模式
208
-
209
- v2.5.1 之前默认走 stdio,每个 client 各 spawn 一个进程。该模式已在 v2.5.1 移除(多 client 场景下 DuckDB 文件锁无法解决)。如确需单 client stdio,可 git checkout v2.4.4 标签。
210
-
211
- ## 环境变量
212
-
213
- **Server 启动时(HTTP 进程的 env)**
214
-
215
- | 变量 | 默认值 | 说明 |
216
- |------|--------|------|
217
- | `EMBEDDING_PROVIDER` | `onnx` | `onnx` / `api` / `tfidf` |
218
- | `ONNX_MODEL_PATH` | `./models/all-MiniLM-L6-v2.onnx` | ONNX 模型路径 |
219
- | `DB_PATH` | `./data/memory.duckdb` | DuckDB 数据库路径 |
220
- | `ANALYZER_API_URL` | — | LLM API 地址(智谱/OpenAI) |
221
- | `ANALYZER_API_KEY` | — | LLM API 密钥 |
222
- | `ANALYZER_MODEL` | `glm-4-flash` | 分析用模型 |
223
- | `TFIDF_DICT_PATH` | `./data/tfidf-dict.json` | TF-IDF 字典路径(可选,仅 tfidf provider 使用,运行时自动生成) |
224
- | `MCP_HTTP_HOST` | `127.0.0.1` | HTTP server 绑定地址(`0.0.0.0` 开放外网,需自行加防火墙/鉴权) |
225
- | `MCP_HTTP_PORT` | `7680` | HTTP server 端口 |
226
- | `MCP_HTTP_PATH` | `/mcp` | MCP 端点路径 |
227
-
228
- ## 工具一览
229
-
230
- | 工具 | 说明 |
231
- |------|------|
232
- | `memory_write` | 写入记忆(encode 编码 + capture 捕获) |
233
- | `memory_search` | 检索记忆(quick/deep/hybrid/keyword + drill 钻取) |
234
- | `memory_list` | 列出记忆(分页 + 状态/类型/强度/关键词过滤 + 排序) |
235
- | `memory_manage` | 管理生命周期(forget/reinforce/consolidate/reclaim/reembed) |
236
- | `memory_evolve` | 自动进化(extract 提取 + persona 画像更新) |
237
- | `memory_compress` | 压缩记忆(compress/decompress/offload) |
238
- | `memory_palace` | 记忆宫殿(build/explore/visualize/scenes) |
239
- | `memory_symbol` | 符号记忆(create/search/export) |
240
- | `memory_stats` | 统计监控(summary/strength/review/pipeline/metrics) |
241
-
242
- ## ONNX 模型
243
-
244
- 首次启动时自动从 HuggingFace 下载模型及 tokenizer 文件(~90MB),支持断点续传。
245
-
246
- 默认使用 `all-MiniLM-L6-v2`(384维,英文优化)。如需多语言支持,设置 `ONNX_MODEL_PATH` 指向 `paraphrase-multilingual-MiniLM-L12-v2`(384维,50+语言,~470MB)。
247
-
248
- 自动下载失败时,控制台会打印平台适配的手动下载命令。
249
-
250
- ### 国内网络环境(镜像加速)
251
-
252
- HuggingFace 官方源(`huggingface.co`)在国内访问经常超时。MMPL 内置**自动镜像切换**:
253
-
254
- - 启动时探测 `huggingface.co`(3 秒超时)
255
- - 可达 → 用官方源
256
- - 不可达 → 自动切到国内镜像 `hf-mirror.com`
257
-
258
- 控制台会打印实际选用的源,例如:
259
- ```
260
- [ONNX] HuggingFace 官方源不可达 (3000ms 超时),切换国内镜像 https://hf-mirror.com
261
- ```
262
-
263
- **手动指定镜像源**(覆盖自动探测):设置 `HF_ENDPOINT` 环境变量(HuggingFace 官方约定):
264
-
265
- ```bash
266
- # Windows
267
- set HF_ENDPOINT=https://hf-mirror.com
268
-
269
- # Linux/macOS
270
- export HF_ENDPOINT=https://hf-mirror.com
271
-
272
- # 或者用自定义镜像
273
- export HF_ENDPOINT=https://your-mirror.example.com
274
- ```
275
-
276
- `HF_ENDPOINT` 优先级最高,设置后会跳过自动探测直接使用。
277
-
278
- ## 开发
279
-
280
- ```bash
281
- npm test # 单元测试(75 用例)
282
- npm run lint # 类型检查
283
- npm run dev # 开发模式
45
+ # 3. 保持 mmpl 服务在跑(插件健康检查不过会自动拉起)
284
46
  ```
285
47
 
286
- ## 许可证
48
+ `hermes memory status` 应列出 `mmpl (no setup needed)`。安装细节与生命周期映射见仓库 `rust/README.md`「Hermes Agent 插件接入」章节。
287
49
 
288
- MIT
50
+ 完整文档见仓库 `rust/README.md` 与 `rust/USERS_GUIDE.md`。
package/install.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MMPL Rust 版 npm 安装器 v5
4
+ * 双平台:Linux (x86_64) + Windows (x86_64)。优先用包内自带产物(离线可用);
5
+ * 缺失时回落 CNB Release 下载(需公开访问)。
6
+ * 语义向量模型(bge-base-zh-v1.5,~103MB)不在包内——MMPL 首次启动时自动从
7
+ * hf-mirror.com 下载到 DATA_DIR/models/(v2.9.0 已修复 copy 自覆盖 bug,下载可成功)。
8
+ */
9
+ const { createWriteStream, existsSync, mkdirSync, chmodSync } = require("fs");
10
+ const { pipeline } = require("stream/promises");
11
+ const { get } = require("https");
12
+ const path = require("path");
13
+ const { execSync } = require("child_process");
14
+
15
+ const VERSION = "3.0.0";
16
+ const IS_WIN = process.platform === "win32";
17
+ const PLATFORM = IS_WIN ? "windows" : "linux";
18
+ const ARCH = "x86_64";
19
+
20
+ // 产物命名:Linux 是 tar.gz(mmpl-linux-x86_64);Windows 是 zip(mmpl.exe + duckdb.dll)。
21
+ const ASSET_NAME = IS_WIN
22
+ ? `mmpl-v${VERSION}-windows-${ARCH}.zip`
23
+ : `mmpl-v${VERSION}-linux-${ARCH}.tar.gz`;
24
+ const URL = `https://cnb.cool/cnb-t/MMPL/-/releases/download/rust-v${VERSION}/${ASSET_NAME}`;
25
+
26
+ const BIN = IS_WIN
27
+ ? path.join(__dirname, "bin", "mmpl.exe")
28
+ : path.join(__dirname, "bin", "mmpl");
29
+ const BUNDLED = path.join(__dirname, ASSET_NAME);
30
+
31
+ function extractLinux(tarPath) {
32
+ mkdirSync(path.dirname(BIN), { recursive: true });
33
+ execSync(`tar xzf ${JSON.stringify(tarPath)} -C ${JSON.stringify(path.dirname(BIN))}`);
34
+ execSync(`mv ${JSON.stringify(path.join(path.dirname(BIN), `mmpl-linux-${ARCH}`))} ${JSON.stringify(BIN)}`);
35
+ chmodSync(BIN, 0o755);
36
+ }
37
+
38
+ function extractWindows(zipPath) {
39
+ mkdirSync(path.dirname(BIN), { recursive: true });
40
+ if (process.platform === "win32") {
41
+ execSync(`powershell -NoProfile -Command "Expand-Archive -Force '${zipPath}' '${path.dirname(BIN)}'"`);
42
+ } else {
43
+ execSync(`unzip -o ${JSON.stringify(zipPath)} -d ${JSON.stringify(path.dirname(BIN))}`);
44
+ }
45
+ }
46
+
47
+ function download(url, redirects = 5) {
48
+ return new Promise((resolve, reject) => {
49
+ get(url, { headers: { "User-Agent": "mmpl-installer" } }, (res) => {
50
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location && redirects > 0) {
51
+ res.resume();
52
+ return resolve(download(res.headers.location, redirects - 1));
53
+ }
54
+ if (res.statusCode !== 200) {
55
+ res.resume();
56
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
57
+ }
58
+ resolve(res);
59
+ }).on("error", reject);
60
+ });
61
+ }
62
+
63
+ async function main() {
64
+ if (existsSync(BIN)) return;
65
+
66
+ if (existsSync(BUNDLED)) {
67
+ console.log(`[mmpl] extracting bundled ${PLATFORM} binary ...`);
68
+ if (IS_WIN) extractWindows(BUNDLED);
69
+ else extractLinux(BUNDLED);
70
+ console.log(`[mmpl] installed: ${BIN}`);
71
+ return;
72
+ }
73
+
74
+ console.log(`[mmpl] downloading Rust binary v${VERSION} (${PLATFORM}-${ARCH}) ...`);
75
+ try {
76
+ const res = await download(URL);
77
+ const tmpFile = BIN + (IS_WIN ? ".zip.download" : ".tar.gz");
78
+ await pipeline(res, createWriteStream(tmpFile));
79
+ if (IS_WIN) extractWindows(tmpFile);
80
+ else extractLinux(tmpFile);
81
+ execSync(`rm -f ${JSON.stringify(tmpFile)}`);
82
+ console.log(`[mmpl] installed: ${BIN}`);
83
+ } catch (e) {
84
+ console.warn(`[mmpl] ⚠️ install failed: ${e.message}`);
85
+ console.warn(`[mmpl] 手动安装: curl -LO ${URL}`);
86
+ process.exit(0);
87
+ }
88
+ }
89
+
90
+ main();
Binary file
Binary file
package/package.json CHANGED
@@ -1,47 +1,37 @@
1
1
  {
2
2
  "name": "@cup319/mmpl",
3
- "version": "2.8.1",
3
+ "version": "3.0.0",
4
+ "description": "MMPL (Memory Palace) — 单二进制 DuckDB 记忆 MCP Server (9 工具 + ONNX 语义向量 + 冲突双通道门控 + 场景构建 + 四层钻取) — Linux + Windows 双平台",
5
+ "license": "MIT",
4
6
  "publishConfig": {
5
7
  "access": "public",
6
8
  "registry": "https://registry.npmjs.org/"
7
9
  },
8
- "description": "MMPL (Memory Palace) — DuckDB 向量记忆系统 (L0-L3 分层 + SM-2 衰减 + 符号压缩 + 9 精简工具)",
9
- "type": "module",
10
- "main": "dist/index.js",
11
10
  "bin": {
12
- "mmpl": "dist/index.js"
11
+ "mmpl": "run.js"
13
12
  },
13
+ "files": [
14
+ "install.js",
15
+ "run.js",
16
+ "README.md",
17
+ "mmpl-v3.0.0-linux-x86_64.tar.gz",
18
+ "mmpl-v3.0.0-windows-x86_64.zip"
19
+ ],
14
20
  "scripts": {
15
- "build": "tsup",
16
- "dev": "tsx src/index.ts",
17
- "start": "node dist/index.js",
18
- "start:http": "node dist/index.js",
19
- "test": "vitest run",
20
- "test:watch": "vitest",
21
- "lint": "tsc --noEmit",
22
- "inspector": "npx @modelcontextprotocol/inspector node dist/index.js"
21
+ "postinstall": "node install.js"
23
22
  },
24
23
  "keywords": [
25
24
  "mcp",
26
25
  "memory",
27
26
  "palace",
28
- "spaced-repetition",
29
- "ai-agent"
27
+ "duckdb",
28
+ "ai-agent",
29
+ "windows",
30
+ "linux"
30
31
  ],
31
- "license": "MIT",
32
- "dependencies": {
33
- "@huggingface/transformers": "^4.2.0",
34
- "@modelcontextprotocol/sdk": "^1.12.1",
35
- "@node-rs/jieba": "^2.0.1",
36
- "duckdb": "^1.4.4",
37
- "onnxruntime-node": "^1.26.0"
38
- },
39
- "devDependencies": {
40
- "@types/better-sqlite3": "^7.6.13",
41
- "@types/node": "^22.15.0",
42
- "tsup": "^8.4.0",
43
- "tsx": "^4.19.0",
44
- "typescript": "^5.8.0",
45
- "vitest": "^3.1.0"
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://cnb.cool/cnb-t/MMPL.git",
35
+ "directory": "rust"
46
36
  }
47
37
  }
package/run.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ /** bin 入口:转发到下载好的二进制(双平台) */
3
+ const { spawn } = require("child_process");
4
+ const path = require("path");
5
+
6
+ const BIN = path.join(__dirname, "bin", process.platform === "win32" ? "mmpl.exe" : "mmpl");
7
+ const child = spawn(BIN, process.argv.slice(2), {
8
+ stdio: "inherit",
9
+ env: process.env,
10
+ });
11
+ child.on("error", (e) => {
12
+ console.error("[mmpl] binary not found — run `npm rebuild @cup319/mmpl` or see README");
13
+ process.exit(1);
14
+ });
15
+ child.on("exit", (code) => process.exit(code ?? 1));