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