lynkr 8.0.0 → 9.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 (128) hide show
  1. package/.lynkr/telemetry.db +0 -0
  2. package/.lynkr/telemetry.db-shm +0 -0
  3. package/.lynkr/telemetry.db-wal +0 -0
  4. package/README.md +196 -322
  5. package/lynkr-skill.tar.gz +0 -0
  6. package/package.json +4 -3
  7. package/src/api/openai-router.js +64 -13
  8. package/src/api/providers-handler.js +171 -3
  9. package/src/api/router.js +9 -2
  10. package/src/clients/circuit-breaker.js +10 -247
  11. package/src/clients/codex-process.js +342 -0
  12. package/src/clients/codex-utils.js +143 -0
  13. package/src/clients/databricks.js +210 -63
  14. package/src/clients/resilience.js +540 -0
  15. package/src/clients/retry.js +22 -167
  16. package/src/clients/standard-tools.js +23 -0
  17. package/src/config/index.js +77 -0
  18. package/src/context/compression.js +42 -9
  19. package/src/context/distill.js +492 -0
  20. package/src/orchestrator/index.js +48 -8
  21. package/src/routing/complexity-analyzer.js +258 -5
  22. package/src/routing/index.js +12 -2
  23. package/src/routing/latency-tracker.js +148 -0
  24. package/src/routing/model-tiers.js +2 -0
  25. package/src/routing/quality-scorer.js +113 -0
  26. package/src/routing/telemetry.js +464 -0
  27. package/src/server.js +13 -12
  28. package/src/tools/code-graph.js +538 -0
  29. package/src/tools/code-mode.js +304 -0
  30. package/src/tools/index.js +4 -0
  31. package/src/tools/lazy-loader.js +18 -0
  32. package/src/tools/mcp-remote.js +7 -0
  33. package/src/tools/smart-selection.js +11 -0
  34. package/src/tools/tinyfish.js +358 -0
  35. package/src/tools/truncate.js +1 -0
  36. package/src/utils/payload.js +206 -0
  37. package/src/utils/perf-timer.js +80 -0
  38. package/.github/FUNDING.yml +0 -15
  39. package/.github/workflows/README.md +0 -215
  40. package/.github/workflows/ci.yml +0 -69
  41. package/.github/workflows/index.yml +0 -62
  42. package/.github/workflows/web-tools-tests.yml +0 -56
  43. package/CITATIONS.bib +0 -6
  44. package/DEPLOYMENT.md +0 -1001
  45. package/LYNKR-TUI-PLAN.md +0 -984
  46. package/PERFORMANCE-REPORT.md +0 -866
  47. package/PLAN-per-client-model-routing.md +0 -252
  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 -198
  52. package/docs/google5be250e608e6da39.html +0 -1
  53. package/docs/index.html +0 -577
  54. package/docs/index.md +0 -584
  55. package/docs/robots.txt +0 -4
  56. package/docs/sitemap.xml +0 -44
  57. package/docs/style.css +0 -1223
  58. package/docs/toon-integration-spec.md +0 -130
  59. package/documentation/README.md +0 -101
  60. package/documentation/api.md +0 -806
  61. package/documentation/claude-code-cli.md +0 -679
  62. package/documentation/codex-cli.md +0 -397
  63. package/documentation/contributing.md +0 -571
  64. package/documentation/cursor-integration.md +0 -734
  65. package/documentation/docker.md +0 -874
  66. package/documentation/embeddings.md +0 -762
  67. package/documentation/faq.md +0 -713
  68. package/documentation/features.md +0 -403
  69. package/documentation/headroom.md +0 -519
  70. package/documentation/installation.md +0 -758
  71. package/documentation/memory-system.md +0 -476
  72. package/documentation/production.md +0 -636
  73. package/documentation/providers.md +0 -1009
  74. package/documentation/routing.md +0 -476
  75. package/documentation/testing.md +0 -629
  76. package/documentation/token-optimization.md +0 -325
  77. package/documentation/tools.md +0 -697
  78. package/documentation/troubleshooting.md +0 -969
  79. package/final-test.js +0 -33
  80. package/headroom-sidecar/config.py +0 -93
  81. package/headroom-sidecar/requirements.txt +0 -14
  82. package/headroom-sidecar/server.py +0 -451
  83. package/monitor-agents.sh +0 -31
  84. package/scripts/audit-log-reader.js +0 -399
  85. package/scripts/compact-dictionary.js +0 -204
  86. package/scripts/test-deduplication.js +0 -448
  87. package/src/db/database.sqlite +0 -0
  88. package/te +0 -11622
  89. package/test/README.md +0 -212
  90. package/test/azure-openai-config.test.js +0 -213
  91. package/test/azure-openai-error-resilience.test.js +0 -238
  92. package/test/azure-openai-format-conversion.test.js +0 -354
  93. package/test/azure-openai-integration.test.js +0 -287
  94. package/test/azure-openai-routing.test.js +0 -175
  95. package/test/azure-openai-streaming.test.js +0 -171
  96. package/test/bedrock-integration.test.js +0 -457
  97. package/test/comprehensive-test-suite.js +0 -928
  98. package/test/config-validation.test.js +0 -207
  99. package/test/cursor-integration.test.js +0 -484
  100. package/test/format-conversion.test.js +0 -578
  101. package/test/hybrid-routing-integration.test.js +0 -269
  102. package/test/hybrid-routing-performance.test.js +0 -428
  103. package/test/llamacpp-integration.test.js +0 -882
  104. package/test/lmstudio-integration.test.js +0 -347
  105. package/test/memory/extractor.test.js +0 -398
  106. package/test/memory/retriever.test.js +0 -613
  107. package/test/memory/retriever.test.js.bak +0 -585
  108. package/test/memory/search.test.js +0 -537
  109. package/test/memory/search.test.js.bak +0 -389
  110. package/test/memory/store.test.js +0 -344
  111. package/test/memory/store.test.js.bak +0 -312
  112. package/test/memory/surprise.test.js +0 -300
  113. package/test/memory-performance.test.js +0 -472
  114. package/test/openai-integration.test.js +0 -683
  115. package/test/openrouter-error-resilience.test.js +0 -418
  116. package/test/passthrough-mode.test.js +0 -385
  117. package/test/performance-benchmark.js +0 -351
  118. package/test/performance-tests.js +0 -528
  119. package/test/routing.test.js +0 -225
  120. package/test/toon-compression.test.js +0 -131
  121. package/test/web-tools.test.js +0 -329
  122. package/test-agents-simple.js +0 -43
  123. package/test-cli-connection.sh +0 -33
  124. package/test-learning-unit.js +0 -126
  125. package/test-learning.js +0 -112
  126. package/test-parallel-agents.sh +0 -124
  127. package/test-parallel-direct.js +0 -155
  128. 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