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
- Variables
- func CheckParams(f *Flow, params map[string]string) error
- func ExpectWarnings(expect string, params map[string]string) []string
- func FileName(name string) string
- func HealLine(step int, t *Target, m Match) string
- func Placeholders(steps []Step) []string
- func Question(name string, cands []Candidate, txt Texts) (string, []string)
- func Resolve(t Target, nodes []Node) (best Match, ranked []Match, ok bool)
- func SamePage(a, b string) bool
- func Score(t Target, n Node) float64
- func Slug(s string) string
- func TextSim(a, b string) float64
- type Candidate
- type Driver
- type Entry
- type ErrDoYourself
- type ErrPassThrough
- type Flow
- type Heal
- type Hints
- type Match
- type Node
- type Param
- type Report
- type Step
- type Stop
- type Store
- type Target
- type Texts
Constants ¶
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 ¶
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 ¶
CheckParams compares the params given to a run with what the flow needs.
func ExpectWarnings ¶
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 Placeholders ¶
Placeholders lists the {{names}} used by steps, in order.
func Resolve ¶
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 ¶
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.
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 ¶
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.
type Driver ¶
type Driver interface {
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 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 ¶
ApplyHeals returns the flow with the healed targets written back.
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.
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 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.
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 Parametrize ¶
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) ExpectStep ¶
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 (Store) List ¶
List reads every flow (project first; a project flow hides a home flow of the same name).
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.
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).