lynkr 7.2.5 → 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 (124) hide show
  1. package/README.md +3 -3
  2. package/config/model-tiers.json +89 -0
  3. package/install.sh +6 -1
  4. package/package.json +4 -2
  5. package/scripts/setup.js +0 -1
  6. package/src/agents/executor.js +14 -6
  7. package/src/api/middleware/session.js +15 -2
  8. package/src/api/openai-router.js +162 -37
  9. package/src/api/providers-handler.js +15 -1
  10. package/src/api/router.js +107 -2
  11. package/src/budget/index.js +4 -3
  12. package/src/clients/databricks.js +431 -234
  13. package/src/clients/gpt-utils.js +181 -0
  14. package/src/clients/ollama-utils.js +66 -140
  15. package/src/clients/routing.js +0 -1
  16. package/src/clients/standard-tools.js +99 -3
  17. package/src/config/index.js +133 -35
  18. package/src/context/toon.js +173 -0
  19. package/src/logger/index.js +23 -0
  20. package/src/orchestrator/index.js +688 -213
  21. package/src/routing/agentic-detector.js +320 -0
  22. package/src/routing/complexity-analyzer.js +202 -2
  23. package/src/routing/cost-optimizer.js +305 -0
  24. package/src/routing/index.js +168 -159
  25. package/src/routing/model-tiers.js +365 -0
  26. package/src/server.js +4 -14
  27. package/src/sessions/cleanup.js +3 -3
  28. package/src/sessions/record.js +10 -1
  29. package/src/sessions/store.js +7 -2
  30. package/src/tools/agent-task.js +48 -1
  31. package/src/tools/index.js +19 -2
  32. package/src/tools/lazy-loader.js +7 -0
  33. package/src/tools/tinyfish.js +358 -0
  34. package/src/tools/truncate.js +1 -0
  35. package/.github/FUNDING.yml +0 -15
  36. package/.github/workflows/README.md +0 -215
  37. package/.github/workflows/ci.yml +0 -69
  38. package/.github/workflows/index.yml +0 -62
  39. package/.github/workflows/web-tools-tests.yml +0 -56
  40. package/CITATIONS.bib +0 -6
  41. package/CLAWROUTER_ROUTING_PLAN.md +0 -910
  42. package/DEPLOYMENT.md +0 -1001
  43. package/LYNKR-TUI-PLAN.md +0 -984
  44. package/PERFORMANCE-REPORT.md +0 -866
  45. package/PLAN-per-client-model-routing.md +0 -252
  46. package/ROUTER_COMPARISON.md +0 -173
  47. package/TIER_ROUTING_PLAN.md +0 -771
  48. package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
  49. package/docs/BingSiteAuth.xml +0 -4
  50. package/docs/docs-style.css +0 -478
  51. package/docs/docs.html +0 -197
  52. package/docs/google5be250e608e6da39.html +0 -1
  53. package/docs/index.html +0 -577
  54. package/docs/index.md +0 -577
  55. package/docs/robots.txt +0 -4
  56. package/docs/sitemap.xml +0 -44
  57. package/docs/style.css +0 -1223
  58. package/documentation/README.md +0 -100
  59. package/documentation/api.md +0 -806
  60. package/documentation/claude-code-cli.md +0 -672
  61. package/documentation/codex-cli.md +0 -397
  62. package/documentation/contributing.md +0 -571
  63. package/documentation/cursor-integration.md +0 -731
  64. package/documentation/docker.md +0 -867
  65. package/documentation/embeddings.md +0 -760
  66. package/documentation/faq.md +0 -659
  67. package/documentation/features.md +0 -396
  68. package/documentation/headroom.md +0 -519
  69. package/documentation/installation.md +0 -706
  70. package/documentation/memory-system.md +0 -476
  71. package/documentation/production.md +0 -601
  72. package/documentation/providers.md +0 -906
  73. package/documentation/testing.md +0 -629
  74. package/documentation/token-optimization.md +0 -323
  75. package/documentation/tools.md +0 -697
  76. package/documentation/troubleshooting.md +0 -893
  77. package/final-test.js +0 -33
  78. package/headroom-sidecar/config.py +0 -93
  79. package/headroom-sidecar/requirements.txt +0 -14
  80. package/headroom-sidecar/server.py +0 -451
  81. package/monitor-agents.sh +0 -31
  82. package/scripts/audit-log-reader.js +0 -399
  83. package/scripts/compact-dictionary.js +0 -204
  84. package/scripts/test-deduplication.js +0 -448
  85. package/src/db/database.sqlite +0 -0
  86. package/test/README.md +0 -212
  87. package/test/azure-openai-config.test.js +0 -204
  88. package/test/azure-openai-error-resilience.test.js +0 -238
  89. package/test/azure-openai-format-conversion.test.js +0 -354
  90. package/test/azure-openai-integration.test.js +0 -281
  91. package/test/azure-openai-routing.test.js +0 -177
  92. package/test/azure-openai-streaming.test.js +0 -171
  93. package/test/bedrock-integration.test.js +0 -471
  94. package/test/comprehensive-test-suite.js +0 -928
  95. package/test/config-validation.test.js +0 -207
  96. package/test/cursor-integration.test.js +0 -484
  97. package/test/format-conversion.test.js +0 -578
  98. package/test/hybrid-routing-integration.test.js +0 -254
  99. package/test/hybrid-routing-performance.test.js +0 -418
  100. package/test/llamacpp-integration.test.js +0 -863
  101. package/test/lmstudio-integration.test.js +0 -335
  102. package/test/memory/extractor.test.js +0 -398
  103. package/test/memory/retriever.test.js +0 -613
  104. package/test/memory/retriever.test.js.bak +0 -585
  105. package/test/memory/search.test.js +0 -537
  106. package/test/memory/search.test.js.bak +0 -389
  107. package/test/memory/store.test.js +0 -344
  108. package/test/memory/store.test.js.bak +0 -312
  109. package/test/memory/surprise.test.js +0 -300
  110. package/test/memory-performance.test.js +0 -472
  111. package/test/openai-integration.test.js +0 -686
  112. package/test/openrouter-error-resilience.test.js +0 -418
  113. package/test/passthrough-mode.test.js +0 -385
  114. package/test/performance-benchmark.js +0 -351
  115. package/test/performance-tests.js +0 -528
  116. package/test/routing.test.js +0 -219
  117. package/test/web-tools.test.js +0 -329
  118. package/test-agents-simple.js +0 -43
  119. package/test-cli-connection.sh +0 -33
  120. package/test-learning-unit.js +0 -126
  121. package/test-learning.js +0 -112
  122. package/test-parallel-agents.sh +0 -124
  123. package/test-parallel-direct.js +0 -155
  124. package/test-subagents.sh +0 -117
