kimi-code-memory-mcp-server 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.en.md +342 -0
  3. package/README.md +267 -125
  4. package/assets/contextFlow.svg +144 -0
  5. package/assets/user-agents.md +111 -0
  6. package/dist/config.d.ts +13 -0
  7. package/dist/config.js +13 -0
  8. package/dist/config.js.map +1 -1
  9. package/dist/context/wire-context.d.ts +3 -0
  10. package/dist/context/wire-context.js +20 -50
  11. package/dist/context/wire-context.js.map +1 -1
  12. package/dist/dao/constants.d.ts +33 -0
  13. package/dist/dao/constants.js +17 -0
  14. package/dist/dao/constants.js.map +1 -0
  15. package/dist/dao/index-catalog.d.ts +19 -0
  16. package/dist/dao/index-catalog.js +94 -0
  17. package/dist/dao/index-catalog.js.map +1 -0
  18. package/dist/dao/index-reconciler.d.ts +13 -0
  19. package/dist/dao/index-reconciler.js +162 -0
  20. package/dist/dao/index-reconciler.js.map +1 -0
  21. package/dist/dao/index-store.d.ts +31 -0
  22. package/dist/dao/index-store.js +128 -0
  23. package/dist/dao/index-store.js.map +1 -0
  24. package/dist/dao/index.d.ts +12 -31
  25. package/dist/dao/index.js +50 -404
  26. package/dist/dao/index.js.map +1 -1
  27. package/dist/dao/memory-store.js +2 -10
  28. package/dist/dao/memory-store.js.map +1 -1
  29. package/dist/dao/memory-tree-renderer.d.ts +22 -0
  30. package/dist/dao/memory-tree-renderer.js +75 -0
  31. package/dist/dao/memory-tree-renderer.js.map +1 -0
  32. package/dist/prompts/index.d.ts +26 -0
  33. package/dist/prompts/index.js +103 -0
  34. package/dist/prompts/index.js.map +1 -0
  35. package/dist/refine/adapter.d.ts +6 -0
  36. package/dist/refine/adapter.js +28 -0
  37. package/dist/refine/adapter.js.map +1 -0
  38. package/dist/refine/constants.d.ts +35 -0
  39. package/dist/refine/constants.js +107 -0
  40. package/dist/refine/constants.js.map +1 -0
  41. package/dist/refine/extractor.d.ts +12 -0
  42. package/dist/refine/extractor.js +122 -0
  43. package/dist/refine/extractor.js.map +1 -0
  44. package/dist/refine/store.d.ts +19 -0
  45. package/dist/refine/store.js +139 -0
  46. package/dist/refine/store.js.map +1 -0
  47. package/dist/refine/types.d.ts +56 -0
  48. package/dist/refine/types.js +5 -0
  49. package/dist/refine/types.js.map +1 -0
  50. package/dist/refined-manager.d.ts +10 -56
  51. package/dist/refined-manager.js +22 -341
  52. package/dist/refined-manager.js.map +1 -1
  53. package/dist/resources/index.d.ts +15 -0
  54. package/dist/resources/index.js +134 -0
  55. package/dist/resources/index.js.map +1 -0
  56. package/dist/server.js +46 -2
  57. package/dist/server.js.map +1 -1
  58. package/dist/setup-cli.d.ts +11 -0
  59. package/dist/setup-cli.js +84 -0
  60. package/dist/setup-cli.js.map +1 -0
  61. package/dist/setup.d.ts +33 -0
  62. package/dist/setup.js +206 -0
  63. package/dist/setup.js.map +1 -0
  64. package/dist/tools/context-tools.d.ts +16 -51
  65. package/dist/tools/context-tools.js +247 -55
  66. package/dist/tools/context-tools.js.map +1 -1
  67. package/dist/tools/index.d.ts +5 -827
  68. package/dist/tools/index.js +23 -354
  69. package/dist/tools/index.js.map +1 -1
  70. package/dist/tools/memory-tools.d.ts +4 -60
  71. package/dist/tools/memory-tools.js +129 -79
  72. package/dist/tools/memory-tools.js.map +1 -1
  73. package/dist/tools/system-tools.d.ts +3 -34
  74. package/dist/tools/system-tools.js +86 -32
  75. package/dist/tools/system-tools.js.map +1 -1
  76. package/dist/tools/theme-tools.d.ts +3 -31
  77. package/dist/tools/theme-tools.js +78 -22
  78. package/dist/tools/theme-tools.js.map +1 -1
  79. package/dist/tools/types.d.ts +21 -0
  80. package/dist/tools/types.js +13 -0
  81. package/dist/tools/types.js.map +1 -0
  82. package/dist/types.d.ts +4 -2
  83. package/dist/utils/action-entities.d.ts +16 -0
  84. package/dist/utils/action-entities.js +35 -0
  85. package/dist/utils/action-entities.js.map +1 -0
  86. package/dist/utils/date.d.ts +11 -0
  87. package/dist/utils/date.js +13 -0
  88. package/dist/utils/date.js.map +1 -0
  89. package/dist/utils/file-helpers.d.ts +10 -0
  90. package/dist/utils/file-helpers.js +28 -0
  91. package/dist/utils/file-helpers.js.map +1 -0
  92. package/dist/utils/headings.d.ts +5 -0
  93. package/dist/utils/headings.js +21 -0
  94. package/dist/utils/headings.js.map +1 -0
  95. package/dist/utils/search.d.ts +17 -0
  96. package/dist/utils/search.js +60 -0
  97. package/dist/utils/search.js.map +1 -0
  98. package/dist/utils/tools.d.ts +5 -0
  99. package/dist/utils/tools.js +10 -0
  100. package/dist/utils/tools.js.map +1 -0
  101. package/dist/version.d.ts +1 -1
  102. package/dist/version.js +1 -1
  103. package/dist/vis/api.d.ts +82 -0
  104. package/dist/vis/api.js +212 -0
  105. package/dist/vis/api.js.map +1 -0
  106. package/dist/vis/auto-start.d.ts +12 -0
  107. package/dist/vis/auto-start.js +87 -0
  108. package/dist/vis/auto-start.js.map +1 -0
  109. package/dist/vis/server.d.ts +14 -0
  110. package/dist/vis/server.js +103 -0
  111. package/dist/vis/server.js.map +1 -0
  112. package/dist/vis/static/app.js +395 -0
  113. package/dist/vis/static/index.html +95 -0
  114. package/dist/vis/static/style.css +707 -0
  115. package/dist/vis-cli.d.ts +7 -0
  116. package/dist/vis-cli.js +140 -0
  117. package/dist/vis-cli.js.map +1 -0
  118. package/docs/0.agent-memory-market-research.md +354 -0
  119. package/docs/1.memory-system-proposal-for-kimi-code.md +688 -0
  120. package/docs/2.memory-architecture-overview.md +417 -0
  121. package/docs/3.memory-skill-prompt-design.md +430 -0
  122. package/docs/4.kimi-code-native-evolution-roadmap.md +559 -0
  123. package/docs/5.decision-guard-design-notes.md +500 -0
  124. package/docs/ARCHITECTURE.md +2 -2
  125. package/docs/design-story.md +350 -0
  126. package/docs/three-layer-memory-model.md +153 -0
  127. package/docs/three-layer-memory-model.zh-CN.md +153 -0
  128. package/package.json +14 -6
  129. package/README.zh-CN.md +0 -227
