claude-flow-novice 2.0.4 → 2.0.5
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/cli/commands/guidance.js +668 -487
- package/dist/src/cli/commands/index-validate.js +29 -18
- package/dist/src/cli/commands/mcp-troubleshoot.js +282 -230
- package/dist/src/cli/commands/neural-goal-init.js +125 -92
- package/dist/src/cli/commands/swarm-exec.js +393 -317
- package/dist/src/cli/commands/validate-framework.js +1100 -983
- package/dist/src/cli/commands/validate.js +223 -144
- package/dist/src/cli/main.js +1 -1
- package/dist/src/cli/simple-commands/__tests__/agent.test.js +277 -265
- package/dist/src/cli/simple-commands/__tests__/memory.test.js +7 -6
- package/dist/src/cli/simple-commands/__tests__/swarm.test.js +356 -373
- package/dist/src/cli/simple-commands/__tests__/task.test.js +7 -6
- package/dist/src/cli/simple-commands/agent.js +193 -157
- package/dist/src/cli/simple-commands/analysis.js +446 -336
- package/dist/src/cli/simple-commands/automation-executor.js +1339 -1095
- package/dist/src/cli/simple-commands/automation.js +469 -481
- package/dist/src/cli/simple-commands/batch-manager.js +313 -261
- package/dist/src/cli/simple-commands/claude-telemetry.js +267 -241
- package/dist/src/cli/simple-commands/claude-track.js +90 -68
- package/dist/src/cli/simple-commands/concurrent-display.js +320 -266
- package/dist/src/cli/simple-commands/config.js +290 -245
- package/dist/src/cli/simple-commands/coordination.js +234 -182
- package/dist/src/cli/simple-commands/enhanced-ui-views.js +615 -812
- package/dist/src/cli/simple-commands/enhanced-webui-complete.js +981 -922
- package/dist/src/cli/simple-commands/fix-hook-variables.js +294 -274
- package/dist/src/cli/simple-commands/github/gh-coordinator.js +457 -378
- package/dist/src/cli/simple-commands/github/github-api.js +574 -535
- package/dist/src/cli/simple-commands/github/init.js +303 -276
- package/dist/src/cli/simple-commands/github.js +247 -222
- package/dist/src/cli/simple-commands/goal.js +63 -51
- package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +278 -208
- package/dist/src/cli/simple-commands/hive-mind/communication.js +696 -601
- package/dist/src/cli/simple-commands/hive-mind/core.js +979 -907
- package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +655 -406
- package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1245 -1125
- package/dist/src/cli/simple-commands/hive-mind/memory.js +1090 -854
- package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +574 -459
- package/dist/src/cli/simple-commands/hive-mind/performance-test.js +347 -263
- package/dist/src/cli/simple-commands/hive-mind/queen.js +768 -727
- package/dist/src/cli/simple-commands/hive-mind/session-manager.js +1049 -745
- package/dist/src/cli/simple-commands/hive-mind-optimize.js +283 -227
- package/dist/src/cli/simple-commands/hive-mind-wizard.js +217 -174
- package/dist/src/cli/simple-commands/hive-mind.js +2282 -1841
- package/dist/src/cli/simple-commands/hive.js +79 -90
- package/dist/src/cli/simple-commands/hook-safety.js +521 -431
- package/dist/src/cli/simple-commands/hooks/session-start-soul.js +254 -203
- package/dist/src/cli/simple-commands/hooks.js +1204 -1064
- package/dist/src/cli/simple-commands/init/agent-copier.js +319 -294
- package/dist/src/cli/simple-commands/init/batch-init.js +562 -496
- package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +19 -13
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +19 -13
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +88 -61
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +150 -125
- package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +49 -42
- package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +61 -43
- package/dist/src/cli/simple-commands/init/copy-revised-templates.js +147 -141
- package/dist/src/cli/simple-commands/init/executable-wrapper.js +44 -31
- package/dist/src/cli/simple-commands/init/gitignore-updater.js +90 -64
- package/dist/src/cli/simple-commands/init/help.js +107 -104
- package/dist/src/cli/simple-commands/init/hive-mind-init.js +528 -509
- package/dist/src/cli/simple-commands/init/index.js +1759 -1510
- package/dist/src/cli/simple-commands/init/performance-monitor.js +317 -234
- package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +504 -441
- package/dist/src/cli/simple-commands/init/rollback/index.js +364 -289
- package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +728 -652
- package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +481 -416
- package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +448 -369
- package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +2 -1
- package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +99 -122
- package/dist/src/cli/simple-commands/init/sparc/workflows.js +37 -32
- package/dist/src/cli/simple-commands/init/sparc-structure.js +62 -55
- package/dist/src/cli/simple-commands/init/template-copier.js +533 -421
- package/dist/src/cli/simple-commands/init/templates/coordination-md.js +6 -3
- package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +318 -344
- package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +218 -173
- package/dist/src/cli/simple-commands/init/templates/github-safe.js +75 -65
- package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +6 -3
- package/dist/src/cli/simple-commands/init/templates/readme-files.js +4 -2
- package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +230 -187
- package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +80 -53
- package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +85 -101
- package/dist/src/cli/simple-commands/init/validation/config-validator.js +330 -283
- package/dist/src/cli/simple-commands/init/validation/health-checker.js +561 -495
- package/dist/src/cli/simple-commands/init/validation/index.js +358 -302
- package/dist/src/cli/simple-commands/init/validation/mode-validator.js +359 -308
- package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +366 -389
- package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +268 -270
- package/dist/src/cli/simple-commands/init/validation/test-runner.js +447 -427
- package/dist/src/cli/simple-commands/init.js +2 -1
- package/dist/src/cli/simple-commands/mcp-health.js +158 -131
- package/dist/src/cli/simple-commands/mcp-integration-layer.js +634 -533
- package/dist/src/cli/simple-commands/mcp.js +400 -345
- package/dist/src/cli/simple-commands/memory-consolidation.js +537 -426
- package/dist/src/cli/simple-commands/memory.js +311 -247
- package/dist/src/cli/simple-commands/migrate-hooks.js +46 -39
- package/dist/src/cli/simple-commands/monitor.js +363 -294
- package/dist/src/cli/simple-commands/neural.js +65 -51
- package/dist/src/cli/simple-commands/pair-autofix-only.js +662 -538
- package/dist/src/cli/simple-commands/pair-basic.js +656 -528
- package/dist/src/cli/simple-commands/pair-old.js +543 -430
- package/dist/src/cli/simple-commands/pair-working.js +751 -615
- package/dist/src/cli/simple-commands/pair.js +751 -615
- package/dist/src/cli/simple-commands/performance-hooks.js +111 -83
- package/dist/src/cli/simple-commands/performance-metrics.js +433 -348
- package/dist/src/cli/simple-commands/process-ui-enhanced.js +787 -708
- package/dist/src/cli/simple-commands/process-ui.js +254 -230
- package/dist/src/cli/simple-commands/realtime-update-system.js +611 -525
- package/dist/src/cli/simple-commands/sparc/architecture.js +1530 -1704
- package/dist/src/cli/simple-commands/sparc/commands.js +516 -438
- package/dist/src/cli/simple-commands/sparc/completion.js +1481 -1224
- package/dist/src/cli/simple-commands/sparc/coordinator.js +978 -913
- package/dist/src/cli/simple-commands/sparc/index.js +298 -241
- package/dist/src/cli/simple-commands/sparc/phase-base.js +390 -314
- package/dist/src/cli/simple-commands/sparc/pseudocode.js +869 -965
- package/dist/src/cli/simple-commands/sparc/refinement.js +1273 -980
- package/dist/src/cli/simple-commands/sparc/specification.js +645 -559
- package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/index.js +55 -47
- package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/swarm.js +87 -101
- package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
- package/dist/src/cli/simple-commands/sparc.js +493 -465
- package/dist/src/cli/simple-commands/start-ui.js +132 -108
- package/dist/src/cli/simple-commands/start-wrapper.js +268 -240
- package/dist/src/cli/simple-commands/start.js +1 -1
- package/dist/src/cli/simple-commands/status.js +275 -254
- package/dist/src/cli/simple-commands/stream-chain-clean.js +171 -128
- package/dist/src/cli/simple-commands/stream-chain-fixed.js +82 -61
- package/dist/src/cli/simple-commands/stream-chain-real.js +331 -267
- package/dist/src/cli/simple-commands/stream-chain-working.js +263 -211
- package/dist/src/cli/simple-commands/stream-chain.js +318 -260
- package/dist/src/cli/simple-commands/stream-processor.js +315 -290
- package/dist/src/cli/simple-commands/swarm-executor.js +222 -189
- package/dist/src/cli/simple-commands/swarm-metrics-integration.js +300 -208
- package/dist/src/cli/simple-commands/swarm-ui.js +703 -623
- package/dist/src/cli/simple-commands/swarm-webui-integration.js +286 -258
- package/dist/src/cli/simple-commands/swarm.js +1082 -887
- package/dist/src/cli/simple-commands/task.js +206 -161
- package/dist/src/cli/simple-commands/timestamp-fix.js +89 -59
- package/dist/src/cli/simple-commands/token-tracker.js +316 -258
- package/dist/src/cli/simple-commands/tool-execution-framework.js +519 -433
- package/dist/src/cli/simple-commands/train-and-stream.js +331 -275
- package/dist/src/cli/simple-commands/training-pipeline.js +725 -619
- package/dist/src/cli/simple-commands/training.js +227 -170
- package/dist/src/cli/simple-commands/verification-hooks.js +284 -261
- package/dist/src/cli/simple-commands/verification-integration.js +417 -389
- package/dist/src/cli/simple-commands/verification-training-integration.js +606 -486
- package/dist/src/cli/simple-commands/verification.js +513 -493
- package/dist/src/cli/simple-commands/web-server.js +836 -766
- package/dist/src/cli/simple-commands/webui-validator.js +124 -106
- package/dist/src/coordination/byzantine-memory-channels.js +25 -1
- package/dist/src/coordination/event-bus/demo-wasm-integration.js +251 -212
- package/dist/src/coordination/event-bus/qe-event-bus.js +748 -608
- package/dist/src/coordination/event-bus/qe-event-bus.test.js +454 -379
- package/dist/src/coordination/iteration-tracker.js +454 -363
- package/dist/src/index.js +384 -35
- package/dist/src/mcp/DEPRECATED.js +60 -46
- package/dist/src/mcp/fixes/mcp-error-fixes.js +134 -115
- package/dist/src/mcp/implementations/agent-tracker.js +128 -114
- package/dist/src/mcp/implementations/daa-tools.js +350 -292
- package/dist/src/mcp/implementations/workflow-tools.js +361 -329
- package/dist/src/mcp/mcp-config-manager.js +1331 -1183
- package/dist/src/mcp/mcp-server-novice-simplified.js +17 -11
- package/dist/src/mcp/mcp-server-novice.js +17 -11
- package/dist/src/mcp/mcp-server-sdk.js +17 -11
- package/dist/src/mcp/mcp-server.js +1484 -1620
- package/dist/src/mcp/ruv-swarm-wrapper.js +239 -209
- package/dist/src/memory/advanced-serializer.js +589 -609
- package/dist/src/memory/enhanced-examples.js +305 -220
- package/dist/src/memory/enhanced-memory.js +336 -295
- package/dist/src/memory/enhanced-session-serializer.js +492 -408
- package/dist/src/memory/fallback-memory-system.js +1021 -900
- package/dist/src/memory/fallback-store.js +131 -93
- package/dist/src/memory/high-performance-serialization.js +730 -592
- package/dist/src/memory/in-memory-store.js +213 -161
- package/dist/src/memory/index.js +157 -123
- package/dist/src/memory/lock-free-structures.js +764 -578
- package/dist/src/memory/memory-mapped-persistence.js +766 -585
- package/dist/src/memory/memory-pressure-manager.js +707 -569
- package/dist/src/memory/migration.js +445 -358
- package/dist/src/memory/shared-memory.js +768 -641
- package/dist/src/memory/sqlite-store.js +325 -245
- package/dist/src/memory/sqlite-wrapper.js +151 -122
- package/dist/src/memory/swarm-memory.js +603 -470
- package/dist/src/memory/test-example.js +134 -126
- package/dist/src/memory/ultra-fast-memory-store.js +821 -622
- package/dist/src/memory/unified-memory-manager.js +437 -356
- package/dist/src/swarm/CodeRefactoringSwarm.js +952 -777
- package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +400 -332
- package/dist/src/utils/error-handler.js +2 -36
- package/dist/src/utils/github-cli-safe.js +64 -56
- package/dist/src/utils/github-cli-safety-wrapper.js +546 -451
- package/dist/src/utils/npx-isolated-cache.js +119 -104
- package/dist/src/utils/preference-manager.js +652 -622
- package/dist/src/utils/timezone-utils.js +105 -86
- package/dist/src/web/api/apm-routes.js +353 -0
- package/dist/src/web/api/config/api-config.js +184 -0
- package/dist/src/web/api/middleware/auth.js +203 -0
- package/dist/src/web/api/middleware/cache.js +273 -0
- package/dist/src/web/api/middleware/error-handler.js +257 -0
- package/dist/src/web/api/middleware/request-logger.js +215 -0
- package/dist/src/web/api/middleware/validation.js +323 -0
- package/dist/src/web/api/routes/events.js +463 -0
- package/dist/src/web/api/routes/hierarchy.js +300 -0
- package/dist/src/web/api/routes/index.js +12 -0
- package/dist/src/web/api/routes/metrics.js +559 -0
- package/dist/src/web/api/routes/parallel-status.js +359 -0
- package/dist/src/web/api/routes/status.js +448 -0
- package/dist/src/web/api/server.js +462 -0
- package/dist/src/web/dashboard/hooks/useWebSocket.js +383 -0
- package/dist/src/web/dashboard/index.js +85 -0
- package/dist/src/web/dashboard/realtime/CustomSyncManager.js +439 -0
- package/dist/src/web/dashboard/realtime/NativeWebSocketManager.js +323 -0
- package/dist/src/web/dashboard/realtime/PerformanceBenchmark.js +527 -0
- package/dist/src/web/dashboard/realtime/RealtimeCommunicationManager.js +474 -0
- package/dist/src/web/dashboard/realtime/RealtimeServer.js +666 -0
- package/dist/src/web/dashboard/realtime/SSEManager.js +426 -0
- package/dist/src/web/dashboard/types.js +4 -0
- package/dist/src/web/messaging/agent-status-tracker.js +453 -0
- package/dist/src/web/messaging/human-intervention-system.js +305 -0
- package/dist/src/web/messaging/message-filter.js +302 -0
- package/dist/src/web/messaging/swarm-message-router.js +324 -0
- package/dist/src/web/messaging/transparency-logger.js +421 -0
- package/dist/src/web/portal-server.js +460 -0
- package/dist/src/web/server.js +322 -0
- package/dist/src/web/websocket/apm-websocket-handler.js +453 -0
- package/dist/src/web/websocket/websocket-manager.js +780 -0
- package/package.json +5 -3
- package/dist/src/cli/minimal-main.js +0 -22
- package/dist/src/enterprise/analytics-manager.js +0 -1135
- package/dist/src/enterprise/audit-manager.js +0 -1115
- package/dist/src/enterprise/cloud-manager.js +0 -891
- package/dist/src/enterprise/deployment-manager.js +0 -966
- package/dist/src/enterprise/index.js +0 -6
- package/dist/src/enterprise/project-manager.js +0 -584
- package/dist/src/enterprise/security-manager.js +0 -991
- package/dist/src/migration/index.js +0 -92
- package/dist/src/migration/logger.js +0 -121
- package/dist/src/migration/migration-analyzer.js +0 -268
- package/dist/src/migration/migration-runner.js +0 -522
- package/dist/src/migration/migration-validator.js +0 -285
- package/dist/src/migration/progress-reporter.js +0 -150
- package/dist/src/migration/rollback-manager.js +0 -321
- package/dist/src/migration/tests/migration-system.test.js +0 -7
- package/dist/src/migration/types.js +0 -3
- package/dist/src/swarm/__tests__/integration.test.js +0 -227
- package/dist/src/swarm/__tests__/prompt-copier.test.js +0 -344
- package/dist/src/swarm/advanced-orchestrator.js +0 -1095
- package/dist/src/swarm/claude-code-interface.js +0 -961
- package/dist/src/swarm/claude-flow-executor.js +0 -229
- package/dist/src/swarm/consensus-coordinator.js +0 -475
- package/dist/src/swarm/coordinator.js +0 -2993
- package/dist/src/swarm/direct-executor.js +0 -1180
- package/dist/src/swarm/error-recovery/advanced-error-detection.js +0 -691
- package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +0 -998
- package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +0 -1197
- package/dist/src/swarm/error-recovery/recovery-monitoring.js +0 -772
- package/dist/src/swarm/error-recovery/resilience-architecture.js +0 -714
- package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +0 -1319
- package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +0 -808
- package/dist/src/swarm/executor-v2.js +0 -322
- package/dist/src/swarm/executor.js +0 -815
- package/dist/src/swarm/hive-mind-integration.js +0 -703
- package/dist/src/swarm/index.js +0 -41
- package/dist/src/swarm/json-output-aggregator.js +0 -267
- package/dist/src/swarm/large-scale-coordinator.js +0 -542
- package/dist/src/swarm/mcp-integration-wrapper.js +0 -628
- package/dist/src/swarm/memory.js +0 -1117
- package/dist/src/swarm/optimizations/__tests__/optimization.test.js +0 -348
- package/dist/src/swarm/optimizations/async-file-manager.js +0 -285
- package/dist/src/swarm/optimizations/circular-buffer.js +0 -162
- package/dist/src/swarm/optimizations/connection-pool.js +0 -244
- package/dist/src/swarm/optimizations/index.js +0 -28
- package/dist/src/swarm/optimizations/optimized-executor.js +0 -320
- package/dist/src/swarm/optimizations/ttl-map.js +0 -234
- package/dist/src/swarm/prompt-cli.js +0 -200
- package/dist/src/swarm/prompt-copier-enhanced.js +0 -202
- package/dist/src/swarm/prompt-copier.js +0 -381
- package/dist/src/swarm/prompt-manager.js +0 -295
- package/dist/src/swarm/prompt-utils.js +0 -310
- package/dist/src/swarm/result-aggregator.js +0 -718
- package/dist/src/swarm/sparc-executor.js +0 -1568
- package/dist/src/swarm/strategies/auto.js +0 -758
- package/dist/src/swarm/strategies/base.js +0 -128
- package/dist/src/swarm/strategies/research.js +0 -914
- package/dist/src/swarm/strategies/strategy-metrics-patch.js +0 -2
- package/dist/src/swarm/types.js +0 -52
- package/dist/src/swarm/workers/copy-worker.js +0 -56
- package/dist/src/validators/epic-config-schema.js +0 -214
- package/dist/src/validators/index.js +0 -10
- package/dist/src/validators/swarm-init-validator.js +0 -259
- package/dist/src/validators/todowrite-batching-validator.js +0 -215
- package/dist/src/validators/todowrite-integration.js +0 -187
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/documentSymbols/browser/documentSymbols.js +0 -23
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/copyPasteContribution.js +0 -57
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/copyPasteController.js +0 -401
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/defaultProviders.js +0 -181
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/dropIntoEditorContribution.js +0 -44
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/dropIntoEditorController.js +0 -157
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/dropOrPasteInto/browser/edit.js +0 -71
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/editorState/browser/editorState.js +0 -112
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findController.js +0 -990
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findDecorations.js +0 -296
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findModel.js +0 -488
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findOptionsWidget.js +0 -138
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findState.js +0 -243
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/find/browser/findWidget.js +0 -1177
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/folding/browser/folding.js +0 -1093
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/folding/browser/foldingDecorations.js +0 -133
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/folding/browser/foldingModel.js +0 -538
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/folding/browser/foldingRanges.js +0 -351
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/fontZoom/browser/fontZoom.js +0 -49
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/format/browser/format.js +0 -360
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/format/browser/formatActions.js +0 -263
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/format/browser/formattingEdit.js +0 -54
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/gotoSymbol/browser/link/clickLinkGesture.js +0 -149
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/hover/browser/contentHover.js +0 -874
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/inlineCompletions/browser/commandIds.js +0 -7
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/inlineCompletions/browser/commands.js +0 -199
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/linesOperations/browser/copyLinesCommand.js +0 -70
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/quickAccess/browser/commandsQuickAccess.js +0 -26
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/quickAccess/browser/editorNavigationQuickAccess.js +0 -153
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/readOnlyMessage/browser/contribution.js +0 -33
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/semanticTokens/browser/documentSemanticTokens.js +0 -354
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/smartSelect/browser/bracketSelections.js +0 -146
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/suggest/browser/completionModel.js +0 -224
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/contrib/unicodeHighlighter/browser/bannerController.js +0 -119
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/edcore.main.js +0 -14
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/editor.all.js +0 -63
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/editor.api.js +0 -55
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/editor.main.js +0 -7
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/editor.worker.js +0 -25
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/editor/standalone/browser/colorizer.js +0 -118
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/language/css/css.worker.js +0 -36869
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/language/css/cssMode.js +0 -2035
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/accessibility/browser/accessibilityService.js +0 -88
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/accessibility/common/accessibility.js +0 -9
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/action/common/action.js +0 -7
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/action/common/actionCommonCategories.js +0 -13
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/actionWidget/browser/actionList.js +0 -276
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/actionWidget/browser/actionWidget.js +0 -248
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/actionWidget/common/actionWidget.js +0 -5
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/actions/common/actions.js +0 -409
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/audioCues/browser/audioCueService.js +0 -176
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/clipboard/browser/clipboardService.js +0 -141
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/clipboard/common/clipboardService.js +0 -6
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/commands/common/commands.js +0 -80
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/configuration/common/configuration.js +0 -86
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/configuration/common/configurationModels.js +0 -554
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/configuration/common/configurationRegistry.js +0 -317
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/configuration/common/configurations.js +0 -41
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextkey/browser/contextKeyService.js +0 -432
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextkey/common/contextkey.js +0 -1547
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextkey/common/contextkeys.js +0 -18
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextview/browser/contextMenuHandler.js +0 -124
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextview/browser/contextMenuService.js +0 -101
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextview/browser/contextView.js +0 -7
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/contextview/browser/contextViewService.js +0 -72
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/dialogs/common/dialogs.js +0 -2
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/dnd/browser/dnd.js +0 -36
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/editor/common/editor.js +0 -17
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/environment/common/environment.js +0 -2
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/extensions/common/extensions.js +0 -47
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/files/common/files.js +0 -9
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/history/browser/contextScopedHistoryWidget.js +0 -105
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/instantiation/common/descriptors.js +0 -11
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/instantiation/common/extensions.js +0 -15
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/keybinding/common/abstractKeybindingService.js +0 -277
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -53
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/quickinput/browser/commandsQuickAccess.js +0 -354
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/theme/browser/defaultStyles.js +0 -162
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/esm/vs/platform/theme/common/colorRegistry.js +0 -482
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/abap/abap.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/apex/apex.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/azcli/azcli.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/bat/bat.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/bicep/bicep.js +0 -11
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/cameligo/cameligo.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/clojure/clojure.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/coffee/coffee.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/cpp/cpp.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/csharp/csharp.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/csp/csp.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/css/css.js +0 -12
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/cypher/cypher.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/dart/dart.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/dockerfile/dockerfile.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/ecl/ecl.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/elixir/elixir.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/basic-languages/flow9/flow9.js +0 -10
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.js +0 -745
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.de.js +0 -31
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.es.js +0 -31
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.fr.js +0 -29
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.it.js +0 -29
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.ja.js +0 -31
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.js +0 -29
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.ko.js +0 -29
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.ru.js +0 -31
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.zh-cn.js +0 -31
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/editor/editor.main.nls.zh-tw.js +0 -29
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/language/css/cssMode.js +0 -13
- package/dist/src/web/frontend/node_modules/.monaco-editor-MndU045b/min/vs/language/css/cssWorker.js +0 -81
- package/dist/src/web/frontend/node_modules/.multicast-dns-iKseM9bB/cli.js +0 -64
- package/dist/src/web/frontend/node_modules/.multicast-dns-iKseM9bB/example.js +0 -36
- package/dist/src/web/frontend/node_modules/.multicast-dns-iKseM9bB/index.js +0 -205
- package/dist/src/web/frontend/node_modules/.multicast-dns-iKseM9bB/test.js +0 -260
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/async/index.browser.js +0 -34
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/async/index.js +0 -35
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/async/index.native.js +0 -26
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/index.browser.js +0 -34
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/index.js +0 -45
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/nanoid.js +0 -1
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/non-secure/index.js +0 -21
- package/dist/src/web/frontend/node_modules/.nanoid-PAMEV9Hd/url-alphabet/index.js +0 -3
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/bin/nodemon.js +0 -16
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/cli/index.js +0 -49
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/cli/parse.js +0 -230
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/config/command.js +0 -43
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/config/defaults.js +0 -34
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/config/exec.js +0 -234
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/config/index.js +0 -93
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/config/load.js +0 -225
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/help/index.js +0 -27
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/index.js +0 -1
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/monitor/index.js +0 -4
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/monitor/match.js +0 -287
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/monitor/run.js +0 -562
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/monitor/signals.js +0 -34
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/monitor/watch.js +0 -244
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/nodemon.js +0 -317
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/rules/add.js +0 -89
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/rules/index.js +0 -53
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/rules/parse.js +0 -43
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/spawn.js +0 -74
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/bus.js +0 -44
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/clone.js +0 -40
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/colour.js +0 -26
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/index.js +0 -103
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/log.js +0 -82
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/utils/merge.js +0 -47
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/lib/version.js +0 -100
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/node_modules/brace-expansion/index.js +0 -201
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/node_modules/has-flag/index.js +0 -8
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/node_modules/minimatch/minimatch.js +0 -947
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/node_modules/supports-color/browser.js +0 -5
- package/dist/src/web/frontend/node_modules/.nodemon-QcvNKhKT/node_modules/supports-color/index.js +0 -131
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/bin/pidtree.js +0 -128
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/index.js +0 -49
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/lib/bin.js +0 -61
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/lib/get.js +0 -45
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/lib/pidtree.js +0 -104
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/lib/ps.js +0 -47
- package/dist/src/web/frontend/node_modules/.pidtree-icfat3SQ/lib/wmic.js +0 -49
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/doc.js +0 -1270
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/acorn.js +0 -15
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/angular.js +0 -2
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/babel.js +0 -15
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/estree.js +0 -36
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/flow.js +0 -19
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/glimmer.js +0 -29
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/graphql.js +0 -29
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/html.js +0 -22
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/markdown.js +0 -63
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/meriyah.js +0 -4
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/postcss.js +0 -54
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/typescript.js +0 -20
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/plugins/yaml.js +0 -160
- package/dist/src/web/frontend/node_modules/.prettier-ApZm3b7s/standalone.js +0 -34
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/bin/react-scripts.js +0 -58
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/env.js +0 -112
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/getHttpsConfig.js +0 -74
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/jest/babelTransform.js +0 -37
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/jest/cssTransform.js +0 -22
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/jest/fileTransform.js +0 -40
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/modules.js +0 -142
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/paths.js +0 -153
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/webpack.config.js +0 -796
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/config/webpackDevServer.config.js +0 -135
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/scripts/build.js +0 -225
- package/dist/src/web/frontend/node_modules/.react-scripts-OTANyoRb/scripts/eject.js +0 -340
|
@@ -1,188 +1,250 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Collective Memory System for Hive Mind
|
|
3
3
|
* Shared knowledge base and learning system
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import EventEmitter from 'events';
|
|
7
|
+
import Database from 'better-sqlite3';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { performance } from 'perf_hooks';
|
|
10
|
+
import { Worker } from 'worker_threads';
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Memory types and their characteristics
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
task: {
|
|
22
|
-
priority: 3,
|
|
23
|
-
ttl: 1800000,
|
|
24
|
-
compress: true
|
|
25
|
-
},
|
|
26
|
-
result: {
|
|
27
|
-
priority: 2,
|
|
28
|
-
ttl: null,
|
|
29
|
-
compress: true
|
|
30
|
-
},
|
|
31
|
-
error: {
|
|
32
|
-
priority: 1,
|
|
33
|
-
ttl: 86400000,
|
|
34
|
-
compress: false
|
|
35
|
-
},
|
|
36
|
-
metric: {
|
|
37
|
-
priority: 3,
|
|
38
|
-
ttl: 3600000,
|
|
39
|
-
compress: true
|
|
40
|
-
},
|
|
41
|
-
consensus: {
|
|
42
|
-
priority: 1,
|
|
43
|
-
ttl: null,
|
|
44
|
-
compress: false
|
|
45
|
-
},
|
|
46
|
-
system: {
|
|
47
|
-
priority: 1,
|
|
48
|
-
ttl: null,
|
|
49
|
-
compress: false
|
|
50
|
-
}
|
|
14
|
+
*/
|
|
15
|
+
const MEMORY_TYPES = {
|
|
16
|
+
knowledge: { priority: 1, ttl: null, compress: false },
|
|
17
|
+
context: { priority: 2, ttl: 3600000, compress: false }, // 1 hour
|
|
18
|
+
task: { priority: 3, ttl: 1800000, compress: true }, // 30 minutes
|
|
19
|
+
result: { priority: 2, ttl: null, compress: true },
|
|
20
|
+
error: { priority: 1, ttl: 86400000, compress: false }, // 24 hours
|
|
21
|
+
metric: { priority: 3, ttl: 3600000, compress: true }, // 1 hour
|
|
22
|
+
consensus: { priority: 1, ttl: null, compress: false },
|
|
23
|
+
system: { priority: 1, ttl: null, compress: false },
|
|
51
24
|
};
|
|
25
|
+
|
|
52
26
|
/**
|
|
53
27
|
* Memory Pool for object reuse
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getStats() {
|
|
70
|
-
return {
|
|
71
|
-
poolSize: this.pool.length,
|
|
72
|
-
allocated: this.allocated,
|
|
73
|
-
reused: this.reused,
|
|
74
|
-
reuseRate: this.reused / (this.allocated + this.reused) * 100
|
|
75
|
-
};
|
|
28
|
+
*/
|
|
29
|
+
class MemoryPool {
|
|
30
|
+
constructor(createFn, resetFn, maxSize = 1000) {
|
|
31
|
+
this.createFn = createFn;
|
|
32
|
+
this.resetFn = resetFn;
|
|
33
|
+
this.maxSize = maxSize;
|
|
34
|
+
this.pool = [];
|
|
35
|
+
this.allocated = 0;
|
|
36
|
+
this.reused = 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
acquire() {
|
|
40
|
+
if (this.pool.length > 0) {
|
|
41
|
+
this.reused++;
|
|
42
|
+
return this.pool.pop();
|
|
76
43
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
44
|
+
this.allocated++;
|
|
45
|
+
return this.createFn();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
release(obj) {
|
|
49
|
+
if (this.pool.length < this.maxSize) {
|
|
50
|
+
this.resetFn(obj);
|
|
51
|
+
this.pool.push(obj);
|
|
84
52
|
}
|
|
85
|
-
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getStats() {
|
|
56
|
+
return {
|
|
57
|
+
poolSize: this.pool.length,
|
|
58
|
+
allocated: this.allocated,
|
|
59
|
+
reused: this.reused,
|
|
60
|
+
reuseRate: (this.reused / (this.allocated + this.reused)) * 100,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
86
65
|
/**
|
|
87
66
|
* Optimized LRU Cache with memory pressure handling
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
67
|
+
*/
|
|
68
|
+
class OptimizedLRUCache {
|
|
69
|
+
constructor(maxSize = 1000, maxMemoryMB = 50) {
|
|
70
|
+
this.maxSize = maxSize;
|
|
71
|
+
this.maxMemory = maxMemoryMB * 1024 * 1024;
|
|
72
|
+
this.cache = new Map();
|
|
73
|
+
this.currentMemory = 0;
|
|
74
|
+
this.hits = 0;
|
|
75
|
+
this.misses = 0;
|
|
76
|
+
this.evictions = 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get(key) {
|
|
80
|
+
if (this.cache.has(key)) {
|
|
81
|
+
const value = this.cache.get(key);
|
|
82
|
+
// Move to end (most recently used)
|
|
83
|
+
this.cache.delete(key);
|
|
84
|
+
this.cache.set(key, value);
|
|
85
|
+
this.hits++;
|
|
86
|
+
return value.data;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const entry = {
|
|
112
|
-
data,
|
|
113
|
-
size,
|
|
114
|
-
timestamp: Date.now()
|
|
115
|
-
};
|
|
116
|
-
this.cache.set(key, entry);
|
|
117
|
-
this.currentMemory += size;
|
|
118
|
-
}
|
|
119
|
-
_estimateSize(obj) {
|
|
120
|
-
return JSON.stringify(obj).length * 2; // Rough estimate
|
|
88
|
+
this.misses++;
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
set(key, data) {
|
|
93
|
+
const size = this._estimateSize(data);
|
|
94
|
+
|
|
95
|
+
// Check memory pressure
|
|
96
|
+
if (this.currentMemory + size > this.maxMemory) {
|
|
97
|
+
this._evictByMemoryPressure(size);
|
|
121
98
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.cache.delete(firstKey);
|
|
127
|
-
this.currentMemory -= entry.size;
|
|
128
|
-
this.evictions++;
|
|
129
|
-
}
|
|
99
|
+
|
|
100
|
+
// Check size limit
|
|
101
|
+
if (this.cache.size >= this.maxSize) {
|
|
102
|
+
this._evictLRU();
|
|
130
103
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
104
|
+
|
|
105
|
+
const entry = {
|
|
106
|
+
data,
|
|
107
|
+
size,
|
|
108
|
+
timestamp: Date.now(),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
this.cache.set(key, entry);
|
|
112
|
+
this.currentMemory += size;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_estimateSize(obj) {
|
|
116
|
+
return JSON.stringify(obj).length * 2; // Rough estimate
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_evictLRU() {
|
|
120
|
+
const firstKey = this.cache.keys().next().value;
|
|
121
|
+
if (firstKey) {
|
|
122
|
+
const entry = this.cache.get(firstKey);
|
|
123
|
+
this.cache.delete(firstKey);
|
|
124
|
+
this.currentMemory -= entry.size;
|
|
125
|
+
this.evictions++;
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_evictByMemoryPressure(neededSize) {
|
|
130
|
+
while (this.currentMemory + neededSize > this.maxMemory && this.cache.size > 0) {
|
|
131
|
+
this._evictLRU();
|
|
140
132
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
forEach(callback) {
|
|
136
|
+
this.cache.forEach((entry, key) => {
|
|
137
|
+
callback(entry, key);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
delete(key) {
|
|
142
|
+
if (this.cache.has(key)) {
|
|
143
|
+
const entry = this.cache.get(key);
|
|
144
|
+
this.cache.delete(key);
|
|
145
|
+
this.currentMemory -= entry.size;
|
|
146
|
+
return true;
|
|
149
147
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.hits = 0;
|
|
164
|
-
this.misses = 0;
|
|
165
|
-
this.evictions = 0;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getStats() {
|
|
152
|
+
return {
|
|
153
|
+
size: this.cache.size,
|
|
154
|
+
memoryUsage: this.currentMemory,
|
|
155
|
+
hitRate: (this.hits / (this.hits + this.misses)) * 100,
|
|
156
|
+
evictions: this.evictions,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
168
161
|
/**
|
|
169
162
|
* Optimized CollectiveMemory class with advanced memory management
|
|
170
|
-
*/
|
|
171
|
-
|
|
163
|
+
*/
|
|
164
|
+
export class CollectiveMemory extends EventEmitter {
|
|
165
|
+
constructor(config = {}) {
|
|
166
|
+
super();
|
|
167
|
+
|
|
168
|
+
/** @type {import('better-sqlite3').Database | null} */
|
|
169
|
+
this.db = null;
|
|
170
|
+
|
|
171
|
+
this.config = {
|
|
172
|
+
swarmId: config.swarmId,
|
|
173
|
+
maxSize: config.maxSize || 100, // MB
|
|
174
|
+
dbPath: config.dbPath || path.join(process.cwd(), '.hive-mind', 'hive.db'),
|
|
175
|
+
compressionThreshold: config.compressionThreshold || 1024, // bytes
|
|
176
|
+
gcInterval: config.gcInterval || 300000, // 5 minutes
|
|
177
|
+
cacheSize: config.cacheSize || 1000,
|
|
178
|
+
cacheMemoryMB: config.cacheMemoryMB || 50,
|
|
179
|
+
enablePooling: config.enablePooling !== false,
|
|
180
|
+
enableAsyncOperations: config.enableAsyncOperations !== false,
|
|
181
|
+
...config,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
this.state = {
|
|
185
|
+
totalSize: 0,
|
|
186
|
+
entryCount: 0,
|
|
187
|
+
compressionRatio: 1,
|
|
188
|
+
lastGC: Date.now(),
|
|
189
|
+
accessPatterns: new Map(),
|
|
190
|
+
performanceMetrics: {
|
|
191
|
+
queryTimes: [],
|
|
192
|
+
avgQueryTime: 0,
|
|
193
|
+
cacheHitRate: 0,
|
|
194
|
+
memoryEfficiency: 0,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
this.gcTimer = null;
|
|
199
|
+
|
|
200
|
+
// Optimized cache with LRU eviction
|
|
201
|
+
this.cache = new OptimizedLRUCache(this.config.cacheSize, this.config.cacheMemoryMB);
|
|
202
|
+
|
|
203
|
+
// Memory pools for frequently created objects
|
|
204
|
+
this.pools = {
|
|
205
|
+
queryResults: new MemoryPool(
|
|
206
|
+
() => ({ results: [], metadata: {} }),
|
|
207
|
+
(obj) => {
|
|
208
|
+
obj.results.length = 0;
|
|
209
|
+
Object.keys(obj.metadata).forEach((k) => delete obj.metadata[k]);
|
|
210
|
+
},
|
|
211
|
+
),
|
|
212
|
+
memoryEntries: new MemoryPool(
|
|
213
|
+
() => ({ id: '', key: '', value: '', metadata: {} }),
|
|
214
|
+
(obj) => {
|
|
215
|
+
obj.id = obj.key = obj.value = '';
|
|
216
|
+
Object.keys(obj.metadata).forEach((k) => delete obj.metadata[k]);
|
|
217
|
+
},
|
|
218
|
+
),
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// Prepared statements for better performance
|
|
222
|
+
this.statements = new Map();
|
|
223
|
+
|
|
224
|
+
// Background worker for heavy operations
|
|
225
|
+
this.backgroundWorker = null;
|
|
226
|
+
|
|
227
|
+
this._initialize();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
172
231
|
* Initialize collective memory with optimizations
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
232
|
+
*/
|
|
233
|
+
_initialize() {
|
|
234
|
+
try {
|
|
235
|
+
// Open database connection with optimizations
|
|
236
|
+
this.db = new Database(this.config.dbPath);
|
|
237
|
+
|
|
238
|
+
// Performance optimizations
|
|
239
|
+
this.db.pragma('journal_mode = WAL');
|
|
240
|
+
this.db.pragma('synchronous = NORMAL');
|
|
241
|
+
this.db.pragma('cache_size = -64000'); // 64MB cache
|
|
242
|
+
this.db.pragma('temp_store = MEMORY');
|
|
243
|
+
this.db.pragma('mmap_size = 268435456'); // 256MB memory mapping
|
|
244
|
+
this.db.pragma('optimize');
|
|
245
|
+
|
|
246
|
+
// Ensure table exists with optimized schema
|
|
247
|
+
this.db.exec(`
|
|
186
248
|
CREATE TABLE IF NOT EXISTS collective_memory (
|
|
187
249
|
id TEXT PRIMARY KEY,
|
|
188
250
|
swarm_id TEXT NOT NULL,
|
|
@@ -221,61 +283,90 @@ import { performance } from "perf_hooks";
|
|
|
221
283
|
FROM collective_memory
|
|
222
284
|
GROUP BY swarm_id, type;
|
|
223
285
|
`);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
286
|
+
|
|
287
|
+
// Prepare optimized statements
|
|
288
|
+
this._prepareStatements();
|
|
289
|
+
|
|
290
|
+
// Load initial statistics
|
|
291
|
+
this._updateStatistics();
|
|
292
|
+
|
|
293
|
+
// Start background optimization processes
|
|
294
|
+
this._startOptimizationTimers();
|
|
295
|
+
|
|
296
|
+
// Initialize background worker for heavy operations
|
|
297
|
+
if (this.config.enableAsyncOperations) {
|
|
298
|
+
this._initializeBackgroundWorker();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
this.emit('memory:initialized', {
|
|
302
|
+
swarmId: this.config.swarmId,
|
|
303
|
+
optimizations: {
|
|
304
|
+
pooling: this.config.enablePooling,
|
|
305
|
+
asyncOps: this.config.enableAsyncOperations,
|
|
306
|
+
cacheSize: this.config.cacheSize,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
} catch (error) {
|
|
310
|
+
this.emit('error', error);
|
|
311
|
+
throw error;
|
|
246
312
|
}
|
|
247
|
-
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
248
316
|
* Prepare optimized SQL statements
|
|
249
|
-
*/
|
|
250
|
-
|
|
317
|
+
*/
|
|
318
|
+
_prepareStatements() {
|
|
319
|
+
this.statements.set(
|
|
320
|
+
'insert',
|
|
321
|
+
this.db.prepare(`
|
|
251
322
|
INSERT OR REPLACE INTO collective_memory
|
|
252
323
|
(id, swarm_id, key, value, type, confidence, created_by, compressed, size)
|
|
253
324
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
254
|
-
`)
|
|
255
|
-
|
|
325
|
+
`),
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
this.statements.set(
|
|
329
|
+
'update',
|
|
330
|
+
this.db.prepare(`
|
|
256
331
|
UPDATE collective_memory
|
|
257
332
|
SET value = ?, accessed_at = strftime('%s','now'), access_count = access_count + 1,
|
|
258
333
|
compressed = ?, size = ?
|
|
259
334
|
WHERE swarm_id = ? AND key = ?
|
|
260
|
-
`)
|
|
261
|
-
|
|
335
|
+
`),
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
this.statements.set(
|
|
339
|
+
'select',
|
|
340
|
+
this.db.prepare(`
|
|
262
341
|
SELECT value, type, compressed, confidence, access_count
|
|
263
342
|
FROM collective_memory
|
|
264
343
|
WHERE swarm_id = ? AND key = ?
|
|
265
|
-
`)
|
|
266
|
-
|
|
344
|
+
`),
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
this.statements.set(
|
|
348
|
+
'updateAccess',
|
|
349
|
+
this.db.prepare(`
|
|
267
350
|
UPDATE collective_memory
|
|
268
351
|
SET accessed_at = strftime('%s','now'), access_count = access_count + 1
|
|
269
352
|
WHERE swarm_id = ? AND key = ?
|
|
270
|
-
`)
|
|
271
|
-
|
|
353
|
+
`),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
this.statements.set(
|
|
357
|
+
'searchByPattern',
|
|
358
|
+
this.db.prepare(`
|
|
272
359
|
SELECT key, type, confidence, created_at, accessed_at, access_count
|
|
273
360
|
FROM collective_memory
|
|
274
361
|
WHERE swarm_id = ? AND key LIKE ? AND confidence >= ?
|
|
275
362
|
ORDER BY access_count DESC, confidence DESC
|
|
276
363
|
LIMIT ?
|
|
277
|
-
`)
|
|
278
|
-
|
|
364
|
+
`),
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
this.statements.set(
|
|
368
|
+
'getStats',
|
|
369
|
+
this.db.prepare(`
|
|
279
370
|
SELECT
|
|
280
371
|
COUNT(*) as count,
|
|
281
372
|
SUM(size) as totalSize,
|
|
@@ -284,191 +375,270 @@ import { performance } from "perf_hooks";
|
|
|
284
375
|
AVG(access_count) as avgAccess
|
|
285
376
|
FROM collective_memory
|
|
286
377
|
WHERE swarm_id = ?
|
|
287
|
-
`)
|
|
288
|
-
|
|
378
|
+
`),
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
this.statements.set(
|
|
382
|
+
'deleteExpired',
|
|
383
|
+
this.db.prepare(`
|
|
289
384
|
DELETE FROM collective_memory
|
|
290
385
|
WHERE swarm_id = ? AND type = ? AND (strftime('%s','now') - accessed_at) > ?
|
|
291
|
-
`)
|
|
292
|
-
|
|
386
|
+
`),
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
this.statements.set(
|
|
390
|
+
'getLRU',
|
|
391
|
+
this.db.prepare(`
|
|
293
392
|
SELECT id, size FROM collective_memory
|
|
294
393
|
WHERE swarm_id = ? AND type NOT IN ('system', 'consensus')
|
|
295
394
|
ORDER BY accessed_at ASC, access_count ASC
|
|
296
395
|
LIMIT ?
|
|
297
|
-
`)
|
|
298
|
-
|
|
299
|
-
|
|
396
|
+
`),
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
300
401
|
* Start optimization timers
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
402
|
+
*/
|
|
403
|
+
_startOptimizationTimers() {
|
|
404
|
+
// Main garbage collection
|
|
405
|
+
this.gcTimer = setInterval(() => this._garbageCollect(), this.config.gcInterval);
|
|
406
|
+
|
|
407
|
+
// Database optimization
|
|
408
|
+
this.optimizeTimer = setInterval(() => this._optimizeDatabase(), 1800000); // 30 minutes
|
|
409
|
+
|
|
410
|
+
// Cache cleanup
|
|
411
|
+
this.cacheTimer = setInterval(() => this._optimizeCache(), 60000); // 1 minute
|
|
412
|
+
|
|
413
|
+
// Performance monitoring
|
|
414
|
+
this.metricsTimer = setInterval(() => this._updatePerformanceMetrics(), 30000); // 30 seconds
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
312
418
|
* Initialize background worker for heavy operations
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
419
|
+
*/
|
|
420
|
+
_initializeBackgroundWorker() {
|
|
421
|
+
// Note: In production, this would initialize a proper Worker
|
|
422
|
+
// For now, we'll use async operations
|
|
423
|
+
this.backgroundQueue = [];
|
|
424
|
+
this.backgroundProcessing = false;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
320
428
|
* Store data in collective memory
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
429
|
+
*/
|
|
430
|
+
async store(key, value, type = 'knowledge', metadata = {}) {
|
|
431
|
+
try {
|
|
432
|
+
const serialized = JSON.stringify(value);
|
|
433
|
+
const size = Buffer.byteLength(serialized);
|
|
434
|
+
const shouldCompress =
|
|
435
|
+
size > this.config.compressionThreshold && MEMORY_TYPES[type]?.compress;
|
|
436
|
+
|
|
437
|
+
let storedValue = serialized;
|
|
438
|
+
let compressed = 0;
|
|
439
|
+
|
|
440
|
+
if (shouldCompress) {
|
|
441
|
+
// In production, use proper compression like zlib
|
|
442
|
+
// For now, we'll just mark it as compressed
|
|
443
|
+
compressed = 1;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const id = `${this.config.swarmId}-${key}-${Date.now()}`;
|
|
447
|
+
|
|
448
|
+
// Check if key already exists
|
|
449
|
+
const existing = this.db
|
|
450
|
+
.prepare(
|
|
451
|
+
`
|
|
336
452
|
SELECT id FROM collective_memory
|
|
337
453
|
WHERE swarm_id = ? AND key = ?
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
454
|
+
`,
|
|
455
|
+
)
|
|
456
|
+
.get(this.config.swarmId, key);
|
|
457
|
+
|
|
458
|
+
if (existing) {
|
|
459
|
+
// Update existing entry
|
|
460
|
+
this.db
|
|
461
|
+
.prepare(
|
|
462
|
+
`
|
|
342
463
|
UPDATE collective_memory
|
|
343
464
|
SET value = ?, type = ?, confidence = ?,
|
|
344
465
|
accessed_at = CURRENT_TIMESTAMP, access_count = access_count + 1,
|
|
345
466
|
compressed = ?, size = ?
|
|
346
467
|
WHERE swarm_id = ? AND key = ?
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
468
|
+
`,
|
|
469
|
+
)
|
|
470
|
+
.run(
|
|
471
|
+
storedValue,
|
|
472
|
+
type,
|
|
473
|
+
metadata.confidence || 1.0,
|
|
474
|
+
compressed,
|
|
475
|
+
size,
|
|
476
|
+
this.config.swarmId,
|
|
477
|
+
key,
|
|
478
|
+
);
|
|
479
|
+
} else {
|
|
480
|
+
// Insert new entry
|
|
481
|
+
this.db
|
|
482
|
+
.prepare(
|
|
483
|
+
`
|
|
351
484
|
INSERT INTO collective_memory
|
|
352
485
|
(id, swarm_id, key, value, type, confidence, created_by, compressed, size)
|
|
353
486
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
487
|
+
`,
|
|
488
|
+
)
|
|
489
|
+
.run(
|
|
490
|
+
id,
|
|
491
|
+
this.config.swarmId,
|
|
492
|
+
key,
|
|
493
|
+
storedValue,
|
|
494
|
+
type,
|
|
495
|
+
metadata.confidence || 1.0,
|
|
496
|
+
metadata.createdBy || 'system',
|
|
497
|
+
compressed,
|
|
498
|
+
size,
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Update cache
|
|
503
|
+
this.cache.set(key, {
|
|
504
|
+
value,
|
|
505
|
+
type,
|
|
506
|
+
timestamp: Date.now(),
|
|
507
|
+
size,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
// Check memory limits
|
|
511
|
+
this._checkMemoryLimits();
|
|
512
|
+
|
|
513
|
+
// Track access pattern
|
|
514
|
+
this._trackAccess(key, 'write');
|
|
515
|
+
|
|
516
|
+
this.emit('memory:stored', { key, type, size });
|
|
517
|
+
|
|
518
|
+
return { success: true, id, size };
|
|
519
|
+
} catch (error) {
|
|
520
|
+
this.emit('error', error);
|
|
521
|
+
throw error;
|
|
381
522
|
}
|
|
382
|
-
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
383
526
|
* Retrieve data from collective memory
|
|
384
|
-
*/
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
527
|
+
*/
|
|
528
|
+
async retrieve(key) {
|
|
529
|
+
try {
|
|
530
|
+
// Check cache first
|
|
531
|
+
if (this.cache.has(key)) {
|
|
532
|
+
const cached = this.cache.get(key);
|
|
533
|
+
this._trackAccess(key, 'cache_hit');
|
|
534
|
+
return cached.value;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Query database
|
|
538
|
+
const result = this.db
|
|
539
|
+
.prepare(
|
|
540
|
+
`
|
|
394
541
|
SELECT value, type, compressed, confidence
|
|
395
542
|
FROM collective_memory
|
|
396
543
|
WHERE swarm_id = ? AND key = ?
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
544
|
+
`,
|
|
545
|
+
)
|
|
546
|
+
.get(this.config.swarmId, key);
|
|
547
|
+
|
|
548
|
+
if (!result) {
|
|
549
|
+
this._trackAccess(key, 'miss');
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Update access statistics
|
|
554
|
+
this.db
|
|
555
|
+
.prepare(
|
|
556
|
+
`
|
|
404
557
|
UPDATE collective_memory
|
|
405
558
|
SET accessed_at = CURRENT_TIMESTAMP,
|
|
406
559
|
access_count = access_count + 1
|
|
407
560
|
WHERE swarm_id = ? AND key = ?
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
561
|
+
`,
|
|
562
|
+
)
|
|
563
|
+
.run(this.config.swarmId, key);
|
|
564
|
+
|
|
565
|
+
// Decompress if needed
|
|
566
|
+
let value = result.value;
|
|
567
|
+
if (result.compressed) {
|
|
568
|
+
// In production, decompress here
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Parse JSON
|
|
572
|
+
const parsed = JSON.parse(value);
|
|
573
|
+
|
|
574
|
+
// Add to cache
|
|
575
|
+
this.cache.set(key, {
|
|
576
|
+
value: parsed,
|
|
577
|
+
type: result.type,
|
|
578
|
+
timestamp: Date.now(),
|
|
579
|
+
confidence: result.confidence,
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
this._trackAccess(key, 'read');
|
|
583
|
+
|
|
584
|
+
return parsed;
|
|
585
|
+
} catch (error) {
|
|
586
|
+
this.emit('error', error);
|
|
587
|
+
throw error;
|
|
429
588
|
}
|
|
430
|
-
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
431
592
|
* Search collective memory
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
593
|
+
*/
|
|
594
|
+
async search(pattern, options = {}) {
|
|
595
|
+
try {
|
|
596
|
+
const limit = options.limit || 50;
|
|
597
|
+
const type = options.type || null;
|
|
598
|
+
const minConfidence = options.minConfidence || 0;
|
|
599
|
+
|
|
600
|
+
let query = `
|
|
438
601
|
SELECT key, type, confidence, created_at, accessed_at, access_count
|
|
439
602
|
FROM collective_memory
|
|
440
603
|
WHERE swarm_id = ?
|
|
441
604
|
AND key LIKE ?
|
|
442
605
|
AND confidence >= ?
|
|
443
606
|
`;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
607
|
+
|
|
608
|
+
const params = [this.config.swarmId, `%${pattern}%`, minConfidence];
|
|
609
|
+
|
|
610
|
+
if (type) {
|
|
611
|
+
query += ' AND type = ?';
|
|
612
|
+
params.push(type);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
query += ' ORDER BY access_count DESC, confidence DESC LIMIT ?';
|
|
616
|
+
params.push(limit);
|
|
617
|
+
|
|
618
|
+
const results = this.db.prepare(query).all(...params);
|
|
619
|
+
|
|
620
|
+
this._trackAccess(`search:${pattern}`, 'search');
|
|
621
|
+
|
|
622
|
+
return results;
|
|
623
|
+
} catch (error) {
|
|
624
|
+
this.emit('error', error);
|
|
625
|
+
throw error;
|
|
462
626
|
}
|
|
463
|
-
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
464
630
|
* Get related memories using association
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
631
|
+
*/
|
|
632
|
+
async getRelated(key, limit = 10) {
|
|
633
|
+
try {
|
|
634
|
+
// Get the original memory
|
|
635
|
+
const original = await this.retrieve(key);
|
|
636
|
+
if (!original) return [];
|
|
637
|
+
|
|
638
|
+
// Simple association: find memories accessed around the same time
|
|
639
|
+
const result = this.db
|
|
640
|
+
.prepare(
|
|
641
|
+
`
|
|
472
642
|
SELECT m1.key, m1.type, m1.confidence, m1.access_count
|
|
473
643
|
FROM collective_memory m1
|
|
474
644
|
JOIN collective_memory m2 ON m1.swarm_id = m2.swarm_id
|
|
@@ -478,250 +648,315 @@ import { performance } from "perf_hooks";
|
|
|
478
648
|
AND ABS(julianday(m1.accessed_at) - julianday(m2.accessed_at)) < 0.01
|
|
479
649
|
ORDER BY m1.confidence DESC, m1.access_count DESC
|
|
480
650
|
LIMIT ?
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
651
|
+
`,
|
|
652
|
+
)
|
|
653
|
+
.all(key, key, this.config.swarmId, limit);
|
|
654
|
+
|
|
655
|
+
return result;
|
|
656
|
+
} catch (error) {
|
|
657
|
+
this.emit('error', error);
|
|
658
|
+
throw error;
|
|
487
659
|
}
|
|
488
|
-
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
489
663
|
* Build associations between memories
|
|
490
|
-
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
664
|
+
*/
|
|
665
|
+
async associate(key1, key2, strength = 1.0) {
|
|
666
|
+
try {
|
|
667
|
+
// Store bidirectional association
|
|
668
|
+
await this.store(
|
|
669
|
+
`assoc:${key1}:${key2}`,
|
|
670
|
+
{
|
|
671
|
+
from: key1,
|
|
672
|
+
to: key2,
|
|
673
|
+
strength,
|
|
674
|
+
created: Date.now(),
|
|
675
|
+
},
|
|
676
|
+
'system',
|
|
677
|
+
);
|
|
678
|
+
|
|
679
|
+
await this.store(
|
|
680
|
+
`assoc:${key2}:${key1}`,
|
|
681
|
+
{
|
|
682
|
+
from: key2,
|
|
683
|
+
to: key1,
|
|
684
|
+
strength,
|
|
685
|
+
created: Date.now(),
|
|
686
|
+
},
|
|
687
|
+
'system',
|
|
688
|
+
);
|
|
689
|
+
|
|
690
|
+
this.emit('memory:associated', { key1, key2, strength });
|
|
691
|
+
} catch (error) {
|
|
692
|
+
this.emit('error', error);
|
|
693
|
+
throw error;
|
|
514
694
|
}
|
|
515
|
-
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
516
698
|
* Consolidate similar memories
|
|
517
|
-
*/
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
699
|
+
*/
|
|
700
|
+
async consolidate() {
|
|
701
|
+
try {
|
|
702
|
+
// Find similar memories
|
|
703
|
+
const memories = this.db
|
|
704
|
+
.prepare(
|
|
705
|
+
`
|
|
521
706
|
SELECT key, value, type, confidence, access_count
|
|
522
707
|
FROM collective_memory
|
|
523
708
|
WHERE swarm_id = ?
|
|
524
709
|
AND type IN ('knowledge', 'result')
|
|
525
710
|
ORDER BY created_at DESC
|
|
526
711
|
LIMIT 1000
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
});
|
|
541
|
-
// Merge similar memories
|
|
542
|
-
let mergeCount = 0;
|
|
543
|
-
consolidated.forEach((group, category)=>{
|
|
544
|
-
if (group.length > 1) {
|
|
545
|
-
const merged = this._mergeMemories(group);
|
|
546
|
-
// Store merged memory
|
|
547
|
-
this.store(`consolidated:${category}`, merged, 'knowledge', {
|
|
548
|
-
confidence: merged.confidence,
|
|
549
|
-
createdBy: 'consolidation'
|
|
550
|
-
});
|
|
551
|
-
mergeCount++;
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
this.emit('memory:consolidated', {
|
|
555
|
-
categories: consolidated.size,
|
|
556
|
-
merged: mergeCount
|
|
557
|
-
});
|
|
558
|
-
return {
|
|
559
|
-
categories: consolidated.size,
|
|
560
|
-
merged: mergeCount
|
|
561
|
-
};
|
|
562
|
-
} catch (error) {
|
|
563
|
-
this.emit('error', error);
|
|
564
|
-
throw error;
|
|
712
|
+
`,
|
|
713
|
+
)
|
|
714
|
+
.all(this.config.swarmId);
|
|
715
|
+
|
|
716
|
+
const consolidated = new Map();
|
|
717
|
+
|
|
718
|
+
// Group by similarity (simple implementation)
|
|
719
|
+
memories.forEach((memory) => {
|
|
720
|
+
const value = JSON.parse(memory.value);
|
|
721
|
+
const category = this._categorizeMemory(value);
|
|
722
|
+
|
|
723
|
+
if (!consolidated.has(category)) {
|
|
724
|
+
consolidated.set(category, []);
|
|
565
725
|
}
|
|
726
|
+
|
|
727
|
+
consolidated.get(category).push({
|
|
728
|
+
...memory,
|
|
729
|
+
value,
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
// Merge similar memories
|
|
734
|
+
let mergeCount = 0;
|
|
735
|
+
consolidated.forEach((group, category) => {
|
|
736
|
+
if (group.length > 1) {
|
|
737
|
+
const merged = this._mergeMemories(group);
|
|
738
|
+
|
|
739
|
+
// Store merged memory
|
|
740
|
+
this.store(`consolidated:${category}`, merged, 'knowledge', {
|
|
741
|
+
confidence: merged.confidence,
|
|
742
|
+
createdBy: 'consolidation',
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
mergeCount++;
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
this.emit('memory:consolidated', { categories: consolidated.size, merged: mergeCount });
|
|
750
|
+
|
|
751
|
+
return { categories: consolidated.size, merged: mergeCount };
|
|
752
|
+
} catch (error) {
|
|
753
|
+
this.emit('error', error);
|
|
754
|
+
throw error;
|
|
566
755
|
}
|
|
567
|
-
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
568
759
|
* Categorize memory for consolidation
|
|
569
|
-
*/
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (typeof value === 'object') {
|
|
575
|
-
const keys = Object.keys(value).sort().join(':');
|
|
576
|
-
return `object:${keys.substring(0, 50)}`;
|
|
577
|
-
}
|
|
578
|
-
return 'other';
|
|
760
|
+
*/
|
|
761
|
+
_categorizeMemory(value) {
|
|
762
|
+
// Simple categorization based on content
|
|
763
|
+
if (typeof value === 'string') {
|
|
764
|
+
return 'text';
|
|
579
765
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
let totalWeight = 0;
|
|
585
|
-
let weightedConfidence = 0;
|
|
586
|
-
const mergedValue = {};
|
|
587
|
-
memories.forEach((memory)=>{
|
|
588
|
-
const weight = memory.access_count + 1;
|
|
589
|
-
totalWeight += weight;
|
|
590
|
-
weightedConfidence += memory.confidence * weight;
|
|
591
|
-
// Merge values (simple implementation)
|
|
592
|
-
if (typeof memory.value === 'object') {
|
|
593
|
-
Object.assign(mergedValue, memory.value);
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
return {
|
|
597
|
-
value: mergedValue,
|
|
598
|
-
confidence: weightedConfidence / totalWeight,
|
|
599
|
-
sourceCount: memories.length
|
|
600
|
-
};
|
|
766
|
+
|
|
767
|
+
if (typeof value === 'object') {
|
|
768
|
+
const keys = Object.keys(value).sort().join(':');
|
|
769
|
+
return `object:${keys.substring(0, 50)}`;
|
|
601
770
|
}
|
|
602
|
-
|
|
771
|
+
|
|
772
|
+
return 'other';
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Merge similar memories
|
|
777
|
+
*/
|
|
778
|
+
_mergeMemories(memories) {
|
|
779
|
+
// Calculate weighted average confidence
|
|
780
|
+
let totalWeight = 0;
|
|
781
|
+
let weightedConfidence = 0;
|
|
782
|
+
const mergedValue = {};
|
|
783
|
+
|
|
784
|
+
memories.forEach((memory) => {
|
|
785
|
+
const weight = memory.access_count + 1;
|
|
786
|
+
totalWeight += weight;
|
|
787
|
+
weightedConfidence += memory.confidence * weight;
|
|
788
|
+
|
|
789
|
+
// Merge values (simple implementation)
|
|
790
|
+
if (typeof memory.value === 'object') {
|
|
791
|
+
Object.assign(mergedValue, memory.value);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
return {
|
|
796
|
+
value: mergedValue,
|
|
797
|
+
confidence: weightedConfidence / totalWeight,
|
|
798
|
+
sourceCount: memories.length,
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
603
803
|
* Garbage collection
|
|
604
|
-
*/
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
804
|
+
*/
|
|
805
|
+
_garbageCollect() {
|
|
806
|
+
try {
|
|
807
|
+
const now = Date.now();
|
|
808
|
+
let deletedCount = 0;
|
|
809
|
+
|
|
810
|
+
// Delete expired memories based on TTL
|
|
811
|
+
Object.entries(MEMORY_TYPES).forEach(([type, config]) => {
|
|
812
|
+
if (config.ttl) {
|
|
813
|
+
const result = this.db
|
|
814
|
+
.prepare(
|
|
815
|
+
`
|
|
612
816
|
DELETE FROM collective_memory
|
|
613
817
|
WHERE swarm_id = ?
|
|
614
818
|
AND type = ?
|
|
615
819
|
AND (julianday('now') - julianday(accessed_at)) * 86400000 > ?
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const cacheTimeout = 300000; // 5 minutes
|
|
622
|
-
this.cache.forEach((value, key)=>{
|
|
623
|
-
if (now - value.timestamp > cacheTimeout) {
|
|
624
|
-
this.cache.delete(key);
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
// Update statistics
|
|
628
|
-
this._updateStatistics();
|
|
629
|
-
this.state.lastGC = now;
|
|
630
|
-
if (deletedCount > 0) {
|
|
631
|
-
this.emit('memory:gc', {
|
|
632
|
-
deleted: deletedCount,
|
|
633
|
-
cacheSize: this.cache.size
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
} catch (error) {
|
|
637
|
-
this.emit('error', error);
|
|
820
|
+
`,
|
|
821
|
+
)
|
|
822
|
+
.run(this.config.swarmId, type, config.ttl);
|
|
823
|
+
|
|
824
|
+
deletedCount += result.changes;
|
|
638
825
|
}
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
// Clear old cache entries
|
|
829
|
+
const cacheTimeout = 300000; // 5 minutes
|
|
830
|
+
this.cache.forEach((value, key) => {
|
|
831
|
+
if (now - value.timestamp > cacheTimeout) {
|
|
832
|
+
this.cache.delete(key);
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// Update statistics
|
|
837
|
+
this._updateStatistics();
|
|
838
|
+
|
|
839
|
+
this.state.lastGC = now;
|
|
840
|
+
|
|
841
|
+
if (deletedCount > 0) {
|
|
842
|
+
this.emit('memory:gc', { deleted: deletedCount, cacheSize: this.cache.size });
|
|
843
|
+
}
|
|
844
|
+
} catch (error) {
|
|
845
|
+
this.emit('error', error);
|
|
639
846
|
}
|
|
640
|
-
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
641
850
|
* Check memory limits and evict if necessary
|
|
642
|
-
*/
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
851
|
+
*/
|
|
852
|
+
_checkMemoryLimits() {
|
|
853
|
+
if (this.state.totalSize > this.config.maxSize * 1024 * 1024) {
|
|
854
|
+
// Evict least recently used memories
|
|
855
|
+
const toEvict = this.db
|
|
856
|
+
.prepare(
|
|
857
|
+
`
|
|
646
858
|
SELECT id, size FROM collective_memory
|
|
647
859
|
WHERE swarm_id = ?
|
|
648
860
|
AND type NOT IN ('system', 'consensus')
|
|
649
861
|
ORDER BY accessed_at ASC, access_count ASC
|
|
650
862
|
LIMIT 100
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
863
|
+
`,
|
|
864
|
+
)
|
|
865
|
+
.all(this.config.swarmId);
|
|
866
|
+
|
|
867
|
+
let freedSize = 0;
|
|
868
|
+
toEvict.forEach((memory) => {
|
|
869
|
+
this.db.prepare('DELETE FROM collective_memory WHERE id = ?').run(memory.id);
|
|
870
|
+
freedSize += memory.size;
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
this.emit('memory:evicted', { count: toEvict.length, freedSize });
|
|
662
874
|
}
|
|
663
|
-
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
664
878
|
* Optimize database performance
|
|
665
|
-
*/
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
879
|
+
*/
|
|
880
|
+
_optimizeDatabase() {
|
|
881
|
+
try {
|
|
882
|
+
// Run database optimization
|
|
883
|
+
this.db.pragma('optimize');
|
|
884
|
+
this.db.pragma('analysis_limit=1000');
|
|
885
|
+
this.db.exec('ANALYZE');
|
|
886
|
+
|
|
887
|
+
// Update database statistics
|
|
888
|
+
this._updateStatistics();
|
|
889
|
+
|
|
890
|
+
this.emit('database:optimized');
|
|
891
|
+
} catch (error) {
|
|
892
|
+
this.emit('error', error);
|
|
677
893
|
}
|
|
678
|
-
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
679
897
|
* Optimize cache performance
|
|
680
|
-
*/
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
898
|
+
*/
|
|
899
|
+
_optimizeCache() {
|
|
900
|
+
try {
|
|
901
|
+
const now = Date.now();
|
|
902
|
+
const cacheTimeout = 300000; // 5 minutes
|
|
903
|
+
|
|
904
|
+
// Clear expired cache entries
|
|
905
|
+
if (this.cache.cache) {
|
|
906
|
+
this.cache.cache.forEach((value, key) => {
|
|
907
|
+
if (now - value.timestamp > cacheTimeout) {
|
|
908
|
+
this.cache.cache.delete(key);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
this.emit('cache:optimized', {
|
|
914
|
+
size: this.cache.cache ? this.cache.cache.size : 0,
|
|
915
|
+
});
|
|
916
|
+
} catch (error) {
|
|
917
|
+
this.emit('error', error);
|
|
698
918
|
}
|
|
699
|
-
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
700
922
|
* Update performance metrics
|
|
701
|
-
*/
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
923
|
+
*/
|
|
924
|
+
_updatePerformanceMetrics() {
|
|
925
|
+
try {
|
|
926
|
+
// Calculate cache hit rate
|
|
927
|
+
const cacheStats = this.cache.getStats();
|
|
928
|
+
this.state.performanceMetrics.cacheHitRate = cacheStats.hitRate || 0;
|
|
929
|
+
|
|
930
|
+
// Calculate memory efficiency
|
|
931
|
+
this.state.performanceMetrics.memoryEfficiency =
|
|
932
|
+
(this.state.totalSize / (this.config.maxSize * 1024 * 1024)) * 100;
|
|
933
|
+
|
|
934
|
+
// Update average query time if we have recent measurements
|
|
935
|
+
if (this.state.performanceMetrics.queryTimes.length > 0) {
|
|
936
|
+
this.state.performanceMetrics.avgQueryTime =
|
|
937
|
+
this.state.performanceMetrics.queryTimes.reduce((sum, time) => sum + time, 0) /
|
|
938
|
+
this.state.performanceMetrics.queryTimes.length;
|
|
939
|
+
|
|
940
|
+
// Keep only recent query times (last 100)
|
|
941
|
+
if (this.state.performanceMetrics.queryTimes.length > 100) {
|
|
942
|
+
this.state.performanceMetrics.queryTimes =
|
|
943
|
+
this.state.performanceMetrics.queryTimes.slice(-100);
|
|
719
944
|
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
this.emit('metrics:updated', this.state.performanceMetrics);
|
|
948
|
+
} catch (error) {
|
|
949
|
+
this.emit('error', error);
|
|
720
950
|
}
|
|
721
|
-
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/**
|
|
722
954
|
* Update memory statistics
|
|
723
|
-
*/
|
|
724
|
-
|
|
955
|
+
*/
|
|
956
|
+
_updateStatistics() {
|
|
957
|
+
const stats = this.db
|
|
958
|
+
.prepare(
|
|
959
|
+
`
|
|
725
960
|
SELECT
|
|
726
961
|
COUNT(*) as count,
|
|
727
962
|
SUM(size) as totalSize,
|
|
@@ -729,328 +964,329 @@ import { performance } from "perf_hooks";
|
|
|
729
964
|
SUM(compressed) as compressedCount
|
|
730
965
|
FROM collective_memory
|
|
731
966
|
WHERE swarm_id = ?
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
967
|
+
`,
|
|
968
|
+
)
|
|
969
|
+
.get(this.config.swarmId);
|
|
970
|
+
|
|
971
|
+
this.state.entryCount = stats.count || 0;
|
|
972
|
+
this.state.totalSize = stats.totalSize || 0;
|
|
973
|
+
this.state.avgConfidence = stats.avgConfidence || 1.0;
|
|
974
|
+
|
|
975
|
+
if (stats.compressedCount > 0) {
|
|
976
|
+
// Estimate compression ratio
|
|
977
|
+
this.state.compressionRatio = 0.6; // Assume 40% compression
|
|
740
978
|
}
|
|
741
|
-
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
742
982
|
* Track access patterns
|
|
743
|
-
*/
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
this.state.accessPatterns.set(key, pattern);
|
|
771
|
-
// Keep access patterns size limited
|
|
772
|
-
if (this.state.accessPatterns.size > 1000) {
|
|
773
|
-
// Remove oldest entries
|
|
774
|
-
const sorted = Array.from(this.state.accessPatterns.entries()).sort((a, b)=>a[1].lastAccess - b[1].lastAccess);
|
|
775
|
-
sorted.slice(0, 100).forEach(([key])=>{
|
|
776
|
-
this.state.accessPatterns.delete(key);
|
|
777
|
-
});
|
|
778
|
-
}
|
|
983
|
+
*/
|
|
984
|
+
_trackAccess(key, operation) {
|
|
985
|
+
const pattern = this.state.accessPatterns.get(key) || {
|
|
986
|
+
reads: 0,
|
|
987
|
+
writes: 0,
|
|
988
|
+
searches: 0,
|
|
989
|
+
cacheHits: 0,
|
|
990
|
+
misses: 0,
|
|
991
|
+
lastAccess: Date.now(),
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
switch (operation) {
|
|
995
|
+
case 'read':
|
|
996
|
+
pattern.reads++;
|
|
997
|
+
break;
|
|
998
|
+
case 'write':
|
|
999
|
+
pattern.writes++;
|
|
1000
|
+
break;
|
|
1001
|
+
case 'search':
|
|
1002
|
+
pattern.searches++;
|
|
1003
|
+
break;
|
|
1004
|
+
case 'cache_hit':
|
|
1005
|
+
pattern.cacheHits++;
|
|
1006
|
+
break;
|
|
1007
|
+
case 'miss':
|
|
1008
|
+
pattern.misses++;
|
|
1009
|
+
break;
|
|
779
1010
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
optimization: {
|
|
795
|
-
cacheOptimized: true,
|
|
796
|
-
poolingEnabled: this.config.enablePooling,
|
|
797
|
-
asyncOperations: this.config.enableAsyncOperations,
|
|
798
|
-
compressionRatio: this.state.compressionRatio,
|
|
799
|
-
performanceMetrics: this.state.performanceMetrics
|
|
800
|
-
}
|
|
801
|
-
};
|
|
1011
|
+
|
|
1012
|
+
pattern.lastAccess = Date.now();
|
|
1013
|
+
this.state.accessPatterns.set(key, pattern);
|
|
1014
|
+
|
|
1015
|
+
// Keep access patterns size limited
|
|
1016
|
+
if (this.state.accessPatterns.size > 1000) {
|
|
1017
|
+
// Remove oldest entries
|
|
1018
|
+
const sorted = Array.from(this.state.accessPatterns.entries()).sort(
|
|
1019
|
+
(a, b) => a[1].lastAccess - b[1].lastAccess,
|
|
1020
|
+
);
|
|
1021
|
+
|
|
1022
|
+
sorted.slice(0, 100).forEach(([key]) => {
|
|
1023
|
+
this.state.accessPatterns.delete(key);
|
|
1024
|
+
});
|
|
802
1025
|
}
|
|
803
|
-
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Get enhanced memory statistics
|
|
1030
|
+
*/
|
|
1031
|
+
getStatistics() {
|
|
1032
|
+
return {
|
|
1033
|
+
swarmId: this.config.swarmId,
|
|
1034
|
+
entryCount: this.state.entryCount,
|
|
1035
|
+
totalSize: this.state.totalSize,
|
|
1036
|
+
maxSize: this.config.maxSize * 1024 * 1024,
|
|
1037
|
+
utilizationPercent: (this.state.totalSize / (this.config.maxSize * 1024 * 1024)) * 100,
|
|
1038
|
+
avgConfidence: this.state.avgConfidence,
|
|
1039
|
+
compressionRatio: this.state.compressionRatio,
|
|
1040
|
+
cacheSize: this.cache.cache ? this.cache.cache.size : 0,
|
|
1041
|
+
lastGC: new Date(this.state.lastGC).toISOString(),
|
|
1042
|
+
accessPatterns: this.state.accessPatterns.size,
|
|
1043
|
+
optimization: {
|
|
1044
|
+
cacheOptimized: true,
|
|
1045
|
+
poolingEnabled: this.config.enablePooling,
|
|
1046
|
+
asyncOperations: this.config.enableAsyncOperations,
|
|
1047
|
+
compressionRatio: this.state.compressionRatio,
|
|
1048
|
+
performanceMetrics: this.state.performanceMetrics,
|
|
1049
|
+
},
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
804
1054
|
* Export memory snapshot
|
|
805
|
-
*/
|
|
806
|
-
|
|
807
|
-
|
|
1055
|
+
*/
|
|
1056
|
+
async exportSnapshot(filepath) {
|
|
1057
|
+
try {
|
|
1058
|
+
const memories = this.db
|
|
1059
|
+
.prepare(
|
|
1060
|
+
`
|
|
808
1061
|
SELECT * FROM collective_memory
|
|
809
1062
|
WHERE swarm_id = ?
|
|
810
1063
|
ORDER BY created_at DESC
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1064
|
+
`,
|
|
1065
|
+
)
|
|
1066
|
+
.all(this.config.swarmId);
|
|
1067
|
+
|
|
1068
|
+
const snapshot = {
|
|
1069
|
+
swarmId: this.config.swarmId,
|
|
1070
|
+
timestamp: new Date().toISOString(),
|
|
1071
|
+
statistics: this.getStatistics(),
|
|
1072
|
+
memories: memories.map((m) => ({
|
|
1073
|
+
...m,
|
|
1074
|
+
value: JSON.parse(m.value),
|
|
1075
|
+
})),
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
// In production, write to file
|
|
1079
|
+
// For now, return the snapshot
|
|
1080
|
+
this.emit('memory:exported', { count: memories.length });
|
|
1081
|
+
|
|
1082
|
+
return snapshot;
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
this.emit('error', error);
|
|
1085
|
+
throw error;
|
|
831
1086
|
}
|
|
832
|
-
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
833
1090
|
* Import memory snapshot
|
|
834
|
-
*/
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}
|
|
1091
|
+
*/
|
|
1092
|
+
async importSnapshot(snapshot) {
|
|
1093
|
+
try {
|
|
1094
|
+
let imported = 0;
|
|
1095
|
+
|
|
1096
|
+
for (const memory of snapshot.memories) {
|
|
1097
|
+
await this.store(memory.key, memory.value, memory.type, {
|
|
1098
|
+
confidence: memory.confidence,
|
|
1099
|
+
createdBy: memory.created_by,
|
|
1100
|
+
});
|
|
1101
|
+
imported++;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
this.emit('memory:imported', { count: imported });
|
|
1105
|
+
|
|
1106
|
+
return { imported };
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
this.emit('error', error);
|
|
1109
|
+
throw error;
|
|
854
1110
|
}
|
|
855
|
-
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
856
1114
|
* Enhanced shutdown with cleanup
|
|
857
|
-
*/
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
if (this.db) {
|
|
871
|
-
this.db.close();
|
|
872
|
-
}
|
|
873
|
-
// Clear memory pools
|
|
874
|
-
if (this.config.enablePooling) {
|
|
875
|
-
Object.values(this.pools).forEach((pool)=>{
|
|
876
|
-
pool.pool.length = 0;
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
const finalStats = {
|
|
880
|
-
cacheStats: this.cache.getStats ? this.cache.getStats() : {},
|
|
881
|
-
poolStats: this.config.enablePooling ? {
|
|
882
|
-
queryResults: this.pools.queryResults.getStats(),
|
|
883
|
-
memoryEntries: this.pools.memoryEntries.getStats()
|
|
884
|
-
} : null,
|
|
885
|
-
performanceMetrics: this.state.performanceMetrics
|
|
886
|
-
};
|
|
887
|
-
this.emit('memory:closed', finalStats);
|
|
1115
|
+
*/
|
|
1116
|
+
close() {
|
|
1117
|
+
// Clear all timers
|
|
1118
|
+
if (this.gcTimer) clearInterval(this.gcTimer);
|
|
1119
|
+
if (this.optimizeTimer) clearInterval(this.optimizeTimer);
|
|
1120
|
+
if (this.cacheTimer) clearInterval(this.cacheTimer);
|
|
1121
|
+
if (this.metricsTimer) clearInterval(this.metricsTimer);
|
|
1122
|
+
|
|
1123
|
+
// Final optimization before closing
|
|
1124
|
+
try {
|
|
1125
|
+
this.db.pragma('optimize');
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
// Ignore errors during shutdown
|
|
888
1128
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
database: {
|
|
901
|
-
fragmentation: this.db.pragma('freelist_count'),
|
|
902
|
-
pageSize: this.db.pragma('page_size'),
|
|
903
|
-
cacheSize: this.db.pragma('cache_size')
|
|
904
|
-
}
|
|
905
|
-
};
|
|
1129
|
+
|
|
1130
|
+
// Close database
|
|
1131
|
+
if (this.db) {
|
|
1132
|
+
this.db.close();
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// Clear memory pools
|
|
1136
|
+
if (this.config.enablePooling) {
|
|
1137
|
+
Object.values(this.pools).forEach((pool) => {
|
|
1138
|
+
pool.pool.length = 0;
|
|
1139
|
+
});
|
|
906
1140
|
}
|
|
907
|
-
|
|
1141
|
+
|
|
1142
|
+
const finalStats = {
|
|
1143
|
+
cacheStats: this.cache.getStats ? this.cache.getStats() : {},
|
|
1144
|
+
poolStats: this.config.enablePooling
|
|
1145
|
+
? {
|
|
1146
|
+
queryResults: this.pools.queryResults.getStats(),
|
|
1147
|
+
memoryEntries: this.pools.memoryEntries.getStats(),
|
|
1148
|
+
}
|
|
1149
|
+
: null,
|
|
1150
|
+
performanceMetrics: this.state.performanceMetrics,
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
this.emit('memory:closed', finalStats);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Get comprehensive memory analytics
|
|
1158
|
+
*/
|
|
1159
|
+
getAnalytics() {
|
|
1160
|
+
return {
|
|
1161
|
+
basic: this.getStatistics(),
|
|
1162
|
+
performance: this.state.performanceMetrics,
|
|
1163
|
+
cache: this.cache.getStats ? this.cache.getStats() : {},
|
|
1164
|
+
pools: this.config.enablePooling
|
|
1165
|
+
? {
|
|
1166
|
+
queryResults: this.pools.queryResults.getStats(),
|
|
1167
|
+
memoryEntries: this.pools.memoryEntries.getStats(),
|
|
1168
|
+
}
|
|
1169
|
+
: null,
|
|
1170
|
+
database: {
|
|
1171
|
+
fragmentation: this.db.pragma('freelist_count'),
|
|
1172
|
+
pageSize: this.db.pragma('page_size'),
|
|
1173
|
+
cacheSize: this.db.pragma('cache_size'),
|
|
1174
|
+
},
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
908
1179
|
* Memory health check
|
|
909
|
-
*/
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
if (analytics.basic.utilizationPercent > 90) {
|
|
923
|
-
health.status = 'warning';
|
|
924
|
-
health.issues.push('High memory utilization');
|
|
925
|
-
health.recommendations.push('Consider increasing max memory or running garbage collection');
|
|
926
|
-
}
|
|
927
|
-
// Check query performance
|
|
928
|
-
if (analytics.performance.avgQueryTime > 100) {
|
|
929
|
-
health.issues.push('Slow query performance');
|
|
930
|
-
health.recommendations.push('Consider database optimization or indexing');
|
|
931
|
-
}
|
|
932
|
-
return health;
|
|
1180
|
+
*/
|
|
1181
|
+
async healthCheck() {
|
|
1182
|
+
const analytics = this.getAnalytics();
|
|
1183
|
+
const health = {
|
|
1184
|
+
status: 'healthy',
|
|
1185
|
+
issues: [],
|
|
1186
|
+
recommendations: [],
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
// Check cache hit rate
|
|
1190
|
+
if (analytics.cache.hitRate < 50) {
|
|
1191
|
+
health.issues.push('Low cache hit rate');
|
|
1192
|
+
health.recommendations.push('Consider increasing cache size');
|
|
933
1193
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
dbPath: config.dbPath || path.join(process.cwd(), '.hive-mind', 'hive.db'),
|
|
941
|
-
compressionThreshold: config.compressionThreshold || 1024,
|
|
942
|
-
gcInterval: config.gcInterval || 300000,
|
|
943
|
-
cacheSize: config.cacheSize || 1000,
|
|
944
|
-
cacheMemoryMB: config.cacheMemoryMB || 50,
|
|
945
|
-
enablePooling: config.enablePooling !== false,
|
|
946
|
-
enableAsyncOperations: config.enableAsyncOperations !== false,
|
|
947
|
-
...config
|
|
948
|
-
};
|
|
949
|
-
this.state = {
|
|
950
|
-
totalSize: 0,
|
|
951
|
-
entryCount: 0,
|
|
952
|
-
compressionRatio: 1,
|
|
953
|
-
lastGC: Date.now(),
|
|
954
|
-
accessPatterns: new Map(),
|
|
955
|
-
performanceMetrics: {
|
|
956
|
-
queryTimes: [],
|
|
957
|
-
avgQueryTime: 0,
|
|
958
|
-
cacheHitRate: 0,
|
|
959
|
-
memoryEfficiency: 0
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
this.gcTimer = null;
|
|
963
|
-
// Optimized cache with LRU eviction
|
|
964
|
-
this.cache = new OptimizedLRUCache(this.config.cacheSize, this.config.cacheMemoryMB);
|
|
965
|
-
// Memory pools for frequently created objects
|
|
966
|
-
this.pools = {
|
|
967
|
-
queryResults: new MemoryPool(()=>({
|
|
968
|
-
results: [],
|
|
969
|
-
metadata: {}
|
|
970
|
-
}), (obj)=>{
|
|
971
|
-
obj.results.length = 0;
|
|
972
|
-
Object.keys(obj.metadata).forEach((k)=>delete obj.metadata[k]);
|
|
973
|
-
}),
|
|
974
|
-
memoryEntries: new MemoryPool(()=>({
|
|
975
|
-
id: '',
|
|
976
|
-
key: '',
|
|
977
|
-
value: '',
|
|
978
|
-
metadata: {}
|
|
979
|
-
}), (obj)=>{
|
|
980
|
-
obj.id = obj.key = obj.value = '';
|
|
981
|
-
Object.keys(obj.metadata).forEach((k)=>delete obj.metadata[k]);
|
|
982
|
-
})
|
|
983
|
-
};
|
|
984
|
-
// Prepared statements for better performance
|
|
985
|
-
this.statements = new Map();
|
|
986
|
-
// Background worker for heavy operations
|
|
987
|
-
this.backgroundWorker = null;
|
|
988
|
-
this._initialize();
|
|
1194
|
+
|
|
1195
|
+
// Check memory usage
|
|
1196
|
+
if (analytics.basic.utilizationPercent > 90) {
|
|
1197
|
+
health.status = 'warning';
|
|
1198
|
+
health.issues.push('High memory utilization');
|
|
1199
|
+
health.recommendations.push('Consider increasing max memory or running garbage collection');
|
|
989
1200
|
}
|
|
1201
|
+
|
|
1202
|
+
// Check query performance
|
|
1203
|
+
if (analytics.performance.avgQueryTime > 100) {
|
|
1204
|
+
health.issues.push('Slow query performance');
|
|
1205
|
+
health.recommendations.push('Consider database optimization or indexing');
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
return health;
|
|
1209
|
+
}
|
|
990
1210
|
}
|
|
1211
|
+
|
|
991
1212
|
/**
|
|
992
1213
|
* Memory optimization utilities
|
|
993
|
-
*/
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1214
|
+
*/
|
|
1215
|
+
export class MemoryOptimizer {
|
|
1216
|
+
static async optimizeCollectiveMemory(memory) {
|
|
1217
|
+
const startTime = performance.now();
|
|
1218
|
+
|
|
1219
|
+
// Run comprehensive optimization
|
|
1220
|
+
await memory._optimizeDatabase();
|
|
1221
|
+
memory._optimizeCache();
|
|
1222
|
+
memory._garbageCollect();
|
|
1223
|
+
|
|
1224
|
+
const duration = performance.now() - startTime;
|
|
1225
|
+
|
|
1226
|
+
return {
|
|
1227
|
+
duration,
|
|
1228
|
+
analytics: memory.getAnalytics(),
|
|
1229
|
+
health: await memory.healthCheck(),
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
static calculateOptimalCacheSize(memoryStats, accessPatterns) {
|
|
1234
|
+
const avgEntrySize = memoryStats.totalSize / memoryStats.entryCount;
|
|
1235
|
+
const hotKeys = Array.from(accessPatterns.entries())
|
|
1236
|
+
.sort((a, b) => b[1] - a[1])
|
|
1237
|
+
.slice(0, Math.min(1000, memoryStats.entryCount * 0.2));
|
|
1238
|
+
|
|
1239
|
+
const optimalCacheEntries = hotKeys.length * 1.2; // 20% buffer
|
|
1240
|
+
const optimalCacheMemoryMB = (optimalCacheEntries * avgEntrySize) / (1024 * 1024);
|
|
1241
|
+
|
|
1242
|
+
return {
|
|
1243
|
+
entries: Math.ceil(optimalCacheEntries),
|
|
1244
|
+
memoryMB: Math.ceil(optimalCacheMemoryMB),
|
|
1245
|
+
efficiency: (hotKeys.length / memoryStats.entryCount) * 100,
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
static generateOptimizationReport(analytics) {
|
|
1250
|
+
const report = {
|
|
1251
|
+
timestamp: new Date().toISOString(),
|
|
1252
|
+
summary: {},
|
|
1253
|
+
recommendations: [],
|
|
1254
|
+
metrics: analytics,
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
// Performance summary
|
|
1258
|
+
report.summary.avgQueryTime = analytics.performance.avgQueryTime;
|
|
1259
|
+
report.summary.cacheHitRate = analytics.cache.hitRate || 0;
|
|
1260
|
+
report.summary.memoryEfficiency = analytics.cache.memoryUsage / (1024 * 1024);
|
|
1261
|
+
|
|
1262
|
+
// Generate recommendations
|
|
1263
|
+
if ((analytics.cache.hitRate || 0) < 70) {
|
|
1264
|
+
report.recommendations.push({
|
|
1265
|
+
type: 'cache',
|
|
1266
|
+
priority: 'high',
|
|
1267
|
+
description: 'Increase cache size to improve hit rate',
|
|
1268
|
+
impact: 'Reduce database queries by up to 30%',
|
|
1269
|
+
});
|
|
1006
1270
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
efficiency: hotKeys.length / memoryStats.entryCount * 100
|
|
1016
|
-
};
|
|
1271
|
+
|
|
1272
|
+
if (analytics.performance.avgQueryTime > 50) {
|
|
1273
|
+
report.recommendations.push({
|
|
1274
|
+
type: 'database',
|
|
1275
|
+
priority: 'medium',
|
|
1276
|
+
description: 'Optimize database indexes and run ANALYZE',
|
|
1277
|
+
impact: 'Improve query performance by 20-40%',
|
|
1278
|
+
});
|
|
1017
1279
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
report.summary.avgQueryTime = analytics.performance.avgQueryTime;
|
|
1027
|
-
report.summary.cacheHitRate = analytics.cache.hitRate || 0;
|
|
1028
|
-
report.summary.memoryEfficiency = analytics.cache.memoryUsage / (1024 * 1024);
|
|
1029
|
-
// Generate recommendations
|
|
1030
|
-
if ((analytics.cache.hitRate || 0) < 70) {
|
|
1031
|
-
report.recommendations.push({
|
|
1032
|
-
type: 'cache',
|
|
1033
|
-
priority: 'high',
|
|
1034
|
-
description: 'Increase cache size to improve hit rate',
|
|
1035
|
-
impact: 'Reduce database queries by up to 30%'
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
if (analytics.performance.avgQueryTime > 50) {
|
|
1039
|
-
report.recommendations.push({
|
|
1040
|
-
type: 'database',
|
|
1041
|
-
priority: 'medium',
|
|
1042
|
-
description: 'Optimize database indexes and run ANALYZE',
|
|
1043
|
-
impact: 'Improve query performance by 20-40%'
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
if (analytics.pools?.queryResults?.reuseRate < 50) {
|
|
1047
|
-
report.recommendations.push({
|
|
1048
|
-
type: 'pooling',
|
|
1049
|
-
priority: 'low',
|
|
1050
|
-
description: 'Increase object pool sizes for better reuse',
|
|
1051
|
-
impact: 'Reduce garbage collection pressure'
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
return report;
|
|
1280
|
+
|
|
1281
|
+
if (analytics.pools?.queryResults?.reuseRate < 50) {
|
|
1282
|
+
report.recommendations.push({
|
|
1283
|
+
type: 'pooling',
|
|
1284
|
+
priority: 'low',
|
|
1285
|
+
description: 'Increase object pool sizes for better reuse',
|
|
1286
|
+
impact: 'Reduce garbage collection pressure',
|
|
1287
|
+
});
|
|
1055
1288
|
}
|
|
1289
|
+
|
|
1290
|
+
return report;
|
|
1291
|
+
}
|
|
1056
1292
|
}
|