kimi-code-memory-mcp-server 0.1.1 → 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.
- package/CHANGELOG.md +28 -1
- package/README.en.md +349 -0
- package/README.md +223 -137
- package/assets/contextFlow.svg +144 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -1
- package/dist/context/wire-context.d.ts +3 -0
- package/dist/context/wire-context.js +20 -50
- package/dist/context/wire-context.js.map +1 -1
- package/dist/dao/constants.d.ts +33 -0
- package/dist/dao/constants.js +17 -0
- package/dist/dao/constants.js.map +1 -0
- package/dist/dao/index-catalog.d.ts +19 -0
- package/dist/dao/index-catalog.js +94 -0
- package/dist/dao/index-catalog.js.map +1 -0
- package/dist/dao/index-reconciler.d.ts +13 -0
- package/dist/dao/index-reconciler.js +162 -0
- package/dist/dao/index-reconciler.js.map +1 -0
- package/dist/dao/index-store.d.ts +31 -0
- package/dist/dao/index-store.js +128 -0
- package/dist/dao/index-store.js.map +1 -0
- package/dist/dao/index.d.ts +12 -31
- package/dist/dao/index.js +50 -404
- package/dist/dao/index.js.map +1 -1
- package/dist/dao/memory-store.js +2 -10
- package/dist/dao/memory-store.js.map +1 -1
- package/dist/dao/memory-tree-renderer.d.ts +22 -0
- package/dist/dao/memory-tree-renderer.js +75 -0
- package/dist/dao/memory-tree-renderer.js.map +1 -0
- package/dist/prompts/index.d.ts +26 -0
- package/dist/prompts/index.js +103 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/refine/adapter.d.ts +6 -0
- package/dist/refine/adapter.js +28 -0
- package/dist/refine/adapter.js.map +1 -0
- package/dist/refine/constants.d.ts +35 -0
- package/dist/refine/constants.js +107 -0
- package/dist/refine/constants.js.map +1 -0
- package/dist/refine/extractor.d.ts +12 -0
- package/dist/refine/extractor.js +122 -0
- package/dist/refine/extractor.js.map +1 -0
- package/dist/refine/store.d.ts +23 -0
- package/dist/refine/store.js +153 -0
- package/dist/refine/store.js.map +1 -0
- package/dist/refine/types.d.ts +56 -0
- package/dist/refine/types.js +5 -0
- package/dist/refine/types.js.map +1 -0
- package/dist/refined-manager.d.ts +14 -56
- package/dist/refined-manager.js +27 -341
- package/dist/refined-manager.js.map +1 -1
- package/dist/resources/index.d.ts +15 -0
- package/dist/resources/index.js +134 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/server.js +46 -2
- package/dist/server.js.map +1 -1
- package/dist/theme-manager.d.ts +1 -0
- package/dist/theme-manager.js +7 -0
- package/dist/theme-manager.js.map +1 -1
- package/dist/tools/context-tools.d.ts +16 -51
- package/dist/tools/context-tools.js +303 -55
- package/dist/tools/context-tools.js.map +1 -1
- package/dist/tools/index.d.ts +5 -827
- package/dist/tools/index.js +23 -354
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/memory-tools.d.ts +4 -60
- package/dist/tools/memory-tools.js +129 -79
- package/dist/tools/memory-tools.js.map +1 -1
- package/dist/tools/system-tools.d.ts +3 -34
- package/dist/tools/system-tools.js +110 -33
- package/dist/tools/system-tools.js.map +1 -1
- package/dist/tools/theme-tools.d.ts +3 -31
- package/dist/tools/theme-tools.js +101 -22
- package/dist/tools/theme-tools.js.map +1 -1
- package/dist/tools/types.d.ts +21 -0
- package/dist/tools/types.js +13 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/types.d.ts +11 -2
- package/dist/utils/action-entities.d.ts +16 -0
- package/dist/utils/action-entities.js +35 -0
- package/dist/utils/action-entities.js.map +1 -0
- package/dist/utils/date.d.ts +11 -0
- package/dist/utils/date.js +13 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/file-helpers.d.ts +10 -0
- package/dist/utils/file-helpers.js +28 -0
- package/dist/utils/file-helpers.js.map +1 -0
- package/dist/utils/headings.d.ts +5 -0
- package/dist/utils/headings.js +21 -0
- package/dist/utils/headings.js.map +1 -0
- package/dist/utils/search.d.ts +17 -0
- package/dist/utils/search.js +60 -0
- package/dist/utils/search.js.map +1 -0
- package/dist/utils/tools.d.ts +5 -0
- package/dist/utils/tools.js +10 -0
- package/dist/utils/tools.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vis/api.d.ts +117 -0
- package/dist/vis/api.js +426 -0
- package/dist/vis/api.js.map +1 -0
- package/dist/vis/auto-start.d.ts +12 -0
- package/dist/vis/auto-start.js +87 -0
- package/dist/vis/auto-start.js.map +1 -0
- package/dist/vis/server.d.ts +14 -0
- package/dist/vis/server.js +337 -0
- package/dist/vis/server.js.map +1 -0
- package/dist/vis/static/api.js +57 -0
- package/dist/vis/static/app.js +1468 -0
- package/dist/vis/static/index.html +25 -0
- package/dist/vis/static/state.js +26 -0
- package/dist/vis/static/style.css +1553 -0
- package/dist/vis/static/utils/helpers.js +94 -0
- package/dist/vis/static/utils/markdown.js +81 -0
- package/dist/vis-cli.d.ts +7 -0
- package/dist/vis-cli.js +140 -0
- package/dist/vis-cli.js.map +1 -0
- package/docs/0.agent-memory-market-research.md +354 -0
- package/docs/1.memory-system-proposal-for-kimi-code.md +688 -0
- package/docs/2.memory-architecture-overview.md +417 -0
- package/docs/3.memory-skill-prompt-design.md +430 -0
- package/docs/4.kimi-code-native-evolution-roadmap.md +559 -0
- package/docs/5.decision-guard-design-notes.md +500 -0
- package/docs/ARCHITECTURE.md +2 -2
- package/docs/design-story.md +350 -0
- package/docs/three-layer-memory-model.md +153 -0
- package/docs/three-layer-memory-model.zh-CN.md +153 -0
- package/package.json +12 -6
- package/README.zh-CN.md +0 -292
package/README.md
CHANGED
|
@@ -1,54 +1,84 @@
|
|
|
1
1
|
# Kimi Code Memory MCP Server
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[English](./README.en.md)
|
|
4
4
|
|
|
5
5
|
[](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/kimi-code-memory-mcp-server)
|
|
6
7
|
[](./LICENSE)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
一个为 [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) 提供跨会话记忆的本地 stdio MCP 服务器。
|
|
9
10
|
|
|
10
|
-
>
|
|
11
|
+
> **注意:** 本包已发布到 npm,包名为 `kimi-code-memory-mcp-server`。你可以直接安装,也可以从源码运行。
|
|
11
12
|
|
|
12
|
-
User-facing memories are stored as plain Markdown files on disk. Refined turn summaries use a local SQLite cache, but no vector database, graph database, or external cloud service is required.
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 特性
|
|
15
15
|
|
|
16
|
-
- **Markdown
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
16
|
+
- **Markdown 优先的记忆** —— 人类可读、适合 git、兼容 LLM。
|
|
17
|
+
- **结构化长期记忆** —— `memory/decisions/`、`memory/knowledge/`、`memory/rules/`、`memory/reference/`。
|
|
18
|
+
- **工作区精要** —— 从 `memory/` 提炼生成的浓缩摘要(≤15 KB)。
|
|
19
|
+
- **跨会话上下文恢复** —— 直接解析 Kimi Code CLI 的 `wire.jsonl`。
|
|
20
|
+
- **主题追溯** —— 将对话轮次和记忆关联到主题,并追踪其演化。
|
|
21
|
+
- **精炼轮次摘要** —— 可在多个主题间共享的轮次级原子摘要。
|
|
22
|
+
- **可重建索引** —— `index.json` 只是缓存,`.md` 文件才是真相来源。
|
|
23
|
+
- **主题与搜索视图删除** —— 支持删除低质量主题或搜索视图,并可选择级联清理其关联的精炼轮次。
|
|
24
|
+
- **可视化仪表盘增强** —— 工作区标题动态显示文件夹名、Markdown 默认只读、轻量级渲染预览、主题/搜索视图删除。
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## 主题追溯
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
传统的上下文管理只关注**纵向**:时间越近越清晰,越久越远越衰减。但这忽略了真实工作的一个核心特征:
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
> **同一个 workspace 中的多次会话,往往不是单一叙事,而是多条主题线交织并行。**
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
例如:
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
- Session A:开发 auth 鉴权
|
|
35
|
+
- Session B:讨论orders数据表的迁移问题
|
|
36
|
+
- Session C:加密RSA+解密BCrypt+验证码CAPTCHA+Cookie
|
|
37
|
+
- Session D:fix sql error bug
|
|
38
|
+
- Session E: 登录Login API设计
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
- Native git diff support
|
|
36
|
-
- No required external database or cloud service
|
|
37
|
-
- Compatibility with any LLM that can read text
|
|
40
|
+
如果只看纵向,这些 session 彼此独立。但如果横向扫描,会发现 A、C、E 都属于"注册登录"这一主题。
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
**主题追溯**就是:把时间线上的每个 turn 看作一个圆柱,圆柱的高度代表该 turn 的计算/思考深度,颜色/标签代表主题。我们甚至可以从kimi code已经压缩归档的上下文中再次挖掘,进行深度横向扫描,把同色圆柱(对话轮turns)找出来,重新建立关联,组成theme并存入记忆。当我们三周以后准备升级的我们的“注册登录”模块,或者修复某个bug的时候,不是对着已经压缩过无数次上下文的agent,重新描述对其当时的设计思路和方案,而是你的agent说:“刚刚通过trace_theme("注册登录")这个主题,发现根据3周前的设计决策和中间经历的2次调整改进,现在的问题我们应该用方案B。”
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
>下图展示了 `kimi-memory` 如何看待对话历史:竖条是时间轴上的 turn,粗横线是簇,灰框是 session,彩色括号把跨 session 的相关 turns / clusters 串联成主题线。
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+

