/** * Canonical normalization of `when` / `until` / `eval` condition expressions. * * This is the **condition-IR seam** of the overstory-convergence roadmap's * FlowIR compiler: it lifts a raw condition string into a stable * {@link NormalizedCond} descriptor that two future consumers share: * * - **Hashing** (consumer a): structurally-equivalent conditions MUST * normalize to the same `canonical` string so they fold identically into * the FlowIR content hash (whitespace, operator spacing, and redundant * enclosing parens do not change meaning → must not change the hash). * - **Deterministic replay** (consumer b): the `when-guard` decision is * re-evaluated from the recorded expression; `refs` tells replay exactly * which `steps.*` / `args.*` / `env.*` inputs the guard read so it can * rebind them from the event log without token spend. * * **Single source of truth — no semantic drift.** The condition grammar * (tokenizer + recursive-descent parser + comparison/truthiness semantics) * lives in {@link ../interpolate.ts}. This module REUSES that parser by * delegating parse-validation (and fail-open semantics) to * {@link tryEvaluateCondition} — it does NOT duplicate or reimplement the * tokenizer/parser. If the parser accepts an expression, it is structurally * valid and we normalize its surface text; if the parser rejects it, we * fail open (see {@link normalizeCond}) so a broken guard never silently * drops a phase — matching the project's fail-open-for-guards invariant. * * The `canonical` form is a surface normalization (whitespace removal + * redundant enclosing-paren stripping with string-literal contents * preserved), not a full AST rewrite: for valid expressions whitespace only * separates tokens, so removing it (after protecting quoted literals) yields * a stable concatenation that is invariant under the cosmetic differences * hashing cares about. Reference extraction runs on the **literal-protected** * surface so `{steps.*}` text inside string literals is never treated as a * real dependency. * * Pure module: no IO, no `Date`, no randomness, never throws. * * @see docs/rfc-0.2.0-architecture.md §5.4 (`flowir/cond.ts` — 条件归一化) * @see ../interpolate.ts for the shared condition parser (tokenize / CondParser / compare / tryEvaluateCondition) */ /** * A condition expression lifted into a stable, hashable descriptor. * * - `source` — the original expression text, verbatim (never normalized). * - `canonical` — a stable normalized surface form: whitespace-collapsed, * operator-spacing-invariant, redundant enclosing parens stripped, with * quoted-string contents preserved. Structurally-equivalent expressions * produce byte-identical `canonical` strings. * - `refs` — the `steps.…` / `args.…` / `env.…` references * the expression reads (in first-occurrence order, de-duplicated). Empty * when the expression failed to parse (fail-open). Placeholders that only * appear inside string literals are **not** counted as refs. */ export interface NormalizedCond { source: string; canonical: string; refs: string[]; } /** * Normalize a `when` / `until` / `eval` condition expression. * * The expression is parsed (validated) by reusing the shared condition * parser in {@link ../interpolate.ts} via {@link tryEvaluateCondition}; on a * parse error this **fails open** — returning `{ source, canonical: * source.trim(), refs: [] }` — so a malformed guard is never silently * dropped and never crashes a compile/replay pass. This mirrors the * project's fail-open-for-guards invariant (`when` parse errors → phase * still runs). Never throws. * * On success, `canonical` is the whitespace/paren-normalized surface form * (stable for hashing) and `refs` are the `steps.*` / `args.*` / `env.*` * references the expression reads (for replay rebinding). Placeholders that * only appear inside string literals are excluded from `refs`. */ export declare function normalizeCond(expr: string): NormalizedCond; //# sourceMappingURL=cond.d.ts.map