@gotza02/seq-thinking 1.1.5 → 1.1.6

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 (49) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/mcp-server.js +1 -1
  5. package/package.json +8 -2
  6. package/agents_test.log +0 -15
  7. package/data/agents/1770106504306-dljh9ef.json +0 -68
  8. package/data/agents/1770106504310-4oarrst.json +0 -58
  9. package/data/agents/1770106540588-pvitt55.json +0 -68
  10. package/data/agents/1770106540595-z2ya871.json +0 -58
  11. package/data/agents/1770106710890-0e2naq1.json +0 -68
  12. package/data/agents/1770106710893-r076yxx.json +0 -58
  13. package/data/agents/1770109212161-4ybd0i7.json +0 -68
  14. package/data/agents/1770109212166-gkhya8h.json +0 -58
  15. package/data/agents/1770117726716-lrnm415.json +0 -68
  16. package/data/agents/1770117726719-w6hsf3v.json +0 -58
  17. package/data/sessions/1770100622009-5afiuyv.json +0 -499
  18. package/data/sessions/1770106504312-75zk750.json +0 -107
  19. package/data/sessions/1770106540597-z8e8soo.json +0 -150
  20. package/data/sessions/1770106710894-0kxgy5x.json +0 -150
  21. package/data/sessions/1770109212169-zpddeb9.json +0 -150
  22. package/data/sessions/1770117726720-frcwj99.json +0 -150
  23. package/real_world_test.log +0 -200
  24. package/real_world_test_dynamic.log +0 -184
  25. package/real_world_test_real.log +0 -184
  26. package/src/__tests__/agents.test.ts +0 -858
  27. package/src/__tests__/mcp-server.test.ts +0 -380
  28. package/src/__tests__/sequential-thinking.test.ts +0 -687
  29. package/src/__tests__/swarm-coordinator.test.ts +0 -903
  30. package/src/__tests__/types.test.ts +0 -839
  31. package/src/__tests__/utils.test.ts +0 -322
  32. package/src/agents/base-agent.ts +0 -288
  33. package/src/agents/critic-agent.ts +0 -582
  34. package/src/agents/index.ts +0 -11
  35. package/src/agents/meta-reasoning-agent.ts +0 -314
  36. package/src/agents/reasoner-agent.ts +0 -312
  37. package/src/agents/synthesizer-agent.ts +0 -641
  38. package/src/index.ts +0 -118
  39. package/src/mcp-server.ts +0 -391
  40. package/src/real_world_test.ts +0 -89
  41. package/src/sequential-thinking.ts +0 -614
  42. package/src/swarm-coordinator.ts +0 -772
  43. package/src/types/index.ts +0 -915
  44. package/src/utils/index.ts +0 -1004
  45. package/src/utils/llm-adapter.ts +0 -110
  46. package/src/utils/logger.ts +0 -56
  47. package/src/utils/persistence.ts +0 -109
  48. package/test_output.log +0 -0
  49. package/tsconfig.json +0 -21
