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.
153 lines (152 loc) • 5.22 kB
JavaScript
/**
* Conflict Resolution Engine
* Detects and resolves coordination conflicts between agents
*/ import { Logger } from '../core/logger.js';
/**
* Conflict Resolution Engine: Detect and resolve coordination conflicts
*/ export class ConflictResolutionEngine {
logger;
activeConflicts;
resolutions;
constructor(){
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: 'ConflictResolutionEngine'
});
this.activeConflicts = new Map();
this.resolutions = new Map();
}
/**
* Detect resource conflict
*/ detectConflict(type, resourceId, agentIds, priorities) {
if (agentIds.length <= 1) {
return null; // No conflict with single agent
}
const conflictId = `${type}-${resourceId}-${Date.now()}`;
const conflict = {
conflictId,
type,
resourceId,
agentIds,
priorities,
timestamp: Date.now()
};
this.activeConflicts.set(conflictId, conflict);
this.logger.warn('Resource conflict detected', {
conflictId,
type,
resourceId,
agentCount: agentIds.length
});
return conflict;
}
/**
* Resolve conflict using specified strategy
*/ resolveConflict(conflict, strategy = 'priority-based') {
this.logger.info('Resolving conflict', {
conflictId: conflict.conflictId,
strategy
});
let resolution;
switch(strategy){
case 'priority-based':
resolution = this.resolvePriorityBased(conflict);
break;
case 'fifo':
resolution = this.resolveFIFO(conflict);
break;
case 'consensus':
resolution = this.resolveConsensus(conflict);
break;
case 'escalate':
resolution = this.resolveEscalate(conflict);
break;
default:
resolution = this.resolvePriorityBased(conflict);
}
this.resolutions.set(conflict.conflictId, resolution);
this.activeConflicts.delete(conflict.conflictId);
this.logger.info('Conflict resolved', {
conflictId: conflict.conflictId,
winner: resolution.winnerAgentId,
blocked: resolution.blockedAgentIds.length
});
return resolution;
}
/**
* Resolve using priority-based strategy (highest priority wins)
*/ resolvePriorityBased(conflict) {
const maxPriority = Math.max(...conflict.priorities);
const winnerIndex = conflict.priorities.indexOf(maxPriority);
const winnerAgentId = conflict.agentIds[winnerIndex];
const blockedAgentIds = conflict.agentIds.filter((_, i)=>i !== winnerIndex);
return {
conflictId: conflict.conflictId,
strategy: 'priority-based',
winnerAgentId,
blockedAgentIds,
reasoning: `Agent ${winnerAgentId} has highest priority (${maxPriority})`,
timestamp: Date.now()
};
}
/**
* Resolve using FIFO strategy (first agent wins)
*/ resolveFIFO(conflict) {
const winnerAgentId = conflict.agentIds[0];
const blockedAgentIds = conflict.agentIds.slice(1);
return {
conflictId: conflict.conflictId,
strategy: 'fifo',
winnerAgentId,
blockedAgentIds,
reasoning: `Agent ${winnerAgentId} requested resource first`,
timestamp: Date.now()
};
}
/**
* Resolve using consensus strategy (requires external consensus)
*/ resolveConsensus(conflict) {
// For now, fallback to priority-based
// In production, this would trigger a consensus vote
this.logger.warn('Consensus resolution not implemented, using priority-based');
return this.resolvePriorityBased(conflict);
}
/**
* Escalate conflict for manual resolution
*/ resolveEscalate(conflict) {
return {
conflictId: conflict.conflictId,
strategy: 'escalate',
winnerAgentId: '',
blockedAgentIds: conflict.agentIds,
reasoning: `Conflict escalated for manual resolution: ${conflict.type} on ${conflict.resourceId}`,
timestamp: Date.now()
};
}
/**
* Get all active conflicts
*/ getActiveConflicts() {
return Array.from(this.activeConflicts.values());
}
/**
* Get resolution history
*/ getResolutions() {
return Array.from(this.resolutions.values());
}
/**
* Clear resolved conflicts
*/ clearResolved() {
this.resolutions.clear();
this.logger.info('Cleared resolution history');
}
}
export default ConflictResolutionEngine;
//# sourceMappingURL=conflict-resolution-engine.js.map