JSPM

@claude-flow/plugin-prime-radiant

0.1.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q66701F
  • License MIT

Mathematical AI interpretability plugin providing sheaf cohomology, spectral analysis, causal inference, and quantum topology for coherence validation, consensus verification, and hallucination prevention.

Package Exports

  • @claude-flow/plugin-prime-radiant
  • @claude-flow/plugin-prime-radiant/tools

Readme

Prime Radiant Plugin for Claude Flow V3

Mathematical AI interpretability plugin providing sheaf cohomology, spectral analysis, causal inference, and quantum topology for coherence validation, consensus verification, and hallucination prevention.

Overview

Prime Radiant integrates the prime-radiant-advanced-wasm package (92KB WASM, zero dependencies) to bring advanced mathematical AI interpretability capabilities to Claude Flow V3:

  • Coherence Checking: Detect contradictions using Sheaf Laplacian energy
  • Spectral Analysis: Analyze system stability via eigenvalue decomposition
  • Causal Inference: Do-calculus based causal reasoning
  • Consensus Verification: Mathematical validation of multi-agent agreement
  • Quantum Topology: Persistent homology and Betti numbers
  • Type Theory: Homotopy Type Theory proofs

Installation

# Install as a Claude Flow plugin
npx claude-flow@v3alpha plugins install prime-radiant

# Or add to your configuration
npx claude-flow@v3alpha config set plugins.prime-radiant.enabled true

Quick Start

Check Coherence

// Via MCP tool
const result = await mcp.call('pr_coherence_check', {
  vectors: [
    [0.1, 0.2, 0.3, ...],  // embedding 1
    [0.15, 0.22, 0.28, ...], // embedding 2
    [0.9, -0.1, 0.5, ...]  // potentially contradictory
  ],
  threshold: 0.3
});

// Result
{
  coherent: false,
  energy: 0.65,
  violations: ['Vector 3 contradicts vectors 1-2'],
  confidence: 0.35
}

Verify Consensus

// Check multi-agent consensus mathematically
const consensus = await mcp.call('pr_consensus_verify', {
  agentStates: [
    { agentId: 'agent-1', embedding: [...], vote: true },
    { agentId: 'agent-2', embedding: [...], vote: true },
    { agentId: 'agent-3', embedding: [...], vote: false }
  ],
  consensusThreshold: 0.8
});

// Result
{
  consensusAchieved: true,
  agreementRatio: 0.87,
  coherenceEnergy: 0.12,
  spectralStability: true
}

Analyze Spectral Stability

// Analyze swarm communication stability
const stability = await mcp.call('pr_spectral_analyze', {
  adjacencyMatrix: [
    [0, 1, 1, 0],
    [1, 0, 1, 1],
    [1, 1, 0, 1],
    [0, 1, 1, 0]
  ],
  analyzeType: 'stability'
});

// Result
{
  stable: true,
  spectralGap: 0.25,
  stabilityIndex: 0.78,
  eigenvalues: [2.73, 0.73, -0.73, -2.73]
}

Causal Inference

// Perform do-calculus causal inference
const causal = await mcp.call('pr_causal_infer', {
  treatment: 'agent_count',
  outcome: 'task_completion_time',
  graph: {
    nodes: ['agent_count', 'coordination_overhead', 'task_completion_time', 'task_complexity'],
    edges: [
      ['agent_count', 'task_completion_time'],
      ['agent_count', 'coordination_overhead'],
      ['coordination_overhead', 'task_completion_time'],
      ['task_complexity', 'agent_count'],
      ['task_complexity', 'task_completion_time']
    ]
  }
});

// Result
{
  causalEffect: -0.35,
  confounders: ['task_complexity'],
  interventionValid: true,
  backdoorPaths: [['agent_count', 'task_complexity', 'task_completion_time']]
}

6 Mathematical Engines

1. CohomologyEngine

Computes Sheaf Laplacian energy to measure contradiction/coherence.

Energy Interpretation:

  • 0.0-0.1: Fully coherent
  • 0.1-0.3: Minor inconsistencies (warning zone)
  • 0.3-0.7: Significant contradictions
  • 0.7-1.0: Major contradictions (rejection zone)

Use Cases:

  • Pre-storage memory validation
  • RAG hallucination prevention
  • Multi-source fact checking

2. SpectralEngine

Analyzes system stability using spectral graph theory.

Key Metrics:

  • Spectral Gap: Difference between first and second eigenvalues
  • Stability Index: Aggregate stability measure (0-1)
  • Clustering Coefficient: Agent clustering tendency

Use Cases:

  • Swarm health monitoring
  • Coordination stability analysis
  • Network topology assessment

3. CausalEngine

Implements do-calculus for causal inference.

Capabilities:

  • Estimate causal effects (not just correlations)
  • Identify confounding variables
  • Find backdoor paths for adjustment
  • Validate intervention strategies

Use Cases:

  • Agent decision analysis
  • Task optimization
  • Root cause identification

4. QuantumEngine

Computes quantum topology features via persistent homology.

Features:

  • Betti Numbers: b0 (components), b1 (loops), b2 (voids)
  • Persistence Diagrams: Birth-death pairs of features
  • Homology Classes: Equivalence classes of cycles

Use Cases:

  • Vector cluster analysis
  • Memory structure analysis
  • Agent relationship topology

5. CategoryEngine

Provides category theory operations.

Operations:

  • Morphism validation
  • Functor application
  • Natural transformation detection

Use Cases:

  • Schema transformations
  • Data structure mappings
  • Type-safe conversions

6. HottEngine

Implements Homotopy Type Theory verification.

Features:

  • Proof verification
  • Type inference
  • Term normalization

