journey

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package journey provides the compiler for converting prompts to deterministic steps.

Package journey provides types and execution for user journey testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType string

ActionType represents deterministic step actions.

const (
	ActionNavigate   ActionType = "navigate"
	ActionClick      ActionType = "click"
	ActionType_      ActionType = "type" // Underscore to avoid conflict with Go keyword
	ActionFill       ActionType = "fill"
	ActionSelect     ActionType = "select"
	ActionCheck      ActionType = "check"
	ActionUncheck    ActionType = "uncheck"
	ActionUpload     ActionType = "upload"
	ActionScroll     ActionType = "scroll"
	ActionHover      ActionType = "hover"
	ActionPress      ActionType = "press"
	ActionWait       ActionType = "wait"
	ActionScreenshot ActionType = "screenshot"
	ActionAssert     ActionType = "assert"
	ActionExtract    ActionType = "extract"
)

type AuditPoint

type AuditPoint struct {
	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`

	// When to audit
	AfterStep string `yaml:"afterStep,omitempty" json:"afterStep,omitempty"` // After specific step ID
	WaitFor   string `yaml:"waitFor,omitempty" json:"waitFor,omitempty"`     // Wait for selector
	Condition string `yaml:"condition,omitempty" json:"condition,omitempty"` // Conditional expression

	// What to audit
	Categories []string `yaml:"categories,omitempty" json:"categories,omitempty"` // Empty = all
	Rules      []string `yaml:"rules,omitempty" json:"rules,omitempty"`           // Specific rules

	// Options
	FullPage   bool `yaml:"fullPage,omitempty" json:"fullPage,omitempty"`
	Screenshot bool `yaml:"screenshot,omitempty" json:"screenshot,omitempty"`
}

AuditPoint defines when and what to audit during a journey.

type CompiledJourney

type CompiledJourney struct {
	OriginalDefinition *Definition    `json:"originalDefinition"`
	CompiledAt         time.Time      `json:"compiledAt"`
	Model              string         `json:"model"`
	Steps              []CompiledStep `json:"steps"`
}

CompiledJourney represents a fully compiled journey.

func (*CompiledJourney) ToDefinition

func (cj *CompiledJourney) ToDefinition() *Definition

ToDefinition converts a compiled journey back to a Definition with all deterministic steps.

type CompiledStep

type CompiledStep struct {
	// Original prompt that generated this
	OriginalPrompt string `json:"originalPrompt"`

	// Compiled deterministic steps
	Steps []Step `json:"steps"`

	// Compilation metadata
	CompiledAt time.Time `json:"compiledAt"`
	Model      string    `json:"model"`

	// Verification status
	Verified     bool      `json:"verified"`
	VerifiedAt   time.Time `json:"verifiedAt,omitempty"`
	VerifyStatus string    `json:"verifyStatus,omitempty"` // success, failure, partial
}

CompiledStep represents a deterministic step compiled from a prompt.

type Compiler

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

Compiler converts prompt-based journey steps to deterministic steps. This enables the "compile once, run many" pattern for reproducible audits.

func NewCompiler

func NewCompiler(client *omnillm.ChatClient, model string, logger *slog.Logger) *Compiler

NewCompiler creates a new journey compiler.

func (*Compiler) CompileJourney

func (c *Compiler) CompileJourney(ctx context.Context, def *Definition) (*CompiledJourney, error)

CompileJourney compiles all prompt-based steps in a journey to deterministic steps.

func (*Compiler) VerifyCompiledStep

func (c *Compiler) VerifyCompiledStep(ctx context.Context, compiled *CompiledStep, executor StepExecutor) error

VerifyCompiledStep executes a compiled step and compares against expected behavior.

type Condition

type Condition struct {
	Description string `yaml:"description" json:"description"`
	Check       string `yaml:"check" json:"check"`       // Selector or expression
	Expected    string `yaml:"expected" json:"expected"` // Expected state
}

Condition represents a pre/post condition.

type Definition

type Definition struct {
	// Identification
	ID          string `yaml:"id" json:"id"`
	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	Version     string `yaml:"version,omitempty" json:"version,omitempty"`

	// Execution mode
	Mode Mode `yaml:"mode" json:"mode"`

	// For agentic mode: high-level goal
	Goal string `yaml:"goal,omitempty" json:"goal,omitempty"`

	// Journey steps
	Steps []Step `yaml:"steps" json:"steps"`

	// Test data for variable substitution
	TestData map[string]any `yaml:"testData,omitempty" json:"testData,omitempty"`

	// Audit configuration
	AuditPoints []AuditPoint `yaml:"auditPoints,omitempty" json:"auditPoints,omitempty"`

	// Pre/post conditions
	Preconditions  []Condition `yaml:"preconditions,omitempty" json:"preconditions,omitempty"`
	Postconditions []Condition `yaml:"postconditions,omitempty" json:"postconditions,omitempty"`

	// Error handling
	OnError ErrorHandler `yaml:"onError,omitempty" json:"onError,omitempty"`

	// Timeout for entire journey
	Timeout time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}

Definition represents a complete journey definition.

type ErrorHandler

type ErrorHandler struct {
	Screenshot    bool   `yaml:"screenshot" json:"screenshot"`
	ContinueOn    string `yaml:"continueOn,omitempty" json:"continueOn,omitempty"` // error types to continue on
	RecoverySteps []Step `yaml:"recoverySteps,omitempty" json:"recoverySteps,omitempty"`
}

ErrorHandler specifies error handling behavior.

type ExecutionState

type ExecutionState struct {
	// Current position
	CurrentStepIndex int    `json:"currentStepIndex"`
	CurrentStepID    string `json:"currentStepId"`

	// Variables accumulated during execution
	Variables map[string]any `json:"variables"`

	// Page state
	CurrentURL   string `json:"currentUrl"`
	CurrentTitle string `json:"currentTitle"`

	// Execution status
	Status    string        `json:"status"` // running, paused, completed, failed
	Error     string        `json:"error,omitempty"`
	StartTime time.Time     `json:"startTime"`
	Duration  time.Duration `json:"duration"`

	// Step results
	StepResults []StepExecutionResult `json:"stepResults"`
}

ExecutionState tracks journey execution state.

type Executor

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

Executor runs journey definitions using vibium for browser automation.

func NewExecutor

func NewExecutor(vibe *vibium.Vibe, compiler *Compiler, logger *slog.Logger) *Executor

NewExecutor creates a new journey executor. The compiler parameter is optional - pass nil if LLM compilation is not needed.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, def *Definition) (*ExecutionState, error)

Execute runs a journey definition and returns the execution state.

func (*Executor) ExecuteStep

func (e *Executor) ExecuteStep(ctx context.Context, step Step) error

ExecuteStep implements StepExecutor interface.

type ExecutorConfig

type ExecutorConfig struct {
	// Default timeout for steps
	StepTimeout time.Duration

	// Screenshot on error
	ScreenshotOnError bool

	// Compile prompts before execution (for hybrid/agentic modes)
	CompilePrompts bool
}

ExecutorConfig configures the executor.

type Mode

type Mode string

Mode represents the journey execution mode.

const (
	ModeAgentic       Mode = "agentic"       // LLM navigates based on prompts
	ModeDeterministic Mode = "deterministic" // Fixed steps with selectors
	ModeHybrid        Mode = "hybrid"        // Mix of both
)

type Parser

type Parser struct{}

Parser parses journey definitions from various formats.

func NewParser

func NewParser() *Parser

NewParser creates a new journey parser.

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(data []byte) (*Definition, error)

ParseBytes parses a journey definition from bytes with format detection.

func (*Parser) ParseFile

func (p *Parser) ParseFile(path string) (*Definition, error)

ParseFile parses a journey definition from a file. Supports .yaml, .yml, and .json extensions.

func (*Parser) ParseJSON

func (p *Parser) ParseJSON(r io.Reader) (*Definition, error)

ParseJSON parses a journey definition from JSON.

func (*Parser) ParseYAML

func (p *Parser) ParseYAML(r io.Reader) (*Definition, error)

ParseYAML parses a journey definition from YAML.

func (*Parser) ValidateSteps

func (p *Parser) ValidateSteps(steps []Step) []ValidationError

ValidateSteps validates a list of steps.

type RetryConfig

type RetryConfig struct {
	MaxAttempts int           `yaml:"maxAttempts" json:"maxAttempts"`
	Delay       time.Duration `yaml:"delay" json:"delay"`
	Backoff     float64       `yaml:"backoff,omitempty" json:"backoff,omitempty"` // Multiplier
}

RetryConfig specifies retry behavior.

type Step

type Step struct {
	// Common fields
	ID   string `yaml:"id,omitempty" json:"id,omitempty"`
	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	// For deterministic mode
	Action   ActionType `yaml:"action,omitempty" json:"action,omitempty"`
	Selector string     `yaml:"selector,omitempty" json:"selector,omitempty"`
	Value    string     `yaml:"value,omitempty" json:"value,omitempty"`
	URL      string     `yaml:"url,omitempty" json:"url,omitempty"`
	Key      string     `yaml:"key,omitempty" json:"key,omitempty"` // For key press

	// For agentic mode
	Prompt       string `yaml:"prompt,omitempty" json:"prompt,omitempty"`
	Instructions string `yaml:"instructions,omitempty" json:"instructions,omitempty"`

	// For file upload/data input
	Data map[string]any `yaml:"data,omitempty" json:"data,omitempty"`
	File string         `yaml:"file,omitempty" json:"file,omitempty"`

	// Wait conditions
	WaitFor     string        `yaml:"waitFor,omitempty" json:"waitFor,omitempty"`     // Selector to wait for
	WaitState   string        `yaml:"waitState,omitempty" json:"waitState,omitempty"` // visible, hidden, attached
	WaitTimeout time.Duration `yaml:"waitTimeout,omitempty" json:"waitTimeout,omitempty"`

	// Audit trigger
	Audit     bool   `yaml:"audit,omitempty" json:"audit,omitempty"`
	AuditName string `yaml:"auditName,omitempty" json:"auditName,omitempty"`

	// Control flow
	Condition string `yaml:"if,omitempty" json:"if,omitempty"`
	UseAuth   bool   `yaml:"auth,omitempty" json:"auth,omitempty"` // Use configured auth

	// Error handling
	ContinueOnError bool          `yaml:"continueOnError,omitempty" json:"continueOnError,omitempty"`
	Retry           *RetryConfig  `yaml:"retry,omitempty" json:"retry,omitempty"`
	Timeout         time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	// For storing results
	Store string `yaml:"store,omitempty" json:"store,omitempty"`

	// Sub-steps (for grouped operations)
	Steps []Step `yaml:"steps,omitempty" json:"steps,omitempty"`
}

Step represents a single step in a journey.

type StepExecutionResult

type StepExecutionResult struct {
	StepIndex int           `json:"stepIndex"`
	StepID    string        `json:"stepId"`
	StepName  string        `json:"stepName"`
	Action    ActionType    `json:"action"`
	Status    string        `json:"status"` // success, failure, skipped
	Error     string        `json:"error,omitempty"`
	StartTime time.Time     `json:"startTime"`
	Duration  time.Duration `json:"duration"`
	Retries   int           `json:"retries"`

	// Output/extracted data
	Output any `json:"output,omitempty"`

	// Page state after step
	PageURL    string `json:"pageUrl"`
	PageTitle  string `json:"pageTitle"`
	Screenshot string `json:"screenshot,omitempty"`

	// If audit was triggered
	AuditResult any `json:"auditResult,omitempty"` // Typed as any to avoid circular import
}

StepExecutionResult contains the result of executing a step.

type StepExecutor

type StepExecutor interface {
	ExecuteStep(ctx context.Context, step Step) error
}

StepExecutor executes individual steps (implemented by journey executor).

type ValidationError

type ValidationError struct {
	StepIndex int    `json:"stepIndex"`
	StepID    string `json:"stepId"`
	Field     string `json:"field"`
	Message   string `json:"message"`
}

ValidationError represents a validation error.

func (ValidationError) Error

func (e ValidationError) Error() string

Jump to

Keyboard shortcuts

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