@synth-coder/memhub 0.2.3 → 0.2.4

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 (143) hide show
  1. package/.eslintrc.cjs +45 -45
  2. package/.factory/commands/opsx-apply.md +150 -150
  3. package/.factory/commands/opsx-archive.md +155 -155
  4. package/.factory/commands/opsx-explore.md +171 -171
  5. package/.factory/commands/opsx-propose.md +104 -104
  6. package/.factory/skills/openspec-apply-change/SKILL.md +156 -156
  7. package/.factory/skills/openspec-archive-change/SKILL.md +114 -114
  8. package/.factory/skills/openspec-explore/SKILL.md +288 -288
  9. package/.factory/skills/openspec-propose/SKILL.md +110 -110
  10. package/.github/workflows/ci.yml +110 -74
  11. package/.github/workflows/release.yml +67 -0
  12. package/.iflow/commands/opsx-apply.md +152 -152
  13. package/.iflow/commands/opsx-archive.md +157 -157
  14. package/.iflow/commands/opsx-explore.md +173 -173
  15. package/.iflow/commands/opsx-propose.md +106 -106
  16. package/.iflow/skills/openspec-apply-change/SKILL.md +156 -156
  17. package/.iflow/skills/openspec-archive-change/SKILL.md +114 -114
  18. package/.iflow/skills/openspec-explore/SKILL.md +288 -288
  19. package/.iflow/skills/openspec-propose/SKILL.md +110 -110
  20. package/.prettierrc +11 -11
  21. package/AGENTS.md +167 -169
  22. package/README.md +276 -195
  23. package/README.zh-CN.md +245 -193
  24. package/dist/src/cli/agents/claude-code.d.ts +5 -0
  25. package/dist/src/cli/agents/claude-code.d.ts.map +1 -0
  26. package/dist/src/cli/agents/claude-code.js +14 -0
  27. package/dist/src/cli/agents/claude-code.js.map +1 -0
  28. package/dist/src/cli/agents/cline.d.ts +5 -0
  29. package/dist/src/cli/agents/cline.d.ts.map +1 -0
  30. package/dist/src/cli/agents/cline.js +14 -0
  31. package/dist/src/cli/agents/cline.js.map +1 -0
  32. package/dist/src/cli/agents/codex.d.ts +5 -0
  33. package/dist/src/cli/agents/codex.d.ts.map +1 -0
  34. package/dist/src/cli/agents/codex.js +14 -0
  35. package/dist/src/cli/agents/codex.js.map +1 -0
  36. package/dist/src/cli/agents/cursor.d.ts +5 -0
  37. package/dist/src/cli/agents/cursor.d.ts.map +1 -0
  38. package/dist/src/cli/agents/cursor.js +14 -0
  39. package/dist/src/cli/agents/cursor.js.map +1 -0
  40. package/dist/src/cli/agents/factory-droid.d.ts +5 -0
  41. package/dist/src/cli/agents/factory-droid.d.ts.map +1 -0
  42. package/dist/src/cli/agents/factory-droid.js +14 -0
  43. package/dist/src/cli/agents/factory-droid.js.map +1 -0
  44. package/dist/src/cli/agents/gemini-cli.d.ts +5 -0
  45. package/dist/src/cli/agents/gemini-cli.d.ts.map +1 -0
  46. package/dist/src/cli/agents/gemini-cli.js +14 -0
  47. package/dist/src/cli/agents/gemini-cli.js.map +1 -0
  48. package/dist/src/cli/agents/index.d.ts +14 -0
  49. package/dist/src/cli/agents/index.d.ts.map +1 -0
  50. package/dist/src/cli/agents/index.js +30 -0
  51. package/dist/src/cli/agents/index.js.map +1 -0
  52. package/dist/src/cli/agents/windsurf.d.ts +5 -0
  53. package/dist/src/cli/agents/windsurf.d.ts.map +1 -0
  54. package/dist/src/cli/agents/windsurf.js +14 -0
  55. package/dist/src/cli/agents/windsurf.js.map +1 -0
  56. package/dist/src/cli/index.d.ts +8 -0
  57. package/dist/src/cli/index.d.ts.map +1 -0
  58. package/dist/src/cli/index.js +168 -0
  59. package/dist/src/cli/index.js.map +1 -0
  60. package/dist/src/cli/init.d.ts +34 -0
  61. package/dist/src/cli/init.d.ts.map +1 -0
  62. package/dist/src/cli/init.js +160 -0
  63. package/dist/src/cli/init.js.map +1 -0
  64. package/dist/src/cli/instructions.d.ts +29 -0
  65. package/dist/src/cli/instructions.d.ts.map +1 -0
  66. package/dist/src/cli/instructions.js +141 -0
  67. package/dist/src/cli/instructions.js.map +1 -0
  68. package/dist/src/cli/types.d.ts +22 -0
  69. package/dist/src/cli/types.d.ts.map +1 -0
  70. package/dist/src/cli/types.js +86 -0
  71. package/dist/src/cli/types.js.map +1 -0
  72. package/dist/src/contracts/mcp.js +34 -34
  73. package/dist/src/contracts/schemas.js.map +1 -1
  74. package/dist/src/server/mcp-server.d.ts.map +1 -1
  75. package/dist/src/server/mcp-server.js +7 -14
  76. package/dist/src/server/mcp-server.js.map +1 -1
  77. package/dist/src/services/embedding-service.d.ts.map +1 -1
  78. package/dist/src/services/embedding-service.js +1 -1
  79. package/dist/src/services/embedding-service.js.map +1 -1
  80. package/dist/src/services/memory-service.d.ts.map +1 -1
  81. package/dist/src/services/memory-service.js.map +1 -1
  82. package/dist/src/storage/markdown-storage.d.ts.map +1 -1
  83. package/dist/src/storage/markdown-storage.js +1 -1
  84. package/dist/src/storage/markdown-storage.js.map +1 -1
  85. package/dist/src/storage/vector-index.d.ts.map +1 -1
  86. package/dist/src/storage/vector-index.js +4 -5
  87. package/dist/src/storage/vector-index.js.map +1 -1
  88. package/docs/README.md +21 -0
  89. package/docs/mcp-tools.md +136 -0
  90. package/docs/user-guide.md +182 -0
  91. package/package.json +61 -59
  92. package/src/cli/agents/claude-code.ts +14 -0
  93. package/src/cli/agents/cline.ts +14 -0
  94. package/src/cli/agents/codex.ts +14 -0
  95. package/src/cli/agents/cursor.ts +14 -0
  96. package/src/cli/agents/factory-droid.ts +14 -0
  97. package/src/cli/agents/gemini-cli.ts +14 -0
  98. package/src/cli/agents/index.ts +36 -0
  99. package/src/cli/agents/windsurf.ts +14 -0
  100. package/src/cli/index.ts +192 -0
  101. package/src/cli/init.ts +218 -0
  102. package/src/cli/instructions.ts +156 -0
  103. package/src/cli/types.ts +112 -0
  104. package/src/contracts/index.ts +12 -12
  105. package/src/contracts/mcp.ts +223 -223
  106. package/src/contracts/schemas.ts +307 -307
  107. package/src/contracts/types.ts +410 -410
  108. package/src/index.ts +8 -8
  109. package/src/server/index.ts +5 -5
  110. package/src/server/mcp-server.ts +169 -186
  111. package/src/services/embedding-service.ts +114 -114
  112. package/src/services/index.ts +5 -5
  113. package/src/services/memory-service.ts +656 -663
  114. package/src/storage/frontmatter-parser.ts +243 -243
  115. package/src/storage/index.ts +6 -6
  116. package/src/storage/markdown-storage.ts +228 -236
  117. package/src/storage/vector-index.ts +159 -160
  118. package/src/utils/index.ts +5 -5
  119. package/src/utils/slugify.ts +63 -63
  120. package/test/cli/init.test.ts +380 -0
  121. package/test/contracts/schemas.test.ts +313 -313
  122. package/test/contracts/types.test.ts +21 -21
  123. package/test/frontmatter-parser-more.test.ts +94 -94
  124. package/test/server/mcp-server.test.ts +211 -210
  125. package/test/services/memory-service-edge.test.ts +248 -248
  126. package/test/services/memory-service.test.ts +291 -279
  127. package/test/storage/frontmatter-parser.test.ts +223 -223
  128. package/test/storage/markdown-storage.test.ts +226 -217
  129. package/test/storage/storage-edge.test.ts +238 -238
  130. package/test/storage/vector-index.test.ts +149 -153
  131. package/test/utils/slugify-edge.test.ts +94 -94
  132. package/test/utils/slugify.test.ts +72 -68
  133. package/tsconfig.json +25 -25
  134. package/tsconfig.test.json +8 -8
  135. package/vitest.config.ts +29 -29
  136. package/docs/architecture-diagrams.md +0 -368
  137. package/docs/architecture.md +0 -381
  138. package/docs/contracts.md +0 -190
  139. package/docs/prompt-template.md +0 -33
  140. package/docs/proposals/mcp-typescript-sdk-refactor.md +0 -568
  141. package/docs/proposals/proposal-close-gates.md +0 -58
  142. package/docs/tool-calling-policy.md +0 -101
  143. package/docs/vector-search.md +0 -306
