@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,307 +1,307 @@
1
- /**
2
- * Zod schemas for runtime validation
3
- * All schemas correspond to types defined in types.ts
4
- */
5
-
6
- import { z } from 'zod';
7
-
8
- // ============================================================================
9
- // Primitive Schemas
10
- // ============================================================================
11
-
12
- /** UUID v4 validation schema */
13
- export const UUIDSchema = z.string().uuid().brand<'UUID'>();
14
-
15
- /** ISO 8601 timestamp validation */
16
- export const ISO8601TimestampSchema = z.string().datetime().brand<'ISO8601'>();
17
-
18
- /** Slug validation (URL-friendly string) */
19
- export const SlugSchema = z
20
- .string()
21
- .min(1)
22
- .max(100)
23
- .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Must be a valid URL slug');
24
-
25
- /** Tag name validation */
26
- export const TagSchema = z
27
- .string()
28
- .min(1)
29
- .max(50)
30
- .regex(/^[a-z0-9-]+$/, 'Tags can only contain lowercase letters, numbers, and hyphens');
31
-
32
- /** Category name validation */
33
- export const CategorySchema = z
34
- .string()
35
- .min(1)
36
- .max(50)
37
- .regex(/^[a-z0-9-]+$/, 'Category can only contain lowercase letters, numbers, and hyphens');
38
-
39
- /** Importance level validation (1-5) */
40
- export const ImportanceSchema = z.number().int().min(1).max(5);
41
-
42
- /** STM memory entry type */
43
- export const MemoryEntryTypeSchema = z.enum([
44
- 'preference', // User likes/dislikes
45
- 'decision', // Technical choices with reasoning
46
- 'context', // Project/environment information
47
- 'fact', // Objective knowledge
48
- ]);
49
-
50
- // ============================================================================
51
- // Memory Schemas
52
- // ============================================================================
53
-
54
- /** Memory front matter schema (YAML portion) */
55
- export const MemoryFrontMatterSchema = z.object({
56
- id: UUIDSchema,
57
- created_at: ISO8601TimestampSchema,
58
- updated_at: ISO8601TimestampSchema,
59
- session_id: UUIDSchema.optional(),
60
- entry_type: MemoryEntryTypeSchema.optional(),
61
- tags: z.array(TagSchema).default([]),
62
- category: CategorySchema.default('general'),
63
- importance: ImportanceSchema.default(3),
64
- });
65
-
66
- /** Complete memory schema */
67
- export const MemorySchema = z.object({
68
- id: UUIDSchema,
69
- createdAt: ISO8601TimestampSchema,
70
- updatedAt: ISO8601TimestampSchema,
71
- sessionId: UUIDSchema.optional(),
72
- entryType: MemoryEntryTypeSchema.optional(),
73
- tags: z.array(z.string()).readonly(),
74
- category: CategorySchema,
75
- importance: ImportanceSchema,
76
- title: z.string().min(1).max(200),
77
- content: z.string().max(100000),
78
- });
79
-
80
- /** Memory file schema */
81
- export const MemoryFileSchema = z.object({
82
- path: z.string().min(1),
83
- filename: z.string().min(1),
84
- content: z.string(),
85
- modifiedAt: ISO8601TimestampSchema,
86
- });
87
-
88
- // ============================================================================
89
- // Result Schemas
90
- // ============================================================================
91
-
92
- /** Search result schema */
93
- export const SearchResultSchema = z.object({
94
- memory: MemorySchema,
95
- score: z.number().min(0).max(1),
96
- matches: z.array(z.string()),
97
- });
98
-
99
- /** List result schema */
100
- export const ListResultSchema = z.object({
101
- memories: z.array(MemorySchema),
102
- total: z.number().int().nonnegative(),
103
- hasMore: z.boolean(),
104
- });
105
-
106
- /** Create result schema */
107
- export const CreateResultSchema = z.object({
108
- id: UUIDSchema,
109
- filePath: z.string().min(1),
110
- memory: MemorySchema,
111
- });
112
-
113
- /** Update result schema */
114
- export const UpdateResultSchema = z.object({
115
- memory: MemorySchema,
116
- });
117
-
118
- /** Delete result schema */
119
- export const DeleteResultSchema = z.object({
120
- success: z.boolean(),
121
- filePath: z.string().min(1),
122
- });
123
-
124
- // ============================================================================
125
- // Filter and Query Schemas
126
- // ============================================================================
127
-
128
- /** Sort field enum */
129
- export const SortFieldSchema = z.enum(['createdAt', 'updatedAt', 'title', 'importance']);
130
-
131
- /** Sort order enum */
132
- export const SortOrderSchema = z.enum(['asc', 'desc']);
133
-
134
- /** Memory filter schema */
135
- export const MemoryFilterSchema = z.object({
136
- category: CategorySchema.optional(),
137
- tags: z.array(TagSchema).optional(),
138
- fromDate: ISO8601TimestampSchema.optional(),
139
- toDate: ISO8601TimestampSchema.optional(),
140
- });
141
-
142
- /** Pagination options schema */
143
- export const PaginationOptionsSchema = z.object({
144
- limit: z.number().int().min(1).max(100).default(20),
145
- offset: z.number().int().min(0).default(0),
146
- });
147
-
148
- /** Sort options schema */
149
- export const SortOptionsSchema = z.object({
150
- sortBy: SortFieldSchema.default('createdAt'),
151
- sortOrder: SortOrderSchema.default('desc'),
152
- });
153
-
154
- // ============================================================================
155
- // MCP Tool Input Schemas
156
- // ============================================================================
157
-
158
- /** Create memory input schema */
159
- export const CreateMemoryInputSchema = z.object({
160
- title: z.string().min(1).max(200),
161
- content: z.string().max(100000),
162
- tags: z.array(TagSchema).default([]),
163
- category: CategorySchema.default('general'),
164
- importance: ImportanceSchema.default(3),
165
- });
166
-
167
- /** Read memory input schema */
168
- export const ReadMemoryInputSchema = z.object({
169
- id: UUIDSchema,
170
- });
171
-
172
- /** Update memory input schema */
173
- export const UpdateMemoryInputSchema = z.object({
174
- id: UUIDSchema,
175
- title: z.string().min(1).max(200).optional(),
176
- content: z.string().max(100000).optional(),
177
- tags: z.array(TagSchema).optional(),
178
- category: CategorySchema.optional(),
179
- importance: ImportanceSchema.optional(),
180
- });
181
-
182
- /** Delete memory input schema */
183
- export const DeleteMemoryInputSchema = z.object({
184
- id: UUIDSchema,
185
- });
186
-
187
- /** List memory input schema */
188
- export const ListMemoryInputSchema = z.object({
189
- category: CategorySchema.optional(),
190
- tags: z.array(TagSchema).optional(),
191
- fromDate: ISO8601TimestampSchema.optional(),
192
- toDate: ISO8601TimestampSchema.optional(),
193
- limit: z.number().int().min(1).max(100).optional(),
194
- offset: z.number().int().min(0).optional(),
195
- sortBy: SortFieldSchema.optional(),
196
- sortOrder: SortOrderSchema.optional(),
197
- });
198
-
199
- /** Search memory input schema */
200
- export const SearchMemoryInputSchema = z.object({
201
- query: z.string().min(1).max(1000),
202
- limit: z.number().int().min(1).max(100).optional(),
203
- category: CategorySchema.optional(),
204
- tags: z.array(TagSchema).optional(),
205
- });
206
-
207
- /** memory_load input schema */
208
- export const MemoryLoadInputSchema = z.object({
209
- id: UUIDSchema.optional(),
210
- query: z.string().min(1).max(1000).optional(),
211
- category: CategorySchema.optional(),
212
- tags: z.array(TagSchema).optional(),
213
- limit: z.number().int().min(1).max(100).optional(),
214
- });
215
-
216
- /** memory_update (upsert/append) input schema */
217
- export const MemoryUpdateInputV2Schema = z.object({
218
- id: UUIDSchema.optional(),
219
- sessionId: UUIDSchema.optional(),
220
- mode: z.enum(['append', 'upsert']).default('append'),
221
- entryType: MemoryEntryTypeSchema.optional(),
222
- title: z.string().min(1).max(200).optional(),
223
- content: z.string().min(1).max(100000),
224
- tags: z.array(TagSchema).optional(),
225
- category: CategorySchema.optional(),
226
- importance: ImportanceSchema.optional(),
227
- });
228
-
229
- // ============================================================================
230
- // MCP Tool Output Schemas
231
- // ============================================================================
232
-
233
- /** Create memory output schema */
234
- export const CreateMemoryOutputSchema = CreateResultSchema;
235
-
236
- /** Read memory output schema */
237
- export const ReadMemoryOutputSchema = z.object({
238
- memory: MemorySchema,
239
- });
240
-
241
- /** Update memory output schema */
242
- export const UpdateMemoryOutputSchema = UpdateResultSchema;
243
-
244
- export const MemoryLoadOutputSchema = z.object({
245
- items: z.array(MemorySchema),
246
- total: z.number().int().nonnegative(),
247
- });
248
-
249
- export const MemoryUpdateOutputSchema = z.object({
250
- id: UUIDSchema,
251
- sessionId: UUIDSchema,
252
- filePath: z.string().min(1),
253
- created: z.boolean(),
254
- updated: z.boolean(),
255
- memory: MemorySchema,
256
- });
257
-
258
- /** Delete memory output schema */
259
- export const DeleteMemoryOutputSchema = DeleteResultSchema;
260
-
261
- /** List memory output schema */
262
- export const ListMemoryOutputSchema = ListResultSchema;
263
-
264
- /** Search memory output schema */
265
- export const SearchMemoryOutputSchema = z.object({
266
- results: z.array(SearchResultSchema),
267
- total: z.number().int().nonnegative(),
268
- });
269
-
270
- /** Get categories output schema */
271
- export const GetCategoriesOutputSchema = z.object({
272
- categories: z.array(CategorySchema),
273
- });
274
-
275
- /** Get tags output schema */
276
- export const GetTagsOutputSchema = z.object({
277
- tags: z.array(TagSchema),
278
- });
279
-
280
- // ============================================================================
281
- // Configuration Schemas
282
- // ============================================================================
283
-
284
- /** Configuration schema */
285
- export const ConfigSchema = z.object({
286
- storagePath: z.string().min(1),
287
- logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
288
- });
289
-
290
- // ============================================================================
291
- // Type Extraction from Schemas
292
- // ============================================================================
293
-
294
- /** Inferred Memory type from schema */
295
- export type MemoryFromSchema = z.infer<typeof MemorySchema>;
296
-
297
- /** Inferred CreateInput type from schema */
298
- export type CreateMemoryInputFromSchema = z.infer<typeof CreateMemoryInputSchema>;
299
-
300
- /** Inferred UpdateInput type from schema */
301
- export type UpdateMemoryInputFromSchema = z.infer<typeof UpdateMemoryInputSchema>;
302
-
303
- /** Inferred ListInput type from schema */
304
- export type ListMemoryInputFromSchema = z.infer<typeof ListMemoryInputSchema>;
305
-
306
- /** Inferred SearchInput type from schema */
307
- export type SearchMemoryInputFromSchema = z.infer<typeof SearchMemoryInputSchema>;
1
+ /**
2
+ * Zod schemas for runtime validation
3
+ * All schemas correspond to types defined in types.ts
4
+ */
5
+
6
+ import { z } from 'zod';
7
+
8
+ // ============================================================================
9
+ // Primitive Schemas
10
+ // ============================================================================
11
+
12
+ /** UUID v4 validation schema */
13
+ export const UUIDSchema = z.string().uuid().brand<'UUID'>();
14
+
15
+ /** ISO 8601 timestamp validation */
16
+ export const ISO8601TimestampSchema = z.string().datetime().brand<'ISO8601'>();
17
+
18
+ /** Slug validation (URL-friendly string) */
19
+ export const SlugSchema = z
20
+ .string()
21
+ .min(1)
22
+ .max(100)
23
+ .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Must be a valid URL slug');
24
+
25
+ /** Tag name validation */
26
+ export const TagSchema = z
27
+ .string()
28
+ .min(1)
29
+ .max(50)
30
+ .regex(/^[a-z0-9-]+$/, 'Tags can only contain lowercase letters, numbers, and hyphens');
31
+
32
+ /** Category name validation */
33
+ export const CategorySchema = z
34
+ .string()
35
+ .min(1)
36
+ .max(50)
37
+ .regex(/^[a-z0-9-]+$/, 'Category can only contain lowercase letters, numbers, and hyphens');
38
+
39
+ /** Importance level validation (1-5) */
40
+ export const ImportanceSchema = z.number().int().min(1).max(5);
41
+
42
+ /** STM memory entry type */
43
+ export const MemoryEntryTypeSchema = z.enum([
44
+ 'preference', // User likes/dislikes
45
+ 'decision', // Technical choices with reasoning
46
+ 'context', // Project/environment information
47
+ 'fact', // Objective knowledge
48
+ ]);
49
+
50
+ // ============================================================================
51
+ // Memory Schemas
52
+ // ============================================================================
53
+
54
+ /** Memory front matter schema (YAML portion) */
55
+ export const MemoryFrontMatterSchema = z.object({
56
+ id: UUIDSchema,
57
+ created_at: ISO8601TimestampSchema,
58
+ updated_at: ISO8601TimestampSchema,
59
+ session_id: UUIDSchema.optional(),
60
+ entry_type: MemoryEntryTypeSchema.optional(),
61
+ tags: z.array(TagSchema).default([]),
62
+ category: CategorySchema.default('general'),
63
+ importance: ImportanceSchema.default(3),
64
+ });
65
+
66
+ /** Complete memory schema */
67
+ export const MemorySchema = z.object({
68
+ id: UUIDSchema,
69
+ createdAt: ISO8601TimestampSchema,
70
+ updatedAt: ISO8601TimestampSchema,
71
+ sessionId: UUIDSchema.optional(),
72
+ entryType: MemoryEntryTypeSchema.optional(),
73
+ tags: z.array(z.string()).readonly(),
74
+ category: CategorySchema,
75
+ importance: ImportanceSchema,
76
+ title: z.string().min(1).max(200),
77
+ content: z.string().max(100000),
78
+ });
79
+
80
+ /** Memory file schema */
81
+ export const MemoryFileSchema = z.object({
82
+ path: z.string().min(1),
83
+ filename: z.string().min(1),
84
+ content: z.string(),
85
+ modifiedAt: ISO8601TimestampSchema,
86
+ });
87
+
88
+ // ============================================================================
89
+ // Result Schemas
90
+ // ============================================================================
91
+
92
+ /** Search result schema */
93
+ export const SearchResultSchema = z.object({
94
+ memory: MemorySchema,
95
+ score: z.number().min(0).max(1),
96
+ matches: z.array(z.string()),
97
+ });
98
+
99
+ /** List result schema */
100
+ export const ListResultSchema = z.object({
101
+ memories: z.array(MemorySchema),
102
+ total: z.number().int().nonnegative(),
103
+ hasMore: z.boolean(),
104
+ });
105
+
106
+ /** Create result schema */
107
+ export const CreateResultSchema = z.object({
108
+ id: UUIDSchema,
109
+ filePath: z.string().min(1),
110
+ memory: MemorySchema,
111
+ });
112
+
113
+ /** Update result schema */
114
+ export const UpdateResultSchema = z.object({
115
+ memory: MemorySchema,
116
+ });
117
+
118
+ /** Delete result schema */
119
+ export const DeleteResultSchema = z.object({
120
+ success: z.boolean(),
121
+ filePath: z.string().min(1),
122
+ });
123
+
124
+ // ============================================================================
125
+ // Filter and Query Schemas
126
+ // ============================================================================
127
+
128
+ /** Sort field enum */
129
+ export const SortFieldSchema = z.enum(['createdAt', 'updatedAt', 'title', 'importance']);
130
+
131
+ /** Sort order enum */
132
+ export const SortOrderSchema = z.enum(['asc', 'desc']);
133
+
134
+ /** Memory filter schema */
135
+ export const MemoryFilterSchema = z.object({
136
+ category: CategorySchema.optional(),
137
+ tags: z.array(TagSchema).optional(),
138
+ fromDate: ISO8601TimestampSchema.optional(),
139
+ toDate: ISO8601TimestampSchema.optional(),
140
+ });
141
+
142
+ /** Pagination options schema */
143
+ export const PaginationOptionsSchema = z.object({
144
+ limit: z.number().int().min(1).max(100).default(20),
145
+ offset: z.number().int().min(0).default(0),
146
+ });
147
+
148
+ /** Sort options schema */
149
+ export const SortOptionsSchema = z.object({
150
+ sortBy: SortFieldSchema.default('createdAt'),
151
+ sortOrder: SortOrderSchema.default('desc'),
152
+ });
153
+
154
+ // ============================================================================
155
+ // MCP Tool Input Schemas
156
+ // ============================================================================
157
+
158
+ /** Create memory input schema */
159
+ export const CreateMemoryInputSchema = z.object({
160
+ title: z.string().min(1).max(200),
161
+ content: z.string().max(100000),
162
+ tags: z.array(TagSchema).default([]),
163
+ category: CategorySchema.default('general'),
164
+ importance: ImportanceSchema.default(3),
165
+ });
166
+
167
+ /** Read memory input schema */
168
+ export const ReadMemoryInputSchema = z.object({
169
+ id: UUIDSchema,
170
+ });
171
+
172
+ /** Update memory input schema */
173
+ export const UpdateMemoryInputSchema = z.object({
174
+ id: UUIDSchema,
175
+ title: z.string().min(1).max(200).optional(),
176
+ content: z.string().max(100000).optional(),
177
+ tags: z.array(TagSchema).optional(),
178
+ category: CategorySchema.optional(),
179
+ importance: ImportanceSchema.optional(),
180
+ });
181
+
182
+ /** Delete memory input schema */
183
+ export const DeleteMemoryInputSchema = z.object({
184
+ id: UUIDSchema,
185
+ });
186
+
187
+ /** List memory input schema */
188
+ export const ListMemoryInputSchema = z.object({
189
+ category: CategorySchema.optional(),
190
+ tags: z.array(TagSchema).optional(),
191
+ fromDate: ISO8601TimestampSchema.optional(),
192
+ toDate: ISO8601TimestampSchema.optional(),
193
+ limit: z.number().int().min(1).max(100).optional(),
194
+ offset: z.number().int().min(0).optional(),
195
+ sortBy: SortFieldSchema.optional(),
196
+ sortOrder: SortOrderSchema.optional(),
197
+ });
198
+
199
+ /** Search memory input schema */
200
+ export const SearchMemoryInputSchema = z.object({
201
+ query: z.string().min(1).max(1000),
202
+ limit: z.number().int().min(1).max(100).optional(),
203
+ category: CategorySchema.optional(),
204
+ tags: z.array(TagSchema).optional(),
205
+ });
206
+
207
+ /** memory_load input schema */
208
+ export const MemoryLoadInputSchema = z.object({
209
+ id: UUIDSchema.optional(),
210
+ query: z.string().min(1).max(1000).optional(),
211
+ category: CategorySchema.optional(),
212
+ tags: z.array(TagSchema).optional(),
213
+ limit: z.number().int().min(1).max(100).optional(),
214
+ });
215
+
216
+ /** memory_update (upsert/append) input schema */
217
+ export const MemoryUpdateInputV2Schema = z.object({
218
+ id: UUIDSchema.optional(),
219
+ sessionId: UUIDSchema.optional(),
220
+ mode: z.enum(['append', 'upsert']).default('append'),
221
+ entryType: MemoryEntryTypeSchema.optional(),
222
+ title: z.string().min(1).max(200).optional(),
223
+ content: z.string().min(1).max(100000),
224
+ tags: z.array(TagSchema).optional(),
225
+ category: CategorySchema.optional(),
226
+ importance: ImportanceSchema.optional(),
227
+ });
228
+
229
+ // ============================================================================
230
+ // MCP Tool Output Schemas
231
+ // ============================================================================
232
+
233
+ /** Create memory output schema */
234
+ export const CreateMemoryOutputSchema = CreateResultSchema;
235
+
236
+ /** Read memory output schema */
237
+ export const ReadMemoryOutputSchema = z.object({
238
+ memory: MemorySchema,
239
+ });
240
+
241
+ /** Update memory output schema */
242
+ export const UpdateMemoryOutputSchema = UpdateResultSchema;
243
+
244
+ export const MemoryLoadOutputSchema = z.object({
245
+ items: z.array(MemorySchema),
246
+ total: z.number().int().nonnegative(),
247
+ });
248
+
249
+ export const MemoryUpdateOutputSchema = z.object({
250
+ id: UUIDSchema,
251
+ sessionId: UUIDSchema,
252
+ filePath: z.string().min(1),
253
+ created: z.boolean(),
254
+ updated: z.boolean(),
255
+ memory: MemorySchema,
256
+ });
257
+
258
+ /** Delete memory output schema */
259
+ export const DeleteMemoryOutputSchema = DeleteResultSchema;
260
+
261
+ /** List memory output schema */
262
+ export const ListMemoryOutputSchema = ListResultSchema;
263
+
264
+ /** Search memory output schema */
265
+ export const SearchMemoryOutputSchema = z.object({
266
+ results: z.array(SearchResultSchema),
267
+ total: z.number().int().nonnegative(),
268
+ });
269
+
270
+ /** Get categories output schema */
271
+ export const GetCategoriesOutputSchema = z.object({
272
+ categories: z.array(CategorySchema),
273
+ });
274
+
275
+ /** Get tags output schema */
276
+ export const GetTagsOutputSchema = z.object({
277
+ tags: z.array(TagSchema),
278
+ });
279
+
280
+ // ============================================================================
281
+ // Configuration Schemas
282
+ // ============================================================================
283
+
284
+ /** Configuration schema */
285
+ export const ConfigSchema = z.object({
286
+ storagePath: z.string().min(1),
287
+ logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
288
+ });
289
+
290
+ // ============================================================================
291
+ // Type Extraction from Schemas
292
+ // ============================================================================
293
+
294
+ /** Inferred Memory type from schema */
295
+ export type MemoryFromSchema = z.infer<typeof MemorySchema>;
296
+
297
+ /** Inferred CreateInput type from schema */
298
+ export type CreateMemoryInputFromSchema = z.infer<typeof CreateMemoryInputSchema>;
299
+
300
+ /** Inferred UpdateInput type from schema */
301
+ export type UpdateMemoryInputFromSchema = z.infer<typeof UpdateMemoryInputSchema>;
302
+
303
+ /** Inferred ListInput type from schema */
304
+ export type ListMemoryInputFromSchema = z.infer<typeof ListMemoryInputSchema>;
305
+
306
+ /** Inferred SearchInput type from schema */
307
+ export type SearchMemoryInputFromSchema = z.infer<typeof SearchMemoryInputSchema>;