23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
623 lines
19 KiB
Markdown
623 lines
19 KiB
Markdown
# Coherence Engine Integration Points
|
|
|
|
## Overview
|
|
|
|
This document describes how the Coherence Engine domain integrates with Claude Flow V3 modules, including the Memory, Security, Coordination, and Hive-Mind domains.
|
|
|
|
## Integration Architecture
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────────────────────────────┐
|
|
│ Claude Flow V3 │
|
|
├─────────────────────────────────────────────────────────────────────────────────┤
|
|
│ │
|
|
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌────────────┐ │
|
|
│ │ Memory Domain │ │ Security Domain │ │ Coordination │ │ Hive-Mind │ │
|
|
│ │ │ │ │ │ Domain │ │ Domain │ │
|
|
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ └─────┬──────┘ │
|
|
│ │ │ │ │ │
|
|
│ │ │ │ │ │
|
|
│ ┌────────▼────────────────────▼────────────────────▼──────────────────▼──────┐ │
|
|
│ │ Coherence Engine Plugin │ │
|
|
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
|
|
│ │ │ Coherence │ │ Input │ │ Consensus │ │ Swarm │ │ │
|
|
│ │ │ Gate │ │ Validator │ │ Verifier │ │ Analyzer │ │ │
|
|
│ │ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │ │
|
|
│ └───────────────────────────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
└─────────────────────────────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
## Memory Domain Integration
|
|
|
|
### Integration Type: Shared Kernel
|
|
|
|
The Coherence Engine shares a kernel with the Memory domain for pre-storage validation.
|
|
|
|
### Hook: pre-memory-store
|
|
|
|
**Purpose**: Validate memory entries for contradiction before storage.
|
|
|
|
**Trigger**: Called before any entry is stored in memory.
|
|
|
|
**Implementation**:
|
|
|
|
```typescript
|
|
// Hook registration
|
|
{
|
|
name: 'pr/pre-memory-store',
|
|
event: 'pre-memory-store',
|
|
priority: HookPriority.HIGH,
|
|
handler: async (context, payload) => {
|
|
const gate = context.get<CoherenceGate>('pr.coherenceGate');
|
|
const memoryService = context.get('memory');
|
|
|
|
// Get existing context from same namespace
|
|
const existingEntries = await memoryService.search({
|
|
namespace: payload.namespace,
|
|
limit: 10,
|
|
embedding: payload.embedding
|
|
});
|
|
|
|
const validation = await gate.validate(payload, existingEntries);
|
|
|
|
if (validation.action === 'reject') {
|
|
throw new CoherenceViolationError(
|
|
validation.coherenceResult.energy,
|
|
validation.coherenceResult.violations
|
|
);
|
|
}
|
|
|
|
// Add coherence metadata
|
|
if (validation.action === 'warn') {
|
|
payload.metadata = {
|
|
...payload.metadata,
|
|
coherenceWarning: true,
|
|
coherenceEnergy: validation.coherenceResult.energy
|
|
};
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
}
|
|
```
|
|
|
|
### Extended Service: CoherentMemoryService
|
|
|
|
**Purpose**: Provides memory operations with built-in coherence validation.
|
|
|
|
**Methods**:
|
|
|
|
| Method | Description | Coherence Integration |
|
|
|--------|-------------|----------------------|
|
|
| `storeWithCoherence()` | Store with validation | Pre-store coherence check |
|
|
| `searchCoherent()` | Search with filtering | Post-search coherence filter |
|
|
| `validateNamespace()` | Validate namespace | Batch coherence analysis |
|
|
|
|
**Usage Example**:
|
|
|
|
```typescript
|
|
// Initialize coherent memory service
|
|
const coherentMemory = new CoherentMemoryService(memoryService, coherenceGate);
|
|
|
|
// Store with coherence validation
|
|
const result = await coherentMemory.storeWithCoherence({
|
|
namespace: 'agents/decisions',
|
|
key: 'decision-123',
|
|
content: 'Agent decided to proceed with option A',
|
|
embedding: embeddingVector
|
|
});
|
|
|
|
if (!result.stored) {
|
|
console.warn(`Entry rejected: energy=${result.coherenceResult.energy}`);
|
|
}
|
|
|
|
// Search with coherence filtering
|
|
const coherentResults = await coherentMemory.searchCoherent(
|
|
queryEmbedding,
|
|
10,
|
|
{ namespace: 'agents/decisions', minCoherence: 0.8 }
|
|
);
|
|
```
|
|
|
|
### Memory Namespaces Used
|
|
|
|
| Namespace | Purpose |
|
|
|-----------|---------|
|
|
| `pr/coherence-checks` | Stores coherence check history |
|
|
| `pr/stability-metrics` | Stores stability analysis results |
|
|
| `pr/thresholds` | Stores configured thresholds |
|
|
|
|
## Security Domain Integration
|
|
|
|
### Integration Type: Conformist
|
|
|
|
The Coherence Engine conforms to the Security domain's patterns for input validation.
|
|
|
|
### Hook: pre-rag-retrieval
|
|
|
|
**Purpose**: Prevent hallucinations by validating retrieved context coherence.
|
|
|
|
**Trigger**: Called before RAG retrieval results are used.
|
|
|
|
**Implementation**:
|
|
|
|
```typescript
|
|
{
|
|
name: 'pr/pre-rag-retrieval',
|
|
event: 'pre-rag-retrieval',
|
|
priority: HookPriority.HIGH,
|
|
handler: async (context, payload) => {
|
|
const bridge = context.get<PrimeRadiantBridge>('pr.bridge');
|
|
|
|
const vectors = payload.retrievedDocs.map(d => new Float32Array(d.embedding));
|
|
|
|
if (vectors.length < 2) return payload;
|
|
|
|
const coherence = await bridge.checkCoherence(vectors);
|
|
|
|
if (coherence.energy > 0.5) {
|
|
// Filter contradictory documents
|
|
console.warn(`RAG coherence warning: ${coherence.violations.join(', ')}`);
|
|
|
|
return {
|
|
...payload,
|
|
retrievedDocs: filterMostCoherent(payload.retrievedDocs, vectors),
|
|
coherenceFiltered: true,
|
|
originalCoherenceEnergy: coherence.energy
|
|
};
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
}
|
|
```
|
|
|
|
### AIDefence Integration
|
|
|
|
**Purpose**: Extend threat detection with coherence-based analysis.
|
|
|
|
**Integration Points**:
|
|
|
|
| AIDefence Feature | Coherence Enhancement |
|
|
|-------------------|----------------------|
|
|
| Input validation | Coherence-based content validation |
|
|
| Threat detection | Causal analysis of attack patterns |
|
|
| Pattern matching | Spectral analysis of threat signatures |
|
|
|
|
**Usage Example**:
|
|
|
|
```typescript
|
|
// Extend AIDefence with coherence checking
|
|
const enhancedScan = async (input: string, embedding: Float32Array) => {
|
|
// Standard AIDefence scan
|
|
const aidefenceResult = await aidefence.scan(input);
|
|
|
|
// Coherence enhancement
|
|
const coherenceResult = await coherenceGate.validate(
|
|
{ embedding },
|
|
await getRecentInputEmbeddings()
|
|
);
|
|
|
|
return {
|
|
...aidefenceResult,
|
|
coherenceScore: coherenceResult.coherenceResult.confidence,
|
|
coherenceWarnings: coherenceResult.coherenceResult.violations
|
|
};
|
|
};
|
|
```
|
|
|
|
## Coordination Domain Integration
|
|
|
|
### Integration Type: Shared Kernel
|
|
|
|
The Coherence Engine shares a kernel with Coordination for swarm stability analysis.
|
|
|
|
### Hook: post-swarm-task
|
|
|
|
**Purpose**: Analyze swarm stability after task completion.
|
|
|
|
**Trigger**: Called after a swarm task completes.
|
|
|
|
**Implementation**:
|
|
|
|
```typescript
|
|
{
|
|
name: 'pr/post-swarm-task',
|
|
event: 'post-task',
|
|
priority: HookPriority.NORMAL,
|
|
handler: async (context, payload) => {
|
|
if (!payload.isSwarmTask) return payload;
|
|
|
|
const bridge = context.get<PrimeRadiantBridge>('pr.bridge');
|
|
const coordination = context.get('coordination');
|
|
|
|
// Get agent communication patterns
|
|
const agentStates = await coordination.getAgentStates();
|
|
const adj = buildCommunicationMatrix(agentStates);
|
|
|
|
// Analyze spectral stability
|
|
const spectral = await bridge.analyzeSpectral(adj);
|
|
|
|
// Store metrics
|
|
await context.get('memory').store({
|
|
namespace: 'pr/stability-metrics',
|
|
key: `task-${payload.taskId}`,
|
|
content: JSON.stringify({
|
|
stable: spectral.stable,
|
|
spectralGap: spectral.spectralGap,
|
|
timestamp: Date.now()
|
|
})
|
|
});
|
|
|
|
return {
|
|
...payload,
|
|
stabilityMetrics: spectral
|
|
};
|
|
}
|
|
}
|
|
```
|
|
|
|
### Swarm Health Monitoring
|
|
|
|
**MCP Tool**: `pr/swarm-health`
|
|
|
|
**Purpose**: Continuous swarm health monitoring using spectral analysis.
|
|
|
|
**Metrics Provided**:
|
|
|
|
| Metric | Description | Healthy Range |
|
|
|--------|-------------|---------------|
|
|
| `spectralGap` | Gap between top eigenvalues | > 0.1 |
|
|
| `stabilityIndex` | Aggregate stability measure | > 0.5 |
|
|
| `clusteringCoefficient` | Agent clustering tendency | 0.3 - 0.7 |
|
|
| `connectivityScore` | Overall swarm connectivity | > 0.8 |
|
|
|
|
**Usage Example**:
|
|
|
|
```typescript
|
|
// Monitor swarm health
|
|
const health = await primeRadiantPlugin.tools.swarmHealth({
|
|
swarmId: 'main-swarm',
|
|
includeHistory: true
|
|
});
|
|
|
|
if (!health.stable) {
|
|
console.warn('Swarm instability detected:', health.recommendations);
|
|
}
|
|
```
|
|
|
|
## Hive-Mind Domain Integration
|
|
|
|
### Integration Type: Shared Kernel
|
|
|
|
The Coherence Engine shares a kernel with Hive-Mind for consensus verification.
|
|
|
|
### Hook: pre-consensus
|
|
|
|
**Purpose**: Mathematically validate consensus proposals before voting.
|
|
|
|
**Trigger**: Called before a consensus vote is accepted.
|
|
|
|
**Implementation**:
|
|
|
|
```typescript
|
|
{
|
|
name: 'pr/pre-consensus',
|
|
event: 'pre-consensus',
|
|
priority: HookPriority.HIGH,
|
|
handler: async (context, payload) => {
|
|
const bridge = context.get<PrimeRadiantBridge>('pr.bridge');
|
|
|
|
// Check proposal coherence against existing decisions
|
|
const vectors = [
|
|
new Float32Array(payload.proposalEmbedding),
|
|
...payload.existingDecisions.map(d => new Float32Array(d.embedding))
|
|
];
|
|
|
|
const coherence = await bridge.checkCoherence(vectors);
|
|
|
|
if (coherence.energy > 0.7) {
|
|
return {
|
|
...payload,
|
|
rejected: true,
|
|
rejectionReason: `Proposal contradicts existing decisions (energy: ${coherence.energy.toFixed(3)})`
|
|
};
|
|
}
|
|
|
|
return {
|
|
...payload,
|
|
coherenceEnergy: coherence.energy,
|
|
coherenceConfidence: coherence.confidence
|
|
};
|
|
}
|
|
}
|
|
```
|
|
|
|
### Extended Service: CoherentHiveMind
|
|
|
|
**Purpose**: Provides hive-mind operations with mathematical verification.
|
|
|
|
**Methods**:
|
|
|
|
| Method | Description | Coherence Integration |
|
|
|--------|-------------|----------------------|
|
|
| `verifyConsensus()` | Verify consensus mathematically | Coherence + spectral check |
|
|
| `analyzeSwarmHealth()` | Analyze swarm health | Spectral stability analysis |
|
|
| `proposeWithValidation()` | Propose with pre-validation | Pre-proposal coherence gate |
|
|
|
|
**Usage Example**:
|
|
|
|
```typescript
|
|
// Initialize coherent hive-mind
|
|
const coherentHive = new CoherentHiveMind(hiveMind, primeRadiantBridge);
|
|
|
|
// Verify consensus mathematically
|
|
const verification = await coherentHive.verifyConsensus('proposal-123');
|
|
|
|
if (!verification.verified) {
|
|
console.warn('Consensus not verified:', {
|
|
coherenceEnergy: verification.coherenceEnergy.getValue(),
|
|
spectralStability: verification.spectralStability,
|
|
agreementRatio: verification.agreementRatio
|
|
});
|
|
}
|
|
|
|
// Analyze swarm health
|
|
const health = await coherentHive.analyzeSwarmHealth();
|
|
if (!health.healthy) {
|
|
for (const rec of health.recommendations) {
|
|
console.warn('Health recommendation:', rec);
|
|
}
|
|
}
|
|
```
|
|
|
|
### Byzantine Fault Tolerance Enhancement
|
|
|
|
**Purpose**: Enhance BFT with mathematical coherence checking.
|
|
|
|
**Integration**:
|
|
|
|
```typescript
|
|
// BFT with coherence verification
|
|
async function bftWithCoherence<T>(
|
|
operation: () => Promise<T>,
|
|
replicaCount: number = 3
|
|
): Promise<T> {
|
|
const results: T[] = [];
|
|
const embeddings: Float32Array[] = [];
|
|
|
|
// Execute on replicas
|
|
for (let i = 0; i < replicaCount; i++) {
|
|
const result = await operation();
|
|
results.push(result);
|
|
embeddings.push(await embed(result));
|
|
}
|
|
|
|
// Check coherence of results
|
|
const coherence = await bridge.checkCoherence(embeddings);
|
|
|
|
if (coherence.energy > 0.5) {
|
|
throw new Error('BFT results are incoherent - potential Byzantine failure');
|
|
}
|
|
|
|
// Return majority result
|
|
return selectMajority(results);
|
|
}
|
|
```
|
|
|
|
## Embeddings Domain Integration
|
|
|
|
### Integration Type: Customer-Supplier
|
|
|
|
The Coherence Engine is a customer of the Embeddings domain.
|
|
|
|
### Embedding Generation
|
|
|
|
**Purpose**: Generate embeddings for coherence checking.
|
|
|
|
**Integration**:
|
|
|
|
```typescript
|
|
// Use embeddings service for coherence input
|
|
const embeddingsService = context.get<EmbeddingsService>('embeddings');
|
|
|
|
async function prepareForCoherence(content: string): Promise<Float32Array> {
|
|
const embedding = await embeddingsService.generate(content);
|
|
return new Float32Array(embedding);
|
|
}
|
|
|
|
// Batch embedding for multiple entries
|
|
async function prepareMultiple(contents: string[]): Promise<Float32Array[]> {
|
|
const embeddings = await embeddingsService.batchGenerate(contents);
|
|
return embeddings.map(e => new Float32Array(e));
|
|
}
|
|
```
|
|
|
|
### Hyperbolic Embedding Support
|
|
|
|
**Purpose**: Enhanced coherence checking with hyperbolic embeddings.
|
|
|
|
**Integration**:
|
|
|
|
```typescript
|
|
// Use hyperbolic embeddings for hierarchical coherence
|
|
const hyperbolicEmbedding = await embeddingsService.generate(content, {
|
|
hyperbolic: true,
|
|
curvature: -1
|
|
});
|
|
|
|
// Coherence in Poincare ball
|
|
const coherence = await bridge.checkCoherenceHyperbolic(
|
|
hyperbolicEmbeddings,
|
|
{ curvature: -1 }
|
|
);
|
|
```
|
|
|
|
## MCP Tool Registration
|
|
|
|
### Tools Provided
|
|
|
|
| Tool Name | Category | Description |
|
|
|-----------|----------|-------------|
|
|
| `pr/coherence-check` | Coherence | Check vector coherence |
|
|
| `pr/spectral-analyze` | Spectral | Analyze spectral stability |
|
|
| `pr/causal-infer` | Causal | Do-calculus inference |
|
|
| `pr/consensus-verify` | Consensus | Verify multi-agent consensus |
|
|
| `pr/quantum-topology` | Topology | Compute topological features |
|
|
| `pr/memory-gate` | Memory | Pre-storage coherence gate |
|
|
|
|
### Tool Registration Example
|
|
|
|
```typescript
|
|
// Register tools with MCP server
|
|
mcpServer.registerTools([
|
|
{
|
|
name: 'pr_coherence_check',
|
|
description: 'Check coherence using Sheaf Laplacian',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
vectors: { type: 'array', items: { type: 'array', items: { type: 'number' } } },
|
|
threshold: { type: 'number', default: 0.3 }
|
|
},
|
|
required: ['vectors']
|
|
},
|
|
handler: coherenceCheckHandler
|
|
},
|
|
// ... other tools
|
|
]);
|
|
```
|
|
|
|
## Event Integration
|
|
|
|
### Domain Events Emitted
|
|
|
|
| Event | Trigger | Consumers |
|
|
|-------|---------|-----------|
|
|
| `CoherenceViolationDetected` | Entry fails coherence | Memory, Logging |
|
|
| `StabilityThresholdBreached` | Spectral gap too low | Coordination, Alerting |
|
|
| `ConsensusVerificationFailed` | Consensus not verified | Hive-Mind, Logging |
|
|
|
|
### Event Handling Example
|
|
|
|
```typescript
|
|
// Subscribe to coherence events
|
|
eventBus.subscribe('CoherenceViolationDetected', async (event) => {
|
|
// Log violation
|
|
await logger.warn('Coherence violation', {
|
|
energy: event.energy,
|
|
violations: event.violations,
|
|
namespace: event.namespace
|
|
});
|
|
|
|
// Update metrics
|
|
await metrics.increment('coherence.violations', {
|
|
namespace: event.namespace,
|
|
action: event.action
|
|
});
|
|
});
|
|
|
|
// Subscribe to stability events
|
|
eventBus.subscribe('StabilityThresholdBreached', async (event) => {
|
|
// Alert on critical instability
|
|
if (event.spectralGap < 0.05) {
|
|
await alerting.critical('Swarm stability critical', {
|
|
sourceType: event.sourceType,
|
|
sourceId: event.sourceId,
|
|
recommendations: event.recommendations
|
|
});
|
|
}
|
|
});
|
|
```
|
|
|
|
## Performance Considerations
|
|
|
|
### Caching Strategy
|
|
|
|
```typescript
|
|
// LRU cache for coherence results
|
|
const coherenceCache = new LRUCache<string, CoherenceResult>({
|
|
max: 1000,
|
|
ttl: 60000 // 1 minute TTL
|
|
});
|
|
|
|
// Cache key generation
|
|
function getCacheKey(vectors: Float32Array[]): string {
|
|
const hash = crypto.createHash('sha256');
|
|
for (const v of vectors) {
|
|
hash.update(Buffer.from(v.buffer));
|
|
}
|
|
return hash.digest('hex');
|
|
}
|
|
```
|
|
|
|
### Batch Processing
|
|
|
|
```typescript
|
|
// Batch coherence validation for efficiency
|
|
async function batchValidate(
|
|
entries: MemoryEntry[],
|
|
batchSize: number = 10
|
|
): Promise<CoherenceValidation[]> {
|
|
const results: CoherenceValidation[] = [];
|
|
|
|
for (let i = 0; i < entries.length; i += batchSize) {
|
|
const batch = entries.slice(i, i + batchSize);
|
|
const batchResults = await Promise.all(
|
|
batch.map(e => coherenceGate.validate(e))
|
|
);
|
|
results.push(...batchResults);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
```
|
|
|
|
### Async Processing
|
|
|
|
```typescript
|
|
// Non-blocking stability analysis
|
|
async function analyzeStabilityAsync(swarmId: string): Promise<void> {
|
|
// Queue analysis for background processing
|
|
await queue.add('stability-analysis', {
|
|
swarmId,
|
|
priority: 'normal'
|
|
});
|
|
}
|
|
|
|
// Background worker
|
|
queue.process('stability-analysis', async (job) => {
|
|
const { swarmId } = job.data;
|
|
const analysis = await stabilityAnalyzer.analyze(swarmId);
|
|
|
|
// Store results
|
|
await memory.store({
|
|
namespace: 'pr/stability-metrics',
|
|
key: `swarm-${swarmId}-${Date.now()}`,
|
|
content: JSON.stringify(analysis)
|
|
});
|
|
|
|
// Emit event if unhealthy
|
|
if (!analysis.isHealthy()) {
|
|
eventBus.emit('StabilityThresholdBreached', {
|
|
type: 'StabilityThresholdBreached',
|
|
timestamp: new Date(),
|
|
analysisId: analysis.id,
|
|
sourceType: 'swarm',
|
|
sourceId: swarmId,
|
|
spectralGap: analysis.spectralGap.getValue(),
|
|
recommendations: analysis.recommendations
|
|
});
|
|
}
|
|
});
|
|
```
|
|
|
|
## Related Documentation
|
|
|
|
- [README](./README.md) - Domain overview
|
|
- [Domain Model](./domain-model.md) - Entities and aggregates
|
|
- [ADR-031: Prime Radiant Integration](../../implementation/adrs/ADR-031-prime-radiant-integration.md)
|
|
- [ADR-006: Unified Memory Service](../../implementation/adrs/ADR-006-UNIFIED-MEMORY.md)
|
|
- [ADR-022: AIDefence Integration](../../implementation/adrs/ADR-022-aidefence-integration.md)
|