2026-11-26 04:25:47 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"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 {
|
2026-11-30 01:17:33 +00:00
|
|
|
if !stagesContainAny(runtime.stages[start:], "polish", "trim", "extract", "analyze") {
|
2026-11-27 17:00:16 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
2026-11-27 16:45:46 +00:00
|
|
|
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-30 01:17:33 +00:00
|
|
|
if !targets.Polish && !targets.Notarius && len(targets.Scriptorium) == 0 {
|
2026-11-26 04:25:47 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
2026-11-30 15:16:00 +00:00
|
|
|
result, err := checkDownstreamReadiness(runtime, targets, true, currentTranscriptUsableForNotarius(projection), runtime.opts.Force)
|
2026-11-26 04:25:47 +00:00
|
|
|
for _, finding := range result.Findings {
|
|
|
|
|
if finding.Severity == preflight.SeverityWarning {
|
2026-11-30 01:17:33 +00:00
|
|
|
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)
|
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
|
|
|
|
2026-11-30 01:17:33 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
}
|