@synth-coder/memhub 0.2.3 → 0.2.5

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 (118) hide show
  1. package/.github/workflows/ci.yml +48 -12
  2. package/.github/workflows/release.yml +70 -0
  3. package/AGENTS.md +71 -73
  4. package/README.md +284 -195
  5. package/README.zh-CN.md +90 -30
  6. package/dist/src/cli/agents/claude-code.d.ts +5 -0
  7. package/dist/src/cli/agents/claude-code.d.ts.map +1 -0
  8. package/dist/src/cli/agents/claude-code.js +14 -0
  9. package/dist/src/cli/agents/claude-code.js.map +1 -0
  10. package/dist/src/cli/agents/cline.d.ts +5 -0
  11. package/dist/src/cli/agents/cline.d.ts.map +1 -0
  12. package/dist/src/cli/agents/cline.js +14 -0
  13. package/dist/src/cli/agents/cline.js.map +1 -0
  14. package/dist/src/cli/agents/cursor.d.ts +5 -0
  15. package/dist/src/cli/agents/cursor.d.ts.map +1 -0
  16. package/dist/src/cli/agents/cursor.js +14 -0
  17. package/dist/src/cli/agents/cursor.js.map +1 -0
  18. package/dist/src/cli/agents/factory-droid.d.ts +5 -0
  19. package/dist/src/cli/agents/factory-droid.d.ts.map +1 -0
  20. package/dist/src/cli/agents/factory-droid.js +14 -0
  21. package/dist/src/cli/agents/factory-droid.js.map +1 -0
  22. package/dist/src/cli/agents/gemini-cli.d.ts +5 -0
  23. package/dist/src/cli/agents/gemini-cli.d.ts.map +1 -0
  24. package/dist/src/cli/agents/gemini-cli.js +14 -0
  25. package/dist/src/cli/agents/gemini-cli.js.map +1 -0
  26. package/dist/src/cli/agents/index.d.ts +13 -0
  27. package/dist/src/cli/agents/index.d.ts.map +1 -0
  28. package/dist/src/cli/agents/index.js +27 -0
  29. package/dist/src/cli/agents/index.js.map +1 -0
  30. package/dist/src/cli/agents/windsurf.d.ts +5 -0
  31. package/dist/src/cli/agents/windsurf.d.ts.map +1 -0
  32. package/dist/src/cli/agents/windsurf.js +14 -0
  33. package/dist/src/cli/agents/windsurf.js.map +1 -0
  34. package/dist/src/cli/index.d.ts +8 -0
  35. package/dist/src/cli/index.d.ts.map +1 -0
  36. package/dist/src/cli/index.js +168 -0
  37. package/dist/src/cli/index.js.map +1 -0
  38. package/dist/src/cli/init.d.ts +34 -0
  39. package/dist/src/cli/init.d.ts.map +1 -0
  40. package/dist/src/cli/init.js +140 -0
  41. package/dist/src/cli/init.js.map +1 -0
  42. package/dist/src/cli/instructions.d.ts +29 -0
  43. package/dist/src/cli/instructions.d.ts.map +1 -0
  44. package/dist/src/cli/instructions.js +141 -0
  45. package/dist/src/cli/instructions.js.map +1 -0
  46. package/dist/src/cli/types.d.ts +22 -0
  47. package/dist/src/cli/types.d.ts.map +1 -0
  48. package/dist/src/cli/types.js +75 -0
  49. package/dist/src/cli/types.js.map +1 -0
  50. package/dist/src/contracts/mcp.js +34 -34
  51. package/dist/src/contracts/schemas.js.map +1 -1
  52. package/dist/src/server/mcp-server.d.ts.map +1 -1
  53. package/dist/src/server/mcp-server.js +7 -14
  54. package/dist/src/server/mcp-server.js.map +1 -1
  55. package/dist/src/services/embedding-service.d.ts.map +1 -1
  56. package/dist/src/services/embedding-service.js +1 -1
  57. package/dist/src/services/embedding-service.js.map +1 -1
  58. package/dist/src/services/memory-service.d.ts.map +1 -1
  59. package/dist/src/services/memory-service.js.map +1 -1
  60. package/dist/src/storage/markdown-storage.d.ts.map +1 -1
  61. package/dist/src/storage/markdown-storage.js +1 -1
  62. package/dist/src/storage/markdown-storage.js.map +1 -1
  63. package/dist/src/storage/vector-index.d.ts.map +1 -1
  64. package/dist/src/storage/vector-index.js +4 -5
  65. package/dist/src/storage/vector-index.js.map +1 -1
  66. package/docs/README.md +21 -0
  67. package/docs/mcp-tools.md +136 -0
  68. package/docs/user-guide.md +184 -0
  69. package/package.json +61 -59
  70. package/src/cli/agents/claude-code.ts +14 -0
  71. package/src/cli/agents/cline.ts +14 -0
  72. package/src/cli/agents/codex.ts +14 -0
  73. package/src/cli/agents/cursor.ts +14 -0
  74. package/src/cli/agents/factory-droid.ts +14 -0
  75. package/src/cli/agents/gemini-cli.ts +14 -0
  76. package/src/cli/agents/index.ts +36 -0
  77. package/src/cli/agents/windsurf.ts +14 -0
  78. package/src/cli/index.ts +192 -0
  79. package/src/cli/init.ts +218 -0
  80. package/src/cli/instructions.ts +156 -0
  81. package/src/cli/types.ts +112 -0
  82. package/src/contracts/index.ts +12 -12
  83. package/src/contracts/mcp.ts +223 -223
  84. package/src/contracts/schemas.ts +307 -307
  85. package/src/contracts/types.ts +410 -410
  86. package/src/index.ts +8 -8
  87. package/src/server/index.ts +5 -5
  88. package/src/server/mcp-server.ts +169 -186
  89. package/src/services/embedding-service.ts +114 -114
  90. package/src/services/index.ts +5 -5
  91. package/src/services/memory-service.ts +656 -663
  92. package/src/storage/frontmatter-parser.ts +243 -243
  93. package/src/storage/index.ts +6 -6
  94. package/src/storage/markdown-storage.ts +228 -236
  95. package/src/storage/vector-index.ts +159 -160
  96. package/src/utils/index.ts +5 -5
  97. package/src/utils/slugify.ts +63 -63
  98. package/test/cli/init.test.ts +402 -0
  99. package/test/contracts/schemas.test.ts +313 -313
  100. package/test/contracts/types.test.ts +21 -21
  101. package/test/frontmatter-parser-more.test.ts +94 -94
  102. package/test/server/mcp-server.test.ts +211 -210
  103. package/test/services/memory-service-edge.test.ts +248 -248
  104. package/test/services/memory-service.test.ts +291 -279
  105. package/test/storage/frontmatter-parser.test.ts +223 -223
  106. package/test/storage/markdown-storage.test.ts +226 -217
  107. package/test/storage/storage-edge.test.ts +238 -238
  108. package/test/storage/vector-index.test.ts +149 -153
  109. package/test/utils/slugify-edge.test.ts +94 -94
  110. package/test/utils/slugify.test.ts +72 -68
  111. package/docs/architecture-diagrams.md +0 -368
  112. package/docs/architecture.md +0 -381
  113. package/docs/contracts.md +0 -190
  114. package/docs/prompt-template.md +0 -33
  115. package/docs/proposals/mcp-typescript-sdk-refactor.md +0 -568
  116. package/docs/proposals/proposal-close-gates.md +0 -58
  117. package/docs/tool-calling-policy.md +0 -101
  118. package/docs/vector-search.md +0 -306
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [18.x, 20.x]
16
+ node-version: [20.x, 22.x]
17
17
 
