Report preflight smoke usage with its correct scope
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm"
|
||||
@@ -11,6 +13,33 @@ import (
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// preflightUsage carries native observations to CommandKit's diagnostic report.
|
||||
// Smoke calls are deliberately absent from PromptKit's execution observer.
|
||||
type preflightUsageKey struct{}
|
||||
type preflightUsage struct {
|
||||
Lines []string
|
||||
Failed bool
|
||||
}
|
||||
|
||||
var preflightUsageTemplate = template.Must(commandkit.ParseTextTemplate("preflight smoke usage", `{{if .Lines}}Preflight smoke usage; execution-observer totals exclude these calls.
|
||||
{{if .Failed}}See per-profile failure details below.
|
||||
{{else}}{{range .Lines}}{{.}}
|
||||
{{end}}{{end}}{{end}}`, nil))
|
||||
|
||||
func preflightUsageFeature() commandkit.InvocationFeature {
|
||||
return commandkit.NewInvocationFeature(commandkit.InvocationFeatureSpec[struct{}]{
|
||||
Start: func(inv commandkit.Invocation, _ struct{}) (context.Context, func() commandkit.Report) {
|
||||
if inv.CanonicalPath() != "preflight" {
|
||||
return inv.Context, nil
|
||||
}
|
||||
usage := new(preflightUsage)
|
||||
return context.WithValue(inv.Context, preflightUsageKey{}, usage), func() commandkit.Report {
|
||||
return commandkit.Report{Value: usage, TextTemplate: preflightUsageTemplate}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outcome {
|
||||
reporter := inv.Reporter()
|
||||
_ = reporter.Progress("Checking local processing readiness.")
|
||||
@@ -37,6 +66,12 @@ func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outc
|
||||
results, err := llm.VerifyStructuredOutput(inv.Context, loaded.Runtime.Engine, prepared.Plan.Profiles, func(id string) {
|
||||
_ = reporter.Progress(fmt.Sprintf("Checking structured output for profile %q.", id))
|
||||
})
|
||||
if usage, ok := inv.Context.Value(preflightUsageKey{}).(*preflightUsage); ok {
|
||||
usage.Failed = err != nil
|
||||
for _, result := range results {
|
||||
usage.Lines = append(usage.Lines, verificationLine(result))
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
details := make([]commandkit.Detail, 0, len(results))
|
||||
for _, result := range results {
|
||||
@@ -45,9 +80,6 @@ func runPreflight(inv commandkit.Invocation, input processInput) commandkit.Outc
|
||||
}
|
||||
return commandkit.Failure("Structured-output verification failed.", details...).WithCause(err)
|
||||
}
|
||||
for _, result := range results {
|
||||
_ = reporter.Info(verificationLine(result))
|
||||
}
|
||||
_ = reporter.AtEnd().Info("Local and structured-output preflight checks passed.")
|
||||
return commandkit.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user