@demlik/tea 0.11.0 → 0.13.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.
Files changed (163) hide show
  1. package/dist/agent/index.d.ts +6 -5
  2. package/dist/agent/index.js +11 -11
  3. package/dist/authed-call/index.d.ts +3 -2
  4. package/dist/authed-call/index.js +7 -7
  5. package/dist/await-terminal/index.d.ts +3 -2
  6. package/dist/await-terminal/index.js +2 -2
  7. package/dist/batch-window/index.d.ts +4 -3
  8. package/dist/batch-window/index.js +3 -3
  9. package/dist/cache/index.d.ts +3 -2
  10. package/dist/cache/index.js +4 -4
  11. package/dist/chart/index.d.ts +4 -3
  12. package/dist/chart/index.js +2 -2
  13. package/dist/chart/inspect/index.d.ts +5 -4
  14. package/dist/chart/inspect/index.js +3 -3
  15. package/dist/chart/inspect/react.d.ts +6 -5
  16. package/dist/chart/inspect/react.js +5 -5
  17. package/dist/chart/lane/index.d.ts +7 -6
  18. package/dist/chart/lane/index.js +6 -6
  19. package/dist/chart/lane/react.d.ts +6 -5
  20. package/dist/chart/lane/react.js +7 -7
  21. package/dist/chart/lane/viewer/assets/{chunk-5RXB4S5H-IPzIfiJ6.js → chunk-5RXB4S5H-CcNtpUd7.js} +1 -1
  22. package/dist/chart/lane/viewer/assets/{classDiagram-v2-OCEON4UE-DnUXz1Pv.js → classDiagram-v2-OCEON4UE-D4uAiFr8.js} +1 -1
  23. package/dist/chart/lane/viewer/assets/{dagre-VZM6K2ZE-Og2UIoWg.js → dagre-VZM6K2ZE-831qZcA8.js} +1 -1
  24. package/dist/chart/lane/viewer/assets/{index-sP-6AD57.css → index-9SkH5NA3.css} +1 -1
  25. package/dist/chart/lane/viewer/assets/{index-Obj05Jex.js → index-Bgt4sXpW.js} +4 -4
  26. package/dist/chart/lane/viewer/assets/{kanban-definition-27J2QSJJ-CxkCxJUN.js → kanban-definition-27J2QSJJ-G7PaPzy-.js} +1 -1
  27. package/dist/chart/lane/viewer/assets/{mindmap-definition-FAOFIHXS-DvgvXZhp.js → mindmap-definition-FAOFIHXS-CGj9nrVk.js} +1 -1
  28. package/dist/chart/lane/viewer/assets/{stateDiagram-OKZ733FA-CIZQWK5X.js → stateDiagram-OKZ733FA-B_88AzBS.js} +1 -1
  29. package/dist/chart/lane/viewer/assets/{stateDiagram-v2-UEYNNEHI-Sm6p0NoR.js → stateDiagram-v2-UEYNNEHI-CR5gcgq6.js} +1 -1
  30. package/dist/chart/lane/viewer/assets/{timeline-definition-Z64GVDOM-CV3KwSb-.js → timeline-definition-Z64GVDOM-CCv52MfY.js} +1 -1
  31. package/dist/chart/lane/viewer/index.html +2 -2
  32. package/dist/chart/report/index.d.ts +5 -4
  33. package/dist/chart/report/index.js +4 -4
  34. package/dist/{chunk-ZF6WDK2D.js → chunk-3I52QZZ5.js} +7 -7
  35. package/dist/{chunk-ZF6WDK2D.js.map → chunk-3I52QZZ5.js.map} +1 -1
  36. package/dist/{chunk-ZD6PNZBK.js → chunk-3ZAFFRRB.js} +3 -3
  37. package/dist/{chunk-ZD6PNZBK.js.map → chunk-3ZAFFRRB.js.map} +1 -1
  38. package/dist/{chunk-4KTWLPL5.js → chunk-4EQZ76JC.js} +3 -3
  39. package/dist/{chunk-4KTWLPL5.js.map → chunk-4EQZ76JC.js.map} +1 -1
  40. package/dist/{chunk-EUF7XOEE.js → chunk-4KLG43GY.js} +6 -6
  41. package/dist/{chunk-EUF7XOEE.js.map → chunk-4KLG43GY.js.map} +1 -1
  42. package/dist/{chunk-JER5O7PQ.js → chunk-7FRZ2CT2.js} +15 -7
  43. package/dist/chunk-7FRZ2CT2.js.map +1 -0
  44. package/dist/{chunk-ZCL7SCBK.js → chunk-CIQG5L42.js} +5 -5
  45. package/dist/{chunk-ZCL7SCBK.js.map → chunk-CIQG5L42.js.map} +1 -1
  46. package/dist/{chunk-TP5UPGLY.js → chunk-CLM6ERNO.js} +3 -3
  47. package/dist/{chunk-TP5UPGLY.js.map → chunk-CLM6ERNO.js.map} +1 -1
  48. package/dist/{chunk-ND3DH6KM.js → chunk-COS5MSTO.js} +3 -3
  49. package/dist/{chunk-ND3DH6KM.js.map → chunk-COS5MSTO.js.map} +1 -1
  50. package/dist/{chunk-JP5D6GSL.js → chunk-CRPZJVD2.js} +4 -4
  51. package/dist/{chunk-JP5D6GSL.js.map → chunk-CRPZJVD2.js.map} +1 -1
  52. package/dist/{chunk-SUST46KO.js → chunk-D62FDQKE.js} +3 -3
  53. package/dist/{chunk-SUST46KO.js.map → chunk-D62FDQKE.js.map} +1 -1
  54. package/dist/{chunk-JGVL3WPL.js → chunk-DGE4PV4A.js} +3 -3
  55. package/dist/{chunk-JGVL3WPL.js.map → chunk-DGE4PV4A.js.map} +1 -1
  56. package/dist/{chunk-WLGO64WC.js → chunk-DMYGQB4O.js} +4 -4
  57. package/dist/{chunk-WLGO64WC.js.map → chunk-DMYGQB4O.js.map} +1 -1
  58. package/dist/{chunk-A56OR5RF.js → chunk-L57ZOT5K.js} +3 -3
  59. package/dist/{chunk-A56OR5RF.js.map → chunk-L57ZOT5K.js.map} +1 -1
  60. package/dist/{chunk-5KJKJOFC.js → chunk-NR7BU22N.js} +3 -3
  61. package/dist/{chunk-5KJKJOFC.js.map → chunk-NR7BU22N.js.map} +1 -1
  62. package/dist/{chunk-7V4EVLZA.js → chunk-O4MVQTEJ.js} +4 -4
  63. package/dist/{chunk-7V4EVLZA.js.map → chunk-O4MVQTEJ.js.map} +1 -1
  64. package/dist/{chunk-B5VXOFMZ.js → chunk-OOYD44JI.js} +54 -3
  65. package/dist/chunk-OOYD44JI.js.map +1 -0
  66. package/dist/{chunk-7SVIRMC6.js → chunk-RH5EFRVJ.js} +3 -3
  67. package/dist/{chunk-7SVIRMC6.js.map → chunk-RH5EFRVJ.js.map} +1 -1
  68. package/dist/{chunk-3JU6657S.js → chunk-VYFAZN3F.js} +3 -3
  69. package/dist/{chunk-3JU6657S.js.map → chunk-VYFAZN3F.js.map} +1 -1
  70. package/dist/chunk-XGELA764.js +163 -0
  71. package/dist/chunk-XGELA764.js.map +1 -0
  72. package/dist/{chunk-I5OV65MS.js → chunk-YUXP55T2.js} +3 -3
  73. package/dist/{chunk-I5OV65MS.js.map → chunk-YUXP55T2.js.map} +1 -1
  74. package/dist/{chunk-E6GEDSF4.js → chunk-YWIKDKHY.js} +3 -3
  75. package/dist/{chunk-E6GEDSF4.js.map → chunk-YWIKDKHY.js.map} +1 -1
  76. package/dist/{chunk-5EHLEUTL.js → chunk-ZSUUOEPL.js} +51 -6
  77. package/dist/chunk-ZSUUOEPL.js.map +1 -0
  78. package/dist/{core-Bjc0bS8j.d.ts → core-Co0LWkIA.d.ts} +190 -3
  79. package/dist/deadline/index.d.ts +3 -2
  80. package/dist/deadline/index.js +3 -3
  81. package/dist/do/index.d.ts +12 -8
  82. package/dist/do/index.js +11 -11
  83. package/dist/do/index.js.map +1 -1
  84. package/dist/{durable-effects-D8SqU_if.d.ts → durable-effects-C6uwzjb5.d.ts} +1 -1
  85. package/dist/extension/index.d.ts +3 -2
  86. package/dist/extension/index.js +3 -3
  87. package/dist/extension/react.js +3 -3
  88. package/dist/extension/subs/index.d.ts +3 -2
  89. package/dist/fan-out/index.d.ts +3 -2
  90. package/dist/{fold-Blbhru48.d.ts → fold-BJPdjc9w.d.ts} +1 -1
  91. package/dist/{graph-CcjWZVrd.d.ts → graph-B3L5e0N1.d.ts} +1 -1
  92. package/dist/idempotent-intake/index.d.ts +3 -2
  93. package/dist/index.d.ts +14 -6
  94. package/dist/index.js +2 -2
  95. package/dist/journal/index.d.ts +373 -0
  96. package/dist/journal/index.js +3 -0
  97. package/dist/journal/index.js.map +1 -0
  98. package/dist/llm-call/index.d.ts +3 -2
  99. package/dist/llm-call/index.js +8 -8
  100. package/dist/{machine-0OmPvsy_.d.ts → machine-BtFWQmmq.d.ts} +1 -1
  101. package/dist/machine-viz/index.d.ts +2 -1
  102. package/dist/machine-viz/index.js +2 -2
  103. package/dist/mem/index.d.ts +3 -2
  104. package/dist/monitored-run/index.d.ts +4 -3
  105. package/dist/monitored-run/index.js +5 -5
  106. package/dist/node/index.d.ts +31 -3
  107. package/dist/node/index.js +92 -3
  108. package/dist/node/index.js.map +1 -1
  109. package/dist/paginated-walk/index.d.ts +3 -2
  110. package/dist/paginated-walk/index.js +7 -7
  111. package/dist/parity/index.d.ts +3 -2
  112. package/dist/parity/index.js +3 -3
  113. package/dist/pbt/arbitraries/index.d.ts +2 -1
  114. package/dist/pbt/index.d.ts +2 -1
  115. package/dist/pbt/index.js +3 -3
  116. package/dist/pbt/runners/index.d.ts +2 -1
  117. package/dist/pbt/runners/index.js +3 -3
  118. package/dist/poller/index.d.ts +3 -2
  119. package/dist/poller/index.js +3 -3
  120. package/dist/prediction/index.d.ts +2 -1
  121. package/dist/prediction/index.js +2 -2
  122. package/dist/pure/index.d.ts +2 -1
  123. package/dist/pure/index.js +2 -2
  124. package/dist/react/index.d.ts +4 -3
  125. package/dist/react/index.js +2 -2
  126. package/dist/react/index.js.map +1 -1
  127. package/dist/reconciler/index.d.ts +3 -2
  128. package/dist/reconciler/index.js +7 -7
  129. package/dist/recorder/index.d.ts +3 -2
  130. package/dist/{reducer-BqyoVyBG.d.ts → reducer-4GNR6b8B.d.ts} +2 -2
  131. package/dist/resilient-call/index.d.ts +3 -2
  132. package/dist/resilient-call/index.js +6 -6
  133. package/dist/{run-BVeqJDBF.d.ts → run-pAcmBpah.d.ts} +3 -3
  134. package/dist/{runtime-types-Bxc637bp.d.ts → runtime-types-CNLmhWif.d.ts} +17 -2
  135. package/dist/saga/index.d.ts +3 -2
  136. package/dist/{samples-DCt6nF8H.d.ts → samples-B3My5oh2.d.ts} +1 -1
  137. package/dist/snapshot/index.d.ts +2 -1
  138. package/dist/snapshot/index.js +3 -3
  139. package/dist/subs/index.d.ts +4 -3
  140. package/dist/subs/index.js +3 -3
  141. package/dist/testing/index.d.ts +3 -2
  142. package/dist/testing/index.js +2 -2
  143. package/dist/throttled-input/index.d.ts +3 -2
  144. package/dist/throttled-input/index.js +6 -6
  145. package/dist/token-refresh/index.d.ts +2 -1
  146. package/dist/token-refresh/index.js +3 -3
  147. package/dist/trace-replay/index.d.ts +3 -2
  148. package/dist/trace-replay/index.js +3 -3
  149. package/dist/{types-D7u9DkH7.d.ts → types-XS_miRnB.d.ts} +1 -1
  150. package/dist/with-deadline/index.d.ts +2 -1
  151. package/dist/with-deadline/index.js +2 -2
  152. package/dist/with-resilience/index.d.ts +3 -2
  153. package/dist/with-resilience/index.js +6 -6
  154. package/dist/with-telemetry/index.d.ts +2 -1
  155. package/dist/with-telemetry/index.js +2 -2
  156. package/dist/work-queue/adapter.d.ts +3 -2
  157. package/dist/work-queue/index.d.ts +3 -2
  158. package/dist/work-queue/ops.d.ts +3 -2
  159. package/dist/workflow/index.d.ts +4 -3
  160. package/package.json +11 -4
  161. package/dist/chunk-5EHLEUTL.js.map +0 -1
  162. package/dist/chunk-B5VXOFMZ.js.map +0 -1
  163. package/dist/chunk-JER5O7PQ.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { replay } from './chunk-5EHLEUTL.js';
1
+ import { replay } from './chunk-ZSUUOEPL.js';
2
2
 
3
3
  // src/chart/inspect/captured.ts
