Rule Engine¶
engine/RuleEngine.ts observes engine:action events and evaluates registered rules. A rule has a name, condition, priority, optional once behavior, and a sequence that can be a Script, an action, an action array, or a function.
Rules that fire once store their fired state in the replicated document (doc.rules.fired) through the rule:markFired action. This makes the one-time decision visible to peers and durable across persistence. The rule engine is a strategy layer; it does not replace action validation or provide an authority boundary.
Rules and policies should be written so their decisions are deterministic from replicated state where possible. If a rule dispatches follow-up actions, those actions return through the same asynchronous Engine dispatch path.