import { SwarmAgent, ServiceOrder } from '@rigstate/shared'; export type AgentWeight = number; /** * THE HIERARCHY OF RIGSTATE * Defines the decision power of each agent in The Council. */ export const AGENT_WEIGHTS: Record = { 'FRANK': 100, // SUPREME COURT (Security/Architecture) - Veto Power 'SVEN': 95, // SENTINEL (Compliance/Audit) - Highly Authoritative 'SINDRE': 80, // VAULT KEEPER (Data Integrity) - High Authority on Data 'MAJA': 70, // SCRIBE (Documentation) - Advisory 'EITRI': 60, // BUILDER (Implementation) - Mutable, subservient to Architects 'NOVA': 50, 'SIGRID': 90 // CUSTODIAN (Global Registry) - High Authority on Curation }; export interface Conflict { id: string; proposal: ServiceOrder; objector: SwarmAgent; reason: string; severity: 'CRITICAL' | 'WARNING' | 'SUGGESTION'; alternativeProposal?: any; } export interface CouncilResolution { outcome: 'UPHELD' | 'OVERRULED' | 'COMPROMISE'; winner: SwarmAgent; action: 'BLOCK' | 'PROCEED' | 'MODIFY'; rationale: string; } /** * THE COUNCIL v2 * Resolves disputes between agents using Weighted Democracy. */ export class Council { /** * Judges a conflict based on Agent weights and Hierarchy. */ public resolve(conflict: Conflict): CouncilResolution { const proposer = conflict.proposal.targetAgent; // The agent doing the work (e.g. Eitri) const objector = conflict.objector; // The agent complaining (e.g. Sven) const proposerWeight = AGENT_WEIGHTS[proposer] || 50; const objectorWeight = AGENT_WEIGHTS[objector] || 50; console.log(`⚖️ COUNCIL IN SESSION: ${objector} (${objectorWeight}) objects to ${proposer} (${proposerWeight})`); // 1. ABSOLUTE VETO (Frank/Sven on Critical Issues) if ((objector === 'FRANK' || objector === 'SVEN') && conflict.severity === 'CRITICAL') { return { outcome: 'UPHELD', winner: objector, action: 'BLOCK', rationale: `Absolute Veto by ${objector} on CRITICAL violation: ${conflict.reason}` }; } // 2. SUGGESTION OVERRIDE (Pragmatism) // If it's just a suggestion, the Builder (Proposer) usually proceeds unless it's the Supreme Court (Frank). if (conflict.severity === 'SUGGESTION' && objector !== 'FRANK') { return { outcome: 'OVERRULED', winner: proposer, action: 'PROCEED', rationale: `Minor suggestion by ${objector} noted but overruled for velocity.` }; } // 3. WEIGHT COMPARISON if (objectorWeight > proposerWeight) { return { outcome: 'UPHELD', winner: objector, action: 'BLOCK', rationale: `${objector} outranks ${proposer}. Objection validated.` }; } // 4. TIE-BREAKER / LOWER AUTHORITY // If weights are equal or objector is lower, we generally favor the builder (Proposer) // unless it's a security suggestion. if (conflict.severity === 'SUGGESTION' && proposer === 'EITRI') { return { outcome: 'OVERRULED', winner: proposer, action: 'PROCEED', rationale: `${proposer} has implementation authority on non-critical suggestions.` }; } // Default: Proposer wins if they outrank objector return { outcome: 'OVERRULED', winner: proposer, action: 'PROCEED', rationale: `Objection overruled. ${proposer} retains authority.` }; } }