agentic-qe 3.2.3 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/v3/qe-accessibility-auditor.md +90 -0
- package/README.md +43 -5
- package/package.json +3 -2
- package/scripts/cloud-db-config.json +37 -0
- package/scripts/cloud-db-connect.sh +37 -0
- package/scripts/cloud-db-tunnel.sh +23 -0
- package/v3/CHANGELOG.md +165 -0
- package/v3/README.md +59 -1
- package/v3/assets/agents/v3/qe-accessibility-auditor.md +90 -0
- package/v3/dist/adapters/claude-flow/index.d.ts +54 -0
- package/v3/dist/adapters/claude-flow/index.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/index.js +79 -0
- package/v3/dist/adapters/claude-flow/index.js.map +1 -0
- package/v3/dist/adapters/claude-flow/model-router-bridge.d.ts +70 -0
- package/v3/dist/adapters/claude-flow/model-router-bridge.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/model-router-bridge.js +203 -0
- package/v3/dist/adapters/claude-flow/model-router-bridge.js.map +1 -0
- package/v3/dist/adapters/claude-flow/pretrain-bridge.d.ts +73 -0
- package/v3/dist/adapters/claude-flow/pretrain-bridge.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/pretrain-bridge.js +276 -0
- package/v3/dist/adapters/claude-flow/pretrain-bridge.js.map +1 -0
- package/v3/dist/adapters/claude-flow/trajectory-bridge.d.ts +70 -0
- package/v3/dist/adapters/claude-flow/trajectory-bridge.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/trajectory-bridge.js +205 -0
- package/v3/dist/adapters/claude-flow/trajectory-bridge.js.map +1 -0
- package/v3/dist/adapters/claude-flow/types.d.ts +99 -0
- package/v3/dist/adapters/claude-flow/types.d.ts.map +1 -0
- package/v3/dist/adapters/claude-flow/types.js +6 -0
- package/v3/dist/adapters/claude-flow/types.js.map +1 -0
- package/v3/dist/causal-discovery/causal-graph.d.ts +80 -1
- package/v3/dist/causal-discovery/causal-graph.d.ts.map +1 -1
- package/v3/dist/causal-discovery/causal-graph.js +111 -1
- package/v3/dist/causal-discovery/causal-graph.js.map +1 -1
- package/v3/dist/cli/bundle.js +11612 -4929
- package/v3/dist/cli/commands/claude-flow-setup.d.ts +82 -0
- package/v3/dist/cli/commands/claude-flow-setup.d.ts.map +1 -0
- package/v3/dist/cli/commands/claude-flow-setup.js +334 -0
- package/v3/dist/cli/commands/claude-flow-setup.js.map +1 -0
- package/v3/dist/cli/commands/hooks.d.ts +2 -0
- package/v3/dist/cli/commands/hooks.d.ts.map +1 -1
- package/v3/dist/cli/commands/hooks.js +13 -2
- package/v3/dist/cli/commands/hooks.js.map +1 -1
- package/v3/dist/cli/commands/init.d.ts +19 -0
- package/v3/dist/cli/commands/init.d.ts.map +1 -0
- package/v3/dist/cli/commands/init.js +345 -0
- package/v3/dist/cli/commands/init.js.map +1 -0
- package/v3/dist/cli/index.js +110 -2
- package/v3/dist/cli/index.js.map +1 -1
- package/v3/dist/coordination/mincut/interfaces.d.ts +8 -2
- package/v3/dist/coordination/mincut/interfaces.d.ts.map +1 -1
- package/v3/dist/coordination/mincut/interfaces.js.map +1 -1
- package/v3/dist/coordination/mincut/mincut-health-monitor.d.ts +5 -0
- package/v3/dist/coordination/mincut/mincut-health-monitor.d.ts.map +1 -1
- package/v3/dist/coordination/mincut/mincut-health-monitor.js +22 -4
- package/v3/dist/coordination/mincut/mincut-health-monitor.js.map +1 -1
- package/v3/dist/coordination/mincut/queen-integration.d.ts +4 -0
- package/v3/dist/coordination/mincut/queen-integration.d.ts.map +1 -1
- package/v3/dist/coordination/mincut/queen-integration.js +14 -1
- package/v3/dist/coordination/mincut/queen-integration.js.map +1 -1
- package/v3/dist/coordination/queen-coordinator.d.ts +5 -0
- package/v3/dist/coordination/queen-coordinator.d.ts.map +1 -1
- package/v3/dist/coordination/queen-coordinator.js +45 -7
- package/v3/dist/coordination/queen-coordinator.js.map +1 -1
- package/v3/dist/domains/learning-optimization/coordinator.d.ts +5 -0
- package/v3/dist/domains/learning-optimization/coordinator.d.ts.map +1 -1
- package/v3/dist/domains/learning-optimization/coordinator.js +79 -0
- package/v3/dist/domains/learning-optimization/coordinator.js.map +1 -1
- package/v3/dist/domains/test-generation/coherence-gate.d.ts +245 -0
- package/v3/dist/domains/test-generation/coherence-gate.d.ts.map +1 -0
- package/v3/dist/domains/test-generation/coherence-gate.js +454 -0
- package/v3/dist/domains/test-generation/coherence-gate.js.map +1 -0
- package/v3/dist/domains/test-generation/coordinator.d.ts +32 -1
- package/v3/dist/domains/test-generation/coordinator.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/coordinator.js +70 -1
- package/v3/dist/domains/test-generation/coordinator.js.map +1 -1
- package/v3/dist/domains/test-generation/index.d.ts +1 -0
- package/v3/dist/domains/test-generation/index.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/index.js +4 -0
- package/v3/dist/domains/test-generation/index.js.map +1 -1
- package/v3/dist/domains/test-generation/services/index.d.ts +1 -0
- package/v3/dist/domains/test-generation/services/index.d.ts.map +1 -1
- package/v3/dist/domains/test-generation/services/index.js +2 -0
- package/v3/dist/domains/test-generation/services/index.js.map +1 -1
- package/v3/dist/domains/visual-accessibility/index.d.ts +2 -1
- package/v3/dist/domains/visual-accessibility/index.d.ts.map +1 -1
- package/v3/dist/domains/visual-accessibility/index.js +1 -0
- package/v3/dist/domains/visual-accessibility/index.js.map +1 -1
- package/v3/dist/domains/visual-accessibility/interfaces.d.ts +131 -0
- package/v3/dist/domains/visual-accessibility/interfaces.d.ts.map +1 -1
- package/v3/dist/domains/visual-accessibility/plugin.d.ts +26 -0
- package/v3/dist/domains/visual-accessibility/plugin.d.ts.map +1 -1
- package/v3/dist/domains/visual-accessibility/plugin.js +151 -0
- package/v3/dist/domains/visual-accessibility/plugin.js.map +1 -1
- package/v3/dist/domains/visual-accessibility/services/accessibility-tester.d.ts +42 -1
- package/v3/dist/domains/visual-accessibility/services/accessibility-tester.d.ts.map +1 -1
- package/v3/dist/domains/visual-accessibility/services/accessibility-tester.js +69 -0
- package/v3/dist/domains/visual-accessibility/services/accessibility-tester.js.map +1 -1
- package/v3/dist/domains/visual-accessibility/services/eu-compliance.d.ts +138 -0
- package/v3/dist/domains/visual-accessibility/services/eu-compliance.d.ts.map +1 -0
- package/v3/dist/domains/visual-accessibility/services/eu-compliance.js +830 -0
- package/v3/dist/domains/visual-accessibility/services/eu-compliance.js.map +1 -0
- package/v3/dist/domains/visual-accessibility/services/index.d.ts +1 -0
- package/v3/dist/domains/visual-accessibility/services/index.d.ts.map +1 -1
- package/v3/dist/domains/visual-accessibility/services/index.js +1 -0
- package/v3/dist/domains/visual-accessibility/services/index.js.map +1 -1
- package/v3/dist/init/enhancements/claude-flow-adapter.d.ts +84 -0
- package/v3/dist/init/enhancements/claude-flow-adapter.d.ts.map +1 -0
- package/v3/dist/init/enhancements/claude-flow-adapter.js +250 -0
- package/v3/dist/init/enhancements/claude-flow-adapter.js.map +1 -0
- package/v3/dist/init/enhancements/detector.d.ts +10 -0
- package/v3/dist/init/enhancements/detector.d.ts.map +1 -0
- package/v3/dist/init/enhancements/detector.js +87 -0
- package/v3/dist/init/enhancements/detector.js.map +1 -0
- package/v3/dist/init/enhancements/index.d.ts +13 -0
- package/v3/dist/init/enhancements/index.d.ts.map +1 -0
- package/v3/dist/init/enhancements/index.js +25 -0
- package/v3/dist/init/enhancements/index.js.map +1 -0
- package/v3/dist/init/enhancements/types.d.ts +93 -0
- package/v3/dist/init/enhancements/types.d.ts.map +1 -0
- package/v3/dist/init/enhancements/types.js +6 -0
- package/v3/dist/init/enhancements/types.js.map +1 -0
- package/v3/dist/init/index.d.ts +8 -0
- package/v3/dist/init/index.d.ts.map +1 -1
- package/v3/dist/init/index.js +4 -0
- package/v3/dist/init/index.js.map +1 -1
- package/v3/dist/init/migration/config-migrator.d.ts +31 -0
- package/v3/dist/init/migration/config-migrator.d.ts.map +1 -0
- package/v3/dist/init/migration/config-migrator.js +133 -0
- package/v3/dist/init/migration/config-migrator.js.map +1 -0
- package/v3/dist/init/migration/data-migrator.d.ts +72 -0
- package/v3/dist/init/migration/data-migrator.d.ts.map +1 -0
- package/v3/dist/init/migration/data-migrator.js +233 -0
- package/v3/dist/init/migration/data-migrator.js.map +1 -0
- package/v3/dist/init/migration/detector.d.ts +44 -0
- package/v3/dist/init/migration/detector.d.ts.map +1 -0
- package/v3/dist/init/migration/detector.js +106 -0
- package/v3/dist/init/migration/detector.js.map +1 -0
- package/v3/dist/init/migration/index.d.ts +8 -0
- package/v3/dist/init/migration/index.d.ts.map +1 -0
- package/v3/dist/init/migration/index.js +8 -0
- package/v3/dist/init/migration/index.js.map +1 -0
- package/v3/dist/init/orchestrator.d.ts +68 -0
- package/v3/dist/init/orchestrator.d.ts.map +1 -0
- package/v3/dist/init/orchestrator.js +239 -0
- package/v3/dist/init/orchestrator.js.map +1 -0
- package/v3/dist/init/phases/01-detection.d.ts +30 -0
- package/v3/dist/init/phases/01-detection.d.ts.map +1 -0
- package/v3/dist/init/phases/01-detection.js +143 -0
- package/v3/dist/init/phases/01-detection.js.map +1 -0
- package/v3/dist/init/phases/02-analysis.d.ts +18 -0
- package/v3/dist/init/phases/02-analysis.d.ts.map +1 -0
- package/v3/dist/init/phases/02-analysis.js +28 -0
- package/v3/dist/init/phases/02-analysis.js.map +1 -0
- package/v3/dist/init/phases/03-configuration.d.ts +26 -0
- package/v3/dist/init/phases/03-configuration.d.ts.map +1 -0
- package/v3/dist/init/phases/03-configuration.js +98 -0
- package/v3/dist/init/phases/03-configuration.js.map +1 -0
- package/v3/dist/init/phases/04-database.d.ts +22 -0
- package/v3/dist/init/phases/04-database.d.ts.map +1 -0
- package/v3/dist/init/phases/04-database.js +88 -0
- package/v3/dist/init/phases/04-database.js.map +1 -0
- package/v3/dist/init/phases/05-learning.d.ts +28 -0
- package/v3/dist/init/phases/05-learning.d.ts.map +1 -0
- package/v3/dist/init/phases/05-learning.js +98 -0
- package/v3/dist/init/phases/05-learning.js.map +1 -0
- package/v3/dist/init/phases/06-code-intelligence.d.ts +33 -0
- package/v3/dist/init/phases/06-code-intelligence.d.ts.map +1 -0
- package/v3/dist/init/phases/06-code-intelligence.js +115 -0
- package/v3/dist/init/phases/06-code-intelligence.js.map +1 -0
- package/v3/dist/init/phases/07-hooks.d.ts +27 -0
- package/v3/dist/init/phases/07-hooks.d.ts.map +1 -0
- package/v3/dist/init/phases/07-hooks.js +209 -0
- package/v3/dist/init/phases/07-hooks.js.map +1 -0
- package/v3/dist/init/phases/08-mcp.d.ts +22 -0
- package/v3/dist/init/phases/08-mcp.d.ts.map +1 -0
- package/v3/dist/init/phases/08-mcp.js +62 -0
- package/v3/dist/init/phases/08-mcp.js.map +1 -0
- package/v3/dist/init/phases/09-assets.d.ts +23 -0
- package/v3/dist/init/phases/09-assets.d.ts.map +1 -0
- package/v3/dist/init/phases/09-assets.js +82 -0
- package/v3/dist/init/phases/09-assets.js.map +1 -0
- package/v3/dist/init/phases/10-workers.d.ts +23 -0
- package/v3/dist/init/phases/10-workers.d.ts.map +1 -0
- package/v3/dist/init/phases/10-workers.js +111 -0
- package/v3/dist/init/phases/10-workers.js.map +1 -0
- package/v3/dist/init/phases/11-claude-md.d.ts +26 -0
- package/v3/dist/init/phases/11-claude-md.d.ts.map +1 -0
- package/v3/dist/init/phases/11-claude-md.js +121 -0
- package/v3/dist/init/phases/11-claude-md.js.map +1 -0
- package/v3/dist/init/phases/12-verification.d.ts +38 -0
- package/v3/dist/init/phases/12-verification.d.ts.map +1 -0
- package/v3/dist/init/phases/12-verification.js +187 -0
- package/v3/dist/init/phases/12-verification.js.map +1 -0
- package/v3/dist/init/phases/index.d.ts +46 -0
- package/v3/dist/init/phases/index.d.ts.map +1 -0
- package/v3/dist/init/phases/index.js +64 -0
- package/v3/dist/init/phases/index.js.map +1 -0
- package/v3/dist/init/phases/phase-interface.d.ts +193 -0
- package/v3/dist/init/phases/phase-interface.d.ts.map +1 -0
- package/v3/dist/init/phases/phase-interface.js +119 -0
- package/v3/dist/init/phases/phase-interface.js.map +1 -0
- package/v3/dist/integrations/coherence/coherence-service.d.ts +323 -0
- package/v3/dist/integrations/coherence/coherence-service.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/coherence-service.js +799 -0
- package/v3/dist/integrations/coherence/coherence-service.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/category-adapter.d.ts +170 -0
- package/v3/dist/integrations/coherence/engines/category-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/category-adapter.js +403 -0
- package/v3/dist/integrations/coherence/engines/category-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/causal-adapter.d.ts +159 -0
- package/v3/dist/integrations/coherence/engines/causal-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/causal-adapter.js +348 -0
- package/v3/dist/integrations/coherence/engines/causal-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/cohomology-adapter.d.ts +174 -0
- package/v3/dist/integrations/coherence/engines/cohomology-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/cohomology-adapter.js +401 -0
- package/v3/dist/integrations/coherence/engines/cohomology-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/homotopy-adapter.d.ts +201 -0
- package/v3/dist/integrations/coherence/engines/homotopy-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/homotopy-adapter.js +324 -0
- package/v3/dist/integrations/coherence/engines/homotopy-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/index.d.ts +20 -0
- package/v3/dist/integrations/coherence/engines/index.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/index.js +26 -0
- package/v3/dist/integrations/coherence/engines/index.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/spectral-adapter.d.ts +193 -0
- package/v3/dist/integrations/coherence/engines/spectral-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/spectral-adapter.js +476 -0
- package/v3/dist/integrations/coherence/engines/spectral-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/engines/witness-adapter.d.ts +175 -0
- package/v3/dist/integrations/coherence/engines/witness-adapter.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/engines/witness-adapter.js +377 -0
- package/v3/dist/integrations/coherence/engines/witness-adapter.js.map +1 -0
- package/v3/dist/integrations/coherence/index.d.ts +84 -0
- package/v3/dist/integrations/coherence/index.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/index.js +114 -0
- package/v3/dist/integrations/coherence/index.js.map +1 -0
- package/v3/dist/integrations/coherence/threshold-tuner.d.ts +396 -0
- package/v3/dist/integrations/coherence/threshold-tuner.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/threshold-tuner.js +538 -0
- package/v3/dist/integrations/coherence/threshold-tuner.js.map +1 -0
- package/v3/dist/integrations/coherence/types.d.ts +879 -0
- package/v3/dist/integrations/coherence/types.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/types.js +134 -0
- package/v3/dist/integrations/coherence/types.js.map +1 -0
- package/v3/dist/integrations/coherence/wasm-loader.d.ts +351 -0
- package/v3/dist/integrations/coherence/wasm-loader.d.ts.map +1 -0
- package/v3/dist/integrations/coherence/wasm-loader.js +842 -0
- package/v3/dist/integrations/coherence/wasm-loader.js.map +1 -0
- package/v3/dist/integrations/embeddings/index/HNSWIndex.d.ts.map +1 -1
- package/v3/dist/integrations/embeddings/index/HNSWIndex.js +4 -1
- package/v3/dist/integrations/embeddings/index/HNSWIndex.js.map +1 -1
- package/v3/dist/kernel/interfaces.d.ts +8 -1
- package/v3/dist/kernel/interfaces.d.ts.map +1 -1
- package/v3/dist/learning/aqe-learning-engine.d.ts +272 -0
- package/v3/dist/learning/aqe-learning-engine.d.ts.map +1 -0
- package/v3/dist/learning/aqe-learning-engine.js +708 -0
- package/v3/dist/learning/aqe-learning-engine.js.map +1 -0
- package/v3/dist/learning/causal-verifier.d.ts +244 -0
- package/v3/dist/learning/causal-verifier.d.ts.map +1 -0
- package/v3/dist/learning/causal-verifier.js +300 -0
- package/v3/dist/learning/causal-verifier.js.map +1 -0
- package/v3/dist/learning/experience-capture.d.ts +266 -0
- package/v3/dist/learning/experience-capture.d.ts.map +1 -0
- package/v3/dist/learning/experience-capture.js +647 -0
- package/v3/dist/learning/experience-capture.js.map +1 -0
- package/v3/dist/learning/index.d.ts +8 -0
- package/v3/dist/learning/index.d.ts.map +1 -1
- package/v3/dist/learning/index.js +16 -0
- package/v3/dist/learning/index.js.map +1 -1
- package/v3/dist/learning/memory-auditor.d.ts +235 -0
- package/v3/dist/learning/memory-auditor.d.ts.map +1 -0
- package/v3/dist/learning/memory-auditor.js +478 -0
- package/v3/dist/learning/memory-auditor.js.map +1 -0
- package/v3/dist/learning/pattern-store.d.ts.map +1 -1
- package/v3/dist/learning/pattern-store.js +27 -6
- package/v3/dist/learning/pattern-store.js.map +1 -1
- package/v3/dist/learning/qe-patterns.d.ts +15 -1
- package/v3/dist/learning/qe-patterns.d.ts.map +1 -1
- package/v3/dist/learning/qe-patterns.js +26 -5
- package/v3/dist/learning/qe-patterns.js.map +1 -1
- package/v3/dist/learning/qe-reasoning-bank.d.ts +38 -2
- package/v3/dist/learning/qe-reasoning-bank.d.ts.map +1 -1
- package/v3/dist/learning/qe-reasoning-bank.js +86 -4
- package/v3/dist/learning/qe-reasoning-bank.js.map +1 -1
- package/v3/dist/learning/real-qe-reasoning-bank.d.ts +32 -2
- package/v3/dist/learning/real-qe-reasoning-bank.d.ts.map +1 -1
- package/v3/dist/learning/real-qe-reasoning-bank.js +61 -6
- package/v3/dist/learning/real-qe-reasoning-bank.js.map +1 -1
- package/v3/dist/mcp/bundle.js +6303 -266
- package/v3/dist/mcp/tools/coherence/audit.d.ts +107 -0
- package/v3/dist/mcp/tools/coherence/audit.d.ts.map +1 -0
- package/v3/dist/mcp/tools/coherence/audit.js +236 -0
- package/v3/dist/mcp/tools/coherence/audit.js.map +1 -0
- package/v3/dist/mcp/tools/coherence/check.d.ts +106 -0
- package/v3/dist/mcp/tools/coherence/check.d.ts.map +1 -0
- package/v3/dist/mcp/tools/coherence/check.js +205 -0
- package/v3/dist/mcp/tools/coherence/check.js.map +1 -0
- package/v3/dist/mcp/tools/coherence/collapse.d.ts +123 -0
- package/v3/dist/mcp/tools/coherence/collapse.d.ts.map +1 -0
- package/v3/dist/mcp/tools/coherence/collapse.js +279 -0
- package/v3/dist/mcp/tools/coherence/collapse.js.map +1 -0
- package/v3/dist/mcp/tools/coherence/consensus.d.ts +100 -0
- package/v3/dist/mcp/tools/coherence/consensus.d.ts.map +1 -0
- package/v3/dist/mcp/tools/coherence/consensus.js +201 -0
- package/v3/dist/mcp/tools/coherence/consensus.js.map +1 -0
- package/v3/dist/mcp/tools/coherence/index.d.ts +31 -0
- package/v3/dist/mcp/tools/coherence/index.d.ts.map +1 -0
- package/v3/dist/mcp/tools/coherence/index.js +42 -0
- package/v3/dist/mcp/tools/coherence/index.js.map +1 -0
- package/v3/dist/mcp/tools/index.d.ts +6 -1
- package/v3/dist/mcp/tools/index.d.ts.map +1 -1
- package/v3/dist/mcp/tools/index.js +9 -1
- package/v3/dist/mcp/tools/index.js.map +1 -1
- package/v3/dist/mcp/tools/mincut/index.d.ts +1 -1
- package/v3/dist/mcp/tools/mincut/index.d.ts.map +1 -1
- package/v3/dist/mcp/tools/mincut/index.js.map +1 -1
- package/v3/dist/mcp/tools/registry.d.ts +4 -0
- package/v3/dist/mcp/tools/registry.d.ts.map +1 -1
- package/v3/dist/mcp/tools/registry.js +5 -0
- package/v3/dist/mcp/tools/registry.js.map +1 -1
- package/v3/dist/mcp/types.d.ts +1 -1
- package/v3/dist/mcp/types.d.ts.map +1 -1
- package/v3/dist/strange-loop/belief-reconciler.d.ts +357 -0
- package/v3/dist/strange-loop/belief-reconciler.d.ts.map +1 -0
- package/v3/dist/strange-loop/belief-reconciler.js +696 -0
- package/v3/dist/strange-loop/belief-reconciler.js.map +1 -0
- package/v3/dist/strange-loop/index.d.ts +1 -0
- package/v3/dist/strange-loop/index.d.ts.map +1 -1
- package/v3/dist/strange-loop/index.js +2 -0
- package/v3/dist/strange-loop/index.js.map +1 -1
- package/v3/dist/strange-loop/strange-loop.d.ts +177 -5
- package/v3/dist/strange-loop/strange-loop.d.ts.map +1 -1
- package/v3/dist/strange-loop/strange-loop.js +452 -9
- package/v3/dist/strange-loop/strange-loop.js.map +1 -1
- package/v3/dist/strange-loop/types.d.ts +205 -1
- package/v3/dist/strange-loop/types.d.ts.map +1 -1
- package/v3/dist/strange-loop/types.js +5 -0
- package/v3/dist/strange-loop/types.js.map +1 -1
- package/v3/package.json +5 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic QE v3 - Spectral Engine Adapter
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Prime Radiant SpectralEngine for spectral graph analysis.
|
|
5
|
+
* Used for predicting swarm collapse through Fiedler value analysis.
|
|
6
|
+
*
|
|
7
|
+
* Fiedler Value (Spectral Gap):
|
|
8
|
+
* The second-smallest eigenvalue of the Laplacian matrix.
|
|
9
|
+
* Low values indicate:
|
|
10
|
+
* - Weak connectivity
|
|
11
|
+
* - Potential for network fragmentation
|
|
12
|
+
* - False consensus risk
|
|
13
|
+
*
|
|
14
|
+
* @module integrations/coherence/engines/spectral-adapter
|
|
15
|
+
*/
|
|
16
|
+
import type { SwarmState, CollapseRisk, IWasmLoader, CoherenceLogger } from '../types';
|
|
17
|
+
/**
|
|
18
|
+
* Interface for the spectral adapter
|
|
19
|
+
*/
|
|
20
|
+
export interface ISpectralAdapter {
|
|
21
|
+
/** Initialize the adapter */
|
|
22
|
+
initialize(): Promise<void>;
|
|
23
|
+
/** Check if initialized */
|
|
24
|
+
isInitialized(): boolean;
|
|
25
|
+
/** Add a node (agent) to the graph */
|
|
26
|
+
addNode(nodeId: string): void;
|
|
27
|
+
/** Add an edge (relationship) between nodes */
|
|
28
|
+
addEdge(source: string, target: string, weight: number): void;
|
|
29
|
+
/** Remove a node */
|
|
30
|
+
removeNode(nodeId: string): void;
|
|
31
|
+
/** Compute the Fiedler value */
|
|
32
|
+
computeFiedlerValue(): number;
|
|
33
|
+
/** Predict collapse risk */
|
|
34
|
+
predictCollapseRisk(): number;
|
|
35
|
+
/** Get weak vertices (at-risk nodes) */
|
|
36
|
+
getWeakVertices(count: number): string[];
|
|
37
|
+
/** Analyze swarm state for collapse risk */
|
|
38
|
+
analyzeSwarmState(state: SwarmState): CollapseRisk;
|
|
39
|
+
/** Clear the graph */
|
|
40
|
+
clear(): void;
|
|
41
|
+
/** Dispose of resources */
|
|
42
|
+
dispose(): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Adapter for the Prime Radiant SpectralEngine
|
|
46
|
+
*
|
|
47
|
+
* Provides spectral graph analysis for predicting swarm collapse
|
|
48
|
+
* and identifying weak points in the agent network.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const adapter = new SpectralAdapter(wasmLoader, logger);
|
|
53
|
+
* await adapter.initialize();
|
|
54
|
+
*
|
|
55
|
+
* adapter.addNode('agent-1');
|
|
56
|
+
* adapter.addNode('agent-2');
|
|
57
|
+
* adapter.addEdge('agent-1', 'agent-2', 1.0);
|
|
58
|
+
*
|
|
59
|
+
* const fiedlerValue = adapter.computeFiedlerValue();
|
|
60
|
+
* const collapseRisk = adapter.predictCollapseRisk();
|
|
61
|
+
* const weakAgents = adapter.getWeakVertices(3);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class SpectralAdapter implements ISpectralAdapter {
|
|
65
|
+
private readonly wasmLoader;
|
|
66
|
+
private readonly logger;
|
|
67
|
+
private engine;
|
|
68
|
+
private initialized;
|
|
69
|
+
private readonly nodes;
|
|
70
|
+
private readonly edges;
|
|
71
|
+
/**
|
|
72
|
+
* Create a new SpectralAdapter
|
|
73
|
+
*
|
|
74
|
+
* @param wasmLoader - WASM module loader
|
|
75
|
+
* @param logger - Optional logger for diagnostics
|
|
76
|
+
*/
|
|
77
|
+
constructor(wasmLoader: IWasmLoader, logger?: CoherenceLogger);
|
|
78
|
+
/**
|
|
79
|
+
* Initialize the adapter by loading the WASM module
|
|
80
|
+
*/
|
|
81
|
+
initialize(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Check if the adapter is initialized
|
|
84
|
+
*/
|
|
85
|
+
isInitialized(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Ensure the adapter is initialized before use
|
|
88
|
+
*/
|
|
89
|
+
private ensureInitialized;
|
|
90
|
+
/**
|
|
91
|
+
* Add a node (agent) to the spectral graph
|
|
92
|
+
*
|
|
93
|
+
* @param nodeId - Unique identifier for the node
|
|
94
|
+
*/
|
|
95
|
+
addNode(nodeId: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Add an edge between two nodes
|
|
98
|
+
*
|
|
99
|
+
* @param source - Source node ID
|
|
100
|
+
* @param target - Target node ID
|
|
101
|
+
* @param weight - Edge weight (relationship strength)
|
|
102
|
+
*/
|
|
103
|
+
addEdge(source: string, target: string, weight: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Remove a node from the graph
|
|
106
|
+
*
|
|
107
|
+
* @param nodeId - ID of the node to remove
|
|
108
|
+
*/
|
|
109
|
+
removeNode(nodeId: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* Compute the Fiedler value (algebraic connectivity)
|
|
112
|
+
*
|
|
113
|
+
* The Fiedler value is the second-smallest eigenvalue of the Laplacian.
|
|
114
|
+
* - Higher values indicate better connectivity
|
|
115
|
+
* - Low values suggest the network could easily split
|
|
116
|
+
* - Zero indicates disconnected components
|
|
117
|
+
*
|
|
118
|
+
* @returns The Fiedler value (>= 0)
|
|
119
|
+
*/
|
|
120
|
+
computeFiedlerValue(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Predict the risk of swarm collapse
|
|
123
|
+
*
|
|
124
|
+
* Based on spectral analysis of the agent connectivity graph.
|
|
125
|
+
*
|
|
126
|
+
* @returns Collapse risk (0-1, higher = more risk)
|
|
127
|
+
*/
|
|
128
|
+
predictCollapseRisk(): number;
|
|
129
|
+
/**
|
|
130
|
+
* Get the nodes most at risk of causing collapse
|
|
131
|
+
*
|
|
132
|
+
* These are nodes whose removal would most significantly
|
|
133
|
+
* impact network connectivity.
|
|
134
|
+
*
|
|
135
|
+
* @param count - Number of weak vertices to return
|
|
136
|
+
* @returns Array of node IDs sorted by vulnerability
|
|
137
|
+
*/
|
|
138
|
+
getWeakVertices(count: number): string[];
|
|
139
|
+
/**
|
|
140
|
+
* Analyze a swarm state for collapse risk
|
|
141
|
+
*
|
|
142
|
+
* Builds a spectral graph from the swarm state and analyzes it.
|
|
143
|
+
*
|
|
144
|
+
* @param state - Current swarm state
|
|
145
|
+
* @returns Collapse risk analysis
|
|
146
|
+
*/
|
|
147
|
+
analyzeSwarmState(state: SwarmState): CollapseRisk;
|
|
148
|
+
/**
|
|
149
|
+
* Build edges between agents based on belief similarity
|
|
150
|
+
*/
|
|
151
|
+
private buildEdgesFromAgents;
|
|
152
|
+
/**
|
|
153
|
+
* Compute similarity between two agents based on their states
|
|
154
|
+
*/
|
|
155
|
+
private computeAgentSimilarity;
|
|
156
|
+
/**
|
|
157
|
+
* Compute overlap between belief sets using embedding similarity
|
|
158
|
+
*/
|
|
159
|
+
private computeBeliefOverlap;
|
|
160
|
+
/**
|
|
161
|
+
* Compute cosine similarity between two vectors
|
|
162
|
+
*/
|
|
163
|
+
private cosineSimilarity;
|
|
164
|
+
/**
|
|
165
|
+
* Generate recommendations based on collapse analysis
|
|
166
|
+
*/
|
|
167
|
+
private generateRecommendations;
|
|
168
|
+
/**
|
|
169
|
+
* Clear all nodes and edges from the graph
|
|
170
|
+
*/
|
|
171
|
+
clear(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Dispose of adapter resources
|
|
174
|
+
*/
|
|
175
|
+
dispose(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Get the number of nodes in the graph
|
|
178
|
+
*/
|
|
179
|
+
getNodeCount(): number;
|
|
180
|
+
/**
|
|
181
|
+
* Get the number of edges in the graph
|
|
182
|
+
*/
|
|
183
|
+
getEdgeCount(): number;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create and initialize a SpectralAdapter
|
|
187
|
+
*
|
|
188
|
+
* @param wasmLoader - WASM module loader
|
|
189
|
+
* @param logger - Optional logger
|
|
190
|
+
* @returns Initialized adapter
|
|
191
|
+
*/
|
|
192
|
+
export declare function createSpectralAdapter(wasmLoader: IWasmLoader, logger?: CoherenceLogger): Promise<SpectralAdapter>;
|
|
193
|
+
//# sourceMappingURL=spectral-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectral-adapter.d.ts","sourceRoot":"","sources":["../../../../src/integrations/coherence/engines/spectral-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EAGZ,WAAW,EACX,eAAe,EAChB,MAAM,UAAU,CAAC;AA8GlB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6BAA6B;IAC7B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,2BAA2B;IAC3B,aAAa,IAAI,OAAO,CAAC;IACzB,sCAAsC;IACtC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,+CAA+C;IAC/C,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9D,oBAAoB;IACpB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gCAAgC;IAChC,mBAAmB,IAAI,MAAM,CAAC;IAC9B,4BAA4B;IAC5B,mBAAmB,IAAI,MAAM,CAAC;IAC9B,wCAAwC;IACxC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzC,4CAA4C;IAC5C,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAAC;IACnD,sBAAsB;IACtB,KAAK,IAAI,IAAI,CAAC;IACd,2BAA2B;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IAapD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAbzB,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiE;IAEvF;;;;;OAKG;gBAEgB,UAAU,EAAE,WAAW,EACvB,MAAM,GAAE,eAA0C;IAGrE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBjC;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAc7B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAiB7D;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAiBhC;;;;;;;;;OASG;IACH,mBAAmB,IAAI,MAAM;IAc7B;;;;;;OAMG;IACH,mBAAmB,IAAI,MAAM;IAc7B;;;;;;;;OAQG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAkBxC;;;;;;;OAOG;IACH,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY;IA0ClD;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAqB9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgD/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAUb;;OAEG;IACH,OAAO,IAAI,IAAI;IAYf;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,YAAY,IAAI,MAAM;CAGvB;AAMD;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,WAAW,EACvB,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,eAAe,CAAC,CAI1B"}
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic QE v3 - Spectral Engine Adapter
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Prime Radiant SpectralEngine for spectral graph analysis.
|
|
5
|
+
* Used for predicting swarm collapse through Fiedler value analysis.
|
|
6
|
+
*
|
|
7
|
+
* Fiedler Value (Spectral Gap):
|
|
8
|
+
* The second-smallest eigenvalue of the Laplacian matrix.
|
|
9
|
+
* Low values indicate:
|
|
10
|
+
* - Weak connectivity
|
|
11
|
+
* - Potential for network fragmentation
|
|
12
|
+
* - False consensus risk
|
|
13
|
+
*
|
|
14
|
+
* @module integrations/coherence/engines/spectral-adapter
|
|
15
|
+
*/
|
|
16
|
+
import { WasmNotLoadedError, DEFAULT_COHERENCE_LOGGER } from '../types';
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// WASM Engine Wrapper
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Creates an ISpectralEngine wrapper around the raw WASM engine
|
|
22
|
+
*
|
|
23
|
+
* IMPORTANT: WASM expects numeric node IDs (usize), so we maintain
|
|
24
|
+
* a bidirectional mapping between string IDs and numeric indices.
|
|
25
|
+
*/
|
|
26
|
+
function createSpectralEngineWrapper(rawEngine) {
|
|
27
|
+
const nodes = new Set();
|
|
28
|
+
const edges = [];
|
|
29
|
+
// Bidirectional mapping: string ID <-> numeric index
|
|
30
|
+
// WASM expects usize (unsigned integer) for node IDs
|
|
31
|
+
const stringToIndex = new Map();
|
|
32
|
+
const indexToString = new Map();
|
|
33
|
+
let nextIndex = 0;
|
|
34
|
+
// Get or create numeric index for a string ID
|
|
35
|
+
const getOrCreateIndex = (id) => {
|
|
36
|
+
let idx = stringToIndex.get(id);
|
|
37
|
+
if (idx === undefined) {
|
|
38
|
+
idx = nextIndex++;
|
|
39
|
+
stringToIndex.set(id, idx);
|
|
40
|
+
indexToString.set(idx, id);
|
|
41
|
+
}
|
|
42
|
+
return idx;
|
|
43
|
+
};
|
|
44
|
+
// Get string ID from numeric index
|
|
45
|
+
const getStringId = (idx) => {
|
|
46
|
+
return indexToString.get(idx) ?? `unknown-${idx}`;
|
|
47
|
+
};
|
|
48
|
+
// Build graph representation for WASM calls using numeric IDs
|
|
49
|
+
// WASM may expect nodes as objects with id/label or as simple numeric array depending on engine
|
|
50
|
+
const buildGraph = () => ({
|
|
51
|
+
nodes: Array.from(nodes).map(id => ({
|
|
52
|
+
id: getOrCreateIndex(id), // Numeric index
|
|
53
|
+
label: id, // Original string ID as label
|
|
54
|
+
})),
|
|
55
|
+
edges: edges.map(e => ({
|
|
56
|
+
source: getOrCreateIndex(e.source), // Convert to numeric
|
|
57
|
+
target: getOrCreateIndex(e.target), // Convert to numeric
|
|
58
|
+
weight: e.weight,
|
|
59
|
+
})),
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
add_node(id) {
|
|
63
|
+
nodes.add(id);
|
|
64
|
+
getOrCreateIndex(id); // Pre-register the ID
|
|
65
|
+
},
|
|
66
|
+
add_edge(source, target, weight) {
|
|
67
|
+
edges.push({ source, target, weight });
|
|
68
|
+
// Pre-register edge endpoint IDs
|
|
69
|
+
getOrCreateIndex(source);
|
|
70
|
+
getOrCreateIndex(target);
|
|
71
|
+
},
|
|
72
|
+
remove_node(id) {
|
|
73
|
+
nodes.delete(id);
|
|
74
|
+
// Note: We don't remove from index mappings to maintain consistency
|
|
75
|
+
for (let i = edges.length - 1; i >= 0; i--) {
|
|
76
|
+
if (edges[i].source === id || edges[i].target === id) {
|
|
77
|
+
edges.splice(i, 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
compute_fiedler_value() {
|
|
82
|
+
const graph = buildGraph();
|
|
83
|
+
return rawEngine.algebraicConnectivity(graph);
|
|
84
|
+
},
|
|
85
|
+
predict_collapse_risk() {
|
|
86
|
+
const graph = buildGraph();
|
|
87
|
+
const fiedler = rawEngine.algebraicConnectivity(graph);
|
|
88
|
+
// Lower Fiedler value = higher collapse risk
|
|
89
|
+
return Math.max(0, Math.min(1, 1 - fiedler));
|
|
90
|
+
},
|
|
91
|
+
get_weak_vertices(count) {
|
|
92
|
+
const graph = buildGraph();
|
|
93
|
+
const minCut = rawEngine.predictMinCut(graph);
|
|
94
|
+
if (!minCut?.vertices)
|
|
95
|
+
return Array.from(nodes).slice(0, count);
|
|
96
|
+
// Convert numeric indices back to string IDs
|
|
97
|
+
return minCut.vertices.slice(0, count).map(idx => getStringId(idx));
|
|
98
|
+
},
|
|
99
|
+
clear() {
|
|
100
|
+
nodes.clear();
|
|
101
|
+
edges.length = 0;
|
|
102
|
+
stringToIndex.clear();
|
|
103
|
+
indexToString.clear();
|
|
104
|
+
nextIndex = 0;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// Spectral Adapter Implementation
|
|
110
|
+
// ============================================================================
|
|
111
|
+
/**
|
|
112
|
+
* Adapter for the Prime Radiant SpectralEngine
|
|
113
|
+
*
|
|
114
|
+
* Provides spectral graph analysis for predicting swarm collapse
|
|
115
|
+
* and identifying weak points in the agent network.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const adapter = new SpectralAdapter(wasmLoader, logger);
|
|
120
|
+
* await adapter.initialize();
|
|
121
|
+
*
|
|
122
|
+
* adapter.addNode('agent-1');
|
|
123
|
+
* adapter.addNode('agent-2');
|
|
124
|
+
* adapter.addEdge('agent-1', 'agent-2', 1.0);
|
|
125
|
+
*
|
|
126
|
+
* const fiedlerValue = adapter.computeFiedlerValue();
|
|
127
|
+
* const collapseRisk = adapter.predictCollapseRisk();
|
|
128
|
+
* const weakAgents = adapter.getWeakVertices(3);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export class SpectralAdapter {
|
|
132
|
+
wasmLoader;
|
|
133
|
+
logger;
|
|
134
|
+
engine = null;
|
|
135
|
+
initialized = false;
|
|
136
|
+
nodes = new Set();
|
|
137
|
+
edges = [];
|
|
138
|
+
/**
|
|
139
|
+
* Create a new SpectralAdapter
|
|
140
|
+
*
|
|
141
|
+
* @param wasmLoader - WASM module loader
|
|
142
|
+
* @param logger - Optional logger for diagnostics
|
|
143
|
+
*/
|
|
144
|
+
constructor(wasmLoader, logger = DEFAULT_COHERENCE_LOGGER) {
|
|
145
|
+
this.wasmLoader = wasmLoader;
|
|
146
|
+
this.logger = logger;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Initialize the adapter by loading the WASM module
|
|
150
|
+
*/
|
|
151
|
+
async initialize() {
|
|
152
|
+
if (this.initialized)
|
|
153
|
+
return;
|
|
154
|
+
this.logger.debug('Initializing SpectralAdapter');
|
|
155
|
+
const isAvailable = await this.wasmLoader.isAvailable();
|
|
156
|
+
if (!isAvailable) {
|
|
157
|
+
throw new WasmNotLoadedError('WASM module is not available. Cannot initialize SpectralAdapter.');
|
|
158
|
+
}
|
|
159
|
+
const module = await this.wasmLoader.load();
|
|
160
|
+
// Create wrapper around raw WASM engine
|
|
161
|
+
const rawEngine = new module.SpectralEngine();
|
|
162
|
+
this.engine = createSpectralEngineWrapper(rawEngine);
|
|
163
|
+
this.initialized = true;
|
|
164
|
+
this.logger.info('SpectralAdapter initialized successfully');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Check if the adapter is initialized
|
|
168
|
+
*/
|
|
169
|
+
isInitialized() {
|
|
170
|
+
return this.initialized;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Ensure the adapter is initialized before use
|
|
174
|
+
*/
|
|
175
|
+
ensureInitialized() {
|
|
176
|
+
if (!this.initialized || !this.engine) {
|
|
177
|
+
throw new WasmNotLoadedError('SpectralAdapter not initialized. Call initialize() first.');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Add a node (agent) to the spectral graph
|
|
182
|
+
*
|
|
183
|
+
* @param nodeId - Unique identifier for the node
|
|
184
|
+
*/
|
|
185
|
+
addNode(nodeId) {
|
|
186
|
+
this.ensureInitialized();
|
|
187
|
+
if (this.nodes.has(nodeId)) {
|
|
188
|
+
this.logger.debug('Node already exists', { nodeId });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.nodes.add(nodeId);
|
|
192
|
+
this.engine.add_node(nodeId);
|
|
193
|
+
this.logger.debug('Added node to spectral graph', { nodeId });
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Add an edge between two nodes
|
|
197
|
+
*
|
|
198
|
+
* @param source - Source node ID
|
|
199
|
+
* @param target - Target node ID
|
|
200
|
+
* @param weight - Edge weight (relationship strength)
|
|
201
|
+
*/
|
|
202
|
+
addEdge(source, target, weight) {
|
|
203
|
+
this.ensureInitialized();
|
|
204
|
+
// Ensure both nodes exist
|
|
205
|
+
if (!this.nodes.has(source)) {
|
|
206
|
+
this.addNode(source);
|
|
207
|
+
}
|
|
208
|
+
if (!this.nodes.has(target)) {
|
|
209
|
+
this.addNode(target);
|
|
210
|
+
}
|
|
211
|
+
this.edges.push({ source, target, weight });
|
|
212
|
+
this.engine.add_edge(source, target, weight);
|
|
213
|
+
this.logger.debug('Added edge to spectral graph', { source, target, weight });
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Remove a node from the graph
|
|
217
|
+
*
|
|
218
|
+
* @param nodeId - ID of the node to remove
|
|
219
|
+
*/
|
|
220
|
+
removeNode(nodeId) {
|
|
221
|
+
this.ensureInitialized();
|
|
222
|
+
this.nodes.delete(nodeId);
|
|
223
|
+
this.engine.remove_node(nodeId);
|
|
224
|
+
// Remove edges connected to this node
|
|
225
|
+
for (let i = this.edges.length - 1; i >= 0; i--) {
|
|
226
|
+
const edge = this.edges[i];
|
|
227
|
+
if (edge.source === nodeId || edge.target === nodeId) {
|
|
228
|
+
this.edges.splice(i, 1);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
this.logger.debug('Removed node from spectral graph', { nodeId });
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Compute the Fiedler value (algebraic connectivity)
|
|
235
|
+
*
|
|
236
|
+
* The Fiedler value is the second-smallest eigenvalue of the Laplacian.
|
|
237
|
+
* - Higher values indicate better connectivity
|
|
238
|
+
* - Low values suggest the network could easily split
|
|
239
|
+
* - Zero indicates disconnected components
|
|
240
|
+
*
|
|
241
|
+
* @returns The Fiedler value (>= 0)
|
|
242
|
+
*/
|
|
243
|
+
computeFiedlerValue() {
|
|
244
|
+
this.ensureInitialized();
|
|
245
|
+
if (this.nodes.size < 2) {
|
|
246
|
+
return 0; // Need at least 2 nodes for meaningful analysis
|
|
247
|
+
}
|
|
248
|
+
const fiedlerValue = this.engine.compute_fiedler_value();
|
|
249
|
+
this.logger.debug('Computed Fiedler value', { fiedlerValue });
|
|
250
|
+
return fiedlerValue;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Predict the risk of swarm collapse
|
|
254
|
+
*
|
|
255
|
+
* Based on spectral analysis of the agent connectivity graph.
|
|
256
|
+
*
|
|
257
|
+
* @returns Collapse risk (0-1, higher = more risk)
|
|
258
|
+
*/
|
|
259
|
+
predictCollapseRisk() {
|
|
260
|
+
this.ensureInitialized();
|
|
261
|
+
if (this.nodes.size < 2) {
|
|
262
|
+
return 0; // Can't collapse with fewer than 2 nodes
|
|
263
|
+
}
|
|
264
|
+
const risk = this.engine.predict_collapse_risk();
|
|
265
|
+
this.logger.debug('Predicted collapse risk', { risk });
|
|
266
|
+
return risk;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get the nodes most at risk of causing collapse
|
|
270
|
+
*
|
|
271
|
+
* These are nodes whose removal would most significantly
|
|
272
|
+
* impact network connectivity.
|
|
273
|
+
*
|
|
274
|
+
* @param count - Number of weak vertices to return
|
|
275
|
+
* @returns Array of node IDs sorted by vulnerability
|
|
276
|
+
*/
|
|
277
|
+
getWeakVertices(count) {
|
|
278
|
+
this.ensureInitialized();
|
|
279
|
+
if (this.nodes.size === 0) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
const safeCount = Math.min(count, this.nodes.size);
|
|
283
|
+
const weakVertices = this.engine.get_weak_vertices(safeCount);
|
|
284
|
+
this.logger.debug('Retrieved weak vertices', {
|
|
285
|
+
requested: count,
|
|
286
|
+
returned: weakVertices.length,
|
|
287
|
+
});
|
|
288
|
+
return weakVertices;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Analyze a swarm state for collapse risk
|
|
292
|
+
*
|
|
293
|
+
* Builds a spectral graph from the swarm state and analyzes it.
|
|
294
|
+
*
|
|
295
|
+
* @param state - Current swarm state
|
|
296
|
+
* @returns Collapse risk analysis
|
|
297
|
+
*/
|
|
298
|
+
analyzeSwarmState(state) {
|
|
299
|
+
const startTime = Date.now();
|
|
300
|
+
// Clear existing graph and build from state
|
|
301
|
+
this.clear();
|
|
302
|
+
// Add agents as nodes
|
|
303
|
+
for (const agent of state.agents) {
|
|
304
|
+
this.addNode(agent.agentId);
|
|
305
|
+
}
|
|
306
|
+
// Add edges based on agent relationships
|
|
307
|
+
// Agents with similar beliefs are connected
|
|
308
|
+
this.buildEdgesFromAgents(state.agents);
|
|
309
|
+
// Analyze the graph
|
|
310
|
+
const risk = this.predictCollapseRisk();
|
|
311
|
+
const fiedlerValue = this.computeFiedlerValue();
|
|
312
|
+
const weakVertices = this.getWeakVertices(5);
|
|
313
|
+
const durationMs = Date.now() - startTime;
|
|
314
|
+
const result = {
|
|
315
|
+
risk,
|
|
316
|
+
fiedlerValue,
|
|
317
|
+
collapseImminent: risk > 0.7,
|
|
318
|
+
weakVertices,
|
|
319
|
+
recommendations: this.generateRecommendations(risk, fiedlerValue, weakVertices),
|
|
320
|
+
durationMs,
|
|
321
|
+
usedFallback: false,
|
|
322
|
+
};
|
|
323
|
+
this.logger.info('Analyzed swarm state', {
|
|
324
|
+
agentCount: state.agents.length,
|
|
325
|
+
risk,
|
|
326
|
+
fiedlerValue,
|
|
327
|
+
durationMs,
|
|
328
|
+
});
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Build edges between agents based on belief similarity
|
|
333
|
+
*/
|
|
334
|
+
buildEdgesFromAgents(agents) {
|
|
335
|
+
for (let i = 0; i < agents.length; i++) {
|
|
336
|
+
for (let j = i + 1; j < agents.length; j++) {
|
|
337
|
+
const similarity = this.computeAgentSimilarity(agents[i], agents[j]);
|
|
338
|
+
if (similarity > 0.3) {
|
|
339
|
+
this.addEdge(agents[i].agentId, agents[j].agentId, similarity);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Compute similarity between two agents based on their states
|
|
346
|
+
*/
|
|
347
|
+
computeAgentSimilarity(agent1, agent2) {
|
|
348
|
+
// Factor in:
|
|
349
|
+
// 1. Health similarity
|
|
350
|
+
const healthSim = 1 - Math.abs(agent1.health - agent2.health);
|
|
351
|
+
// 2. Success rate similarity
|
|
352
|
+
const successSim = 1 - Math.abs(agent1.successRate - agent2.successRate);
|
|
353
|
+
// 3. Same agent type bonus
|
|
354
|
+
const typeBonus = agent1.agentType === agent2.agentType ? 0.2 : 0;
|
|
355
|
+
// 4. Belief overlap (if both have beliefs)
|
|
356
|
+
let beliefSim = 0;
|
|
357
|
+
if (agent1.beliefs.length > 0 && agent2.beliefs.length > 0) {
|
|
358
|
+
beliefSim = this.computeBeliefOverlap(agent1.beliefs, agent2.beliefs);
|
|
359
|
+
}
|
|
360
|
+
// Weighted combination
|
|
361
|
+
return (healthSim * 0.3 + successSim * 0.3 + typeBonus + beliefSim * 0.2);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Compute overlap between belief sets using embedding similarity
|
|
365
|
+
*/
|
|
366
|
+
computeBeliefOverlap(beliefs1, beliefs2) {
|
|
367
|
+
if (beliefs1.length === 0 || beliefs2.length === 0) {
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
let totalSimilarity = 0;
|
|
371
|
+
let comparisons = 0;
|
|
372
|
+
for (const b1 of beliefs1) {
|
|
373
|
+
for (const b2 of beliefs2) {
|
|
374
|
+
totalSimilarity += this.cosineSimilarity(b1.embedding, b2.embedding);
|
|
375
|
+
comparisons++;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return comparisons > 0 ? totalSimilarity / comparisons : 0;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Compute cosine similarity between two vectors
|
|
382
|
+
*/
|
|
383
|
+
cosineSimilarity(a, b) {
|
|
384
|
+
if (a.length !== b.length || a.length === 0) {
|
|
385
|
+
return 0;
|
|
386
|
+
}
|
|
387
|
+
let dotProduct = 0;
|
|
388
|
+
let normA = 0;
|
|
389
|
+
let normB = 0;
|
|
390
|
+
for (let i = 0; i < a.length; i++) {
|
|
391
|
+
dotProduct += a[i] * b[i];
|
|
392
|
+
normA += a[i] * a[i];
|
|
393
|
+
normB += b[i] * b[i];
|
|
394
|
+
}
|
|
395
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
396
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Generate recommendations based on collapse analysis
|
|
400
|
+
*/
|
|
401
|
+
generateRecommendations(risk, fiedlerValue, weakVertices) {
|
|
402
|
+
const recommendations = [];
|
|
403
|
+
if (risk > 0.7) {
|
|
404
|
+
recommendations.push('CRITICAL: Immediate action required to prevent swarm collapse.');
|
|
405
|
+
recommendations.push('Consider spawning additional coordination agents to strengthen connectivity.');
|
|
406
|
+
}
|
|
407
|
+
else if (risk > 0.5) {
|
|
408
|
+
recommendations.push('WARNING: Elevated collapse risk detected. Monitor closely.');
|
|
409
|
+
}
|
|
410
|
+
if (fiedlerValue < 0.1) {
|
|
411
|
+
recommendations.push('Network connectivity is weak. Consider adding redundant communication channels.');
|
|
412
|
+
}
|
|
413
|
+
if (fiedlerValue < 0.05) {
|
|
414
|
+
recommendations.push('ALERT: Near-zero Fiedler value indicates potential false consensus.');
|
|
415
|
+
recommendations.push('Recommend spawning an independent reviewer to verify decisions.');
|
|
416
|
+
}
|
|
417
|
+
if (weakVertices.length > 0) {
|
|
418
|
+
recommendations.push(`At-risk agents: ${weakVertices.join(', ')}. Consider reassigning critical tasks.`);
|
|
419
|
+
}
|
|
420
|
+
if (recommendations.length === 0) {
|
|
421
|
+
recommendations.push('Swarm health is good. No immediate action required.');
|
|
422
|
+
}
|
|
423
|
+
return recommendations;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Clear all nodes and edges from the graph
|
|
427
|
+
*/
|
|
428
|
+
clear() {
|
|
429
|
+
this.ensureInitialized();
|
|
430
|
+
this.nodes.clear();
|
|
431
|
+
this.edges.length = 0;
|
|
432
|
+
this.engine.clear();
|
|
433
|
+
this.logger.debug('Cleared spectral graph');
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Dispose of adapter resources
|
|
437
|
+
*/
|
|
438
|
+
dispose() {
|
|
439
|
+
if (this.engine) {
|
|
440
|
+
this.engine.clear();
|
|
441
|
+
this.engine = null;
|
|
442
|
+
}
|
|
443
|
+
this.nodes.clear();
|
|
444
|
+
this.edges.length = 0;
|
|
445
|
+
this.initialized = false;
|
|
446
|
+
this.logger.info('SpectralAdapter disposed');
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get the number of nodes in the graph
|
|
450
|
+
*/
|
|
451
|
+
getNodeCount() {
|
|
452
|
+
return this.nodes.size;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get the number of edges in the graph
|
|
456
|
+
*/
|
|
457
|
+
getEdgeCount() {
|
|
458
|
+
return this.edges.length;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
// ============================================================================
|
|
462
|
+
// Factory Function
|
|
463
|
+
// ============================================================================
|
|
464
|
+
/**
|
|
465
|
+
* Create and initialize a SpectralAdapter
|
|
466
|
+
*
|
|
467
|
+
* @param wasmLoader - WASM module loader
|
|
468
|
+
* @param logger - Optional logger
|
|
469
|
+
* @returns Initialized adapter
|
|
470
|
+
*/
|
|
471
|
+
export async function createSpectralAdapter(wasmLoader, logger) {
|
|
472
|
+
const adapter = new SpectralAdapter(wasmLoader, logger);
|
|
473
|
+
await adapter.initialize();
|
|
474
|
+
return adapter;
|
|
475
|
+
}
|
|
476
|
+
//# sourceMappingURL=spectral-adapter.js.map
|