2026-11-26 04:25:47 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2026-11-27 16:45:46 +00:00
|
|
|
"path/filepath"
|
2026-11-26 04:25:47 +00:00
|
|
|
|
2026-11-27 16:45:46 +00:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
2026-11-26 04:25:47 +00:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
2026-11-27 16:45:46 +00:00
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
2026-11-26 04:25:47 +00:00
|
|
|
)
|
|
|
|
|
|
2026-11-27 16:45:46 +00:00
|
|
|
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)
|
2026-11-26 04:25:47 +00:00
|
|
|
if err != nil {
|
2026-11-27 16:45:46 +00:00
|
|
|
return fmt.Errorf("project downstream preflight work: %w", err)
|
2026-11-26 04:25:47 +00:00
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
targets, err := executionDownstreamTargets(runtime.cfg, runtime.identity.SessionID, projection)
|
2026-11-26 04:25:47 +00:00
|
|
|
if err != nil {
|
2026-11-27 16:45:46 +00:00
|
|
|
return fmt.Errorf("select downstream preflight targets: %w", err)
|
2026-11-26 04:25:47 +00:00
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
if !targets.Polish && len(targets.Scriptorium) == 0 {
|
2026-11-26 04:25:47 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
if len(targets.Scriptorium) > 0 && runtime.env.Scriptorium == nil {
|
2026-11-26 04:25:47 +00:00
|
|
|
runtime.env.Scriptorium = runtime.dependencies.newScriptorium()
|
|
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
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)
|
|
|
|
|
}
|
2026-11-26 04:25:47 +00:00
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
result, err := preflight.CheckDownstream(runtime.ctx, runtime.env.Scriptorium, checker, targets, request)
|
2026-11-26 04:25:47 +00:00
|
|
|
for _, finding := range result.Findings {
|
|
|
|
|
if finding.Severity == preflight.SeverityWarning {
|
2026-11-26 04:29:18 +00:00
|
|
|
runtime.env.Warn(formatPromptFinding(finding), "stage", finding.Stage, "artifact", finding.Artifact, "prompt", finding.PromptID, "issue", finding.IssueCode, "input", finding.InputName, "variable", finding.VariableName)
|
2026-11-26 04:25:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
2026-11-27 16:45:46 +00:00
|
|
|
return fmt.Errorf("downstream preflight: %w", err)
|
2026-11-26 04:25:47 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2026-11-26 04:29:18 +00:00
|
|
|
|
|
|
|
|
func formatPromptFinding(item preflight.Finding) string {
|
|
|
|
|
context := fmt.Sprintf("%s prompt %q", item.Stage, item.PromptID)
|
|
|
|
|
if item.Artifact != "" {
|
|
|
|
|
context = fmt.Sprintf("%s artifact %q prompt %q", item.Stage, item.Artifact, item.PromptID)
|
|
|
|
|
}
|
|
|
|
|
if item.IssueCode != "" {
|
|
|
|
|
return fmt.Sprintf("%s: %s (issue=%s input=%q variable=%q)", context, item.Message, item.IssueCode, item.InputName, item.VariableName)
|
|
|
|
|
}
|
|
|
|
|
return context + ": " + item.Message
|
|
|
|
|
}
|