Run downstream preflight after preparation
This commit is contained in:
@@ -2,39 +2,60 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
func inspectInvocationRequirements(runtime *invocationRuntime) error {
|
||||
if !stagesContainAny(runtime.stages, "trim", "analyze") {
|
||||
func inspectInvocationRequirements(runtime *invocationRuntime, start int) error {
|
||||
remaining := runtime.plan
|
||||
remaining.stages = append([]stage.Stage(nil), runtime.stages[start:]...)
|
||||
projection, err := projectSelectedWork(runtime.ctx, runtime.cfg, remaining, runtime.opts.Force, runtime.opts.SelectedArtifacts, runtime.effectiveArtifacts, runtime.artifactStore, runtime.manifest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("project downstream preflight work: %w", err)
|
||||
}
|
||||
targets, err := executionDownstreamTargets(runtime.cfg, runtime.identity.SessionID, projection)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select downstream preflight targets: %w", err)
|
||||
}
|
||||
if !targets.Polish && len(targets.Scriptorium) == 0 {
|
||||
return nil
|
||||
}
|
||||
projection, err := projectSelectedWork(runtime.ctx, runtime.cfg, runtime.plan, runtime.opts.Force, runtime.opts.SelectedArtifacts, runtime.effectiveArtifacts, runtime.artifactStore, runtime.manifest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("project prompt inspection work: %w", err)
|
||||
}
|
||||
targets, err := executionInspectionTargets(runtime.cfg, runtime.identity.SessionID, projection)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select prompt inspection targets: %w", err)
|
||||
}
|
||||
if len(targets) == 0 {
|
||||
return nil
|
||||
}
|
||||
if runtime.env.Scriptorium == nil {
|
||||
if len(targets.Scriptorium) > 0 && runtime.env.Scriptorium == nil {
|
||||
runtime.env.Scriptorium = runtime.dependencies.newScriptorium()
|
||||
}
|
||||
if runtime.env.Scriptorium == nil {
|
||||
return fmt.Errorf("initialize scriptorium runner: no runner available")
|
||||
var checker preflight.AuditaChecker
|
||||
var request audita.PolishRequest
|
||||
if targets.Polish {
|
||||
if runtime.env.Audita == nil {
|
||||
runner, err := runtime.dependencies.newAudita(runtime.cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("initialize audita runner: %w", err)
|
||||
}
|
||||
runtime.env.Audita = runner
|
||||
}
|
||||
var ok bool
|
||||
checker, ok = runtime.env.Audita.(preflight.AuditaChecker)
|
||||
if !ok || checker == nil {
|
||||
return fmt.Errorf("audita runner does not support preflight")
|
||||
}
|
||||
root := filepath.Join(runtime.identity.LocalWorkDir, "polish")
|
||||
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 {
|
||||
return fmt.Errorf("build audita preflight: %w", err)
|
||||
}
|
||||
}
|
||||
result, err := preflight.Check(runtime.ctx, runtime.env.Scriptorium, targets)
|
||||
result, err := preflight.CheckDownstream(runtime.ctx, runtime.env.Scriptorium, checker, targets, request)
|
||||
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)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("scriptorium preflight: %w", err)
|
||||
return fmt.Errorf("downstream preflight: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user