@@ -1,687 +0,0 @@
1
- /**
2
- * Sequential Thinking Engine Test Suite
3
- * Tests for ConfidenceCalibrator, ThoughtGraph, MetaReasoningEngine,
4
- * SelfCorrectionEngine, AdaptiveGranularityEngine, and SessionManager
5
- */
6
- import { test, describe, beforeEach } from 'node:test';
7
- import assert from 'node:assert';
8
- import {
9
- ConfidenceCalibrator,
10
- ThoughtGraph,
11
- MetaReasoningEngine,
12
- SelfCorrectionEngine,
13
- AdaptiveGranularityEngine,
14
- SessionManager,
15
- } from '../sequential-thinking.js';
16
- import { ThoughtType, SessionStatus, TaskStatus, type SessionContext, type SessionSettings } from '../types/index.js';
17
-
18
- describe('ConfidenceCalibrator', () => {
19
- let calibrator: ConfidenceCalibrator;
20
-
21
- beforeEach(() => {
22
- calibrator = new ConfidenceCalibrator();
23
- });
24
-
25
- test('should create initial confidence with valid structure', () => {
26
- const confidence = calibrator.createInitialConfidence();
27
-
28
- assert.ok(typeof confidence.overall === 'number');
29
- assert.ok(confidence.overall >= 0 && confidence.overall <= 1);
30
-
31
- assert.ok(typeof confidence.components.logicalConsistency === 'number');
32
- assert.ok(typeof confidence.components.factualAccuracy === 'number');
33
- assert.ok(typeof confidence.components.reasoningQuality === 'number');
34
- assert.ok(typeof confidence.components.evidenceStrength === 'number');
35
-
36
- assert.ok(Array.isArray(confidence.uncertaintyBounds));
37
- assert.strictEqual(confidence.uncertaintyBounds.length, 2);
38
- assert.ok(confidence.uncertaintyBounds[0] <= confidence.uncertaintyBounds[1]);
39
-
40
- assert.ok(Array.isArray(confidence.calibrationHistory));
41
- });
42
-
43
- test('should calculate overall confidence from components', () => {
44
- const components = {
45
- logicalConsistency: 0.9,
46
- factualAccuracy: 0.8,
47
- reasoningQuality: 0.85,
48
- evidenceStrength: 0.75,
49
- };
50
-
51
- const overall = calibrator.calculateOverall(components);
52
- assert.ok(overall >= 0 && overall <= 1);
53
- assert.ok(overall > 0.7 && overall < 0.9);
54
- });
55
-
56
- test('should handle all zero components', () => {
57
- const components = {
58
- logicalConsistency: 0,
59
- factualAccuracy: 0,
60
- reasoningQuality: 0,
61
- evidenceStrength: 0,
62
- };
63
-
64
- const overall = calibrator.calculateOverall(components);
65
- assert.strictEqual(overall, 0);
66
- });
67
-
68
- test('should handle all perfect components', () => {
69
- const components = {
70
- logicalConsistency: 1,
71
- factualAccuracy: 1,
72
- reasoningQuality: 1,
73
- evidenceStrength: 1,
74
- };
75
-
76
- const overall = calibrator.calculateOverall(components);
77
- assert.strictEqual(overall, 1);
78
- });
79
-
80
- test('should handle mixed component values', () => {
81
- const components = {
82
- logicalConsistency: 0.5,
83
- factualAccuracy: 0.5,
84
- reasoningQuality: 0.5,
85
- evidenceStrength: 0.5,
86
- };
87
-
88
- const overall = calibrator.calculateOverall(components);
89
- assert.strictEqual(overall, 0.5);
90
- });
91
- });
92
-
93
- describe('ThoughtGraph', () => {
94
- let graph: ThoughtGraph;
95
- const sessionId = 'test-session-001';
96
-
97
- beforeEach(() => {
98
- graph = new ThoughtGraph();
99
- });
100
-
101
- test('should create a thought with default options', () => {
102
- const thought = graph.createThought(sessionId, 'Test thought content');
103
-
104
- assert.ok(thought.id);
105
- assert.strictEqual(thought.sessionId, sessionId);
106
- assert.strictEqual(thought.content, 'Test thought content');
107
- assert.strictEqual(thought.thoughtType, ThoughtType.ANALYSIS);
108
- assert.strictEqual(thought.stepNumber, 1);
109
- assert.ok(thought.confidence);
110
- assert.ok(thought.branchId);
111
- assert.ok(thought.metadata.createdAt);
112
- });
113
-
114
- test('should create a thought with custom options', () => {
115
- const thought = graph.createThought(sessionId, 'Custom thought', {
116
- thoughtType: ThoughtType.ANALYSIS,
117
- confidence: 0.9,
118
- tags: ['test', 'analysis'],
119
- assumptions: ['assumption-1'],
120
- dependencies: ['dep-1'],
121
- agentId: 'agent-001',
122
- });
123
-
124
- assert.strictEqual(thought.thoughtType, ThoughtType.ANALYSIS);
125
- assert.deepStrictEqual(thought.tags, ['test', 'analysis']);
126
- assert.deepStrictEqual(thought.assumptions, ['assumption-1']);
127
- assert.deepStrictEqual(thought.dependencies, ['dep-1']);
128
- assert.strictEqual(thought.metadata.agentId, 'agent-001');
129
- });
130
-
131
- test('should create child thoughts with correct step numbers', () => {
132
- const parent = graph.createThought(sessionId, 'Parent thought');
133
- const child = graph.createThought(sessionId, 'Child thought', {
134
- parentThoughtId: parent.id,
135
- });
136
-
137
- assert.strictEqual(child.stepNumber, 2);
138
- assert.strictEqual(child.parentThoughtId, parent.id);
139
- assert.ok(parent.childThoughtIds.includes(child.id));
140
- });
141
-
142
- test('should create multiple levels of thoughts', () => {
143
- const level1 = graph.createThought(sessionId, 'Level 1');
144
- const level2 = graph.createThought(sessionId, 'Level 2', {
145
- parentThoughtId: level1.id,
146
- });
147
- const level3 = graph.createThought(sessionId, 'Level 3', {
148
- parentThoughtId: level2.id,
149
- });
150
-
151
- assert.strictEqual(level1.stepNumber, 1);
152
- assert.strictEqual(level2.stepNumber, 2);
153
- assert.strictEqual(level3.stepNumber, 3);
154
- });
155
-
156
- test('should revise a thought', () => {
157
- const original = graph.createThought(sessionId, 'Original content');
158
- const revised = graph.reviseThought(original.id, 'Revised content', 'Improved clarity');
159
-
160
- assert.notStrictEqual(revised.id, original.id);
161
- assert.strictEqual(revised.revisionOf, original.id);
162
- assert.strictEqual(revised.content, 'Revised content');
163
- assert.strictEqual(revised.revisionHistory.length, 1);
164
- assert.strictEqual(revised.revisionHistory[0].previousContent, 'Original content');
165
- assert.strictEqual(revised.revisionHistory[0].revisionReason, 'Improved clarity');
166
- });
167
-
168
- test('should create a branch', () => {
169
- const root = graph.createThought(sessionId, 'Root thought');
170
- const { branch, thought } = graph.createBranch(
171
- sessionId,
172
- root.id,
173
- 'Alternative Path',
174
- 'Exploring alternative reasoning',
175
- 'Branch thought'
176
- );
177
-
178
- assert.ok(branch.id);
179
- assert.strictEqual(branch.name, 'Alternative Path');
180
- assert.strictEqual(branch.parentBranchId, root.branchId);
181
- assert.ok(branch.thoughtIds.includes(thought.id));
182
- assert.strictEqual(thought.branchId, branch.id);
183
- });
184
-
185
- test('should merge branches', () => {
186
- const root = graph.createThought(sessionId, 'Root thought');
187
- const { branch: branch1 } = graph.createBranch(sessionId, root.id, 'Branch 1', 'First branch', 'B1 thought');
188
- const { branch: branch2 } = graph.createBranch(sessionId, root.id, 'Branch 2', 'Second branch', 'B2 thought');
189
-
190
- const mergeThought = graph.mergeBranches(branch1.id, branch2.id, 'Merged conclusion');
191
-
192
- assert.ok(mergeThought);
193
- assert.strictEqual(mergeThought.thoughtType, ThoughtType.MERGE_POINT);
194
- });
195
-
196
- test('should prune a branch', () => {
197
- const root = graph.createThought(sessionId, 'Root thought');
198
- const { branch } = graph.createBranch(sessionId, root.id, 'To Prune', 'Will be pruned', 'Prune me');
199
-
200
- graph.pruneBranch(branch.id, 'Low confidence');
201
-
202
- const branches = graph.getBranches();
203
- const prunedBranch = branches.get(branch.id);
204
- assert.ok(prunedBranch);
205
- assert.strictEqual(prunedBranch.status, 'pruned');
206
- });
207
-
208
- test('should get thinking path', () => {
209
- const thought1 = graph.createThought(sessionId, 'Thought 1');
210
- const thought2 = graph.createThought(sessionId, 'Thought 2', {
211
- parentThoughtId: thought1.id,
212
- });
213
- const thought3 = graph.createThought(sessionId, 'Thought 3', {
214
- parentThoughtId: thought2.id,
215
- });
216
-
217
- const path = graph.getThinkingPath(thought3.id);
218
-
219
- assert.strictEqual(path.length, 3);
220
- assert.strictEqual(path[0].id, thought1.id);
221
- assert.strictEqual(path[1].id, thought2.id);
222
- assert.strictEqual(path[2].id, thought3.id);
223
- });
224
-
225
- test('should get branch comparison', () => {
226
- const root = graph.createThought(sessionId, 'Root thought');
227
- const { branch: branch1 } = graph.createBranch(sessionId, root.id, 'Branch 1', 'First', 'B1');
228
- const { branch: branch2 } = graph.createBranch(sessionId, root.id, 'Branch 2', 'Second', 'B2');
229
-
230
- graph.createThought(sessionId, 'B1 child', { branchId: branch1.id });
231
- graph.createThought(sessionId, 'B2 child', { branchId: branch2.id });
232
-
233
- const comparison = graph.getBranchComparison([branch1.id, branch2.id]);
234
-
235
- assert.strictEqual(comparison.length, 2);
236
- comparison.forEach(item => {
237
- assert.ok(item.branchId);
238
- assert.ok(typeof item.thoughtCount === 'number');
239
- assert.ok(typeof item.averageConfidence === 'number');
240
- });
241
- });
242
-
243
- test('should store thoughts and branches correctly', () => {
244
- const root = graph.createThought(sessionId, 'Test thought');
245
- graph.createBranch(sessionId, root.id, 'Branch 1', 'Test Branch', 'Branch content');
246
-
247
- const thoughts = graph.getThoughts();
248
- const branches = graph.getBranches();
249
-
250
- assert.ok(thoughts instanceof Map);
251
- assert.ok(branches instanceof Map);
252
- assert.ok(thoughts.size > 0);
253
- assert.ok(branches.size > 0);
254
- });
255
-
256
- test('should handle multiple thoughts in same branch', () => {
257
- const thought1 = graph.createThought(sessionId, 'Thought 1');
258
- const thought2 = graph.createThought(sessionId, 'Thought 2', {
259
- branchId: thought1.branchId,
260
- });
261
- const thought3 = graph.createThought(sessionId, 'Thought 3', {
262
- branchId: thought1.branchId,
263
- parentThoughtId: thought2.id,
264
- });
265
-
266
- assert.strictEqual(thought1.branchId, thought2.branchId);
267
- assert.strictEqual(thought2.branchId, thought3.branchId);
268
- });
269
-
270
- test('should handle thought with null parent', () => {
271
- const thought = graph.createThought(sessionId, 'Root thought', {
272
- parentThoughtId: null,
273
- });
274
-
275
- assert.strictEqual(thought.parentThoughtId, null);
276
- assert.strictEqual(thought.stepNumber, 1);
277
- });
278
-
279
- test('should handle revision of non-existent thought gracefully', () => {
280
- assert.throws(() => {
281
- graph.reviseThought('non-existent-id', 'Content', 'Reason');
282
- });
283
- });
284
- });
285
-
286
- describe('MetaReasoningEngine', () => {
287
- let engine: MetaReasoningEngine;
288
- let graph: ThoughtGraph;
289
-
290
- beforeEach(() => {
291
- engine = new MetaReasoningEngine();
292
- graph = new ThoughtGraph();
293
- });
294
-
295
- test('should reflect on session', async () => {
296
- const session = createMockSession();
297
- const reflection = await engine.reflect(session);
298
-
299
- assert.ok(reflection.reflectionType);
300
- assert.ok(reflection.content);
301
- assert.ok(Array.isArray(reflection.insights));
302
- assert.ok(Array.isArray(reflection.recommendations));
303
- });
304
-
305
- test('should generate meta observation for thought', () => {
306
- const sessionId = 'test-session';
307
- const thought = graph.createThought(sessionId, 'Test thought');
308
-
309
- const metaNote = engine.generateMetaObservation(thought.id, graph);
310
-
311
- if (metaNote) {
312
- assert.ok(metaNote.id);
313
- assert.strictEqual(metaNote.thoughtId, thought.id);
314
- assert.ok(metaNote.content);
315
- assert.ok(['pattern', 'concern', 'strategy', 'bias', 'confidence', 'process'].includes(metaNote.observationType));
316
- assert.ok(metaNote.timestamp);
317
- assert.ok(Array.isArray(metaNote.triggeredActions));
318
- }
319
- });
320
-
321
- test('should handle empty session reflection', async () => {
322
- const emptySession = createMockSession({ totalThoughts: 0, totalBranches: 0 });
323
- const reflection = await engine.reflect(emptySession);
324
-
325
- assert.ok(reflection);
326
- assert.ok(Array.isArray(reflection.insights));
327
- assert.ok(Array.isArray(reflection.recommendations));
328
- });
329
-
330
- test('should handle session with multiple branches', async () => {
331
- const session = createMockSession({ totalThoughts: 10, totalBranches: 3 });
332
- const reflection = await engine.reflect(session);
333
-
334
- assert.ok(reflection.insights.length > 0 || reflection.recommendations.length > 0);
335
- });
336
- });
337
-
338
- describe('SelfCorrectionEngine', () => {
339
- let engine: SelfCorrectionEngine;
340
- let graph: ThoughtGraph;
341
-
342
- beforeEach(() => {
343
- engine = new SelfCorrectionEngine();
344
- graph = new ThoughtGraph();
345
- });
346
-
347
- test('should detect issues in thought', async () => {
348
- const sessionId = 'test-session';
349
- const thought = graph.createThought(sessionId, 'Test thought with potential issues');
350
-
351
- const issues = await engine.detectIssues(thought, graph);
352
-
353
- assert.ok(Array.isArray(issues));
354
- issues.forEach(issue => {
355
- assert.ok(['logical', 'factual', 'assumption', 'calibration'].includes(issue.type));
356
- assert.ok(['low', 'medium', 'high'].includes(issue.severity));
357
- assert.ok(issue.description);
358
- assert.ok(issue.suggestion);
359
- });
360
- });
361
-
362
- test('should detect no issues in well-formed thought', async () => {
363
- const sessionId = 'test-session';
364
- const thought = graph.createThought(sessionId, 'Well-formed thought with clear reasoning', {
365
- confidence: 0.95,
366
- assumptions: ['valid-assumption'],
367
- });
368
-
369
- const issues = await engine.detectIssues(thought, graph);
370
-
371
- // Should either return empty array or only low severity issues
372
- issues.forEach(issue => {
373
- assert.ok(issue.severity === 'low');
374
- });
375
- });
376
-
377
- test('should check session health', () => {
378
- const session = createMockSession({ totalThoughts: 5, totalBranches: 2 });
379
-
380
- const health = engine.checkSessionHealth(session);
381
-
382
- assert.ok(typeof health.isHealthy === 'boolean');
383
- assert.ok(Array.isArray(health.issues));
384
- assert.ok(Array.isArray(health.suggestions));
385
- assert.ok(typeof health.confidence === 'number');
386
- assert.ok(health.confidence >= 0 && health.confidence <= 1);
387
- });
388
-
389
- test('should identify unhealthy session', () => {
390
- const unhealthySession = createMockSession({
391
- totalThoughts: 100,
392
- totalBranches: 50,
393
- status: SessionStatus.COMPLETED
394
- });
395
-
396
- const health = engine.checkSessionHealth(unhealthySession);
397
-
398
- // High branch count might indicate issues
399
- if (health.issues.length > 0) {
400
- assert.ok(health.issues.some(issue => issue.includes('branch') || issue.includes('complexity')));
401
- }
402
- });
403
-
404
- test('should handle empty session health check', () => {
405
- const emptySession = createMockSession({ totalThoughts: 0, totalBranches: 0 });
406
-
407
- const health = engine.checkSessionHealth(emptySession);
408
-
409
- assert.ok(typeof health.isHealthy === 'boolean');
410
- assert.ok(health.issues.length >= 0);
411
- });
412
- });
413
-
414
- describe('AdaptiveGranularityEngine', () => {
415
- let engine: AdaptiveGranularityEngine;
416
-
417
- beforeEach(() => {
418
- engine = new AdaptiveGranularityEngine();
419
- });
420
-
421
- test('should calculate granularity for simple topic', async () => {
422
- const context = createMockContext();
423
- const result = await engine.calculateGranularity('Simple topic', context, 1);
424
-
425
- assert.ok(typeof result.detail === 'number');
426
- assert.ok(result.detail > 0 && result.detail <= 1);
427
- assert.ok(result.reasoning);
428
- });
429
-
430
- test('should calculate granularity for complex topic', async () => {
431
- const context = createMockContext();
432
- const complexTopic = 'Analyze the implications of quantum computing on cryptographic systems';
433
- const result = await engine.calculateGranularity(complexTopic, context, 1);
434
-
435
- assert.ok(result.detail > 0);
436
- assert.ok(result.reasoning.length > 0);
437
- });
438
-
439
- test('should adjust granularity based on depth', async () => {
440
- const context = createMockContext();
441
- const topic = 'Test topic';
442
-
443
- const shallow = await engine.calculateGranularity(topic, context, 1);
444
- const deep = await engine.calculateGranularity(topic, context, 10);
445
-
446
- // Deeper depth might suggest different granularity
447
- assert.ok(typeof shallow.detail === 'number');
448
- assert.ok(typeof deep.detail === 'number');
449
- });
450
-
451
- test('should get recommendation for session', () => {
452
- const session = createMockSession();
453
-
454
- const recommendation = engine.getRecommendation(session);
455
-
456
- assert.ok(recommendation.suggestedAction);
457
- assert.ok(typeof recommendation.detail === 'number');
458
- assert.ok(recommendation.reasoning);
459
- });
460
-
461
- test('should handle empty context', async () => {
462
- const emptyContext: SessionContext = {
463
- originalProblem: '',
464
- constraints: [],
465
- relevantInformation: [],
466
- workingMemory: new Map(),
467
- longTermReferences: [],
468
- };
469
-
470
- const result = await engine.calculateGranularity('Topic', emptyContext, 1);
471
-
472
- assert.ok(typeof result.detail === 'number');
473
- assert.ok(result.reasoning);
474
- });
475
-
476
- test('should handle very complex context', async () => {
477
- const complexContext: SessionContext = {
478
- originalProblem: 'Complex multi-faceted problem',
479
- constraints: Array(20).fill('constraint'),
480
- relevantInformation: Array(50).fill('info'),
481
- workingMemory: new Map(Array(30).fill(0).map((_, i) => [`key${i}`, `value${i}`])),
482
- longTermReferences: Array(10).fill('ref'),
483
- };
484
-
485
- const result = await engine.calculateGranularity('Complex topic', complexContext, 5);
486
-
487
- assert.ok(typeof result.detail === 'number');
488
- assert.ok(result.detail > 0 && result.detail <= 1);
489
- });
490
- });
491
-
492
- describe('SessionManager', () => {
493
- let manager: SessionManager;
494
-
495
- beforeEach(() => {
496
- manager = new SessionManager();
497
- });
498
-
499
- test('should create a session', async () => {
500
- const session = await manager.createSession('Test topic');
501
-
502
- assert.ok(session.id);
503
- assert.strictEqual(session.topic, 'Test topic');
504
- assert.strictEqual(session.status, SessionStatus.INITIALIZING);
505
- assert.ok(session.branches instanceof Map);
506
- assert.ok(session.thoughts instanceof Map);
507
- assert.ok(session.settings);
508
- assert.ok(session.metadata.createdAt);
509
- });
510
-
511
- test('should create session with custom settings', async () => {
512
- const customSettings: Partial<SessionSettings> = {
513
- maxBranches: 10,
514
- confidenceThreshold: 0.8,
515
- enableSelfCorrection: false,
516
- };
517
-
518
- const session = await manager.createSession('Test topic', customSettings);
519
-
520
- assert.strictEqual(session.settings.maxBranches, 10);
521
- assert.strictEqual(session.settings.confidenceThreshold, 0.8);
522
- assert.strictEqual(session.settings.enableSelfCorrection, false);
523
- });
524
-
525
- test('should add thought to session', async () => {
526
- const session = await manager.createSession('Test topic');
527
- const result = await manager.addThought(session.id, 'Test thought content');
528
-
529
- assert.ok(result.thought);
530
- assert.strictEqual(result.thought.content, 'Test thought content');
531
- assert.ok(result.thought.confidence);
532
- });
533
-
534
- test('should add thought with options', async () => {
535
- const session = await manager.createSession('Test topic');
536
- const result = await manager.addThought(session.id, 'Test thought', {
537
- thoughtType: ThoughtType.ANALYSIS,
538
- confidence: 0.9,
539
- tags: ['test'],
540
- });
541
-
542
- assert.strictEqual(result.thought.thoughtType, ThoughtType.ANALYSIS);
543
- assert.deepStrictEqual(result.thought.tags, ['test']);
544
- });
545
-
546
- test('should get session by id', async () => {
547
- const session = await manager.createSession('Test topic');
548
- const retrieved = manager.getSession(session.id);
549
-
550
- assert.ok(retrieved);
551
- assert.strictEqual(retrieved!.id, session.id);
552
- assert.strictEqual(retrieved!.topic, 'Test topic');
553
- });
554
-
555
- test('should return undefined for non-existent session', () => {
556
- const retrieved = manager.getSession('non-existent-id');
557
- assert.strictEqual(retrieved, undefined);
558
- });
559
-
560
- test('should get thought graph', () => {
561
- const graph = manager.getThoughtGraph();
562
- assert.ok(graph);
563
- assert.ok(typeof graph.createThought === 'function');
564
- });
565
-
566
- test('should get meta engine', () => {
567
- const engine = manager.getMetaEngine();
568
- assert.ok(engine);
569
- assert.ok(typeof engine.reflect === 'function');
570
- });
571
-
572
- test('should complete session', async () => {
573
- const session = await manager.createSession('Test topic');
574
- await manager.addThought(session.id, 'Thought 1');
575
-
576
- await manager.completeSession(session.id);
577
-
578
- const completed = manager.getSession(session.id);
579
- assert.strictEqual(completed!.status, 'completed');
580
- assert.ok(completed!.metadata.completedAt);
581
- });
582
-
583
- test('should get session status', async () => {
584
- const session = await manager.createSession('Test topic');
585
- await manager.addThought(session.id, 'Thought 1');
586
-
587
- const status = manager.getSessionStatus(session.id);
588
-
589
- assert.ok(status);
590
- assert.strictEqual(status.id, session.id);
591
- assert.ok(status.status);
592
- assert.ok(typeof status.totalThoughts === 'number');
593
- assert.ok(Array.isArray(status.branches));
594
- assert.ok(typeof status.averageConfidence === 'number');
595
- assert.ok(status.lastActivity);
596
- });
597
-
598
- test('should track multiple thoughts', async () => {
599
- const session = await manager.createSession('Test topic');
600
-
601
- await manager.addThought(session.id, 'Thought 1');
602
- await manager.addThought(session.id, 'Thought 2');
603
- await manager.addThought(session.id, 'Thought 3');
604
-
605
- const status = manager.getSessionStatus(session.id);
606
- assert.strictEqual(status.totalThoughts, 3);
607
- });
608
-
609
- test('should handle adding thought to non-existent session', async () => {
610
- await assert.rejects(async () => {
611
- await manager.addThought('non-existent-id', 'Test thought');
612
- });
613
- });
614
-
615
- test('should handle completing non-existent session', async () => {
616
- await assert.rejects(async () => {
617
- await manager.completeSession('non-existent-id');
618
- });
619
- });
620
-
621
- test('should create multiple independent sessions', async () => {
622
- const session1 = await manager.createSession('Topic 1');
623
- const session2 = await manager.createSession('Topic 2');
624
-
625
- assert.notStrictEqual(session1.id, session2.id);
626
-
627
- await manager.addThought(session1.id, 'Thought for session 1');
628
- await manager.addThought(session2.id, 'Thought for session 2');
629
-
630
- const status1 = manager.getSessionStatus(session1.id);
631
- const status2 = manager.getSessionStatus(session2.id);
632
-
633
- assert.strictEqual(status1.totalThoughts, 1);
634
- assert.strictEqual(status2.totalThoughts, 1);
635
- });
636
- });
637
-
638
- // Helper functions
639
- function createMockSession(overrides: { totalThoughts?: number; totalBranches?: number; status?: SessionStatus } = {}) {
640
- const now = new Date();
641
- return {
642
- id: 'mock-session',
643
- topic: 'Mock Topic',
644
- status: overrides.status || SessionStatus.ACTIVE,
645
- currentBranchId: 'branch-001',
646
- branches: new Map(),
647
- thoughts: new Map(),
648
- metaNotes: new Map(),
649
- context: {
650
- originalProblem: 'Mock problem',
651
- constraints: [],
652
- relevantInformation: [],
653
- workingMemory: new Map(),
654
- longTermReferences: [],
655
- },
656
- settings: {
657
- maxBranches: 5,
658
- maxDepth: 10,
659
- confidenceThreshold: 0.7,
660
- enableSelfCorrection: true,
661
- enableMetaReasoning: true,
662
- enableParallelHypotheses: false,
663
- adaptiveGranularity: true,
664
- granularitySettings: {
665
- minStepDetail: 1,
666
- maxStepDetail: 10,
667
- complexityThreshold: 0.5,
668
- },
669
- },
670
- metadata: {
671
- createdAt: now,
672
- lastActivityAt: now,
673
- totalThoughts: overrides.totalThoughts ?? 5,
674
- totalBranches: overrides.totalBranches ?? 1,
675
- },
676
- };
677
- }
678
-
679
- function createMockContext(): SessionContext {
680
- return {
681
- originalProblem: 'Test problem',
682
- constraints: ['constraint-1', 'constraint-2'],
683
- relevantInformation: ['info-1', 'info-2'],
684
- workingMemory: new Map([['key', 'value']]),
685
- longTermReferences: ['ref-1'],
686
- };
687
- }