|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
下面是一段真实的 Kimi Code CLI 会话动图,使用 `kimi-memory`。用户先后要求总结 MCP 记忆服务器的演进历史、以及 E2E 测试工具的演进历史;Agent 跨会话召回相关记忆与对话 turns,并生成结构化总结。
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
相关工具:`tag_theme`、`trace_theme`、`list_themes`、`search_context`、`refine_session_turns`、`load_turn_context`。
|
|
53
|
+
|
|
54
|
+
## 为什么用 Markdown?
|
|
55
|
+
|
|
56
|
+
大多数 Agent 记忆系统默认使用向量数据库。这在模糊检索场景有效,但也让记忆变得不透明、难以审计、难以版本控制。
|
|
57
|
+
|
|
58
|
+
本项目从相反的假设出发:
|
|
59
|
+
|
|
60
|
+
> 记忆在存储之前应该经过**判断、结构化,并由用户拥有**。
|
|
61
|
+
|
|
62
|
+
Markdown + YAML frontmatter 带来:
|
|
63
|
+
|
|
64
|
+
- 完全可读、可编辑
|
|
65
|
+
- 原生支持 git diff
|
|
66
|
+
- 无需外部数据库或云服务
|
|
67
|
+
- 兼容任何能读取文本的 LLM
|
|
68
|
+
|
|
69
|
+
设计 rationale 见 [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)。
|
|
70
|
+
|
|
71
|
+
## 安装
|
|
72
|
+
|
|
73
|
+
需要 Node.js ≥ 18。
|
|
74
|
+
|
|
75
|
+
### 从 npm 安装(推荐)
|
|
46
76
|
|
|
47
77
|
```bash
|
|
48
78
|
npm install -g kimi-code-memory-mcp-server
|
|
49
79
|
```
|
|
50
80
|
|
|
51
|
-
###
|
|
81
|
+
### 从源码安装
|
|
52
82
|
|
|
53
83
|
```bash
|
|
54
84
|
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
@@ -57,38 +87,38 @@ npm install
|
|
|
57
87
|
npm run build
|
|
58
88
|
```
|
|
59
89
|
|
|
60
|
-
##
|
|
90
|
+
## 快速配置(推荐)
|
|
61
91
|
|
|
62
|
-
|
|
92
|
+
从 npm 安装后,运行 setup 命令自动配置 Kimi Code CLI:
|
|
63
93
|
|
|
64
94
|
```bash
|
|
65
95
|
npx kimi-memory-setup
|
|
66
96
|
```
|
|
67
97
|
|
|
68
|
-
|
|
98
|
+
它会完成:
|
|
69
99
|
|
|
70
|
-
1.
|
|
71
|
-
2.
|
|
72
|
-
3.
|
|
73
|
-
4.
|
|
100
|
+
1. 检测 `~/.kimi-code` 目录。
|
|
101
|
+
2. 在 `~/.kimi-code/AGENTS.md` 顶部注入记忆协议规则。
|
|
102
|
+
3. 将 `memory-manage` Skill 安装到 `~/.kimi-code/skills/memory-manage`。
|
|
103
|
+
4. 在 `~/.kimi-code/mcp.json` 中添加 `kimi-memory` MCP 服务器配置。
|
|
74
104
|
|
|
75
|
-
|
|
105
|
+
预览变更而不写入文件:
|
|
76
106
|
|
|
77
107
|
```bash
|
|
78
108
|
npx kimi-memory-setup --dry-run
|
|
79
109
|
```
|
|
80
110
|
|
|
81
|
-
|
|
111
|
+
后续如需移除注入的配置:
|
|
82
112
|
|
|
83
113
|
```bash
|
|
84
114
|
npx kimi-memory-setup --undo
|
|
85
115
|
```
|
|
86
116
|
|
|
87
|
-
##
|
|
117
|
+
## 配置 Kimi Code CLI(手动)
|
|
88
118
|
|
|
89
|
-
|
|
119
|
+
如果你希望手动配置,编辑 `~/.kimi-code/mcp.json` 并添加服务器。
|
|
90
120
|
|
|
91
|
-
|
|
121
|
+
如果你用 `npm install -g` 安装,使用全局 `node_modules` 中 `dist/server.js` 的绝对路径:
|
|
92
122
|
|
|
93
123
|
```json
|
|
94
124
|
{
|
|
@@ -102,7 +132,7 @@ If you installed from npm with `-g`, use the absolute path to `dist/server.js` i
|
|
|
102
132
|
}
|
|
103
133
|
```
|
|
104
134
|
|
|
105
|
-
|
|
135
|
+
或者直接通过 `npx` 运行(无需安装):
|
|
106
136
|
|
|
107
137
|
```json
|
|
108
138
|
{
|
|
@@ -116,7 +146,7 @@ Or run it directly via `npx` (no install required):
|
|
|
116
146
|
}
|
|
117
147
|
```
|
|
118
148
|
|
|
119
|
-
|
|
149
|
+
如果你从源码构建,指向本地 `dist/server.js`:
|
|
120
150
|
|
|
121
151
|
```json
|
|
122
152
|
{
|
|
@@ -130,109 +160,164 @@ If you built from source, point to your local `dist/server.js`:
|
|
|
130
160
|
}
|
|
131
161
|
```
|
|
132
162
|
|
|
133
|
-
|
|
163
|
+
服务器名称 **`kimi-memory`** 很重要,因为本仓库自带的 `AGENTS.md` 规则以 `mcp__kimi-memory__*` 形式调用工具(例如 `mcp__kimi-memory__bootstrap_workspace`)。
|
|
134
164
|
|
|
135
|
-
|
|
165
|
+
重启 Kimi Code CLI 以加载该服务器。
|
|
136
166
|
|
|
137
|
-
##
|
|
167
|
+
## 可选:安装用户级 AGENTS.md 启动钩子
|
|
138
168
|
|
|
139
|
-
|
|
169
|
+
如需每次会话启动时自动恢复记忆并应用行为规范,将本仓库自带的 `AGENTS.md` 复制到 Kimi Code 用户目录:
|
|
140
170
|
|
|
141
171
|
```bash
|
|
142
172
|
cp AGENTS.md ~/.kimi-code/AGENTS.md
|
|
143
173
|
```
|
|
144
174
|
|
|
145
|
-
|
|
175
|
+
这会安装一个启动钩子,让 Kimi Code CLI 在每次会话开始时调用 `bootstrap_workspace`,并遵循记忆分类和决策守卫规则。由于 `AGENTS.md` 会注入到**每个**会话中,它是放置记忆相关行为协议的正确位置。
|
|
146
176
|
|
|
147
|
-
>
|
|
177
|
+
> **注意:** `AGENTS.md` 规则会注入到每个会话中,请只保留与记忆相关的约定,不要包含属于其他 MCP server 的工具偏好。
|
|
148
178
|
>
|
|
149
|
-
>
|
|
179
|
+
> **前提条件:** 必须在 `~/.kimi-code/mcp.json` 中将 MCP 服务器注册为 `kimi-memory`,否则 `AGENTS.md` 中的 `mcp__kimi-memory__*` 调用会失败。
|
|
150
180
|
|
|
151
|
-
##
|
|
181
|
+
## 可选:安装记忆 Skill
|
|
152
182
|
|
|
153
|
-
|
|
183
|
+
本仓库还包含一个轻量 Skill(`skills/memory-manage/SKILL.md`),用于在用户表达记忆相关意图时提醒 Kimi Code CLI 调用记忆工具。
|
|
154
184
|
|
|
155
185
|
```bash
|
|
156
186
|
cp -r skills/memory-manage ~/.kimi-code/skills/memory-manage
|
|
157
187
|
```
|
|
158
188
|
|
|
159
|
-
|
|
189
|
+
该 Skill 本身**不强制**行为,它只是一个调度器。真正的协议(何时 remember、决策守卫等)应配置在 `AGENTS.md` 中。
|
|
160
190
|
|
|
161
|
-
##
|
|
191
|
+
## 快速开始
|
|
162
192
|
|
|
163
|
-
|
|
193
|
+
服务器加载后,Agent 可以自然地调用记忆工具(工具名带有你在 MCP 配置中注册的 server 名称前缀,例如 `mcp__kimi-memory__*`):
|
|
164
194
|
|
|
165
195
|
```text
|
|
166
|
-
|
|
167
|
-
Agent
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
Agent
|
|
171
|
-
[
|
|
172
|
-
→ "
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Agent
|
|
176
|
-
[
|
|
177
|
-
→
|
|
196
|
+
用户:我们用 SQLite 作为缓存层。
|
|
197
|
+
Agent:[调用 mcp__kimi-memory__remember] key=use-sqlite-cache, folder=memory/decisions
|
|
198
|
+
|
|
199
|
+
用户:为什么选 SQLite?
|
|
200
|
+
Agent:[调用 mcp__kimi-memory__search] query=SQLite cache decision
|
|
201
|
+
[调用 mcp__kimi-memory__recall] key=use-sqlite-cache, folder=memory/decisions
|
|
202
|
+
→ "我们选择 SQLite 而不是 Redis,因为……"
|
|
203
|
+
|
|
204
|
+
用户:缓存设计是怎么演化的?
|
|
205
|
+
Agent:[调用 mcp__kimi-memory__tag_theme] theme=cache-design
|
|
206
|
+
[调用 mcp__kimi-memory__trace_theme] theme=cache-design
|
|
207
|
+
→ 展示跨会话的相关轮次和决策
|
|
178
208
|
```
|
|
179
209
|
|
|
180
|
-
##
|
|
210
|
+
## 存储布局
|
|
181
211
|
|
|
182
|
-
|
|
212
|
+
服务器将数据存储在 `~/.kimi-code-memory/<workspace-id>/` 下:
|
|
183
213
|
|
|
184
214
|
```text
|
|
185
215
|
~/.kimi-code-memory/workspace-a1b2c3d4/
|
|
186
|
-
├── index.json # v3-kv
|
|
216
|
+
├── index.json # v3-kv 元数据缓存(可重建)
|
|
187
217
|
├── memory/
|
|
188
|
-
│ ├── decisions/ #
|
|
189
|
-
│ ├── knowledge/ #
|
|
190
|
-
│ ├── rules/ #
|
|
191
|
-
│ └── reference/ #
|
|
218
|
+
│ ├── decisions/ # 架构与产品决策
|
|
219
|
+
│ ├── knowledge/ # 项目相关知识
|
|
220
|
+
│ ├── rules/ # 约定与红线
|
|
221
|
+
│ └── reference/ # 外部参考
|
|
192
222
|
├── essence/
|
|
193
|
-
│ └── essence.md #
|
|
194
|
-
├── notes/ #
|
|
223
|
+
│ └── essence.md # 工作区精要(≤15 KB)
|
|
224
|
+
├── notes/ # 临时速记
|
|
195
225
|
├── themes/
|
|
196
|
-
│ └── my-theme.json # theme -> turn/memory
|
|
226
|
+
│ └── my-theme.json # theme -> turn/memory 引用
|
|
197
227
|
└── refined/
|
|
198
|
-
└── refined.sqlite #
|
|
228
|
+
└── refined.sqlite # 轮次级摘要
|
|
199
229
|
```
|
|
200
230
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
###
|
|
204
|
-
|
|
205
|
-
|
|
|
206
|
-
|
|
207
|
-
| `MEMORY_STORE_ROOT` |
|
|
208
|
-
| `MEMORY_SESSIONS_ROOT` |
|
|
209
|
-
| `KIMI_CODE_HOME` |
|
|
210
|
-
|
|
211
|
-
##
|
|
212
|
-
|
|
213
|
-
|
|
|
214
|
-
|
|
215
|
-
| `remember` |
|
|
216
|
-
| `recall` |
|
|
217
|
-
| `
|
|
218
|
-
| `
|
|
219
|
-
| `
|
|
220
|
-
| `
|
|
221
|
-
| `
|
|
222
|
-
| `
|
|
223
|
-
| `
|
|
224
|
-
| `
|
|
225
|
-
| `
|
|
226
|
-
| `
|
|
227
|
-
| `
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
| `
|
|
231
|
-
| `
|
|
232
|
-
| `
|
|
233
|
-
| `
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
可通过 `MEMORY_STORE_ROOT` 环境变量覆盖存储根目录。
|
|
232
|
+
|
|
233
|
+
### 环境变量
|
|
234
|
+
|
|
235
|
+
| 变量 | 用途 |
|
|
236
|
+
|------|------|
|
|
237
|
+
| `MEMORY_STORE_ROOT` | 覆盖默认存储根目录 `~/.kimi-code-memory`。 |
|
|
238
|
+
| `MEMORY_SESSIONS_ROOT` | 覆盖默认的 `~/.kimi-code/sessions` 路径,用于发现 `wire.jsonl` 文件。 |
|
|
239
|
+
| `KIMI_CODE_HOME` | `MEMORY_SESSIONS_ROOT` 的替代方案;会话从 `<KIMI_CODE_HOME>/sessions` 读取。 |
|
|
240
|
+
|
|
241
|
+
## 工具列表
|
|
242
|
+
|
|
243
|
+
| 工具 | 用途 |
|
|
244
|
+
|------|------|
|
|
245
|
+
| `remember` | 写入一条 Markdown 记忆 |
|
|
246
|
+
| `recall` | 按 key 读取记忆 |
|
|
247
|
+
| `search` | 在记忆中关键词搜索 |
|
|
248
|
+
| `list` | 列出记忆,支持按 folder / tag 过滤和 limit 限制 |
|
|
249
|
+
| `list_tags` | 列出所有标签 |
|
|
250
|
+
| `delete` | 删除记忆 |
|
|
251
|
+
| `move` | 移动或重命名记忆 |
|
|
252
|
+
| `organize_memories` | 将 `memory/` 提炼为 `essence/essence.md` |
|
|
253
|
+
| `sync_workspace_index` | 从磁盘重建 `index.json` |
|
|
254
|
+
| `bootstrap_workspace` | 加载上下文、精要和记忆树 |
|
|
255
|
+
| `load_workspace_context` | 加载最近对话上下文 |
|
|
256
|
+
| `load_more_context` | 加载更早的对话轮次 |
|
|
257
|
+
| `search_context` | 跨所有会话 wire 搜索 |
|
|
258
|
+
| `load_turn_context` | 加载指定轮次详情 |
|
|
259
|
+
| `tag_theme` | 将轮次或记忆关联到主题 |
|
|
260
|
+
| `trace_theme` | 追溯主题演化 |
|
|
261
|
+
| `list_themes` | 列出主题 |
|
|
262
|
+
| `delete_theme` | 删除主题关联文件 |
|
|
263
|
+
| `list_search_views` | 列出保存的搜索视图 |
|
|
264
|
+
| `delete_search_view` | 删除搜索视图(可选级联删除关联精炼轮次) |
|
|
265
|
+
| `open_memory_dashboard` | 在浏览器中打开记忆仪表盘 |
|
|
266
|
+
| `refine_session_turns` | 生成精炼轮次摘要 |
|
|
267
|
+
|
|
268
|
+
## Prompts
|
|
269
|
+
|
|
270
|
+
本服务器同时提供可复用的 MCP Prompt,供客户端在调用工具前拉取:
|
|
271
|
+
|
|
272
|
+
| Prompt | 用途 |
|
|
273
|
+
|--------|------|
|
|
274
|
+
| `memory-decision-check` | 修改文件前,先检查与其相关的历史决策 |
|
|
275
|
+
| `memory-theme-trace` | 追溯某个主题在多次会话中的演化 |
|
|
276
|
+
| `memory-session-summary` | 总结当前会话,并建议值得挂载的主题 |
|
|
277
|
+
|
|
278
|
+
## Resources
|
|
279
|
+
|
|
280
|
+
本服务器暴露以下 MCP Resource URI,客户端可按需读取:
|
|
281
|
+
|
|
282
|
+
| URI 模式 | 说明 |
|
|
283
|
+
|----------|------|
|
|
284
|
+
| `memory://<folder>/<key>` | 读取 `memory/` 下的某条 Markdown 记忆 |
|
|
285
|
+
| `theme://<theme>` | 读取某个主题的关联摘要(Markdown 格式) |
|
|
286
|
+
| `essence://essence` | 读取工作区精要 `essence/essence.md` |
|
|
287
|
+
|
|
288
|
+
## 可视化仪表盘
|
|
289
|
+
|
|
290
|
+
提供独立的 Web 仪表盘,用于查看工作区记忆、主题时间线和近期决策:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
npx kimi-memory-vis
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
启动后会自动打开浏览器,默认地址 `http://127.0.0.1:58628`。
|
|
297
|
+
|
|
298
|
+
也可以在 MCP 服务器启动时自动启动仪表盘:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
export KIMI_MEMORY_AUTO_VIS=1
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
或者在会话中让 Agent 打开:
|
|
305
|
+
|
|
306
|
+
```json
|
|
307
|
+
{ "name": "open_memory_dashboard" }
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
仪表盘支持:
|
|
311
|
+
|
|
312
|
+
- 工作区概览与 `essence.md` 浏览/编辑(默认只读,点击“编辑”后修改)
|
|
313
|
+
- Markdown 文档轻量级渲染,超长内容自带滚动条
|
|
314
|
+
- 主题时间线浏览与主题删除
|
|
315
|
+
- 搜索视图列表与删除(支持仅删视图或级联清理精炼轮次)
|
|
316
|
+
- 近期决策列表
|
|
317
|
+
- 显式记忆目录浏览
|
|
318
|
+
- 控制面板标题与面包屑根目录显示为用户工作区文件夹名
|
|
319
|
+
|
|
320
|
+
## 开发
|
|
236
321
|
|
|
237
322
|
```bash
|
|
238
323
|
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
@@ -243,50 +328,51 @@ npm test
|
|
|
243
328
|
npm run lint
|
|
244
329
|
```
|
|
245
330
|
|
|
246
|
-
|
|
331
|
+
贡献指南见 [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.zh-CN.md)。
|
|
247
332
|
|
|
248
|
-
##
|
|
333
|
+
## 项目结构
|
|
249
334
|
|
|
250
335
|
```text
|
|
251
336
|
src/
|
|
252
|
-
├── server.ts # MCP
|
|
253
|
-
├── config.ts #
|
|
254
|
-
├── theme-manager.ts #
|
|
255
|
-
├── refined-manager.ts #
|
|
337
|
+
├── server.ts # MCP 服务器入口
|
|
338
|
+
├── config.ts # 默认值与路径
|
|
339
|
+
├── theme-manager.ts # 主题存储
|
|
340
|
+
├── refined-manager.ts # 精炼轮次存储
|
|
256
341
|
├── dao/
|
|
257
|
-
│ ├── index.ts # index.json DAO
|
|
258
|
-
│ └── memory-store.ts # Markdown
|
|
342
|
+
│ ├── index.ts # index.json DAO(v3-kv)
|
|
343
|
+
│ └── memory-store.ts # Markdown 文件操作
|
|
259
344
|
├── context/
|
|
260
|
-
│ └── wire-context.ts # wire.jsonl
|
|
345
|
+
│ └── wire-context.ts # wire.jsonl 解析
|
|
261
346
|
├── tools/
|
|
262
|
-
│ ├── index.ts #
|
|
263
|
-
│ ├── memory-tools.ts #
|
|
264
|
-
│ ├── context-tools.ts #
|
|
265
|
-
│ ├── theme-tools.ts #
|
|
266
|
-
│ └── system-tools.ts #
|
|
347
|
+
│ ├── index.ts # 工具 schema 与分发
|
|
348
|
+
│ ├── memory-tools.ts # 记忆增删改查
|
|
349
|
+
│ ├── context-tools.ts # 上下文恢复
|
|
350
|
+
│ ├── theme-tools.ts # 主题追溯
|
|
351
|
+
│ └── system-tools.ts # 整理/同步/引导
|
|
267
352
|
└── utils/
|
|
268
353
|
├── frontmatter.ts
|
|
269
354
|
├── paths.ts
|
|
270
355
|
└── validation.ts
|
|
271
356
|
```
|
|
272
357
|
|
|
273
|
-
##
|
|
358
|
+
## 路线图
|
|
274
359
|
|
|
275
|
-
- [x]
|
|
360
|
+
- [x] 模块化源码结构
|
|
276
361
|
- [x] ESLint + Prettier
|
|
277
|
-
- [x]
|
|
278
|
-
- [x]
|
|
279
|
-
- [ ]
|
|
280
|
-
- [ ]
|
|
281
|
-
- [ ]
|
|
282
|
-
- [ ]
|
|
362
|
+
- [x] 基础集成测试
|
|
363
|
+
- [x] 上下文/主题工具核心测试覆盖
|
|
364
|
+
- [ ] 可选本地 embedding 搜索
|
|
365
|
+
- [ ] 可选 LLM 精炼轮次
|
|
366
|
+
- [ ] 可插拔 wire 格式适配器
|
|
367
|
+
- [ ] 内存使用 benchmark
|
|
283
368
|
|
|
284
|
-
##
|
|
369
|
+
## 相关文档
|
|
285
370
|
|
|
286
|
-
- [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)
|
|
287
|
-
- [`docs/
|
|
288
|
-
- [`docs/
|
|
371
|
+
- [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) —— 系统设计与数据流
|
|
372
|
+
- [`docs/three-layer-memory-model.zh-CN.md`](./docs/three-layer-memory-model.zh-CN.md) —— 本服务器背后的记忆模型理论
|
|
373
|
+
- [`docs/search-logic.zh-CN.md`](./docs/search-logic.zh-CN.md) —— `search` 与 `search_context` 的实现逻辑
|
|
374
|
+
- [`docs/CONTRIBUTING.zh-CN.md`](./docs/CONTRIBUTING.zh-CN.md) —— 如何贡献
|
|
289
375
|
|
|
290
|
-
##
|
|
376
|
+
## 许可证
|
|
291
377
|
|
|
292
378
|
MIT
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 520" width="900" height="520">
|
|
2
|
+
<defs>
|
|
3
|
+
<style>
|
|
4
|
+
.session-box { fill: #f5f5f5; stroke: #bdbdbd; stroke-width: 2; }
|
|
5
|
+
.timeline { stroke: #212121; stroke-width: 4; stroke-linecap: round; }
|
|
6
|
+
.turn { stroke: none; rx: 2; }
|
|
7
|
+
.cluster { stroke-width: 6; stroke-linecap: round; fill: none; opacity: 0.85; }
|
|
8
|
+
.theme-line { fill: none; stroke-width: 2; }
|
|
9
|
+
.theme-bracket { fill: none; stroke-width: 1.5; }
|
|
10
|
+
.label { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 13px; fill: #424242; }
|
|
11
|
+
.label-small { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 11px; fill: #757575; }
|
|
12
|
+
.theme-label { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 13px; font-weight: 600; }
|
|
13
|
+
.legend-box { rx: 3; }
|
|
14
|
+
</style>
|
|
15
|
+
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
|
16
|
+
<polygon points="0 0, 10 3.5, 0 7" fill="#212121"/>
|
|
17
|
+
</marker>
|
|
18
|
+
</defs>
|
|
19
|
+
|
|
20
|
+
<!-- Background -->
|
|
21
|
+
<rect width="900" height="520" fill="#ffffff"/>
|
|
22
|
+
|
|
23
|
+
<!-- Sessions -->
|
|
24
|
+
<rect class="session-box" x="70" y="220" width="180" height="110" rx="6"/>
|
|
25
|
+
<rect class="session-box" x="265" y="220" width="180" height="110" rx="6"/>
|
|
26
|
+
<rect class="session-box" x="460" y="220" width="180" height="110" rx="6"/>
|
|
27
|
+
<rect class="session-box" x="655" y="220" width="180" height="110" rx="6"/>
|
|
28
|
+
|
|
29
|
+
<!-- Session labels -->
|
|
30
|
+
<text class="label" x="160" y="355" text-anchor="middle">sessionA</text>
|
|
31
|
+
<text class="label" x="355" y="355" text-anchor="middle">sessionB</text>
|
|
32
|
+
<text class="label" x="550" y="355" text-anchor="middle">sessionC</text>
|
|
33
|
+
<text class="label" x="745" y="355" text-anchor="middle">sessionD</text>
|
|
34
|
+
|
|
35
|
+
<!-- Timeline -->
|
|
36
|
+
<line class="timeline" x1="40" y1="300" x2="860" y2="300" marker-end="url(#arrowhead)"/>
|
|
37
|
+
<text class="label" x="870" y="305" text-anchor="start">timeline</text>
|
|
38
|
+
|
|
39
|
+
<!-- ========== Session A turns ========== -->
|
|
40
|
+
<!-- Red turns (themeC) -->
|
|
41
|
+
<rect class="turn" fill="#e53935" x="105" y="265" width="8" height="35"/>
|
|
42
|
+
<rect class="turn" fill="#e53935" x="120" y="255" width="8" height="45"/>
|
|
43
|
+
<rect class="turn" fill="#e53935" x="135" y="270" width="8" height="30"/>
|
|
44
|
+
<!-- Orange turn -->
|
|
45
|
+
<rect class="turn" fill="#fb8c00" x="165" y="275" width="8" height="25"/>
|
|
46
|
+
<!-- Blue turns (themeB) -->
|
|
47
|
+
<rect class="turn" fill="#1e88e5" x="195" y="260" width="8" height="40"/>
|
|
48
|
+
<rect class="turn" fill="#1e88e5" x="210" y="275" width="8" height="25"/>
|
|
49
|
+
<rect class="turn" fill="#1e88e5" x="225" y="280" width="8" height="20"/>
|
|
50
|
+
|
|
51
|
+
<!-- Clusters A -->
|
|
52
|
+
<line class="cluster" stroke="#e53935" x1="100" y1="315" x2="145" y2="315"/>
|
|
53
|
+
<line class="cluster" stroke="#1e88e5" x1="190" y1="315" x2="235" y2="315"/>
|
|
54
|
+
|
|
55
|
+
<!-- ========== Session B turns ========== -->
|
|
56
|
+
<!-- Red turns (themeC) -->
|
|
57
|
+
<rect class="turn" fill="#e53935" x="300" y="270" width="8" height="30"/>
|
|
58
|
+
<rect class="turn" fill="#e53935" x="315" y="255" width="8" height="45"/>
|
|
59
|
+
<rect class="turn" fill="#e53935" x="330" y="265" width="8" height="35"/>
|
|
60
|
+
<!-- Green turn (themeA) -->
|
|
61
|
+
<rect class="turn" fill="#43a047" x="365" y="275" width="8" height="25"/>
|
|
62
|
+
<!-- Blue turns (themeB) -->
|
|
63
|
+
<rect class="turn" fill="#1e88e5" x="395" y="260" width="8" height="40"/>
|
|
64
|
+
<rect class="turn" fill="#1e88e5" x="410" y="250" width="8" height="50"/>
|
|
65
|
+
<rect class="turn" fill="#1e88e5" x="425" y="275" width="8" height="25"/>
|
|
66
|
+
|
|
67
|
+
<!-- Clusters B -->
|
|
68
|
+
<line class="cluster" stroke="#e53935" x1="295" y1="315" x2="340" y2="315"/>
|
|
69
|
+
<line class="cluster" stroke="#1e88e5" x1="390" y1="315" x2="435" y2="315"/>
|
|
70
|
+
|
|
71
|
+
<!-- ========== Session C turns ========== -->
|
|
72
|
+
<!-- Orange turn -->
|
|
73
|
+
<rect class="turn" fill="#fb8c00" x="485" y="280" width="8" height="20"/>
|
|
74
|
+
<!-- Green turns (themeA) -->
|
|
75
|
+
<rect class="turn" fill="#43a047" x="510" y="255" width="8" height="45"/>
|
|
76
|
+
<rect class="turn" fill="#43a047" x="525" y="245" width="8" height="55"/>
|
|
77
|
+
<rect class="turn" fill="#43a047" x="540" y="270" width="8" height="30"/>
|
|
78
|
+
<!-- Red turn (themeC) -->
|
|
79
|
+
<rect class="turn" fill="#e53935" x="575" y="270" width="8" height="30"/>
|
|
80
|
+
<!-- Blue turns (themeB) -->
|
|
81
|
+
<rect class="turn" fill="#1e88e5" x="605" y="265" width="8" height="35"/>
|
|
82
|
+
<rect class="turn" fill="#1e88e5" x="620" y="275" width="8" height="25"/>
|
|
83
|
+
|
|
84
|
+
<!-- Clusters C -->
|
|
85
|
+
<line class="cluster" stroke="#43a047" x1="505" y1="315" x2="550" y2="315"/>
|
|
86
|
+
<line class="cluster" stroke="#1e88e5" x1="600" y1="315" x2="630" y2="315"/>
|
|
87
|
+
|
|
88
|
+
<!-- ========== Session D turns ========== -->
|
|
89
|
+
<!-- Blue turns (themeB) -->
|
|
90
|
+
<rect class="turn" fill="#1e88e5" x="675" y="275" width="8" height="25"/>
|
|
91
|
+
<rect class="turn" fill="#1e88e5" x="690" y="260" width="8" height="40"/>
|
|
92
|
+
<!-- Green turns (themeA) -->
|
|
93
|
+
<rect class="turn" fill="#43a047" x="720" y="265" width="8" height="35"/>
|
|
94
|
+
<rect class="turn" fill="#43a047" x="735" y="250" width="8" height="50"/>
|
|
95
|
+
<rect class="turn" fill="#43a047" x="750" y="270" width="8" height="30"/>
|
|
96
|
+
|
|
97
|
+
<!-- Clusters D -->
|
|
98
|
+
<line class="cluster" stroke="#1e88e5" x1="670" y1="315" x2="700" y2="315"/>
|
|
99
|
+
<line class="cluster" stroke="#43a047" x1="715" y1="315" x2="760" y2="315"/>
|
|
100
|
+
|
|
101
|
+
<!-- ========== Theme brackets (endpoints align with vertical connectors) ========== -->
|
|
102
|
+
<!-- themeC (red): sessionA red cluster → sessionB red cluster → sessionC red turn -->
|
|
103
|
+
<path class="theme-bracket" stroke="#e53935" d="M 122 190 L 122 175 L 579 175 L 579 190"/>
|
|
104
|
+
<text class="theme-label" fill="#e53935" x="350" y="168" text-anchor="middle">themeC</text>
|
|
105
|
+
|
|
106
|
+
<!-- themeB (blue): sessionA → sessionB → sessionC → sessionD blue clusters -->
|
|
107
|
+
<path class="theme-bracket" stroke="#1e88e5" d="M 212 135 L 212 120 L 685 120 L 685 135"/>
|
|
108
|
+
<text class="theme-label" fill="#1e88e5" x="448" y="113" text-anchor="middle">themeB</text>
|
|
109
|
+
|
|
110
|
+
<!-- themeA (green): sessionB green turn → sessionC green cluster → sessionD green cluster -->
|
|
111
|
+
<path class="theme-bracket" stroke="#43a047" d="M 369 95 L 369 80 L 737 80 L 737 95"/>
|
|
112
|
+
<text class="theme-label" fill="#43a047" x="553" y="73" text-anchor="middle">themeA</text>
|
|
113
|
+
|
|
114
|
+
<!-- Vertical connectors from themes to representative turns/clusters -->
|
|
115
|
+
<line class="theme-line" stroke="#e53935" x1="122" y1="175" x2="122" y2="220"/>
|
|
116
|
+
<line class="theme-line" stroke="#e53935" x1="317" y1="175" x2="317" y2="220"/>
|
|
117
|
+
<line class="theme-line" stroke="#e53935" x1="579" y1="175" x2="579" y2="220"/>
|
|
118
|
+
|
|
119
|
+
<line class="theme-line" stroke="#1e88e5" x1="212" y1="120" x2="212" y2="220"/>
|
|
120
|
+
<line class="theme-line" stroke="#1e88e5" x1="412" y1="120" x2="412" y2="220"/>
|
|
121
|
+
<line class="theme-line" stroke="#1e88e5" x1="615" y1="120" x2="615" y2="220"/>
|
|
122
|
+
<line class="theme-line" stroke="#1e88e5" x1="685" y1="120" x2="685" y2="220"/>
|
|
123
|
+
|
|
124
|
+
<line class="theme-line" stroke="#43a047" x1="369" y1="80" x2="369" y2="220"/>
|
|
125
|
+
<line class="theme-line" stroke="#43a047" x1="527" y1="80" x2="527" y2="220"/>
|
|
126
|
+
<line class="theme-line" stroke="#43a047" x1="737" y1="80" x2="737" y2="220"/>
|
|
127
|
+
|
|
128
|
+
<!-- Callouts -->
|
|
129
|
+
<line stroke="#9e9e9e" stroke-width="1" x1="122" y1="250" x2="122" y2="235"/>
|
|
130
|
+
<text class="label-small" x="122" y="248" text-anchor="middle" fill="#e53935">turn</text>
|
|
131
|
+
|
|
132
|
+
<line stroke="#9e9e9e" stroke-width="1" x1="122" y1="332" x2="122" y2="350"/>
|
|
133
|
+
<text class="label-small" x="122" y="365" text-anchor="middle" fill="#e53935">cluster</text>
|
|
134
|
+
|
|
135
|
+
<!-- Legend (top-left to avoid blocking theme lines) -->
|
|
136
|
+
<rect class="legend-box" x="30" y="30" width="190" height="95" fill="#fafafa" stroke="#e0e0e0"/>
|
|
137
|
+
<text class="label" x="40" y="52" font-weight="600">图例</text>
|
|
138
|
+
<rect class="turn" fill="#e53935" x="40" y="62" width="6" height="20"/>
|
|
139
|
+
<text class="label-small" x="55" y="76">= turn(对话轮)</text>
|
|
140
|
+
<line class="cluster" stroke="#1e88e5" x1="40" y1="92" x2="70" y2="92"/>
|
|
141
|
+
<text class="label-small" x="75" y="96">= cluster(簇)</text>
|
|
142
|
+
<rect class="session-box" x="40" y="105" width="30" height="12"/>
|
|
143
|
+
<text class="label-small" x="75" y="115">= session</text>
|
|
144
|
+
</svg>
|