kynjal-cli 4.0.0 → 4.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.
- package/dist/src/appliance/gguf-engine.d.ts +91 -0
- package/dist/src/appliance/gguf-engine.d.ts.map +1 -0
- package/dist/src/appliance/gguf-engine.js +286 -525
- package/dist/src/appliance/gguf-engine.js.map +1 -1
- package/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
- package/dist/src/appliance/ruvllm-bridge.d.ts.map +1 -0
- package/dist/src/appliance/ruvllm-bridge.js +203 -403
- package/dist/src/appliance/ruvllm-bridge.js.map +1 -1
- package/dist/src/appliance/rvfa-builder.d.ts +44 -0
- package/dist/src/appliance/rvfa-builder.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-builder.js +154 -208
- package/dist/src/appliance/rvfa-builder.js.map +1 -1
- package/dist/src/appliance/rvfa-distribution.d.ts +97 -0
- package/dist/src/appliance/rvfa-distribution.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-distribution.js +260 -423
- package/dist/src/appliance/rvfa-distribution.js.map +1 -1
- package/dist/src/appliance/rvfa-format.d.ts +111 -0
- package/dist/src/appliance/rvfa-format.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-format.js +128 -200
- package/dist/src/appliance/rvfa-format.js.map +1 -1
- package/dist/src/appliance/rvfa-runner.d.ts +69 -0
- package/dist/src/appliance/rvfa-runner.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-runner.js +168 -304
- package/dist/src/appliance/rvfa-runner.js.map +1 -1
- package/dist/src/appliance/rvfa-signing.d.ts +123 -0
- package/dist/src/appliance/rvfa-signing.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-signing.js +173 -295
- package/dist/src/appliance/rvfa-signing.js.map +1 -1
- package/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/dist/src/benchmarks/pretrain/index.d.ts.map +1 -0
- package/dist/src/benchmarks/pretrain/index.js +331 -542
- package/dist/src/benchmarks/pretrain/index.js.map +1 -1
- package/dist/src/commands/agent.js +574 -697
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.js +1218 -1548
- package/dist/src/commands/analyze.js.map +1 -1
- package/dist/src/commands/appliance-advanced.js +158 -267
- package/dist/src/commands/appliance-advanced.js.map +1 -1
- package/dist/src/commands/appliance.js +318 -493
- package/dist/src/commands/appliance.js.map +1 -1
- package/dist/src/commands/benchmark.js +372 -523
- package/dist/src/commands/benchmark.js.map +1 -1
- package/dist/src/commands/claims.js +274 -364
- package/dist/src/commands/claims.js.map +1 -1
- package/dist/src/commands/cleanup.js +113 -157
- package/dist/src/commands/cleanup.js.map +1 -1
- package/dist/src/commands/completions.js +477 -118
- package/dist/src/commands/completions.js.map +1 -1
- package/dist/src/commands/config.js +237 -303
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.js +487 -596
- package/dist/src/commands/daemon.js.map +1 -1
- package/dist/src/commands/deployment.js +194 -275
- package/dist/src/commands/deployment.js.map +1 -1
- package/dist/src/commands/doctor.js +504 -686
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/embeddings.js +1293 -1543
- package/dist/src/commands/embeddings.js.map +1 -1
- package/dist/src/commands/guidance.js +449 -596
- package/dist/src/commands/guidance.js.map +1 -1
- package/dist/src/commands/hive-mind.js +854 -938
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.js +3112 -3519
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +115 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +126 -308
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/init.js +788 -940
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/issues.js +383 -558
- package/dist/src/commands/issues.js.map +1 -1
- package/dist/src/commands/mcp.js +493 -605
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.js +833 -1026
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +282 -347
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/neural.js +1289 -1563
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/commands/performance.js +497 -643
- package/dist/src/commands/performance.js.map +1 -1
- package/dist/src/commands/plugins.js +668 -841
- package/dist/src/commands/plugins.js.map +1 -1
- package/dist/src/commands/process.js +392 -447
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/progress.js +162 -256
- package/dist/src/commands/progress.js.map +1 -1
- package/dist/src/commands/providers.js +150 -220
- package/dist/src/commands/providers.js.map +1 -1
- package/dist/src/commands/route.js +520 -665
- package/dist/src/commands/route.js.map +1 -1
- package/dist/src/commands/ruvector/backup.js +505 -651
- package/dist/src/commands/ruvector/backup.js.map +1 -1
- package/dist/src/commands/ruvector/benchmark.js +349 -401
- package/dist/src/commands/ruvector/benchmark.js.map +1 -1
- package/dist/src/commands/ruvector/import.js +224 -266
- package/dist/src/commands/ruvector/import.js.map +1 -1
- package/dist/src/commands/ruvector/index.js +37 -75
- package/dist/src/commands/ruvector/index.js.map +1 -1
- package/dist/src/commands/ruvector/init.js +336 -359
- package/dist/src/commands/ruvector/init.js.map +1 -1
- package/dist/src/commands/ruvector/migrate.js +335 -322
- package/dist/src/commands/ruvector/migrate.js.map +1 -1
- package/dist/src/commands/ruvector/optimize.js +375 -431
- package/dist/src/commands/ruvector/optimize.js.map +1 -1
- package/dist/src/commands/ruvector/setup.js +703 -117
- package/dist/src/commands/ruvector/setup.js.map +1 -1
- package/dist/src/commands/ruvector/status.js +364 -419
- package/dist/src/commands/ruvector/status.js.map +1 -1
- package/dist/src/commands/security.js +485 -608
- package/dist/src/commands/security.js.map +1 -1
- package/dist/src/commands/session.js +504 -626
- package/dist/src/commands/session.js.map +1 -1
- package/dist/src/commands/start.js +267 -364
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.js +380 -486
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +408 -488
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/task.js +423 -538
- package/dist/src/commands/task.js.map +1 -1
- package/dist/src/commands/transfer-store.js +322 -412
- package/dist/src/commands/transfer-store.js.map +1 -1
- package/dist/src/commands/update.js +196 -291
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/workflow.js +386 -486
- package/dist/src/commands/workflow.js.map +1 -1
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +38 -39
- package/dist/src/config-adapter.js.map +1 -1
- package/dist/src/index.d.ts +77 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +309 -411
- package/dist/src/index.js.map +1 -1
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +246 -507
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts +25 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +368 -78
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts +41 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +1307 -996
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts +60 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +657 -12
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/index.d.ts +1 -1
- package/dist/src/init/index.d.ts.map +1 -1
- package/dist/src/init/index.js +1 -1
- package/dist/src/init/index.js.map +1 -1
- package/dist/src/init/mcp-generator.js +33 -37
- package/dist/src/init/mcp-generator.js.map +1 -1
- package/dist/src/init/settings-generator.js +76 -77
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/init/statusline-generator.js +801 -3
- package/dist/src/init/statusline-generator.js.map +1 -1
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/init/types.js +76 -59
- package/dist/src/init/types.js.map +1 -1
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +81 -125
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts +161 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +470 -757
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +391 -492
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/agentdb-tools.js +332 -533
- package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.js +172 -236
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
- package/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/dist/src/mcp-tools/auto-install.d.ts.map +1 -0
- package/dist/src/mcp-tools/auto-install.js +80 -142
- package/dist/src/mcp-tools/auto-install.js.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +252 -375
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/claims-tools.js +473 -565
- package/dist/src/mcp-tools/claims-tools.js.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +197 -272
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/coordination-tools.js +500 -572
- package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
- package/dist/src/mcp-tools/daa-tools.js +286 -364
- package/dist/src/mcp-tools/daa-tools.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +582 -693
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/mcp-tools/github-tools.js +260 -311
- package/dist/src/mcp-tools/github-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.js +573 -640
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +2215 -2648
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +350 -505
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/neural-tools.js +315 -412
- package/dist/src/mcp-tools/neural-tools.js.map +1 -1
- package/dist/src/mcp-tools/performance-tools.js +420 -480
- package/dist/src/mcp-tools/performance-tools.js.map +1 -1
- package/dist/src/mcp-tools/progress-tools.js +204 -278
- package/dist/src/mcp-tools/progress-tools.js.map +1 -1
- package/dist/src/mcp-tools/ruvllm-tools.js +163 -279
- package/dist/src/mcp-tools/ruvllm-tools.js.map +1 -1
- package/dist/src/mcp-tools/security-tools.js +297 -429
- package/dist/src/mcp-tools/security-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.js +185 -234
- package/dist/src/mcp-tools/session-tools.js.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +207 -260
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/system-tools.js +276 -325
- package/dist/src/mcp-tools/system-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.js +270 -336
- package/dist/src/mcp-tools/task-tools.js.map +1 -1
- package/dist/src/mcp-tools/terminal-tools.js +148 -196
- package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
- package/dist/src/mcp-tools/transfer-tools.js +186 -333
- package/dist/src/mcp-tools/transfer-tools.js.map +1 -1
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/wasm-agent-tools.js +133 -280
- package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/workflow-tools.js +405 -450
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
- package/dist/src/memory/ewc-consolidation.d.ts +295 -0
- package/dist/src/memory/ewc-consolidation.d.ts.map +1 -0
- package/dist/src/memory/ewc-consolidation.js +190 -303
- package/dist/src/memory/ewc-consolidation.js.map +1 -1
- package/dist/src/memory/intelligence.d.ts +338 -0
- package/dist/src/memory/intelligence.d.ts.map +1 -0
- package/dist/src/memory/intelligence.js +569 -794
- package/dist/src/memory/intelligence.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +407 -0
- package/dist/src/memory/memory-bridge.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge.js +1170 -1640
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-initializer.d.ts +412 -0
- package/dist/src/memory/memory-initializer.d.ts.map +1 -0
- package/dist/src/memory/memory-initializer.js +1836 -1851
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/dist/src/memory/sona-optimizer.d.ts.map +1 -0
- package/dist/src/memory/sona-optimizer.js +199 -329
- package/dist/src/memory/sona-optimizer.js.map +1 -1
- package/dist/src/output.d.ts +2 -2
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +242 -272
- package/dist/src/output.js.map +1 -1
- package/dist/src/parser.d.ts +51 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +140 -187
- package/dist/src/parser.js.map +1 -1
- package/dist/src/plugins/manager.d.ts +133 -0
- package/dist/src/plugins/manager.d.ts.map +1 -0
- package/dist/src/plugins/manager.js +285 -521
- package/dist/src/plugins/manager.js.map +1 -1
- package/dist/src/plugins/store/discovery.d.ts +88 -0
- package/dist/src/plugins/store/discovery.d.ts.map +1 -0
- package/dist/src/plugins/store/discovery.js +271 -358
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/plugins/store/index.d.ts +76 -0
- package/dist/src/plugins/store/index.d.ts.map +1 -0
- package/dist/src/plugins/store/index.js +48 -105
- package/dist/src/plugins/store/index.js.map +1 -1
- package/dist/src/plugins/store/search.d.ts +46 -0
- package/dist/src/plugins/store/search.d.ts.map +1 -0
- package/dist/src/plugins/store/search.js +69 -107
- package/dist/src/plugins/store/search.js.map +1 -1
- package/dist/src/plugins/store/types.d.ts +274 -0
- package/dist/src/plugins/store/types.d.ts.map +1 -0
- package/dist/src/plugins/tests/demo-plugin-store.js +113 -160
- package/dist/src/plugins/tests/demo-plugin-store.js.map +1 -1
- package/dist/src/plugins/tests/standalone-test.js +172 -223
- package/dist/src/plugins/tests/standalone-test.js.map +1 -1
- package/dist/src/plugins/tests/test-plugin-store.js +190 -228
- package/dist/src/plugins/tests/test-plugin-store.js.map +1 -1
- package/dist/src/production/circuit-breaker.d.ts +101 -0
- package/dist/src/production/circuit-breaker.d.ts.map +1 -0
- package/dist/src/production/circuit-breaker.js +62 -126
- package/dist/src/production/circuit-breaker.js.map +1 -1
- package/dist/src/production/error-handler.d.ts +92 -0
- package/dist/src/production/error-handler.d.ts.map +1 -0
- package/dist/src/production/error-handler.js +86 -156
- package/dist/src/production/error-handler.js.map +1 -1
- package/dist/src/production/monitoring.d.ts +161 -0
- package/dist/src/production/monitoring.d.ts.map +1 -0
- package/dist/src/production/monitoring.js +139 -220
- package/dist/src/production/monitoring.js.map +1 -1
- package/dist/src/production/rate-limiter.d.ts +80 -0
- package/dist/src/production/rate-limiter.d.ts.map +1 -0
- package/dist/src/production/rate-limiter.js +74 -93
- package/dist/src/production/rate-limiter.js.map +1 -1
- package/dist/src/production/retry.d.ts +48 -0
- package/dist/src/production/retry.d.ts.map +1 -0
- package/dist/src/production/retry.js +75 -167
- package/dist/src/production/retry.js.map +1 -1
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +436 -560
- package/dist/src/prompt.js.map +1 -1
- package/dist/src/runtime/headless.d.ts +60 -0
- package/dist/src/runtime/headless.d.ts.map +1 -0
- package/dist/src/runtime/headless.js +197 -286
- package/dist/src/runtime/headless.js.map +1 -1
- package/dist/src/ruvector/agent-wasm.d.ts +182 -0
- package/dist/src/ruvector/agent-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/agent-wasm.js +156 -351
- package/dist/src/ruvector/agent-wasm.js.map +1 -1
- package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/ast-analyzer.js +145 -232
- package/dist/src/ruvector/ast-analyzer.js.map +1 -1
- package/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-router.js +287 -419
- package/dist/src/ruvector/coverage-router.js.map +1 -1
- package/dist/src/ruvector/coverage-tools.js +56 -101
- package/dist/src/ruvector/coverage-tools.js.map +1 -1
- package/dist/src/ruvector/diff-classifier.d.ts +175 -0
- package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
- package/dist/src/ruvector/diff-classifier.js +324 -451
- package/dist/src/ruvector/diff-classifier.js.map +1 -1
- package/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/dist/src/ruvector/enhanced-model-router.d.ts.map +1 -0
- package/dist/src/ruvector/enhanced-model-router.js +260 -336
- package/dist/src/ruvector/enhanced-model-router.js.map +1 -1
- package/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/dist/src/ruvector/flash-attention.d.ts.map +1 -0
- package/dist/src/ruvector/flash-attention.js +223 -254
- package/dist/src/ruvector/flash-attention.js.map +1 -1
- package/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/graph-analyzer.js +486 -680
- package/dist/src/ruvector/graph-analyzer.js.map +1 -1
- package/dist/src/ruvector/index.d.ts +40 -0
- package/dist/src/ruvector/index.d.ts.map +1 -0
- package/dist/src/ruvector/index.js +36 -106
- package/dist/src/ruvector/index.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -0
- package/dist/src/ruvector/lora-adapter.js +155 -248
- package/dist/src/ruvector/lora-adapter.js.map +1 -1
- package/dist/src/ruvector/model-router.d.ts +220 -0
- package/dist/src/ruvector/model-router.d.ts.map +1 -0
- package/dist/src/ruvector/model-router.js +175 -248
- package/dist/src/ruvector/model-router.js.map +1 -1
- package/dist/src/ruvector/moe-router.d.ts +206 -0
- package/dist/src/ruvector/moe-router.d.ts.map +1 -0
- package/dist/src/ruvector/moe-router.js +228 -286
- package/dist/src/ruvector/moe-router.js.map +1 -1
- package/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
- package/dist/src/ruvector/q-learning-router.js +257 -338
- package/dist/src/ruvector/q-learning-router.js.map +1 -1
- package/dist/src/ruvector/ruvllm-wasm.d.ts +179 -0
- package/dist/src/ruvector/ruvllm-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/ruvllm-wasm.js +270 -434
- package/dist/src/ruvector/ruvllm-wasm.js.map +1 -1
- package/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/dist/src/ruvector/semantic-router.d.ts.map +1 -0
- package/dist/src/ruvector/semantic-router.js +60 -67
- package/dist/src/ruvector/semantic-router.js.map +1 -1
- package/dist/src/ruvector/vector-db.d.ts +69 -0
- package/dist/src/ruvector/vector-db.d.ts.map +1 -0
- package/dist/src/ruvector/vector-db.js +119 -205
- package/dist/src/ruvector/vector-db.js.map +1 -1
- package/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/dist/src/services/agentic-flow-bridge.d.ts.map +1 -0
- package/dist/src/services/agentic-flow-bridge.js +32 -105
- package/dist/src/services/agentic-flow-bridge.js.map +1 -1
- package/dist/src/services/claim-service.d.ts +204 -0
- package/dist/src/services/claim-service.d.ts.map +1 -0
- package/dist/src/services/claim-service.js +615 -940
- package/dist/src/services/claim-service.js.map +1 -1
- package/dist/src/services/container-worker-pool.d.ts +197 -0
- package/dist/src/services/container-worker-pool.d.ts.map +1 -0
- package/dist/src/services/container-worker-pool.js +398 -666
- package/dist/src/services/container-worker-pool.js.map +1 -1
- package/dist/src/services/headless-worker-executor.d.ts +304 -0
- package/dist/src/services/headless-worker-executor.d.ts.map +1 -0
- package/dist/src/services/headless-worker-executor.js +441 -467
- package/dist/src/services/headless-worker-executor.js.map +1 -1
- package/dist/src/services/index.d.ts +4 -4
- package/dist/src/services/index.d.ts.map +1 -1
- package/dist/src/services/index.js +4 -4
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/services/registry-api.d.ts +58 -0
- package/dist/src/services/registry-api.d.ts.map +1 -0
- package/dist/src/services/registry-api.js +92 -200
- package/dist/src/services/registry-api.js.map +1 -1
- package/dist/src/services/ruvector-training.d.ts +222 -0
- package/dist/src/services/ruvector-training.d.ts.map +1 -0
- package/dist/src/services/ruvector-training.js +257 -337
- package/dist/src/services/ruvector-training.js.map +1 -1
- package/dist/src/services/worker-daemon.d.ts +228 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +591 -849
- package/dist/src/services/worker-daemon.js.map +1 -1
- package/dist/src/services/worker-queue.d.ts +194 -0
- package/dist/src/services/worker-queue.d.ts.map +1 -0
- package/dist/src/services/worker-queue.js +331 -548
- package/dist/src/services/worker-queue.js.map +1 -1
- package/dist/src/suggest.d.ts +53 -0
- package/dist/src/suggest.d.ts.map +1 -0
- package/dist/src/suggest.js +45 -55
- package/dist/src/suggest.js.map +1 -1
- package/dist/src/transfer/anonymization/index.js +29 -37
- package/dist/src/transfer/anonymization/index.js.map +1 -1
- package/dist/src/transfer/deploy-seraphine.js +128 -155
- package/dist/src/transfer/deploy-seraphine.js.map +1 -1
- package/dist/src/transfer/export.d.ts +25 -0
- package/dist/src/transfer/export.d.ts.map +1 -0
- package/dist/src/transfer/export.js +84 -142
- package/dist/src/transfer/export.js.map +1 -1
- package/dist/src/transfer/index.d.ts +1 -1
- package/dist/src/transfer/index.d.ts.map +1 -1
- package/dist/src/transfer/index.js +0 -2
- package/dist/src/transfer/index.js.map +1 -1
- package/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/dist/src/transfer/ipfs/client.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/client.js +187 -337
- package/dist/src/transfer/ipfs/client.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/dist/src/transfer/ipfs/upload.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/upload.js +288 -434
- package/dist/src/transfer/ipfs/upload.js.map +1 -1
- package/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/dist/src/transfer/models/seraphine.d.ts.map +1 -0
- package/dist/src/transfer/models/seraphine.js +55 -55
- package/dist/src/transfer/models/seraphine.js.map +1 -1
- package/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/dist/src/transfer/serialization/cfp.d.ts.map +1 -0
- package/dist/src/transfer/serialization/cfp.js +30 -31
- package/dist/src/transfer/serialization/cfp.js.map +1 -1
- package/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/dist/src/transfer/storage/gcs.d.ts.map +1 -0
- package/dist/src/transfer/storage/gcs.js +165 -232
- package/dist/src/transfer/storage/gcs.js.map +1 -1
- package/dist/src/transfer/store/discovery.d.ts +84 -0
- package/dist/src/transfer/store/discovery.d.ts.map +1 -0
- package/dist/src/transfer/store/discovery.js +239 -349
- package/dist/src/transfer/store/discovery.js.map +1 -1
- package/dist/src/transfer/store/download.d.ts +70 -0
- package/dist/src/transfer/store/download.d.ts.map +1 -0
- package/dist/src/transfer/store/download.js +243 -365
- package/dist/src/transfer/store/download.js.map +1 -1
- package/dist/src/transfer/store/index.d.ts +84 -0
- package/dist/src/transfer/store/index.d.ts.map +1 -0
- package/dist/src/transfer/store/index.js +63 -130
- package/dist/src/transfer/store/index.js.map +1 -1
- package/dist/src/transfer/store/publish.d.ts +76 -0
- package/dist/src/transfer/store/publish.d.ts.map +1 -0
- package/dist/src/transfer/store/publish.js +184 -258
- package/dist/src/transfer/store/publish.js.map +1 -1
- package/dist/src/transfer/store/registry.js +50 -72
- package/dist/src/transfer/store/registry.js.map +1 -1
- package/dist/src/transfer/store/search.d.ts +54 -0
- package/dist/src/transfer/store/search.d.ts.map +1 -0
- package/dist/src/transfer/store/search.js +64 -96
- package/dist/src/transfer/store/search.js.map +1 -1
- package/dist/src/transfer/store/tests/standalone-test.js +174 -231
- package/dist/src/transfer/store/tests/standalone-test.js.map +1 -1
- package/dist/src/transfer/test-seraphine.js +95 -130
- package/dist/src/transfer/test-seraphine.js.map +1 -1
- package/dist/src/transfer/tests/test-store.js +194 -239
- package/dist/src/transfer/tests/test-store.js.map +1 -1
- package/dist/src/transfer/types.d.ts +245 -0
- package/dist/src/transfer/types.d.ts.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +26 -55
- package/dist/src/types.js.map +1 -1
- package/dist/src/update/checker.d.ts +34 -0
- package/dist/src/update/checker.d.ts.map +1 -0
- package/dist/src/update/checker.js +106 -183
- package/dist/src/update/checker.js.map +1 -1
- package/dist/src/update/executor.d.ts +32 -0
- package/dist/src/update/executor.d.ts.map +1 -0
- package/dist/src/update/executor.js +135 -198
- package/dist/src/update/executor.js.map +1 -1
- package/dist/src/update/index.d.ts +33 -0
- package/dist/src/update/index.d.ts.map +1 -0
- package/dist/src/update/index.js +38 -85
- package/dist/src/update/index.js.map +1 -1
- package/dist/src/update/rate-limiter.d.ts +20 -0
- package/dist/src/update/rate-limiter.d.ts.map +1 -0
- package/dist/src/update/rate-limiter.js +19 -31
- package/dist/src/update/rate-limiter.js.map +1 -1
- package/dist/src/update/validator.d.ts +17 -0
- package/dist/src/update/validator.d.ts.map +1 -0
- package/dist/src/update/validator.js +38 -64
- package/dist/src/update/validator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -13,59 +13,12 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @module q-learning-router
|
|
15
15
|
*/
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
38
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
-
function step(op) {
|
|
41
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
-
while (_) try {
|
|
43
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
-
switch (op[0]) {
|
|
46
|
-
case 0: case 1: t = op; break;
|
|
47
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
-
default:
|
|
51
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
-
if (t[2]) _.ops.pop();
|
|
56
|
-
_.trys.pop(); continue;
|
|
57
|
-
}
|
|
58
|
-
op = body.call(thisArg, _);
|
|
59
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
16
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
64
17
|
import { dirname } from 'path';
|
|
65
18
|
/**
|
|
66
19
|
* Default configuration
|
|
67
20
|
*/
|
|
68
|
-
|
|
21
|
+
const DEFAULT_CONFIG = {
|
|
69
22
|
learningRate: 0.1,
|
|
70
23
|
gamma: 0.99,
|
|
71
24
|
explorationInitial: 1.0,
|
|
@@ -81,12 +34,12 @@ var DEFAULT_CONFIG = {
|
|
|
81
34
|
cacheTTL: 300000,
|
|
82
35
|
modelPath: '.swarm/q-learning-model.json',
|
|
83
36
|
autoSaveInterval: 100,
|
|
84
|
-
stateSpaceDim: 64
|
|
37
|
+
stateSpaceDim: 64,
|
|
85
38
|
};
|
|
86
39
|
/**
|
|
87
40
|
* Route names mapping
|
|
88
41
|
*/
|
|
89
|
-
|
|
42
|
+
const ROUTE_NAMES = [
|
|
90
43
|
'coder',
|
|
91
44
|
'tester',
|
|
92
45
|
'reviewer',
|
|
@@ -99,7 +52,7 @@ var ROUTE_NAMES = [
|
|
|
99
52
|
/**
|
|
100
53
|
* Task feature keywords for state representation
|
|
101
54
|
*/
|
|
102
|
-
|
|
55
|
+
const FEATURE_KEYWORDS = [
|
|
103
56
|
// Code-related
|
|
104
57
|
'implement', 'code', 'write', 'create', 'build', 'develop',
|
|
105
58
|
// Testing-related
|
|
@@ -127,155 +80,126 @@ var FEATURE_KEYWORDS = [
|
|
|
127
80
|
* - Prioritized experience replay
|
|
128
81
|
* - Model persistence
|
|
129
82
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
83
|
+
export class QLearningRouter {
|
|
84
|
+
config;
|
|
85
|
+
qTable = new Map();
|
|
86
|
+
epsilon;
|
|
87
|
+
stepCount = 0;
|
|
88
|
+
updateCount = 0;
|
|
89
|
+
avgTDError = 0;
|
|
90
|
+
ruvectorEngine = null;
|
|
91
|
+
useNative = false;
|
|
92
|
+
// Experience replay buffer (circular buffer)
|
|
93
|
+
replayBuffer = [];
|
|
94
|
+
replayBufferIdx = 0;
|
|
95
|
+
totalExperiences = 0;
|
|
96
|
+
// LRU cache for route decisions
|
|
97
|
+
routeCache = new Map();
|
|
98
|
+
cacheOrder = [];
|
|
99
|
+
cacheHits = 0;
|
|
100
|
+
cacheMisses = 0;
|
|
101
|
+
// Feature hash cache for state representation
|
|
102
|
+
featureHashCache = new Map();
|
|
103
|
+
constructor(config = {}) {
|
|
104
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
151
105
|
this.epsilon = this.config.explorationInitial;
|
|
152
106
|
}
|
|
153
107
|
/**
|
|
154
108
|
* Initialize the router, attempting to load ruvector native module
|
|
155
109
|
* and restore persisted model if available
|
|
156
110
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return [3 /*break*/, 3];
|
|
171
|
-
case 2:
|
|
172
|
-
_c = _d.sent();
|
|
173
|
-
// Fallback to JS implementation
|
|
174
|
-
this.useNative = false;
|
|
175
|
-
return [3 /*break*/, 3];
|
|
176
|
-
case 3:
|
|
177
|
-
// Try to load persisted model
|
|
178
|
-
return [4 /*yield*/, this.loadModel()];
|
|
179
|
-
case 4:
|
|
180
|
-
// Try to load persisted model
|
|
181
|
-
_d.sent();
|
|
182
|
-
return [2 /*return*/];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
};
|
|
111
|
+
async initialize() {
|
|
112
|
+
try {
|
|
113
|
+
const ruvector = await import('@ruvector/core');
|
|
114
|
+
this.ruvectorEngine = ruvector.createQLearning?.(this.config);
|
|
115
|
+
this.useNative = !!this.ruvectorEngine;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Fallback to JS implementation
|
|
119
|
+
this.useNative = false;
|
|
120
|
+
}
|
|
121
|
+
// Try to load persisted model
|
|
122
|
+
await this.loadModel();
|
|
123
|
+
}
|
|
187
124
|
/**
|
|
188
125
|
* Load model from persistence file
|
|
189
126
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
console.warn("[Q-Learning] Failed to load model: " + err);
|
|
219
|
-
return [2 /*return*/, false];
|
|
220
|
-
}
|
|
221
|
-
return [2 /*return*/];
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
};
|
|
127
|
+
async loadModel(path) {
|
|
128
|
+
const modelPath = path || this.config.modelPath;
|
|
129
|
+
try {
|
|
130
|
+
if (!existsSync(modelPath)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const data = readFileSync(modelPath, 'utf-8');
|
|
134
|
+
const model = JSON.parse(data);
|
|
135
|
+
// Validate version compatibility
|
|
136
|
+
if (!model.version || !model.version.startsWith('1.')) {
|
|
137
|
+
console.warn(`[Q-Learning] Incompatible model version: ${model.version}`);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
// Import Q-table
|
|
141
|
+
this.import(model.qTable);
|
|
142
|
+
// Restore stats
|
|
143
|
+
this.stepCount = model.stats.stepCount || 0;
|
|
144
|
+
this.updateCount = model.stats.updateCount || 0;
|
|
145
|
+
this.avgTDError = model.stats.avgTDError || 0;
|
|
146
|
+
this.epsilon = model.stats.epsilon || this.config.explorationInitial;
|
|
147
|
+
this.totalExperiences = model.metadata?.totalExperiences || 0;
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
console.warn(`[Q-Learning] Failed to load model: ${err}`);
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
225
155
|
/**
|
|
226
156
|
* Save model to persistence file
|
|
227
157
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
return [2 /*return*/];
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
};
|
|
158
|
+
async saveModel(path) {
|
|
159
|
+
const modelPath = path || this.config.modelPath;
|
|
160
|
+
try {
|
|
161
|
+
// Ensure directory exists
|
|
162
|
+
const dir = dirname(modelPath);
|
|
163
|
+
if (!existsSync(dir)) {
|
|
164
|
+
mkdirSync(dir, { recursive: true });
|
|
165
|
+
}
|
|
166
|
+
const model = {
|
|
167
|
+
version: '1.0.0',
|
|
168
|
+
config: {
|
|
169
|
+
learningRate: this.config.learningRate,
|
|
170
|
+
gamma: this.config.gamma,
|
|
171
|
+
explorationDecayType: this.config.explorationDecayType,
|
|
172
|
+
numActions: this.config.numActions,
|
|
173
|
+
},
|
|
174
|
+
qTable: this.export(),
|
|
175
|
+
stats: {
|
|
176
|
+
stepCount: this.stepCount,
|
|
177
|
+
updateCount: this.updateCount,
|
|
178
|
+
avgTDError: this.avgTDError,
|
|
179
|
+
epsilon: this.epsilon,
|
|
180
|
+
},
|
|
181
|
+
metadata: {
|
|
182
|
+
savedAt: new Date().toISOString(),
|
|
183
|
+
totalExperiences: this.totalExperiences,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
writeFileSync(modelPath, JSON.stringify(model, null, 2));
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
console.warn(`[Q-Learning] Failed to save model: ${err}`);
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
269
194
|
/**
|
|
270
195
|
* Route a task based on its context
|
|
271
196
|
* Uses LRU cache for repeated task patterns
|
|
272
197
|
*/
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
var stateKey = this.hashStateOptimized(taskContext);
|
|
198
|
+
route(taskContext, explore = true) {
|
|
199
|
+
const stateKey = this.hashStateOptimized(taskContext);
|
|
276
200
|
// Check cache first (only for exploitation, not exploration)
|
|
277
201
|
if (!explore) {
|
|
278
|
-
|
|
202
|
+
const cached = this.getCachedRoute(stateKey);
|
|
279
203
|
if (cached) {
|
|
280
204
|
this.cacheHits++;
|
|
281
205
|
return cached;
|
|
@@ -283,9 +207,9 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
283
207
|
this.cacheMisses++;
|
|
284
208
|
}
|
|
285
209
|
// Check if we should explore using decayed epsilon
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
210
|
+
const shouldExplore = explore && Math.random() < this.epsilon;
|
|
211
|
+
let actionIdx;
|
|
212
|
+
let qValues;
|
|
289
213
|
if (shouldExplore) {
|
|
290
214
|
// Random exploration
|
|
291
215
|
actionIdx = Math.floor(Math.random() * this.config.numActions);
|
|
@@ -297,95 +221,95 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
297
221
|
actionIdx = this.argmax(qValues);
|
|
298
222
|
}
|
|
299
223
|
// Calculate confidence from softmax of Q-values
|
|
300
|
-
|
|
224
|
+
const confidence = this.softmaxConfidence(qValues, actionIdx);
|
|
301
225
|
// Get alternatives sorted by Q-value
|
|
302
|
-
|
|
303
|
-
.map(
|
|
304
|
-
.sort(
|
|
226
|
+
const alternatives = ROUTE_NAMES
|
|
227
|
+
.map((route, idx) => ({ route, score: qValues[idx] }))
|
|
228
|
+
.sort((a, b) => b.score - a.score)
|
|
305
229
|
.slice(1, 4); // Top 3 alternatives
|
|
306
|
-
|
|
230
|
+
const decision = {
|
|
307
231
|
route: ROUTE_NAMES[actionIdx] || 'coder',
|
|
308
|
-
confidence
|
|
309
|
-
qValues
|
|
232
|
+
confidence,
|
|
233
|
+
qValues,
|
|
310
234
|
explored: shouldExplore,
|
|
311
|
-
alternatives
|
|
235
|
+
alternatives,
|
|
312
236
|
};
|
|
313
237
|
// Cache the decision for exploitation queries
|
|
314
238
|
if (!shouldExplore) {
|
|
315
239
|
this.cacheRoute(stateKey, decision);
|
|
316
240
|
}
|
|
317
241
|
return decision;
|
|
318
|
-
}
|
|
242
|
+
}
|
|
319
243
|
/**
|
|
320
244
|
* Get cached route decision (LRU cache)
|
|
321
245
|
*/
|
|
322
|
-
|
|
323
|
-
|
|
246
|
+
getCachedRoute(stateKey) {
|
|
247
|
+
const entry = this.routeCache.get(stateKey);
|
|
324
248
|
if (!entry) {
|
|
325
249
|
return null;
|
|
326
250
|
}
|
|
327
251
|
// Check TTL
|
|
328
252
|
if (Date.now() - entry.timestamp > this.config.cacheTTL) {
|
|
329
|
-
this.routeCache
|
|
330
|
-
this.cacheOrder = this.cacheOrder.filter(
|
|
253
|
+
this.routeCache.delete(stateKey);
|
|
254
|
+
this.cacheOrder = this.cacheOrder.filter(k => k !== stateKey);
|
|
331
255
|
return null;
|
|
332
256
|
}
|
|
333
257
|
// Update LRU order
|
|
334
|
-
this.cacheOrder = this.cacheOrder.filter(
|
|
258
|
+
this.cacheOrder = this.cacheOrder.filter(k => k !== stateKey);
|
|
335
259
|
this.cacheOrder.push(stateKey);
|
|
336
260
|
entry.hits++;
|
|
337
261
|
return entry.decision;
|
|
338
|
-
}
|
|
262
|
+
}
|
|
339
263
|
/**
|
|
340
264
|
* Cache a route decision (LRU eviction)
|
|
341
265
|
*/
|
|
342
|
-
|
|
266
|
+
cacheRoute(stateKey, decision) {
|
|
343
267
|
// Evict oldest if cache is full
|
|
344
268
|
while (this.routeCache.size >= this.config.cacheSize && this.cacheOrder.length > 0) {
|
|
345
|
-
|
|
269
|
+
const oldest = this.cacheOrder.shift();
|
|
346
270
|
if (oldest) {
|
|
347
|
-
this.routeCache
|
|
271
|
+
this.routeCache.delete(oldest);
|
|
348
272
|
}
|
|
349
273
|
}
|
|
350
274
|
this.routeCache.set(stateKey, {
|
|
351
|
-
decision
|
|
275
|
+
decision,
|
|
352
276
|
timestamp: Date.now(),
|
|
353
|
-
hits: 0
|
|
277
|
+
hits: 0,
|
|
354
278
|
});
|
|
355
279
|
this.cacheOrder.push(stateKey);
|
|
356
|
-
}
|
|
280
|
+
}
|
|
357
281
|
/**
|
|
358
282
|
* Invalidate cache (call after significant Q-table updates)
|
|
359
283
|
*/
|
|
360
|
-
|
|
284
|
+
invalidateCache() {
|
|
361
285
|
this.routeCache.clear();
|
|
362
286
|
this.cacheOrder = [];
|
|
363
|
-
}
|
|
287
|
+
}
|
|
364
288
|
/**
|
|
365
289
|
* Update Q-values based on feedback
|
|
366
290
|
* Includes experience replay for stable learning
|
|
367
291
|
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
292
|
+
update(taskContext, action, reward, nextContext) {
|
|
293
|
+
const stateKey = this.hashStateOptimized(taskContext);
|
|
294
|
+
const actionIdx = ROUTE_NAMES.indexOf(action);
|
|
371
295
|
if (actionIdx === -1) {
|
|
372
296
|
return 0;
|
|
373
297
|
}
|
|
374
|
-
|
|
298
|
+
const nextStateKey = nextContext ? this.hashStateOptimized(nextContext) : null;
|
|
375
299
|
// Store experience in replay buffer
|
|
376
300
|
if (this.config.enableReplay) {
|
|
377
|
-
|
|
378
|
-
stateKey
|
|
379
|
-
actionIdx
|
|
380
|
-
reward
|
|
381
|
-
nextStateKey
|
|
301
|
+
const experience = {
|
|
302
|
+
stateKey,
|
|
303
|
+
actionIdx,
|
|
304
|
+
reward,
|
|
305
|
+
nextStateKey,
|
|
382
306
|
timestamp: Date.now(),
|
|
383
|
-
priority: Math.abs(reward) + 0.1
|
|
307
|
+
priority: Math.abs(reward) + 0.1, // Initial priority based on reward magnitude
|
|
384
308
|
};
|
|
385
309
|
this.addToReplayBuffer(experience);
|
|
386
310
|
}
|
|
387
311
|
// Perform direct update
|
|
388
|
-
|
|
312
|
+
const tdError = this.updateQValue(stateKey, actionIdx, reward, nextStateKey);
|
|
389
313
|
// Perform experience replay
|
|
390
314
|
if (this.config.enableReplay && this.replayBuffer.length >= this.config.replayBatchSize) {
|
|
391
315
|
this.experienceReplay();
|
|
@@ -401,25 +325,25 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
401
325
|
this.avgTDError = (this.avgTDError * (this.updateCount - 1) + Math.abs(tdError)) / this.updateCount;
|
|
402
326
|
// Auto-save periodically
|
|
403
327
|
if (this.config.autoSaveInterval > 0 && this.updateCount % this.config.autoSaveInterval === 0) {
|
|
404
|
-
this.saveModel()
|
|
328
|
+
this.saveModel().catch(() => { }); // Fire and forget
|
|
405
329
|
}
|
|
406
330
|
// Invalidate cache periodically to reflect Q-table changes
|
|
407
331
|
if (this.updateCount % 50 === 0) {
|
|
408
332
|
this.invalidateCache();
|
|
409
333
|
}
|
|
410
334
|
return tdError;
|
|
411
|
-
}
|
|
335
|
+
}
|
|
412
336
|
/**
|
|
413
337
|
* Internal Q-value update
|
|
414
338
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
339
|
+
updateQValue(stateKey, actionIdx, reward, nextStateKey) {
|
|
340
|
+
const entry = this.getOrCreateEntry(stateKey);
|
|
341
|
+
const currentQ = entry.qValues[actionIdx];
|
|
418
342
|
// Calculate target Q-value
|
|
419
|
-
|
|
343
|
+
let targetQ;
|
|
420
344
|
if (nextStateKey) {
|
|
421
|
-
|
|
422
|
-
|
|
345
|
+
const nextQValues = this.getQValues(nextStateKey);
|
|
346
|
+
const maxNextQ = Math.max(...nextQValues);
|
|
423
347
|
targetQ = reward + this.config.gamma * maxNextQ;
|
|
424
348
|
}
|
|
425
349
|
else {
|
|
@@ -427,17 +351,17 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
427
351
|
targetQ = reward;
|
|
428
352
|
}
|
|
429
353
|
// TD error
|
|
430
|
-
|
|
354
|
+
const tdError = targetQ - currentQ;
|
|
431
355
|
// Update Q-value
|
|
432
356
|
entry.qValues[actionIdx] += this.config.learningRate * tdError;
|
|
433
357
|
entry.visits++;
|
|
434
358
|
entry.lastUpdate = Date.now();
|
|
435
359
|
return tdError;
|
|
436
|
-
}
|
|
360
|
+
}
|
|
437
361
|
/**
|
|
438
362
|
* Add experience to circular replay buffer
|
|
439
363
|
*/
|
|
440
|
-
|
|
364
|
+
addToReplayBuffer(experience) {
|
|
441
365
|
if (this.replayBuffer.length < this.config.replayBufferSize) {
|
|
442
366
|
this.replayBuffer.push(experience);
|
|
443
367
|
}
|
|
@@ -446,36 +370,35 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
446
370
|
}
|
|
447
371
|
this.replayBufferIdx = (this.replayBufferIdx + 1) % this.config.replayBufferSize;
|
|
448
372
|
this.totalExperiences++;
|
|
449
|
-
}
|
|
373
|
+
}
|
|
450
374
|
/**
|
|
451
375
|
* Perform prioritized experience replay
|
|
452
376
|
* Samples mini-batch from buffer and updates Q-values
|
|
453
377
|
*/
|
|
454
|
-
|
|
378
|
+
experienceReplay() {
|
|
455
379
|
if (this.replayBuffer.length < this.config.replayBatchSize) {
|
|
456
380
|
return;
|
|
457
381
|
}
|
|
458
382
|
// Prioritized sampling based on TD error magnitude
|
|
459
|
-
|
|
460
|
-
for (
|
|
461
|
-
|
|
462
|
-
var tdError = this.updateQValue(exp.stateKey, exp.actionIdx, exp.reward, exp.nextStateKey);
|
|
383
|
+
const batch = this.samplePrioritizedBatch(this.config.replayBatchSize);
|
|
384
|
+
for (const exp of batch) {
|
|
385
|
+
const tdError = this.updateQValue(exp.stateKey, exp.actionIdx, exp.reward, exp.nextStateKey);
|
|
463
386
|
// Update priority for future sampling
|
|
464
387
|
exp.priority = Math.abs(tdError) + 0.01; // Small constant to avoid zero priority
|
|
465
388
|
}
|
|
466
|
-
}
|
|
389
|
+
}
|
|
467
390
|
/**
|
|
468
391
|
* Sample a prioritized batch from replay buffer
|
|
469
392
|
* Uses proportional prioritization
|
|
470
393
|
*/
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
394
|
+
samplePrioritizedBatch(batchSize) {
|
|
395
|
+
const totalPriority = this.replayBuffer.reduce((sum, exp) => sum + exp.priority, 0);
|
|
396
|
+
const batch = [];
|
|
397
|
+
const selected = new Set();
|
|
475
398
|
while (batch.length < batchSize && selected.size < this.replayBuffer.length) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
for (
|
|
399
|
+
let threshold = Math.random() * totalPriority;
|
|
400
|
+
let cumSum = 0;
|
|
401
|
+
for (let i = 0; i < this.replayBuffer.length; i++) {
|
|
479
402
|
if (selected.has(i))
|
|
480
403
|
continue;
|
|
481
404
|
cumSum += this.replayBuffer[i].priority;
|
|
@@ -487,19 +410,19 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
487
410
|
}
|
|
488
411
|
}
|
|
489
412
|
return batch;
|
|
490
|
-
}
|
|
413
|
+
}
|
|
491
414
|
/**
|
|
492
415
|
* Calculate epsilon using configured decay strategy
|
|
493
416
|
*/
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
417
|
+
calculateEpsilon() {
|
|
418
|
+
const { explorationInitial, explorationFinal, explorationDecay, explorationDecayType } = this.config;
|
|
419
|
+
const progress = Math.min(this.stepCount / explorationDecay, 1.0);
|
|
497
420
|
switch (explorationDecayType) {
|
|
498
421
|
case 'linear':
|
|
499
422
|
return explorationFinal + (explorationInitial - explorationFinal) * (1 - progress);
|
|
500
423
|
case 'exponential':
|
|
501
424
|
// Exponential decay: epsilon = final + (initial - final) * exp(-decay_rate * step)
|
|
502
|
-
|
|
425
|
+
const decayRate = -Math.log((explorationFinal / explorationInitial) + 1e-8) / explorationDecay;
|
|
503
426
|
return explorationFinal + (explorationInitial - explorationFinal) * Math.exp(-decayRate * this.stepCount);
|
|
504
427
|
case 'cosine':
|
|
505
428
|
// Cosine annealing: smooth transition
|
|
@@ -507,12 +430,12 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
507
430
|
default:
|
|
508
431
|
return Math.max(explorationFinal, explorationInitial - this.stepCount / explorationDecay);
|
|
509
432
|
}
|
|
510
|
-
}
|
|
433
|
+
}
|
|
511
434
|
/**
|
|
512
435
|
* Get statistics including cache and replay buffer metrics
|
|
513
436
|
*/
|
|
514
|
-
|
|
515
|
-
|
|
437
|
+
getStats() {
|
|
438
|
+
const cacheHitRate = this.cacheHits + this.cacheMisses > 0
|
|
516
439
|
? this.cacheHits / (this.cacheHits + this.cacheMisses)
|
|
517
440
|
: 0;
|
|
518
441
|
return {
|
|
@@ -526,18 +449,18 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
526
449
|
cacheSize: this.routeCache.size,
|
|
527
450
|
cacheHits: this.cacheHits,
|
|
528
451
|
cacheMisses: this.cacheMisses,
|
|
529
|
-
cacheHitRate
|
|
452
|
+
cacheHitRate,
|
|
530
453
|
// Replay buffer metrics
|
|
531
454
|
replayBufferSize: this.replayBuffer.length,
|
|
532
455
|
totalExperiences: this.totalExperiences,
|
|
533
456
|
// Feature hash cache
|
|
534
|
-
featureHashCacheSize: this.featureHashCache.size
|
|
457
|
+
featureHashCacheSize: this.featureHashCache.size,
|
|
535
458
|
};
|
|
536
|
-
}
|
|
459
|
+
}
|
|
537
460
|
/**
|
|
538
461
|
* Reset the router (clears all learned data)
|
|
539
462
|
*/
|
|
540
|
-
|
|
463
|
+
reset() {
|
|
541
464
|
this.qTable.clear();
|
|
542
465
|
this.epsilon = this.config.explorationInitial;
|
|
543
466
|
this.stepCount = 0;
|
|
@@ -554,121 +477,119 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
554
477
|
this.cacheMisses = 0;
|
|
555
478
|
// Reset feature hash cache
|
|
556
479
|
this.featureHashCache.clear();
|
|
557
|
-
}
|
|
480
|
+
}
|
|
558
481
|
/**
|
|
559
482
|
* Export Q-table for persistence
|
|
560
483
|
*/
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
for (
|
|
564
|
-
var _b = _a[_i], key = _b[0], entry = _b[1];
|
|
484
|
+
export() {
|
|
485
|
+
const result = {};
|
|
486
|
+
for (const [key, entry] of this.qTable) {
|
|
565
487
|
result[key] = {
|
|
566
488
|
qValues: Array.from(entry.qValues),
|
|
567
|
-
visits: entry.visits
|
|
489
|
+
visits: entry.visits,
|
|
568
490
|
};
|
|
569
491
|
}
|
|
570
492
|
return result;
|
|
571
|
-
}
|
|
493
|
+
}
|
|
572
494
|
/**
|
|
573
495
|
* Import Q-table from persistence
|
|
574
496
|
*/
|
|
575
|
-
|
|
497
|
+
import(data) {
|
|
576
498
|
this.qTable.clear();
|
|
577
|
-
for (
|
|
578
|
-
var _b = _a[_i], key = _b[0], entry = _b[1];
|
|
499
|
+
for (const [key, entry] of Object.entries(data)) {
|
|
579
500
|
this.qTable.set(key, {
|
|
580
501
|
qValues: new Float32Array(entry.qValues),
|
|
581
502
|
visits: entry.visits,
|
|
582
|
-
lastUpdate: Date.now()
|
|
503
|
+
lastUpdate: Date.now(),
|
|
583
504
|
});
|
|
584
505
|
}
|
|
585
|
-
}
|
|
506
|
+
}
|
|
586
507
|
// Private methods
|
|
587
508
|
/**
|
|
588
509
|
* Legacy hash function (kept for backward compatibility)
|
|
589
510
|
*/
|
|
590
|
-
|
|
511
|
+
hashState(context) {
|
|
591
512
|
// Simple hash for context string
|
|
592
|
-
|
|
593
|
-
for (
|
|
594
|
-
|
|
513
|
+
let hash = 0;
|
|
514
|
+
for (let i = 0; i < context.length; i++) {
|
|
515
|
+
const char = context.charCodeAt(i);
|
|
595
516
|
hash = ((hash << 5) - hash) + char;
|
|
596
517
|
hash = hash & hash; // Convert to 32-bit integer
|
|
597
518
|
}
|
|
598
|
-
return
|
|
599
|
-
}
|
|
519
|
+
return `state_${hash}`;
|
|
520
|
+
}
|
|
600
521
|
/**
|
|
601
522
|
* Optimized state hashing using feature extraction
|
|
602
523
|
* Creates a more semantic representation of the task context
|
|
603
524
|
*/
|
|
604
|
-
|
|
525
|
+
hashStateOptimized(context) {
|
|
605
526
|
// Check feature hash cache first
|
|
606
527
|
if (this.featureHashCache.has(context)) {
|
|
607
|
-
|
|
528
|
+
const cached = this.featureHashCache.get(context);
|
|
608
529
|
return this.featureVectorToKey(cached);
|
|
609
530
|
}
|
|
610
531
|
// Extract features from context
|
|
611
|
-
|
|
532
|
+
const features = this.extractFeatures(context);
|
|
612
533
|
// Cache the feature vector
|
|
613
534
|
if (this.featureHashCache.size < 1000) { // Limit cache size
|
|
614
535
|
this.featureHashCache.set(context, features);
|
|
615
536
|
}
|
|
616
537
|
return this.featureVectorToKey(features);
|
|
617
|
-
}
|
|
538
|
+
}
|
|
618
539
|
/**
|
|
619
540
|
* Extract feature vector from task context
|
|
620
541
|
* Uses keyword matching and n-gram hashing
|
|
621
542
|
*/
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
543
|
+
extractFeatures(context) {
|
|
544
|
+
const features = new Float32Array(this.config.stateSpaceDim);
|
|
545
|
+
const lowerContext = context.toLowerCase();
|
|
546
|
+
const words = lowerContext.split(/\s+/);
|
|
626
547
|
// Feature 1-32: Keyword presence (binary features)
|
|
627
|
-
for (
|
|
548
|
+
for (let i = 0; i < FEATURE_KEYWORDS.length && i < 32; i++) {
|
|
628
549
|
if (lowerContext.includes(FEATURE_KEYWORDS[i])) {
|
|
629
550
|
features[i] = 1.0;
|
|
630
551
|
}
|
|
631
552
|
}
|
|
632
553
|
// Feature 33-40: Context length buckets
|
|
633
|
-
|
|
554
|
+
const lengthBucket = Math.min(Math.floor(context.length / 50), 7);
|
|
634
555
|
features[32 + lengthBucket] = 1.0;
|
|
635
556
|
// Feature 41-48: Word count buckets
|
|
636
|
-
|
|
557
|
+
const wordBucket = Math.min(Math.floor(words.length / 5), 7);
|
|
637
558
|
features[40 + wordBucket] = 1.0;
|
|
638
559
|
// Feature 49-56: File extension hints
|
|
639
|
-
|
|
640
|
-
for (
|
|
560
|
+
const extPatterns = ['.ts', '.js', '.py', '.go', '.rs', '.java', '.md', '.json'];
|
|
561
|
+
for (let i = 0; i < extPatterns.length; i++) {
|
|
641
562
|
if (lowerContext.includes(extPatterns[i])) {
|
|
642
563
|
features[48 + i] = 1.0;
|
|
643
564
|
}
|
|
644
565
|
}
|
|
645
566
|
// Feature 57-64: N-gram hash features (for capturing unique patterns)
|
|
646
|
-
for (
|
|
647
|
-
|
|
648
|
-
|
|
567
|
+
for (let i = 0; i < words.length - 1 && i < 8; i++) {
|
|
568
|
+
const bigram = `${words[i]}_${words[i + 1]}`;
|
|
569
|
+
const hash = this.murmurhash3(bigram) % 8;
|
|
649
570
|
features[56 + hash] += 0.25;
|
|
650
571
|
}
|
|
651
572
|
// Normalize features
|
|
652
|
-
|
|
653
|
-
for (
|
|
573
|
+
let norm = 0;
|
|
574
|
+
for (let i = 0; i < features.length; i++) {
|
|
654
575
|
norm += features[i] * features[i];
|
|
655
576
|
}
|
|
656
577
|
norm = Math.sqrt(norm) || 1;
|
|
657
|
-
for (
|
|
578
|
+
for (let i = 0; i < features.length; i++) {
|
|
658
579
|
features[i] /= norm;
|
|
659
580
|
}
|
|
660
581
|
return features;
|
|
661
|
-
}
|
|
582
|
+
}
|
|
662
583
|
/**
|
|
663
584
|
* Convert feature vector to state key
|
|
664
585
|
* Uses locality-sensitive hashing for similar contexts
|
|
665
586
|
*/
|
|
666
|
-
|
|
587
|
+
featureVectorToKey(features) {
|
|
667
588
|
// Quantize features to create discrete state
|
|
668
|
-
|
|
669
|
-
for (
|
|
670
|
-
|
|
671
|
-
for (
|
|
589
|
+
const quantized = [];
|
|
590
|
+
for (let i = 0; i < features.length; i += 4) {
|
|
591
|
+
let bucket = 0;
|
|
592
|
+
for (let j = 0; j < 4 && i + j < features.length; j++) {
|
|
672
593
|
if (features[i + j] > 0.25) {
|
|
673
594
|
bucket |= (1 << j);
|
|
674
595
|
}
|
|
@@ -676,21 +597,21 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
676
597
|
quantized.push(bucket);
|
|
677
598
|
}
|
|
678
599
|
// Create hash from quantized values
|
|
679
|
-
|
|
680
|
-
for (
|
|
600
|
+
let hash = 0;
|
|
601
|
+
for (let i = 0; i < quantized.length; i++) {
|
|
681
602
|
hash = ((hash << 4) ^ quantized[i]) & 0x7fffffff;
|
|
682
603
|
}
|
|
683
|
-
return
|
|
684
|
-
}
|
|
604
|
+
return `fstate_${hash.toString(36)}`;
|
|
605
|
+
}
|
|
685
606
|
/**
|
|
686
607
|
* MurmurHash3 32-bit implementation for n-gram hashing
|
|
687
608
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
for (
|
|
693
|
-
|
|
609
|
+
murmurhash3(str) {
|
|
610
|
+
let h1 = 0xdeadbeef;
|
|
611
|
+
const c1 = 0xcc9e2d51;
|
|
612
|
+
const c2 = 0x1b873593;
|
|
613
|
+
for (let i = 0; i < str.length; i++) {
|
|
614
|
+
let k1 = str.charCodeAt(i);
|
|
694
615
|
k1 = Math.imul(k1, c1);
|
|
695
616
|
k1 = (k1 << 15) | (k1 >>> 17);
|
|
696
617
|
k1 = Math.imul(k1, c2);
|
|
@@ -705,54 +626,52 @@ var QLearningRouter = /** @class */ (function () {
|
|
|
705
626
|
h1 = Math.imul(h1, 0xc2b2ae35);
|
|
706
627
|
h1 ^= h1 >>> 16;
|
|
707
628
|
return h1 >>> 0;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
|
|
629
|
+
}
|
|
630
|
+
getQValues(stateKey) {
|
|
631
|
+
const entry = this.qTable.get(stateKey);
|
|
711
632
|
if (!entry) {
|
|
712
633
|
return new Array(this.config.numActions).fill(0);
|
|
713
634
|
}
|
|
714
635
|
return Array.from(entry.qValues);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
636
|
+
}
|
|
637
|
+
getOrCreateEntry(stateKey) {
|
|
638
|
+
let entry = this.qTable.get(stateKey);
|
|
718
639
|
if (!entry) {
|
|
719
640
|
entry = {
|
|
720
641
|
qValues: new Float32Array(this.config.numActions),
|
|
721
642
|
visits: 0,
|
|
722
|
-
lastUpdate: Date.now()
|
|
643
|
+
lastUpdate: Date.now(),
|
|
723
644
|
};
|
|
724
645
|
this.qTable.set(stateKey, entry);
|
|
725
646
|
}
|
|
726
647
|
return entry;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
for (
|
|
648
|
+
}
|
|
649
|
+
argmax(values) {
|
|
650
|
+
let maxIdx = 0;
|
|
651
|
+
let maxVal = values[0];
|
|
652
|
+
for (let i = 1; i < values.length; i++) {
|
|
732
653
|
if (values[i] > maxVal) {
|
|
733
654
|
maxVal = values[i];
|
|
734
655
|
maxIdx = i;
|
|
735
656
|
}
|
|
736
657
|
}
|
|
737
658
|
return maxIdx;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
659
|
+
}
|
|
660
|
+
softmaxConfidence(qValues, actionIdx) {
|
|
661
|
+
const maxQ = Math.max(...qValues);
|
|
662
|
+
const expValues = qValues.map(q => Math.exp(q - maxQ)); // Subtract max for numerical stability
|
|
663
|
+
const sumExp = expValues.reduce((a, b) => a + b, 0);
|
|
743
664
|
return expValues[actionIdx] / sumExp;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
.sort(
|
|
748
|
-
|
|
749
|
-
for (
|
|
750
|
-
this.qTable
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
}());
|
|
755
|
-
export { QLearningRouter };
|
|
665
|
+
}
|
|
666
|
+
pruneQTable() {
|
|
667
|
+
const entries = Array.from(this.qTable.entries())
|
|
668
|
+
.sort((a, b) => a[1].lastUpdate - b[1].lastUpdate);
|
|
669
|
+
const toRemove = entries.length - Math.floor(this.config.maxStates * 0.8);
|
|
670
|
+
for (let i = 0; i < toRemove; i++) {
|
|
671
|
+
this.qTable.delete(entries[i][0]);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
756
675
|
/**
|
|
757
676
|
* Factory function
|
|
758
677
|
*/
|