Expose native session planning and artifact catalogs
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
// Plan validates configuration and prints a read-only execution preview.
|
||||
@@ -48,83 +49,33 @@ func planWithDependencies(ctx context.Context, args []string, out io.Writer, dep
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
m, err := loadManifestIfPresent(ctx, cfg)
|
||||
input := &executionInput{plan: request.Plan, Force: commandkit.Supplied[bool]{Value: request.Force}}
|
||||
report, err := buildSessionPlan(ctx, cfg, input, selectedArtifacts, effective)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
return err
|
||||
}
|
||||
if err := validateBoundedPrerequisites(request.Plan, m); err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||
paths := store.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
model, err := cloneManifestForPlan(m, cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: clone session state: %w", err)
|
||||
}
|
||||
|
||||
stages := request.Plan.Stages()
|
||||
stageEnv := &stage.Env{
|
||||
Config: cfg, SelectedArtifactKeys: append([]string(nil), selectedArtifacts...),
|
||||
EffectiveArtifacts: effective, ArtifactStore: store, Force: request.Force,
|
||||
}
|
||||
|
||||
runCount := 0
|
||||
skipCount := 0
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := fmt.Fprintf(out, "narratio session plan: read-only workdir at %s; %s\n", paths.Root, effectiveConfigSummary(cfg)); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, selectedStage := range stages {
|
||||
semanticConfig, err := currentStageSemanticConfig(selectedStage, stageEnv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: fingerprint semantic configuration for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
decision := decideStageExecution(recordedStageStatus(model, selectedStage.Name()), request.Force, nil)
|
||||
var validation *stage.ResumeValidation
|
||||
if decision.action == stageActionSkip {
|
||||
checked, validationErr := evaluateStageResume(ctx, selectedStage, stageEnv, model, semanticConfig)
|
||||
if validationErr != nil {
|
||||
return fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
validation = checked
|
||||
decision = decideStageExecution(recordedStageStatus(model, selectedStage.Name()), request.Force, checked)
|
||||
}
|
||||
if _, err := applyPreExecutionDecision(model, selectedStage.Name(), decision, time.Now().UTC()); err != nil {
|
||||
return fmt.Errorf("plan: model resume invalidation for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
if decision.action == stageActionRun && selectedStage.Name() == "analyze" {
|
||||
if validator, ok := selectedStage.(stage.ResumeValidator); ok {
|
||||
checked, validationErr := validator.ValidateResume(ctx, stageEnv, model)
|
||||
if validationErr != nil {
|
||||
return fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
checked = checked.Normalized()
|
||||
validation = &checked
|
||||
}
|
||||
}
|
||||
if decision.action == stageActionRun {
|
||||
runCount, skipCount := 0, 0
|
||||
for _, entry := range report.Stages {
|
||||
if entry.Action == string(stageActionRun) {
|
||||
runCount++
|
||||
} else {
|
||||
skipCount++
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, "%s: %s\n", selectedStage.Name(), decision.action); err != nil {
|
||||
if _, err := fmt.Fprintf(out, "%s: %s\n", entry.Name, entry.Action); err != nil {
|
||||
return err
|
||||
}
|
||||
if validation != nil && validation.Analyze != nil {
|
||||
if err := writeAnalyzePlanDetails(out, validation.Analyze); err != nil {
|
||||
if entry.Analysis != nil {
|
||||
if err := writeAnalyzePlanDetails(out, entry.Analysis); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if decision.action == stageActionRun {
|
||||
if err := modelPlannedStageRun(model, selectedStage, cfg, decision, semanticConfig); err != nil {
|
||||
return fmt.Errorf("plan: model stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, "totals: run=%d skip=%d\n", runCount, skipCount); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = fmt.Fprintf(out, "totals: run=%d skip=%d\n", runCount, skipCount)
|
||||
return err
|
||||
}
|
||||
|
||||
func cloneManifestForPlan(source *manifest.Manifest, cfg *config.Config) (*manifest.Manifest, error) {
|
||||
@@ -175,20 +126,20 @@ func plannedSelfSkipReason(stageName string, cfg *config.Config) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func writeAnalyzePlanDetails(out io.Writer, summary *stage.AnalyzeResumeSummary) error {
|
||||
func writeAnalyzePlanDetails(out io.Writer, summary *plannedAnalysis) error {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " targets: %s\n", planStringList(summary.ExplicitTargets)); err != nil {
|
||||
if _, err := fmt.Fprintf(out, " targets: %s\n", planStringList(summary.Targets)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " prerequisites: %s\n", planArtifactList(summary.PrerequisiteWork)); err != nil {
|
||||
if _, err := fmt.Fprintf(out, " prerequisites: %s\n", planArtifactList(summary.Prerequisites)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " execute: %s\n", planArtifactList(summary.ExecutionOrder)); err != nil {
|
||||
if _, err := fmt.Fprintf(out, " execute: %s\n", planArtifactList(summary.Execute)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(out, " reuse: %s\n", planArtifactList(summary.ReusedCurrent))
|
||||
_, err := fmt.Fprintf(out, " reuse: %s\n", planArtifactList(summary.Reuse))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -199,7 +150,7 @@ func planStringList(values []string) string {
|
||||
return strings.Join(values, ", ")
|
||||
}
|
||||
|
||||
func planArtifactList(values []stage.AnalyzeResumeArtifact) string {
|
||||
func planArtifactList(values []plannedArtifact) string {
|
||||
if len(values) == 0 {
|
||||
return "none"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user