feat: add bd mol progress command for efficient molecule monitoring (bd-8xnf)
Adds a new `bd mol progress` command that shows molecule progress using indexed queries instead of loading all steps into memory. This makes it suitable for mega-molecules with millions of steps. Features: - Efficient SQL-based counting via idx_dependencies_depends_on_type index - Progress display: completed / total (percentage) - Current step identification - Rate calculation from closure timestamps - ETA estimation - JSON output support New storage interface method: GetMoleculeProgress(ctx, moleculeID) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
3593ba8d66
commit
0a96b10bba
183
cmd/bd/mol_progress.go
Normal file
183
cmd/bd/mol_progress.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
"github.com/steveyegge/beads/internal/ui"
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
||||
var molProgressCmd = &cobra.Command{
|
||||
Use: "progress [molecule-id]",
|
||||
Short: "Show molecule progress summary",
|
||||
Long: `Show efficient progress summary for a molecule.
|
||||
|
||||
This command uses indexed queries to count progress without loading all steps,
|
||||
making it suitable for very large molecules (millions of steps).
|
||||
|
||||
If no molecule-id is given, shows progress for any molecule you're working on.
|
||||
|
||||
Output includes:
|
||||
- Progress: completed / total (percentage)
|
||||
- Current step: the in-progress step (if any)
|
||||
- Rate: steps/hour based on closure times
|
||||
- ETA: estimated time to completion
|
||||
|
||||
Example:
|
||||
bd mol progress bd-hanoi-xyz`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := rootCtx
|
||||
|
||||
// mol progress requires direct store access
|
||||
if store == nil {
|
||||
if daemonClient != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: mol progress requires direct database access\n")
|
||||
fmt.Fprintf(os.Stderr, "Hint: use --no-daemon flag: bd --no-daemon mol progress\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Error: no database connection\n")
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var moleculeID string
|
||||
if len(args) == 1 {
|
||||
// Explicit molecule ID given
|
||||
resolved, err := utils.ResolvePartialID(ctx, store, args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: molecule '%s' not found\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
moleculeID = resolved
|
||||
} else {
|
||||
// Infer from in_progress work
|
||||
molecules := findInProgressMolecules(ctx, store, actor)
|
||||
if len(molecules) == 0 {
|
||||
if jsonOutput {
|
||||
outputJSON([]interface{}{})
|
||||
return
|
||||
}
|
||||
fmt.Println("No molecules in progress.")
|
||||
fmt.Println("\nUse: bd mol progress <molecule-id>")
|
||||
return
|
||||
}
|
||||
// Show progress for first molecule
|
||||
moleculeID = molecules[0].MoleculeID
|
||||
}
|
||||
|
||||
stats, err := store.GetMoleculeProgress(ctx, moleculeID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
// Add computed fields for JSON output
|
||||
output := map[string]interface{}{
|
||||
"molecule_id": stats.MoleculeID,
|
||||
"molecule_title": stats.MoleculeTitle,
|
||||
"total": stats.Total,
|
||||
"completed": stats.Completed,
|
||||
"in_progress": stats.InProgress,
|
||||
"current_step_id": stats.CurrentStepID,
|
||||
}
|
||||
if stats.Total > 0 {
|
||||
output["percent"] = float64(stats.Completed) * 100 / float64(stats.Total)
|
||||
}
|
||||
if stats.FirstClosed != nil && stats.LastClosed != nil && stats.Completed > 1 {
|
||||
duration := stats.LastClosed.Sub(*stats.FirstClosed)
|
||||
if duration > 0 {
|
||||
rate := float64(stats.Completed-1) / duration.Hours()
|
||||
output["rate_per_hour"] = rate
|
||||
remaining := stats.Total - stats.Completed
|
||||
if rate > 0 {
|
||||
etaHours := float64(remaining) / rate
|
||||
output["eta_hours"] = etaHours
|
||||
}
|
||||
}
|
||||
}
|
||||
outputJSON(output)
|
||||
return
|
||||
}
|
||||
|
||||
// Human-readable output
|
||||
printMoleculeProgressStats(stats)
|
||||
},
|
||||
}
|
||||
|
||||
// printMoleculeProgressStats prints molecule progress in human-readable format
|
||||
func printMoleculeProgressStats(stats *types.MoleculeProgressStats) {
|
||||
fmt.Printf("Molecule: %s (%s)\n", ui.RenderAccent(stats.MoleculeID), stats.MoleculeTitle)
|
||||
|
||||
// Progress bar
|
||||
var percent float64
|
||||
if stats.Total > 0 {
|
||||
percent = float64(stats.Completed) * 100 / float64(stats.Total)
|
||||
}
|
||||
fmt.Printf("Progress: %s / %s (%.1f%%)\n",
|
||||
formatNumber(stats.Completed),
|
||||
formatNumber(stats.Total),
|
||||
percent)
|
||||
|
||||
// Current step
|
||||
if stats.CurrentStepID != "" {
|
||||
fmt.Printf("Current step: %s\n", stats.CurrentStepID)
|
||||
} else if stats.InProgress > 0 {
|
||||
fmt.Printf("In progress: %d step(s)\n", stats.InProgress)
|
||||
}
|
||||
|
||||
// Rate calculation
|
||||
if stats.FirstClosed != nil && stats.LastClosed != nil && stats.Completed > 1 {
|
||||
duration := stats.LastClosed.Sub(*stats.FirstClosed)
|
||||
if duration > 0 {
|
||||
// Rate is (completed - 1) because we need at least 2 points to measure rate
|
||||
rate := float64(stats.Completed-1) / duration.Hours()
|
||||
fmt.Printf("Rate: ~%.0f steps/hour\n", rate)
|
||||
|
||||
// ETA
|
||||
remaining := stats.Total - stats.Completed
|
||||
if rate > 0 && remaining > 0 {
|
||||
etaHours := float64(remaining) / rate
|
||||
fmt.Printf("ETA: %s remaining\n", formatDuration(etaHours))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// formatNumber formats large numbers with commas (handles millions)
|
||||
func formatNumber(n int) string {
|
||||
if n < 1000 {
|
||||
return fmt.Sprintf("%d", n)
|
||||
}
|
||||
if n < 1000000 {
|
||||
return fmt.Sprintf("%d,%03d", n/1000, n%1000)
|
||||
}
|
||||
millions := n / 1000000
|
||||
thousands := (n % 1000000) / 1000
|
||||
ones := n % 1000
|
||||
return fmt.Sprintf("%d,%03d,%03d", millions, thousands, ones)
|
||||
}
|
||||
|
||||
// formatDuration formats hours as a human-readable duration
|
||||
func formatDuration(hours float64) string {
|
||||
if hours < 1 {
|
||||
minutes := hours * 60
|
||||
return fmt.Sprintf("~%.0f minutes", minutes)
|
||||
}
|
||||
if hours < 24 {
|
||||
return fmt.Sprintf("~%.1f hours", hours)
|
||||
}
|
||||
days := hours / 24
|
||||
if days < 7 {
|
||||
return fmt.Sprintf("~%.1f days", days)
|
||||
}
|
||||
weeks := days / 7
|
||||
return fmt.Sprintf("~%.1f weeks", weeks)
|
||||
}
|
||||
|
||||
func init() {
|
||||
molCmd.AddCommand(molProgressCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user