/** * Patch Evaluation * * Evaluates ConditionalPatchOp[] to produce concrete schema operations. * * @see SPEC v0.4.0 §18.5, §18.6 */ import type { ExprNode as CoreExprNode } from "@manifesto-ai/core"; import type { ConditionalPatchOp, LoweredPatchOp } from "../lowering/lower-patch.js"; import type { EvaluationContext, EvaluationSnapshot } from "./context.js"; /** * Evaluated schema patch operation. * * All conditions have been evaluated and values resolved where appropriate. * Expressions in addComputed, addConstraint, addActionAvailable are preserved * for runtime evaluation by Core. */ export type EvaluatedPatchOp = LoweredPatchOp; /** * Result of evaluating a conditional patch. */ export interface EvaluatedPatch { /** * Fragment identifier (for tracing). */ fragmentId: string; /** * The evaluated operation. */ op: EvaluatedPatchOp; /** * Confidence (preserved from fragment). */ confidence: number; /** * Whether condition was evaluated (true) or there was no condition. */ conditionEvaluated: boolean; } /** * Result of patch evaluation. */ export interface PatchEvaluationResult { /** * Patches that passed their conditions. */ patches: EvaluatedPatch[]; /** * Patches that were skipped due to false/null conditions. */ skipped: Array<{ fragmentId: string; reason: "false" | "null" | "non-boolean"; }>; /** * Final working snapshot after all evaluations. */ finalSnapshot: EvaluationSnapshot; } /** * Evaluate conditional patch operations. * * Implements sequential evaluation semantics: later patches see effects * of earlier patches via working snapshot. * * Conditions are boolean-only: true applies, false/null/non-boolean skips. * * @param ops - Conditional patch operations from lowering phase * @param ctx - Initial evaluation context * @returns Evaluation result with applied and skipped patches * * @see SPEC v0.4.0 §18.5, FDR-MEL-070, FDR-MEL-073 */ export declare function evaluateConditionalPatchOps(ops: ConditionalPatchOp[], ctx: EvaluationContext): PatchEvaluationResult; /** * Simple evaluation: returns patches that pass conditions. * * Does not track skipped patches or maintain sequential semantics. * Use this for stateless condition evaluation. * * @param ops - Conditional patch operations * @param ctx - Evaluation context * @returns Patches that passed their conditions */ export declare function evaluatePatches(ops: ConditionalPatchOp[], ctx: EvaluationContext): EvaluatedPatch[]; /** * Evaluate expressions in a patch operation to concrete values. * * Use this when you need fully concrete values (no expressions). * * Note: addComputed.expr, addConstraint.rule, and addActionAvailable.expr * are meant to remain as expressions for runtime evaluation by Core. * * @param op - Lowered patch operation * @param ctx - Evaluation context * @returns Patch operation with evaluated expressions */ export declare function evaluatePatchExpressions(op: LoweredPatchOp, _ctx: EvaluationContext): LoweredPatchOp; /** * Check if a condition evaluates to true. * * Boolean-only: only true returns true. * false, null, and non-boolean values return false. * * @param condition - Condition expression (or undefined for always-true) * @param ctx - Evaluation context * @returns True if condition passes * * @see FDR-MEL-073 */ export declare function evaluateCondition(condition: CoreExprNode | undefined, ctx: EvaluationContext): boolean; /** * Classify a condition evaluation result. * * @param condition - Condition expression * @param ctx - Evaluation context * @returns Classification of condition result */ export declare function classifyCondition(condition: CoreExprNode | undefined, ctx: EvaluationContext): { passes: boolean; reason: "no-condition" | "true" | "false" | "null" | "non-boolean"; };