65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package orch
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"ai-workflow-skill/packages/coord-core/protocol"
|
|
"ai-workflow-skill/packages/coord-core/store"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type reconcileOptions struct {
|
|
runID string
|
|
}
|
|
|
|
func newReconcileCmd(root *rootOptions) *cobra.Command {
|
|
opts := &reconcileOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "reconcile",
|
|
Short: "Reconcile inbox thread state back into orch task state",
|
|
Long: helpLong(
|
|
"Use reconcile to fold inbox thread state back into orch task and run state.",
|
|
"reconcile is the bridge from worker-side inbox activity to leader-side scheduler state.",
|
|
"Call reconcile before making new dispatch, retry, or status decisions when you need fresh state.",
|
|
),
|
|
Example: ` orch --db .agents/coord.db reconcile --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()
|
|
|
|
result, err := store.NewOrchStore(sqlDB).ReconcileRun(ctx, opts.runID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
resp := protocol.Success{
|
|
OK: true,
|
|
Command: "reconcile",
|
|
Data: map[string]any{
|
|
"run": result.Run,
|
|
"task_counts": result.TaskCounts,
|
|
"updated_tasks": result.UpdatedTasks,
|
|
},
|
|
}
|
|
if root.json {
|
|
return protocol.WriteJSON(cmd.OutOrStdout(), resp)
|
|
}
|
|
|
|
_, err = fmt.Fprintf(cmd.OutOrStdout(), "reconciled run %s (%d updated tasks)\n", result.Run.RunID, len(result.UpdatedTasks))
|
|
return err
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&opts.runID, "run", "", "Run ID")
|
|
_ = cmd.MarkFlagRequired("run")
|
|
|
|
return cmd
|
|
}
|