moflo 4.8.31 → 4.8.33
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/package.json +13 -10
- package/src/@claude-flow/cli/dist/src/commands/doctor.js +1298 -1107
- package/src/@claude-flow/cli/dist/src/memory/memory-initializer.js +4 -7
- package/src/@claude-flow/cli/package.json +106 -106
- package/src/@claude-flow/neural/README.md +260 -0
- package/src/@claude-flow/neural/dist/algorithms/a2c.js +361 -0
- package/src/@claude-flow/neural/dist/algorithms/curiosity.js +392 -0
- package/src/@claude-flow/neural/dist/algorithms/decision-transformer.js +415 -0
- package/src/@claude-flow/neural/dist/algorithms/dqn.js +303 -0
- package/src/@claude-flow/neural/dist/algorithms/index.js +74 -0
- package/src/@claude-flow/neural/dist/algorithms/ppo.js +331 -0
- package/src/@claude-flow/neural/dist/algorithms/q-learning.js +259 -0
- package/src/@claude-flow/neural/dist/algorithms/sarsa.js +297 -0
- package/src/@claude-flow/neural/dist/application/index.js +7 -0
- package/src/@claude-flow/neural/dist/application/services/neural-application-service.js +161 -0
- package/src/@claude-flow/neural/dist/domain/entities/pattern.js +134 -0
- package/src/@claude-flow/neural/dist/domain/index.js +8 -0
- package/src/@claude-flow/neural/dist/domain/services/learning-service.js +195 -0
- package/src/@claude-flow/neural/dist/index.js +201 -0
- package/src/@claude-flow/neural/dist/modes/balanced.js +234 -0
- package/src/@claude-flow/neural/dist/modes/base.js +77 -0
- package/src/@claude-flow/neural/dist/modes/batch.js +316 -0
- package/src/@claude-flow/neural/dist/modes/edge.js +310 -0
- package/src/@claude-flow/neural/dist/modes/index.js +13 -0
- package/src/@claude-flow/neural/dist/modes/real-time.js +196 -0
- package/src/@claude-flow/neural/dist/modes/research.js +389 -0
- package/src/@claude-flow/neural/dist/pattern-learner.js +603 -0
- package/src/@claude-flow/neural/dist/reasoning-bank.js +993 -0
- package/src/@claude-flow/neural/dist/reasoningbank-adapter.js +463 -0
- package/src/@claude-flow/neural/dist/sona-integration.js +316 -0
- package/src/@claude-flow/neural/dist/sona-manager.js +695 -0
- package/src/@claude-flow/neural/dist/types.js +11 -0
- package/src/@claude-flow/neural/package.json +26 -0
- package/.claude/agents/browser/browser-agent.yaml +0 -182
- package/.claude/agents/database-specialist.yaml +0 -21
- package/.claude/agents/index.yaml +0 -17
- package/.claude/agents/project-coordinator.yaml +0 -15
- package/.claude/agents/python-specialist.yaml +0 -21
- package/.claude/agents/security-auditor.yaml +0 -20
- package/.claude/agents/typescript-specialist.yaml +0 -21
- package/.claude/checkpoints/1767754460.json +0 -8
- package/.claude/config/v3-dependency-optimization.json +0 -266
- package/.claude/config/v3-performance-targets.json +0 -251
- package/.claude/guidance/moflo-bootstrap.md +0 -129
- package/.claude/mcp.json +0 -13
- package/.claude/settings.json +0 -351
- package/.claude/settings.local.json +0 -18
- package/.claude/skills/agentdb-advanced/SKILL.md +0 -550
- package/.claude/skills/agentdb-learning/SKILL.md +0 -545
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +0 -339
- package/.claude/skills/agentdb-optimization/SKILL.md +0 -509
- package/.claude/skills/agentdb-vector-search/SKILL.md +0 -339
- package/.claude/skills/browser/SKILL.md +0 -204
- package/.claude/skills/fl/SKILL.md +0 -583
- package/.claude/skills/flo/SKILL.md +0 -583
- package/.claude/skills/github-code-review/SKILL.md +0 -1140
- package/.claude/skills/github-multi-repo/SKILL.md +0 -874
- package/.claude/skills/github-project-management/SKILL.md +0 -1277
- package/.claude/skills/github-release-management/SKILL.md +0 -1081
- package/.claude/skills/github-workflow-automation/SKILL.md +0 -1065
- package/.claude/skills/hive-mind-advanced/SKILL.md +0 -712
- package/.claude/skills/hooks-automation/SKILL.md +0 -1201
- package/.claude/skills/pair-programming/SKILL.md +0 -1202
- package/.claude/skills/performance-analysis/SKILL.md +0 -563
- package/.claude/skills/reasoningbank-agentdb/SKILL.md +0 -446
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +0 -201
- package/.claude/skills/skill-builder/SKILL.md +0 -910
- package/.claude/skills/sparc-methodology/SKILL.md +0 -1115
- package/.claude/skills/stream-chain/SKILL.md +0 -563
- package/.claude/skills/swarm-advanced/SKILL.md +0 -973
- package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
- package/.claude/skills/v3-cli-modernization/SKILL.md +0 -872
- package/.claude/skills/v3-core-implementation/SKILL.md +0 -797
- package/.claude/skills/v3-ddd-architecture/SKILL.md +0 -442
- package/.claude/skills/v3-integration-deep/SKILL.md +0 -241
- package/.claude/skills/v3-mcp-optimization/SKILL.md +0 -777
- package/.claude/skills/v3-memory-unification/SKILL.md +0 -174
- package/.claude/skills/v3-performance-optimization/SKILL.md +0 -390
- package/.claude/skills/v3-security-overhaul/SKILL.md +0 -82
- package/.claude/skills/v3-swarm-coordination/SKILL.md +0 -340
- package/.claude/skills/verification-quality/SKILL.md +0 -649
- package/.claude/skills/worker-benchmarks/skill.md +0 -135
- package/.claude/skills/worker-integration/skill.md +0 -154
- package/.claude/workflow-state.json +0 -9
- package/src/@claude-flow/cli/dist/src/appliance/gguf-engine.d.ts +0 -91
- package/src/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +0 -102
- package/src/@claude-flow/cli/dist/src/appliance/rvfa-builder.d.ts +0 -44
- package/src/@claude-flow/cli/dist/src/appliance/rvfa-distribution.d.ts +0 -97
- package/src/@claude-flow/cli/dist/src/appliance/rvfa-format.d.ts +0 -111
- package/src/@claude-flow/cli/dist/src/appliance/rvfa-runner.d.ts +0 -69
- package/src/@claude-flow/cli/dist/src/appliance/rvfa-signing.d.ts +0 -123
- package/src/@claude-flow/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -58
- package/src/@claude-flow/cli/dist/src/commands/agent.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/analyze.d.ts +0 -19
- package/src/@claude-flow/cli/dist/src/commands/appliance-advanced.d.ts +0 -9
- package/src/@claude-flow/cli/dist/src/commands/appliance.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/benchmark.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/claims.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/completions.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/config.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/daemon.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/deployment.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/diagnose.d.ts +0 -16
- package/src/@claude-flow/cli/dist/src/commands/doctor.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/embeddings.d.ts +0 -18
- package/src/@claude-flow/cli/dist/src/commands/gate.d.ts +0 -23
- package/src/@claude-flow/cli/dist/src/commands/github.d.ts +0 -12
- package/src/@claude-flow/cli/dist/src/commands/guidance.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/hive-mind.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/hooks.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/index.d.ts +0 -115
- package/src/@claude-flow/cli/dist/src/commands/init.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/issues.d.ts +0 -21
- package/src/@claude-flow/cli/dist/src/commands/mcp.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/memory.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/migrate.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/neural.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/orc.d.ts +0 -21
- package/src/@claude-flow/cli/dist/src/commands/performance.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/plugins.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/process.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/progress.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/providers.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/route.d.ts +0 -16
- package/src/@claude-flow/cli/dist/src/commands/ruvector/backup.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/ruvector/benchmark.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/ruvector/import.d.ts +0 -18
- package/src/@claude-flow/cli/dist/src/commands/ruvector/index.d.ts +0 -29
- package/src/@claude-flow/cli/dist/src/commands/ruvector/init.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/ruvector/migrate.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/ruvector/optimize.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/ruvector/setup.d.ts +0 -18
- package/src/@claude-flow/cli/dist/src/commands/ruvector/status.d.ts +0 -11
- package/src/@claude-flow/cli/dist/src/commands/security.d.ts +0 -10
- package/src/@claude-flow/cli/dist/src/commands/session.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/start.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/status.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/swarm.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/task.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/transfer-store.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/commands/update.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/commands/workflow.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/config/moflo-config.d.ts +0 -93
- package/src/@claude-flow/cli/dist/src/config-adapter.d.ts +0 -15
- package/src/@claude-flow/cli/dist/src/index.d.ts +0 -81
- package/src/@claude-flow/cli/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
- package/src/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +0 -30
- package/src/@claude-flow/cli/dist/src/init/executor.d.ts +0 -41
- package/src/@claude-flow/cli/dist/src/init/helpers-generator.d.ts +0 -51
- package/src/@claude-flow/cli/dist/src/init/index.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/init/mcp-generator.d.ts +0 -29
- package/src/@claude-flow/cli/dist/src/init/moflo-init.d.ts +0 -31
- package/src/@claude-flow/cli/dist/src/init/settings-generator.d.ts +0 -14
- package/src/@claude-flow/cli/dist/src/init/statusline-generator.d.ts +0 -28
- package/src/@claude-flow/cli/dist/src/init/types.d.ts +0 -285
- package/src/@claude-flow/cli/dist/src/mcp-client.d.ts +0 -92
- package/src/@claude-flow/cli/dist/src/mcp-server.d.ts +0 -161
- package/src/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +0 -9
- package/src/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.d.ts +0 -30
- package/src/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.d.ts +0 -38
- package/src/@claude-flow/cli/dist/src/mcp-tools/auto-install.d.ts +0 -83
- package/src/@claude-flow/cli/dist/src/mcp-tools/browser-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/claims-tools.d.ts +0 -12
- package/src/@claude-flow/cli/dist/src/mcp-tools/config-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/daa-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.d.ts +0 -9
- package/src/@claude-flow/cli/dist/src/mcp-tools/github-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.d.ts +0 -44
- package/src/@claude-flow/cli/dist/src/mcp-tools/index.d.ts +0 -23
- package/src/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +0 -14
- package/src/@claude-flow/cli/dist/src/mcp-tools/neural-tools.d.ts +0 -16
- package/src/@claude-flow/cli/dist/src/mcp-tools/performance-tools.d.ts +0 -16
- package/src/@claude-flow/cli/dist/src/mcp-tools/progress-tools.d.ts +0 -14
- package/src/@claude-flow/cli/dist/src/mcp-tools/security-tools.d.ts +0 -18
- package/src/@claude-flow/cli/dist/src/mcp-tools/session-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/mcp-tools/system-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/task-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.d.ts +0 -14
- package/src/@claude-flow/cli/dist/src/mcp-tools/types.d.ts +0 -31
- package/src/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.d.ts +0 -8
- package/src/@claude-flow/cli/dist/src/memory/ewc-consolidation.d.ts +0 -271
- package/src/@claude-flow/cli/dist/src/memory/intelligence.d.ts +0 -285
- package/src/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +0 -413
- package/src/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +0 -405
- package/src/@claude-flow/cli/dist/src/memory/sona-optimizer.d.ts +0 -227
- package/src/@claude-flow/cli/dist/src/output.d.ts +0 -133
- package/src/@claude-flow/cli/dist/src/parser.d.ts +0 -51
- package/src/@claude-flow/cli/dist/src/plugins/manager.d.ts +0 -133
- package/src/@claude-flow/cli/dist/src/plugins/store/discovery.d.ts +0 -88
- package/src/@claude-flow/cli/dist/src/plugins/store/index.d.ts +0 -76
- package/src/@claude-flow/cli/dist/src/plugins/store/search.d.ts +0 -46
- package/src/@claude-flow/cli/dist/src/plugins/store/types.d.ts +0 -274
- package/src/@claude-flow/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +0 -7
- package/src/@claude-flow/cli/dist/src/plugins/tests/standalone-test.d.ts +0 -12
- package/src/@claude-flow/cli/dist/src/plugins/tests/test-plugin-store.d.ts +0 -7
- package/src/@claude-flow/cli/dist/src/production/circuit-breaker.d.ts +0 -101
- package/src/@claude-flow/cli/dist/src/production/error-handler.d.ts +0 -92
- package/src/@claude-flow/cli/dist/src/production/index.d.ts +0 -23
- package/src/@claude-flow/cli/dist/src/production/monitoring.d.ts +0 -161
- package/src/@claude-flow/cli/dist/src/production/rate-limiter.d.ts +0 -80
- package/src/@claude-flow/cli/dist/src/production/retry.d.ts +0 -48
- package/src/@claude-flow/cli/dist/src/prompt.d.ts +0 -44
- package/src/@claude-flow/cli/dist/src/runtime/headless.d.ts +0 -60
- package/src/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +0 -67
- package/src/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +0 -160
- package/src/@claude-flow/cli/dist/src/ruvector/coverage-tools.d.ts +0 -33
- package/src/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +0 -175
- package/src/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.d.ts +0 -146
- package/src/@claude-flow/cli/dist/src/ruvector/flash-attention.d.ts +0 -195
- package/src/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +0 -187
- package/src/@claude-flow/cli/dist/src/ruvector/index.d.ts +0 -34
- package/src/@claude-flow/cli/dist/src/ruvector/lora-adapter.d.ts +0 -218
- package/src/@claude-flow/cli/dist/src/ruvector/model-router.d.ts +0 -220
- package/src/@claude-flow/cli/dist/src/ruvector/moe-router.d.ts +0 -206
- package/src/@claude-flow/cli/dist/src/ruvector/q-learning-router.d.ts +0 -211
- package/src/@claude-flow/cli/dist/src/ruvector/semantic-router.d.ts +0 -77
- package/src/@claude-flow/cli/dist/src/ruvector/vector-db.d.ts +0 -69
- package/src/@claude-flow/cli/dist/src/services/agent-router.d.ts +0 -63
- package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.d.ts +0 -50
- package/src/@claude-flow/cli/dist/src/services/claim-service.d.ts +0 -204
- package/src/@claude-flow/cli/dist/src/services/container-worker-pool.d.ts +0 -197
- package/src/@claude-flow/cli/dist/src/services/daemon-lock.d.ts +0 -60
- package/src/@claude-flow/cli/dist/src/services/headless-worker-executor.d.ts +0 -304
- package/src/@claude-flow/cli/dist/src/services/index.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/services/learning-service.d.ts +0 -161
- package/src/@claude-flow/cli/dist/src/services/moflo-require.d.ts +0 -34
- package/src/@claude-flow/cli/dist/src/services/registry-api.d.ts +0 -58
- package/src/@claude-flow/cli/dist/src/services/ruvector-training.d.ts +0 -214
- package/src/@claude-flow/cli/dist/src/services/worker-daemon.d.ts +0 -225
- package/src/@claude-flow/cli/dist/src/services/worker-queue.d.ts +0 -194
- package/src/@claude-flow/cli/dist/src/services/workflow-gate.d.ts +0 -88
- package/src/@claude-flow/cli/dist/src/suggest.d.ts +0 -53
- package/src/@claude-flow/cli/dist/src/transfer/anonymization/index.d.ts +0 -25
- package/src/@claude-flow/cli/dist/src/transfer/deploy-seraphine.d.ts +0 -13
- package/src/@claude-flow/cli/dist/src/transfer/export.d.ts +0 -25
- package/src/@claude-flow/cli/dist/src/transfer/index.d.ts +0 -12
- package/src/@claude-flow/cli/dist/src/transfer/ipfs/client.d.ts +0 -109
- package/src/@claude-flow/cli/dist/src/transfer/ipfs/upload.d.ts +0 -95
- package/src/@claude-flow/cli/dist/src/transfer/models/seraphine.d.ts +0 -72
- package/src/@claude-flow/cli/dist/src/transfer/serialization/cfp.d.ts +0 -49
- package/src/@claude-flow/cli/dist/src/transfer/storage/gcs.d.ts +0 -82
- package/src/@claude-flow/cli/dist/src/transfer/storage/index.d.ts +0 -6
- package/src/@claude-flow/cli/dist/src/transfer/store/discovery.d.ts +0 -84
- package/src/@claude-flow/cli/dist/src/transfer/store/download.d.ts +0 -70
- package/src/@claude-flow/cli/dist/src/transfer/store/index.d.ts +0 -84
- package/src/@claude-flow/cli/dist/src/transfer/store/publish.d.ts +0 -76
- package/src/@claude-flow/cli/dist/src/transfer/store/registry.d.ts +0 -58
- package/src/@claude-flow/cli/dist/src/transfer/store/search.d.ts +0 -54
- package/src/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.d.ts +0 -12
- package/src/@claude-flow/cli/dist/src/transfer/store/types.d.ts +0 -193
- package/src/@claude-flow/cli/dist/src/transfer/test-seraphine.d.ts +0 -6
- package/src/@claude-flow/cli/dist/src/transfer/tests/test-store.d.ts +0 -7
- package/src/@claude-flow/cli/dist/src/transfer/types.d.ts +0 -245
- package/src/@claude-flow/cli/dist/src/types.d.ts +0 -198
- package/src/@claude-flow/cli/dist/src/update/checker.d.ts +0 -34
- package/src/@claude-flow/cli/dist/src/update/executor.d.ts +0 -32
- package/src/@claude-flow/cli/dist/src/update/index.d.ts +0 -33
- package/src/@claude-flow/cli/dist/src/update/rate-limiter.d.ts +0 -20
- package/src/@claude-flow/cli/dist/src/update/validator.d.ts +0 -17
- package/src/@claude-flow/guidance/dist/adversarial.d.ts +0 -284
- package/src/@claude-flow/guidance/dist/analyzer.d.ts +0 -530
- package/src/@claude-flow/guidance/dist/artifacts.d.ts +0 -283
- package/src/@claude-flow/guidance/dist/authority.d.ts +0 -290
- package/src/@claude-flow/guidance/dist/capabilities.d.ts +0 -209
- package/src/@claude-flow/guidance/dist/coherence.d.ts +0 -233
- package/src/@claude-flow/guidance/dist/compiler.d.ts +0 -87
- package/src/@claude-flow/guidance/dist/conformance-kit.d.ts +0 -225
- package/src/@claude-flow/guidance/dist/continue-gate.d.ts +0 -214
- package/src/@claude-flow/guidance/dist/crypto-utils.d.ts +0 -17
- package/src/@claude-flow/guidance/dist/evolution.d.ts +0 -282
- package/src/@claude-flow/guidance/dist/gates.d.ts +0 -79
- package/src/@claude-flow/guidance/dist/gateway.d.ts +0 -206
- package/src/@claude-flow/guidance/dist/generators.d.ts +0 -153
- package/src/@claude-flow/guidance/dist/headless.d.ts +0 -177
- package/src/@claude-flow/guidance/dist/hooks.d.ts +0 -109
- package/src/@claude-flow/guidance/dist/index.d.ts +0 -205
- package/src/@claude-flow/guidance/dist/ledger.d.ts +0 -162
- package/src/@claude-flow/guidance/dist/manifest-validator.d.ts +0 -289
- package/src/@claude-flow/guidance/dist/memory-gate.d.ts +0 -222
- package/src/@claude-flow/guidance/dist/meta-governance.d.ts +0 -265
- package/src/@claude-flow/guidance/dist/optimizer.d.ts +0 -104
- package/src/@claude-flow/guidance/dist/persistence.d.ts +0 -189
- package/src/@claude-flow/guidance/dist/proof.d.ts +0 -185
- package/src/@claude-flow/guidance/dist/retriever.d.ts +0 -116
- package/src/@claude-flow/guidance/dist/ruvbot-integration.d.ts +0 -370
- package/src/@claude-flow/guidance/dist/temporal.d.ts +0 -426
- package/src/@claude-flow/guidance/dist/trust.d.ts +0 -283
- package/src/@claude-flow/guidance/dist/truth-anchors.d.ts +0 -276
- package/src/@claude-flow/guidance/dist/types.d.ts +0 -378
- package/src/@claude-flow/guidance/dist/uncertainty.d.ts +0 -372
- package/src/@claude-flow/guidance/dist/wasm-kernel.d.ts +0 -48
- package/src/@claude-flow/memory/dist/agent-memory-scope.d.ts +0 -131
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +0 -8
- package/src/@claude-flow/memory/dist/agentdb-adapter.d.ts +0 -165
- package/src/@claude-flow/memory/dist/agentdb-backend.d.ts +0 -212
- package/src/@claude-flow/memory/dist/agentdb-backend.test.d.ts +0 -7
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +0 -65
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +0 -48
- package/src/@claude-flow/memory/dist/application/index.d.ts +0 -12
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +0 -72
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +0 -121
- package/src/@claude-flow/memory/dist/auto-memory-bridge.d.ts +0 -226
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +0 -8
- package/src/@claude-flow/memory/dist/benchmark.test.d.ts +0 -2
- package/src/@claude-flow/memory/dist/cache-manager.d.ts +0 -134
- package/src/@claude-flow/memory/dist/controller-registry.d.ts +0 -216
- package/src/@claude-flow/memory/dist/controller-registry.test.d.ts +0 -14
- package/src/@claude-flow/memory/dist/database-provider.d.ts +0 -87
- package/src/@claude-flow/memory/dist/database-provider.test.d.ts +0 -7
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +0 -143
- package/src/@claude-flow/memory/dist/domain/index.d.ts +0 -11
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +0 -102
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +0 -105
- package/src/@claude-flow/memory/dist/hnsw-index.d.ts +0 -111
- package/src/@claude-flow/memory/dist/hnsw-lite.d.ts +0 -23
- package/src/@claude-flow/memory/dist/hybrid-backend.d.ts +0 -245
- package/src/@claude-flow/memory/dist/hybrid-backend.test.d.ts +0 -8
- package/src/@claude-flow/memory/dist/index.d.ts +0 -204
- package/src/@claude-flow/memory/dist/infrastructure/index.d.ts +0 -17
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +0 -66
- package/src/@claude-flow/memory/dist/learning-bridge.d.ts +0 -137
- package/src/@claude-flow/memory/dist/learning-bridge.test.d.ts +0 -8
- package/src/@claude-flow/memory/dist/memory-graph.d.ts +0 -100
- package/src/@claude-flow/memory/dist/memory-graph.test.d.ts +0 -8
- package/src/@claude-flow/memory/dist/migration.d.ts +0 -68
- package/src/@claude-flow/memory/dist/persistent-sona.d.ts +0 -144
- package/src/@claude-flow/memory/dist/query-builder.d.ts +0 -211
- package/src/@claude-flow/memory/dist/rvf-backend.d.ts +0 -51
- package/src/@claude-flow/memory/dist/rvf-learning-store.d.ts +0 -139
- package/src/@claude-flow/memory/dist/rvf-migration.d.ts +0 -45
- package/src/@claude-flow/memory/dist/sqlite-backend.d.ts +0 -121
- package/src/@claude-flow/memory/dist/sqljs-backend.d.ts +0 -127
- package/src/@claude-flow/memory/dist/types.d.ts +0 -484
- package/src/@claude-flow/shared/dist/core/config/defaults.d.ts +0 -41
- package/src/@claude-flow/shared/dist/core/config/index.d.ts +0 -8
- package/src/@claude-flow/shared/dist/core/config/loader.d.ts +0 -45
- package/src/@claude-flow/shared/dist/core/config/schema.d.ts +0 -1134
- package/src/@claude-flow/shared/dist/core/config/validator.d.ts +0 -92
- package/src/@claude-flow/shared/dist/core/event-bus.d.ts +0 -31
- package/src/@claude-flow/shared/dist/core/index.d.ts +0 -15
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +0 -200
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +0 -310
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +0 -224
- package/src/@claude-flow/shared/dist/core/interfaces/index.d.ts +0 -10
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +0 -298
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +0 -185
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +0 -35
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +0 -60
- package/src/@claude-flow/shared/dist/core/orchestrator/index.d.ts +0 -46
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +0 -56
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +0 -83
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +0 -49
- package/src/@claude-flow/shared/dist/events/domain-events.d.ts +0 -282
- package/src/@claude-flow/shared/dist/events/event-store.d.ts +0 -126
- package/src/@claude-flow/shared/dist/events/event-store.test.d.ts +0 -8
- package/src/@claude-flow/shared/dist/events/example-usage.d.ts +0 -10
- package/src/@claude-flow/shared/dist/events/index.d.ts +0 -21
- package/src/@claude-flow/shared/dist/events/projections.d.ts +0 -177
- package/src/@claude-flow/shared/dist/events/rvf-event-log.d.ts +0 -82
- package/src/@claude-flow/shared/dist/events/state-reconstructor.d.ts +0 -101
- package/src/@claude-flow/shared/dist/events.d.ts +0 -80
- package/src/@claude-flow/shared/dist/hooks/example-usage.d.ts +0 -42
- package/src/@claude-flow/shared/dist/hooks/executor.d.ts +0 -100
- package/src/@claude-flow/shared/dist/hooks/hooks.test.d.ts +0 -9
- package/src/@claude-flow/shared/dist/hooks/index.d.ts +0 -52
- package/src/@claude-flow/shared/dist/hooks/registry.d.ts +0 -133
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +0 -105
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +0 -144
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +0 -158
- package/src/@claude-flow/shared/dist/hooks/safety/index.d.ts +0 -17
- package/src/@claude-flow/shared/dist/hooks/session-hooks.d.ts +0 -234
- package/src/@claude-flow/shared/dist/hooks/task-hooks.d.ts +0 -163
- package/src/@claude-flow/shared/dist/hooks/types.d.ts +0 -267
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +0 -9
- package/src/@claude-flow/shared/dist/index.d.ts +0 -20
- package/src/@claude-flow/shared/dist/mcp/connection-pool.d.ts +0 -98
- package/src/@claude-flow/shared/dist/mcp/index.d.ts +0 -69
- package/src/@claude-flow/shared/dist/mcp/server.d.ts +0 -166
- package/src/@claude-flow/shared/dist/mcp/session-manager.d.ts +0 -136
- package/src/@claude-flow/shared/dist/mcp/tool-registry.d.ts +0 -178
- package/src/@claude-flow/shared/dist/mcp/transport/http.d.ts +0 -104
- package/src/@claude-flow/shared/dist/mcp/transport/index.d.ts +0 -102
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +0 -104
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +0 -133
- package/src/@claude-flow/shared/dist/mcp/types.d.ts +0 -438
- package/src/@claude-flow/shared/dist/plugin-interface.d.ts +0 -544
- package/src/@claude-flow/shared/dist/plugin-loader.d.ts +0 -139
- package/src/@claude-flow/shared/dist/plugin-registry.d.ts +0 -183
- package/src/@claude-flow/shared/dist/plugins/index.d.ts +0 -10
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +0 -106
- package/src/@claude-flow/shared/dist/plugins/official/index.d.ts +0 -10
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +0 -121
- package/src/@claude-flow/shared/dist/plugins/types.d.ts +0 -93
- package/src/@claude-flow/shared/dist/resilience/bulkhead.d.ts +0 -105
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +0 -132
- package/src/@claude-flow/shared/dist/resilience/index.d.ts +0 -19
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +0 -168
- package/src/@claude-flow/shared/dist/resilience/retry.d.ts +0 -91
- package/src/@claude-flow/shared/dist/security/index.d.ts +0 -10
- package/src/@claude-flow/shared/dist/security/input-validation.d.ts +0 -73
- package/src/@claude-flow/shared/dist/security/secure-random.d.ts +0 -92
- package/src/@claude-flow/shared/dist/services/index.d.ts +0 -7
- package/src/@claude-flow/shared/dist/services/v3-progress.service.d.ts +0 -124
- package/src/@claude-flow/shared/dist/types/agent.types.d.ts +0 -137
- package/src/@claude-flow/shared/dist/types/index.d.ts +0 -11
- package/src/@claude-flow/shared/dist/types/mcp.types.d.ts +0 -266
- package/src/@claude-flow/shared/dist/types/memory.types.d.ts +0 -236
- package/src/@claude-flow/shared/dist/types/swarm.types.d.ts +0 -186
- package/src/@claude-flow/shared/dist/types/task.types.d.ts +0 -178
- package/src/@claude-flow/shared/dist/types.d.ts +0 -197
- package/src/@claude-flow/shared/dist/utils/secure-logger.d.ts +0 -69
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision Transformer
|
|
3
|
+
*
|
|
4
|
+
* Implements sequence modeling approach for RL:
|
|
5
|
+
* - Trajectory as sequence: (s, a, R, s, a, R, ...)
|
|
6
|
+
* - Return-conditioned generation
|
|
7
|
+
* - Causal transformer attention
|
|
8
|
+
* - Offline RL from trajectories
|
|
9
|
+
*
|
|
10
|
+
* Performance Target: <10ms per forward pass
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Default Decision Transformer configuration
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_DT_CONFIG = {
|
|
16
|
+
algorithm: 'decision-transformer',
|
|
17
|
+
learningRate: 0.0001,
|
|
18
|
+
gamma: 0.99,
|
|
19
|
+
entropyCoef: 0,
|
|
20
|
+
valueLossCoef: 0,
|
|
21
|
+
maxGradNorm: 1.0,
|
|
22
|
+
epochs: 1,
|
|
23
|
+
miniBatchSize: 64,
|
|
24
|
+
contextLength: 20,
|
|
25
|
+
numHeads: 4,
|
|
26
|
+
numLayers: 2,
|
|
27
|
+
hiddenDim: 64,
|
|
28
|
+
embeddingDim: 32,
|
|
29
|
+
dropout: 0.1,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Decision Transformer Implementation
|
|
33
|
+
*/
|
|
34
|
+
export class DecisionTransformer {
|
|
35
|
+
config;
|
|
36
|
+
// Embeddings
|
|
37
|
+
stateEmbed;
|
|
38
|
+
actionEmbed;
|
|
39
|
+
returnEmbed;
|
|
40
|
+
posEmbed;
|
|
41
|
+
// Transformer layers (simplified)
|
|
42
|
+
attentionWeights;
|
|
43
|
+
ffnWeights;
|
|
44
|
+
// Output head
|
|
45
|
+
actionHead;
|
|
46
|
+
// Training buffer
|
|
47
|
+
trajectoryBuffer = [];
|
|
48
|
+
// Dimensions
|
|
49
|
+
stateDim = 768;
|
|
50
|
+
numActions = 4;
|
|
51
|
+
// Statistics
|
|
52
|
+
updateCount = 0;
|
|
53
|
+
avgLoss = 0;
|
|
54
|
+
constructor(config = {}) {
|
|
55
|
+
this.config = { ...DEFAULT_DT_CONFIG, ...config };
|
|
56
|
+
// Initialize embeddings
|
|
57
|
+
this.stateEmbed = this.initEmbedding(this.stateDim, this.config.embeddingDim);
|
|
58
|
+
this.actionEmbed = this.initEmbedding(this.numActions, this.config.embeddingDim);
|
|
59
|
+
this.returnEmbed = this.initEmbedding(1, this.config.embeddingDim);
|
|
60
|
+
this.posEmbed = this.initEmbedding(this.config.contextLength * 3, this.config.embeddingDim);
|
|
61
|
+
// Initialize transformer layers
|
|
62
|
+
this.attentionWeights = [];
|
|
63
|
+
this.ffnWeights = [];
|
|
64
|
+
for (let l = 0; l < this.config.numLayers; l++) {
|
|
65
|
+
// Attention: Q, K, V, O projections
|
|
66
|
+
this.attentionWeights.push([
|
|
67
|
+
this.initWeight(this.config.embeddingDim, this.config.hiddenDim), // Q
|
|
68
|
+
this.initWeight(this.config.embeddingDim, this.config.hiddenDim), // K
|
|
69
|
+
this.initWeight(this.config.embeddingDim, this.config.hiddenDim), // V
|
|
70
|
+
this.initWeight(this.config.hiddenDim, this.config.embeddingDim), // O
|
|
71
|
+
]);
|
|
72
|
+
// FFN: up and down projections
|
|
73
|
+
this.ffnWeights.push([
|
|
74
|
+
this.initWeight(this.config.embeddingDim, this.config.hiddenDim * 4),
|
|
75
|
+
this.initWeight(this.config.hiddenDim * 4, this.config.embeddingDim),
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
// Action prediction head
|
|
79
|
+
this.actionHead = this.initWeight(this.config.embeddingDim, this.numActions);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Add trajectory for training
|
|
83
|
+
*/
|
|
84
|
+
addTrajectory(trajectory) {
|
|
85
|
+
if (trajectory.isComplete && trajectory.steps.length > 0) {
|
|
86
|
+
this.trajectoryBuffer.push(trajectory);
|
|
87
|
+
// Keep buffer bounded
|
|
88
|
+
if (this.trajectoryBuffer.length > 1000) {
|
|
89
|
+
this.trajectoryBuffer = this.trajectoryBuffer.slice(-1000);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Train on buffered trajectories
|
|
95
|
+
* Target: <10ms per batch
|
|
96
|
+
*/
|
|
97
|
+
train() {
|
|
98
|
+
const startTime = performance.now();
|
|
99
|
+
if (this.trajectoryBuffer.length === 0) {
|
|
100
|
+
return { loss: 0, accuracy: 0 };
|
|
101
|
+
}
|
|
102
|
+
// Sample mini-batch of trajectories
|
|
103
|
+
const batchSize = Math.min(this.config.miniBatchSize, this.trajectoryBuffer.length);
|
|
104
|
+
const batch = [];
|
|
105
|
+
for (let i = 0; i < batchSize; i++) {
|
|
106
|
+
const idx = Math.floor(Math.random() * this.trajectoryBuffer.length);
|
|
107
|
+
batch.push(this.trajectoryBuffer[idx]);
|
|
108
|
+
}
|
|
109
|
+
let totalLoss = 0;
|
|
110
|
+
let correct = 0;
|
|
111
|
+
let total = 0;
|
|
112
|
+
for (const trajectory of batch) {
|
|
113
|
+
// Create sequence from trajectory
|
|
114
|
+
const sequence = this.createSequence(trajectory);
|
|
115
|
+
if (sequence.length < 2)
|
|
116
|
+
continue;
|
|
117
|
+
// Forward pass and compute loss
|
|
118
|
+
for (let t = 1; t < sequence.length; t++) {
|
|
119
|
+
// Use context up to position t
|
|
120
|
+
const context = sequence.slice(Math.max(0, t - this.config.contextLength), t);
|
|
121
|
+
const target = sequence[t];
|
|
122
|
+
// Predict action
|
|
123
|
+
const predicted = this.forward(context);
|
|
124
|
+
const predictedAction = this.argmax(predicted);
|
|
125
|
+
// Cross-entropy loss
|
|
126
|
+
const loss = -Math.log(predicted[target.action] + 1e-8);
|
|
127
|
+
totalLoss += loss;
|
|
128
|
+
if (predictedAction === target.action) {
|
|
129
|
+
correct++;
|
|
130
|
+
}
|
|
131
|
+
total++;
|
|
132
|
+
// Gradient update (simplified)
|
|
133
|
+
this.updateWeights(context, target.action, predicted);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.updateCount++;
|
|
137
|
+
this.avgLoss = total > 0 ? totalLoss / total : 0;
|
|
138
|
+
const elapsed = performance.now() - startTime;
|
|
139
|
+
if (elapsed > 10) {
|
|
140
|
+
console.warn(`DT training exceeded target: ${elapsed.toFixed(2)}ms > 10ms`);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
loss: this.avgLoss,
|
|
144
|
+
accuracy: total > 0 ? correct / total : 0,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get action conditioned on target return
|
|
149
|
+
*/
|
|
150
|
+
getAction(states, actions, targetReturn) {
|
|
151
|
+
// Build sequence
|
|
152
|
+
const sequence = [];
|
|
153
|
+
let returnToGo = targetReturn;
|
|
154
|
+
for (let i = 0; i < states.length; i++) {
|
|
155
|
+
sequence.push({
|
|
156
|
+
returnToGo,
|
|
157
|
+
state: states[i],
|
|
158
|
+
action: actions[i] ?? 0,
|
|
159
|
+
timestep: i,
|
|
160
|
+
});
|
|
161
|
+
// Decrease return-to-go by estimated reward
|
|
162
|
+
if (i > 0) {
|
|
163
|
+
returnToGo -= 0.1; // Default reward decrement for inference
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Forward pass
|
|
167
|
+
const logits = this.forward(sequence);
|
|
168
|
+
return this.argmax(logits);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Forward pass through transformer
|
|
172
|
+
*/
|
|
173
|
+
forward(sequence) {
|
|
174
|
+
// Embed sequence elements
|
|
175
|
+
const seqLen = Math.min(sequence.length, this.config.contextLength);
|
|
176
|
+
const embedDim = this.config.embeddingDim;
|
|
177
|
+
// Initialize hidden states (simplified: stack all modalities)
|
|
178
|
+
const hidden = new Float32Array(seqLen * 3 * embedDim);
|
|
179
|
+
for (let t = 0; t < seqLen; t++) {
|
|
180
|
+
const entry = sequence[sequence.length - seqLen + t];
|
|
181
|
+
const baseIdx = t * 3 * embedDim;
|
|
182
|
+
// Embed return
|
|
183
|
+
for (let d = 0; d < embedDim; d++) {
|
|
184
|
+
hidden[baseIdx + d] = entry.returnToGo * this.returnEmbed[d];
|
|
185
|
+
}
|
|
186
|
+
// Embed state
|
|
187
|
+
for (let d = 0; d < embedDim; d++) {
|
|
188
|
+
let stateSum = 0;
|
|
189
|
+
for (let s = 0; s < Math.min(entry.state.length, this.stateDim); s++) {
|
|
190
|
+
stateSum += entry.state[s] * this.stateEmbed[s * embedDim + d];
|
|
191
|
+
}
|
|
192
|
+
hidden[baseIdx + embedDim + d] = stateSum;
|
|
193
|
+
}
|
|
194
|
+
// Embed action
|
|
195
|
+
for (let d = 0; d < embedDim; d++) {
|
|
196
|
+
hidden[baseIdx + 2 * embedDim + d] = this.actionEmbed[entry.action * embedDim + d];
|
|
197
|
+
}
|
|
198
|
+
// Add positional embedding
|
|
199
|
+
for (let d = 0; d < 3 * embedDim; d++) {
|
|
200
|
+
hidden[baseIdx + d] += this.posEmbed[t * 3 * embedDim + d] || 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Apply transformer layers
|
|
204
|
+
for (let l = 0; l < this.config.numLayers; l++) {
|
|
205
|
+
hidden.set(this.transformerLayer(hidden, seqLen * 3, l));
|
|
206
|
+
}
|
|
207
|
+
// Extract last state position embedding for action prediction
|
|
208
|
+
const lastStateIdx = (seqLen * 3 - 2) * embedDim;
|
|
209
|
+
const lastState = hidden.slice(lastStateIdx, lastStateIdx + embedDim);
|
|
210
|
+
// Action prediction
|
|
211
|
+
const logits = new Float32Array(this.numActions);
|
|
212
|
+
for (let a = 0; a < this.numActions; a++) {
|
|
213
|
+
let sum = 0;
|
|
214
|
+
for (let d = 0; d < embedDim; d++) {
|
|
215
|
+
sum += lastState[d] * this.actionHead[d * this.numActions + a];
|
|
216
|
+
}
|
|
217
|
+
logits[a] = sum;
|
|
218
|
+
}
|
|
219
|
+
return this.softmax(logits);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get statistics
|
|
223
|
+
*/
|
|
224
|
+
getStats() {
|
|
225
|
+
return {
|
|
226
|
+
updateCount: this.updateCount,
|
|
227
|
+
bufferSize: this.trajectoryBuffer.length,
|
|
228
|
+
avgLoss: this.avgLoss,
|
|
229
|
+
contextLength: this.config.contextLength,
|
|
230
|
+
numLayers: this.config.numLayers,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// ==========================================================================
|
|
234
|
+
// Private Methods
|
|
235
|
+
// ==========================================================================
|
|
236
|
+
initEmbedding(inputDim, outputDim) {
|
|
237
|
+
const embed = new Float32Array(inputDim * outputDim);
|
|
238
|
+
const scale = Math.sqrt(2 / inputDim);
|
|
239
|
+
for (let i = 0; i < embed.length; i++) {
|
|
240
|
+
embed[i] = (Math.random() - 0.5) * scale;
|
|
241
|
+
}
|
|
242
|
+
return embed;
|
|
243
|
+
}
|
|
244
|
+
initWeight(inputDim, outputDim) {
|
|
245
|
+
const weight = new Float32Array(inputDim * outputDim);
|
|
246
|
+
const scale = Math.sqrt(2 / inputDim);
|
|
247
|
+
for (let i = 0; i < weight.length; i++) {
|
|
248
|
+
weight[i] = (Math.random() - 0.5) * scale;
|
|
249
|
+
}
|
|
250
|
+
return weight;
|
|
251
|
+
}
|
|
252
|
+
createSequence(trajectory) {
|
|
253
|
+
const sequence = [];
|
|
254
|
+
// Compute returns-to-go
|
|
255
|
+
const rewards = trajectory.steps.map(s => s.reward);
|
|
256
|
+
const returnsToGo = new Array(rewards.length).fill(0);
|
|
257
|
+
let cumReturn = 0;
|
|
258
|
+
for (let t = rewards.length - 1; t >= 0; t--) {
|
|
259
|
+
cumReturn = rewards[t] + this.config.gamma * cumReturn;
|
|
260
|
+
returnsToGo[t] = cumReturn;
|
|
261
|
+
}
|
|
262
|
+
// Create sequence entries
|
|
263
|
+
for (let t = 0; t < trajectory.steps.length; t++) {
|
|
264
|
+
sequence.push({
|
|
265
|
+
returnToGo: returnsToGo[t],
|
|
266
|
+
state: trajectory.steps[t].stateAfter,
|
|
267
|
+
action: this.hashAction(trajectory.steps[t].action),
|
|
268
|
+
timestep: t,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return sequence;
|
|
272
|
+
}
|
|
273
|
+
transformerLayer(hidden, seqLen, layerIdx) {
|
|
274
|
+
const embedDim = this.config.embeddingDim;
|
|
275
|
+
const hiddenDim = this.config.hiddenDim;
|
|
276
|
+
const numHeads = this.config.numHeads;
|
|
277
|
+
const headDim = hiddenDim / numHeads;
|
|
278
|
+
const output = new Float32Array(hidden.length);
|
|
279
|
+
// Self-attention (simplified causal)
|
|
280
|
+
const [Wq, Wk, Wv, Wo] = this.attentionWeights[layerIdx];
|
|
281
|
+
// Compute Q, K, V for all positions
|
|
282
|
+
const Q = new Float32Array(seqLen * hiddenDim);
|
|
283
|
+
const K = new Float32Array(seqLen * hiddenDim);
|
|
284
|
+
const V = new Float32Array(seqLen * hiddenDim);
|
|
285
|
+
for (let pos = 0; pos < seqLen; pos++) {
|
|
286
|
+
for (let h = 0; h < hiddenDim; h++) {
|
|
287
|
+
let qSum = 0, kSum = 0, vSum = 0;
|
|
288
|
+
for (let d = 0; d < embedDim; d++) {
|
|
289
|
+
const hiddenVal = hidden[pos * embedDim + d];
|
|
290
|
+
qSum += hiddenVal * Wq[d * hiddenDim + h];
|
|
291
|
+
kSum += hiddenVal * Wk[d * hiddenDim + h];
|
|
292
|
+
vSum += hiddenVal * Wv[d * hiddenDim + h];
|
|
293
|
+
}
|
|
294
|
+
Q[pos * hiddenDim + h] = qSum;
|
|
295
|
+
K[pos * hiddenDim + h] = kSum;
|
|
296
|
+
V[pos * hiddenDim + h] = vSum;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Causal attention
|
|
300
|
+
for (let pos = 0; pos < seqLen; pos++) {
|
|
301
|
+
// Compute attention scores for current position
|
|
302
|
+
const scores = new Float32Array(pos + 1);
|
|
303
|
+
for (let k = 0; k <= pos; k++) {
|
|
304
|
+
let score = 0;
|
|
305
|
+
for (let h = 0; h < hiddenDim; h++) {
|
|
306
|
+
score += Q[pos * hiddenDim + h] * K[k * hiddenDim + h];
|
|
307
|
+
}
|
|
308
|
+
scores[k] = score / Math.sqrt(headDim);
|
|
309
|
+
}
|
|
310
|
+
// Softmax
|
|
311
|
+
const maxScore = Math.max(...scores);
|
|
312
|
+
let sumExp = 0;
|
|
313
|
+
for (let k = 0; k <= pos; k++) {
|
|
314
|
+
scores[k] = Math.exp(scores[k] - maxScore);
|
|
315
|
+
sumExp += scores[k];
|
|
316
|
+
}
|
|
317
|
+
for (let k = 0; k <= pos; k++) {
|
|
318
|
+
scores[k] /= sumExp;
|
|
319
|
+
}
|
|
320
|
+
// Weighted sum of values
|
|
321
|
+
const attnOut = new Float32Array(hiddenDim);
|
|
322
|
+
for (let k = 0; k <= pos; k++) {
|
|
323
|
+
for (let h = 0; h < hiddenDim; h++) {
|
|
324
|
+
attnOut[h] += scores[k] * V[k * hiddenDim + h];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// Output projection
|
|
328
|
+
for (let d = 0; d < embedDim; d++) {
|
|
329
|
+
let sum = hidden[pos * embedDim + d]; // Residual
|
|
330
|
+
for (let h = 0; h < hiddenDim; h++) {
|
|
331
|
+
sum += attnOut[h] * Wo[h * embedDim + d];
|
|
332
|
+
}
|
|
333
|
+
output[pos * embedDim + d] = sum;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// FFN with residual
|
|
337
|
+
const [Wup, Wdown] = this.ffnWeights[layerIdx];
|
|
338
|
+
const ffnHiddenDim = hiddenDim * 4;
|
|
339
|
+
for (let pos = 0; pos < seqLen; pos++) {
|
|
340
|
+
// Up projection + GELU
|
|
341
|
+
const ffnHidden = new Float32Array(ffnHiddenDim);
|
|
342
|
+
for (let h = 0; h < ffnHiddenDim; h++) {
|
|
343
|
+
let sum = 0;
|
|
344
|
+
for (let d = 0; d < embedDim; d++) {
|
|
345
|
+
sum += output[pos * embedDim + d] * Wup[d * ffnHiddenDim + h];
|
|
346
|
+
}
|
|
347
|
+
// GELU approximation
|
|
348
|
+
ffnHidden[h] = sum * 0.5 * (1 + Math.tanh(0.7978845608 * (sum + 0.044715 * sum * sum * sum)));
|
|
349
|
+
}
|
|
350
|
+
// Down projection
|
|
351
|
+
for (let d = 0; d < embedDim; d++) {
|
|
352
|
+
let sum = output[pos * embedDim + d]; // Residual
|
|
353
|
+
for (let h = 0; h < ffnHiddenDim; h++) {
|
|
354
|
+
sum += ffnHidden[h] * Wdown[h * embedDim + d];
|
|
355
|
+
}
|
|
356
|
+
output[pos * embedDim + d] = sum;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return output;
|
|
360
|
+
}
|
|
361
|
+
updateWeights(context, targetAction, predicted) {
|
|
362
|
+
// Simplified gradient update for action head
|
|
363
|
+
const lr = this.config.learningRate;
|
|
364
|
+
const embedDim = this.config.embeddingDim;
|
|
365
|
+
// Gradient of cross-entropy
|
|
366
|
+
const grad = new Float32Array(this.numActions);
|
|
367
|
+
for (let a = 0; a < this.numActions; a++) {
|
|
368
|
+
grad[a] = predicted[a] - (a === targetAction ? 1 : 0);
|
|
369
|
+
}
|
|
370
|
+
// Update action head (simplified)
|
|
371
|
+
for (let d = 0; d < embedDim; d++) {
|
|
372
|
+
for (let a = 0; a < this.numActions; a++) {
|
|
373
|
+
this.actionHead[d * this.numActions + a] -= lr * grad[a] * 0.1;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
softmax(logits) {
|
|
378
|
+
const max = Math.max(...logits);
|
|
379
|
+
const exps = new Float32Array(logits.length);
|
|
380
|
+
let sum = 0;
|
|
381
|
+
for (let i = 0; i < logits.length; i++) {
|
|
382
|
+
exps[i] = Math.exp(logits[i] - max);
|
|
383
|
+
sum += exps[i];
|
|
384
|
+
}
|
|
385
|
+
for (let i = 0; i < exps.length; i++) {
|
|
386
|
+
exps[i] /= sum;
|
|
387
|
+
}
|
|
388
|
+
return exps;
|
|
389
|
+
}
|
|
390
|
+
argmax(values) {
|
|
391
|
+
let maxIdx = 0;
|
|
392
|
+
let maxVal = values[0];
|
|
393
|
+
for (let i = 1; i < values.length; i++) {
|
|
394
|
+
if (values[i] > maxVal) {
|
|
395
|
+
maxVal = values[i];
|
|
396
|
+
maxIdx = i;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return maxIdx;
|
|
400
|
+
}
|
|
401
|
+
hashAction(action) {
|
|
402
|
+
let hash = 0;
|
|
403
|
+
for (let i = 0; i < action.length; i++) {
|
|
404
|
+
hash = (hash * 31 + action.charCodeAt(i)) % this.numActions;
|
|
405
|
+
}
|
|
406
|
+
return hash;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Factory function
|
|
411
|
+
*/
|
|
412
|
+
export function createDecisionTransformer(config) {
|
|
413
|
+
return new DecisionTransformer(config);
|
|
414
|
+
}
|
|
415
|
+
//# sourceMappingURL=decision-transformer.js.map
|