package/README.md CHANGED
@@ -1,195 +1,276 @@
1
- # MemHub
2
-
3
- Git-friendly memory MCP server for coding agents.
4
-
5
- MemHub stores decisions, preferences, and reusable knowledge as plain Markdown files with YAML front matter, so everything is easy to review, diff, and version with Git.
6
-
7
- ---
8
-
9
- ## Why MemHub
10
-
11
- - **Git-native**: all memory is plain text files
12
- - **Agent-friendly**: exposed as MCP tools over stdio
13
- - **Human-readable**: YAML metadata + Markdown body
14
- - **Quality-gated**: lint + typecheck + tests + coverage gate
15
-
16
- ---
17
-
18
- ## Features
19
-
20
- - Markdown-based memory storage (`.md`)
21
- - YAML Front Matter metadata (`id`, `session_id`, `entry_type`, `tags`, `category`, `importance`, timestamps)
22
- - STM-first 2-tool interface: `memory_load` + `memory_update`
23
- - Concurrent CLI-safe storage layout: `YYYY-MM-DD/session_uuid/...`
24
- - MCP stdio server compatible with MCP clients
25
-
26
- ---
27
-
28
- ## Quick Start
29
-
30
- ### 1) Install from npm
31
-
32
- ```bash
33
- npm i @synth-coder/memhub
34
- ```
35
-
36
- ### 2) Or install dependencies for local development
37
-
38
- ```bash
39
- npm install
40
- ```
41
-
42
- ### 3) Build
43
-
44
- ```bash
45
- npm run build
46
- ```
47
-
48
- ### 4) Run quality gate
49
- ```bash
50
- npm run quality
51
- ```
52
-
53
- ---
54
-
55
- ## Use as MCP Server (stdio)
56
-
57
- ### Option A: run directly via npx (recommended)
58
-
59
- ```bash
60
- npx -y @synth-coder/memhub
61
- ```
62
-
63
- > On Windows, do **not** append `memhub` after the package name.
64
- > If a source `.js` file opens in editor, upgrade to latest package version (`0.1.2+`) and retry.
65
-
66
- Example MCP client config:
67
-
68
- ```json
69
- {
70
- "mcpServers": {
71
- "memhub": {
72
- "command": "npx",
73
- "args": ["-y", "@synth-coder/memhub"],
74
- "env": {
75
- "MEMHUB_STORAGE_PATH": "/absolute/path/to/memories",
76
- "MEMHUB_LOG_LEVEL": "info"
77
- }
78
- }
79
- }
80
- }
81
- ```
82
-
83
- ### Option B: local repo run
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
- ## Environment Variables
99
-
100
- - `MEMHUB_STORAGE_PATH` (default: `./memories`)
101
- - `MEMHUB_LOG_LEVEL` (default: `info`, options: `debug|info|warn|error`)
102
-
103
- ---
104
-
105
- ## Memory File Format
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 design
120
-
121
- Define tool contracts and schemas before implementation.
122
- ```
123
-
124
- Filename format:
125
-
126
- ```text
127
- YYYY-MM-DD-title-slug.md
128
- ```
129
-
130
- ---
131
-
132
- ## MCP Tools
133
-
134
- - `memory_load`
135
- First-turn tool. Load STM context for the current task/session.
136
- - `memory_update`
137
- Final-turn tool. Write back decisions, preferences, knowledge, and task-state updates.
138
-
139
- Calling policy: see `docs/tool-calling-policy.md`.
140
-
141
- ---
142
-
143
- ## Development
144
-
145
- ### Scripts
146
-
147
- ```bash
148
- npm run build
149
- npm run lint
150
- npm run typecheck
151
- npm run test
152
- npm run test:coverage
153
- npm run quality
154
- ```
155
-
156
- ### Engineering Workflow
157
-
158
- - Contract-first (types + schema first)
159
- - TDD (`red -> green -> refactor`)
160
- - Quality gate enforced before merge
161
- - Coverage threshold: **>= 80%**
162
-
163
- ---
164
-
165
- ## Project Structure
166
-
167
- ```text
168
- memhub/
169
- ├── docs/
170
- ├── src/
171
- │ ├── contracts/
172
- │ ├── server/
173
- │ ├── services/
174
- │ ├── storage/
175
- │ └── utils/
176
- ├── test/
177
- └── .github/workflows/
178
- ```
179
-
180
- ---
181
-
182
- ## Roadmap
183
-
184
- - [x] Architecture and contracts
185
- - [x] Core storage/service/server implementation
186
- - [x] Quality gate (lint/typecheck/test/coverage)
187
- - [ ] Integration tests
188
- - [ ] Performance improvements
189
- - [x] npm release (`@synth-coder/memhub@0.2.0`)
190
-
191
- ---
192
-
193
- ## License
194
-
195
- MIT
1
+ # MemHub
2
+
3
+ Git-friendly memory MCP server for coding agents.
4
+
5
+ ---
6
+
7
+ ## Quick Start
8
+
9
+ ### One-Line Setup
10
+
11
+ Configure MemHub for your AI agent with a single command:
12
+
13
+ ```bash
14
+ npx -y @synth-coder/memhub init
15
+ ```
16
+
17
+ This launches an interactive prompt to select your agent. MemHub will:
18
+ 1. Add MCP server config to your agent's configuration file
19
+ 2. Add MemHub usage instructions to your agent's rules file
20
+
21
+ **Supported Agents:**
22
+
23
+ | Agent | Config File | Instructions File |
24
+ |-------|-------------|-------------------|
25
+ | Claude Code | `~/.claude/settings.json` | `~/.claude/CLAUDE.md` |
26
+ | Cursor | `~/.cursor/mcp.json` | `~/.cursorrules` |
27
+ | Cline | `~/.cline/mcp.json` | `~/.clinerules` |
28
+ | Windsurf | `~/.codeium/windsurf/mcp_config.json` | `~/.windsurfrules` |
29
+ | Factory Droid | `~/.factory/mcp.json` | `~/.factory/AGENTS.md` |
30
+ | Gemini CLI | `~/.gemini/settings.json` | `~/.gemini/GEMINI.md` |
31
+ | Codex | `~/.codex/config.toml` | `~/.codex/AGENTS.md` |
32
+
33
+ ### CLI Options
34
+
35
+ ```bash
36
+ # Interactive selection (global - default)
37
+ npx -y @synth-coder/memhub init
38
+
39
+ # Skip interactive prompt
40
+ npx -y @synth-coder/memhub init -a claude-code
41
+
42
+ # Configure for current project only (local)
43
+ npx -y @synth-coder/memhub init -a cursor -l
44
+
45
+ # Update existing configuration
46
+ npx -y @synth-coder/memhub init -a claude-code --force
47
+ ```
48
+
49
+ | Option | Description |
50
+ |--------|-------------|
51
+ | `-a, --agent <name>` | Agent type (skip interactive) |
52
+ | `-l, --local` | Configure for current project (default: global) |
53
+ | `-f, --force` | Update existing configuration |
54
+
55
+ ### Run as MCP Server
56
+
57
+ ```bash
58
+ npx -y @synth-coder/memhub
59
+ ```
60
+
61
+ > On Windows, do **not** append `memhub` after the package name.
62
+
63
+ ### Manual Configuration
64
+
65
+ If you prefer manual setup, add this to your MCP client config:
66
+
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "memhub": {
71
+ "command": "npx",
72
+ "args": ["-y", "@synth-coder/memhub"],
73
+ "env": {
74
+ "MEMHUB_STORAGE_PATH": "/absolute/path/to/memories",
75
+ "MEMHUB_LOG_LEVEL": "info"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Configure Your Agent
85
+
86
+ Add the following to your coding agent's system prompt to enable persistent memory:
87
+
88
+ ```markdown
89
+ ## Memory System
90
+
91
+ You have access to persistent memory across conversations. Use it wisely:
92
+
93
+ - **Remember preferences** — Learn what the user likes and avoid repeating mistakes
94
+ - **Recall decisions** — Build on past reasoning instead of starting from scratch
95
+ - **Store context** — Project knowledge that survives session boundaries
96
+
97
+ ### When to Use
98
+
99
+ #### `memory_load`
100
+
101
+ Call when you need context from past conversations:
102
+ - User references something from before
103
+ - You're unsure about user preferences
104
+ - A decision needs historical context
105
+
106
+ Don't call for simple, self-contained tasks.
107
+
108
+ #### `memory_update`
109
+
110
+ Call when you discover something worth remembering:
111
+ - User expresses a preference
112
+ - You made a significant decision with reasoning
113
+ - Project context changed
114
+
115
+ Don't call for temporary or one-time information.
116
+
117
+ ### Principle
118
+
119
+ Memory should feel natural — triggered by context, not by schedule. When in doubt, ask: "Would future me benefit from knowing this?"
120
+ ```
121
+
122
+ ---
123
+
124
+ ## MCP Tools
125
+
126
+ - `memory_load`
127
+ First-turn tool. Load STM context for the current task/session.
128
+ - `memory_update`
129
+ Final-turn tool. Write back decisions, preferences, knowledge, and task-state updates.
130
+
131
+ See [docs/mcp-tools.md](docs/mcp-tools.md) for detailed API reference.
132
+
133
+ ---
134
+
135
+ ## Why MemHub
136
+
137
+ Most AI memory tools rely on external APIs or simple keyword matching. MemHub is different:
138
+
139
+ ### Semantic Search with Local AI
140
+
141
+ - **Vector Database**: Powered by LanceDB for fast similarity search
142
+ - **Local Embeddings**: Quantized Transformers.js model runs entirely on your machine
143
+ - **Zero API Costs**: No external services, no API keys, no rate limits
144
+ - **Privacy First**: Your memories never leave your computer
145
+
146
+ ### Git-Native Storage
147
+
148
+ - **Plain Text**: All memories are Markdown files with YAML front matter
149
+ - **Version Control**: Commit, branch, review, and revert like any code
150
+ - **Human Readable**: Browse and edit memories with any text editor
151
+ - **Team Friendly**: Share memories via git repository
152
+
153
+ ### How It Works
154
+
155
+ ```
156
+ User Query → Local Embedding Model → Vector Search → Ranked Results
157
+ ↑ ↓
158
+ Runs on CPU LanceDB Index
159
+ (no GPU required) (embedded database)
160
+ ```
161
+
162
+ When you call `memory_load`, MemHub:
163
+ 1. Converts your query to a vector using a local quantized model
164
+ 2. Searches the LanceDB index for semantically similar memories
165
+ 3. Returns ranked results with relevance scores
166
+
167
+ This means "testing framework preference" finds memories about "Vitest vs Jest decision" — even without exact keyword matches.
168
+
169
+ ---
170
+
171
+ ## Features
172
+
173
+ - **Semantic Search** — Vector-based similarity search with LanceDB
174
+ - **Local Embeddings** — Quantized Transformers.js model, runs on CPU
175
+ - **Markdown Storage** — Human-readable `.md` files with YAML front matter
176
+ - **Git-Friendly** — Version control, diff, review your memories
177
+ - **MCP Protocol** — Works with Claude Code, Cursor, Cline, Windsurf, and more
178
+ - **One-Line Setup** — `npx -y @synth-coder/memhub init`
179
+
180
+ ---
181
+
182
+ ## Environment Variables
183
+
184
+ - `MEMHUB_STORAGE_PATH` (default: `~/.memhub`)
185
+ - `MEMHUB_LOG_LEVEL` (default: `info`, options: `debug|info|warn|error`)
186
+
187
+ ---
188
+
189
+ ## Memory File Format
190
+
191
+ ```markdown
192
+ ---
193
+ id: "550e8400-e29b-41d4-a716-446655440000"
194
+ created_at: "2026-03-03T08:00:00.000Z"
195
+ updated_at: "2026-03-03T08:00:00.000Z"
196
+ tags:
197
+ - architecture
198
+ - tdd
199
+ category: "engineering"
200
+ importance: 4
201
+ ---
202
+
203
+ # Contract-first MCP design
204
+
205
+ Define tool contracts and schemas before implementation.
206
+ ```
207
+
208
+ Filename format:
209
+
210
+ ```text
211
+ YYYY-MM-DD-title-slug.md
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Development
217
+
218
+ ### Install & Build
219
+
220
+ ```bash
221
+ npx pnpm install
222
+ npx pnpm run build
223
+ ```
224
+
225
+ ### Scripts
226
+
227
+ ```bash
228
+ npx pnpm run build
229
+ npx pnpm run lint
230
+ npx pnpm run format
231
+ npx pnpm run typecheck
232
+ npx pnpm run test
233
+ npx pnpm run quality
234
+ ```
235
+
236
+ ### Engineering Workflow
237
+
238
+ - Contract-first (types + schema first)
239
+ - TDD (`red -> green -> refactor`)
240
+ - Quality gate enforced before merge
241
+ - Coverage threshold: **>= 80%**
242
+
243
+ ---
244
+
245
+ ## Project Structure
246
+
247
+ ```text
248
+ memhub/
249
+ ├── docs/
250
+ ├── src/
251
+ │ ├── contracts/
252
+ │ ├── server/
253
+ │ ├── services/
254
+ │ ├── storage/
255
+ │ └── utils/
256
+ ├── test/
257
+ └── .github/workflows/
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Roadmap
263
+
264
+ - [x] Architecture and contracts
265
+ - [x] Core storage/service/server implementation
266
+ - [x] Quality gate (lint/typecheck/test/coverage)
267
+ - [x] CLI init command for quick setup
268
+ - [ ] Integration tests
269
+ - [ ] Performance improvements
270
+ - [x] npm release (`@synth-coder/memhub@0.2.3`)
271
+
272
+ ---
273
+
274
+ ## License
275
+
276
+ MIT