@nagi-js/core 0.1.0 → 0.1.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -104,7 +104,7 @@ interface StepConfigBase<Input, N extends NeedsMap> {
104
104
  readonly input: NoInfer<Input>;
105
105
  readonly needs: NoInfer<NeedsOutputs<N>>;
106
106
  }) => boolean;
107
- readonly timeout?: Millis;
107
+ readonly timeoutMs?: Millis;
108
108
  }
109
109
  interface TaskConfig<Input, N extends NeedsMap, Output> extends StepConfigBase<Input, N> {
110
110
  readonly retry?: RetryPolicy;
@@ -129,7 +129,7 @@ interface MatchDiscriminatorConfig<Input, N extends NeedsMap, D extends string,
129
129
  readonly needs: NoInfer<NeedsOutputs<N>>;
130
130
  }) => D;
131
131
  readonly cases: {
132
- readonly [K in D]: (b: Builder<Input>) => M[K];
132
+ readonly [K in D]: (b: Builder<Input>) => BuildResult<Input, M[K]>;
133
133
  };
134
134
  }
135
135
  interface MatchArmGuard<Input, N extends NeedsMap, M extends StepMap> {
@@ -138,12 +138,12 @@ interface MatchArmGuard<Input, N extends NeedsMap, M extends StepMap> {
138
138
  readonly needs: NoInfer<NeedsOutputs<N>>;
139
139
  }) => boolean;
140
140
  readonly otherwise?: never;
141
- readonly build: (b: Builder<Input>) => M;
141
+ readonly build: (b: Builder<Input>) => BuildResult<Input, M>;
142
142
  }
143
143
  interface MatchArmOtherwise<Input, M extends StepMap> {
144
144
  readonly otherwise: true;
145
145
  readonly when?: never;
146
- readonly build: (b: Builder<Input>) => M;
146
+ readonly build: (b: Builder<Input>) => BuildResult<Input, M>;
147
147
  }
148
148
  type MatchArm<Input, N extends NeedsMap, M extends StepMap> = MatchArmGuard<Input, N, M> | MatchArmOtherwise<Input, M>;
149
149
  /**
@@ -158,11 +158,11 @@ type MatchArmShape<Input, N extends NeedsMap> = {
158
158
  readonly needs: NoInfer<NeedsOutputs<N>>;
159
159
  }) => boolean;
160
160
  readonly otherwise?: never;
161
- readonly build: (b: Builder<Input>) => StepMap;
161
+ readonly build: (b: Builder<Input>) => BuildResult<Input, StepMap>;
162
162
  } | {
163
163
  readonly otherwise: true;
164
164
  readonly when?: never;
165
- readonly build: (b: Builder<Input>) => StepMap;
165
+ readonly build: (b: Builder<Input>) => BuildResult<Input, StepMap>;
166
166
  };
167
167
  /**
168
168
  * Guard mode — Rust-style `match { x if guard => ... }`. Top-to-bottom,
@@ -182,14 +182,52 @@ type MatchDiscriminatorOutput<D extends string, M extends Record<D, StepMap>> =
182
182
  [K in D]: MatchArmOutput<M[K]>;
183
183
  }[D];
184
184
  /**
185
- * `b` inside `flow({ build: (b) => ... })`. Constructors return `Step<Output>`
186
- * values whose Output has been inferred from the handler / schema / arms.
185
+ * Per-entry config for `b.step(key, config)`. `Needs` is a const tuple of
186
+ * sibling keys that resolve against the chain's accumulator `A`.
187
187
  */
