package cmd import ( "fmt" "os" "github.com/kb-search/kb/internal/api" "github.com/kb-search/kb/internal/output" "github.com/spf13/cobra" ) var statusCmd = &cobra.Command{ Use: "status", Short: "Show engine status", RunE: runStatus, } func init() { rootCmd.AddCommand(statusCmd) } func runStatus(cmd *cobra.Command, args []string) error { client := api.NewClient() resp, err := client.Get("/api/v1/status") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if err := api.CheckError(resp); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if output.IsJSON() { var raw interface{} if err := api.DecodeJSON(resp, &raw); err != nil { return fmt.Errorf("failed to decode response: %w", err) } output.PrintJSON(raw) return nil } var status struct { ModelName string `json:"model_name"` EmbeddingDim int `json:"embedding_dim"` Device string `json:"device"` DB struct { DocumentsByType map[string]int `json:"documents_by_type"` TotalChunks int `json:"total_chunks"` DBSizeBytes int64 `json:"db_size_bytes"` } `json:"db"` Queue struct { Queued int `json:"queued"` Processing int `json:"processing"` } `json:"queue"` } if err := api.DecodeJSON(resp, &status); err != nil { return fmt.Errorf("failed to decode response: %w", err) } pairs := [][]string{ {"Model", status.ModelName}, {"Embedding Dim", fmt.Sprintf("%d", status.EmbeddingDim)}, {"Device", status.Device}, {"Total Chunks", fmt.Sprintf("%d", status.DB.TotalChunks)}, {"DB Size", fmt.Sprintf("%d bytes", status.DB.DBSizeBytes)}, {"Queued Jobs", fmt.Sprintf("%d", status.Queue.Queued)}, {"Processing Jobs", fmt.Sprintf("%d", status.Queue.Processing)}, } output.PrintKeyValue(pairs) if len(status.DB.DocumentsByType) > 0 { fmt.Println("\nDocuments by Type:") var bPairs [][]string for k, v := range status.DB.DocumentsByType { bPairs = append(bPairs, []string{" " + k, fmt.Sprintf("%d", v)}) } output.PrintKeyValue(bPairs) } return nil }