Implement BZZZ Phase 2A: Unified SLURP Architecture with Consensus Elections
🎯 Major architectural achievement: SLURP is now a specialized BZZZ agent with admin role ## Core Implementation: ### 1. Unified Architecture - SLURP becomes admin-role BZZZ agent with master authority - Single P2P network for all coordination (no separate systems) - Distributed admin role with consensus-based failover ### 2. Role-Based Authority System (pkg/config/roles.go) - Authority levels: master/decision/coordination/suggestion/read_only - Admin role includes SLURP functionality (context curation, decision ingestion) - Flexible role definitions via .ucxl/roles.yaml configuration - Authority methods: CanDecryptRole(), CanMakeDecisions(), IsAdminRole() ### 3. Election System with Consensus (pkg/election/election.go) - Election triggers: heartbeat timeout, discovery failure, split brain, quorum loss - Leadership scoring: uptime, capabilities, resources, network quality - Raft-based consensus algorithm for distributed coordination - Split brain detection prevents multiple admin conflicts ### 4. Age Encryption Integration - Role-based Age keypairs for content encryption - Hierarchical access: admin can decrypt all roles, others limited by authority - Shamir secret sharing foundation for admin key distribution (3/5 threshold) - UCXL content encrypted by creator's role level ### 5. Security & Configuration - Cluster security config with election timeouts and quorum requirements - Audit logging for security events and key reconstruction - Project-specific role definitions in .ucxl/roles.yaml - Role-specific prompt templates in .ucxl/templates/ ### 6. Main Application Integration (main.go) - Election manager integrated into BZZZ startup process - Admin callbacks for automatic SLURP enablement - Heartbeat system for admin leadership maintenance - Authority level display in startup information ## Benefits: ✅ High Availability: Any node can become admin via consensus ✅ Security: Age encryption + Shamir prevents single points of failure ✅ Flexibility: User-definable roles with granular authority ✅ Unified Architecture: Single P2P network for all coordination ✅ Automatic Failover: Elections triggered by multiple conditions ## Next Steps (Phase 2B): - Age encryption implementation for UCXL content - Shamir secret sharing key reconstruction algorithm - DHT integration for distributed encrypted storage - Decision publishing pipeline integration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
67
main.go
67
main.go
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/anthonyrawlins/bzzz/logging"
|
||||
"github.com/anthonyrawlins/bzzz/p2p"
|
||||
"github.com/anthonyrawlins/bzzz/pkg/config"
|
||||
"github.com/anthonyrawlins/bzzz/pkg/election"
|
||||
"github.com/anthonyrawlins/bzzz/pkg/hive"
|
||||
"github.com/anthonyrawlins/bzzz/pkg/ucxi"
|
||||
"github.com/anthonyrawlins/bzzz/pubsub"
|
||||
@@ -111,6 +112,18 @@ func main() {
|
||||
fmt.Printf("📍 Node ID: %s\n", node.ID().ShortString())
|
||||
fmt.Printf("🤖 Agent ID: %s\n", cfg.Agent.ID)
|
||||
fmt.Printf("🎯 Specialization: %s\n", cfg.Agent.Specialization)
|
||||
|
||||
// Display authority level if role is configured
|
||||
if cfg.Agent.Role != "" {
|
||||
authority, err := cfg.GetRoleAuthority(cfg.Agent.Role)
|
||||
if err == nil {
|
||||
fmt.Printf("🎭 Role: %s (Authority: %s)\n", cfg.Agent.Role, authority)
|
||||
if authority == config.AuthorityMaster {
|
||||
fmt.Printf("👑 This node can become admin/SLURP\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("🐝 Hive API: %s\n", cfg.HiveAPI.BaseURL)
|
||||
fmt.Printf("🔗 Listening addresses:\n")
|
||||
for _, addr := range node.Addresses() {
|
||||
@@ -144,6 +157,60 @@ func main() {
|
||||
fmt.Printf("🎯 Joined role-based collaboration topics\n")
|
||||
}
|
||||
}
|
||||
|
||||
// === Admin Election System ===
|
||||
// Initialize election manager
|
||||
electionManager := election.NewElectionManager(ctx, cfg, node.Host(), ps, node.ID().ShortString())
|
||||
|
||||
// Set election callbacks
|
||||
electionManager.SetCallbacks(
|
||||
func(oldAdmin, newAdmin string) {
|
||||
fmt.Printf("👑 Admin changed: %s -> %s\n", oldAdmin, newAdmin)
|
||||
|
||||
// If this node becomes admin, enable SLURP functionality
|
||||
if newAdmin == node.ID().ShortString() {
|
||||
fmt.Printf("🎯 This node is now admin - enabling SLURP functionality\n")
|
||||
cfg.Slurp.Enabled = true
|
||||
// Apply admin role configuration
|
||||
if err := cfg.ApplyRoleDefinition("admin"); err != nil {
|
||||
fmt.Printf("⚠️ Failed to apply admin role: %v\n", err)
|
||||
}
|
||||
}
|
||||
},
|
||||
func(winner string) {
|
||||
fmt.Printf("🏆 Election completed, winner: %s\n", winner)
|
||||
},
|
||||
)
|
||||
|
||||
// Start election manager
|
||||
if err := electionManager.Start(); err != nil {
|
||||
fmt.Printf("❌ Failed to start election manager: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("✅ Election manager started\n")
|
||||
}
|
||||
defer electionManager.Stop()
|
||||
|
||||
// Start admin heartbeat if this node is admin
|
||||
if electionManager.IsCurrentAdmin() {
|
||||
go func() {
|
||||
ticker := time.NewTicker(cfg.Security.ElectionConfig.HeartbeatTimeout / 2)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if electionManager.IsCurrentAdmin() {
|
||||
if err := electionManager.SendAdminHeartbeat(); err != nil {
|
||||
fmt.Printf("❌ Failed to send admin heartbeat: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
// ============================
|
||||
|
||||
// === Hive & Task Coordination Integration ===
|
||||
// Initialize Hive API client
|
||||
|
||||
Reference in New Issue
Block a user