188
- interface Builder<Input = unknown> {
188
+ interface StepEntryConfig<Input, A extends Record<string, unknown>, Needs extends ReadonlyArray<keyof A & string>, Output> {
189
+ readonly needs?: Needs;
190
+ readonly retry?: RetryPolicy;
191
+ readonly timeoutMs?: Millis;
192
+ readonly when?: (args: {
193
+ readonly input: NoInfer<Input>;
194
+ readonly needs: {
195
+ readonly [P in Needs[number]]: A[P];
196
+ };
197
+ }) => boolean;
198
+ readonly run: (args: {
199
+ readonly input: NoInfer<Input>;
200
+ readonly needs: {
201
+ readonly [P in Needs[number]]: A[P];
202
+ };
203
+ readonly ctx: StepCtx<NoInfer<Input>>;
204
+ }) => Promise<Output>;
205
+ }
206
+ /**
207
+ * `b` inside `flow({ build: (b) => ... })`.
208
+ *
209
+ * Two complementary authoring styles:
210
+ *
211
+ * 1. **Standalone constructors** — `b.task`, `b.signal`, `b.match` each
212
+ * return a `Step<Output>` value the user can assign and reference. The
213
+ * build callback returns a `StepMap` of those values.
214
+ *
215
+ * 2. **Chain (key-first)** — `b.step(key, config)` is keyed and chainable.
216
+ * Each call extends the builder's accumulator `A` with `{ [Key]: Output }`,
217
+ * and subsequent `.step()` calls type `needs: ["sibling"]` against `A`.
218
+ * `b.include(key, prebuiltStep)` brings a `Step<O>` (from `b.task` /
219
+ * `b.signal` / `b.match`) into the chain under a key. The chain itself
220
+ * is returned from the build callback; `flow()` extracts the accumulator.
221
+ *
222
+ * Both styles compose in the same build callback — the chain end is the
223
+ * canonical result; pre-built standalone steps enter the chain via
224
+ * `.include(key, step)`.
225
+ */
226
+ interface Builder<Input = unknown, A extends Record<string, unknown> = Record<never, never>> {
189
227
  task<N extends NeedsMap, Output>(config: TaskConfig<Input, N, Output>): Step<Output>;
190
228
  signal<N extends NeedsMap, S extends StandardSchemaV1>(config: SignalConfig<Input, N, S>): Step<InferSchemaOutput<S>>;
191
229
  match<N extends NeedsMap, D extends string, Cases extends {
192
- readonly [K in D]: (b: Builder<Input>) => StepMap;
230
+ readonly [K in D]: (b: Builder<Input>) => BuildResult<Input, StepMap>;
193
231
  }>(config: {
194
232
  readonly needs?: N;
195
233
  readonly on: (args: {
@@ -198,27 +236,66 @@ interface Builder<Input = unknown> {
198
236
  }) => D;
199
237
  readonly cases: Cases;
200
238
  }): Step<{
201
- readonly [K in keyof Cases]: MatchArmOutput<ReturnType<Cases[K]>>;
239
+ readonly [K in keyof Cases]: MatchArmOutput<AsStepMap<ReturnType<Cases[K]>>>;
202
240
  }[keyof Cases]>;
203
241
  match<N extends NeedsMap, Arms extends ReadonlyArray<MatchArmShape<Input, N>>>(config: {
204
242
  readonly needs?: N;
205
243
  readonly arms: Arms;
206
- }): Step<MatchArmOutput<ReturnType<Arms[number]["build"]>>>;
244
+ }): Step<MatchArmOutput<AsStepMap<ReturnType<Arms[number]["build"]>>>>;
245
+ /**
246
+ * Chainable task definition. The first arg is the persisted step id; the
247
+ * config follows the standalone `task` shape plus a `needs: ["sibling"]`
248
+ * tuple of accumulator keys. Returns the same builder typed with the new
249
+ * entry appended to `A`.
250
+ *
251
+ * b.step('fetchRecording', { run: async () => ({ url: '…' }) })
252
+ * .step('transcribe', {
253
+ * needs: ['fetchRecording'],
254
+ * run: async ({ needs }) => ({ text: needs.fetchRecording.url + '…' }),
255
+ * })
256
+ */
257
+ step<const Key extends string, const Needs extends ReadonlyArray<keyof A & string>, Output>(key: Exclude<Key, keyof A>, config: StepEntryConfig<Input, A, Needs, Output>): Builder<Input, A & {
258
+ readonly [K in Key]: Output;
259
+ }>;
260
+ /**
261
+ * Include a pre-built `Step<O>` (from `b.task` / `b.signal` / `b.match`)
262
+ * into the chain under a key. The included step's output joins `A`.
263
+ */
264
+ include<const Key extends string, S extends Step<unknown>>(key: Exclude<Key, keyof A>, step: S): Builder<Input, A & {
265
+ readonly [K in Key]: S extends Step<infer O> ? O : never;
266
+ }>;
207
267
  }
