@synth-coder/memhub 0.2.1 → 0.2.3
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.
- package/.eslintrc.cjs +45 -45
- package/.factory/commands/opsx-apply.md +150 -0
- package/.factory/commands/opsx-archive.md +155 -0
- package/.factory/commands/opsx-explore.md +171 -0
- package/.factory/commands/opsx-propose.md +104 -0
- package/.factory/skills/openspec-apply-change/SKILL.md +156 -0
- package/.factory/skills/openspec-archive-change/SKILL.md +114 -0
- package/.factory/skills/openspec-explore/SKILL.md +288 -0
- package/.factory/skills/openspec-propose/SKILL.md +110 -0
- package/.github/workflows/ci.yml +74 -74
- package/.iflow/commands/opsx-apply.md +152 -152
- package/.iflow/commands/opsx-archive.md +157 -157
- package/.iflow/commands/opsx-explore.md +173 -173
- package/.iflow/commands/opsx-propose.md +106 -106
- package/.iflow/skills/openspec-apply-change/SKILL.md +156 -156
- package/.iflow/skills/openspec-archive-change/SKILL.md +114 -114
- package/.iflow/skills/openspec-explore/SKILL.md +288 -288
- package/.iflow/skills/openspec-propose/SKILL.md +110 -110
- package/.prettierrc +11 -11
- package/AGENTS.md +169 -26
- package/README.md +195 -195
- package/README.zh-CN.md +193 -193
- package/dist/src/contracts/mcp.js +34 -34
- package/dist/src/server/mcp-server.d.ts +8 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/mcp-server.js +23 -2
- package/dist/src/server/mcp-server.js.map +1 -1
- package/dist/src/services/memory-service.d.ts +1 -0
- package/dist/src/services/memory-service.d.ts.map +1 -1
- package/dist/src/services/memory-service.js +125 -82
- package/dist/src/services/memory-service.js.map +1 -1
- package/docs/architecture-diagrams.md +368 -0
- package/docs/architecture.md +381 -349
- package/docs/contracts.md +190 -119
- package/docs/prompt-template.md +33 -79
- package/docs/proposals/mcp-typescript-sdk-refactor.md +568 -568
- package/docs/proposals/proposal-close-gates.md +58 -58
- package/docs/tool-calling-policy.md +101 -107
- package/docs/vector-search.md +306 -0
- package/package.json +59 -58
- package/src/contracts/index.ts +12 -12
- package/src/contracts/mcp.ts +222 -222
- package/src/contracts/schemas.ts +307 -307
- package/src/contracts/types.ts +410 -410
- package/src/index.ts +8 -8
- package/src/server/index.ts +5 -5
- package/src/server/mcp-server.ts +185 -161
- package/src/services/embedding-service.ts +114 -114
- package/src/services/index.ts +5 -5
- package/src/services/memory-service.ts +663 -621
- package/src/storage/frontmatter-parser.ts +243 -243
- package/src/storage/index.ts +6 -6
- package/src/storage/markdown-storage.ts +236 -236
- package/src/storage/vector-index.ts +160 -160
- package/src/utils/index.ts +5 -5
- package/src/utils/slugify.ts +63 -63
- package/test/contracts/schemas.test.ts +313 -313
- package/test/contracts/types.test.ts +21 -21
- package/test/frontmatter-parser-more.test.ts +94 -94
- package/test/server/mcp-server.test.ts +210 -169
- package/test/services/memory-service-edge.test.ts +248 -248
- package/test/services/memory-service.test.ts +278 -278
- package/test/storage/frontmatter-parser.test.ts +222 -222
- package/test/storage/markdown-storage.test.ts +216 -216
- package/test/storage/storage-edge.test.ts +238 -238
- package/test/storage/vector-index.test.ts +153 -153
- package/test/utils/slugify-edge.test.ts +94 -94
- package/test/utils/slugify.test.ts +68 -68
- package/tsconfig.json +25 -25
- package/tsconfig.test.json +8 -8
- package/vitest.config.ts +29 -29
package/src/contracts/types.ts
CHANGED
|
@@ -1,410 +1,410 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core type definitions for MemHub
|
|
3
|
-
* These types represent the data models used throughout the application
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Identity Types
|
|
8
|
-
// ============================================================================
|
|
9
|
-
|
|
10
|
-
/** UUID v4 string format */
|
|
11
|
-
export type UUID = string;
|
|
12
|
-
|
|
13
|
-
/** ISO 8601 timestamp string */
|
|
14
|
-
export type ISO8601Timestamp = string;
|
|
15
|
-
|
|
16
|
-
/** URL-friendly slug string */
|
|
17
|
-
export type Slug = string;
|
|
18
|
-
|
|
19
|
-
// ============================================================================
|
|
20
|
-
// Memory Types
|
|
21
|
-
// ============================================================================
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Represents a memory entry stored in Markdown format
|
|
25
|
-
* Content is split between YAML Front Matter (metadata) and Markdown body
|
|
26
|
-
*/
|
|
27
|
-
export type MemoryEntryType =
|
|
28
|
-
| 'preference' // User likes/dislikes
|
|
29
|
-
| 'decision' // Technical choices with reasoning
|
|
30
|
-
| 'context' // Project/environment information
|
|
31
|
-
| 'fact'; // Objective knowledge
|
|
32
|
-
|
|
33
|
-
export interface Memory {
|
|
34
|
-
/** UUID v4 unique identifier */
|
|
35
|
-
readonly id: UUID;
|
|
36
|
-
|
|
37
|
-
// Metadata (stored in YAML Front Matter)
|
|
38
|
-
/** Creation timestamp in ISO 8601 format */
|
|
39
|
-
readonly createdAt: ISO8601Timestamp;
|
|
40
|
-
/** Last update timestamp in ISO 8601 format */
|
|
41
|
-
updatedAt: ISO8601Timestamp;
|
|
42
|
-
/** Session UUID for concurrent CLI isolation */
|
|
43
|
-
sessionId?: UUID;
|
|
44
|
-
/** Memory entry type */
|
|
45
|
-
entryType?: MemoryEntryType;
|
|
46
|
-
/** Tags for categorization and search */
|
|
47
|
-
tags: readonly string[];
|
|
48
|
-
/** Category for organization */
|
|
49
|
-
category: string;
|
|
50
|
-
/** Importance level from 1 (low) to 5 (high) */
|
|
51
|
-
importance: number;
|
|
52
|
-
|
|
53
|
-
// Content (stored in Markdown body)
|
|
54
|
-
/** Title as H1 heading in Markdown */
|
|
55
|
-
title: string;
|
|
56
|
-
/** Markdown formatted content */
|
|
57
|
-
content: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Raw memory data as stored in YAML Front Matter + Markdown
|
|
62
|
-
* Used for serialization/deserialization
|
|
63
|
-
*/
|
|
64
|
-
export interface MemoryFrontMatter {
|
|
65
|
-
id: UUID;
|
|
66
|
-
created_at: ISO8601Timestamp;
|
|
67
|
-
updated_at: ISO8601Timestamp;
|
|
68
|
-
session_id?: UUID;
|
|
69
|
-
entry_type?: MemoryEntryType;
|
|
70
|
-
tags: readonly string[];
|
|
71
|
-
category: string;
|
|
72
|
-
importance: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Complete file content representation
|
|
77
|
-
*/
|
|
78
|
-
export interface MemoryFile {
|
|
79
|
-
/** Relative path from storage root */
|
|
80
|
-
readonly path: string;
|
|
81
|
-
/** Filename with extension */
|
|
82
|
-
readonly filename: string;
|
|
83
|
-
/** Raw file content */
|
|
84
|
-
readonly content: string;
|
|
85
|
-
/** Last modification timestamp */
|
|
86
|
-
readonly modifiedAt: ISO8601Timestamp;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ============================================================================
|
|
90
|
-
// Operation Result Types
|
|
91
|
-
// ============================================================================
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Result of a search operation
|
|
95
|
-
*/
|
|
96
|
-
export interface SearchResult {
|
|
97
|
-
/** The matched memory */
|
|
98
|
-
readonly memory: Memory;
|
|
99
|
-
/** Relevance score between 0 and 1 */
|
|
100
|
-
readonly score: number;
|
|
101
|
-
/** Matching text snippets with context */
|
|
102
|
-
readonly matches: readonly string[];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Result of a list/query operation with pagination
|
|
107
|
-
*/
|
|
108
|
-
export interface ListResult {
|
|
109
|
-
/** Memory entries for current page */
|
|
110
|
-
readonly memories: readonly Memory[];
|
|
111
|
-
/** Total count without pagination */
|
|
112
|
-
readonly total: number;
|
|
113
|
-
/** Whether more results exist */
|
|
114
|
-
readonly hasMore: boolean;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Result of create operation
|
|
119
|
-
*/
|
|
120
|
-
export interface CreateResult {
|
|
121
|
-
/** ID of created memory */
|
|
122
|
-
readonly id: UUID;
|
|
123
|
-
/** Path to stored file */
|
|
124
|
-
readonly filePath: string;
|
|
125
|
-
/** Complete memory object */
|
|
126
|
-
readonly memory: Memory;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Result of update operation
|
|
131
|
-
*/
|
|
132
|
-
export interface UpdateResult {
|
|
133
|
-
/** Updated memory object */
|
|
134
|
-
readonly memory: Memory;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Result of delete operation
|
|
139
|
-
*/
|
|
140
|
-
export interface DeleteResult {
|
|
141
|
-
/** Whether deletion was successful */
|
|
142
|
-
readonly success: boolean;
|
|
143
|
-
/** Path of deleted file */
|
|
144
|
-
readonly filePath: string;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// ============================================================================
|
|
148
|
-
// Filter and Query Types
|
|
149
|
-
// ============================================================================
|
|
150
|
-
|
|
151
|
-
/** Sortable fields for memory listing */
|
|
152
|
-
export type SortField = 'createdAt' | 'updatedAt' | 'title' | 'importance';
|
|
153
|
-
|
|
154
|
-
/** Sort direction */
|
|
155
|
-
export type SortOrder = 'asc' | 'desc';
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Filter options for listing memories
|
|
159
|
-
*/
|
|
160
|
-
export interface MemoryFilter {
|
|
161
|
-
/** Filter by category */
|
|
162
|
-
readonly category?: string;
|
|
163
|
-
/** Filter by tags (AND relationship) */
|
|
164
|
-
readonly tags?: readonly string[];
|
|
165
|
-
/** Filter by creation date range start */
|
|
166
|
-
readonly fromDate?: ISO8601Timestamp;
|
|
167
|
-
/** Filter by creation date range end */
|
|
168
|
-
readonly toDate?: ISO8601Timestamp;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Pagination options
|
|
173
|
-
*/
|
|
174
|
-
export interface PaginationOptions {
|
|
175
|
-
/** Number of results to return (max 100) */
|
|
176
|
-
readonly limit: number;
|
|
177
|
-
/** Number of results to skip */
|
|
178
|
-
readonly offset: number;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Sorting options
|
|
183
|
-
*/
|
|
184
|
-
export interface SortOptions {
|
|
185
|
-
/** Field to sort by */
|
|
186
|
-
readonly sortBy: SortField;
|
|
187
|
-
/** Sort direction */
|
|
188
|
-
readonly sortOrder: SortOrder;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// ============================================================================
|
|
192
|
-
// MCP Tool Input Types
|
|
193
|
-
// ============================================================================
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Input for memory_create tool
|
|
197
|
-
*/
|
|
198
|
-
export interface CreateMemoryInput {
|
|
199
|
-
readonly title: string;
|
|
200
|
-
readonly content: string;
|
|
201
|
-
readonly tags?: readonly string[];
|
|
202
|
-
readonly category?: string;
|
|
203
|
-
readonly importance?: number;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Input for memory_read tool
|
|
208
|
-
*/
|
|
209
|
-
export interface ReadMemoryInput {
|
|
210
|
-
readonly id: UUID;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Input for memory_update tool
|
|
215
|
-
*/
|
|
216
|
-
export interface UpdateMemoryInput {
|
|
217
|
-
readonly id: UUID;
|
|
218
|
-
readonly title?: string;
|
|
219
|
-
readonly content?: string;
|
|
220
|
-
readonly tags?: readonly string[];
|
|
221
|
-
readonly category?: string;
|
|
222
|
-
readonly importance?: number;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Input for memory_delete tool
|
|
227
|
-
*/
|
|
228
|
-
export interface DeleteMemoryInput {
|
|
229
|
-
readonly id: UUID;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Input for memory_list tool
|
|
234
|
-
*/
|
|
235
|
-
export interface ListMemoryInput
|
|
236
|
-
extends Partial<MemoryFilter>, Partial<PaginationOptions>, Partial<SortOptions> {}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Input for memory_search tool
|
|
240
|
-
*/
|
|
241
|
-
export interface SearchMemoryInput extends Partial<MemoryFilter> {
|
|
242
|
-
readonly query: string;
|
|
243
|
-
readonly limit?: number;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Input for memory_load tool
|
|
248
|
-
*/
|
|
249
|
-
export interface MemoryLoadInput extends Partial<MemoryFilter> {
|
|
250
|
-
readonly id?: UUID;
|
|
251
|
-
readonly query?: string;
|
|
252
|
-
readonly limit?: number;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Input for memory_update tool (upsert/append)
|
|
257
|
-
*/
|
|
258
|
-
export interface MemoryUpdateInput {
|
|
259
|
-
readonly id?: UUID;
|
|
260
|
-
readonly sessionId?: UUID;
|
|
261
|
-
readonly mode?: 'append' | 'upsert';
|
|
262
|
-
readonly entryType?: MemoryEntryType;
|
|
263
|
-
readonly title?: string;
|
|
264
|
-
readonly content: string;
|
|
265
|
-
readonly tags?: readonly string[];
|
|
266
|
-
readonly category?: string;
|
|
267
|
-
readonly importance?: number;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// ============================================================================
|
|
271
|
-
// MCP Tool Output Types
|
|
272
|
-
// ============================================================================
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Output for memory_create tool
|
|
276
|
-
*/
|
|
277
|
-
export interface CreateMemoryOutput extends CreateResult {}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Output for memory_read tool
|
|
281
|
-
*/
|
|
282
|
-
export interface ReadMemoryOutput {
|
|
283
|
-
readonly memory: Memory;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Output for memory_update tool
|
|
288
|
-
*/
|
|
289
|
-
export interface UpdateMemoryOutput extends UpdateResult {}
|
|
290
|
-
|
|
291
|
-
export interface MemoryLoadOutput {
|
|
292
|
-
readonly items: readonly Memory[];
|
|
293
|
-
readonly total: number;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export interface MemoryUpdateOutput {
|
|
297
|
-
readonly id: UUID;
|
|
298
|
-
readonly sessionId: UUID;
|
|
299
|
-
readonly filePath: string;
|
|
300
|
-
readonly created: boolean;
|
|
301
|
-
readonly updated: boolean;
|
|
302
|
-
readonly memory: Memory;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Output for memory_delete tool
|
|
307
|
-
*/
|
|
308
|
-
export interface DeleteMemoryOutput extends DeleteResult {}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Output for memory_list tool
|
|
312
|
-
*/
|
|
313
|
-
export interface ListMemoryOutput extends ListResult {}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Output for memory_search tool
|
|
317
|
-
*/
|
|
318
|
-
export interface SearchMemoryOutput {
|
|
319
|
-
readonly results: readonly SearchResult[];
|
|
320
|
-
readonly total: number;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Output for memory_get_categories tool
|
|
325
|
-
*/
|
|
326
|
-
export interface GetCategoriesOutput {
|
|
327
|
-
readonly categories: readonly string[];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Output for memory_get_tags tool
|
|
332
|
-
*/
|
|
333
|
-
export interface GetTagsOutput {
|
|
334
|
-
readonly tags: readonly string[];
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// ============================================================================
|
|
338
|
-
// Error Types
|
|
339
|
-
// ============================================================================
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* MemHub custom error codes (MCP standard + custom)
|
|
343
|
-
*/
|
|
344
|
-
export enum ErrorCode {
|
|
345
|
-
// Standard MCP error codes
|
|
346
|
-
PARSE_ERROR = -32700,
|
|
347
|
-
INVALID_REQUEST = -32600,
|
|
348
|
-
METHOD_NOT_FOUND = -32601,
|
|
349
|
-
INVALID_PARAMS = -32602,
|
|
350
|
-
INTERNAL_ERROR = -32603,
|
|
351
|
-
|
|
352
|
-
// MemHub custom error codes
|
|
353
|
-
NOT_FOUND = -32001,
|
|
354
|
-
STORAGE_ERROR = -32002,
|
|
355
|
-
VALIDATION_ERROR = -32003,
|
|
356
|
-
DUPLICATE_ERROR = -32004,
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Alias for backward compatibility
|
|
361
|
-
* @deprecated Use ErrorCode.METHOD_NOT_FOUND instead
|
|
362
|
-
*/
|
|
363
|
-
export const MethodNotFoundError = ErrorCode.METHOD_NOT_FOUND;
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Error data structure for additional context
|
|
367
|
-
*/
|
|
368
|
-
export interface ErrorData {
|
|
369
|
-
readonly details?: unknown;
|
|
370
|
-
readonly field?: string;
|
|
371
|
-
readonly suggestion?: string;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* MCP Error structure
|
|
376
|
-
*/
|
|
377
|
-
export interface McpError {
|
|
378
|
-
readonly code: ErrorCode;
|
|
379
|
-
readonly message: string;
|
|
380
|
-
readonly data?: ErrorData;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// ============================================================================
|
|
384
|
-
// Configuration Types
|
|
385
|
-
// ============================================================================
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Application configuration
|
|
389
|
-
*/
|
|
390
|
-
export interface Config {
|
|
391
|
-
/** Storage directory path */
|
|
392
|
-
readonly storagePath: string;
|
|
393
|
-
/** Log level */
|
|
394
|
-
readonly logLevel: 'debug' | 'info' | 'warn' | 'error';
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// ============================================================================
|
|
398
|
-
// Utility Types
|
|
399
|
-
// ============================================================================
|
|
400
|
-
|
|
401
|
-
/** Deep readonly version of a type */
|
|
402
|
-
export type DeepReadonly<T> = {
|
|
403
|
-
readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
/** Nullable type */
|
|
407
|
-
export type Nullable<T> = T | null;
|
|
408
|
-
|
|
409
|
-
/** Optional fields made required */
|
|
410
|
-
export type RequiredFields<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for MemHub
|
|
3
|
+
* These types represent the data models used throughout the application
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Identity Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
/** UUID v4 string format */
|
|
11
|
+
export type UUID = string;
|
|
12
|
+
|
|
13
|
+
/** ISO 8601 timestamp string */
|
|
14
|
+
export type ISO8601Timestamp = string;
|
|
15
|
+
|
|
16
|
+
/** URL-friendly slug string */
|
|
17
|
+
export type Slug = string;
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Memory Types
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents a memory entry stored in Markdown format
|
|
25
|
+
* Content is split between YAML Front Matter (metadata) and Markdown body
|
|
26
|
+
*/
|
|
27
|
+
export type MemoryEntryType =
|
|
28
|
+
| 'preference' // User likes/dislikes
|
|
29
|
+
| 'decision' // Technical choices with reasoning
|
|
30
|
+
| 'context' // Project/environment information
|
|
31
|
+
| 'fact'; // Objective knowledge
|
|
32
|
+
|
|
33
|
+
export interface Memory {
|
|
34
|
+
/** UUID v4 unique identifier */
|
|
35
|
+
readonly id: UUID;
|
|
36
|
+
|
|
37
|
+
// Metadata (stored in YAML Front Matter)
|
|
38
|
+
/** Creation timestamp in ISO 8601 format */
|
|
39
|
+
readonly createdAt: ISO8601Timestamp;
|
|
40
|
+
/** Last update timestamp in ISO 8601 format */
|
|
41
|
+
updatedAt: ISO8601Timestamp;
|
|
42
|
+
/** Session UUID for concurrent CLI isolation */
|
|
43
|
+
sessionId?: UUID;
|
|
44
|
+
/** Memory entry type */
|
|
45
|
+
entryType?: MemoryEntryType;
|
|
46
|
+
/** Tags for categorization and search */
|
|
47
|
+
tags: readonly string[];
|
|
48
|
+
/** Category for organization */
|
|
49
|
+
category: string;
|
|
50
|
+
/** Importance level from 1 (low) to 5 (high) */
|
|
51
|
+
importance: number;
|
|
52
|
+
|
|
53
|
+
// Content (stored in Markdown body)
|
|
54
|
+
/** Title as H1 heading in Markdown */
|
|
55
|
+
title: string;
|
|
56
|
+
/** Markdown formatted content */
|
|
57
|
+
content: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Raw memory data as stored in YAML Front Matter + Markdown
|
|
62
|
+
* Used for serialization/deserialization
|
|
63
|
+
*/
|
|
64
|
+
export interface MemoryFrontMatter {
|
|
65
|
+
id: UUID;
|
|
66
|
+
created_at: ISO8601Timestamp;
|
|
67
|
+
updated_at: ISO8601Timestamp;
|
|
68
|
+
session_id?: UUID;
|
|
69
|
+
entry_type?: MemoryEntryType;
|
|
70
|
+
tags: readonly string[];
|
|
71
|
+
category: string;
|
|
72
|
+
importance: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Complete file content representation
|
|
77
|
+
*/
|
|
78
|
+
export interface MemoryFile {
|
|
79
|
+
/** Relative path from storage root */
|
|
80
|
+
readonly path: string;
|
|
81
|
+
/** Filename with extension */
|
|
82
|
+
readonly filename: string;
|
|
83
|
+
/** Raw file content */
|
|
84
|
+
readonly content: string;
|
|
85
|
+
/** Last modification timestamp */
|
|
86
|
+
readonly modifiedAt: ISO8601Timestamp;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Operation Result Types
|
|
91
|
+
// ============================================================================
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Result of a search operation
|
|
95
|
+
*/
|
|
96
|
+
export interface SearchResult {
|
|
97
|
+
/** The matched memory */
|
|
98
|
+
readonly memory: Memory;
|
|
99
|
+
/** Relevance score between 0 and 1 */
|
|
100
|
+
readonly score: number;
|
|
101
|
+
/** Matching text snippets with context */
|
|
102
|
+
readonly matches: readonly string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Result of a list/query operation with pagination
|
|
107
|
+
*/
|
|
108
|
+
export interface ListResult {
|
|
109
|
+
/** Memory entries for current page */
|
|
110
|
+
readonly memories: readonly Memory[];
|
|
111
|
+
/** Total count without pagination */
|
|
112
|
+
readonly total: number;
|
|
113
|
+
/** Whether more results exist */
|
|
114
|
+
readonly hasMore: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Result of create operation
|
|
119
|
+
*/
|
|
120
|
+
export interface CreateResult {
|
|
121
|
+
/** ID of created memory */
|
|
122
|
+
readonly id: UUID;
|
|
123
|
+
/** Path to stored file */
|
|
124
|
+
readonly filePath: string;
|
|
125
|
+
/** Complete memory object */
|
|
126
|
+
readonly memory: Memory;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Result of update operation
|
|
131
|
+
*/
|
|
132
|
+
export interface UpdateResult {
|
|
133
|
+
/** Updated memory object */
|
|
134
|
+
readonly memory: Memory;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Result of delete operation
|
|
139
|
+
*/
|
|
140
|
+
export interface DeleteResult {
|
|
141
|
+
/** Whether deletion was successful */
|
|
142
|
+
readonly success: boolean;
|
|
143
|
+
/** Path of deleted file */
|
|
144
|
+
readonly filePath: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Filter and Query Types
|
|
149
|
+
// ============================================================================
|
|
150
|
+
|
|
151
|
+
/** Sortable fields for memory listing */
|
|
152
|
+
export type SortField = 'createdAt' | 'updatedAt' | 'title' | 'importance';
|
|
153
|
+
|
|
154
|
+
/** Sort direction */
|
|
155
|
+
export type SortOrder = 'asc' | 'desc';
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Filter options for listing memories
|
|
159
|
+
*/
|
|
160
|
+
export interface MemoryFilter {
|
|
161
|
+
/** Filter by category */
|
|
162
|
+
readonly category?: string;
|
|
163
|
+
/** Filter by tags (AND relationship) */
|
|
164
|
+
readonly tags?: readonly string[];
|
|
165
|
+
/** Filter by creation date range start */
|
|
166
|
+
readonly fromDate?: ISO8601Timestamp;
|
|
167
|
+
/** Filter by creation date range end */
|
|
168
|
+
readonly toDate?: ISO8601Timestamp;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Pagination options
|
|
173
|
+
*/
|
|
174
|
+
export interface PaginationOptions {
|
|
175
|
+
/** Number of results to return (max 100) */
|
|
176
|
+
readonly limit: number;
|
|
177
|
+
/** Number of results to skip */
|
|
178
|
+
readonly offset: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Sorting options
|
|
183
|
+
*/
|
|
184
|
+
export interface SortOptions {
|
|
185
|
+
/** Field to sort by */
|
|
186
|
+
readonly sortBy: SortField;
|
|
187
|
+
/** Sort direction */
|
|
188
|
+
readonly sortOrder: SortOrder;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ============================================================================
|
|
192
|
+
// MCP Tool Input Types
|
|
193
|
+
// ============================================================================
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Input for memory_create tool
|
|
197
|
+
*/
|
|
198
|
+
export interface CreateMemoryInput {
|
|
199
|
+
readonly title: string;
|
|
200
|
+
readonly content: string;
|
|
201
|
+
readonly tags?: readonly string[];
|
|
202
|
+
readonly category?: string;
|
|
203
|
+
readonly importance?: number;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Input for memory_read tool
|
|
208
|
+
*/
|
|
209
|
+
export interface ReadMemoryInput {
|
|
210
|
+
readonly id: UUID;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Input for memory_update tool
|
|
215
|
+
*/
|
|
216
|
+
export interface UpdateMemoryInput {
|
|
217
|
+
readonly id: UUID;
|
|
218
|
+
readonly title?: string;
|
|
219
|
+
readonly content?: string;
|
|
220
|
+
readonly tags?: readonly string[];
|
|
221
|
+
readonly category?: string;
|
|
222
|
+
readonly importance?: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Input for memory_delete tool
|
|
227
|
+
*/
|
|
228
|
+
export interface DeleteMemoryInput {
|
|
229
|
+
readonly id: UUID;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Input for memory_list tool
|
|
234
|
+
*/
|
|
235
|
+
export interface ListMemoryInput
|
|
236
|
+
extends Partial<MemoryFilter>, Partial<PaginationOptions>, Partial<SortOptions> {}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Input for memory_search tool
|
|
240
|
+
*/
|
|
241
|
+
export interface SearchMemoryInput extends Partial<MemoryFilter> {
|
|
242
|
+
readonly query: string;
|
|
243
|
+
readonly limit?: number;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Input for memory_load tool
|
|
248
|
+
*/
|
|
249
|
+
export interface MemoryLoadInput extends Partial<MemoryFilter> {
|
|
250
|
+
readonly id?: UUID;
|
|
251
|
+
readonly query?: string;
|
|
252
|
+
readonly limit?: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Input for memory_update tool (upsert/append)
|
|
257
|
+
*/
|
|
258
|
+
export interface MemoryUpdateInput {
|
|
259
|
+
readonly id?: UUID;
|
|
260
|
+
readonly sessionId?: UUID;
|
|
261
|
+
readonly mode?: 'append' | 'upsert';
|
|
262
|
+
readonly entryType?: MemoryEntryType;
|
|
263
|
+
readonly title?: string;
|
|
264
|
+
readonly content: string;
|
|
265
|
+
readonly tags?: readonly string[];
|
|
266
|
+
readonly category?: string;
|
|
267
|
+
readonly importance?: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ============================================================================
|
|
271
|
+
// MCP Tool Output Types
|
|
272
|
+
// ============================================================================
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Output for memory_create tool
|
|
276
|
+
*/
|
|
277
|
+
export interface CreateMemoryOutput extends CreateResult {}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Output for memory_read tool
|
|
281
|
+
*/
|
|
282
|
+
export interface ReadMemoryOutput {
|
|
283
|
+
readonly memory: Memory;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Output for memory_update tool
|
|
288
|
+
*/
|
|
289
|
+
export interface UpdateMemoryOutput extends UpdateResult {}
|
|
290
|
+
|
|
291
|
+
export interface MemoryLoadOutput {
|
|
292
|
+
readonly items: readonly Memory[];
|
|
293
|
+
readonly total: number;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface MemoryUpdateOutput {
|
|
297
|
+
readonly id: UUID;
|
|
298
|
+
readonly sessionId: UUID;
|
|
299
|
+
readonly filePath: string;
|
|
300
|
+
readonly created: boolean;
|
|
301
|
+
readonly updated: boolean;
|
|
302
|
+
readonly memory: Memory;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Output for memory_delete tool
|
|
307
|
+
*/
|
|
308
|
+
export interface DeleteMemoryOutput extends DeleteResult {}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Output for memory_list tool
|
|
312
|
+
*/
|
|
313
|
+
export interface ListMemoryOutput extends ListResult {}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Output for memory_search tool
|
|
317
|
+
*/
|
|
318
|
+
export interface SearchMemoryOutput {
|
|
319
|
+
readonly results: readonly SearchResult[];
|
|
320
|
+
readonly total: number;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Output for memory_get_categories tool
|
|
325
|
+
*/
|
|
326
|
+
export interface GetCategoriesOutput {
|
|
327
|
+
readonly categories: readonly string[];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Output for memory_get_tags tool
|
|
332
|
+
*/
|
|
333
|
+
export interface GetTagsOutput {
|
|
334
|
+
readonly tags: readonly string[];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ============================================================================
|
|
338
|
+
// Error Types
|
|
339
|
+
// ============================================================================
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* MemHub custom error codes (MCP standard + custom)
|
|
343
|
+
*/
|
|
344
|
+
export enum ErrorCode {
|
|
345
|
+
// Standard MCP error codes
|
|
346
|
+
PARSE_ERROR = -32700,
|
|
347
|
+
INVALID_REQUEST = -32600,
|
|
348
|
+
METHOD_NOT_FOUND = -32601,
|
|
349
|
+
INVALID_PARAMS = -32602,
|
|
350
|
+
INTERNAL_ERROR = -32603,
|
|
351
|
+
|
|
352
|
+
// MemHub custom error codes
|
|
353
|
+
NOT_FOUND = -32001,
|
|
354
|
+
STORAGE_ERROR = -32002,
|
|
355
|
+
VALIDATION_ERROR = -32003,
|
|
356
|
+
DUPLICATE_ERROR = -32004,
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Alias for backward compatibility
|
|
361
|
+
* @deprecated Use ErrorCode.METHOD_NOT_FOUND instead
|
|
362
|
+
*/
|
|
363
|
+
export const MethodNotFoundError = ErrorCode.METHOD_NOT_FOUND;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Error data structure for additional context
|
|
367
|
+
*/
|
|
368
|
+
export interface ErrorData {
|
|
369
|
+
readonly details?: unknown;
|
|
370
|
+
readonly field?: string;
|
|
371
|
+
readonly suggestion?: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* MCP Error structure
|
|
376
|
+
*/
|
|
377
|
+
export interface McpError {
|
|
378
|
+
readonly code: ErrorCode;
|
|
379
|
+
readonly message: string;
|
|
380
|
+
readonly data?: ErrorData;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ============================================================================
|
|
384
|
+
// Configuration Types
|
|
385
|
+
// ============================================================================
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Application configuration
|
|
389
|
+
*/
|
|
390
|
+
export interface Config {
|
|
391
|
+
/** Storage directory path */
|
|
392
|
+
readonly storagePath: string;
|
|
393
|
+
/** Log level */
|
|
394
|
+
readonly logLevel: 'debug' | 'info' | 'warn' | 'error';
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ============================================================================
|
|
398
|
+
// Utility Types
|
|
399
|
+
// ============================================================================
|
|
400
|
+
|
|
401
|
+
/** Deep readonly version of a type */
|
|
402
|
+
export type DeepReadonly<T> = {
|
|
403
|
+
readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/** Nullable type */
|
|
407
|
+
export type Nullable<T> = T | null;
|
|
408
|
+
|
|
409
|
+
/** Optional fields made required */
|
|
410
|
+
export type RequiredFields<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
|