package app import ( "context" "flag" "fmt" "io" "gitea.maximumdirect.net/eric/narratio/internal/config" ) // Run executes the pipeline plan and persists manifest state. func Run(ctx context.Context, args []string, out io.Writer) error { fs := flag.NewFlagSet("run", flag.ContinueOnError) fs.SetOutput(io.Discard) var pipelinePath string var sessionPath string var force bool fs.StringVar(&pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)") fs.StringVar(&sessionPath, "session", "", "path to session.yml") fs.BoolVar(&force, "force", false, "force stage execution (reserved for future behavior)") if err := fs.Parse(args); err != nil { return fmt.Errorf("run: invalid flags: %w", err) } if fs.NArg() != 0 { return fmt.Errorf("run: unexpected positional arguments") } if sessionPath == "" { return fmt.Errorf("run: --session is required") } resolvedPipelinePath, err := resolvePipelineConfigPath(pipelinePath) if err != nil { return fmt.Errorf("run: %w", err) } cfg, err := config.Load(resolvedPipelinePath, sessionPath) if err != nil { return fmt.Errorf("run: %w", err) } if err := config.Validate(cfg); err != nil { return fmt.Errorf("run: %w", err) } stages := BuildFullPlan() summary, err := executeStages(ctx, cfg, stages, RunOptions{Force: force}) if err != nil { return fmt.Errorf("run: %w", err) } _, err = fmt.Fprintf( out, "narratio run: session %s; executed=%d skipped=%d; manifest=%s\n", summary.SessionID, len(summary.Executed), len(summary.Skipped), summary.ManifestPath, ) return err }