@jam-overture/loom 0.2.0 → 0.3.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 (194) hide show
  1. package/dist/audience/compose.d.ts +112 -0
  2. package/dist/audience/compose.js +134 -0
  3. package/dist/audience/memory.d.ts +14 -0
  4. package/dist/audience/memory.js +71 -0
  5. package/dist/audience/overlay-store.d.ts +343 -0
  6. package/dist/audience/overlay-store.js +217 -0
  7. package/dist/audience/rule.d.ts +121 -0
  8. package/dist/audience/rule.js +78 -0
  9. package/dist/cli/index.d.ts +3 -4
  10. package/dist/cli/index.js +3 -4
  11. package/dist/data/adapter.d.ts +9 -1
  12. package/dist/data/adapter.js +2 -0
  13. package/dist/data/resolve.d.ts +1 -1
  14. package/dist/interpretation/anthropic.d.ts +1 -1
  15. package/dist/interpretation/anthropic.js +2 -22
  16. package/dist/interpretation/client.d.ts +1 -1
  17. package/dist/interpretation/materialize.js +67 -22
  18. package/dist/interpretation/openai-compatible.d.ts +36 -0
  19. package/dist/interpretation/openai-compatible.js +79 -0
  20. package/dist/interpretation/status.d.ts +19 -0
  21. package/dist/interpretation/status.js +26 -0
  22. package/dist/live/index.d.ts +73 -0
  23. package/dist/live/index.js +73 -0
  24. package/dist/live/pages.d.ts +187 -0
  25. package/dist/live/pages.js +161 -0
  26. package/dist/live/pull.d.ts +147 -0
  27. package/dist/live/pull.js +398 -0
  28. package/dist/live/pulling.d.ts +79 -0
  29. package/dist/live/pulling.js +117 -0
  30. package/dist/live/window.d.ts +129 -0
  31. package/dist/live/window.js +132 -0
  32. package/dist/render/addressed.d.ts +35 -0
  33. package/dist/render/addressed.js +79 -0
  34. package/dist/render/document-theme.d.ts +70 -0
  35. package/dist/render/document-theme.js +139 -0
  36. package/dist/render/editable.d.ts +15 -1
  37. package/dist/render/editable.js +13 -1
  38. package/dist/render/expected.d.ts +98 -0
  39. package/dist/render/expected.js +88 -0
  40. package/dist/render/index.d.ts +2 -0
  41. package/dist/render/index.js +2 -0
  42. package/dist/render/render.d.ts +11 -0
  43. package/dist/render/render.js +192 -46
  44. package/dist/render/request.d.ts +8 -1
  45. package/dist/render/request.js +1 -0
  46. package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
  47. package/dist/runtime/auto-apply-ceiling.js +66 -0
  48. package/dist/runtime/gate.js +69 -10
  49. package/dist/runtime/index.d.ts +1 -0
  50. package/dist/runtime/index.js +1 -0
  51. package/dist/runtime/nesting.d.ts +13 -1
  52. package/dist/runtime/nesting.js +41 -24
  53. package/dist/runtime/policy-change.js +8 -2
  54. package/dist/runtime/policy-log.d.ts +5 -5
  55. package/dist/runtime/policy.d.ts +8 -6
  56. package/dist/runtime/policy.js +5 -2
  57. package/dist/runtime/repointing.js +0 -0
  58. package/dist/sdk/definition.d.ts +65 -6
  59. package/dist/sdk/definition.js +44 -0
  60. package/dist/sdk/registry.d.ts +17 -1
  61. package/dist/sdk/registry.js +39 -0
  62. package/dist/signals/acted.contract.d.ts +21 -0
  63. package/dist/signals/acted.contract.js +236 -0
  64. package/dist/signals/acted.d.ts +359 -0
  65. package/dist/signals/acted.js +135 -0
  66. package/dist/signals/agenda.d.ts +585 -0
  67. package/dist/signals/agenda.js +295 -0
  68. package/dist/signals/arrivals.contract.d.ts +21 -0
  69. package/dist/signals/arrivals.contract.js +180 -0
  70. package/dist/signals/arrivals.d.ts +375 -0
  71. package/dist/signals/arrivals.js +254 -0
  72. package/dist/signals/broadcast.d.ts +25 -15
  73. package/dist/signals/broadcast.js +209 -36
  74. package/dist/signals/collect.d.ts +137 -43
  75. package/dist/signals/collect.js +103 -36
  76. package/dist/signals/conversion.d.ts +348 -0
  77. package/dist/signals/conversion.js +235 -0
  78. package/dist/signals/correlated.contract.d.ts +24 -0
  79. package/dist/signals/correlated.contract.js +94 -0
  80. package/dist/signals/counters.d.ts +51 -0
  81. package/dist/signals/counters.js +58 -0
  82. package/dist/signals/deployment-change.d.ts +28 -4
  83. package/dist/signals/deployment-change.js +57 -16
  84. package/dist/signals/deployment.d.ts +18 -5
  85. package/dist/signals/deployment.js +37 -11
  86. package/dist/signals/door.d.ts +34 -12
  87. package/dist/signals/door.js +37 -13
  88. package/dist/signals/expire.d.ts +192 -0
  89. package/dist/signals/expire.js +213 -0
  90. package/dist/signals/frontier.d.ts +268 -0
  91. package/dist/signals/frontier.js +145 -0
  92. package/dist/signals/funnel-hours.contract.d.ts +21 -0
  93. package/dist/signals/funnel-hours.contract.js +221 -0
  94. package/dist/signals/funnel-hours.d.ts +293 -0
  95. package/dist/signals/funnel-hours.js +99 -0
  96. package/dist/signals/funnel.d.ts +60 -0
  97. package/dist/signals/funnel.js +35 -20
  98. package/dist/signals/health.d.ts +201 -4
  99. package/dist/signals/health.js +214 -2
  100. package/dist/signals/index.d.ts +19 -0
  101. package/dist/signals/index.js +19 -0
  102. package/dist/signals/inside.d.ts +190 -0
  103. package/dist/signals/inside.js +263 -0
  104. package/dist/signals/join.d.ts +56 -0
  105. package/dist/signals/join.js +60 -0
  106. package/dist/signals/journal.d.ts +112 -9
  107. package/dist/signals/kept.contract.d.ts +22 -0
  108. package/dist/signals/kept.contract.js +111 -0
  109. package/dist/signals/library-agenda-change.d.ts +324 -0
  110. package/dist/signals/library-agenda-change.js +199 -0
  111. package/dist/signals/library-agenda.d.ts +258 -0
  112. package/dist/signals/library-agenda.js +167 -0
  113. package/dist/signals/library-reach-change.d.ts +10 -0
  114. package/dist/signals/library-reach-change.js +11 -3
  115. package/dist/signals/library-senders-change.d.ts +457 -0
  116. package/dist/signals/library-senders-change.js +367 -0
  117. package/dist/signals/library-senders-reach-change.d.ts +486 -0
  118. package/dist/signals/library-senders-reach-change.js +538 -0
  119. package/dist/signals/library-senders-reach.d.ts +340 -0
  120. package/dist/signals/library-senders-reach.js +252 -0
  121. package/dist/signals/library-senders.d.ts +271 -0
  122. package/dist/signals/library-senders.js +180 -0
  123. package/dist/signals/library-word-reach-change.js +2 -6
  124. package/dist/signals/memory.js +142 -1
  125. package/dist/signals/migrate.d.ts +6 -5
  126. package/dist/signals/migrate.js +150 -6
  127. package/dist/signals/notice.d.ts +88 -33
  128. package/dist/signals/notice.js +38 -16
  129. package/dist/signals/part-pace.d.ts +378 -0
  130. package/dist/signals/part-pace.js +333 -0
  131. package/dist/signals/parts.d.ts +25 -15
  132. package/dist/signals/parts.js +32 -73
  133. package/dist/signals/postgres.js +400 -26
  134. package/dist/signals/region.d.ts +1 -1
  135. package/dist/signals/retention.d.ts +43 -21
  136. package/dist/signals/retention.js +25 -8
  137. package/dist/signals/rhythm.d.ts +302 -0
  138. package/dist/signals/rhythm.js +262 -0
  139. package/dist/signals/rollup.d.ts +127 -1
  140. package/dist/signals/rollup.js +211 -24
  141. package/dist/signals/schema.d.ts +640 -3
  142. package/dist/signals/schema.js +239 -3
  143. package/dist/signals/silences.d.ts +310 -11
  144. package/dist/signals/silences.js +243 -0
  145. package/dist/signals/subtrees.d.ts +123 -0
  146. package/dist/signals/subtrees.js +102 -0
  147. package/dist/signals/tally.d.ts +125 -4
  148. package/dist/signals/unread.d.ts +292 -0
  149. package/dist/signals/unread.js +137 -0
  150. package/dist/signals/window-agenda.d.ts +276 -0
  151. package/dist/signals/window-agenda.js +83 -0
  152. package/dist/signals/window-funnels.d.ts +88 -0
  153. package/dist/signals/window-funnels.js +47 -0
  154. package/dist/store/cache.d.ts +101 -0
  155. package/dist/store/cache.js +149 -0
  156. package/dist/store/history.d.ts +82 -0
  157. package/dist/store/history.js +36 -0
  158. package/dist/store/index.d.ts +11 -0
  159. package/dist/store/index.js +11 -0
  160. package/dist/store/migrate.d.ts +26 -0
  161. package/dist/store/migrate.js +64 -0
  162. package/dist/store/postgres-audience.d.ts +14 -0
  163. package/dist/store/postgres-audience.js +272 -0
  164. package/dist/store/postgres.d.ts +1 -0
  165. package/dist/store/postgres.js +1 -0
  166. package/dist/store/schema.d.ts +312 -0
  167. package/dist/store/schema.js +77 -0
  168. package/dist/store/source.d.ts +57 -1
  169. package/dist/store/source.js +65 -1
  170. package/dist/submit/resolve.d.ts +1 -1
  171. package/dist/telemetry/index.d.ts +1 -0
  172. package/dist/telemetry/index.js +1 -0
  173. package/dist/telemetry/journal.d.ts +32 -0
  174. package/dist/telemetry/memory.js +10 -1
  175. package/dist/telemetry/postgres.js +18 -2
  176. package/dist/telemetry/window.d.ts +135 -0
  177. package/dist/telemetry/window.js +101 -0
  178. package/dist/testing/audience-overlay-contract.d.ts +31 -0
  179. package/dist/testing/audience-overlay-contract.js +354 -0
  180. package/dist/testing/contracts.d.ts +1 -0
  181. package/dist/testing/contracts.js +1 -0
  182. package/dist/testing/journal-contract.js +158 -5
  183. package/dist/theme/contrast.d.ts +19 -14
  184. package/dist/theme/contrast.js +181 -17
  185. package/dist/tree/apply.js +13 -0
  186. package/dist/tree/mutation.d.ts +18 -0
  187. package/dist/tree/mutation.js +24 -12
  188. package/dist/tree/navigation.d.ts +5 -0
  189. package/dist/tree/navigation.js +32 -10
  190. package/dist/tree/outline.d.ts +7 -0
  191. package/dist/tree/outline.js +9 -5
  192. package/package.json +39 -96
  193. package/dist/runtime/inverse-interpreter.d.ts +0 -90
  194. package/dist/runtime/inverse-interpreter.js +0 -56
