@danielsimonjr/memory-mcp 0.47.1 → 9.8.0

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 (207) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2000 -194
  3. package/dist/__tests__/file-path.test.js +5 -5
  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 +85 -133
  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 +643 -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 +917 -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 +490 -13
  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 +14 -13
  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 +1041 -0
  53. package/dist/features/StreamingExporter.d.ts +123 -0
  54. package/dist/features/StreamingExporter.d.ts.map +1 -0
  55. package/dist/features/StreamingExporter.js +203 -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 +12 -45
  64. package/dist/memory.jsonl +1 -18
  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/SearchFilterChain.d.ts +120 -0
  86. package/dist/search/SearchFilterChain.d.ts.map +1 -0
  87. package/dist/search/SearchFilterChain.js +2 -4
  88. package/dist/search/SearchManager.d.ts +326 -0
  89. package/dist/search/SearchManager.d.ts.map +1 -0
  90. package/dist/search/SearchManager.js +148 -0
  91. package/dist/search/SearchSuggestions.d.ts +27 -0
  92. package/dist/search/SearchSuggestions.d.ts.map +1 -0
  93. package/dist/search/SearchSuggestions.js +1 -1
  94. package/dist/search/SemanticSearch.d.ts +149 -0
  95. package/dist/search/SemanticSearch.d.ts.map +1 -0
  96. package/dist/search/SemanticSearch.js +323 -0
  97. package/dist/search/TFIDFEventSync.d.ts +85 -0
  98. package/dist/search/TFIDFEventSync.d.ts.map +1 -0
  99. package/dist/search/TFIDFEventSync.js +133 -0
  100. package/dist/search/TFIDFIndexManager.d.ts +151 -0
  101. package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
  102. package/dist/search/TFIDFIndexManager.js +232 -17
  103. package/dist/search/VectorStore.d.ts +235 -0
  104. package/dist/search/VectorStore.d.ts.map +1 -0
  105. package/dist/search/VectorStore.js +311 -0
  106. package/dist/search/index.d.ts +21 -0
  107. package/dist/search/index.d.ts.map +1 -0
  108. package/dist/search/index.js +12 -0
  109. package/dist/server/MCPServer.d.ts +21 -0
  110. package/dist/server/MCPServer.d.ts.map +1 -0
  111. package/dist/server/MCPServer.js +4 -4
  112. package/dist/server/responseCompressor.d.ts +94 -0
  113. package/dist/server/responseCompressor.d.ts.map +1 -0
  114. package/dist/server/responseCompressor.js +127 -0
  115. package/dist/server/toolDefinitions.d.ts +27 -0
  116. package/dist/server/toolDefinitions.d.ts.map +1 -0
  117. package/dist/server/toolDefinitions.js +189 -18
  118. package/dist/server/toolHandlers.d.ts +41 -0
  119. package/dist/server/toolHandlers.d.ts.map +1 -0
  120. package/dist/server/toolHandlers.js +467 -75
  121. package/dist/types/index.d.ts +13 -0
  122. package/dist/types/index.d.ts.map +1 -0
  123. package/dist/types/index.js +1 -1
  124. package/dist/types/types.d.ts +1654 -0
  125. package/dist/types/types.d.ts.map +1 -0
  126. package/dist/types/types.js +9 -0
  127. package/dist/utils/compressedCache.d.ts +192 -0
  128. package/dist/utils/compressedCache.d.ts.map +1 -0
  129. package/dist/utils/compressedCache.js +309 -0
  130. package/dist/utils/compressionUtil.d.ts +214 -0
  131. package/dist/utils/compressionUtil.d.ts.map +1 -0
  132. package/dist/utils/compressionUtil.js +247 -0
  133. package/dist/utils/constants.d.ts +245 -0
  134. package/dist/utils/constants.d.ts.map +1 -0
  135. package/dist/utils/constants.js +124 -0
  136. package/dist/utils/entityUtils.d.ts +321 -0
  137. package/dist/utils/entityUtils.d.ts.map +1 -0
  138. package/dist/utils/entityUtils.js +434 -4
  139. package/dist/utils/errors.d.ts +95 -0
  140. package/dist/utils/errors.d.ts.map +1 -0
  141. package/dist/utils/errors.js +24 -0
  142. package/dist/utils/formatters.d.ts +145 -0
  143. package/dist/utils/formatters.d.ts.map +1 -0
  144. package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
  145. package/dist/utils/index.d.ts +23 -0
  146. package/dist/utils/index.d.ts.map +1 -0
  147. package/dist/utils/index.js +69 -31
  148. package/dist/utils/indexes.d.ts +270 -0
  149. package/dist/utils/indexes.d.ts.map +1 -0
  150. package/dist/utils/indexes.js +526 -0
  151. package/dist/utils/logger.d.ts +24 -0
  152. package/dist/utils/logger.d.ts.map +1 -0
  153. package/dist/utils/operationUtils.d.ts +124 -0
  154. package/dist/utils/operationUtils.d.ts.map +1 -0
  155. package/dist/utils/operationUtils.js +175 -0
  156. package/dist/utils/parallelUtils.d.ts +72 -0
  157. package/dist/utils/parallelUtils.d.ts.map +1 -0
  158. package/dist/utils/parallelUtils.js +169 -0
  159. package/dist/utils/schemas.d.ts +374 -0
  160. package/dist/utils/schemas.d.ts.map +1 -0
  161. package/dist/utils/schemas.js +302 -2
  162. package/dist/utils/searchAlgorithms.d.ts +99 -0
  163. package/dist/utils/searchAlgorithms.d.ts.map +1 -0
  164. package/dist/utils/searchAlgorithms.js +167 -0
  165. package/dist/utils/searchCache.d.ts +108 -0
  166. package/dist/utils/searchCache.d.ts.map +1 -0
  167. package/dist/utils/taskScheduler.d.ts +290 -0
  168. package/dist/utils/taskScheduler.d.ts.map +1 -0
  169. package/dist/utils/taskScheduler.js +466 -0
  170. package/dist/workers/index.d.ts +12 -0
  171. package/dist/workers/index.d.ts.map +1 -0
  172. package/dist/workers/index.js +9 -0
  173. package/dist/workers/levenshteinWorker.d.ts +60 -0
  174. package/dist/workers/levenshteinWorker.d.ts.map +1 -0
  175. package/dist/workers/levenshteinWorker.js +98 -0
  176. package/package.json +17 -4
  177. package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
  178. package/dist/__tests__/integration/workflows.test.js +0 -449
  179. package/dist/__tests__/performance/benchmarks.test.js +0 -413
  180. package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
  181. package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
  182. package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
  183. package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
  184. package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
  185. package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
  186. package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
  187. package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
  188. package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
  189. package/dist/core/KnowledgeGraphManager.js +0 -423
  190. package/dist/features/BackupManager.js +0 -311
  191. package/dist/features/ExportManager.js +0 -305
  192. package/dist/features/ImportExportManager.js +0 -50
  193. package/dist/features/ImportManager.js +0 -328
  194. package/dist/types/analytics.types.js +0 -6
  195. package/dist/types/entity.types.js +0 -7
  196. package/dist/types/import-export.types.js +0 -7
  197. package/dist/types/search.types.js +0 -7
  198. package/dist/types/tag.types.js +0 -6
  199. package/dist/utils/dateUtils.js +0 -89
  200. package/dist/utils/filterUtils.js +0 -155
  201. package/dist/utils/levenshtein.js +0 -62
  202. package/dist/utils/pathUtils.js +0 -115
  203. package/dist/utils/responseFormatter.js +0 -55
  204. package/dist/utils/tagUtils.js +0 -107
  205. package/dist/utils/tfidf.js +0 -90
  206. package/dist/utils/validationHelper.js +0 -99
  207. package/dist/utils/validationUtils.js +0 -109
