/** * Invariant evaluator. * * A block's `invariants` are free-form assertions (e.g. `"approval_rate_pct <= 100"`, * `"health_score between 0 and 100"`, `"arr >= 0"`) that must hold for the block's * result set. Until now they were stored in the manifest and surfaced to agents as * prompt grounding, but never executed — so "certified" did not mean "the stated * guarantees hold". * * This module parses each invariant string into a checkable predicate over result * columns and evaluates it against the block's result rows. It is a SMALL, SAFE * evaluator: it never calls `eval()` / `Function()`. Anything it cannot parse is * reported as an "uncheckable invariant" warning rather than failing closed. * * Supported forms (case-insensitive on keywords): * - comparisons: ` ` where op is `>= <= > < == = != <>` * - between: ` between and ` (inclusive) * - not between: ` not between and ` * - null checks: ` is null` / ` is not null` * - non-negative etc. handled by the comparison form (`arr >= 0`). * * The column is checked across EVERY row; a single-value result is just one row. * An invariant passes only if it holds for all rows. The first violating row is * reported in `detail` so the failure is actionable. */ /** Outcome of evaluating a single invariant against a result set. */ export interface InvariantResult { /** The original invariant expression string, verbatim. */ expr: string; /** True when the invariant held for every row (or was vacuously true for an empty result). */ passed: boolean; /** * True when the invariant string could not be parsed into a checkable predicate. * Uncheckable invariants do NOT count as violations — they are surfaced as * warnings so authors can fix the wording. `passed` is true for these so they * never block certification. */ uncheckable?: boolean; /** Human-readable explanation of the pass / fail / uncheckable outcome. */ detail: string; } /** A minimal, column/row-shaped view of a block result the evaluator can read. */ export interface InvariantResultSet { /** Column names present in the result. */ columns: string[]; /** Result rows keyed by column name. A scalar result is a single row. */ rows: Array>; } type Comparator = '>=' | '<=' | '>' | '<' | '==' | '!='; interface ComparisonPredicate { kind: 'comparison'; column: string; op: Comparator; value: number; } interface BetweenPredicate { kind: 'between'; column: string; low: number; high: number; negated: boolean; } interface NullPredicate { kind: 'null'; column: string; negated: boolean; } type Predicate = ComparisonPredicate | BetweenPredicate | NullPredicate; interface ParseFailure { kind: 'unparseable'; reason: string; } type ParseOutcome = Predicate | ParseFailure; /** * Parse a single invariant string into a checkable predicate, or a parse failure * describing why it is uncheckable. Pure / side-effect free. */ export declare function parseInvariant(raw: string): ParseOutcome; /** * Evaluate a single invariant string against a result set. * * Always returns an {@link InvariantResult}; it never throws. Unparseable * invariants and references to missing columns are reported as `uncheckable` * (passed = true) so they warn rather than block. */ export declare function evaluateInvariant(raw: string, result: InvariantResultSet): InvariantResult; /** * Evaluate every invariant in `invariants` against `result`. Order-preserving. * Returns an empty array for an empty / undefined invariant list, so callers can * treat "no invariants" as "nothing to enforce". */ export declare function evaluateInvariants(invariants: string[] | undefined, result: InvariantResultSet): InvariantResult[]; /** True when any of the supplied results is a real (checkable) violation. */ export declare function hasInvariantViolation(results: InvariantResult[] | undefined): boolean; export {}; //# sourceMappingURL=invariant-evaluator.d.ts.map