package main import ( "fmt" "os" "path/filepath" "chorus/internal/hapui" "chorus/internal/runtime" ) func main() { // Early CLI handling: print help/version without requiring env/config for _, a := range os.Args[1:] { switch a { case "--help", "-h", "help": fmt.Printf("%s-hap %s\n\n", runtime.AppName, runtime.AppVersion) fmt.Println("Usage:") fmt.Printf(" %s [--help] [--version]\n\n", filepath.Base(os.Args[0])) fmt.Println("CHORUS Human Agent Portal - Human Interface to P2P Agent Networks") fmt.Println() fmt.Println("This binary provides a human-friendly interface to participate in P2P agent") fmt.Println("coordination networks. Humans can collaborate with autonomous agents using") fmt.Println("the same protocols and appear as peers in the distributed network.") fmt.Println() fmt.Println("Environment (common):") fmt.Println(" CHORUS_LICENSE_ID (required)") fmt.Println(" CHORUS_AGENT_ID (optional; auto-generated if empty)") fmt.Println(" CHORUS_P2P_PORT (default 9000)") fmt.Println(" CHORUS_API_PORT (default 8080)") fmt.Println(" CHORUS_HEALTH_PORT (default 8081)") fmt.Println(" CHORUS_DHT_ENABLED (default true)") fmt.Println(" CHORUS_BOOTSTRAP_PEERS (comma-separated multiaddrs)") fmt.Println(" OLLAMA_ENDPOINT (default http://localhost:11434)") fmt.Println() fmt.Println("HAP-Specific Environment:") fmt.Println(" CHORUS_HAP_MODE (terminal|web, default terminal)") fmt.Println(" CHORUS_HAP_WEB_PORT (default 8082)") fmt.Println() fmt.Println("Example:") fmt.Println(" CHORUS_LICENSE_ID=dev-123 \\") fmt.Println(" CHORUS_AGENT_ID=human-alice \\") fmt.Println(" CHORUS_HAP_MODE=terminal \\") fmt.Println(" CHORUS_P2P_PORT=9001 ./chorus-hap") fmt.Println() fmt.Println("HAP Features:") fmt.Println(" - Human-friendly message composition") fmt.Println(" - HMMM reasoning template helpers") fmt.Println(" - UCXL context browsing") fmt.Println(" - Collaborative decision participation") fmt.Println(" - Terminal and web interface modes") fmt.Println(" - Same P2P protocols as autonomous agents") return case "--version", "-v": fmt.Printf("%s-hap %s\n", runtime.AppName, runtime.AppVersion) return } } // Initialize shared P2P runtime (same as agent) sharedRuntime, err := runtime.Initialize("hap") if err != nil { fmt.Fprintf(os.Stderr, "❌ Failed to initialize CHORUS HAP: %v\n", err) os.Exit(1) } defer sharedRuntime.Cleanup() // Start HAP mode with human interface if err := startHAPMode(sharedRuntime); err != nil { fmt.Fprintf(os.Stderr, "❌ HAP mode failed: %v\n", err) os.Exit(1) } } // startHAPMode runs the Human Agent Portal with interactive interface func startHAPMode(runtime *runtime.SharedRuntime) error { runtime.Logger.Info("👤 Starting CHORUS Human Agent Portal (HAP)") runtime.Logger.Info("🔗 Connected to P2P network as human agent") runtime.Logger.Info("📝 Ready for collaborative reasoning and decision making") // Get HAP mode from environment (terminal or web) hapMode := os.Getenv("CHORUS_HAP_MODE") if hapMode == "" { hapMode = "terminal" } switch hapMode { case "terminal": return startTerminalInterface(runtime) case "web": return startWebInterface(runtime) default: return fmt.Errorf("unknown HAP mode: %s (valid: terminal, web)", hapMode) } } // startTerminalInterface provides a terminal-based human interface func startTerminalInterface(runtime *runtime.SharedRuntime) error { runtime.Logger.Info("💻 Starting terminal interface for human interaction") // Create and start the HAP terminal interface terminal := hapui.NewTerminalInterface(runtime) runtime.Logger.Info("🎯 Human agent terminal interface ready") // Start the interactive terminal return terminal.Start() } // startWebInterface provides a web-based human interface func startWebInterface(runtime *runtime.SharedRuntime) error { runtime.Logger.Info("🌐 Starting web interface for human interaction") // TODO Phase 3: Implement web interface // - HTTP server with WebSocket for real-time updates // - Web forms for HMMM message composition // - Context browser UI // - Decision voting interface runtime.Logger.Info("⚠️ Web interface not yet implemented") runtime.Logger.Info("🔄 HAP running in stub mode - P2P connectivity established") runtime.Logger.Info("📍 Next: Implement Phase 3 web interface") // For now, fall back to terminal mode return startTerminalInterface(runtime) }