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,601 +0,0 @@
1
- # Production Hardening Guide
2
-
3
- Complete guide to deploying Lynkr in production with 14 hardening features for reliability, observability, and security.
4
-
5
- ---
6
-
7
- ## Overview
8
-
9
- Lynkr includes 14 production-ready features:
10
- - **Reliability:** Circuit breakers, retries, load shedding, graceful shutdown
11
- - **Observability:** Prometheus metrics, structured logging, health checks
12
- - **Security:** Input validation, policy enforcement, sandboxing
13
- - **Performance:** Minimal overhead (~7μs), 140K req/sec throughput
14
-
15
- ---
16
-
17
- ## Reliability Features
18
-
19
- ### 1. Circuit Breaker Pattern
20
-
21
- Protects against cascading failures to external services.
22
-
23
- **States:**
24
- - `CLOSED` - Normal operation
25
- - `OPEN` - Failing fast (provider down)
26
- - `HALF_OPEN` - Testing recovery
27
-
28
- **Configuration:**
29
- ```bash
30
- # Failures before opening circuit
31
- CIRCUIT_BREAKER_FAILURE_THRESHOLD=5 # default: 5
32
-
33
- # Successes needed to close from half-open
34
- CIRCUIT_BREAKER_SUCCESS_THRESHOLD=2 # default: 2
35
-
36
- # Time before attempting recovery (ms)
37
- CIRCUIT_BREAKER_TIMEOUT=60000 # default: 60000 (1 min)
38
- ```
39
-
40
- **How it works:**
41
- 1. 5 failures → Circuit OPEN
42
- 2. Wait 60 seconds
43
- 3. Try 1 request → Circuit HALF_OPEN
44
- 4. 2 successes → Circuit CLOSED
45
-
46
- ### 2. Exponential Backoff with Jitter
47
-
48
- Automatic retries for transient failures.
49
-
50
- **Configuration:**
51
- ```bash
52
- # Max retry attempts
53
- API_RETRY_MAX_RETRIES=3 # default: 3
54
-
55
- # Initial retry delay (ms)
56
- API_RETRY_INITIAL_DELAY=1000 # default: 1000
57
-
58
- # Maximum retry delay (ms)
59
- API_RETRY_MAX_DELAY=30000 # default: 30000
60
- ```
61
-
62
- **Retry schedule:**
63
- - Attempt 1: Immediate
64
- - Attempt 2: 1s + jitter (±500ms)
65
- - Attempt 3: 2s + jitter (±1s)
66
- - Attempt 4: 4s + jitter (±2s)
67
-
68
- **Retryable errors:**
69
- - 5xx status codes
70
- - Network timeouts
71
- - Connection errors
72
-
73
- **Non-retryable errors:**
74
- - 4xx status codes
75
- - Authentication errors
76
- - Validation errors
77
-
78
- ### 3. Load Shedding
79
-
80
- Proactive request rejection when system is overloaded.
81
-
82
- **Configuration:**
83
- ```bash
84
- # Memory usage threshold (0-1)
85
- LOAD_SHEDDING_MEMORY_THRESHOLD=0.85 # default: 0.85 (85%)
86
-
87
- # Heap usage threshold (0-1)
88
- LOAD_SHEDDING_HEAP_THRESHOLD=0.90 # default: 0.90 (90%)
89
-
90
- # Max concurrent requests
91
- LOAD_SHEDDING_ACTIVE_REQUESTS_THRESHOLD=1000 # default: 1000
92
- ```
93
-
94
- **Behavior:**
95
- - Returns HTTP 503 during overload
96
- - Includes `Retry-After` header
97
- - Cached state (1s) for performance
98
-
99
- **Monitoring:**
100
- ```bash
101
- curl http://localhost:8081/metrics | grep lynkr_load_shedding
102
- ```
103
-
104
- ### 4. Graceful Shutdown
105
-
106
- Zero-downtime deployments.
107
-
108
- **Configuration:**
109
- ```bash
110
- # Shutdown timeout (ms)
111
- GRACEFUL_SHUTDOWN_TIMEOUT=30000 # default: 30000 (30s)
112
- ```
113
-
114
- **Sequence:**
115
- 1. Receive SIGTERM/SIGINT
116
- 2. Stop accepting new requests
117
- 3. Complete in-flight requests (max 30s)
118
- 4. Close database connections
119
- 5. Exit
120
-
121
- **Kubernetes:**
122
- ```yaml
123
- spec:
124
- containers:
125
- - name: lynkr
126
- lifecycle:
127
- preStop:
128
- exec:
129
- command: ["/bin/sh", "-c", "sleep 5"]
130
- terminationGracePeriodSeconds: 35
131
- ```
132
-
133
- ---
134
-
135
- ## Observability
136
-
137
- ### 5. Prometheus Metrics
138
-
139
- Comprehensive metrics collection.
140
-
141
- **Endpoint:**
142
- ```bash
143
- curl http://localhost:8081/metrics
144
- ```
145
-
146
- **Request Metrics:**
147
- ```
148
- # Request rate
149
- lynkr_requests_total{provider="databricks",status="200"} 1234
150
-
151
- # Latency histogram
152
- lynkr_request_duration_seconds_bucket{provider="databricks",le="0.5"} 980
153
- lynkr_request_duration_seconds_bucket{provider="databricks",le="1"} 1200
154
- lynkr_request_duration_seconds_sum 1234.5
155
- lynkr_request_duration_seconds_count 1234
156
-
157
- # Error rate
158
- lynkr_errors_total{provider="databricks",type="timeout"} 12
159
- ```
160
-
161
- **Token Metrics:**
162
- ```
163
- # Token usage
164
- lynkr_tokens_input_total{provider="databricks"} 5000000
165
- lynkr_tokens_output_total{provider="databricks"} 500000
166
- lynkr_tokens_cached_total 2000000
167
-
168
- # Cache hits
169
- lynkr_cache_hits_total 850
170
- lynkr_cache_misses_total 150
171
- ```
172
-
173
- **System Metrics:**
174
- ```
175
- # Memory usage
176
- process_resident_memory_bytes 104857600
177
- nodejs_heap_size_used_bytes 52428800
178
-
179
- # Circuit breaker state
180
- lynkr_circuit_breaker_state{provider="databricks",state="closed"} 1
181
-
182
- # Active requests
183
- lynkr_active_requests 42
184
- ```
185
-
186
- **Configuration:**
187
- ```bash
188
- METRICS_ENABLED=true # default: true
189
- ```
190
-
191
- ### 6. Structured Logging
192
-
193
- JSON logs with request ID correlation.
194
-
195
- **Configuration:**
196
- ```bash
197
- LOG_LEVEL=info # options: error, warn, info, debug
198
- REQUEST_LOGGING_ENABLED=true # default: true
199
- ```
200
-
201
- **Log format:**
202
- ```json
203
- {
204
- "level": "info",
205
- "time": 1705123456789,
206
- "msg": "Request processed",
207
- "requestId": "req_abc123",
208
- "provider": "databricks",
209
- "statusCode": 200,
210
- "duration": 1250,
211
- "tokens": {
212
- "input": 1250,
213
- "output": 234,
214
- "cached": 750
215
- }
216
- }
217
- ```
218
-
219
- **Log aggregation:**
220
- - Stdout (captured by Docker/K8s)
221
- - Parse with structured log tools
222
- - Send to Elasticsearch, Splunk, etc.
223
-
224
- ### 7. Health Checks
225
-
226
- Kubernetes-ready health endpoints.
227
-
228
- **Liveness Probe:**
229
- ```bash
230
- curl http://localhost:8081/health/live
231
-
232
- # Returns:
233
- {
234
- "status": "ok",
235
- "provider": "databricks",
236
- "timestamp": "2026-01-12T00:00:00.000Z"
237
- }
238
- ```
239
-
240
- **Readiness Probe:**
241
- ```bash
242
- curl http://localhost:8081/health/ready
243
-
244
- # Returns:
245
- {
246
- "status": "ready",
247
- "checks": {
248
- "database": "ok",
249
- "provider": "ok"
250
- }
251
- }
252
- ```
253
-
254
- **Deep Health Check:**
255
- ```bash
256
- curl "http://localhost:8081/health/ready?deep=true"
257
-
258
- # Returns:
259
- {
260
- "status": "ready",
261
- "checks": {
262
- "database": "ok",
263
- "provider": "ok",
264
- "memory": {"used": "50%", "status": "ok"},
265
- "circuit_breaker": {"state": "closed", "status": "ok"}
266
- }
267
- }
268
- ```
269
-
270
- **Kubernetes:**
271
- ```yaml
272
- livenessProbe:
273
- httpGet:
274
- path: /health/live
275
- port: 8081
276
- initialDelaySeconds: 10
277
- periodSeconds: 10
278
-
279
- readinessProbe:
280
- httpGet:
281
- path: /health/ready
282
- port: 8081
283
- initialDelaySeconds: 5
284
- periodSeconds: 5
285
- ```
286
-
287
- **Configuration:**
288
- ```bash
289
- HEALTH_CHECK_ENABLED=true # default: true
290
- ```
291
-
292
- ---
293
-
294
- ## Security
295
-
296
- ### 8. Input Validation
297
-
298
- Zero-dependency schema validation.
299
-
300
- **Validates:**
301
- - Request body structure
302
- - Required fields
303
- - Field types
304
- - Value constraints
305
-
306
- **Example:**
307
- ```javascript
308
- // Invalid request
309
- {
310
- "model": 123, // Should be string
311
- "max_tokens": -1 // Should be positive
312
- }
313
-
314
- // Returns 400 Bad Request
315
- {
316
- "error": "Invalid request",
317
- "details": [
318
- "model must be string",
319
- "max_tokens must be positive"
320
- ]
321
- }
322
- ```
323
-
324
- ### 9. Policy Enforcement
325
-
326
- Environment-driven guardrails.
327
-
328
- **Git Policies:**
329
- ```bash
330
- # Allow git push (default: disabled)
331
- POLICY_GIT_ALLOW_PUSH=false
332
-
333
- # Require tests before commit (default: disabled)
334
- POLICY_GIT_REQUIRE_TESTS=false
335
-
336
- # Custom test command
337
- POLICY_GIT_TEST_COMMAND="npm test"
338
- ```
339
-
340
- **Web Fetch Policies:**
341
- ```bash
342
- # Allowed hosts for web_fetch tool
343
- WEB_SEARCH_ALLOWED_HOSTS=github.com,stackoverflow.com
344
-
345
- # Web search endpoint
346
- WEB_SEARCH_ENDPOINT=http://localhost:8888/search
347
- ```
348
-
349
- **Workspace Policies:**
350
- ```bash
351
- # Workspace root directory
352
- WORKSPACE_ROOT=/path/to/projects
353
-
354
- # Max agent loop iterations
355
- POLICY_MAX_STEPS=8
356
- ```
357
-
358
- ### 10. Sandboxing
359
-
360
- Optional Docker isolation for MCP tools.
361
-
362
- **Configuration:**
363
- ```bash
364
- # Enable MCP sandbox
365
- MCP_SANDBOX_ENABLED=true # default: true
366
-
367
- # Docker image for sandbox
368
- MCP_SANDBOX_IMAGE=ubuntu:22.04
369
- ```
370
-
371
- **How it works:**
372
- 1. MCP tool invoked
373
- 2. Launch Docker container
374
- 3. Execute tool in container
375
- 4. Return result
376
- 5. Destroy container
377
-
378
- **Benefits:**
379
- - Isolated execution
380
- - Resource limits
381
- - No host access
382
- - Safe for untrusted tools
383
-
384
- ---
385
-
386
- ## Deployment
387
-
388
- ### Kubernetes
389
-
390
- **deployment.yaml:**
391
- ```yaml
392
- apiVersion: apps/v1
393
- kind: Deployment
394
- metadata:
395
- name: lynkr
396
- spec:
397
- replicas: 3
398
- selector:
399
- matchLabels:
400
- app: lynkr
401
- template:
402
- metadata:
403
- labels:
404
- app: lynkr
405
- spec:
406
- containers:
407
- - name: lynkr
408
- image: lynkr:latest
409
- ports:
410
- - containerPort: 8081
411
- env:
412
- - name: MODEL_PROVIDER
413
- value: "databricks"
414
- - name: DATABRICKS_API_KEY
415
- valueFrom:
416
- secretKeyRef:
417
- name: lynkr-secrets
418
- key: databricks-api-key
419
- resources:
420
- requests:
421
- cpu: "500m"
422
- memory: "512Mi"
423
- limits:
424
- cpu: "2"
425
- memory: "2Gi"
426
- livenessProbe:
427
- httpGet:
428
- path: /health/live
429
- port: 8081
430
- initialDelaySeconds: 10
431
- periodSeconds: 10
432
- readinessProbe:
433
- httpGet:
434
- path: /health/ready
435
- port: 8081
436
- initialDelaySeconds: 5
437
- periodSeconds: 5
438
- ---
439
- apiVersion: v1
440
- kind: Service
441
- metadata:
442
- name: lynkr
443
- spec:
444
- selector:
445
- app: lynkr
446
- ports:
447
- - port: 80
448
- targetPort: 8081
449
- type: LoadBalancer
450
- ```
451
-
452
- ### Docker Compose
453
-
454
- See [Docker Deployment Guide](docker.md) for complete setup.
455
-
456
- ### Systemd
457
-
458
- **lynkr.service:**
459
- ```ini
460
- [Unit]
461
- Description=Lynkr Proxy
462
- After=network.target
463
-
464
- [Service]
465
- Type=simple
466
- User=lynkr
467
- WorkingDirectory=/opt/lynkr
468
- EnvironmentFile=/etc/lynkr/lynkr.env
469
- ExecStart=/usr/bin/node /opt/lynkr/index.js
470
- Restart=always
471
- RestartSec=10
472
-
473
- [Install]
474
- WantedBy=multi-user.target
475
- ```
476
-
477
- ```bash
478
- sudo systemctl enable lynkr
479
- sudo systemctl start lynkr
480
- sudo journalctl -u lynkr -f
481
- ```
482
-
483
- ---
484
-
485
- ## Monitoring
486
-
487
- ### Prometheus
488
-
489
- **prometheus.yml:**
490
- ```yaml
491
- scrape_configs:
492
- - job_name: 'lynkr'
493
- static_configs:
494
- - targets: ['localhost:8081']
495
- metrics_path: '/metrics'
496
- scrape_interval: 15s
497
- ```
498
-
499
- ### Grafana Dashboard
500
-
501
- **Key metrics to monitor:**
502
- - Request rate (req/sec)
503
- - Latency percentiles (p50, p95, p99)
504
- - Error rate
505
- - Token usage
506
- - Cache hit rate
507
- - Circuit breaker state
508
- - Memory usage
509
-
510
- **Sample queries:**
511
- ```promql
512
- # Request rate
513
- rate(lynkr_requests_total[5m])
514
-
515
- # 95th percentile latency
516
- histogram_quantile(0.95, rate(lynkr_request_duration_seconds_bucket[5m]))
517
-
518
- # Error rate
519
- rate(lynkr_errors_total[5m]) / rate(lynkr_requests_total[5m])
520
-
521
- # Cache hit rate
522
- lynkr_cache_hits_total / (lynkr_cache_hits_total + lynkr_cache_misses_total)
523
- ```
524
-
525
- ---
526
-
527
- ## Best Practices
528
-
529
- ### 1. Use Reverse Proxy
530
-
531
- ```nginx
532
- server {
533
- listen 443 ssl;
534
- server_name lynkr.example.com;
535
-
536
- ssl_certificate /path/to/cert.pem;
537
- ssl_certificate_key /path/to/key.pem;
538
-
539
- location / {
540
- proxy_pass http://localhost:8081;
541
- proxy_set_header Host $host;
542
- proxy_set_header X-Real-IP $remote_addr;
543
- }
544
- }
545
- ```
546
-
547
- ### 2. Set Resource Limits
548
-
549
- ```yaml
550
- resources:
551
- requests:
552
- cpu: "500m"
553
- memory: "512Mi"
554
- limits:
555
- cpu: "2"
556
- memory: "2Gi"
557
- ```
558
-
559
- ### 3. Enable All Hardening Features
560
-
561
- ```bash
562
- CIRCUIT_BREAKER_FAILURE_THRESHOLD=5
563
- LOAD_SHEDDING_MEMORY_THRESHOLD=0.85
564
- GRACEFUL_SHUTDOWN_TIMEOUT=30000
565
- METRICS_ENABLED=true
566
- HEALTH_CHECK_ENABLED=true
567
- ```
568
-
569
- ### 4. Monitor Metrics
570
-
571
- - Set up Prometheus + Grafana
572
- - Alert on high error rates
573
- - Alert on high latency
574
- - Monitor token usage
575
-
576
- ### 5. Rotate Secrets
577
-
578
- ```bash
579
- # Rotate API keys regularly
580
- kubectl create secret generic lynkr-secrets \
581
- --from-literal=databricks-api-key=new-key \
582
- --dry-run=client -o yaml | kubectl apply -f -
583
-
584
- # Rollout restart
585
- kubectl rollout restart deployment/lynkr
586
- ```
587
-
588
- ---
589
-
590
- ## Next Steps
591
-
592
- - **[Docker Deployment](docker.md)** - Docker setup
593
- - **[API Reference](api.md)** - API endpoints
594
- - **[Troubleshooting](troubleshooting.md)** - Common issues
595
-
596
- ---
597
-
598
- ## Getting Help
599
-
600
- - **[GitHub Discussions](https://github.com/vishalveerareddy123/Lynkr/discussions)** - Ask questions
601
- - **[GitHub Issues](https://github.com/vishalveerareddy123/Lynkr/issues)** - Report issues