@danielsimonjr/memory-mcp 0.48.0 → 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 (209) 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 +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 +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 +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 +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/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 +188 -17
  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/memory-saved-searches.jsonl +0 -0
  195. package/dist/memory-tag-aliases.jsonl +0 -0
  196. package/dist/types/analytics.types.js +0 -6
  197. package/dist/types/entity.types.js +0 -7
  198. package/dist/types/import-export.types.js +0 -7
  199. package/dist/types/search.types.js +0 -7
  200. package/dist/types/tag.types.js +0 -6
  201. package/dist/utils/dateUtils.js +0 -89
  202. package/dist/utils/filterUtils.js +0 -155
  203. package/dist/utils/levenshtein.js +0 -62
  204. package/dist/utils/pathUtils.js +0 -115
  205. package/dist/utils/responseFormatter.js +0 -55
  206. package/dist/utils/tagUtils.js +0 -107
  207. package/dist/utils/tfidf.js +0 -90
  208. package/dist/utils/validationHelper.js +0 -99
  209. package/dist/utils/validationUtils.js +0 -109
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Streaming Export Module
3
+ *
4
+ * Provides streaming export functionality for large knowledge graphs to avoid
5
+ * loading entire graphs into memory. Supports JSONL and CSV formats with
6
+ * incremental writing to disk.
7
+ *
8
+ * @module features/StreamingExporter
9
+ */
10
+ import type { ReadonlyKnowledgeGraph, LongRunningOperationOptions } from '../types/types.js';
11
+ /**
12
+ * Result summary from a streaming export operation.
13
+ *
14
+ * Provides statistics about the export including bytes written,
15
+ * entity/relation counts, and duration.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const result: StreamResult = {
20
+ * bytesWritten: 125000,
21
+ * entitiesWritten: 150,
22
+ * relationsWritten: 320,
23
+ * durationMs: 1250
24
+ * };
25
+ * ```
26
+ */
27
+ export interface StreamResult {
28
+ /** Total bytes written to the output file */
29
+ bytesWritten: number;
30
+ /** Number of entities written */
31
+ entitiesWritten: number;
32
+ /** Number of relations written */
33
+ relationsWritten: number;
34
+ /** Duration of the export operation in milliseconds */
35
+ durationMs: number;
36
+ }
37
+ /**
38
+ * Streaming exporter for knowledge graphs.
39
+ *
40
+ * Provides memory-efficient export by streaming data directly to files
41
+ * instead of building large strings in memory. Supports JSONL and CSV formats.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const exporter = new StreamingExporter('/path/to/output.jsonl');
46
+ * const result = await exporter.streamJSONL(graph);
47
+ * console.log(`Wrote ${result.bytesWritten} bytes in ${result.durationMs}ms`);
48
+ * ```
49
+ */
50
+ export declare class StreamingExporter {
51
+ private readonly filePath;
52
+ /**
53
+ * Create a new streaming exporter.
54
+ *
55
+ * @param filePath - Path to the output file
56
+ */
57
+ constructor(filePath: string);
58
+ /**
59
+ * Stream a knowledge graph to JSONL format.
60
+ *
61
+ * Each entity and relation is written as a separate JSON line.
62
+ * Memory usage is constant regardless of graph size.
63
+ *
64
+ * Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
65
+ *
66
+ * @param graph - The knowledge graph to export
67
+ * @param options - Optional progress/cancellation options (Phase 9B)
68
+ * @returns Promise resolving to export statistics
69
+ * @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const exporter = new StreamingExporter('export.jsonl');
74
+ * const result = await exporter.streamJSONL(graph);
75
+ * console.log(`Exported ${result.entitiesWritten} entities`);
76
+ *
77
+ * // With progress tracking (Phase 9B)
78
+ * const result = await exporter.streamJSONL(graph, {
79
+ * onProgress: (p) => console.log(`${p.percentage}% complete`),
80
+ * });
81
+ * ```
82
+ */
83
+ streamJSONL(graph: ReadonlyKnowledgeGraph, options?: LongRunningOperationOptions): Promise<StreamResult>;
84
+ /**
85
+ * Stream a knowledge graph to CSV format.
86
+ *
87
+ * Exports entities as CSV rows with proper escaping for special characters.
88
+ * Header row includes: name, type, observations, tags, importance, createdAt, lastModified.
89
+ *
90
+ * Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
91
+ *
92
+ * @param graph - The knowledge graph to export
93
+ * @param options - Optional progress/cancellation options (Phase 9B)
94
+ * @returns Promise resolving to export statistics
95
+ * @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const exporter = new StreamingExporter('export.csv');
100
+ * const result = await exporter.streamCSV(graph);
101
+ * console.log(`Exported ${result.entitiesWritten} entities as CSV`);
102
+ *
103
+ * // With progress tracking (Phase 9B)
104
+ * const result = await exporter.streamCSV(graph, {
105
+ * onProgress: (p) => console.log(`${p.percentage}% complete`),
106
+ * });
107
+ * ```
108
+ */
109
+ streamCSV(graph: ReadonlyKnowledgeGraph, options?: LongRunningOperationOptions): Promise<StreamResult>;
110
+ /**
111
+ * Convert an entity to a CSV row with proper escaping.
112
+ *
113
+ * Escapes double quotes by doubling them and wraps fields in quotes.
114
+ * Arrays (observations, tags) are joined with semicolons.
115
+ *
116
+ * @param entity - The entity to convert
117
+ * @returns CSV row string (without trailing newline)
118
+ *
119
+ * @private
120
+ */
121
+ private entityToCSVRow;
122
+ }
123
+ //# sourceMappingURL=StreamingExporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingExporter.d.ts","sourceRoot":"","sources":["../../src/features/StreamingExporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAU,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAGrG;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IAErB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IAExB,kCAAkC;IAClC,gBAAgB,EAAE,MAAM,CAAC;IAEzB,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAiB;IAMhB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IALrC;;;;OAIG;gBAC0B,QAAQ,EAAE,MAAM;IAE7C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,WAAW,CACf,KAAK,EAAE,sBAAsB,EAC7B,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,YAAY,CAAC;IA+DxB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,SAAS,CACb,KAAK,EAAE,sBAAsB,EAC7B,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,YAAY,CAAC;IAuDxB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,cAAc;CAcvB"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Streaming Export Module
3
+ *
4
+ * Provides streaming export functionality for large knowledge graphs to avoid
5
+ * loading entire graphs into memory. Supports JSONL and CSV formats with
6
+ * incremental writing to disk.
7
+ *
8
+ * @module features/StreamingExporter
9
+ */
10
+ import { createWriteStream } from 'fs';
11
+ import { checkCancellation, createProgressReporter, createProgress } from '../utils/index.js';
12
+ /**
13
+ * Streaming exporter for knowledge graphs.
14
+ *
15
+ * Provides memory-efficient export by streaming data directly to files
16
+ * instead of building large strings in memory. Supports JSONL and CSV formats.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const exporter = new StreamingExporter('/path/to/output.jsonl');
21
+ * const result = await exporter.streamJSONL(graph);
22
+ * console.log(`Wrote ${result.bytesWritten} bytes in ${result.durationMs}ms`);
23
+ * ```
24
+ */
25
+ export class StreamingExporter {
26
+ filePath;
27
+ /**
28
+ * Create a new streaming exporter.
29
+ *
30
+ * @param filePath - Path to the output file
31
+ */
32
+ constructor(filePath) {
33
+ this.filePath = filePath;
34
+ }
35
+ /**
36
+ * Stream a knowledge graph to JSONL format.
37
+ *
38
+ * Each entity and relation is written as a separate JSON line.
39
+ * Memory usage is constant regardless of graph size.
40
+ *
41
+ * Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
42
+ *
43
+ * @param graph - The knowledge graph to export
44
+ * @param options - Optional progress/cancellation options (Phase 9B)
45
+ * @returns Promise resolving to export statistics
46
+ * @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const exporter = new StreamingExporter('export.jsonl');
51
+ * const result = await exporter.streamJSONL(graph);
52
+ * console.log(`Exported ${result.entitiesWritten} entities`);
53
+ *
54
+ * // With progress tracking (Phase 9B)
55
+ * const result = await exporter.streamJSONL(graph, {
56
+ * onProgress: (p) => console.log(`${p.percentage}% complete`),
57
+ * });
58
+ * ```
59
+ */
60
+ async streamJSONL(graph, options) {
61
+ // Check for early cancellation
62
+ checkCancellation(options?.signal, 'streamJSONL');
63
+ // Setup progress reporter
64
+ const reportProgress = createProgressReporter(options?.onProgress);
65
+ const total = graph.entities.length + graph.relations.length;
66
+ let processed = 0;
67
+ reportProgress?.(createProgress(0, total, 'streamJSONL'));
68
+ const start = Date.now();
69
+ let bytesWritten = 0;
70
+ let entitiesWritten = 0;
71
+ let relationsWritten = 0;
72
+ const writeStream = createWriteStream(this.filePath);
73
+ // Write entities
74
+ for (const entity of graph.entities) {
75
+ // Check for cancellation periodically
76
+ checkCancellation(options?.signal, 'streamJSONL');
77
+ const line = JSON.stringify(entity) + '\n';
78
+ writeStream.write(line);
79
+ bytesWritten += Buffer.byteLength(line, 'utf-8');
80
+ entitiesWritten++;
81
+ processed++;
82
+ reportProgress?.(createProgress(processed, total, 'writing entities'));
83
+ }
84
+ // Write relations
85
+ for (const relation of graph.relations) {
86
+ // Check for cancellation periodically
87
+ checkCancellation(options?.signal, 'streamJSONL');
88
+ const line = JSON.stringify(relation) + '\n';
89
+ writeStream.write(line);
90
+ bytesWritten += Buffer.byteLength(line, 'utf-8');
91
+ relationsWritten++;
92
+ processed++;
93
+ reportProgress?.(createProgress(processed, total, 'writing relations'));
94
+ }
95
+ // Check for cancellation before finalizing
96
+ checkCancellation(options?.signal, 'streamJSONL');
97
+ // Wait for stream to finish
98
+ await new Promise((resolve, reject) => {
99
+ writeStream.end(() => resolve());
100
+ writeStream.on('error', reject);
101
+ });
102
+ // Report completion
103
+ reportProgress?.(createProgress(total, total, 'streamJSONL'));
104
+ return {
105
+ bytesWritten,
106
+ entitiesWritten,
107
+ relationsWritten,
108
+ durationMs: Date.now() - start,
109
+ };
110
+ }
111
+ /**
112
+ * Stream a knowledge graph to CSV format.
113
+ *
114
+ * Exports entities as CSV rows with proper escaping for special characters.
115
+ * Header row includes: name, type, observations, tags, importance, createdAt, lastModified.
116
+ *
117
+ * Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
118
+ *
119
+ * @param graph - The knowledge graph to export
120
+ * @param options - Optional progress/cancellation options (Phase 9B)
121
+ * @returns Promise resolving to export statistics
122
+ * @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const exporter = new StreamingExporter('export.csv');
127
+ * const result = await exporter.streamCSV(graph);
128
+ * console.log(`Exported ${result.entitiesWritten} entities as CSV`);
129
+ *
130
+ * // With progress tracking (Phase 9B)
131
+ * const result = await exporter.streamCSV(graph, {
132
+ * onProgress: (p) => console.log(`${p.percentage}% complete`),
133
+ * });
134
+ * ```
135
+ */
136
+ async streamCSV(graph, options) {
137
+ // Check for early cancellation
138
+ checkCancellation(options?.signal, 'streamCSV');
139
+ // Setup progress reporter
140
+ const reportProgress = createProgressReporter(options?.onProgress);
141
+ const total = graph.entities.length;
142
+ let processed = 0;
143
+ reportProgress?.(createProgress(0, total, 'streamCSV'));
144
+ const start = Date.now();
145
+ let bytesWritten = 0;
146
+ let entitiesWritten = 0;
147
+ const relationsWritten = 0; // CSV format doesn't export relations
148
+ const writeStream = createWriteStream(this.filePath);
149
+ // Write header
150
+ const header = 'name,type,observations,tags,importance,createdAt,lastModified\n';
151
+ writeStream.write(header);
152
+ bytesWritten += Buffer.byteLength(header, 'utf-8');
153
+ // Write entity rows
154
+ for (const entity of graph.entities) {
155
+ // Check for cancellation periodically
156
+ checkCancellation(options?.signal, 'streamCSV');
157
+ const row = this.entityToCSVRow(entity) + '\n';
158
+ writeStream.write(row);
159
+ bytesWritten += Buffer.byteLength(row, 'utf-8');
160
+ entitiesWritten++;
161
+ processed++;
162
+ reportProgress?.(createProgress(processed, total, 'writing entities'));
163
+ }
164
+ // Check for cancellation before finalizing
165
+ checkCancellation(options?.signal, 'streamCSV');
166
+ // Wait for stream to finish
167
+ await new Promise((resolve, reject) => {
168
+ writeStream.end(() => resolve());
169
+ writeStream.on('error', reject);
170
+ });
171
+ // Report completion
172
+ reportProgress?.(createProgress(total, total, 'streamCSV'));
173
+ return {
174
+ bytesWritten,
175
+ entitiesWritten,
176
+ relationsWritten,
177
+ durationMs: Date.now() - start,
178
+ };
179
+ }
180
+ /**
181
+ * Convert an entity to a CSV row with proper escaping.
182
+ *
183
+ * Escapes double quotes by doubling them and wraps fields in quotes.
184
+ * Arrays (observations, tags) are joined with semicolons.
185
+ *
186
+ * @param entity - The entity to convert
187
+ * @returns CSV row string (without trailing newline)
188
+ *
189
+ * @private
190
+ */
191
+ entityToCSVRow(entity) {
192
+ const escape = (s) => `"${s.replace(/"/g, '""')}"`;
193
+ return [
194
+ escape(entity.name),
195
+ escape(entity.entityType),
196
+ escape(entity.observations.join('; ')),
197
+ escape((entity.tags ?? []).join('; ')),
198
+ entity.importance?.toString() ?? '',
199
+ entity.createdAt ?? '',
200
+ entity.lastModified ?? '',
201
+ ].join(',');
202
+ }
203
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Tag Manager
3
+ *
4
+ * Manages tag aliases and canonical tag resolution.
5
+ *
6
+ * @module features/TagManager
7
+ */
8
+ import type { TagAlias } from '../types/index.js';
9
+ /**
10
+ * Manages tag alias system for synonym mapping.
11
+ */
12
+ export declare class TagManager {
13
+ private tagAliasesFilePath;
14
+ constructor(tagAliasesFilePath: string);
15
+ /**
16
+ * Load all tag aliases from JSONL file.
17
+ *
18
+ * @returns Array of tag aliases
19
+ */
20
+ private loadTagAliases;
21
+ /**
22
+ * Save tag aliases to JSONL file.
23
+ *
24
+ * @param aliases - Array of tag aliases
25
+ */
26
+ private saveTagAliases;
27
+ /**
28
+ * Resolve a tag through aliases to get its canonical form.
29
+ *
30
+ * This method follows the alias chain to find the canonical (main) tag name.
31
+ * All tags are normalized to lowercase for consistency.
32
+ * If the tag has no alias, it returns the tag itself as canonical.
33
+ *
34
+ * @param tag - Tag to resolve (can be alias or canonical)
35
+ * @returns Canonical tag name (lowercase)
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const manager = new TagManager(tagAliasesPath);
40
+ *
41
+ * // Set up: assume "js" is aliased to "javascript"
42
+ * await manager.addTagAlias('js', 'javascript');
43
+ *
44
+ * // Resolve alias to canonical
45
+ * const canonical = await manager.resolveTag('js');
46
+ * console.log(canonical); // "javascript"
47
+ *
48
+ * // Resolve canonical tag (returns as-is)
49
+ * const unchanged = await manager.resolveTag('javascript');
50
+ * console.log(unchanged); // "javascript"
51
+ *
52
+ * // Resolve unknown tag (returns normalized)
53
+ * const unknown = await manager.resolveTag('PYTHON');
54
+ * console.log(unknown); // "python"
55
+ * ```
56
+ */
57
+ resolveTag(tag: string): Promise<string>;
58
+ /**
59
+ * Add a tag alias (synonym mapping).
60
+ *
61
+ * Creates a mapping from an alias (synonym) to a canonical (main) tag.
62
+ * This enables flexible tagging where users can use different terms
63
+ * that all resolve to the same canonical tag.
64
+ *
65
+ * Validation rules:
66
+ * - Prevents duplicate aliases (same alias can't map to different canonicals)
67
+ * - Prevents chained aliases (alias must point to canonical, not another alias)
68
+ * - All tags are normalized to lowercase
69
+ *
70
+ * @param alias - The alias/synonym (will be normalized to lowercase)
71
+ * @param canonical - The canonical (main) tag name (will be normalized to lowercase)
72
+ * @param description - Optional description explaining the alias relationship
73
+ * @returns Newly created TagAlias object with metadata
74
+ * @throws {Error} If alias already exists or would create chained aliases
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const manager = new TagManager(tagAliasesPath);
79
+ *
80
+ * // Create simple alias
81
+ * await manager.addTagAlias('js', 'javascript', 'Common abbreviation');
82
+ *
83
+ * // Create multiple aliases for same canonical
84
+ * await manager.addTagAlias('py', 'python');
85
+ * await manager.addTagAlias('py3', 'python', 'Python 3.x');
86
+ *
87
+ * // Error: duplicate alias
88
+ * try {
89
+ * await manager.addTagAlias('js', 'ecmascript'); // Fails - 'js' already aliased
90
+ * } catch (error) {
91
+ * console.error('Alias already exists');
92
+ * }
93
+ *
94
+ * // Error: chained alias
95
+ * await manager.addTagAlias('js', 'javascript');
96
+ * try {
97
+ * await manager.addTagAlias('javascript', 'ecmascript'); // Fails - can't alias canonical
98
+ * } catch (error) {
99
+ * console.error('Cannot create chained aliases');
100
+ * }
101
+ * ```
102
+ */
103
+ addTagAlias(alias: string, canonical: string, description?: string): Promise<TagAlias>;
104
+ /**
105
+ * List all tag aliases.
106
+ *
107
+ * @returns Array of all tag aliases
108
+ */
109
+ listTagAliases(): Promise<TagAlias[]>;
110
+ /**
111
+ * Remove a tag alias.
112
+ *
113
+ * @param alias - Alias to remove
114
+ * @returns True if removed, false if not found
115
+ */
116
+ removeTagAlias(alias: string): Promise<boolean>;
117
+ /**
118
+ * Get all aliases (synonyms) for a canonical tag.
119
+ *
120
+ * Returns all alias names that resolve to the specified canonical tag.
121
+ * Useful for discovering alternative names users might use for a tag.
122
+ * The canonical tag name is normalized to lowercase.
123
+ *
124
+ * @param canonicalTag - Canonical tag name (will be normalized to lowercase)
125
+ * @returns Array of alias names (all lowercase)
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const manager = new TagManager(tagAliasesPath);
130
+ *
131
+ * // Set up some aliases
132
+ * await manager.addTagAlias('js', 'javascript');
133
+ * await manager.addTagAlias('ecmascript', 'javascript');
134
+ * await manager.addTagAlias('es6', 'javascript');
135
+ *
136
+ * // Get all aliases for canonical tag
137
+ * const aliases = await manager.getAliasesForTag('javascript');
138
+ * console.log(aliases); // ['js', 'ecmascript', 'es6']
139
+ *
140
+ * // Empty array if no aliases
141
+ * const noAliases = await manager.getAliasesForTag('python');
142
+ * console.log(noAliases); // []
143
+ * ```
144
+ */
145
+ getAliasesForTag(canonicalTag: string): Promise<string[]>;
146
+ }
147
+ //# sourceMappingURL=TagManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TagManager.d.ts","sourceRoot":"","sources":["../../src/features/TagManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;GAEG;AACH,qBAAa,UAAU;IACT,OAAO,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,MAAM;IAE9C;;;;OAIG;YACW,cAAc;IAa5B;;;;OAIG;YACW,cAAc;IAK5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA8B5F;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAI3C;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcrD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAKhE"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Features Module Barrel Export
3
+ * Phase 4: Re-extracted specialized managers for single responsibility
4
+ * Phase 7: Added streaming export utilities
5
+ */
6
+ export { TagManager } from './TagManager.js';
7
+ export { IOManager, type ExportFormat, type ImportFormat, type MergeStrategy, type BackupMetadata, type BackupInfo, } from './IOManager.js';
8
+ export { AnalyticsManager } from './AnalyticsManager.js';
9
+ export { CompressionManager } from './CompressionManager.js';
10
+ export { ArchiveManager, type ArchiveCriteria, type ArchiveOptions, type ArchiveResult, } from './ArchiveManager.js';
11
+ export { StreamingExporter, type StreamResult } from './StreamingExporter.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/features/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * Features Module Barrel Export
3
+ * Phase 4: Re-extracted specialized managers for single responsibility
4
+ * Phase 7: Added streaming export utilities
3
5
  */
4
6
  export { TagManager } from './TagManager.js';
5
- export { HierarchyManager } from './HierarchyManager.js';
7
+ export { IOManager, } from './IOManager.js';
6
8
  export { AnalyticsManager } from './AnalyticsManager.js';
7
9
  export { CompressionManager } from './CompressionManager.js';
8
- export { ArchiveManager } from './ArchiveManager.js';
9
- export { BackupManager } from './BackupManager.js';
10
- export { ExportManager } from './ExportManager.js';
11
- export { ImportManager } from './ImportManager.js';
12
- // Note: ExportFilter type moved to types/import-export.types.ts
10
+ export { ArchiveManager, } from './ArchiveManager.js';
11
+ export { StreamingExporter } from './StreamingExporter.js';
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { defaultMemoryPath, ensureMemoryFilePath } from './utils/index.js';
3
+ import { ManagerContext } from './core/ManagerContext.js';
4
+ import type { Entity, Relation, KnowledgeGraph, GraphStats, ValidationReport, ValidationIssue, ValidationWarning, SavedSearch, TagAlias, SearchResult, BooleanQueryNode, ImportResult, CompressionResult } from './types/index.js';
5
+ export { defaultMemoryPath, ensureMemoryFilePath };
6
+ export type { Entity, Relation, KnowledgeGraph, GraphStats, ValidationReport, ValidationIssue, ValidationWarning, SavedSearch, TagAlias, SearchResult, BooleanQueryNode, ImportResult, CompressionResult, };
7
+ export { ManagerContext };
8
+ export { ManagerContext as KnowledgeGraphManager };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAU,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;AAGnD,YAAY,EACV,MAAM,EACN,QAAQ,EACR,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,GAClB,CAAC;AAGF,OAAO,EAAE,cAAc,EAAE,CAAC;AAG1B,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env node
2
- import { logger } from './utils/logger.js';
3
- import { KnowledgeGraphManager } from './core/KnowledgeGraphManager.js';
2
+ import { logger, defaultMemoryPath, ensureMemoryFilePath } from './utils/index.js';
3
+ import { ManagerContext } from './core/ManagerContext.js';
4
4
  import { MCPServer } from './server/MCPServer.js';
5
- // Import path utilities from canonical location (has path traversal protection)
6
- import { defaultMemoryPath, ensureMemoryFilePath } from './utils/pathUtils.js';
7
5
  // Re-export path utilities for backward compatibility
8
6
  export { defaultMemoryPath, ensureMemoryFilePath };
9
- // Re-export KnowledgeGraphManager for backward compatibility
10
- export { KnowledgeGraphManager };
11
- let knowledgeGraphManager;
7
+ // Re-export ManagerContext (replaces KnowledgeGraphManager)
8
+ export { ManagerContext };
9
+ // Backward compatibility alias
10
+ export { ManagerContext as KnowledgeGraphManager };
11
+ let managerContext;
12
12
  async function main() {
13
13
  // Initialize memory file path with backward compatibility
14
14
  const memoryFilePath = await ensureMemoryFilePath();
15
- // Initialize knowledge graph manager with the memory file path
16
- knowledgeGraphManager = new KnowledgeGraphManager(memoryFilePath);
15
+ // Initialize manager context with the memory file path
16
+ managerContext = new ManagerContext(memoryFilePath);
17
17
  // Initialize and start MCP server
18
- const server = new MCPServer(knowledgeGraphManager);
18
+ const server = new MCPServer(managerContext);
19
19
  await server.start();
20
20
  }
21
21
  main().catch((error) => {