@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,223 +1,223 @@
1
- /**
2
- * MCP (Model Context Protocol) specific types and constants
3
- * Tool definitions and business-level types (protocol types provided by SDK)
4
- */
5
-
6
- import type { Memory } from './types.js';
7
-
8
- // ============================================================================
9
- // MCP Protocol Version
10
- // ============================================================================
11
-
12
- /** Current MCP protocol version */
13
- export const MCP_PROTOCOL_VERSION = '2024-11-05';
14
-
15
- /** Server information */
16
- export const SERVER_INFO = {
17
- name: 'memhub',
18
- version: '0.2.0',
19
- } as const;
20
-
21
- // ============================================================================
22
- // MCP Tool Definitions (kept for SDK use)
23
- // ============================================================================
24
-
25
- /** Tool definition for tool/list */
26
- export interface Tool {
27
- name: string;
28
- description: string;
29
- inputSchema: ToolInputSchema;
30
- }
31
-
32
- /** Tool input schema (JSON Schema) */
33
- export interface ToolInputSchema {
34
- type: 'object';
35
- properties?: Record<string, unknown>;
36
- required?: string[];
37
- additionalProperties?: boolean;
38
- }
39
-
40
- // ============================================================================
41
- // MCP Tool List
42
- // ============================================================================
43
-
44
- /** All available tool names */
45
- export const TOOL_NAMES = ['memory_load', 'memory_update'] as const;
46
-
47
- /** Tool name type */
48
- export type ToolName = (typeof TOOL_NAMES)[number];
49
-
50
- /** Tool definitions for MCP server */
51
- export const TOOL_DEFINITIONS: readonly Tool[] = [
52
- {
53
- name: 'memory_load',
54
- description: `Retrieve stored memories to recall user preferences, past decisions, project context, and learned knowledge.
55
-
56
- WHEN TO USE (call proactively):
57
- • Starting a new conversation or task
58
- • User references past discussions ("remember when...", "as I mentioned before")
59
- • Need context about user's coding style, preferences, or project decisions
60
- • Uncertain about user's existing preferences or constraints
61
- • Before making assumptions about user requirements
62
-
63
- WHAT IT PROVIDES:
64
- • User preferences (coding style, frameworks, naming conventions)
65
- • Past decisions and their rationale
66
- • Project-specific context and constraints
67
- • Previously learned knowledge about the user
68
-
69
- Call this early to provide personalized, context-aware responses.`,
70
- inputSchema: {
71
- type: 'object',
72
- properties: {
73
- query: {
74
- type: 'string',
75
- description:
76
- 'Search query to find relevant memories. Examples: "react preferences", "error handling approach", "database choice"',
77
- },
78
- id: {
79
- type: 'string',
80
- description: 'Direct lookup by memory ID (if known)',
81
- },
82
- category: {
83
- type: 'string',
84
- description:
85
- 'Filter by category: "general" (default), "preference", "decision", "knowledge", "project"',
86
- },
87
- tags: {
88
- type: 'array',
89
- items: { type: 'string' },
90
- description: 'Filter by tags. Example: ["typescript", "backend"]',
91
- },
92
- limit: {
93
- type: 'number',
94
- description: 'Max results (default: 20, max: 100)',
95
- },
96
- },
97
- additionalProperties: false,
98
- },
99
- },
100
- {
101
- name: 'memory_update',
102
- description: `Store important information to remember for future conversations.
103
-
104
- WHEN TO USE (call when learning something worth remembering):
105
- • User explicitly states a preference ("I prefer functional components")
106
- • User makes a decision with rationale ("We'll use PostgreSQL because...")
107
- • You discover important project context (tech stack, constraints, patterns)
108
- • User corrects your assumption ("Actually, I don't use Redux")
109
- • Task state changes that should persist
110
-
111
- WHAT TO STORE:
112
- • Preferences: coding style, frameworks, naming conventions
113
- • Decisions: architecture choices, library selections, with reasoning
114
- • Knowledge: project-specific patterns, gotchas, conventions
115
- • Context: team structure, deployment process, testing approach
116
-
117
- TIPS:
118
- • content is required and most important
119
- • title helps with search (auto-generated if omitted)
120
- • Use entryType to categorize: "preference", "decision", "context", "fact"
121
- • importance: 1-5 (default: 3), higher = more critical to remember`,
122
- inputSchema: {
123
- type: 'object',
124
- properties: {
125
- content: {
126
- type: 'string',
127
- description:
128
- 'The information to remember. Be specific and include context. Example: "User prefers TypeScript with strict mode. Uses functional React components with hooks. Avoids class components."',
129
- },
130
- title: {
131
- type: 'string',
132
- description:
133
- 'Brief title for the memory (auto-generated from content if omitted). Example: "TypeScript and React preferences"',
134
- },
135
- entryType: {
136
- type: 'string',
137
- enum: ['preference', 'decision', 'context', 'fact'],
138
- description:
139
- 'Type of memory. "preference" for user likes/dislikes, "decision" for choices made, "context" for project info, "fact" for learned facts',
140
- },
141
- category: {
142
- type: 'string',
143
- description:
144
- 'Category for grouping. Default: "general". Example: "frontend", "backend", "project-alpha"',
145
- },
146
- tags: {
147
- type: 'array',
148
- items: { type: 'string' },
149
- description: 'Tags for filtering. Example: ["typescript", "react", "coding-style"]',
150
- },
151
- importance: {
152
- type: 'number',
153
- description: 'Importance level 1-5. 5 = critical, always recall. Default: 3',
154
- },
155
- },
156
- required: ['content'],
157
- additionalProperties: false,
158
- },
159
- },
160
- ] as const;
161
-
162
- // ============================================================================
163
- // Error Codes (MemHub Custom)
164
- // ============================================================================
165
-
166
- /** MemHub custom error codes */
167
- export const MEMHUB_ERROR_CODES = {
168
- NOT_FOUND: -32001,
169
- STORAGE_ERROR: -32002,
170
- VALIDATION_ERROR: -32003,
171
- DUPLICATE_ERROR: -32004,
172
- } as const;
173
-
174
- /** Combined error codes (includes JSON-RPC standard codes) */
175
- export const ERROR_CODES = {
176
- PARSE_ERROR: -32700,
177
- INVALID_REQUEST: -32600,
178
- METHOD_NOT_FOUND: -32601,
179
- INVALID_PARAMS: -32602,
180
- INTERNAL_ERROR: -32603,
181
- ...MEMHUB_ERROR_CODES,
182
- } as const;
183
-
184
- // ============================================================================
185
- // Utility Types
186
- // ============================================================================
187
-
188
- /** Helper type to extract result type from a tool name */
189
- export type ToolResult<T extends ToolName> = T extends 'memory_load'
190
- ? { items: Memory[]; total: number }
191
- : T extends 'memory_update'
192
- ? {
193
- id: string;
194
- sessionId: string;
195
- filePath: string;
196
- created: boolean;
197
- updated: boolean;
198
- memory: Memory;
199
- }
200
- : never;
201
-
202
- /** Helper type to extract input type from a tool name */
203
- export type ToolInput<T extends ToolName> = T extends 'memory_load'
204
- ? {
205
- id?: string;
206
- query?: string;
207
- category?: string;
208
- tags?: string[];
209
- limit?: number;
210
- }
211
- : T extends 'memory_update'
212
- ? {
213
- id?: string;
214
- sessionId?: string;
215
- mode?: 'append' | 'upsert';
216
- entryType?: 'preference' | 'decision' | 'context' | 'fact';
217
- title?: string;
218
- content: string;
219
- tags?: string[];
220
- category?: string;
221
- importance?: number;
222
- }
223
- : never;
1
+ /**
2
+ * MCP (Model Context Protocol) specific types and constants
3
+ * Tool definitions and business-level types (protocol types provided by SDK)
4
+ */
5
+
6
+ import type { Memory } from './types.js';
7
+
8
+ // ============================================================================
9
+ // MCP Protocol Version
10
+ // ============================================================================
11
+
12
+ /** Current MCP protocol version */
13
+ export const MCP_PROTOCOL_VERSION = '2024-11-05';
14
+
15
+ /** Server information */
16
+ export const SERVER_INFO = {
17
+ name: 'memhub',
18
+ version: '0.2.0',
19
+ } as const;
20
+
21
+ // ============================================================================
22
+ // MCP Tool Definitions (kept for SDK use)
23
+ // ============================================================================
24
+
25
+ /** Tool definition for tool/list */
26
+ export interface Tool {
27
+ name: string;
28
+ description: string;
29
+ inputSchema: ToolInputSchema;
30
+ }
31
+
32
+ /** Tool input schema (JSON Schema) */
33
+ export interface ToolInputSchema {
34
+ type: 'object';
35
+ properties?: Record<string, unknown>;
36
+ required?: string[];
37
+ additionalProperties?: boolean;
38
+ }
39
+
40
+ // ============================================================================
41
+ // MCP Tool List
42
+ // ============================================================================
43
+
44
+ /** All available tool names */
45
+ export const TOOL_NAMES = ['memory_load', 'memory_update'] as const;
46
+
47
+ /** Tool name type */
48
+ export type ToolName = (typeof TOOL_NAMES)[number];
49
+
50
+ /** Tool definitions for MCP server */
51
+ export const TOOL_DEFINITIONS: readonly Tool[] = [
52
+ {
53
+ name: 'memory_load',
54
+ description: `Retrieve stored memories to recall user preferences, past decisions, project context, and learned knowledge.
55
+
56
+ WHEN TO USE (call proactively):
57
+ • Starting a new conversation or task
58
+ • User references past discussions ("remember when...", "as I mentioned before")
59
+ • Need context about user's coding style, preferences, or project decisions
60
+ • Uncertain about user's existing preferences or constraints
61
+ • Before making assumptions about user requirements
62
+
63
+ WHAT IT PROVIDES:
64
+ • User preferences (coding style, frameworks, naming conventions)
65
+ • Past decisions and their rationale
66
+ • Project-specific context and constraints
67
+ • Previously learned knowledge about the user
68
+
69
+ Call this early to provide personalized, context-aware responses.`,
70
+ inputSchema: {
71
+ type: 'object',
72
+ properties: {
73
+ query: {
74
+ type: 'string',
75
+ description:
76
+ 'Search query to find relevant memories. Examples: "react preferences", "error handling approach", "database choice"',
77
+ },
78
+ id: {
79
+ type: 'string',
80
+ description: 'Direct lookup by memory ID (if known)',
81
+ },
82
+ category: {
83
+ type: 'string',
84
+ description:
85
+ 'Filter by category: "general" (default), "preference", "decision", "knowledge", "project"',
86
+ },
87
+ tags: {
88
+ type: 'array',
89
+ items: { type: 'string' },
90
+ description: 'Filter by tags. Example: ["typescript", "backend"]',
91
+ },
92
+ limit: {
93
+ type: 'number',
94
+ description: 'Max results (default: 20, max: 100)',
95
+ },
96
+ },
97
+ additionalProperties: false,
98
+ },
99
+ },
100
+ {
101
+ name: 'memory_update',
102
+ description: `Store important information to remember for future conversations.
103
+
104
+ WHEN TO USE (call when learning something worth remembering):
105
+ • User explicitly states a preference ("I prefer functional components")
106
+ • User makes a decision with rationale ("We'll use PostgreSQL because...")
107
+ • You discover important project context (tech stack, constraints, patterns)
108
+ • User corrects your assumption ("Actually, I don't use Redux")
109
+ • Task state changes that should persist
110
+
111
+ WHAT TO STORE:
112
+ • Preferences: coding style, frameworks, naming conventions
113
+ • Decisions: architecture choices, library selections, with reasoning
114
+ • Knowledge: project-specific patterns, gotchas, conventions
115
+ • Context: team structure, deployment process, testing approach
116
+
117
+ TIPS:
118
+ • content is required and most important
119
+ • title helps with search (auto-generated if omitted)
120
+ • Use entryType to categorize: "preference", "decision", "context", "fact"
121
+ • importance: 1-5 (default: 3), higher = more critical to remember`,
122
+ inputSchema: {
123
+ type: 'object',
124
+ properties: {
125
+ content: {
126
+ type: 'string',
127
+ description:
128
+ 'The information to remember. Be specific and include context. Example: "User prefers TypeScript with strict mode. Uses functional React components with hooks. Avoids class components."',
129
+ },
130
+ title: {
131
+ type: 'string',
132
+ description:
133
+ 'Brief title for the memory (auto-generated from content if omitted). Example: "TypeScript and React preferences"',
134
+ },
135
+ entryType: {
136
+ type: 'string',
137
+ enum: ['preference', 'decision', 'context', 'fact'],
138
+ description:
139
+ 'Type of memory. "preference" for user likes/dislikes, "decision" for choices made, "context" for project info, "fact" for learned facts',
140
+ },
141
+ category: {
142
+ type: 'string',
143
+ description:
144
+ 'Category for grouping. Default: "general". Example: "frontend", "backend", "project-alpha"',
145
+ },
146
+ tags: {
147
+ type: 'array',
148
+ items: { type: 'string' },
149
+ description: 'Tags for filtering. Example: ["typescript", "react", "coding-style"]',
150
+ },
151
+ importance: {
152
+ type: 'number',
153
+ description: 'Importance level 1-5. 5 = critical, always recall. Default: 3',
154
+ },
155
+ },
156
+ required: ['content'],
157
+ additionalProperties: false,
158
+ },
159
+ },
160
+ ] as const;
161
+
162
+ // ============================================================================
163
+ // Error Codes (MemHub Custom)
164
+ // ============================================================================
165
+
166
+ /** MemHub custom error codes */
167
+ export const MEMHUB_ERROR_CODES = {
168
+ NOT_FOUND: -32001,
169
+ STORAGE_ERROR: -32002,
170
+ VALIDATION_ERROR: -32003,
171
+ DUPLICATE_ERROR: -32004,
172
+ } as const;
173
+
174
+ /** Combined error codes (includes JSON-RPC standard codes) */
175
+ export const ERROR_CODES = {
176
+ PARSE_ERROR: -32700,
177
+ INVALID_REQUEST: -32600,
178
+ METHOD_NOT_FOUND: -32601,
179
+ INVALID_PARAMS: -32602,
180
+ INTERNAL_ERROR: -32603,
181
+ ...MEMHUB_ERROR_CODES,
182
+ } as const;
183
+
184
+ // ============================================================================
185
+ // Utility Types
186
+ // ============================================================================
187
+
188
+ /** Helper type to extract result type from a tool name */
189
+ export type ToolResult<T extends ToolName> = T extends 'memory_load'
190
+ ? { items: Memory[]; total: number }
191
+ : T extends 'memory_update'
192
+ ? {
193
+ id: string;
194
+ sessionId: string;
195
+ filePath: string;
196
+ created: boolean;
197
+ updated: boolean;
198
+ memory: Memory;
199
+ }
200
+ : never;
201
+
202
+ /** Helper type to extract input type from a tool name */
203
+ export type ToolInput<T extends ToolName> = T extends 'memory_load'
204
+ ? {
205
+ id?: string;
206
+ query?: string;
207
+ category?: string;
208
+ tags?: string[];
209
+ limit?: number;
210
+ }
211
+ : T extends 'memory_update'
212
+ ? {
213
+ id?: string;
214
+ sessionId?: string;
215
+ mode?: 'append' | 'upsert';
216
+ entryType?: 'preference' | 'decision' | 'context' | 'fact';
217
+ title?: string;
218
+ content: string;
219
+ tags?: string[];
220
+ category?: string;
221
+ importance?: number;
222
+ }
223
+ : never;