18
18
  steps:
19
19
  - name: Checkout repository
@@ -23,22 +23,40 @@ jobs:
23
23
  uses: actions/setup-node@v4
24
24
  with:
25
25
  node-version: ${{ matrix.node-version }}
26
- cache: 'npm'
26
+
27
+ - name: Setup pnpm
28
+ uses: pnpm/action-setup@v4
29
+ with:
30
+ version: 9
31
+
32
+ - name: Get pnpm store directory
33
+ shell: bash
34
+ run: |
35
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
36
+ id: pnpm-cache
37
+
38
+ - name: Setup pnpm cache
39
+ uses: actions/cache@v4
40
+ with:
41
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
42
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43
+ restore-keys: |
44
+ ${{ runner.os }}-pnpm-store-
27
45
 
28
46
  - name: Install dependencies
29
- run: npm ci
47
+ run: pnpm install --frozen-lockfile
30
48
 
31
49
  - name: Run linter
32
- run: npm run lint
50
+ run: pnpm run lint
33
51
 
34
52
  - name: Check formatting
35
- run: npm run format:check
53
+ run: pnpm run format:check
36
54
 
37
55
  - name: Run type check
38
- run: npm run typecheck
56
+ run: pnpm run typecheck
39
57
 
40
58
  - name: Run tests with coverage
