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