66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
|
pk "go.maximumdirect.net/promptkit"
|
|
)
|
|
|
|
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, event pk.ExecutionEvent) {
|
|
if coordinates.StageIndex == nil || (event.Kind != pk.ExecutionStarted && event.Kind != pk.ExecutionFinished) {
|
|
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 event.Kind == pk.ExecutionStarted {
|
|
progress(fmt.Sprintf("%s %s started", location, operation))
|
|
} else {
|
|
progress(fmt.Sprintf("%s %s finished (%s, %d provider attempts)", location, operation, event.Outcome, event.Attempts))
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|