Resolve import cycles and migrate to chorus.services module path
This comprehensive refactoring addresses critical architectural issues: IMPORT CYCLE RESOLUTION: • pkg/crypto ↔ pkg/slurp/roles: Created pkg/security/access_levels.go • pkg/ucxl → pkg/dht: Created pkg/storage/interfaces.go • pkg/slurp/leader → pkg/election → pkg/slurp/storage: Moved types to pkg/election/interfaces.go MODULE PATH MIGRATION: • Changed from github.com/anthonyrawlins/bzzz to chorus.services/bzzz • Updated all import statements across 115+ files • Maintains compatibility while removing personal GitHub account dependency TYPE SYSTEM IMPROVEMENTS: • Resolved duplicate type declarations in crypto package • Added missing type definitions (RoleStatus, TimeRestrictions, KeyStatus, KeyRotationResult) • Proper interface segregation to prevent future cycles ARCHITECTURAL BENEFITS: • Build now progresses past structural issues to normal dependency resolution • Cleaner separation of concerns between packages • Eliminates circular dependencies that prevented compilation • Establishes foundation for scalable codebase growth 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/anthonyrawlins/bzzz/pkg/config"
|
||||
"github.com/anthonyrawlins/bzzz/pubsub"
|
||||
"chorus.services/bzzz/pkg/config"
|
||||
"chorus.services/bzzz/pubsub"
|
||||
libp2p "github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/anthonyrawlins/bzzz/pkg/config"
|
||||
"chorus.services/bzzz/pkg/config"
|
||||
)
|
||||
|
||||
func TestElectionManager_NewElectionManager(t *testing.T) {
|
||||
|
||||
163
pkg/election/interfaces.go
Normal file
163
pkg/election/interfaces.go
Normal file
@@ -0,0 +1,163 @@
|
||||
// Package election provides election interfaces and types
|
||||
// This file contains shared interfaces to avoid circular dependencies.
|
||||
|
||||
package election
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LeaderInfo represents information about the current leader
|
||||
type LeaderInfo struct {
|
||||
NodeID string `json:"node_id"` // Leader node ID
|
||||
Role string `json:"role"` // Leader role
|
||||
Term int64 `json:"term"` // Election term
|
||||
ElectedAt time.Time `json:"elected_at"` // When elected
|
||||
LastSeen time.Time `json:"last_seen"` // Last heartbeat
|
||||
Capabilities []string `json:"capabilities"` // Leader capabilities
|
||||
}
|
||||
|
||||
// GenerationStatus represents status of context generation operations
|
||||
type GenerationStatus struct {
|
||||
IsGenerating bool `json:"is_generating"` // Whether generation is active
|
||||
ActiveRequests int `json:"active_requests"` // Number of active requests
|
||||
QueuedRequests int `json:"queued_requests"` // Number of queued requests
|
||||
LastGeneration time.Time `json:"last_generation"` // Last generation time
|
||||
GenerationCount int64 `json:"generation_count"` // Total generations
|
||||
LeaderID string `json:"leader_id"` // Current leader
|
||||
}
|
||||
|
||||
// ContextGenerationRequest represents a request for context generation
|
||||
type ContextGenerationRequest struct {
|
||||
ID string `json:"id"` // Request ID
|
||||
RequesterID string `json:"requester_id"` // Node requesting
|
||||
Priority int `json:"priority"` // Request priority
|
||||
Context map[string]interface{} `json:"context"` // Request context
|
||||
CreatedAt time.Time `json:"created_at"` // Request creation time
|
||||
Deadline *time.Time `json:"deadline"` // Optional deadline
|
||||
}
|
||||
|
||||
// ContextGenerationResult represents the result of a context generation request
|
||||
type ContextGenerationResult struct {
|
||||
RequestID string `json:"request_id"` // Original request ID
|
||||
Success bool `json:"success"` // Whether successful
|
||||
Error string `json:"error"` // Error message if failed
|
||||
GeneratedAt time.Time `json:"generated_at"` // When generated
|
||||
GeneratedBy string `json:"generated_by"` // Node that generated
|
||||
Context []byte `json:"context"` // Generated context data
|
||||
}
|
||||
|
||||
// ContextLeadershipCallbacks defines callbacks for context leadership events
|
||||
type ContextLeadershipCallbacks struct {
|
||||
// OnBecomeContextLeader is called when this node becomes context leader
|
||||
OnBecomeContextLeader func(ctx context.Context, term int64) error
|
||||
|
||||
// OnLoseContextLeadership is called when this node loses context leadership
|
||||
OnLoseContextLeadership func(ctx context.Context, newLeader string) error
|
||||
|
||||
// OnContextLeaderChanged is called when any leadership change occurs
|
||||
OnContextLeaderChanged func(oldLeader, newLeader string, term int64)
|
||||
|
||||
// OnContextGenerationStarted is called when context generation starts
|
||||
OnContextGenerationStarted func(leaderID string)
|
||||
|
||||
// OnContextGenerationStopped is called when context generation stops
|
||||
OnContextGenerationStopped func(leaderID string, reason string)
|
||||
|
||||
// OnContextFailover is called when context leadership failover occurs
|
||||
OnContextFailover func(oldLeader, newLeader string, duration time.Duration)
|
||||
|
||||
// OnContextError is called when context-related errors occur
|
||||
OnContextError func(err error, severity ErrorSeverity)
|
||||
}
|
||||
|
||||
// ErrorSeverity represents severity levels for election errors
|
||||
type ErrorSeverity string
|
||||
|
||||
const (
|
||||
ErrorSeverityLow ErrorSeverity = "low" // Low severity error
|
||||
ErrorSeverityMedium ErrorSeverity = "medium" // Medium severity error
|
||||
ErrorSeverityHigh ErrorSeverity = "high" // High severity error
|
||||
ErrorSeverityCritical ErrorSeverity = "critical" // Critical error
|
||||
)
|
||||
|
||||
// ContextManager defines interface for managing context generation
|
||||
type ContextManager interface {
|
||||
// Context generation management
|
||||
RequestContextGeneration(req *ContextGenerationRequest) error
|
||||
GetGenerationStatus() (*GenerationStatus, error)
|
||||
StartGeneration(ctx context.Context) error
|
||||
StopGeneration(ctx context.Context) error
|
||||
|
||||
// Leadership awareness
|
||||
IsLeader() bool
|
||||
SetLeader(isLeader bool)
|
||||
|
||||
// Health and status
|
||||
GetHealth() (bool, error)
|
||||
GetMetrics() map[string]interface{}
|
||||
}
|
||||
|
||||
// Additional types for context failover (simplified versions)
|
||||
|
||||
// ContextGenerationJob represents a context generation job
|
||||
type ContextGenerationJob struct {
|
||||
ID string `json:"id"` // Job ID
|
||||
RequestID string `json:"request_id"` // Original request ID
|
||||
Status string `json:"status"` // Job status
|
||||
CreatedAt time.Time `json:"created_at"` // Creation time
|
||||
UpdatedAt time.Time `json:"updated_at"` // Last update
|
||||
CompletedAt *time.Time `json:"completed_at"` // Completion time
|
||||
Context map[string]interface{} `json:"context"` // Job context
|
||||
}
|
||||
|
||||
// ClusterState represents simplified cluster state
|
||||
type ClusterState struct {
|
||||
Nodes map[string]interface{} `json:"nodes"` // Node states
|
||||
Leadership map[string]string `json:"leadership"` // Leadership assignments
|
||||
LastUpdated time.Time `json:"last_updated"` // Last state update
|
||||
StateVersion int64 `json:"state_version"` // State version
|
||||
}
|
||||
|
||||
// ResourceAllocation represents resource allocation
|
||||
type ResourceAllocation struct {
|
||||
NodeID string `json:"node_id"` // Target node
|
||||
Resources map[string]interface{} `json:"resources"` // Allocated resources
|
||||
AllocatedAt time.Time `json:"allocated_at"` // Allocation time
|
||||
ExpiresAt *time.Time `json:"expires_at"` // Expiration time
|
||||
}
|
||||
|
||||
// ManagerConfig represents manager configuration
|
||||
type ManagerConfig struct {
|
||||
MaxConcurrentJobs int `json:"max_concurrent_jobs"` // Max concurrent jobs
|
||||
QueueSize int `json:"queue_size"` // Queue size limit
|
||||
TimeoutDuration time.Duration `json:"timeout_duration"` // Job timeout
|
||||
Settings map[string]interface{} `json:"settings"` // Additional settings
|
||||
}
|
||||
|
||||
// GenerationPolicy represents context generation policy
|
||||
type GenerationPolicy struct {
|
||||
Priority string `json:"priority"` // Priority scheme
|
||||
MaxRetries int `json:"max_retries"` // Maximum retries
|
||||
BackoffType string `json:"backoff_type"` // Backoff strategy
|
||||
Settings map[string]interface{} `json:"settings"` // Policy settings
|
||||
}
|
||||
|
||||
// QueuePolicy represents queue management policy
|
||||
type QueuePolicy struct {
|
||||
Strategy string `json:"strategy"` // Queue strategy
|
||||
MaxSize int `json:"max_size"` // Maximum queue size
|
||||
DropPolicy string `json:"drop_policy"` // What to drop when full
|
||||
Settings map[string]interface{} `json:"settings"` // Queue settings
|
||||
}
|
||||
|
||||
// DefaultManagerConfig returns default manager configuration
|
||||
func DefaultManagerConfig() *ManagerConfig {
|
||||
return &ManagerConfig{
|
||||
MaxConcurrentJobs: 10,
|
||||
QueueSize: 100,
|
||||
TimeoutDuration: 30 * time.Minute,
|
||||
Settings: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/anthonyrawlins/bzzz/pkg/slurp/leader"
|
||||
slurpContext "github.com/anthonyrawlins/bzzz/pkg/slurp/context"
|
||||
slurpContext "chorus.services/bzzz/pkg/slurp/context"
|
||||
)
|
||||
|
||||
// SLURPElection extends the base Election interface to include Project Manager contextual intelligence duties
|
||||
@@ -15,19 +14,19 @@ type SLURPElection interface {
|
||||
// Project Manager specific capabilities
|
||||
|
||||
// RegisterContextManager registers a SLURP context manager for leader duties
|
||||
RegisterContextManager(manager leader.ContextManager) error
|
||||
RegisterContextManager(manager ContextManager) error
|
||||
|
||||
// IsContextLeader returns whether this node is the current context generation leader
|
||||
IsContextLeader() bool
|
||||
|
||||
// GetContextManager returns the registered context manager (if leader)
|
||||
GetContextManager() (leader.ContextManager, error)
|
||||
GetContextManager() (ContextManager, error)
|
||||
|
||||
// TransferContextLeadership initiates graceful context leadership transfer
|
||||
TransferContextLeadership(ctx context.Context, targetNodeID string) error
|
||||
|
||||
// GetContextLeaderInfo returns information about current context leader
|
||||
GetContextLeaderInfo() (*leader.LeaderInfo, error)
|
||||
GetContextLeaderInfo() (*LeaderInfo, error)
|
||||
|
||||
// Context generation coordination
|
||||
|
||||
@@ -38,10 +37,10 @@ type SLURPElection interface {
|
||||
StopContextGeneration(ctx context.Context) error
|
||||
|
||||
// GetContextGenerationStatus returns status of context operations
|
||||
GetContextGenerationStatus() (*leader.GenerationStatus, error)
|
||||
GetContextGenerationStatus() (*GenerationStatus, error)
|
||||
|
||||
// RequestContextGeneration queues a context generation request
|
||||
RequestContextGeneration(req *leader.ContextGenerationRequest) error
|
||||
RequestContextGeneration(req *ContextGenerationRequest) error
|
||||
|
||||
// Context leadership monitoring
|
||||
|
||||
@@ -167,19 +166,19 @@ type ContextFailoverState struct {
|
||||
TransferTime time.Time `json:"transfer_time"` // When transfer occurred
|
||||
|
||||
// Context generation state
|
||||
QueuedRequests []*leader.ContextGenerationRequest `json:"queued_requests"` // Queued requests
|
||||
ActiveJobs map[string]*leader.ContextGenerationJob `json:"active_jobs"` // Active jobs
|
||||
CompletedJobs []*leader.ContextGenerationJob `json:"completed_jobs"` // Recent completed jobs
|
||||
QueuedRequests []*ContextGenerationRequest `json:"queued_requests"` // Queued requests
|
||||
ActiveJobs map[string]*ContextGenerationJob `json:"active_jobs"` // Active jobs
|
||||
CompletedJobs []*ContextGenerationJob `json:"completed_jobs"` // Recent completed jobs
|
||||
|
||||
// Cluster coordination state
|
||||
ClusterState *leader.ClusterState `json:"cluster_state"` // Current cluster state
|
||||
ResourceAllocations map[string]*leader.ResourceAllocation `json:"resource_allocations"` // Resource allocations
|
||||
ClusterState *ClusterState `json:"cluster_state"` // Current cluster state
|
||||
ResourceAllocations map[string]*ResourceAllocation `json:"resource_allocations"` // Resource allocations
|
||||
NodeAssignments map[string][]string `json:"node_assignments"` // Task assignments per node
|
||||
|
||||
// Configuration state
|
||||
ManagerConfig *leader.ManagerConfig `json:"manager_config"` // Manager configuration
|
||||
GenerationPolicy *leader.GenerationPolicy `json:"generation_policy"` // Generation policy
|
||||
QueuePolicy *leader.QueuePolicy `json:"queue_policy"` // Queue policy
|
||||
ManagerConfig *ManagerConfig `json:"manager_config"` // Manager configuration
|
||||
GenerationPolicy *GenerationPolicy `json:"generation_policy"` // Generation policy
|
||||
QueuePolicy *QueuePolicy `json:"queue_policy"` // Queue policy
|
||||
|
||||
// State validation
|
||||
StateVersion int64 `json:"state_version"` // State version
|
||||
|
||||
@@ -9,9 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/anthonyrawlins/bzzz/pkg/config"
|
||||
"github.com/anthonyrawlins/bzzz/pkg/slurp/leader"
|
||||
"github.com/anthonyrawlins/bzzz/pubsub"
|
||||
"chorus.services/bzzz/pkg/config"
|
||||
"chorus.services/bzzz/pubsub"
|
||||
libp2p "github.com/libp2p/go-libp2p/core/host"
|
||||
)
|
||||
|
||||
@@ -21,7 +20,7 @@ type SLURPElectionManager struct {
|
||||
|
||||
// SLURP-specific state
|
||||
contextMu sync.RWMutex
|
||||
contextManager leader.ContextManager
|
||||
contextManager ContextManager
|
||||
slurpConfig *SLURPElectionConfig
|
||||
contextCallbacks *ContextLeadershipCallbacks
|
||||
|
||||
@@ -75,7 +74,7 @@ func NewSLURPElectionManager(
|
||||
}
|
||||
|
||||
// RegisterContextManager registers a SLURP context manager for leader duties
|
||||
func (sem *SLURPElectionManager) RegisterContextManager(manager leader.ContextManager) error {
|
||||
func (sem *SLURPElectionManager) RegisterContextManager(manager ContextManager) error {
|
||||
sem.contextMu.Lock()
|
||||
defer sem.contextMu.Unlock()
|
||||
|
||||
@@ -102,7 +101,7 @@ func (sem *SLURPElectionManager) IsContextLeader() bool {
|
||||
}
|
||||
|
||||
// GetContextManager returns the registered context manager (if leader)
|
||||
func (sem *SLURPElectionManager) GetContextManager() (leader.ContextManager, error) {
|
||||
func (sem *SLURPElectionManager) GetContextManager() (ContextManager, error) {
|
||||
sem.contextMu.RLock()
|
||||
defer sem.contextMu.RUnlock()
|
||||
|
||||
@@ -175,7 +174,7 @@ func (sem *SLURPElectionManager) TransferContextLeadership(ctx context.Context,
|
||||
}
|
||||
|
||||
// GetContextLeaderInfo returns information about current context leader
|
||||
func (sem *SLURPElectionManager) GetContextLeaderInfo() (*leader.LeaderInfo, error) {
|
||||
func (sem *SLURPElectionManager) GetContextLeaderInfo() (*LeaderInfo, error) {
|
||||
sem.contextMu.RLock()
|
||||
defer sem.contextMu.RUnlock()
|
||||
|
||||
@@ -184,7 +183,7 @@ func (sem *SLURPElectionManager) GetContextLeaderInfo() (*leader.LeaderInfo, err
|
||||
return nil, fmt.Errorf("no current leader")
|
||||
}
|
||||
|
||||
info := &leader.LeaderInfo{
|
||||
info := &LeaderInfo{
|
||||
NodeID: leaderID,
|
||||
Term: sem.contextTerm,
|
||||
ElectedAt: time.Now(), // TODO: Track actual election time
|
||||
@@ -342,14 +341,14 @@ func (sem *SLURPElectionManager) StopContextGeneration(ctx context.Context) erro
|
||||
}
|
||||
|
||||
// GetContextGenerationStatus returns status of context operations
|
||||
func (sem *SLURPElectionManager) GetContextGenerationStatus() (*leader.GenerationStatus, error) {
|
||||
func (sem *SLURPElectionManager) GetContextGenerationStatus() (*GenerationStatus, error) {
|
||||
sem.contextMu.RLock()
|
||||
manager := sem.contextManager
|
||||
isLeader := sem.isContextLeader
|
||||
sem.contextMu.RUnlock()
|
||||
|
||||
if manager == nil {
|
||||
return &leader.GenerationStatus{
|
||||
return &GenerationStatus{
|
||||
IsLeader: false,
|
||||
LeaderID: sem.GetCurrentAdmin(),
|
||||
LastUpdate: time.Now(),
|
||||
@@ -369,7 +368,7 @@ func (sem *SLURPElectionManager) GetContextGenerationStatus() (*leader.Generatio
|
||||
}
|
||||
|
||||
// RequestContextGeneration queues a context generation request
|
||||
func (sem *SLURPElectionManager) RequestContextGeneration(req *leader.ContextGenerationRequest) error {
|
||||
func (sem *SLURPElectionManager) RequestContextGeneration(req *ContextGenerationRequest) error {
|
||||
sem.contextMu.RLock()
|
||||
manager := sem.contextManager
|
||||
isLeader := sem.isContextLeader
|
||||
@@ -422,15 +421,15 @@ func (sem *SLURPElectionManager) PrepareContextFailover(ctx context.Context) (*C
|
||||
if sem.contextManager != nil {
|
||||
// Get queued requests (if supported)
|
||||
// TODO: Add interface method to get queued requests
|
||||
state.QueuedRequests = []*leader.ContextGenerationRequest{}
|
||||
state.QueuedRequests = []*ContextGenerationRequest{}
|
||||
|
||||
// Get active jobs (if supported)
|
||||
// TODO: Add interface method to get active jobs
|
||||
state.ActiveJobs = make(map[string]*leader.ContextGenerationJob)
|
||||
state.ActiveJobs = make(map[string]*ContextGenerationJob)
|
||||
|
||||
// Get manager configuration
|
||||
// TODO: Add interface method to get configuration
|
||||
state.ManagerConfig = leader.DefaultManagerConfig()
|
||||
state.ManagerConfig = DefaultManagerConfig()
|
||||
}
|
||||
|
||||
// Get cluster health snapshot
|
||||
@@ -743,7 +742,7 @@ func (chm *ContextHealthMonitor) GetClusterHealth() *ContextClusterHealth {
|
||||
}
|
||||
|
||||
// UpdateGenerationStatus updates health based on generation status
|
||||
func (chm *ContextHealthMonitor) UpdateGenerationStatus(status *leader.GenerationStatus) {
|
||||
func (chm *ContextHealthMonitor) UpdateGenerationStatus(status *GenerationStatus) {
|
||||
chm.mu.Lock()
|
||||
defer chm.mu.Unlock()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/anthonyrawlins/bzzz/pkg/config"
|
||||
"chorus.services/bzzz/pkg/config"
|
||||
)
|
||||
|
||||
// SLURPCandidateCapabilities represents SLURP-specific capabilities for election candidates
|
||||
|
||||
Reference in New Issue
Block a user