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:
anthonyrawlins
2025-08-17 10:04:25 +10:00
parent e9252ccddc
commit d96c931a29
115 changed files with 1010 additions and 534 deletions

View File

@@ -24,7 +24,7 @@ type SecurityConfig struct {
// Config represents the complete configuration for a Bzzz agent
type Config struct {
HiveAPI HiveAPIConfig `yaml:"hive_api"`
WHOOSHAPI WHOOSHAPIConfig `yaml:"hive_api"`
Agent AgentConfig `yaml:"agent"`
GitHub GitHubConfig `yaml:"github"`
P2P P2PConfig `yaml:"p2p"`
@@ -36,8 +36,8 @@ type Config struct {
Security SecurityConfig `yaml:"security"` // Cluster security and elections
}
// HiveAPIConfig holds Hive system integration settings
type HiveAPIConfig struct {
// WHOOSHAPIConfig holds WHOOSH system integration settings
type WHOOSHAPIConfig struct {
BaseURL string `yaml:"base_url"`
APIKey string `yaml:"api_key"`
Timeout time.Duration `yaml:"timeout"`
@@ -258,7 +258,7 @@ func LoadConfig(configPath string) (*Config, error) {
// getDefaultConfig returns the default configuration
func getDefaultConfig() *Config {
return &Config{
HiveAPI: HiveAPIConfig{
WHOOSHAPI: WHOOSHAPIConfig{
BaseURL: "https://hive.home.deepblack.cloud",
Timeout: 30 * time.Second,
RetryCount: 3,
@@ -404,12 +404,12 @@ func loadFromFile(config *Config, filePath string) error {
// loadFromEnv loads configuration from environment variables
func loadFromEnv(config *Config) error {
// Hive API configuration
// WHOOSH API configuration
if url := os.Getenv("BZZZ_HIVE_API_URL"); url != "" {
config.HiveAPI.BaseURL = url
config.WHOOSHAPI.BaseURL = url
}
if apiKey := os.Getenv("BZZZ_HIVE_API_KEY"); apiKey != "" {
config.HiveAPI.APIKey = apiKey
config.WHOOSHAPI.APIKey = apiKey
}
// Agent configuration
@@ -481,7 +481,7 @@ func loadFromEnv(config *Config) error {
// validateConfig validates the configuration values
func validateConfig(config *Config) error {
// Validate required fields
if config.HiveAPI.BaseURL == "" {
if config.WHOOSHAPI.BaseURL == "" {
return fmt.Errorf("hive_api.base_url is required")
}

View File

@@ -59,19 +59,19 @@ func GetEnvironmentSpecificDefaults(environment string) *Config {
switch environment {
case "development", "dev":
config.HiveAPI.BaseURL = "http://localhost:8000"
config.WHOOSHAPI.BaseURL = "http://localhost:8000"
config.P2P.EscalationWebhook = "http://localhost:5678/webhook-test/human-escalation"
config.Logging.Level = "debug"
config.Agent.PollInterval = 10 * time.Second
case "staging":
config.HiveAPI.BaseURL = "https://hive-staging.home.deepblack.cloud"
config.WHOOSHAPI.BaseURL = "https://hive-staging.home.deepblack.cloud"
config.P2P.EscalationWebhook = "https://n8n-staging.home.deepblack.cloud/webhook-test/human-escalation"
config.Logging.Level = "info"
config.Agent.PollInterval = 20 * time.Second
case "production", "prod":
config.HiveAPI.BaseURL = "https://hive.home.deepblack.cloud"
config.WHOOSHAPI.BaseURL = "https://hive.home.deepblack.cloud"
config.P2P.EscalationWebhook = "https://n8n.home.deepblack.cloud/webhook-test/human-escalation"
config.Logging.Level = "warn"
config.Agent.PollInterval = 30 * time.Second

View File

@@ -11,10 +11,10 @@ import (
// HybridConfig manages feature flags and configuration for Phase 2 hybrid mode
type HybridConfig struct {
// DHT Configuration
DHT DHTConfig `json:"dht" yaml:"dht"`
DHT HybridDHTConfig `json:"dht" yaml:"dht"`
// UCXL Configuration
UCXL UCXLConfig `json:"ucxl" yaml:"ucxl"`
UCXL HybridUCXLConfig `json:"ucxl" yaml:"ucxl"`
// Discovery Configuration
Discovery DiscoveryConfig `json:"discovery" yaml:"discovery"`
@@ -23,7 +23,7 @@ type HybridConfig struct {
Monitoring MonitoringConfig `json:"monitoring" yaml:"monitoring"`
}
type DHTConfig struct {
type HybridDHTConfig struct {
Backend string `env:"BZZZ_DHT_BACKEND" default:"mock" json:"backend" yaml:"backend"`
BootstrapNodes []string `env:"BZZZ_DHT_BOOTSTRAP_NODES" json:"bootstrap_nodes" yaml:"bootstrap_nodes"`
FallbackOnError bool `env:"BZZZ_FALLBACK_ON_ERROR" default:"true" json:"fallback_on_error" yaml:"fallback_on_error"`
@@ -33,7 +33,7 @@ type DHTConfig struct {
OperationTimeout time.Duration `env:"BZZZ_DHT_OPERATION_TIMEOUT" default:"10s" json:"operation_timeout" yaml:"operation_timeout"`
}
type UCXLConfig struct {
type HybridUCXLConfig struct {
CacheEnabled bool `env:"BZZZ_UCXL_CACHE_ENABLED" default:"true" json:"cache_enabled" yaml:"cache_enabled"`
CacheTTL time.Duration `env:"BZZZ_UCXL_CACHE_TTL" default:"5m" json:"cache_ttl" yaml:"cache_ttl"`
UseDistributed bool `env:"BZZZ_UCXL_USE_DISTRIBUTED" default:"false" json:"use_distributed" yaml:"use_distributed"`
@@ -59,7 +59,7 @@ func LoadHybridConfig() (*HybridConfig, error) {
config := &HybridConfig{}
// Load DHT configuration
config.DHT = DHTConfig{
config.DHT = HybridDHTConfig{
Backend: getEnvString("BZZZ_DHT_BACKEND", "mock"),
BootstrapNodes: getEnvStringSlice("BZZZ_DHT_BOOTSTRAP_NODES", []string{}),
FallbackOnError: getEnvBool("BZZZ_FALLBACK_ON_ERROR", true),
@@ -70,7 +70,7 @@ func LoadHybridConfig() (*HybridConfig, error) {
}
// Load UCXL configuration
config.UCXL = UCXLConfig{
config.UCXL = HybridUCXLConfig{
CacheEnabled: getEnvBool("BZZZ_UCXL_CACHE_ENABLED", true),
CacheTTL: getEnvDuration("BZZZ_UCXL_CACHE_TTL", 5*time.Minute),
UseDistributed: getEnvBool("BZZZ_UCXL_USE_DISTRIBUTED", false),
@@ -105,7 +105,7 @@ func LoadHybridConfig() (*HybridConfig, error) {
func (c *HybridConfig) Validate() error {
// Validate DHT backend
validBackends := []string{"mock", "real", "hybrid"}
if !contains(validBackends, c.DHT.Backend) {
if !hybridContains(validBackends, c.DHT.Backend) {
return fmt.Errorf("invalid DHT backend '%s', must be one of: %v", c.DHT.Backend, validBackends)
}
@@ -192,7 +192,7 @@ func getEnvStringSlice(key string, defaultValue []string) []string {
return defaultValue
}
func contains(slice []string, item string) bool {
func hybridContains(slice []string, item string) bool {
for _, s := range slice {
if s == item {
return true
@@ -231,7 +231,7 @@ func (w *ConfigWatcher) Events() <-chan ConfigurationChangeEvent {
// UpdateDHTBackend changes the DHT backend at runtime
func (w *ConfigWatcher) UpdateDHTBackend(backend string) error {
validBackends := []string{"mock", "real", "hybrid"}
if !contains(validBackends, backend) {
if !hybridContains(validBackends, backend) {
return fmt.Errorf("invalid DHT backend '%s'", backend)
}

View File

@@ -2,13 +2,8 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"gopkg.in/yaml.v2"
)
// AuthorityLevel defines the decision-making authority of a role