@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
@@ -1,110 +1,110 @@
1
- ---
2
- name: openspec-propose
3
- description: Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
4
- license: MIT
5
- compatibility: Requires openspec CLI.
6
- metadata:
7
- author: openspec
8
- version: "1.0"
9
- generatedBy: "1.2.0"
10
- ---
11
-
12
- Propose a new change - create the change and generate all artifacts in one step.
13
-
14
- I'll create a change with artifacts:
15
- - proposal.md (what & why)
16
- - design.md (how)
17
- - tasks.md (implementation steps)
18
-
19
- When ready to implement, run /opsx:apply
20
-
21
- ---
22
-
23
- **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
24
-
25
- **Steps**
26
-
27
- 1. **If no clear input provided, ask what they want to build**
28
-
29
- Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
30
- > "What change do you want to work on? Describe what you want to build or fix."
31
-
32
- From their description, derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
33
-
34
- **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
35
-
36
- 2. **Create the change directory**
37
- ```bash
38
- openspec new change "<name>"
39
- ```
40
- This creates a scaffolded change at `openspec/changes/<name>/` with `.openspec.yaml`.
41
-
42
- 3. **Get the artifact build order**
43
- ```bash
44
- openspec status --change "<name>" --json
45
- ```
46
- Parse the JSON to get:
47
- - `applyRequires`: array of artifact IDs needed before implementation (e.g., `["tasks"]`)
48
- - `artifacts`: list of all artifacts with their status and dependencies
49
-
50
- 4. **Create artifacts in sequence until apply-ready**
51
-
52
- Use the **TodoWrite tool** to track progress through the artifacts.
53
-
54
- Loop through artifacts in dependency order (artifacts with no pending dependencies first):
55
-
56
- a. **For each artifact that is `ready` (dependencies satisfied)**:
57
- - Get instructions:
58
- ```bash
59
- openspec instructions <artifact-id> --change "<name>" --json
60
- ```
61
- - The instructions JSON includes:
62
- - `context`: Project background (constraints for you - do NOT include in output)
63
- - `rules`: Artifact-specific rules (constraints for you - do NOT include in output)
64
- - `template`: The structure to use for your output file
65
- - `instruction`: Schema-specific guidance for this artifact type
66
- - `outputPath`: Where to write the artifact
67
- - `dependencies`: Completed artifacts to read for context
68
- - Read any completed dependency files for context
69
- - Create the artifact file using `template` as the structure
70
- - Apply `context` and `rules` as constraints - but do NOT copy them into the file
71
- - Show brief progress: "Created <artifact-id>"
72
-
73
- b. **Continue until all `applyRequires` artifacts are complete**
74
- - After creating each artifact, re-run `openspec status --change "<name>" --json`
75
- - Check if every artifact ID in `applyRequires` has `status: "done"` in the artifacts array
76
- - Stop when all `applyRequires` artifacts are done
77
-
78
- c. **If an artifact requires user input** (unclear context):
79
- - Use **AskUserQuestion tool** to clarify
80
- - Then continue with creation
81
-
82
- 5. **Show final status**
83
- ```bash
84
- openspec status --change "<name>"
85
- ```
86
-
87
- **Output**
88
-
89
- After completing all artifacts, summarize:
90
- - Change name and location
91
- - List of artifacts created with brief descriptions
92
- - What's ready: "All artifacts created! Ready for implementation."
93
- - Prompt: "Run `/opsx:apply` or ask me to implement to start working on the tasks."
94
-
95
- **Artifact Creation Guidelines**
96
-
97
- - Follow the `instruction` field from `openspec instructions` for each artifact type
98
- - The schema defines what each artifact should contain - follow it
99
- - Read dependency artifacts for context before creating new ones
100
- - Use `template` as the structure for your output file - fill in its sections
101
- - **IMPORTANT**: `context` and `rules` are constraints for YOU, not content for the file
102
- - Do NOT copy `<context>`, `<rules>`, `<project_context>` blocks into the artifact
103
- - These guide what you write, but should never appear in the output
104
-
105
- **Guardrails**
106
- - Create ALL artifacts needed for implementation (as defined by schema's `apply.requires`)
107
- - Always read dependency artifacts before creating a new one
108
- - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
109
- - If a change with that name already exists, ask if user wants to continue it or create a new one
110
- - Verify each artifact file exists after writing before proceeding to next
1
+ ---
2
+ name: openspec-propose
3
+ description: Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
4
+ license: MIT
5
+ compatibility: Requires openspec CLI.
6
+ metadata:
7
+ author: openspec
8
+ version: "1.0"
9
+ generatedBy: "1.2.0"
10
+ ---
11
+
12
+ Propose a new change - create the change and generate all artifacts in one step.
13
+
14
+ I'll create a change with artifacts:
15
+ - proposal.md (what & why)
16
+ - design.md (how)
17
+ - tasks.md (implementation steps)
18
+
19
+ When ready to implement, run /opsx:apply
20
+
21
+ ---
22
+
23
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
24
+
25
+ **Steps**
26
+
27
+ 1. **If no clear input provided, ask what they want to build**
28
+
29
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
30
+ > "What change do you want to work on? Describe what you want to build or fix."
31
+
32
+ From their description, derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
33
+
34
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
35
+
36
+ 2. **Create the change directory**
37
+ ```bash
38
+ openspec new change "<name>"
39
+ ```
40
+ This creates a scaffolded change at `openspec/changes/<name>/` with `.openspec.yaml`.
41
+
42
+ 3. **Get the artifact build order**
43
+ ```bash
44
+ openspec status --change "<name>" --json
45
+ ```
46
+ Parse the JSON to get:
47
+ - `applyRequires`: array of artifact IDs needed before implementation (e.g., `["tasks"]`)
48
+ - `artifacts`: list of all artifacts with their status and dependencies
49
+
50
+ 4. **Create artifacts in sequence until apply-ready**
51
+
52
+ Use the **TodoWrite tool** to track progress through the artifacts.
53
+
54
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
55
+
56
+ a. **For each artifact that is `ready` (dependencies satisfied)**:
57
+ - Get instructions:
58
+ ```bash
59
+ openspec instructions <artifact-id> --change "<name>" --json
60
+ ```
61
+ - The instructions JSON includes:
62
+ - `context`: Project background (constraints for you - do NOT include in output)
63
+ - `rules`: Artifact-specific rules (constraints for you - do NOT include in output)
64
+ - `template`: The structure to use for your output file
65
+ - `instruction`: Schema-specific guidance for this artifact type
66
+ - `outputPath`: Where to write the artifact
67
+ - `dependencies`: Completed artifacts to read for context
68
+ - Read any completed dependency files for context
69
+ - Create the artifact file using `template` as the structure
70
+ - Apply `context` and `rules` as constraints - but do NOT copy them into the file
71
+ - Show brief progress: "Created <artifact-id>"
72
+
73
+ b. **Continue until all `applyRequires` artifacts are complete**
74
+ - After creating each artifact, re-run `openspec status --change "<name>" --json`
75
+ - Check if every artifact ID in `applyRequires` has `status: "done"` in the artifacts array
76
+ - Stop when all `applyRequires` artifacts are done
77
+
78
+ c. **If an artifact requires user input** (unclear context):
79
+ - Use **AskUserQuestion tool** to clarify
80
+ - Then continue with creation
81
+
82
+ 5. **Show final status**
83
+ ```bash
84
+ openspec status --change "<name>"
85
+ ```
86
+
87
+ **Output**
88
+
89
+ After completing all artifacts, summarize:
90
+ - Change name and location
91
+ - List of artifacts created with brief descriptions
92
+ - What's ready: "All artifacts created! Ready for implementation."
93
+ - Prompt: "Run `/opsx:apply` or ask me to implement to start working on the tasks."
94
+
95
+ **Artifact Creation Guidelines**
96
+
97
+ - Follow the `instruction` field from `openspec instructions` for each artifact type
98
+ - The schema defines what each artifact should contain - follow it
99
+ - Read dependency artifacts for context before creating new ones
100
+ - Use `template` as the structure for your output file - fill in its sections
101
+ - **IMPORTANT**: `context` and `rules` are constraints for YOU, not content for the file
102
+ - Do NOT copy `<context>`, `<rules>`, `<project_context>` blocks into the artifact
103
+ - These guide what you write, but should never appear in the output
104
+
105
+ **Guardrails**
106
+ - Create ALL artifacts needed for implementation (as defined by schema's `apply.requires`)
107
+ - Always read dependency artifacts before creating a new one
108
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
109
+ - If a change with that name already exists, ask if user wants to continue it or create a new one
110
+ - Verify each artifact file exists after writing before proceeding to next
package/.prettierrc CHANGED
@@ -1,11 +1,11 @@
1
- {
2
- "semi": true,
3
- "trailingComma": "es5",
4
- "singleQuote": true,
5
- "printWidth": 100,
6
- "tabWidth": 2,
7
- "useTabs": false,
8
- "bracketSpacing": true,
9
- "arrowParens": "avoid",
10
- "endOfLine": "lf"
11
- }
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": true,
5
+ "printWidth": 100,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "bracketSpacing": true,
9
+ "arrowParens": "avoid",
10
+ "endOfLine": "lf"
11
+ }
package/AGENTS.md CHANGED
@@ -1,169 +1,167 @@
1
- # AGENTS.md - MemHub Project Guide
2
-
3
- ## Project Overview
4
-
5
- MemHub is a Git-friendly memory MCP server for coding agents. It stores decisions, preferences, and reusable knowledge as plain Markdown files with YAML front matter.
6
-
7
- **Tech Stack**: TypeScript (ES2022), Node.js 18+, MCP SDK, Zod, LanceDB, Transformers.js
8
-
9
- ## Dev Environment
10
-
11
- ```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
20
- ```
21
-
22
- ## Key Commands
23
-
24
- | Command | Description |
25
- |---------|-------------|
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 |
35
-
36
- ## Project Structure
37
-
38
- ```
39
- src/
40
- contracts/ # Type definitions, Zod schemas, MCP contracts
41
- server/ # MCP stdio server entry point
42
- services/ # Business logic (MemoryService, EmbeddingService)
43
- storage/ # Storage layer (Markdown, VectorIndex)
44
- utils/ # Shared utilities (slugify, etc.)
45
- test/ # Vitest unit tests mirroring src/ structure
46
- docs/ # Documentation
47
- ```
48
-
49
- ## Coding Conventions
50
-
51
- ### TypeScript Style
52
- - Use `readonly` for immutable fields in interfaces
53
- - Use `type` for aliases, `interface` for object shapes
54
- - Prefer `import type` for type-only imports
55
- - Use ESM: `.js` extension in imports, `verbatimModuleSyntax`
56
- - Explicit return types on exported functions
57
- - Use Zod for runtime validation
58
-
59
- ### File Naming
60
- - `kebab-case.ts` for all files
61
- - Test files: `<module>.test.ts` or `<module>-edge.test.ts`
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
- ### Example Code Style
69
-
70
- ```typescript
71
- // Types with readonly fields
72
- export interface Memory {
73
- readonly id: UUID;
74
- readonly tags: readonly string[];
75
- }
76
-
77
- // Service with explicit types
78
- export class MemoryService {
79
- constructor(private readonly config: MemoryServiceConfig) {}
80
-
81
- async create(input: CreateMemoryInput): Promise<CreateResult> {
82
- // implementation
83
- }
84
- }
85
-
86
- // Zod schema for validation
87
- export const MemorySchema = z.object({
88
- id: z.string().uuid(),
89
- tags: z.array(z.string()),
90
- });
91
- ```
92
-
93
- ## Testing Guidelines
94
-
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
100
-
101
- ## Documentation Guidelines
102
-
103
- 文档是代码契约的一部分,必须与实现保持同步。
104
-
105
- ### 何时更新文档
106
-
107
- **必须更新文档的场景:**
108
-
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 中的版本引用
114
-
115
- **文档与代码的对应关系:**
116
-
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) |
123
-
124
- ### 文档更新流程
125
-
126
- 1. 修改代码后,检查相关文档是否需要同步
127
- 2. 对照代码实现校对文档描述
128
- 3. 移除文档中不存在于代码的参数/字段
129
- 4. 补充文档中缺失的新增参数/字段
130
- 5. 确保示例代码与实际类型定义一致
131
-
132
- ### 验证方法
133
-
134
- ```bash
135
- # 对比代码中的类型定义与文档描述
136
- grep -A 20 "interface MemoryLoadInput" src/contracts/types.ts
137
- grep -A 20 "MemoryLoadInput" docs/contracts.md
138
- ```
139
-
140
- ## Git Workflow
141
-
142
- - Commit message format: `type: description` (feat/fix/docs/chore/refactor/test)
143
- - Always run quality gate before committing
144
- - PR title format: `[scope] Description`
145
-
146
- ## Dos and Don'ts
147
-
148
- ### Do
149
- - Run `pnpm run quality` before committing
150
- - Add tests for new code
151
- - Use `import type` for type-only imports
152
- - Keep functions small and focused
153
- - Update types and schemas together
154
-
155
- ### Don't
156
- - Skip the quality gate
157
- - Use `any` without justification
158
- - Mutate function parameters
159
- - Add code without corresponding tests
160
- - 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.
1
+ # AGENTS.md - MemHub Project Guide
2
+
3
+ ## Project Overview
4
+
5
+ MemHub is a Git-friendly memory MCP server for coding agents. It stores decisions, preferences, and reusable knowledge as plain Markdown files with YAML front matter.
6
+
7
+ **Tech Stack**: TypeScript (ES2022), Node.js 18+, MCP SDK, Zod, LanceDB, Transformers.js
8
+
9
+ ---
10
+
11
+ ## Dev Environment
12
+
13
+ ```bash
14
+ npx pnpm install # Install dependencies
15
+ npx pnpm run build # Compile TypeScript
16
+ npx pnpm run quality # Quality gate (lint + typecheck + test + coverage)
17
+ ```
18
+
19
+ | Command | Description |
20
+ |---------|-------------|
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
+ ---
32
+
33
+ ## Project Structure
34
+
35
+ ```
36
+ src/
37
+ contracts/ # Type definitions, Zod schemas, MCP contracts
38
+ cli/ # CLI commands (init, etc.)
39
+ server/ # MCP stdio server entry point
40
+ services/ # Business logic (MemoryService, EmbeddingService)
41
+ storage/ # Storage layer (Markdown, VectorIndex)
42
+ utils/ # Shared utilities (slugify, etc.)
43
+ test/ # Vitest unit tests mirroring src/ structure
44
+ docs/ # Documentation
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Coding Style
50
+
51
+ ### TypeScript Conventions
52
+ - Use `readonly` for immutable fields in interfaces
53
+ - Use `type` for aliases, `interface` for object shapes
54
+ - Prefer `import type` for type-only imports
55
+ - Use ESM: `.js` extension in imports, `verbatimModuleSyntax`
56
+ - Explicit return types on exported functions
57
+ - Use Zod for runtime validation
58
+
59
+ ### File Naming
60
+ - `kebab-case.ts` for all files
61
+ - Test files: `<module>.test.ts` or `<module>-edge.test.ts`
62
+
63
+ ### Example Code Style
64
+
65
+ ```typescript
66
+ // Types with readonly fields
67
+ export interface Memory {
68
+ readonly id: UUID;
69
+ readonly tags: readonly string[];
70
+ }
71
+
72
+ // Service with explicit types
73
+ export class MemoryService {
74
+ constructor(private readonly config: MemoryServiceConfig) {}
75
+
76
+ async create(input: CreateMemoryInput): Promise<CreateResult> {
77
+ // implementation
78
+ }
79
+ }
80
+
81
+ // Zod schema for validation
82
+ export const MemorySchema = z.object({
83
+ id: z.string().uuid(),
84
+ tags: z.array(z.string()),
85
+ });
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Workflows
91
+
92
+ ### Add New MCP Tool
93
+
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`
101
+
102
+ ### Support New Agent
103
+
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`
111
+
112
+ ### Release New Version
113
+
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`
119
+
120
+ ---
121
+
122
+ ## Documentation Sync
123
+
124
+ Documentation must stay in sync with code. **Update docs when changing:**
125
+
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 |
132
+
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
+ ---
144
+
145
+ ## Git Workflow
146
+
147
+ - Commit message: `type: description` (feat/fix/docs/chore/refactor/test)
148
+ - Always run quality gate before committing
149
+ - PR title: `[scope] Description`
150
+
151
+ ---
152
+
153
+ ## Dos and Don'ts
154
+
155
+ ### Do
156
+ - Run `npx pnpm run quality` before committing
157
+ - Add tests for new code
158
+ - Use `import type` for type-only imports
159
+ - Keep functions small and focused
160
+ - Update types, schemas, and docs together
161
+
162
+ ### Don't
163
+ - Skip the quality gate
164
+ - Use `any` without justification
165
+ - Mutate function parameters
166
+ - Add code without corresponding tests
167
+ - Commit directly to main (use branches for features)