41
- run: npm run test:coverage
59
+ run: pnpm run test:coverage
42
60
 
43
61
  - name: Upload coverage reports
44
62
  uses: codecov/codecov-action@v3
@@ -60,15 +78,33 @@ jobs:
60
78
  uses: actions/setup-node@v4
61
79
  with:
62
80
  node-version: 20.x
63
- cache: 'npm'
81
+
82
+ - name: Setup pnpm
83
+ uses: pnpm/action-setup@v4
84
+ with:
85
+ version: 9
86
+
87
+ - name: Get pnpm store directory
88
+ shell: bash
89
+ run: |
90
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
91
+ id: pnpm-cache
92
+
93
+ - name: Setup pnpm cache
94
+ uses: actions/cache@v4
95
+ with:
96
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
97
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
98
+ restore-keys: |
99
+ ${{ runner.os }}-pnpm-store-
64
100
 
65
101
  - name: Install dependencies
66
- run: npm ci
102
+ run: pnpm install --frozen-lockfile
67
103
 
68
104
  - name: Build project
69
- run: npm run build
105
+ run: pnpm run build
70
106
 
71
107
  - name: Check build output
72
108
  run: |
73
- test -f dist/index.js
74
- test -f dist/server/mcp-server.js
109
+ test -f dist/src/index.js
110
+ test -f dist/src/server/mcp-server.js
@@ -0,0 +1,70 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ quality:
13
+ name: Quality Gate
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Setup Node.js
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: 20.x
24
+
25
+ - name: Setup pnpm
26
+ uses: pnpm/action-setup@v4
27
+ with:
28
+ version: 9
29
+
30
+ - name: Install dependencies
31
+ run: pnpm install --frozen-lockfile
32
+
33
+ - name: Run quality gate
34
+ run: pnpm run quality
35
+
36
+ publish:
37
+ name: Publish to npm
38
+ runs-on: ubuntu-latest
39
+ needs: quality
40
+
41
+ steps:
42
+ - name: Checkout repository
43
+ uses: actions/checkout@v4
44
+
45
+ - name: Setup Node.js
46
+ uses: actions/setup-node@v4
47
+ with:
48
+ node-version: 20.x
49
+ registry-url: 'https://registry.npmjs.org'
50
+
51
+ - name: Setup pnpm
52
+ uses: pnpm/action-setup@v4
53
+ with:
54
+ version: 9
55
+
56
+ - name: Install dependencies
57
+ run: pnpm install --frozen-lockfile
58
+
59
+ - name: Build
60
+ run: pnpm run build
61
+
62
+ - name: Publish to npm
63
+ run: pnpm publish --no-git-checks
64
+ env:
65
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66
+
67
+ - name: Create GitHub Release
68
+ uses: softprops/action-gh-release@v1
69
+ with:
70
+ generate_release_notes: true
package/AGENTS.md CHANGED
@@ -6,38 +6,36 @@ MemHub is a Git-friendly memory MCP server for coding agents. It stores decision
6
6
 
7
7
  **Tech Stack**: TypeScript (ES2022), Node.js 18+, MCP SDK, Zod, LanceDB, Transformers.js
8
8
 
9
+ ---
10
+
9
11
  ## Dev Environment
10
12
 
11
13
  ```bash
12
- # Install dependencies
13
- pnpm install
14
-
15
- # Build
16
- pnpm run build
17
-
18
- # Quality gate (lint + typecheck + test + coverage)
19
- pnpm run quality
14
+ npx pnpm install # Install dependencies
15
+ npx pnpm run build # Compile TypeScript
16
+ npx pnpm run quality # Quality gate (lint + typecheck + test + coverage)
20
17
  ```
21
18
 
22
- ## Key Commands
23
-
24
19
  | Command | Description |
25
20
  |---------|-------------|
