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,396 +0,0 @@
1
- # Core Features & Architecture
2
-
3
- Complete guide to Lynkr's architecture, request flow, and core capabilities.
4
-
5
- ---
6
-
7
- ## Architecture Overview
8
-
9
- ```
10
- ┌─────────────────┐
11
- │ Claude Code CLI │ or Cursor IDE
12
- └────────┬────────┘
13
- │ Anthropic/OpenAI Format
14
-
15
- ┌─────────────────┐
16
- │ Lynkr Proxy │
17
- │ Port: 8081 │
18
- │ │
19
- │ • Format Conv. │
20
- │ • Token Optim. │
21
- │ • Provider Route│
22
- │ • Tool Calling │
23
- │ • Caching │
24
- └────────┬────────┘
25
-
26
- ├──→ Databricks (Claude 4.5)
27
- ├──→ AWS Bedrock (100+ models)
28
- ├──→ OpenRouter (100+ models)
29
- ├──→ Ollama (local, free)
30
- ├──→ llama.cpp (local, free)
31
- ├──→ Azure OpenAI (GPT-4o, o1)
32
- ├──→ OpenAI (GPT-4o, o3)
33
- └──→ Azure Anthropic (Claude)
34
- ```
35
-
36
- ---
37
-
38
- ## Request Flow
39
-
40
- ### 1. Request Reception
41
-
42
- **Entry Points:**
43
- - `/v1/messages` - Anthropic format (Claude Code CLI)
44
- - `/v1/chat/completions` - OpenAI format (Cursor IDE)
45
-
46
- **Middleware Stack:**
47
- 1. Load shedding (reject if overloaded)
48
- 2. Request logging (with correlation ID)
49
- 3. Validation (schema check)
50
- 4. Metrics collection
51
- 5. Route to orchestrator
52
-
53
- ### 2. Provider Routing
54
-
55
- **Smart Routing Logic:**
56
-
57
- ```javascript
58
- if (PREFER_OLLAMA && toolCount <= OLLAMA_MAX_TOOLS_FOR_ROUTING) {
59
- provider = "ollama"; // Local, fast, free
60
- } else if (toolCount <= OPENROUTER_MAX_TOOLS_FOR_ROUTING) {
61
- provider = "openrouter"; // Cloud, moderate complexity
62
- } else {
63
- provider = fallbackProvider; // Databricks/Azure, complex
64
- }
65
- ```
66
-
67
- **Automatic Fallback:**
68
- - If primary provider fails → Use FALLBACK_PROVIDER
69
- - Transparent to client
70
- - No request failures due to provider issues
71
-
72
- ### 3. Format Conversion
73
-
74
- **Anthropic → Provider:**
75
- ```javascript
76
- {
77
- model: "claude-3-5-sonnet",
78
- messages: [...],
79
- tools: [...]
80
- }
81
-
82
- Provider-specific format
83
- (Databricks, Bedrock, OpenRouter, etc.)
84
- ```
85
-
86
- **Provider → Anthropic:**
87
- ```javascript
88
- Provider response
89
-
90
- {
91
- id: "msg_...",
92
- type: "message",
93
- role: "assistant",
94
- content: [{type: "text", text: "..."}],
95
- usage: {input_tokens: 123, output_tokens: 456}
96
- }
97
- ```
98
-
99
- ### 4. Token Optimization
100
-
101
- **6 Phases Applied:**
102
- 1. Smart tool selection
103
- 2. Prompt caching
104
- 3. Memory deduplication
105
- 4. Tool response truncation
106
- 5. Dynamic system prompts
107
- 6. Conversation compression
108
-
109
- **Result:** 60-80% token reduction
110
-
111
- ### 5. Tool Execution
112
-
113
- **Server Mode (default):**
114
- - Tools execute on Lynkr server
115
- - Access server filesystem
116
- - Server-side command execution
117
-
118
- **Client Mode (passthrough):**
119
- - Tools execute on CLI side
120
- - Access client filesystem
121
- - Client-side command execution
122
-
123
- ### 6. Response Streaming
124
-
125
- **Token-by-Token Streaming:**
126
- ```javascript
127
- // SSE format
128
- event: message
129
- data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Hello"}}
130
-
131
- event: message
132
- data: {"type":"content_block_delta","delta":{"type":"text_delta","text":" world"}}
133
-
134
- event: done
135
- data: {}
136
- ```
137
-
138
- **Benefits:**
139
- - Real-time user feedback
140
- - Lower perceived latency
141
- - Better UX for long responses
142
-
143
- ---
144
-
145
- ## Core Components
146
-
147
- ### API Layer (`src/api/`)
148
-
149
- **router.js** - Main routes
150
- - `/v1/messages` - Anthropic format
151
- - `/v1/chat/completions` - OpenAI format
152
- - `/v1/models` - List models
153
- - `/v1/embeddings` - Generate embeddings
154
- - `/health/*` - Health checks
155
- - `/metrics` - Prometheus metrics
156
-
157
- **Middleware:**
158
- - `load-shedding.js` - Overload protection
159
- - `request-logging.js` - Structured logging
160
- - `metrics.js` - Metrics collection
161
- - `validation.js` - Input validation
162
- - `error-handling.js` - Error formatting
163
-
164
- ### Provider Clients (`src/clients/`)
165
-
166
- **databricks.js** - Main invocation function
167
- - `invokeModel()` - Route to provider
168
- - `invokeDatabricks()` - Databricks API
169
- - `invokeAzureAnthropic()` - Azure Anthropic
170
- - `invokeOpenRouter()` - OpenRouter
171
- - `invokeOllama()` - Ollama local
172
- - `invokeLlamaCpp()` - llama.cpp
173
- - `invokeBedrock()` - AWS Bedrock
174
-
175
- **Format converters:**
176
- - `openrouter-utils.js` - OpenAI format conversion
177
- - `bedrock-utils.js` - Bedrock format conversion
178
-
179
- **Reliability:**
180
- - `circuit-breaker.js` - Circuit breaker pattern
181
- - `retry.js` - Exponential backoff with jitter
182
-
183
- ### Orchestrator (`src/orchestrator/`)
184
-
185
- **Agent Loop:**
186
- 1. Receive request
187
- 2. Inject memories
188
- 3. Call provider
189
- 4. Execute tools (if requested)
190
- 5. Return to provider
191
- 6. Repeat until done (max 8 steps)
192
- 7. Extract memories
193
- 8. Return final response
194
-
195
- **Features:**
196
- - Tool execution modes (server/client)
197
- - Policy enforcement
198
- - Memory injection/extraction
199
- - Token optimization
200
-
201
- ### Tools (`src/tools/`)
202
-
203
- **Standard Tools:**
204
- - `workspace.js` - Read, Write, Edit files
205
- - `git.js` - Git operations
206
- - `bash.js` - Shell command execution
207
- - `test.js` - Test harness
208
- - `task.js` - Task tracking
209
- - `memory.js` - Memory management
210
-
211
- **MCP Tools:**
212
- - Dynamic tool registration
213
- - JSON-RPC 2.0 communication
214
- - Sandbox isolation (optional)
215
-
216
- ### Caching (`src/cache/`)
217
-
218
- **Prompt Cache:**
219
- - LRU cache with TTL
220
- - SHA-256 keying
221
- - Hit rate tracking
222
-
223
- **Memory Cache:**
224
- - In-memory storage
225
- - TTL-based eviction
226
- - Automatic cleanup
227
-
228
- ### Database (`src/db/`)
229
-
230
- **SQLite Databases:**
231
- - `memories.db` - Long-term memories
232
- - `sessions.db` - Conversation history
233
- - `workspace-index.db` - Workspace metadata
234
-
235
- **Operations:**
236
- - Memory CRUD
237
- - Session tracking
238
- - FTS5 search
239
-
240
- ### Observability (`src/observability/`)
241
-
242
- **Metrics:**
243
- - Request rate, latency, errors
244
- - Token usage, cache hits
245
- - Circuit breaker state
246
- - System resources
247
-
248
- **Logging:**
249
- - Structured JSON logs (pino)
250
- - Request ID correlation
251
- - Error tracking
252
- - Performance profiling
253
-
254
- ### Configuration (`src/config/`)
255
-
256
- **Environment Variables:**
257
- - Provider configuration
258
- - Feature flags
259
- - Policy settings
260
- - Performance tuning
261
-
262
- **Validation:**
263
- - Required field checks
264
- - Type validation
265
- - Value constraints
266
- - Provider-specific validation
267
-
268
- ---
269
-
270
- ## Key Features
271
-
272
- ### 1. Multi-Provider Support
273
-
274
- **9+ Providers:**
275
- - Cloud: Databricks, Bedrock, OpenRouter, Azure, OpenAI
276
- - Local: Ollama, llama.cpp, LM Studio
277
-
278
- **Hybrid Routing:**
279
- - Automatic provider selection
280
- - Transparent failover
281
- - Cost optimization
282
-
283
- ### 2. Token Optimization
284
-
285
- **60-80% Cost Reduction:**
286
- - 6 optimization phases
287
- - $77k-$115k annual savings
288
- - Automatic optimization
289
-
290
- ### 3. Long-Term Memory
291
-
292
- **Titans-Inspired:**
293
- - Surprise-based storage
294
- - Semantic search (FTS5)
295
- - Multi-signal retrieval
296
- - Automatic extraction
297
-
298
- ### 4. Production Hardening
299
-
300
- **14 Features:**
301
- - Circuit breakers
302
- - Load shedding
303
- - Graceful shutdown
304
- - Prometheus metrics
305
- - Health checks
306
- - Error resilience
307
-
308
- ### 5. MCP Integration
309
-
310
- **Model Context Protocol:**
311
- - Automatic discovery
312
- - JSON-RPC 2.0 client
313
- - Dynamic tool registration
314
- - Sandbox isolation
315
-
316
- ### 6. IDE Compatibility
317
-
318
- **Works With:**
319
- - Claude Code CLI (native)
320
- - Cursor IDE (OpenAI format)
321
- - Continue.dev (OpenAI format)
322
- - Any OpenAI-compatible client
323
-
324
- ---
325
-
326
- ## Performance
327
-
328
- ### Benchmarks
329
-
330
- **Request Throughput:**
331
- - **140,000 requests/second** capacity
332
- - **~7μs overhead** per request
333
- - Minimal performance impact
334
-
335
- **Latency:**
336
- - Local providers: 100-500ms
337
- - Cloud providers: 500ms-2s
338
- - Caching: <1ms (cache hits)
339
-
340
- **Memory Usage:**
341
- - Base: ~100MB
342
- - Per connection: ~1MB
343
- - Caching: ~50MB
344
-
345
- **Token Optimization:**
346
- - Average reduction: 60-80%
347
- - Cache hit rate: 70-90%
348
- - Dedup effectiveness: 85%
349
-
350
- ---
351
-
352
- ## Scaling
353
-
354
- ### Horizontal Scaling
355
-
356
- ```bash
357
- # Run multiple instances
358
- PM2_INSTANCES=4 pm2 start lynkr
359
-
360
- # Behind load balancer (nginx, HAProxy)
361
- # Shared database for memories
362
- ```
363
-
364
- ### Vertical Scaling
365
-
366
- ```bash
367
- # Increase cache size
368
- PROMPT_CACHE_MAX_ENTRIES=256
369
-
370
- # Increase connection pool
371
- # (provider-specific)
372
- ```
373
-
374
- ### Database Optimization
375
-
376
- ```bash
377
- # Enable WAL mode (better concurrency)
378
- # Automatic vacuum
379
- # Index optimization
380
- ```
381
-
382
- ---
383
-
384
- ## Next Steps
385
-
386
- - **[Memory System](memory-system.md)** - Long-term memory details
387
- - **[Token Optimization](token-optimization.md)** - Cost reduction strategies
388
- - **[Production Guide](production.md)** - Deploy to production
389
- - **[Tools Guide](tools.md)** - Tool execution modes
390
-
391
- ---
392
-
393
- ## Getting Help
394
-
395
- - **[GitHub Discussions](https://github.com/vishalveerareddy123/Lynkr/discussions)** - Ask questions
396
- - **[GitHub Issues](https://github.com/vishalveerareddy123/Lynkr/issues)** - Report issues