@danielsimonjr/memory-mcp 0.48.0 → 9.8.2

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 (210) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2000 -194
  3. package/dist/__tests__/file-path.test.js +7 -11
  4. package/dist/__tests__/knowledge-graph.test.js +3 -8
  5. package/dist/core/EntityManager.d.ts +266 -0
  6. package/dist/core/EntityManager.d.ts.map +1 -0
  7. package/dist/core/EntityManager.js +89 -137
  8. package/dist/core/GraphEventEmitter.d.ts +202 -0
  9. package/dist/core/GraphEventEmitter.d.ts.map +1 -0
  10. package/dist/core/GraphEventEmitter.js +346 -0
  11. package/dist/core/GraphStorage.d.ts +395 -0
  12. package/dist/core/GraphStorage.d.ts.map +1 -0
  13. package/dist/core/GraphStorage.js +644 -31
  14. package/dist/core/GraphTraversal.d.ts +141 -0
  15. package/dist/core/GraphTraversal.d.ts.map +1 -0
  16. package/dist/core/GraphTraversal.js +573 -0
  17. package/dist/core/HierarchyManager.d.ts +111 -0
  18. package/dist/core/HierarchyManager.d.ts.map +1 -0
  19. package/dist/{features → core}/HierarchyManager.js +14 -9
  20. package/dist/core/ManagerContext.d.ts +72 -0
  21. package/dist/core/ManagerContext.d.ts.map +1 -0
  22. package/dist/core/ManagerContext.js +118 -0
  23. package/dist/core/ObservationManager.d.ts +85 -0
  24. package/dist/core/ObservationManager.d.ts.map +1 -0
  25. package/dist/core/ObservationManager.js +51 -57
  26. package/dist/core/RelationManager.d.ts +131 -0
  27. package/dist/core/RelationManager.d.ts.map +1 -0
  28. package/dist/core/RelationManager.js +31 -7
  29. package/dist/core/SQLiteStorage.d.ts +354 -0
  30. package/dist/core/SQLiteStorage.d.ts.map +1 -0
  31. package/dist/core/SQLiteStorage.js +918 -0
  32. package/dist/core/StorageFactory.d.ts +45 -0
  33. package/dist/core/StorageFactory.d.ts.map +1 -0
  34. package/dist/core/StorageFactory.js +64 -0
  35. package/dist/core/TransactionManager.d.ts +464 -0
  36. package/dist/core/TransactionManager.d.ts.map +1 -0
  37. package/dist/core/TransactionManager.js +493 -14
  38. package/dist/core/index.d.ts +17 -0
  39. package/dist/core/index.d.ts.map +1 -0
  40. package/dist/core/index.js +12 -2
  41. package/dist/features/AnalyticsManager.d.ts +44 -0
  42. package/dist/features/AnalyticsManager.d.ts.map +1 -0
  43. package/dist/features/AnalyticsManager.js +3 -2
  44. package/dist/features/ArchiveManager.d.ts +133 -0
  45. package/dist/features/ArchiveManager.d.ts.map +1 -0
  46. package/dist/features/ArchiveManager.js +221 -14
  47. package/dist/features/CompressionManager.d.ts +117 -0
  48. package/dist/features/CompressionManager.d.ts.map +1 -0
  49. package/dist/features/CompressionManager.js +189 -20
  50. package/dist/features/IOManager.d.ts +225 -0
  51. package/dist/features/IOManager.d.ts.map +1 -0
  52. package/dist/features/IOManager.js +1092 -0
  53. package/dist/features/StreamingExporter.d.ts +128 -0
  54. package/dist/features/StreamingExporter.d.ts.map +1 -0
  55. package/dist/features/StreamingExporter.js +211 -0
  56. package/dist/features/TagManager.d.ts +147 -0
  57. package/dist/features/TagManager.d.ts.map +1 -0
  58. package/dist/features/index.d.ts +12 -0
  59. package/dist/features/index.d.ts.map +1 -0
  60. package/dist/features/index.js +5 -6
  61. package/dist/index.d.ts +9 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -10
  64. package/dist/memory.jsonl +1 -26
  65. package/dist/search/BasicSearch.d.ts +51 -0
  66. package/dist/search/BasicSearch.d.ts.map +1 -0
  67. package/dist/search/BasicSearch.js +9 -3
  68. package/dist/search/BooleanSearch.d.ts +98 -0
  69. package/dist/search/BooleanSearch.d.ts.map +1 -0
  70. package/dist/search/BooleanSearch.js +156 -9
  71. package/dist/search/EmbeddingService.d.ts +178 -0
  72. package/dist/search/EmbeddingService.d.ts.map +1 -0
  73. package/dist/search/EmbeddingService.js +358 -0
  74. package/dist/search/FuzzySearch.d.ts +118 -0
  75. package/dist/search/FuzzySearch.d.ts.map +1 -0
  76. package/dist/search/FuzzySearch.js +241 -25
  77. package/dist/search/QueryCostEstimator.d.ts +111 -0
  78. package/dist/search/QueryCostEstimator.d.ts.map +1 -0
  79. package/dist/search/QueryCostEstimator.js +355 -0
  80. package/dist/search/RankedSearch.d.ts +71 -0
  81. package/dist/search/RankedSearch.d.ts.map +1 -0
  82. package/dist/search/RankedSearch.js +54 -6
  83. package/dist/search/SavedSearchManager.d.ts +79 -0
  84. package/dist/search/SavedSearchManager.d.ts.map +1 -0
  85. package/dist/search/SavedSearchManager.js +3 -2
  86. package/dist/search/SearchFilterChain.d.ts +120 -0
  87. package/dist/search/SearchFilterChain.d.ts.map +1 -0
  88. package/dist/search/SearchFilterChain.js +2 -4
  89. package/dist/search/SearchManager.d.ts +326 -0
  90. package/dist/search/SearchManager.d.ts.map +1 -0
  91. package/dist/search/SearchManager.js +148 -0
  92. package/dist/search/SearchSuggestions.d.ts +27 -0
  93. package/dist/search/SearchSuggestions.d.ts.map +1 -0
  94. package/dist/search/SearchSuggestions.js +1 -1
  95. package/dist/search/SemanticSearch.d.ts +149 -0
  96. package/dist/search/SemanticSearch.d.ts.map +1 -0
  97. package/dist/search/SemanticSearch.js +323 -0
  98. package/dist/search/TFIDFEventSync.d.ts +85 -0
  99. package/dist/search/TFIDFEventSync.d.ts.map +1 -0
  100. package/dist/search/TFIDFEventSync.js +133 -0
  101. package/dist/search/TFIDFIndexManager.d.ts +151 -0
  102. package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
  103. package/dist/search/TFIDFIndexManager.js +232 -17
  104. package/dist/search/VectorStore.d.ts +235 -0
  105. package/dist/search/VectorStore.d.ts.map +1 -0
  106. package/dist/search/VectorStore.js +311 -0
  107. package/dist/search/index.d.ts +21 -0
  108. package/dist/search/index.d.ts.map +1 -0
  109. package/dist/search/index.js +12 -0
  110. package/dist/server/MCPServer.d.ts +21 -0
  111. package/dist/server/MCPServer.d.ts.map +1 -0
  112. package/dist/server/MCPServer.js +4 -4
  113. package/dist/server/responseCompressor.d.ts +94 -0
  114. package/dist/server/responseCompressor.d.ts.map +1 -0
  115. package/dist/server/responseCompressor.js +127 -0
  116. package/dist/server/toolDefinitions.d.ts +27 -0
  117. package/dist/server/toolDefinitions.d.ts.map +1 -0
  118. package/dist/server/toolDefinitions.js +188 -17
  119. package/dist/server/toolHandlers.d.ts +41 -0
  120. package/dist/server/toolHandlers.d.ts.map +1 -0
  121. package/dist/server/toolHandlers.js +469 -75
  122. package/dist/types/index.d.ts +13 -0
  123. package/dist/types/index.d.ts.map +1 -0
  124. package/dist/types/index.js +1 -1
  125. package/dist/types/types.d.ts +1654 -0
  126. package/dist/types/types.d.ts.map +1 -0
  127. package/dist/types/types.js +9 -0
  128. package/dist/utils/compressedCache.d.ts +192 -0
  129. package/dist/utils/compressedCache.d.ts.map +1 -0
  130. package/dist/utils/compressedCache.js +309 -0
  131. package/dist/utils/compressionUtil.d.ts +214 -0
  132. package/dist/utils/compressionUtil.d.ts.map +1 -0
  133. package/dist/utils/compressionUtil.js +247 -0
  134. package/dist/utils/constants.d.ts +245 -0
  135. package/dist/utils/constants.d.ts.map +1 -0
  136. package/dist/utils/constants.js +124 -0
  137. package/dist/utils/entityUtils.d.ts +354 -0
  138. package/dist/utils/entityUtils.d.ts.map +1 -0
  139. package/dist/utils/entityUtils.js +511 -4
  140. package/dist/utils/errors.d.ts +95 -0
  141. package/dist/utils/errors.d.ts.map +1 -0
  142. package/dist/utils/errors.js +24 -0
  143. package/dist/utils/formatters.d.ts +145 -0
  144. package/dist/utils/formatters.d.ts.map +1 -0
  145. package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
  146. package/dist/utils/index.d.ts +23 -0
  147. package/dist/utils/index.d.ts.map +1 -0
  148. package/dist/utils/index.js +71 -31
  149. package/dist/utils/indexes.d.ts +270 -0
  150. package/dist/utils/indexes.d.ts.map +1 -0
  151. package/dist/utils/indexes.js +526 -0
  152. package/dist/utils/logger.d.ts +24 -0
  153. package/dist/utils/logger.d.ts.map +1 -0
  154. package/dist/utils/operationUtils.d.ts +124 -0
  155. package/dist/utils/operationUtils.d.ts.map +1 -0
  156. package/dist/utils/operationUtils.js +175 -0
  157. package/dist/utils/parallelUtils.d.ts +76 -0
  158. package/dist/utils/parallelUtils.d.ts.map +1 -0
  159. package/dist/utils/parallelUtils.js +191 -0
  160. package/dist/utils/schemas.d.ts +374 -0
  161. package/dist/utils/schemas.d.ts.map +1 -0
  162. package/dist/utils/schemas.js +307 -7
  163. package/dist/utils/searchAlgorithms.d.ts +99 -0
  164. package/dist/utils/searchAlgorithms.d.ts.map +1 -0
  165. package/dist/utils/searchAlgorithms.js +167 -0
  166. package/dist/utils/searchCache.d.ts +108 -0
  167. package/dist/utils/searchCache.d.ts.map +1 -0
  168. package/dist/utils/taskScheduler.d.ts +294 -0
  169. package/dist/utils/taskScheduler.d.ts.map +1 -0
  170. package/dist/utils/taskScheduler.js +486 -0
  171. package/dist/workers/index.d.ts +12 -0
  172. package/dist/workers/index.d.ts.map +1 -0
  173. package/dist/workers/index.js +9 -0
  174. package/dist/workers/levenshteinWorker.d.ts +60 -0
  175. package/dist/workers/levenshteinWorker.d.ts.map +1 -0
  176. package/dist/workers/levenshteinWorker.js +98 -0
  177. package/package.json +17 -4
  178. package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
  179. package/dist/__tests__/integration/workflows.test.js +0 -449
  180. package/dist/__tests__/performance/benchmarks.test.js +0 -413
  181. package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
  182. package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
  183. package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
  184. package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
  185. package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
  186. package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
  187. package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
  188. package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
  189. package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
  190. package/dist/core/KnowledgeGraphManager.js +0 -423
  191. package/dist/features/BackupManager.js +0 -311
  192. package/dist/features/ExportManager.js +0 -305
  193. package/dist/features/ImportExportManager.js +0 -50
  194. package/dist/features/ImportManager.js +0 -328
  195. package/dist/memory-saved-searches.jsonl +0 -0
  196. package/dist/memory-tag-aliases.jsonl +0 -0
  197. package/dist/types/analytics.types.js +0 -6
  198. package/dist/types/entity.types.js +0 -7
  199. package/dist/types/import-export.types.js +0 -7
  200. package/dist/types/search.types.js +0 -7
  201. package/dist/types/tag.types.js +0 -6
  202. package/dist/utils/dateUtils.js +0 -89
  203. package/dist/utils/filterUtils.js +0 -155
  204. package/dist/utils/levenshtein.js +0 -62
  205. package/dist/utils/pathUtils.js +0 -115
  206. package/dist/utils/responseFormatter.js +0 -55
  207. package/dist/utils/tagUtils.js +0 -107
  208. package/dist/utils/tfidf.js +0 -90
  209. package/dist/utils/validationHelper.js +0 -99
  210. package/dist/utils/validationUtils.js +0 -109
