UNPKG

claude-flow-novice

Version:

Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture Includes Local RuVector Accelerator and all CFN skills for complete functionality.

93 lines (92 loc) 2.93 kB
/** * Byzantine Consensus Adapter * Minimal implementation for CFN Loop consensus validation */ import { Logger } from '../core/logger.js'; /** * Adapter for Byzantine fault-tolerant consensus in CFN Loop */ export class ByzantineConsensusAdapter { memoryManager; logger; config; constructor(config = {}, memoryManager){ this.memoryManager = memoryManager; this.config = { consensusThreshold: config.consensusThreshold ?? 0.9, validatorCount: config.validatorCount ?? 4, faultTolerance: config.faultTolerance ?? 1 }; const loggerConfig = process.env.CLAUDE_FLOW_ENV === 'test' ? { level: 'error', format: 'json', destination: 'console' } : { level: 'info', format: 'json', destination: 'console' }; this.logger = new Logger(loggerConfig, { component: 'ByzantineConsensusAdapter' }); } /** * Execute Byzantine consensus validation */ async executeConsensus(votes) { this.logger.info('Executing Byzantine consensus', { totalVotes: votes.length, threshold: this.config.consensusThreshold }); // Count votes const approveVotes = votes.filter((v)=>v.vote === 'approve').length; const totalVotes = votes.length; // Calculate consensus score const consensusScore = totalVotes > 0 ? approveVotes / totalVotes : 0; // Determine consensus const consensusReached = consensusScore >= this.config.consensusThreshold; // Identify potentially faulty validators (low confidence) const faultyValidators = votes.filter((v)=>v.confidence < 0.5).map((v)=>v.validatorId); const result = { consensusReached, consensusScore, votes, faultyValidators, timestamp: Date.now() }; this.logger.info('Byzantine consensus complete', { consensusReached, consensusScore, approveVotes, totalVotes, faultyValidators: faultyValidators.length }); return result; } /** * Validate vote integrity */ validateVote(vote) { if (!vote.validatorId || !vote.vote) { return false; } if (![ 'approve', 'reject', 'abstain' ].includes(vote.vote)) { return false; } if (vote.confidence < 0 || vote.confidence > 1) { return false; } return true; } /** * Get consensus threshold */ getThreshold() { return this.config.consensusThreshold; } /** * Get validator count */ getValidatorCount() { return this.config.validatorCount; } } //# sourceMappingURL=byzantine-consensus-adapter.js.map