workflow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workflow holds a parsed workflow and what the engine plans from it: triggers, reach, plan items, runs and their idempotency keys.

Index

Constants

View Source
const (
	KindPlanned       = "workflow_planned"   // Key item id:decision, Data reason
	KindStepRan       = "workflow_step_ran"  // Key item id:step index
	KindStepRefused   = "workflow_refused"   // Key item id:attempt
	KindStepFailed    = "workflow_failed"    // Key item id:attempt
	KindItemDismissed = "workflow_dismissed" // Key item id
	KindItemDropped   = "workflow_dropped"   // Key item id:at, Data why
)
View Source
const MaxAttempts = 3

MaxAttempts is how many failed runs make an item's key terminal.

Variables

EngineKinds are the engine's own event kinds; a workflow's `on` may not name them.

Functions

This section is empty.

Types

type Action

type Action string
const (
	ActionApply   Action = "apply"
	ActionDismiss Action = "dismiss"
	ActionSkip    Action = "skip"
	ActionGuide   Action = "guide"
)

type Approval

type Approval struct {
	Default  Outcome
	Window   time.Duration
	WaitWhen Predicate // a match makes the item pending with default wait, even when a guard refuses
}

type Cron

type Cron struct {
	// contains filtered or unexported fields
}

Cron is a five-field schedule ("0 9 * * 1-5") read in the location of the time it is asked about. When both day fields are restricted, a day matches either, as in cron(8).

func ParseCron

func ParseCron(src string) (*Cron, error)

func (*Cron) Next

func (c *Cron) Next(after time.Time) time.Time

Next is the first firing strictly after after; zero when none comes within years.

func (*Cron) Prev

func (c *Cron) Prev(at time.Time) time.Time

Prev is the last firing at or before at; zero when none came within years.

type Decision

type Decision string
const (
	DecisionRun     Decision = "run"
	DecisionPending Decision = "pending"
	DecisionBlocked Decision = "blocked"
	DecisionSkipped Decision = "skipped"
)

type Event

type Event struct {
	ID              int64 // events.id
	Unit            unit.Unit
	Kind, Key, Data string
	At              time.Time
}

type Fact

type Fact struct {
	Name  string
	Value any
}

type Facts

type Facts map[string]any

Facts are a unit's facts by dotted name; values are bool, int, string, []string, time.Duration or time.Time. "<slot>.repo" is "owner/repo" or "" and is what the pause's Repos reads.

type Gain

type Gain struct{ MemoryBytes, DiskBytes int64 }

type Item

type Item struct {
	ID       string
	Key      Key
	Workflow string
	Unit     unit.Unit
	Decision Decision
	Reason   string
	Steps    []Step
	Gain     Gain
	Why      Why
	Default  Outcome
	Deadline time.Time
	Guidance string // set by Act(guide) only
	Attempts int
	Error    string
	Mode     Mode
	At       time.Time
}

type Key

type Key struct {
	Workflow string
	Unit     unit.Unit
	Value    string // sha256 hex of the sorted key values, first 16 chars
}

Key is the idempotency key: workflow, unit and the key facts' values (for a schedule trigger, plus the firing time).

func NewKey

func NewKey(w Workflow, u unit.Unit, f Facts, fired time.Time) Key

func (Key) ID

func (k Key) ID() string

ID is "<workflow>/<provider>/<path-escaped-key>/<value>".

type Limits

type Limits struct {
	PerRun, PerDay, PerUnitPerDay int
	Cooldown                      time.Duration
}

type Mode

type Mode string
const (
	ModeObserve Mode = "observe"
	ModeApply   Mode = "apply"
)

type Outcome

type Outcome string

Outcome is what a pending item does when its window ends unanswered.

const (
	OutcomeRun  Outcome = "run"
	OutcomeWait Outcome = "wait"
)

type Predicate

type Predicate interface {
	Match(v Vars) (bool, error)
	Reads() []string
}

Predicate is a compiled `when`; Reads are the facts it names, for the why.

func All

func All(ps ...Predicate) Predicate

All is a predicate that matches when every one of ps does; a nil one matches.

type Reach

type Reach string
const (
	ReachLocal   Reach = "local"
	ReachPrivate Reach = "private"
	ReachVisible Reach = "visible"
)

type Refused

type Refused struct{ Err error }

Refused is a predicate that never matches and says why on every match.

func (Refused) Match

func (r Refused) Match(Vars) (bool, error)

func (Refused) Reads

func (Refused) Reads() []string

type Run

type Run struct {
	Key      Key
	Status   RunStatus
	Attempts int
	Error    string
	At       time.Time
}

type RunStatus

type RunStatus string
const (
	RunDone      RunStatus = "done"
	RunDismissed RunStatus = "dismissed"
	RunFailed    RunStatus = "failed"
	RunRefused   RunStatus = "refused"
)

type Step

type Step struct {
	Use   string         // a name of builtin.Steps
	Reach Reach          // from the vocabulary, never from the manifest
	Args  map[string]any // e.g. {"intent": "review", "round": "follow-up"}
}

type Trigger

type Trigger struct {
	Kind     TriggerKind
	On       []string // event kinds, Kind == TriggerEvent
	Schedule *Cron    // Kind == TriggerSchedule
}

type TriggerKind

type TriggerKind string
const (
	TriggerSweep    TriggerKind = "sweep"
	TriggerEvent    TriggerKind = "event"
	TriggerSchedule TriggerKind = "schedule"
)

type Vars

type Vars struct {
	Facts   Facts // the unit's slot ("pr.state", "session.idle_for")
	Trigger Facts // "trigger.kind", "trigger.event.kind", "trigger.event.key", "trigger.event.data", "trigger.fired_at"
	Config  Facts // "config.cleanup.idle", ...
	Now     time.Time
}

type Why

type Why struct {
	Workflow string
	Trigger  TriggerKind
	Event    *Event
	FiredAt  time.Time
	Matched  []Fact // the predicate's Reads with their values, sorted by name
}

type Workflow

type Workflow struct {
	Name, Description string
	Provider          unit.ProviderID // the manifest's `subject`
	Slot              string          // the provider's fact slot: "pr" for github, else the provider id
	Trigger           Trigger
	When              Predicate
	Steps             []Step
	Limits            Limits
	Mode              Mode
	AllowVisible      bool
	Order             int
	Key               []string // fact names; empty means the slot's fingerprint fact
	Approval          Approval
	Source            string // manifest path
	// DraftApproval is the manifest's [draft_approval] block; nil when absent.
	DraftApproval *draft.Approval
}

func (Workflow) Visible

func (w Workflow) Visible() bool

Visible says whether a step of the workflow acts in the user's name where others see it.

Jump to

Keyboard shortcuts

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