@@ -1,4 +1,6 @@
1
1
  import { createElement, Fragment } from "react";
2
+ import { DEFAULT_AUDIENCE_ID } from "../audience/audience.js";
3
+ import { parseBindings } from "../data/binding.js";
2
4
  import { NO_DATA } from "../data/resolution.js";
3
5
  import { NO_FRAMES } from "../frame/resolution.js";
4
6
  import { ANCHOR_PROP_KEY, DATA_PROP_KEY, SUBMIT_PROP_KEY } from "../reserved-props.js";
@@ -9,9 +11,10 @@ import { createAnchorLedger, resolveAnchor, } from "./anchor.js";
9
11
  import { isBehaviourResolver, NO_RESOLVED_BEHAVIOURS, NO_CONTROL_NAME_PROPS, resolveBehaviours, resolveControlNames, } from "./behaviour.js";
10
12
  import { literalThemeElement } from "./inline-variables.js";
11
13
  import { editableAttributes } from "./editable.js";
14
+ import { checkAnswers, isAnswerReader, } from "./expected.js";
12
15
  import { isFrameResolver, resolveNodeFrames } from "./frame.js";
13
16
  import { NO_SLOTS, } from "./primitive.js";
14
- import { isBindingReader, unreadBindings } from "./reads.js";
17
+ import { isBindingReader, unreadBindings, } from "./reads.js";
15
18
  import { isSlotPlacer, unplacedSlots } from "./slots.js";
