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,696 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Belief Reconciler
|
|
3
|
+
* ADR-052: Strange Loop Belief Reconciliation Protocol
|
|
4
|
+
*
|
|
5
|
+
* Handles contradictory beliefs detected by the CoherenceService.
|
|
6
|
+
* When the sheaf Laplacian energy indicates high incoherence,
|
|
7
|
+
* this module identifies conflicting beliefs, determines the optimal
|
|
8
|
+
* resolution strategy, applies reconciliation, and creates audit records.
|
|
9
|
+
*
|
|
10
|
+
* The reconciliation process follows this pattern:
|
|
11
|
+
* ```
|
|
12
|
+
* Detect Contradiction
|
|
13
|
+
* |
|
|
14
|
+
* v
|
|
15
|
+
* Select Strategy -----> latest | authority | consensus | merge | escalate
|
|
16
|
+
* |
|
|
17
|
+
* v
|
|
18
|
+
* Apply Resolution
|
|
19
|
+
* |
|
|
20
|
+
* v
|
|
21
|
+
* Create Witness Record
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module strange-loop/belief-reconciler
|
|
25
|
+
*/
|
|
26
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
27
|
+
/**
|
|
28
|
+
* Default configuration for belief reconciler
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_BELIEF_RECONCILER_CONFIG = {
|
|
31
|
+
defaultStrategy: 'authority',
|
|
32
|
+
authorityThreshold: 0.7,
|
|
33
|
+
consensusThreshold: 0.6,
|
|
34
|
+
consensusTimeoutMs: 5000,
|
|
35
|
+
enableWitness: true,
|
|
36
|
+
maxHistorySize: 1000,
|
|
37
|
+
mergeSimilarityThreshold: 0.8,
|
|
38
|
+
autoEscalateOnFailure: true,
|
|
39
|
+
failuresBeforeEscalate: 3,
|
|
40
|
+
};
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Default Implementations
|
|
43
|
+
// ============================================================================
|
|
44
|
+
/**
|
|
45
|
+
* Default vote collector that returns empty votes (for testing)
|
|
46
|
+
*/
|
|
47
|
+
class NoOpVoteCollector {
|
|
48
|
+
async collectVotes() {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Default witness adapter that creates mock records (for testing)
|
|
54
|
+
*/
|
|
55
|
+
class NoOpWitnessAdapter {
|
|
56
|
+
async createWitness(data) {
|
|
57
|
+
const hash = `mock-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
58
|
+
return {
|
|
59
|
+
witnessId: uuidv4(),
|
|
60
|
+
decisionId: data?.id || uuidv4(),
|
|
61
|
+
hash,
|
|
62
|
+
chainPosition: 0,
|
|
63
|
+
timestamp: new Date(),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Belief Reconciler Implementation
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Reconciles contradictory beliefs in the swarm
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const reconciler = createBeliefReconciler({
|
|
76
|
+
* defaultStrategy: 'authority',
|
|
77
|
+
* authorityThreshold: 0.8
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* const result = await reconciler.reconcile(contradictions);
|
|
81
|
+
* if (result.success) {
|
|
82
|
+
* // Apply new beliefs
|
|
83
|
+
* for (const belief of result.newBeliefs) {
|
|
84
|
+
* await beliefStore.add(belief);
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export class BeliefReconciler {
|
|
90
|
+
config;
|
|
91
|
+
strategy;
|
|
92
|
+
history = [];
|
|
93
|
+
eventListeners = new Map();
|
|
94
|
+
voteCollector;
|
|
95
|
+
witnessAdapter;
|
|
96
|
+
consecutiveFailures = 0;
|
|
97
|
+
/** Belief store for looking up beliefs by ID */
|
|
98
|
+
beliefStore = new Map();
|
|
99
|
+
constructor(config = {}, options) {
|
|
100
|
+
this.config = { ...DEFAULT_BELIEF_RECONCILER_CONFIG, ...config };
|
|
101
|
+
this.strategy = this.config.defaultStrategy;
|
|
102
|
+
this.voteCollector = options?.voteCollector || new NoOpVoteCollector();
|
|
103
|
+
this.witnessAdapter = this.config.enableWitness
|
|
104
|
+
? options?.witnessAdapter || new NoOpWitnessAdapter()
|
|
105
|
+
: null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Register a belief for lookup during reconciliation
|
|
109
|
+
*/
|
|
110
|
+
registerBelief(belief) {
|
|
111
|
+
this.beliefStore.set(belief.id, belief);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Register multiple beliefs
|
|
115
|
+
*/
|
|
116
|
+
registerBeliefs(beliefs) {
|
|
117
|
+
for (const belief of beliefs) {
|
|
118
|
+
this.registerBelief(belief);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear all registered beliefs
|
|
123
|
+
*/
|
|
124
|
+
clearBeliefs() {
|
|
125
|
+
this.beliefStore.clear();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reconcile contradictions using the configured strategy
|
|
129
|
+
*/
|
|
130
|
+
async reconcile(contradictions) {
|
|
131
|
+
const startTime = Date.now();
|
|
132
|
+
// Emit start event
|
|
133
|
+
this.emit('belief_reconciliation_started', {
|
|
134
|
+
contradictionCount: contradictions.length,
|
|
135
|
+
strategy: this.strategy,
|
|
136
|
+
});
|
|
137
|
+
if (contradictions.length === 0) {
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
strategy: this.strategy,
|
|
141
|
+
resolvedContradictions: [],
|
|
142
|
+
unresolvedContradictions: [],
|
|
143
|
+
newBeliefs: [],
|
|
144
|
+
durationMs: Date.now() - startTime,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Check for auto-escalation
|
|
148
|
+
const effectiveStrategy = this.shouldAutoEscalate()
|
|
149
|
+
? 'escalate'
|
|
150
|
+
: this.strategy;
|
|
151
|
+
let result;
|
|
152
|
+
try {
|
|
153
|
+
switch (effectiveStrategy) {
|
|
154
|
+
case 'latest':
|
|
155
|
+
result = await this.reconcileByLatest(contradictions, startTime);
|
|
156
|
+
break;
|
|
157
|
+
case 'authority':
|
|
158
|
+
result = await this.reconcileByAuthority(contradictions, startTime);
|
|
159
|
+
break;
|
|
160
|
+
case 'consensus':
|
|
161
|
+
result = await this.reconcileByConsensus(contradictions, startTime);
|
|
162
|
+
break;
|
|
163
|
+
case 'merge':
|
|
164
|
+
result = await this.reconcileByMerge(contradictions, startTime);
|
|
165
|
+
break;
|
|
166
|
+
case 'escalate':
|
|
167
|
+
result = await this.reconcileByEscalation(contradictions, startTime);
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
// Fallback to authority if unknown strategy
|
|
171
|
+
result = await this.reconcileByAuthority(contradictions, startTime);
|
|
172
|
+
}
|
|
173
|
+
// Track failures for auto-escalation
|
|
174
|
+
if (!result.success) {
|
|
175
|
+
this.consecutiveFailures++;
|
|
176
|
+
this.emit('belief_reconciliation_failed', {
|
|
177
|
+
result,
|
|
178
|
+
failureCount: this.consecutiveFailures,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this.consecutiveFailures = 0;
|
|
183
|
+
this.emit('belief_reconciled', {
|
|
184
|
+
result,
|
|
185
|
+
resolvedCount: result.resolvedContradictions.length,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
// Create witness record if enabled
|
|
189
|
+
if (this.witnessAdapter && result.success) {
|
|
190
|
+
const witness = await this.witnessAdapter.createWitness({
|
|
191
|
+
id: uuidv4(),
|
|
192
|
+
type: 'reconciliation',
|
|
193
|
+
strategy: effectiveStrategy,
|
|
194
|
+
contradictions,
|
|
195
|
+
result,
|
|
196
|
+
timestamp: Date.now(),
|
|
197
|
+
});
|
|
198
|
+
result.witnessId = witness.witnessId;
|
|
199
|
+
}
|
|
200
|
+
// Record in history
|
|
201
|
+
this.addToHistory(contradictions, result);
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
this.consecutiveFailures++;
|
|
206
|
+
const errorResult = {
|
|
207
|
+
success: false,
|
|
208
|
+
strategy: effectiveStrategy,
|
|
209
|
+
resolvedContradictions: [],
|
|
210
|
+
unresolvedContradictions: contradictions,
|
|
211
|
+
newBeliefs: [],
|
|
212
|
+
durationMs: Date.now() - startTime,
|
|
213
|
+
};
|
|
214
|
+
this.emit('belief_reconciliation_failed', {
|
|
215
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
216
|
+
failureCount: this.consecutiveFailures,
|
|
217
|
+
});
|
|
218
|
+
this.addToHistory(contradictions, errorResult);
|
|
219
|
+
return errorResult;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the current reconciliation strategy
|
|
224
|
+
*/
|
|
225
|
+
getStrategy() {
|
|
226
|
+
return this.strategy;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Set the reconciliation strategy
|
|
230
|
+
*/
|
|
231
|
+
setStrategy(strategy) {
|
|
232
|
+
const oldStrategy = this.strategy;
|
|
233
|
+
this.strategy = strategy;
|
|
234
|
+
this.consecutiveFailures = 0; // Reset failure count on strategy change
|
|
235
|
+
this.emit('strategy_changed', {
|
|
236
|
+
oldStrategy,
|
|
237
|
+
newStrategy: strategy,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get reconciliation history
|
|
242
|
+
*/
|
|
243
|
+
getHistory() {
|
|
244
|
+
return [...this.history];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Clear reconciliation history
|
|
248
|
+
*/
|
|
249
|
+
clearHistory() {
|
|
250
|
+
this.history = [];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get reconciliation statistics
|
|
254
|
+
*/
|
|
255
|
+
getStats() {
|
|
256
|
+
const stats = {
|
|
257
|
+
totalReconciliations: this.history.length,
|
|
258
|
+
successfulReconciliations: 0,
|
|
259
|
+
failedReconciliations: 0,
|
|
260
|
+
totalContradictionsResolved: 0,
|
|
261
|
+
avgDurationMs: 0,
|
|
262
|
+
strategyDistribution: {
|
|
263
|
+
latest: 0,
|
|
264
|
+
authority: 0,
|
|
265
|
+
consensus: 0,
|
|
266
|
+
merge: 0,
|
|
267
|
+
escalate: 0,
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
let totalDuration = 0;
|
|
271
|
+
for (const record of this.history) {
|
|
272
|
+
if (record.result.success) {
|
|
273
|
+
stats.successfulReconciliations++;
|
|
274
|
+
stats.totalContradictionsResolved +=
|
|
275
|
+
record.result.resolvedContradictions.length;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
stats.failedReconciliations++;
|
|
279
|
+
}
|
|
280
|
+
totalDuration += record.result.durationMs;
|
|
281
|
+
stats.strategyDistribution[record.result.strategy]++;
|
|
282
|
+
}
|
|
283
|
+
if (this.history.length > 0) {
|
|
284
|
+
stats.avgDurationMs = totalDuration / this.history.length;
|
|
285
|
+
}
|
|
286
|
+
return stats;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Add event listener
|
|
290
|
+
*/
|
|
291
|
+
on(event, listener) {
|
|
292
|
+
if (!this.eventListeners.has(event)) {
|
|
293
|
+
this.eventListeners.set(event, new Set());
|
|
294
|
+
}
|
|
295
|
+
this.eventListeners.get(event).add(listener);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Remove event listener
|
|
299
|
+
*/
|
|
300
|
+
off(event, listener) {
|
|
301
|
+
this.eventListeners.get(event)?.delete(listener);
|
|
302
|
+
}
|
|
303
|
+
// ============================================================================
|
|
304
|
+
// Strategy Implementations
|
|
305
|
+
// ============================================================================
|
|
306
|
+
/**
|
|
307
|
+
* Reconcile by preferring the most recent belief
|
|
308
|
+
*/
|
|
309
|
+
async reconcileByLatest(contradictions, startTime) {
|
|
310
|
+
const resolved = [];
|
|
311
|
+
const unresolved = [];
|
|
312
|
+
const newBeliefs = [];
|
|
313
|
+
for (const contradiction of contradictions) {
|
|
314
|
+
const [belief1, belief2] = this.getConflictingBeliefs(contradiction);
|
|
315
|
+
if (!belief1 || !belief2) {
|
|
316
|
+
unresolved.push(contradiction);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
// Compare timestamps - prefer the newer belief
|
|
320
|
+
const newer = belief1.timestamp > belief2.timestamp ? belief1 : belief2;
|
|
321
|
+
const older = belief1.timestamp > belief2.timestamp ? belief2 : belief1;
|
|
322
|
+
// Create a new belief that supersedes both
|
|
323
|
+
const reconciledBelief = this.createReconciledBelief(newer, older, 'latest');
|
|
324
|
+
newBeliefs.push(reconciledBelief);
|
|
325
|
+
resolved.push(contradiction);
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
success: resolved.length > 0,
|
|
329
|
+
strategy: 'latest',
|
|
330
|
+
resolvedContradictions: resolved,
|
|
331
|
+
unresolvedContradictions: unresolved,
|
|
332
|
+
newBeliefs,
|
|
333
|
+
durationMs: Date.now() - startTime,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Reconcile by preferring higher-confidence beliefs
|
|
338
|
+
*/
|
|
339
|
+
async reconcileByAuthority(contradictions, startTime) {
|
|
340
|
+
const resolved = [];
|
|
341
|
+
const unresolved = [];
|
|
342
|
+
const newBeliefs = [];
|
|
343
|
+
for (const contradiction of contradictions) {
|
|
344
|
+
const [belief1, belief2] = this.getConflictingBeliefs(contradiction);
|
|
345
|
+
if (!belief1 || !belief2) {
|
|
346
|
+
unresolved.push(contradiction);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
// Check if either belief meets the authority threshold
|
|
350
|
+
const maxConfidence = Math.max(belief1.confidence, belief2.confidence);
|
|
351
|
+
if (maxConfidence < this.config.authorityThreshold) {
|
|
352
|
+
// Neither belief is authoritative enough - cannot resolve
|
|
353
|
+
unresolved.push(contradiction);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
// Prefer the higher confidence belief
|
|
357
|
+
const authoritative = belief1.confidence >= belief2.confidence ? belief1 : belief2;
|
|
358
|
+
const subordinate = belief1.confidence >= belief2.confidence ? belief2 : belief1;
|
|
359
|
+
const reconciledBelief = this.createReconciledBelief(authoritative, subordinate, 'authority');
|
|
360
|
+
newBeliefs.push(reconciledBelief);
|
|
361
|
+
resolved.push(contradiction);
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
success: resolved.length > 0,
|
|
365
|
+
strategy: 'authority',
|
|
366
|
+
resolvedContradictions: resolved,
|
|
367
|
+
unresolvedContradictions: unresolved,
|
|
368
|
+
newBeliefs,
|
|
369
|
+
durationMs: Date.now() - startTime,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Reconcile by collecting votes from agents
|
|
374
|
+
*/
|
|
375
|
+
async reconcileByConsensus(contradictions, startTime) {
|
|
376
|
+
const resolved = [];
|
|
377
|
+
const unresolved = [];
|
|
378
|
+
const newBeliefs = [];
|
|
379
|
+
for (const contradiction of contradictions) {
|
|
380
|
+
const [belief1, belief2] = this.getConflictingBeliefs(contradiction);
|
|
381
|
+
if (!belief1 || !belief2) {
|
|
382
|
+
unresolved.push(contradiction);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
// Collect votes from agents
|
|
386
|
+
const votes = await this.voteCollector.collectVotes([belief1, belief2], this.config.consensusTimeoutMs);
|
|
387
|
+
if (votes.length === 0) {
|
|
388
|
+
// No votes received - cannot reach consensus
|
|
389
|
+
unresolved.push(contradiction);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
// Tally votes (weighted by confidence)
|
|
393
|
+
const voteTally = new Map();
|
|
394
|
+
let totalWeight = 0;
|
|
395
|
+
for (const vote of votes) {
|
|
396
|
+
const currentWeight = voteTally.get(vote.beliefId) || 0;
|
|
397
|
+
voteTally.set(vote.beliefId, currentWeight + vote.confidence);
|
|
398
|
+
totalWeight += vote.confidence;
|
|
399
|
+
}
|
|
400
|
+
// Check if consensus threshold is met
|
|
401
|
+
const winningBeliefId = Array.from(voteTally.entries()).reduce((max, [id, weight]) => (weight > max.weight ? { id, weight } : max), { id: '', weight: 0 });
|
|
402
|
+
const consensusPercentage = winningBeliefId.weight / totalWeight;
|
|
403
|
+
if (consensusPercentage < this.config.consensusThreshold) {
|
|
404
|
+
// Consensus threshold not met
|
|
405
|
+
unresolved.push(contradiction);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
// Consensus reached
|
|
409
|
+
const winningBelief = winningBeliefId.id === belief1.id ? belief1 : belief2;
|
|
410
|
+
const losingBelief = winningBeliefId.id === belief1.id ? belief2 : belief1;
|
|
411
|
+
const reconciledBelief = this.createReconciledBelief(winningBelief, losingBelief, 'consensus', { consensusPercentage, voteCount: votes.length });
|
|
412
|
+
newBeliefs.push(reconciledBelief);
|
|
413
|
+
resolved.push(contradiction);
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
success: resolved.length > 0,
|
|
417
|
+
strategy: 'consensus',
|
|
418
|
+
resolvedContradictions: resolved,
|
|
419
|
+
unresolvedContradictions: unresolved,
|
|
420
|
+
newBeliefs,
|
|
421
|
+
durationMs: Date.now() - startTime,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Reconcile by attempting to merge compatible beliefs
|
|
426
|
+
*
|
|
427
|
+
* Uses category theory principles to find a compatible merge:
|
|
428
|
+
* - If beliefs are about different aspects of the same entity, merge them
|
|
429
|
+
* - If beliefs can be generalized to a higher-level belief, do so
|
|
430
|
+
* - If beliefs represent partial views, combine them
|
|
431
|
+
*/
|
|
432
|
+
async reconcileByMerge(contradictions, startTime) {
|
|
433
|
+
const resolved = [];
|
|
434
|
+
const unresolved = [];
|
|
435
|
+
const newBeliefs = [];
|
|
436
|
+
for (const contradiction of contradictions) {
|
|
437
|
+
const [belief1, belief2] = this.getConflictingBeliefs(contradiction);
|
|
438
|
+
if (!belief1 || !belief2) {
|
|
439
|
+
unresolved.push(contradiction);
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
// Check if beliefs are mergeable (similar enough in embedding space)
|
|
443
|
+
const similarity = this.computeEmbeddingSimilarity(belief1.embedding, belief2.embedding);
|
|
444
|
+
if (similarity < this.config.mergeSimilarityThreshold) {
|
|
445
|
+
// Beliefs are too different to merge
|
|
446
|
+
unresolved.push(contradiction);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
// Attempt to merge the beliefs
|
|
450
|
+
const mergedBelief = this.mergeBeliefsCategorial(belief1, belief2);
|
|
451
|
+
if (!mergedBelief) {
|
|
452
|
+
unresolved.push(contradiction);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
newBeliefs.push(mergedBelief);
|
|
456
|
+
resolved.push(contradiction);
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
success: resolved.length > 0,
|
|
460
|
+
strategy: 'merge',
|
|
461
|
+
resolvedContradictions: resolved,
|
|
462
|
+
unresolvedContradictions: unresolved,
|
|
463
|
+
newBeliefs,
|
|
464
|
+
durationMs: Date.now() - startTime,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Escalate contradictions to the Queen coordinator
|
|
469
|
+
*/
|
|
470
|
+
async reconcileByEscalation(contradictions, startTime) {
|
|
471
|
+
// Emit escalation event for Queen to handle
|
|
472
|
+
this.emit('escalation_requested', {
|
|
473
|
+
contradictions,
|
|
474
|
+
reason: this.consecutiveFailures >= this.config.failuresBeforeEscalate
|
|
475
|
+
? 'repeated_failures'
|
|
476
|
+
: 'explicit_escalation',
|
|
477
|
+
timestamp: Date.now(),
|
|
478
|
+
});
|
|
479
|
+
// Escalation is always "successful" in that we've deferred the decision
|
|
480
|
+
// The contradictions are marked as unresolved until Queen responds
|
|
481
|
+
return {
|
|
482
|
+
success: true,
|
|
483
|
+
strategy: 'escalate',
|
|
484
|
+
resolvedContradictions: [],
|
|
485
|
+
unresolvedContradictions: contradictions,
|
|
486
|
+
newBeliefs: [],
|
|
487
|
+
durationMs: Date.now() - startTime,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
// ============================================================================
|
|
491
|
+
// Helper Methods
|
|
492
|
+
// ============================================================================
|
|
493
|
+
/**
|
|
494
|
+
* Get the beliefs involved in a contradiction
|
|
495
|
+
*/
|
|
496
|
+
getConflictingBeliefs(contradiction) {
|
|
497
|
+
const [id1, id2] = contradiction.nodeIds;
|
|
498
|
+
return [
|
|
499
|
+
this.beliefStore.get(id1) || null,
|
|
500
|
+
this.beliefStore.get(id2) || null,
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Create a new belief from reconciliation
|
|
505
|
+
*/
|
|
506
|
+
createReconciledBelief(primary, secondary, strategy, metadata) {
|
|
507
|
+
return {
|
|
508
|
+
id: uuidv4(),
|
|
509
|
+
statement: primary.statement,
|
|
510
|
+
embedding: primary.embedding,
|
|
511
|
+
confidence: this.computeReconciledConfidence(primary, secondary, strategy),
|
|
512
|
+
source: `reconciled:${strategy}`,
|
|
513
|
+
timestamp: new Date(),
|
|
514
|
+
evidence: [
|
|
515
|
+
...(primary.evidence || []),
|
|
516
|
+
`Reconciled from ${primary.id} (${strategy})`,
|
|
517
|
+
`Supersedes: ${secondary.id}`,
|
|
518
|
+
...(metadata ? [JSON.stringify(metadata)] : []),
|
|
519
|
+
],
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Compute confidence for a reconciled belief
|
|
524
|
+
*/
|
|
525
|
+
computeReconciledConfidence(primary, secondary, strategy) {
|
|
526
|
+
switch (strategy) {
|
|
527
|
+
case 'latest':
|
|
528
|
+
// Newer belief gets a small boost if recent
|
|
529
|
+
return Math.min(primary.confidence * 1.05, 1.0);
|
|
530
|
+
case 'authority':
|
|
531
|
+
// Authoritative belief keeps its confidence
|
|
532
|
+
return primary.confidence;
|
|
533
|
+
case 'consensus':
|
|
534
|
+
// Consensus-backed belief gets a boost
|
|
535
|
+
return Math.min(primary.confidence * 1.1, 1.0);
|
|
536
|
+
case 'merge':
|
|
537
|
+
// Merged belief gets the average confidence
|
|
538
|
+
return (primary.confidence + secondary.confidence) / 2;
|
|
539
|
+
case 'escalate':
|
|
540
|
+
// Escalated beliefs get reduced confidence until resolved
|
|
541
|
+
return primary.confidence * 0.8;
|
|
542
|
+
default:
|
|
543
|
+
return primary.confidence;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Compute cosine similarity between two embeddings
|
|
548
|
+
*/
|
|
549
|
+
computeEmbeddingSimilarity(a, b) {
|
|
550
|
+
if (a.length !== b.length || a.length === 0) {
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
let dotProduct = 0;
|
|
554
|
+
let normA = 0;
|
|
555
|
+
let normB = 0;
|
|
556
|
+
for (let i = 0; i < a.length; i++) {
|
|
557
|
+
dotProduct += a[i] * b[i];
|
|
558
|
+
normA += a[i] * a[i];
|
|
559
|
+
normB += b[i] * b[i];
|
|
560
|
+
}
|
|
561
|
+
const magnitude = Math.sqrt(normA) * Math.sqrt(normB);
|
|
562
|
+
if (magnitude === 0) {
|
|
563
|
+
return 0;
|
|
564
|
+
}
|
|
565
|
+
return dotProduct / magnitude;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Merge two beliefs using category theory principles
|
|
569
|
+
*
|
|
570
|
+
* This implements a simplified pullback construction:
|
|
571
|
+
* - Find the common "generalization" of both beliefs
|
|
572
|
+
* - Create a new belief that captures both perspectives
|
|
573
|
+
*/
|
|
574
|
+
mergeBeliefsCategorial(belief1, belief2) {
|
|
575
|
+
// Compute the merged embedding (midpoint in embedding space)
|
|
576
|
+
const mergedEmbedding = belief1.embedding.map((v, i) => (v + belief2.embedding[i]) / 2);
|
|
577
|
+
// Normalize the merged embedding
|
|
578
|
+
const norm = Math.sqrt(mergedEmbedding.reduce((sum, v) => sum + v * v, 0));
|
|
579
|
+
const normalizedEmbedding = norm > 0 ? mergedEmbedding.map((v) => v / norm) : mergedEmbedding;
|
|
580
|
+
// Create a merged statement
|
|
581
|
+
const mergedStatement = this.mergeStatements(belief1.statement, belief2.statement);
|
|
582
|
+
// Combine evidence
|
|
583
|
+
const combinedEvidence = [
|
|
584
|
+
...(belief1.evidence || []),
|
|
585
|
+
...(belief2.evidence || []),
|
|
586
|
+
`Merged from: ${belief1.id} + ${belief2.id}`,
|
|
587
|
+
];
|
|
588
|
+
return {
|
|
589
|
+
id: uuidv4(),
|
|
590
|
+
statement: mergedStatement,
|
|
591
|
+
embedding: normalizedEmbedding,
|
|
592
|
+
confidence: (belief1.confidence + belief2.confidence) / 2,
|
|
593
|
+
source: `merged:${belief1.source}+${belief2.source}`,
|
|
594
|
+
timestamp: new Date(),
|
|
595
|
+
evidence: combinedEvidence,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Merge two statements into a combined statement
|
|
600
|
+
*/
|
|
601
|
+
mergeStatements(statement1, statement2) {
|
|
602
|
+
// Simple approach: combine both perspectives
|
|
603
|
+
if (statement1 === statement2) {
|
|
604
|
+
return statement1;
|
|
605
|
+
}
|
|
606
|
+
// Check if one is a subset of the other
|
|
607
|
+
if (statement1.includes(statement2)) {
|
|
608
|
+
return statement1;
|
|
609
|
+
}
|
|
610
|
+
if (statement2.includes(statement1)) {
|
|
611
|
+
return statement2;
|
|
612
|
+
}
|
|
613
|
+
// Combine with conjunction
|
|
614
|
+
return `${statement1} (merged with: ${statement2})`;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Check if auto-escalation should be triggered
|
|
618
|
+
*/
|
|
619
|
+
shouldAutoEscalate() {
|
|
620
|
+
return (this.config.autoEscalateOnFailure &&
|
|
621
|
+
this.consecutiveFailures >= this.config.failuresBeforeEscalate);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Add a reconciliation to history
|
|
625
|
+
*/
|
|
626
|
+
addToHistory(contradictions, result) {
|
|
627
|
+
const record = {
|
|
628
|
+
id: uuidv4(),
|
|
629
|
+
contradictions,
|
|
630
|
+
result,
|
|
631
|
+
timestamp: Date.now(),
|
|
632
|
+
};
|
|
633
|
+
this.history.push(record);
|
|
634
|
+
// Trim history if needed
|
|
635
|
+
while (this.history.length > this.config.maxHistorySize) {
|
|
636
|
+
this.history.shift();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Emit an event to listeners
|
|
641
|
+
*/
|
|
642
|
+
emit(type, data) {
|
|
643
|
+
const event = {
|
|
644
|
+
type,
|
|
645
|
+
timestamp: Date.now(),
|
|
646
|
+
data,
|
|
647
|
+
};
|
|
648
|
+
const listeners = this.eventListeners.get(type);
|
|
649
|
+
if (listeners) {
|
|
650
|
+
const listenerArray = Array.from(listeners);
|
|
651
|
+
for (let i = 0; i < listenerArray.length; i++) {
|
|
652
|
+
try {
|
|
653
|
+
listenerArray[i](event);
|
|
654
|
+
}
|
|
655
|
+
catch {
|
|
656
|
+
// Ignore listener errors
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
// ============================================================================
|
|
663
|
+
// Factory Functions
|
|
664
|
+
// ============================================================================
|
|
665
|
+
/**
|
|
666
|
+
* Create a belief reconciler with optional configuration
|
|
667
|
+
*
|
|
668
|
+
* @param config - Partial configuration to override defaults
|
|
669
|
+
* @param options - Optional dependencies (vote collector, witness adapter)
|
|
670
|
+
* @returns Configured BeliefReconciler instance
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```typescript
|
|
674
|
+
* // Basic usage
|
|
675
|
+
* const reconciler = createBeliefReconciler();
|
|
676
|
+
*
|
|
677
|
+
* // With custom configuration
|
|
678
|
+
* const reconciler = createBeliefReconciler({
|
|
679
|
+
* defaultStrategy: 'consensus',
|
|
680
|
+
* consensusThreshold: 0.7
|
|
681
|
+
* });
|
|
682
|
+
*
|
|
683
|
+
* // With dependencies
|
|
684
|
+
* const reconciler = createBeliefReconciler(
|
|
685
|
+
* { enableWitness: true },
|
|
686
|
+
* {
|
|
687
|
+
* voteCollector: myVoteCollector,
|
|
688
|
+
* witnessAdapter: myWitnessAdapter
|
|
689
|
+
* }
|
|
690
|
+
* );
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
export function createBeliefReconciler(config, options) {
|
|
694
|
+
return new BeliefReconciler(config, options);
|
|
695
|
+
}
|
|
696
|
+
//# sourceMappingURL=belief-reconciler.js.map
|