Use Cases:

  • Formal verification
  • Type-level proofs
  • Mathematical correctness

Integration with V3 Domains

Memory Domain

Hook: pr/pre-memory-store

Validates memory entries before storage:

// Automatic coherence checking on memory store
await memoryService.store({
  namespace: 'agents/decisions',
  key: 'decision-123',
  content: 'Proceed with option A',
  embedding: embeddingVector
});

// If incoherent with existing entries:
// - Energy > 0.7: Throws CoherenceViolationError
// - Energy 0.3-0.7: Stores with coherenceWarning metadata
// - Energy < 0.3: Stores normally

Hive-Mind Domain

Hook: pr/pre-consensus

Validates consensus proposals:

// Consensus proposals are mathematically validated
const proposal = await hiveMind.consensus({
  action: 'propose',
  type: 'agent-allocation',
  value: { task: 'optimization', agents: ['coder', 'tester'] }
});

// If proposal contradicts existing decisions:
// - Energy > 0.7: Proposal rejected with reason
// - Otherwise: Proposal includes coherence metrics

Coordination Domain

Hook: pr/post-swarm-task

Analyzes swarm stability after tasks:

// After swarm task completion, stability is analyzed
const taskResult = await swarm.executeTask({
  task: 'implement-feature',
  agents: ['coordinator', 'coder', 'tester']
});

// taskResult includes:
// - stabilityMetrics.stable: boolean
// - stabilityMetrics.spectralGap: number

Security Domain

Hook: pr/pre-rag-retrieval

Prevents hallucinations in RAG:

// Retrieved documents are checked for coherence
const context = await rag.retrieve('How to implement auth?');

// If retrieved docs are contradictory:
// - Energy > 0.5: Filters to most coherent subset
// - Adds coherenceFiltered and originalCoherenceEnergy metadata

Configuration

# claude-flow.config.yaml
plugins:
  prime-radiant:
    enabled: true
    config:
      coherence:
        warnThreshold: 0.3
        rejectThreshold: 0.7
        cacheEnabled: true
        cacheTTL: 60000
      spectral:
        stabilityThreshold: 0.1
        maxMatrixSize: 1000
      causal:
        maxBackdoorPaths: 10
        confidenceThreshold: 0.8

CLI Commands

# Check coherence of a file
npx claude-flow@v3alpha plugins run prime-radiant coherence-check --file data.json

# Analyze swarm stability
npx claude-flow@v3alpha plugins run prime-radiant spectral-analyze --swarm-id main

# Run causal inference
npx claude-flow@v3alpha plugins run prime-radiant causal-infer \
  --treatment "agent_count" \
  --outcome "completion_time" \
  --graph graph.json

# Get plugin status
npx claude-flow@v3alpha plugins status prime-radiant

Performance

Operation Latency Notes
WASM Load <50ms One-time at plugin init
Coherence Check <5ms Per validation
Spectral Analysis <20ms Up to 100x100 matrix
Causal Inference <10ms Per query
Quantum Topology <50ms Per computation
Memory Overhead <10MB Including WASM + engines

Use Cases

1. Memory Coherence Gate

Prevent contradictory information from entering memory:

// Configuration
await config.set('plugins.prime-radiant.config.coherence.rejectThreshold', 0.6);

// All memory stores now pass through coherence gate
await memory.store({
  namespace: 'facts',
  key: 'earth-shape',
  content: 'The Earth is round',
  embedding: await embed('The Earth is round')
});

// This would be rejected (contradicts above)
try {
  await memory.store({
    namespace: 'facts',
    key: 'earth-shape-2',
    content: 'The Earth is flat',
    embedding: await embed('The Earth is flat')
  });
} catch (e) {
  // CoherenceViolationError: energy=0.89
}

2. Consensus Verification

Mathematically verify multi-agent agreement:

// Get consensus with mathematical verification
const verified = await coherentHiveMind.verifyConsensus('proposal-123');

if (!verified.verified) {
  console.log('Consensus issues:', {
    coherenceEnergy: verified.coherenceEnergy,
    spectralStability: verified.spectralStability,
    agreementRatio: verified.agreementRatio
  });
}

3. Hallucination Detection

Catch RAG inconsistencies before they cause problems:

// Enable hallucination detection
hooks.enable('pr/pre-rag-retrieval');

// RAG retrieval now filters contradictory docs
const context = await rag.retrieve(query);

if (context.coherenceFiltered) {
  console.log(`Filtered contradictory docs. Original energy: ${context.originalCoherenceEnergy}`);
}

4. Swarm Stability Monitoring

Monitor swarm health in real-time:

// Get swarm health analysis
const health = await mcp.call('pr_spectral_analyze', {
  adjacencyMatrix: await getSwarmAdjacencyMatrix(),
  analyzeType: 'stability'
});

if (!health.stable) {
  console.warn('Swarm instability detected!', {
    spectralGap: health.spectralGap,
    stabilityIndex: health.stabilityIndex
  });
}

API Reference

MCP Tools

Tool Description
pr_coherence_check Check vector coherence
pr_spectral_analyze Analyze spectral stability
pr_causal_infer Do-calculus inference
pr_consensus_verify Verify consensus
pr_quantum_topology Compute topology features
pr_memory_gate Pre-storage coherence gate

Hooks

Hook Event Priority
pr/pre-memory-store pre-memory-store HIGH
pr/pre-consensus pre-consensus HIGH
pr/post-swarm-task post-task NORMAL
pr/pre-rag-retrieval pre-rag-retrieval HIGH

Events

Event Description
CoherenceViolationDetected Entry failed coherence check
StabilityThresholdBreached Spectral gap below threshold
ConsensusVerificationFailed Consensus not mathematically verified

References