@@ -0,0 +1,354 @@
1
+ /**
2
+ * Entity Utilities
3
+ *
4
+ * Consolidated module for entity-related utilities including:
5
+ * - Entity lookup and manipulation functions
6
+ * - Tag normalization and matching
7
+ * - Date parsing and validation
8
+ * - Entity filtering by various criteria
9
+ * - Path utilities and validation
10
+ *
11
+ * @module utils/entityUtils
12
+ */
13
+ import type { Entity, KnowledgeGraph } from '../types/index.js';
14
+ /**
15
+ * Finds an entity by name in the graph.
16
+ * Overloaded to provide type-safe returns based on throwIfNotFound parameter.
17
+ *
18
+ * @param graph - The knowledge graph to search
19
+ * @param name - The entity name to find
20
+ * @param throwIfNotFound - Whether to throw if entity doesn't exist (default: true)
21
+ * @returns The entity if found, null if not found and throwIfNotFound is false
22
+ * @throws EntityNotFoundError if entity not found and throwIfNotFound is true
23
+ */
24
+ export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound: true): Entity;
25
+ export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound: false): Entity | null;
26
+ export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound?: boolean): Entity | null;
27
+ /**
28
+ * Finds multiple entities by name.
29
+ *
30
+ * @param graph - The knowledge graph to search
31
+ * @param names - Array of entity names to find
32
+ * @param throwIfAnyNotFound - Whether to throw if any entity doesn't exist (default: true)
33
+ * @returns Array of found entities (may be shorter than names if throwIfAnyNotFound is false)
34
+ * @throws EntityNotFoundError if any entity not found and throwIfAnyNotFound is true
35
+ */
36
+ export declare function findEntitiesByNames(graph: KnowledgeGraph, names: string[], throwIfAnyNotFound?: boolean): Entity[];
37
+ /**
38
+ * Checks if an entity exists in the graph.
39
+ *
40
+ * @param graph - The knowledge graph to search
41
+ * @param name - The entity name to check
42
+ * @returns true if entity exists, false otherwise
43
+ */
44
+ export declare function entityExists(graph: KnowledgeGraph, name: string): boolean;
45
+ /**
46
+ * Gets the index of an entity in the graph's entities array.
47
+ *
48
+ * @param graph - The knowledge graph to search
49
+ * @param name - The entity name to find
50
+ * @returns The index if found, -1 otherwise
51
+ */
52
+ export declare function getEntityIndex(graph: KnowledgeGraph, name: string): number;
53
+ /**
54
+ * Removes an entity from the graph by name.
55
+ * Mutates the graph's entities array in place.
56
+ *
57
+ * @param graph - The knowledge graph to modify
58
+ * @param name - The entity name to remove
59
+ * @returns true if entity was removed, false if not found
60
+ */
61
+ export declare function removeEntityByName(graph: KnowledgeGraph, name: string): boolean;
62
+ /**
63
+ * Gets all entity names as a Set for fast lookup.
64
+ *
65
+ * @param graph - The knowledge graph
66
+ * @returns Set of all entity names
67
+ */
68
+ export declare function getEntityNameSet(graph: KnowledgeGraph): Set<string>;
69
+ /**
70
+ * Groups entities by their type.
71
+ *
72
+ * @param entities - Array of entities to group
73
+ * @returns Map of entity type to array of entities
74
+ */
75
+ export declare function groupEntitiesByType(entities: Entity[]): Map<string, Entity[]>;
76
+ /**
77
+ * Updates the lastModified timestamp on an entity.
78
+ * Mutates the entity in place.
79
+ *
80
+ * @param entity - The entity to update
81
+ * @returns The updated entity (same reference)
82
+ */
83
+ export declare function touchEntity(entity: Entity): Entity;
84
+ /**
85
+ * Normalizes a single tag to lowercase and trimmed.
86
+ *
87
+ * @param tag - Tag to normalize
88
+ * @returns Normalized tag
89
+ */
90
+ export declare function normalizeTag(tag: string): string;
91
+ /**
92
+ * Normalizes an array of tags to lowercase.
93
+ * Handles undefined/null input gracefully.
94
+ *
95
+ * @param tags - Array of tags to normalize, or undefined
96
+ * @returns Normalized tags array, or empty array if input is undefined/null
97
+ */
98
+ export declare function normalizeTags(tags: string[] | undefined | null): string[];
99
+ /**
100
+ * Checks if an entity's tags include any of the specified search tags.
101
+ * Both inputs are normalized before comparison.
102
+ *
103
+ * @param entityTags - Tags on the entity (may be undefined)
104
+ * @param searchTags - Tags to search for (may be undefined)
105
+ * @returns true if any search tag matches any entity tag, false if no match or either is empty
106
+ */
107
+ export declare function hasMatchingTag(entityTags: string[] | undefined, searchTags: string[] | undefined): boolean;
108
+ /**
109
+ * Checks if entity tags include ALL of the specified required tags.
110
+ *
111
+ * @param entityTags - Tags on the entity (may be undefined)
112
+ * @param requiredTags - All tags that must be present
113
+ * @returns true if all required tags are present
114
+ */
115
+ export declare function hasAllTags(entityTags: string[] | undefined, requiredTags: string[]): boolean;
116
+ /**
117
+ * Filters entities by tag match.
118
+ * Returns all entities if searchTags is empty or undefined.
119
+ *
120
+ * @param entities - Array of entities with optional tags property
121
+ * @param searchTags - Tags to filter by
122
+ * @returns Filtered entities that have at least one matching tag
123
+ */
124
+ export declare function filterByTags<T extends {
125
+ tags?: string[];
126
+ }>(entities: T[], searchTags: string[] | undefined): T[];
127
+ /**
128
+ * Adds new tags to an existing tag array, avoiding duplicates.
129
+ * All tags are normalized to lowercase.
130
+ *
131
+ * @param existingTags - Current tags (may be undefined)
132
+ * @param newTags - Tags to add
133
+ * @returns Combined tags array with no duplicates
134
+ */
135
+ export declare function addUniqueTags(existingTags: string[] | undefined, newTags: string[]): string[];
136
+ /**
137
+ * Removes specified tags from an existing tag array.
138
+ * Comparison is case-insensitive.
139
+ *
140
+ * @param existingTags - Current tags (may be undefined)
141
+ * @param tagsToRemove - Tags to remove
142
+ * @returns Tags array with specified tags removed
143
+ */
144
+ export declare function removeTags(existingTags: string[] | undefined, tagsToRemove: string[]): string[];
145
+ /**
146
+ * Check if a date falls within a specified range.
147
+ *
148
+ * @param date - ISO 8601 date string to check (may be undefined)
149
+ * @param start - Optional start date (inclusive)
150
+ * @param end - Optional end date (inclusive)
151
+ * @returns True if date is within range or no filters are set
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * isWithinDateRange('2024-06-15T00:00:00Z', '2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z'); // true
156
+ * isWithinDateRange('2024-06-15T00:00:00Z', '2024-07-01T00:00:00Z'); // false
157
+ * isWithinDateRange(undefined); // true (no filters)
158
+ * isWithinDateRange(undefined, '2024-01-01T00:00:00Z'); // false (has filter but no date)
159
+ * ```
160
+ */
161
+ export declare function isWithinDateRange(date: string | undefined, start?: string, end?: string): boolean;
162
+ /**
163
+ * Parse and validate date range strings.
164
+ *
165
+ * @param startDate - Optional ISO 8601 start date
166
+ * @param endDate - Optional ISO 8601 end date
167
+ * @returns Parsed Date objects or null
168
+ */
169
+ export declare function parseDateRange(startDate?: string, endDate?: string): {
170
+ start: Date | null;
171
+ end: Date | null;
172
+ };
173
+ /**
174
+ * Validate if a string is a valid ISO 8601 date.
175
+ *
176
+ * @param date - Date string to validate
177
+ * @returns True if valid ISO 8601 date
178
+ */
179
+ export declare function isValidISODate(date: string): boolean;
180
+ /**
181
+ * Get current timestamp in ISO 8601 format.
182
+ *
183
+ * @returns Current timestamp string
184
+ */
185
+ export declare function getCurrentTimestamp(): string;
186
+ /**
187
+ * Checks if an entity's importance is within the specified range.
188
+ * Entities without importance are treated as not matching if any filter is set.
189
+ *
190
+ * @param importance - The entity's importance value (may be undefined)
191
+ * @param minImportance - Minimum importance filter (inclusive)
192
+ * @param maxImportance - Maximum importance filter (inclusive)
193
+ * @returns true if importance is within range or no filters are set
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * // Check if entity passes importance filter
198
+ * if (isWithinImportanceRange(entity.importance, 5, 10)) {
199
+ * // Entity has importance between 5 and 10
200
+ * }
201
+ * ```
202
+ */
203
+ export declare function isWithinImportanceRange(importance: number | undefined, minImportance?: number, maxImportance?: number): boolean;
204
+ /**
205
+ * Filters entities by importance range.
206
+ * Returns all entities if no importance filters are specified.
207
+ *
208
+ * @param entities - Array of entities to filter
209
+ * @param minImportance - Minimum importance filter (inclusive)
210
+ * @param maxImportance - Maximum importance filter (inclusive)
211
+ * @returns Filtered entities within the importance range
212
+ */
213
+ export declare function filterByImportance(entities: Entity[], minImportance?: number, maxImportance?: number): Entity[];
214
+ /**
215
+ * Filters entities by creation date range.
216
+ *
217
+ * @param entities - Array of entities to filter
218
+ * @param startDate - Start of date range (inclusive)
219
+ * @param endDate - End of date range (inclusive)
220
+ * @returns Filtered entities created within the date range
221
+ */
222
+ export declare function filterByCreatedDate(entities: Entity[], startDate?: string, endDate?: string): Entity[];
223
+ /**
224
+ * Filters entities by last modified date range.
225
+ *
226
+ * @param entities - Array of entities to filter
227
+ * @param startDate - Start of date range (inclusive)
228
+ * @param endDate - End of date range (inclusive)
229
+ * @returns Filtered entities modified within the date range
230
+ */
231
+ export declare function filterByModifiedDate(entities: Entity[], startDate?: string, endDate?: string): Entity[];
232
+ /**
233
+ * Filters entities by entity type.
234
+ *
235
+ * @param entities - Array of entities to filter
236
+ * @param entityType - Entity type to filter by (case-sensitive)
237
+ * @returns Filtered entities of the specified type
238
+ */
239
+ export declare function filterByEntityType(entities: Entity[], entityType?: string): Entity[];
240
+ /**
241
+ * Common search filters that can be applied to entities.
242
+ */
243
+ export interface CommonSearchFilters {
244
+ tags?: string[];
245
+ minImportance?: number;
246
+ maxImportance?: number;
247
+ entityType?: string;
248
+ createdAfter?: string;
249
+ createdBefore?: string;
250
+ modifiedAfter?: string;
251
+ modifiedBefore?: string;
252
+ }
253
+ /**
254
+ * Checks if an entity passes all the specified filters.
255
+ * Short-circuits on first failing filter for performance.
256
+ *
257
+ * Note: Tag filtering should be handled separately using hasMatchingTag
258
+ * as it requires special normalization logic.
259
+ *
260
+ * @param entity - Entity to check
261
+ * @param filters - Filters to apply
262
+ * @returns true if entity passes all filters
263
+ */
264
+ export declare function entityPassesFilters(entity: Entity, filters: Omit<CommonSearchFilters, 'tags'>): boolean;
265
+ /**
266
+ * Sanitizes an object by removing potentially dangerous keys.
267
+ * This prevents prototype pollution attacks when using Object.assign() or spread operators.
268
+ *
269
+ * @param obj - The object to sanitize
270
+ * @returns A new object with dangerous keys removed
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * // Safe usage with Object.assign
275
+ * const updates = sanitizeObject(userInput);
276
+ * Object.assign(entity, updates);
277
+ *
278
+ * // Protects against prototype pollution
279
+ * const malicious = { __proto__: { admin: true } };
280
+ * const safe = sanitizeObject(malicious); // { }
281
+ * ```
282
+ */
283
+ export declare function sanitizeObject<T extends Record<string, unknown>>(obj: T): Partial<T>;
284
+ /**
285
+ * Escapes a CSV field to prevent formula injection attacks.
286
+ * Prepends a single quote to values that start with dangerous characters.
287
+ *
288
+ * @param field - The field value to escape
289
+ * @returns Escaped field value safe for CSV export
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * escapeCsvFormula('=SUM(A1:A10)'); // "'=SUM(A1:A10)"
294
+ * escapeCsvFormula('normal text'); // 'normal text'
295
+ * ```
296
+ */
297
+ export declare function escapeCsvFormula(field: string | undefined | null): string;
298
+ /**
299
+ * Validate and normalize a file path to prevent path traversal attacks.
300
+ *
301
+ * This function:
302
+ * - Normalizes the path to canonical form
303
+ * - Converts relative paths to absolute paths
304
+ * - Detects and prevents path traversal attempts (..)
305
+ *
306
+ * @param filePath - The file path to validate
307
+ * @param baseDir - Optional base directory for relative paths (defaults to process.cwd())
308
+ * @returns Validated absolute file path
309
+ * @throws {FileOperationError} If path traversal is detected or path is invalid
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * // Valid paths
314
+ * validateFilePath('/var/data/memory.jsonl'); // Returns absolute path
315
+ * validateFilePath('data/memory.jsonl'); // Returns absolute path from cwd
316
+ *
317
+ * // Invalid paths (throws FileOperationError)
318
+ * validateFilePath('../../../etc/passwd'); // Path traversal detected
319
+ * validateFilePath('/var/data/../../../etc/passwd'); // Path traversal detected
320
+ * ```
321
+ */
322
+ export declare function validateFilePath(filePath: string, baseDir?: string): string;
323
+ /**
324
+ * Default memory file path (in project root directory, outside dist/).
325
+ */
326
+ export declare const defaultMemoryPath: string;
327
+ /**
328
+ * Ensure memory file path with backward compatibility migration.
329
+ *
330
+ * Handles:
331
+ * 1. Custom MEMORY_FILE_PATH environment variable (with path traversal protection)
332
+ * 2. Backward compatibility: migrates memory.json to memory.jsonl
333
+ * 3. Absolute vs relative path resolution
334
+ *
335
+ * @returns Resolved and validated memory file path
336
+ * @throws {FileOperationError} If path traversal is detected in MEMORY_FILE_PATH
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * // Use environment variable
341
+ * process.env.MEMORY_FILE_PATH = '/data/memory.jsonl';
342
+ * const path = await ensureMemoryFilePath(); // '/data/memory.jsonl'
343
+ *
344
+ * // Use default path
345
+ * delete process.env.MEMORY_FILE_PATH;
346
+ * const path = await ensureMemoryFilePath(); // './memory.jsonl'
347
+ *
348
+ * // Invalid path (throws error)
349
+ * process.env.MEMORY_FILE_PATH = '../../../etc/passwd';
350
+ * await ensureMemoryFilePath(); // Throws FileOperationError
351
+ * ```
352
+ */
353
+ export declare function ensureMemoryFilePath(): Promise<string>;
354
+ //# sourceMappingURL=entityUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityUtils.d.ts","sourceRoot":"","sources":["../../src/utils/entityUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAm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