kynjal-cli 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/appliance/gguf-engine.d.ts +91 -0
- package/dist/src/appliance/gguf-engine.d.ts.map +1 -0
- package/dist/src/appliance/gguf-engine.js +286 -525
- package/dist/src/appliance/gguf-engine.js.map +1 -1
- package/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
- package/dist/src/appliance/ruvllm-bridge.d.ts.map +1 -0
- package/dist/src/appliance/ruvllm-bridge.js +203 -403
- package/dist/src/appliance/ruvllm-bridge.js.map +1 -1
- package/dist/src/appliance/rvfa-builder.d.ts +44 -0
- package/dist/src/appliance/rvfa-builder.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-builder.js +154 -208
- package/dist/src/appliance/rvfa-builder.js.map +1 -1
- package/dist/src/appliance/rvfa-distribution.d.ts +97 -0
- package/dist/src/appliance/rvfa-distribution.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-distribution.js +260 -423
- package/dist/src/appliance/rvfa-distribution.js.map +1 -1
- package/dist/src/appliance/rvfa-format.d.ts +111 -0
- package/dist/src/appliance/rvfa-format.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-format.js +128 -200
- package/dist/src/appliance/rvfa-format.js.map +1 -1
- package/dist/src/appliance/rvfa-runner.d.ts +69 -0
- package/dist/src/appliance/rvfa-runner.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-runner.js +168 -304
- package/dist/src/appliance/rvfa-runner.js.map +1 -1
- package/dist/src/appliance/rvfa-signing.d.ts +123 -0
- package/dist/src/appliance/rvfa-signing.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-signing.js +173 -295
- package/dist/src/appliance/rvfa-signing.js.map +1 -1
- package/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/dist/src/benchmarks/pretrain/index.d.ts.map +1 -0
- package/dist/src/benchmarks/pretrain/index.js +331 -542
- package/dist/src/benchmarks/pretrain/index.js.map +1 -1
- package/dist/src/commands/agent.js +574 -697
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.js +1218 -1548
- package/dist/src/commands/analyze.js.map +1 -1
- package/dist/src/commands/appliance-advanced.js +158 -267
- package/dist/src/commands/appliance-advanced.js.map +1 -1
- package/dist/src/commands/appliance.js +318 -493
- package/dist/src/commands/appliance.js.map +1 -1
- package/dist/src/commands/benchmark.js +372 -523
- package/dist/src/commands/benchmark.js.map +1 -1
- package/dist/src/commands/claims.js +274 -364
- package/dist/src/commands/claims.js.map +1 -1
- package/dist/src/commands/cleanup.js +113 -157
- package/dist/src/commands/cleanup.js.map +1 -1
- package/dist/src/commands/completions.js +477 -118
- package/dist/src/commands/completions.js.map +1 -1
- package/dist/src/commands/config.js +237 -303
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.js +487 -596
- package/dist/src/commands/daemon.js.map +1 -1
- package/dist/src/commands/deployment.js +194 -275
- package/dist/src/commands/deployment.js.map +1 -1
- package/dist/src/commands/doctor.js +504 -686
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/embeddings.js +1293 -1543
- package/dist/src/commands/embeddings.js.map +1 -1
- package/dist/src/commands/guidance.js +449 -596
- package/dist/src/commands/guidance.js.map +1 -1
- package/dist/src/commands/hive-mind.js +854 -938
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.js +3112 -3519
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +115 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +126 -308
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/init.js +788 -940
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/issues.js +383 -558
- package/dist/src/commands/issues.js.map +1 -1
- package/dist/src/commands/mcp.js +493 -605
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.js +833 -1026
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +282 -347
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/neural.js +1289 -1563
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/commands/performance.js +497 -643
- package/dist/src/commands/performance.js.map +1 -1
- package/dist/src/commands/plugins.js +668 -841
- package/dist/src/commands/plugins.js.map +1 -1
- package/dist/src/commands/process.js +392 -447
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/progress.js +162 -256
- package/dist/src/commands/progress.js.map +1 -1
- package/dist/src/commands/providers.js +150 -220
- package/dist/src/commands/providers.js.map +1 -1
- package/dist/src/commands/route.js +520 -665
- package/dist/src/commands/route.js.map +1 -1
- package/dist/src/commands/ruvector/backup.js +505 -651
- package/dist/src/commands/ruvector/backup.js.map +1 -1
- package/dist/src/commands/ruvector/benchmark.js +349 -401
- package/dist/src/commands/ruvector/benchmark.js.map +1 -1
- package/dist/src/commands/ruvector/import.js +224 -266
- package/dist/src/commands/ruvector/import.js.map +1 -1
- package/dist/src/commands/ruvector/index.js +37 -75
- package/dist/src/commands/ruvector/index.js.map +1 -1
- package/dist/src/commands/ruvector/init.js +336 -359
- package/dist/src/commands/ruvector/init.js.map +1 -1
- package/dist/src/commands/ruvector/migrate.js +335 -322
- package/dist/src/commands/ruvector/migrate.js.map +1 -1
- package/dist/src/commands/ruvector/optimize.js +375 -431
- package/dist/src/commands/ruvector/optimize.js.map +1 -1
- package/dist/src/commands/ruvector/setup.js +703 -117
- package/dist/src/commands/ruvector/setup.js.map +1 -1
- package/dist/src/commands/ruvector/status.js +364 -419
- package/dist/src/commands/ruvector/status.js.map +1 -1
- package/dist/src/commands/security.js +485 -608
- package/dist/src/commands/security.js.map +1 -1
- package/dist/src/commands/session.js +504 -626
- package/dist/src/commands/session.js.map +1 -1
- package/dist/src/commands/start.js +267 -364
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.js +380 -486
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +408 -488
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/task.js +423 -538
- package/dist/src/commands/task.js.map +1 -1
- package/dist/src/commands/transfer-store.js +322 -412
- package/dist/src/commands/transfer-store.js.map +1 -1
- package/dist/src/commands/update.js +196 -291
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/workflow.js +386 -486
- package/dist/src/commands/workflow.js.map +1 -1
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +38 -39
- package/dist/src/config-adapter.js.map +1 -1
- package/dist/src/index.d.ts +77 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +309 -411
- package/dist/src/index.js.map +1 -1
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +246 -507
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts +25 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +368 -78
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts +41 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +1307 -996
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts +60 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +657 -12
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/index.d.ts +1 -1
- package/dist/src/init/index.d.ts.map +1 -1
- package/dist/src/init/index.js +1 -1
- package/dist/src/init/index.js.map +1 -1
- package/dist/src/init/mcp-generator.js +33 -37
- package/dist/src/init/mcp-generator.js.map +1 -1
- package/dist/src/init/settings-generator.js +76 -77
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/init/statusline-generator.js +801 -3
- package/dist/src/init/statusline-generator.js.map +1 -1
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/init/types.js +76 -59
- package/dist/src/init/types.js.map +1 -1
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +81 -125
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts +161 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +470 -757
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +391 -492
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/agentdb-tools.js +332 -533
- package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.js +172 -236
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
- package/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/dist/src/mcp-tools/auto-install.d.ts.map +1 -0
- package/dist/src/mcp-tools/auto-install.js +80 -142
- package/dist/src/mcp-tools/auto-install.js.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +252 -375
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/claims-tools.js +473 -565
- package/dist/src/mcp-tools/claims-tools.js.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +197 -272
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/coordination-tools.js +500 -572
- package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
- package/dist/src/mcp-tools/daa-tools.js +286 -364
- package/dist/src/mcp-tools/daa-tools.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +582 -693
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/mcp-tools/github-tools.js +260 -311
- package/dist/src/mcp-tools/github-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.js +573 -640
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +2215 -2648
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +350 -505
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/neural-tools.js +315 -412
- package/dist/src/mcp-tools/neural-tools.js.map +1 -1
- package/dist/src/mcp-tools/performance-tools.js +420 -480
- package/dist/src/mcp-tools/performance-tools.js.map +1 -1
- package/dist/src/mcp-tools/progress-tools.js +204 -278
- package/dist/src/mcp-tools/progress-tools.js.map +1 -1
- package/dist/src/mcp-tools/ruvllm-tools.js +163 -279
- package/dist/src/mcp-tools/ruvllm-tools.js.map +1 -1
- package/dist/src/mcp-tools/security-tools.js +297 -429
- package/dist/src/mcp-tools/security-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.js +185 -234
- package/dist/src/mcp-tools/session-tools.js.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +207 -260
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/system-tools.js +276 -325
- package/dist/src/mcp-tools/system-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.js +270 -336
- package/dist/src/mcp-tools/task-tools.js.map +1 -1
- package/dist/src/mcp-tools/terminal-tools.js +148 -196
- package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
- package/dist/src/mcp-tools/transfer-tools.js +186 -333
- package/dist/src/mcp-tools/transfer-tools.js.map +1 -1
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/wasm-agent-tools.js +133 -280
- package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/workflow-tools.js +405 -450
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
- package/dist/src/memory/ewc-consolidation.d.ts +295 -0
- package/dist/src/memory/ewc-consolidation.d.ts.map +1 -0
- package/dist/src/memory/ewc-consolidation.js +190 -303
- package/dist/src/memory/ewc-consolidation.js.map +1 -1
- package/dist/src/memory/intelligence.d.ts +338 -0
- package/dist/src/memory/intelligence.d.ts.map +1 -0
- package/dist/src/memory/intelligence.js +569 -794
- package/dist/src/memory/intelligence.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +407 -0
- package/dist/src/memory/memory-bridge.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge.js +1170 -1640
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-initializer.d.ts +412 -0
- package/dist/src/memory/memory-initializer.d.ts.map +1 -0
- package/dist/src/memory/memory-initializer.js +1836 -1851
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/dist/src/memory/sona-optimizer.d.ts.map +1 -0
- package/dist/src/memory/sona-optimizer.js +199 -329
- package/dist/src/memory/sona-optimizer.js.map +1 -1
- package/dist/src/output.d.ts +2 -2
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +242 -272
- package/dist/src/output.js.map +1 -1
- package/dist/src/parser.d.ts +51 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +140 -187
- package/dist/src/parser.js.map +1 -1
- package/dist/src/plugins/manager.d.ts +133 -0
- package/dist/src/plugins/manager.d.ts.map +1 -0
- package/dist/src/plugins/manager.js +285 -521
- package/dist/src/plugins/manager.js.map +1 -1
- package/dist/src/plugins/store/discovery.d.ts +88 -0
- package/dist/src/plugins/store/discovery.d.ts.map +1 -0
- package/dist/src/plugins/store/discovery.js +271 -358
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/plugins/store/index.d.ts +76 -0
- package/dist/src/plugins/store/index.d.ts.map +1 -0
- package/dist/src/plugins/store/index.js +48 -105
- package/dist/src/plugins/store/index.js.map +1 -1
- package/dist/src/plugins/store/search.d.ts +46 -0
- package/dist/src/plugins/store/search.d.ts.map +1 -0
- package/dist/src/plugins/store/search.js +69 -107
- package/dist/src/plugins/store/search.js.map +1 -1
- package/dist/src/plugins/store/types.d.ts +274 -0
- package/dist/src/plugins/store/types.d.ts.map +1 -0
- package/dist/src/plugins/tests/demo-plugin-store.js +113 -160
- package/dist/src/plugins/tests/demo-plugin-store.js.map +1 -1
- package/dist/src/plugins/tests/standalone-test.js +172 -223
- package/dist/src/plugins/tests/standalone-test.js.map +1 -1
- package/dist/src/plugins/tests/test-plugin-store.js +190 -228
- package/dist/src/plugins/tests/test-plugin-store.js.map +1 -1
- package/dist/src/production/circuit-breaker.d.ts +101 -0
- package/dist/src/production/circuit-breaker.d.ts.map +1 -0
- package/dist/src/production/circuit-breaker.js +62 -126
- package/dist/src/production/circuit-breaker.js.map +1 -1
- package/dist/src/production/error-handler.d.ts +92 -0
- package/dist/src/production/error-handler.d.ts.map +1 -0
- package/dist/src/production/error-handler.js +86 -156
- package/dist/src/production/error-handler.js.map +1 -1
- package/dist/src/production/monitoring.d.ts +161 -0
- package/dist/src/production/monitoring.d.ts.map +1 -0
- package/dist/src/production/monitoring.js +139 -220
- package/dist/src/production/monitoring.js.map +1 -1
- package/dist/src/production/rate-limiter.d.ts +80 -0
- package/dist/src/production/rate-limiter.d.ts.map +1 -0
- package/dist/src/production/rate-limiter.js +74 -93
- package/dist/src/production/rate-limiter.js.map +1 -1
- package/dist/src/production/retry.d.ts +48 -0
- package/dist/src/production/retry.d.ts.map +1 -0
- package/dist/src/production/retry.js +75 -167
- package/dist/src/production/retry.js.map +1 -1
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +436 -560
- package/dist/src/prompt.js.map +1 -1
- package/dist/src/runtime/headless.d.ts +60 -0
- package/dist/src/runtime/headless.d.ts.map +1 -0
- package/dist/src/runtime/headless.js +197 -286
- package/dist/src/runtime/headless.js.map +1 -1
- package/dist/src/ruvector/agent-wasm.d.ts +182 -0
- package/dist/src/ruvector/agent-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/agent-wasm.js +156 -351
- package/dist/src/ruvector/agent-wasm.js.map +1 -1
- package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/ast-analyzer.js +145 -232
- package/dist/src/ruvector/ast-analyzer.js.map +1 -1
- package/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-router.js +287 -419
- package/dist/src/ruvector/coverage-router.js.map +1 -1
- package/dist/src/ruvector/coverage-tools.js +56 -101
- package/dist/src/ruvector/coverage-tools.js.map +1 -1
- package/dist/src/ruvector/diff-classifier.d.ts +175 -0
- package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
- package/dist/src/ruvector/diff-classifier.js +324 -451
- package/dist/src/ruvector/diff-classifier.js.map +1 -1
- package/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/dist/src/ruvector/enhanced-model-router.d.ts.map +1 -0
- package/dist/src/ruvector/enhanced-model-router.js +260 -336
- package/dist/src/ruvector/enhanced-model-router.js.map +1 -1
- package/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/dist/src/ruvector/flash-attention.d.ts.map +1 -0
- package/dist/src/ruvector/flash-attention.js +223 -254
- package/dist/src/ruvector/flash-attention.js.map +1 -1
- package/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/graph-analyzer.js +486 -680
- package/dist/src/ruvector/graph-analyzer.js.map +1 -1
- package/dist/src/ruvector/index.d.ts +40 -0
- package/dist/src/ruvector/index.d.ts.map +1 -0
- package/dist/src/ruvector/index.js +36 -106
- package/dist/src/ruvector/index.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -0
- package/dist/src/ruvector/lora-adapter.js +155 -248
- package/dist/src/ruvector/lora-adapter.js.map +1 -1
- package/dist/src/ruvector/model-router.d.ts +220 -0
- package/dist/src/ruvector/model-router.d.ts.map +1 -0
- package/dist/src/ruvector/model-router.js +175 -248
- package/dist/src/ruvector/model-router.js.map +1 -1
- package/dist/src/ruvector/moe-router.d.ts +206 -0
- package/dist/src/ruvector/moe-router.d.ts.map +1 -0
- package/dist/src/ruvector/moe-router.js +228 -286
- package/dist/src/ruvector/moe-router.js.map +1 -1
- package/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
- package/dist/src/ruvector/q-learning-router.js +257 -338
- package/dist/src/ruvector/q-learning-router.js.map +1 -1
- package/dist/src/ruvector/ruvllm-wasm.d.ts +179 -0
- package/dist/src/ruvector/ruvllm-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/ruvllm-wasm.js +270 -434
- package/dist/src/ruvector/ruvllm-wasm.js.map +1 -1
- package/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/dist/src/ruvector/semantic-router.d.ts.map +1 -0
- package/dist/src/ruvector/semantic-router.js +60 -67
- package/dist/src/ruvector/semantic-router.js.map +1 -1
- package/dist/src/ruvector/vector-db.d.ts +69 -0
- package/dist/src/ruvector/vector-db.d.ts.map +1 -0
- package/dist/src/ruvector/vector-db.js +119 -205
- package/dist/src/ruvector/vector-db.js.map +1 -1
- package/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/dist/src/services/agentic-flow-bridge.d.ts.map +1 -0
- package/dist/src/services/agentic-flow-bridge.js +32 -105
- package/dist/src/services/agentic-flow-bridge.js.map +1 -1
- package/dist/src/services/claim-service.d.ts +204 -0
- package/dist/src/services/claim-service.d.ts.map +1 -0
- package/dist/src/services/claim-service.js +615 -940
- package/dist/src/services/claim-service.js.map +1 -1
- package/dist/src/services/container-worker-pool.d.ts +197 -0
- package/dist/src/services/container-worker-pool.d.ts.map +1 -0
- package/dist/src/services/container-worker-pool.js +398 -666
- package/dist/src/services/container-worker-pool.js.map +1 -1
- package/dist/src/services/headless-worker-executor.d.ts +304 -0
- package/dist/src/services/headless-worker-executor.d.ts.map +1 -0
- package/dist/src/services/headless-worker-executor.js +441 -467
- package/dist/src/services/headless-worker-executor.js.map +1 -1
- package/dist/src/services/index.d.ts +4 -4
- package/dist/src/services/index.d.ts.map +1 -1
- package/dist/src/services/index.js +4 -4
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/services/registry-api.d.ts +58 -0
- package/dist/src/services/registry-api.d.ts.map +1 -0
- package/dist/src/services/registry-api.js +92 -200
- package/dist/src/services/registry-api.js.map +1 -1
- package/dist/src/services/ruvector-training.d.ts +222 -0
- package/dist/src/services/ruvector-training.d.ts.map +1 -0
- package/dist/src/services/ruvector-training.js +257 -337
- package/dist/src/services/ruvector-training.js.map +1 -1
- package/dist/src/services/worker-daemon.d.ts +228 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +591 -849
- package/dist/src/services/worker-daemon.js.map +1 -1
- package/dist/src/services/worker-queue.d.ts +194 -0
- package/dist/src/services/worker-queue.d.ts.map +1 -0
- package/dist/src/services/worker-queue.js +331 -548
- package/dist/src/services/worker-queue.js.map +1 -1
- package/dist/src/suggest.d.ts +53 -0
- package/dist/src/suggest.d.ts.map +1 -0
- package/dist/src/suggest.js +45 -55
- package/dist/src/suggest.js.map +1 -1
- package/dist/src/transfer/anonymization/index.js +29 -37
- package/dist/src/transfer/anonymization/index.js.map +1 -1
- package/dist/src/transfer/deploy-seraphine.js +128 -155
- package/dist/src/transfer/deploy-seraphine.js.map +1 -1
- package/dist/src/transfer/export.d.ts +25 -0
- package/dist/src/transfer/export.d.ts.map +1 -0
- package/dist/src/transfer/export.js +84 -142
- package/dist/src/transfer/export.js.map +1 -1
- package/dist/src/transfer/index.d.ts +1 -1
- package/dist/src/transfer/index.d.ts.map +1 -1
- package/dist/src/transfer/index.js +0 -2
- package/dist/src/transfer/index.js.map +1 -1
- package/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/dist/src/transfer/ipfs/client.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/client.js +187 -337
- package/dist/src/transfer/ipfs/client.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/dist/src/transfer/ipfs/upload.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/upload.js +288 -434
- package/dist/src/transfer/ipfs/upload.js.map +1 -1
- package/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/dist/src/transfer/models/seraphine.d.ts.map +1 -0
- package/dist/src/transfer/models/seraphine.js +55 -55
- package/dist/src/transfer/models/seraphine.js.map +1 -1
- package/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/dist/src/transfer/serialization/cfp.d.ts.map +1 -0
- package/dist/src/transfer/serialization/cfp.js +30 -31
- package/dist/src/transfer/serialization/cfp.js.map +1 -1
- package/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/dist/src/transfer/storage/gcs.d.ts.map +1 -0
- package/dist/src/transfer/storage/gcs.js +165 -232
- package/dist/src/transfer/storage/gcs.js.map +1 -1
- package/dist/src/transfer/store/discovery.d.ts +84 -0
- package/dist/src/transfer/store/discovery.d.ts.map +1 -0
- package/dist/src/transfer/store/discovery.js +239 -349
- package/dist/src/transfer/store/discovery.js.map +1 -1
- package/dist/src/transfer/store/download.d.ts +70 -0
- package/dist/src/transfer/store/download.d.ts.map +1 -0
- package/dist/src/transfer/store/download.js +243 -365
- package/dist/src/transfer/store/download.js.map +1 -1
- package/dist/src/transfer/store/index.d.ts +84 -0
- package/dist/src/transfer/store/index.d.ts.map +1 -0
- package/dist/src/transfer/store/index.js +63 -130
- package/dist/src/transfer/store/index.js.map +1 -1
- package/dist/src/transfer/store/publish.d.ts +76 -0
- package/dist/src/transfer/store/publish.d.ts.map +1 -0
- package/dist/src/transfer/store/publish.js +184 -258
- package/dist/src/transfer/store/publish.js.map +1 -1
- package/dist/src/transfer/store/registry.js +50 -72
- package/dist/src/transfer/store/registry.js.map +1 -1
- package/dist/src/transfer/store/search.d.ts +54 -0
- package/dist/src/transfer/store/search.d.ts.map +1 -0
- package/dist/src/transfer/store/search.js +64 -96
- package/dist/src/transfer/store/search.js.map +1 -1
- package/dist/src/transfer/store/tests/standalone-test.js +174 -231
- package/dist/src/transfer/store/tests/standalone-test.js.map +1 -1
- package/dist/src/transfer/test-seraphine.js +95 -130
- package/dist/src/transfer/test-seraphine.js.map +1 -1
- package/dist/src/transfer/tests/test-store.js +194 -239
- package/dist/src/transfer/tests/test-store.js.map +1 -1
- package/dist/src/transfer/types.d.ts +245 -0
- package/dist/src/transfer/types.d.ts.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +26 -55
- package/dist/src/types.js.map +1 -1
- package/dist/src/update/checker.d.ts +34 -0
- package/dist/src/update/checker.d.ts.map +1 -0
- package/dist/src/update/checker.js +106 -183
- package/dist/src/update/checker.js.map +1 -1
- package/dist/src/update/executor.d.ts +32 -0
- package/dist/src/update/executor.d.ts.map +1 -0
- package/dist/src/update/executor.js +135 -198
- package/dist/src/update/executor.js.map +1 -1
- package/dist/src/update/index.d.ts +33 -0
- package/dist/src/update/index.d.ts.map +1 -0
- package/dist/src/update/index.js +38 -85
- package/dist/src/update/index.js.map +1 -1
- package/dist/src/update/rate-limiter.d.ts +20 -0
- package/dist/src/update/rate-limiter.d.ts.map +1 -0
- package/dist/src/update/rate-limiter.js +19 -31
- package/dist/src/update/rate-limiter.js.map +1 -1
- package/dist/src/update/validator.d.ts +17 -0
- package/dist/src/update/validator.d.ts.map +1 -0
- package/dist/src/update/validator.js +38 -64
- package/dist/src/update/validator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -10,62 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module v3/cli/intelligence
|
|
12
12
|
*/
|
|
13
|
-
var __assign = (this && this.__assign) || function () {
|
|
14
|
-
__assign = Object.assign || function(t) {
|
|
15
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
16
|
-
s = arguments[i];
|
|
17
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
18
|
-
t[p] = s[p];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
return __assign.apply(this, arguments);
|
|
23
|
-
};
|
|
24
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
34
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
35
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
36
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
37
|
-
function step(op) {
|
|
38
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
39
|
-
while (_) try {
|
|
40
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
41
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
42
|
-
switch (op[0]) {
|
|
43
|
-
case 0: case 1: t = op; break;
|
|
44
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
45
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
46
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
47
|
-
default:
|
|
48
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
49
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
50
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
51
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
52
|
-
if (t[2]) _.ops.pop();
|
|
53
|
-
_.trys.pop(); continue;
|
|
54
|
-
}
|
|
55
|
-
op = body.call(thisArg, _);
|
|
56
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
57
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
61
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
62
|
-
if (ar || !(i in from)) {
|
|
63
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
64
|
-
ar[i] = from[i];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
68
|
-
};
|
|
69
13
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
70
14
|
import { homedir } from 'node:os';
|
|
71
15
|
import { join } from 'node:path';
|
|
@@ -78,9 +22,9 @@ import { join } from 'node:path';
|
|
|
78
22
|
* falling back to home directory
|
|
79
23
|
*/
|
|
80
24
|
function getDataDir() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
25
|
+
const cwd = process.cwd();
|
|
26
|
+
const localDir = join(cwd, '.claude-flow', 'neural');
|
|
27
|
+
const homeDir = join(homedir(), '.claude-flow', 'neural');
|
|
84
28
|
// Prefer local directory if .claude-flow exists
|
|
85
29
|
if (existsSync(join(cwd, '.claude-flow'))) {
|
|
86
30
|
return localDir;
|
|
@@ -91,7 +35,7 @@ function getDataDir() {
|
|
|
91
35
|
* Ensure the data directory exists
|
|
92
36
|
*/
|
|
93
37
|
function ensureDataDir() {
|
|
94
|
-
|
|
38
|
+
const dir = getDataDir();
|
|
95
39
|
if (!existsSync(dir)) {
|
|
96
40
|
mkdirSync(dir, { recursive: true });
|
|
97
41
|
}
|
|
@@ -112,7 +56,7 @@ function getStatsPath() {
|
|
|
112
56
|
// ============================================================================
|
|
113
57
|
// Default Configuration
|
|
114
58
|
// ============================================================================
|
|
115
|
-
|
|
59
|
+
const DEFAULT_SONA_CONFIG = {
|
|
116
60
|
instantLoopEnabled: true,
|
|
117
61
|
backgroundLoopEnabled: false,
|
|
118
62
|
loraLearningRate: 0.001,
|
|
@@ -131,13 +75,15 @@ var DEFAULT_SONA_CONFIG = {
|
|
|
131
75
|
* Uses circular buffer for O(1) signal recording
|
|
132
76
|
* Achieves <0.05ms per operation
|
|
133
77
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
78
|
+
class LocalSonaCoordinator {
|
|
79
|
+
config;
|
|
80
|
+
signals;
|
|
81
|
+
signalHead = 0;
|
|
82
|
+
signalCount = 0;
|
|
83
|
+
trajectories = [];
|
|
84
|
+
adaptationTimes = [];
|
|
85
|
+
currentTrajectorySteps = [];
|
|
86
|
+
constructor(config) {
|
|
141
87
|
this.config = config;
|
|
142
88
|
// Pre-allocate circular buffer
|
|
143
89
|
this.signals = new Array(config.maxSignals);
|
|
@@ -146,62 +92,61 @@ var LocalSonaCoordinator = /** @class */ (function () {
|
|
|
146
92
|
* Record a signal - O(1) operation
|
|
147
93
|
* Target: <0.05ms
|
|
148
94
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
95
|
+
recordSignal(signal) {
|
|
96
|
+
const start = performance.now();
|
|
151
97
|
// Circular buffer insertion - constant time
|
|
152
98
|
this.signals[this.signalHead] = signal;
|
|
153
99
|
this.signalHead = (this.signalHead + 1) % this.config.maxSignals;
|
|
154
100
|
if (this.signalCount < this.config.maxSignals) {
|
|
155
101
|
this.signalCount++;
|
|
156
102
|
}
|
|
157
|
-
|
|
103
|
+
const elapsed = performance.now() - start;
|
|
158
104
|
this.adaptationTimes.push(elapsed);
|
|
159
105
|
if (this.adaptationTimes.length > 100) {
|
|
160
106
|
this.adaptationTimes.shift();
|
|
161
107
|
}
|
|
162
|
-
}
|
|
108
|
+
}
|
|
163
109
|
/**
|
|
164
110
|
* Record complete trajectory
|
|
165
111
|
*/
|
|
166
|
-
|
|
112
|
+
recordTrajectory(trajectory) {
|
|
167
113
|
this.trajectories.push(trajectory);
|
|
168
114
|
if (this.trajectories.length > this.config.maxTrajectorySize) {
|
|
169
115
|
this.trajectories.shift();
|
|
170
116
|
}
|
|
171
|
-
}
|
|
117
|
+
}
|
|
172
118
|
/**
|
|
173
119
|
* Get recent signals
|
|
174
120
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var idx = (this.signalHead - 1 - i + this.config.maxSignals) % this.config.maxSignals;
|
|
121
|
+
getRecentSignals(count = 10) {
|
|
122
|
+
const result = [];
|
|
123
|
+
const actualCount = Math.min(count, this.signalCount);
|
|
124
|
+
for (let i = 0; i < actualCount; i++) {
|
|
125
|
+
const idx = (this.signalHead - 1 - i + this.config.maxSignals) % this.config.maxSignals;
|
|
181
126
|
if (this.signals[idx]) {
|
|
182
127
|
result.push(this.signals[idx]);
|
|
183
128
|
}
|
|
184
129
|
}
|
|
185
130
|
return result;
|
|
186
|
-
}
|
|
131
|
+
}
|
|
187
132
|
/**
|
|
188
133
|
* Get average adaptation time
|
|
189
134
|
*/
|
|
190
|
-
|
|
135
|
+
getAvgAdaptationTime() {
|
|
191
136
|
if (this.adaptationTimes.length === 0)
|
|
192
137
|
return 0;
|
|
193
|
-
return this.adaptationTimes.reduce(
|
|
194
|
-
}
|
|
138
|
+
return this.adaptationTimes.reduce((a, b) => a + b, 0) / this.adaptationTimes.length;
|
|
139
|
+
}
|
|
195
140
|
/**
|
|
196
141
|
* Add a step to the current in-progress trajectory
|
|
197
142
|
*/
|
|
198
|
-
|
|
143
|
+
addTrajectoryStep(step) {
|
|
199
144
|
this.currentTrajectorySteps.push(step);
|
|
200
145
|
// Prevent unbounded growth
|
|
201
146
|
if (this.currentTrajectorySteps.length > this.config.maxTrajectorySize) {
|
|
202
147
|
this.currentTrajectorySteps.shift();
|
|
203
148
|
}
|
|
204
|
-
}
|
|
149
|
+
}
|
|
205
150
|
/**
|
|
206
151
|
* End the current trajectory with a verdict and apply RL updates.
|
|
207
152
|
* Reward mapping: success=1.0, partial=0.5, failure=-0.5
|
|
@@ -209,52 +154,48 @@ var LocalSonaCoordinator = /** @class */ (function () {
|
|
|
209
154
|
* For successful/partial trajectories, boosts confidence of similar patterns
|
|
210
155
|
* in the ReasoningBank. For failures, reduces confidence scores.
|
|
211
156
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
k: 3,
|
|
237
|
-
threshold: 0.3
|
|
238
|
-
});
|
|
239
|
-
for (_c = 0, similar_1 = similar; _c < similar_1.length; _c++) {
|
|
240
|
-
match = similar_1[_c];
|
|
241
|
-
pattern = bank.get(match.id);
|
|
242
|
-
if (!pattern)
|
|
243
|
-
continue;
|
|
244
|
-
delta = reward * 0.1;
|
|
245
|
-
newConfidence = Math.max(0.0, Math.min(1.0, pattern.confidence + delta));
|
|
246
|
-
pattern.confidence = newConfidence;
|
|
247
|
-
pattern.usageCount++;
|
|
248
|
-
pattern.lastUsedAt = Date.now();
|
|
249
|
-
patternsUpdated++;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// Clear current trajectory
|
|
253
|
-
this.currentTrajectorySteps = [];
|
|
254
|
-
return [2 /*return*/, { reward: reward, patternsUpdated: patternsUpdated }];
|
|
157
|
+
async endTrajectory(verdict, bank) {
|
|
158
|
+
const rewardMap = {
|
|
159
|
+
success: 1.0,
|
|
160
|
+
partial: 0.5,
|
|
161
|
+
failure: -0.5
|
|
162
|
+
};
|
|
163
|
+
const reward = rewardMap[verdict] ?? 0;
|
|
164
|
+
// Record the completed trajectory
|
|
165
|
+
const completedTrajectory = {
|
|
166
|
+
steps: [...this.currentTrajectorySteps],
|
|
167
|
+
verdict,
|
|
168
|
+
timestamp: Date.now()
|
|
169
|
+
};
|
|
170
|
+
this.recordTrajectory(completedTrajectory);
|
|
171
|
+
// Update pattern confidences based on reward
|
|
172
|
+
let patternsUpdated = 0;
|
|
173
|
+
const allPatterns = bank.getAll();
|
|
174
|
+
for (const step of this.currentTrajectorySteps) {
|
|
175
|
+
if (!step.embedding || step.embedding.length === 0)
|
|
176
|
+
continue;
|
|
177
|
+
// Find patterns similar to this trajectory step
|
|
178
|
+
const similar = bank.findSimilar(step.embedding, {
|
|
179
|
+
k: 3,
|
|
180
|
+
threshold: 0.3
|
|
255
181
|
});
|
|
256
|
-
|
|
257
|
-
|
|
182
|
+
for (const match of similar) {
|
|
183
|
+
const pattern = bank.get(match.id);
|
|
184
|
+
if (!pattern)
|
|
185
|
+
continue;
|
|
186
|
+
// Adjust confidence: positive reward boosts, negative reduces
|
|
187
|
+
const delta = reward * 0.1; // small step per update
|
|
188
|
+
const newConfidence = Math.max(0.0, Math.min(1.0, pattern.confidence + delta));
|
|
189
|
+
pattern.confidence = newConfidence;
|
|
190
|
+
pattern.usageCount++;
|
|
191
|
+
pattern.lastUsedAt = Date.now();
|
|
192
|
+
patternsUpdated++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Clear current trajectory
|
|
196
|
+
this.currentTrajectorySteps = [];
|
|
197
|
+
return { reward, patternsUpdated };
|
|
198
|
+
}
|
|
258
199
|
/**
|
|
259
200
|
* Distill learning from recent successful trajectories.
|
|
260
201
|
* Applies LoRA-style confidence updates and integrates EWC++ consolidation.
|
|
@@ -263,140 +204,121 @@ var LocalSonaCoordinator = /** @class */ (function () {
|
|
|
263
204
|
* increases the pattern's stored confidence by loraLearningRate * reward.
|
|
264
205
|
* Before applying updates, checks EWC penalty to prevent catastrophic forgetting.
|
|
265
206
|
*/
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
continue;
|
|
320
|
-
oldConfidence = pattern.confidence;
|
|
321
|
-
// Check EWC penalty before applying update
|
|
322
|
-
if (ewcConsolidator) {
|
|
323
|
-
oldWeights = [oldConfidence];
|
|
324
|
-
proposedConfidence = Math.min(1.0, oldConfidence + this.config.loraLearningRate * reward);
|
|
325
|
-
newWeights = [proposedConfidence];
|
|
326
|
-
penalty = ewcConsolidator.getPenalty(oldWeights, newWeights);
|
|
327
|
-
totalEwcPenalty += penalty;
|
|
328
|
-
// If penalty is too high, reduce the update magnitude
|
|
329
|
-
if (penalty > this.config.ewcLambda) {
|
|
330
|
-
dampedDelta = (this.config.loraLearningRate * reward) / (1 + penalty);
|
|
331
|
-
pattern.confidence = Math.max(0.0, Math.min(1.0, oldConfidence + dampedDelta));
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
pattern.confidence = proposedConfidence;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
// No EWC: apply full LoRA update
|
|
339
|
-
pattern.confidence = Math.max(0.0, Math.min(1.0, oldConfidence + this.config.loraLearningRate * reward));
|
|
340
|
-
}
|
|
341
|
-
pattern.lastUsedAt = Date.now();
|
|
342
|
-
patternsDistilled++;
|
|
343
|
-
confidenceChanges.push({
|
|
344
|
-
id: pattern.id,
|
|
345
|
-
oldConf: oldConfidence,
|
|
346
|
-
newConf: pattern.confidence,
|
|
347
|
-
embedding: pattern.embedding
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
207
|
+
async distillLearning(bank) {
|
|
208
|
+
let patternsDistilled = 0;
|
|
209
|
+
let totalEwcPenalty = 0;
|
|
210
|
+
// Get recent successful trajectories
|
|
211
|
+
const recentSuccessful = this.trajectories.filter(t => t.verdict === 'success' || t.verdict === 'partial').slice(-10); // last 10 successful
|
|
212
|
+
if (recentSuccessful.length === 0) {
|
|
213
|
+
return { patternsDistilled: 0, ewcPenalty: 0 };
|
|
214
|
+
}
|
|
215
|
+
// Try to get EWC consolidator
|
|
216
|
+
let ewcConsolidator = null;
|
|
217
|
+
try {
|
|
218
|
+
const ewcModule = await import('./ewc-consolidation.js');
|
|
219
|
+
ewcConsolidator = await ewcModule.getEWCConsolidator({
|
|
220
|
+
lambda: this.config.ewcLambda
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
// EWC not available, proceed without consolidation protection
|
|
225
|
+
}
|
|
226
|
+
const rewardMap = {
|
|
227
|
+
success: 1.0,
|
|
228
|
+
partial: 0.5
|
|
229
|
+
};
|
|
230
|
+
// Collect confidence changes for EWC Fisher update
|
|
231
|
+
const confidenceChanges = [];
|
|
232
|
+
for (const trajectory of recentSuccessful) {
|
|
233
|
+
const reward = rewardMap[trajectory.verdict] ?? 0;
|
|
234
|
+
for (const step of trajectory.steps) {
|
|
235
|
+
if (!step.embedding || step.embedding.length === 0)
|
|
236
|
+
continue;
|
|
237
|
+
const similar = bank.findSimilar(step.embedding, {
|
|
238
|
+
k: 3,
|
|
239
|
+
threshold: 0.4
|
|
240
|
+
});
|
|
241
|
+
for (const match of similar) {
|
|
242
|
+
const pattern = bank.get(match.id);
|
|
243
|
+
if (!pattern)
|
|
244
|
+
continue;
|
|
245
|
+
// Only distill from high-confidence matches
|
|
246
|
+
if (match.confidence < 0.5)
|
|
247
|
+
continue;
|
|
248
|
+
const oldConfidence = pattern.confidence;
|
|
249
|
+
// Check EWC penalty before applying update
|
|
250
|
+
if (ewcConsolidator) {
|
|
251
|
+
const oldWeights = [oldConfidence];
|
|
252
|
+
const proposedConfidence = Math.min(1.0, oldConfidence + this.config.loraLearningRate * reward);
|
|
253
|
+
const newWeights = [proposedConfidence];
|
|
254
|
+
const penalty = ewcConsolidator.getPenalty(oldWeights, newWeights);
|
|
255
|
+
totalEwcPenalty += penalty;
|
|
256
|
+
// If penalty is too high, reduce the update magnitude
|
|
257
|
+
if (penalty > this.config.ewcLambda) {
|
|
258
|
+
const dampedDelta = (this.config.loraLearningRate * reward) / (1 + penalty);
|
|
259
|
+
pattern.confidence = Math.max(0.0, Math.min(1.0, oldConfidence + dampedDelta));
|
|
351
260
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
_loop_1 = function (change) {
|
|
355
|
-
// Use confidence delta as gradient proxy
|
|
356
|
-
var gradient = change.embedding.map(function (e) { return e * Math.abs(change.newConf - change.oldConf); });
|
|
357
|
-
ewcConsolidator.recordGradient(change.id, gradient, true);
|
|
358
|
-
};
|
|
359
|
-
for (_f = 0, confidenceChanges_1 = confidenceChanges; _f < confidenceChanges_1.length; _f++) {
|
|
360
|
-
change = confidenceChanges_1[_f];
|
|
361
|
-
_loop_1(change);
|
|
362
|
-
}
|
|
261
|
+
else {
|
|
262
|
+
pattern.confidence = proposedConfidence;
|
|
363
263
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// No EWC: apply full LoRA update
|
|
267
|
+
pattern.confidence = Math.max(0.0, Math.min(1.0, oldConfidence + this.config.loraLearningRate * reward));
|
|
268
|
+
}
|
|
269
|
+
pattern.lastUsedAt = Date.now();
|
|
270
|
+
patternsDistilled++;
|
|
271
|
+
confidenceChanges.push({
|
|
272
|
+
id: pattern.id,
|
|
273
|
+
oldConf: oldConfidence,
|
|
274
|
+
newConf: pattern.confidence,
|
|
275
|
+
embedding: pattern.embedding
|
|
276
|
+
});
|
|
367
277
|
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Update EWC Fisher matrix with confidence changes
|
|
281
|
+
if (ewcConsolidator && confidenceChanges.length > 0) {
|
|
282
|
+
for (const change of confidenceChanges) {
|
|
283
|
+
// Use confidence delta as gradient proxy
|
|
284
|
+
const gradient = change.embedding.map(e => e * Math.abs(change.newConf - change.oldConf));
|
|
285
|
+
ewcConsolidator.recordGradient(change.id, gradient, true);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Persist updated patterns
|
|
289
|
+
bank.flushToDisk();
|
|
290
|
+
return { patternsDistilled, ewcPenalty: totalEwcPenalty };
|
|
291
|
+
}
|
|
371
292
|
/**
|
|
372
293
|
* Get current trajectory steps (for inspection)
|
|
373
294
|
*/
|
|
374
|
-
|
|
375
|
-
return
|
|
376
|
-
}
|
|
295
|
+
getCurrentTrajectorySteps() {
|
|
296
|
+
return [...this.currentTrajectorySteps];
|
|
297
|
+
}
|
|
377
298
|
/**
|
|
378
299
|
* Get statistics
|
|
379
300
|
*/
|
|
380
|
-
|
|
301
|
+
stats() {
|
|
381
302
|
return {
|
|
382
303
|
signalCount: this.signalCount,
|
|
383
304
|
trajectoryCount: this.trajectories.length,
|
|
384
305
|
avgAdaptationMs: this.getAvgAdaptationTime()
|
|
385
306
|
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
}());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
389
309
|
/**
|
|
390
310
|
* Lightweight ReasoningBank
|
|
391
311
|
* Uses Map for O(1) storage and array for similarity search
|
|
392
312
|
* Supports persistence to disk
|
|
393
313
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
314
|
+
class LocalReasoningBank {
|
|
315
|
+
patterns = new Map();
|
|
316
|
+
patternList = [];
|
|
317
|
+
maxSize;
|
|
318
|
+
persistenceEnabled;
|
|
319
|
+
dirty = false;
|
|
320
|
+
saveTimeout = null;
|
|
321
|
+
constructor(options) {
|
|
400
322
|
this.maxSize = options.maxSize;
|
|
401
323
|
this.persistenceEnabled = options.persistence !== false;
|
|
402
324
|
// Load persisted patterns
|
|
@@ -407,29 +329,27 @@ var LocalReasoningBank = /** @class */ (function () {
|
|
|
407
329
|
/**
|
|
408
330
|
* Load patterns from disk
|
|
409
331
|
*/
|
|
410
|
-
|
|
332
|
+
loadFromDisk() {
|
|
411
333
|
try {
|
|
412
|
-
|
|
334
|
+
const path = getPatternsPath();
|
|
413
335
|
if (existsSync(path)) {
|
|
414
|
-
|
|
336
|
+
const data = JSON.parse(readFileSync(path, 'utf-8'));
|
|
415
337
|
if (Array.isArray(data)) {
|
|
416
|
-
for (
|
|
417
|
-
var pattern = data_1[_i];
|
|
338
|
+
for (const pattern of data) {
|
|
418
339
|
this.patterns.set(pattern.id, pattern);
|
|
419
340
|
this.patternList.push(pattern);
|
|
420
341
|
}
|
|
421
342
|
}
|
|
422
343
|
}
|
|
423
344
|
}
|
|
424
|
-
catch
|
|
345
|
+
catch {
|
|
425
346
|
// Ignore load errors, start fresh
|
|
426
347
|
}
|
|
427
|
-
}
|
|
348
|
+
}
|
|
428
349
|
/**
|
|
429
350
|
* Save patterns to disk (debounced)
|
|
430
351
|
*/
|
|
431
|
-
|
|
432
|
-
var _this = this;
|
|
352
|
+
saveToDisk() {
|
|
433
353
|
if (!this.persistenceEnabled)
|
|
434
354
|
return;
|
|
435
355
|
this.dirty = true;
|
|
@@ -437,19 +357,19 @@ var LocalReasoningBank = /** @class */ (function () {
|
|
|
437
357
|
if (this.saveTimeout) {
|
|
438
358
|
clearTimeout(this.saveTimeout);
|
|
439
359
|
}
|
|
440
|
-
this.saveTimeout = setTimeout(
|
|
441
|
-
|
|
360
|
+
this.saveTimeout = setTimeout(() => {
|
|
361
|
+
this.flushToDisk();
|
|
442
362
|
}, 100);
|
|
443
|
-
}
|
|
363
|
+
}
|
|
444
364
|
/**
|
|
445
365
|
* Immediately flush patterns to disk
|
|
446
366
|
*/
|
|
447
|
-
|
|
367
|
+
flushToDisk() {
|
|
448
368
|
if (!this.persistenceEnabled || !this.dirty)
|
|
449
369
|
return;
|
|
450
370
|
try {
|
|
451
371
|
ensureDataDir();
|
|
452
|
-
|
|
372
|
+
const path = getPatternsPath();
|
|
453
373
|
writeFileSync(path, JSON.stringify(this.patternList, null, 2), 'utf-8');
|
|
454
374
|
this.dirty = false;
|
|
455
375
|
}
|
|
@@ -457,21 +377,25 @@ var LocalReasoningBank = /** @class */ (function () {
|
|
|
457
377
|
// Log but don't throw - persistence failures shouldn't break training
|
|
458
378
|
console.error('Failed to persist patterns:', error);
|
|
459
379
|
}
|
|
460
|
-
}
|
|
380
|
+
}
|
|
461
381
|
/**
|
|
462
382
|
* Store a pattern - O(1)
|
|
463
383
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
384
|
+
store(pattern) {
|
|
385
|
+
const now = Date.now();
|
|
386
|
+
const stored = {
|
|
387
|
+
...pattern,
|
|
388
|
+
usageCount: pattern.usageCount ?? 0,
|
|
389
|
+
createdAt: pattern.createdAt ?? now,
|
|
390
|
+
lastUsedAt: pattern.lastUsedAt ?? now
|
|
391
|
+
};
|
|
468
392
|
// Update or insert
|
|
469
393
|
if (this.patterns.has(pattern.id)) {
|
|
470
|
-
|
|
394
|
+
const existing = this.patterns.get(pattern.id);
|
|
471
395
|
stored.usageCount = existing.usageCount + 1;
|
|
472
396
|
stored.createdAt = existing.createdAt;
|
|
473
397
|
// Update in list
|
|
474
|
-
|
|
398
|
+
const idx = this.patternList.findIndex(p => p.id === pattern.id);
|
|
475
399
|
if (idx >= 0) {
|
|
476
400
|
this.patternList[idx] = stored;
|
|
477
401
|
}
|
|
@@ -479,9 +403,9 @@ var LocalReasoningBank = /** @class */ (function () {
|
|
|
479
403
|
else {
|
|
480
404
|
// Evict oldest if at capacity
|
|
481
405
|
if (this.patterns.size >= this.maxSize) {
|
|
482
|
-
|
|
406
|
+
const oldest = this.patternList.shift();
|
|
483
407
|
if (oldest) {
|
|
484
|
-
this.patterns
|
|
408
|
+
this.patterns.delete(oldest.id);
|
|
485
409
|
}
|
|
486
410
|
}
|
|
487
411
|
this.patternList.push(stored);
|
|
@@ -489,110 +413,108 @@ var LocalReasoningBank = /** @class */ (function () {
|
|
|
489
413
|
this.patterns.set(pattern.id, stored);
|
|
490
414
|
// Trigger persistence (debounced)
|
|
491
415
|
this.saveToDisk();
|
|
492
|
-
}
|
|
416
|
+
}
|
|
493
417
|
/**
|
|
494
418
|
* Find similar patterns by embedding
|
|
495
419
|
*/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
var _a = options.k, k = _a === void 0 ? 5 : _a, _b = options.threshold, threshold = _b === void 0 ? 0.5 : _b, type = options.type;
|
|
420
|
+
findSimilar(queryEmbedding, options) {
|
|
421
|
+
const { k = 5, threshold = 0.5, type } = options;
|
|
499
422
|
// Filter by type if specified
|
|
500
|
-
|
|
501
|
-
? this.patternList.filter(
|
|
423
|
+
let candidates = type
|
|
424
|
+
? this.patternList.filter(p => p.type === type)
|
|
502
425
|
: this.patternList;
|
|
503
426
|
// Compute similarities
|
|
504
|
-
|
|
505
|
-
pattern
|
|
506
|
-
score:
|
|
507
|
-
})
|
|
427
|
+
const scored = candidates.map(pattern => ({
|
|
428
|
+
pattern,
|
|
429
|
+
score: this.cosineSim(queryEmbedding, pattern.embedding)
|
|
430
|
+
}));
|
|
508
431
|
// Filter by threshold and sort
|
|
509
432
|
return scored
|
|
510
|
-
.filter(
|
|
511
|
-
.sort(
|
|
433
|
+
.filter(s => s.score >= threshold)
|
|
434
|
+
.sort((a, b) => b.score - a.score)
|
|
512
435
|
.slice(0, k)
|
|
513
|
-
.map(
|
|
436
|
+
.map(s => {
|
|
514
437
|
// Update usage
|
|
515
438
|
s.pattern.usageCount++;
|
|
516
439
|
s.pattern.lastUsedAt = Date.now();
|
|
517
|
-
return
|
|
440
|
+
return { ...s.pattern, confidence: s.score };
|
|
518
441
|
});
|
|
519
|
-
}
|
|
442
|
+
}
|
|
520
443
|
/**
|
|
521
444
|
* Optimized cosine similarity
|
|
522
445
|
*/
|
|
523
|
-
|
|
446
|
+
cosineSim(a, b) {
|
|
524
447
|
if (!a || !b || a.length === 0 || b.length === 0)
|
|
525
448
|
return 0;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
for (
|
|
529
|
-
|
|
449
|
+
const len = Math.min(a.length, b.length);
|
|
450
|
+
let dot = 0, normA = 0, normB = 0;
|
|
451
|
+
for (let i = 0; i < len; i++) {
|
|
452
|
+
const ai = a[i], bi = b[i];
|
|
530
453
|
dot += ai * bi;
|
|
531
454
|
normA += ai * ai;
|
|
532
455
|
normB += bi * bi;
|
|
533
456
|
}
|
|
534
|
-
|
|
457
|
+
const mag = Math.sqrt(normA * normB);
|
|
535
458
|
return mag === 0 ? 0 : dot / mag;
|
|
536
|
-
}
|
|
459
|
+
}
|
|
537
460
|
/**
|
|
538
461
|
* Get statistics
|
|
539
462
|
*/
|
|
540
|
-
|
|
463
|
+
stats() {
|
|
541
464
|
return {
|
|
542
465
|
size: this.patterns.size,
|
|
543
466
|
patternCount: this.patternList.length
|
|
544
467
|
};
|
|
545
|
-
}
|
|
468
|
+
}
|
|
546
469
|
/**
|
|
547
470
|
* Get pattern by ID
|
|
548
471
|
*/
|
|
549
|
-
|
|
472
|
+
get(id) {
|
|
550
473
|
return this.patterns.get(id);
|
|
551
|
-
}
|
|
474
|
+
}
|
|
552
475
|
/**
|
|
553
476
|
* Get all patterns
|
|
554
477
|
*/
|
|
555
|
-
|
|
556
|
-
return
|
|
557
|
-
}
|
|
478
|
+
getAll() {
|
|
479
|
+
return [...this.patternList];
|
|
480
|
+
}
|
|
558
481
|
/**
|
|
559
482
|
* Get patterns by type
|
|
560
483
|
*/
|
|
561
|
-
|
|
562
|
-
return this.patternList.filter(
|
|
563
|
-
}
|
|
484
|
+
getByType(type) {
|
|
485
|
+
return this.patternList.filter(p => p.type === type);
|
|
486
|
+
}
|
|
564
487
|
/**
|
|
565
488
|
* Delete a pattern by ID
|
|
566
489
|
*/
|
|
567
|
-
|
|
568
|
-
|
|
490
|
+
delete(id) {
|
|
491
|
+
const pattern = this.patterns.get(id);
|
|
569
492
|
if (!pattern)
|
|
570
493
|
return false;
|
|
571
|
-
this.patterns
|
|
572
|
-
|
|
494
|
+
this.patterns.delete(id);
|
|
495
|
+
const idx = this.patternList.findIndex(p => p.id === id);
|
|
573
496
|
if (idx >= 0) {
|
|
574
497
|
this.patternList.splice(idx, 1);
|
|
575
498
|
}
|
|
576
499
|
this.saveToDisk();
|
|
577
500
|
return true;
|
|
578
|
-
}
|
|
501
|
+
}
|
|
579
502
|
/**
|
|
580
503
|
* Clear all patterns
|
|
581
504
|
*/
|
|
582
|
-
|
|
505
|
+
clear() {
|
|
583
506
|
this.patterns.clear();
|
|
584
507
|
this.patternList = [];
|
|
585
508
|
this.saveToDisk();
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
}());
|
|
509
|
+
}
|
|
510
|
+
}
|
|
589
511
|
// ============================================================================
|
|
590
512
|
// Module State
|
|
591
513
|
// ============================================================================
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
514
|
+
let sonaCoordinator = null;
|
|
515
|
+
let reasoningBank = null;
|
|
516
|
+
let intelligenceInitialized = false;
|
|
517
|
+
let globalStats = {
|
|
596
518
|
trajectoriesRecorded: 0,
|
|
597
519
|
lastAdaptation: null
|
|
598
520
|
};
|
|
@@ -603,18 +525,17 @@ var globalStats = {
|
|
|
603
525
|
* Load persisted stats from disk
|
|
604
526
|
*/
|
|
605
527
|
function loadPersistedStats() {
|
|
606
|
-
var _a, _b;
|
|
607
528
|
try {
|
|
608
|
-
|
|
529
|
+
const path = getStatsPath();
|
|
609
530
|
if (existsSync(path)) {
|
|
610
|
-
|
|
531
|
+
const data = JSON.parse(readFileSync(path, 'utf-8'));
|
|
611
532
|
if (data && typeof data === 'object') {
|
|
612
|
-
globalStats.trajectoriesRecorded =
|
|
613
|
-
globalStats.lastAdaptation =
|
|
533
|
+
globalStats.trajectoriesRecorded = data.trajectoriesRecorded ?? 0;
|
|
534
|
+
globalStats.lastAdaptation = data.lastAdaptation ?? null;
|
|
614
535
|
}
|
|
615
536
|
}
|
|
616
537
|
}
|
|
617
|
-
catch
|
|
538
|
+
catch {
|
|
618
539
|
// Ignore load errors, start fresh
|
|
619
540
|
}
|
|
620
541
|
}
|
|
@@ -624,10 +545,10 @@ function loadPersistedStats() {
|
|
|
624
545
|
function savePersistedStats() {
|
|
625
546
|
try {
|
|
626
547
|
ensureDataDir();
|
|
627
|
-
|
|
548
|
+
const path = getStatsPath();
|
|
628
549
|
writeFileSync(path, JSON.stringify(globalStats, null, 2), 'utf-8');
|
|
629
550
|
}
|
|
630
|
-
catch
|
|
551
|
+
catch {
|
|
631
552
|
// Ignore save errors
|
|
632
553
|
}
|
|
633
554
|
}
|
|
@@ -638,277 +559,210 @@ function savePersistedStats() {
|
|
|
638
559
|
* Initialize the intelligence system (SONA + ReasoningBank)
|
|
639
560
|
* Uses optimized local implementations
|
|
640
561
|
*/
|
|
641
|
-
export function initializeIntelligence(config) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
// Load persisted stats if available
|
|
662
|
-
loadPersistedStats();
|
|
663
|
-
intelligenceInitialized = true;
|
|
664
|
-
return [2 /*return*/, {
|
|
665
|
-
success: true,
|
|
666
|
-
sonaEnabled: true,
|
|
667
|
-
reasoningBankEnabled: true
|
|
668
|
-
}];
|
|
669
|
-
}
|
|
670
|
-
catch (error) {
|
|
671
|
-
return [2 /*return*/, {
|
|
672
|
-
success: false,
|
|
673
|
-
sonaEnabled: false,
|
|
674
|
-
reasoningBankEnabled: false,
|
|
675
|
-
error: error instanceof Error ? error.message : String(error)
|
|
676
|
-
}];
|
|
677
|
-
}
|
|
678
|
-
return [2 /*return*/];
|
|
562
|
+
export async function initializeIntelligence(config) {
|
|
563
|
+
if (intelligenceInitialized) {
|
|
564
|
+
return {
|
|
565
|
+
success: true,
|
|
566
|
+
sonaEnabled: !!sonaCoordinator,
|
|
567
|
+
reasoningBankEnabled: !!reasoningBank
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
// Merge config with defaults
|
|
572
|
+
const finalConfig = {
|
|
573
|
+
...DEFAULT_SONA_CONFIG,
|
|
574
|
+
...config
|
|
575
|
+
};
|
|
576
|
+
// Initialize local SONA (optimized for <0.05ms)
|
|
577
|
+
sonaCoordinator = new LocalSonaCoordinator(finalConfig);
|
|
578
|
+
// Initialize local ReasoningBank with persistence enabled
|
|
579
|
+
reasoningBank = new LocalReasoningBank({
|
|
580
|
+
maxSize: finalConfig.maxPatterns,
|
|
581
|
+
persistence: true
|
|
679
582
|
});
|
|
680
|
-
|
|
583
|
+
// Load persisted stats if available
|
|
584
|
+
loadPersistedStats();
|
|
585
|
+
intelligenceInitialized = true;
|
|
586
|
+
return {
|
|
587
|
+
success: true,
|
|
588
|
+
sonaEnabled: true,
|
|
589
|
+
reasoningBankEnabled: true
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
return {
|
|
594
|
+
success: false,
|
|
595
|
+
sonaEnabled: false,
|
|
596
|
+
reasoningBankEnabled: false,
|
|
597
|
+
error: error instanceof Error ? error.message : String(error)
|
|
598
|
+
};
|
|
599
|
+
}
|
|
681
600
|
}
|
|
682
601
|
/**
|
|
683
602
|
* Record a trajectory step for learning
|
|
684
603
|
* Performance: <0.05ms without embedding generation
|
|
685
604
|
*/
|
|
686
|
-
export function recordStep(step) {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
case 5:
|
|
712
|
-
bridgeResult = _d.sent();
|
|
713
|
-
if (bridgeResult) {
|
|
714
|
-
embedding = bridgeResult.embedding;
|
|
715
|
-
}
|
|
716
|
-
return [3 /*break*/, 7];
|
|
717
|
-
case 6:
|
|
718
|
-
_b = _d.sent();
|
|
719
|
-
return [3 /*break*/, 7];
|
|
720
|
-
case 7:
|
|
721
|
-
if (!!embedding) return [3 /*break*/, 10];
|
|
722
|
-
return [4 /*yield*/, import('./memory-initializer.js')];
|
|
723
|
-
case 8:
|
|
724
|
-
generateEmbedding = (_d.sent()).generateEmbedding;
|
|
725
|
-
return [4 /*yield*/, generateEmbedding(step.content)];
|
|
726
|
-
case 9:
|
|
727
|
-
result = _d.sent();
|
|
728
|
-
embedding = result.embedding;
|
|
729
|
-
_d.label = 10;
|
|
730
|
-
case 10:
|
|
731
|
-
// Record in SONA - <0.05ms
|
|
732
|
-
sonaCoordinator.recordSignal({
|
|
733
|
-
type: step.type,
|
|
734
|
-
content: step.content,
|
|
735
|
-
embedding: embedding,
|
|
736
|
-
metadata: step.metadata,
|
|
737
|
-
timestamp: step.timestamp || Date.now()
|
|
738
|
-
});
|
|
739
|
-
stepWithEmbedding = __assign(__assign({}, step), { embedding: embedding });
|
|
740
|
-
sonaCoordinator.addTrajectoryStep(stepWithEmbedding);
|
|
741
|
-
// Store in ReasoningBank for retrieval
|
|
742
|
-
if (reasoningBank) {
|
|
743
|
-
reasoningBank.store({
|
|
744
|
-
id: "step_" + Date.now() + "_" + Math.random().toString(36).substring(7),
|
|
745
|
-
type: step.type,
|
|
746
|
-
embedding: embedding,
|
|
747
|
-
content: step.content,
|
|
748
|
-
confidence: 1.0,
|
|
749
|
-
metadata: step.metadata
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
if (!(step.type === 'result' && reasoningBank)) return [3 /*break*/, 13];
|
|
753
|
-
verdict = ((_a = step.metadata) === null || _a === void 0 ? void 0 : _a.verdict) || 'partial';
|
|
754
|
-
return [4 /*yield*/, sonaCoordinator.endTrajectory(verdict, reasoningBank)];
|
|
755
|
-
case 11:
|
|
756
|
-
_d.sent();
|
|
757
|
-
// Distill learning from recent successful trajectories
|
|
758
|
-
return [4 /*yield*/, sonaCoordinator.distillLearning(reasoningBank)];
|
|
759
|
-
case 12:
|
|
760
|
-
// Distill learning from recent successful trajectories
|
|
761
|
-
_d.sent();
|
|
762
|
-
globalStats.lastAdaptation = Date.now();
|
|
763
|
-
_d.label = 13;
|
|
764
|
-
case 13:
|
|
765
|
-
globalStats.trajectoriesRecorded++;
|
|
766
|
-
savePersistedStats();
|
|
767
|
-
return [2 /*return*/, true];
|
|
768
|
-
case 14:
|
|
769
|
-
_c = _d.sent();
|
|
770
|
-
return [2 /*return*/, false];
|
|
771
|
-
case 15: return [2 /*return*/];
|
|
605
|
+
export async function recordStep(step) {
|
|
606
|
+
if (!sonaCoordinator) {
|
|
607
|
+
const init = await initializeIntelligence();
|
|
608
|
+
if (!init.success)
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
try {
|
|
612
|
+
// Generate embedding if not provided
|
|
613
|
+
// ADR-053: Try AgentDB v3 bridge embedder first
|
|
614
|
+
let embedding = step.embedding;
|
|
615
|
+
if (!embedding) {
|
|
616
|
+
try {
|
|
617
|
+
const bridge = await import('./memory-bridge.js');
|
|
618
|
+
const bridgeResult = await bridge.bridgeGenerateEmbedding(step.content);
|
|
619
|
+
if (bridgeResult) {
|
|
620
|
+
embedding = bridgeResult.embedding;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch {
|
|
624
|
+
// Bridge not available
|
|
625
|
+
}
|
|
626
|
+
if (!embedding) {
|
|
627
|
+
const { generateEmbedding } = await import('./memory-initializer.js');
|
|
628
|
+
const result = await generateEmbedding(step.content);
|
|
629
|
+
embedding = result.embedding;
|
|
772
630
|
}
|
|
631
|
+
}
|
|
632
|
+
// Record in SONA - <0.05ms
|
|
633
|
+
sonaCoordinator.recordSignal({
|
|
634
|
+
type: step.type,
|
|
635
|
+
content: step.content,
|
|
636
|
+
embedding,
|
|
637
|
+
metadata: step.metadata,
|
|
638
|
+
timestamp: step.timestamp || Date.now()
|
|
773
639
|
});
|
|
774
|
-
|
|
640
|
+
// Add to current trajectory for RL tracking
|
|
641
|
+
const stepWithEmbedding = { ...step, embedding };
|
|
642
|
+
sonaCoordinator.addTrajectoryStep(stepWithEmbedding);
|
|
643
|
+
// Store in ReasoningBank for retrieval
|
|
644
|
+
if (reasoningBank) {
|
|
645
|
+
reasoningBank.store({
|
|
646
|
+
id: `step_${Date.now()}_${Math.random().toString(36).substring(7)}`,
|
|
647
|
+
type: step.type,
|
|
648
|
+
embedding,
|
|
649
|
+
content: step.content,
|
|
650
|
+
confidence: 1.0,
|
|
651
|
+
metadata: step.metadata
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
// When a 'result' step arrives, end the trajectory and run RL loop
|
|
655
|
+
if (step.type === 'result' && reasoningBank) {
|
|
656
|
+
// Determine verdict from metadata or default to 'partial'
|
|
657
|
+
const verdict = step.metadata?.verdict || 'partial';
|
|
658
|
+
await sonaCoordinator.endTrajectory(verdict, reasoningBank);
|
|
659
|
+
// Distill learning from recent successful trajectories
|
|
660
|
+
await sonaCoordinator.distillLearning(reasoningBank);
|
|
661
|
+
globalStats.lastAdaptation = Date.now();
|
|
662
|
+
}
|
|
663
|
+
globalStats.trajectoriesRecorded++;
|
|
664
|
+
savePersistedStats();
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
775
670
|
}
|
|
776
671
|
/**
|
|
777
672
|
* Record a complete trajectory with verdict
|
|
778
673
|
*/
|
|
779
|
-
export function recordTrajectory(steps, verdict) {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
return [2 /*return*/, false];
|
|
791
|
-
_b.label = 2;
|
|
792
|
-
case 2:
|
|
793
|
-
_b.trys.push([2, 6, , 7]);
|
|
794
|
-
sonaCoordinator.recordTrajectory({
|
|
795
|
-
steps: steps,
|
|
796
|
-
verdict: verdict,
|
|
797
|
-
timestamp: Date.now()
|
|
798
|
-
});
|
|
799
|
-
if (!reasoningBank) return [3 /*break*/, 5];
|
|
800
|
-
// Load steps into the coordinator for endTrajectory processing
|
|
801
|
-
for (_i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
|
|
802
|
-
step = steps_1[_i];
|
|
803
|
-
sonaCoordinator.addTrajectoryStep(step);
|
|
804
|
-
}
|
|
805
|
-
return [4 /*yield*/, sonaCoordinator.endTrajectory(verdict, reasoningBank)];
|
|
806
|
-
case 3:
|
|
807
|
-
_b.sent();
|
|
808
|
-
return [4 /*yield*/, sonaCoordinator.distillLearning(reasoningBank)];
|
|
809
|
-
case 4:
|
|
810
|
-
_b.sent();
|
|
811
|
-
_b.label = 5;
|
|
812
|
-
case 5:
|
|
813
|
-
globalStats.trajectoriesRecorded++;
|
|
814
|
-
globalStats.lastAdaptation = Date.now();
|
|
815
|
-
savePersistedStats();
|
|
816
|
-
return [2 /*return*/, true];
|
|
817
|
-
case 6:
|
|
818
|
-
_a = _b.sent();
|
|
819
|
-
return [2 /*return*/, false];
|
|
820
|
-
case 7: return [2 /*return*/];
|
|
821
|
-
}
|
|
674
|
+
export async function recordTrajectory(steps, verdict) {
|
|
675
|
+
if (!sonaCoordinator) {
|
|
676
|
+
const init = await initializeIntelligence();
|
|
677
|
+
if (!init.success)
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
try {
|
|
681
|
+
sonaCoordinator.recordTrajectory({
|
|
682
|
+
steps,
|
|
683
|
+
verdict,
|
|
684
|
+
timestamp: Date.now()
|
|
822
685
|
});
|
|
823
|
-
|
|
686
|
+
// Apply RL: update pattern confidences based on verdict
|
|
687
|
+
if (reasoningBank) {
|
|
688
|
+
// Load steps into the coordinator for endTrajectory processing
|
|
689
|
+
for (const step of steps) {
|
|
690
|
+
sonaCoordinator.addTrajectoryStep(step);
|
|
691
|
+
}
|
|
692
|
+
await sonaCoordinator.endTrajectory(verdict, reasoningBank);
|
|
693
|
+
await sonaCoordinator.distillLearning(reasoningBank);
|
|
694
|
+
}
|
|
695
|
+
globalStats.trajectoriesRecorded++;
|
|
696
|
+
globalStats.lastAdaptation = Date.now();
|
|
697
|
+
savePersistedStats();
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
catch {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
824
703
|
}
|
|
825
|
-
export function findSimilarPatterns(query, options) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
case 2:
|
|
840
|
-
_e.trys.push([2, 11, , 12]);
|
|
841
|
-
queryEmbedding = null;
|
|
842
|
-
_e.label = 3;
|
|
843
|
-
case 3:
|
|
844
|
-
_e.trys.push([3, 6, , 7]);
|
|
845
|
-
return [4 /*yield*/, import('./memory-bridge.js')];
|
|
846
|
-
case 4:
|
|
847
|
-
bridge = _e.sent();
|
|
848
|
-
return [4 /*yield*/, bridge.bridgeGenerateEmbedding(query)];
|
|
849
|
-
case 5:
|
|
850
|
-
bridgeResult = _e.sent();
|
|
851
|
-
if (bridgeResult) {
|
|
852
|
-
queryEmbedding = bridgeResult.embedding;
|
|
853
|
-
}
|
|
854
|
-
return [3 /*break*/, 7];
|
|
855
|
-
case 6:
|
|
856
|
-
_c = _e.sent();
|
|
857
|
-
return [3 /*break*/, 7];
|
|
858
|
-
case 7:
|
|
859
|
-
if (!!queryEmbedding) return [3 /*break*/, 10];
|
|
860
|
-
return [4 /*yield*/, import('./memory-initializer.js')];
|
|
861
|
-
case 8:
|
|
862
|
-
generateEmbedding = (_e.sent()).generateEmbedding;
|
|
863
|
-
return [4 /*yield*/, generateEmbedding(query)];
|
|
864
|
-
case 9:
|
|
865
|
-
queryResult = _e.sent();
|
|
866
|
-
queryEmbedding = queryResult.embedding;
|
|
867
|
-
_e.label = 10;
|
|
868
|
-
case 10:
|
|
869
|
-
isHashFallback = queryEmbedding.length === 128;
|
|
870
|
-
defaultThreshold = isHashFallback ? 0.1 : 0.5;
|
|
871
|
-
results = reasoningBank.findSimilar(queryEmbedding, {
|
|
872
|
-
k: (_a = options === null || options === void 0 ? void 0 : options.k) !== null && _a !== void 0 ? _a : 5,
|
|
873
|
-
threshold: (_b = options === null || options === void 0 ? void 0 : options.threshold) !== null && _b !== void 0 ? _b : defaultThreshold,
|
|
874
|
-
type: options === null || options === void 0 ? void 0 : options.type
|
|
875
|
-
});
|
|
876
|
-
return [2 /*return*/, results.map(function (r) {
|
|
877
|
-
var _a, _b;
|
|
878
|
-
return ({
|
|
879
|
-
id: r.id,
|
|
880
|
-
type: r.type,
|
|
881
|
-
embedding: r.embedding,
|
|
882
|
-
content: r.content,
|
|
883
|
-
confidence: r.confidence,
|
|
884
|
-
usageCount: r.usageCount,
|
|
885
|
-
createdAt: r.createdAt,
|
|
886
|
-
lastUsedAt: r.lastUsedAt,
|
|
887
|
-
similarity: (_b = (_a = r.similarity) !== null && _a !== void 0 ? _a : r.confidence) !== null && _b !== void 0 ? _b : 0.5
|
|
888
|
-
});
|
|
889
|
-
})];
|
|
890
|
-
case 11:
|
|
891
|
-
_d = _e.sent();
|
|
892
|
-
return [2 /*return*/, []];
|
|
893
|
-
case 12: return [2 /*return*/];
|
|
704
|
+
export async function findSimilarPatterns(query, options) {
|
|
705
|
+
if (!reasoningBank) {
|
|
706
|
+
const init = await initializeIntelligence();
|
|
707
|
+
if (!init.success)
|
|
708
|
+
return [];
|
|
709
|
+
}
|
|
710
|
+
try {
|
|
711
|
+
// ADR-053: Try AgentDB v3 bridge embedder first
|
|
712
|
+
let queryEmbedding = null;
|
|
713
|
+
try {
|
|
714
|
+
const bridge = await import('./memory-bridge.js');
|
|
715
|
+
const bridgeResult = await bridge.bridgeGenerateEmbedding(query);
|
|
716
|
+
if (bridgeResult) {
|
|
717
|
+
queryEmbedding = bridgeResult.embedding;
|
|
894
718
|
}
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
// Bridge not available
|
|
722
|
+
}
|
|
723
|
+
if (!queryEmbedding) {
|
|
724
|
+
const { generateEmbedding } = await import('./memory-initializer.js');
|
|
725
|
+
const queryResult = await generateEmbedding(query);
|
|
726
|
+
queryEmbedding = queryResult.embedding;
|
|
727
|
+
}
|
|
728
|
+
// Hash-fallback embeddings (128-dim) produce lower cosine similarities
|
|
729
|
+
// than ONNX/transformer embeddings, so use a lower default threshold
|
|
730
|
+
const isHashFallback = queryEmbedding.length === 128;
|
|
731
|
+
const defaultThreshold = isHashFallback ? 0.1 : 0.5;
|
|
732
|
+
const results = reasoningBank.findSimilar(queryEmbedding, {
|
|
733
|
+
k: options?.k ?? 5,
|
|
734
|
+
threshold: options?.threshold ?? defaultThreshold,
|
|
735
|
+
type: options?.type
|
|
895
736
|
});
|
|
896
|
-
|
|
737
|
+
return results.map((r) => ({
|
|
738
|
+
id: r.id,
|
|
739
|
+
type: r.type,
|
|
740
|
+
embedding: r.embedding,
|
|
741
|
+
content: r.content,
|
|
742
|
+
confidence: r.confidence,
|
|
743
|
+
usageCount: r.usageCount,
|
|
744
|
+
createdAt: r.createdAt,
|
|
745
|
+
lastUsedAt: r.lastUsedAt,
|
|
746
|
+
similarity: r.similarity ?? r.confidence ?? 0.5
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
return [];
|
|
751
|
+
}
|
|
897
752
|
}
|
|
898
753
|
/**
|
|
899
754
|
* Get intelligence system statistics
|
|
900
755
|
*/
|
|
901
756
|
export function getIntelligenceStats() {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
var bankStats = reasoningBank === null || reasoningBank === void 0 ? void 0 : reasoningBank.stats();
|
|
757
|
+
const sonaStats = sonaCoordinator?.stats();
|
|
758
|
+
const bankStats = reasoningBank?.stats();
|
|
905
759
|
return {
|
|
906
760
|
sonaEnabled: !!sonaCoordinator,
|
|
907
|
-
reasoningBankSize:
|
|
908
|
-
patternsLearned:
|
|
761
|
+
reasoningBankSize: bankStats?.size ?? 0,
|
|
762
|
+
patternsLearned: bankStats?.patternCount ?? 0,
|
|
909
763
|
trajectoriesRecorded: globalStats.trajectoriesRecorded,
|
|
910
764
|
lastAdaptation: globalStats.lastAdaptation,
|
|
911
|
-
avgAdaptationTime:
|
|
765
|
+
avgAdaptationTime: sonaStats?.avgAdaptationMs ?? 0
|
|
912
766
|
};
|
|
913
767
|
}
|
|
914
768
|
/**
|
|
@@ -930,34 +784,21 @@ export function getReasoningBank() {
|
|
|
930
784
|
* @param verdict - 'success' (reward=1.0), 'partial' (0.5), or 'failure' (-0.5)
|
|
931
785
|
* @returns Update statistics or null if not initialized
|
|
932
786
|
*/
|
|
933
|
-
export function endTrajectoryWithVerdict(verdict) {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
return [4 /*yield*/, sonaCoordinator.endTrajectory(verdict, reasoningBank)];
|
|
949
|
-
case 3:
|
|
950
|
-
result = _b.sent();
|
|
951
|
-
globalStats.lastAdaptation = Date.now();
|
|
952
|
-
savePersistedStats();
|
|
953
|
-
return [2 /*return*/, result];
|
|
954
|
-
case 4:
|
|
955
|
-
_a = _b.sent();
|
|
956
|
-
return [2 /*return*/, null];
|
|
957
|
-
case 5: return [2 /*return*/];
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
});
|
|
787
|
+
export async function endTrajectoryWithVerdict(verdict) {
|
|
788
|
+
if (!sonaCoordinator || !reasoningBank) {
|
|
789
|
+
const init = await initializeIntelligence();
|
|
790
|
+
if (!init.success)
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
const result = await sonaCoordinator.endTrajectory(verdict, reasoningBank);
|
|
795
|
+
globalStats.lastAdaptation = Date.now();
|
|
796
|
+
savePersistedStats();
|
|
797
|
+
return result;
|
|
798
|
+
}
|
|
799
|
+
catch {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
961
802
|
}
|
|
962
803
|
/**
|
|
963
804
|
* Distill learning from recent successful trajectories.
|
|
@@ -965,34 +806,21 @@ export function endTrajectoryWithVerdict(verdict) {
|
|
|
965
806
|
*
|
|
966
807
|
* @returns Distillation statistics or null if not initialized
|
|
967
808
|
*/
|
|
968
|
-
export function distillLearning() {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
return [4 /*yield*/, sonaCoordinator.distillLearning(reasoningBank)];
|
|
984
|
-
case 3:
|
|
985
|
-
result = _b.sent();
|
|
986
|
-
globalStats.lastAdaptation = Date.now();
|
|
987
|
-
savePersistedStats();
|
|
988
|
-
return [2 /*return*/, result];
|
|
989
|
-
case 4:
|
|
990
|
-
_a = _b.sent();
|
|
991
|
-
return [2 /*return*/, null];
|
|
992
|
-
case 5: return [2 /*return*/];
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
});
|
|
809
|
+
export async function distillLearning() {
|
|
810
|
+
if (!sonaCoordinator || !reasoningBank) {
|
|
811
|
+
const init = await initializeIntelligence();
|
|
812
|
+
if (!init.success)
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
try {
|
|
816
|
+
const result = await sonaCoordinator.distillLearning(reasoningBank);
|
|
817
|
+
globalStats.lastAdaptation = Date.now();
|
|
818
|
+
savePersistedStats();
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
catch {
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
996
824
|
}
|
|
997
825
|
/**
|
|
998
826
|
* Clear intelligence state
|
|
@@ -1009,32 +837,31 @@ export function clearIntelligence() {
|
|
|
1009
837
|
/**
|
|
1010
838
|
* Benchmark SONA adaptation time
|
|
1011
839
|
*/
|
|
1012
|
-
export function benchmarkAdaptation(iterations) {
|
|
1013
|
-
if (iterations === void 0) { iterations = 1000; }
|
|
840
|
+
export function benchmarkAdaptation(iterations = 1000) {
|
|
1014
841
|
if (!sonaCoordinator) {
|
|
1015
842
|
initializeIntelligence();
|
|
1016
843
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
for (
|
|
1020
|
-
|
|
844
|
+
const times = [];
|
|
845
|
+
const testEmbedding = Array.from({ length: 384 }, () => Math.random());
|
|
846
|
+
for (let i = 0; i < iterations; i++) {
|
|
847
|
+
const start = performance.now();
|
|
1021
848
|
sonaCoordinator.recordSignal({
|
|
1022
849
|
type: 'test',
|
|
1023
|
-
content:
|
|
850
|
+
content: `benchmark_${i}`,
|
|
1024
851
|
embedding: testEmbedding,
|
|
1025
852
|
timestamp: Date.now()
|
|
1026
853
|
});
|
|
1027
854
|
times.push(performance.now() - start);
|
|
1028
855
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
856
|
+
const totalMs = times.reduce((a, b) => a + b, 0);
|
|
857
|
+
const avgMs = totalMs / iterations;
|
|
858
|
+
const minMs = Math.min(...times);
|
|
859
|
+
const maxMs = Math.max(...times);
|
|
1033
860
|
return {
|
|
1034
|
-
totalMs
|
|
1035
|
-
avgMs
|
|
1036
|
-
minMs
|
|
1037
|
-
maxMs
|
|
861
|
+
totalMs,
|
|
862
|
+
avgMs,
|
|
863
|
+
minMs,
|
|
864
|
+
maxMs,
|
|
1038
865
|
targetMet: avgMs < 0.05
|
|
1039
866
|
};
|
|
1040
867
|
}
|
|
@@ -1045,62 +872,42 @@ export function benchmarkAdaptation(iterations) {
|
|
|
1045
872
|
* Get all patterns from ReasoningBank
|
|
1046
873
|
* Returns persisted patterns even after process restart
|
|
1047
874
|
*/
|
|
1048
|
-
export function getAllPatterns() {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
embedding: p.embedding,
|
|
1065
|
-
content: p.content,
|
|
1066
|
-
confidence: p.confidence,
|
|
1067
|
-
usageCount: p.usageCount,
|
|
1068
|
-
createdAt: p.createdAt,
|
|
1069
|
-
lastUsedAt: p.lastUsedAt
|
|
1070
|
-
}); })];
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
});
|
|
875
|
+
export async function getAllPatterns() {
|
|
876
|
+
if (!reasoningBank) {
|
|
877
|
+
const init = await initializeIntelligence();
|
|
878
|
+
if (!init.success)
|
|
879
|
+
return [];
|
|
880
|
+
}
|
|
881
|
+
return reasoningBank.getAll().map(p => ({
|
|
882
|
+
id: p.id,
|
|
883
|
+
type: p.type,
|
|
884
|
+
embedding: p.embedding,
|
|
885
|
+
content: p.content,
|
|
886
|
+
confidence: p.confidence,
|
|
887
|
+
usageCount: p.usageCount,
|
|
888
|
+
createdAt: p.createdAt,
|
|
889
|
+
lastUsedAt: p.lastUsedAt
|
|
890
|
+
}));
|
|
1074
891
|
}
|
|
1075
892
|
/**
|
|
1076
893
|
* Get patterns by type from ReasoningBank
|
|
1077
894
|
*/
|
|
1078
|
-
export function getPatternsByType(type) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
embedding: p.embedding,
|
|
1095
|
-
content: p.content,
|
|
1096
|
-
confidence: p.confidence,
|
|
1097
|
-
usageCount: p.usageCount,
|
|
1098
|
-
createdAt: p.createdAt,
|
|
1099
|
-
lastUsedAt: p.lastUsedAt
|
|
1100
|
-
}); })];
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
});
|
|
895
|
+
export async function getPatternsByType(type) {
|
|
896
|
+
if (!reasoningBank) {
|
|
897
|
+
const init = await initializeIntelligence();
|
|
898
|
+
if (!init.success)
|
|
899
|
+
return [];
|
|
900
|
+
}
|
|
901
|
+
return reasoningBank.getByType(type).map(p => ({
|
|
902
|
+
id: p.id,
|
|
903
|
+
type: p.type,
|
|
904
|
+
embedding: p.embedding,
|
|
905
|
+
content: p.content,
|
|
906
|
+
confidence: p.confidence,
|
|
907
|
+
usageCount: p.usageCount,
|
|
908
|
+
createdAt: p.createdAt,
|
|
909
|
+
lastUsedAt: p.lastUsedAt
|
|
910
|
+
}));
|
|
1104
911
|
}
|
|
1105
912
|
/**
|
|
1106
913
|
* Flush patterns to disk immediately
|
|
@@ -1116,112 +923,80 @@ export function flushPatterns() {
|
|
|
1116
923
|
* Compact patterns by removing duplicates/similar patterns
|
|
1117
924
|
* @param threshold Similarity threshold (0-1), patterns above this are considered duplicates
|
|
1118
925
|
*/
|
|
1119
|
-
export function compactPatterns(threshold) {
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
dotProduct = 0;
|
|
1151
|
-
normA = 0;
|
|
1152
|
-
normB = 0;
|
|
1153
|
-
for (k = 0; k < embA.length; k++) {
|
|
1154
|
-
dotProduct += embA[k] * embB[k];
|
|
1155
|
-
normA += embA[k] * embA[k];
|
|
1156
|
-
normB += embB[k] * embB[k];
|
|
1157
|
-
}
|
|
1158
|
-
similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
1159
|
-
if (similarity >= threshold) {
|
|
1160
|
-
useA = patterns[i].usageCount || 0;
|
|
1161
|
-
useB = patterns[j].usageCount || 0;
|
|
1162
|
-
toRemove.add(useA >= useB ? patterns[j].id : patterns[i].id);
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
// Remove duplicates
|
|
1167
|
-
for (_i = 0, toRemove_1 = toRemove; _i < toRemove_1.length; _i++) {
|
|
1168
|
-
id = toRemove_1[_i];
|
|
1169
|
-
reasoningBank["delete"](id);
|
|
1170
|
-
}
|
|
1171
|
-
// Flush to disk
|
|
1172
|
-
flushPatterns();
|
|
1173
|
-
return [2 /*return*/, {
|
|
1174
|
-
before: before,
|
|
1175
|
-
after: before - toRemove.size,
|
|
1176
|
-
removed: toRemove.size
|
|
1177
|
-
}];
|
|
926
|
+
export async function compactPatterns(threshold = 0.95) {
|
|
927
|
+
if (!reasoningBank) {
|
|
928
|
+
const init = await initializeIntelligence();
|
|
929
|
+
if (!init.success) {
|
|
930
|
+
return { before: 0, after: 0, removed: 0 };
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
const patterns = reasoningBank.getAll();
|
|
934
|
+
const before = patterns.length;
|
|
935
|
+
// Find duplicates using cosine similarity
|
|
936
|
+
const toRemove = new Set();
|
|
937
|
+
for (let i = 0; i < patterns.length; i++) {
|
|
938
|
+
if (toRemove.has(patterns[i].id))
|
|
939
|
+
continue;
|
|
940
|
+
const embA = patterns[i].embedding;
|
|
941
|
+
if (!embA || embA.length === 0)
|
|
942
|
+
continue;
|
|
943
|
+
for (let j = i + 1; j < patterns.length; j++) {
|
|
944
|
+
if (toRemove.has(patterns[j].id))
|
|
945
|
+
continue;
|
|
946
|
+
const embB = patterns[j].embedding;
|
|
947
|
+
if (!embB || embB.length === 0 || embA.length !== embB.length)
|
|
948
|
+
continue;
|
|
949
|
+
// Compute cosine similarity
|
|
950
|
+
let dotProduct = 0;
|
|
951
|
+
let normA = 0;
|
|
952
|
+
let normB = 0;
|
|
953
|
+
for (let k = 0; k < embA.length; k++) {
|
|
954
|
+
dotProduct += embA[k] * embB[k];
|
|
955
|
+
normA += embA[k] * embA[k];
|
|
956
|
+
normB += embB[k] * embB[k];
|
|
1178
957
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
958
|
+
const similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
959
|
+
if (similarity >= threshold) {
|
|
960
|
+
// Remove the one with lower usage count
|
|
961
|
+
const useA = patterns[i].usageCount || 0;
|
|
962
|
+
const useB = patterns[j].usageCount || 0;
|
|
963
|
+
toRemove.add(useA >= useB ? patterns[j].id : patterns[i].id);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
// Remove duplicates
|
|
968
|
+
for (const id of toRemove) {
|
|
969
|
+
reasoningBank.delete(id);
|
|
970
|
+
}
|
|
971
|
+
// Flush to disk
|
|
972
|
+
flushPatterns();
|
|
973
|
+
return {
|
|
974
|
+
before,
|
|
975
|
+
after: before - toRemove.size,
|
|
976
|
+
removed: toRemove.size,
|
|
977
|
+
};
|
|
1181
978
|
}
|
|
1182
979
|
/**
|
|
1183
980
|
* Delete a pattern by ID
|
|
1184
981
|
*/
|
|
1185
|
-
export function deletePattern(id) {
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
return [4 /*yield*/, initializeIntelligence()];
|
|
1193
|
-
case 1:
|
|
1194
|
-
init = _a.sent();
|
|
1195
|
-
if (!init.success)
|
|
1196
|
-
return [2 /*return*/, false];
|
|
1197
|
-
_a.label = 2;
|
|
1198
|
-
case 2: return [2 /*return*/, reasoningBank["delete"](id)];
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
});
|
|
982
|
+
export async function deletePattern(id) {
|
|
983
|
+
if (!reasoningBank) {
|
|
984
|
+
const init = await initializeIntelligence();
|
|
985
|
+
if (!init.success)
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
return reasoningBank.delete(id);
|
|
1202
989
|
}
|
|
1203
990
|
/**
|
|
1204
991
|
* Clear all patterns (both in memory and on disk)
|
|
1205
992
|
*/
|
|
1206
|
-
export function clearAllPatterns() {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
return [4 /*yield*/, initializeIntelligence()];
|
|
1214
|
-
case 1:
|
|
1215
|
-
init = _a.sent();
|
|
1216
|
-
if (!init.success)
|
|
1217
|
-
return [2 /*return*/];
|
|
1218
|
-
_a.label = 2;
|
|
1219
|
-
case 2:
|
|
1220
|
-
reasoningBank.clear();
|
|
1221
|
-
return [2 /*return*/];
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
});
|
|
993
|
+
export async function clearAllPatterns() {
|
|
994
|
+
if (!reasoningBank) {
|
|
995
|
+
const init = await initializeIntelligence();
|
|
996
|
+
if (!init.success)
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
reasoningBank.clear();
|
|
1225
1000
|
}
|
|
1226
1001
|
/**
|
|
1227
1002
|
* Get the neural data directory path
|
|
@@ -1233,14 +1008,14 @@ export function getNeuralDataDir() {
|
|
|
1233
1008
|
* Get persistence status
|
|
1234
1009
|
*/
|
|
1235
1010
|
export function getPersistenceStatus() {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1011
|
+
const dataDir = getDataDir();
|
|
1012
|
+
const patternsFile = getPatternsPath();
|
|
1013
|
+
const statsFile = getStatsPath();
|
|
1239
1014
|
return {
|
|
1240
1015
|
enabled: true,
|
|
1241
|
-
dataDir
|
|
1242
|
-
patternsFile
|
|
1243
|
-
statsFile
|
|
1016
|
+
dataDir,
|
|
1017
|
+
patternsFile,
|
|
1018
|
+
statsFile,
|
|
1244
1019
|
patternsExist: existsSync(patternsFile),
|
|
1245
1020
|
statsExist: existsSync(statsFile)
|
|
1246
1021
|
};
|