@@ -1,423 +0,0 @@
1
- /**
2
- * Knowledge Graph Manager
3
- *
4
- * Central manager coordinating all knowledge graph operations.
5
- * Delegates to specialized managers for different concerns.
6
- *
7
- * @module core/KnowledgeGraphManager
8
- */
9
- import path from 'path';
10
- import { DEFAULT_DUPLICATE_THRESHOLD, SEARCH_LIMITS } from '../utils/constants.js';
11
- import { GraphStorage } from './GraphStorage.js';
12
- import { EntityManager } from './EntityManager.js';
13
- import { RelationManager } from './RelationManager.js';
14
- import { SearchManager } from '../search/SearchManager.js';
15
- import { CompressionManager } from '../features/CompressionManager.js';
16
- import { HierarchyManager } from '../features/HierarchyManager.js';
17
- import { ExportManager } from '../features/ExportManager.js';
18
- import { ImportManager } from '../features/ImportManager.js';
19
- import { AnalyticsManager } from '../features/AnalyticsManager.js';
20
- import { TagManager } from '../features/TagManager.js';
21
- import { ArchiveManager } from '../features/ArchiveManager.js';
22
- /**
23
- * Central manager coordinating all knowledge graph operations.
24
- *
25
- * This class serves as the main facade for interacting with the knowledge graph,
26
- * delegating to specialized managers for different concerns:
27
- * - EntityManager: Entity CRUD operations
28
- * - RelationManager: Relation CRUD operations
29
- * - SearchManager: All search operations (basic, ranked, boolean, fuzzy)
30
- * - CompressionManager: Duplicate detection and merging
31
- * - HierarchyManager: Parent-child relationships and tree operations
32
- * - ExportManager: Export to various formats
33
- * - ImportManager: Import from various formats
34
- * - AnalyticsManager: Statistics and validation
35
- * - TagManager: Tag alias management
36
- * - ArchiveManager: Entity archiving
37
- */
38
- export class KnowledgeGraphManager {
39
- savedSearchesFilePath;
40
- tagAliasesFilePath;
41
- storage;
42
- // Lazy-initialized managers for improved startup performance
43
- _entityManager;
44
- _relationManager;
45
- _searchManager;
46
- _compressionManager;
47
- _hierarchyManager;
48
- _exportManager;
49
- _importManager;
50
- _analyticsManager;
51
- _tagManager;
52
- _archiveManager;
53
- constructor(memoryFilePath) {
54
- // Saved searches file is stored alongside the memory file
55
- const dir = path.dirname(memoryFilePath);
56
- const basename = path.basename(memoryFilePath, path.extname(memoryFilePath));
57
- this.savedSearchesFilePath = path.join(dir, `${basename}-saved-searches.jsonl`);
58
- this.tagAliasesFilePath = path.join(dir, `${basename}-tag-aliases.jsonl`);
59
- this.storage = new GraphStorage(memoryFilePath);
60
- // Managers are now initialized lazily via getters
61
- }
62
- // Lazy getters for managers - instantiated on first access
63
- get entityManager() {
64
- return (this._entityManager ??= new EntityManager(this.storage));
65
- }
66
- get relationManager() {
67
- return (this._relationManager ??= new RelationManager(this.storage));
68
- }
69
- get searchManager() {
70
- return (this._searchManager ??= new SearchManager(this.storage, this.savedSearchesFilePath));
71
- }
72
- get compressionManager() {
73
- return (this._compressionManager ??= new CompressionManager(this.storage));
74
- }
75
- get hierarchyManager() {
76
- return (this._hierarchyManager ??= new HierarchyManager(this.storage));
77
- }
78
- get exportManager() {
79
- return (this._exportManager ??= new ExportManager());
80
- }
81
- get importManager() {
82
- return (this._importManager ??= new ImportManager(this.storage));
83
- }
84
- get analyticsManager() {
85
- return (this._analyticsManager ??= new AnalyticsManager(this.storage));
86
- }
87
- get tagManager() {
88
- return (this._tagManager ??= new TagManager(this.tagAliasesFilePath));
89
- }
90
- get archiveManager() {
91
- return (this._archiveManager ??= new ArchiveManager(this.storage));
92
- }
93
- async loadGraph() {
94
- return this.storage.loadGraph();
95
- }
96
- /**
97
- * Phase 4: Create multiple entities in a single batch operation.
98
- * Batch optimization: All entities are processed and saved in a single saveGraph() call,
99
- * minimizing disk I/O. This is significantly more efficient than creating entities one at a time.
100
- */
101
- async createEntities(entities) {
102
- return this.entityManager.createEntities(entities);
103
- }
104
- /**
105
- * Phase 4: Create multiple relations in a single batch operation.
106
- * Batch optimization: All relations are processed and saved in a single saveGraph() call,
107
- * minimizing disk I/O. This is significantly more efficient than creating relations one at a time.
108
- */
109
- async createRelations(relations) {
110
- return this.relationManager.createRelations(relations);
111
- }
112
- async addObservations(observations) {
113
- return this.entityManager.addObservations(observations);
114
- }
115
- async deleteEntities(entityNames) {
116
- return this.entityManager.deleteEntities(entityNames);
117
- }
118
- async deleteObservations(deletions) {
119
- return this.entityManager.deleteObservations(deletions);
120
- }
121
- async deleteRelations(relations) {
122
- return this.relationManager.deleteRelations(relations);
123
- }
124
- async readGraph() {
125
- return this.loadGraph();
126
- }
127
- // Phase 3: Enhanced search function with tags and importance filters
128
- async searchNodes(query, tags, minImportance, maxImportance) {
129
- return this.searchManager.searchNodes(query, tags, minImportance, maxImportance);
130
- }
131
- async openNodes(names) {
132
- return this.searchManager.openNodes(names);
133
- }
134
- // Phase 3: Enhanced searchByDateRange with tags filter
135
- async searchByDateRange(startDate, endDate, entityType, tags) {
136
- return this.searchManager.searchByDateRange(startDate, endDate, entityType, tags);
137
- }
138
- async getGraphStats() {
139
- return this.analyticsManager.getGraphStats();
140
- }
141
- // Phase 3: Add tags to an entity
142
- async addTags(entityName, tags) {
143
- return this.entityManager.addTags(entityName, tags);
144
- }
145
- // Phase 3: Remove tags from an entity
146
- async removeTags(entityName, tags) {
147
- return this.entityManager.removeTags(entityName, tags);
148
- }
149
- // Phase 3: Set importance level for an entity
150
- async setImportance(entityName, importance) {
151
- return this.entityManager.setImportance(entityName, importance);
152
- }
153
- // Tier 0 B5: Bulk tag operations for efficient tag management
154
- /**
155
- * Add tags to multiple entities in a single operation
156
- */
157
- async addTagsToMultipleEntities(entityNames, tags) {
158
- return this.entityManager.addTagsToMultipleEntities(entityNames, tags);
159
- }
160
- /**
161
- * Replace a tag with a new tag across all entities (rename tag)
162
- */
163
- async replaceTag(oldTag, newTag) {
164
- return this.entityManager.replaceTag(oldTag, newTag);
165
- }
166
- /**
167
- * Merge two tags into one (combine tag1 and tag2 into targetTag)
168
- */
169
- async mergeTags(tag1, tag2, targetTag) {
170
- return this.entityManager.mergeTags(tag1, tag2, targetTag);
171
- }
172
- // Tier 0 A1: Graph validation for data integrity
173
- /**
174
- * Validate the knowledge graph for integrity issues and provide a detailed report
175
- */
176
- async validateGraph() {
177
- return this.analyticsManager.validateGraph();
178
- }
179
- // Tier 0 C4: Saved searches for efficient query management
180
- /**
181
- * Save a search query for later reuse
182
- */
183
- async saveSearch(search) {
184
- return this.searchManager.saveSearch(search);
185
- }
186
- /**
187
- * List all saved searches
188
- */
189
- async listSavedSearches() {
190
- return this.searchManager.listSavedSearches();
191
- }
192
- /**
193
- * Get a specific saved search by name
194
- */
195
- async getSavedSearch(name) {
196
- return this.searchManager.getSavedSearch(name);
197
- }
198
- /**
199
- * Execute a saved search by name
200
- */
201
- async executeSavedSearch(name) {
202
- return this.searchManager.executeSavedSearch(name);
203
- }
204
- /**
205
- * Delete a saved search
206
- */
207
- async deleteSavedSearch(name) {
208
- return this.searchManager.deleteSavedSearch(name);
209
- }
210
- /**
211
- * Update a saved search
212
- */
213
- async updateSavedSearch(name, updates) {
214
- return this.searchManager.updateSavedSearch(name, updates);
215
- }
216
- /**
217
- * Fuzzy search for entities with typo tolerance
218
- * @param query - Search query
219
- * @param threshold - Similarity threshold (0.0 to 1.0), default 0.7
220
- * @param tags - Optional tags filter
221
- * @param minImportance - Optional minimum importance
222
- * @param maxImportance - Optional maximum importance
223
- * @returns Filtered knowledge graph with fuzzy matches
224
- */
225
- async fuzzySearch(query, threshold = 0.7, tags, minImportance, maxImportance) {
226
- return this.searchManager.fuzzySearch(query, threshold, tags, minImportance, maxImportance);
227
- }
228
- /**
229
- * Get "did you mean?" suggestions for a query
230
- * @param query - The search query
231
- * @param maxSuggestions - Maximum number of suggestions to return
232
- * @returns Array of suggested entity/type names
233
- */
234
- async getSearchSuggestions(query, maxSuggestions = 5) {
235
- return this.searchManager.getSearchSuggestions(query, maxSuggestions);
236
- }
237
- /**
238
- * Search nodes with TF-IDF ranking for relevance scoring
239
- * @param query - Search query
240
- * @param tags - Optional tags filter
241
- * @param minImportance - Optional minimum importance
242
- * @param maxImportance - Optional maximum importance
243
- * @param limit - Optional maximum number of results (default 50)
244
- * @returns Array of search results with scores, sorted by relevance
245
- */
246
- async searchNodesRanked(query, tags, minImportance, maxImportance, limit = SEARCH_LIMITS.DEFAULT) {
247
- return this.searchManager.searchNodesRanked(query, tags, minImportance, maxImportance, limit);
248
- }
249
- /**
250
- * Boolean search with support for AND, OR, NOT operators and field-specific queries
251
- * @param query - Boolean query string (e.g., "name:Alice AND (type:person OR observation:programming)")
252
- * @param tags - Optional tags filter
253
- * @param minImportance - Optional minimum importance
254
- * @param maxImportance - Optional maximum importance
255
- * @returns Filtered knowledge graph matching the boolean query
256
- */
257
- async booleanSearch(query, tags, minImportance, maxImportance) {
258
- return this.searchManager.booleanSearch(query, tags, minImportance, maxImportance);
259
- }
260
- // Phase 2: Hierarchical nesting - hierarchy navigation methods
261
- /**
262
- * Set the parent of an entity (creates hierarchy relationship)
263
- * @param entityName - Name of the entity to set parent for
264
- * @param parentName - Name of the parent entity (or null to remove parent)
265
- * @returns Updated entity
266
- */
267
- async setEntityParent(entityName, parentName) {
268
- return this.hierarchyManager.setEntityParent(entityName, parentName);
269
- }
270
- /**
271
- * Get the immediate children of an entity
272
- */
273
- async getChildren(entityName) {
274
- return this.hierarchyManager.getChildren(entityName);
275
- }
276
- /**
277
- * Get the parent of an entity
278
- */
279
- async getParent(entityName) {
280
- return this.hierarchyManager.getParent(entityName);
281
- }
282
- /**
283
- * Get all ancestors of an entity (parent, grandparent, etc.)
284
- */
285
- async getAncestors(entityName) {
286
- return this.hierarchyManager.getAncestors(entityName);
287
- }
288
- /**
289
- * Get all descendants of an entity (children, grandchildren, etc.)
290
- */
291
- async getDescendants(entityName) {
292
- return this.hierarchyManager.getDescendants(entityName);
293
- }
294
- /**
295
- * Get the entire subtree rooted at an entity (entity + all descendants)
296
- */
297
- async getSubtree(entityName) {
298
- return this.hierarchyManager.getSubtree(entityName);
299
- }
300
- /**
301
- * Get root entities (entities with no parent)
302
- */
303
- async getRootEntities() {
304
- return this.hierarchyManager.getRootEntities();
305
- }
306
- /**
307
- * Get the depth of an entity in the hierarchy (0 for root, 1 for child of root, etc.)
308
- */
309
- async getEntityDepth(entityName) {
310
- return this.hierarchyManager.getEntityDepth(entityName);
311
- }
312
- /**
313
- * Move an entity to a new parent (maintaining its descendants)
314
- */
315
- async moveEntity(entityName, newParentName) {
316
- return this.hierarchyManager.moveEntity(entityName, newParentName);
317
- }
318
- // Phase 3: Memory compression - duplicate detection and merging
319
- /**
320
- * Find duplicate entities in the graph based on similarity threshold
321
- * @param threshold - Similarity threshold (0.0 to 1.0), default 0.8
322
- * @returns Array of duplicate groups (each group has similar entities)
323
- */
324
- async findDuplicates(threshold = DEFAULT_DUPLICATE_THRESHOLD) {
325
- return this.compressionManager.findDuplicates(threshold);
326
- }
327
- /**
328
- * Merge a group of entities into a single entity
329
- * @param entityNames - Names of entities to merge (first one is kept)
330
- * @param targetName - Optional new name for merged entity (default: first entity name)
331
- * @returns The merged entity
332
- */
333
- async mergeEntities(entityNames, targetName) {
334
- return this.compressionManager.mergeEntities(entityNames, targetName);
335
- }
336
- /**
337
- * Compress the knowledge graph by finding and merging duplicates
338
- * @param threshold - Similarity threshold for duplicate detection (0.0 to 1.0)
339
- * @param dryRun - If true, only report what would be compressed without applying changes
340
- * @returns Compression result with statistics
341
- */
342
- async compressGraph(threshold = 0.8, dryRun = false) {
343
- return this.compressionManager.compressGraph(threshold, dryRun);
344
- }
345
- // Phase 4: Memory archiving system
346
- /**
347
- * Archive old or low-importance entities to a separate storage
348
- * @param criteria - Criteria for archiving (age, importance, tags)
349
- * @param dryRun - If true, preview what would be archived
350
- * @returns Number of entities archived
351
- */
352
- async archiveEntities(criteria, dryRun = false) {
353
- return this.archiveManager.archiveEntities(criteria, dryRun);
354
- }
355
- // Tier 0 B2: Tag aliases for synonym management
356
- /**
357
- * Resolve a tag through aliases to get its canonical form
358
- * @param tag - Tag to resolve (can be alias or canonical)
359
- * @returns Canonical tag name
360
- */
361
- async resolveTag(tag) {
362
- return this.tagManager.resolveTag(tag);
363
- }
364
- /**
365
- * Add a tag alias (synonym mapping)
366
- * @param alias - The alias/synonym
367
- * @param canonical - The canonical (main) tag name
368
- * @param description - Optional description of the alias
369
- */
370
- async addTagAlias(alias, canonical, description) {
371
- return this.tagManager.addTagAlias(alias, canonical, description);
372
- }
373
- /**
374
- * List all tag aliases
375
- */
376
- async listTagAliases() {
377
- return this.tagManager.listTagAliases();
378
- }
379
- /**
380
- * Remove a tag alias
381
- */
382
- async removeTagAlias(alias) {
383
- return this.tagManager.removeTagAlias(alias);
384
- }
385
- /**
386
- * Get all aliases for a canonical tag
387
- */
388
- async getAliasesForTag(canonicalTag) {
389
- return this.tagManager.getAliasesForTag(canonicalTag);
390
- }
391
- // Phase 4 & Tier 0 D1: Export graph in various formats
392
- /**
393
- * Export the knowledge graph in the specified format with optional filtering.
394
- * Supports JSON, CSV, GraphML, GEXF, DOT, Markdown, and Mermaid formats.
395
- *
396
- * @param format - Export format: 'json', 'csv', 'graphml', 'gexf', 'dot', 'markdown', 'mermaid'
397
- * @param filter - Optional filter object with same structure as searchByDateRange
398
- * @returns Exported graph data as a formatted string
399
- */
400
- async exportGraph(format, filter) {
401
- // Get filtered or full graph based on filter parameter
402
- let graph;
403
- if (filter) {
404
- graph = await this.searchByDateRange(filter.startDate, filter.endDate, filter.entityType, filter.tags);
405
- }
406
- else {
407
- graph = await this.loadGraph();
408
- }
409
- return this.exportManager.exportGraph(graph, format);
410
- }
411
- // Tier 0 D2: Import capabilities with merge strategies
412
- /**
413
- * Import knowledge graph from various formats
414
- * @param format - Import format: 'json', 'csv', or 'graphml'
415
- * @param data - The import data as a string
416
- * @param mergeStrategy - How to handle conflicts: 'replace', 'skip', 'merge', 'fail'
417
- * @param dryRun - If true, preview changes without applying them
418
- * @returns Import result with statistics
419
- */
420
- async importGraph(format, data, mergeStrategy = 'skip', dryRun = false) {
421
- return this.importManager.importGraph(format, data, mergeStrategy, dryRun);
422
- }
423
- }