package orch import ( "fmt" "ai-workflow-skill/packages/coord-core/protocol" "ai-workflow-skill/packages/coord-core/store" "github.com/spf13/cobra" ) type statusOptions struct { runID string } func newStatusCmd(root *rootOptions) *cobra.Command { opts := &statusOptions{} cmd := &cobra.Command{ Use: "status", Short: "Show task state summary for the run", Long: helpLong( "Use status to show the full operational view for one run.", "status reconciles inbox state first, then returns the run summary, aggregate task counts, the task list, and latest attempt/message context.", "Use status as the main leader dashboard command. Prefer it over run show when you need the latest task-level execution picture before making the next dispatch, answer, retry, or cleanup decision.", ), Example: ` orch --db .agents/coord.db status --run blog_mvp_001 orch --db .agents/coord.db --json status --run blog_mvp_001`, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() sqlDB, err := openOrchDB(ctx, root.dbPath) if err != nil { return err } defer sqlDB.Close() orchStore := store.NewOrchStore(sqlDB) if _, err := orchStore.ReconcileRun(ctx, opts.runID); err != nil { return err } overview, err := orchStore.GetRunStatusView(ctx, opts.runID) if err != nil { return err } resp := protocol.Success{ OK: true, Command: "status", Data: map[string]any{ "run": overview.Run, "task_counts": overview.TaskCounts, "tasks": overview.Tasks, }, } if root.json { return protocol.WriteJSON(cmd.OutOrStdout(), resp) } if _, err := fmt.Fprintf(cmd.OutOrStdout(), "run %s status %s\n", overview.Run.RunID, overview.Run.Status); err != nil { return err } for _, task := range overview.Tasks { if _, err := fmt.Fprintf(cmd.OutOrStdout(), "%s\t%s\t%s\n", task.TaskID, task.Status, task.Title); err != nil { return err } } return nil }, } cmd.Flags().StringVar(&opts.runID, "run", "", "Run ID") _ = cmd.MarkFlagRequired("run") return cmd }