26
- | `pnpm run build` | Compile TypeScript |
27
- | `pnpm run lint` | ESLint check |
28
- | `pnpm run lint:fix` | Auto-fix lint issues |
29
- | `pnpm run typecheck` | TypeScript type check |
30
- | `pnpm run test` | Run Vitest tests |
31
- | `pnpm run test:watch` | Watch mode tests |
32
- | `pnpm run test:coverage` | Tests with coverage |
33
- | `pnpm run quality` | Full quality gate |
34
- | `pnpm vitest run -t "test name"` | Run specific test |
21
+ | `npx pnpm run build` | Compile TypeScript |
22
+ | `npx pnpm run lint` | ESLint check |
23
+ | `npx pnpm run lint:fix` | Auto-fix lint issues |
24
+ | `npx pnpm run format` | Format code with Prettier |
25
+ | `npx pnpm run typecheck` | TypeScript type check |
26
+ | `npx pnpm run test` | Run Vitest tests |
27
+ | `npx pnpm run test:coverage` | Tests with coverage |
28
+ | `npx pnpm run quality` | Full quality gate |
29
+ | `npx pnpm vitest run -t "test name"` | Run specific test |
30
+
31
+ ---
35
32
 
36
33
  ## Project Structure
37
34
 
38
35
  ```
39
36
  src/
40
37
  contracts/ # Type definitions, Zod schemas, MCP contracts
38
+ cli/ # CLI commands (init, etc.)
41
39
  server/ # MCP stdio server entry point
42
40
  services/ # Business logic (MemoryService, EmbeddingService)
43
41
  storage/ # Storage layer (Markdown, VectorIndex)
@@ -46,9 +44,11 @@ test/ # Vitest unit tests mirroring src/ structure
46
44
  docs/ # Documentation
47
45
  ```
48
46
 
49
- ## Coding Conventions
47
+ ---
48
+
49
+ ## Coding Style
50
50
 
51
- ### TypeScript Style
51
+ ### TypeScript Conventions
52
52
  - Use `readonly` for immutable fields in interfaces
53
53
  - Use `type` for aliases, `interface` for object shapes
54
54
  - Prefer `import type` for type-only imports
@@ -60,11 +60,6 @@ docs/ # Documentation
60
60
  - `kebab-case.ts` for all files
61
61
  - Test files: `<module>.test.ts` or `<module>-edge.test.ts`
62
62
 
63
- ### Code Organization
64
- - Contracts first: define types and schemas before implementation
65
- - TDD workflow: red → green → refactor
66
- - One export per file preferred; barrel exports in `index.ts`
67
-
68
63
  ### Example Code Style
69
64
 
70
65
  ```typescript
@@ -90,67 +85,79 @@ export const MemorySchema = z.object({
90
85
  });
91
86
  ```
92
87
 
93
- ## Testing Guidelines
88
+ ---
94
89
 
95
- - Test coverage threshold: **>= 80%**
96
- - Tests mirror `src/` structure in `test/` directory
97
- - Use Vitest: `describe`, `it`, `expect` pattern
98
- - Edge cases go in `*-edge.test.ts` files
99
- - Run `pnpm run quality` before committing
90
+ ## Workflows
100
91
 
101
- ## Documentation Guidelines
92
+ ### Add New MCP Tool
102
93
 
103
- 文档是代码契约的一部分,必须与实现保持同步。
94
+ 1. **Define types** → `src/contracts/types.ts`
95
+ 2. **Define schema** → `src/contracts/schemas.ts`
96
+ 3. **Register tool** → `src/contracts/mcp.ts`
97
+ 4. **Implement logic** → `src/services/memory-service.ts`
98
+ 5. **Add tests** → `test/services/memory-service.test.ts`
99
+ 6. **Update docs** → `docs/mcp-tools.md`
100
+ 7. **Run quality gate** → `npx pnpm run quality`
104
101
 
105
- ### 何时更新文档
102
+ ### Support New Agent
106
103
 
107
- **必须更新文档的场景:**
104
+ 1. **Add agent type** → `src/cli/types.ts` (AgentType union)
105
+ 2. **Create agent config** → `src/cli/agents/<agent-name>.ts`
106
+ 3. **Register in init** → `src/cli/init.ts` (AGENT_CONFIGS map)
107
+ 4. **Add tests** → `test/cli/init.test.ts`
108
+ 5. **Update docs** → `docs/user-guide.md` (supported agents table)
109
+ 6. **Update README** → `README.md` and `README.zh-CN.md`
110
+ 7. **Run quality gate** → `npx pnpm run quality`
108
111
 