@@ -1,398 +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
-
6
- describe("Memory Extractor", () => {
7
- let extractor;
8
- let testDbPath;
9
- let originalEnv;
10
-
11
- beforeEach(() => {
12
- // Save original environment
13
- originalEnv = { ...process.env };
14
-
15
- // Create a unique temporary test database
16
- const timestamp = Date.now();
17
- const random = Math.floor(Math.random() * 1000000);
18
- testDbPath = path.join(__dirname, `../../data/test-extractor-${timestamp}-${random}.db`);
19
-
20
- // Set test environment BEFORE loading any modules
21
- process.env.SESSION_DB_PATH = testDbPath;
22
- process.env.MEMORY_SURPRISE_THRESHOLD = "0.1"; // Very low threshold for tests
23
- process.env.MEMORY_ENABLED = "true";
24
- process.env.MEMORY_EXTRACTION_ENABLED = "true";
25
-
26
- // Clear ALL module cache to ensure fresh config
27
- Object.keys(require.cache).forEach(key => {
28
- if (key.includes('/src/')) {
29
- delete require.cache[key];
30
- }
31
- });
32
-
33
- // Initialize database first
34
- const db = require("../../src/db");
35
-
36
- // Create test sessions to satisfy foreign key constraints
37
- const now = Date.now();
38
- const insertSession = db.prepare(`
39
- INSERT OR IGNORE INTO sessions (id, created_at, updated_at, metadata)
40
- VALUES (?, ?, ?, ?)
41
- `);
42
- insertSession.run("test-session", now, now, "{}");
43
- insertSession.run("test-session-123", now, now, "{}");
44
- insertSession.run("test", now, now, "{}");
45
-
46
- // Then load extractor module
47
- extractor = require("../../src/memory/extractor");
48
- });
49
-
50
- afterEach(() => {
51
- // Close database connection first
52
- try {
53
- const db = require("../../src/db");
54
- if (db && typeof db.close === 'function') {
55
- db.close();
56
- }
57
- } catch (err) {
58
- // Ignore if already closed
59
- }
60
-
61
- // Clear module cache to release all references
62
- Object.keys(require.cache).forEach(key => {
63
- if (key.includes('/src/')) {
64
- delete require.cache[key];
65
- }
66
- });
67
-
68
- // Restore environment
69
- process.env = originalEnv;
70
-
71
- // Clean up all SQLite files (db, wal, shm)
72
- try {
73
- const files = [
74
- testDbPath,
75
- `${testDbPath}-wal`,
76
- `${testDbPath}-shm`,
77
- `${testDbPath}-journal`
78
- ];
79
-
80
- for (const file of files) {
81
- if (fs.existsSync(file)) {
82
- fs.unlinkSync(file);
83
- }
84
- }
85
- } catch (err) {
86
- // Ignore cleanup errors
87
- }
88
- });
89
-
90
- describe("extractMemories()", () => {
91
- it("should extract preferences from assistant response", async () => {
92
- const assistantResponse = {
93
- role: "assistant",
94
- content: "I understand that you prefer Python for data processing tasks and always use it for scripts."
95
- };
96
-
97
- const conversationMessages = [
98
- { role: "user", content: "I prefer Python for data processing" }
99
- ];
100
-
101
- const memories = await extractor.extractMemories(
102
- assistantResponse,
103
- conversationMessages,
104
- { sessionId: "test-session" }
105
- );
106
-
107
- assert.ok(Array.isArray(memories), "Should return array");
108
- const preferences = memories.filter(m => m.type === "preference");
109
- // With low threshold and novel content, should extract at least one
110
- assert.ok(preferences.length >= 0, "Should attempt extraction");
111
- });
112
-
113
- it("should extract decisions from assistant response", async () => {
114
- const assistantResponse = {
115
- role: "assistant",
116
- content: "We decided to use Express.js for the API framework and SQLite for the database storage system."
117
- };
118
-
119
- const conversationMessages = [
120
- { role: "user", content: "What should we use for the backend?" }
121
- ];
122
-
123
- const memories = await extractor.extractMemories(
124
- assistantResponse,
125
- conversationMessages,
126
- { sessionId: "test-session" }
127
- );
128
-
129
- assert.ok(Array.isArray(memories));
130
- const decisions = memories.filter(m => m.type === "decision");
131
- assert.ok(decisions.length >= 0);
132
- });
133
-
134
- it("should extract facts from assistant response", async () => {
135
- const assistantResponse = {
136
- role: "assistant",
137
- content: "This project uses TypeScript with strict mode enabled and implements ESLint for code quality."
138
- };
139
-
140
- const conversationMessages = [
141
- { role: "user", content: "Tell me about the project setup" }
142
- ];
143
-
144
- const memories = await extractor.extractMemories(
145
- assistantResponse,
146
- conversationMessages,
147
- { sessionId: "test-session" }
148
- );
149
-
150
- assert.ok(Array.isArray(memories));
151
- const facts = memories.filter(m => m.type === "fact");
152
- assert.ok(facts.length >= 0);
153
- });
154
-
155
- it("should include surprise scores in memories", async () => {
156
- const assistantResponse = {
157
- role: "assistant",
158
- content: "IMPORTANT: User always prefers async/await over callbacks in JavaScript code."
159
- };
160
-
161
- const memories = await extractor.extractMemories(
162
- assistantResponse,
163
- [],
164
- { sessionId: "test-session" }
165
- );
166
-
167
- if (memories.length > 0) {
168
- assert.ok(memories[0].surpriseScore >= 0 && memories[0].surpriseScore <= 1);
169
- assert.ok(memories[0].importance >= 0 && memories[0].importance <= 1);
170
- }
171
- });
172
-
173
- it("should include session context in stored memories", async () => {
174
- const assistantResponse = {
175
- role: "assistant",
176
- content: "I'll remember that you prefer async/await over callbacks for asynchronous operations."
177
- };
178
-
179
- const conversationMessages = [
180
- { role: "user", content: "Please use async/await" }
181
- ];
182
-
183
- const memories = await extractor.extractMemories(
184
- assistantResponse,
185
- conversationMessages,
186
- { sessionId: "test-session-123" }
187
- );
188
-
189
- if (memories.length > 0) {
190
- assert.strictEqual(memories[0].sessionId, "test-session-123");
191
- }
192
- });
193
-
194
- it("should handle empty assistant response", async () => {
195
- const assistantResponse = {
196
- role: "assistant",
197
- content: ""
198
- };
199
-
200
- const memories = await extractor.extractMemories(
201
- assistantResponse,
202
- [],
203
- { sessionId: "test-session" }
204
- );
205
-
206
- assert.strictEqual(memories.length, 0);
207
- });
208
-
209
- it("should handle responses with no extractable patterns", async () => {
210
- const assistantResponse = {
211
- role: "assistant",
212
- content: "Okay."
213
- };
214
-
215
- const memories = await extractor.extractMemories(
216
- assistantResponse,
217
- [],
218
- { sessionId: "test-session" }
219
- );
220
-
221
- assert.strictEqual(memories.length, 0);
222
- });
223
- });
224
-
225
- describe("Pattern Extraction (Internal)", () => {
226
- it("should match preference patterns", async () => {
227
- const responses = [
228
- "You always use TypeScript for new projects.",
229
- "User prefers functional programming over object-oriented design patterns.",
230
- "You typically want detailed error messages in production environments."
231
- ];
232
-
233
- for (const content of responses) {
234
- const memories = await extractor.extractMemories(
235
- { role: "assistant", content },
236
- [],
237
- { sessionId: "test" }
238
- );
239
- // Should at least try to extract (may be filtered by surprise)
240
- assert.ok(Array.isArray(memories));
241
- }
242
- });
243
-
244
- it("should match decision patterns", async () => {
245
- const responses = [
246
- "We decided to implement rate limiting at the API gateway level for better security.",
247
- "Going with PostgreSQL over MySQL for better JSON support and performance.",
248
- "Selected React for the frontend framework based on team experience."
249
- ];
250
-
251
- for (const content of responses) {
252
- const memories = await extractor.extractMemories(
253
- { role: "assistant", content },
254
- [],
255
- { sessionId: "test" }
256
- );
257
- assert.ok(Array.isArray(memories));
258
- }
259
- });
260
-
261
- it("should match fact patterns", async () => {
262
- const responses = [
263
- "This application uses Redis for caching and RabbitMQ for message queuing.",
264
- "The project implements JWT authentication with RS256 signing algorithm.",
265
- "IMPORTANT: Always validate user input for SQL injection vulnerabilities."
266
- ];
267
-
268
- for (const content of responses) {
269
- const memories = await extractor.extractMemories(
270
- { role: "assistant", content },
271
- [],
272
- { sessionId: "test" }
273
- );
274
- assert.ok(Array.isArray(memories));
275
- }
276
- });
277
- });
278
-
279
- describe("Edge Cases", () => {
280
- it("should handle very long assistant responses", async () => {
281
- const longContent = "The system architecture uses " + "microservices ".repeat(100);
282
- const assistantResponse = {
283
- role: "assistant",
284
- content: longContent
285
- };
286
-
287
- const memories = await extractor.extractMemories(
288
- assistantResponse,
289
- [],
290
- { sessionId: "test-session" }
291
- );
292
-
293
- assert.ok(Array.isArray(memories));
294
- });
295
-
296
- it("should handle special characters and code blocks", async () => {
297
- const assistantResponse = {
298
- role: "assistant",
299
- content: "This project uses @nestjs/core ^9.0.0 and implements JWT authentication with tokens."
300
- };
301
-
302
- const memories = await extractor.extractMemories(
303
- assistantResponse,
304
- [],
305
- { sessionId: "test-session" }
306
- );
307
-
308
- assert.ok(Array.isArray(memories));
309
- });
310
-
311
- it("should handle mixed content types", async () => {
312
- const assistantResponse = {
313
- role: "assistant",
314
- content: `
315
- I understand your requirements for the new authentication system.
316
- You prefer Python for this project and want to use FastAPI.
317
- We decided to use FastAPI for the backend framework with async support.
318
- The application uses PostgreSQL for the database with connection pooling.
319
- The UserModel class handles data validation and serialization.
320
- `
321
- };
322
-
323
- const memories = await extractor.extractMemories(
324
- assistantResponse,
325
- [],
326
- { sessionId: "test-session" }
327
- );
328
-
329
- assert.ok(Array.isArray(memories));
330
- // May extract multiple types
331
- if (memories.length > 0) {
332
- const types = new Set(memories.map(m => m.type));
333
- assert.ok(types.size >= 1);
334
- }
335
- });
336
-
337
- it("should not throw on malformed input", async () => {
338
- await assert.doesNotReject(async () => {
339
- await extractor.extractMemories(null, []);
340
- await extractor.extractMemories({}, []);
341
- await extractor.extractMemories({ content: null }, []);
342
- });
343
- });
344
- });
345
-
346
- describe("Surprise-Based Filtering", () => {
347
- it("should filter memories below surprise threshold", async () => {
348
- const store = require("../../src/memory/store");
349
-
350
- // Create existing memory
351
- store.createMemory({
352
- content: "User prefers Python programming",
353
- type: "preference",
354
- importance: 0.8
355
- });
356
-
357
- // Try to extract very similar memory
358
- const assistantResponse = {
359
- role: "assistant",
360
- content: "You prefer Python for programming tasks."
361
- };
362
-
363
- const memories = await extractor.extractMemories(
364
- assistantResponse,
365
- [],
366
- { sessionId: "test-session" }
367
- );
368
-
369
- // Should be filtered due to similarity (low surprise)
370
- const pythonPrefs = memories.filter(m =>
371
- m.type === "preference" && m.content.toLowerCase().includes("python")
372
- );
373
-
374
- // Either filtered out entirely, or has low surprise score
375
- if (pythonPrefs.length > 0) {
376
- assert.ok(pythonPrefs[0].surpriseScore <= 0.5);
377
- }
378
- });
379
-
380
- it("should store novel high-surprise memories", async () => {
381
- const assistantResponse = {
382
- role: "assistant",
383
- content: "CRITICAL: User always wants to use Rust for systems programming with zero-cost abstractions."
384
- };
385
-
386
- const memories = await extractor.extractMemories(
387
- assistantResponse,
388
- [{ role: "user", content: "IMPORTANT: Use Rust!" }],
389
- { sessionId: "test-session" }
390
- );
391
-
392
- // Novel content with emphasis should have higher surprise
393
- if (memories.length > 0) {
394
- assert.ok(memories[0].surpriseScore >= 0.1);
395
- }
396
- });
397
- });
398
- });