@furongjun1999/dsh-memory 0.4.2 → 0.4.4
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.
- package/README.md +59 -20
- package/cordis.patch.yml +1 -1
- package/docs/cordis-patch-profile-web.example.yml +35 -0
- package/docs//345/267/245/344/275/234/347/272/252/345/276/213_/350/256/244/347/237/245/345/233/276/346/235/241/347/233/256_v1.1.json +356 -0
- package/docs//347/201/265/346/236/242MCP/345/267/245/345/205/267/346/200/273/350/241/250_v3.4.md +3 -2
- package/docs//347/201/265/346/236/242_/350/207/252/346/210/221/345/261/202/345/256/232/344/271/211.md +43 -0
- package/docs//347/231/275/347/256/261/346/231/272/350/203/275/347/263/273/345/210/227/302/267/347/254/254/344/272/224/347/257/207/357/274/232/350/256/251AI/347/234/237/346/255/243/350/243/205/344/270/212/350/256/260/345/277/206.md +373 -0
- package/docs//350/256/244/347/237/245/345/233/276_MD/347/233/256/345/275/225/346/226/271/346/241/210_v0.1.md +530 -0
- package/docs//350/256/244/347/237/245/345/233/276/344/275/234/344/270/272/350/256/260/345/277/206/346/223/215/344/275/234/347/263/273/347/273/237_/350/257/204/344/274/260/344/270/216/350/267/257/347/272/277_v0.1.md +94 -0
- package/docs//350/256/260/345/277/206/346/223/215/344/275/234/347/263/273/347/273/237_MdCGOS/344/270/216MCP/346/216/245/345/205/245_v0.1.md +178 -0
- package/package.json +93 -77
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# md_cg · 记忆操作系统(Memory OS)· 实现与接入
|
|
2
|
+
|
|
3
|
+
> 在 MdCG(P0/P1 已验证引擎)之上补齐「记忆操作系统」能力,并暴露为 MCP 服务。
|
|
4
|
+
> 2026-09-08 · 全部经 dsh 端独立实跑验证
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 一、本次交付
|
|
9
|
+
|
|
10
|
+
| 文件 | 职责 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| `md_cg/mdcos.py` | **MdCGOS**:在 MdCG 上新增 7 项记忆 OS 能力 |
|
|
13
|
+
| `md_cg/mcp_server.py` | **MCP server**(stdio + JSON-RPC 2.0,协议 2024-11-05,17 工具,零依赖)|
|
|
14
|
+
| `md_cg/test_p2.py` | P2 验收(7 项能力)**31/31** |
|
|
15
|
+
| `md_cg/test_p2_mcp.py` | MCP 协议验收 **23/23** |
|
|
16
|
+
|
|
17
|
+
回归:**P0 25/25 · P1 37/37 仍全绿**(未修改 MdCG 既有语义)。
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 二、七项能力(对标 deja-vu / dsh-noema)
|
|
22
|
+
|
|
23
|
+
| # | 能力 | 接口 | 要点 |
|
|
24
|
+
|---|---|---|---|
|
|
25
|
+
| 1 | **Fix pairs 自动挖掘** | `mine_fix_pairs(events)` | 行为日志「错误→修复」→ **knowledge/ 可路由修复知识** + **rejected/ 负记忆**(此错不必深挖根因);幂等 |
|
|
26
|
+
| 2 | **role 分层索引** | `add(role=...)` · `search(roles=, include_work=)` | 工具输出/命令/编辑(`tool-output/command/edit`)**默认不参与正排**,避免稀释召回 |
|
|
27
|
+
| 3 | **RRF 并行多路召回** | `search_rrf(...)` | 词法 / 条件桶 / 实体 / 图扩展 四路并行 → Reciprocal Rank Fusion;结果带 **provenance**(可审计)|
|
|
28
|
+
| 4 | **审核队列 edit/merge** | `propose` · `review_list` · `review_decide` | 海马体式 `hippocampus/inbox.jsonl` → `decisions.jsonl`;裁决 **accept / reject / edit / merge** |
|
|
29
|
+
| 5 | **tombstone + 恢复检查** | `forget` · `restore` · `is_tombstoned` | 软删除入 `trash/` + `_deletions.jsonl` 删除清单;恢复时校验,须 `force` 才可强恢复 |
|
|
30
|
+
| 6 | **payload-free 审计** | `_audit` · `audit_records` | 每次变更只记 `{t,op,id,actor,payload_hash}`,**绝不记内容** |
|
|
31
|
+
| 7 | **budget-driven pack** | `recall(query, budget_tokens)` | 装到预算花完;**超大条目跳过而非停下**(继续尝试更小的)|
|
|
32
|
+
|
|
33
|
+
另:`health_os()` 在原有健康度上并入 OS 指标(role 分布 / 待审数 / 墓碑数 / 审计事件数 / 反思数)。
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 三、DSH 接入(MCP)
|
|
38
|
+
|
|
39
|
+
### 3.1 启动
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
MDCG_ROOT="D:/Program Files/2_ai/AEIS/data/mdcg" \
|
|
43
|
+
MDCG_ACTOR="dsh" \
|
|
44
|
+
PYTHONPATH="D:/Program Files/2_ai/dsh-memory/llm-adapter-poc" \
|
|
45
|
+
python -m md_cg.mcp_server
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3.2 DSH 侧配置(cordis.yml / MCP client)
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
- id: mdcg
|
|
52
|
+
name: mdcg-mcp # MCP server(stdio)
|
|
53
|
+
config:
|
|
54
|
+
command: python
|
|
55
|
+
args: ["-m", "md_cg.mcp_server"]
|
|
56
|
+
env:
|
|
57
|
+
MDCG_ROOT: "D:/Program Files/2_ai/AEIS/data/mdcg"
|
|
58
|
+
MDCG_ACTOR: "dsh"
|
|
59
|
+
PYTHONPATH: "D:/Program Files/2_ai/dsh-memory/llm-adapter-poc"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3.3 工具面(17)
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
写:mdcg_remember · mdcg_rejected · mdcg_unresolved · mdcg_propose
|
|
66
|
+
读:mdcg_get · mdcg_search · mdcg_recall · mdcg_review_list
|
|
67
|
+
认知:mdcg_reflect · mdcg_verify · mdcg_flywheel · mdcg_mine_fix_pairs
|
|
68
|
+
生命周期:mdcg_forget · mdcg_restore · mdcg_review_decide
|
|
69
|
+
运维:mdcg_health · mdcg_service_info
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3.4 典型调用序列
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
会话开始 → mdcg_recall(query=用户请求, budget_tokens=1200)
|
|
76
|
+
重要判断 → mdcg_search(query, context=当前情境) # 拿 state(四态)
|
|
77
|
+
踩坑/修好 → mdcg_mine_fix_pairs(events) # 自动沉淀负记忆 + 修复知识
|
|
78
|
+
新知识候选 → mdcg_propose(...) → 人工/agent 审核 → mdcg_review_decide
|
|
79
|
+
需要清理 → mdcg_forget(id, reason) → 审计可查
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 四、验证命令
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cd "D:/Program Files/2_ai/dsh-memory/llm-adapter-poc"
|
|
88
|
+
set PYTHONPATH=.
|
|
89
|
+
python -m md_cg.test_p2 # 31/31 七项能力
|
|
90
|
+
python -m md_cg.test_p2_mcp # 23/23 MCP 协议
|
|
91
|
+
python -m md_cg.test_p0 # 25/25 回归
|
|
92
|
+
python -m md_cg.test_p1 # 37/37 回归
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 五、与竞品对照(本次补齐后)
|
|
98
|
+
|
|
99
|
+
| 维度 | deja-vu | dsh-noema | **灵枢 md_cg(本次后)** |
|
|
100
|
+
|---|---|---|---|
|
|
101
|
+
| 负记忆 | Fix pairs 自动挖掘 | rejected 候选 | **Fix pairs 自动挖掘 + rejected/unresolved** |
|
|
102
|
+
| 召回融合 | BM25 + 双 tier | BM25+PageIndex+图 **RRF** | **四路 RRF + 条件路由 T0–T3** |
|
|
103
|
+
| role 分层 | ✅ 工具输出/命令/编辑不参与 | — | **✅ 同** |
|
|
104
|
+
| 审核 | — | inbox→decisions(含 edit/merge)| **✅ 含 edit/merge** |
|
|
105
|
+
| 隐私 | 索引时 redact | 敏感度+墓碑+payload-free | **✅ tombstone + 恢复检查 + payload-free** |
|
|
106
|
+
| 预算控制 | budgeted digest | budget-driven pack | **✅ 跳过超大** |
|
|
107
|
+
| 系统调用面 | 单二进制 | MCP stdio | **✅ MCP stdio(17 工具)** |
|
|
108
|
+
| 独有 | — | — | **条件路由 + 资格四态 + CCG 五要素 + 信息差 D/d²D + 飞轮** |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 六、#2 进程/权限(公开知识 / 私有记忆隔离)
|
|
113
|
+
|
|
114
|
+
> **动机**:灵枢是开源仓库,而记忆很大一部分是私有内容。权限模型必须让
|
|
115
|
+
> 「公开知识」与「私有记忆」在**物理**与**逻辑**两层隔离。
|
|
116
|
+
|
|
117
|
+
`md_cg/security.py` + `MdCGSecure`(mdcos.py):
|
|
118
|
+
|
|
119
|
+
| 机制 | 说明 |
|
|
120
|
+
|---|---|
|
|
121
|
+
| **Principal** | `tenant / actor / clearance / can_write / can_admin / session` |
|
|
122
|
+
| **密级链** | `public < internal < private < secret` |
|
|
123
|
+
| **读隔离** | `search / recall / get / search_rrf` 一致过滤:clearance 之上的节点**不可见即不存在** |
|
|
124
|
+
| **写隔离** | 写入敏感度 > clearance → `AccessDenied`;`secret` 对 clearance<secret **写入即拒** |
|
|
125
|
+
| **管理隔离** | `forget / restore / review_decide` 需 `can_admin` |
|
|
126
|
+
| **租户注册表** | `~/.mdcg/_tenants.json`:tenant → `{root, clearance_cap}`;**公开根在仓库内,私有根在仓库外** |
|
|
127
|
+
| **夹紧** | `principal_for(tenant)` 把调用方 clearance 夹到租户上限(不能越租户) |
|
|
128
|
+
| **审计** | 每条审计带 `tenant / session / clearance`(可追溯到哪个会话做了什么) |
|
|
129
|
+
|
|
130
|
+
MCP 侧通过环境变量配置:
|
|
131
|
+
```yaml
|
|
132
|
+
env:
|
|
133
|
+
MDCG_ROOT: "D:/.../public-root" # 公开租户
|
|
134
|
+
MDCG_TENANT: "public"
|
|
135
|
+
MDCG_CLEARANCE: "public" # public < internal < private < secret
|
|
136
|
+
MDCG_CAN_WRITE: "1"
|
|
137
|
+
MDCG_CAN_ADMIN: "0" # 管理操作默认关闭
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 七、#3 设备驱动(会话流 → 记忆)
|
|
143
|
+
|
|
144
|
+
`md_cg/sources.py`:
|
|
145
|
+
|
|
146
|
+
| 组件 | 说明 |
|
|
147
|
+
|---|---|
|
|
148
|
+
| **Source** | 统一事件流 `{t, seq, role, text, session, cwd}` |
|
|
149
|
+
| **JsonlSource** | 通用 JSONL(字段映射可配)|
|
|
150
|
+
| **DSHSessionSource** | 读 `~/.dsh/sessions/**/session.jsonl[.zstd]`;映射 `user/message→user`、`assistant/message→assistant`(reasoning 默认丢弃)、`tool/call→command`、`tool/result→tool-output`;zstd 为**可选**依赖,缺失优雅降级 |
|
|
151
|
+
| **Ingestor** | 增量摄取:**watermark**(`_sources.json`)+ `(session,seq)` 去重 + 幂等 + **自动 fix-pair 挖掘** |
|
|
152
|
+
| **默认策略** | 会话落 `contextual` 层,**sensitivity=private**(不进公开根)|
|
|
153
|
+
|
|
154
|
+
实测:真实 DSH 会话 **3/3 可解析**;增量摄取幂等;权限不足时 `denied` 计数 + `hint` 报告(不静默)。
|
|
155
|
+
|
|
156
|
+
MCP 工具:`mdcg_ingest`(`source=auto` 自动发现本机 DSH 会话)、`mdcg_watermarks`、`mdcg_whoami`。
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 八、验收总表
|
|
161
|
+
|
|
162
|
+
| 套件 | 覆盖 | 结果 |
|
|
163
|
+
|---|---|---|
|
|
164
|
+
| `test_p0` | 引擎基线(分桶/回退阶梯/只读契约/并发) | **25/25** |
|
|
165
|
+
| `test_p1` | 白箱架构 9 维 | **37/37** |
|
|
166
|
+
| `test_p2` | 七项 OS 能力 | **31/31** |
|
|
167
|
+
| `test_p3` | #2 权限 + #3 设备驱动 | **33/33** |
|
|
168
|
+
| `test_p2_mcp` | MCP 协议端到端(含权限/摄取) | **29/29** |
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 九、下一步(OS 化剩余项)
|
|
173
|
+
|
|
174
|
+
1. **单一权威存储**:AEIS 私有记忆迁移 —— **暂缓**(开源仓库不能承载私有内容;
|
|
175
|
+
须等私有租户根(仓库外)就绪后再做)。
|
|
176
|
+
2. **常驻服务**:会话/心跳/自愈(当前 MCP 进程已常驻,缺心跳与重启策略)。
|
|
177
|
+
3. **更多驱动**:视觉/语音产出接入(`sources.py` 已是可插拔,加 Source 即可)。
|
|
178
|
+
|
package/package.json
CHANGED
|
@@ -1,77 +1,93 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@furongjun1999/dsh-memory",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "灵枢(Lingshu·líng shū)DeepSeek Harness 插件:完整大脑——长期记忆/知识飞轮/自我认知/递归反思接入 DSH,对话自动沉淀进记忆库",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"types": "lib/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./lib/index.d.ts",
|
|
11
|
-
"import": "./lib/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"lib",
|
|
16
|
-
"src",
|
|
17
|
-
"README.md",
|
|
18
|
-
"cordis.yml.example",
|
|
19
|
-
"cordis.patch.yml",
|
|
20
|
-
"docs"
|
|
21
|
-
],
|
|
22
|
-
"keywords": [
|
|
23
|
-
"deepseek",
|
|
24
|
-
"dsh",
|
|
25
|
-
"dsh-plugin",
|
|
26
|
-
"cordis",
|
|
27
|
-
"memory",
|
|
28
|
-
"agent",
|
|
29
|
-
"aeis",
|
|
30
|
-
"lingshu",
|
|
31
|
-
"multi-agent",
|
|
32
|
-
"spatiotemporal",
|
|
33
|
-
"knowledge-graph"
|
|
34
|
-
],
|
|
35
|
-
"license": "MIT",
|
|
36
|
-
"
|
|
37
|
-
"@deepseek-ai/cordis":
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"@deepseek-ai/dsh-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"@deepseek-ai/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"@deepseek-ai/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@furongjun1999/dsh-memory",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"description": "灵枢(Lingshu·líng shū)DeepSeek Harness 插件:完整大脑——长期记忆/知识飞轮/自我认知/递归反思接入 DSH,对话自动沉淀进记忆库",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"src",
|
|
17
|
+
"README.md",
|
|
18
|
+
"cordis.yml.example",
|
|
19
|
+
"cordis.patch.yml",
|
|
20
|
+
"docs"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"deepseek",
|
|
24
|
+
"dsh",
|
|
25
|
+
"dsh-plugin",
|
|
26
|
+
"cordis",
|
|
27
|
+
"memory",
|
|
28
|
+
"agent",
|
|
29
|
+
"aeis",
|
|
30
|
+
"lingshu",
|
|
31
|
+
"multi-agent",
|
|
32
|
+
"spatiotemporal",
|
|
33
|
+
"knowledge-graph"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"@deepseek-ai/cordis": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"@deepseek-ai/dsh-llm": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"@deepseek-ai/dsh-session": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@deepseek-ai/dsh-system-prompt": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@deepseek-ai/dsh-tools": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@deepseek-ai/schemastery": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@deepseek-ai/cordis": ">=4.0.1",
|
|
58
|
+
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6",
|
|
59
|
+
"@deepseek-ai/dsh-session": ">=0.1.0-rc.6",
|
|
60
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.6",
|
|
61
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.6",
|
|
62
|
+
"@deepseek-ai/schemastery": ">=3.0.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
66
|
+
"@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
|
|
67
|
+
"@deepseek-ai/dsh-session": "^0.1.0-rc.6",
|
|
68
|
+
"@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
|
|
69
|
+
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
|
|
70
|
+
"@deepseek-ai/schemastery": "^3.0.0",
|
|
71
|
+
"@types/node": "^24.0.0",
|
|
72
|
+
"tsx": "^4.19.0",
|
|
73
|
+
"typescript": "^5.5.0"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsc -p tsconfig.json",
|
|
77
|
+
"test": "npm run build && node --import tsx --test \"test/*.test.ts\"",
|
|
78
|
+
"prepare": "npm run build",
|
|
79
|
+
"prepublishOnly": "npm run build && npm test"
|
|
80
|
+
},
|
|
81
|
+
"repository": {
|
|
82
|
+
"type": "git",
|
|
83
|
+
"url": "https://github.com/FuRongJun-1999/dsh-memory.git"
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=22.19"
|
|
87
|
+
},
|
|
88
|
+
"dsh": {
|
|
89
|
+
"bundle": {
|
|
90
|
+
"patch": "./cordis.patch.yml"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|