@monoes/monomindcli 1.10.56 → 1.11.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/coordinator.md +71 -0
- package/.claude/agents/generated/case-analyst.md +50 -0
- package/.claude/agents/generated/copy-editor.md +45 -0
- package/.claude/agents/generated/court-reporter.md +50 -0
- package/.claude/agents/generated/defender.md +51 -0
- package/.claude/agents/generated/editor-in-chief.md +45 -0
- package/.claude/agents/generated/fact-checker.md +45 -0
- package/.claude/agents/generated/judge.md +51 -0
- package/.claude/agents/generated/prosecutor.md +51 -0
- package/.claude/agents/generated/reporter.md +45 -0
- package/.claude/commands/hooks/README.md +1 -1
- package/.claude/commands/hooks/overview.md +1 -1
- package/.claude/commands/mastermind/_repeat.md +1 -1
- package/.claude/commands/mastermind/do.md +3 -1
- package/.claude/commands/mastermind/help.md +2 -2
- package/.claude/commands/mastermind/master.md +39 -6
- package/.claude/commands/mastermind/memory.md +1 -1
- package/.claude/commands/memory/memory-search.md +2 -2
- package/.claude/commands/monitoring/status.md +1 -1
- package/.claude/commands/{browse.md → monobrowse.md} +2 -2
- package/.claude/commands/sparc.md +1 -1
- package/.claude/helpers/handlers/graph-status-handler.cjs +1 -1
- package/.claude/helpers/loop-tracker.cjs +1 -1
- package/.claude/skills/agent-browser-testing/SKILL.md +1 -1
- package/.claude/skills/hooks-automation/SKILL.md +0 -3
- package/.claude/skills/mastermind/build.md +1 -1
- package/.claude/skills/mastermind/code-quality-reviewer-prompt.md +60 -0
- package/.claude/skills/mastermind/content.md +1 -1
- package/.claude/skills/mastermind/createorg.md +79 -2
- package/.claude/skills/mastermind/design.md +3 -1
- package/.claude/skills/mastermind/finance.md +1 -1
- package/.claude/skills/mastermind/implementer-prompt.md +109 -0
- package/.claude/skills/mastermind/marketing.md +1 -1
- package/.claude/skills/mastermind/ops.md +1 -1
- package/.claude/skills/mastermind/plan.md +20 -2
- package/.claude/skills/mastermind/release.md +1 -1
- package/.claude/skills/mastermind/research.md +1 -1
- package/.claude/skills/mastermind/review.md +1 -1
- package/.claude/skills/mastermind/sales.md +1 -1
- package/.claude/skills/mastermind/spec-reviewer-prompt.md +63 -0
- package/.claude/skills/sparc-methodology/SKILL.md +3 -3
- package/.claude/skills/swarm-advanced/SKILL.md +1 -4
- package/README.md +18 -32
- package/dist/src/agents/registry-builder.d.ts +1 -7
- package/dist/src/agents/registry-builder.d.ts.map +1 -1
- package/dist/src/agents/registry-builder.js +10 -6
- package/dist/src/agents/registry-builder.js.map +1 -1
- package/dist/src/benchmarks/benchmark-runner.d.ts +59 -12
- package/dist/src/benchmarks/benchmark-runner.d.ts.map +1 -1
- package/dist/src/benchmarks/benchmark-runner.js +67 -13
- package/dist/src/benchmarks/benchmark-runner.js.map +1 -1
- package/dist/src/benchmarks/metric-evaluators.d.ts.map +1 -1
- package/dist/src/benchmarks/metric-evaluators.js.map +1 -1
- package/dist/src/benchmarks/pretrain/index.d.ts +0 -13
- package/dist/src/benchmarks/pretrain/index.d.ts.map +1 -1
- package/dist/src/benchmarks/pretrain/index.js.map +1 -1
- package/dist/src/commands/agent-wasm.d.ts +2 -2
- package/dist/src/commands/agent-wasm.js +5 -5
- package/dist/src/commands/agent.d.ts.map +1 -1
- package/dist/src/commands/agent.js +1 -6
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.d.ts +1 -1
- package/dist/src/commands/analyze.d.ts.map +1 -1
- package/dist/src/commands/analyze.js +8 -18
- package/dist/src/commands/analyze.js.map +1 -1
- package/dist/src/commands/doctor.d.ts.map +1 -1
- package/dist/src/commands/doctor.js +53 -3
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/embeddings.d.ts.map +1 -1
- package/dist/src/commands/embeddings.js +9 -33
- package/dist/src/commands/embeddings.js.map +1 -1
- package/dist/src/commands/hooks.d.ts.map +1 -1
- package/dist/src/commands/hooks.js +24 -76
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +4 -6
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +8 -15
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/init.js +2 -2
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/issues.d.ts.map +1 -1
- package/dist/src/commands/issues.js +16 -11
- package/dist/src/commands/issues.js.map +1 -1
- package/dist/src/commands/mcp.d.ts +1 -1
- package/dist/src/commands/memory.js +6 -6
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.d.ts.map +1 -1
- package/dist/src/commands/migrate.js +1 -2
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/monograph.d.ts.map +1 -1
- package/dist/src/commands/monograph.js +18 -11
- package/dist/src/commands/monograph.js.map +1 -1
- package/dist/src/commands/monovector/backup.d.ts +11 -0
- package/dist/src/commands/monovector/backup.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/backup.js +25 -25
- package/dist/src/commands/monovector/backup.js.map +1 -0
- package/dist/src/commands/monovector/benchmark.d.ts +11 -0
- package/dist/src/commands/monovector/benchmark.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/benchmark.js +14 -14
- package/dist/src/commands/monovector/benchmark.js.map +1 -0
- package/dist/src/commands/monovector/import.d.ts +18 -0
- package/dist/src/commands/monovector/import.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/import.js +21 -21
- package/dist/src/commands/monovector/import.js.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/index.d.ts +6 -6
- package/dist/src/commands/monovector/index.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/index.js +22 -22
- package/dist/src/commands/monovector/index.js.map +1 -0
- package/dist/src/commands/monovector/init.d.ts +11 -0
- package/dist/src/commands/monovector/init.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/init.js +36 -36
- package/dist/src/commands/monovector/init.js.map +1 -0
- package/dist/src/commands/monovector/migrate.d.ts +11 -0
- package/dist/src/commands/monovector/migrate.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/migrate.js +16 -16
- package/dist/src/commands/monovector/migrate.js.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/optimize.d.ts +2 -2
- package/dist/src/commands/monovector/optimize.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/optimize.js +10 -10
- package/dist/src/commands/monovector/optimize.js.map +1 -0
- package/dist/src/commands/monovector/setup.d.ts +18 -0
- package/dist/src/commands/monovector/setup.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/setup.js +77 -77
- package/dist/src/commands/monovector/setup.js.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/status.d.ts +2 -2
- package/dist/src/commands/monovector/status.d.ts.map +1 -0
- package/dist/src/commands/{ruvector → monovector}/status.js +34 -34
- package/dist/src/commands/monovector/status.js.map +1 -0
- package/dist/src/commands/neural.d.ts +1 -1
- package/dist/src/commands/neural.d.ts.map +1 -1
- package/dist/src/commands/neural.js +31 -608
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/commands/performance.d.ts.map +1 -1
- package/dist/src/commands/performance.js +7 -10
- package/dist/src/commands/performance.js.map +1 -1
- package/dist/src/commands/plugins.d.ts.map +1 -1
- package/dist/src/commands/plugins.js +3 -4
- package/dist/src/commands/plugins.js.map +1 -1
- package/dist/src/commands/process.d.ts.map +1 -1
- package/dist/src/commands/process.js +5 -12
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/progress.d.ts.map +1 -1
- package/dist/src/commands/progress.js +16 -16
- package/dist/src/commands/progress.js.map +1 -1
- package/dist/src/commands/replay.d.ts.map +1 -1
- package/dist/src/commands/replay.js.map +1 -1
- package/dist/src/commands/route.d.ts +2 -2
- package/dist/src/commands/route.js +23 -23
- package/dist/src/commands/route.js.map +1 -1
- package/dist/src/commands/status.d.ts.map +1 -1
- package/dist/src/commands/status.js +0 -3
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.d.ts.map +1 -1
- package/dist/src/commands/swarm.js +2 -3
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/update.d.ts +1 -1
- package/dist/src/config-adapter.d.ts.map +1 -1
- package/dist/src/config-adapter.js +27 -0
- package/dist/src/config-adapter.js.map +1 -1
- package/dist/src/consensus/audit-writer.d.ts +44 -17
- package/dist/src/consensus/audit-writer.d.ts.map +1 -1
- package/dist/src/consensus/audit-writer.js.map +1 -1
- package/dist/src/dlq/dlq-replayer.d.ts +1 -1
- package/dist/src/dlq/dlq-replayer.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +5 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts.map +1 -1
- package/dist/src/init/claudemd-generator.js +10 -14
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts.map +1 -1
- package/dist/src/init/executor.js +17 -27
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts +1 -1
- package/dist/src/init/helpers-generator.js +2 -2
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/mcp-client.d.ts.map +1 -1
- package/dist/src/mcp-client.js +1 -7
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +9 -1
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +1 -52
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.js +5 -5
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
- package/dist/src/mcp-tools/auto-install.d.ts +4 -4
- package/dist/src/mcp-tools/autopilot-tools.d.ts +1 -1
- package/dist/src/mcp-tools/browser-tools.d.ts +1 -1
- package/dist/src/mcp-tools/browser-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +6 -5
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/claims-tools.d.ts +1 -1
- package/dist/src/mcp-tools/coordination-tools.d.ts +1 -1
- package/dist/src/mcp-tools/coordination-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/coordination-tools.js +51 -54
- package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
- package/dist/src/mcp-tools/daa-tools.d.ts +1 -1
- package/dist/src/mcp-tools/daa-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/daa-tools.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +10 -10
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/mcp-tools/guidance-tools.d.ts +1 -1
- package/dist/src/mcp-tools/guidance-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/guidance-tools.js +0 -24
- package/dist/src/mcp-tools/guidance-tools.js.map +1 -1
- 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 +189 -446
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/index.d.ts +0 -2
- package/dist/src/mcp-tools/index.d.ts.map +1 -1
- package/dist/src/mcp-tools/index.js +0 -2
- package/dist/src/mcp-tools/index.js.map +1 -1
- package/dist/src/mcp-tools/monograph-compat.d.ts +334 -0
- package/dist/src/mcp-tools/monograph-compat.d.ts.map +1 -0
- package/dist/src/mcp-tools/monograph-compat.js +1108 -0
- package/dist/src/mcp-tools/monograph-compat.js.map +1 -0
- package/dist/src/mcp-tools/monograph-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/monograph-tools.js +76 -34
- package/dist/src/mcp-tools/monograph-tools.js.map +1 -1
- package/dist/src/mcp-tools/neural-tools.d.ts +2 -2
- package/dist/src/mcp-tools/neural-tools.js +2 -2
- package/dist/src/mcp-tools/neural-tools.js.map +1 -1
- package/dist/src/mcp-tools/progress-tools.d.ts +1 -1
- package/dist/src/mcp-tools/ruvllm-tools.d.ts +2 -2
- package/dist/src/mcp-tools/ruvllm-tools.js +3 -3
- package/dist/src/mcp-tools/terminal-tools.d.ts +1 -1
- package/dist/src/mcp-tools/terminal-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/terminal-tools.js +29 -19
- package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
- package/dist/src/mcp-tools/transfer-tools.d.ts +1 -1
- package/dist/src/mcp-tools/wasm-agent-tools.d.ts +1 -1
- package/dist/src/mcp-tools/wasm-agent-tools.js +2 -2
- package/dist/src/memory/intelligence.d.ts.map +1 -1
- package/dist/src/memory/intelligence.js +14 -8
- package/dist/src/memory/intelligence.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +17 -2
- package/dist/src/memory/memory-bridge.d.ts.map +1 -1
- package/dist/src/memory/memory-bridge.js +76 -23
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-initializer.d.ts +2 -2
- package/dist/src/memory/memory-initializer.d.ts.map +1 -1
- package/dist/src/memory/memory-initializer.js +37 -39
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/monovector/capabilities.d.ts +34 -0
- package/dist/src/monovector/capabilities.d.ts.map +1 -0
- package/dist/src/monovector/capabilities.js +37 -0
- package/dist/src/monovector/capabilities.js.map +1 -0
- package/dist/src/monovector/command-outcomes.d.ts +37 -0
- package/dist/src/monovector/command-outcomes.d.ts.map +1 -0
- package/dist/src/monovector/command-outcomes.js +87 -0
- package/dist/src/monovector/command-outcomes.js.map +1 -0
- package/dist/src/monovector/coverage-router.d.ts +103 -0
- package/dist/src/monovector/coverage-router.d.ts.map +1 -0
- package/dist/src/monovector/coverage-router.js +337 -0
- package/dist/src/monovector/coverage-router.js.map +1 -0
- package/dist/src/monovector/coverage-tools.d.ts +14 -0
- package/dist/src/monovector/coverage-tools.d.ts.map +1 -0
- package/dist/src/monovector/coverage-tools.js +112 -0
- package/dist/src/monovector/coverage-tools.js.map +1 -0
- package/dist/src/{ruvector → monovector}/diff-classifier.d.ts +2 -2
- package/dist/src/monovector/diff-classifier.d.ts.map +1 -0
- package/dist/src/monovector/diff-classifier.js.map +1 -0
- package/dist/src/monovector/index.d.ts +61 -0
- package/dist/src/monovector/index.d.ts.map +1 -0
- package/dist/src/monovector/index.js +67 -0
- package/dist/src/monovector/index.js.map +1 -0
- package/dist/src/monovector/init-state.d.ts +35 -0
- package/dist/src/monovector/init-state.d.ts.map +1 -0
- package/dist/src/monovector/init-state.js +36 -0
- package/dist/src/monovector/init-state.js.map +1 -0
- package/dist/src/monovector/route-outcomes.d.ts +55 -0
- package/dist/src/monovector/route-outcomes.d.ts.map +1 -0
- package/dist/src/monovector/route-outcomes.js +137 -0
- package/dist/src/monovector/route-outcomes.js.map +1 -0
- package/dist/src/parser.js +3 -3
- package/dist/src/parser.js.map +1 -1
- package/dist/src/plugins/store/discovery.d.ts.map +1 -1
- package/dist/src/plugins/store/discovery.js +0 -31
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/production/circuit-breaker.d.ts +26 -6
- package/dist/src/production/circuit-breaker.d.ts.map +1 -1
- package/dist/src/production/circuit-breaker.js.map +1 -1
- package/dist/src/production/error-handler.d.ts +55 -30
- package/dist/src/production/error-handler.d.ts.map +1 -1
- package/dist/src/production/error-handler.js.map +1 -1
- package/dist/src/production/index.d.ts +3 -20
- package/dist/src/production/index.d.ts.map +1 -1
- package/dist/src/production/index.js +3 -15
- package/dist/src/production/index.js.map +1 -1
- package/dist/src/production/monitoring.d.ts +54 -34
- package/dist/src/production/monitoring.d.ts.map +1 -1
- package/dist/src/production/monitoring.js +12 -14
- package/dist/src/production/monitoring.js.map +1 -1
- package/dist/src/production/rate-limiter.d.ts +64 -19
- package/dist/src/production/rate-limiter.d.ts.map +1 -1
- package/dist/src/production/rate-limiter.js +5 -5
- package/dist/src/production/rate-limiter.js.map +1 -1
- package/dist/src/production/retry.d.ts.map +1 -1
- package/dist/src/production/retry.js +4 -2
- package/dist/src/production/retry.js.map +1 -1
- package/dist/src/runtime/headless.d.ts +3 -3
- package/dist/src/services/claim-service.d.ts +50 -59
- package/dist/src/services/claim-service.d.ts.map +1 -1
- package/dist/src/services/claim-service.js +83 -50
- package/dist/src/services/claim-service.js.map +1 -1
- package/dist/src/services/config-file-manager.d.ts.map +1 -1
- package/dist/src/services/config-file-manager.js +8 -1
- package/dist/src/services/config-file-manager.js.map +1 -1
- package/dist/src/services/worker-daemon.d.ts.map +1 -1
- package/dist/src/services/worker-daemon.js +4 -0
- package/dist/src/services/worker-daemon.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.d.ts +1 -1
- package/dist/src/transfer/storage/gcs.d.ts +1 -1
- package/dist/src/types.d.ts +13 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/ui/collector.mjs +51 -11
- package/dist/src/ui/dashboard.html +313 -88
- package/dist/src/ui/server.mjs +163 -8
- package/dist/src/update/checker.d.ts +1 -1
- package/dist/src/update/index.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/scripts/publish-registry.ts +0 -1
- package/.claude/commands/monomind/adr.md +0 -11
- package/.claude/commands/monomind/budget.md +0 -7
- package/.claude/commands/monomind/createtask.md +0 -277
- package/.claude/commands/monomind/do.md +0 -498
- package/.claude/commands/monomind/graph-status.md +0 -7
- package/.claude/commands/monomind/help.md +0 -118
- package/.claude/commands/monomind/idea.md +0 -273
- package/.claude/commands/monomind/improve.md +0 -352
- package/.claude/commands/monomind/loops.md +0 -7
- package/.claude/commands/monomind/memory.md +0 -230
- package/.claude/commands/monomind/repeat.md +0 -257
- package/.claude/commands/monomind/review.md +0 -317
- package/.claude/commands/monomind/specialagents.md +0 -125
- package/.claude/commands/monomind/swarm.md +0 -161
- package/.claude/commands/monomind/understand.md +0 -139
- package/.claude/commands/training/README.md +0 -39
- package/.claude/commands/training/neural-patterns.md +0 -73
- package/.claude/commands/training/neural-train.md +0 -79
- package/dist/src/commands/appliance-advanced.d.ts +0 -9
- package/dist/src/commands/appliance-advanced.d.ts.map +0 -1
- package/dist/src/commands/appliance-advanced.js +0 -238
- package/dist/src/commands/appliance-advanced.js.map +0 -1
- package/dist/src/commands/appliance.d.ts +0 -8
- package/dist/src/commands/appliance.d.ts.map +0 -1
- package/dist/src/commands/appliance.js +0 -406
- package/dist/src/commands/appliance.js.map +0 -1
- package/dist/src/commands/ruvector/backup.d.ts +0 -11
- package/dist/src/commands/ruvector/backup.d.ts.map +0 -1
- package/dist/src/commands/ruvector/backup.js.map +0 -1
- package/dist/src/commands/ruvector/benchmark.d.ts +0 -11
- package/dist/src/commands/ruvector/benchmark.d.ts.map +0 -1
- package/dist/src/commands/ruvector/benchmark.js.map +0 -1
- package/dist/src/commands/ruvector/import.d.ts +0 -18
- package/dist/src/commands/ruvector/import.d.ts.map +0 -1
- package/dist/src/commands/ruvector/import.js.map +0 -1
- package/dist/src/commands/ruvector/index.d.ts.map +0 -1
- package/dist/src/commands/ruvector/index.js.map +0 -1
- package/dist/src/commands/ruvector/init.d.ts +0 -11
- package/dist/src/commands/ruvector/init.d.ts.map +0 -1
- package/dist/src/commands/ruvector/init.js.map +0 -1
- package/dist/src/commands/ruvector/migrate.d.ts +0 -11
- package/dist/src/commands/ruvector/migrate.d.ts.map +0 -1
- package/dist/src/commands/ruvector/migrate.js.map +0 -1
- package/dist/src/commands/ruvector/optimize.d.ts.map +0 -1
- package/dist/src/commands/ruvector/optimize.js.map +0 -1
- package/dist/src/commands/ruvector/setup.d.ts +0 -18
- package/dist/src/commands/ruvector/setup.d.ts.map +0 -1
- package/dist/src/commands/ruvector/setup.js.map +0 -1
- package/dist/src/commands/ruvector/status.d.ts.map +0 -1
- package/dist/src/commands/ruvector/status.js.map +0 -1
- package/dist/src/ruvector/agent-wasm.d.ts +0 -182
- package/dist/src/ruvector/agent-wasm.d.ts.map +0 -1
- package/dist/src/ruvector/agent-wasm.js +0 -316
- package/dist/src/ruvector/agent-wasm.js.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/ast-analyzer.js +0 -277
- package/dist/src/ruvector/ast-analyzer.js.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/coverage-router.js +0 -539
- package/dist/src/ruvector/coverage-router.js.map +0 -1
- package/dist/src/ruvector/coverage-tools.d.ts +0 -33
- package/dist/src/ruvector/coverage-tools.d.ts.map +0 -1
- package/dist/src/ruvector/coverage-tools.js +0 -157
- package/dist/src/ruvector/coverage-tools.js.map +0 -1
- package/dist/src/ruvector/diff-classifier.d.ts.map +0 -1
- package/dist/src/ruvector/diff-classifier.js.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/enhanced-model-router.js +0 -551
- package/dist/src/ruvector/enhanced-model-router.js.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/flash-attention.js +0 -643
- package/dist/src/ruvector/flash-attention.js.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/graph-analyzer.js +0 -929
- package/dist/src/ruvector/graph-analyzer.js.map +0 -1
- package/dist/src/ruvector/index.d.ts +0 -56
- package/dist/src/ruvector/index.d.ts.map +0 -1
- package/dist/src/ruvector/index.js +0 -58
- package/dist/src/ruvector/index.js.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/lora-adapter.js +0 -455
- package/dist/src/ruvector/lora-adapter.js.map +0 -1
- package/dist/src/ruvector/model-router.d.ts +0 -222
- package/dist/src/ruvector/model-router.d.ts.map +0 -1
- package/dist/src/ruvector/model-router.js +0 -512
- package/dist/src/ruvector/model-router.js.map +0 -1
- package/dist/src/ruvector/moe-router.d.ts +0 -213
- package/dist/src/ruvector/moe-router.d.ts.map +0 -1
- package/dist/src/ruvector/moe-router.js +0 -649
- package/dist/src/ruvector/moe-router.js.map +0 -1
- package/dist/src/ruvector/q-learning-router.d.ts +0 -217
- package/dist/src/ruvector/q-learning-router.d.ts.map +0 -1
- package/dist/src/ruvector/q-learning-router.js +0 -712
- package/dist/src/ruvector/q-learning-router.js.map +0 -1
- package/dist/src/ruvector/ruvllm-wasm.d.ts +0 -179
- package/dist/src/ruvector/ruvllm-wasm.d.ts.map +0 -1
- package/dist/src/ruvector/ruvllm-wasm.js +0 -363
- package/dist/src/ruvector/ruvllm-wasm.js.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/semantic-router.js +0 -178
- package/dist/src/ruvector/semantic-router.js.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/ruvector/vector-db.js +0 -243
- package/dist/src/ruvector/vector-db.js.map +0 -1
- package/dist/src/services/ruvector-training.d.ts +0 -222
- package/dist/src/services/ruvector-training.d.ts.map +0 -1
- package/dist/src/services/ruvector-training.js +0 -696
- package/dist/src/services/ruvector-training.js.map +0 -1
- package/dist/src/ui/.monomind/loops/loop-1779095996252-mdjpp.json +0 -11
- package/dist/src/ui/data/agent-avatars.html +0 -763
- package/dist/src/ui/data/agent-avatars.json +0 -966
- package/dist/src/ui/data/avatars/account-strategist.svg +0 -58
- package/dist/src/ui/data/avatars/accounts-payable.svg +0 -54
- package/dist/src/ui/data/avatars/adaptive-coordinator.svg +0 -55
- package/dist/src/ui/data/avatars/adaptive-coordinator2.svg +0 -54
- package/dist/src/ui/data/avatars/ai-citation.svg +0 -57
- package/dist/src/ui/data/avatars/ai-engineer.svg +0 -61
- package/dist/src/ui/data/avatars/analytics-reporter.svg +0 -53
- package/dist/src/ui/data/avatars/api-tester.svg +0 -53
- package/dist/src/ui/data/avatars/architecture.svg +0 -54
- package/dist/src/ui/data/avatars/automation-governance.svg +0 -55
- package/dist/src/ui/data/avatars/backend-dev.svg +0 -53
- package/dist/src/ui/data/avatars/benchmarker.svg +0 -54
- package/dist/src/ui/data/avatars/blockchain-auditor.svg +0 -53
- package/dist/src/ui/data/avatars/byzantine-coord.svg +0 -57
- package/dist/src/ui/data/avatars/case-analyst.svg +0 -57
- package/dist/src/ui/data/avatars/cicd-engineer.svg +0 -55
- package/dist/src/ui/data/avatars/cloud-architect.svg +0 -54
- package/dist/src/ui/data/avatars/code-review-swarm.svg +0 -57
- package/dist/src/ui/data/avatars/coder-v119.svg +0 -57
- package/dist/src/ui/data/avatars/coder.svg +0 -58
- package/dist/src/ui/data/avatars/collective-coord.svg +0 -54
- package/dist/src/ui/data/avatars/compliance-auditor.svg +0 -58
- package/dist/src/ui/data/avatars/consensus-coordinator.svg +0 -54
- package/dist/src/ui/data/avatars/content-creator.svg +0 -54
- package/dist/src/ui/data/avatars/crdt-synchronizer.svg +0 -53
- package/dist/src/ui/data/avatars/cro-specialist.svg +0 -58
- package/dist/src/ui/data/avatars/data-consolidator.svg +0 -54
- package/dist/src/ui/data/avatars/data-engineer.svg +0 -53
- package/dist/src/ui/data/avatars/database-optimizer.svg +0 -61
- package/dist/src/ui/data/avatars/deal-strategist.svg +0 -54
- package/dist/src/ui/data/avatars/defender.svg +0 -53
- package/dist/src/ui/data/avatars/devops-automator.svg +0 -56
- package/dist/src/ui/data/avatars/discovery-coach.svg +0 -54
- package/dist/src/ui/data/avatars/email-marketing.svg +0 -57
- package/dist/src/ui/data/avatars/embedded-firmware.svg +0 -61
- package/dist/src/ui/data/avatars/evidence-collector.svg +0 -57
- package/dist/src/ui/data/avatars/experiment-tracker.svg +0 -53
- package/dist/src/ui/data/avatars/feedback-synthesizer.svg +0 -54
- package/dist/src/ui/data/avatars/finance-tracker.svg +0 -54
- package/dist/src/ui/data/avatars/frontend-developer.svg +0 -54
- package/dist/src/ui/data/avatars/game-audio-engineer.svg +0 -59
- package/dist/src/ui/data/avatars/game-designer.svg +0 -54
- package/dist/src/ui/data/avatars/gossip-coordinator.svg +0 -54
- package/dist/src/ui/data/avatars/hierarchical-coord.svg +0 -54
- package/dist/src/ui/data/avatars/incident-commander.svg +0 -57
- package/dist/src/ui/data/avatars/infrastructure.svg +0 -54
- package/dist/src/ui/data/avatars/input-validator.svg +0 -53
- package/dist/src/ui/data/avatars/ios-developer.svg +0 -54
- package/dist/src/ui/data/avatars/issue-tracker.svg +0 -53
- package/dist/src/ui/data/avatars/judge.svg +0 -55
- package/dist/src/ui/data/avatars/launch-strategist.svg +0 -54
- package/dist/src/ui/data/avatars/legal-compliance.svg +0 -53
- package/dist/src/ui/data/avatars/level-designer.svg +0 -53
- package/dist/src/ui/data/avatars/load-balancer.svg +0 -57
- package/dist/src/ui/data/avatars/mcp-builder.svg +0 -53
- package/dist/src/ui/data/avatars/memory-coordinator.svg +0 -55
- package/dist/src/ui/data/avatars/mesh-coordinator.svg +0 -55
- package/dist/src/ui/data/avatars/ml-developer.svg +0 -58
- package/dist/src/ui/data/avatars/mobile-app-builder.svg +0 -53
- package/dist/src/ui/data/avatars/mobile-dev.svg +0 -54
- package/dist/src/ui/data/avatars/model-qa.svg +0 -58
- package/dist/src/ui/data/avatars/narrative-designer.svg +0 -58
- package/dist/src/ui/data/avatars/outbound-strategist.svg +0 -55
- package/dist/src/ui/data/avatars/path-validator.svg +0 -54
- package/dist/src/ui/data/avatars/payment-agent.svg +0 -53
- package/dist/src/ui/data/avatars/perf-analyzer.svg +0 -58
- package/dist/src/ui/data/avatars/pipeline-analyst.svg +0 -54
- package/dist/src/ui/data/avatars/planner.svg +0 -55
- package/dist/src/ui/data/avatars/pr-manager.svg +0 -54
- package/dist/src/ui/data/avatars/pricing-strategist.svg +0 -54
- package/dist/src/ui/data/avatars/product-manager.svg +0 -54
- package/dist/src/ui/data/avatars/production-validator.svg +0 -54
- package/dist/src/ui/data/avatars/project-shepherd.svg +0 -54
- package/dist/src/ui/data/avatars/proposal-strategist.svg +0 -54
- package/dist/src/ui/data/avatars/prosecutor.svg +0 -57
- package/dist/src/ui/data/avatars/pseudocode.svg +0 -53
- package/dist/src/ui/data/avatars/queen-coordinator.svg +0 -55
- package/dist/src/ui/data/avatars/quorum-manager.svg +0 -53
- package/dist/src/ui/data/avatars/raft-manager.svg +0 -53
- package/dist/src/ui/data/avatars/reality-checker.svg +0 -58
- package/dist/src/ui/data/avatars/recruitment.svg +0 -58
- package/dist/src/ui/data/avatars/refinement.svg +0 -53
- package/dist/src/ui/data/avatars/release-manager.svg +0 -54
- package/dist/src/ui/data/avatars/repo-architect.svg +0 -54
- package/dist/src/ui/data/avatars/researcher.svg +0 -58
- package/dist/src/ui/data/avatars/resource-allocator.svg +0 -53
- package/dist/src/ui/data/avatars/reviewer.svg +0 -53
- package/dist/src/ui/data/avatars/safe-executor.svg +0 -53
- package/dist/src/ui/data/avatars/sales-coach.svg +0 -53
- package/dist/src/ui/data/avatars/sales-engineer.svg +0 -58
- package/dist/src/ui/data/avatars/scout-explorer.svg +0 -58
- package/dist/src/ui/data/avatars/security-architect.svg +0 -54
- package/dist/src/ui/data/avatars/security-auditor.svg +0 -55
- package/dist/src/ui/data/avatars/senior-developer.svg +0 -58
- package/dist/src/ui/data/avatars/senior-pm.svg +0 -58
- package/dist/src/ui/data/avatars/seo-specialist.svg +0 -57
- package/dist/src/ui/data/avatars/social-media.svg +0 -54
- package/dist/src/ui/data/avatars/solidity-engineer.svg +0 -58
- package/dist/src/ui/data/avatars/sparc-coder.svg +0 -58
- package/dist/src/ui/data/avatars/sparc-coord.svg +0 -56
- package/dist/src/ui/data/avatars/specification.svg +0 -57
- package/dist/src/ui/data/avatars/sprint-prioritizer.svg +0 -53
- package/dist/src/ui/data/avatars/sre.svg +0 -54
- package/dist/src/ui/data/avatars/studio-operations.svg +0 -53
- package/dist/src/ui/data/avatars/studio-producer.svg +0 -55
- package/dist/src/ui/data/avatars/support-responder.svg +0 -56
- package/dist/src/ui/data/avatars/system-architect.svg +0 -54
- package/dist/src/ui/data/avatars/task-orchestrator.svg +0 -56
- package/dist/src/ui/data/avatars/technical-artist.svg +0 -53
- package/dist/src/ui/data/avatars/technical-writer.svg +0 -59
- package/dist/src/ui/data/avatars/tester.svg +0 -53
- package/dist/src/ui/data/avatars/threat-detection.svg +0 -61
- package/dist/src/ui/data/avatars/trend-researcher.svg +0 -54
- package/dist/src/ui/data/avatars/trial-director.svg +0 -55
- package/dist/src/ui/data/avatars/unity-architect.svg +0 -54
- package/dist/src/ui/data/avatars/visionos-engineer.svg +0 -57
- package/dist/src/ui/data/avatars/worker-specialist.svg +0 -55
- package/dist/src/ui/data/avatars/workflow-architect.svg +0 -57
- package/dist/src/ui/data/avatars/workflow-automation.svg +0 -54
- package/dist/src/ui/data/avatars/zk-steward.svg +0 -54
- package/dist/src/ui/data/known-projects.json +0 -1
- /package/dist/src/{ruvector → monovector}/diff-classifier.js +0 -0
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Q-Learning Router for Task Routing
|
|
3
|
-
*
|
|
4
|
-
* Uses reinforcement learning to optimize task routing decisions
|
|
5
|
-
* based on historical performance and context.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Caching for repeated task patterns (LRU cache)
|
|
9
|
-
* - Optimized state space with feature hashing
|
|
10
|
-
* - Epsilon decay with exponential annealing
|
|
11
|
-
* - Experience replay buffer for stable learning
|
|
12
|
-
* - Model persistence to .swarm/q-learning-model.json
|
|
13
|
-
*
|
|
14
|
-
* @module q-learning-router
|
|
15
|
-
*/
|
|
16
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, statSync } from 'fs';
|
|
17
|
-
import { dirname, join } from 'path';
|
|
18
|
-
/**
|
|
19
|
-
* Default configuration
|
|
20
|
-
*/
|
|
21
|
-
const DEFAULT_CONFIG = {
|
|
22
|
-
learningRate: 0.1,
|
|
23
|
-
gamma: 0.99,
|
|
24
|
-
explorationInitial: 1.0,
|
|
25
|
-
explorationFinal: 0.01,
|
|
26
|
-
explorationDecay: 10000,
|
|
27
|
-
explorationDecayType: 'exponential',
|
|
28
|
-
maxStates: 10000,
|
|
29
|
-
numActions: 8,
|
|
30
|
-
replayBufferSize: 1000,
|
|
31
|
-
replayBatchSize: 32,
|
|
32
|
-
enableReplay: true,
|
|
33
|
-
cacheSize: 256,
|
|
34
|
-
cacheTTL: 300000,
|
|
35
|
-
modelPath: '.swarm/q-learning-model.json',
|
|
36
|
-
autoSaveInterval: 100,
|
|
37
|
-
stateSpaceDim: 64,
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Route names mapping
|
|
41
|
-
*/
|
|
42
|
-
const ROUTE_NAMES = [
|
|
43
|
-
'coder',
|
|
44
|
-
'tester',
|
|
45
|
-
'reviewer',
|
|
46
|
-
'architect',
|
|
47
|
-
'researcher',
|
|
48
|
-
'optimizer',
|
|
49
|
-
'debugger',
|
|
50
|
-
'documenter',
|
|
51
|
-
];
|
|
52
|
-
/**
|
|
53
|
-
* Task feature keywords for state representation
|
|
54
|
-
*/
|
|
55
|
-
const FEATURE_KEYWORDS = [
|
|
56
|
-
// Code-related
|
|
57
|
-
'implement', 'code', 'write', 'create', 'build', 'develop',
|
|
58
|
-
// Testing-related
|
|
59
|
-
'test', 'spec', 'coverage', 'unit', 'integration', 'e2e',
|
|
60
|
-
// Review-related
|
|
61
|
-
'review', 'check', 'audit', 'analyze', 'inspect',
|
|
62
|
-
// Architecture-related
|
|
63
|
-
'architect', 'design', 'structure', 'pattern', 'system',
|
|
64
|
-
// Research-related
|
|
65
|
-
'research', 'investigate', 'explore', 'find', 'search',
|
|
66
|
-
// Optimization-related
|
|
67
|
-
'optimize', 'performance', 'speed', 'memory', 'improve',
|
|
68
|
-
// Debug-related
|
|
69
|
-
'debug', 'fix', 'bug', 'error', 'issue', 'problem',
|
|
70
|
-
// Documentation-related
|
|
71
|
-
'document', 'docs', 'readme', 'comment', 'explain',
|
|
72
|
-
];
|
|
73
|
-
/**
|
|
74
|
-
* Q-Learning Router for intelligent task routing
|
|
75
|
-
*
|
|
76
|
-
* Optimized with:
|
|
77
|
-
* - LRU cache for repeated task patterns
|
|
78
|
-
* - Feature hashing for efficient state space
|
|
79
|
-
* - Exponential epsilon decay
|
|
80
|
-
* - Prioritized experience replay
|
|
81
|
-
* - Model persistence
|
|
82
|
-
*/
|
|
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 };
|
|
105
|
-
this.epsilon = this.config.explorationInitial;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Initialize the router, attempting to load ruvector native module
|
|
109
|
-
* and restore persisted model if available
|
|
110
|
-
*/
|
|
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
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Load model from persistence file
|
|
126
|
-
*/
|
|
127
|
-
async loadModel(path) {
|
|
128
|
-
const modelPath = path ? path : join(process.cwd(), this.config.modelPath);
|
|
129
|
-
try {
|
|
130
|
-
if (!existsSync(modelPath)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
const MAX_MODEL_SIZE = 20 * 1024 * 1024; // 20 MB
|
|
134
|
-
const st = statSync(modelPath, { throwIfNoEntry: false });
|
|
135
|
-
if (!st || st.size > MAX_MODEL_SIZE)
|
|
136
|
-
return false;
|
|
137
|
-
const data = readFileSync(modelPath, 'utf-8');
|
|
138
|
-
const model = JSON.parse(data);
|
|
139
|
-
// Validate version compatibility
|
|
140
|
-
if (!model.version || !model.version.startsWith('1.')) {
|
|
141
|
-
console.warn(`[Q-Learning] Incompatible model version: ${model.version}`);
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
// Import Q-table
|
|
145
|
-
this.import(model.qTable);
|
|
146
|
-
// Restore stats
|
|
147
|
-
this.stepCount = model.stats.stepCount || 0;
|
|
148
|
-
this.updateCount = model.stats.updateCount || 0;
|
|
149
|
-
this.avgTDError = model.stats.avgTDError || 0;
|
|
150
|
-
this.epsilon = model.stats.epsilon || this.config.explorationInitial;
|
|
151
|
-
this.totalExperiences = model.metadata?.totalExperiences || 0;
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
console.warn(`[Q-Learning] Failed to load model: ${err}`);
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Save model to persistence file
|
|
161
|
-
*/
|
|
162
|
-
async saveModel(path) {
|
|
163
|
-
const modelPath = path ? path : join(process.cwd(), this.config.modelPath);
|
|
164
|
-
try {
|
|
165
|
-
// Ensure directory exists
|
|
166
|
-
const dir = dirname(modelPath);
|
|
167
|
-
if (!existsSync(dir)) {
|
|
168
|
-
mkdirSync(dir, { recursive: true });
|
|
169
|
-
}
|
|
170
|
-
const model = {
|
|
171
|
-
version: '1.0.0',
|
|
172
|
-
config: {
|
|
173
|
-
learningRate: this.config.learningRate,
|
|
174
|
-
gamma: this.config.gamma,
|
|
175
|
-
explorationDecayType: this.config.explorationDecayType,
|
|
176
|
-
numActions: this.config.numActions,
|
|
177
|
-
},
|
|
178
|
-
qTable: this.export(),
|
|
179
|
-
stats: {
|
|
180
|
-
stepCount: this.stepCount,
|
|
181
|
-
updateCount: this.updateCount,
|
|
182
|
-
avgTDError: this.avgTDError,
|
|
183
|
-
epsilon: this.epsilon,
|
|
184
|
-
},
|
|
185
|
-
metadata: {
|
|
186
|
-
savedAt: new Date().toISOString(),
|
|
187
|
-
totalExperiences: this.totalExperiences,
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
const tmp = modelPath + '.tmp';
|
|
191
|
-
writeFileSync(tmp, JSON.stringify(model, null, 2));
|
|
192
|
-
renameSync(tmp, modelPath);
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
catch (err) {
|
|
196
|
-
console.warn(`[Q-Learning] Failed to save model: ${err}`);
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Route a task based on its context
|
|
202
|
-
* Uses LRU cache for repeated task patterns
|
|
203
|
-
*/
|
|
204
|
-
route(taskContext, explore = true) {
|
|
205
|
-
const stateKey = this.hashStateOptimized(taskContext);
|
|
206
|
-
// Check if we should explore using decayed epsilon
|
|
207
|
-
const shouldExplore = explore && Math.random() < this.epsilon;
|
|
208
|
-
// Check cache first (only for exploitation, not exploration)
|
|
209
|
-
if (!shouldExplore) {
|
|
210
|
-
const cached = this.getCachedRoute(stateKey);
|
|
211
|
-
if (cached) {
|
|
212
|
-
this.cacheHits++;
|
|
213
|
-
return cached;
|
|
214
|
-
}
|
|
215
|
-
this.cacheMisses++;
|
|
216
|
-
}
|
|
217
|
-
let actionIdx;
|
|
218
|
-
let qValues;
|
|
219
|
-
if (shouldExplore) {
|
|
220
|
-
// Random exploration
|
|
221
|
-
actionIdx = Math.floor(Math.random() * this.config.numActions);
|
|
222
|
-
qValues = this.getQValues(stateKey);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
// Exploit - choose best action
|
|
226
|
-
qValues = this.getQValues(stateKey);
|
|
227
|
-
actionIdx = this.argmax(qValues);
|
|
228
|
-
}
|
|
229
|
-
// Calculate confidence from softmax of Q-values
|
|
230
|
-
const confidence = this.softmaxConfidence(qValues, actionIdx);
|
|
231
|
-
// Get alternatives sorted by Q-value
|
|
232
|
-
const alternatives = ROUTE_NAMES
|
|
233
|
-
.map((route, idx) => ({ route, score: qValues[idx] }))
|
|
234
|
-
.sort((a, b) => b.score - a.score)
|
|
235
|
-
.slice(1, 4); // Top 3 alternatives
|
|
236
|
-
const decision = {
|
|
237
|
-
route: ROUTE_NAMES[actionIdx] || 'coder',
|
|
238
|
-
confidence,
|
|
239
|
-
qValues,
|
|
240
|
-
explored: shouldExplore,
|
|
241
|
-
alternatives,
|
|
242
|
-
};
|
|
243
|
-
// Cache the decision for exploitation queries
|
|
244
|
-
if (!shouldExplore) {
|
|
245
|
-
this.cacheRoute(stateKey, decision);
|
|
246
|
-
}
|
|
247
|
-
return decision;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Get cached route decision (LRU cache)
|
|
251
|
-
*/
|
|
252
|
-
getCachedRoute(stateKey) {
|
|
253
|
-
const entry = this.routeCache.get(stateKey);
|
|
254
|
-
if (!entry) {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
// Check TTL
|
|
258
|
-
if (Date.now() - entry.timestamp > this.config.cacheTTL) {
|
|
259
|
-
this.routeCache.delete(stateKey);
|
|
260
|
-
this.cacheOrder = this.cacheOrder.filter(k => k !== stateKey);
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
// Update LRU order
|
|
264
|
-
this.cacheOrder = this.cacheOrder.filter(k => k !== stateKey);
|
|
265
|
-
this.cacheOrder.push(stateKey);
|
|
266
|
-
entry.hits++;
|
|
267
|
-
return entry.decision;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Cache a route decision (LRU eviction)
|
|
271
|
-
*/
|
|
272
|
-
cacheRoute(stateKey, decision) {
|
|
273
|
-
// Evict oldest if cache is full
|
|
274
|
-
while (this.routeCache.size >= this.config.cacheSize && this.cacheOrder.length > 0) {
|
|
275
|
-
const oldest = this.cacheOrder.shift();
|
|
276
|
-
if (oldest) {
|
|
277
|
-
this.routeCache.delete(oldest);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
this.routeCache.set(stateKey, {
|
|
281
|
-
decision,
|
|
282
|
-
timestamp: Date.now(),
|
|
283
|
-
hits: 0,
|
|
284
|
-
});
|
|
285
|
-
this.cacheOrder.push(stateKey);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Invalidate cache (call after significant Q-table updates)
|
|
289
|
-
*/
|
|
290
|
-
invalidateCache() {
|
|
291
|
-
this.routeCache.clear();
|
|
292
|
-
this.cacheOrder = [];
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Update Q-values based on feedback
|
|
296
|
-
* Includes experience replay for stable learning
|
|
297
|
-
*/
|
|
298
|
-
update(taskContext, action, reward, nextContext) {
|
|
299
|
-
const stateKey = this.hashStateOptimized(taskContext);
|
|
300
|
-
const actionIdx = ROUTE_NAMES.indexOf(action);
|
|
301
|
-
if (actionIdx === -1) {
|
|
302
|
-
return 0;
|
|
303
|
-
}
|
|
304
|
-
const nextStateKey = nextContext ? this.hashStateOptimized(nextContext) : null;
|
|
305
|
-
// Store experience in replay buffer
|
|
306
|
-
if (this.config.enableReplay) {
|
|
307
|
-
const experience = {
|
|
308
|
-
stateKey,
|
|
309
|
-
actionIdx,
|
|
310
|
-
reward,
|
|
311
|
-
nextStateKey,
|
|
312
|
-
timestamp: Date.now(),
|
|
313
|
-
priority: Math.abs(reward) + 0.1, // Initial priority based on reward magnitude
|
|
314
|
-
};
|
|
315
|
-
this.addToReplayBuffer(experience);
|
|
316
|
-
}
|
|
317
|
-
// Perform direct update
|
|
318
|
-
const tdError = this.updateQValue(stateKey, actionIdx, reward, nextStateKey);
|
|
319
|
-
// Perform experience replay
|
|
320
|
-
if (this.config.enableReplay && this.replayBuffer.length >= this.config.replayBatchSize) {
|
|
321
|
-
this.experienceReplay();
|
|
322
|
-
}
|
|
323
|
-
// Decay exploration using configured strategy
|
|
324
|
-
this.stepCount++;
|
|
325
|
-
this.epsilon = this.calculateEpsilon();
|
|
326
|
-
// Prune Q-table if needed
|
|
327
|
-
if (this.qTable.size > this.config.maxStates) {
|
|
328
|
-
this.pruneQTable();
|
|
329
|
-
}
|
|
330
|
-
this.updateCount++;
|
|
331
|
-
this.avgTDError = (this.avgTDError * (this.updateCount - 1) + Math.abs(tdError)) / this.updateCount;
|
|
332
|
-
// Auto-save periodically
|
|
333
|
-
if (this.config.autoSaveInterval > 0 && this.updateCount % this.config.autoSaveInterval === 0) {
|
|
334
|
-
this.saveModel().catch(() => { }); // Fire and forget
|
|
335
|
-
}
|
|
336
|
-
// Invalidate cache periodically to reflect Q-table changes
|
|
337
|
-
if (this.updateCount % 50 === 0) {
|
|
338
|
-
this.invalidateCache();
|
|
339
|
-
}
|
|
340
|
-
return tdError;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Internal Q-value update
|
|
344
|
-
*/
|
|
345
|
-
updateQValue(stateKey, actionIdx, reward, nextStateKey) {
|
|
346
|
-
const entry = this.getOrCreateEntry(stateKey);
|
|
347
|
-
const currentQ = entry.qValues[actionIdx];
|
|
348
|
-
// Calculate target Q-value
|
|
349
|
-
let targetQ;
|
|
350
|
-
if (nextStateKey) {
|
|
351
|
-
const nextQValues = this.getQValues(nextStateKey);
|
|
352
|
-
const maxNextQ = Math.max(...nextQValues);
|
|
353
|
-
targetQ = reward + this.config.gamma * maxNextQ;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
// Terminal state
|
|
357
|
-
targetQ = reward;
|
|
358
|
-
}
|
|
359
|
-
// TD error
|
|
360
|
-
const tdError = targetQ - currentQ;
|
|
361
|
-
// Update Q-value
|
|
362
|
-
entry.qValues[actionIdx] += this.config.learningRate * tdError;
|
|
363
|
-
entry.visits++;
|
|
364
|
-
entry.lastUpdate = Date.now();
|
|
365
|
-
return tdError;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Add experience to circular replay buffer
|
|
369
|
-
*/
|
|
370
|
-
addToReplayBuffer(experience) {
|
|
371
|
-
if (this.replayBuffer.length < this.config.replayBufferSize) {
|
|
372
|
-
this.replayBuffer.push(experience);
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
this.replayBuffer[this.replayBufferIdx] = experience;
|
|
376
|
-
}
|
|
377
|
-
this.replayBufferIdx = (this.replayBufferIdx + 1) % this.config.replayBufferSize;
|
|
378
|
-
this.totalExperiences++;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Perform prioritized experience replay
|
|
382
|
-
* Samples mini-batch from buffer and updates Q-values
|
|
383
|
-
*/
|
|
384
|
-
experienceReplay() {
|
|
385
|
-
if (this.replayBuffer.length < this.config.replayBatchSize) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
// Prioritized sampling based on TD error magnitude
|
|
389
|
-
const batch = this.samplePrioritizedBatch(this.config.replayBatchSize);
|
|
390
|
-
for (const exp of batch) {
|
|
391
|
-
const tdError = this.updateQValue(exp.stateKey, exp.actionIdx, exp.reward, exp.nextStateKey);
|
|
392
|
-
// Update priority for future sampling
|
|
393
|
-
exp.priority = Math.abs(tdError) + 0.01; // Small constant to avoid zero priority
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Sample a prioritized batch from replay buffer
|
|
398
|
-
* Uses proportional prioritization
|
|
399
|
-
*/
|
|
400
|
-
samplePrioritizedBatch(batchSize) {
|
|
401
|
-
const totalPriority = this.replayBuffer.reduce((sum, exp) => sum + exp.priority, 0);
|
|
402
|
-
const batch = [];
|
|
403
|
-
const selected = new Set();
|
|
404
|
-
while (batch.length < batchSize && selected.size < this.replayBuffer.length) {
|
|
405
|
-
let threshold = Math.random() * totalPriority;
|
|
406
|
-
let cumSum = 0;
|
|
407
|
-
const prevLen = batch.length;
|
|
408
|
-
for (let i = 0; i < this.replayBuffer.length; i++) {
|
|
409
|
-
if (selected.has(i))
|
|
410
|
-
continue;
|
|
411
|
-
cumSum += this.replayBuffer[i].priority;
|
|
412
|
-
if (cumSum >= threshold) {
|
|
413
|
-
batch.push(this.replayBuffer[i]);
|
|
414
|
-
selected.add(i);
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
if (batch.length === prevLen)
|
|
419
|
-
break; // nothing was selectable, exit
|
|
420
|
-
}
|
|
421
|
-
return batch;
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Calculate epsilon using configured decay strategy
|
|
425
|
-
*/
|
|
426
|
-
calculateEpsilon() {
|
|
427
|
-
const { explorationInitial, explorationFinal, explorationDecay, explorationDecayType } = this.config;
|
|
428
|
-
const progress = Math.min(this.stepCount / explorationDecay, 1.0);
|
|
429
|
-
switch (explorationDecayType) {
|
|
430
|
-
case 'linear':
|
|
431
|
-
return explorationFinal + (explorationInitial - explorationFinal) * (1 - progress);
|
|
432
|
-
case 'exponential':
|
|
433
|
-
// Exponential decay: epsilon = final + (initial - final) * exp(-decay_rate * step)
|
|
434
|
-
const decayRate = -Math.log((explorationFinal / explorationInitial) + 1e-8) / explorationDecay;
|
|
435
|
-
return explorationFinal + (explorationInitial - explorationFinal) * Math.exp(-decayRate * this.stepCount);
|
|
436
|
-
case 'cosine':
|
|
437
|
-
// Cosine annealing: smooth transition
|
|
438
|
-
return explorationFinal + (explorationInitial - explorationFinal) * 0.5 * (1 + Math.cos(Math.PI * progress));
|
|
439
|
-
default:
|
|
440
|
-
return Math.max(explorationFinal, explorationInitial - this.stepCount / explorationDecay);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Get statistics including cache and replay buffer metrics
|
|
445
|
-
*/
|
|
446
|
-
getStats() {
|
|
447
|
-
const cacheHitRate = this.cacheHits + this.cacheMisses > 0
|
|
448
|
-
? this.cacheHits / (this.cacheHits + this.cacheMisses)
|
|
449
|
-
: 0;
|
|
450
|
-
return {
|
|
451
|
-
updateCount: this.updateCount,
|
|
452
|
-
qTableSize: this.qTable.size,
|
|
453
|
-
epsilon: this.epsilon,
|
|
454
|
-
avgTDError: this.avgTDError,
|
|
455
|
-
stepCount: this.stepCount,
|
|
456
|
-
useNative: this.useNative ? 1 : 0,
|
|
457
|
-
// Cache metrics
|
|
458
|
-
cacheSize: this.routeCache.size,
|
|
459
|
-
cacheHits: this.cacheHits,
|
|
460
|
-
cacheMisses: this.cacheMisses,
|
|
461
|
-
cacheHitRate,
|
|
462
|
-
// Replay buffer metrics
|
|
463
|
-
replayBufferSize: this.replayBuffer.length,
|
|
464
|
-
totalExperiences: this.totalExperiences,
|
|
465
|
-
// Feature hash cache
|
|
466
|
-
featureHashCacheSize: this.featureHashCache.size,
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Reset the router (clears all learned data)
|
|
471
|
-
*/
|
|
472
|
-
reset() {
|
|
473
|
-
this.qTable.clear();
|
|
474
|
-
this.epsilon = this.config.explorationInitial;
|
|
475
|
-
this.stepCount = 0;
|
|
476
|
-
this.updateCount = 0;
|
|
477
|
-
this.avgTDError = 0;
|
|
478
|
-
// Reset replay buffer
|
|
479
|
-
this.replayBuffer = [];
|
|
480
|
-
this.replayBufferIdx = 0;
|
|
481
|
-
this.totalExperiences = 0;
|
|
482
|
-
// Reset cache
|
|
483
|
-
this.routeCache.clear();
|
|
484
|
-
this.cacheOrder = [];
|
|
485
|
-
this.cacheHits = 0;
|
|
486
|
-
this.cacheMisses = 0;
|
|
487
|
-
// Reset feature hash cache
|
|
488
|
-
this.featureHashCache.clear();
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Export Q-table for persistence
|
|
492
|
-
*/
|
|
493
|
-
export() {
|
|
494
|
-
const result = {};
|
|
495
|
-
for (const [key, entry] of this.qTable) {
|
|
496
|
-
result[key] = {
|
|
497
|
-
qValues: Array.from(entry.qValues),
|
|
498
|
-
visits: entry.visits,
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
return result;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Import Q-table from persistence with strict validation.
|
|
505
|
-
* SECURITY: a poisoned `.swarm/q-table.json` (co-located process write,
|
|
506
|
-
* malicious test fixture) with `qValues: [Infinity, ...]` would otherwise
|
|
507
|
-
* propagate NaN/Infinity through every argmax + Q-update — the attacker
|
|
508
|
-
* deterministically chooses every routing decision. Mirror the
|
|
509
|
-
* ewc-consolidation.ts:loadFromDisk pattern: per-field shape + finite-numeric
|
|
510
|
-
* + dimension check, drop bad records silently.
|
|
511
|
-
*/
|
|
512
|
-
import(data) {
|
|
513
|
-
this.qTable.clear();
|
|
514
|
-
if (!data || typeof data !== 'object')
|
|
515
|
-
return;
|
|
516
|
-
let imported = 0;
|
|
517
|
-
for (const [key, entry] of Object.entries(data)) {
|
|
518
|
-
if (imported >= this.config.maxStates)
|
|
519
|
-
break;
|
|
520
|
-
if (typeof key !== 'string' || key.length === 0 || key.length > 256)
|
|
521
|
-
continue;
|
|
522
|
-
if (!entry || typeof entry !== 'object' || !Array.isArray(entry.qValues))
|
|
523
|
-
continue;
|
|
524
|
-
if (entry.qValues.length !== this.config.numActions)
|
|
525
|
-
continue;
|
|
526
|
-
if (!entry.qValues.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
527
|
-
continue;
|
|
528
|
-
if (typeof entry.visits !== 'number' || !Number.isFinite(entry.visits) || entry.visits < 0)
|
|
529
|
-
continue;
|
|
530
|
-
this.qTable.set(key, {
|
|
531
|
-
qValues: new Float32Array(entry.qValues),
|
|
532
|
-
visits: entry.visits,
|
|
533
|
-
lastUpdate: Date.now(),
|
|
534
|
-
});
|
|
535
|
-
imported++;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
// Private methods
|
|
539
|
-
/**
|
|
540
|
-
* Legacy hash function (kept for backward compatibility)
|
|
541
|
-
*/
|
|
542
|
-
hashState(context) {
|
|
543
|
-
// Simple hash for context string
|
|
544
|
-
let hash = 0;
|
|
545
|
-
for (let i = 0; i < context.length; i++) {
|
|
546
|
-
const char = context.charCodeAt(i);
|
|
547
|
-
hash = ((hash << 5) - hash) + char;
|
|
548
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
549
|
-
}
|
|
550
|
-
return `state_${hash}`;
|
|
551
|
-
}
|
|
552
|
-
/**
|
|
553
|
-
* Optimized state hashing using feature extraction
|
|
554
|
-
* Creates a more semantic representation of the task context
|
|
555
|
-
*/
|
|
556
|
-
hashStateOptimized(context) {
|
|
557
|
-
// Check feature hash cache first
|
|
558
|
-
if (this.featureHashCache.has(context)) {
|
|
559
|
-
const cached = this.featureHashCache.get(context);
|
|
560
|
-
return this.featureVectorToKey(cached);
|
|
561
|
-
}
|
|
562
|
-
// Extract features from context
|
|
563
|
-
const features = this.extractFeatures(context);
|
|
564
|
-
// Cache the feature vector
|
|
565
|
-
if (this.featureHashCache.size < 1000) { // Limit cache size
|
|
566
|
-
this.featureHashCache.set(context, features);
|
|
567
|
-
}
|
|
568
|
-
return this.featureVectorToKey(features);
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Extract feature vector from task context
|
|
572
|
-
* Uses keyword matching and n-gram hashing
|
|
573
|
-
*/
|
|
574
|
-
extractFeatures(context) {
|
|
575
|
-
const features = new Float32Array(this.config.stateSpaceDim);
|
|
576
|
-
const lowerContext = context.toLowerCase();
|
|
577
|
-
const words = lowerContext.split(/\s+/);
|
|
578
|
-
// Feature 1-32: Keyword presence (binary features)
|
|
579
|
-
for (let i = 0; i < FEATURE_KEYWORDS.length && i < 32; i++) {
|
|
580
|
-
if (lowerContext.includes(FEATURE_KEYWORDS[i])) {
|
|
581
|
-
features[i] = 1.0;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
// Feature 33-40: Context length buckets
|
|
585
|
-
const lengthBucket = Math.min(Math.floor(context.length / 50), 7);
|
|
586
|
-
features[32 + lengthBucket] = 1.0;
|
|
587
|
-
// Feature 41-48: Word count buckets
|
|
588
|
-
const wordBucket = Math.min(Math.floor(words.length / 5), 7);
|
|
589
|
-
features[40 + wordBucket] = 1.0;
|
|
590
|
-
// Feature 49-56: File extension hints
|
|
591
|
-
const extPatterns = ['.ts', '.js', '.py', '.go', '.rs', '.java', '.md', '.json'];
|
|
592
|
-
for (let i = 0; i < extPatterns.length; i++) {
|
|
593
|
-
if (lowerContext.includes(extPatterns[i])) {
|
|
594
|
-
features[48 + i] = 1.0;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
// Feature 57-64: N-gram hash features (for capturing unique patterns)
|
|
598
|
-
for (let i = 0; i < words.length - 1 && i < 8; i++) {
|
|
599
|
-
const bigram = `${words[i]}_${words[i + 1]}`;
|
|
600
|
-
const hash = this.murmurhash3(bigram) % 8;
|
|
601
|
-
features[56 + hash] += 0.25;
|
|
602
|
-
}
|
|
603
|
-
// Normalize features
|
|
604
|
-
let norm = 0;
|
|
605
|
-
for (let i = 0; i < features.length; i++) {
|
|
606
|
-
norm += features[i] * features[i];
|
|
607
|
-
}
|
|
608
|
-
norm = Math.sqrt(norm) || 1;
|
|
609
|
-
for (let i = 0; i < features.length; i++) {
|
|
610
|
-
features[i] /= norm;
|
|
611
|
-
}
|
|
612
|
-
return features;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Convert feature vector to state key
|
|
616
|
-
* Uses locality-sensitive hashing for similar contexts
|
|
617
|
-
*/
|
|
618
|
-
featureVectorToKey(features) {
|
|
619
|
-
// Quantize features to create discrete state
|
|
620
|
-
const quantized = [];
|
|
621
|
-
for (let i = 0; i < features.length; i += 4) {
|
|
622
|
-
let bucket = 0;
|
|
623
|
-
for (let j = 0; j < 4 && i + j < features.length; j++) {
|
|
624
|
-
if (features[i + j] > 0.25) {
|
|
625
|
-
bucket |= (1 << j);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
quantized.push(bucket);
|
|
629
|
-
}
|
|
630
|
-
// Create hash from quantized values
|
|
631
|
-
let hash = 0;
|
|
632
|
-
for (let i = 0; i < quantized.length; i++) {
|
|
633
|
-
hash = ((hash << 4) ^ quantized[i]) & 0x7fffffff;
|
|
634
|
-
}
|
|
635
|
-
return `fstate_${hash.toString(36)}`;
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* MurmurHash3 32-bit implementation for n-gram hashing
|
|
639
|
-
*/
|
|
640
|
-
murmurhash3(str) {
|
|
641
|
-
let h1 = 0xdeadbeef;
|
|
642
|
-
const c1 = 0xcc9e2d51;
|
|
643
|
-
const c2 = 0x1b873593;
|
|
644
|
-
for (let i = 0; i < str.length; i++) {
|
|
645
|
-
let k1 = str.charCodeAt(i);
|
|
646
|
-
k1 = Math.imul(k1, c1);
|
|
647
|
-
k1 = (k1 << 15) | (k1 >>> 17);
|
|
648
|
-
k1 = Math.imul(k1, c2);
|
|
649
|
-
h1 ^= k1;
|
|
650
|
-
h1 = (h1 << 13) | (h1 >>> 19);
|
|
651
|
-
h1 = Math.imul(h1, 5) + 0xe6546b64;
|
|
652
|
-
}
|
|
653
|
-
h1 ^= str.length;
|
|
654
|
-
h1 ^= h1 >>> 16;
|
|
655
|
-
h1 = Math.imul(h1, 0x85ebca6b);
|
|
656
|
-
h1 ^= h1 >>> 13;
|
|
657
|
-
h1 = Math.imul(h1, 0xc2b2ae35);
|
|
658
|
-
h1 ^= h1 >>> 16;
|
|
659
|
-
return h1 >>> 0;
|
|
660
|
-
}
|
|
661
|
-
getQValues(stateKey) {
|
|
662
|
-
const entry = this.qTable.get(stateKey);
|
|
663
|
-
if (!entry) {
|
|
664
|
-
return new Array(this.config.numActions).fill(0);
|
|
665
|
-
}
|
|
666
|
-
return Array.from(entry.qValues);
|
|
667
|
-
}
|
|
668
|
-
getOrCreateEntry(stateKey) {
|
|
669
|
-
let entry = this.qTable.get(stateKey);
|
|
670
|
-
if (!entry) {
|
|
671
|
-
entry = {
|
|
672
|
-
qValues: new Float32Array(this.config.numActions),
|
|
673
|
-
visits: 0,
|
|
674
|
-
lastUpdate: Date.now(),
|
|
675
|
-
};
|
|
676
|
-
this.qTable.set(stateKey, entry);
|
|
677
|
-
}
|
|
678
|
-
return entry;
|
|
679
|
-
}
|
|
680
|
-
argmax(values) {
|
|
681
|
-
let maxIdx = 0;
|
|
682
|
-
let maxVal = values[0];
|
|
683
|
-
for (let i = 1; i < values.length; i++) {
|
|
684
|
-
if (values[i] > maxVal) {
|
|
685
|
-
maxVal = values[i];
|
|
686
|
-
maxIdx = i;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return maxIdx;
|
|
690
|
-
}
|
|
691
|
-
softmaxConfidence(qValues, actionIdx) {
|
|
692
|
-
const maxQ = Math.max(...qValues);
|
|
693
|
-
const expValues = qValues.map(q => Math.exp(q - maxQ)); // Subtract max for numerical stability
|
|
694
|
-
const sumExp = expValues.reduce((a, b) => a + b, 0);
|
|
695
|
-
return expValues[actionIdx] / sumExp;
|
|
696
|
-
}
|
|
697
|
-
pruneQTable() {
|
|
698
|
-
const entries = Array.from(this.qTable.entries())
|
|
699
|
-
.sort((a, b) => a[1].lastUpdate - b[1].lastUpdate);
|
|
700
|
-
const toRemove = entries.length - Math.floor(this.config.maxStates * 0.8);
|
|
701
|
-
for (let i = 0; i < toRemove; i++) {
|
|
702
|
-
this.qTable.delete(entries[i][0]);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* Factory function
|
|
708
|
-
*/
|
|
709
|
-
export function createQLearningRouter(config) {
|
|
710
|
-
return new QLearningRouter(config);
|
|
711
|
-
}
|
|
712
|
-
//# sourceMappingURL=q-learning-router.js.map
|