Add native Notarius readiness checks
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/notarius"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
func inspectInvocationRequirements(runtime *invocationRuntime, start int) error {
|
||||
if !stagesContainAny(runtime.stages[start:], "polish", "trim", "analyze") {
|
||||
if !stagesContainAny(runtime.stages[start:], "polish", "trim", "extract", "analyze") {
|
||||
return nil
|
||||
}
|
||||
remaining := runtime.plan
|
||||
@@ -23,7 +26,7 @@ func inspectInvocationRequirements(runtime *invocationRuntime, start int) error
|
||||
if err != nil {
|
||||
return fmt.Errorf("select downstream preflight targets: %w", err)
|
||||
}
|
||||
if !targets.Polish && len(targets.Scriptorium) == 0 {
|
||||
if !targets.Polish && !targets.Notarius && len(targets.Scriptorium) == 0 {
|
||||
return nil
|
||||
}
|
||||
if len(targets.Scriptorium) > 0 && runtime.env.Scriptorium == nil {
|
||||
@@ -44,7 +47,7 @@ func inspectInvocationRequirements(runtime *invocationRuntime, start int) error
|
||||
if !ok || checker == nil {
|
||||
return fmt.Errorf("audita runner does not support preflight")
|
||||
}
|
||||
root := filepath.Join(runtime.identity.LocalWorkDir, "polish")
|
||||
root := artifacts.SessionInvocationProbeDir(runtime.paths, runtime.identity.RunID, "audita")
|
||||
output := filepath.Join(root, "outputs", "transcripts", "polished.json")
|
||||
request, _, err = stage.BuildPolishRequest(runtime.paths, runtime.manifest, "", output, filepath.Join(root, "logs"), filepath.Join(root, "debug"))
|
||||
if err != nil {
|
||||
@@ -52,9 +55,36 @@ func inspectInvocationRequirements(runtime *invocationRuntime, start int) error
|
||||
}
|
||||
}
|
||||
result, err := preflight.CheckDownstream(runtime.ctx, runtime.env.Scriptorium, checker, targets, request)
|
||||
if err == nil && targets.Notarius {
|
||||
if runtime.env.Notarius == nil {
|
||||
runtime.env.Notarius = runtime.dependencies.newNotarius()
|
||||
}
|
||||
native, ok := runtime.env.Notarius.(notarius.ReadinessChecker)
|
||||
if !ok || native == nil {
|
||||
return fmt.Errorf("notarius runner does not support preflight")
|
||||
}
|
||||
useCurrent := currentTranscriptUsableForNotarius(projection)
|
||||
root := artifacts.SessionInvocationProbeDir(runtime.paths, runtime.identity.RunID, "notarius")
|
||||
probe, buildErr := stage.BuildNotariusReadiness(runtime.cfg, runtime.paths, runtime.manifest, root, useCurrent, runtime.opts.Force)
|
||||
if buildErr != nil {
|
||||
return fmt.Errorf("build notarius preflight: %w", buildErr)
|
||||
}
|
||||
checked, checkErr := preflight.CheckNotarius(runtime.ctx, native, probe.Request)
|
||||
result.Findings = append(result.Findings, checked.Findings...)
|
||||
if verifyErr := probe.VerifyReferences(); verifyErr != nil {
|
||||
checkErr = errors.Join(checkErr, fmt.Errorf("verify Notarius probe references: %w", verifyErr))
|
||||
}
|
||||
err = checkErr
|
||||
}
|
||||
for _, finding := range result.Findings {
|
||||
if finding.Severity == preflight.SeverityWarning {
|
||||
runtime.env.Warn(formatPromptFinding(finding), "stage", finding.Stage, "artifact", finding.Artifact, "prompt", finding.PromptID, "issue", finding.IssueCode, "input", finding.InputName, "variable", finding.VariableName)
|
||||
message := formatPromptFinding(finding)
|
||||
if finding.Stage == "extract" {
|
||||
message = "Notarius: " + finding.Message
|
||||
}
|
||||
runtime.env.Warn(message, "stage", finding.Stage, "artifact", finding.Artifact, "prompt", finding.PromptID, "issue", finding.IssueCode, "input", finding.InputName, "variable", finding.VariableName)
|
||||
} else if finding.Severity == preflight.SeverityInfo && finding.Stage == "extract" {
|
||||
runtime.env.Info(finding.Message)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -63,6 +93,18 @@ func inspectInvocationRequirements(runtime *invocationRuntime, start int) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func currentTranscriptUsableForNotarius(projection *workProjection) bool {
|
||||
for _, item := range projection.Stages {
|
||||
if item.Name == "extract" {
|
||||
break
|
||||
}
|
||||
if item.Decision.action == stageActionRun && (item.Name == "transcribe" || item.Name == "merge" || item.Name == "polish" || item.Name == "normalize" || item.Name == "trim") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func formatPromptFinding(item preflight.Finding) string {
|
||||
context := fmt.Sprintf("%s prompt %q", item.Stage, item.PromptID)
|
||||
if item.Artifact != "" {
|
||||
|
||||
Reference in New Issue
Block a user