109
- 1. **接口变更** 新增、修改、删除 MCP 工具参数或返回值
110
- 2. **类型定义变更** — 修改 `src/contracts/types.ts` 中的类型
111
- 3. **Schema 变更** — 修改 `src/contracts/schemas.ts` 中的 Zod schema
112
- 4. **行为变更** — 工具的调用逻辑、错误处理、默认值发生变化
113
- 5. **版本发布** — package.json 版本号变更时,同步更新 README 中的版本引用
112
+ ### Release New Version
114
113
 
115
- **文档与代码的对应关系:**
114
+ 1. **Update version** → `package.json`
115
+ 2. **Update Roadmap** → `README.md` (mark released items)
116
+ 3. **Run quality gate** → `npx pnpm run quality`
117
+ 4. **Commit & tag** → `git commit && git tag v<x.y.z>`
118
+ 5. **Publish** → `npm publish`
116
119
 
117
- | 代码文件 | 对应文档 |
118
- |---------|---------|
119
- | `src/contracts/types.ts` | `docs/contracts.md`、`docs/architecture.md` |
120
- | `src/contracts/schemas.ts` | `docs/contracts.md` |
121
- | `src/contracts/mcp.ts` | `docs/contracts.md`、`docs/tool-calling-policy.md` |
122
- | `package.json` (version) | `README.md` (Roadmap) |
120
+ ---
123
121
 
124
- ### 文档更新流程
122
+ ## Documentation Sync
125
123
 
126
- 1. 修改代码后,检查相关文档是否需要同步
127
- 2. 对照代码实现校对文档描述
128
- 3. 移除文档中不存在于代码的参数/字段
129
- 4. 补充文档中缺失的新增参数/字段
130
- 5. 确保示例代码与实际类型定义一致
124
+ Documentation must stay in sync with code. **Update docs when changing:**
131
125
 
132
- ### 验证方法
126
+ | Code Change | Update Doc |
127
+ |-------------|------------|
128
+ | MCP tool parameters/returns | `docs/mcp-tools.md` |
129
+ | CLI options/behavior | `docs/user-guide.md` |
130
+ | New agent support | `docs/user-guide.md`, `README.md` |
131
+ | Version number | `README.md` Roadmap |
133
132
 
134
- ```bash
135
- # 对比代码中的类型定义与文档描述
136
- grep -A 20 "interface MemoryLoadInput" src/contracts/types.ts
137
- grep -A 20 "MemoryLoadInput" docs/contracts.md
138
- ```
133
+ ---
134
+
135
+ ## Testing Guidelines
136
+
137
+ - **Coverage threshold**: >= 80%
138
+ - Tests mirror `src/` structure in `test/` directory
139
+ - Use Vitest: `describe`, `it`, `expect` pattern
140
+ - Edge cases go in `*-edge.test.ts` files
141
+ - Run `npx pnpm run quality` before committing
142
+
143
+ ---
139
144
 
140
145
  ## Git Workflow
141
146
 
142
- - Commit message format: `type: description` (feat/fix/docs/chore/refactor/test)
147
+ - Commit message: `type: description` (feat/fix/docs/chore/refactor/test)
143
148
  - Always run quality gate before committing
144
- - PR title format: `[scope] Description`
149
+ - PR title: `[scope] Description`
150
+
151
+ ---
145
152
 
146
153
  ## Dos and Don'ts
147
154
 
148
155
  ### Do
149
- - Run `pnpm run quality` before committing
156
+ - Run `npx pnpm run quality` before committing
150
157
  - Add tests for new code
151
158
  - Use `import type` for type-only imports
152
159
  - Keep functions small and focused
153
- - Update types and schemas together
160
+ - Update types, schemas, and docs together
154
161
 
155
162
  ### Don't
156
163
  - Skip the quality gate
@@ -158,12 +165,3 @@ grep -A 20 "MemoryLoadInput" docs/contracts.md
158
165
  - Mutate function parameters
159
166
  - Add code without corresponding tests
160
167
  - Commit directly to main (use branches for features)
161
-
162
- ## MCP Tool Reference
163
-
164
- MemHub exposes two primary tools:
165
-
166
- 1. **memory_load** - First-turn tool to load STM context
167
- 2. **memory_update** - Final-turn tool to write back decisions/knowledge
168
-
169
- See `docs/tool-calling-policy.md` for detailed usage patterns.