recipe

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package recipe implements a named, shareable workflow library for cloop. A recipe bundles a flow YAML, a goal template, lifecycle hooks, and default environment variables into a single installable YAML file stored in .cloop/recipes/<name>.yaml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(workDir, name string) ([]byte, error)

Export serialises a recipe back to YAML bytes suitable for sharing.

func MarshalExample

func MarshalExample(r *Recipe) ([]byte, error)

MarshalExample serialises a Recipe to YAML bytes (exported wrapper for cmd use).

func Remove

func Remove(workDir, name string) error

Remove deletes the recipe file for the given name.

Types

type Recipe

type Recipe struct {
	// Name is the unique identifier for the recipe (used as the file stem).
	Name string `yaml:"name"`

	// Description is a short human-readable summary.
	Description string `yaml:"description,omitempty"`

	// Version is an optional semantic version string (e.g. "1.0.0").
	Version string `yaml:"version,omitempty"`

	// Author is the optional creator name or email.
	Author string `yaml:"author,omitempty"`

	// FlowYAML is the embedded flow pipeline definition (YAML text).
	// It is rendered as a Go text/template before execution; use {{.Goal}},
	// {{.Name}}, or any key from ExtraVars.
	FlowYAML string `yaml:"flow_yaml"`

	// GoalTemplate is an optional Go text/template that generates the cloop
	// goal string. The template receives a TemplateData value.
	// When empty, the --goal flag value is used verbatim.
	GoalTemplate string `yaml:"goal_template,omitempty"`

	// Hooks defines shell commands to run at plan/task lifecycle events.
	Hooks hooks.Config `yaml:"hooks,omitempty"`

	// EnvVars lists environment variables to set before running the recipe.
	// These are merged with the project's existing env vars (recipe values win).
	EnvVars []env.Var `yaml:"env_vars,omitempty"`
}

Recipe is a named, shareable automation workflow that combines a flow pipeline, a goal template, lifecycle hooks, and default environment variables into a single installable unit.

func ExampleRecipe

func ExampleRecipe() *Recipe

ExampleRecipe returns a minimal but complete example recipe for documentation/init purposes.

func Install

func Install(workDir, source string) (*Recipe, error)

Install copies a recipe from a local file path or HTTP(S) URL into .cloop/recipes/<name>.yaml. The source must contain valid recipe YAML.

func List

func List(workDir string) ([]*Recipe, error)

List returns all Recipe objects found in .cloop/recipes/. Returns an empty slice (not an error) when the directory does not exist.

func Load

func Load(workDir, name string) (*Recipe, error)

Load reads and parses a recipe from .cloop/recipes/<name>.yaml. The read is bounded by maxRecipeBytes — a runaway recipe file (e.g. a multi-GB blob mistakenly written into the recipes dir) is rejected with *boundedread.SizeError before any payload is loaded.

type RunConfig

type RunConfig struct {
	// Goal overrides the default goal. Required when GoalTemplate is non-empty
	// and no default is embedded in the recipe.
	Goal string

	// ExtraVars are additional key→value pairs available inside templates.
	ExtraVars map[string]string

	// WorkDir is the project working directory.
	WorkDir string

	// CloopBin is the path to the cloop binary (defaults to os.Executable).
	CloopBin string

	// DryRun prints steps without executing them.
	DryRun bool
}

RunConfig controls recipe execution behaviour.

type RunResult

type RunResult struct {
	// Recipe is the recipe that was executed.
	Recipe *Recipe

	// FlowResults contains per-step outcomes.
	FlowResults []flow.StepResult

	// Err is the first fatal error, if any.
	Err error
}

RunResult captures the outcome of executing a recipe.

func Run

func Run(ctx context.Context, r *Recipe, cfg RunConfig) (*RunResult, error)

Run instantiates the recipe (renders templates, applies env vars and hooks), writes a temporary flow file, then delegates to flow.Run.

type TemplateData

type TemplateData struct {
	// Goal is the goal string provided via --goal or the recipe default.
	Goal string
	// Name is the recipe name.
	Name string
	// Timestamp is the current UTC time.
	Timestamp time.Time
	// Extra holds any additional key→value pairs passed by the caller.
	Extra map[string]string
}

TemplateData is passed to GoalTemplate and FlowYAML rendering.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL