@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
@@ -0,0 +1,112 @@
1
+ /**
2
+ * CLI types and constants
3
+ */
4
+
5
+ export type AgentType =
6
+ | 'cursor'
7
+ | 'claude-code'
8
+ | 'cline'
9
+ | 'windsurf'
10
+ | 'factory-droid'
11
+ | 'gemini-cli'
12
+ | 'codex';
13
+
14
+ export interface AgentConfig {
15
+ readonly id: AgentType;
16
+ readonly name: string;
17
+ readonly description: string;
18
+ /** Local config file path (relative to project root) */
19
+ readonly configFile: string;
20
+ /** Global config file path (relative to home directory) */
21
+ readonly globalConfigFile: string;
22
+ readonly configFormat: 'json' | 'markdown' | 'toml';
23
+ /** Local instructions file path */
24
+ readonly instructionsFile: string;
25
+ /** Global instructions file path (relative to home directory) */
26
+ readonly globalInstructionsFile: string;
27
+ readonly instructionsFormat: 'markdown' | 'plain';
28
+ }
29
+
30
+ export const AGENTS: readonly AgentConfig[] = [
31
+ {
32
+ id: 'cursor',
33
+ name: 'Cursor',
34
+ description: 'AI code editor with MCP support',
35
+ configFile: '.cursor/mcp.json',
36
+ globalConfigFile: '.cursor/mcp.json',
37
+ configFormat: 'json',
38
+ instructionsFile: '.cursorrules',
39
+ globalInstructionsFile: '.cursorrules',
40
+ instructionsFormat: 'plain',
41
+ },
42
+ {
43
+ id: 'claude-code',
44
+ name: 'Claude Code',
45
+ description: 'Anthropic CLI for Claude',
46
+ configFile: '.mcp.json',
47
+ globalConfigFile: '.claude/settings.json',
48
+ configFormat: 'json',
49
+ instructionsFile: 'CLAUDE.md',
50
+ globalInstructionsFile: '.claude/CLAUDE.md',
51
+ instructionsFormat: 'markdown',
52
+ },
53
+ {
54
+ id: 'cline',
55
+ name: 'Cline',
56
+ description: 'VS Code extension for AI coding',
57
+ configFile: '.cline/mcp.json',
58
+ globalConfigFile: '.cline/mcp.json',
59
+ configFormat: 'json',
60
+ instructionsFile: '.clinerules',
61
+ globalInstructionsFile: '.clinerules',
62
+ instructionsFormat: 'plain',
63
+ },
64
+ {
65
+ id: 'windsurf',
66
+ name: 'Windsurf',
67
+ description: 'Codeium AI editor',
68
+ configFile: '.codeium/windsurf/mcp_config.json',
69
+ globalConfigFile: '.codeium/windsurf/mcp_config.json',
70
+ configFormat: 'json',
71
+ instructionsFile: '.windsurfrules',
72
+ globalInstructionsFile: '.windsurfrules',
73
+ instructionsFormat: 'plain',
74
+ },
75
+ {
76
+ id: 'factory-droid',
77
+ name: 'Factory Droid',
78
+ description: 'Factory AI coding agent',
79
+ configFile: '.factory/mcp.json',
80
+ globalConfigFile: '.factory/mcp.json',
81
+ configFormat: 'json',
82
+ instructionsFile: '.factory/AGENTS.md',
83
+ globalInstructionsFile: '.factory/AGENTS.md',
84
+ instructionsFormat: 'markdown',
85
+ },
86
+ {
87
+ id: 'gemini-cli',
88
+ name: 'Gemini CLI',
89
+ description: 'Google Gemini command line tool',
90
+ configFile: '.gemini/settings.json',
91
+ globalConfigFile: '.gemini/settings.json',
92
+ configFormat: 'json',
93
+ instructionsFile: 'GEMINI.md',
94
+ globalInstructionsFile: '.gemini/GEMINI.md',
95
+ instructionsFormat: 'markdown',
96
+ },
97
+ {
98
+ id: 'codex',
99
+ name: 'Codex',
100
+ description: 'OpenAI CLI coding agent',
101
+ configFile: '.codex/config.toml',
102
+ globalConfigFile: '.codex/config.toml',
103
+ configFormat: 'toml',
104
+ instructionsFile: 'AGENTS.md',
105
+ globalInstructionsFile: '.codex/AGENTS.md',
106
+ instructionsFormat: 'markdown',
107
+ },
108
+ ] as const;
109
+
110
+ export function getAgentById(id: AgentType): AgentConfig | undefined {
111
+ return AGENTS.find(agent => agent.id === id);
112
+ }
@@ -1,12 +1,12 @@
1
- /**
2
- * Contract exports - Central export point for all types and schemas
3
- */
4
-
5
- // Types
6
- export * from './types.js';
7
-
8
- // Schemas
9
- export * from './schemas.js';
10
-
11
- // MCP protocol types
12
- export * from './mcp.js';
1
+ /**
2
+ * Contract exports - Central export point for all types and schemas
3
+ */
4
+
5
+ // Types
6
+ export * from './types.js';
7
+
8
+ // Schemas
9
+ export * from './schemas.js';
10
+
11
+ // MCP protocol types
12
+ export * from './mcp.js';
@@ -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;