4
4
  function captureCmds(machine, input) {
@@ -453,5 +453,5 @@ function inspectReducerState(desc, state, opts = {}) {
453
453
  }
454
454
 
455
455
  export { captureCmds, describeChart, describeReducerChart, edgeAt, explainRefusal, firedAt, firedCounts, inspectReducerState, inspectState, inspectStateSummary, previewEvent, previewReducerEvent, reducerEdgeAt, refusalAtState, sampleMsg, stateInfo };
456
- //# sourceMappingURL=chunk-ZD6PNZBK.js.map
457
- //# sourceMappingURL=chunk-ZD6PNZBK.js.map
456
+ //# sourceMappingURL=chunk-3ZAFFRRB.js.map
457
+ //# sourceMappingURL=chunk-3ZAFFRRB.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/chart/inspect/captured.ts","../src/chart/inspect/describe.ts","../src/chart/inspect/samples.ts","../src/chart/inspect/live.ts","../src/chart/inspect/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,CACd,IAAA,EACA,KAAA,EACA,IAAA,GAAuB,EAAC,EACQ;AAChC,EAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA,KAAM,mBAAA,CAAoB,IAAA,EAAM,KAAA,EAAO,CAAA,CAAE,IAAA,EAAM,IAAI,CAAC,CAAA;AAC9E","file":"chunk-ZD6PNZBK.js","sourcesContent":["// ═══════════════════════════════════════════════════════════════════════════\n// THE CAPTURED CMDS — what actually fired, not what would.\n//\n// `describeChart` reads the cmds an edge DECLARES, and `previewEvent` reports\n// them as the effects a dispatch would cause. That is a BEFORE question, and it\n// has two blind spots by construction:\n//\n// 1. a `{ to, cell }` edge declares no cmds at all — the cell builds them in\n// its body, so the chart has nothing to show for exactly the edges that do\n// the most interesting work; and\n// 2. a guarded edge declares both arms, and only one of them ever fired.\n//\n// This module answers the AFTER question, and it does it without a new observer\n// seam: `replay` already returns the cmds a fold emitted, and the scrubber\n// already re-folds a prefix of the recorded msgs through it. So \"what fired at\n// step n\" is the difference between two prefixes that are already being\n// computed — read off the machine's own output, by the same pure fold, with\n// nothing subscribed and nothing intercepted.\n//\n// PURE. `replay` runs `init` + `update` only — never `interpret`, never a Store,\n// never a subscription — so capturing a cmd list cannot re-perform the effect it\n// is reporting. That is the same guarantee the scrubber rests on.\n//\n// COST. One `replay` per step, so the walk is quadratic in the trace length.\n// That is deliberate: the alternative is a second fold implementation inside\n// this module, and a second fold is a second answer — the thing the whole\n// inspector exists to avoid. Traces are inspector-sized (tens to hundreds of\n// msgs), and the fold is pure arithmetic over plain data.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport { type Cmd, type Machine, replay, type Sub } from \"../../index\";\n\n/**\n * The cmds ONE step emitted, tagged with the msg that caused them.\n *\n * `step` is `0` for `init` and `n` for the nth recorded msg, which is the same\n * index the scrubber's cursor uses — so a UI showing step `n` asks for\n * `capture.steps[n]` and gets the effects of the transition it is displaying.\n */\nexport interface CapturedStep<M extends { type: string }, K extends Cmd> {\n /** `0` = `init`; `1..n` = the nth recorded msg. */\n readonly step: number;\n /**\n * The msg that caused these cmds. `null` at step `0` — `init` has no cause,\n * and pinning its cmds on the first msg would be a lie about who fired them.\n */\n readonly by: M | null;\n /** What ACTUALLY fired, in emission order. Cell-built cmds included. */\n readonly cmds: readonly K[];\n}\n\n/**\n * Every step of a recorded run, with the cmds each one actually emitted.\n *\n * `stoppedAt` is the honest degradation: a fold that throws (a chart compiled\n * against parts that are not there, a cell that blew up on a state the current\n * code no longer produces) truncates the capture at that step and says so,\n * rather than reporting a short list as if it were complete.\n */\nexport interface CmdCapture<M extends { type: string }, K extends Cmd> {\n readonly steps: readonly CapturedStep<M, K>[];\n /** Every captured cmd, flattened in fire order. */\n readonly cmds: readonly K[];\n /** Present iff the fold threw before the trace ran out. */\n readonly stoppedAt?: { readonly step: number; readonly error: string };\n}\n\n/** The recorded input a capture folds — `Trace`'s two input halves. */\nexport interface CaptureInput<S, M extends { type: string }, Ctx> {\n readonly msgs: readonly M[];\n readonly ctx: Ctx;\n /** The rehydrated state the run booted from, when it booted from one. */\n readonly loaded?: S | null;\n}\n\n/**\n * Fold `input` through `machine` and report the cmds EVERY step emitted.\n *\n * This is the after-the-fact counterpart to the declarative preview: where\n * `EventPreview.cmds` says *what would fire if this event were dispatched now*,\n * this says *what did fire, in order, and which msg caused it*. Both are useful\n * and they are not the same question — a cell edge declares no cmds and emits\n * plenty, and a guarded edge declares two arms and takes one.\n */\nexport function captureCmds<\n S,\n M extends { type: string },\n K extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, K, U, Ctx>,\n input: CaptureInput<S, M, Ctx>,\n): CmdCapture<M, K> {\n const steps: CapturedStep<M, K>[] = [];\n const cmds: K[] = [];\n let seen = 0;\n\n for (let n = 0; n <= input.msgs.length; n++) {\n let sofar: readonly K[];\n try {\n // `replay`'s cmds are CUMULATIVE over the prefix, in fold order, so the\n // ones this step added are exactly the tail past the previous prefix.\n sofar = replay(machine, {\n msgs: input.msgs.slice(0, n),\n ctx: input.ctx,\n loaded: input.loaded ?? null,\n }).cmds;\n } catch (e) {\n return {\n steps,\n cmds,\n stoppedAt: {\n step: n,\n error: e instanceof Error ? e.message : String(e),\n },\n };\n }\n const fired = sofar.slice(seen);\n seen = sofar.length;\n cmds.push(...fired);\n steps.push({\n step: n,\n by: n === 0 ? null : (input.msgs[n - 1] ?? null),\n cmds: fired,\n });\n }\n\n return { steps, cmds };\n}\n\n/**\n * The step at cursor `n`, or `undefined` when the capture does not reach it\n * (an out-of-range cursor, or a fold that stopped early).\n */\nexport function firedAt<M extends { type: string }, K extends Cmd>(\n capture: CmdCapture<M, K>,\n step: number,\n): CapturedStep<M, K> | undefined {\n return capture.steps.find((s) => s.step === step);\n}\n\n/**\n * The captured cmds grouped by cmd NAME, in first-fire order — the roll-up a\n * \"which effects did this run actually perform\" panel wants.\n */\nexport function firedCounts<M extends { type: string }, K extends Cmd>(\n capture: CmdCapture<M, K>,\n): readonly { readonly type: string; readonly count: number }[] {\n const counts = new Map<string, number>();\n for (const c of capture.cmds) {\n counts.set(c.type, (counts.get(c.type) ?? 0) + 1);\n }\n return [...counts].map(([type, count]) => ({ type, count }));\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE STATIC DESCRIPTION — a chart, read as data.\n//\n// Everything a debugger UI needs to build itself is already IN the chart: the\n// phases, the states, which one is the entry, which are terminal, every edge\n// with its event / targets / guard / cell / cmds, and — the part no other\n// inspector has — every explicit REFUSAL, because the chart's totality means a\n// (state, event) pair is DECLARED or REFUSED and there is no third case.\n//\n// So this module hand-lists nothing. It walks the same runtime views `compile`\n// walks, and it derives refusals with the SAME predicate `compile` uses to\n// decide between a self-loop and a `NoCellError` — one rule, read twice, so\n// the picture and the machine cannot disagree about what is refused.\n//\n// PURE and framework-free. No React, no DOM, no `Machine`. A script, an Ink\n// TUI, or a test gets exactly this.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { Chart, EventOrigin } from \"../graph\";\n\n// ── the runtime views (the same shapes `compile` reads) ───────────────────\nexport type RtEdge =\n | string\n | {\n readonly target?: string;\n readonly when?: string;\n readonly otherwise?: string;\n readonly cmd?: string | readonly string[];\n readonly otherwiseCmd?: string | readonly string[];\n readonly resume?: { readonly fallback: string };\n readonly to?: readonly string[];\n readonly cell?: string;\n };\ntype RtNode = {\n readonly initial?: true;\n readonly data?: object;\n readonly on?: Record<string, RtEdge>;\n readonly ignore?: readonly string[];\n // BOTH POLARITIES. `end: true` (reached the goal) and `end: \"error\"` (stopped\n // because it failed) are both finals — `graph.ts`'s `IsEndOf` reads the pair,\n // and `end-polarity.test.ts` pins the two runtime sites that used to read\n // only `=== true`. This was the third such site: an error final described\n // here as `end: false` re-acquired the totality obligation, so a scoped event\n // over it came back `undeclared` (\"the chart's totality was bypassed\")\n // instead of refused — the loudest possible wrong answer.\n readonly end?: true | \"error\";\n};\ntype RtChart = {\n readonly ctx?: object;\n readonly events: Record<\n string,\n {\n readonly scope: string | readonly string[];\n readonly foreign?: true;\n readonly from?: EventOrigin;\n readonly data?: object;\n }\n >;\n readonly cmds?: Record<string, object>;\n readonly states: Record<string, Record<string, RtNode>>;\n};\n\n/** `undefined` → none; `\"x\"` → one; `[\"x\",\"y\"]` → both, in declaration order. */\nfunction cmdNames(\n ref: string | readonly string[] | undefined,\n): readonly string[] {\n if (ref === undefined) return [];\n return typeof ref === \"string\" ? [ref] : [...ref];\n}\n\nfunction scopeList(scope: string | readonly string[]): readonly string[] {\n return typeof scope === \"string\" ? [scope] : [...scope];\n}\n\n// ── the description ───────────────────────────────────────────────────────\n\n/**\n * WHY a (state, event) pair is refused. The chart's three refusal mechanisms,\n * each carrying the evidence that produced it, so a UI can say *\"`WIP` is not\n * addressed to `blocked` — its scope is `edges`\"* rather than \"disabled\".\n *\n * `undeclared` is the fourth case the type layer forbids: a pair that is live,\n * unhandled and unrefused. It cannot occur on a chart that compiled through\n * `defineChart`, and it is reported rather than swallowed because reaching it\n * means the types were bypassed with a cast — which is precisely when a\n * debugger should say so instead of drawing a well-behaved button.\n */\nexport type RefusalReason =\n | {\n readonly kind: \"end\";\n /** Terminal state: it accepts nothing, by declaration. */\n readonly state: string;\n }\n | {\n readonly kind: \"out-of-scope\";\n /** The event's declared `scope`, flattened to its members. */\n readonly scope: readonly string[];\n /** The phase this state lives in — the one that is not in `scope`. */\n readonly phase: string;\n }\n | {\n /**\n * `scope: \"edges\"` — the event is live exactly where an edge declares it,\n * and this state declares none.\n *\n * SPLIT OUT OF `out-of-scope` because the phase has nothing to do with it.\n * `\"edges\"` is not a phase name, so the phase test could never pass and\n * the refusal came back naming a phase the reader then went looking for:\n * *\"`DONE` is not addressed to phase `working` (scope: edges)\"* — three\n * pieces of vocabulary for one fact, and the fact is not in there. The\n * default scope is `edges`, so this was most refusals on most charts.\n */\n readonly kind: \"no-edge\";\n readonly state: string;\n }\n | {\n readonly kind: \"ignored\";\n /** The event is live here and this state refuses it BY NAME. */\n readonly state: string;\n }\n | { readonly kind: \"undeclared\" };\n\n/** A one-line, human-readable rendering of a {@link RefusalReason}. */\nexport function explainRefusal(event: string, reason: RefusalReason): string {\n switch (reason.kind) {\n case \"end\":\n return `\"${reason.state}\" is an end state — it accepts nothing`;\n case \"out-of-scope\":\n return `\"${event}\" is not addressed to phase \"${reason.phase}\" (scope: ${reason.scope.join(\", \")})`;\n case \"no-edge\":\n return `\"${reason.state}\" declares no \"${event}\" edge`;\n case \"ignored\":\n return `\"${reason.state}\" lists \"${event}\" in its \\`ignore\\``;\n case \"undeclared\":\n return `\"${event}\" is live here, unhandled and unrefused — the chart's totality was bypassed`;\n }\n}\n\n/** What kind of transition an edge declares. */\nexport type EdgeKind = \"plain\" | \"guarded\" | \"cell\" | \"resume\";\n\n/** One declared edge — a `(state, event)` pair the chart routes. */\nexport interface ChartEdge {\n readonly from: string;\n readonly event: string;\n /** `\"${from}.${event}\"` — the site key guards/cmds/cells are indexed by. */\n readonly at: string;\n readonly kind: EdgeKind;\n /**\n * Every state this edge can land on, in declaration order. A guarded edge\n * contributes both arms; a cell edge contributes its whole declared `to`.\n * For a resume edge this is the fallback alone — the real target is\n * `state.was`, which is a property of the LIVE state, not of the chart.\n */\n readonly targets: readonly string[];\n /** The guard's name, on a guarded edge. */\n readonly guard?: string;\n /** The target taken when the guard HOLDS. */\n readonly then?: string;\n /** The target taken when the guard FAILS. */\n readonly otherwise?: string;\n /** The cell's name, on a `{ to, cell }` edge. */\n readonly cell?: string;\n /** The declared fallback, on a `resume` edge. */\n readonly fallback?: string;\n /** Cmds fired when the edge fires (the guard's `then` arm, if guarded). */\n readonly cmds: readonly string[];\n /** Cmds fired when the guard FAILS. Empty unless the edge is guarded. */\n readonly otherwiseCmds: readonly string[];\n}\n\n/** A (state, event) pair the chart explicitly refuses, and why. */\nexport interface ChartRefusal {\n readonly from: string;\n readonly event: string;\n readonly reason: RefusalReason;\n}\n\n/** One state, with the facts the chart declares about it. */\nexport interface ChartStateInfo {\n readonly name: string;\n /** The phase it was declared under. */\n readonly phase: string;\n /** `initial: true` — the entry state. Exactly one per machine-bearing chart. */\n readonly initial: boolean;\n /**\n * Terminal by DECLARATION, not by \"has no outgoing edges\" — `true` for both\n * polarities, because both accept nothing and both owe nothing.\n */\n readonly end: boolean;\n /**\n * WHICH ending. `true` a success final, `\"error\"` the failure terminal,\n * `false` not a final at all.\n *\n * `end` answers \"does this accept anything\"; this answers \"did the machine\n * win or lose\". A lane needs both and they are not the same question —\n * `shipped` and `frozen` are equally terminal and are not the same outcome.\n */\n readonly endPolarity: false | true | \"error\";\n /** Carries a `resume` edge out of it, so the compiler injects `was` here. */\n readonly parking: boolean;\n}\n\n/** One event of the alphabet. */\nexport interface ChartEventInfo {\n readonly name: string;\n /** The declared `scope`, flattened: `\"edges\"`, `\"all\"`, or phase names. */\n readonly scope: readonly string[];\n /** `foreign: true` — the name belongs to someone else and stays bare. */\n readonly foreign: boolean;\n /**\n * WHERE THIS EVENT COMES FROM — `from`, read back off the chart.\n *\n * `undefined` means the chart does not say, which is a fact of its own and\n * never a default: a UI that groups its button row by sender must render the\n * undeclared ones as undeclared rather than filing them under a guess.\n */\n readonly from?: EventOrigin;\n /**\n * Whether the event DECLARED a payload (`data: ty<…>()`).\n *\n * `ty<T>()` is `{}` at runtime, so `T` is unreadable — but the `data` KEY is\n * right there in the literal, so \"does this event carry a payload at all\" IS\n * a runtime fact. It is what decides whether a sample is required.\n */\n readonly hasPayload: boolean;\n}\n\n/**\n * A whole chart, as data a UI can build itself from. Nothing here is supplied\n * by the caller; every field is read off the one chart value.\n */\nexport interface ChartDescription {\n /** The phases, in declaration order, each with its member states. */\n readonly phases: readonly {\n readonly name: string;\n readonly states: readonly string[];\n }[];\n readonly states: readonly ChartStateInfo[];\n /** The state marked `initial: true`, or `undefined` on a chart with none. */\n readonly initial: string | undefined;\n readonly events: readonly ChartEventInfo[];\n /** Every cmd DECLARED in the `cmds` section — the effect alphabet. */\n readonly cmds: readonly string[];\n /** Every guard name any edge references. */\n readonly guards: readonly string[];\n /** Every cell name any `{ to, cell }` edge references. */\n readonly cells: readonly string[];\n readonly edges: readonly ChartEdge[];\n readonly refusals: readonly ChartRefusal[];\n}\n\n/**\n * A read edge MINUS the state it leaves — everything about an edge that is a\n * fact of the edge itself rather than of the grid it sits in.\n *\n * The reducer form has no state dimension (`src/chart/inspect/reducer.ts`), so\n * its edges are exactly this: same kinds, same targets, same guard/cell/cmd\n * fields, with `from` unrepresentable rather than blank.\n */\nexport type EdgeCore = Omit<ChartEdge, \"from\">;\n\n/**\n * Read one edge spec into {@link EdgeCore}. `at` is the site key the parts bag\n * is indexed by — `\"state.event\"` in the grid form, the bare event in the\n * reducer form — and it is passed in rather than derived, because that key IS\n * the difference between the two forms.\n */\nexport function readEdgeCore(\n event: string,\n at: string,\n spec: RtEdge,\n): EdgeCore {\n const edge = typeof spec === \"string\" ? { target: spec } : spec;\n const cmds = cmdNames(edge.cmd);\n const otherwiseCmds = cmdNames(edge.otherwiseCmd);\n\n if (edge.cell !== undefined) {\n return {\n event,\n at,\n kind: \"cell\",\n targets: [...(edge.to ?? [])],\n cell: edge.cell,\n cmds,\n otherwiseCmds,\n };\n }\n if (edge.resume !== undefined) {\n return {\n event,\n at,\n kind: \"resume\",\n targets: [edge.resume.fallback],\n fallback: edge.resume.fallback,\n cmds,\n otherwiseCmds,\n };\n }\n if (edge.when !== undefined) {\n const then = edge.target ?? \"\";\n const otherwise = edge.otherwise ?? \"\";\n return {\n event,\n at,\n kind: \"guarded\",\n targets: [then, otherwise],\n guard: edge.when,\n then,\n otherwise,\n cmds,\n otherwiseCmds,\n };\n }\n return {\n event,\n at,\n kind: \"plain\",\n targets: edge.target === undefined ? [] : [edge.target],\n cmds,\n otherwiseCmds,\n };\n}\n\n/** Read one edge spec into the flat {@link ChartEdge} shape. */\nfunction readEdge(from: string, event: string, spec: RtEdge): ChartEdge {\n return { from, ...readEdgeCore(event, `${from}.${event}`, spec) };\n}\n\n/**\n * Why `from` refuses `event`, or `undefined` when it does not refuse it.\n *\n * THE SAME PREDICATE `compile` USES. `compile` computes `refused = end || !live\n * || ignore.includes(e)` to decide between a self-loop and a `NoCellError`;\n * this splits the same three tests apart to name WHICH one fired, in the order\n * that makes the most specific declaration win — `end: true` is a statement\n * about the state, `scope` about the event, `ignore` about the pair.\n */\nfunction refusalAt(\n c: RtChart,\n node: RtNode,\n phase: string,\n state: string,\n event: string,\n): RefusalReason | undefined {\n if (node.on?.[event] !== undefined) return undefined;\n if (node.end !== undefined) return { kind: \"end\", state };\n const scope = scopeList(c.events[event]?.scope ?? \"edges\");\n const live = scope.includes(\"all\") || scope.includes(phase);\n // `edges` is a scope with no phase in it, so it fails the phase test for a\n // reason that is not about the phase — say the one that is true. Only when\n // `edges` is the WHOLE scope: a `[\"edges\", \"review\"]` event really is out of\n // scope in `working`, and that is the phase's news after all.\n if (!live && scope.length === 1 && scope[0] === \"edges\") {\n return { kind: \"no-edge\", state };\n }\n if (!live) return { kind: \"out-of-scope\", scope, phase };\n if ((node.ignore ?? []).includes(event)) return { kind: \"ignored\", state };\n return { kind: \"undeclared\" };\n}\n\n/**\n * Read a chart into its {@link ChartDescription}.\n *\n * Pure, total, and allocation-only — it never executes a guard, a cell or a\n * payload builder, so it is safe on a chart whose parts do not exist yet.\n */\nexport function describeChart<const C extends Chart<C>>(\n chart: C,\n): ChartDescription {\n const c = chart as unknown as RtChart;\n\n const phases: { name: string; states: string[] }[] = [];\n const states: ChartStateInfo[] = [];\n const edges: ChartEdge[] = [];\n const refusals: ChartRefusal[] = [];\n const guards = new Set<string>();\n const cells = new Set<string>();\n const parking = new Set<string>();\n let initial: string | undefined;\n\n // Pass 1 — the nodes, the phases and the edges. `parking` is a derivation\n // over the whole chart (a state is parking iff SOME edge out of it resumes),\n // so it is collected here and read in pass 2.\n const flat: { state: string; phase: string; node: RtNode }[] = [];\n for (const [phase, members] of Object.entries(c.states)) {\n const names: string[] = [];\n for (const [state, node] of Object.entries(members)) {\n names.push(state);\n flat.push({ state, phase, node });\n if (node.initial === true) initial ??= state;\n for (const [event, spec] of Object.entries(node.on ?? {})) {\n const edge = readEdge(state, event, spec);\n edges.push(edge);\n if (edge.guard !== undefined) guards.add(edge.guard);\n if (edge.cell !== undefined) cells.add(edge.cell);\n if (edge.kind === \"resume\") parking.add(state);\n }\n }\n phases.push({ name: phase, states: names });\n }\n\n // Pass 2 — the state records (which need `parking`) and the refusals (which\n // are a full |S| × |M| sweep minus the declared edges).\n const events = Object.keys(c.events);\n for (const { state, phase, node } of flat) {\n states.push({\n name: state,\n phase,\n initial: node.initial === true,\n end: node.end !== undefined,\n endPolarity: node.end ?? false,\n parking: parking.has(state),\n });\n for (const event of events) {\n const reason = refusalAt(c, node, phase, state, event);\n if (reason !== undefined) refusals.push({ from: state, event, reason });\n }\n }\n\n return {\n phases: phases.map((p) => ({ name: p.name, states: p.states })),\n states,\n initial,\n events: events.map((name) => {\n const decl = c.events[name];\n return {\n name,\n scope: scopeList(decl?.scope ?? \"edges\"),\n foreign: decl?.foreign === true,\n ...(decl?.from === undefined ? {} : { from: decl.from }),\n hasPayload: decl !== undefined && \"data\" in decl,\n };\n }),\n cmds: Object.keys(c.cmds ?? {}),\n guards: [...guards],\n cells: [...cells],\n edges,\n refusals,\n };\n}\n\n/** The declared edge out of `state` on `event`, or `undefined`. */\nexport function edgeAt(\n desc: ChartDescription,\n state: string,\n event: string,\n): ChartEdge | undefined {\n return desc.edges.find((e) => e.from === state && e.event === event);\n}\n\n/** Why `state` refuses `event`, or `undefined` when it does not. */\nexport function refusalAtState(\n desc: ChartDescription,\n state: string,\n event: string,\n): RefusalReason | undefined {\n return desc.refusals.find((r) => r.from === state && r.event === event)\n ?.reason;\n}\n\n/** The record for `state`, or `undefined` when the chart has no such state. */\nexport function stateInfo(\n desc: ChartDescription,\n state: string,\n): ChartStateInfo | undefined {\n return desc.states.find((s) => s.name === state);\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// SAMPLES — the one thing the chart genuinely cannot know, typed BY the chart.\n//\n// `ty<T>()` is `{}` at runtime (graph.ts:33): a phantom whose TYPE remembers\n// the payload and whose VALUE remembers nothing. So an inspector that wants to\n// dispatch `WIP` cannot invent `{ at: 1 }` — the shape is erased before any\n// runtime code could read it.\n//\n// The author therefore supplies a sample per event. That is a REAL fact the\n// chart does not carry (what a plausible `at` is), which is why it is a prop\n// at all — and it is the ONLY payload prop, because everything else about the\n// event (its name, its scope, whether it carries a payload) IS in the chart.\n//\n// The bag is typed the same way `Assigns`/`Guards`/`Cmds` are: a mapped type\n// over a key union DERIVED from the chart, so the sample for `X` must be\n// exactly `X`'s declared payload, a typo'd event name is an excess property,\n// and an event whose payload the author forgot is a missing property tsc names.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventName, MsgOf } from \"../graph\";\n\ntype Narrow<U, K> = Extract<U, { type: K }>;\n\n/**\n * Event `E`'s declared payload — its Msg member minus the `type` the chart\n * already owns.\n *\n * Read off `MsgOf<C>` rather than off the `events` section directly, so it is\n * the SAME derivation the compiled machine consumes: a sample that type-checks\n * here is a msg the machine accepts, by construction. An event with no `data`\n * has `DataOf = unknown`, so this is `{}` — no keys, nothing to supply.\n */\nexport type SamplePayload<C, E extends string> = Omit<\n Narrow<MsgOf<C>, E>,\n \"type\"\n>;\n\n/** Does event `E` declare a payload the author must fill in? */\ntype NeedsSample<C, E extends string> = [keyof SamplePayload<C, E>] extends [\n never,\n]\n ? false\n : true;\n\n/**\n * The sample bag: one entry per event that DECLARES a payload, each typed as\n * exactly that payload.\n *\n * The `as` clause drops the payload-free events from the key union entirely —\n * so `{ START: {} }` for a bare `START: { scope: \"edges\" }` is an excess\n * property tsc rejects, rather than a meaningless entry it accepts. \"Where an\n * event has no declared payload, no sample is required\" is therefore not a\n * convention; it is unrepresentable to supply one.\n *\n * The `type` tag is absent for the same reason it is absent from an `assign`'s\n * return: it is the chart's fact, stamped on by {@link sampleMsg}, so the\n * author cannot write it wrong and cannot write it twice.\n *\n * ```ts\n * const samples: Samples<LaneG> = {\n * WIP: { at: 1 },\n * FAIL: { at: 2, reason: \"flaky\" }, // `reason` is REQUIRED — the chart says so\n * // BLOCKED: … // omit one and tsc names it\n * };\n * ```\n */\nexport type Samples<C> = {\n readonly [E in EventName<C> as [NeedsSample<C, E>] extends [true]\n ? E\n : never]: SamplePayload<C, E>;\n};\n\n/** The samples bag as the runtime reads it: event name → payload object. */\nexport type RtSamples = Readonly<Record<string, object | undefined>>;\n\n/**\n * Build the Msg for `event` from the sample bag: the payload, plus the `type`\n * the chart owns.\n *\n * Returns `undefined` exactly when the event needs a payload and none was\n * supplied — which is the honest \"cannot\" the guard preview degrades on,\n * rather than a half-built msg that makes a guard throw for the wrong reason.\n */\nexport function sampleMsg(\n event: string,\n hasPayload: boolean,\n samples: RtSamples | undefined,\n): { readonly type: string } | undefined {\n const payload = samples?.[event];\n if (payload === undefined) {\n return hasPayload ? undefined : { type: event };\n }\n return { ...payload, type: event };\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE LIVE LAYER — the chart, asked about the state it is in RIGHT NOW.\n//\n// The static description says what the machine can do anywhere. This says what\n// it can do here: which events are legal, which are refused and why, and — the\n// genuinely new capability — WHICH BRANCH a guarded edge would take, evaluated\n// by running the named guard against the live state and a sample msg.\n//\n// Everything here is PURE. Guards, cells and cmd builders are pure by the TEA\n// invariants (they are the same things `replay` is allowed to call), so a\n// preview costs nothing and changes nothing. Nothing in this file dispatches,\n// interprets, or touches a runtime.\n//\n// HONEST DEGRADATION is the design rule. A guard that cannot be evaluated — no\n// sample for its msg, no `guards` bag, a body that throws on this state — is\n// reported as `unknown` WITH the reason. It is never guessed, and never\n// silently rendered as `else`.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventOrigin } from \"../graph\";\nimport {\n type ChartDescription,\n type ChartEdge,\n type EdgeCore,\n edgeAt,\n explainRefusal,\n type RefusalReason,\n refusalAtState,\n} from \"./describe\";\nimport { type RtSamples, sampleMsg } from \"./samples\";\n\n// ── the runtime views of the parts bag ────────────────────────────────────\ntype RtState = { readonly type: string; readonly was?: string };\ntype RtMsg = { readonly type: string };\ntype RtGuard = (s: RtState, m: RtMsg, at: string) => boolean;\ntype RtCellFn = (\n s: RtState,\n m: RtMsg,\n at: string,\n) => readonly [RtState, readonly { readonly type: string }[]];\n\n// The parameter type is `never[]`, deliberately. A `Guards<C, S, M>` entry is\n// PRE-NARROWED to its use site (`(s: ReviewState, m: FailMsg, at: \"review.FAIL\")`),\n// and parameters are checked contravariantly — so a bag typed against a widened\n// `(s: { type: string }, …)` REJECTS the very bag `compile` demands, which would\n// force every caller to cast the parts they already have. `never` is the one\n// parameter type every function accepts, so the author passes `parts` through\n// untouched; the narrowing back to a callable shape is one cast, here, at the\n// call boundary (the same place `compile` puts its own).\n/** Any guard, however narrowly its use sites typed it. */\nexport type AnyGuard = (...args: never[]) => boolean;\n/** Any cell, in either the single-body or the per-site form. */\nexport type AnyCell =\n | ((...args: never[]) => readonly [{ readonly type: string }, unknown])\n | Readonly<Record<string, unknown>>;\n\n/**\n * The code parts a preview may consult — the SAME bag `compile` receives, so\n * an author passes the one they already built rather than a second copy.\n * Every field is optional: the preview degrades where a part is absent.\n */\nexport interface InspectParts {\n readonly guards?: Readonly<Record<string, AnyGuard | undefined>>;\n readonly cells?: Readonly<Record<string, AnyCell | undefined>>;\n}\n\n/** Everything a live preview may consult, beyond the state itself. */\nexport interface InspectOptions {\n /** The parts bag `compile` was given. Guards/cells are read from it. */\n readonly parts?: InspectParts;\n /** Sample payload per event — see `./samples`. */\n readonly samples?: RtSamples;\n}\n\n// ── guard preview ─────────────────────────────────────────────────────────\n\n/** Why a guard could not be evaluated. Each is a fact, not a guess. */\nexport type GuardUnknown =\n | \"no-guard-bag\"\n | \"no-implementation\"\n | \"no-sample\"\n | \"threw\";\n\n/**\n * Which branch a guarded edge would take right now.\n *\n * `then` / `else` are ANSWERS — the guard ran, on this state, with this msg.\n * `unknown` is the honest non-answer, carrying the reason and (for a throwing\n * guard) the message, so a UI shows \"cannot evaluate: no sample for FAIL\"\n * rather than a confidently wrong arrow.\n */\nexport type GuardPreview =\n | {\n readonly guard: string;\n readonly branch: \"then\" | \"else\";\n /** The state that branch lands on. */\n readonly target: string;\n /** The cmds that branch fires. */\n readonly cmds: readonly string[];\n }\n | {\n readonly guard: string;\n readonly branch: \"unknown\";\n readonly why: GuardUnknown;\n /** The thrown error's message, when `why` is `\"threw\"`. */\n readonly error?: string;\n };\n\n/**\n * Run the named guard against `state` + a sample msg. Never throws.\n *\n * Takes an {@link EdgeCore} rather than a `ChartEdge`, so BOTH chart forms get\n * this one implementation: a guard is pure and site-keyed by `at` in either\n * form, and `from` is the only field that differs between their edges — a field\n * this function never reads. `./reducer` calls it directly.\n */\nexport function previewGuardOn(\n edge: EdgeCore,\n state: { readonly type: string },\n msg: RtMsg | undefined,\n opts: InspectOptions,\n): GuardPreview {\n const guard = edge.guard as string;\n const bag = opts.parts?.guards;\n if (bag === undefined)\n return { guard, branch: \"unknown\", why: \"no-guard-bag\" };\n const fn = bag[guard] as RtGuard | undefined;\n if (fn === undefined)\n return { guard, branch: \"unknown\", why: \"no-implementation\" };\n if (msg === undefined) return { guard, branch: \"unknown\", why: \"no-sample\" };\n try {\n const held = fn(state, msg, edge.at) === true;\n return held\n ? {\n guard,\n branch: \"then\",\n target: edge.then ?? \"\",\n cmds: edge.cmds,\n }\n : {\n guard,\n branch: \"else\",\n target: edge.otherwise ?? \"\",\n cmds: edge.otherwiseCmds,\n };\n } catch (e) {\n return {\n guard,\n branch: \"unknown\",\n why: \"threw\",\n error: e instanceof Error ? e.message : String(e),\n };\n }\n}\n\n// ── target resolution ─────────────────────────────────────────────────────\n\n/** How a single target was determined, when one could be. */\nexport type ResolvedBy = \"declared\" | \"guard\" | \"resume\" | \"cell\";\n\n/**\n * Run a cell purely to learn which target it actually picks. Never throws.\n *\n * {@link EdgeCore}, for the same reason {@link previewGuardOn} takes one: the\n * escape hatch is the same escape hatch in both chart forms, and `buildCell`\n * serves both from one body — so previewing it must not fork either.\n */\nexport function runCellOn(\n edge: EdgeCore,\n state: { readonly type: string },\n msg: RtMsg | undefined,\n opts: InspectOptions,\n): string | undefined {\n const impl = opts.parts?.cells?.[edge.cell as string] as\n | RtCellFn\n | Record<string, RtCellFn | undefined>\n | undefined;\n if (impl === undefined || msg === undefined) return undefined;\n // The two cell forms `compile` supports: one body for every site, or one\n // body per site keyed by `at`.\n const hand = typeof impl === \"function\" ? impl : impl[edge.at];\n if (hand === undefined) return undefined;\n try {\n const [next] = hand(state, msg, edge.at);\n const to = next?.type;\n // Respect the edge's own `to` clamp: a cell that returns outside it is the\n // `CellTargetError` case, and a preview must not draw what the runtime\n // would refuse.\n return typeof to === \"string\" && edge.targets.includes(to) ? to : undefined;\n } catch {\n return undefined;\n }\n}\n\n// ── the verdict ───────────────────────────────────────────────────────────\n\n/**\n * What would happen if `event` were dispatched at the current state.\n *\n * A refusal is FIRST-CLASS: it carries the reason and a rendered explanation,\n * so a UI draws it as visibly refused rather than omitting the control. That\n * is the totality property paying rent — the chart knows the difference\n * between \"not routed here\", \"deliberately dropped here\" and \"this state is\n * over\", and a debugger that hides all three behind a missing button throws\n * away the one thing this substrate knows and others do not.\n */\nexport interface EventPreview {\n readonly event: string;\n readonly status: \"legal\" | \"refused\";\n /**\n * Who would send this — the event's declared `from`, carried through rather\n * than recomputed, so a button row can be grouped by sender with the same\n * answer the report's \"waiting on\" line gives. `undefined` when the chart\n * does not say.\n */\n readonly from?: EventOrigin;\n /** Present iff `status` is `\"refused\"`. */\n readonly reason?: RefusalReason;\n /** A one-line rendering of `reason`. Present iff refused. */\n readonly why?: string;\n /** The declared edge. Present iff legal. */\n readonly edge?: ChartEdge;\n /** Present iff the edge is guarded. */\n readonly guard?: GuardPreview;\n /**\n * The cmds that WOULD fire — read off the edge's declaration. For a guarded\n * edge whose branch resolved, the cmds of THAT arm; for one that did not, the\n * `then` arm's (the declared happy path) — `guard.branch === \"unknown\"` is\n * what says so.\n *\n * This is the BEFORE question, and a `{ to, cell }` edge answers it with an\n * empty list BY DECLARATION: the cell builds its cmds inside its body, so the\n * chart has none to declare. For what actually fired, ask the after question\n * — `captureCmds` in `./captured`, which reads the emitted cmds off the\n * machine's own output.\n */\n readonly cmds: readonly string[];\n /** Every state the edge declares it can reach. */\n readonly targets: readonly string[];\n /** The single target, when one is determined. */\n readonly resolved?: string;\n /** How {@link EventPreview.resolved} was determined. */\n readonly resolvedBy?: ResolvedBy;\n /**\n * The msg this preview used — the sample plus the chart's `type`. `undefined`\n * when the event declares a payload and no sample was supplied, which is\n * also why a guard or cell may have come back `unknown`.\n */\n readonly msg?: { readonly type: string };\n}\n\n/**\n * Preview one event against a live state.\n *\n * @param desc the chart's {@link ChartDescription}.\n * @param state the live state — anything with a `type` (and `was`, on a\n * parking state, which is what makes a resume target resolvable).\n */\nexport function previewEvent<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n event: string,\n opts: InspectOptions = {},\n): EventPreview {\n const st = state as RtState;\n const edge = edgeAt(desc, st.type, event);\n const info = desc.events.find((e) => e.name === event);\n // The ONE read of provenance in this file, shared by both arms: a refused\n // event has a sender too, and hiding it would make the refused half of a\n // grouped button row unfilable.\n const from = info?.from === undefined ? {} : { from: info.from };\n\n if (edge === undefined) {\n const reason = refusalAtState(desc, st.type, event) ?? {\n kind: \"undeclared\" as const,\n };\n return {\n event,\n ...from,\n status: \"refused\",\n reason,\n why: explainRefusal(event, reason),\n cmds: [],\n targets: [],\n };\n }\n\n const msg = sampleMsg(event, info?.hasPayload === true, opts.samples);\n const base = {\n event,\n ...from,\n status: \"legal\" as const,\n edge,\n targets: edge.targets,\n msg,\n };\n\n switch (edge.kind) {\n case \"plain\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.targets[0],\n resolvedBy: edge.targets.length === 1 ? \"declared\" : undefined,\n };\n\n case \"guarded\": {\n const guard = previewGuardOn(edge, st, msg, opts);\n return {\n ...base,\n guard,\n cmds: guard.branch === \"unknown\" ? edge.cmds : guard.cmds,\n resolved: guard.branch === \"unknown\" ? undefined : guard.target,\n resolvedBy: guard.branch === \"unknown\" ? undefined : \"guard\",\n };\n }\n\n case \"resume\":\n // `was ?? fallback` — the runtime's own rule, read off the live state.\n // This is always resolvable, because `was` is INJECTED by the compiler\n // on entry to a parking state rather than authored.\n return {\n ...base,\n cmds: edge.cmds,\n targets: st.was === undefined ? edge.targets : [st.was],\n resolved: st.was ?? edge.fallback,\n resolvedBy: \"resume\",\n };\n\n case \"cell\": {\n const resolved = runCellOn(edge, st, msg, opts);\n return {\n ...base,\n // A cell builds its own cmds inside its body, so the chart declares\n // none for it — `cmds` is empty by declaration, not by omission.\n cmds: edge.cmds,\n resolved,\n resolvedBy: resolved === undefined ? undefined : \"cell\",\n };\n }\n }\n}\n\n/**\n * Preview EVERY event of the alphabet against a live state, in the chart's\n * declaration order.\n *\n * This is the button row: one entry per declared event, each either legal\n * (with its branch, targets and cmds) or refused (with its reason). Nothing is\n * filtered out — a refused event is a control the UI draws, not one it lacks.\n */\nexport function inspectState<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n opts: InspectOptions = {},\n): readonly EventPreview[] {\n return desc.events.map((e) => previewEvent(desc, state, e.name, opts));\n}\n\n/**\n * {@link inspectState}, plus the two roll-ups a caller almost always wants\n * next: the legal event names and the refused ones.\n *\n * The whole verdict list is still there — the split is a convenience, not a\n * filter, and `events` remains the surface a UI renders so a refusal keeps its\n * reason.\n */\nexport function inspectStateSummary<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n opts: InspectOptions = {},\n): {\n readonly state: S;\n readonly events: readonly EventPreview[];\n readonly legal: readonly string[];\n readonly refused: readonly string[];\n} {\n const events = inspectState(desc, state, opts);\n return {\n state,\n events,\n legal: events.filter((e) => e.status === \"legal\").map((e) => e.event),\n refused: events.filter((e) => e.status === \"refused\").map((e) => e.event),\n };\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE REDUCER FORM, AS A DEBUGGER READS IT — the honest subset.\n//\n// `defineReducerChart` drops the dimension the machine does not have: no\n// phases, no per-state `on`, no `scope`, no `ignore`, no `end`. So its\n// description is not `ChartDescription` with some fields left empty; it is a\n// genuinely THINNER shape, and the whole design rule of this file is that the\n// thinness is stated rather than faked.\n//\n// WHAT IT CAN TRUTHFULLY SAY\n// - the flat state list, and the entry state (`initial`, one word);\n// - the event alphabet, each with `foreign`, `from` provenance, and whether\n// it declares a payload;\n// - per-event routing — the same four edge kinds, including a `{ to, cell }`\n// edge's whole declared fan-out;\n// - TOTALITY over events, which this form enforces MORE strictly than the\n// grid form: `on` is a required mapped type over the alphabet, so an event\n// with no edge is a missing property tsc names, where the grid form's\n// `scope: \"edges\"` lets an event be routed from nowhere at all.\n//\n// WHAT IT CANNOT, AND WILL NOT PRETEND TO\n// - per-state REFUSAL. A reducer cell receives the whole state un-narrowed\n// and decides inside its body; there is no (state, event) pair for the\n// chart to refuse. An empty `refusals: []` would read as \"nothing is\n// refused\", which is the loudest possible wrong answer — so the field holds\n// an {@link Unanswerable} instead, and a consumer that tries to iterate it\n// gets a type error rather than a comfortable lie.\n// - phases, and event `scope`. Same reason, same treatment.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventOrigin, ReducerChart } from \"../graph\";\nimport { type EdgeCore, type RtEdge, readEdgeCore } from \"./describe\";\nimport {\n type GuardPreview,\n type InspectOptions,\n previewGuardOn,\n type ResolvedBy,\n runCellOn,\n} from \"./live\";\nimport { sampleMsg } from \"./samples\";\n\n// ── the runtime view (the same shape `compileReducer` reads) ──────────────\ntype RtReducerChart = {\n readonly ctx?: object;\n readonly states: readonly string[];\n readonly initial: string;\n readonly events: Record<\n string,\n {\n readonly foreign?: true;\n readonly from?: EventOrigin;\n readonly data?: object;\n }\n >;\n readonly cmds?: Record<string, object>;\n readonly on: Record<string, RtEdge>;\n};\n\n/**\n * A QUESTION THIS FORM CANNOT ANSWER, carried in the slot where the grid form\n * carries the answer.\n *\n * `answerable: false` is the whole type: there is no `true` member, because a\n * question this form CAN answer is answered with the answer. So `desc.refusals`\n * on a reducer description is not an empty list a UI silently renders — it is a\n * value whose only shape says why the list is not there, and code written\n * against the grid form's array fails to compile against it.\n */\nexport interface Unanswerable<Q extends string> {\n readonly answerable: false;\n /** Which question — the grid-form field this stands in for. */\n readonly question: Q;\n /** One line, ready to render. */\n readonly why: string;\n}\n\nconst NO_PHASES: Unanswerable<\"phases\"> = {\n answerable: false,\n question: \"phases\",\n why: \"this chart form has no phase dimension — every edge is reachable from every state\",\n};\nconst NO_REFUSALS: Unanswerable<\"refusals\"> = {\n answerable: false,\n question: \"refusals\",\n why: \"this chart form has no state dimension — a refusal is a (state, event) fact, and a reducer cell decides inside its body\",\n};\nconst NO_SCOPE: Unanswerable<\"scope\"> = {\n answerable: false,\n question: \"scope\",\n why: \"this chart form has no phase dimension — `scope` answers 'at which states does this event mean anything', which has no content here\",\n};\n\n/** One edge of a reducer chart — an edge with no state to leave from. */\nexport type ReducerEdge = EdgeCore;\n\n/** One event of a reducer chart's alphabet. `scope` has no counterpart here. */\nexport interface ReducerEventInfo {\n readonly name: string;\n /** `foreign: true` — the name belongs to someone else and stays bare. */\n readonly foreign: boolean;\n /** WHO SENDS THIS. `undefined` means the chart does not say — never a guess. */\n readonly from?: EventOrigin;\n /** Whether the event declared a payload (`data: ty<…>()`). */\n readonly hasPayload: boolean;\n /** `false` iff the chart declares this event and routes it nowhere. */\n readonly routed: boolean;\n}\n\n/**\n * A reducer-form chart, as data a UI can build itself from — the same contract\n * as {@link import(\"./describe\").ChartDescription}, over the facts this form\n * actually has.\n */\nexport interface ReducerChartDescription {\n /** The declared state names, in declaration order. Flat: there are no groups. */\n readonly states: readonly string[];\n /** The entry state — the chart's `initial` field, not a marked node. */\n readonly initial: string;\n readonly events: readonly ReducerEventInfo[];\n /** Every cmd DECLARED in the `cmds` section — the effect alphabet. */\n readonly cmds: readonly string[];\n readonly guards: readonly string[];\n readonly cells: readonly string[];\n /** One edge per routed event, in the alphabet's declaration order. */\n readonly edges: readonly ReducerEdge[];\n /**\n * TOTALITY, read back off the value: `true` iff every declared event owes and\n * has an edge. Through the typed door this is always `true` — `on` is a\n * required mapped type — so a `false` here means the types were bypassed with\n * a cast, exactly as `refusals`' `undeclared` kind does in the grid form.\n */\n readonly total: boolean;\n /** The declared events with no edge. Empty through the typed door. */\n readonly missing: readonly string[];\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly phases: Unanswerable<\"phases\">;\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly refusals: Unanswerable<\"refusals\">;\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly scope: Unanswerable<\"scope\">;\n}\n\n/**\n * Read a reducer-form chart into its {@link ReducerChartDescription}.\n *\n * Pure, total and allocation-only, exactly as `describeChart` is: it never runs\n * a guard, a cell or a payload builder, so it is safe on a chart whose parts do\n * not exist yet.\n */\nexport function describeReducerChart<const C extends ReducerChart<C>>(\n chart: C,\n): ReducerChartDescription {\n const c = chart as unknown as RtReducerChart;\n\n const edges: ReducerEdge[] = [];\n const events: ReducerEventInfo[] = [];\n const missing: string[] = [];\n const guards = new Set<string>();\n const cells = new Set<string>();\n\n for (const [name, decl] of Object.entries(c.events)) {\n // the site key IS the event: one dimension, so `at` is the bare name — the\n // same key `compileReducer` hands guards, cmds and cells.\n const spec = c.on?.[name];\n if (spec === undefined) {\n missing.push(name);\n } else {\n const edge = readEdgeCore(name, name, spec);\n edges.push(edge);\n if (edge.guard !== undefined) guards.add(edge.guard);\n if (edge.cell !== undefined) cells.add(edge.cell);\n }\n events.push({\n name,\n foreign: decl?.foreign === true,\n ...(decl?.from === undefined ? {} : { from: decl.from }),\n hasPayload: decl !== undefined && \"data\" in decl,\n routed: spec !== undefined,\n });\n }\n\n return {\n states: [...(c.states ?? [])],\n initial: c.initial,\n events,\n cmds: Object.keys(c.cmds ?? {}),\n guards: [...guards],\n cells: [...cells],\n edges,\n total: missing.length === 0,\n missing,\n phases: NO_PHASES,\n refusals: NO_REFUSALS,\n scope: NO_SCOPE,\n };\n}\n\n/** The edge that routes `event`, or `undefined` when the chart routes it nowhere. */\nexport function reducerEdgeAt(\n desc: ReducerChartDescription,\n event: string,\n): ReducerEdge | undefined {\n return desc.edges.find((e) => e.event === event);\n}\n\n// ── the live layer ────────────────────────────────────────────────────────\n\n/**\n * What would happen if `event` were dispatched at the current state.\n *\n * There is NO `status` field, and its absence is the honest part: this form\n * cannot refuse an event — `on` is total over the alphabet and there is no\n * state dimension to refuse from — so a \"legal\" tag would be a distinction\n * without a second case. Everything a grid preview can still say here it says:\n * the edge, the guard's branch, the declared fan-out, the target a cell picks.\n *\n * The cmds are the DECLARED ones — the before question. For what actually\n * fired, see `captureCmds` in `./captured`.\n */\nexport interface ReducerEventPreview {\n readonly event: string;\n /** The event's declared `from`, carried through rather than recomputed. */\n readonly from?: EventOrigin;\n /** The declared edge. `undefined` only when the chart routes the event nowhere. */\n readonly edge?: ReducerEdge;\n /** Present iff the edge is guarded. */\n readonly guard?: GuardPreview;\n /** The cmds the edge DECLARES for the arm that resolved. */\n readonly cmds: readonly string[];\n /** Every state the edge declares it can reach. */\n readonly targets: readonly string[];\n /** The single target, when one is determined. */\n readonly resolved?: string;\n /** How {@link ReducerEventPreview.resolved} was determined. */\n readonly resolvedBy?: ResolvedBy;\n /** The msg this preview used, or `undefined` when no sample was supplied. */\n readonly msg?: { readonly type: string };\n}\n\n/**\n * Preview one event of a reducer chart against a live state.\n *\n * The guard and cell previews are the SAME functions the grid form uses — a\n * guard is pure and a cell is pure in both forms, and the only difference is\n * that `at` is the bare event name.\n */\nexport function previewReducerEvent<S extends { readonly type: string }>(\n desc: ReducerChartDescription,\n state: S,\n event: string,\n opts: InspectOptions = {},\n): ReducerEventPreview {\n const info = desc.events.find((e) => e.name === event);\n const from = info?.from === undefined ? {} : { from: info.from };\n const edge = reducerEdgeAt(desc, event);\n\n if (edge === undefined) {\n // Unreachable through the typed door: `on` is a required mapped type. It is\n // reported rather than swallowed for the same reason `undeclared` is — a\n // chart that reaches here was cast into existence.\n return { event, ...from, cmds: [], targets: [] };\n }\n\n const msg = sampleMsg(event, info?.hasPayload === true, opts.samples);\n const base = { event, ...from, edge, targets: edge.targets, msg };\n\n switch (edge.kind) {\n case \"plain\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.targets[0],\n resolvedBy: edge.targets.length === 1 ? \"declared\" : undefined,\n };\n\n case \"guarded\": {\n const guard = previewGuardOn(edge, state, msg, opts);\n return {\n ...base,\n guard,\n cmds: guard.branch === \"unknown\" ? edge.cmds : guard.cmds,\n resolved: guard.branch === \"unknown\" ? undefined : guard.target,\n resolvedBy: guard.branch === \"unknown\" ? undefined : \"guard\",\n };\n }\n\n case \"cell\": {\n const resolved = runCellOn(edge, state, msg, opts);\n return {\n ...base,\n // A cell builds its own cmds in its body, so the chart declares none —\n // empty BY DECLARATION, which is exactly the gap `captureCmds` closes.\n cmds: edge.cmds,\n resolved,\n resolvedBy: resolved === undefined ? undefined : \"cell\",\n };\n }\n\n // `resume` needs a phase dimension and `defineReducerChart` rejects it by\n // name (`__resumeNeedsAPhaseDimension`). Reaching here means a cast; the\n // declared fallback is the only truthful answer left.\n case \"resume\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.fallback,\n resolvedBy: \"resume\",\n };\n }\n}\n\n/**\n * Preview EVERY event of a reducer chart's alphabet against a live state, in\n * declaration order. The button row — and here every control is live, because\n * this form has nothing with which to refuse one.\n */\nexport function inspectReducerState<S extends { readonly type: string }>(\n desc: ReducerChartDescription,\n state: S,\n opts: InspectOptions = {},\n): readonly ReducerEventPreview[] {\n return desc.events.map((e) => previewReducerEvent(desc, state, e.name, opts));\n}\n"]}
1
+ {"version":3,"sources":["../src/chart/inspect/captured.ts","../src/chart/inspect/describe.ts","../src/chart/inspect/samples.ts","../src/chart/inspect/live.ts","../src/chart/inspect/reducer.ts"],"names":[],"mappings":";;;AAoFO,SAAS,WAAA,CAOd,SACA,KAAA,EACkB;AAClB,EAAA,MAAM,QAA8B,EAAC;AACrC,EAAA,MAAM,OAAY,EAAC;AACnB,EAAA,IAAI,IAAA,GAAO,CAAA;AAEX,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,IAAK,KAAA,CAAM,IAAA,CAAK,QAAQ,CAAA,EAAA,EAAK;AAC3C,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AAGF,MAAA,KAAA,GAAQ,OAAO,OAAA,EAAS;AAAA,QACtB,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,QAC3B,KAAK,KAAA,CAAM,GAAA;AAAA,QACX,MAAA,EAAQ,MAAM,MAAA,IAAU;AAAA,OACzB,CAAA,CAAE,IAAA;AAAA,IACL,SAAS,CAAA,EAAG;AACV,MAAA,OAAO;AAAA,QACL,KAAA;AAAA,QACA,IAAA;AAAA,QACA,SAAA,EAAW;AAAA,UACT,IAAA,EAAM,CAAA;AAAA,UACN,OAAO,CAAA,YAAa,KAAA,GAAQ,CAA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,IAEA,KAAK,MAAA,EAAQ;AACX,MAAA,MAAM,QAAA,GAAW,SAAA,CAAU,IAAA,EAAM,KAAA,EAAO,KAAK,IAAI,CAAA;AACjD,MAAA,OAAO;AAAA,QACL,GAAG,IAAA;AAAA;AAAA;AAAA,QAGH,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,QAAA;AAAA,QACA,UAAA,EAAY,QAAA,KAAa,MAAA,GAAY,MAAA,GAAY;AAAA,OACnD;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,KAAK,QAAA;AACH,MAAA,OAAO;AAAA,QACL,GAAG,IAAA;AAAA,QACH,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,UAAU,IAAA,CAAK,QAAA;AAAA,QACf,UAAA,EAAY;AAAA,OACd;AAAA;AAEN;AAOO,SAAS,mBAAA,CACd,IAAA,EACA,KAAA,EACA,IAAA,GAAuB,EAAC,EACQ;AAChC,EAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA,KAAM,mBAAA,CAAoB,IAAA,EAAM,KAAA,EAAO,CAAA,CAAE,IAAA,EAAM,IAAI,CAAC,CAAA;AAC9E","file":"chunk-3ZAFFRRB.js","sourcesContent":["// ═══════════════════════════════════════════════════════════════════════════\n// THE CAPTURED CMDS — what actually fired, not what would.\n//\n// `describeChart` reads the cmds an edge DECLARES, and `previewEvent` reports\n// them as the effects a dispatch would cause. That is a BEFORE question, and it\n// has two blind spots by construction:\n//\n// 1. a `{ to, cell }` edge declares no cmds at all — the cell builds them in\n// its body, so the chart has nothing to show for exactly the edges that do\n// the most interesting work; and\n// 2. a guarded edge declares both arms, and only one of them ever fired.\n//\n// This module answers the AFTER question, and it does it without a new observer\n// seam: `replay` already returns the cmds a fold emitted, and the scrubber\n// already re-folds a prefix of the recorded msgs through it. So \"what fired at\n// step n\" is the difference between two prefixes that are already being\n// computed — read off the machine's own output, by the same pure fold, with\n// nothing subscribed and nothing intercepted.\n//\n// PURE. `replay` runs `init` + `update` only — never `interpret`, never a Store,\n// never a subscription — so capturing a cmd list cannot re-perform the effect it\n// is reporting. That is the same guarantee the scrubber rests on.\n//\n// COST. One `replay` per step, so the walk is quadratic in the trace length.\n// That is deliberate: the alternative is a second fold implementation inside\n// this module, and a second fold is a second answer — the thing the whole\n// inspector exists to avoid. Traces are inspector-sized (tens to hundreds of\n// msgs), and the fold is pure arithmetic over plain data.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport { type Cmd, type Machine, replay, type Sub } from \"../../index\";\n\n/**\n * The cmds ONE step emitted, tagged with the msg that caused them.\n *\n * `step` is `0` for `init` and `n` for the nth recorded msg, which is the same\n * index the scrubber's cursor uses — so a UI showing step `n` asks for\n * `capture.steps[n]` and gets the effects of the transition it is displaying.\n */\nexport interface CapturedStep<M extends { type: string }, K extends Cmd> {\n /** `0` = `init`; `1..n` = the nth recorded msg. */\n readonly step: number;\n /**\n * The msg that caused these cmds. `null` at step `0` — `init` has no cause,\n * and pinning its cmds on the first msg would be a lie about who fired them.\n */\n readonly by: M | null;\n /** What ACTUALLY fired, in emission order. Cell-built cmds included. */\n readonly cmds: readonly K[];\n}\n\n/**\n * Every step of a recorded run, with the cmds each one actually emitted.\n *\n * `stoppedAt` is the honest degradation: a fold that throws (a chart compiled\n * against parts that are not there, a cell that blew up on a state the current\n * code no longer produces) truncates the capture at that step and says so,\n * rather than reporting a short list as if it were complete.\n */\nexport interface CmdCapture<M extends { type: string }, K extends Cmd> {\n readonly steps: readonly CapturedStep<M, K>[];\n /** Every captured cmd, flattened in fire order. */\n readonly cmds: readonly K[];\n /** Present iff the fold threw before the trace ran out. */\n readonly stoppedAt?: { readonly step: number; readonly error: string };\n}\n\n/** The recorded input a capture folds — `Trace`'s two input halves. */\nexport interface CaptureInput<S, M extends { type: string }, Ctx> {\n readonly msgs: readonly M[];\n readonly ctx: Ctx;\n /** The rehydrated state the run booted from, when it booted from one. */\n readonly loaded?: S | null;\n}\n\n/**\n * Fold `input` through `machine` and report the cmds EVERY step emitted.\n *\n * This is the after-the-fact counterpart to the declarative preview: where\n * `EventPreview.cmds` says *what would fire if this event were dispatched now*,\n * this says *what did fire, in order, and which msg caused it*. Both are useful\n * and they are not the same question — a cell edge declares no cmds and emits\n * plenty, and a guarded edge declares two arms and takes one.\n */\nexport function captureCmds<\n S,\n M extends { type: string },\n K extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, K, U, Ctx>,\n input: CaptureInput<S, M, Ctx>,\n): CmdCapture<M, K> {\n const steps: CapturedStep<M, K>[] = [];\n const cmds: K[] = [];\n let seen = 0;\n\n for (let n = 0; n <= input.msgs.length; n++) {\n let sofar: readonly K[];\n try {\n // `replay`'s cmds are CUMULATIVE over the prefix, in fold order, so the\n // ones this step added are exactly the tail past the previous prefix.\n sofar = replay(machine, {\n msgs: input.msgs.slice(0, n),\n ctx: input.ctx,\n loaded: input.loaded ?? null,\n }).cmds;\n } catch (e) {\n return {\n steps,\n cmds,\n stoppedAt: {\n step: n,\n error: e instanceof Error ? e.message : String(e),\n },\n };\n }\n const fired = sofar.slice(seen);\n seen = sofar.length;\n cmds.push(...fired);\n steps.push({\n step: n,\n by: n === 0 ? null : (input.msgs[n - 1] ?? null),\n cmds: fired,\n });\n }\n\n return { steps, cmds };\n}\n\n/**\n * The step at cursor `n`, or `undefined` when the capture does not reach it\n * (an out-of-range cursor, or a fold that stopped early).\n */\nexport function firedAt<M extends { type: string }, K extends Cmd>(\n capture: CmdCapture<M, K>,\n step: number,\n): CapturedStep<M, K> | undefined {\n return capture.steps.find((s) => s.step === step);\n}\n\n/**\n * The captured cmds grouped by cmd NAME, in first-fire order — the roll-up a\n * \"which effects did this run actually perform\" panel wants.\n */\nexport function firedCounts<M extends { type: string }, K extends Cmd>(\n capture: CmdCapture<M, K>,\n): readonly { readonly type: string; readonly count: number }[] {\n const counts = new Map<string, number>();\n for (const c of capture.cmds) {\n counts.set(c.type, (counts.get(c.type) ?? 0) + 1);\n }\n return [...counts].map(([type, count]) => ({ type, count }));\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE STATIC DESCRIPTION — a chart, read as data.\n//\n// Everything a debugger UI needs to build itself is already IN the chart: the\n// phases, the states, which one is the entry, which are terminal, every edge\n// with its event / targets / guard / cell / cmds, and — the part no other\n// inspector has — every explicit REFUSAL, because the chart's totality means a\n// (state, event) pair is DECLARED or REFUSED and there is no third case.\n//\n// So this module hand-lists nothing. It walks the same runtime views `compile`\n// walks, and it derives refusals with the SAME predicate `compile` uses to\n// decide between a self-loop and a `NoCellError` — one rule, read twice, so\n// the picture and the machine cannot disagree about what is refused.\n//\n// PURE and framework-free. No React, no DOM, no `Machine`. A script, an Ink\n// TUI, or a test gets exactly this.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { Chart, EventOrigin } from \"../graph\";\n\n// ── the runtime views (the same shapes `compile` reads) ───────────────────\nexport type RtEdge =\n | string\n | {\n readonly target?: string;\n readonly when?: string;\n readonly otherwise?: string;\n readonly cmd?: string | readonly string[];\n readonly otherwiseCmd?: string | readonly string[];\n readonly resume?: { readonly fallback: string };\n readonly to?: readonly string[];\n readonly cell?: string;\n };\ntype RtNode = {\n readonly initial?: true;\n readonly data?: object;\n readonly on?: Record<string, RtEdge>;\n readonly ignore?: readonly string[];\n // BOTH POLARITIES. `end: true` (reached the goal) and `end: \"error\"` (stopped\n // because it failed) are both finals — `graph.ts`'s `IsEndOf` reads the pair,\n // and `end-polarity.test.ts` pins the two runtime sites that used to read\n // only `=== true`. This was the third such site: an error final described\n // here as `end: false` re-acquired the totality obligation, so a scoped event\n // over it came back `undeclared` (\"the chart's totality was bypassed\")\n // instead of refused — the loudest possible wrong answer.\n readonly end?: true | \"error\";\n};\ntype RtChart = {\n readonly ctx?: object;\n readonly events: Record<\n string,\n {\n readonly scope: string | readonly string[];\n readonly foreign?: true;\n readonly from?: EventOrigin;\n readonly data?: object;\n }\n >;\n readonly cmds?: Record<string, object>;\n readonly states: Record<string, Record<string, RtNode>>;\n};\n\n/** `undefined` → none; `\"x\"` → one; `[\"x\",\"y\"]` → both, in declaration order. */\nfunction cmdNames(\n ref: string | readonly string[] | undefined,\n): readonly string[] {\n if (ref === undefined) return [];\n return typeof ref === \"string\" ? [ref] : [...ref];\n}\n\nfunction scopeList(scope: string | readonly string[]): readonly string[] {\n return typeof scope === \"string\" ? [scope] : [...scope];\n}\n\n// ── the description ───────────────────────────────────────────────────────\n\n/**\n * WHY a (state, event) pair is refused. The chart's three refusal mechanisms,\n * each carrying the evidence that produced it, so a UI can say *\"`WIP` is not\n * addressed to `blocked` — its scope is `edges`\"* rather than \"disabled\".\n *\n * `undeclared` is the fourth case the type layer forbids: a pair that is live,\n * unhandled and unrefused. It cannot occur on a chart that compiled through\n * `defineChart`, and it is reported rather than swallowed because reaching it\n * means the types were bypassed with a cast — which is precisely when a\n * debugger should say so instead of drawing a well-behaved button.\n */\nexport type RefusalReason =\n | {\n readonly kind: \"end\";\n /** Terminal state: it accepts nothing, by declaration. */\n readonly state: string;\n }\n | {\n readonly kind: \"out-of-scope\";\n /** The event's declared `scope`, flattened to its members. */\n readonly scope: readonly string[];\n /** The phase this state lives in — the one that is not in `scope`. */\n readonly phase: string;\n }\n | {\n /**\n * `scope: \"edges\"` — the event is live exactly where an edge declares it,\n * and this state declares none.\n *\n * SPLIT OUT OF `out-of-scope` because the phase has nothing to do with it.\n * `\"edges\"` is not a phase name, so the phase test could never pass and\n * the refusal came back naming a phase the reader then went looking for:\n * *\"`DONE` is not addressed to phase `working` (scope: edges)\"* — three\n * pieces of vocabulary for one fact, and the fact is not in there. The\n * default scope is `edges`, so this was most refusals on most charts.\n */\n readonly kind: \"no-edge\";\n readonly state: string;\n }\n | {\n readonly kind: \"ignored\";\n /** The event is live here and this state refuses it BY NAME. */\n readonly state: string;\n }\n | { readonly kind: \"undeclared\" };\n\n/** A one-line, human-readable rendering of a {@link RefusalReason}. */\nexport function explainRefusal(event: string, reason: RefusalReason): string {\n switch (reason.kind) {\n case \"end\":\n return `\"${reason.state}\" is an end state — it accepts nothing`;\n case \"out-of-scope\":\n return `\"${event}\" is not addressed to phase \"${reason.phase}\" (scope: ${reason.scope.join(\", \")})`;\n case \"no-edge\":\n return `\"${reason.state}\" declares no \"${event}\" edge`;\n case \"ignored\":\n return `\"${reason.state}\" lists \"${event}\" in its \\`ignore\\``;\n case \"undeclared\":\n return `\"${event}\" is live here, unhandled and unrefused — the chart's totality was bypassed`;\n }\n}\n\n/** What kind of transition an edge declares. */\nexport type EdgeKind = \"plain\" | \"guarded\" | \"cell\" | \"resume\";\n\n/** One declared edge — a `(state, event)` pair the chart routes. */\nexport interface ChartEdge {\n readonly from: string;\n readonly event: string;\n /** `\"${from}.${event}\"` — the site key guards/cmds/cells are indexed by. */\n readonly at: string;\n readonly kind: EdgeKind;\n /**\n * Every state this edge can land on, in declaration order. A guarded edge\n * contributes both arms; a cell edge contributes its whole declared `to`.\n * For a resume edge this is the fallback alone — the real target is\n * `state.was`, which is a property of the LIVE state, not of the chart.\n */\n readonly targets: readonly string[];\n /** The guard's name, on a guarded edge. */\n readonly guard?: string;\n /** The target taken when the guard HOLDS. */\n readonly then?: string;\n /** The target taken when the guard FAILS. */\n readonly otherwise?: string;\n /** The cell's name, on a `{ to, cell }` edge. */\n readonly cell?: string;\n /** The declared fallback, on a `resume` edge. */\n readonly fallback?: string;\n /** Cmds fired when the edge fires (the guard's `then` arm, if guarded). */\n readonly cmds: readonly string[];\n /** Cmds fired when the guard FAILS. Empty unless the edge is guarded. */\n readonly otherwiseCmds: readonly string[];\n}\n\n/** A (state, event) pair the chart explicitly refuses, and why. */\nexport interface ChartRefusal {\n readonly from: string;\n readonly event: string;\n readonly reason: RefusalReason;\n}\n\n/** One state, with the facts the chart declares about it. */\nexport interface ChartStateInfo {\n readonly name: string;\n /** The phase it was declared under. */\n readonly phase: string;\n /** `initial: true` — the entry state. Exactly one per machine-bearing chart. */\n readonly initial: boolean;\n /**\n * Terminal by DECLARATION, not by \"has no outgoing edges\" — `true` for both\n * polarities, because both accept nothing and both owe nothing.\n */\n readonly end: boolean;\n /**\n * WHICH ending. `true` a success final, `\"error\"` the failure terminal,\n * `false` not a final at all.\n *\n * `end` answers \"does this accept anything\"; this answers \"did the machine\n * win or lose\". A lane needs both and they are not the same question —\n * `shipped` and `frozen` are equally terminal and are not the same outcome.\n */\n readonly endPolarity: false | true | \"error\";\n /** Carries a `resume` edge out of it, so the compiler injects `was` here. */\n readonly parking: boolean;\n}\n\n/** One event of the alphabet. */\nexport interface ChartEventInfo {\n readonly name: string;\n /** The declared `scope`, flattened: `\"edges\"`, `\"all\"`, or phase names. */\n readonly scope: readonly string[];\n /** `foreign: true` — the name belongs to someone else and stays bare. */\n readonly foreign: boolean;\n /**\n * WHERE THIS EVENT COMES FROM — `from`, read back off the chart.\n *\n * `undefined` means the chart does not say, which is a fact of its own and\n * never a default: a UI that groups its button row by sender must render the\n * undeclared ones as undeclared rather than filing them under a guess.\n */\n readonly from?: EventOrigin;\n /**\n * Whether the event DECLARED a payload (`data: ty<…>()`).\n *\n * `ty<T>()` is `{}` at runtime, so `T` is unreadable — but the `data` KEY is\n * right there in the literal, so \"does this event carry a payload at all\" IS\n * a runtime fact. It is what decides whether a sample is required.\n */\n readonly hasPayload: boolean;\n}\n\n/**\n * A whole chart, as data a UI can build itself from. Nothing here is supplied\n * by the caller; every field is read off the one chart value.\n */\nexport interface ChartDescription {\n /** The phases, in declaration order, each with its member states. */\n readonly phases: readonly {\n readonly name: string;\n readonly states: readonly string[];\n }[];\n readonly states: readonly ChartStateInfo[];\n /** The state marked `initial: true`, or `undefined` on a chart with none. */\n readonly initial: string | undefined;\n readonly events: readonly ChartEventInfo[];\n /** Every cmd DECLARED in the `cmds` section — the effect alphabet. */\n readonly cmds: readonly string[];\n /** Every guard name any edge references. */\n readonly guards: readonly string[];\n /** Every cell name any `{ to, cell }` edge references. */\n readonly cells: readonly string[];\n readonly edges: readonly ChartEdge[];\n readonly refusals: readonly ChartRefusal[];\n}\n\n/**\n * A read edge MINUS the state it leaves — everything about an edge that is a\n * fact of the edge itself rather than of the grid it sits in.\n *\n * The reducer form has no state dimension (`src/chart/inspect/reducer.ts`), so\n * its edges are exactly this: same kinds, same targets, same guard/cell/cmd\n * fields, with `from` unrepresentable rather than blank.\n */\nexport type EdgeCore = Omit<ChartEdge, \"from\">;\n\n/**\n * Read one edge spec into {@link EdgeCore}. `at` is the site key the parts bag\n * is indexed by — `\"state.event\"` in the grid form, the bare event in the\n * reducer form — and it is passed in rather than derived, because that key IS\n * the difference between the two forms.\n */\nexport function readEdgeCore(\n event: string,\n at: string,\n spec: RtEdge,\n): EdgeCore {\n const edge = typeof spec === \"string\" ? { target: spec } : spec;\n const cmds = cmdNames(edge.cmd);\n const otherwiseCmds = cmdNames(edge.otherwiseCmd);\n\n if (edge.cell !== undefined) {\n return {\n event,\n at,\n kind: \"cell\",\n targets: [...(edge.to ?? [])],\n cell: edge.cell,\n cmds,\n otherwiseCmds,\n };\n }\n if (edge.resume !== undefined) {\n return {\n event,\n at,\n kind: \"resume\",\n targets: [edge.resume.fallback],\n fallback: edge.resume.fallback,\n cmds,\n otherwiseCmds,\n };\n }\n if (edge.when !== undefined) {\n const then = edge.target ?? \"\";\n const otherwise = edge.otherwise ?? \"\";\n return {\n event,\n at,\n kind: \"guarded\",\n targets: [then, otherwise],\n guard: edge.when,\n then,\n otherwise,\n cmds,\n otherwiseCmds,\n };\n }\n return {\n event,\n at,\n kind: \"plain\",\n targets: edge.target === undefined ? [] : [edge.target],\n cmds,\n otherwiseCmds,\n };\n}\n\n/** Read one edge spec into the flat {@link ChartEdge} shape. */\nfunction readEdge(from: string, event: string, spec: RtEdge): ChartEdge {\n return { from, ...readEdgeCore(event, `${from}.${event}`, spec) };\n}\n\n/**\n * Why `from` refuses `event`, or `undefined` when it does not refuse it.\n *\n * THE SAME PREDICATE `compile` USES. `compile` computes `refused = end || !live\n * || ignore.includes(e)` to decide between a self-loop and a `NoCellError`;\n * this splits the same three tests apart to name WHICH one fired, in the order\n * that makes the most specific declaration win — `end: true` is a statement\n * about the state, `scope` about the event, `ignore` about the pair.\n */\nfunction refusalAt(\n c: RtChart,\n node: RtNode,\n phase: string,\n state: string,\n event: string,\n): RefusalReason | undefined {\n if (node.on?.[event] !== undefined) return undefined;\n if (node.end !== undefined) return { kind: \"end\", state };\n const scope = scopeList(c.events[event]?.scope ?? \"edges\");\n const live = scope.includes(\"all\") || scope.includes(phase);\n // `edges` is a scope with no phase in it, so it fails the phase test for a\n // reason that is not about the phase — say the one that is true. Only when\n // `edges` is the WHOLE scope: a `[\"edges\", \"review\"]` event really is out of\n // scope in `working`, and that is the phase's news after all.\n if (!live && scope.length === 1 && scope[0] === \"edges\") {\n return { kind: \"no-edge\", state };\n }\n if (!live) return { kind: \"out-of-scope\", scope, phase };\n if ((node.ignore ?? []).includes(event)) return { kind: \"ignored\", state };\n return { kind: \"undeclared\" };\n}\n\n/**\n * Read a chart into its {@link ChartDescription}.\n *\n * Pure, total, and allocation-only — it never executes a guard, a cell or a\n * payload builder, so it is safe on a chart whose parts do not exist yet.\n */\nexport function describeChart<const C extends Chart<C>>(\n chart: C,\n): ChartDescription {\n const c = chart as unknown as RtChart;\n\n const phases: { name: string; states: string[] }[] = [];\n const states: ChartStateInfo[] = [];\n const edges: ChartEdge[] = [];\n const refusals: ChartRefusal[] = [];\n const guards = new Set<string>();\n const cells = new Set<string>();\n const parking = new Set<string>();\n let initial: string | undefined;\n\n // Pass 1 — the nodes, the phases and the edges. `parking` is a derivation\n // over the whole chart (a state is parking iff SOME edge out of it resumes),\n // so it is collected here and read in pass 2.\n const flat: { state: string; phase: string; node: RtNode }[] = [];\n for (const [phase, members] of Object.entries(c.states)) {\n const names: string[] = [];\n for (const [state, node] of Object.entries(members)) {\n names.push(state);\n flat.push({ state, phase, node });\n if (node.initial === true) initial ??= state;\n for (const [event, spec] of Object.entries(node.on ?? {})) {\n const edge = readEdge(state, event, spec);\n edges.push(edge);\n if (edge.guard !== undefined) guards.add(edge.guard);\n if (edge.cell !== undefined) cells.add(edge.cell);\n if (edge.kind === \"resume\") parking.add(state);\n }\n }\n phases.push({ name: phase, states: names });\n }\n\n // Pass 2 — the state records (which need `parking`) and the refusals (which\n // are a full |S| × |M| sweep minus the declared edges).\n const events = Object.keys(c.events);\n for (const { state, phase, node } of flat) {\n states.push({\n name: state,\n phase,\n initial: node.initial === true,\n end: node.end !== undefined,\n endPolarity: node.end ?? false,\n parking: parking.has(state),\n });\n for (const event of events) {\n const reason = refusalAt(c, node, phase, state, event);\n if (reason !== undefined) refusals.push({ from: state, event, reason });\n }\n }\n\n return {\n phases: phases.map((p) => ({ name: p.name, states: p.states })),\n states,\n initial,\n events: events.map((name) => {\n const decl = c.events[name];\n return {\n name,\n scope: scopeList(decl?.scope ?? \"edges\"),\n foreign: decl?.foreign === true,\n ...(decl?.from === undefined ? {} : { from: decl.from }),\n hasPayload: decl !== undefined && \"data\" in decl,\n };\n }),\n cmds: Object.keys(c.cmds ?? {}),\n guards: [...guards],\n cells: [...cells],\n edges,\n refusals,\n };\n}\n\n/** The declared edge out of `state` on `event`, or `undefined`. */\nexport function edgeAt(\n desc: ChartDescription,\n state: string,\n event: string,\n): ChartEdge | undefined {\n return desc.edges.find((e) => e.from === state && e.event === event);\n}\n\n/** Why `state` refuses `event`, or `undefined` when it does not. */\nexport function refusalAtState(\n desc: ChartDescription,\n state: string,\n event: string,\n): RefusalReason | undefined {\n return desc.refusals.find((r) => r.from === state && r.event === event)\n ?.reason;\n}\n\n/** The record for `state`, or `undefined` when the chart has no such state. */\nexport function stateInfo(\n desc: ChartDescription,\n state: string,\n): ChartStateInfo | undefined {\n return desc.states.find((s) => s.name === state);\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// SAMPLES — the one thing the chart genuinely cannot know, typed BY the chart.\n//\n// `ty<T>()` is `{}` at runtime (graph.ts:33): a phantom whose TYPE remembers\n// the payload and whose VALUE remembers nothing. So an inspector that wants to\n// dispatch `WIP` cannot invent `{ at: 1 }` — the shape is erased before any\n// runtime code could read it.\n//\n// The author therefore supplies a sample per event. That is a REAL fact the\n// chart does not carry (what a plausible `at` is), which is why it is a prop\n// at all — and it is the ONLY payload prop, because everything else about the\n// event (its name, its scope, whether it carries a payload) IS in the chart.\n//\n// The bag is typed the same way `Assigns`/`Guards`/`Cmds` are: a mapped type\n// over a key union DERIVED from the chart, so the sample for `X` must be\n// exactly `X`'s declared payload, a typo'd event name is an excess property,\n// and an event whose payload the author forgot is a missing property tsc names.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventName, MsgOf } from \"../graph\";\n\ntype Narrow<U, K> = Extract<U, { type: K }>;\n\n/**\n * Event `E`'s declared payload — its Msg member minus the `type` the chart\n * already owns.\n *\n * Read off `MsgOf<C>` rather than off the `events` section directly, so it is\n * the SAME derivation the compiled machine consumes: a sample that type-checks\n * here is a msg the machine accepts, by construction. An event with no `data`\n * has `DataOf = unknown`, so this is `{}` — no keys, nothing to supply.\n */\nexport type SamplePayload<C, E extends string> = Omit<\n Narrow<MsgOf<C>, E>,\n \"type\"\n>;\n\n/** Does event `E` declare a payload the author must fill in? */\ntype NeedsSample<C, E extends string> = [keyof SamplePayload<C, E>] extends [\n never,\n]\n ? false\n : true;\n\n/**\n * The sample bag: one entry per event that DECLARES a payload, each typed as\n * exactly that payload.\n *\n * The `as` clause drops the payload-free events from the key union entirely —\n * so `{ START: {} }` for a bare `START: { scope: \"edges\" }` is an excess\n * property tsc rejects, rather than a meaningless entry it accepts. \"Where an\n * event has no declared payload, no sample is required\" is therefore not a\n * convention; it is unrepresentable to supply one.\n *\n * The `type` tag is absent for the same reason it is absent from an `assign`'s\n * return: it is the chart's fact, stamped on by {@link sampleMsg}, so the\n * author cannot write it wrong and cannot write it twice.\n *\n * ```ts\n * const samples: Samples<LaneG> = {\n * WIP: { at: 1 },\n * FAIL: { at: 2, reason: \"flaky\" }, // `reason` is REQUIRED — the chart says so\n * // BLOCKED: … // omit one and tsc names it\n * };\n * ```\n */\nexport type Samples<C> = {\n readonly [E in EventName<C> as [NeedsSample<C, E>] extends [true]\n ? E\n : never]: SamplePayload<C, E>;\n};\n\n/** The samples bag as the runtime reads it: event name → payload object. */\nexport type RtSamples = Readonly<Record<string, object | undefined>>;\n\n/**\n * Build the Msg for `event` from the sample bag: the payload, plus the `type`\n * the chart owns.\n *\n * Returns `undefined` exactly when the event needs a payload and none was\n * supplied — which is the honest \"cannot\" the guard preview degrades on,\n * rather than a half-built msg that makes a guard throw for the wrong reason.\n */\nexport function sampleMsg(\n event: string,\n hasPayload: boolean,\n samples: RtSamples | undefined,\n): { readonly type: string } | undefined {\n const payload = samples?.[event];\n if (payload === undefined) {\n return hasPayload ? undefined : { type: event };\n }\n return { ...payload, type: event };\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE LIVE LAYER — the chart, asked about the state it is in RIGHT NOW.\n//\n// The static description says what the machine can do anywhere. This says what\n// it can do here: which events are legal, which are refused and why, and — the\n// genuinely new capability — WHICH BRANCH a guarded edge would take, evaluated\n// by running the named guard against the live state and a sample msg.\n//\n// Everything here is PURE. Guards, cells and cmd builders are pure by the TEA\n// invariants (they are the same things `replay` is allowed to call), so a\n// preview costs nothing and changes nothing. Nothing in this file dispatches,\n// interprets, or touches a runtime.\n//\n// HONEST DEGRADATION is the design rule. A guard that cannot be evaluated — no\n// sample for its msg, no `guards` bag, a body that throws on this state — is\n// reported as `unknown` WITH the reason. It is never guessed, and never\n// silently rendered as `else`.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventOrigin } from \"../graph\";\nimport {\n type ChartDescription,\n type ChartEdge,\n type EdgeCore,\n edgeAt,\n explainRefusal,\n type RefusalReason,\n refusalAtState,\n} from \"./describe\";\nimport { type RtSamples, sampleMsg } from \"./samples\";\n\n// ── the runtime views of the parts bag ────────────────────────────────────\ntype RtState = { readonly type: string; readonly was?: string };\ntype RtMsg = { readonly type: string };\ntype RtGuard = (s: RtState, m: RtMsg, at: string) => boolean;\ntype RtCellFn = (\n s: RtState,\n m: RtMsg,\n at: string,\n) => readonly [RtState, readonly { readonly type: string }[]];\n\n// The parameter type is `never[]`, deliberately. A `Guards<C, S, M>` entry is\n// PRE-NARROWED to its use site (`(s: ReviewState, m: FailMsg, at: \"review.FAIL\")`),\n// and parameters are checked contravariantly — so a bag typed against a widened\n// `(s: { type: string }, …)` REJECTS the very bag `compile` demands, which would\n// force every caller to cast the parts they already have. `never` is the one\n// parameter type every function accepts, so the author passes `parts` through\n// untouched; the narrowing back to a callable shape is one cast, here, at the\n// call boundary (the same place `compile` puts its own).\n/** Any guard, however narrowly its use sites typed it. */\nexport type AnyGuard = (...args: never[]) => boolean;\n/** Any cell, in either the single-body or the per-site form. */\nexport type AnyCell =\n | ((...args: never[]) => readonly [{ readonly type: string }, unknown])\n | Readonly<Record<string, unknown>>;\n\n/**\n * The code parts a preview may consult — the SAME bag `compile` receives, so\n * an author passes the one they already built rather than a second copy.\n * Every field is optional: the preview degrades where a part is absent.\n */\nexport interface InspectParts {\n readonly guards?: Readonly<Record<string, AnyGuard | undefined>>;\n readonly cells?: Readonly<Record<string, AnyCell | undefined>>;\n}\n\n/** Everything a live preview may consult, beyond the state itself. */\nexport interface InspectOptions {\n /** The parts bag `compile` was given. Guards/cells are read from it. */\n readonly parts?: InspectParts;\n /** Sample payload per event — see `./samples`. */\n readonly samples?: RtSamples;\n}\n\n// ── guard preview ─────────────────────────────────────────────────────────\n\n/** Why a guard could not be evaluated. Each is a fact, not a guess. */\nexport type GuardUnknown =\n | \"no-guard-bag\"\n | \"no-implementation\"\n | \"no-sample\"\n | \"threw\";\n\n/**\n * Which branch a guarded edge would take right now.\n *\n * `then` / `else` are ANSWERS — the guard ran, on this state, with this msg.\n * `unknown` is the honest non-answer, carrying the reason and (for a throwing\n * guard) the message, so a UI shows \"cannot evaluate: no sample for FAIL\"\n * rather than a confidently wrong arrow.\n */\nexport type GuardPreview =\n | {\n readonly guard: string;\n readonly branch: \"then\" | \"else\";\n /** The state that branch lands on. */\n readonly target: string;\n /** The cmds that branch fires. */\n readonly cmds: readonly string[];\n }\n | {\n readonly guard: string;\n readonly branch: \"unknown\";\n readonly why: GuardUnknown;\n /** The thrown error's message, when `why` is `\"threw\"`. */\n readonly error?: string;\n };\n\n/**\n * Run the named guard against `state` + a sample msg. Never throws.\n *\n * Takes an {@link EdgeCore} rather than a `ChartEdge`, so BOTH chart forms get\n * this one implementation: a guard is pure and site-keyed by `at` in either\n * form, and `from` is the only field that differs between their edges — a field\n * this function never reads. `./reducer` calls it directly.\n */\nexport function previewGuardOn(\n edge: EdgeCore,\n state: { readonly type: string },\n msg: RtMsg | undefined,\n opts: InspectOptions,\n): GuardPreview {\n const guard = edge.guard as string;\n const bag = opts.parts?.guards;\n if (bag === undefined)\n return { guard, branch: \"unknown\", why: \"no-guard-bag\" };\n const fn = bag[guard] as RtGuard | undefined;\n if (fn === undefined)\n return { guard, branch: \"unknown\", why: \"no-implementation\" };\n if (msg === undefined) return { guard, branch: \"unknown\", why: \"no-sample\" };\n try {\n const held = fn(state, msg, edge.at) === true;\n return held\n ? {\n guard,\n branch: \"then\",\n target: edge.then ?? \"\",\n cmds: edge.cmds,\n }\n : {\n guard,\n branch: \"else\",\n target: edge.otherwise ?? \"\",\n cmds: edge.otherwiseCmds,\n };\n } catch (e) {\n return {\n guard,\n branch: \"unknown\",\n why: \"threw\",\n error: e instanceof Error ? e.message : String(e),\n };\n }\n}\n\n// ── target resolution ─────────────────────────────────────────────────────\n\n/** How a single target was determined, when one could be. */\nexport type ResolvedBy = \"declared\" | \"guard\" | \"resume\" | \"cell\";\n\n/**\n * Run a cell purely to learn which target it actually picks. Never throws.\n *\n * {@link EdgeCore}, for the same reason {@link previewGuardOn} takes one: the\n * escape hatch is the same escape hatch in both chart forms, and `buildCell`\n * serves both from one body — so previewing it must not fork either.\n */\nexport function runCellOn(\n edge: EdgeCore,\n state: { readonly type: string },\n msg: RtMsg | undefined,\n opts: InspectOptions,\n): string | undefined {\n const impl = opts.parts?.cells?.[edge.cell as string] as\n | RtCellFn\n | Record<string, RtCellFn | undefined>\n | undefined;\n if (impl === undefined || msg === undefined) return undefined;\n // The two cell forms `compile` supports: one body for every site, or one\n // body per site keyed by `at`.\n const hand = typeof impl === \"function\" ? impl : impl[edge.at];\n if (hand === undefined) return undefined;\n try {\n const [next] = hand(state, msg, edge.at);\n const to = next?.type;\n // Respect the edge's own `to` clamp: a cell that returns outside it is the\n // `CellTargetError` case, and a preview must not draw what the runtime\n // would refuse.\n return typeof to === \"string\" && edge.targets.includes(to) ? to : undefined;\n } catch {\n return undefined;\n }\n}\n\n// ── the verdict ───────────────────────────────────────────────────────────\n\n/**\n * What would happen if `event` were dispatched at the current state.\n *\n * A refusal is FIRST-CLASS: it carries the reason and a rendered explanation,\n * so a UI draws it as visibly refused rather than omitting the control. That\n * is the totality property paying rent — the chart knows the difference\n * between \"not routed here\", \"deliberately dropped here\" and \"this state is\n * over\", and a debugger that hides all three behind a missing button throws\n * away the one thing this substrate knows and others do not.\n */\nexport interface EventPreview {\n readonly event: string;\n readonly status: \"legal\" | \"refused\";\n /**\n * Who would send this — the event's declared `from`, carried through rather\n * than recomputed, so a button row can be grouped by sender with the same\n * answer the report's \"waiting on\" line gives. `undefined` when the chart\n * does not say.\n */\n readonly from?: EventOrigin;\n /** Present iff `status` is `\"refused\"`. */\n readonly reason?: RefusalReason;\n /** A one-line rendering of `reason`. Present iff refused. */\n readonly why?: string;\n /** The declared edge. Present iff legal. */\n readonly edge?: ChartEdge;\n /** Present iff the edge is guarded. */\n readonly guard?: GuardPreview;\n /**\n * The cmds that WOULD fire — read off the edge's declaration. For a guarded\n * edge whose branch resolved, the cmds of THAT arm; for one that did not, the\n * `then` arm's (the declared happy path) — `guard.branch === \"unknown\"` is\n * what says so.\n *\n * This is the BEFORE question, and a `{ to, cell }` edge answers it with an\n * empty list BY DECLARATION: the cell builds its cmds inside its body, so the\n * chart has none to declare. For what actually fired, ask the after question\n * — `captureCmds` in `./captured`, which reads the emitted cmds off the\n * machine's own output.\n */\n readonly cmds: readonly string[];\n /** Every state the edge declares it can reach. */\n readonly targets: readonly string[];\n /** The single target, when one is determined. */\n readonly resolved?: string;\n /** How {@link EventPreview.resolved} was determined. */\n readonly resolvedBy?: ResolvedBy;\n /**\n * The msg this preview used — the sample plus the chart's `type`. `undefined`\n * when the event declares a payload and no sample was supplied, which is\n * also why a guard or cell may have come back `unknown`.\n */\n readonly msg?: { readonly type: string };\n}\n\n/**\n * Preview one event against a live state.\n *\n * @param desc the chart's {@link ChartDescription}.\n * @param state the live state — anything with a `type` (and `was`, on a\n * parking state, which is what makes a resume target resolvable).\n */\nexport function previewEvent<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n event: string,\n opts: InspectOptions = {},\n): EventPreview {\n const st = state as RtState;\n const edge = edgeAt(desc, st.type, event);\n const info = desc.events.find((e) => e.name === event);\n // The ONE read of provenance in this file, shared by both arms: a refused\n // event has a sender too, and hiding it would make the refused half of a\n // grouped button row unfilable.\n const from = info?.from === undefined ? {} : { from: info.from };\n\n if (edge === undefined) {\n const reason = refusalAtState(desc, st.type, event) ?? {\n kind: \"undeclared\" as const,\n };\n return {\n event,\n ...from,\n status: \"refused\",\n reason,\n why: explainRefusal(event, reason),\n cmds: [],\n targets: [],\n };\n }\n\n const msg = sampleMsg(event, info?.hasPayload === true, opts.samples);\n const base = {\n event,\n ...from,\n status: \"legal\" as const,\n edge,\n targets: edge.targets,\n msg,\n };\n\n switch (edge.kind) {\n case \"plain\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.targets[0],\n resolvedBy: edge.targets.length === 1 ? \"declared\" : undefined,\n };\n\n case \"guarded\": {\n const guard = previewGuardOn(edge, st, msg, opts);\n return {\n ...base,\n guard,\n cmds: guard.branch === \"unknown\" ? edge.cmds : guard.cmds,\n resolved: guard.branch === \"unknown\" ? undefined : guard.target,\n resolvedBy: guard.branch === \"unknown\" ? undefined : \"guard\",\n };\n }\n\n case \"resume\":\n // `was ?? fallback` — the runtime's own rule, read off the live state.\n // This is always resolvable, because `was` is INJECTED by the compiler\n // on entry to a parking state rather than authored.\n return {\n ...base,\n cmds: edge.cmds,\n targets: st.was === undefined ? edge.targets : [st.was],\n resolved: st.was ?? edge.fallback,\n resolvedBy: \"resume\",\n };\n\n case \"cell\": {\n const resolved = runCellOn(edge, st, msg, opts);\n return {\n ...base,\n // A cell builds its own cmds inside its body, so the chart declares\n // none for it — `cmds` is empty by declaration, not by omission.\n cmds: edge.cmds,\n resolved,\n resolvedBy: resolved === undefined ? undefined : \"cell\",\n };\n }\n }\n}\n\n/**\n * Preview EVERY event of the alphabet against a live state, in the chart's\n * declaration order.\n *\n * This is the button row: one entry per declared event, each either legal\n * (with its branch, targets and cmds) or refused (with its reason). Nothing is\n * filtered out — a refused event is a control the UI draws, not one it lacks.\n */\nexport function inspectState<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n opts: InspectOptions = {},\n): readonly EventPreview[] {\n return desc.events.map((e) => previewEvent(desc, state, e.name, opts));\n}\n\n/**\n * {@link inspectState}, plus the two roll-ups a caller almost always wants\n * next: the legal event names and the refused ones.\n *\n * The whole verdict list is still there — the split is a convenience, not a\n * filter, and `events` remains the surface a UI renders so a refusal keeps its\n * reason.\n */\nexport function inspectStateSummary<S extends { readonly type: string }>(\n desc: ChartDescription,\n state: S,\n opts: InspectOptions = {},\n): {\n readonly state: S;\n readonly events: readonly EventPreview[];\n readonly legal: readonly string[];\n readonly refused: readonly string[];\n} {\n const events = inspectState(desc, state, opts);\n return {\n state,\n events,\n legal: events.filter((e) => e.status === \"legal\").map((e) => e.event),\n refused: events.filter((e) => e.status === \"refused\").map((e) => e.event),\n };\n}\n","// ═══════════════════════════════════════════════════════════════════════════\n// THE REDUCER FORM, AS A DEBUGGER READS IT — the honest subset.\n//\n// `defineReducerChart` drops the dimension the machine does not have: no\n// phases, no per-state `on`, no `scope`, no `ignore`, no `end`. So its\n// description is not `ChartDescription` with some fields left empty; it is a\n// genuinely THINNER shape, and the whole design rule of this file is that the\n// thinness is stated rather than faked.\n//\n// WHAT IT CAN TRUTHFULLY SAY\n// - the flat state list, and the entry state (`initial`, one word);\n// - the event alphabet, each with `foreign`, `from` provenance, and whether\n// it declares a payload;\n// - per-event routing — the same four edge kinds, including a `{ to, cell }`\n// edge's whole declared fan-out;\n// - TOTALITY over events, which this form enforces MORE strictly than the\n// grid form: `on` is a required mapped type over the alphabet, so an event\n// with no edge is a missing property tsc names, where the grid form's\n// `scope: \"edges\"` lets an event be routed from nowhere at all.\n//\n// WHAT IT CANNOT, AND WILL NOT PRETEND TO\n// - per-state REFUSAL. A reducer cell receives the whole state un-narrowed\n// and decides inside its body; there is no (state, event) pair for the\n// chart to refuse. An empty `refusals: []` would read as \"nothing is\n// refused\", which is the loudest possible wrong answer — so the field holds\n// an {@link Unanswerable} instead, and a consumer that tries to iterate it\n// gets a type error rather than a comfortable lie.\n// - phases, and event `scope`. Same reason, same treatment.\n// ═══════════════════════════════════════════════════════════════════════════\n\nimport type { EventOrigin, ReducerChart } from \"../graph\";\nimport { type EdgeCore, type RtEdge, readEdgeCore } from \"./describe\";\nimport {\n type GuardPreview,\n type InspectOptions,\n previewGuardOn,\n type ResolvedBy,\n runCellOn,\n} from \"./live\";\nimport { sampleMsg } from \"./samples\";\n\n// ── the runtime view (the same shape `compileReducer` reads) ──────────────\ntype RtReducerChart = {\n readonly ctx?: object;\n readonly states: readonly string[];\n readonly initial: string;\n readonly events: Record<\n string,\n {\n readonly foreign?: true;\n readonly from?: EventOrigin;\n readonly data?: object;\n }\n >;\n readonly cmds?: Record<string, object>;\n readonly on: Record<string, RtEdge>;\n};\n\n/**\n * A QUESTION THIS FORM CANNOT ANSWER, carried in the slot where the grid form\n * carries the answer.\n *\n * `answerable: false` is the whole type: there is no `true` member, because a\n * question this form CAN answer is answered with the answer. So `desc.refusals`\n * on a reducer description is not an empty list a UI silently renders — it is a\n * value whose only shape says why the list is not there, and code written\n * against the grid form's array fails to compile against it.\n */\nexport interface Unanswerable<Q extends string> {\n readonly answerable: false;\n /** Which question — the grid-form field this stands in for. */\n readonly question: Q;\n /** One line, ready to render. */\n readonly why: string;\n}\n\nconst NO_PHASES: Unanswerable<\"phases\"> = {\n answerable: false,\n question: \"phases\",\n why: \"this chart form has no phase dimension — every edge is reachable from every state\",\n};\nconst NO_REFUSALS: Unanswerable<\"refusals\"> = {\n answerable: false,\n question: \"refusals\",\n why: \"this chart form has no state dimension — a refusal is a (state, event) fact, and a reducer cell decides inside its body\",\n};\nconst NO_SCOPE: Unanswerable<\"scope\"> = {\n answerable: false,\n question: \"scope\",\n why: \"this chart form has no phase dimension — `scope` answers 'at which states does this event mean anything', which has no content here\",\n};\n\n/** One edge of a reducer chart — an edge with no state to leave from. */\nexport type ReducerEdge = EdgeCore;\n\n/** One event of a reducer chart's alphabet. `scope` has no counterpart here. */\nexport interface ReducerEventInfo {\n readonly name: string;\n /** `foreign: true` — the name belongs to someone else and stays bare. */\n readonly foreign: boolean;\n /** WHO SENDS THIS. `undefined` means the chart does not say — never a guess. */\n readonly from?: EventOrigin;\n /** Whether the event declared a payload (`data: ty<…>()`). */\n readonly hasPayload: boolean;\n /** `false` iff the chart declares this event and routes it nowhere. */\n readonly routed: boolean;\n}\n\n/**\n * A reducer-form chart, as data a UI can build itself from — the same contract\n * as {@link import(\"./describe\").ChartDescription}, over the facts this form\n * actually has.\n */\nexport interface ReducerChartDescription {\n /** The declared state names, in declaration order. Flat: there are no groups. */\n readonly states: readonly string[];\n /** The entry state — the chart's `initial` field, not a marked node. */\n readonly initial: string;\n readonly events: readonly ReducerEventInfo[];\n /** Every cmd DECLARED in the `cmds` section — the effect alphabet. */\n readonly cmds: readonly string[];\n readonly guards: readonly string[];\n readonly cells: readonly string[];\n /** One edge per routed event, in the alphabet's declaration order. */\n readonly edges: readonly ReducerEdge[];\n /**\n * TOTALITY, read back off the value: `true` iff every declared event owes and\n * has an edge. Through the typed door this is always `true` — `on` is a\n * required mapped type — so a `false` here means the types were bypassed with\n * a cast, exactly as `refusals`' `undeclared` kind does in the grid form.\n */\n readonly total: boolean;\n /** The declared events with no edge. Empty through the typed door. */\n readonly missing: readonly string[];\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly phases: Unanswerable<\"phases\">;\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly refusals: Unanswerable<\"refusals\">;\n /** NOT AVAILABLE — see {@link Unanswerable}. */\n readonly scope: Unanswerable<\"scope\">;\n}\n\n/**\n * Read a reducer-form chart into its {@link ReducerChartDescription}.\n *\n * Pure, total and allocation-only, exactly as `describeChart` is: it never runs\n * a guard, a cell or a payload builder, so it is safe on a chart whose parts do\n * not exist yet.\n */\nexport function describeReducerChart<const C extends ReducerChart<C>>(\n chart: C,\n): ReducerChartDescription {\n const c = chart as unknown as RtReducerChart;\n\n const edges: ReducerEdge[] = [];\n const events: ReducerEventInfo[] = [];\n const missing: string[] = [];\n const guards = new Set<string>();\n const cells = new Set<string>();\n\n for (const [name, decl] of Object.entries(c.events)) {\n // the site key IS the event: one dimension, so `at` is the bare name — the\n // same key `compileReducer` hands guards, cmds and cells.\n const spec = c.on?.[name];\n if (spec === undefined) {\n missing.push(name);\n } else {\n const edge = readEdgeCore(name, name, spec);\n edges.push(edge);\n if (edge.guard !== undefined) guards.add(edge.guard);\n if (edge.cell !== undefined) cells.add(edge.cell);\n }\n events.push({\n name,\n foreign: decl?.foreign === true,\n ...(decl?.from === undefined ? {} : { from: decl.from }),\n hasPayload: decl !== undefined && \"data\" in decl,\n routed: spec !== undefined,\n });\n }\n\n return {\n states: [...(c.states ?? [])],\n initial: c.initial,\n events,\n cmds: Object.keys(c.cmds ?? {}),\n guards: [...guards],\n cells: [...cells],\n edges,\n total: missing.length === 0,\n missing,\n phases: NO_PHASES,\n refusals: NO_REFUSALS,\n scope: NO_SCOPE,\n };\n}\n\n/** The edge that routes `event`, or `undefined` when the chart routes it nowhere. */\nexport function reducerEdgeAt(\n desc: ReducerChartDescription,\n event: string,\n): ReducerEdge | undefined {\n return desc.edges.find((e) => e.event === event);\n}\n\n// ── the live layer ────────────────────────────────────────────────────────\n\n/**\n * What would happen if `event` were dispatched at the current state.\n *\n * There is NO `status` field, and its absence is the honest part: this form\n * cannot refuse an event — `on` is total over the alphabet and there is no\n * state dimension to refuse from — so a \"legal\" tag would be a distinction\n * without a second case. Everything a grid preview can still say here it says:\n * the edge, the guard's branch, the declared fan-out, the target a cell picks.\n *\n * The cmds are the DECLARED ones — the before question. For what actually\n * fired, see `captureCmds` in `./captured`.\n */\nexport interface ReducerEventPreview {\n readonly event: string;\n /** The event's declared `from`, carried through rather than recomputed. */\n readonly from?: EventOrigin;\n /** The declared edge. `undefined` only when the chart routes the event nowhere. */\n readonly edge?: ReducerEdge;\n /** Present iff the edge is guarded. */\n readonly guard?: GuardPreview;\n /** The cmds the edge DECLARES for the arm that resolved. */\n readonly cmds: readonly string[];\n /** Every state the edge declares it can reach. */\n readonly targets: readonly string[];\n /** The single target, when one is determined. */\n readonly resolved?: string;\n /** How {@link ReducerEventPreview.resolved} was determined. */\n readonly resolvedBy?: ResolvedBy;\n /** The msg this preview used, or `undefined` when no sample was supplied. */\n readonly msg?: { readonly type: string };\n}\n\n/**\n * Preview one event of a reducer chart against a live state.\n *\n * The guard and cell previews are the SAME functions the grid form uses — a\n * guard is pure and a cell is pure in both forms, and the only difference is\n * that `at` is the bare event name.\n */\nexport function previewReducerEvent<S extends { readonly type: string }>(\n desc: ReducerChartDescription,\n state: S,\n event: string,\n opts: InspectOptions = {},\n): ReducerEventPreview {\n const info = desc.events.find((e) => e.name === event);\n const from = info?.from === undefined ? {} : { from: info.from };\n const edge = reducerEdgeAt(desc, event);\n\n if (edge === undefined) {\n // Unreachable through the typed door: `on` is a required mapped type. It is\n // reported rather than swallowed for the same reason `undeclared` is — a\n // chart that reaches here was cast into existence.\n return { event, ...from, cmds: [], targets: [] };\n }\n\n const msg = sampleMsg(event, info?.hasPayload === true, opts.samples);\n const base = { event, ...from, edge, targets: edge.targets, msg };\n\n switch (edge.kind) {\n case \"plain\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.targets[0],\n resolvedBy: edge.targets.length === 1 ? \"declared\" : undefined,\n };\n\n case \"guarded\": {\n const guard = previewGuardOn(edge, state, msg, opts);\n return {\n ...base,\n guard,\n cmds: guard.branch === \"unknown\" ? edge.cmds : guard.cmds,\n resolved: guard.branch === \"unknown\" ? undefined : guard.target,\n resolvedBy: guard.branch === \"unknown\" ? undefined : \"guard\",\n };\n }\n\n case \"cell\": {\n const resolved = runCellOn(edge, state, msg, opts);\n return {\n ...base,\n // A cell builds its own cmds in its body, so the chart declares none —\n // empty BY DECLARATION, which is exactly the gap `captureCmds` closes.\n cmds: edge.cmds,\n resolved,\n resolvedBy: resolved === undefined ? undefined : \"cell\",\n };\n }\n\n // `resume` needs a phase dimension and `defineReducerChart` rejects it by\n // name (`__resumeNeedsAPhaseDimension`). Reaching here means a cast; the\n // declared fallback is the only truthful answer left.\n case \"resume\":\n return {\n ...base,\n cmds: edge.cmds,\n resolved: edge.fallback,\n resolvedBy: \"resume\",\n };\n }\n}\n\n/**\n * Preview EVERY event of a reducer chart's alphabet against a live state, in\n * declaration order. The button row — and here every control is live, because\n * this form has nothing with which to refuse one.\n */\nexport function inspectReducerState<S extends { readonly type: string }>(\n desc: ReducerChartDescription,\n state: S,\n opts: InspectOptions = {},\n): readonly ReducerEventPreview[] {\n return desc.events.map((e) => previewReducerEvent(desc, state, e.name, opts));\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { foldMsgs } from './chunk-B5VXOFMZ.js';
1
+ import { foldMsgs } from './chunk-OOYD44JI.js';
2
2
 
3
3
  // src/prediction/index.ts
4
4
  var tagSeq = (seq, value) => ({ seq, value });
@@ -29,5 +29,5 @@ function reconcile(machine, authoritativeState, lastAppliedSeq, pending) {
29
29
  }
30
30
 
31
31
  export { NO_ACK, ack, initAck, nextSeq, partitionByAck, reconcile, tagSeq };
32
- //# sourceMappingURL=chunk-4KTWLPL5.js.map
33
- //# sourceMappingURL=chunk-4KTWLPL5.js.map
32
+ //# sourceMappingURL=chunk-4EQZ76JC.js.map
33
+ //# sourceMappingURL=chunk-4EQZ76JC.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/prediction/index.ts"],"names":[],"mappings":";;;AAgDO,IAAM,SAAS,CAAI,GAAA,EAAU,KAAA,MAA4B,EAAE,KAAK,KAAA,EAAM;AActE,IAAM,GAAA,GAAM,CAAC,cAAA,MAA8B,EAAE,cAAA,EAAe;AAgB5D,IAAM,MAAA,GAAc;AAOpB,IAAM,OAAA,GAAU,MAAW,GAAA,CAAI,MAAM;AAmBrC,IAAM,cAAA,GAAiB,CAC5B,MAAA,EACA,QAAA,KACoB;AACpB,EAAA,MAAM,cAAA,GACJ,OAAO,QAAA,KAAa,QAAA,GAAW,WAAW,QAAA,CAAS,cAAA;AACrD,EAAA,MAAM,QAAwB,EAAC;AAC/B,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAA,KAAA,MAAW,QAAQ,MAAA,EAAQ;AACzB,IAAA,IAAI,IAAA,CAAK,OAAO,cAAA,EAAgB;AAC9B,MAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACnB;AAAA,EACF;AACA,EAAA,OAAO,EAAE,OAAO,OAAA,EAAQ;AAC1B;AAQO,IAAM,OAAA,GAAU,CAAI,MAAA,KACzB,MAAA,CAAO,OAAO,CAAC,GAAA,EAAK,IAAA,KAAU,IAAA,CAAK,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,GAAM,GAAA,EAAM,EAAE,CAAA,GAAI;AAwBjE,SAAS,SAAA,CAOd,OAAA,EACA,kBAAA,EACA,cAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAQ,GAAI,cAAA,CAAe,SAAS,cAAc,CAAA;AACnE,EAAA,OAAO,QAAA;AAAA,IACL,OAAA;AAAA,IACA,kBAAA;AAAA,IACA,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,OAAO,KAAK;AAAA,GACtC;AACF","file":"chunk-4KTWLPL5.js","sourcesContent":["/**\n * @demlik/tea/prediction — the client-prediction ack primitive (epic #186, facet 2).\n *\n * The contract the Gambetta/Valve authoritative-server netcode loop needs:\n * **command-seq-in → last-applied-seq-out.** A client tags each predicted\n * command/`Msg` with a monotonic `seq`; the authoritative side replies with the\n * `lastAppliedSeq` it has processed. `partitionByAck` then splits the client's\n * pending buffer into the inputs the server has ACKED (`seq <= lastAppliedSeq`)\n * and those still PENDING (`seq > lastAppliedSeq`) — the un-acked tail the\n * reconciliation pass (#214) replays over the authoritative snapshot via\n * `foldMsgs` (#211, `@demlik/tea/pure`).\n *\n * Deliberately **Model-shape-agnostic** (ADR 0006): the ack is a standalone\n * value, NOT a field this module requires on the consumer's `State`. It\n * generalizes the `lastAckedSeq`-on-the-Model + `seq`-threaded-through-the-Msg\n * pattern vortex hand-rolled (epic #186). It is a LEAF module — pure and\n * runtime-free, importing nothing from the tea core or host, so it can never\n * drag `run`/the host into a client bundle.\n *\n * This is the read/ack side of the primitive; `tagSeq`/`nextSeq` are the write\n * side, letting a client mint monotonic seqs from its pending buffer alone —\n * again with no counter field on the Model.\n *\n * `reconcile` (the read side's payoff, #214) composes this ack partition with\n * the pure fold seam `foldMsgs` (#211) to perform the whole Gambetta/Valve\n * reconciliation step in one call. The `foldMsgs` import is the ONLY dependency\n * this leaf takes, and it reaches into the pure-core leaf (`../pure/core`) — NOT\n * the runtime root — so the module stays runtime-free and the `@demlik/tea/pure`\n * import-graph guard (ADR 0006, #213) still holds.\n */\n\nimport type { Cmd, Machine, Sub } from \"../pure/core\";\nimport { foldMsgs } from \"../pure/core\";\n\n/**\n * A monotonic, non-negative sequence number tagging one client-predicted\n * command. Monotonicity is the client's contract (mint successive seqs with\n * `nextSeq`); this module only ever *compares* seqs.\n */\nexport type Seq = number;\n\n/** A command (or `Msg`) tagged with the `seq` the client assigned it. */\nexport interface SeqTagged<T> {\n readonly seq: Seq;\n readonly value: T;\n}\n\n/** Tag a command/`Msg` with its sequence number. */\nexport const tagSeq = <T>(seq: Seq, value: T): SeqTagged<T> => ({ seq, value });\n\n/**\n * The authoritative side's acknowledgement: the highest `seq` it has applied.\n * Everything with `seq <= lastAppliedSeq` is settled; everything above is still\n * in flight. This *is* the whole \"ack from the authoritative side\" — a value\n * the consumer carries however it likes (a wire field, a message payload),\n * never a shape this module imposes on the Model.\n */\nexport interface Ack {\n readonly lastAppliedSeq: Seq;\n}\n\n/** Construct an `Ack` for a last-applied sequence number. */\nexport const ack = (lastAppliedSeq: Seq): Ack => ({ lastAppliedSeq });\n\n/**\n * The \"nothing applied yet\" cursor — the ack value for a server that has applied\n * no client input at all. Because `nextSeq` mints **0-based** seqs and\n * `partitionByAck` acks **inclusively** (`seq <= lastAppliedSeq`), the pre-first\n * cursor must sit strictly *below* seq 0: `lastAppliedSeq = 0` would falsely ack\n * the seq-0 input before the server ever saw it. `-1` is \"before any seq\", and\n * `partitionByAck(buffer, NO_ACK)` therefore leaves the whole buffer PENDING.\n *\n * This names the boundary value on the seam so no consumer has to re-discover it\n * as a magic number: it is the primitive's own design (0-based mint + inclusive\n * partition) that creates the trap, so it is the primitive's job to name the\n * escape. Pair with {@link initAck} when an {@link Ack} is wanted instead of the\n * bare `Seq`.\n */\nexport const NO_ACK: Seq = -1;\n\n/**\n * The `Ack` for a server that has applied nothing yet — `ack(NO_ACK)`. The `Ack`\n * counterpart to the {@link NO_ACK} `Seq` sentinel, for a consumer that carries\n * an `Ack` rather than a bare `lastAppliedSeq`.\n */\nexport const initAck = (): Ack => ack(NO_ACK);\n\n/** The result of splitting a seq-tagged buffer against an ack. */\nexport interface AckPartition<T> {\n /** Inputs the authoritative side has applied (`seq <= lastAppliedSeq`). */\n readonly acked: readonly SeqTagged<T>[];\n /** Inputs still in flight / un-acked (`seq > lastAppliedSeq`) — the replay tail. */\n readonly pending: readonly SeqTagged<T>[];\n}\n\n/**\n * Partition a buffer of seq-tagged commands into ACKED and PENDING against the\n * authoritative `lastAppliedSeq`. Pure and total: every item lands in exactly\n * one bucket, input order is preserved within each bucket, and the boundary\n * `seq == lastAppliedSeq` is ACKED (inclusive `<=`). Routing is by `seq` value,\n * not buffer position, so an out-of-order or duplicate-seq buffer partitions\n * correctly. Accepts either an {@link Ack} or a bare `lastAppliedSeq` number, so\n * a caller passes whichever it holds.\n */\nexport const partitionByAck = <T>(\n buffer: readonly SeqTagged<T>[],\n ackOrSeq: Ack | Seq,\n): AckPartition<T> => {\n const lastAppliedSeq =\n typeof ackOrSeq === \"number\" ? ackOrSeq : ackOrSeq.lastAppliedSeq;\n const acked: SeqTagged<T>[] = [];\n const pending: SeqTagged<T>[] = [];\n for (const item of buffer) {\n if (item.seq <= lastAppliedSeq) {\n acked.push(item);\n } else {\n pending.push(item);\n }\n }\n return { acked, pending };\n};\n\n/**\n * The next sequence number to assign: one past the highest `seq` in the buffer,\n * or `0` for an empty buffer. Lets a client mint monotonic seqs from its pending\n * buffer alone — no counter field on the Model — and is tolerant of an unordered\n * buffer (it takes the max, not the last element).\n */\nexport const nextSeq = <T>(buffer: readonly SeqTagged<T>[]): Seq =>\n buffer.reduce((max, item) => (item.seq > max ? item.seq : max), -1) + 1;\n\n/**\n * The client prediction/reconciliation helper — the Gambetta/Valve\n * authoritative-server loop's reconcile step, generalized (#214, epic #186).\n *\n * Given the latest `authoritativeState` from the server, the server's\n * `lastAppliedSeq` ack, and the client's `pending` buffer of seq-tagged inputs,\n * it returns the corrected predicted state: drop the inputs the server has\n * already applied (`seq <= lastAppliedSeq`) and replay ONLY the un-acked tail\n * (`seq > lastAppliedSeq`) over the authoritative snapshot.\n *\n * It is **composed, not re-derived** (ADR 0006): the drop is {@link partitionByAck}\n * (the ack primitive, #212) and the replay is `foldMsgs` (the pure fold seam,\n * #211) — there is no second copy of the partition logic and no second copy of\n * the fold. `lastAppliedSeq` accepts either an {@link Ack} or a bare `Seq`, so a\n * caller passes whichever it holds, matching `partitionByAck`.\n *\n * Pure and host-agnostic: it takes the `machine` (which `foldMsgs` needs to\n * dispatch `update`) but touches no `Store`, `interpret`, or subscription, and\n * imports nothing from the runtime — so it ships on `@demlik/tea/prediction`\n * and the client-safe `@demlik/tea/pure` umbrella without dragging `run` into a\n * client bundle.\n */\nexport function reconcile<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n authoritativeState: S,\n lastAppliedSeq: Ack | Seq,\n pending: readonly SeqTagged<M>[],\n): S {\n const { pending: unacked } = partitionByAck(pending, lastAppliedSeq);\n return foldMsgs(\n machine,\n authoritativeState,\n unacked.map((tagged) => tagged.value),\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/prediction/index.ts"],"names":[],"mappings":";;;AAgDO,IAAM,SAAS,CAAI,GAAA,EAAU,KAAA,MAA4B,EAAE,KAAK,KAAA,EAAM;AActE,IAAM,GAAA,GAAM,CAAC,cAAA,MAA8B,EAAE,cAAA,EAAe;AAgB5D,IAAM,MAAA,GAAc;AAOpB,IAAM,OAAA,GAAU,MAAW,GAAA,CAAI,MAAM;AAmBrC,IAAM,cAAA,GAAiB,CAC5B,MAAA,EACA,QAAA,KACoB;AACpB,EAAA,MAAM,cAAA,GACJ,OAAO,QAAA,KAAa,QAAA,GAAW,WAAW,QAAA,CAAS,cAAA;AACrD,EAAA,MAAM,QAAwB,EAAC;AAC/B,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAA,KAAA,MAAW,QAAQ,MAAA,EAAQ;AACzB,IAAA,IAAI,IAAA,CAAK,OAAO,cAAA,EAAgB;AAC9B,MAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACnB;AAAA,EACF;AACA,EAAA,OAAO,EAAE,OAAO,OAAA,EAAQ;AAC1B;AAQO,IAAM,OAAA,GAAU,CAAI,MAAA,KACzB,MAAA,CAAO,OAAO,CAAC,GAAA,EAAK,IAAA,KAAU,IAAA,CAAK,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,GAAM,GAAA,EAAM,EAAE,CAAA,GAAI;AAwBjE,SAAS,SAAA,CAOd,OAAA,EACA,kBAAA,EACA,cAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAQ,GAAI,cAAA,CAAe,SAAS,cAAc,CAAA;AACnE,EAAA,OAAO,QAAA;AAAA,IACL,OAAA;AAAA,IACA,kBAAA;AAAA,IACA,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,OAAO,KAAK;AAAA,GACtC;AACF","file":"chunk-4EQZ76JC.js","sourcesContent":["/**\n * @demlik/tea/prediction — the client-prediction ack primitive (epic #186, facet 2).\n *\n * The contract the Gambetta/Valve authoritative-server netcode loop needs:\n * **command-seq-in → last-applied-seq-out.** A client tags each predicted\n * command/`Msg` with a monotonic `seq`; the authoritative side replies with the\n * `lastAppliedSeq` it has processed. `partitionByAck` then splits the client's\n * pending buffer into the inputs the server has ACKED (`seq <= lastAppliedSeq`)\n * and those still PENDING (`seq > lastAppliedSeq`) — the un-acked tail the\n * reconciliation pass (#214) replays over the authoritative snapshot via\n * `foldMsgs` (#211, `@demlik/tea/pure`).\n *\n * Deliberately **Model-shape-agnostic** (ADR 0006): the ack is a standalone\n * value, NOT a field this module requires on the consumer's `State`. It\n * generalizes the `lastAckedSeq`-on-the-Model + `seq`-threaded-through-the-Msg\n * pattern vortex hand-rolled (epic #186). It is a LEAF module — pure and\n * runtime-free, importing nothing from the tea core or host, so it can never\n * drag `run`/the host into a client bundle.\n *\n * This is the read/ack side of the primitive; `tagSeq`/`nextSeq` are the write\n * side, letting a client mint monotonic seqs from its pending buffer alone —\n * again with no counter field on the Model.\n *\n * `reconcile` (the read side's payoff, #214) composes this ack partition with\n * the pure fold seam `foldMsgs` (#211) to perform the whole Gambetta/Valve\n * reconciliation step in one call. The `foldMsgs` import is the ONLY dependency\n * this leaf takes, and it reaches into the pure-core leaf (`../pure/core`) — NOT\n * the runtime root — so the module stays runtime-free and the `@demlik/tea/pure`\n * import-graph guard (ADR 0006, #213) still holds.\n */\n\nimport type { Cmd, Machine, Sub } from \"../pure/core\";\nimport { foldMsgs } from \"../pure/core\";\n\n/**\n * A monotonic, non-negative sequence number tagging one client-predicted\n * command. Monotonicity is the client's contract (mint successive seqs with\n * `nextSeq`); this module only ever *compares* seqs.\n */\nexport type Seq = number;\n\n/** A command (or `Msg`) tagged with the `seq` the client assigned it. */\nexport interface SeqTagged<T> {\n readonly seq: Seq;\n readonly value: T;\n}\n\n/** Tag a command/`Msg` with its sequence number. */\nexport const tagSeq = <T>(seq: Seq, value: T): SeqTagged<T> => ({ seq, value });\n\n/**\n * The authoritative side's acknowledgement: the highest `seq` it has applied.\n * Everything with `seq <= lastAppliedSeq` is settled; everything above is still\n * in flight. This *is* the whole \"ack from the authoritative side\" — a value\n * the consumer carries however it likes (a wire field, a message payload),\n * never a shape this module imposes on the Model.\n */\nexport interface Ack {\n readonly lastAppliedSeq: Seq;\n}\n\n/** Construct an `Ack` for a last-applied sequence number. */\nexport const ack = (lastAppliedSeq: Seq): Ack => ({ lastAppliedSeq });\n\n/**\n * The \"nothing applied yet\" cursor — the ack value for a server that has applied\n * no client input at all. Because `nextSeq` mints **0-based** seqs and\n * `partitionByAck` acks **inclusively** (`seq <= lastAppliedSeq`), the pre-first\n * cursor must sit strictly *below* seq 0: `lastAppliedSeq = 0` would falsely ack\n * the seq-0 input before the server ever saw it. `-1` is \"before any seq\", and\n * `partitionByAck(buffer, NO_ACK)` therefore leaves the whole buffer PENDING.\n *\n * This names the boundary value on the seam so no consumer has to re-discover it\n * as a magic number: it is the primitive's own design (0-based mint + inclusive\n * partition) that creates the trap, so it is the primitive's job to name the\n * escape. Pair with {@link initAck} when an {@link Ack} is wanted instead of the\n * bare `Seq`.\n */\nexport const NO_ACK: Seq = -1;\n\n/**\n * The `Ack` for a server that has applied nothing yet — `ack(NO_ACK)`. The `Ack`\n * counterpart to the {@link NO_ACK} `Seq` sentinel, for a consumer that carries\n * an `Ack` rather than a bare `lastAppliedSeq`.\n */\nexport const initAck = (): Ack => ack(NO_ACK);\n\n/** The result of splitting a seq-tagged buffer against an ack. */\nexport interface AckPartition<T> {\n /** Inputs the authoritative side has applied (`seq <= lastAppliedSeq`). */\n readonly acked: readonly SeqTagged<T>[];\n /** Inputs still in flight / un-acked (`seq > lastAppliedSeq`) — the replay tail. */\n readonly pending: readonly SeqTagged<T>[];\n}\n\n/**\n * Partition a buffer of seq-tagged commands into ACKED and PENDING against the\n * authoritative `lastAppliedSeq`. Pure and total: every item lands in exactly\n * one bucket, input order is preserved within each bucket, and the boundary\n * `seq == lastAppliedSeq` is ACKED (inclusive `<=`). Routing is by `seq` value,\n * not buffer position, so an out-of-order or duplicate-seq buffer partitions\n * correctly. Accepts either an {@link Ack} or a bare `lastAppliedSeq` number, so\n * a caller passes whichever it holds.\n */\nexport const partitionByAck = <T>(\n buffer: readonly SeqTagged<T>[],\n ackOrSeq: Ack | Seq,\n): AckPartition<T> => {\n const lastAppliedSeq =\n typeof ackOrSeq === \"number\" ? ackOrSeq : ackOrSeq.lastAppliedSeq;\n const acked: SeqTagged<T>[] = [];\n const pending: SeqTagged<T>[] = [];\n for (const item of buffer) {\n if (item.seq <= lastAppliedSeq) {\n acked.push(item);\n } else {\n pending.push(item);\n }\n }\n return { acked, pending };\n};\n\n/**\n * The next sequence number to assign: one past the highest `seq` in the buffer,\n * or `0` for an empty buffer. Lets a client mint monotonic seqs from its pending\n * buffer alone — no counter field on the Model — and is tolerant of an unordered\n * buffer (it takes the max, not the last element).\n */\nexport const nextSeq = <T>(buffer: readonly SeqTagged<T>[]): Seq =>\n buffer.reduce((max, item) => (item.seq > max ? item.seq : max), -1) + 1;\n\n/**\n * The client prediction/reconciliation helper — the Gambetta/Valve\n * authoritative-server loop's reconcile step, generalized (#214, epic #186).\n *\n * Given the latest `authoritativeState` from the server, the server's\n * `lastAppliedSeq` ack, and the client's `pending` buffer of seq-tagged inputs,\n * it returns the corrected predicted state: drop the inputs the server has\n * already applied (`seq <= lastAppliedSeq`) and replay ONLY the un-acked tail\n * (`seq > lastAppliedSeq`) over the authoritative snapshot.\n *\n * It is **composed, not re-derived** (ADR 0006): the drop is {@link partitionByAck}\n * (the ack primitive, #212) and the replay is `foldMsgs` (the pure fold seam,\n * #211) — there is no second copy of the partition logic and no second copy of\n * the fold. `lastAppliedSeq` accepts either an {@link Ack} or a bare `Seq`, so a\n * caller passes whichever it holds, matching `partitionByAck`.\n *\n * Pure and host-agnostic: it takes the `machine` (which `foldMsgs` needs to\n * dispatch `update`) but touches no `Store`, `interpret`, or subscription, and\n * imports nothing from the runtime — so it ships on `@demlik/tea/prediction`\n * and the client-safe `@demlik/tea/pure` umbrella without dragging `run` into a\n * client bundle.\n */\nexport function reconcile<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n authoritativeState: S,\n lastAppliedSeq: Ack | Seq,\n pending: readonly SeqTagged<M>[],\n): S {\n const { pending: unacked } = partitionByAck(pending, lastAppliedSeq);\n return foldMsgs(\n machine,\n authoritativeState,\n unacked.map((tagged) => tagged.value),\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
1
  import { MsgType } from './chunk-JELSZN25.js';
2
- import { deadlineSub } from './chunk-JGVL3WPL.js';
2
+ import { initCache, set, get } from './chunk-RH5EFRVJ.js';
3
+ import { deadlineSub } from './chunk-DGE4PV4A.js';
3
4
  import { asRng, recordFailure, shouldRetry, nextDelayMs, initRetry } from './chunk-Q2UM7BXU.js';
4
5
  import { initBucket, tryConsume } from './chunk-S2EGRPCM.js';
5
6
  import { initCircuit, onSuccess, onFailure, canPass } from './chunk-UF4MZSLT.js';
6
- import { initCache, set, get } from './chunk-7SVIRMC6.js';
7
- import { tryInterpret } from './chunk-5EHLEUTL.js';
8
- import { without } from './chunk-B5VXOFMZ.js';
7
+ import { tryInterpret } from './chunk-ZSUUOEPL.js';
8
+ import { without } from './chunk-OOYD44JI.js';
9
9
 
10
10
  // src/resilient-call/index.ts
11
11
  function circuitPolicy(config) {
@@ -219,5 +219,5 @@ function liftResilience(state, [slice, cmds]) {
219
219
  }
220
220
 
221
221
  export { createResilientCall, liftResilience };
222
- //# sourceMappingURL=chunk-EUF7XOEE.js.map
223
- //# sourceMappingURL=chunk-EUF7XOEE.js.map
222
+ //# sourceMappingURL=chunk-4KLG43GY.js.map
223
+ //# sourceMappingURL=chunk-4KLG43GY.js.map