208
- interface FlowConfig<Id extends string, InputSchema extends StandardSchemaV1, M extends StepMap, Output = unknown> {
268
+ /**
269
+ * Acceptable shape for a build callback's return. Either a plain `StepMap`
270
+ * (record-literal style) or a `Builder<Input, A>` whose accumulator is
271
+ * extracted by `flow()`.
272
+ */
273
+ type BuildResult<Input, M extends StepMap> = M | Builder<Input, BuilderAccumulator<M>>;
274
+ /** Convert a `StepMap` back to its accumulator shape `{ [K]: Output }`. */
275
+ type BuilderAccumulator<M extends StepMap> = {
276
+ readonly [K in keyof M]: M[K] extends Step<infer O> ? O : never;
277
+ };
278
+ /** Extract a `StepMap` from either a plain map or a `Builder` chain result. */
279
+ type AsStepMap<R> = R extends Builder<unknown, infer A> ? {
280
+ readonly [K in keyof A]: Step<A[K]>;
281
+ } : R extends StepMap ? R : never;
282
+ interface FlowConfig<Id extends string, InputSchema extends StandardSchemaV1, R, Output = unknown> {
209
283
  /** Stable persistence handle. TanStack-key shaped (kebab or snake). */
210
284
  readonly id: Id;
211
285
  readonly input: InputSchema;
212
- readonly build: (b: Builder<InferSchemaOutput<InputSchema>>) => M;
286
+ /**
287
+ * Returns either a `StepMap` (record-literal style with `b.task` / `b.signal`
288
+ * / `b.match`) or a chained `Builder<Input, A>` (Express-style with `b.step`
289
+ * / `b.include`). `flow()` extracts the assembled `StepMap` either way.
290
+ */
291
+ readonly build: (b: Builder<InferSchemaOutput<InputSchema>>) => R;
213
292
  /**
214
293
  * Compute the flow's terminal output from its step outputs. Fired once at
215
294
  * `flow.completed` and persisted on the fact + `onFlowComplete` event.
216
295
  * Skipped steps land as `null` in the input record at runtime even though
217
296
  * the type claims otherwise (consistent with the "skip is transitive" lock).
218
- * Method-shorthand syntax keeps `M` bivariant so `Flow<Id, S, M, O>` remains
219
- * assignable to `Flow<string, S, StepMap, O>` in fixture/test code.
220
297
  */
221
- output?(steps: NeedsOutputs<M>): Output;
298
+ output?(steps: NeedsOutputs<AsStepMap<R>>): Output;
222
299
  }
223
300
  interface Flow<Id extends string = string, InputSchema extends StandardSchemaV1 = StandardSchemaV1, M extends StepMap = StepMap, Output = unknown> {
224
301
  readonly id: Id;
@@ -386,6 +463,48 @@ interface Store {
386
463
  readonly output: T;
387
464
  readonly fact: StepCompletedFact | StepFailedFact;
388
465
  }>): Promise<T>;
466
+ /**
467
+ * Deduped store of canonical flow DAGs, keyed by content hash. Inserts are
468
+ * idempotent — the same `(flowHash, dag)` may be written by many concurrent
469
+ * boots; only the first physical row survives. Subsequent writes are
470
+ * no-ops.
471
+ *
472
+ * Adapters MUST enforce this at the durability layer (e.g. Postgres
473
+ * `INSERT ... ON CONFLICT (flow_hash) DO NOTHING`).
474
+ */
475
+ upsertSnapshot(args: {
476
+ readonly flowHash: string;
477
+ readonly flowId: string;
478
+ readonly dag: Json;
479
+ }): Promise<void>;
480
+ /**
481
+ * Read the currently-published hash for a flow id. Returns `null` if no
482
+ * `flow_ref` row exists yet — first boot of a never-published flow.
483
+ */
484
+ getRef(flowId: string): Promise<string | null>;
485
+ /**
486
+ * Atomically set the published hash for a flow id. Last writer wins; the
487
+ * audit trail of ref changes lives in {@link appendGlobalFact} as
488
+ * `flow_ref.updated`.
489
+ *
490
+ * Adapters MUST enforce atomicity at the durability layer (e.g. Postgres
491
+ * `INSERT ... ON CONFLICT (flow_id) DO UPDATE`).
492
+ */
493
+ setRef(flowId: string, flowHash: string): Promise<void>;
494
+ /**
495
+ * Load a snapshot by its content hash. Returns `null` if no snapshot with
496
+ * this hash has been recorded — e.g., the deployment is replaying a run
497
+ * whose pinned topology was never seen by this store.
498
+ */
499
+ loadSnapshot(flowHash: string): Promise<{
500
+ readonly flowId: string;
501
+ readonly dag: Json;
502
+ } | null>;
503
+ /**
504
+ * Append a non-run-scoped fact. See {@link GlobalFact} for the union.
505
+ * Currently only `flow_ref.updated` events flow through this method.
506
+ */
507
+ appendGlobalFact(fact: GlobalFact): Promise<void>;
389
508
  }