16
19
  import { isUnshownReader, readUnshown, unshownRows, } from "./unshown.js";
17
20
  import { isTextResolver, NO_TEXT, overlayText, } from "./text.js";
@@ -25,23 +28,41 @@ import { partitionReservedProps, resolveTheme, themeStyle, THEME_PROP_KEY } from
25
28
  * with the values substituted beneath them (0283).
26
29
  */
27
30
  const rampFor = (options) => options.themeValues === "literals" ? "fixed" : "fluid";
28
- const renderChildren = (children, context) => children.length === 0 ? null : children.map((child) => renderNode(child, context));
31
+ /**
32
+ * A list of nodes, each walked from its own root.
33
+ *
34
+ * The `.map` is one level and spends no frame per level; each `renderSubtree`
35
+ * carries its own stack. Only a decorative copy starts a list this way now — a
36
+ * node's own children are rendered by the walk that reached it.
37
+ */
38
+ const renderNodeList = (children, context) => children.length === 0 ? null : children.map((child) => renderSubtree(child, context));
29
39
  const isRootNode = (node, context) => node.id === context.tree.root.id;
30
- const renderElementBody = (node, context) => {
40
+ /**
41
+ * The children this element receives, split the way its primitive takes them.
42
+ *
43
+ * It renders nothing. The walk has already rendered every child by the time
44
+ * this runs (0380), and what is left is the routing — which is why the slot
45
+ * rules above are a statement about `from.kind` rather than about recursion.
46
+ */
47
+ const elementBodyFrom = (node, rendered) => {
31
48
  if (!node.children.some((child) => child.kind === "slot")) {
32
- return { children: renderChildren(node.children, context), slots: NO_SLOTS };
49
+ return {
50
+ children: rendered.length === 0 ? null : rendered.map((child) => child.element),
51
+ slots: NO_SLOTS,
52
+ };
33
53
  }
34
54
  const slots = Object.create(null);
35
55
  const rest = [];
36
- for (const child of node.children) {
37
- if (child.kind !== "slot") {
38
- rest.push(renderNode(child, context));
56
+ for (const child of rendered) {
57
+ if (child.from.kind !== "slot") {
58
+ rest.push(child.element);
39
59
  continue;
40
60
  }
41
- const placed = renderNode(child, context);
42
- const existing = slots[child.name];
43
- slots[child.name] =
44
- existing === undefined ? placed : [...(Array.isArray(existing) ? existing : [existing]), placed];
61
+ const existing = slots[child.from.name];
62
+ slots[child.from.name] =
63
+ existing === undefined
64
+ ? child.element
65
+ : [...(Array.isArray(existing) ? existing : [existing]), child.element];
45
66
  }
46
67
  return { children: rest.length === 0 ? null : rest, slots: Object.freeze(slots) };
47
68
  };
@@ -67,7 +88,7 @@ const decorativeChildrenFor = (node, context) => {
67
88
  let rendered = false;
68
89
  return () => {
69
90
  if (!rendered) {
70
- copy = renderChildren(node.children, {
91
+ copy = renderNodeList(node.children, {
71
92
  ...context,
72
93
  editMode: false,
73
94
  addressed: false,
@@ -94,7 +115,11 @@ const renderContextFor = (node, slots, data, submit, frames, anchor, text, behav
94
115
  ...(submit ? { submit } : {}),
95
116
  ...(anchor ? { anchor } : {}),
96
117
  ...(context.editMode || context.addressed
97
- ? { editable: editableAttributes(node, isRoot ? context.tree : undefined) }
118
+ ? {
119
+ editable: isRoot
120
+ ? editableAttributes(node, context.tree, context.audience)
121
+ : editableAttributes(node),
122
+ }
98
123
  : {}),
99
124
  ...(theme ? { theme } : {}),
100
125
  };
@@ -122,7 +147,11 @@ const nodeDataFor = (node, declared, context) => {
122
147
  unavailable: problem.unavailable,
123
148
  });
124
149
  }
125
- const data = context.data.lookup(node.id);
150
+ const given = context.data.lookup(node.id);
151
+ const declaredReads = context.reads?.bindingsReadBy(node.type);
152
+ const { data, refused } = checkAnswers(given, declaredReads, context.expects?.answersExpectedBy(node.type), node.props);
153
+ if (refused.length > 0)
154
+ reportRefusedAnswers(node, declared, refused, context);
126
155
  /**
127
156
  * A resolution that answered nothing for a node that asked for something has
128
157
  * never heard of the node: `buildDataResolution` gives every planned binding an
@@ -137,7 +166,7 @@ const nodeDataFor = (node, declared, context) => {
137
166
  if (reported === 0 && !hasAnswers(data) && asksForSomething(declared)) {
138
167
  context.collect({ code: "data-unresolved", nodeId: node.id, resolution: "unrelated" });
139
168
  }
140
- reportUnreadBindings(node, data, context);
169
+ reportUnreadBindings(node, data, declaredReads, context);
141
170
  reportUnshownRows(node, data, context);
142
171
  return data;
143
172
  };
@@ -168,6 +197,45 @@ const reportUnplacedSlots = (node, context) => {
168
197
  context.collect({ code: "slot-unplaced", nodeId: node.id, type: node.type, name });
169
198
  }
170
199
  };
200
+ /**
201
+ * A diagnostic for every answer this node was given that its primitive declared
202
+ * it cannot read.
203
+ *
204
+ * Reported as `data-unavailable`, which is the code it is: the binding has no
205
+ * value, and the reason it carries says whose schema refused it — the source's
206
+ * own, or the primitive reading it (0357). A code of its own would have said the
207
+ * same thing one word differently and split anything counting bindings that went
208
+ * unanswered across two codes.
209
+ *
210
+ * The source id comes from the node's own `loom:data`, re-parsed here rather
211
+ * than carried down from the plan. It costs a parse on the one path where an
212
+ * answer was refused and nothing at all on every other node, which is the
213
+ * trade worth making: the plan's own copy would have to travel through the
214
+ * resolution to reach here, and a resolution is asked about a node id and
215
+ * deliberately knows nothing about what the node declared.
216
+ *
217
+ * A refusal whose name is not in that map cannot happen on a rendered node — a
218
+ * ready answer under a name is there because the plan read that name off this
219
+ * node — and is passed over rather than reported against a source nobody named.
220
+ * `nameRead` guards the same impossibility for the same reason.
221
+ */
222
+ const reportRefusedAnswers = (node, declared, refused, context) => {
223
+ const bindings = parseBindings(declared);
224
+ if (!bindings.ok)
225
+ return;
226
+ for (const [name, bound] of bindings.value) {
227
+ const refusal = refused.find((candidate) => candidate.name === name);
228
+ if (!refusal)
229
+ continue;
230
+ context.collect({
231
+ code: "data-unavailable",
232
+ nodeId: node.id,
233
+ name,
234
+ source: bound.source,
235
+ unavailable: { reason: "unreadable-answer", detail: refusal.detail },
236
+ });
237
+ }
238
+ };
171
239
  /**
172
240
  * A diagnostic for every name this node was answered under that its primitive
173
241
  * says it does not read.
@@ -188,8 +256,7 @@ const reportUnplacedSlots = (node, context) => {
188
256
  * declaration may name the prop that names the binding rather than the binding
189
257
  * (0184), and this walk is the only place holding both.
190
258
  */
191
- const reportUnreadBindings = (node, data, context) => {
192
- const declared = context.reads?.bindingsReadBy(node.type);
259
+ const reportUnreadBindings = (node, data, declared, context) => {
193
260
  if (declared === undefined)
194
261
  return;
195
262
  const asked = [];
@@ -419,7 +486,17 @@ const reportUnreadReservedProps = (node, reserved, isRoot, context) => {
419
486
  context.collect({ code: "reserved-prop-unrecognised", nodeId: node.id, key });
420
487
  }
421
488
  };
422
- const renderElement = (node, context) => {
489
+ /**
490
+ * Everything about an element that is settled before its children are walked,
491
+ * returned as the assembly that finishes it — or `null` where the node is
492
+ * omitted and its subtree is never walked at all.
493
+ *
494
+ * The split is at the seam `renderElementBody` used to sit on (0380). It is
495
+ * what lets the walk be a loop: the order props are validated in and anchors
496
+ * are claimed in is document order, which this preserves by running on the way
497
+ * down, and the element itself is built on the way up.
498
+ */
499
+ const prepareElement = (node, context) => {
423
500
  const primitive = context.resolver.resolve(node.type);
424
501
  /**
425
502
  * An unknown primitive omits its whole subtree rather than promoting the
@@ -473,39 +550,106 @@ const renderElement = (node, context) => {
473
550
  const text = context.text?.textFor(node.type) ?? NO_TEXT;
474
551
  const behaviours = nodeBehavioursFor(node, props, text, context);
475
552
  reportUnplacedSlots(node, context);
476
- const body = renderElementBody(node, context);
477
- const rendered = {
478
- loom: renderContextFor(node, body.slots, data, submit, frames, anchor, text, behaviours, context),
479
- props,
480
- children: body.children,
553
+ return (body) => {
554
+ const rendered = {
555
+ loom: renderContextFor(node, body.slots, data, submit, frames, anchor, text, behaviours, context),
556
+ props,
557
+ children: body.children,
558
+ };
559
+ return context.literals
560
+ ? literalThemeElement(primitive, context.literals, node.id, rendered)
561
+ : createElement(primitive, { key: node.id, ...rendered });
481
562
  };
482
- return context.literals
483
- ? literalThemeElement(primitive, context.literals, node.id, rendered)
484
- : createElement(primitive, { key: node.id, ...rendered });
485
563
  };
486
564
  /**
487
- * A slot is a projection point, not a box. It renders its projected content, or
488
- * its own children as the fallback when the host projected nothing, and adds no
489
- * element of its own in either case.
565
+ * A slot is a projection point, not a box: it adds no element of its own
566
+ * whether it carries what the host projected or its own children as the
567
+ * fallback. Which of the two it carries is decided in the walk, because only
568
+ * the fallback has children to render first.
490
569
  */
491
- const renderSlot = (node, context) => {
492
- /** Own-property only, for the reason given in `staticPrimitiveResolver`. */
493
- const projected = Object.hasOwn(context.slots, node.name)
494
- ? context.slots[node.name]
495
- : renderChildren(node.children, context);
496
- return createElement(Fragment, { key: node.id }, projected);
570
+ const slotFragment = (node, projected) => createElement(Fragment, { key: node.id }, projected);
571
+ const readChildren = (work, children) => {
572
+ /** Reversed, so the pop order is the document order the recursion gave. */
573
+ for (let index = children.length - 1; index >= 0; index -= 1) {
574
+ const child = children[index];
575
+ if (child)
576
+ work.push({ step: "read", node: child });
577
+ }
497
578
  };
498
- const renderNode = (node, context) => {
499
- switch (node.kind) {
500
- case "element":
501
- return renderElement(node, context);
502
- case "text":
503
- return node.value;
504
- case "slot":
505
- return renderSlot(node, context);
506
- default:
507
- return assertNever(node, "renderNode");
579
+ /**
580
+ * One subtree, rendered with an **explicit stack** and no call frame per level
581
+ * (0380).
582
+ *
583
+ * Until this was a loop, a page of a thousand elements threw
584
+ * `RangeError: Maximum call stack size exceeded` — on **every** render, and at
585
+ * the shallowest depth anything in the framework stopped at. React is not the
586
+ * reason that bound existed: its own server renderer walks fifty thousand
587
+ * levels in 135 ms, so what stopped a deep page was this function.
588
+ *
589
+ * Nothing about the output moves. Elements are prepared on the way down, in
590
+ * document order, which is what the anchor ledger and the diagnostic order
591
+ * depend on; they are built on the way up, around children that are already
592
+ * `ReactNode`s. A node the renderer omits is pushed as `null` and its subtree
593
+ * is never read, which is how a subtree under an unknown primitive stays silent
594
+ * rather than raising a diagnostic per node.
595
+ */
596
+ const renderSubtree = (root, context) => {
597
+ const work = [{ step: "read", node: root }];
598
+ const finished = [];
599
+ /** The last `count` children, taken off the stack in document order. */
600
+ const take = (count) => finished.splice(finished.length - count, count);
601
+ for (let next = work.pop(); next !== undefined; next = work.pop()) {
602
+ switch (next.step) {
603
+ case "build":
604
+ finished.push({
605
+ from: next.node,
606
+ element: next.assemble(elementBodyFrom(next.node, take(next.children))),
607
+ });
608
+ continue;
609
+ case "fill": {
610
+ const fallback = take(next.children);
611
+ finished.push({
612
+ from: next.node,
613
+ element: slotFragment(next.node, fallback.length === 0 ? null : fallback.map((child) => child.element)),
614
+ });
615
+ continue;
616
+ }
617
+ case "read":
618
+ break;
619
+ default:
620
+ return assertNever(next, "renderSubtree");
621
+ }
622
+ const node = next.node;
623
+ switch (node.kind) {
624
+ case "text":
625
+ finished.push({ from: node, element: node.value });
626
+ break;
627
+ case "slot":
628
+ /** Own-property only, for the reason given in `staticPrimitiveResolver`. */
629
+ if (Object.hasOwn(context.slots, node.name)) {
630
+ finished.push({ from: node, element: slotFragment(node, context.slots[node.name]) });
631
+ break;
632
+ }
633
+ work.push({ step: "fill", node, children: node.children.length });
634
+ readChildren(work, node.children);
635
+ break;
636
+ case "element": {
637
+ const assemble = prepareElement(node, context);
638
+ if (!assemble) {
639
+ finished.push({ from: node, element: null });
640
+ break;
641
+ }
642
+ work.push({ step: "build", node, assemble, children: node.children.length });
643
+ readChildren(work, node.children);
644
+ break;
645
+ }
646
+ default:
647
+ return assertNever(node, "renderSubtree");
648
+ }
508
649
  }
650
+ const rendered = finished[0];
651
+ /** Unreachable: one node in, one element out, and every branch pushes one. */
652
+ return rendered ? rendered.element : null;
509
653
  };
510
654
  /**
511
655
  * The theme is resolved once, from the root, before the walk begins — a tree
@@ -583,11 +727,12 @@ const renderFrom = (tree, from, options, collect) => {
583
727
  if (options.themeValues === "literals" && !theme) {
584
728
  collect({ code: "theme-values-unmounted", nodeId: tree.root.id });
585
729
  }
586
- const element = renderNode(from, {
730
+ const element = renderSubtree(from, {
587
731
  resolver: options.resolver,
588
732
  validator: options.validator,
589
733
  editMode: options.editMode ?? false,
590
734
  addressed: options.addressed ?? false,
735
+ audience: options.audience === DEFAULT_AUDIENCE_ID ? undefined : options.audience,
591
736
  slots: options.slots ?? {},
592
737
  tree,
593
738
  theme: theme ? themeStyle(theme, rampFor(options)) : undefined,
@@ -596,6 +741,7 @@ const renderFrom = (tree, from, options, collect) => {
596
741
  origins: options.origins,
597
742
  frames: isFrameResolver(options.resolver) ? options.resolver : undefined,
598
743
  reads: isBindingReader(options.resolver) ? options.resolver : undefined,
744
+ expects: isAnswerReader(options.resolver) ? options.resolver : undefined,
599
745
  unshown: isUnshownReader(options.resolver) ? options.resolver : undefined,
600
746
  placer: isSlotPlacer(options.resolver) ? options.resolver : undefined,
601
747
  text: composeText(options.resolver, options.text),
@@ -1,3 +1,4 @@
1
+ import type { AudienceId } from "../audience/audience.js";
1
2
  import type { DataRegistry } from "../data/adapter.js";
2
3
  import type { FrameOriginRegistry } from "../frame/origin.js";
3
4
  import type { TreeId } from "../ids.js";
@@ -33,8 +34,14 @@ export type RenderRequest = {
33
34
  * they are about. Off when absent (0136).
34
35
  */
35
36
  readonly addressed?: boolean;
37
+ /**
38
+ * The segment the site's server sorted this reader into, written on an
39
+ * addressed page's root so its signals are filed under it. See
40
+ * `RenderOptions.audience`.
41
+ */
42
+ readonly audience?: AudienceId | undefined;
36
43
  /** Opaque host context — audience, locale, flags — passed through to the source. */
37
- readonly context?: JsonObject;
44
+ readonly context?: JsonObject | undefined;
38
45
  };
39
46
  export type TreeSourceError = {
40
47
  readonly code: "not-found" | "unavailable";
@@ -46,6 +46,7 @@ export const renderRequest = async (request, dependencies) => {
46
46
  resolver: dependencies.resolver,
47
47
  editMode: request.editMode,
48
48
  ...(request.addressed ? { addressed: true } : {}),
49
+ audience: request.audience,
49
50
  ...(dependencies.validator ? { validator: dependencies.validator } : {}),
50
51
  ...(dependencies.themes ? { themes: dependencies.themes } : {}),
51
52
  ...(data ? { data } : {}),
@@ -0,0 +1,54 @@
1
+ import { z } from "zod";
2
+ import { type StakeLevel } from "./stake-level.js";
3
+ /**
4
+ * How much a policy lets an origin apply unattended, including none of it.
5
+ *
6
+ * A ceiling used to be a stake level, which made the strictest thing a
7
+ * deployment could say about an origin *low-stakes changes go live*. There is
8
+ * no level beneath `low`, so *nothing goes live, every change waits for a
9
+ * person* was not expressible at all — not by a lower ceiling, which does not
10
+ * exist, and not by `refusalFloor`, which throws the change away instead of
11
+ * holding it for somebody to look at.
12
+ *
13
+ * So the ceiling is its own scale: the four stake levels with one more rung
14
+ * below them. It lives beside the levels rather than among them because
15
+ * `nothing` is not a measure of damage — nothing is ever assessed at `nothing`
16
+ * stakes — and putting it in `STAKE_ORDER` would offer it to every reader of a
17
+ * level, `refusalFloor` and a role's acceptance ceiling included (0285).
18
+ */
19
+ /**
20
+ * The rung below `low`: this origin applies nothing on its own.
21
+ *
22
+ * Spelled as a word rather than as an absent entry, because an absent entry
23
+ * already means something — `ceilingFor` reads it as `low` — and a policy
24
+ * cannot say *I thought about this origin and decided none of it* by leaving it
25
+ * out.
26
+ */
27
+ export declare const NOTHING_AUTO_APPLIES = "nothing";
28
+ export declare const autoApplyCeilingSchema: z.ZodUnion<[z.ZodLiteral<"nothing">, z.ZodEnum<["low", "medium", "high", "critical"]>]>;
29
+ /** A stake level, or the rung below all of them. */
30
+ export type AutoApplyCeiling = z.infer<typeof autoApplyCeilingSchema>;
31
+ /**
32
+ * The ceiling scale in order, which like `STAKE_ORDER` is the order and not
33
+ * merely the set.
34
+ *
35
+ * Built from the stake order rather than written out again, so a level added to
36
+ * the scale the Gate weighs on arrives here in the same edit and cannot be
37
+ * ranked by accident.
38
+ */
39
+ export declare const CEILING_ORDER: readonly AutoApplyCeiling[];
40
+ /**
41
+ * Two ceilings compared. Only the sign is meaningful: negative is stricter,
42
+ * positive is looser, zero is the same latitude.
43
+ */
44
+ export declare const compareCeilings: (left: AutoApplyCeiling, right: AutoApplyCeiling) => number;
45
+ /**
46
+ * Whether a change assessed at this level is above what the origin may apply
47
+ * unattended — which, at `nothing`, every change is.
48
+ *
49
+ * A stake level is a ceiling, so this is one comparison on one scale rather
50
+ * than a branch on the sentinel. `low` stakes against a `low` ceiling is *at*
51
+ * it and applies; `low` stakes against `nothing` is above it and waits.
52
+ */
53
+ export declare const isAboveCeiling: (level: StakeLevel, ceiling: AutoApplyCeiling) => boolean;
54
+ //# sourceMappingURL=auto-apply-ceiling.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ import { everyMemberOf } from "../closed-set.js";
3
+ import { STAKE_ORDER, stakeLevelSchema } from "./stake-level.js";
4
+ /**
5
+ * How much a policy lets an origin apply unattended, including none of it.
6
+ *
7
+ * A ceiling used to be a stake level, which made the strictest thing a
8
+ * deployment could say about an origin *low-stakes changes go live*. There is
9
+ * no level beneath `low`, so *nothing goes live, every change waits for a
10
+ * person* was not expressible at all — not by a lower ceiling, which does not
11
+ * exist, and not by `refusalFloor`, which throws the change away instead of
12
+ * holding it for somebody to look at.
13
+ *
14
+ * So the ceiling is its own scale: the four stake levels with one more rung
15
+ * below them. It lives beside the levels rather than among them because
16
+ * `nothing` is not a measure of damage — nothing is ever assessed at `nothing`
17
+ * stakes — and putting it in `STAKE_ORDER` would offer it to every reader of a
18
+ * level, `refusalFloor` and a role's acceptance ceiling included (0285).
19
+ */
20
+ /**
21
+ * The rung below `low`: this origin applies nothing on its own.
22
+ *
23
+ * Spelled as a word rather than as an absent entry, because an absent entry
24
+ * already means something — `ceilingFor` reads it as `low` — and a policy
25
+ * cannot say *I thought about this origin and decided none of it* by leaving it
26
+ * out.
27
+ */
28
+ export const NOTHING_AUTO_APPLIES = "nothing";
29
+ export const autoApplyCeilingSchema = z.union([z.literal(NOTHING_AUTO_APPLIES), stakeLevelSchema]);
30
+ /**
31
+ * The ceiling scale in order, which like `STAKE_ORDER` is the order and not
32
+ * merely the set.
33
+ *
34
+ * Built from the stake order rather than written out again, so a level added to
35
+ * the scale the Gate weighs on arrives here in the same edit and cannot be
36
+ * ranked by accident.
37
+ */
38
+ export const CEILING_ORDER = everyMemberOf()([
39
+ NOTHING_AUTO_APPLIES,
40
+ ...STAKE_ORDER,
41
+ ]);
42
+ /**
43
+ * Where a ceiling sits on that scale.
44
+ *
45
+ * `indexOf` answers `-1` for a value this list does not name, which ranks it
46
+ * beneath `nothing` and so waves the change through — the same reassuring
47
+ * failure `rankOf` in `stake-level.ts` documents, reached the same way and
48
+ * filed in the same entry. The list is complete at compile time, so the route
49
+ * left is a value that never passed through the types.
50
+ */
51
+ const rankOf = (ceiling) => CEILING_ORDER.indexOf(ceiling);
52
+ /**
53
+ * Two ceilings compared. Only the sign is meaningful: negative is stricter,
54
+ * positive is looser, zero is the same latitude.
55
+ */
56
+ export const compareCeilings = (left, right) => rankOf(left) - rankOf(right);
57
+ /**
58
+ * Whether a change assessed at this level is above what the origin may apply
59
+ * unattended — which, at `nothing`, every change is.
60
+ *
61
+ * A stake level is a ceiling, so this is one comparison on one scale rather
62
+ * than a branch on the sentinel. `low` stakes against a `low` ceiling is *at*
63
+ * it and applies; `low` stakes against `nothing` is above it and waits.
64
+ */
65
+ export const isAboveCeiling = (level, ceiling) => compareCeilings(level, ceiling) > 0;
66
+ //# sourceMappingURL=auto-apply-ceiling.js.map
@@ -1,7 +1,24 @@
1
+ import { isAboveCeiling, NOTHING_AUTO_APPLIES, } from "./auto-apply-ceiling.js";
1
2
  import { policyFingerprintOf } from "./policy-fingerprint.js";
2
3
  import { ceilingFor } from "./policy.js";
3
- import { isAbove, isAtLeast } from "./stake-level.js";
4
+ import { isAtLeast } from "./stake-level.js";
4
5
  import { stakeFactor } from "./stakes.js";
6
+ /**
7
+ * The clause the four rungs below the refusal floor share, because they share
8
+ * one argument: a level cannot say "never auto-apply" while ceilings are per
9
+ * origin (0002), so these facts are held for a person regardless of who asked.
10
+ */
11
+ const HELD_WHATEVER_THE_ORIGIN = "this deployment holds for a person whatever its origin may apply";
12
+ /**
13
+ * A reason's sentence: what the change does, then what the policy did about it.
14
+ *
15
+ * Both halves, because either alone has been mistaken for the whole. The damage
16
+ * on its own is identical for a change that is held and the same change refused
17
+ * — the damage really is the same, and a reviewer shown only that cannot tell
18
+ * *this needs you* from *this will never be offered*. The consequence on its own
19
+ * would describe a policy and never the change in front of the reader.
20
+ */
21
+ const sentence = (damage, consequence) => damage.length > 0 ? `${damage}, which ${consequence}` : consequence;
5
22
  const decide = (assessment, policy, kind, reason) => ({
6
23
  kind,
7
24
  reason,
@@ -54,6 +71,7 @@ const rejectBelowConfidenceFloor = {
54
71
  return null;
55
72
  return `interpreter confidence ${confidence} is below the floor of ${policy.confidenceFloor}`;
56
73
  },
74
+ consequence: () => "this deployment refuses outright",
57
75
  };
58
76
  /** Some changes are not offered to the user at all, however they were asked for. */
59
77
  const rejectAtRefusalFloor = {
@@ -62,9 +80,9 @@ const rejectAtRefusalFloor = {
62
80
  fires: (assessment, policy) => {
63
81
  if (!isAtLeast(assessment.stakes.level, policy.refusalFloor))
64
82
  return null;
65
- const detail = assessment.stakes.factors.map((factor) => factor.detail).join("; ");
66
- return detail || `stakes reached ${policy.refusalFloor}`;
83
+ return assessment.stakes.factors.map((factor) => factor.detail).join("; ");
67
84
  },
85
+ consequence: (_assessment, policy) => `this deployment refuses outright at ${policy.refusalFloor} stakes`,
68
86
  };
69
87
  /** Undo would not undo reality, so a human decides — regardless of how small it looks. */
70
88
  const confirmIrreversible = {
@@ -76,6 +94,7 @@ const confirmIrreversible = {
76
94
  const detail = assessment.reversibility.reasons.map((reason) => reason.code).join("; ");
77
95
  return `cannot be undone cleanly: ${detail}`;
78
96
  },
97
+ consequence: () => HELD_WHATEVER_THE_ORIGIN,
79
98
  };
80
99
  /**
81
100
  * A change that writes over work already in the log is never applied without a
@@ -94,6 +113,7 @@ const confirmDiscardsLaterWork = {
94
113
  code: "discards-later-work",
95
114
  kind: "requires-confirmation",
96
115
  fires: (assessment) => stakeFactor(assessment.stakes, "discards-later-work")?.detail ?? null,
116
+ consequence: () => HELD_WHATEVER_THE_ORIGIN,
97
117
  };
98
118
  /**
99
119
  * A change that moves where a form posts is never applied without a person,
@@ -111,6 +131,7 @@ const confirmRedirectedSubmission = {
111
131
  code: "redirected-submission",
112
132
  kind: "requires-confirmation",
113
133
  fires: (assessment) => stakeFactor(assessment.stakes, "redirected-submission")?.detail ?? null,
134
+ consequence: () => HELD_WHATEVER_THE_ORIGIN,
114
135
  };
115
136
  /**
116
137
  * A change that points a region at different data is never applied without a
@@ -128,18 +149,51 @@ const confirmRepointedBinding = {
128
149
  code: "repointed-binding",
129
150
  kind: "requires-confirmation",
130
151
  fires: (assessment) => stakeFactor(assessment.stakes, "repointed-binding")?.detail ?? null,
152
+ consequence: () => HELD_WHATEVER_THE_ORIGIN,
153
+ };
154
+ /**
155
+ * What the ceiling rung says the change does, and why at `nothing` it says
156
+ * nothing at all.
157
+ *
158
+ * Everywhere else the factors are the better damage line: they say what about
159
+ * *this* change took it over the line, which is what somebody deciding whether
160
+ * to allow it wants. At `nothing` there is no line this change crossed — the
161
+ * deployment decided in advance that this origin applies none of its changes
162
+ * (0405) — so naming a factor would offer a reason that is not the reason, and
163
+ * invite a person to think a smaller change would have gone through.
164
+ *
165
+ * It is therefore the one rung whose damage half is empty *by policy* rather
166
+ * than for want of a factor to name, and the consequence below is the whole
167
+ * sentence. That is the single exception to the two-half shape, and it is an
168
+ * exception in the half that is said rather than in the half that is left out:
169
+ * the sentence still names the verdict and still names what decided it.
170
+ */
171
+ const ceilingDamage = (assessment, ceiling) => ceiling === NOTHING_AUTO_APPLIES
172
+ ? ""
173
+ : assessment.stakes.factors.map((factor) => factor.detail).join("; ");
174
+ /**
175
+ * What this deployment did about it, and on which of its thresholds.
176
+ *
177
+ * At `nothing` the threshold is the origin itself rather than a level on the
178
+ * scale, so the clause names the origin and what it is configured to apply —
179
+ * which is both what the policy did and the fact that a person is required.
180
+ */
181
+ const ceilingConsequence = (assessment, ceiling) => {
182
+ const { origin } = assessment.proposal.provenance;
183
+ if (ceiling === NOTHING_AUTO_APPLIES)
184
+ return `${origin} applies nothing without a person`;
185
+ return `this deployment holds for a person above ${origin}'s ${ceiling} ceiling`;
131
186
  };
132
187
  const confirmAboveCeiling = {
133
188
  code: "stakes-above-ceiling",
134
189
  kind: "requires-confirmation",
135
190
  fires: (assessment, policy) => {
136
191
  const ceiling = ceilingFor(policy, assessment.proposal.provenance.origin);
137
- if (!isAbove(assessment.stakes.level, ceiling))
192
+ if (!isAboveCeiling(assessment.stakes.level, ceiling))
138
193
  return null;
139
- const detail = assessment.stakes.factors.map((factor) => factor.detail).join("; ");
140
- return (detail ||
141
- `${assessment.stakes.level} stakes exceed the ${ceiling} ceiling for ${assessment.proposal.provenance.origin}`);
194
+ return ceilingDamage(assessment, ceiling);
142
195
  },
196
+ consequence: (assessment, policy) => ceilingConsequence(assessment, ceilingFor(policy, assessment.proposal.provenance.origin)),
143
197
  };
144
198
  const confirmBelowMinimumConfidence = {
145
199
  code: "confidence-below-minimum",
@@ -150,6 +204,7 @@ const confirmBelowMinimumConfidence = {
150
204
  return null;
151
205
  return `interpreter confidence ${confidence} is below ${policy.minimumConfidence}`;
152
206
  },
207
+ consequence: () => "this deployment holds for a person",
153
208
  };
154
209
  /** Nothing objected, so the change goes through. */
155
210
  const accept = (assessment, policy) => decide(assessment, policy, "accepted", {
@@ -182,9 +237,13 @@ const ESCALATION_RULES = [
182
237
  export const ESCALATION_LADDER = ESCALATION_RULES.map((rule) => rule.code);
183
238
  export const gate = (assessment, policy) => {
184
239
  for (const rule of ESCALATION_RULES) {
185
- const detail = rule.fires(assessment, policy);
186
- if (detail !== null)
187
- return decide(assessment, policy, rule.kind, { code: rule.code, detail });
240
+ const damage = rule.fires(assessment, policy);
241
+ if (damage === null)
242
+ continue;
243
+ return decide(assessment, policy, rule.kind, {
244
+ code: rule.code,
245
+ detail: sentence(damage, rule.consequence(assessment, policy)),
246
+ });
188
247
  }
189
248
  return accept(assessment, policy);
190
249
  };
@@ -7,6 +7,7 @@
7
7
  */
8
8
  export * from "./analysis.js";
9
9
  export * from "./assessment.js";
10
+ export * from "./auto-apply-ceiling.js";
10
11
  export * from "./checks.js";
11
12
  export * from "./disposition.js";
12
13
  export * from "./events.js";
@@ -7,6 +7,7 @@
7
7
  */
8
8
  export * from "./analysis.js";
9
9
  export * from "./assessment.js";
10
+ export * from "./auto-apply-ceiling.js";
10
11
  export * from "./checks.js";
11
12
  export * from "./disposition.js";
12
13
  export * from "./events.js";