package cli import ( "fmt" "strings" "gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting" "gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes" "gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner" "gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput" ) func runnerProgress(progress func(string)) func(runner.Progress) { if progress == nil { return nil } return func(event runner.Progress) { location := progressLocation(event.ModuleIndex, event.ModuleKey, event.ModuleID, event.SectionIndex) message := location + " " + event.State if event.Count != nil { unit := "proposals" if event.SectionIndex == nil { unit = "corrections" if event.State == "started" { unit = "chunks" } } message += fmt.Sprintf(" (%d %s)", *event.Count, unit) } progress(message) } } func reportModelProgress(progress func(string), coordinates structuredoutput.DiagnosticContext, counts *outcomes.ExecutionCounts, err error) { if coordinates.StageIndex == nil { return } location := progressLocation(*coordinates.StageIndex, coordinates.ModuleKey, coordinates.StageID, coordinates.SectionIndex) operation := strings.ReplaceAll(coordinates.Role, "_", " ") if coordinates.ValidatorName != "" { operation += " " + coordinates.ValidatorName } if coordinates.BatchIndex != nil { operation += fmt.Sprintf(" batch %d", *coordinates.BatchIndex+1) } if coordinates.RepairAttempt != nil { if coordinates.Role != "correction_repair" { operation += " repair" } operation += fmt.Sprintf(" turn %d", *coordinates.RepairAttempt) } if counts == nil { progress(fmt.Sprintf("%s %s started", location, operation)) return } outcome := "completed" if err != nil { outcome = "failed" } if counts.Available { outcome += fmt.Sprintf(", %d provider attempts", counts.ProviderAttempts) } progress(fmt.Sprintf("%s %s finished (%s)", location, operation, outcome)) } func progressLocation(index int, module string, id *string, section *int) string { location := "Stage " + reporting.StageLabel(index, module, id) if section != nil { location += fmt.Sprintf(", chunk %d", *section+1) } return location }