/** * rules.ts, the v1 predicate set, evaluated as pure functions over the state * ring buffer each trigger already persists. * * Every rule takes (observations, ruleState, now) and returns a decision plus * the next rule state. Nothing here does I/O, nothing here holds a timer, and * nothing here mutates its input, which is what makes the whole set testable * without a running daemon and safe to re-evaluate after a restart. * * The nine rules: * change value differs from the previous observation * value comparison against a fixed operand (edge or level) * transition one specific previous -> current pair * threshold enter/exit band, so a value hovering on the line * cannot flap the trigger (hysteresis) * debounce-n inner rule must match N consecutive checks * dedup-ttl inner rule fires at most once per fingerprint per TTL * rate-of-change delta across a time window, per second or per minute * windowed-aggregate min/max/mean/sum/count/stddev over a time window * correlation other triggers' fires inside a window, read from the * bounded shared event log */ import type { ComparisonOperator, TriggerEventLogEntry, TriggerObservation, TriggerRule, TriggerRuleState, TriggerValue } from './types.js'; export interface RuleEvaluationContext { /** Newest last. The rule reads whatever depth the ring buffer retains. */ readonly observations: readonly TriggerObservation[]; readonly ruleState: TriggerRuleState; readonly now: number; /** Bounded shared event log, the only channel correlation can read. */ readonly eventLog: readonly TriggerEventLogEntry[]; /** Excluded from its own correlation window. */ readonly selfTriggerId: string; } export interface RuleDecision { readonly fire: boolean; readonly ruleState: TriggerRuleState; /** Human-readable why, recorded on the run record either way. */ readonly reason: string; /** Identity used by dedup-ttl and by the shared event log. */ readonly fingerprint: string; } export declare function compare(operator: ComparisonOperator, left: TriggerValue, right: TriggerValue): boolean; /** Evaluates one rule. Pure: same inputs, same decision, no side effects. */ export declare function evaluateRule(rule: TriggerRule, context: RuleEvaluationContext): RuleDecision; //# sourceMappingURL=rules.d.ts.map