/** * # Genuine content-addressed hash over canonical FlowIR * * This is pi-taskflow's **own** content-addressed hash (Q5=own) over the * canonical {@link FlowIR} type contract defined in `./schema.ts`. Unlike * `./hash.ts`'s `flowDefHash` — which fingerprints the *DSL Taskflow * definition* (vendored from overstory, async Web Crypto, truncated to 16 * bytes / 32 hex) — this module hashes the *compiled IR* synchronously with * `node:crypto` SHA-256 (full 64-hex-char digest). The two answer different * questions: * * - `flowDefHash(def)` — "did the *flow definition* change?" (DSL-level) * - `hashFlowIR(ir)` — "is this *compiled IR* the same IR?" (IR-level) * * Wired into `compileTaskflowToIR` via `hashFlowIR` (`ir:<64-hex>`). * The IR-level hash is the content-addressed key the event-sourced kernel * (batch 2, `flowir/compile.ts`) will use to deduplicate compiled graphs and * to key per-phase fingerprints (`hashNode`) independent of surface formatting. * * ## Canonicalization guarantees * * {@link canonicalizeFlowIR} produces a DETERMINISTIC serialization that is * invariant under the cosmetic differences two logically-equivalent IRs may * differ by: * * - **Object key order** — all object keys are stable-sorted (UTF-16 code * units), so reordering fields on a node or on the IR object does not * change the canonical form. * - **Node array order** — `nodes` is re-sorted by `id` (stable), so two IRs * that list the same nodes in different order canonicalize identically. * Other arrays (`inject`, `emits`, `deps`, `edges`) keep their order — * their ordering is semantically meaningful (declared-read order, edge * declaration order) and must be preserved. * - **Condition spelling** — a node's `when` guard is canonicalized via * {@link normalizeCond} (`./cond.ts`), which collapses whitespace, operator * spacing, and redundant enclosing parens while preserving string-literal * contents. Equivalent conditions canonicalize identically. * - **Insignificant formatting** — `undefined` optional fields are dropped, * so their presence/absence does not change the hash. * * Two logically-equivalent FlowIRs (key reorder, whitespace, equivalent * condition spelling) MUST canonicalize to the same string. * * ## Domain-separated digests * * Return values are prefixed: * - `hashFlowIR` → `ir:<64-hex>` * - `hashNode` → `node:<64-hex>` * * so IR-level and node-level digests never collide in a shared cache key * namespace. * * ## Purity * * Zero runtime deps besides `node:crypto`. No IO, no `Date`, no randomness, * never throws. The hash is synchronous (unlike `flowDefHash`). * * Exported from the FlowIR barrel (`./index.ts`) for consumers; **not yet * wired** into runtime/cache — `usedFallbackHash` is untouched. Wiring * happens in batch 2. * * @see ./schema.ts for the canonical FlowIR type contract. * @see ./cond.ts for condition normalization (`normalizeCond`). * @see ./hash.ts for the DSL-level `flowDefHash` (vendored from overstory). */ import type { FlowIR, FlowIRNode } from "./schema.ts"; /** * Deterministic, order- and whitespace-independent canonical serialization of * a {@link FlowIR}. * * - `nodes` is re-sorted by `id` (stable) so node-list order does not affect * the result. * - Each node's `when` guard is canonicalized via {@link normalizeCond}. * - All object keys are stable-sorted; `undefined` optionals are dropped. * - `inject`/`emits`/`deps`/`edges` arrays keep their order (semantic). * * Two logically-equivalent FlowIRs MUST canonicalize to the same string. * Never throws. */ export declare function canonicalizeFlowIR(ir: FlowIR): string; /** * Deterministic canonical serialization of a single {@link FlowIRNode}, for * per-node content addressing. Same canonicalization rules as * {@link canonicalizeFlowIR} applied to one node (`when` normalized, keys * sorted, `undefined` optionals dropped, `inject`/`emits`/`deps` order * preserved). Never throws. */ export declare function canonicalizeNode(node: FlowIRNode): string; /** * Domain-separated content hash of a compiled FlowIR. * Returns `ir:<64 lowercase hex SHA-256 chars>` over {@link canonicalizeFlowIR}. * Synchronous. Never throws. */ export declare function hashFlowIR(ir: FlowIR): string; /** * Domain-separated per-node content hash. * Returns `node:<64 lowercase hex SHA-256 chars>` over {@link canonicalizeNode}. * Synchronous. Never throws. */ export declare function hashNode(node: FlowIRNode): string; //# sourceMappingURL=canonical-hash.d.ts.map