package/README.md CHANGED
@@ -1,46 +1,82 @@
1
1
  # Kimi Code Memory MCP Server
2
2
 
3
- [中文](./README.zh-CN.md)
3
+ [English](./README.en.md)
4
4
 
5
5
  [![CI](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/kimi-code-memory-mcp-server.svg?color=brightgreen)](https://www.npmjs.com/package/kimi-code-memory-mcp-server)
6
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
7
8
 
8
- A local stdio MCP server that gives [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) cross-session memory.
9
+ 一个为 [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) 提供跨会话记忆的本地 stdio MCP 服务器。
9
10
 
10
- > **Note:** This package is not yet published to npm. Install and run it from source (see below).
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
- ## Features
14
+ ## 特性
15
15
 
16
- - **Markdown-first memories** human-readable, git-friendly, LLM-compatible.
17
- - **Structured long-term memory** — `memory/decisions/`, `memory/knowledge/`, `memory/rules/`, `memory/reference/`.
18
- - **Workspace essence** condensed digest (≤15 KB) generated from `memory/`.
19
- - **Cross-session context recovery** — parses Kimi Code CLI's `wire.jsonl` directly.
20
- - **Theme tracing** — associate conversation turns and memories with themes, then trace their evolution.
21
- - **Refined turn summaries** — reusable turn-level atomic summaries shared across themes.
22
- - **Rebuilding index** `index.json` is a cache; `.md` files are the source of truth.
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
23
 
24
- ## Why Markdown?
24
+ ## 主题追溯
25
25
 
26
- Most agent memory systems default to vector databases. That works for fuzzy retrieval, but it also makes memories opaque, hard to audit, and hard to version-control.
26
+ 传统的上下文管理只关注**纵向**:时间越近越清晰,越久越远越衰减。但这忽略了真实工作的一个核心特征:
27
27
 
28
- This project starts from the opposite assumption:
28
+ > **同一个 workspace 中的多次会话,往往不是单一叙事,而是多条主题线交织并行。**
29
29
 
30
- > Memories should be **judged, structured, and owned by the user** before they are stored.
30
+ 例如:
31
31
 
32
- Markdown + YAML frontmatter gives you:
32
+ - Session A:开发 auth 鉴权
33
+ - Session B:讨论orders数据表的迁移问题
34
+ - Session C:加密RSA+解密BCrypt+验证码CAPTCHA+Cookie
35
+ - Session D:fix sql error bug
36
+ - Session E: 登录Login API设计
33
37
 
34
- - Full readability and editability
35
- - Native git diff support
36
- - No required external database or cloud service
37
- - Compatibility with any LLM that can read text
38
+ 如果只看纵向,这些 session 彼此独立。但如果横向扫描,会发现 A、C、E 都属于"注册登录"这一主题。
38
39
 
39
- See [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) for the design rationale.
40
+ **主题追溯**就是:把时间线上的每个 turn 看作一个圆柱,圆柱的高度代表该 turn 的计算/思考深度,颜色/标签代表主题。我们甚至可以从kimi code已经压缩归档的上下文中再次挖掘,进行深度横向扫描,把同色圆柱(对话轮turns)找出来,重新建立关联,组成theme并存入记忆。当我们三周以后准备升级的我们的“注册登录”模块,或者修复某个bug的时候,不是对着已经压缩过无数次上下文的agent,重新描述对其当时的设计思路和方案,而是你的agent说:“刚刚通过trace_theme("注册登录")这个主题,发现根据3周前的设计决策和中间经历的2次调整改进,现在的问题我们应该用方案B。”
40
41
 
41
- ## Install
42
+ >下图展示了 `kimi-memory` 如何看待对话历史:竖条是时间轴上的 turn,粗横线是簇,灰框是 session,彩色括号把跨 session 的相关 turns / clusters 串联成主题线。
42
43
 
43
- Currently the package must be installed from source. Node.js ≥ 18 is required.
44
+ ![时间轴上的 turns、簇、session 与主题追溯](./assets/contextFlow.svg)
45
+
46
+ 下面是一段真实的 Kimi Code CLI 会话动图,使用 `kimi-memory`。用户先后要求总结 MCP 记忆服务器的演进历史、以及 E2E 测试工具的演进历史;Agent 跨会话召回相关记忆与对话 turns,并生成结构化总结。
47
+
48
+ ![Kimi Memory MCP Server 演示](https://github.com/user-attachments/assets/a8947676-1487-47ed-8e0c-8d15f8662618)
49
+
50
+ 相关工具:`tag_theme`、`trace_theme`、`list_themes`、`search_context`、`refine_session_turns`、`load_turn_context`。
51
+
52
+ ## 为什么用 Markdown?
53
+
54
+ 大多数 Agent 记忆系统默认使用向量数据库。这在模糊检索场景有效,但也让记忆变得不透明、难以审计、难以版本控制。
55
+
56
+ 本项目从相反的假设出发:
57
+
58
+ > 记忆在存储之前应该经过**判断、结构化,并由用户拥有**。
59
+
60
+ Markdown + YAML frontmatter 带来:
61
+
62
+ - 完全可读、可编辑
63
+ - 原生支持 git diff
64
+ - 无需外部数据库或云服务
65
+ - 兼容任何能读取文本的 LLM
66
+
67
+ 设计 rationale 见 [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)。
68
+
69
+ ## 安装
70
+
71
+ 需要 Node.js ≥ 18。
72
+
73
+ ### 从 npm 安装(推荐)
74
+
75
+ ```bash
76
+ npm install -g kimi-code-memory-mcp-server
77
+ ```
78
+
79
+ ### 从源码安装
44
80
 
45
81
  ```bash
46
82
  git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
@@ -49,9 +85,66 @@ npm install
49
85
  npm run build
50
86
  ```
51
87
 
52
- ## Configure Kimi Code CLI
88
+ ## 快速配置(推荐)
89
+
90
+ 从 npm 安装后,运行 setup 命令自动配置 Kimi Code CLI:
91
+
92
+ ```bash
93
+ npx kimi-memory-setup
94
+ ```
95
+
96
+ 它会完成:
53
97
 
54
- Edit `~/.kimi-code/mcp.json` and point to the built server entry:
98
+ 1. 检测 `~/.kimi-code` 目录。
99
+ 2. 在 `~/.kimi-code/AGENTS.md` 顶部注入记忆协议规则。
100
+ 3. 将 `memory-manage` Skill 安装到 `~/.kimi-code/skills/memory-manage`。
101
+ 4. 在 `~/.kimi-code/mcp.json` 中添加 `kimi-memory` MCP 服务器配置。
102
+
103
+ 预览变更而不写入文件:
104
+
105
+ ```bash
106
+ npx kimi-memory-setup --dry-run
107
+ ```
108
+
109
+ 后续如需移除注入的配置:
110
+
111
+ ```bash
112
+ npx kimi-memory-setup --undo
113
+ ```
114
+
115
+ ## 配置 Kimi Code CLI(手动)
116
+
117
+ 如果你希望手动配置,编辑 `~/.kimi-code/mcp.json` 并添加服务器。
118
+
119
+ 如果你用 `npm install -g` 安装,使用全局 `node_modules` 中 `dist/server.js` 的绝对路径:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "kimi-memory": {
125
+ "command": "node",
126
+ "args": ["/absolute/path/to/global/node_modules/kimi-code-memory-mcp-server/dist/server.js"],
127
+ "enabled": true
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ 或者直接通过 `npx` 运行(无需安装):
134
+
135
+ ```json
136
+ {
137
+ "mcpServers": {
138
+ "kimi-memory": {
139
+ "command": "npx",
140
+ "args": ["-y", "kimi-code-memory-mcp-server"],
141
+ "enabled": true
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ 如果你从源码构建,指向本地 `dist/server.js`:
55
148
 
56
149
  ```json
57
150
  {
@@ -65,109 +158,157 @@ Edit `~/.kimi-code/mcp.json` and point to the built server entry:
65
158
  }
66
159
  ```
67
160
 
68
- The server name **`kimi-memory`** is important because the bundled `AGENTS.md` rules call tools as `mcp__kimi-memory__*` (for example `mcp__kimi-memory__bootstrap_workspace`).
161
+ 服务器名称 **`kimi-memory`** 很重要,因为本仓库自带的 `AGENTS.md` 规则以 `mcp__kimi-memory__*` 形式调用工具(例如 `mcp__kimi-memory__bootstrap_workspace`)。
69
162
 
70
- Restart Kimi Code CLI to load the server.
163
+ 重启 Kimi Code CLI 以加载该服务器。
71
164
 
72
- ## Optional: Install User-Level AGENTS.md Startup Hook
165
+ ## 可选:安装用户级 AGENTS.md 启动钩子
73
166
 
74
- For automatic memory recovery and behavioral rules on every session start, copy the bundled `AGENTS.md` to your Kimi Code user directory:
167
+ 如需每次会话启动时自动恢复记忆并应用行为规范,将本仓库自带的 `AGENTS.md` 复制到 Kimi Code 用户目录:
75
168
 
76
169
  ```bash
77
170
  cp AGENTS.md ~/.kimi-code/AGENTS.md
78
171
  ```
79
172
 
80
- This installs a startup hook that tells Kimi Code CLI to call `bootstrap_workspace` at the beginning of every session, and to follow the memory classification and decision-guard rules. Because `AGENTS.md` is injected into **every** session, it is the right place for memory-related behavior protocols.
173
+ 这会安装一个启动钩子,让 Kimi Code CLI 在每次会话开始时调用 `bootstrap_workspace`,并遵循记忆分类和决策守卫规则。由于 `AGENTS.md` 会注入到**每个**会话中,它是放置记忆相关行为协议的正确位置。
81
174
 
82
- > **Note:** Keep `AGENTS.md` focused on memory-related conventions only. Do not include tool preferences that belong to other MCP servers.
175
+ > **注意:** `AGENTS.md` 规则会注入到每个会话中,请只保留与记忆相关的约定,不要包含属于其他 MCP server 的工具偏好。
83
176
  >
84
- > **Prerequisite:** The MCP server must be registered under the name `kimi-memory` in `~/.kimi-code/mcp.json`, otherwise the `mcp__kimi-memory__*` calls in `AGENTS.md` will fail.
177
+ > **前提条件:** 必须在 `~/.kimi-code/mcp.json` 中将 MCP 服务器注册为 `kimi-memory`,否则 `AGENTS.md` 中的 `mcp__kimi-memory__*` 调用会失败。
85
178
 
86
- ## Optional: Install the Memory Skill
179
+ ## 可选:安装记忆 Skill
87
180
 
88
- This repository also includes a lightweight Skill (`skills/memory-manage/SKILL.md`) that reminds Kimi Code CLI to call the memory tools when the user expresses a memory-related intent.
181
+ 本仓库还包含一个轻量 Skill(`skills/memory-manage/SKILL.md`),用于在用户表达记忆相关意图时提醒 Kimi Code CLI 调用记忆工具。
89
182
 
90
183
  ```bash
91
184
  cp -r skills/memory-manage ~/.kimi-code/skills/memory-manage
92
185
  ```
93
186
 
94
- The Skill does **not** enforce behavior on its own; it is a dispatcher. The actual protocols (when to remember, decision guard, etc.) live in `AGENTS.md`.
187
+ Skill 本身**不强制**行为,它只是一个调度器。真正的协议(何时 remember、决策守卫等)应配置在 `AGENTS.md` 中。
95
188
 
96
- ## Quick Start
189
+ ## 快速开始
97
190
 
98
- After the server is loaded, the agent can call memory tools naturally (tool names are prefixed with the MCP server name you configured, e.g. `mcp__kimi-memory__*`):
191
+ 服务器加载后,Agent 可以自然地调用记忆工具(工具名带有你在 MCP 配置中注册的 server 名称前缀,例如 `mcp__kimi-memory__*`):
99
192
 
100
193
  ```text
101
- User: Let's use SQLite for the cache layer.
102
- Agent: [calls mcp__kimi-memory__remember] key=use-sqlite-cache, folder=memory/decisions
103
-
104
- User: Why did we choose SQLite?
105
- Agent: [calls mcp__kimi-memory__search] query=SQLite cache decision
106
- [calls mcp__kimi-memory__recall] key=use-sqlite-cache, folder=memory/decisions
107
- → "We chose SQLite over Redis because..."
108
-
109
- User: How has the cache design evolved?
110
- Agent: [calls mcp__kimi-memory__tag_theme] theme=cache-design
111
- [calls mcp__kimi-memory__trace_theme] theme=cache-design
112
- shows related turns and decisions across sessions
194
+ 用户:我们用 SQLite 作为缓存层。
195
+ Agent[调用 mcp__kimi-memory__remember] key=use-sqlite-cache, folder=memory/decisions
196
+
197
+ 用户:为什么选 SQLite
198
+ Agent[调用 mcp__kimi-memory__search] query=SQLite cache decision
199
+ [调用 mcp__kimi-memory__recall] key=use-sqlite-cache, folder=memory/decisions
200
+ → "我们选择 SQLite 而不是 Redis,因为……"
201
+
202
+ 用户:缓存设计是怎么演化的?
203
+ Agent[调用 mcp__kimi-memory__tag_theme] theme=cache-design
204
+ [调用 mcp__kimi-memory__trace_theme] theme=cache-design
205
+ 展示跨会话的相关轮次和决策
113
206
  ```
114
207
 
115
- ## Storage Layout
208
+ ## 存储布局
116
209
 
117
- The server stores data under `~/.kimi-code-memory/<workspace-id>/`:
210
+ 服务器将数据存储在 `~/.kimi-code-memory/<workspace-id>/` 下:
118
211
 
119
212
  ```text
120
213
  ~/.kimi-code-memory/workspace-a1b2c3d4/
121
- ├── index.json # v3-kv metadata cache (rebuildable)
214
+ ├── index.json # v3-kv 元数据缓存(可重建)
122
215
  ├── memory/
123
- │ ├── decisions/ # architecture and product decisions
124
- │ ├── knowledge/ # project-specific knowledge
125
- │ ├── rules/ # conventions and guardrails
126
- │ └── reference/ # external references
216
+ │ ├── decisions/ # 架构与产品决策
217
+ │ ├── knowledge/ # 项目相关知识
218
+ │ ├── rules/ # 约定与红线
219
+ │ └── reference/ # 外部参考
127
220
  ├── essence/
128
- │ └── essence.md # workspace digest (≤15 KB)
129
- ├── notes/ # scratch notes
221
+ │ └── essence.md # 工作区精要(≤15 KB
222
+ ├── notes/ # 临时速记
130
223
  ├── themes/
131
- │ └── my-theme.json # theme -> turn/memory refs
224
+ │ └── my-theme.json # theme -> turn/memory 引用
132
225
  └── refined/
133
- └── refined.sqlite # turn-level summaries
134
- ```
135
-
136
- You can override the storage root with the `MEMORY_STORE_ROOT` environment variable.
137
-
138
- ### Environment Variables
139
-
140
- | Variable | Purpose |
141
- |----------|---------|
142
- | `MEMORY_STORE_ROOT` | Override the default `~/.kimi-code-memory` storage root. |
143
- | `MEMORY_SESSIONS_ROOT` | Override the default `~/.kimi-code/sessions` path used to discover `wire.jsonl` files. |
144
- | `KIMI_CODE_HOME` | Alternative to `MEMORY_SESSIONS_ROOT`; sessions are read from `<KIMI_CODE_HOME>/sessions`. |
145
-
146
- ## Tools
147
-
148
- | Tool | Purpose |
149
- |------|---------|
150
- | `remember` | Write a Markdown memory |
151
- | `recall` | Read a memory by key |
152
- | `recall_recent` | List recently updated memories |
153
- | `search` | Keyword search across memories |
154
- | `list` | List memories |
155
- | `list_tags` | List all tags |
156
- | `delete` | Delete a memory |
157
- | `move` | Move or rename a memory |
158
- | `organize_memories` | Distill `memory/` into `essence/essence.md` |
159
- | `sync_workspace_index` | Rebuild `index.json` from disk |
160
- | `bootstrap_workspace` | Load context, essence, and memory tree |
161
- | `load_workspace_context` | Load recent conversation context |
162
- | `load_more_context` | Load older conversation rounds |
163
- | `search_context` | Search across all session wires |
164
- | `load_turn_context` | Load specific turn details |
165
- | `tag_theme` | Associate a turn or memory with a theme |
166
- | `trace_theme` | Trace a theme's evolution |
167
- | `list_themes` | List themes |
168
- | `refine_session_turns` | Generate refined turn summaries |
169
-
170
- ## Development
226
+ └── refined.sqlite # 轮次级摘要
227
+ ```
228
+
229
+ 可通过 `MEMORY_STORE_ROOT` 环境变量覆盖存储根目录。
230
+
231
+ ### 环境变量
232
+
233
+ | 变量 | 用途 |
234
+ |------|------|
235
+ | `MEMORY_STORE_ROOT` | 覆盖默认存储根目录 `~/.kimi-code-memory`。 |
236
+ | `MEMORY_SESSIONS_ROOT` | 覆盖默认的 `~/.kimi-code/sessions` 路径,用于发现 `wire.jsonl` 文件。 |
237
+ | `KIMI_CODE_HOME` | `MEMORY_SESSIONS_ROOT` 的替代方案;会话从 `<KIMI_CODE_HOME>/sessions` 读取。 |
238
+
239
+ ## 工具列表
240
+
241
+ | 工具 | 用途 |
242
+ |------|------|
243
+ | `remember` | 写入一条 Markdown 记忆 |
244
+ | `recall` | key 读取记忆 |
245
+ | `search` | 在记忆中关键词搜索 |
246
+ | `list` | 列出记忆,支持按 folder / tag 过滤和 limit 限制 |
247
+ | `list_tags` | 列出所有标签 |
248
+ | `delete` | 删除记忆 |
249
+ | `move` | 移动或重命名记忆 |
250
+ | `organize_memories` | `memory/` 提炼为 `essence/essence.md` |
251
+ | `sync_workspace_index` | 从磁盘重建 `index.json` |
252
+ | `bootstrap_workspace` | 加载上下文、精要和记忆树 |
253
+ | `load_workspace_context` | 加载最近对话上下文 |
254
+ | `load_more_context` | 加载更早的对话轮次 |
255
+ | `search_context` | 跨所有会话 wire 搜索 |
256
+ | `load_turn_context` | 加载指定轮次详情 |
257
+ | `tag_theme` | 将轮次或记忆关联到主题 |
258
+ | `trace_theme` | 追溯主题演化 |
259
+ | `list_themes` | 列出主题 |
260
+ | `refine_session_turns` | 生成精炼轮次摘要 |
261
+
262
+ ## Prompts
263
+
264
+ 本服务器同时提供可复用的 MCP Prompt,供客户端在调用工具前拉取:
265
+
266
+ | Prompt | 用途 |
267
+ |--------|------|
268
+ | `memory-decision-check` | 修改文件前,先检查与其相关的历史决策 |
269
+ | `memory-theme-trace` | 追溯某个主题在多次会话中的演化 |
270
+ | `memory-session-summary` | 总结当前会话,并建议值得挂载的主题 |
271
+
272
+ ## Resources
273
+
274
+ 本服务器暴露以下 MCP Resource URI,客户端可按需读取:
275
+
276
+ | URI 模式 | 说明 |
277
+ |----------|------|
278
+ | `memory://<folder>/<key>` | 读取 `memory/` 下的某条 Markdown 记忆 |
279
+ | `theme://<theme>` | 读取某个主题的关联摘要(Markdown 格式) |
280
+ | `essence://essence` | 读取工作区精要 `essence/essence.md` |
281
+
282
+ ## 可视化仪表盘
283
+
284
+ 提供独立的 Web 仪表盘,用于查看工作区记忆、主题时间线和近期决策:
285
+
286
+ ```bash
287
+ npx kimi-memory-vis
288
+ ```
289
+
290
+ 启动后会自动打开浏览器,默认地址 `http://127.0.0.1:58628`。
291
+
292
+ 也可以在 MCP 服务器启动时自动启动仪表盘:
293
+
294
+ ```bash
295
+ export KIMI_MEMORY_AUTO_VIS=1
296
+ ```
297
+
298
+ 或者在会话中让 Agent 打开:
299
+
300
+ ```json
301
+ { "name": "open_memory_dashboard" }
302
+ ```
303
+
304
+ 仪表盘支持:
305
+
306
+ - 工作区概览与 `essence.md` 行内编辑
307
+ - 主题时间线浏览
308
+ - 近期决策列表
309
+ - 显式记忆目录浏览
310
+
311
+ ## 开发
171
312
 
172
313
  ```bash
173
314
  git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
@@ -178,50 +319,51 @@ npm test
178
319
  npm run lint
179
320
  ```
180
321
 
181
- See [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.md) for contribution guidelines.
322
+ 贡献指南见 [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.zh-CN.md)
182
323
 
183
- ## Project Structure
324
+ ## 项目结构
184
325
 
185
326
  ```text
186
327
  src/
187
- ├── server.ts # MCP server entry
188
- ├── config.ts # defaults and paths
189
- ├── theme-manager.ts # theme storage
190
- ├── refined-manager.ts # refined turn storage
328
+ ├── server.ts # MCP 服务器入口
329
+ ├── config.ts # 默认值与路径
330
+ ├── theme-manager.ts # 主题存储
331
+ ├── refined-manager.ts # 精炼轮次存储
191
332
  ├── dao/
192
- │ ├── index.ts # index.json DAO (v3-kv)
193
- │ └── memory-store.ts # Markdown file operations
333
+ │ ├── index.ts # index.json DAOv3-kv
334
+ │ └── memory-store.ts # Markdown 文件操作
194
335
  ├── context/
195
- │ └── wire-context.ts # wire.jsonl parsing
336
+ │ └── wire-context.ts # wire.jsonl 解析
196
337
  ├── tools/
197
- │ ├── index.ts # tool schemas & dispatch
198
- │ ├── memory-tools.ts # memory CRUD
199
- │ ├── context-tools.ts # context recovery
200
- │ ├── theme-tools.ts # theme tracing
201
- │ └── system-tools.ts # organize/sync/bootstrap
338
+ │ ├── index.ts # 工具 schema 与分发
339
+ │ ├── memory-tools.ts # 记忆增删改查
340
+ │ ├── context-tools.ts # 上下文恢复
341
+ │ ├── theme-tools.ts # 主题追溯
342
+ │ └── system-tools.ts # 整理/同步/引导
202
343
  └── utils/
203
344
  ├── frontmatter.ts
204
345
  ├── paths.ts
205
346
  └── validation.ts
206
347
  ```
207
348
 
208
- ## Roadmap
349
+ ## 路线图
209
350
 
210
- - [x] Modular source structure
351
+ - [x] 模块化源码结构
211
352
  - [x] ESLint + Prettier
212
- - [x] Basic integration tests
213
- - [x] Core test coverage for context/theme tools
214
- - [ ] Optional local embedding search
215
- - [ ] Optional LLM-based turn refinement
216
- - [ ] Pluggable wire format adapters
217
- - [ ] Memory usage benchmarks
353
+ - [x] 基础集成测试
354
+ - [x] 上下文/主题工具核心测试覆盖
355
+ - [ ] 可选本地 embedding 搜索
356
+ - [ ] 可选 LLM 精炼轮次
357
+ - [ ] 可插拔 wire 格式适配器
358
+ - [ ] 内存使用 benchmark
218
359
 
219
- ## Related Documents
360
+ ## 相关文档
220
361
 
221
- - [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) system design and data flow
222
- - [`docs/search-logic.md`](./docs/search-logic.md) how `search` and `search_context` work
223
- - [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.md) how to contribute
362
+ - [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) —— 系统设计与数据流
363
+ - [`docs/three-layer-memory-model.zh-CN.md`](./docs/three-layer-memory-model.zh-CN.md) —— 本服务器背后的记忆模型理论
364
+ - [`docs/search-logic.zh-CN.md`](./docs/search-logic.zh-CN.md) —— `search` `search_context` 的实现逻辑
365
+ - [`docs/CONTRIBUTING.zh-CN.md`](./docs/CONTRIBUTING.zh-CN.md) —— 如何贡献
224
366
 
225
- ## License
367
+ ## 许可证
226
368
 
227
369
  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>