rules

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package rules compiles and evaluates the boolean expressions used by choice nodes. Expressions are written in expr-lang and evaluated against the invocation context, exposed as three variables: `input` (the start payload), `results` (each visited node's output, keyed by node id) and `signals` (received signal payloads, keyed by signal name).

when: "results.triage.risk_score > 80"
when: "input.tier == 'pro' && signals.approval.granted"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Program

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

Program is a compiled choice expression.

func Compile

func Compile(code string) (*Program, error)

Compile compiles a boolean expression that may reference `input`, `results`, `signals`, `branches` and `last_node`.

func (*Program) Match

func (p *Program) Match(contextDoc json.RawMessage) (bool, error)

Match evaluates the program against the assembled context document ({"input": …, "results": {…}, "signals": {…}}). A false result and a non-nil error are returned when evaluation fails (e.g. a referenced field is missing); callers typically treat that as "no match" and fall through to the default rule.

func (*Program) MatchContext added in v0.1.0

func (p *Program) MatchContext(ctx context.Context, contextDoc json.RawMessage) (bool, error)

MatchContext is Match using ctx for pre/post evaluation cancellation checks. Choice expressions are intentionally compiled to straight-line predicates and run with an explicit VM memory budget; expr does not provide a preemptive VM deadline, so compile-time restrictions are the primary CPU bound.

Jump to

Keyboard shortcuts

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