mcp-memory-keeper 0.10.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 (98) hide show
  1. package/CHANGELOG.md +433 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1051 -0
  4. package/bin/mcp-memory-keeper +52 -0
  5. package/dist/__tests__/helpers/database-test-helper.js +160 -0
  6. package/dist/__tests__/helpers/test-server.js +92 -0
  7. package/dist/__tests__/integration/advanced-features.test.js +614 -0
  8. package/dist/__tests__/integration/backward-compatibility.test.js +245 -0
  9. package/dist/__tests__/integration/batchOperationsE2E.test.js +396 -0
  10. package/dist/__tests__/integration/batchOperationsHandler.test.js +1230 -0
  11. package/dist/__tests__/integration/channelManagementHandler.test.js +1291 -0
  12. package/dist/__tests__/integration/channels.test.js +376 -0
  13. package/dist/__tests__/integration/checkpoint.test.js +251 -0
  14. package/dist/__tests__/integration/concurrent-access.test.js +190 -0
  15. package/dist/__tests__/integration/context-operations.test.js +243 -0
  16. package/dist/__tests__/integration/contextDiff.test.js +852 -0
  17. package/dist/__tests__/integration/contextDiffHandler.test.js +976 -0
  18. package/dist/__tests__/integration/contextExportHandler.test.js +510 -0
  19. package/dist/__tests__/integration/contextGetPaginationDefaults.test.js +298 -0
  20. package/dist/__tests__/integration/contextReassignChannelHandler.test.js +908 -0
  21. package/dist/__tests__/integration/contextRelationshipsHandler.test.js +1151 -0
  22. package/dist/__tests__/integration/contextSearch.test.js +938 -0
  23. package/dist/__tests__/integration/contextSearchHandler.test.js +552 -0
  24. package/dist/__tests__/integration/contextWatchActual.test.js +165 -0
  25. package/dist/__tests__/integration/contextWatchHandler.test.js +1500 -0
  26. package/dist/__tests__/integration/cross-session-sharing.test.js +302 -0
  27. package/dist/__tests__/integration/database-initialization.test.js +134 -0
  28. package/dist/__tests__/integration/enhanced-context-operations.test.js +1082 -0
  29. package/dist/__tests__/integration/enhancedContextGetHandler.test.js +915 -0
  30. package/dist/__tests__/integration/enhancedContextTimelineHandler.test.js +716 -0
  31. package/dist/__tests__/integration/error-cases.test.js +407 -0
  32. package/dist/__tests__/integration/export-import.test.js +367 -0
  33. package/dist/__tests__/integration/feature-flags.test.js +542 -0
  34. package/dist/__tests__/integration/file-operations.test.js +264 -0
  35. package/dist/__tests__/integration/git-integration.test.js +237 -0
  36. package/dist/__tests__/integration/index-tools.test.js +496 -0
  37. package/dist/__tests__/integration/issue11-actual-bug-demo.test.js +304 -0
  38. package/dist/__tests__/integration/issue11-search-filters-bug.test.js +561 -0
  39. package/dist/__tests__/integration/issue12-checkpoint-restore-behavior.test.js +621 -0
  40. package/dist/__tests__/integration/issue13-key-validation.test.js +433 -0
  41. package/dist/__tests__/integration/knowledge-graph.test.js +338 -0
  42. package/dist/__tests__/integration/migrations.test.js +528 -0
  43. package/dist/__tests__/integration/multi-agent.test.js +546 -0
  44. package/dist/__tests__/integration/pagination-critical-fix.test.js +296 -0
  45. package/dist/__tests__/integration/paginationDefaultsHandler.test.js +600 -0
  46. package/dist/__tests__/integration/project-directory.test.js +283 -0
  47. package/dist/__tests__/integration/resource-cleanup.test.js +149 -0
  48. package/dist/__tests__/integration/retention.test.js +513 -0
  49. package/dist/__tests__/integration/search.test.js +333 -0
  50. package/dist/__tests__/integration/semantic-search.test.js +266 -0
  51. package/dist/__tests__/integration/server-initialization.test.js +307 -0
  52. package/dist/__tests__/integration/session-management.test.js +219 -0
  53. package/dist/__tests__/integration/simplified-sharing.test.js +346 -0
  54. package/dist/__tests__/integration/smart-compaction.test.js +230 -0
  55. package/dist/__tests__/integration/summarization.test.js +308 -0
  56. package/dist/__tests__/integration/watcher-migration-validation.test.js +544 -0
  57. package/dist/__tests__/security/input-validation.test.js +115 -0
  58. package/dist/__tests__/utils/agents.test.js +473 -0
  59. package/dist/__tests__/utils/database.test.js +177 -0
  60. package/dist/__tests__/utils/git.test.js +122 -0
  61. package/dist/__tests__/utils/knowledge-graph.test.js +297 -0
  62. package/dist/__tests__/utils/migrationHealthCheck.test.js +302 -0
  63. package/dist/__tests__/utils/project-directory-messages.test.js +188 -0
  64. package/dist/__tests__/utils/timezone-safe-dates.js +119 -0
  65. package/dist/__tests__/utils/validation.test.js +200 -0
  66. package/dist/__tests__/utils/vector-store.test.js +231 -0
  67. package/dist/handlers/contextWatchHandlers.js +206 -0
  68. package/dist/index.js +4310 -0
  69. package/dist/index.phase1.backup.js +410 -0
  70. package/dist/index.phase2.backup.js +704 -0
  71. package/dist/migrations/003_add_channels.js +174 -0
  72. package/dist/migrations/004_add_context_watch.js +151 -0
  73. package/dist/migrations/005_add_context_watch.js +98 -0
  74. package/dist/migrations/simplify-sharing.js +117 -0
  75. package/dist/repositories/BaseRepository.js +30 -0
  76. package/dist/repositories/CheckpointRepository.js +140 -0
  77. package/dist/repositories/ContextRepository.js +1873 -0
  78. package/dist/repositories/FileRepository.js +104 -0
  79. package/dist/repositories/RepositoryManager.js +62 -0
  80. package/dist/repositories/SessionRepository.js +66 -0
  81. package/dist/repositories/WatcherRepository.js +252 -0
  82. package/dist/repositories/index.js +15 -0
  83. package/dist/server.js +384 -0
  84. package/dist/test-helpers/database-helper.js +128 -0
  85. package/dist/types/entities.js +3 -0
  86. package/dist/utils/agents.js +791 -0
  87. package/dist/utils/channels.js +150 -0
  88. package/dist/utils/database.js +731 -0
  89. package/dist/utils/feature-flags.js +476 -0
  90. package/dist/utils/git.js +145 -0
  91. package/dist/utils/knowledge-graph.js +264 -0
  92. package/dist/utils/migrationHealthCheck.js +373 -0
  93. package/dist/utils/migrations.js +452 -0
  94. package/dist/utils/retention.js +460 -0
  95. package/dist/utils/timestamps.js +112 -0
  96. package/dist/utils/validation.js +296 -0
  97. package/dist/utils/vector-store.js +247 -0
  98. package/package.json +84 -0
