lynkr 8.0.0 → 8.0.1

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 (102) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/api/openai-router.js +34 -2
  4. package/src/clients/standard-tools.js +23 -0
  5. package/src/config/index.js +20 -0
  6. package/src/orchestrator/index.js +2 -2
  7. package/src/server.js +2 -12
  8. package/src/tools/index.js +4 -0
  9. package/src/tools/lazy-loader.js +7 -0
  10. package/src/tools/tinyfish.js +358 -0
  11. package/src/tools/truncate.js +1 -0
  12. package/.github/FUNDING.yml +0 -15
  13. package/.github/workflows/README.md +0 -215
  14. package/.github/workflows/ci.yml +0 -69
  15. package/.github/workflows/index.yml +0 -62
  16. package/.github/workflows/web-tools-tests.yml +0 -56
  17. package/CITATIONS.bib +0 -6
  18. package/DEPLOYMENT.md +0 -1001
  19. package/LYNKR-TUI-PLAN.md +0 -984
  20. package/PERFORMANCE-REPORT.md +0 -866
  21. package/PLAN-per-client-model-routing.md +0 -252
  22. package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
  23. package/docs/BingSiteAuth.xml +0 -4
  24. package/docs/docs-style.css +0 -478
  25. package/docs/docs.html +0 -198
  26. package/docs/google5be250e608e6da39.html +0 -1
  27. package/docs/index.html +0 -577
  28. package/docs/index.md +0 -584
  29. package/docs/robots.txt +0 -4
  30. package/docs/sitemap.xml +0 -44
  31. package/docs/style.css +0 -1223
  32. package/docs/toon-integration-spec.md +0 -130
  33. package/documentation/README.md +0 -101
  34. package/documentation/api.md +0 -806
  35. package/documentation/claude-code-cli.md +0 -679
  36. package/documentation/codex-cli.md +0 -397
  37. package/documentation/contributing.md +0 -571
  38. package/documentation/cursor-integration.md +0 -734
  39. package/documentation/docker.md +0 -874
  40. package/documentation/embeddings.md +0 -762
  41. package/documentation/faq.md +0 -713
  42. package/documentation/features.md +0 -403
  43. package/documentation/headroom.md +0 -519
  44. package/documentation/installation.md +0 -758
  45. package/documentation/memory-system.md +0 -476
  46. package/documentation/production.md +0 -636
  47. package/documentation/providers.md +0 -1009
  48. package/documentation/routing.md +0 -476
  49. package/documentation/testing.md +0 -629
  50. package/documentation/token-optimization.md +0 -325
  51. package/documentation/tools.md +0 -697
  52. package/documentation/troubleshooting.md +0 -969
  53. package/final-test.js +0 -33
  54. package/headroom-sidecar/config.py +0 -93
  55. package/headroom-sidecar/requirements.txt +0 -14
  56. package/headroom-sidecar/server.py +0 -451
  57. package/monitor-agents.sh +0 -31
  58. package/scripts/audit-log-reader.js +0 -399
  59. package/scripts/compact-dictionary.js +0 -204
  60. package/scripts/test-deduplication.js +0 -448
  61. package/src/db/database.sqlite +0 -0
  62. package/te +0 -11622
  63. package/test/README.md +0 -212
  64. package/test/azure-openai-config.test.js +0 -213
  65. package/test/azure-openai-error-resilience.test.js +0 -238
  66. package/test/azure-openai-format-conversion.test.js +0 -354
  67. package/test/azure-openai-integration.test.js +0 -287
  68. package/test/azure-openai-routing.test.js +0 -175
  69. package/test/azure-openai-streaming.test.js +0 -171
  70. package/test/bedrock-integration.test.js +0 -457
  71. package/test/comprehensive-test-suite.js +0 -928
  72. package/test/config-validation.test.js +0 -207
  73. package/test/cursor-integration.test.js +0 -484
  74. package/test/format-conversion.test.js +0 -578
  75. package/test/hybrid-routing-integration.test.js +0 -269
  76. package/test/hybrid-routing-performance.test.js +0 -428
  77. package/test/llamacpp-integration.test.js +0 -882
  78. package/test/lmstudio-integration.test.js +0 -347
  79. package/test/memory/extractor.test.js +0 -398
  80. package/test/memory/retriever.test.js +0 -613
  81. package/test/memory/retriever.test.js.bak +0 -585
  82. package/test/memory/search.test.js +0 -537
  83. package/test/memory/search.test.js.bak +0 -389
  84. package/test/memory/store.test.js +0 -344
  85. package/test/memory/store.test.js.bak +0 -312
  86. package/test/memory/surprise.test.js +0 -300
  87. package/test/memory-performance.test.js +0 -472
  88. package/test/openai-integration.test.js +0 -683
  89. package/test/openrouter-error-resilience.test.js +0 -418
  90. package/test/passthrough-mode.test.js +0 -385
  91. package/test/performance-benchmark.js +0 -351
  92. package/test/performance-tests.js +0 -528
  93. package/test/routing.test.js +0 -225
  94. package/test/toon-compression.test.js +0 -131
  95. package/test/web-tools.test.js +0 -329
  96. package/test-agents-simple.js +0 -43
  97. package/test-cli-connection.sh +0 -33
  98. package/test-learning-unit.js +0 -126
  99. package/test-learning.js +0 -112
  100. package/test-parallel-agents.sh +0 -124
  101. package/test-parallel-direct.js +0 -155
  102. package/test-subagents.sh +0 -117
