Add daemon fallback visibility and version compatibility checks
Implemented bd-150: Improve daemon fallback visibility and user feedback - Added DaemonStatus struct to track connection state - Enhanced BD_DEBUG logging with detailed diagnostics and timing - Added BD_VERBOSE mode with actionable warnings when falling back - Implemented health checks before using daemon - Clear fallback reasons: connect_failed, health_failed, auto_start_disabled, auto_start_failed, flag_no_daemon - Updated documentation Implemented bd-151: Add version compatibility checks for daemon RPC protocol - Added ClientVersion field to RPC Request struct - Client sends version (0.9.10) in all requests - Server validates version compatibility using semver: - Major version must match - Daemon >= client for backward compatibility - Clear error messages with directional hints (upgrade daemon vs upgrade client) - Added ClientVersion and Compatible fields to HealthResponse - Implemented 'bd version --daemon' command to check compatibility - Fixed batch operations to propagate ClientVersion for proper checks - Updated documentation with version compatibility section Code review improvements: - Propagate ClientVersion in batch sub-requests - Directional error messages based on which side is older - Made ServerVersion a var for future unification Amp-Thread-ID: https://ampcode.com/threads/T-b5fe36b8-c065-44a9-a55b-582573671609 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -2,8 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -17,6 +20,13 @@ var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
checkDaemon, _ := cmd.Flags().GetBool("daemon")
|
||||
|
||||
if checkDaemon {
|
||||
showDaemonVersion()
|
||||
return
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(map[string]string{
|
||||
"version": Version,
|
||||
@@ -28,6 +38,55 @@ var versionCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func showDaemonVersion() {
|
||||
// Connect to daemon (PersistentPreRun skips version command)
|
||||
// We need to find the database path first to get the socket path
|
||||
if dbPath == "" {
|
||||
// Use public API to find database (same logic as PersistentPreRun)
|
||||
if foundDB := beads.FindDatabasePath(); foundDB != "" {
|
||||
dbPath = foundDB
|
||||
}
|
||||
}
|
||||
|
||||
socketPath := getSocketPath()
|
||||
client, err := rpc.TryConnect(socketPath)
|
||||
if err != nil || client == nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: daemon is not running\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: start daemon with 'bd daemon'\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
health, err := client.Health()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error checking daemon health: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
outputJSON(map[string]interface{}{
|
||||
"daemon_version": health.Version,
|
||||
"client_version": Version,
|
||||
"compatible": health.Compatible,
|
||||
"daemon_uptime": health.Uptime,
|
||||
})
|
||||
} else {
|
||||
fmt.Printf("Daemon version: %s\n", health.Version)
|
||||
fmt.Printf("Client version: %s\n", Version)
|
||||
if health.Compatible {
|
||||
fmt.Printf("Compatibility: ✓ compatible\n")
|
||||
} else {
|
||||
fmt.Printf("Compatibility: ✗ incompatible (restart daemon recommended)\n")
|
||||
}
|
||||
fmt.Printf("Daemon uptime: %.1f seconds\n", health.Uptime)
|
||||
}
|
||||
|
||||
if !health.Compatible {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
versionCmd.Flags().Bool("daemon", false, "Check daemon version and compatibility")
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user