@synth-coder/memhub 0.2.1 → 0.2.3
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/.eslintrc.cjs +45 -45
- package/.factory/commands/opsx-apply.md +150 -0
- package/.factory/commands/opsx-archive.md +155 -0
- package/.factory/commands/opsx-explore.md +171 -0
- package/.factory/commands/opsx-propose.md +104 -0
- package/.factory/skills/openspec-apply-change/SKILL.md +156 -0
- package/.factory/skills/openspec-archive-change/SKILL.md +114 -0
- package/.factory/skills/openspec-explore/SKILL.md +288 -0
- package/.factory/skills/openspec-propose/SKILL.md +110 -0
- package/.github/workflows/ci.yml +74 -74
- package/.iflow/commands/opsx-apply.md +152 -152
- package/.iflow/commands/opsx-archive.md +157 -157
- package/.iflow/commands/opsx-explore.md +173 -173
- package/.iflow/commands/opsx-propose.md +106 -106
- package/.iflow/skills/openspec-apply-change/SKILL.md +156 -156
- package/.iflow/skills/openspec-archive-change/SKILL.md +114 -114
- package/.iflow/skills/openspec-explore/SKILL.md +288 -288
- package/.iflow/skills/openspec-propose/SKILL.md +110 -110
- package/.prettierrc +11 -11
- package/AGENTS.md +169 -26
- package/README.md +195 -195
- package/README.zh-CN.md +193 -193
- package/dist/src/contracts/mcp.js +34 -34
- package/dist/src/server/mcp-server.d.ts +8 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/mcp-server.js +23 -2
- package/dist/src/server/mcp-server.js.map +1 -1
- package/dist/src/services/memory-service.d.ts +1 -0
- package/dist/src/services/memory-service.d.ts.map +1 -1
- package/dist/src/services/memory-service.js +125 -82
- package/dist/src/services/memory-service.js.map +1 -1
- package/docs/architecture-diagrams.md +368 -0
- package/docs/architecture.md +381 -349
- package/docs/contracts.md +190 -119
- package/docs/prompt-template.md +33 -79
- package/docs/proposals/mcp-typescript-sdk-refactor.md +568 -568
- package/docs/proposals/proposal-close-gates.md +58 -58
- package/docs/tool-calling-policy.md +101 -107
- package/docs/vector-search.md +306 -0
- package/package.json +59 -58
- package/src/contracts/index.ts +12 -12
- package/src/contracts/mcp.ts +222 -222
- package/src/contracts/schemas.ts +307 -307
- package/src/contracts/types.ts +410 -410
- package/src/index.ts +8 -8
- package/src/server/index.ts +5 -5
- package/src/server/mcp-server.ts +185 -161
- package/src/services/embedding-service.ts +114 -114
- package/src/services/index.ts +5 -5
- package/src/services/memory-service.ts +663 -621
- package/src/storage/frontmatter-parser.ts +243 -243
- package/src/storage/index.ts +6 -6
- package/src/storage/markdown-storage.ts +236 -236
- package/src/storage/vector-index.ts +160 -160
- package/src/utils/index.ts +5 -5
- package/src/utils/slugify.ts +63 -63
- package/test/contracts/schemas.test.ts +313 -313
- package/test/contracts/types.test.ts +21 -21
- package/test/frontmatter-parser-more.test.ts +94 -94
- package/test/server/mcp-server.test.ts +210 -169
- package/test/services/memory-service-edge.test.ts +248 -248
- package/test/services/memory-service.test.ts +278 -278
- package/test/storage/frontmatter-parser.test.ts +222 -222
- package/test/storage/markdown-storage.test.ts +216 -216
- package/test/storage/storage-edge.test.ts +238 -238
- package/test/storage/vector-index.test.ts +153 -153
- package/test/utils/slugify-edge.test.ts +94 -94
- package/test/utils/slugify.test.ts +68 -68
- package/tsconfig.json +25 -25
- package/tsconfig.test.json +8 -8
- package/vitest.config.ts +29 -29
package/README.zh-CN.md
CHANGED
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
# MemHub
|
|
2
|
-
|
|
3
|
-
一个面向编码代理(Codex / Claude Code / OpenCode 等)的 **Git 友好记忆 MCP Server**。
|
|
4
|
-
|
|
5
|
-
MemHub 将“用户决策、长期偏好、可复用知识”保存为 **Markdown 文件 + YAML Front Matter**,便于人读、审查、版本管理和协作。
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 为什么用 MemHub
|
|
10
|
-
|
|
11
|
-
- **Git 原生**:所有记忆都是纯文本文件,天然可 diff / 可回滚
|
|
12
|
-
- **面向 Agent**:通过 MCP(stdio)暴露工具,便于模型调用
|
|
13
|
-
- **人类可读**:元数据在 YAML,正文在 Markdown
|
|
14
|
-
- **质量可控**:内置 lint / typecheck / test / coverage 门禁
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## 核心特性
|
|
19
|
-
|
|
20
|
-
- Markdown 持久化(`.md`)
|
|
21
|
-
- YAML Front Matter 元数据(`id / session_id / entry_type / tags / category / importance / 时间戳`)
|
|
22
|
-
- STM-first 双工具接口:`memory_load` + `memory_update`
|
|
23
|
-
- 并发 CLI 安全目录:`YYYY-MM-DD/session_uuid/...`
|
|
24
|
-
- MCP stdio server,可接入主流 MCP 客户端
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## 快速开始
|
|
29
|
-
|
|
30
|
-
### 1)从 npm 安装
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm i @synth-coder/memhub
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### 2)本地开发安装依赖
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npm install
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### 3)构建
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
npm run build
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### 4)执行质量门禁
|
|
49
|
-
```bash
|
|
50
|
-
npm run quality
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## 作为 MCP Server 使用(stdio)
|
|
56
|
-
|
|
57
|
-
### 方式 A:npx 直接运行(推荐)
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npx -y @synth-coder/memhub
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
> Windows 下不要在包名后再加 `memhub` 参数。
|
|
64
|
-
> 如果出现“弹出源码 .js 文件”的情况,请升级到最新版本(`0.1.2+`)后重试。
|
|
65
|
-
|
|
66
|
-
在你的 MCP 客户端配置中添加:
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
{
|
|
70
|
-
"mcpServers": {
|
|
71
|
-
"memhub": {
|
|
72
|
-
"command": "npx",
|
|
73
|
-
"args": ["-y", "@synth-coder/memhub"],
|
|
74
|
-
"env": {
|
|
75
|
-
"MEMHUB_STORAGE_PATH": "/绝对路径/你的记忆目录",
|
|
76
|
-
"MEMHUB_LOG_LEVEL": "info"
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### 方式 B:本地仓库运行
|
|
84
|
-
|
|
85
|
-
```json
|
|
86
|
-
{
|
|
87
|
-
"mcpServers": {
|
|
88
|
-
"memhub": {
|
|
89
|
-
"command": "node",
|
|
90
|
-
"args": ["dist/src/server/mcp-server.js"]
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
## 环境变量
|
|
99
|
-
|
|
100
|
-
- `MEMHUB_STORAGE_PATH`:记忆存储目录(默认:`./memories`)
|
|
101
|
-
- `MEMHUB_LOG_LEVEL`:日志级别(默认:`info`,可选:`debug|info|warn|error`)
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## 记忆文件格式
|
|
106
|
-
|
|
107
|
-
```markdown
|
|
108
|
-
---
|
|
109
|
-
id: "550e8400-e29b-41d4-a716-446655440000"
|
|
110
|
-
created_at: "2026-03-03T08:00:00.000Z"
|
|
111
|
-
updated_at: "2026-03-03T08:00:00.000Z"
|
|
112
|
-
tags:
|
|
113
|
-
- architecture
|
|
114
|
-
- tdd
|
|
115
|
-
category: "engineering"
|
|
116
|
-
importance: 4
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
# Contract-first MCP 设计
|
|
120
|
-
|
|
121
|
-
先定义工具契约与 schema,再进入实现。
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
文件名格式:
|
|
125
|
-
|
|
126
|
-
```text
|
|
127
|
-
YYYY-MM-DD-title-slug.md
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## MCP 工具列表
|
|
133
|
-
|
|
134
|
-
> 调用策略建议见:`docs/tool-calling-policy.md`(首轮 `memory_load`,末轮 `memory_update`)。
|
|
135
|
-
|
|
136
|
-
- `memory_load`:首轮加载短期记忆(STM)上下文
|
|
137
|
-
- `memory_update`:末轮回写决策/偏好/知识/状态变化
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## 开发说明
|
|
142
|
-
|
|
143
|
-
### 常用脚本
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
npm run build
|
|
147
|
-
npm run lint
|
|
148
|
-
npm run typecheck
|
|
149
|
-
npm run test
|
|
150
|
-
npm run test:coverage
|
|
151
|
-
npm run quality
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### 工程流程(默认)
|
|
155
|
-
|
|
156
|
-
- 契约优先(先类型与 schema)
|
|
157
|
-
- 严格 TDD(`红 -> 绿 -> 重构`)
|
|
158
|
-
- 合并前必须通过质量门禁
|
|
159
|
-
- 覆盖率阈值:**>= 80%**
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## 项目结构
|
|
164
|
-
|
|
165
|
-
```text
|
|
166
|
-
memhub/
|
|
167
|
-
├── docs/
|
|
168
|
-
├── src/
|
|
169
|
-
│ ├── contracts/
|
|
170
|
-
│ ├── server/
|
|
171
|
-
│ ├── services/
|
|
172
|
-
│ ├── storage/
|
|
173
|
-
│ └── utils/
|
|
174
|
-
├── test/
|
|
175
|
-
└── .github/workflows/
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## 路线图
|
|
181
|
-
|
|
182
|
-
- [x] 架构与契约设计
|
|
183
|
-
- [x] 核心实现(storage/service/server)
|
|
184
|
-
- [x] 质量门禁(lint/typecheck/test/coverage)
|
|
185
|
-
- [ ] 集成测试
|
|
186
|
-
- [ ] 性能优化
|
|
187
|
-
- [x] npm 发布(`@synth-coder/memhub@0.1.3`)
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
## License
|
|
192
|
-
|
|
193
|
-
MIT
|
|
1
|
+
# MemHub
|
|
2
|
+
|
|
3
|
+
一个面向编码代理(Codex / Claude Code / OpenCode 等)的 **Git 友好记忆 MCP Server**。
|
|
4
|
+
|
|
5
|
+
MemHub 将“用户决策、长期偏好、可复用知识”保存为 **Markdown 文件 + YAML Front Matter**,便于人读、审查、版本管理和协作。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 为什么用 MemHub
|
|
10
|
+
|
|
11
|
+
- **Git 原生**:所有记忆都是纯文本文件,天然可 diff / 可回滚
|
|
12
|
+
- **面向 Agent**:通过 MCP(stdio)暴露工具,便于模型调用
|
|
13
|
+
- **人类可读**:元数据在 YAML,正文在 Markdown
|
|
14
|
+
- **质量可控**:内置 lint / typecheck / test / coverage 门禁
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 核心特性
|
|
19
|
+
|
|
20
|
+
- Markdown 持久化(`.md`)
|
|
21
|
+
- YAML Front Matter 元数据(`id / session_id / entry_type / tags / category / importance / 时间戳`)
|
|
22
|
+
- STM-first 双工具接口:`memory_load` + `memory_update`
|
|
23
|
+
- 并发 CLI 安全目录:`YYYY-MM-DD/session_uuid/...`
|
|
24
|
+
- MCP stdio server,可接入主流 MCP 客户端
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 快速开始
|
|
29
|
+
|
|
30
|
+
### 1)从 npm 安装
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm i @synth-coder/memhub
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2)本地开发安装依赖
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3)构建
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 4)执行质量门禁
|
|
49
|
+
```bash
|
|
50
|
+
npm run quality
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 作为 MCP Server 使用(stdio)
|
|
56
|
+
|
|
57
|
+
### 方式 A:npx 直接运行(推荐)
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx -y @synth-coder/memhub
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> Windows 下不要在包名后再加 `memhub` 参数。
|
|
64
|
+
> 如果出现“弹出源码 .js 文件”的情况,请升级到最新版本(`0.1.2+`)后重试。
|
|
65
|
+
|
|
66
|
+
在你的 MCP 客户端配置中添加:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"memhub": {
|
|
72
|
+
"command": "npx",
|
|
73
|
+
"args": ["-y", "@synth-coder/memhub"],
|
|
74
|
+
"env": {
|
|
75
|
+
"MEMHUB_STORAGE_PATH": "/绝对路径/你的记忆目录",
|
|
76
|
+
"MEMHUB_LOG_LEVEL": "info"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 方式 B:本地仓库运行
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"mcpServers": {
|
|
88
|
+
"memhub": {
|
|
89
|
+
"command": "node",
|
|
90
|
+
"args": ["dist/src/server/mcp-server.js"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 环境变量
|
|
99
|
+
|
|
100
|
+
- `MEMHUB_STORAGE_PATH`:记忆存储目录(默认:`./memories`)
|
|
101
|
+
- `MEMHUB_LOG_LEVEL`:日志级别(默认:`info`,可选:`debug|info|warn|error`)
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 记忆文件格式
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
---
|
|
109
|
+
id: "550e8400-e29b-41d4-a716-446655440000"
|
|
110
|
+
created_at: "2026-03-03T08:00:00.000Z"
|
|
111
|
+
updated_at: "2026-03-03T08:00:00.000Z"
|
|
112
|
+
tags:
|
|
113
|
+
- architecture
|
|
114
|
+
- tdd
|
|
115
|
+
category: "engineering"
|
|
116
|
+
importance: 4
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
# Contract-first MCP 设计
|
|
120
|
+
|
|
121
|
+
先定义工具契约与 schema,再进入实现。
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
文件名格式:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
YYYY-MM-DD-title-slug.md
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## MCP 工具列表
|
|
133
|
+
|
|
134
|
+
> 调用策略建议见:`docs/tool-calling-policy.md`(首轮 `memory_load`,末轮 `memory_update`)。
|
|
135
|
+
|
|
136
|
+
- `memory_load`:首轮加载短期记忆(STM)上下文
|
|
137
|
+
- `memory_update`:末轮回写决策/偏好/知识/状态变化
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 开发说明
|
|
142
|
+
|
|
143
|
+
### 常用脚本
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm run build
|
|
147
|
+
npm run lint
|
|
148
|
+
npm run typecheck
|
|
149
|
+
npm run test
|
|
150
|
+
npm run test:coverage
|
|
151
|
+
npm run quality
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 工程流程(默认)
|
|
155
|
+
|
|
156
|
+
- 契约优先(先类型与 schema)
|
|
157
|
+
- 严格 TDD(`红 -> 绿 -> 重构`)
|
|
158
|
+
- 合并前必须通过质量门禁
|
|
159
|
+
- 覆盖率阈值:**>= 80%**
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 项目结构
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
memhub/
|
|
167
|
+
├── docs/
|
|
168
|
+
├── src/
|
|
169
|
+
│ ├── contracts/
|
|
170
|
+
│ ├── server/
|
|
171
|
+
│ ├── services/
|
|
172
|
+
│ ├── storage/
|
|
173
|
+
│ └── utils/
|
|
174
|
+
├── test/
|
|
175
|
+
└── .github/workflows/
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 路线图
|
|
181
|
+
|
|
182
|
+
- [x] 架构与契约设计
|
|
183
|
+
- [x] 核心实现(storage/service/server)
|
|
184
|
+
- [x] 质量门禁(lint/typecheck/test/coverage)
|
|
185
|
+
- [ ] 集成测试
|
|
186
|
+
- [ ] 性能优化
|
|
187
|
+
- [x] npm 发布(`@synth-coder/memhub@0.1.3`)
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
@@ -21,21 +21,21 @@ export const TOOL_NAMES = ['memory_load', 'memory_update'];
|
|
|
21
21
|
export const TOOL_DEFINITIONS = [
|
|
22
22
|
{
|
|
23
23
|
name: 'memory_load',
|
|
24
|
-
description: `Retrieve stored memories to recall user preferences, past decisions, project context, and learned knowledge.
|
|
25
|
-
|
|
26
|
-
WHEN TO USE (call proactively):
|
|
27
|
-
• Starting a new conversation or task
|
|
28
|
-
• User references past discussions ("remember when...", "as I mentioned before")
|
|
29
|
-
• Need context about user's coding style, preferences, or project decisions
|
|
30
|
-
• Uncertain about user's existing preferences or constraints
|
|
31
|
-
• Before making assumptions about user requirements
|
|
32
|
-
|
|
33
|
-
WHAT IT PROVIDES:
|
|
34
|
-
• User preferences (coding style, frameworks, naming conventions)
|
|
35
|
-
• Past decisions and their rationale
|
|
36
|
-
• Project-specific context and constraints
|
|
37
|
-
• Previously learned knowledge about the user
|
|
38
|
-
|
|
24
|
+
description: `Retrieve stored memories to recall user preferences, past decisions, project context, and learned knowledge.
|
|
25
|
+
|
|
26
|
+
WHEN TO USE (call proactively):
|
|
27
|
+
• Starting a new conversation or task
|
|
28
|
+
• User references past discussions ("remember when...", "as I mentioned before")
|
|
29
|
+
• Need context about user's coding style, preferences, or project decisions
|
|
30
|
+
• Uncertain about user's existing preferences or constraints
|
|
31
|
+
• Before making assumptions about user requirements
|
|
32
|
+
|
|
33
|
+
WHAT IT PROVIDES:
|
|
34
|
+
• User preferences (coding style, frameworks, naming conventions)
|
|
35
|
+
• Past decisions and their rationale
|
|
36
|
+
• Project-specific context and constraints
|
|
37
|
+
• Previously learned knowledge about the user
|
|
38
|
+
|
|
39
39
|
Call this early to provide personalized, context-aware responses.`,
|
|
40
40
|
inputSchema: {
|
|
41
41
|
type: 'object',
|
|
@@ -67,25 +67,25 @@ Call this early to provide personalized, context-aware responses.`,
|
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
name: 'memory_update',
|
|
70
|
-
description: `Store important information to remember for future conversations.
|
|
71
|
-
|
|
72
|
-
WHEN TO USE (call when learning something worth remembering):
|
|
73
|
-
• User explicitly states a preference ("I prefer functional components")
|
|
74
|
-
• User makes a decision with rationale ("We'll use PostgreSQL because...")
|
|
75
|
-
• You discover important project context (tech stack, constraints, patterns)
|
|
76
|
-
• User corrects your assumption ("Actually, I don't use Redux")
|
|
77
|
-
• Task state changes that should persist
|
|
78
|
-
|
|
79
|
-
WHAT TO STORE:
|
|
80
|
-
• Preferences: coding style, frameworks, naming conventions
|
|
81
|
-
• Decisions: architecture choices, library selections, with reasoning
|
|
82
|
-
• Knowledge: project-specific patterns, gotchas, conventions
|
|
83
|
-
• Context: team structure, deployment process, testing approach
|
|
84
|
-
|
|
85
|
-
TIPS:
|
|
86
|
-
• content is required and most important
|
|
87
|
-
• title helps with search (auto-generated if omitted)
|
|
88
|
-
• Use entryType to categorize: "preference", "decision", "context", "fact"
|
|
70
|
+
description: `Store important information to remember for future conversations.
|
|
71
|
+
|
|
72
|
+
WHEN TO USE (call when learning something worth remembering):
|
|
73
|
+
• User explicitly states a preference ("I prefer functional components")
|
|
74
|
+
• User makes a decision with rationale ("We'll use PostgreSQL because...")
|
|
75
|
+
• You discover important project context (tech stack, constraints, patterns)
|
|
76
|
+
• User corrects your assumption ("Actually, I don't use Redux")
|
|
77
|
+
• Task state changes that should persist
|
|
78
|
+
|
|
79
|
+
WHAT TO STORE:
|
|
80
|
+
• Preferences: coding style, frameworks, naming conventions
|
|
81
|
+
• Decisions: architecture choices, library selections, with reasoning
|
|
82
|
+
• Knowledge: project-specific patterns, gotchas, conventions
|
|
83
|
+
• Context: team structure, deployment process, testing approach
|
|
84
|
+
|
|
85
|
+
TIPS:
|
|
86
|
+
• content is required and most important
|
|
87
|
+
• title helps with search (auto-generated if omitted)
|
|
88
|
+
• Use entryType to categorize: "preference", "decision", "context", "fact"
|
|
89
89
|
• importance: 1-5 (default: 3), higher = more critical to remember`,
|
|
90
90
|
inputSchema: {
|
|
91
91
|
type: 'object',
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* Uses @modelcontextprotocol/sdk for protocol handling
|
|
5
5
|
*/
|
|
6
6
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Resolve storage path with the following priority:
|
|
9
|
+
* 1. MEMHUB_STORAGE_PATH env var (if set):
|
|
10
|
+
* - Absolute path: use as-is
|
|
11
|
+
* - Relative path starting with '.': resolve from current working directory
|
|
12
|
+
* 2. Default: ~/.memhub (user home directory)
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveStoragePath(): string;
|
|
7
15
|
/**
|
|
8
16
|
* Create McpServer instance using SDK
|
|
9
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":";AACA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":";AACA;;;GAGG;AAMH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AA+BnE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAc3C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CA0FxC"}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Uses @modelcontextprotocol/sdk for protocol handling
|
|
5
5
|
*/
|
|
6
6
|
import { readFileSync, existsSync } from 'fs';
|
|
7
|
-
import { join, dirname } from 'path';
|
|
7
|
+
import { join, dirname, resolve } from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
+
import { homedir } from 'os';
|
|
9
10
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
10
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
11
12
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
@@ -24,11 +25,31 @@ if (!existsSync(packageJsonPath)) {
|
|
|
24
25
|
packageJsonPath = join(__dirname, '../../package.json');
|
|
25
26
|
}
|
|
26
27
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
28
|
+
/**
|
|
29
|
+
* Resolve storage path with the following priority:
|
|
30
|
+
* 1. MEMHUB_STORAGE_PATH env var (if set):
|
|
31
|
+
* - Absolute path: use as-is
|
|
32
|
+
* - Relative path starting with '.': resolve from current working directory
|
|
33
|
+
* 2. Default: ~/.memhub (user home directory)
|
|
34
|
+
*/
|
|
35
|
+
export function resolveStoragePath() {
|
|
36
|
+
const envPath = process.env.MEMHUB_STORAGE_PATH;
|
|
37
|
+
if (envPath) {
|
|
38
|
+
// If it's an absolute path, use as-is
|
|
39
|
+
if (envPath.startsWith('/') || envPath.match(/^[A-Z]:\\/i)) {
|
|
40
|
+
return envPath;
|
|
41
|
+
}
|
|
42
|
+
// Relative path: resolve from current working directory
|
|
43
|
+
return resolve(process.cwd(), envPath);
|
|
44
|
+
}
|
|
45
|
+
// Default: ~/.memhub
|
|
46
|
+
return join(homedir(), '.memhub');
|
|
47
|
+
}
|
|
27
48
|
/**
|
|
28
49
|
* Create McpServer instance using SDK
|
|
29
50
|
*/
|
|
30
51
|
export function createMcpServer() {
|
|
31
|
-
const storagePath =
|
|
52
|
+
const storagePath = resolveStoragePath();
|
|
32
53
|
const vectorSearch = process.env.MEMHUB_VECTOR_SEARCH !== 'false';
|
|
33
54
|
const memoryService = new MemoryService({ storagePath, vectorSearch });
|
|
34
55
|
// Create server using SDK
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,E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IACjC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACtD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,2CAA2C;AAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC;AACxE,IAAI,MAAM,EAAE,CAAC;IACX,0DAA0D;IAC1D,YAAY,CAAC,GAAG,EAAE;QAChB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-service.d.ts","sourceRoot":"","sources":["../../../src/services/memory-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,aAAa,EAGb,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-service.d.ts","sourceRoot":"","sources":["../../../src/services/memory-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,aAAa,EAGb,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAmBlD;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAGnB,IAAI,EAAE,SAAS;aACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAF9C,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,SAAS,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKjD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAU;gBAElC,MAAM,EAAE,mBAAmB;IA2DvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAgB5B;;;OAGG;YACW,qBAAqB;IAanC;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAkC7D;;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