kimi-code-memory-mcp-server 0.1.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/AGENTS.md +144 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/README.zh-CN.md +227 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +63 -0
- package/dist/config.js.map +1 -0
- package/dist/context/wire-context.d.ts +171 -0
- package/dist/context/wire-context.js +586 -0
- package/dist/context/wire-context.js.map +1 -0
- package/dist/dao/index.d.ts +76 -0
- package/dist/dao/index.js +490 -0
- package/dist/dao/index.js.map +1 -0
- package/dist/dao/memory-store.d.ts +24 -0
- package/dist/dao/memory-store.js +112 -0
- package/dist/dao/memory-store.js.map +1 -0
- package/dist/refined-manager.d.ts +70 -0
- package/dist/refined-manager.js +369 -0
- package/dist/refined-manager.js.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.js +71 -0
- package/dist/server.js.map +1 -0
- package/dist/theme-manager.d.ts +40 -0
- package/dist/theme-manager.js +88 -0
- package/dist/theme-manager.js.map +1 -0
- package/dist/tools/context-tools.d.ts +56 -0
- package/dist/tools/context-tools.js +332 -0
- package/dist/tools/context-tools.js.map +1 -0
- package/dist/tools/index.d.ts +835 -0
- package/dist/tools/index.js +370 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory-tools.d.ts +62 -0
- package/dist/tools/memory-tools.js +292 -0
- package/dist/tools/memory-tools.js.map +1 -0
- package/dist/tools/system-tools.d.ts +37 -0
- package/dist/tools/system-tools.js +195 -0
- package/dist/tools/system-tools.js.map +1 -0
- package/dist/tools/theme-tools.d.ts +34 -0
- package/dist/tools/theme-tools.js +186 -0
- package/dist/tools/theme-tools.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +10 -0
- package/dist/utils/frontmatter.js +61 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/mutex.d.ts +11 -0
- package/dist/utils/mutex.js +17 -0
- package/dist/utils/mutex.js.map +1 -0
- package/dist/utils/paths.d.ts +19 -0
- package/dist/utils/paths.js +54 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/validation.d.ts +15 -0
- package/dist/utils/validation.js +40 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/docs/ARCHITECTURE.md +144 -0
- package/docs/CONTRIBUTING.md +83 -0
- package/docs/CONTRIBUTING.zh-CN.md +83 -0
- package/docs/search-logic.md +157 -0
- package/docs/search-logic.zh-CN.md +157 -0
- package/examples/README.md +34 -0
- package/examples/sample-workspace/essence/essence.md +26 -0
- package/examples/sample-workspace/index.json +36 -0
- package/examples/sample-workspace/memory/decisions/sample-decision.md +30 -0
- package/examples/sample-workspace/memory/knowledge/sample-knowledge.md +24 -0
- package/examples/sample-workspace/memory/reference/sample-reference.md +20 -0
- package/examples/sample-workspace/memory/rules/sample-rule.md +31 -0
- package/examples/sample-workspace/themes/cache-design.json +15 -0
- package/package.json +72 -0
- package/skills/memory-manage/SKILL.md +43 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
## 强制启动协议
|
|
2
|
+
|
|
3
|
+
每次会话开始后、回答用户第一个问题或执行任何可能改变项目状态的操作之前,**必须调用** `mcp__kimi-memory__bootstrap_workspace()`。
|
|
4
|
+
|
|
5
|
+
必须读取并内化:
|
|
6
|
+
1. `essence.md` —— 当前工作区什么最重要
|
|
7
|
+
2. `memoryIndexTree` —— 记忆目录结构,关注标记 `[new]` 的最近变化
|
|
8
|
+
3. `recentContext` —— 当前 session 的最近对话
|
|
9
|
+
4. `notesRefs` —— 是否有待处理的速记
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 记忆分类约定
|
|
14
|
+
|
|
15
|
+
| 类型 | folder | tags | 用途 |
|
|
16
|
+
|------|--------|------|------|
|
|
17
|
+
| 决策 | `memory/decisions/` | `decision` | 架构、接口、流程决策 |
|
|
18
|
+
| 规则 | `memory/rules/` | `rule` | 编码规范、协作红线 |
|
|
19
|
+
| 知识 | `memory/knowledge/` | `knowledge` | 技术栈、业务背景 |
|
|
20
|
+
| 参考 | `memory/reference/` | `reference` | 外部链接、文档引用 |
|
|
21
|
+
| 速记 | `notes/` | `scratch` | 临时便签,不进入长期精要 |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 什么时候必须 `remember`?
|
|
26
|
+
|
|
27
|
+
出现以下信号时立即写入 `memory/`:
|
|
28
|
+
|
|
29
|
+
- 用户说"我们决定…"、"拍板了" → `memory/decisions/`,tag `decision`
|
|
30
|
+
- 用户说"这里必须…"、"红线是…" → `memory/rules/`,tag `rule`
|
|
31
|
+
- 技术选型、接口约定首次出现 → `memory/knowledge/`,tag `knowledge`
|
|
32
|
+
- 定位到 bug 根因和修复方案 → `memory/decisions/` 或 `memory/knowledge/`,tag `fix`
|
|
33
|
+
- 编码风格、目录结构、命名规范 → `memory/rules/`,tag `convention`
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 什么时候不要 `remember`?
|
|
38
|
+
|
|
39
|
+
- ❌ 临时调试命令或探索性代码
|
|
40
|
+
- ❌ 用户未确认的推测
|
|
41
|
+
- ❌ 一次性报错(没有形成通用结论)
|
|
42
|
+
- ❌ 当前会话的临时上下文(由 `wire.jsonl` 自动捕获)
|
|
43
|
+
- ❌ 已经在 `memory/` 中存在的知识
|
|
44
|
+
|
|
45
|
+
判断口诀:如果这条信息三天后回头看仍然有价值,才写入 `memory/`。
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 决策守卫
|
|
50
|
+
|
|
51
|
+
准备执行任何可能改变项目状态的操作之前(写文件、改结构、做选择、引入依赖):
|
|
52
|
+
|
|
53
|
+
1. 提取关键词(技术实体 + 动作)
|
|
54
|
+
2. 并行查询:
|
|
55
|
+
- `search(query, folder="memory")` —— 查决策/规则/知识
|
|
56
|
+
- `search_context(query)` —— 查历史对话
|
|
57
|
+
3. 命中且一致 → 引用来源后继续
|
|
58
|
+
4. 命中但矛盾 → 向用户报告冲突,请求澄清
|
|
59
|
+
5. 未命中但重要 → 询问用户"这是一个新决策,是否记录?"
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 引用来源的纪律
|
|
64
|
+
|
|
65
|
+
所有从 `memory/` 召回的关键结论,回复中必须标注来源:
|
|
66
|
+
|
|
67
|
+
- ✅ "根据 `memory/decisions/xxx`,我们决定…"
|
|
68
|
+
- ❌ "我们之前决定…"(无来源)
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 主题追溯
|
|
73
|
+
|
|
74
|
+
当用户要求追溯某个主题时:
|
|
75
|
+
|
|
76
|
+
1. 确认主题范围
|
|
77
|
+
2. 用 `search_context` 打捞相关 turns(调用时会自动按 90 秒时间簇扩展并提炼命中的 turns)
|
|
78
|
+
3. 用 `list_search_views` 查看最近的搜索视图,作为 theme 挂载的候选集
|
|
79
|
+
4. 对搜索命中的 turns 做语义分析,用 `tag_theme` 把 genuinely belongs to the theme 的 turns 逐个挂载到 `themes/<theme>.json`
|
|
80
|
+
5. 如果候选不足,用新的 query 再次 `search_context` 打捞,生成新的 search view
|
|
81
|
+
6. 用 `trace_theme` 输出主题时间线
|
|
82
|
+
|
|
83
|
+
`search_context` 已内置提炼能力,不需要单独调用 `refine_session_turns`。
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 记忆卫生检查清单
|
|
88
|
+
|
|
89
|
+
每次调用 `remember` 前:
|
|
90
|
+
|
|
91
|
+
- [ ] 这条信息三天后还有价值吗?
|
|
92
|
+
- [ ] 是否已有重复记忆?(先 `search`)
|
|
93
|
+
- [ ] `folder` 选对了吗?项目相关不进 `notes/`
|
|
94
|
+
- [ ] `tags` 是否包含最贴切的分类标签?
|
|
95
|
+
- [ ] 正文是否包含决策原因/影响范围/相关文件?
|
|
96
|
+
|
|
97
|
+
每次做决策前:
|
|
98
|
+
|
|
99
|
+
- [ ] 是否已 `search` 相关历史决策?
|
|
100
|
+
- [ ] 是否已检查 `essence.md` 中的核心约束?
|
|
101
|
+
- [ ] 如果与历史记忆冲突,是否已向用户澄清?
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## MCP Server 版本号规则
|
|
106
|
+
|
|
107
|
+
项目存在两个版本号,必须区分并保持一致:
|
|
108
|
+
|
|
109
|
+
| 版本号 | 位置 | 用途 |
|
|
110
|
+
|--------|------|------|
|
|
111
|
+
| 仓库版本 | `package.json#version` | 发布包、Git tag、CHANGELOG 的版本 |
|
|
112
|
+
| 运行实例版本 | `src/version.ts` → `src/server.ts` | MCP 协议握手时报告的版本 |
|
|
113
|
+
|
|
114
|
+
- 采用 SemVer 2.0.0(`MAJOR.MINOR.PATCH`)。
|
|
115
|
+
- 单一事实来源:`package.json#version`。
|
|
116
|
+
- 运行实例版本通过 `npm run sync-version` 从 `package.json` 同步到 `src/version.ts`。
|
|
117
|
+
- `npm run build` 会自动执行同步。
|
|
118
|
+
- 禁止手动修改 `src/version.ts`;改版本只改 `package.json`。
|
|
119
|
+
|
|
120
|
+
### 升级触发条件
|
|
121
|
+
|
|
122
|
+
| 位 | 触发条件 |
|
|
123
|
+
|----|----------|
|
|
124
|
+
| MAJOR | 不兼容的协议/存储格式/工具签名变更 |
|
|
125
|
+
| MINOR | 新增工具或能力、非破坏性增强 |
|
|
126
|
+
| PATCH | Bug 修复、性能优化、文档/测试更新 |
|
|
127
|
+
|
|
128
|
+
### 代码变更后验证顺序
|
|
129
|
+
|
|
130
|
+
1. 仓库内:`npm run typecheck && npm run lint && npm test`
|
|
131
|
+
2. **运行实例实测**:当仓库测试受本地环境干扰(例如仓库本身积累了大量历史 sessions、数据状态复杂,导致难以在干净条件下验证)时,将新代码同步到实际 MCP 运行实例(如 Kimi Code CLI 调用的 server),用真实工作区验证行为。
|
|
132
|
+
3. 严禁仅以仓库测试通过为由跳过必要的运行实例实测,尤其是涉及环境变量、路径解析、缓存/模块状态的变更。
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 禁止行为
|
|
137
|
+
|
|
138
|
+
- 禁止用 `folder="notes"` 保存项目相关记忆
|
|
139
|
+
- 禁止写入空 tags
|
|
140
|
+
- 禁止只口头答应而不调用工具
|
|
141
|
+
- 禁止手动修改 `~/.kimi-code/sessions/` 下的 `wire.jsonl`
|
|
142
|
+
- 禁止手动修改 `src/version.ts`(应通过 `package.json` + `npm run sync-version` 同步)
|
|
143
|
+
- **当用户输入以 `?` / `?` 结尾时,禁止执行任何写入/修改/构建/运行等改变项目状态的操作**:只能回答问题和进行讨论,必须等待用户明确说出「确定」「可以」「开始吧」等指令后才能行动
|
|
144
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-06-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of Kimi Code Memory MCP Server.
|
|
12
|
+
- Modular source structure (`src/tools`, `src/dao`, `src/context`, `src/utils`).
|
|
13
|
+
- Memory CRUD tools: `remember`, `recall`, `recall_recent`, `search`, `list`, `list_tags`, `delete`, `move`.
|
|
14
|
+
- Context recovery tools: `bootstrap_workspace`, `load_workspace_context`, `load_more_context`, `search_context`, `load_turn_context`.
|
|
15
|
+
- Theme tracing tools: `tag_theme`, `trace_theme`, `list_themes`, `refine_session_turns`.
|
|
16
|
+
- System tools: `organize_memories`, `sync_workspace_index`, `get_current_workspace`.
|
|
17
|
+
- Markdown + YAML frontmatter storage with rebuildable `index.json` v3-kv cache.
|
|
18
|
+
- ESLint + Prettier configuration.
|
|
19
|
+
- Basic integration tests.
|
|
20
|
+
- English and Chinese READMEs.
|
|
21
|
+
- GitHub issue and PR templates.
|
|
22
|
+
- CI workflow running tests and lint on pull requests.
|
|
23
|
+
- MCP server versioning rules: SemVer for repository version, runtime version synced from `package.json`, and a release workflow that includes real-instance validation.
|
|
24
|
+
|
|
25
|
+
[Unreleased]: https://github.com/Zehee/kimi-code-memory-mcp-server/compare/v0.1.0...HEAD
|
|
26
|
+
[0.1.0]: https://github.com/Zehee/kimi-code-memory-mcp-server/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kimi-code-memory-mcp-server contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Kimi Code Memory MCP Server
|
|
2
|
+
|
|
3
|
+
[中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
A local stdio MCP server that gives [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) cross-session memory.
|
|
9
|
+
|
|
10
|
+
> **Note:** This package is not yet published to npm. Install and run it from source (see below).
|
|
11
|
+
|
|
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
|
+
|
|
14
|
+
## Features
|
|
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.
|
|
23
|
+
|
|
24
|
+
## Why Markdown?
|
|
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.
|
|
27
|
+
|
|
28
|
+
This project starts from the opposite assumption:
|
|
29
|
+
|
|
30
|
+
> Memories should be **judged, structured, and owned by the user** before they are stored.
|
|
31
|
+
|
|
32
|
+
Markdown + YAML frontmatter gives you:
|
|
33
|
+
|
|
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
|
+
|
|
39
|
+
See [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) for the design rationale.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
Currently the package must be installed from source. Node.js ≥ 18 is required.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
47
|
+
cd kimi-code-memory-mcp-server
|
|
48
|
+
npm install
|
|
49
|
+
npm run build
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configure Kimi Code CLI
|
|
53
|
+
|
|
54
|
+
Edit `~/.kimi-code/mcp.json` and point to the built server entry:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"kimi-memory": {
|
|
60
|
+
"command": "node",
|
|
61
|
+
"args": ["/absolute/path/to/kimi-code-memory-mcp-server/dist/server.js"],
|
|
62
|
+
"enabled": true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
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`).
|
|
69
|
+
|
|
70
|
+
Restart Kimi Code CLI to load the server.
|
|
71
|
+
|
|
72
|
+
## Optional: Install User-Level AGENTS.md Startup Hook
|
|
73
|
+
|
|
74
|
+
For automatic memory recovery and behavioral rules on every session start, copy the bundled `AGENTS.md` to your Kimi Code user directory:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cp AGENTS.md ~/.kimi-code/AGENTS.md
|
|
78
|
+
```
|
|
79
|
+
|
|
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.
|
|
81
|
+
|
|
82
|
+
> **Note:** Keep `AGENTS.md` focused on memory-related conventions only. Do not include tool preferences that belong to other MCP servers.
|
|
83
|
+
>
|
|
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.
|
|
85
|
+
|
|
86
|
+
## Optional: Install the Memory Skill
|
|
87
|
+
|
|
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.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
cp -r skills/memory-manage ~/.kimi-code/skills/memory-manage
|
|
92
|
+
```
|
|
93
|
+
|
|
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`.
|
|
95
|
+
|
|
96
|
+
## Quick Start
|
|
97
|
+
|
|
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__*`):
|
|
99
|
+
|
|
100
|
+
```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
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Storage Layout
|
|
116
|
+
|
|
117
|
+
The server stores data under `~/.kimi-code-memory/<workspace-id>/`:
|
|
118
|
+
|
|
119
|
+
```text
|
|
120
|
+
~/.kimi-code-memory/workspace-a1b2c3d4/
|
|
121
|
+
├── index.json # v3-kv metadata cache (rebuildable)
|
|
122
|
+
├── memory/
|
|
123
|
+
│ ├── decisions/ # architecture and product decisions
|
|
124
|
+
│ ├── knowledge/ # project-specific knowledge
|
|
125
|
+
│ ├── rules/ # conventions and guardrails
|
|
126
|
+
│ └── reference/ # external references
|
|
127
|
+
├── essence/
|
|
128
|
+
│ └── essence.md # workspace digest (≤15 KB)
|
|
129
|
+
├── notes/ # scratch notes
|
|
130
|
+
├── themes/
|
|
131
|
+
│ └── my-theme.json # theme -> turn/memory refs
|
|
132
|
+
└── 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
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
174
|
+
cd kimi-code-memory-mcp-server
|
|
175
|
+
npm install
|
|
176
|
+
npm run build
|
|
177
|
+
npm test
|
|
178
|
+
npm run lint
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
See [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.md) for contribution guidelines.
|
|
182
|
+
|
|
183
|
+
## Project Structure
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
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
|
|
191
|
+
├── dao/
|
|
192
|
+
│ ├── index.ts # index.json DAO (v3-kv)
|
|
193
|
+
│ └── memory-store.ts # Markdown file operations
|
|
194
|
+
├── context/
|
|
195
|
+
│ └── wire-context.ts # wire.jsonl parsing
|
|
196
|
+
├── 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
|
|
202
|
+
└── utils/
|
|
203
|
+
├── frontmatter.ts
|
|
204
|
+
├── paths.ts
|
|
205
|
+
└── validation.ts
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Roadmap
|
|
209
|
+
|
|
210
|
+
- [x] Modular source structure
|
|
211
|
+
- [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
|
|
218
|
+
|
|
219
|
+
## Related Documents
|
|
220
|
+
|
|
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
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Kimi Code Memory MCP Server
|
|
2
|
+
|
|
3
|
+
[English](./README.md)
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
一个为 [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) 提供跨会话记忆的本地 stdio MCP 服务器。
|
|
9
|
+
|
|
10
|
+
> **注意:** 本包尚未发布到 npm,请按下面的说明从源码安装运行。
|
|
11
|
+
|
|
12
|
+
面向用户的记忆以普通 Markdown 文件存储在磁盘上。精炼轮次摘要使用本地 SQLite 缓存,但无需向量数据库、图数据库或外部云服务。
|
|
13
|
+
|
|
14
|
+
## 特性
|
|
15
|
+
|
|
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?
|
|
25
|
+
|
|
26
|
+
大多数 Agent 记忆系统默认使用向量数据库。这在模糊检索场景有效,但也让记忆变得不透明、难以审计、难以版本控制。
|
|
27
|
+
|
|
28
|
+
本项目从相反的假设出发:
|
|
29
|
+
|
|
30
|
+
> 记忆在存储之前应该经过**判断、结构化,并由用户拥有**。
|
|
31
|
+
|
|
32
|
+
Markdown + YAML frontmatter 带来:
|
|
33
|
+
|
|
34
|
+
- 完全可读、可编辑
|
|
35
|
+
- 原生支持 git diff
|
|
36
|
+
- 无需外部数据库或云服务
|
|
37
|
+
- 兼容任何能读取文本的 LLM
|
|
38
|
+
|
|
39
|
+
设计 rationale 见 [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)。
|
|
40
|
+
|
|
41
|
+
## 安装
|
|
42
|
+
|
|
43
|
+
目前本包需要从源码安装。需要 Node.js ≥ 18。
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
47
|
+
cd kimi-code-memory-mcp-server
|
|
48
|
+
npm install
|
|
49
|
+
npm run build
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 配置 Kimi Code CLI
|
|
53
|
+
|
|
54
|
+
编辑 `~/.kimi-code/mcp.json`,指向构建后的服务器入口:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"kimi-memory": {
|
|
60
|
+
"command": "node",
|
|
61
|
+
"args": ["/absolute/path/to/kimi-code-memory-mcp-server/dist/server.js"],
|
|
62
|
+
"enabled": true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
服务器名称 **`kimi-memory`** 很重要,因为本仓库自带的 `AGENTS.md` 规则以 `mcp__kimi-memory__*` 形式调用工具(例如 `mcp__kimi-memory__bootstrap_workspace`)。
|
|
69
|
+
|
|
70
|
+
重启 Kimi Code CLI 以加载该服务器。
|
|
71
|
+
|
|
72
|
+
## 可选:安装用户级 AGENTS.md 启动钩子
|
|
73
|
+
|
|
74
|
+
如需每次会话启动时自动恢复记忆并应用行为规范,将本仓库自带的 `AGENTS.md` 复制到 Kimi Code 用户目录:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cp AGENTS.md ~/.kimi-code/AGENTS.md
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
这会安装一个启动钩子,让 Kimi Code CLI 在每次会话开始时调用 `bootstrap_workspace`,并遵循记忆分类和决策守卫规则。由于 `AGENTS.md` 会注入到**每个**会话中,它是放置记忆相关行为协议的正确位置。
|
|
81
|
+
|
|
82
|
+
> **注意:** `AGENTS.md` 规则会注入到每个会话中,请只保留与记忆相关的约定,不要包含属于其他 MCP server 的工具偏好。
|
|
83
|
+
>
|
|
84
|
+
> **前提条件:** 必须在 `~/.kimi-code/mcp.json` 中将 MCP 服务器注册为 `kimi-memory`,否则 `AGENTS.md` 中的 `mcp__kimi-memory__*` 调用会失败。
|
|
85
|
+
|
|
86
|
+
## 可选:安装记忆 Skill
|
|
87
|
+
|
|
88
|
+
本仓库还包含一个轻量 Skill(`skills/memory-manage/SKILL.md`),用于在用户表达记忆相关意图时提醒 Kimi Code CLI 调用记忆工具。
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
cp -r skills/memory-manage ~/.kimi-code/skills/memory-manage
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
该 Skill 本身**不强制**行为,它只是一个调度器。真正的协议(何时 remember、决策守卫等)应配置在 `AGENTS.md` 中。
|
|
95
|
+
|
|
96
|
+
## 快速开始
|
|
97
|
+
|
|
98
|
+
服务器加载后,Agent 可以自然地调用记忆工具(工具名带有你在 MCP 配置中注册的 server 名称前缀,例如 `mcp__kimi-memory__*`):
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
用户:我们用 SQLite 作为缓存层。
|
|
102
|
+
Agent:[调用 mcp__kimi-memory__remember] key=use-sqlite-cache, folder=memory/decisions
|
|
103
|
+
|
|
104
|
+
用户:为什么选 SQLite?
|
|
105
|
+
Agent:[调用 mcp__kimi-memory__search] query=SQLite cache decision
|
|
106
|
+
[调用 mcp__kimi-memory__recall] key=use-sqlite-cache, folder=memory/decisions
|
|
107
|
+
→ "我们选择 SQLite 而不是 Redis,因为……"
|
|
108
|
+
|
|
109
|
+
用户:缓存设计是怎么演化的?
|
|
110
|
+
Agent:[调用 mcp__kimi-memory__tag_theme] theme=cache-design
|
|
111
|
+
[调用 mcp__kimi-memory__trace_theme] theme=cache-design
|
|
112
|
+
→ 展示跨会话的相关轮次和决策
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 存储布局
|
|
116
|
+
|
|
117
|
+
服务器将数据存储在 `~/.kimi-code-memory/<workspace-id>/` 下:
|
|
118
|
+
|
|
119
|
+
```text
|
|
120
|
+
~/.kimi-code-memory/workspace-a1b2c3d4/
|
|
121
|
+
├── index.json # v3-kv 元数据缓存(可重建)
|
|
122
|
+
├── memory/
|
|
123
|
+
│ ├── decisions/ # 架构与产品决策
|
|
124
|
+
│ ├── knowledge/ # 项目相关知识
|
|
125
|
+
│ ├── rules/ # 约定与红线
|
|
126
|
+
│ └── reference/ # 外部参考
|
|
127
|
+
├── essence/
|
|
128
|
+
│ └── essence.md # 工作区精要(≤15 KB)
|
|
129
|
+
├── notes/ # 临时速记
|
|
130
|
+
├── themes/
|
|
131
|
+
│ └── my-theme.json # theme -> turn/memory 引用
|
|
132
|
+
└── refined/
|
|
133
|
+
└── refined.sqlite # 轮次级摘要
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
可通过 `MEMORY_STORE_ROOT` 环境变量覆盖存储根目录。
|
|
137
|
+
|
|
138
|
+
### 环境变量
|
|
139
|
+
|
|
140
|
+
| 变量 | 用途 |
|
|
141
|
+
|------|------|
|
|
142
|
+
| `MEMORY_STORE_ROOT` | 覆盖默认存储根目录 `~/.kimi-code-memory`。 |
|
|
143
|
+
| `MEMORY_SESSIONS_ROOT` | 覆盖默认的 `~/.kimi-code/sessions` 路径,用于发现 `wire.jsonl` 文件。 |
|
|
144
|
+
| `KIMI_CODE_HOME` | `MEMORY_SESSIONS_ROOT` 的替代方案;会话从 `<KIMI_CODE_HOME>/sessions` 读取。 |
|
|
145
|
+
|
|
146
|
+
## 工具列表
|
|
147
|
+
|
|
148
|
+
| 工具 | 用途 |
|
|
149
|
+
|------|------|
|
|
150
|
+
| `remember` | 写入一条 Markdown 记忆 |
|
|
151
|
+
| `recall` | 按 key 读取记忆 |
|
|
152
|
+
| `recall_recent` | 列出最近更新的记忆 |
|
|
153
|
+
| `search` | 在记忆中关键词搜索 |
|
|
154
|
+
| `list` | 列出记忆 |
|
|
155
|
+
| `list_tags` | 列出所有标签 |
|
|
156
|
+
| `delete` | 删除记忆 |
|
|
157
|
+
| `move` | 移动或重命名记忆 |
|
|
158
|
+
| `organize_memories` | 将 `memory/` 提炼为 `essence/essence.md` |
|
|
159
|
+
| `sync_workspace_index` | 从磁盘重建 `index.json` |
|
|
160
|
+
| `bootstrap_workspace` | 加载上下文、精要和记忆树 |
|
|
161
|
+
| `load_workspace_context` | 加载最近对话上下文 |
|
|
162
|
+
| `load_more_context` | 加载更早的对话轮次 |
|
|
163
|
+
| `search_context` | 跨所有会话 wire 搜索 |
|
|
164
|
+
| `load_turn_context` | 加载指定轮次详情 |
|
|
165
|
+
| `tag_theme` | 将轮次或记忆关联到主题 |
|
|
166
|
+
| `trace_theme` | 追溯主题演化 |
|
|
167
|
+
| `list_themes` | 列出主题 |
|
|
168
|
+
| `refine_session_turns` | 生成精炼轮次摘要 |
|
|
169
|
+
|
|
170
|
+
## 开发
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
|
|
174
|
+
cd kimi-code-memory-mcp-server
|
|
175
|
+
npm install
|
|
176
|
+
npm run build
|
|
177
|
+
npm test
|
|
178
|
+
npm run lint
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
贡献指南见 [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.zh-CN.md)。
|
|
182
|
+
|
|
183
|
+
## 项目结构
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
src/
|
|
187
|
+
├── server.ts # MCP 服务器入口
|
|
188
|
+
├── config.ts # 默认值与路径
|
|
189
|
+
├── theme-manager.ts # 主题存储
|
|
190
|
+
├── refined-manager.ts # 精炼轮次存储
|
|
191
|
+
├── dao/
|
|
192
|
+
│ ├── index.ts # index.json DAO(v3-kv)
|
|
193
|
+
│ └── memory-store.ts # Markdown 文件操作
|
|
194
|
+
├── context/
|
|
195
|
+
│ └── wire-context.ts # wire.jsonl 解析
|
|
196
|
+
├── tools/
|
|
197
|
+
│ ├── index.ts # 工具 schema 与分发
|
|
198
|
+
│ ├── memory-tools.ts # 记忆增删改查
|
|
199
|
+
│ ├── context-tools.ts # 上下文恢复
|
|
200
|
+
│ ├── theme-tools.ts # 主题追溯
|
|
201
|
+
│ └── system-tools.ts # 整理/同步/引导
|
|
202
|
+
└── utils/
|
|
203
|
+
├── frontmatter.ts
|
|
204
|
+
├── paths.ts
|
|
205
|
+
└── validation.ts
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 路线图
|
|
209
|
+
|
|
210
|
+
- [x] 模块化源码结构
|
|
211
|
+
- [x] ESLint + Prettier
|
|
212
|
+
- [x] 基础集成测试
|
|
213
|
+
- [x] 上下文/主题工具核心测试覆盖
|
|
214
|
+
- [ ] 可选本地 embedding 搜索
|
|
215
|
+
- [ ] 可选 LLM 精炼轮次
|
|
216
|
+
- [ ] 可插拔 wire 格式适配器
|
|
217
|
+
- [ ] 内存使用 benchmark
|
|
218
|
+
|
|
219
|
+
## 相关文档
|
|
220
|
+
|
|
221
|
+
- [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) —— 系统设计与数据流
|
|
222
|
+
- [`docs/search-logic.zh-CN.md`](./docs/search-logic.zh-CN.md) —— `search` 与 `search_context` 的实现逻辑
|
|
223
|
+
- [`docs/CONTRIBUTING.zh-CN.md`](./docs/CONTRIBUTING.zh-CN.md) —— 如何贡献
|
|
224
|
+
|
|
225
|
+
## 许可证
|
|
226
|
+
|
|
227
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global configuration.
|
|
3
|
+
*
|
|
4
|
+
* The store root can be overridden via the MEMORY_STORE_ROOT environment
|
|
5
|
+
* variable. When unset, it defaults to ~/.kimi-code-memory/ so that the
|
|
6
|
+
* server behaves like a user-level tool even when installed as a package.
|
|
7
|
+
*/
|
|
8
|
+
export declare const homedir: string;
|
|
9
|
+
export declare function getStoreRoot(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the directory where Kimi Code CLI session wires are stored.
|
|
12
|
+
*
|
|
13
|
+
* Priority:
|
|
14
|
+
* 1. MEMORY_SESSIONS_ROOT environment variable (absolute path)
|
|
15
|
+
* 2. KIMI_CODE_HOME environment variable (<KIMI_CODE_HOME>/sessions)
|
|
16
|
+
* 3. Default ~/.kimi-code/sessions
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSessionsRoot(): string;
|
|
19
|
+
export interface ContextWindow {
|
|
20
|
+
detailedRounds: number;
|
|
21
|
+
defaultSummaryRounds: number;
|
|
22
|
+
loadMoreChunkSize: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const DEFAULT_CONTEXT_WINDOW: ContextWindow;
|
|
25
|
+
export declare const DEFAULT_RECENT_CHANGE_LIMIT = 5;
|
|
26
|
+
export declare const ESSENCE_SIZE_LIMIT: number;
|
|
27
|
+
/**
|
|
28
|
+
* search_context 用于把相邻 turn 聚成「簇」的默认时间间隔(秒)。
|
|
29
|
+
*
|
|
30
|
+
* 「簇」是指一小段连续的来回对话,通常围绕同一个决策或讨论展开。
|
|
31
|
+
* 如果两个相邻 turn 的时间间隔超过这个值,就认为它们属于不同的簇。
|
|
32
|
+
*
|
|
33
|
+
* 90 秒适合典型的 agent-user 对话:既能区分开不同话题,又足以保留
|
|
34
|
+
* 一段流畅讨论的完整性。每次搜索可以通过 cluster_gap_seconds 参数覆盖。
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_CLUSTER_GAP_SECONDS = 90;
|