390
509
  interface QueueMessage {
391
510
  readonly receipt: string;
@@ -439,7 +558,39 @@ interface FlowStartedFact extends FactBase {
439
558
  readonly kind: "flow.started";
440
559
  readonly flowId: string;
441
560
  readonly input: Json;
561
+ /**
562
+ * Content hash of the canonical flow DAG at the moment this run started.
563
+ * Pins the run to a specific topology; `wf.replay()` reads this to detect
564
+ * snapshot drift. Optional in v0 — legacy runs from before the snapshot
565
+ * store landed have `undefined`. After a soak period it becomes required.
566
+ */
567
+ readonly flowHash?: string;
568
+ /**
569
+ * Free-form handler-code identifier, typically a git SHA. Sourced from
570
+ * `nagi({ codeVersion })`. Captures handler-source drift orthogonally to
571
+ * `flowHash` (which only captures topology). See RFC 0001
572
+ * "Topology vs handler code."
573
+ */
574
+ readonly codeVersion?: string;
442
575
  }
576
+ /**
577
+ * A non-run-scoped event, recorded as a side effect of nagi runtime activity
578
+ * that has no specific `runId`. Lives in the `nagi.global_fact` table.
579
+ *
580
+ * Per RFC 0001: when nagi boots and a flow's canonical hash differs from the
581
+ * currently-published one, the runtime updates `flow_ref` and appends a
582
+ * `flow_ref.updated` global fact. The audit trail of ref changes is queryable
583
+ * independently of any single run.
584
+ */
585
+ interface FlowRefUpdatedFact {
586
+ readonly kind: "flow_ref.updated";
587
+ readonly flowId: string;
588
+ /** Previous hash, or null when this is the first publish of `flowId`. */
589
+ readonly from: string | null;
590
+ readonly to: string;
591
+ readonly at: Date;
592
+ }
593
+ type GlobalFact = FlowRefUpdatedFact;
443
594
  interface FlowCompletedFact extends FactBase {
444
595
  readonly kind: "flow.completed";
445
596
  readonly output: Json;
@@ -513,10 +664,23 @@ interface RunState {
513
664
  readonly status: RunStatus;
514
665
  readonly steps: Readonly<Record<StepId, StepState>>;
515
666
  readonly facts: ReadonlyArray<Fact>;
667
+ /** Content hash of the canonical flow DAG this run is pinned to. */
668
+ readonly flowHash?: string;
669
+ /** Handler-code identifier (typically a git SHA) recorded at run start. */
670
+ readonly codeVersion?: string;
516
671
  }
517
672
  type ReplayMode = "inspect" | "continue";
518
673
  interface ReplayOpts {
519
674
  readonly mode: ReplayMode;
675
+ /**
676
+ * When true, allow replays to proceed even if the live flow's canonical
677
+ * hash differs from the snapshot pinned to the run. Scheduling decisions
678
+ * come from the pinned snapshot; handler bodies are resolved from the
679
+ * currently-registered flow by step id (best-effort).
680
+ *
681
+ * When false (default), drift throws `NagiSnapshotDriftError`.
682
+ */
683
+ readonly allowDrift?: boolean;
520
684
  }
521
685
 
522
686
  /**
@@ -535,7 +699,115 @@ interface ReplayOpts {
535
699
  * 4. Promote `MatchArmDef._nested` → `MatchArmDef.stepIds` (the namespaced
536
700
  * IDs of the arm's nested steps), then drop `_nested`.
537
701
  */
538
- declare function flow<const Id extends string, InputSchema extends StandardSchemaV1, M extends StepMap, Output = unknown>(config: FlowConfig<Id, InputSchema, M, Output>): Flow<Id, InputSchema, M, Output>;
702
+ declare function flow<const Id extends string, InputSchema extends StandardSchemaV1, R, Output = unknown>(config: FlowConfig<Id, InputSchema, R, Output>): Flow<Id, InputSchema, AsStepMap<R>, Output>;
703
+
704
+ /**
705
+ * Canonical retry shape. Defaults are materialized explicitly so equivalent
706
+ * retry configs hash identically regardless of source-side omission style.
707
+ * `retryOn` is dropped — it's a function, not serializable.
708
+ */
709
+ interface CanonicalRetryPolicy {
710
+ readonly maxAttempts: number;
711
+ readonly backoff: BackoffStrategy;
712
+ readonly initialDelayMs: Millis;
713
+ readonly maxDelayMs: Millis;
714
+ }
715
+ /**
716
+ * Canonical schema fingerprint. v0 hashes `validate.toString()` alongside
717
+ * runtime-stable `vendor` + `version` — best-effort, breaks under minification.
718
+ * Documented as a known limit in RFC 0001.
719
+ */
720
+ interface CanonicalSchema {
721
+ readonly vendor: string;
722
+ readonly version: number;
723
+ readonly validateHash: string;
724
+ }
725
+ interface CanonicalMatchArm {
726
+ readonly id: string;
727
+ readonly otherwise?: true;
728
+ readonly whenHash?: string;
729
+ /** Namespaced IDs of nested steps for this arm, sorted lexicographically. */
730
+ readonly stepIds: readonly StepId[];
731
+ }
732
+ interface CanonicalStep {
733
+ readonly id: StepId;
734
+ readonly kind: StepKind;
735
+ /** Upstream step ids the step depends on, sorted lexicographically. */
736
+ readonly needs: readonly StepId[];
737
+ readonly whenHash?: string;
738
+ readonly retry?: CanonicalRetryPolicy;
739
+ readonly timeoutMs?: Millis;
740
+ readonly signalSchema?: CanonicalSchema;
741
+ readonly matchMode?: "discriminator" | "guard";
742
+ readonly matchOnHash?: string;
743
+ readonly matchArms?: readonly CanonicalMatchArm[];
744
+ }
745
+ interface CanonicalDag {
746
+ readonly flowId: string;
747
+ readonly inputSchema: CanonicalSchema;
748
+ /** Steps sorted by `id` lexicographically — insertion order is ignored. */
749
+ readonly steps: readonly CanonicalStep[];
750
+ }
751
+ /**
752
+ * Build the canonical DAG for a flow.
753
+ *
754
+ * Stable across cosmetic source changes (step-key reorder, needs-key reorder)
755
+ * and different across topology changes (added/removed steps, edge changes,
756
+ * `when` flips, retry edits, timeout edits).
757
+ *
758
+ * Handler `run` bodies are intentionally NOT part of the hash — see RFC 0001
759
+ * "Topology vs handler code." Use `nagi({ codeVersion })` (typically a git
760
+ * SHA) to capture handler-code drift orthogonally.
761
+ *
762
+ * Async because predicate/schema source bodies are sha256'd via
763
+ * `crypto.subtle` so the stored `dag` JSON stays compact.
764
+ */
765
+ declare function canonicalize(flow: Flow): Promise<CanonicalDag>;
766
+ /**
767
+ * Compute the sha256 hex digest of a canonical DAG. Uses Web Crypto
768
+ * (`crypto.subtle.digest`) which is available in Node ≥ 19, modern browsers,
769
+ * Cloudflare Workers, Deno, and Bun.
770
+ *
771
+ * The DAG is serialized via {@link stableStringify} so object-key order is
772
+ * deterministic. Two equivalent DAGs produce byte-identical input bytes.
773
+ */
774
+ declare function sha256Canonical(dag: CanonicalDag): Promise<string>;
775
+
776
+ /** Fields on a step whose hash-relevant value can change between snapshots. */
777
+ type SnapshotChangedField = "kind" | "when" | "retry" | "timeoutMs" | "signalSchema" | "matchMode" | "matchOn" | "matchArms";
778
+ interface SnapshotChangedEdge {
779
+ readonly from: StepId;
780
+ readonly to: StepId;
781
+ readonly before: "needed" | "absent";
782
+ readonly after: "needed" | "absent";
783
+ }
784
+ interface SnapshotChangedField_ {
785
+ readonly stepId: StepId;
786
+ readonly field: SnapshotChangedField;
787
+ }
788
+ /**
789
+ * Structural delta between two snapshots — added/removed steps, added/removed
790
+ * edges, per-field topology changes on shared steps.
791
+ *
792
+ * Pure function over canonical DAGs. The output mirrors the RFC 0001 shape:
793
+ *
794
+ * {
795
+ * addedSteps,
796
+ * removedSteps,
797
+ * changedEdges, // append-or-remove edges between shared steps
798
+ * changedPredicates // when / retry / timeoutMs / schema / match changes
799
+ * }
800
+ *
801
+ * "Changed" means the canonical hash-relevant value differs. For predicates
802
+ * this is best-effort under the same source-hash limit as canonicalize.
803
+ */
804
+ interface SnapshotDiff {
805
+ readonly addedSteps: readonly StepId[];
806
+ readonly removedSteps: readonly StepId[];
807
+ readonly changedEdges: readonly SnapshotChangedEdge[];
808
+ readonly changedPredicates: readonly SnapshotChangedField_[];
809
+ }
810
+ declare function diffSnapshots(before: CanonicalDag, after: CanonicalDag): SnapshotDiff;
539
811
 
540
812
  interface InMemoryStoreOpts {
541
813
  readonly leaseMs?: Millis;
@@ -545,6 +817,9 @@ declare class InMemoryStore implements Store {
545
817
  private readonly outputs;
546
818
  private readonly onces;
547
819
  private readonly leases;
820
+ private readonly snapshots;
821
+ private readonly refs;
822
+ private readonly globalFacts;
548
823
  private readonly leaseMs;
549
824
  constructor(opts?: InMemoryStoreOpts);
550
825
  appendFact(runId: RunId, fact: Fact): Promise<void>;
@@ -562,6 +837,20 @@ declare class InMemoryStore implements Store {
562
837
  readonly output: T;
563
838
  readonly fact: StepCompletedFact | StepFailedFact;
564
839
  }>): Promise<T>;
840
+ upsertSnapshot(args: {
841
+ readonly flowHash: string;
842
+ readonly flowId: string;
843
+ readonly dag: Json;
844
+ }): Promise<void>;
845
+ getRef(flowId: string): Promise<string | null>;
846
+ setRef(flowId: string, flowHash: string): Promise<void>;
847
+ loadSnapshot(flowHash: string): Promise<{
848
+ readonly flowId: string;
849
+ readonly dag: Json;
850
+ } | null>;
851
+ appendGlobalFact(fact: GlobalFact): Promise<void>;
852
+ /** Test-only: peek at the in-memory global fact log. */
853
+ readGlobalFacts(): ReadonlyArray<GlobalFact>;
565
854
  }
566
855
  /**
567
856
  * Project an append-only fact stream into a `RunState`. Public so adapters
@@ -624,6 +913,14 @@ interface NagiConfig {
624
913
  readonly hooks?: FlowHooks;
625
914
  readonly logger?: Logger;
626
915
  readonly defaultRetry?: RetryPolicy;
916
+ /**
917
+ * Handler-code identifier — typically a git SHA from `process.env.GIT_SHA`
918
+ * or your build's bundle hash. Persisted on `workflow_run.code_version` and
919
+ * on every `flow.started` fact for runs started by this process. Captures
920
+ * handler-body drift orthogonally to the topology hash. See RFC 0001
921
+ * "Topology vs handler code."
922
+ */
923
+ readonly codeVersion?: string;
627
924
  }
628
925
  interface StartOpts {
629
926
  /**
@@ -660,6 +957,22 @@ declare class NagiValidationError extends Error {
660
957
  declare class NagiRuntimeError extends Error {
661
958
  constructor(message: string);
662
959
  }
663
- declare function nagi(config: NagiConfig): Wf;
960
+ /**
961
+ * Thrown by `wf.replay(runId)` when the live flow's canonical hash differs
962
+ * from the snapshot the run was pinned to. The default replay behavior is
963
+ * fail-loud — pass `replayOpts.allowDrift = true` to proceed using a
964
+ * synthesized flow (topology from snapshot, handlers/predicates from live).
965
+ */
966
+ declare class NagiSnapshotDriftError extends Error {
967
+ readonly runId: RunId;
968
+ readonly expected: string;
969
+ readonly actual: string;
970
+ constructor(args: {
971
+ readonly runId: RunId;
972
+ readonly expected: string;
973
+ readonly actual: string;
974
+ });
975
+ }
976
+ declare function nagi(config: NagiConfig): Promise<Wf>;
664
977
 
665
- export { type AttemptNumber, type BackoffStrategy, type Builder, type ClaimToken, type Clock, type Fact, type FactKind, type Flow, type FlowCompleteEvent, type FlowCompletedFact, type FlowConfig, type FlowErrorEvent, type FlowEvent, type FlowFailedFact, type FlowHooks, type FlowInput, type FlowOutput, type FlowStartEvent, type FlowStartedFact, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, type InferSchemaInput, type InferSchemaOutput, type Json, type Logger, type MatchArm, type MatchArmGuard, type MatchArmOtherwise, type MatchArmOutput, type MatchArmSelectedFact, type MatchArmShape, type MatchDiscriminatorConfig, type MatchDiscriminatorOutput, type MatchGuardConfig, type Millis, type NagiConfig, NagiRuntimeError, NagiValidationError, type NeedsMap, type NeedsOutputs, type OnceRecordedFact, type Queue, type QueueDequeueOpts, type QueueEnqueueOpts, type QueueMessage, type Register, type ReplayMode, type ReplayOpts, type RetryPolicy, type RunId, type RunState, type RunStatus, type SerializedError, type SignalConfig, type SignalReceivedEvent, type SignalReceivedFact, type SignalSentEvent, type SignalSentFact, StandardSchemaV1, type StartOpts, type Step, type StepCompleteEvent, type StepCompletedFact, type StepCtx, type StepErrorEvent, type StepEvent, type StepFailedFact, type StepId, type StepKind, type StepMap, type StepOutput, type StepRetriedFact, type StepRetryEvent, type StepSkippedFact, type StepStartEvent, type StepStartedFact, type StepState, type StepStatus, type Store, type TaskConfig, type Trigger, type Tx, type Wf, type Worker, type WorkerConfig, type WorkerRunOnceOpts, type WorkerRunResult, type WorkerRunUntilEmptyOpts, flow, nagi, projectRunState };
978
+ export { type AsStepMap, type AttemptNumber, type BackoffStrategy, type BuildResult, type Builder, type BuilderAccumulator, type CanonicalDag, type CanonicalMatchArm, type CanonicalRetryPolicy, type CanonicalSchema, type CanonicalStep, type ClaimToken, type Clock, type Fact, type FactKind, type Flow, type FlowCompleteEvent, type FlowCompletedFact, type FlowConfig, type FlowErrorEvent, type FlowEvent, type FlowFailedFact, type FlowHooks, type FlowInput, type FlowOutput, type FlowRefUpdatedFact, type FlowStartEvent, type FlowStartedFact, type GlobalFact, InMemoryClock, InMemoryQueue, InMemoryStore, InMemoryTrigger, type InferSchemaInput, type InferSchemaOutput, type Json, type Logger, type MatchArm, type MatchArmGuard, type MatchArmOtherwise, type MatchArmOutput, type MatchArmSelectedFact, type MatchArmShape, type MatchDiscriminatorConfig, type MatchDiscriminatorOutput, type MatchGuardConfig, type Millis, type NagiConfig, NagiRuntimeError, NagiSnapshotDriftError, NagiValidationError, type NeedsMap, type NeedsOutputs, type OnceRecordedFact, type Queue, type QueueDequeueOpts, type QueueEnqueueOpts, type QueueMessage, type Register, type ReplayMode, type ReplayOpts, type RetryPolicy, type RunId, type RunState, type RunStatus, type SerializedError, type SignalConfig, type SignalReceivedEvent, type SignalReceivedFact, type SignalSentEvent, type SignalSentFact, type SnapshotChangedEdge, type SnapshotChangedField, type SnapshotDiff, StandardSchemaV1, type StartOpts, type Step, type StepCompleteEvent, type StepCompletedFact, type StepCtx, type StepEntryConfig, type StepErrorEvent, type StepEvent, type StepFailedFact, type StepId, type StepKind, type StepMap, type StepOutput, type StepRetriedFact, type StepRetryEvent, type StepSkippedFact, type StepStartEvent, type StepStartedFact, type StepState, type StepStatus, type Store, type TaskConfig, type Trigger, type Tx, type Wf, type Worker, type WorkerConfig, type WorkerRunOnceOpts, type WorkerRunResult, type WorkerRunUntilEmptyOpts, canonicalize, diffSnapshots, flow, nagi, projectRunState, sha256Canonical };