smart_brain 0.1.2 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/MEMPAL_GUIDE.md +1074 -0
- data/README.en.md +173 -173
- data/README.md +467 -173
- data/config/brain.yml +69 -1
- data/conversation_demo.rb +438 -438
- data/db/migrate/002_turn_events_payload.sql +9 -0
- data/db/migrate/003_tiers_and_lifecycle.sql +28 -0
- data/db/migrate/004_kg_edges.sql +30 -0
- data/db/migrate/005_domains_and_memory_scopes.sql +163 -0
- data/docs/coding_todo.md +139 -0
- data/docs/context_package.md +220 -0
- data/docs/evidence_pack.md +190 -0
- data/docs/gap_vs_mempal.md +161 -0
- data/docs/mcp.md +93 -0
- data/docs/memory_types.md +278 -0
- data/docs/multi_scope_memory_refactor_plan.md +483 -0
- data/docs/multi_scope_migration.md +65 -0
- data/docs/policies.md +308 -0
- data/docs/retrieval_plan.md +231 -0
- data/docs/smartbrain_design.md +299 -0
- data/docs/user_guide.md +546 -0
- data/example.rb +91 -91
- data/examples/01_memory_basic.rb +57 -0
- data/examples/02_governance.rb +63 -0
- data/examples/03_postgres_persistence.rb +63 -0
- data/examples/04_ollama_llm.rb +69 -0
- data/examples/05_smart_rag_integration.rb +79 -0
- data/examples/06_multi_scope_memory.rb +50 -0
- data/examples/README.md +49 -0
- data/exe/smart_brain +168 -0
- data/lib/smart_brain/adapters/smart_rag/direct_client.rb +16 -5
- data/lib/smart_brain/adapters/smart_rag/http_client.rb +16 -5
- data/lib/smart_brain/adapters/smart_rag/null_client.rb +7 -2
- data/lib/smart_brain/adapters/smart_rag/scope_filter.rb +60 -0
- data/lib/smart_brain/configuration.rb +57 -0
- data/lib/smart_brain/consolidator/working_summary.rb +80 -12
- data/lib/smart_brain/context_composer/composer.rb +40 -3
- data/lib/smart_brain/contracts/retrieval_plan.rb +10 -0
- data/lib/smart_brain/contracts/scope_context.rb +46 -0
- data/lib/smart_brain/contracts/scope_ref.rb +25 -0
- data/lib/smart_brain/db.rb +109 -0
- data/lib/smart_brain/event_store/in_memory.rb +6 -2
- data/lib/smart_brain/event_store/postgres.rb +199 -0
- data/lib/smart_brain/fusion/merger.rb +31 -2
- data/lib/smart_brain/governance/briefing.rb +146 -0
- data/lib/smart_brain/governance/fact_check.rb +110 -0
- data/lib/smart_brain/governance/knowledge_graph.rb +60 -0
- data/lib/smart_brain/governance/lifecycle.rb +225 -0
- data/lib/smart_brain/governance/tiers.rb +60 -0
- data/lib/smart_brain/memory_extractor/extractor.rb +25 -7
- data/lib/smart_brain/memory_store/in_memory.rb +202 -17
- data/lib/smart_brain/memory_store/postgres.rb +500 -0
- data/lib/smart_brain/model_provider/base.rb +87 -0
- data/lib/smart_brain/model_provider/factory.rb +49 -0
- data/lib/smart_brain/model_provider/ollama.rb +60 -0
- data/lib/smart_brain/model_provider/openai.rb +60 -0
- data/lib/smart_brain/model_provider/stub.rb +26 -0
- data/lib/smart_brain/model_provider.rb +7 -0
- data/lib/smart_brain/observability/tracker.rb +39 -1
- data/lib/smart_brain/retrievers/exact_retriever.rb +6 -0
- data/lib/smart_brain/retrievers/memory_retriever.rb +59 -5
- data/lib/smart_brain/runtime.rb +288 -16
- data/lib/smart_brain/scopes/conflict_resolver.rb +67 -0
- data/lib/smart_brain/scopes/registry.rb +133 -0
- data/lib/smart_brain/scopes/resolver.rb +32 -0
- data/lib/smart_brain/server/http_app.rb +143 -0
- data/lib/smart_brain/server/mcp_server.rb +385 -0
- data/lib/smart_brain/server/service.rb +129 -0
- data/lib/smart_brain/support/levenshtein.rb +35 -0
- data/lib/smart_brain/version.rb +5 -5
- data/lib/smart_brain.rb +80 -35
- metadata +88 -36
data/MEMPAL_GUIDE.md
ADDED
|
@@ -0,0 +1,1074 @@
|
|
|
1
|
+
# mempal 完整使用指南
|
|
2
|
+
|
|
3
|
+
> 版本:v0.9.0 | 2026-07-09
|
|
4
|
+
> `cargo install mempal` — 单二进制项目记忆工具,让任何 coding agent 在 10 秒内带出处找回历史决策。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 目录
|
|
9
|
+
|
|
10
|
+
1. [核心概念](#1-核心概念)
|
|
11
|
+
2. [安装](#2-安装)
|
|
12
|
+
3. [配置](#3-配置)
|
|
13
|
+
4. [CLI 命令速查表](#4-cli-命令速查表)
|
|
14
|
+
5. [快速入门 5 分钟](#5-快速入门-5-分钟)
|
|
15
|
+
6. [核心 CLI 工作流](#6-核心-cli-工作流)
|
|
16
|
+
7. [知识生命周期(Knowledge Lifecycle)](#7-知识生命周期knowledge-lifecycle)
|
|
17
|
+
8. [Phase-2 Knowledge Card](#8-phase-2-knowledge-card)
|
|
18
|
+
9. [Phase-3 自进化(Self-Evolution)](#9-phase-3-自进化self-evolution)
|
|
19
|
+
10. [MCP Server 与工具](#10-mcp-server-与工具)
|
|
20
|
+
11. [多 Agent 协作(Cowork)](#11-多-agent-协作cowork)
|
|
21
|
+
12. [Agent Diary](#12-agent-diary)
|
|
22
|
+
13. [知识图谱(Knowledge Graph)](#13-知识图谱knowledge-graph)
|
|
23
|
+
14. [AAAK 输出格式化](#14-aaak-输出格式化)
|
|
24
|
+
15. [事实核查(Fact Check)](#15-事实核查fact-check)
|
|
25
|
+
16. [Auto-Dream 集成](#16-auto-dream-集成)
|
|
26
|
+
17. [开发命令](#17-开发命令)
|
|
27
|
+
18. [MEMORY_PROTOCOL](#18-memory_protocol)
|
|
28
|
+
19. [FAQ](#19-faq)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 1. 核心概念
|
|
33
|
+
|
|
34
|
+
在 mempal 中有四个核心名词:
|
|
35
|
+
|
|
36
|
+
- **wing**:顶级作用域,通常是一个项目或知识域(如 `mempal`、`myapp`)
|
|
37
|
+
- **room**:wing 内的子作用域,由目录结构推断或通过 taxonomy 编辑
|
|
38
|
+
- **drawer**:一条存储的记忆项或文本块
|
|
39
|
+
- **source_file**:drawer 来源文件(相对路径,保持引用稳定)
|
|
40
|
+
|
|
41
|
+
### 记忆分层(Mind Model)
|
|
42
|
+
|
|
43
|
+
| Tier | 含义 | 说明 |
|
|
44
|
+
|------|------|------|
|
|
45
|
+
| `dao_tian` | 天道 | 最高层,不可变的根本规律/原则(默认注入 budget=1) |
|
|
46
|
+
| `dao_ren` | 人道 | 经验规则、最佳实践、架构决策 |
|
|
47
|
+
| `shu` | 术 | 特定工具/库/框架的使用技巧 |
|
|
48
|
+
| `qi` | 器 | 具体代码示例、配置片段 |
|
|
49
|
+
| `evidence` | 证据 | 原始记忆,未经提炼的观察记录 |
|
|
50
|
+
|
|
51
|
+
### 锚点(Anchor)
|
|
52
|
+
|
|
53
|
+
记忆的作用范围:`worktree` → `repo` → `global`
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 2. 安装
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 基础安装
|
|
61
|
+
cargo install mempal --version 0.9.0 --locked
|
|
62
|
+
|
|
63
|
+
# 带 REST API 支持
|
|
64
|
+
cargo install mempal --version 0.9.0 --locked --features rest
|
|
65
|
+
|
|
66
|
+
# 开发模式
|
|
67
|
+
cargo run -- --help
|
|
68
|
+
cargo run --features rest -- serve --help
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
数据全部存储在 `~/.mempal/palace.db`(SQLite + sqlite-vec 单一文件)。
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 3. 配置
|
|
76
|
+
|
|
77
|
+
配置文件路径:`~/.mempal/config.toml`
|
|
78
|
+
|
|
79
|
+
### 默认配置(model2vec 后端)
|
|
80
|
+
|
|
81
|
+
```toml
|
|
82
|
+
db_path = "~/.mempal/palace.db"
|
|
83
|
+
|
|
84
|
+
[embed]
|
|
85
|
+
backend = "model2vec"
|
|
86
|
+
# model = "minishlab/potion-multilingual-128M" # 默认多语言模型,256 维
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### ONNX 后端
|
|
90
|
+
|
|
91
|
+
```toml
|
|
92
|
+
[embed]
|
|
93
|
+
backend = "onnx"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 外部 API 后端(如 Ollama)
|
|
97
|
+
|
|
98
|
+
```toml
|
|
99
|
+
[embed]
|
|
100
|
+
backend = "api"
|
|
101
|
+
api_endpoint = "http://localhost:11434/api/embeddings"
|
|
102
|
+
api_model = "nomic-embed-text"
|
|
103
|
+
dimensions = 768
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Feature Flag
|
|
107
|
+
|
|
108
|
+
| Feature | 作用 |
|
|
109
|
+
|---------|------|
|
|
110
|
+
| `model2vec`(默认) | model2vec-rs 本地嵌入,零原生依赖 |
|
|
111
|
+
| `onnx` | ONNX Runtime,更高精度 |
|
|
112
|
+
| `rest` | 启用 REST API 服务器 |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 4. CLI 命令速查表
|
|
117
|
+
|
|
118
|
+
### 4.1 基础操作
|
|
119
|
+
|
|
120
|
+
| 命令 | 用途 |
|
|
121
|
+
|------|------|
|
|
122
|
+
| `mempal status` | 显示 schema 版本、drawer 数量、triple 数、wing/room 分布 |
|
|
123
|
+
| `mempal doctor` | 诊断 binary/PATH/schema 兼容性 |
|
|
124
|
+
| `mempal release-readiness` | 检查发布准备状态(package/docs/spec/runbook 等) |
|
|
125
|
+
|
|
126
|
+
### 4.2 项目初始化与导入
|
|
127
|
+
|
|
128
|
+
| 命令 | 用途 |
|
|
129
|
+
|------|------|
|
|
130
|
+
| `mempal init <DIR> [--dry-run] [--ignore-file PATH] [--no-gitignore] [--no-mempalignore]` | 推断 wing 名,生成初始 taxonomy rooms |
|
|
131
|
+
| `mempal ingest --wing <WING> <DIR> [--dry-run] [--room ROOM] [--format FORMAT] [--no-strip-noise] [--diary-rollup]` | 分块、嵌入、存储整个项目目录树 |
|
|
132
|
+
| `mempal ingest <FILE> --wing <WING>` | 导入单文件到指定 wing |
|
|
133
|
+
|
|
134
|
+
**忽略规则**:默认尊重 `.gitignore` 和 `.mempalignore`,可禁用 `--no-gitignore` / `--no-mempalignore`,用 `--ignore-file PATH` 添加自定义忽略文件。`.git/`、`target/`、`node_modules/` 始终硬跳过。
|
|
135
|
+
|
|
136
|
+
**支持的格式**(自动检测):
|
|
137
|
+
- Claude Code JSONL
|
|
138
|
+
- ChatGPT JSON
|
|
139
|
+
- Codex CLI JSONL
|
|
140
|
+
- Slack DM JSON
|
|
141
|
+
- 纯文本(fallback)
|
|
142
|
+
|
|
143
|
+
### 4.3 搜索与上下文
|
|
144
|
+
|
|
145
|
+
| 命令 | 用途 |
|
|
146
|
+
|------|------|
|
|
147
|
+
| `mempal search <QUERY> [--wing W] [--room R] [--top-k N] [--json] [--memory-kind evidence\|knowledge] [--field F] [--tier T] [--status S] [--anchor-kind K] [--with-neighbors]` | 混合搜索(BM25 + 向量 + RRF)+ tunnel hints |
|
|
148
|
+
| `mempal context <QUERY> [--field F] [--domain D] [--cwd DIR] [--include-evidence] [--include-cards] [--max-items N] [--dao-tian-limit N] [--format json]` | 按 `dao_tian → dao_ren → shu → qi` 组装 mind-model context;默认 `dao_tian_limit=1` |
|
|
149
|
+
| `mempal brief <QUERY> [--field F] [--domain D] [--cwd DIR] [--max-items N]` | 生成确定性 citation-first 认知要点(summary/key facts/evidence/cards/uncertainty/next actions) |
|
|
150
|
+
| `mempal wake-up [--format aaak]` | L0/L1 重要性排序唤醒刷新 |
|
|
151
|
+
|
|
152
|
+
### 4.4 跨项目管理
|
|
153
|
+
|
|
154
|
+
| 命令 | 用途 |
|
|
155
|
+
|------|------|
|
|
156
|
+
| `mempal projects [--format json]` | 列出所有已知项目(wing + worktree + 计数 + 最近活动) |
|
|
157
|
+
| `mempal resume <FUZZY> [--format json] [--evidence-limit N] [--candidate-limit N]` | 模糊匹配项目名并返回路径 + 最近决策 + 下一步 |
|
|
158
|
+
|
|
159
|
+
### 4.5 知识图谱(KG)
|
|
160
|
+
|
|
161
|
+
| 命令 | 用途 |
|
|
162
|
+
|------|------|
|
|
163
|
+
| `mempal kg add <Subject> <Predicate> <Object> [--source-drawer ID]` | 添加三元组 |
|
|
164
|
+
| `mempal kg query [--subject S] [--predicate P] [--object O] [--all]` | 查询三元组 |
|
|
165
|
+
| `mempal kg timeline <ENTITY>` | 某实体的时间线视图 |
|
|
166
|
+
| `mempal kg stats` | KG 统计 |
|
|
167
|
+
| `mempal kg list` | 列出所有三元组 |
|
|
168
|
+
|
|
169
|
+
### 4.6 知识生命周期(Stage-1)
|
|
170
|
+
|
|
171
|
+
| 命令 | 用途 |
|
|
172
|
+
|------|------|
|
|
173
|
+
| `mempal knowledge policy [--format json]` | 查看 promotion 阈值表 |
|
|
174
|
+
| `mempal knowledge gate <ID> [--target-status S] [--reviewer R] [--format json]` | 只读评估 knowledge drawer 是否满足 promotion 门槛 |
|
|
175
|
+
| `mempal knowledge distill --statement S --content C --tier dao_ren\|qi --supporting-ref IDs [--domain D] [--field F] [--dry-run]` | 从 evidence refs 创建 candidate knowledge drawer |
|
|
176
|
+
| `mempal knowledge promote <ID> --status promoted --verification-ref IDs --reason R [--reviewer R]` | gate-enforced 提升 knowledge drawer |
|
|
177
|
+
| `mempal knowledge demote <ID> --status demoted --evidence-ref IDs --reason R --reason-type contradicted\|obsolete\|superseded` | 降级/退役 knowledge drawer |
|
|
178
|
+
| `mempal knowledge publish-anchor <ID> --to repo\|global --reason R [--target-anchor-id ID] [--cwd DIR] [--reviewer R]` | 显式 outward anchor publication(worktree→repo→global) |
|
|
179
|
+
|
|
180
|
+
### 4.7 Knowledge Card(Phase-2)
|
|
181
|
+
|
|
182
|
+
| 命令 | 用途 |
|
|
183
|
+
|------|------|
|
|
184
|
+
| `mempal knowledge-card create --statement S --content C --tier T [--id ID] [--status S] [--domain D] [--field F] [--cwd DIR]` | 创建 knowledge card |
|
|
185
|
+
| `mempal knowledge-card get <CARD_ID>` | 获取单个 card |
|
|
186
|
+
| `mempal knowledge-card list [--tier T] [--status S] [--domain D] [--field F] [--anchor-kind K] [--anchor-id ID]` | 列出 cards |
|
|
187
|
+
| `mempal knowledge-card retrieve <QUERY> [--domain D] [--field F] [--cwd DIR] [--top-k N] [--evidence-top-k N]` | 通过 linked evidence 检索 cards |
|
|
188
|
+
| `mempal knowledge-card link <CARD_ID> <EVIDENCE_DRAWER_ID> --role supports\|contradicts\|teaches [--note N]` | 链接 evidence 到 card |
|
|
189
|
+
| `mempal knowledge-card event <CARD_ID> --type TYPE --reason R [--from-status S] [--to-status S] [--actor A]` | 追加 lifecycle event |
|
|
190
|
+
| `mempal knowledge-card events <CARD_ID>` | 查看 card 的 events 历史 |
|
|
191
|
+
| `mempal knowledge-card gate <CARD_ID> [--target-status S] [--reviewer R]` | card promotion readiness 评估 |
|
|
192
|
+
| `mempal knowledge-card promote <CARD_ID> --status S --verification-ref IDs --reason R [--reviewer R] [--allow-counterexamples] [--enforce-gate\|--no-enforce-gate]` | gate-enforced card promotion |
|
|
193
|
+
| `mempal knowledge-card demote <CARD_ID> --status S --evidence-ref IDs --reason R --reason-type TYPE` | evidence-backed card demotion |
|
|
194
|
+
| `mempal knowledge-card backfill-plan [--tier T] [--status S] [--domain D] [--field F]` | Stage-1 drawer → Phase-2 card 回填预览(dry-run) |
|
|
195
|
+
| `mempal knowledge-card backfill-apply [--tier T] [--status S] [--domain D] [--field F] [--execute]` | 显式执行回填(默认 dry-run,加 `--execute` 写入) |
|
|
196
|
+
|
|
197
|
+
### 4.8 Phase-3 自进化
|
|
198
|
+
|
|
199
|
+
#### 4.8.1 Runtime Adoption Evidence
|
|
200
|
+
|
|
201
|
+
| 命令 | 用途 |
|
|
202
|
+
|------|------|
|
|
203
|
+
| `mempal phase3 adoption guidance` | 查看 recording 语义指南 |
|
|
204
|
+
| `mempal phase3 adoption instrumentation-policy` | 查看只读 instrumentation opt-in 边界 |
|
|
205
|
+
| `mempal phase3 adoption prepare-record --track T --signal S --feature F [--query Q] [--context-hash H] [--card-id ID] [--note N]` | 只读生成 record 命令与 payload |
|
|
206
|
+
| `mempal phase3 adoption capture --surface S --outcome O --track T --signal S --feature F [--query Q] [--card-id ID] [--note N] [--execute]` | 显式 capture surface/outcome → checked runtime adoption record |
|
|
207
|
+
| `mempal phase3 adoption check-record --track T --signal S --feature F [--query Q] [--card-id ID] [--metadata-json JSON]` | 只读检查 record 质量 |
|
|
208
|
+
| `mempal phase3 adoption record-checked --track T --signal S --feature F [--query Q] [--card-id ID] [--allow-warnings]` | 质量门控写入 runtime adoption evidence |
|
|
209
|
+
| `mempal phase3 adoption wrap --track T --signal S --feature F [--execute] [--allow-warnings] <COMMAND>` | 包裹一次 child command,自动 capture adoption evidence |
|
|
210
|
+
| `mempal phase3 adoption record --track T --signal S --feature F [--query Q] [--card-id ID] [--note N] [--metadata-json JSON]` | 直接写入 runtime adoption event |
|
|
211
|
+
| `mempal phase3 adoption list [--track T] [--feature F] [--limit N]` | 列出 adoption events |
|
|
212
|
+
| `mempal phase3 adoption stats [--track T] [--feature F]` | 按 track+feature 汇总 adoption 统计 |
|
|
213
|
+
| `mempal phase3 adoption review [--track T] [--feature F] [--signal S] [--limit N]` | 只读汇总 adoption evidence 审查报告 |
|
|
214
|
+
| `mempal phase3 adoption analytics` | 按 track+feature 汇总 runtime adoption analytics |
|
|
215
|
+
|
|
216
|
+
#### 4.8.2 Card Context Default
|
|
217
|
+
|
|
218
|
+
| 命令 | 用途 |
|
|
219
|
+
|------|------|
|
|
220
|
+
| `mempal phase3 gate card-context` | 只读检查 card context 默认开启条件 |
|
|
221
|
+
| `mempal phase3 readiness card-context` | 只读判断 `include_cards` 是否具备未来默认开启资格 |
|
|
222
|
+
| `mempal phase3 default-proposal card-context --rollback-criterion C1 [--rollback-criterion C2 ...]` | 只读生成默认开启提案,不改默认值 |
|
|
223
|
+
| `mempal phase3 default-control card-context --enable [--rollback-criterion C]` | proposal-gated 启用 card context 默认 |
|
|
224
|
+
| `mempal phase3 default-control card-context --disable [--rollback-criterion C]` | 可逆禁用 card context 默认 |
|
|
225
|
+
| `mempal phase3 rollback-control card-context [--execute]` | 将 rollback evidence 转为可执行的默认关闭策略 |
|
|
226
|
+
|
|
227
|
+
#### 4.8.3 Evaluator Advisory
|
|
228
|
+
|
|
229
|
+
| 命令 | 用途 |
|
|
230
|
+
|------|------|
|
|
231
|
+
| `mempal phase3 evaluator advise --evaluator-id ID --subject-kind KIND --subject-id ID --proposed-action ACTION --evidence-ref IDs [--counterexample-ref IDs] [--risk-note NOTES] [--note N]` | advisory-only 评估建议,不具备 lifecycle authority |
|
|
232
|
+
|
|
233
|
+
#### 4.8.4 Research Adapter
|
|
234
|
+
|
|
235
|
+
| 命令 | 用途 |
|
|
236
|
+
|------|------|
|
|
237
|
+
| `mempal phase3 research-validate-plan <PATH>` | 验证外部 research report contract |
|
|
238
|
+
| `mempal phase3 research-ingest-plan <PATH> [--execute]` | 把 research findings 写入 evidence(默认 dry-run) |
|
|
239
|
+
|
|
240
|
+
### 4.9 Cowork 多 Agent 协作
|
|
241
|
+
|
|
242
|
+
#### 4.9.1 基础 Cowork
|
|
243
|
+
|
|
244
|
+
| 命令 | 用途 |
|
|
245
|
+
|------|------|
|
|
246
|
+
| `mempal cowork-drain --target claude\|codex --cwd DIR [--format plain\|codex-hook-json]` | 排空 inbox 消息(用于 hook 自动交付) |
|
|
247
|
+
| `mempal cowork-drain --target claude\|codex --cwd-source stdin-json [--format codex-hook-json]` | Codex 侧通过 stdin JSON 获取 cwd 的 drain 方式 |
|
|
248
|
+
| `mempal cowork-status --cwd DIR` | 查看 inbox 状态(只读,不排空) |
|
|
249
|
+
| `mempal cowork-runbook` | 打印多 agent 协作操作手册 |
|
|
250
|
+
| `mempal cowork-install-hooks [--global-codex]` | 安装 Claude+Codex UserPromptSubmit hooks |
|
|
251
|
+
|
|
252
|
+
#### 4.9.2 Multi-Agent Bus
|
|
253
|
+
|
|
254
|
+
| 命令 | 用途 |
|
|
255
|
+
|------|------|
|
|
256
|
+
| `mempal cowork-register --agent-id ID --tool claude\|codex --cwd DIR [--transport inbox\|tmux] [--tmux-target TARGET]` | 注册 concrete agent 实例 |
|
|
257
|
+
| `mempal cowork-send --from A --to B --cwd DIR --message M [--thread-id TID] [--channel CH]` | 向一个 agent 发送消息 |
|
|
258
|
+
| `mempal cowork-broadcast --from A --to B1 --to B2 --cwd DIR --message M [--thread-id TID] [--channel CH]` | 向多个 agent 广播消息 |
|
|
259
|
+
| `mempal cowork-agent-drain --agent-id ID --cwd DIR [--format plain\|codex-hook-json]` | 排空特定 agent 的 bus inbox |
|
|
260
|
+
| `mempal cowork-agents --cwd DIR [--now ISO]` | 列出已注册 agent(含 presence 状态) |
|
|
261
|
+
| `mempal cowork-events --cwd DIR [--limit N]` | 回放 append-only bus event log |
|
|
262
|
+
| `mempal cowork-ack --agent-id ID --cwd DIR --message-id MID` | 确认一条 delivery 消息 |
|
|
263
|
+
| `mempal cowork-deliveries --agent-id ID --cwd DIR [--pending\|--all]` | 查看 delivery 状态 |
|
|
264
|
+
| `mempal cowork-channel-set --cwd DIR --channel NAME --agent-id ID [--agent-id ID2 ...] [--remove\|--add]` | 管理 channel membership |
|
|
265
|
+
| `mempal cowork-channels --cwd DIR` | 列出所有 channels |
|
|
266
|
+
| `mempal cowork-channel-send --from A --cwd DIR --channel NAME --message M [--thread-id TID]` | 向 channel 所有成员发送 |
|
|
267
|
+
| `mempal cowork-tmux-peek --agent-id ID --cwd DIR [--lines N]` | tmux live pane 只读捕获 |
|
|
268
|
+
| `mempal cowork-heartbeat --agent-id ID --cwd DIR` | 更新 agent 心跳(presence) |
|
|
269
|
+
| `mempal cowork-peek --tool claude\|codex --cwd DIR [--limit N] [--since ISO] [--format json]` | 读 partner agent 的 LIVE session(无 tmux) |
|
|
270
|
+
| `mempal cowork-doctor --cwd DIR [--now ISO] [--probe-tmux]` | 只读诊断 registry/presence/deliveries/sessions/channels |
|
|
271
|
+
| `mempal cowork-session-create --cwd DIR --session-id ID --title T [--goal G] --agent A1 --agent A2 [--channel C] [--thread-id TID]` | 创建 team session |
|
|
272
|
+
| `mempal cowork-sessions --cwd DIR` | 列出 team sessions |
|
|
273
|
+
| `mempal cowork-session-status --cwd DIR --session-id ID --status active\|paused\|closed` | 更新 session 状态 |
|
|
274
|
+
| `mempal cowork-session-close --cwd DIR --session-id ID [--capture] [--execute]` | 关闭 session,可选 capture handoff |
|
|
275
|
+
| `mempal cowork-handoff --cwd DIR [--thread-id TID] [--channel CH] [--session-id SID] [--limit N]` | 生成 multi-agent handoff summary |
|
|
276
|
+
| `mempal cowork-capture --cwd DIR [--summary-source S] [--wing W] [--room R] [--thread-id TID] [--session-id SID] [--note N] [--execute]` | 显式 capture cowork handoff → evidence |
|
|
277
|
+
|
|
278
|
+
### 4.10 维护命令
|
|
279
|
+
|
|
280
|
+
| 命令 | 用途 |
|
|
281
|
+
|------|------|
|
|
282
|
+
| `mempal maintenance-runbook` | 打印维护操作手册 |
|
|
283
|
+
| `mempal maintenance guided-run` | 只读输出 dream/maintenance 推荐命令与状态计数 |
|
|
284
|
+
| `mempal delete <DRAWER_ID>` | 软删除(可逆直到 purge) |
|
|
285
|
+
| `mempal purge [--before ISO]` | 永久移除软删除的 drawers |
|
|
286
|
+
| `mempal reindex [--stale] [--force] [--dry-run]` | 切换模型/维度后重新嵌入 |
|
|
287
|
+
| `mempal compress <TEXT>` | 将任意文本格式化为 AAAK |
|
|
288
|
+
| `mempal taxonomy list` | 查看当前路由关键词 |
|
|
289
|
+
| `mempal taxonomy edit <WING> <ROOM> --keywords K1,K2` | 调整路由行为 |
|
|
290
|
+
| `mempal field-taxonomy [--format json]` | 查看 recommended field 值 |
|
|
291
|
+
| `mempal tunnels` | 发现跨 wing 共享 room |
|
|
292
|
+
| `mempal tunnels add --left W1 --right W2 --label L` | 显式添加跨 wing 链接 |
|
|
293
|
+
| `mempal tunnels delete <ID>` | 删除 tunnel |
|
|
294
|
+
| `mempal tunnels follow --from W [--hops N]` | 沿 tunnel 链遍历 |
|
|
295
|
+
|
|
296
|
+
### 4.11 服务与基准测试
|
|
297
|
+
|
|
298
|
+
| 命令 | 用途 |
|
|
299
|
+
|------|------|
|
|
300
|
+
| `mempal serve --mcp` | 通过 stdio 运行 MCP 服务器 |
|
|
301
|
+
| `mempal fact-check [PATH\|-] [--wing W] [--room R] [--now ISO]` | 离线矛盾检测(读文件或 stdin) |
|
|
302
|
+
| `mempal bench longmemeval <DATA_FILE> [--mode raw\|aaak\|rooms] [--granularity session\|turn] [--limit N] [--top-k N] [--out FILE]` | 运行 LongMemEval 检索基准测试 |
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## 5. 快速入门 5 分钟
|
|
307
|
+
|
|
308
|
+
### 5.1 推断并写入 taxonomy
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# 预览
|
|
312
|
+
mempal init ~/code/myapp --dry-run
|
|
313
|
+
|
|
314
|
+
# 写入
|
|
315
|
+
mempal init ~/code/myapp
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 5.2 预览导入
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
mempal ingest ~/code/myapp --wing myapp --dry-run
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 5.3 导入项目
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
mempal ingest ~/code/myapp --wing myapp
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### 5.4 搜索
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
mempal search "auth decision clerk"
|
|
334
|
+
mempal search "database decision" --wing myapp --json
|
|
335
|
+
mempal search "token refresh bug" --wing myapp --room auth
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### 5.5 生成上下文
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
mempal wake-up
|
|
342
|
+
mempal context "how to handle auth" --include-evidence
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 6. 核心 CLI 工作流
|
|
348
|
+
|
|
349
|
+
### 6.1 Search 搜索
|
|
350
|
+
|
|
351
|
+
搜索结果包含:
|
|
352
|
+
- `drawer_id`、`content`、`wing`、`room`、`source_file`、`similarity`、`route`
|
|
353
|
+
- 结构化 signals:`entities`、`topics`、`flags`、`emotions`、`importance_stars`
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
# JSON 结构化输出
|
|
357
|
+
mempal search "auth decision" --json
|
|
358
|
+
|
|
359
|
+
# 带邻居 chunk
|
|
360
|
+
mempal search "bug fix" --with-neighbors
|
|
361
|
+
|
|
362
|
+
# 过滤 memory kind
|
|
363
|
+
mempal search "pattern" --memory-kind knowledge
|
|
364
|
+
|
|
365
|
+
# 按 field/domain/tier 过滤
|
|
366
|
+
mempal search "architecture" --field architecture --tier dao_ren --anchor-kind repo
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**检索架构**:
|
|
370
|
+
```
|
|
371
|
+
query → BM25 (FTS5) → Vector (sqlite-vec) → RRF Fusion (k=60) → Wing/Room filter → Tunnel hints
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### 6.2 Context 上下文组装
|
|
375
|
+
|
|
376
|
+
`mempal context` 按 mind-model 层级组装运行指导:
|
|
377
|
+
|
|
378
|
+
```
|
|
379
|
+
dao_tian → dao_ren → shu → qi → evidence(可选)
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
# 基础 context(dao_tian 默认最多 1 条)
|
|
384
|
+
mempal context "how to handle auth"
|
|
385
|
+
|
|
386
|
+
# 包含 evidence
|
|
387
|
+
mempal context "migration pattern" --include-evidence
|
|
388
|
+
|
|
389
|
+
# 包含 knowledge cards
|
|
390
|
+
mempal context "architecture" --include-cards
|
|
391
|
+
|
|
392
|
+
# 提高 dao_tian 预算
|
|
393
|
+
mempal context "core principles" --dao-tian-limit 3
|
|
394
|
+
|
|
395
|
+
# JSON 输出
|
|
396
|
+
mempal context "auth pattern" --format json --max-items 20
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 6.3 Brief 认知要点
|
|
400
|
+
|
|
401
|
+
`mempal brief` 生成确定性 citation-first 认知要点,不调用 LLM、不写 DB:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
mempal brief "current project state"
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
输出:summary / key_facts / evidence / cards / entities / unresolved / uncertainty / next_actions
|
|
408
|
+
|
|
409
|
+
### 6.4 跨项目管理
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# 列出所有项目
|
|
413
|
+
mempal projects
|
|
414
|
+
mempal projects --format json
|
|
415
|
+
|
|
416
|
+
# 模糊 resume 项目
|
|
417
|
+
mempal resume mempal
|
|
418
|
+
mempal resume "my app" --evidence-limit 3 --format json
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### 6.5 删除与清理
|
|
422
|
+
|
|
423
|
+
```bash
|
|
424
|
+
# 软删除
|
|
425
|
+
mempal delete drawer_xxx
|
|
426
|
+
|
|
427
|
+
# 永久清理
|
|
428
|
+
mempal purge
|
|
429
|
+
mempal purge --before 2026-04-10T00:00:00Z
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### 6.6 Taxonomy 管理
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
# 查看
|
|
436
|
+
mempal taxonomy list
|
|
437
|
+
|
|
438
|
+
# 编辑关键词(改善路由精度)
|
|
439
|
+
mempal taxonomy edit myapp deploy --keywords "render,railway,postgres,migration"
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## 7. 知识生命周期(Knowledge Lifecycle)
|
|
445
|
+
|
|
446
|
+
Stage-1 knowledge drawer 的生命周期流程:
|
|
447
|
+
|
|
448
|
+
```
|
|
449
|
+
evidence → distill (candidate) → gate (检查门槛) → promote (active) → demote/retire
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### 7.1 查看策略
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
mempal knowledge policy --format json
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### 7.2 蒸馏(Distill)
|
|
459
|
+
|
|
460
|
+
从 evidence drawers 创建候选 knowledge:
|
|
461
|
+
|
|
462
|
+
```bash
|
|
463
|
+
mempal knowledge distill \
|
|
464
|
+
--statement "Prefer evidence before asserting project facts" \
|
|
465
|
+
--content "When answering project-specific questions, cite source-backed memory." \
|
|
466
|
+
--tier dao_ren \
|
|
467
|
+
--supporting-ref drawer_evidence_1 \
|
|
468
|
+
--supporting-ref drawer_evidence_2 \
|
|
469
|
+
--field architecture \
|
|
470
|
+
--importance 3 \
|
|
471
|
+
--dry-run
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
- 只能创建 `dao_ren` 或 `qi` 的 candidate
|
|
475
|
+
- `dao_tian` 和 `shu` 不开放 candidate 状态
|
|
476
|
+
|
|
477
|
+
### 7.3 Gate(门槛检查)
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
mempal knowledge gate drawer_knowledge --format json
|
|
481
|
+
mempal knowledge gate drawer_dao_tian --target-status canonical --reviewer human --format json
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### 7.4 Promote(提升)
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
mempal knowledge promote drawer_knowledge \
|
|
488
|
+
--status promoted \
|
|
489
|
+
--verification-ref drawer_evidence_1 \
|
|
490
|
+
--reason "validated across repeated runs" \
|
|
491
|
+
--reviewer "human"
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### 7.5 Demote(降级)
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
mempal knowledge demote drawer_knowledge \
|
|
498
|
+
--status demoted \
|
|
499
|
+
--evidence-ref drawer_counterexample \
|
|
500
|
+
--reason "new evidence contradicts this" \
|
|
501
|
+
--reason-type contradicted
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 7.6 Anchor Publication(锚点发布)
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
mempal knowledge publish-anchor drawer_knowledge \
|
|
508
|
+
--to repo \
|
|
509
|
+
--reason "stable across this repository"
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## 8. Phase-2 Knowledge Card
|
|
515
|
+
|
|
516
|
+
Knowledge Card 是 Phase-2 的治理层,通过 `knowledge_cards` 表 + `knowledge_evidence_links`(role-separated)+ `knowledge_events`(append-only)提供更细粒度的知识治理。
|
|
517
|
+
|
|
518
|
+
### 8.1 创建 Card
|
|
519
|
+
|
|
520
|
+
```bash
|
|
521
|
+
mempal knowledge-card create \
|
|
522
|
+
--statement "Always check repo docs before writing infra code" \
|
|
523
|
+
--content "When writing infrastructure code for this project..." \
|
|
524
|
+
--tier dao_ren \
|
|
525
|
+
--status candidate \
|
|
526
|
+
--field infrastructure
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
### 8.2 链接 Evidence
|
|
530
|
+
|
|
531
|
+
```bash
|
|
532
|
+
mempal knowledge-card link card_xxx drawer_evidence_1 --role supports --note "confirms the rule"
|
|
533
|
+
mempal knowledge-card link card_xxx drawer_counter --role contradicts
|
|
534
|
+
mempal knowledge-card link card_xxx drawer_lesson --role teaches
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### 8.3 Gate → Promote/Demote
|
|
538
|
+
|
|
539
|
+
```bash
|
|
540
|
+
# 查看门槛
|
|
541
|
+
mempal knowledge-card gate card_xxx --target-status promoted --format json
|
|
542
|
+
|
|
543
|
+
# 提升(gate-enforced)
|
|
544
|
+
mempal knowledge-card promote card_xxx \
|
|
545
|
+
--status promoted \
|
|
546
|
+
--verification-ref drawer_evidence_1 \
|
|
547
|
+
--reason "proven across 10+ sessions"
|
|
548
|
+
|
|
549
|
+
# 降级
|
|
550
|
+
mempal knowledge-card demote card_xxx \
|
|
551
|
+
--status demoted \
|
|
552
|
+
--evidence-ref drawer_counterexample \
|
|
553
|
+
--reason "new evidence contradicts this" \
|
|
554
|
+
--reason-type contradicted
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### 8.4 检索 Card
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
mempal knowledge-card retrieve "infrastructure rules" --top-k 5 --format json
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
检索通过 linked evidence 反向查找 active cards,不改默认 search 行为。
|
|
564
|
+
|
|
565
|
+
### 8.5 回填(Backfill)
|
|
566
|
+
|
|
567
|
+
将 Stage-1 knowledge drawers 迁移到 Phase-2 cards:
|
|
568
|
+
|
|
569
|
+
```bash
|
|
570
|
+
# 预览
|
|
571
|
+
mempal knowledge-card backfill-plan --tier dao_ren --status promoted
|
|
572
|
+
mempal knowledge-card backfill-plan --field architecture --format json
|
|
573
|
+
|
|
574
|
+
# 执行
|
|
575
|
+
mempal knowledge-card backfill-apply --tier dao_ren --status promoted --execute
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## 9. Phase-3 自进化(Self-Evolution)
|
|
581
|
+
|
|
582
|
+
Phase-3 是 mempal 的自进化基础设施,关注 **runtime adoption evidence** —— 即记录哪些 features 在生产中被接受/拒绝/遗漏/回滚。
|
|
583
|
+
|
|
584
|
+
### 9.1 Recording 语义
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
# 查看 guidance
|
|
588
|
+
mempal phase3 adoption guidance
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
四种 signal 类型:
|
|
592
|
+
- `used`:agent 使用了这个 feature
|
|
593
|
+
- `accepted`:agent 接受了输出(区别于 used)
|
|
594
|
+
- `rejected`:agent 拒绝了输出
|
|
595
|
+
- `miss`:应该出现但没有出现
|
|
596
|
+
- `rollback`:需要回滚
|
|
597
|
+
|
|
598
|
+
### 9.2 准备记录
|
|
599
|
+
|
|
600
|
+
```bash
|
|
601
|
+
# 只读生成 record 命令
|
|
602
|
+
mempal phase3 adoption prepare-record \
|
|
603
|
+
--track context \
|
|
604
|
+
--signal used \
|
|
605
|
+
--feature include_cards \
|
|
606
|
+
--query "architecture" \
|
|
607
|
+
--card-id card_xxx
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### 9.3 Capture 记录
|
|
611
|
+
|
|
612
|
+
```bash
|
|
613
|
+
# 显式 capture
|
|
614
|
+
mempal phase3 adoption capture \
|
|
615
|
+
--surface "mempal_context" \
|
|
616
|
+
--outcome "accepted" \
|
|
617
|
+
--track context \
|
|
618
|
+
--signal accepted \
|
|
619
|
+
--feature include_cards \
|
|
620
|
+
--query "auth pattern" \
|
|
621
|
+
--execute
|
|
622
|
+
|
|
623
|
+
# 检查质量
|
|
624
|
+
mempal phase3 adoption check-record \
|
|
625
|
+
--track context \
|
|
626
|
+
--signal accepted \
|
|
627
|
+
--feature include_cards
|
|
628
|
+
|
|
629
|
+
# 质量门控写入
|
|
630
|
+
mempal phase3 adoption record-checked \
|
|
631
|
+
--track context \
|
|
632
|
+
--signal accepted \
|
|
633
|
+
--feature include_cards
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
### 9.4 Wrap(包装注入)
|
|
637
|
+
|
|
638
|
+
```bash
|
|
639
|
+
# 包裹一次命令执行并自动 capture
|
|
640
|
+
mempal phase3 adoption wrap \
|
|
641
|
+
--track context \
|
|
642
|
+
--signal used \
|
|
643
|
+
--feature include_cards \
|
|
644
|
+
--execute \
|
|
645
|
+
-- mempal context "architecture" --include-cards
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### 9.5 审查与分析
|
|
649
|
+
|
|
650
|
+
```bash
|
|
651
|
+
# 列出
|
|
652
|
+
mempal phase3 adoption list --track context --limit 20
|
|
653
|
+
|
|
654
|
+
# 统计
|
|
655
|
+
mempal phase3 adoption stats --feature include_cards
|
|
656
|
+
|
|
657
|
+
# 审查
|
|
658
|
+
mempal phase3 adoption review --track context
|
|
659
|
+
|
|
660
|
+
# 分析
|
|
661
|
+
mempal phase3 adoption analytics
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### 9.6 Card Context 默认开关
|
|
665
|
+
|
|
666
|
+
```bash
|
|
667
|
+
# 检查 readiness
|
|
668
|
+
mempal phase3 readiness card-context
|
|
669
|
+
|
|
670
|
+
# 生成提案
|
|
671
|
+
mempal phase3 default-proposal card-context \
|
|
672
|
+
--rollback-criterion "adoption evidence below threshold"
|
|
673
|
+
|
|
674
|
+
# 启用/禁用
|
|
675
|
+
mempal phase3 default-control card-context --enable
|
|
676
|
+
mempal phase3 default-control card-context --disable
|
|
677
|
+
|
|
678
|
+
# 回滚
|
|
679
|
+
mempal phase3 rollback-control card-context --execute
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
### 9.7 Evaluator Advisory
|
|
683
|
+
|
|
684
|
+
```bash
|
|
685
|
+
mempal phase3 evaluator advise \
|
|
686
|
+
--evaluator-id "evaluator_1" \
|
|
687
|
+
--subject-kind knowledge_card \
|
|
688
|
+
--subject-id card_xxx \
|
|
689
|
+
--proposed-action promote \
|
|
690
|
+
--evidence-ref drawer_evidence_1 \
|
|
691
|
+
--risk-note "insufficient counterexamples" \
|
|
692
|
+
--note "review before promotion"
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### 9.8 Research Adapter
|
|
696
|
+
|
|
697
|
+
```bash
|
|
698
|
+
# 验证外部 research report
|
|
699
|
+
mempal phase3 research-validate-plan /path/to/report.json
|
|
700
|
+
|
|
701
|
+
# 预览或执行 research evidence ingest
|
|
702
|
+
mempal phase3 research-ingest-plan /path/to/report.json
|
|
703
|
+
mempal phase3 research-ingest-plan /path/to/report.json --execute
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
---
|
|
707
|
+
|
|
708
|
+
## 10. MCP Server 与工具
|
|
709
|
+
|
|
710
|
+
### 10.1 启动
|
|
711
|
+
|
|
712
|
+
```bash
|
|
713
|
+
mempal serve --mcp
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
### 10.2 MCP 工具完整列表(26 个)
|
|
717
|
+
|
|
718
|
+
| # | 工具名 | 类型 | 用途 |
|
|
719
|
+
|---|--------|------|------|
|
|
720
|
+
| 1 | `mempal_status` | 只读 | schema 版本、drawer 计数、triple 统计、各 wing/room 分布、MEMORY_PROTOCOL |
|
|
721
|
+
| 2 | `mempal_doctor` | 只读 | binary/PATH/schema 兼容性诊断 + MCP tool/action 能力清单 |
|
|
722
|
+
| 3 | `mempal_search` | 只读 | BM25+向量+RRF 混合检索,返回结构化 signals(entities/topics/flags/emotions/importance_stars)+ tunnel hints |
|
|
723
|
+
| 4 | `mempal_context` | 只读 | mind-model context:`dao_tian → dao_ren → shu → qi`,默认 `dao_tian_limit=1`,支持 `include_evidence`/`include_cards` |
|
|
724
|
+
| 5 | `mempal_brief` | 只读 | deterministic citation-first 认知要点(不调用 LLM、不写 DB) |
|
|
725
|
+
| 6 | `mempal_field_taxonomy` | 只读 | recommended field 值列表(guidance only) |
|
|
726
|
+
| 7 | `mempal_knowledge_distill` | 写 | 从 evidence refs 创建 candidate knowledge drawer |
|
|
727
|
+
| 8 | `mempal_knowledge_policy` | 只读 | Stage-1 promotion 阈值表 |
|
|
728
|
+
| 9 | `mempal_knowledge_gate` | 只读 | 评估 knowledge drawer 是否满足 promotion 门槛 |
|
|
729
|
+
| 10 | `mempal_knowledge_promote` | 写 | gate-enforced knowledge promotion |
|
|
730
|
+
| 11 | `mempal_knowledge_demote` | 写 | evidence-backed knowledge demotion |
|
|
731
|
+
| 12 | `mempal_knowledge_publish_anchor` | 写 | metadata-only outward anchor publication |
|
|
732
|
+
| 13 | `mempal_knowledge_cards` | 读写 | Phase-2 card list/get/events/gate/promote/demote/retrieve |
|
|
733
|
+
| 14 | `mempal_phase3` | 读写 | Phase-3 adoption: guidance/prepare_record/capture/check_record/record_checked/review/readiness/analytics/record/list/stats/gate/research_validate_plan/research_ingest_plan/evaluator_advise/default_proposal/instrumentation_policy |
|
|
734
|
+
| 15 | `mempal_ingest` | 写 | 存储记忆(支持 `dry_run`,暴露 `lock_wait_ms`) |
|
|
735
|
+
| 16 | `mempal_delete` | 写 | 软删除 + audit |
|
|
736
|
+
| 17 | `mempal_taxonomy` | 读写 | 路由关键词管理 |
|
|
737
|
+
| 18 | `mempal_kg` | 读写 | 知识图谱:add/query/invalidate/timeline/stats |
|
|
738
|
+
| 19 | `mempal_tunnels` | 读写 | 跨 wing 链接发现与管理 |
|
|
739
|
+
| 20 | `mempal_projects` | 只读 | 列出所有项目(wing + worktree + 计数 + 最近活动) |
|
|
740
|
+
| 21 | `mempal_resume` | 只读 | 模糊匹配项目名并返回路径 + 最近决策 + 下一步 |
|
|
741
|
+
| 22 | `mempal_peek_partner` | 只读 | 读 partner agent live session(可选 `cwd` 跨项目) |
|
|
742
|
+
| 23 | `mempal_session_peek` | 只读 | 按 `tool + cwd` 显式读 session(同工具/跨项目) |
|
|
743
|
+
| 24 | `mempal_cowork_push` | 写 | 投递 ephemeral handoff → partner inbox |
|
|
744
|
+
| 25 | `mempal_cowork_bus` | 读写 | 多 agent bus: register/list/send/broadcast/drain/events/deliveries/ack/heartbeat/channel_set/channel_list/channel_send/tmux_peek/doctor/session_create/session_list/session_status/session_close/handoff/capture |
|
|
745
|
+
| 26 | `mempal_fact_check` | 只读 | 离线矛盾检测(SimilarNameConflict/RelationContradiction/StaleFact) |
|
|
746
|
+
|
|
747
|
+
### 10.3 常用 MCP 请求示例
|
|
748
|
+
|
|
749
|
+
**搜索**:
|
|
750
|
+
```json
|
|
751
|
+
{
|
|
752
|
+
"query": "auth decision clerk",
|
|
753
|
+
"wing": "myapp",
|
|
754
|
+
"top_k": 5
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
**存储**:
|
|
759
|
+
```json
|
|
760
|
+
{
|
|
761
|
+
"content": "decided to use Clerk for auth",
|
|
762
|
+
"wing": "myapp",
|
|
763
|
+
"room": "auth",
|
|
764
|
+
"source": "/repo/README.md"
|
|
765
|
+
}
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
**预览(dry_run)**:
|
|
769
|
+
```json
|
|
770
|
+
{
|
|
771
|
+
"content": "decided to use Clerk for auth",
|
|
772
|
+
"wing": "myapp",
|
|
773
|
+
"dry_run": true
|
|
774
|
+
}
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
**删除**:
|
|
778
|
+
```json
|
|
779
|
+
{
|
|
780
|
+
"drawer_id": "drawer_myapp_auth_1234abcd"
|
|
781
|
+
}
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
**Cowork Push**:
|
|
785
|
+
```json
|
|
786
|
+
{
|
|
787
|
+
"target_tool": "codex",
|
|
788
|
+
"cwd": "/path/to/project",
|
|
789
|
+
"message": "I've finished the auth refactor. Next: remove old Auth0 code."
|
|
790
|
+
}
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
### 10.4 MEMORY_PROTOCOL
|
|
794
|
+
|
|
795
|
+
MCP 服务器在 `initialize.instructions` 字段中嵌入全部 MEMORY_PROTOCOL,任何 MCP 客户端连接时自动学习工作流——零配置。协议包含 18 条规则(Rule 0-17),覆盖搜索纪律、context vs wake-up 边界、ingest 入口点、知识生命周期、cowork 通信等。
|
|
796
|
+
|
|
797
|
+
---
|
|
798
|
+
|
|
799
|
+
## 11. 多 Agent 协作(Cowork)
|
|
800
|
+
|
|
801
|
+
### 11.1 核心原语
|
|
802
|
+
|
|
803
|
+
mempal 提供三个层次的 cowork:
|
|
804
|
+
|
|
805
|
+
1. **Legacy Cowork(P6/P8)**:`mempal_peek_partner` + `mempal_cowork_push`,Claude ↔ Codex 双 agent
|
|
806
|
+
2. **Multi-Agent Bus(P84-P90)**:`mempal_cowork_bus`,多 agent concrete `agent_id` 总线
|
|
807
|
+
3. **Team Sessions(P94-P96)**:session create/list/status/close + handoff + capture
|
|
808
|
+
|
|
809
|
+
### 11.2 安装 Hooks
|
|
810
|
+
|
|
811
|
+
```bash
|
|
812
|
+
mempal cowork-install-hooks --global-codex
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
这写入:
|
|
816
|
+
- `.claude/hooks/user-prompt-submit.sh` + `.claude/settings.json` 对应条目
|
|
817
|
+
- `~/.codex/hooks.json`(需要 `codex features enable codex_hooks`)
|
|
818
|
+
|
|
819
|
+
> **注意**:Codex 侧需要重启 TUI 才能识别新 hooks 配置。
|
|
820
|
+
|
|
821
|
+
### 11.3 Legacy Cowork 流
|
|
822
|
+
|
|
823
|
+
```bash
|
|
824
|
+
# Claude 查看 Codex 在干什么
|
|
825
|
+
mempal cowork-peek --tool codex --cwd "$PWD"
|
|
826
|
+
|
|
827
|
+
# Claude 向 Codex 推送消息
|
|
828
|
+
mempal cowork-send --from claude --to codex --cwd "$PWD" --message "done with auth"
|
|
829
|
+
|
|
830
|
+
# Codex 排空 inbox(hook 自动调用)
|
|
831
|
+
mempal cowork-drain --target codex --cwd-source stdin-json --format codex-hook-json
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
### 11.4 Multi-Agent Bus 流
|
|
835
|
+
|
|
836
|
+
```bash
|
|
837
|
+
# 注册 agent
|
|
838
|
+
mempal cowork-register --agent-id claude-main --tool claude --cwd "$PWD" --transport tmux --tmux-target "session:0.0"
|
|
839
|
+
mempal cowork-register --agent-id codex-rev --tool codex --cwd "$PWD" --transport inbox
|
|
840
|
+
|
|
841
|
+
# 发送
|
|
842
|
+
mempal cowork-send --from claude-main --to codex-rev --cwd "$PWD" --message "review PR #42"
|
|
843
|
+
|
|
844
|
+
# 广播
|
|
845
|
+
mempal cowork-broadcast --from claude-main --to codex-rev --to claude-test --cwd "$PWD" --message "urgent: rollback"
|
|
846
|
+
|
|
847
|
+
# Channel 通信
|
|
848
|
+
mempal cowork-channel-set --cwd "$PWD" --channel review --agent-id claude-main --agent-id codex-rev
|
|
849
|
+
mempal cowork-channel-send --from claude-main --cwd "$PWD" --channel review --message "ready for review"
|
|
850
|
+
|
|
851
|
+
# 诊断
|
|
852
|
+
mempal cowork-doctor --cwd "$PWD" --probe-tmux
|
|
853
|
+
|
|
854
|
+
# 心跳
|
|
855
|
+
mempal cowork-heartbeat --agent-id claude-main --cwd "$PWD"
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
### 11.5 Team Session 流
|
|
859
|
+
|
|
860
|
+
```bash
|
|
861
|
+
# 创建 session
|
|
862
|
+
mempal cowork-session-create --cwd "$PWD" \
|
|
863
|
+
--session-id sprint-42 \
|
|
864
|
+
--title "Sprint 42 Auth Migration" \
|
|
865
|
+
--goal "Migrate auth from Auth0 to Clerk" \
|
|
866
|
+
--agent claude-main \
|
|
867
|
+
--agent codex-rev \
|
|
868
|
+
--channel review
|
|
869
|
+
|
|
870
|
+
# 查看 session
|
|
871
|
+
mempal cowork-sessions --cwd "$PWD"
|
|
872
|
+
|
|
873
|
+
# 生成 handoff
|
|
874
|
+
mempal cowork-handoff --cwd "$PWD" --session-id sprint-42
|
|
875
|
+
|
|
876
|
+
# 关闭 session + capture handoff
|
|
877
|
+
mempal cowork-session-close --cwd "$PWD" --session-id sprint-42 --capture --execute
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
### 11.6 已知限制
|
|
881
|
+
|
|
882
|
+
1. **Codex `codex_hooks` feature flag**:需要手动启用 `codex features enable codex_hooks`
|
|
883
|
+
2. **TUI 重启**:Codex/Claude Configuration 缓存,修改后需重启
|
|
884
|
+
3. **MCP server re-spawn**:升级 mempal binary 后重启 Claude Code
|
|
885
|
+
4. **At-next-submit**:push 在 partner 下一次用户 prompt 时才可见,非实时
|
|
886
|
+
5. **Scope**:mempal_cowork_push 仅 Claude ↔ Codex 家族
|
|
887
|
+
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
## 12. Agent Diary
|
|
891
|
+
|
|
892
|
+
Agent Diary 是一种跨 session 行为学习约定,使用已有工具:
|
|
893
|
+
|
|
894
|
+
```bash
|
|
895
|
+
# 写入 diary(通过 MCP mempal_ingest,convention: wing="agent-diary", room=agent-name)
|
|
896
|
+
# 内容前缀:OBSERVATION: / LESSON: / PATTERN:
|
|
897
|
+
|
|
898
|
+
# 搜索 diary
|
|
899
|
+
mempal search "lesson" --wing agent-diary
|
|
900
|
+
mempal search "pattern infrastructure" --wing agent-diary --room claude
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
| 前缀 | 用途 |
|
|
904
|
+
|------|------|
|
|
905
|
+
| `OBSERVATION:` | 事实行为观察 |
|
|
906
|
+
| `LESSON:` | 从错误/成功中提炼的经验 |
|
|
907
|
+
| `PATTERN:` | 跨 session 的重复行为模式 |
|
|
908
|
+
|
|
909
|
+
---
|
|
910
|
+
|
|
911
|
+
## 13. 知识图谱(Knowledge Graph)
|
|
912
|
+
|
|
913
|
+
三元组支持时态有效性(`valid_from`/`valid_to`),可手动失效:
|
|
914
|
+
|
|
915
|
+
```bash
|
|
916
|
+
# 添加
|
|
917
|
+
mempal kg add "Kai" "recommends" "Clerk"
|
|
918
|
+
mempal kg add "Clerk" "replaced" "Auth0" --source-drawer drawer_xxx
|
|
919
|
+
|
|
920
|
+
# 查询
|
|
921
|
+
mempal kg query --subject Kai
|
|
922
|
+
mempal kg query --predicate recommends
|
|
923
|
+
mempal kg query --all
|
|
924
|
+
|
|
925
|
+
# 时间线
|
|
926
|
+
mempal kg timeline "Kai"
|
|
927
|
+
|
|
928
|
+
# 统计
|
|
929
|
+
mempal kg stats
|
|
930
|
+
mempal kg list
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
---
|
|
934
|
+
|
|
935
|
+
## 14. AAAK 输出格式化
|
|
936
|
+
|
|
937
|
+
AAAK 是纯输出侧格式,不影响存储和检索:
|
|
938
|
+
|
|
939
|
+
```bash
|
|
940
|
+
mempal compress "Kai recommended Clerk over Auth0 based on pricing and DX"
|
|
941
|
+
# V1|manual|compress|1744156800|cli
|
|
942
|
+
# 0:KAI+CLK+AUT|kai_clerk_auth0|"Kai recommended Clerk..."|★★★★|determ|DECISION
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
中文支持(jieba-rs POS tagging):
|
|
946
|
+
```bash
|
|
947
|
+
mempal compress "张三推荐Clerk替换Auth0,因为价格更优"
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
---
|
|
951
|
+
|
|
952
|
+
## 15. 事实核查(Fact Check)
|
|
953
|
+
|
|
954
|
+
离线、零 LLM、零网络,检测三种问题:
|
|
955
|
+
|
|
956
|
+
| 问题类型 | 触发条件 |
|
|
957
|
+
|---------|---------|
|
|
958
|
+
| `SimilarNameConflict` | 文本中提到与已知 entity Levenshtein 距离 ≤2 的名字 |
|
|
959
|
+
| `RelationContradiction` | 文本断言与已有 KG triple 冲突 |
|
|
960
|
+
| `StaleFact` | 文本中的 triple 在 KG 中 `valid_to < now` |
|
|
961
|
+
|
|
962
|
+
```bash
|
|
963
|
+
# 检查文件
|
|
964
|
+
mempal fact-check path/to/notes.txt --wing myapp
|
|
965
|
+
|
|
966
|
+
# 检查 stdin
|
|
967
|
+
echo "Kai stopped using Clerk" | mempal fact-check --wing myapp
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
---
|
|
971
|
+
|
|
972
|
+
## 16. Auto-Dream 集成
|
|
973
|
+
|
|
974
|
+
在项目 `CLAUDE.md` 中添加:
|
|
975
|
+
|
|
976
|
+
```markdown
|
|
977
|
+
## Auto-Dream Integration
|
|
978
|
+
|
|
979
|
+
When performing auto-dream or manual dream:
|
|
980
|
+
1. Call mempal_search to verify facts being consolidated
|
|
981
|
+
2. Save high-value insights to mempal (mempal_ingest, importance >= 3)
|
|
982
|
+
3. If MEMORY.md and mempal contradict, trust mempal (has citations)
|
|
983
|
+
4. Write dream summary as agent diary (wing="agent-diary", room="claude")
|
|
984
|
+
5. Check triples for expired relationships to invalidate
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
---
|
|
988
|
+
|
|
989
|
+
## 17. 开发命令
|
|
990
|
+
|
|
991
|
+
```bash
|
|
992
|
+
# 测试
|
|
993
|
+
cargo test --workspace
|
|
994
|
+
cargo test --workspace --all-features
|
|
995
|
+
|
|
996
|
+
# Lint
|
|
997
|
+
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
998
|
+
cargo fmt --all --check
|
|
999
|
+
|
|
1000
|
+
# 重新嵌入
|
|
1001
|
+
mempal reindex
|
|
1002
|
+
mempal reindex --stale
|
|
1003
|
+
mempal reindex --force --dry-run
|
|
1004
|
+
|
|
1005
|
+
# 基准测试
|
|
1006
|
+
mempal bench longmemeval /path/to/longmemeval_s_cleaned.json --limit 20
|
|
1007
|
+
mempal bench longmemeval /path/to/data.json --mode aaak --granularity turn --out results.jsonl
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
1012
|
+
## 18. MEMORY_PROTOCOL
|
|
1013
|
+
|
|
1014
|
+
协议嵌入在 `mempal_status` 和 `mempal wake-up` 的输出中,共 18 条规则(Rule 0-17):
|
|
1015
|
+
|
|
1016
|
+
- **Rule 0**:每 session 先调 `mempal_status` 发现 wings
|
|
1017
|
+
- **Rule 1**:wake-up 是 L0/L1 刷新,不是 typed context
|
|
1018
|
+
- **Rule 2**:搜索优先用 `wing="mempal"` 缩小范围
|
|
1019
|
+
- **Rule 3**:历史决策问题默认 `top_k=2`,不足再放大
|
|
1020
|
+
- **Rule 3a**:非英语 query 翻译为英语
|
|
1021
|
+
- **Rule 4**:每次 commit 后用 `mempal_ingest` 保存决策
|
|
1022
|
+
- **Rule 5**:显式消费结构化 signals(flags/entities/importance_stars)
|
|
1023
|
+
- **Rule 5a**:session 结束写 diary 条目
|
|
1024
|
+
- **Rule 6**:大响应重试更窄范围
|
|
1025
|
+
- **Rule 7**:`content` 是 raw text,不期待 AAAK 格式
|
|
1026
|
+
- **Rule 8**:基于 mempal 结果作答时引用 `drawer_id` 和 `source_file`
|
|
1027
|
+
- **Rule 9**:没找到高信号结果明确说明,不猜测
|
|
1028
|
+
- **Rule 10**:`mempal_context` 用于 workflow/skill/tool 选择(不自动执行)
|
|
1029
|
+
- **Rule 11**:assert entity 关系前运行 `mempal_fact_check`
|
|
1030
|
+
- **Rule 12**:`mempal_ingest` 默认写 evidence,knowledge-only 字段被拒
|
|
1031
|
+
- **Rule 13**:cowork push 用于 transient status update
|
|
1032
|
+
- **Rule 14**:`mempal_peek_partner` 不要 self-peek
|
|
1033
|
+
- **Rule 15**:`mempal_knowledge_distill` 创建 candidate,不自动 promote
|
|
1034
|
+
- **Rule 16**:`mempal_brief` 用于快速认知定位
|
|
1035
|
+
- **Rule 17**:`mempal_phase3` 用于 recording runtime adoption
|
|
1036
|
+
|
|
1037
|
+
---
|
|
1038
|
+
|
|
1039
|
+
## 19. FAQ
|
|
1040
|
+
|
|
1041
|
+
### 搜索结果不对
|
|
1042
|
+
|
|
1043
|
+
- 加 `--wing` 明确范围
|
|
1044
|
+
- 加 `--room` 锁定子系统
|
|
1045
|
+
- 检查 taxonomy:`mempal taxonomy list`
|
|
1046
|
+
- 非英语查询翻译为英语
|
|
1047
|
+
|
|
1048
|
+
### 中文搜索效果差
|
|
1049
|
+
|
|
1050
|
+
翻译为英语查询,或使用 `--wing`/`--room` 缩小范围。
|
|
1051
|
+
|
|
1052
|
+
### 为什么 source_file 是相对路径
|
|
1053
|
+
|
|
1054
|
+
保持引用稳定,无论通过绝对或相对路径导入。
|
|
1055
|
+
|
|
1056
|
+
### 切换嵌入模型后
|
|
1057
|
+
|
|
1058
|
+
运行 `mempal reindex` 重新嵌入所有 drawers。
|
|
1059
|
+
|
|
1060
|
+
### delete 是软删除吗
|
|
1061
|
+
|
|
1062
|
+
是。`mempal delete` 标记软删除,`mempal purge` 永久移除。
|
|
1063
|
+
|
|
1064
|
+
---
|
|
1065
|
+
|
|
1066
|
+
## 参考文档
|
|
1067
|
+
|
|
1068
|
+
- 设计文档:`docs/specs/2026-04-08-mempal-design.md`
|
|
1069
|
+
- 使用指南:`docs/usage.md`
|
|
1070
|
+
- AAAK 方言:`docs/aaak-dialect.md`
|
|
1071
|
+
- Cowork Runbook:`docs/COWORK-RUNBOOK.md`
|
|
1072
|
+
- Maintenance Runbook:`docs/MAINTENANCE-RUNBOOK.md`
|
|
1073
|
+
- 基准测试:`benchmarks/longmemeval_s_summary.md`
|
|
1074
|
+
- 在线书籍:[MemPalace: AI 记忆的第一性原理](https://zhanghandong.github.io/mempalace-book/)
|