2026-11-26 04:25:47 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/preflight"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func inspectInvocationRequirements(runtime *invocationRuntime) error {
|
|
|
|
|
if !stagesContainAny(runtime.stages, "trim", "analyze") {
|
|
|
|
|
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 {
|
|
|
|
|
runtime.env.Scriptorium = runtime.dependencies.newScriptorium()
|
|
|
|
|
}
|
|
|
|
|
if runtime.env.Scriptorium == nil {
|
|
|
|
|
return fmt.Errorf("initialize scriptorium runner: no runner available")
|
|
|
|
|
}
|
|
|
|
|
result, err := preflight.Check(runtime.ctx, runtime.env.Scriptorium, targets)
|
|
|
|
|
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 {
|
|
|
|
|
return fmt.Errorf("scriptorium preflight: %w", err)
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|