flows

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 16 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 flows turns a successful run into a reusable, parametrized flow and replays it.

A flow is a list of steps keyed by what a person would recognize (role, accessible name, the row/landmark it sits in, its position among equals) plus quiet hints (id, name attribute, placeholder, type…), never by refs, which only live for one page. Typed values the human marks as parameters become {{name}} placeholders. Replay re-resolves every target on the live page (self-healing when the page changed but the meaning didn't) and runs each step through the same action engine, approvals and pause gate as the AI's own calls. See docs/RECORDING.md.

Index

Constants

View Source
const (
	DoOpen    = "open"
	DoBack    = "back"
	DoForward = "forward"
	DoReload  = "reload"
	DoSet     = "set" // a fill field: text, option or checkbox state
	DoPress   = "press"
	DoScroll  = "scroll"
	DoAccept  = "accept" // the page's JavaScript dialog
	DoDismiss = "dismiss"
	// DoWait waits for text (Value) or an element (Target) to appear, or to go with Gone, or for
	// Ms milliseconds. A wait with Expect set is the flow's own check of its result (last step).
	DoWait = "wait"
)

Step actions.

Variables

View Source
var ErrNothing = errors.New("nothing to save: no successful actions since the last flow_save (act first, or pass steps)")

ErrNothing is returned when there are no steps to save.

Functions

func CheckParams

func CheckParams(f *Flow, params map[string]string) error

CheckParams compares the params given to a run with what the flow needs.

func ExpectWarnings

func ExpectWarnings(expect string, params map[string]string) []string

ExpectWarnings checks flow_save's expect text against the chosen params (name → value typed): a {{placeholder}} written by hand never appears on the page, and a param value spelled with other capitalization in expect doesn't become its placeholder, so every run would look for the recorded text whatever the value.

func FileName

func FileName(name string) string

FileName is a flow's file name.

func HealLine

func HealLine(step int, t *Target, m Match) string

HealLine describes a healed step for the AI.

func Placeholders

func Placeholders(steps []Step) []string

Placeholders lists the {{names}} used by steps, in order.

func Question

func Question(name string, cands []Candidate, txt Texts) (string, []string)

Question builds the question and its options (at most 6, as ask_human allows).

func Resolve

func Resolve(t Target, nodes []Node) (best Match, ranked []Match, ok bool)

Resolve finds the target on the page. ok is false when nothing is confident enough; ranked then holds the closest candidates (best first) for the AI to look at.

func SamePage

func SamePage(a, b string) bool

SamePage reports whether two pages (host + path) are the same page of a site: same host (ignoring www.) and the same path, where segments that are ids (numbers, hex, UUIDs, slugs with digits) may differ: /product/42 and /product/77 are one page with other data.

func Score

func Score(t Target, n Node) float64

Score rates how likely node n is the element the target recorded (0..1).

func Slug

func Slug(s string) string

Slug makes an identifier from a label: lowercase ASCII letters, digits and underscores.

func TextSim

func TextSim(a, b string) float64

TextSim is textSim for other packages (the site map's screen and control search).

Types

type Candidate

type Candidate struct {
	Name  string
	Value string
	Field string // the field's label
	Steps []int  // 1-based steps that use it
}

Candidate is a typed value that could become a parameter.

func InferParams

func InferParams(steps []Step) []Candidate

InferParams lists the typed values of steps that could be parameters, in order of first use. Secrets are never candidates (their values were never stored); one-character values and checkbox states are left out. The same value typed twice is one candidate.

func ParseChoice

func ParseChoice(answer string, cands []Candidate, txt Texts) ([]Candidate, bool)

ParseChoice reads the human's answer to the "which values are parameters?" question: the "all" / "none" option, an "only <name>" option, or typed numbers / names ("1, 3", "email").

type Driver

type Driver interface {
	// Navigate runs open / back / forward / reload and returns the tool response.
	Navigate(ctx context.Context, s Step) (string, error)
	// Nodes lists the page's actionable elements; withHints also reads their DOM hints (slower,
	// only needed when a target doesn't match exactly).
	Nodes(ctx context.Context, withHints bool) ([]Node, error)
	// Act runs a step on ref ("" for press / scroll / dialog steps) and returns the response.
	Act(ctx context.Context, s Step, ref string) (string, error)
	// Outline is the current page outline (shown to the AI when a step can't be resolved).
	Outline(ctx context.Context) (string, error)
	// Page is where the browser is now, as host + path (like Step.Page).
	Page(ctx context.Context) string
}

Driver runs steps on the live browser. In Daisybell it is the tools package calling the same handlers as the AI's own act / fill / navigate calls, so the pause gate, approvals, credential handoffs, the ghost cursor and the activity feed all apply to a replay.

type Entry

type Entry struct {
	Flow *Flow
	Path string
	Err  error
}

Entry is a listed flow.

type ErrDoYourself

type ErrDoYourself struct{ Err error }

ErrDoYourself stops the run at a step the AI (or the human) must do by hand, with the page outline, like a step whose target wasn't found.

func (*ErrDoYourself) Error

func (e *ErrDoYourself) Error() string

func (*ErrDoYourself) Unwrap

func (e *ErrDoYourself) Unwrap() error

type ErrPassThrough

type ErrPassThrough struct {
	Err  error
	Step int // the step that was running (1-based), to resume there
}

ErrPassThrough wraps errors the caller must return as they are (e.g. the MCP client must ask the human and retry the call): the run stops without a report.

func (*ErrPassThrough) Error

func (e *ErrPassThrough) Error() string

func (*ErrPassThrough) Unwrap

func (e *ErrPassThrough) Unwrap() error

type Flow

type Flow struct {
	Name        string  `yaml:"name"`
	Description string  `yaml:"description,omitempty"`
	Site        string  `yaml:"site,omitempty"`
	Created     string  `yaml:"created,omitempty"`
	Params      []Param `yaml:"params,omitempty"`
	Steps       []Step  `yaml:"steps"`
}

Flow is one saved flow (a YAML file).

func ApplyHeals

func ApplyHeals(f *Flow, heals []Heal) *Flow

ApplyHeals returns the flow with the healed targets written back.

func ReadFile

func ReadFile(path string) (*Flow, error)

ReadFile parses one flow file.

func (*Flow) Validate

func (f *Flow) Validate() error

Validate checks a flow loaded from disk.

type Heal

type Heal struct {
	Step  int
	Was   Target
	Now   Match
	Fixed *Target // the target as found now (for updating the flow)
}

Heal is a step whose target matched by similarity.

type Hints

type Hints struct {
	Tag          string `yaml:"tag,omitempty"`
	ID           string `yaml:"id,omitempty"`
	Name         string `yaml:"name,omitempty"`
	Type         string `yaml:"type,omitempty"`
	Placeholder  string `yaml:"placeholder,omitempty"`
	Autocomplete string `yaml:"autocomplete,omitempty"`
	TestID       string `yaml:"testid,omitempty"`
	Href         string `yaml:"href,omitempty"` // path only
}

Hints are DOM details that help re-find an element whose label changed.

func (*Hints) Empty

func (h *Hints) Empty() bool

Empty reports hints with nothing in them.

type Match

type Match struct {
	Node  Node
	Score float64
	// Exact is a match on role, name, context and position: no healing involved.
	Exact bool
}

Match is a scored candidate.

type Node

type Node struct {
	Ref     string
	Role    string
	Name    string
	Context string
	Nth     int
	Hints   *Hints
}

Node is an element of the live page that a step may target.

func (Node) Describe

func (n Node) Describe() string

Describe renders a node for messages: `e14 button "Create account" in form "Signup"`.

type Param

type Param struct {
	Name string `yaml:"name"`
	// Example is the value typed when the flow was recorded (never for secrets).
	Example string `yaml:"example,omitempty"`
	// Field is the label of the field it goes into, for the AI and the human.
	Field string `yaml:"field,omitempty"`
}

Param is a value asked for on each run.

type Report

type Report struct {
	Flow  string
	Total int
	From  int // first step run (1-based)
	Done  int // steps completed in this run
	// Healed are the steps whose target was re-found by meaning (the page changed).
	Healed []Heal
	// Stop is set when the run stopped before the end.
	Stop *Stop
	// Last is the response of the last step (what changed on the page); the expect check does
	// not replace it.
	Last string
	// Expect is the flow's result check (filled in) when it ran and passed.
	Expect string
}

Report is the outcome of a run.

func Run

func Run(ctx context.Context, f *Flow, params map[string]string, from int, d Driver) (*Report, error)

Run replays the flow from step from (1-based) with params.

func (*Report) Format

func (r *Report) Format(params map[string]string) string

Format renders the report for the AI.

type Step

type Step struct {
	Do     string  `yaml:"do"`
	URL    string  `yaml:"url,omitempty"`
	Target *Target `yaml:"target,omitempty"`
	Value  string  `yaml:"value,omitempty"`
	// Secret steps were typed by the human (passwords, codes, card data): replay hands the field
	// to the human again; the value is never stored.
	Secret bool `yaml:"secret,omitempty"`
	// Gone and Ms are for wait steps: wait for the text or element to disappear; a fixed wait.
	Gone bool `yaml:"gone,omitempty"`
	Ms   int  `yaml:"ms,omitempty"`
	// Expect marks the final wait that checks the flow's result (flow_save expect=…).
	Expect bool   `yaml:"expect,omitempty"`
	Why    string `yaml:"why,omitempty"`
	// Page is where the step ran (host and path), for messages.
	Page string `yaml:"page,omitempty"`
}

Step is one action.

func Fill

func Fill(s Step, params map[string]string) (Step, error)

Fill substitutes {{name}} in a step's value and URL (URL-encoded there).

func Parametrize

func Parametrize(steps []Step, chosen []Candidate) []Step

Parametrize replaces the chosen candidates' values with {{name}} in step values, in the URLs of open steps (query and path, URL-encoded or not) and inside the text of wait steps (so expect="Thanks, Ana" checks the name of this run, not the recorded one). Selectors are never touched.

func (Step) Describe

func (s Step) Describe() string

Describe renders a step in one line: `type textbox "Email" = {{email}}`.

func (Step) ExpectStep

func (s Step) ExpectStep() bool

ExpectStep reports whether s is the flow's check of its result.

type Stop

type Stop struct {
	Step    int
	Desc    string
	Reason  string
	Closest []Match
	Outline string
	// Unresolved is set when the step's target wasn't found (the AI should look and continue).
	Unresolved bool
	// Expect is set when every step ran but the flow's expected text isn't on the page.
	Expect bool
}

Stop says where and why a run stopped.

type Store

type Store struct {
	// Project is the project's flows directory (may not exist).
	Project string
	// Home is ~/.daisybell/flows.
	Home string
}

Store keeps flows as YAML files: in the project (<dir>/.daisybell/flows, when that folder exists, so a team can commit them) and in ~/.daisybell/flows.

func NewStore

func NewStore(workDir, home string) Store

NewStore returns the store for a working directory and Daisybell home.

func (Store) List

func (s Store) List() []Entry

List reads every flow (project first; a project flow hides a home flow of the same name).

func (Store) Load

func (s Store) Load(name string) (*Flow, string, error)

Load reads a flow by name (project first).

func (Store) Names

func (s Store) Names() []string

Names lists the saved flow names.

func (Store) Save

func (s Store) Save(f *Flow, now time.Time) (string, error)

Save writes f (the previous version, if any, goes to .history/). It returns the path.

func (Store) SaveDir

func (s Store) SaveDir() string

SaveDir is where new flows go: the project folder when it exists, else the home folder.

type Target

type Target struct {
	Role    string `yaml:"role"`
	Name    string `yaml:"name"`
	Context string `yaml:"context,omitempty"`
	// Nth is the position among elements with the same role, name and context (1 = first).
	Nth   int    `yaml:"nth,omitempty"`
	Hints *Hints `yaml:"hints,omitempty"`
}

Target is an element by meaning.

func (*Target) Describe

func (t *Target) Describe() string

Describe renders a target for messages: `button "Place order" in row "Invoice #12"`.

type Texts

type Texts struct {
	Question string // %q flow name, then the numbered list
	All      string
	None     string
	Only     string // %s param name
}

Texts are the human-facing strings of flow_save's question (shown in the Cockpit or by the MCP client), in the OS language.

func HumanTexts

func HumanTexts() Texts

HumanTexts picks the language from the OS locale (like the elicitation forms).

Jump to

Keyboard shortcuts

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