@@ -0,0 +1,546 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const database_1 = require("../../utils/database");
37
+ const knowledge_graph_1 = require("../../utils/knowledge-graph");
38
+ const vector_store_1 = require("../../utils/vector-store");
39
+ const agents_1 = require("../../utils/agents");
40
+ const os = __importStar(require("os"));
41
+ const path = __importStar(require("path"));
42
+ const fs = __importStar(require("fs"));
43
+ const uuid_1 = require("uuid");
44
+ describe('Multi-Agent System Integration Tests', () => {
45
+ let dbManager;
46
+ let tempDbPath;
47
+ let db;
48
+ let testSessionId;
49
+ let knowledgeGraph;
50
+ let vectorStore;
51
+ let agentCoordinator;
52
+ beforeEach(() => {
53
+ tempDbPath = path.join(os.tmpdir(), `test-multiagent-${Date.now()}.db`);
54
+ dbManager = new database_1.DatabaseManager({
55
+ filename: tempDbPath,
56
+ maxSize: 10 * 1024 * 1024,
57
+ walMode: true,
58
+ });
59
+ db = dbManager.getDatabase();
60
+ // Initialize components
61
+ knowledgeGraph = new knowledge_graph_1.KnowledgeGraphManager(db);
62
+ vectorStore = new vector_store_1.VectorStore(db);
63
+ agentCoordinator = new agents_1.AgentCoordinator();
64
+ // Register agents
65
+ const analyzerAgent = new agents_1.AnalyzerAgent(db, knowledgeGraph, vectorStore);
66
+ const synthesizerAgent = new agents_1.SynthesizerAgent(db, vectorStore);
67
+ agentCoordinator.registerAgent(analyzerAgent);
68
+ agentCoordinator.registerAgent(synthesizerAgent);
69
+ // Create test session
70
+ testSessionId = (0, uuid_1.v4)();
71
+ db.prepare('INSERT INTO sessions (id, name, description) VALUES (?, ?, ?)').run(testSessionId, 'Multi-Agent Test', 'Testing multi-agent system');
72
+ });
73
+ afterEach(() => {
74
+ dbManager.close();
75
+ try {
76
+ fs.unlinkSync(tempDbPath);
77
+ fs.unlinkSync(`${tempDbPath}-wal`);
78
+ fs.unlinkSync(`${tempDbPath}-shm`);
79
+ }
80
+ catch (_e) {
81
+ // Ignore
82
+ }
83
+ });
84
+ describe('Pattern Analysis', () => {
85
+ beforeEach(() => {
86
+ // Create diverse test data
87
+ const items = [
88
+ // Tasks
89
+ {
90
+ key: 'implement_auth',
91
+ value: 'Implement OAuth2 authentication flow',
92
+ category: 'task',
93
+ priority: 'high',
94
+ },
95
+ {
96
+ key: 'add_tests',
97
+ value: 'Add unit tests for auth module',
98
+ category: 'task',
99
+ priority: 'high',
100
+ },
101
+ {
102
+ key: 'update_docs',
103
+ value: 'Update API documentation',
104
+ category: 'task',
105
+ priority: 'normal',
106
+ },
107
+ {
108
+ key: 'fix_bug_123',
109
+ value: 'Fix login timeout issue',
110
+ category: 'task',
111
+ priority: 'high',
112
+ },
113
+ {
114
+ key: 'refactor_db',
115
+ value: 'Refactor database connection pool',
116
+ category: 'task',
117
+ priority: 'low',
118
+ },
119
+ // Decisions
120
+ {
121
+ key: 'use_jwt',
122
+ value: 'Use JWT tokens with 24h expiry',
123
+ category: 'decision',
124
+ priority: 'high',
125
+ },
126
+ {
127
+ key: 'db_choice',
128
+ value: 'Use PostgreSQL for main database',
129
+ category: 'decision',
130
+ priority: 'high',
131
+ },
132
+ {
133
+ key: 'cache_strategy',
134
+ value: 'Implement Redis caching for sessions',
135
+ category: 'decision',
136
+ priority: 'normal',
137
+ },
138
+ // Progress
139
+ {
140
+ key: 'login_complete',
141
+ value: 'Completed login form UI',
142
+ category: 'progress',
143
+ priority: 'normal',
144
+ },
145
+ {
146
+ key: 'api_designed',
147
+ value: 'Designed REST API endpoints',
148
+ category: 'progress',
149
+ priority: 'normal',
150
+ },
151
+ {
152
+ key: 'tests_passing',
153
+ value: 'All auth tests passing',
154
+ category: 'progress',
155
+ priority: 'normal',
156
+ },
157
+ // Notes
158
+ {
159
+ key: 'security_note',
160
+ value: 'Remember to add rate limiting',
161
+ category: 'note',
162
+ priority: 'high',
163
+ },
164
+ {
165
+ key: 'performance_tip',
166
+ value: 'Consider connection pooling',
167
+ category: 'note',
168
+ priority: 'normal',
169
+ },
170
+ ];
171
+ for (const item of items) {
172
+ db.prepare('INSERT INTO context_items (id, session_id, key, value, category, priority, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)').run((0, uuid_1.v4)(), testSessionId, item.key, item.value, item.category, item.priority, new Date().toISOString());
173
+ }
174
+ });
175
+ it('should analyze patterns and provide insights', async () => {
176
+ const task = {
177
+ id: (0, uuid_1.v4)(),
178
+ type: 'analyze',
179
+ input: {
180
+ analysisType: 'patterns',
181
+ sessionId: testSessionId,
182
+ },
183
+ };
184
+ const results = await agentCoordinator.delegate(task);
185
+ expect(results.length).toBe(1);
186
+ expect(results[0].agentType).toBe('analyzer');
187
+ expect(results[0].confidence).toBeGreaterThan(0.7);
188
+ const output = results[0].output;
189
+ expect(output.patterns).toBeDefined();
190
+ expect(output.patterns.categoryDistribution.task).toBe(5);
191
+ expect(output.patterns.categoryDistribution.decision).toBe(3);
192
+ expect(output.patterns.priorityDistribution.high).toBe(6);
193
+ expect(output.insights).toBeInstanceOf(Array);
194
+ expect(output.insights.length).toBeGreaterThan(0);
195
+ });
196
+ it('should filter analysis by categories', async () => {
197
+ const task = {
198
+ id: (0, uuid_1.v4)(),
199
+ type: 'analyze',
200
+ input: {
201
+ analysisType: 'patterns',
202
+ sessionId: testSessionId,
203
+ categories: ['task', 'decision'],
204
+ },
205
+ };
206
+ const results = await agentCoordinator.delegate(task);
207
+ const output = results[0].output;
208
+ expect(output.itemCount).toBe(8); // 5 tasks + 3 decisions
209
+ expect(output.patterns.categoryDistribution.progress).toBeUndefined();
210
+ expect(output.patterns.categoryDistribution.note).toBeUndefined();
211
+ });
212
+ it('should analyze temporal patterns', async () => {
213
+ const task = {
214
+ id: (0, uuid_1.v4)(),
215
+ type: 'analyze',
216
+ input: {
217
+ analysisType: 'patterns',
218
+ sessionId: testSessionId,
219
+ timeframe: '-7 days',
220
+ },
221
+ };
222
+ const results = await agentCoordinator.delegate(task);
223
+ const output = results[0].output;
224
+ expect(output.patterns.temporalPatterns).toBeDefined();
225
+ expect(output.patterns.temporalPatterns.hourly).toBeDefined();
226
+ expect(output.patterns.temporalPatterns.daily).toBeDefined();
227
+ });
228
+ });
229
+ describe('Relationship Analysis', () => {
230
+ beforeEach(() => {
231
+ // Create entities and relationships
232
+ const authService = knowledgeGraph.createEntity(testSessionId, 'class', 'AuthService');
233
+ const tokenManager = knowledgeGraph.createEntity(testSessionId, 'class', 'TokenManager');
234
+ const userRepo = knowledgeGraph.createEntity(testSessionId, 'class', 'UserRepository');
235
+ const database = knowledgeGraph.createEntity(testSessionId, 'module', 'PostgreSQL');
236
+ knowledgeGraph.createRelation(testSessionId, authService.id, 'uses', tokenManager.id);
237
+ knowledgeGraph.createRelation(testSessionId, authService.id, 'calls', userRepo.id);
238
+ knowledgeGraph.createRelation(testSessionId, userRepo.id, 'connects_to', database.id);
239
+ knowledgeGraph.createRelation(testSessionId, tokenManager.id, 'generates', authService.id, 0.8);
240
+ });
241
+ it('should analyze entity relationships', async () => {
242
+ const task = {
243
+ id: (0, uuid_1.v4)(),
244
+ type: 'analyze',
245
+ input: {
246
+ analysisType: 'relationships',
247
+ sessionId: testSessionId,
248
+ },
249
+ };
250
+ const results = await agentCoordinator.delegate(task);
251
+ const output = results[0].output;
252
+ expect(output.analysis.entityCount).toBe(4);
253
+ expect(output.analysis.relationshipTypes).toBeDefined();
254
+ expect(output.analysis.centralNodes).toBeDefined();
255
+ expect(output.analysis.clusters).toBeDefined();
256
+ expect(output.recommendations).toBeInstanceOf(Array);
257
+ });
258
+ it('should find central nodes in graph', async () => {
259
+ const task = {
260
+ id: (0, uuid_1.v4)(),
261
+ type: 'analyze',
262
+ input: {
263
+ analysisType: 'relationships',
264
+ sessionId: testSessionId,
265
+ maxDepth: 3,
266
+ },
267
+ };
268
+ const results = await agentCoordinator.delegate(task);
269
+ const output = results[0].output;
270
+ const centralNodes = output.analysis.centralNodes;
271
+ expect(centralNodes.length).toBeGreaterThan(0);
272
+ expect(centralNodes[0].connections).toBeGreaterThan(0);
273
+ });
274
+ });
275
+ describe('Trend Analysis', () => {
276
+ beforeEach(() => {
277
+ // Create items with different timestamps
278
+ const now = new Date();
279
+ const items = [];
280
+ for (let i = 7; i >= 0; i--) {
281
+ const date = new Date(now);
282
+ date.setDate(date.getDate() - i);
283
+ // Simulate increasing activity
284
+ const itemCount = i === 0 ? 5 : i === 1 ? 4 : 2;
285
+ for (let j = 0; j < itemCount; j++) {
286
+ items.push({
287
+ key: `item_${i}_${j}`,
288
+ value: `Activity on day ${i}`,
289
+ category: j % 2 === 0 ? 'task' : 'progress',
290
+ priority: j === 0 ? 'high' : 'normal',
291
+ created_at: date.toISOString(),
292
+ });
293
+ }
294
+ }
295
+ for (const item of items) {
296
+ db.prepare('INSERT INTO context_items (id, session_id, key, value, category, priority, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)').run((0, uuid_1.v4)(), testSessionId, item.key, item.value, item.category, item.priority, item.created_at);
297
+ }
298
+ });
299
+ it('should analyze activity trends', async () => {
300
+ const task = {
301
+ id: (0, uuid_1.v4)(),
302
+ type: 'analyze',
303
+ input: {
304
+ analysisType: 'trends',
305
+ sessionId: testSessionId,
306
+ timeframe: '-7 days',
307
+ },
308
+ };
309
+ const results = await agentCoordinator.delegate(task);
310
+ const output = results[0].output;
311
+ expect(output.trends.activityTrend).toBeDefined();
312
+ expect(output.trends.activityTrend.direction).toBe('increasing');
313
+ expect(output.trends.categoryTrends).toBeDefined();
314
+ expect(output.trends.predictions).toBeDefined();
315
+ });
316
+ });
317
+ describe('Synthesis Operations', () => {
318
+ beforeEach(() => {
319
+ // Add diverse content for synthesis
320
+ const items = [
321
+ {
322
+ key: 'critical_bug',
323
+ value: 'Production server memory leak',
324
+ category: 'task',
325
+ priority: 'high',
326
+ },
327
+ {
328
+ key: 'auth_decision',
329
+ value: 'Implement OAuth2 with Google and GitHub',
330
+ category: 'decision',
331
+ priority: 'high',
332
+ },
333
+ {
334
+ key: 'api_progress',
335
+ value: 'Completed 80% of API endpoints',
336
+ category: 'progress',
337
+ priority: 'normal',
338
+ },
339
+ {
340
+ key: 'deploy_task',
341
+ value: 'Deploy to staging environment',
342
+ category: 'task',
343
+ priority: 'high',
344
+ },
345
+ {
346
+ key: 'test_progress',
347
+ value: 'Test coverage at 85%',
348
+ category: 'progress',
349
+ priority: 'normal',
350
+ },
351
+ ];
352
+ for (const item of items) {
353
+ db.prepare('INSERT INTO context_items (id, session_id, key, value, category, priority) VALUES (?, ?, ?, ?, ?, ?)').run((0, uuid_1.v4)(), testSessionId, item.key, item.value, item.category, item.priority);
354
+ }
355
+ });
356
+ it('should create comprehensive summary', async () => {
357
+ const task = {
358
+ id: (0, uuid_1.v4)(),
359
+ type: 'synthesize',
360
+ input: {
361
+ synthesisType: 'summary',
362
+ sessionId: testSessionId,
363
+ maxLength: 2000,
364
+ },
365
+ };
366
+ const results = await agentCoordinator.delegate(task);
367
+ expect(results[0].agentType).toBe('synthesizer');
368
+ const output = results[0].output;
369
+ expect(output.summary).toBeDefined();
370
+ expect(output.summary).toContain('Context Summary');
371
+ expect(output.summary).toContain('Key Decisions');
372
+ expect(output.summary).toContain('Current Tasks');
373
+ expect(output.summary.length).toBeLessThanOrEqual(2000);
374
+ });
375
+ it('should generate actionable recommendations', async () => {
376
+ const analysisResults = {
377
+ highPriorityCount: 3,
378
+ contextSize: 500,
379
+ staleTasks: false,
380
+ };
381
+ const task = {
382
+ id: (0, uuid_1.v4)(),
383
+ type: 'synthesize',
384
+ input: {
385
+ synthesisType: 'recommendations',
386
+ analysisResults,
387
+ },
388
+ };
389
+ const results = await agentCoordinator.delegate(task);
390
+ const output = results[0].output;
391
+ expect(output.immediate).toBeDefined();
392
+ expect(output.shortTerm).toBeDefined();
393
+ expect(output.longTerm).toBeDefined();
394
+ expect(output.warnings).toBeDefined();
395
+ });
396
+ });
397
+ describe('Agent Chaining', () => {
398
+ beforeEach(() => {
399
+ // Setup comprehensive test data
400
+ const items = [
401
+ {
402
+ key: 'main_feature',
403
+ value: 'Building real-time chat system',
404
+ category: 'task',
405
+ priority: 'high',
406
+ },
407
+ {
408
+ key: 'tech_decision',
409
+ value: 'Use WebSockets for real-time communication',
410
+ category: 'decision',
411
+ priority: 'high',
412
+ },
413
+ {
414
+ key: 'progress_ws',
415
+ value: 'WebSocket server implementation complete',
416
+ category: 'progress',
417
+ priority: 'normal',
418
+ },
419
+ {
420
+ key: 'security_task',
421
+ value: 'Implement message encryption',
422
+ category: 'task',
423
+ priority: 'high',
424
+ },
425
+ {
426
+ key: 'scale_note',
427
+ value: 'Consider horizontal scaling for chat servers',
428
+ category: 'note',
429
+ priority: 'normal',
430
+ },
431
+ ];
432
+ for (const item of items) {
433
+ db.prepare('INSERT INTO context_items (id, session_id, key, value, category, priority) VALUES (?, ?, ?, ?, ?, ?)').run((0, uuid_1.v4)(), testSessionId, item.key, item.value, item.category, item.priority);
434
+ }
435
+ });
436
+ it('should process analysis then synthesis chain', async () => {
437
+ const tasks = [
438
+ {
439
+ id: (0, uuid_1.v4)(),
440
+ type: 'analyze',
441
+ input: {
442
+ analysisType: 'comprehensive',
443
+ sessionId: testSessionId,
444
+ },
445
+ },
446
+ {
447
+ id: (0, uuid_1.v4)(),
448
+ type: 'synthesize',
449
+ input: {
450
+ synthesisType: 'recommendations',
451
+ },
452
+ },
453
+ ];
454
+ const results = await agentCoordinator.processChain(tasks);
455
+ expect(results.length).toBe(2);
456
+ expect(results[0].agentType).toBe('analyzer');
457
+ expect(results[1].agentType).toBe('synthesizer');
458
+ // Second task should use first task's output
459
+ expect(results[1].output.immediate).toBeDefined();
460
+ expect(results[1].output.shortTerm).toBeDefined();
461
+ expect(results[1].output.longTerm).toBeDefined();
462
+ expect(results[1].output.warnings).toBeDefined();
463
+ // Should have generated some recommendations
464
+ const totalRecommendations = results[1].output.immediate.length +
465
+ results[1].output.shortTerm.length +
466
+ results[1].output.longTerm.length;
467
+ expect(totalRecommendations).toBeGreaterThan(0);
468
+ });
469
+ });
470
+ describe('Comprehensive Analysis', () => {
471
+ it('should perform full system analysis', async () => {
472
+ // Add complex data
473
+ const items = [
474
+ {
475
+ key: 'arch_decision',
476
+ value: 'Microservices architecture with API gateway',
477
+ category: 'decision',
478
+ priority: 'high',
479
+ },
480
+ {
481
+ key: 'auth_task',
482
+ value: 'Implement JWT authentication',
483
+ category: 'task',
484
+ priority: 'high',
485
+ },
486
+ {
487
+ key: 'db_progress',
488
+ value: 'Database schema migration complete',
489
+ category: 'progress',
490
+ priority: 'normal',
491
+ },
492
+ {
493
+ key: 'perf_note',
494
+ value: 'Monitor API response times',
495
+ category: 'note',
496
+ priority: 'high',
497
+ },
498
+ ];
499
+ for (const item of items) {
500
+ db.prepare('INSERT INTO context_items (id, session_id, key, value, category, priority) VALUES (?, ?, ?, ?, ?, ?)').run((0, uuid_1.v4)(), testSessionId, item.key, item.value, item.category, item.priority);
501
+ }
502
+ const task = {
503
+ id: (0, uuid_1.v4)(),
504
+ type: 'analyze',
505
+ input: {
506
+ analysisType: 'comprehensive',
507
+ sessionId: testSessionId,
508
+ },
509
+ };
510
+ const results = await agentCoordinator.delegate(task);
511
+ const output = results[0].output;
512
+ expect(output.patterns).toBeDefined();
513
+ expect(output.relationships).toBeDefined();
514
+ expect(output.trends).toBeDefined();
515
+ expect(output.overallInsights).toBeDefined();
516
+ expect(output.overallInsights.length).toBeGreaterThan(0);
517
+ expect(results[0].confidence).toBe(0.9);
518
+ });
519
+ });
520
+ describe('Error Handling', () => {
521
+ it('should handle invalid task type gracefully', async () => {
522
+ const task = {
523
+ id: (0, uuid_1.v4)(),
524
+ type: 'invalid',
525
+ input: {},
526
+ };
527
+ const results = await agentCoordinator.delegate(task);
528
+ expect(results.length).toBe(1);
529
+ expect(results[0].output.error).toBeDefined();
530
+ expect(results[0].confidence).toBe(0);
531
+ });
532
+ it('should handle missing session gracefully', async () => {
533
+ const task = {
534
+ id: (0, uuid_1.v4)(),
535
+ type: 'analyze',
536
+ input: {
537
+ analysisType: 'patterns',
538
+ sessionId: 'non-existent-session',
539
+ },
540
+ };
541
+ const results = await agentCoordinator.delegate(task);
542
+ expect(results[0].output.itemCount).toBe(0);
543
+ expect(results[0].confidence).toBeLessThan(0.8); // Lower confidence with no data
544
+ });
545
+ });
546
+ });