From 991a2d995a4475931dcb74d21442f7949406b206 Mon Sep 17 00:00:00 2001 From: Daan van Etten Date: Sat, 18 Oct 2025 00:17:11 +0200 Subject: [PATCH] Fix panic in 'bd stats' when daemon is running (#69) The statsCmd was not checking if a daemon client was available before trying to access the store directly. When the daemon is running, store is nil, causing a panic. This fix adds a check for daemonClient and uses RPC to get statistics when the daemon is available, falling back to direct store access only when running in direct mode. --- cmd/bd/ready.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cmd/bd/ready.go b/cmd/bd/ready.go index cb8fa097..36f3efc2 100644 --- a/cmd/bd/ready.go +++ b/cmd/bd/ready.go @@ -168,6 +168,44 @@ var statsCmd = &cobra.Command{ Use: "stats", Short: "Show statistics", Run: func(cmd *cobra.Command, args []string) { + // If daemon is running, use RPC + if daemonClient != nil { + resp, err := daemonClient.Stats() + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + + var stats types.Statistics + if err := json.Unmarshal(resp.Data, &stats); err != nil { + fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err) + os.Exit(1) + } + + if jsonOutput { + outputJSON(stats) + return + } + + cyan := color.New(color.FgCyan).SprintFunc() + green := color.New(color.FgGreen).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() + + fmt.Printf("\n%s Beads Statistics:\n\n", cyan("📊")) + fmt.Printf("Total Issues: %d\n", stats.TotalIssues) + fmt.Printf("Open: %s\n", green(fmt.Sprintf("%d", stats.OpenIssues))) + fmt.Printf("In Progress: %s\n", yellow(fmt.Sprintf("%d", stats.InProgressIssues))) + fmt.Printf("Closed: %d\n", stats.ClosedIssues) + fmt.Printf("Blocked: %d\n", stats.BlockedIssues) + fmt.Printf("Ready: %s\n", green(fmt.Sprintf("%d", stats.ReadyIssues))) + if stats.AverageLeadTime > 0 { + fmt.Printf("Avg Lead Time: %.1f hours\n", stats.AverageLeadTime) + } + fmt.Println() + return + } + + // Direct mode ctx := context.Background() stats, err := store.GetStatistics(ctx) if err != nil {