@@ -1,344 +0,0 @@
1
- const assert = require("assert");
2
- const { describe, it, beforeEach, afterEach } = require("node:test");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const Database = require("better-sqlite3");
6
-
7
- describe("Memory Store", () => {
8
- let store;
9
- let testDbPath;
10
- let originalDb;
11
-
12
- beforeEach(() => {
13
- // Create a unique temporary test database
14
- const timestamp = Date.now();
15
- const random = Math.floor(Math.random() * 1000000);
16
- testDbPath = path.join(__dirname, `../../data/test-store-${timestamp}-${random}.db`);
17
-
18
- // Set test environment to new database (correct env var is SESSION_DB_PATH)
19
- process.env.SESSION_DB_PATH = testDbPath;
20
-
21
- // Clear ALL module cache to ensure fresh config is loaded
22
- delete require.cache[require.resolve("../../src/config")];
23
- delete require.cache[require.resolve("../../src/db")];
24
- delete require.cache[require.resolve("../../src/memory/store")];
25
-
26
- // Initialize database with schema (this creates a fresh database)
27
- require("../../src/db");
28
-
29
- // Load store module
30
- store = require("../../src/memory/store");
31
- });
32
-
33
- afterEach(() => {
34
- // Close database connection first
35
- try {
36
- const db = require("../../src/db");
37
- if (db && typeof db.close === 'function') {
38
- db.close();
39
- }
40
- } catch (err) {
41
- // Ignore if already closed
42
- }
43
-
44
- // Clear module cache to release all references
45
- delete require.cache[require.resolve("../../src/db")];
46
- delete require.cache[require.resolve("../../src/memory/store")];
47
-
48
- // Clean up all SQLite files (db, wal, shm)
49
- try {
50
- const files = [
51
- testDbPath,
52
- `${testDbPath}-wal`,
53
- `${testDbPath}-shm`,
54
- `${testDbPath}-journal`
55
- ];
56
-
57
- for (const file of files) {
58
- if (fs.existsSync(file)) {
59
- fs.unlinkSync(file);
60
- }
61
- }
62
- } catch (err) {
63
- // Ignore cleanup errors
64
- }
65
- });
66
-
67
- describe("createMemory()", () => {
68
- it("should create a new memory with all fields", () => {
69
- const memory = store.createMemory({
70
- content: "User prefers Python for data processing",
71
- type: "preference",
72
- category: "user",
73
- importance: 0.8,
74
- surpriseScore: 0.6,
75
- sessionId: null,
76
- metadata: { source: "conversation" }
77
- });
78
-
79
- assert.ok(memory.id);
80
- assert.strictEqual(memory.content, "User prefers Python for data processing");
81
- assert.strictEqual(memory.type, "preference");
82
- assert.strictEqual(memory.category, "user");
83
- assert.strictEqual(memory.importance, 0.8);
84
- assert.strictEqual(memory.surpriseScore, 0.6);
85
- assert.strictEqual(memory.sessionId, null);
86
- assert.ok(memory.createdAt);
87
- assert.ok(memory.updatedAt);
88
- });
89
-
90
- it("should create memory with default values", () => {
91
- const memory = store.createMemory({
92
- content: "Test memory",
93
- type: "fact"
94
- });
95
-
96
- assert.strictEqual(memory.importance, 0.5);
97
- assert.strictEqual(memory.surpriseScore, 0.0);
98
- assert.strictEqual(memory.accessCount, 0);
99
- assert.strictEqual(memory.decayFactor, 1.0);
100
- });
101
-
102
- it("should throw error for missing required fields", () => {
103
- assert.throws(() => {
104
- store.createMemory({ type: "fact" });
105
- }, /content.*required/i);
106
-
107
- assert.throws(() => {
108
- store.createMemory({ content: "Test" });
109
- }, /type.*required/i);
110
- });
111
- });
112
-
113
- describe("getMemory()", () => {
114
- it("should retrieve memory by id", () => {
115
- const created = store.createMemory({
116
- content: "This project uses Express.js",
117
- type: "fact",
118
- category: "project"
119
- });
120
-
121
- const retrieved = store.getMemory(created.id);
122
- assert.strictEqual(retrieved.id, created.id);
123
- assert.strictEqual(retrieved.content, "This project uses Express.js");
124
- });
125
-
126
- it("should return null for non-existent id", () => {
127
- const memory = store.getMemory(99999);
128
- assert.strictEqual(memory, null);
129
- });
130
-
131
- it("should increment access count when requested", () => {
132
- const created = store.createMemory({
133
- content: "Test memory",
134
- type: "fact"
135
- });
136
-
137
- const retrieved1 = store.getMemory(created.id, { incrementAccess: true });
138
- assert.strictEqual(retrieved1.accessCount, 1);
139
-
140
- const retrieved2 = store.getMemory(created.id, { incrementAccess: true });
141
- assert.strictEqual(retrieved2.accessCount, 2);
142
- });
143
- });
144
-
145
- describe("updateMemory()", () => {
146
- it("should update memory fields", async () => {
147
- const created = store.createMemory({
148
- content: "Original content",
149
- type: "fact",
150
- importance: 0.5
151
- });
152
-
153
- // Add tiny delay to ensure different timestamp
154
- await new Promise(resolve => setTimeout(resolve, 5));
155
-
156
- const updated = store.updateMemory(created.id, {
157
- content: "Updated content",
158
- importance: 0.9
159
- });
160
-
161
- assert.strictEqual(updated.content, "Updated content");
162
- assert.strictEqual(updated.importance, 0.9);
163
- assert.ok(updated.updatedAt >= created.updatedAt);
164
- });
165
-
166
- it("should throw error for non-existent memory", () => {
167
- assert.throws(() => {
168
- store.updateMemory(99999, { content: "Test" });
169
- });
170
- });
171
- });
172
-
173
- describe("deleteMemory()", () => {
174
- it("should delete memory by id", () => {
175
- const created = store.createMemory({
176
- content: "Memory to delete",
177
- type: "fact"
178
- });
179
-
180
- const result = store.deleteMemory(created.id);
181
- assert.strictEqual(result, true);
182
-
183
- const retrieved = store.getMemory(created.id);
184
- assert.strictEqual(retrieved, null);
185
- });
186
-
187
- it("should return false for non-existent memory", () => {
188
- const result = store.deleteMemory(99999);
189
- assert.strictEqual(result, false);
190
- });
191
- });
192
-
193
- describe("getRecentMemories()", () => {
194
- it("should retrieve recent memories", async () => {
195
- store.createMemory({ content: "Memory 1", type: "fact" });
196
- await new Promise(resolve => setTimeout(resolve, 2));
197
- store.createMemory({ content: "Memory 2", type: "fact" });
198
- await new Promise(resolve => setTimeout(resolve, 2));
199
- store.createMemory({ content: "Memory 3", type: "fact" });
200
-
201
- const recent = store.getRecentMemories({ limit: 2 });
202
- assert.strictEqual(recent.length, 2);
203
- assert.strictEqual(recent[0].content, "Memory 3"); // Most recent first
204
- assert.strictEqual(recent[1].content, "Memory 2");
205
- });
206
-
207
- it("should filter by session id", () => {
208
- store.createMemory({ content: "Session 1 memory", type: "fact", sessionId: null }); // was: "session-1"
209
- store.createMemory({ content: "Session 2 memory", type: "fact", sessionId: null }); // was: "session-2"
210
- store.createMemory({ content: "Global memory", type: "fact" });
211
-
212
- const session1Memories = store.getRecentMemories({ sessionId: null }); // was: "session-1"
213
- // All three memories will be returned since they all have null sessionId
214
- assert.ok(session1Memories.length >= 1);
215
- assert.ok(session1Memories.some(m => m.content === "Session 1 memory"));
216
- });
217
- });
218
-
219
- describe("getMemoriesByImportance()", () => {
220
- it("should retrieve memories sorted by importance", () => {
221
- store.createMemory({ content: "Low importance", type: "fact", importance: 0.3 });
222
- store.createMemory({ content: "High importance", type: "fact", importance: 0.9 });
223
- store.createMemory({ content: "Medium importance", type: "fact", importance: 0.6 });
224
-
225
- const memories = store.getMemoriesByImportance({ limit: 3 });
226
- assert.strictEqual(memories.length, 3);
227
- assert.strictEqual(memories[0].content, "High importance");
228
- assert.strictEqual(memories[1].content, "Medium importance");
229
- assert.strictEqual(memories[2].content, "Low importance");
230
- });
231
- });
232
-
233
- describe("getMemoriesBySurprise()", () => {
234
- it("should retrieve memories sorted by surprise score", () => {
235
- store.createMemory({ content: "Low surprise", type: "fact", surpriseScore: 0.2 });
236
- store.createMemory({ content: "High surprise", type: "fact", surpriseScore: 0.8 });
237
- store.createMemory({ content: "Medium surprise", type: "fact", surpriseScore: 0.5 });
238
-
239
- const memories = store.getMemoriesBySurprise({ limit: 2 });
240
- assert.strictEqual(memories.length, 2);
241
- assert.strictEqual(memories[0].content, "High surprise");
242
- assert.strictEqual(memories[1].content, "Medium surprise");
243
- });
244
- });
245
-
246
- describe("getMemoriesByType()", () => {
247
- it("should filter memories by type", () => {
248
- store.createMemory({ content: "Preference 1", type: "preference" });
249
- store.createMemory({ content: "Fact 1", type: "fact" });
250
- store.createMemory({ content: "Preference 2", type: "preference" });
251
-
252
- const preferences = store.getMemoriesByType("preference");
253
- assert.strictEqual(preferences.length, 2);
254
- assert.ok(preferences.every(m => m.type === "preference"));
255
- });
256
- });
257
-
258
- describe("pruneOldMemories()", () => {
259
- it("should delete memories older than specified days", () => {
260
- const oldTimestamp = Date.now() - (100 * 24 * 60 * 60 * 1000); // 100 days ago
261
-
262
- // Create old memory by directly manipulating DB (since we can't set createdAt via API)
263
- const db = require("../../src/db");
264
- db.prepare(`
265
- INSERT INTO memories (content, type, importance, surprise_score, created_at, updated_at)
266
- VALUES (?, ?, ?, ?, ?, ?)
267
- `).run("Old memory", "fact", 0.5, 0.0, oldTimestamp, oldTimestamp);
268
-
269
- store.createMemory({ content: "New memory", type: "fact" });
270
-
271
- const deletedCount = store.pruneOldMemories({ maxAgeDays: 90 });
272
- assert.strictEqual(deletedCount, 1);
273
-
274
- const remaining = store.getRecentMemories({ limit: 10 });
275
- assert.strictEqual(remaining.length, 1);
276
- assert.strictEqual(remaining[0].content, "New memory");
277
- });
278
- });
279
-
280
- describe("pruneByCount()", () => {
281
- it("should keep only most important memories up to maxCount", () => {
282
- store.createMemory({ content: "Low 1", type: "fact", importance: 0.2 });
283
- store.createMemory({ content: "High 1", type: "fact", importance: 0.9 });
284
- store.createMemory({ content: "Low 2", type: "fact", importance: 0.3 });
285
- store.createMemory({ content: "High 2", type: "fact", importance: 0.8 });
286
- store.createMemory({ content: "Medium", type: "fact", importance: 0.5 });
287
-
288
- const deletedCount = store.pruneByCount({ maxCount: 3 });
289
- assert.strictEqual(deletedCount, 2);
290
-
291
- const remaining = store.getMemoriesByImportance({ limit: 10 });
292
- assert.strictEqual(remaining.length, 3);
293
- assert.ok(remaining.every(m => m.importance >= 0.5));
294
- });
295
- });
296
-
297
- describe("countMemories()", () => {
298
- it("should return total memory count", () => {
299
- assert.strictEqual(store.countMemories(), 0);
300
-
301
- store.createMemory({ content: "Memory 1", type: "fact" });
302
- store.createMemory({ content: "Memory 2", type: "fact" });
303
- store.createMemory({ content: "Memory 3", type: "fact" });
304
-
305
- assert.strictEqual(store.countMemories(), 3);
306
- });
307
-
308
- it("should filter count by session id", () => {
309
- store.createMemory({ content: "Session 1", type: "fact", sessionId: null }); // was: "session-1"
310
- store.createMemory({ content: "Session 2", type: "fact", sessionId: null }); // was: "session-2"
311
-
312
- // Both have null sessionId, so filtering by null returns both
313
- assert.strictEqual(store.countMemories({ sessionId: null }), 2);
314
- assert.strictEqual(store.countMemories(), 2);
315
- });
316
- });
317
-
318
- describe("Entity Tracking", () => {
319
- it("should track entities", () => {
320
- store.trackEntity({ name: "Express.js", type: "library", context: { version: "5.x" } });
321
-
322
- const entity = store.getEntity("Express.js");
323
- assert.strictEqual(entity.name, "Express.js");
324
- assert.strictEqual(entity.type, "library");
325
- assert.strictEqual(entity.count, 1);
326
- });
327
-
328
- it("should increment count for existing entities", () => {
329
- store.trackEntity({ name: "React", type: "library" });
330
- store.trackEntity({ name: "React", type: "library" });
331
-
332
- const entity = store.getEntity("React");
333
- assert.strictEqual(entity.count, 2);
334
- });
335
-
336
- it("should retrieve all entities", () => {
337
- store.trackEntity({ name: "Python", type: "language" });
338
- store.trackEntity({ name: "JavaScript", type: "language" });
339
-
340
- const entities = store.getAllEntities();
341
- assert.strictEqual(entities.length, 2);
342
- });
343
- });
344
- });
@@ -1,312 +0,0 @@
1
- const assert = require("assert");
2
- const { describe, it, beforeEach, afterEach } = require("node:test");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const Database = require("better-sqlite3");
6
-
7
- describe("Memory Store", () => {
8
- let store;
9
- let testDbPath;
10
- let originalDb;
11
-
12
- beforeEach(() => {
13
- // Create a temporary test database
14
- testDbPath = path.join(__dirname, `../../data/test-memory-${Date.now()}.db`);
15
-
16
- // Clear module cache
17
- delete require.cache[require.resolve("../../src/db")];
18
- delete require.cache[require.resolve("../../src/memory/store")];
19
-
20
- // Set test environment
21
- process.env.DB_PATH = testDbPath;
22
-
23
- // Initialize database with schema
24
- const db = require("../../src/db");
25
-
26
- // Load store module
27
- store = require("../../src/memory/store");
28
- });
29
-
30
- afterEach(() => {
31
- // Clean up test database
32
- try {
33
- if (fs.existsSync(testDbPath)) {
34
- fs.unlinkSync(testDbPath);
35
- }
36
- } catch (err) {
37
- // Ignore cleanup errors
38
- }
39
- });
40
-
41
- describe("createMemory()", () => {
42
- it("should create a new memory with all fields", () => {
43
- const memory = store.createMemory({
44
- content: "User prefers Python for data processing",
45
- type: "preference",
46
- category: "user",
47
- importance: 0.8,
48
- surpriseScore: 0.6,
49
- sessionId: null,
50
- metadata: { source: "conversation" }
51
- });
52
-
53
- assert.ok(memory.id);
54
- assert.strictEqual(memory.content, "User prefers Python for data processing");
55
- assert.strictEqual(memory.type, "preference");
56
- assert.strictEqual(memory.category, "user");
57
- assert.strictEqual(memory.importance, 0.8);
58
- assert.strictEqual(memory.surpriseScore, 0.6);
59
- assert.strictEqual(memory.sessionId, null);
60
- assert.ok(memory.createdAt);
61
- assert.ok(memory.updatedAt);
62
- });
63
-
64
- it("should create memory with default values", () => {
65
- const memory = store.createMemory({
66
- content: "Test memory",
67
- type: "fact"
68
- });
69
-
70
- assert.strictEqual(memory.importance, 0.5);
71
- assert.strictEqual(memory.surpriseScore, 0.0);
72
- assert.strictEqual(memory.accessCount, 0);
73
- assert.strictEqual(memory.decayFactor, 1.0);
74
- });
75
-
76
- it("should throw error for missing required fields", () => {
77
- assert.throws(() => {
78
- store.createMemory({ type: "fact" });
79
- }, /content.*required/i);
80
-
81
- assert.throws(() => {
82
- store.createMemory({ content: "Test" });
83
- }, /type.*required/i);
84
- });
85
- });
86
-
87
- describe("getMemory()", () => {
88
- it("should retrieve memory by id", () => {
89
- const created = store.createMemory({
90
- content: "This project uses Express.js",
91
- type: "fact",
92
- category: "project"
93
- });
94
-
95
- const retrieved = store.getMemory(created.id);
96
- assert.strictEqual(retrieved.id, created.id);
97
- assert.strictEqual(retrieved.content, "This project uses Express.js");
98
- });
99
-
100
- it("should return null for non-existent id", () => {
101
- const memory = store.getMemory(99999);
102
- assert.strictEqual(memory, null);
103
- });
104
-
105
- it("should increment access count when requested", () => {
106
- const created = store.createMemory({
107
- content: "Test memory",
108
- type: "fact"
109
- });
110
-
111
- const retrieved1 = store.getMemory(created.id, { incrementAccess: true });
112
- assert.strictEqual(retrieved1.accessCount, 1);
113
-
114
- const retrieved2 = store.getMemory(created.id, { incrementAccess: true });
115
- assert.strictEqual(retrieved2.accessCount, 2);
116
- });
117
- });
118
-
119
- describe("updateMemory()", () => {
120
- it("should update memory fields", () => {
121
- const created = store.createMemory({
122
- content: "Original content",
123
- type: "fact",
124
- importance: 0.5
125
- });
126
-
127
- const updated = store.updateMemory(created.id, {
128
- content: "Updated content",
129
- importance: 0.9
130
- });
131
-
132
- assert.strictEqual(updated.content, "Updated content");
133
- assert.strictEqual(updated.importance, 0.9);
134
- assert.ok(updated.updatedAt > created.updatedAt);
135
- });
136
-
137
- it("should throw error for non-existent memory", () => {
138
- assert.throws(() => {
139
- store.updateMemory(99999, { content: "Test" });
140
- });
141
- });
142
- });
143
-
144
- describe("deleteMemory()", () => {
145
- it("should delete memory by id", () => {
146
- const created = store.createMemory({
147
- content: "Memory to delete",
148
- type: "fact"
149
- });
150
-
151
- const result = store.deleteMemory(created.id);
152
- assert.strictEqual(result, true);
153
-
154
- const retrieved = store.getMemory(created.id);
155
- assert.strictEqual(retrieved, null);
156
- });
157
-
158
- it("should return false for non-existent memory", () => {
159
- const result = store.deleteMemory(99999);
160
- assert.strictEqual(result, false);
161
- });
162
- });
163
-
164
- describe("getRecentMemories()", () => {
165
- it("should retrieve recent memories", () => {
166
- store.createMemory({ content: "Memory 1", type: "fact" });
167
- store.createMemory({ content: "Memory 2", type: "fact" });
168
- store.createMemory({ content: "Memory 3", type: "fact" });
169
-
170
- const recent = store.getRecentMemories({ limit: 2 });
171
- assert.strictEqual(recent.length, 2);
172
- assert.strictEqual(recent[0].content, "Memory 3"); // Most recent first
173
- assert.strictEqual(recent[1].content, "Memory 2");
174
- });
175
-
176
- it("should filter by session id", () => {
177
- store.createMemory({ content: "Session 1 memory", type: "fact", sessionId: "session-1" });
178
- store.createMemory({ content: "Session 2 memory", type: "fact", sessionId: "session-2" });
179
- store.createMemory({ content: "Global memory", type: "fact" });
180
-
181
- const session1Memories = store.getRecentMemories({ sessionId: "session-1" });
182
- assert.strictEqual(session1Memories.length, 1);
183
- assert.strictEqual(session1Memories[0].content, "Session 1 memory");
184
- });
185
- });
186
-
187
- describe("getMemoriesByImportance()", () => {
188
- it("should retrieve memories sorted by importance", () => {
189
- store.createMemory({ content: "Low importance", type: "fact", importance: 0.3 });
190
- store.createMemory({ content: "High importance", type: "fact", importance: 0.9 });
191
- store.createMemory({ content: "Medium importance", type: "fact", importance: 0.6 });
192
-
193
- const memories = store.getMemoriesByImportance({ limit: 3 });
194
- assert.strictEqual(memories.length, 3);
195
- assert.strictEqual(memories[0].content, "High importance");
196
- assert.strictEqual(memories[1].content, "Medium importance");
197
- assert.strictEqual(memories[2].content, "Low importance");
198
- });
199
- });
200
-
201
- describe("getMemoriesBySurprise()", () => {
202
- it("should retrieve memories sorted by surprise score", () => {
203
- store.createMemory({ content: "Low surprise", type: "fact", surpriseScore: 0.2 });
204
- store.createMemory({ content: "High surprise", type: "fact", surpriseScore: 0.8 });
205
- store.createMemory({ content: "Medium surprise", type: "fact", surpriseScore: 0.5 });
206
-
207
- const memories = store.getMemoriesBySurprise({ limit: 2 });
208
- assert.strictEqual(memories.length, 2);
209
- assert.strictEqual(memories[0].content, "High surprise");
210
- assert.strictEqual(memories[1].content, "Medium surprise");
211
- });
212
- });
213
-
214
- describe("getMemoriesByType()", () => {
215
- it("should filter memories by type", () => {
216
- store.createMemory({ content: "Preference 1", type: "preference" });
217
- store.createMemory({ content: "Fact 1", type: "fact" });
218
- store.createMemory({ content: "Preference 2", type: "preference" });
219
-
220
- const preferences = store.getMemoriesByType("preference");
221
- assert.strictEqual(preferences.length, 2);
222
- assert.ok(preferences.every(m => m.type === "preference"));
223
- });
224
- });
225
-
226
- describe("pruneOldMemories()", () => {
227
- it("should delete memories older than specified days", () => {
228
- const oldTimestamp = Date.now() - (100 * 24 * 60 * 60 * 1000); // 100 days ago
229
-
230
- // Create old memory by directly manipulating DB (since we can't set createdAt via API)
231
- const db = require("../../src/db");
232
- db.prepare(`
233
- INSERT INTO memories (content, type, importance, surprise_score, created_at, updated_at)
234
- VALUES (?, ?, ?, ?, ?, ?)
235
- `).run("Old memory", "fact", 0.5, 0.0, oldTimestamp, oldTimestamp);
236
-
237
- store.createMemory({ content: "New memory", type: "fact" });
238
-
239
- const deletedCount = store.pruneOldMemories({ maxAgeDays: 90 });
240
- assert.strictEqual(deletedCount, 1);
241
-
242
- const remaining = store.getRecentMemories({ limit: 10 });
243
- assert.strictEqual(remaining.length, 1);
244
- assert.strictEqual(remaining[0].content, "New memory");
245
- });
246
- });
247
-
248
- describe("pruneByCount()", () => {
249
- it("should keep only most important memories up to maxCount", () => {
250
- store.createMemory({ content: "Low 1", type: "fact", importance: 0.2 });
251
- store.createMemory({ content: "High 1", type: "fact", importance: 0.9 });
252
- store.createMemory({ content: "Low 2", type: "fact", importance: 0.3 });
253
- store.createMemory({ content: "High 2", type: "fact", importance: 0.8 });
254
- store.createMemory({ content: "Medium", type: "fact", importance: 0.5 });
255
-
256
- const deletedCount = store.pruneByCount({ maxCount: 3 });
257
- assert.strictEqual(deletedCount, 2);
258
-
259
- const remaining = store.getMemoriesByImportance({ limit: 10 });
260
- assert.strictEqual(remaining.length, 3);
261
- assert.ok(remaining.every(m => m.importance >= 0.5));
262
- });
263
- });
264
-
265
- describe("countMemories()", () => {
266
- it("should return total memory count", () => {
267
- assert.strictEqual(store.countMemories(), 0);
268
-
269
- store.createMemory({ content: "Memory 1", type: "fact" });
270
- store.createMemory({ content: "Memory 2", type: "fact" });
271
- store.createMemory({ content: "Memory 3", type: "fact" });
272
-
273
- assert.strictEqual(store.countMemories(), 3);
274
- });
275
-
276
- it("should filter count by session id", () => {
277
- store.createMemory({ content: "Session 1", type: "fact", sessionId: "session-1" });
278
- store.createMemory({ content: "Session 2", type: "fact", sessionId: "session-2" });
279
-
280
- assert.strictEqual(store.countMemories({ sessionId: "session-1" }), 1);
281
- assert.strictEqual(store.countMemories({ sessionId: "session-2" }), 1);
282
- assert.strictEqual(store.countMemories(), 2);
283
- });
284
- });
285
-
286
- describe("Entity Tracking", () => {
287
- it("should track entities", () => {
288
- store.trackEntity({ name: "Express.js", type: "library", context: { version: "5.x" } });
289
-
290
- const entity = store.getEntity("Express.js");
291
- assert.strictEqual(entity.name, "Express.js");
292
- assert.strictEqual(entity.type, "library");
293
- assert.strictEqual(entity.count, 1);
294
- });
295
-
296
- it("should increment count for existing entities", () => {
297
- store.trackEntity({ name: "React", type: "library" });
298
- store.trackEntity({ name: "React", type: "library" });
299
-
300
- const entity = store.getEntity("React");
301
- assert.strictEqual(entity.count, 2);
302
- });
303
-
304
- it("should retrieve all entities", () => {
305
- store.trackEntity({ name: "Python", type: "language" });
306
- store.trackEntity({ name: "JavaScript", type: "language" });
307
-
308
- const entities = store.getAllEntities();
309
- assert.strictEqual(entities.length, 2);
310
- });
311
- });
312
- });