@jam-overture/loom 0.1.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 (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +743 -0
  3. package/dist/catalogue.d.ts +70 -0
  4. package/dist/catalogue.js +88 -0
  5. package/dist/cli/args.d.ts +17 -0
  6. package/dist/cli/args.js +83 -0
  7. package/dist/cli/filesystem.d.ts +15 -0
  8. package/dist/cli/filesystem.js +31 -0
  9. package/dist/cli/index.d.ts +12 -0
  10. package/dist/cli/index.js +12 -0
  11. package/dist/cli/main.d.ts +3 -0
  12. package/dist/cli/main.js +30 -0
  13. package/dist/cli/namespace.d.ts +40 -0
  14. package/dist/cli/namespace.js +40 -0
  15. package/dist/cli/plan.d.ts +84 -0
  16. package/dist/cli/plan.js +113 -0
  17. package/dist/cli/run.d.ts +17 -0
  18. package/dist/cli/run.js +75 -0
  19. package/dist/cli/templates.d.ts +43 -0
  20. package/dist/cli/templates.js +134 -0
  21. package/dist/closed-set.d.ts +34 -0
  22. package/dist/closed-set.js +34 -0
  23. package/dist/data/adapter.d.ts +123 -0
  24. package/dist/data/adapter.js +91 -0
  25. package/dist/data/binding.d.ts +48 -0
  26. package/dist/data/binding.js +39 -0
  27. package/dist/data/catalogue.d.ts +26 -0
  28. package/dist/data/catalogue.js +6 -0
  29. package/dist/data/index.d.ts +14 -0
  30. package/dist/data/index.js +14 -0
  31. package/dist/data/plan.d.ts +58 -0
  32. package/dist/data/plan.js +0 -0
  33. package/dist/data/resolution.d.ts +91 -0
  34. package/dist/data/resolution.js +96 -0
  35. package/dist/data/resolve.d.ts +46 -0
  36. package/dist/data/resolve.js +37 -0
  37. package/dist/data/source.d.ts +40 -0
  38. package/dist/data/source.js +45 -0
  39. package/dist/deadline.d.ts +57 -0
  40. package/dist/deadline.js +78 -0
  41. package/dist/frame/catalogue.d.ts +24 -0
  42. package/dist/frame/catalogue.js +5 -0
  43. package/dist/frame/index.d.ts +12 -0
  44. package/dist/frame/index.js +12 -0
  45. package/dist/frame/origin.d.ts +87 -0
  46. package/dist/frame/origin.js +114 -0
  47. package/dist/frame/resolution.d.ts +85 -0
  48. package/dist/frame/resolution.js +79 -0
  49. package/dist/grammar.d.ts +26 -0
  50. package/dist/grammar.js +28 -0
  51. package/dist/ids.d.ts +57 -0
  52. package/dist/ids.js +104 -0
  53. package/dist/index.d.ts +26 -0
  54. package/dist/index.js +26 -0
  55. package/dist/interactivity.d.ts +50 -0
  56. package/dist/interactivity.js +22 -0
  57. package/dist/interpretation/anthropic.d.ts +22 -0
  58. package/dist/interpretation/anthropic.js +76 -0
  59. package/dist/interpretation/client.d.ts +83 -0
  60. package/dist/interpretation/client.js +2 -0
  61. package/dist/interpretation/draft.d.ts +234 -0
  62. package/dist/interpretation/draft.js +84 -0
  63. package/dist/interpretation/index.d.ts +15 -0
  64. package/dist/interpretation/index.js +15 -0
  65. package/dist/interpretation/interpreter.d.ts +62 -0
  66. package/dist/interpretation/interpreter.js +151 -0
  67. package/dist/interpretation/materialize.d.ts +42 -0
  68. package/dist/interpretation/materialize.js +107 -0
  69. package/dist/interpretation/prompt.d.ts +229 -0
  70. package/dist/interpretation/prompt.js +285 -0
  71. package/dist/interpretation/render.d.ts +76 -0
  72. package/dist/interpretation/render.js +272 -0
  73. package/dist/interpretation/schema.d.ts +49 -0
  74. package/dist/interpretation/schema.js +131 -0
  75. package/dist/json.d.ts +35 -0
  76. package/dist/json.js +11 -0
  77. package/dist/paging.d.ts +60 -0
  78. package/dist/paging.js +49 -0
  79. package/dist/primitive-type.d.ts +32 -0
  80. package/dist/primitive-type.js +39 -0
  81. package/dist/render/addressing.d.ts +59 -0
  82. package/dist/render/addressing.js +60 -0
  83. package/dist/render/anchor.d.ts +105 -0
  84. package/dist/render/anchor.js +84 -0
  85. package/dist/render/behaviour-adjust.d.ts +62 -0
  86. package/dist/render/behaviour-adjust.js +78 -0
  87. package/dist/render/behaviour-copy.d.ts +53 -0
  88. package/dist/render/behaviour-copy.js +75 -0
  89. package/dist/render/behaviour-disclose.d.ts +74 -0
  90. package/dist/render/behaviour-disclose.js +77 -0
  91. package/dist/render/behaviour-present.d.ts +123 -0
  92. package/dist/render/behaviour-present.js +173 -0
  93. package/dist/render/behaviour.d.ts +243 -0
  94. package/dist/render/behaviour.js +284 -0
  95. package/dist/render/control.d.ts +81 -0
  96. package/dist/render/control.js +80 -0
  97. package/dist/render/decorative.d.ts +62 -0
  98. package/dist/render/decorative.js +2 -0
  99. package/dist/render/diagnostics.d.ts +260 -0
  100. package/dist/render/diagnostics.js +61 -0
  101. package/dist/render/disclosed.d.ts +37 -0
  102. package/dist/render/disclosed.js +37 -0
  103. package/dist/render/editable.d.ts +34 -0
  104. package/dist/render/editable.js +35 -0
  105. package/dist/render/frame.d.ts +42 -0
  106. package/dist/render/frame.js +31 -0
  107. package/dist/render/index.d.ts +35 -0
  108. package/dist/render/index.js +35 -0
  109. package/dist/render/inline-variables.d.ts +77 -0
  110. package/dist/render/inline-variables.js +220 -0
  111. package/dist/render/presented.d.ts +82 -0
  112. package/dist/render/presented.js +82 -0
  113. package/dist/render/primitive.d.ts +228 -0
  114. package/dist/render/primitive.js +36 -0
  115. package/dist/render/props.d.ts +48 -0
  116. package/dist/render/props.js +2 -0
  117. package/dist/render/reads.d.ts +73 -0
  118. package/dist/render/reads.js +45 -0
  119. package/dist/render/render.d.ts +164 -0
  120. package/dist/render/render.js +571 -0
  121. package/dist/render/request.d.ts +111 -0
  122. package/dist/render/request.js +60 -0
  123. package/dist/render/text.d.ts +91 -0
  124. package/dist/render/text.js +44 -0
  125. package/dist/render/theme.d.ts +61 -0
  126. package/dist/render/theme.js +52 -0
  127. package/dist/reserved-props.d.ts +35 -0
  128. package/dist/reserved-props.js +45 -0
  129. package/dist/result.d.ts +27 -0
  130. package/dist/result.js +30 -0
  131. package/dist/role.d.ts +71 -0
  132. package/dist/role.js +22 -0
  133. package/dist/runtime/analysis.d.ts +149 -0
  134. package/dist/runtime/analysis.js +187 -0
  135. package/dist/runtime/assessment.d.ts +35 -0
  136. package/dist/runtime/assessment.js +13 -0
  137. package/dist/runtime/disposition.d.ts +102 -0
  138. package/dist/runtime/disposition.js +59 -0
  139. package/dist/runtime/events.d.ts +187 -0
  140. package/dist/runtime/events.js +7 -0
  141. package/dist/runtime/gate.d.ts +43 -0
  142. package/dist/runtime/gate.js +169 -0
  143. package/dist/runtime/index.d.ts +27 -0
  144. package/dist/runtime/index.js +27 -0
  145. package/dist/runtime/intent.d.ts +60 -0
  146. package/dist/runtime/intent.js +36 -0
  147. package/dist/runtime/interpreter.d.ts +117 -0
  148. package/dist/runtime/interpreter.js +46 -0
  149. package/dist/runtime/inverse-interpreter.d.ts +90 -0
  150. package/dist/runtime/inverse-interpreter.js +56 -0
  151. package/dist/runtime/inverse.d.ts +87 -0
  152. package/dist/runtime/inverse.js +48 -0
  153. package/dist/runtime/narration.d.ts +24 -0
  154. package/dist/runtime/narration.js +36 -0
  155. package/dist/runtime/nesting.d.ts +31 -0
  156. package/dist/runtime/nesting.js +46 -0
  157. package/dist/runtime/pipeline.d.ts +124 -0
  158. package/dist/runtime/pipeline.js +178 -0
  159. package/dist/runtime/policy-fingerprint.d.ts +29 -0
  160. package/dist/runtime/policy-fingerprint.js +119 -0
  161. package/dist/runtime/policy-source.d.ts +42 -0
  162. package/dist/runtime/policy-source.js +8 -0
  163. package/dist/runtime/policy.d.ts +156 -0
  164. package/dist/runtime/policy.js +107 -0
  165. package/dist/runtime/proposal.d.ts +423 -0
  166. package/dist/runtime/proposal.js +109 -0
  167. package/dist/runtime/redirection.d.ts +53 -0
  168. package/dist/runtime/redirection.js +38 -0
  169. package/dist/runtime/repointing.d.ts +71 -0
  170. package/dist/runtime/repointing.js +0 -0
  171. package/dist/runtime/reversibility.d.ts +36 -0
  172. package/dist/runtime/reversibility.js +39 -0
  173. package/dist/runtime/stake-level.d.ts +33 -0
  174. package/dist/runtime/stake-level.js +58 -0
  175. package/dist/runtime/stakes.d.ts +47 -0
  176. package/dist/runtime/stakes.js +305 -0
  177. package/dist/runtime/vocabulary.d.ts +122 -0
  178. package/dist/runtime/vocabulary.js +87 -0
  179. package/dist/sdk/audit.d.ts +195 -0
  180. package/dist/sdk/audit.js +128 -0
  181. package/dist/sdk/catalogue.d.ts +37 -0
  182. package/dist/sdk/catalogue.js +16 -0
  183. package/dist/sdk/conformance.d.ts +342 -0
  184. package/dist/sdk/conformance.js +494 -0
  185. package/dist/sdk/copy.d.ts +105 -0
  186. package/dist/sdk/copy.js +90 -0
  187. package/dist/sdk/definition.d.ts +242 -0
  188. package/dist/sdk/definition.js +64 -0
  189. package/dist/sdk/index.d.ts +19 -0
  190. package/dist/sdk/index.js +19 -0
  191. package/dist/sdk/interactivity.d.ts +29 -0
  192. package/dist/sdk/interactivity.js +34 -0
  193. package/dist/sdk/pairings.d.ts +124 -0
  194. package/dist/sdk/pairings.js +81 -0
  195. package/dist/sdk/registry.d.ts +162 -0
  196. package/dist/sdk/registry.js +329 -0
  197. package/dist/sdk/selection.d.ts +46 -0
  198. package/dist/sdk/selection.js +24 -0
  199. package/dist/sdk/text.d.ts +100 -0
  200. package/dist/sdk/text.js +105 -0
  201. package/dist/sdk/vocabulary.d.ts +39 -0
  202. package/dist/sdk/vocabulary.js +36 -0
  203. package/dist/signals/broadcast.d.ts +134 -0
  204. package/dist/signals/broadcast.js +451 -0
  205. package/dist/signals/collect.d.ts +184 -0
  206. package/dist/signals/collect.js +196 -0
  207. package/dist/signals/deliver.d.ts +64 -0
  208. package/dist/signals/deliver.js +85 -0
  209. package/dist/signals/fold.d.ts +112 -0
  210. package/dist/signals/fold.js +76 -0
  211. package/dist/signals/index.d.ts +31 -0
  212. package/dist/signals/index.js +31 -0
  213. package/dist/signals/ingest.d.ts +51 -0
  214. package/dist/signals/ingest.js +70 -0
  215. package/dist/signals/intake.d.ts +149 -0
  216. package/dist/signals/intake.js +154 -0
  217. package/dist/signals/journal.d.ts +94 -0
  218. package/dist/signals/journal.js +11 -0
  219. package/dist/signals/kinds.d.ts +22 -0
  220. package/dist/signals/kinds.js +22 -0
  221. package/dist/signals/ledger.d.ts +46 -0
  222. package/dist/signals/ledger.js +81 -0
  223. package/dist/signals/memory.d.ts +17 -0
  224. package/dist/signals/memory.js +99 -0
  225. package/dist/signals/migrate.d.ts +27 -0
  226. package/dist/signals/migrate.js +78 -0
  227. package/dist/signals/postgres.d.ts +7 -0
  228. package/dist/signals/postgres.js +295 -0
  229. package/dist/signals/rollup.d.ts +142 -0
  230. package/dist/signals/rollup.js +0 -0
  231. package/dist/signals/schema.d.ts +534 -0
  232. package/dist/signals/schema.js +92 -0
  233. package/dist/signals/signal.d.ts +381 -0
  234. package/dist/signals/signal.js +150 -0
  235. package/dist/signals/tally.d.ts +70 -0
  236. package/dist/signals/tally.js +2 -0
  237. package/dist/signals/view.d.ts +51 -0
  238. package/dist/signals/view.js +54 -0
  239. package/dist/store/attribution.d.ts +125 -0
  240. package/dist/store/attribution.js +116 -0
  241. package/dist/store/database.d.ts +14 -0
  242. package/dist/store/database.js +2 -0
  243. package/dist/store/driver.d.ts +29 -0
  244. package/dist/store/driver.js +39 -0
  245. package/dist/store/errors.d.ts +56 -0
  246. package/dist/store/errors.js +37 -0
  247. package/dist/store/index.d.ts +16 -0
  248. package/dist/store/index.js +16 -0
  249. package/dist/store/memory.d.ts +3 -0
  250. package/dist/store/memory.js +115 -0
  251. package/dist/store/migrate.d.ts +54 -0
  252. package/dist/store/migrate.js +122 -0
  253. package/dist/store/postgres-holds.d.ts +4 -0
  254. package/dist/store/postgres-holds.js +192 -0
  255. package/dist/store/postgres.d.ts +8 -0
  256. package/dist/store/postgres.js +262 -0
  257. package/dist/store/replay.d.ts +94 -0
  258. package/dist/store/replay.js +82 -0
  259. package/dist/store/revert.d.ts +116 -0
  260. package/dist/store/revert.js +243 -0
  261. package/dist/store/schema.d.ts +371 -0
  262. package/dist/store/schema.js +78 -0
  263. package/dist/store/source.d.ts +23 -0
  264. package/dist/store/source.js +37 -0
  265. package/dist/store/store.d.ts +231 -0
  266. package/dist/store/store.js +52 -0
  267. package/dist/store/undone.d.ts +18 -0
  268. package/dist/store/undone.js +89 -0
  269. package/dist/submit/catalogue.d.ts +20 -0
  270. package/dist/submit/catalogue.js +5 -0
  271. package/dist/submit/declaration.d.ts +39 -0
  272. package/dist/submit/declaration.js +30 -0
  273. package/dist/submit/endpoint.d.ts +131 -0
  274. package/dist/submit/endpoint.js +160 -0
  275. package/dist/submit/index.d.ts +13 -0
  276. package/dist/submit/index.js +13 -0
  277. package/dist/submit/plan.d.ts +49 -0
  278. package/dist/submit/plan.js +47 -0
  279. package/dist/submit/resolution.d.ts +61 -0
  280. package/dist/submit/resolution.js +64 -0
  281. package/dist/submit/resolve.d.ts +45 -0
  282. package/dist/submit/resolve.js +36 -0
  283. package/dist/telemetry/calibration.d.ts +132 -0
  284. package/dist/telemetry/calibration.js +151 -0
  285. package/dist/telemetry/episode.d.ts +140 -0
  286. package/dist/telemetry/episode.js +272 -0
  287. package/dist/telemetry/event.d.ts +2310 -0
  288. package/dist/telemetry/event.js +405 -0
  289. package/dist/telemetry/index.d.ts +15 -0
  290. package/dist/telemetry/index.js +15 -0
  291. package/dist/telemetry/journal.d.ts +116 -0
  292. package/dist/telemetry/journal.js +11 -0
  293. package/dist/telemetry/memory.d.ts +24 -0
  294. package/dist/telemetry/memory.js +75 -0
  295. package/dist/telemetry/migrate.d.ts +26 -0
  296. package/dist/telemetry/migrate.js +40 -0
  297. package/dist/telemetry/postgres.d.ts +6 -0
  298. package/dist/telemetry/postgres.js +139 -0
  299. package/dist/telemetry/retention.d.ts +131 -0
  300. package/dist/telemetry/retention.js +217 -0
  301. package/dist/telemetry/schema.d.ts +113 -0
  302. package/dist/telemetry/schema.js +33 -0
  303. package/dist/telemetry/sink.d.ts +42 -0
  304. package/dist/telemetry/sink.js +61 -0
  305. package/dist/testing/contracts.d.ts +34 -0
  306. package/dist/testing/contracts.js +34 -0
  307. package/dist/testing/definitions.d.ts +15 -0
  308. package/dist/testing/definitions.js +48 -0
  309. package/dist/testing/doubles.d.ts +94 -0
  310. package/dist/testing/doubles.js +141 -0
  311. package/dist/testing/episode-harness.d.ts +49 -0
  312. package/dist/testing/episode-harness.js +65 -0
  313. package/dist/testing/filesystem.d.ts +17 -0
  314. package/dist/testing/filesystem.js +17 -0
  315. package/dist/testing/fixtures.d.ts +57 -0
  316. package/dist/testing/fixtures.js +84 -0
  317. package/dist/testing/hold-contract.d.ts +19 -0
  318. package/dist/testing/hold-contract.js +374 -0
  319. package/dist/testing/index.d.ts +41 -0
  320. package/dist/testing/index.js +41 -0
  321. package/dist/testing/journal-contract.d.ts +17 -0
  322. package/dist/testing/journal-contract.js +353 -0
  323. package/dist/testing/model-replies.d.ts +34 -0
  324. package/dist/testing/model-replies.js +101 -0
  325. package/dist/testing/primitives.d.ts +7 -0
  326. package/dist/testing/primitives.js +29 -0
  327. package/dist/testing/reader-signal-contract.d.ts +38 -0
  328. package/dist/testing/reader-signal-contract.js +318 -0
  329. package/dist/testing/row-security.d.ts +17 -0
  330. package/dist/testing/row-security.js +21 -0
  331. package/dist/testing/store-contract.d.ts +25 -0
  332. package/dist/testing/store-contract.js +500 -0
  333. package/dist/theme/apply.d.ts +17 -0
  334. package/dist/theme/apply.js +60 -0
  335. package/dist/theme/contrast.d.ts +197 -0
  336. package/dist/theme/contrast.js +259 -0
  337. package/dist/theme/derive.d.ts +77 -0
  338. package/dist/theme/derive.js +167 -0
  339. package/dist/theme/faces.d.ts +73 -0
  340. package/dist/theme/faces.js +119 -0
  341. package/dist/theme/font-packs.d.ts +25 -0
  342. package/dist/theme/font-packs.js +257 -0
  343. package/dist/theme/index.d.ts +20 -0
  344. package/dist/theme/index.js +20 -0
  345. package/dist/theme/lab.d.ts +30 -0
  346. package/dist/theme/lab.js +46 -0
  347. package/dist/theme/library.d.ts +114 -0
  348. package/dist/theme/library.js +300 -0
  349. package/dist/theme/measure.d.ts +144 -0
  350. package/dist/theme/measure.js +145 -0
  351. package/dist/theme/palettes.d.ts +64 -0
  352. package/dist/theme/palettes.js +497 -0
  353. package/dist/theme/registry.d.ts +59 -0
  354. package/dist/theme/registry.js +60 -0
  355. package/dist/theme/separation.d.ts +177 -0
  356. package/dist/theme/separation.js +203 -0
  357. package/dist/theme/style-presets.d.ts +60 -0
  358. package/dist/theme/style-presets.js +124 -0
  359. package/dist/theme/theme.d.ts +253 -0
  360. package/dist/theme/theme.js +171 -0
  361. package/dist/tree/apply.d.ts +16 -0
  362. package/dist/tree/apply.js +104 -0
  363. package/dist/tree/builders.d.ts +19 -0
  364. package/dist/tree/builders.js +20 -0
  365. package/dist/tree/compare.d.ts +68 -0
  366. package/dist/tree/compare.js +75 -0
  367. package/dist/tree/configuration.d.ts +25 -0
  368. package/dist/tree/configuration.js +108 -0
  369. package/dist/tree/delta.d.ts +288 -0
  370. package/dist/tree/delta.js +88 -0
  371. package/dist/tree/errors.d.ts +69 -0
  372. package/dist/tree/errors.js +34 -0
  373. package/dist/tree/identity.d.ts +117 -0
  374. package/dist/tree/identity.js +145 -0
  375. package/dist/tree/index.d.ts +21 -0
  376. package/dist/tree/index.js +21 -0
  377. package/dist/tree/inverse.d.ts +24 -0
  378. package/dist/tree/inverse.js +112 -0
  379. package/dist/tree/mutation.d.ts +18 -0
  380. package/dist/tree/mutation.js +49 -0
  381. package/dist/tree/naming.d.ts +4 -0
  382. package/dist/tree/naming.js +35 -0
  383. package/dist/tree/navigation.d.ts +38 -0
  384. package/dist/tree/navigation.js +83 -0
  385. package/dist/tree/node.d.ts +103 -0
  386. package/dist/tree/node.js +46 -0
  387. package/dist/tree/outline.d.ts +28 -0
  388. package/dist/tree/outline.js +10 -0
  389. package/dist/tree/tree.d.ts +83 -0
  390. package/dist/tree/tree.js +62 -0
  391. package/dist/write/commit.d.ts +124 -0
  392. package/dist/write/commit.js +234 -0
  393. package/dist/write/held.d.ts +674 -0
  394. package/dist/write/held.js +185 -0
  395. package/dist/write/index.d.ts +11 -0
  396. package/dist/write/index.js +11 -0
  397. package/dist/write/liveness.d.ts +132 -0
  398. package/dist/write/liveness.js +91 -0
  399. package/dist/write/revert.d.ts +79 -0
  400. package/dist/write/revert.js +134 -0
  401. package/package.json +160 -0
@@ -0,0 +1,178 @@
1
+ import { applyDelta } from "../tree/apply.js";
2
+ import { assessChange } from "./assessment.js";
3
+ import { gate } from "./gate.js";
4
+ import { narrator } from "./narration.js";
5
+ /**
6
+ * The five ways an ask can end, in the order a host meets them.
7
+ *
8
+ * The same addition `WRITE_OUTCOME_KINDS` is for the write path, one level up:
9
+ * a `switch` is exhaustive at compile time and enumeration has no answer, so
10
+ * anything that wants to *walk* the endings — a surface explaining what a host
11
+ * must handle, a dashboard seeding a bucket per ending before the first request,
12
+ * a runbook — keeps its own copy and nothing fails when a sixth lands.
13
+ *
14
+ * Ordered applied, awaiting-confirmation, rejected, not-interpreted,
15
+ * not-applicable: the three the Gate decides first, then the two that never
16
+ * reached it. A reader taking them in this order learns the shape of the
17
+ * pipeline; alphabetical order would put `applied` beside `awaiting-confirmation`
18
+ * for no reason a reader could use.
19
+ */
20
+ export const COMPOSITION_OUTCOME_KINDS = [
21
+ "applied",
22
+ "awaiting-confirmation",
23
+ "rejected",
24
+ "not-interpreted",
25
+ "not-applicable",
26
+ ];
27
+ const emitter = (runtime, tree) => narrator(runtime.events, runtime.clock, tree.treeId);
28
+ /**
29
+ * Applies an already-assessed change. Shared by the auto-apply path and the
30
+ * confirmation path so both emit the same events and enforce the same revision
31
+ * check — a confirmation that arrives after the tree moved on must not land.
32
+ */
33
+ const applyAssessedChange = (runtime, tree, assessment, disposition) => {
34
+ const emit = emitter(runtime, tree);
35
+ const applied = applyDelta(tree, assessment.proposal.delta);
36
+ if (!applied.ok) {
37
+ emit({
38
+ type: "application-failed",
39
+ proposalId: assessment.proposal.proposalId,
40
+ error: applied.error,
41
+ });
42
+ return { kind: "not-applicable", proposal: assessment.proposal, error: applied.error };
43
+ }
44
+ emit({
45
+ type: "change-applied",
46
+ proposalId: assessment.proposal.proposalId,
47
+ revision: applied.value.revision,
48
+ inverse: assessment.reversibility.inverse,
49
+ });
50
+ return {
51
+ kind: "applied",
52
+ tree: applied.value,
53
+ assessment,
54
+ disposition,
55
+ inverse: assessment.reversibility.inverse,
56
+ };
57
+ };
58
+ const dispositionOutcome = (runtime, tree, assessment, disposition) => {
59
+ switch (disposition.kind) {
60
+ case "accepted":
61
+ return applyAssessedChange(runtime, tree, assessment, disposition);
62
+ case "requires-confirmation":
63
+ return { kind: "awaiting-confirmation", assessment, disposition };
64
+ case "rejected":
65
+ return { kind: "rejected", assessment, disposition };
66
+ }
67
+ };
68
+ const judgeProposal = (runtime, tree, proposal, policy) => {
69
+ const emit = emitter(runtime, tree);
70
+ emit({ type: "change-proposed", proposal });
71
+ const assessed = assessChange(tree, proposal, policy, runtime.idFactory.deltaId(), runtime.propsVocabulary);
72
+ if (!assessed.ok) {
73
+ emit({ type: "assessment-failed", proposal, error: assessed.error });
74
+ return { kind: "not-applicable", proposal, error: assessed.error };
75
+ }
76
+ const assessment = assessed.value;
77
+ emit({ type: "change-assessed", assessment });
78
+ const disposition = gate(assessment, policy);
79
+ emit({ type: "disposition-decided", proposalId: proposal.proposalId, disposition });
80
+ return { kind: "judged", assessment, disposition };
81
+ };
82
+ /**
83
+ * One attempt, and the "one" is structural: this function judges the repaired
84
+ * proposal and returns its outcome, so there is no path back into itself and no
85
+ * counter to get wrong. A repair that is refused again is terminal.
86
+ *
87
+ * The runtime — not the repairer — stamps `repairOf`, so a weaker second
88
+ * proposal cannot present itself as an unrelated first attempt. Both
89
+ * dispositions are already in the event stream by the time this returns, which
90
+ * is what makes "refused, then accepted a smaller version" a pattern telemetry
91
+ * can find rather than one it has to infer.
92
+ *
93
+ * A repairer that declines leaves the original refusal standing and carries its
94
+ * error out on the outcome, so a caller holding only the return value can still
95
+ * tell that ending from a run where nothing was asked.
96
+ */
97
+ const attemptRepair = async (runtime, tree, intent, policy, repairer, refusal) => {
98
+ const emit = emitter(runtime, tree);
99
+ const refused = refusal.assessment.proposal;
100
+ const { disposition } = refusal;
101
+ emit({
102
+ type: "repair-requested",
103
+ refusedProposalId: refused.proposalId,
104
+ reason: disposition.reason,
105
+ });
106
+ const repaired = await repairer.repair({ intent, refused, disposition }, tree);
107
+ if (!repaired.ok) {
108
+ emit({ type: "repair-failed", refusedProposalId: refused.proposalId, error: repaired.error });
109
+ return {
110
+ kind: "rejected",
111
+ assessment: refusal.assessment,
112
+ disposition,
113
+ repairFailure: repaired.error,
114
+ };
115
+ }
116
+ const judged = judgeProposal(runtime, tree, { ...repaired.value, repairOf: refused.proposalId }, policy);
117
+ return judged.kind === "not-applicable"
118
+ ? judged
119
+ : dispositionOutcome(runtime, tree, judged.assessment, judged.disposition);
120
+ };
121
+ export const composeChange = async (runtime, tree, intent) => {
122
+ const emit = emitter(runtime, tree);
123
+ emit({ type: "intent-received", intent });
124
+ /**
125
+ * Resolved once, before interpretation, and used for every judgment this
126
+ * intent produces — including a repair's. Resolving again per proposal would
127
+ * let a repair be judged by a different policy than the proposal it replaces,
128
+ * which is the one comparison the gate exists to make (0006).
129
+ */
130
+ const policy = runtime.policySource.resolve({ tree, intent });
131
+ emit({ type: "policy-resolved", intentId: intent.intentId, policy });
132
+ const interpreted = await runtime.interpreter.interpret(intent, tree);
133
+ if (!interpreted.ok) {
134
+ emit({ type: "interpretation-failed", intent, error: interpreted.error });
135
+ return { kind: "not-interpreted", error: interpreted.error };
136
+ }
137
+ const judged = judgeProposal(runtime, tree, interpreted.value, policy);
138
+ if (judged.kind === "not-applicable")
139
+ return judged;
140
+ const { repairer } = runtime;
141
+ if (judged.disposition.kind === "rejected" && repairer) {
142
+ return attemptRepair(runtime, tree, intent, policy, repairer, judged);
143
+ }
144
+ return dispositionOutcome(runtime, tree, judged.assessment, judged.disposition);
145
+ };
146
+ /**
147
+ * Completes a change the Gate held back. The assessment is recomputed against
148
+ * the tree as it stands now rather than trusting the one captured at proposal
149
+ * time, so a confirmation cannot smuggle in a decision made about a different
150
+ * tree. A change the Gate now refuses outright stays refused, even with a
151
+ * human saying yes.
152
+ */
153
+ export const confirmChange = (runtime, tree, proposal, intent) => {
154
+ const emit = emitter(runtime, tree);
155
+ /**
156
+ * Resolved again rather than carried over from the hold, for the same reason
157
+ * the assessment is recomputed: the second look is a look at things as they
158
+ * are now. A host that narrowed a policy while a proposal sat in the queue
159
+ * meant that for the queue too, and the disposition records which one
160
+ * actually decided.
161
+ */
162
+ const policy = runtime.policySource.resolve({ tree, intent });
163
+ emit({ type: "policy-resolved", intentId: intent.intentId, policy });
164
+ const assessed = assessChange(tree, proposal, policy, runtime.idFactory.deltaId(), runtime.propsVocabulary);
165
+ if (!assessed.ok) {
166
+ emit({ type: "assessment-failed", proposal, error: assessed.error });
167
+ return { kind: "not-applicable", proposal, error: assessed.error };
168
+ }
169
+ const assessment = assessed.value;
170
+ emit({ type: "change-assessed", assessment });
171
+ const disposition = gate(assessment, policy);
172
+ emit({ type: "disposition-decided", proposalId: proposal.proposalId, disposition });
173
+ if (disposition.kind === "rejected") {
174
+ return { kind: "rejected", assessment, disposition };
175
+ }
176
+ return applyAssessedChange(runtime, tree, assessment, disposition);
177
+ };
178
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1,29 @@
1
+ import type { GatePolicy } from "./policy.js";
2
+ export declare const policyFingerprintOf: (policy: GatePolicy) => string;
3
+ /**
4
+ * Which set of knobs a fingerprint describes. Total on purpose: a string that is
5
+ * not a fingerprint this version produced is treated as its own shape, so it
6
+ * compares as *incomparable* to everything. Failing toward "cannot tell" is the
7
+ * right direction — the alternative is a malformed record silently reading as
8
+ * agreement.
9
+ */
10
+ export declare const policyShapeOf: (fingerprint: string) => string;
11
+ /**
12
+ * What a set of fingerprints seen under one policy name says about that name.
13
+ *
14
+ * - `unrecorded` — nothing carried a fingerprint. Every one of those judgments
15
+ * predates this field, and no amount of reading will recover what they ran on.
16
+ * - `single` — one ruleset judged all of them. The name held.
17
+ * - `changed` — two fingerprints of the same shape differ, so a host edited a
18
+ * policy without renaming it, and records naming it describe two gates.
19
+ * - `incomparable` — the fingerprints come from different versions of the policy
20
+ * schema. Something may have been edited too; this cannot say.
21
+ *
22
+ * `single` is a statement about the fingerprints present and nothing else. A
23
+ * segment that also holds unfingerprinted judgments is not thereby proven
24
+ * constant, which is why the count of those is reported alongside rather than
25
+ * folded in here.
26
+ */
27
+ export type RulesetContinuity = "unrecorded" | "single" | "changed" | "incomparable";
28
+ export declare const rulesetContinuityOf: (fingerprints: readonly string[]) => RulesetContinuity;
29
+ //# sourceMappingURL=policy-fingerprint.d.ts.map
@@ -0,0 +1,119 @@
1
+ const atom = (value) => ({ kind: "atom", value });
2
+ const set = (members) => ({ kind: "set", members });
3
+ const map = (entries) => ({
4
+ kind: "map",
5
+ entries,
6
+ });
7
+ const struct = (fields) => ({
8
+ kind: "struct",
9
+ fields,
10
+ });
11
+ /**
12
+ * What one vocabulary entry says, as a value a map can digest. The prop list is
13
+ * sorted and deduplicated for the reason a set is: which props turn a primitive
14
+ * into a target is a membership test, and neither their order nor a repeat
15
+ * reaches a decision.
16
+ */
17
+ const interactiveDigest = (when) => when === "always" ? "always" : `when:${Array.from(new Set(when.whenProps)).sort().join(",")}`;
18
+ const interactiveEntries = (types) => Object.fromEntries(Object.entries(types).map(([type, when]) => [type, when && interactiveDigest(when)]));
19
+ const project = (policy) => ({
20
+ protectedPrimitiveTypes: set(policy.protectedPrimitiveTypes),
21
+ outOfTreeEffectTypes: set(policy.outOfTreeEffectTypes),
22
+ protectedPropKeys: set(policy.protectedPropKeys),
23
+ interactiveTypes: map(interactiveEntries(policy.interactiveTypes)),
24
+ registeredPrimitiveTypes: set(policy.registeredPrimitiveTypes),
25
+ removalThresholds: struct({
26
+ medium: atom(policy.removalThresholds.medium),
27
+ high: atom(policy.removalThresholds.high),
28
+ }),
29
+ breadthThreshold: atom(policy.breadthThreshold),
30
+ shallowDepthThreshold: atom(policy.shallowDepthThreshold),
31
+ inverseRetentionBudget: atom(policy.inverseRetentionBudget),
32
+ minimumConfidence: atom(policy.minimumConfidence),
33
+ confidenceFloor: atom(policy.confidenceFloor),
34
+ autoApplyCeiling: map(policy.autoApplyCeiling),
35
+ refusalFloor: atom(policy.refusalFloor),
36
+ });
37
+ const byKey = ([left], [right]) => left < right ? -1 : left > right ? 1 : 0;
38
+ const sortedEntries = (record) => Object.entries(record).sort(byKey);
39
+ /** Every key path that is structure rather than data, in a stable order. */
40
+ const shapePathsOf = (field, path) => {
41
+ if (field.kind !== "struct")
42
+ return [path];
43
+ return sortedEntries(field.fields).flatMap(([key, nested]) => shapePathsOf(nested, `${path}.${key}`));
44
+ };
45
+ /**
46
+ * JSON encoding of every atom, so a value containing the separator cannot forge
47
+ * one. Sets are sorted and deduplicated, because a vocabulary list is a
48
+ * membership test and neither order nor repetition reaches a decision.
49
+ *
50
+ * The map's filter is narrowing rather than a branch: a `Partial` record yields
51
+ * `V | undefined` from `Object.entries`, and an entry with no value would have to
52
+ * be dropped anyway — an unset ceiling and an absent one are one policy to
53
+ * `ceilingFor`.
54
+ */
55
+ const encodeField = (field, path) => {
56
+ switch (field.kind) {
57
+ case "atom":
58
+ return [`${path}=${JSON.stringify(field.value)}`];
59
+ case "set":
60
+ return [`${path}=${JSON.stringify(Array.from(new Set(field.members)).sort())}`];
61
+ case "map": {
62
+ const entries = sortedEntries(field.entries).filter((entry) => entry[1] !== undefined);
63
+ return [`${path}=${JSON.stringify(entries)}`];
64
+ }
65
+ case "struct":
66
+ return sortedEntries(field.fields).flatMap(([key, nested]) => encodeField(nested, `${path}.${key}`));
67
+ }
68
+ };
69
+ const FNV_OFFSET_BASIS = 0xcbf29ce484222325n;
70
+ const FNV_PRIME = 0x100000001b3n;
71
+ const SIXTY_FOUR_BITS = 0xffffffffffffffffn;
72
+ /**
73
+ * FNV-1a, 64-bit, written out rather than imported.
74
+ *
75
+ * A cryptographic digest would need `crypto.subtle`, which is asynchronous, and
76
+ * the Gate is synchronous and pure by decision (0002, 0033) — stamping a
77
+ * fingerprint must not be the thing that makes a decision await something. There
78
+ * is no adversary here to resist, only accident, and accidental collision across
79
+ * the handful of policies a host runs is not a risk worth an async decision path.
80
+ */
81
+ const digest = (input) => {
82
+ let hash = FNV_OFFSET_BASIS;
83
+ for (const byte of new TextEncoder().encode(input)) {
84
+ hash = ((hash ^ BigInt(byte)) * FNV_PRIME) & SIXTY_FOUR_BITS;
85
+ }
86
+ return hash.toString(16).padStart(16, "0");
87
+ };
88
+ const SHAPE_LENGTH = 8;
89
+ const FINGERPRINT_SEPARATOR = ":";
90
+ export const policyFingerprintOf = (policy) => {
91
+ const fields = sortedEntries(project(policy));
92
+ const shape = fields.flatMap(([key, field]) => shapePathsOf(field, key));
93
+ const values = fields.flatMap(([key, field]) => encodeField(field, key));
94
+ return [
95
+ digest(shape.join("\n")).slice(0, SHAPE_LENGTH),
96
+ digest(values.join("\n")),
97
+ ].join(FINGERPRINT_SEPARATOR);
98
+ };
99
+ /**
100
+ * Which set of knobs a fingerprint describes. Total on purpose: a string that is
101
+ * not a fingerprint this version produced is treated as its own shape, so it
102
+ * compares as *incomparable* to everything. Failing toward "cannot tell" is the
103
+ * right direction — the alternative is a malformed record silently reading as
104
+ * agreement.
105
+ */
106
+ export const policyShapeOf = (fingerprint) => {
107
+ const separator = fingerprint.indexOf(FINGERPRINT_SEPARATOR);
108
+ return separator === -1 ? fingerprint : fingerprint.slice(0, separator);
109
+ };
110
+ export const rulesetContinuityOf = (fingerprints) => {
111
+ const distinct = new Set(fingerprints);
112
+ if (distinct.size === 0)
113
+ return "unrecorded";
114
+ if (distinct.size === 1)
115
+ return "single";
116
+ const shapes = new Set(Array.from(distinct, policyShapeOf));
117
+ return shapes.size === distinct.size ? "incomparable" : "changed";
118
+ };
119
+ //# sourceMappingURL=policy-fingerprint.js.map
@@ -0,0 +1,42 @@
1
+ import type { LoomTree } from "../tree/tree.js";
2
+ import type { EditIntent } from "./intent.js";
3
+ import type { GatePolicy } from "./policy.js";
4
+ /**
5
+ * Where the Gate's policy comes from.
6
+ *
7
+ * `GatePolicy` is the set of choices the Gate consults; this is the seam that
8
+ * decides *which* set a given change is judged by. Without it a runtime holds
9
+ * one policy for its lifetime, so a host serving two tenants, two surfaces, or
10
+ * two trust levels from one process has no supported way to judge them
11
+ * differently — it has to build a whole runtime per request and hope every
12
+ * construction site agrees.
13
+ *
14
+ * Two properties are deliberate, and both are about keeping the judgment
15
+ * honest rather than about convenience.
16
+ *
17
+ * **It cannot see the proposal.** The context is the tree and the ask, both of
18
+ * which exist before anything is interpreted. A source that could read the
19
+ * proposed change could choose a lenient policy in response to a change the
20
+ * strict one would have refused, and the refusal rate would look healthy while
21
+ * meaning nothing. Who is asking, and of what, decides the policy; what came
22
+ * back is then judged by it.
23
+ *
24
+ * **It is synchronous and pure.** Resolution sits inside the decision path, so
25
+ * an implementation that awaited a network call would make every change slower
26
+ * and every decision unreproducible — a replay could not fetch what the
27
+ * original run fetched. A host whose policy lives elsewhere loads it before
28
+ * entering the write path and closes over it here.
29
+ */
30
+ export type PolicyContext = {
31
+ readonly tree: LoomTree;
32
+ readonly intent: EditIntent;
33
+ };
34
+ export interface PolicySource {
35
+ readonly resolve: (context: PolicyContext) => GatePolicy;
36
+ }
37
+ /**
38
+ * One policy, for everything. The honest spelling of what a single-tenant host
39
+ * wants, and what the runtime used to assume everyone wanted.
40
+ */
41
+ export declare const fixedPolicy: (policy: GatePolicy) => PolicySource;
42
+ //# sourceMappingURL=policy-source.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * One policy, for everything. The honest spelling of what a single-tenant host
3
+ * wants, and what the runtime used to assume everyone wanted.
4
+ */
5
+ export const fixedPolicy = (policy) => ({
6
+ resolve: () => policy,
7
+ });
8
+ //# sourceMappingURL=policy-source.js.map
@@ -0,0 +1,156 @@
1
+ import { z } from "zod";
2
+ import { type IntentOrigin } from "./intent.js";
3
+ import { type StakeLevel } from "./stake-level.js";
4
+ /**
5
+ * Everything the Gate needs that is a choice rather than a fact.
6
+ *
7
+ * Two kinds of knob live here. The vocabulary knobs (which primitives and prop
8
+ * keys matter) are host-supplied, because Loom Core cannot know that
9
+ * `commerce.checkout` is more consequential than `layout.stack`. The structural
10
+ * knobs (how big a removal is "large", how close to the root counts as
11
+ * restructuring) are host-independent and ship with defaults.
12
+ */
13
+ export declare const gatePolicySchema: z.ZodObject<{
14
+ /**
15
+ * What a disposition says when asked which policy judged the change.
16
+ *
17
+ * Host-declared rather than runtime-minted, like `Provenance.interpreter`:
18
+ * the runtime cannot know what distinguishes a host's two policies, and a
19
+ * name the host chose is one it can find again in its own configuration.
20
+ *
21
+ * The contract that makes it worth recording: **a name identifies content**.
22
+ * A host that changes what a policy contains gives it a new name, because
23
+ * every disposition already written under the old one claims to have been
24
+ * judged by what that name meant then.
25
+ */
26
+ policyId: z.ZodDefault<z.ZodString>;
27
+ /** Touching one of these elevates the change. Host vocabulary. */
28
+ protectedPrimitiveTypes: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodBranded<z.ZodString, "PrimitiveType">, "many">>>;
29
+ /**
30
+ * Primitives whose configuration reaches outside the tree — a live payment
31
+ * flow, a sent notification. Reverting the tree does not revert the effect,
32
+ * so changes touching these are never treated as reversible.
33
+ */
34
+ outOfTreeEffectTypes: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodBranded<z.ZodString, "PrimitiveType">, "many">>>;
35
+ /** Prop keys that carry meaning rather than presentation. Host vocabulary. */
36
+ protectedPropKeys: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodString, "many">>>;
37
+ /**
38
+ * Primitives that render a target the reader aims at — an anchor, a button —
39
+ * and what makes them one. A change that leaves one of these inside another
40
+ * puts a control where the reader cannot reach it, so the page renders and
41
+ * something on it stops working.
42
+ *
43
+ * Host vocabulary like the lists above, but the host does not have to write
44
+ * it: `interactiveTypesFor(registry)` in the SDK reads what each primitive
45
+ * declared about itself, so the knowledge stays with the component rather
46
+ * than in a policy file that drifts from it. Empty by default, which is
47
+ * exactly today's behaviour — a deployment that declares nothing is judged on
48
+ * shape alone.
49
+ */
50
+ interactiveTypes: z.ZodDefault<z.ZodType<Readonly<Record<string, import("../interactivity.js").InteractiveWhen | undefined>>, z.ZodTypeDef, unknown>>;
51
+ /**
52
+ * Every primitive this deployment can draw. A change that would insert a node
53
+ * of any other type puts a hole on the page, so the Gate refuses it rather
54
+ * than letting the log keep a revision nothing can render (0173).
55
+ *
56
+ * Host vocabulary like the lists above, and like them the host does not have
57
+ * to write it: `registeredTypesFor(registry)` in the SDK reads it off the
58
+ * registry the renderer already resolves against, so the two cannot drift.
59
+ *
60
+ * **Empty means undeclared, not empty.** A host that leaves this out is not
61
+ * claiming a library of nothing; it is declining to say, and gets exactly
62
+ * today's behaviour — an unrenderable insert is appended and reported at
63
+ * render. The asymmetry with an allowlist is deliberate and is the only way a
64
+ * default can be both additive and safe.
65
+ */
66
+ registeredPrimitiveTypes: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodBranded<z.ZodString, "PrimitiveType">, "many">>>;
67
+ removalThresholds: z.ZodDefault<z.ZodObject<{
68
+ medium: z.ZodNumber;
69
+ high: z.ZodNumber;
70
+ }, "strip", z.ZodTypeAny, {
71
+ medium: number;
72
+ high: number;
73
+ }, {
74
+ medium: number;
75
+ high: number;
76
+ }>>;
77
+ /** Distinct nodes touched before a change counts as broad. */
78
+ breadthThreshold: z.ZodDefault<z.ZodNumber>;
79
+ /** Depth at or above which a structural change counts as restructuring. */
80
+ shallowDepthThreshold: z.ZodDefault<z.ZodNumber>;
81
+ /** Nodes an inverse delta may retain before undo stops being practical. */
82
+ inverseRetentionBudget: z.ZodDefault<z.ZodNumber>;
83
+ /** Below this, the change needs confirmation; below the floor, it is refused. */
84
+ minimumConfidence: z.ZodDefault<z.ZodNumber>;
85
+ confidenceFloor: z.ZodDefault<z.ZodNumber>;
86
+ /**
87
+ * The highest stakes each origin may apply without asking. An explicit human
88
+ * instruction earns more latitude than an adaptation nobody requested.
89
+ */
90
+ autoApplyCeiling: z.ZodDefault<z.ZodRecord<z.ZodEnum<["user-instruction", "system-signal", "scheduled-adaptation", "developer"]>, z.ZodEnum<["low", "medium", "high", "critical"]>>>;
91
+ /** At or above this, the change is refused outright rather than offered. */
92
+ refusalFloor: z.ZodDefault<z.ZodEnum<["low", "medium", "high", "critical"]>>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ policyId: string;
95
+ protectedPrimitiveTypes: readonly (string & z.BRAND<"PrimitiveType">)[];
96
+ outOfTreeEffectTypes: readonly (string & z.BRAND<"PrimitiveType">)[];
97
+ protectedPropKeys: readonly string[];
98
+ interactiveTypes: Readonly<Record<string, import("../interactivity.js").InteractiveWhen | undefined>>;
99
+ registeredPrimitiveTypes: readonly (string & z.BRAND<"PrimitiveType">)[];
100
+ removalThresholds: {
101
+ medium: number;
102
+ high: number;
103
+ };
104
+ breadthThreshold: number;
105
+ shallowDepthThreshold: number;
106
+ inverseRetentionBudget: number;
107
+ minimumConfidence: number;
108
+ confidenceFloor: number;
109
+ autoApplyCeiling: Partial<Record<"user-instruction" | "system-signal" | "scheduled-adaptation" | "developer", "low" | "medium" | "high" | "critical">>;
110
+ refusalFloor: "low" | "medium" | "high" | "critical";
111
+ }, {
112
+ policyId?: string | undefined;
113
+ protectedPrimitiveTypes?: readonly string[] | undefined;
114
+ outOfTreeEffectTypes?: readonly string[] | undefined;
115
+ protectedPropKeys?: readonly string[] | undefined;
116
+ interactiveTypes?: unknown;
117
+ registeredPrimitiveTypes?: readonly string[] | undefined;
118
+ removalThresholds?: {
119
+ medium: number;
120
+ high: number;
121
+ } | undefined;
122
+ breadthThreshold?: number | undefined;
123
+ shallowDepthThreshold?: number | undefined;
124
+ inverseRetentionBudget?: number | undefined;
125
+ minimumConfidence?: number | undefined;
126
+ confidenceFloor?: number | undefined;
127
+ autoApplyCeiling?: Partial<Record<"user-instruction" | "system-signal" | "scheduled-adaptation" | "developer", "low" | "medium" | "high" | "critical">> | undefined;
128
+ refusalFloor?: "low" | "medium" | "high" | "critical" | undefined;
129
+ }>;
130
+ /**
131
+ * The policy's fields, stated once.
132
+ *
133
+ * This was a hand-written mirror of the schema above until 12 September, and the
134
+ * line that looked like it held the two together — `defaultGatePolicy:
135
+ * GatePolicy = gatePolicySchema.parse({})` — only caught one direction. A field
136
+ * *removed* from the schema made the parsed value un-assignable and failed the
137
+ * build. A field *added* to the schema was an excess property on a returned
138
+ * value rather than on a fresh object literal, so it compiled, and
139
+ * `keyof GatePolicy` never heard about it. Every consumer keyed on the type —
140
+ * and two lanes now key documentation off it — silently omitted the new field.
141
+ *
142
+ * Deriving it makes the drift impossible rather than tested. The four
143
+ * host-vocabulary lists carry `.readonly()` in the schema so that the inferred
144
+ * type keeps the `readonly` arrays callers already pass, which is the one place
145
+ * `z.infer` and the old mirror disagreed.
146
+ */
147
+ export type GatePolicy = Readonly<z.infer<typeof gatePolicySchema>>;
148
+ /**
149
+ * The structural knobs are opinionated; the vocabulary lists are empty because
150
+ * only the host knows which of its primitives are consequential. With no
151
+ * vocabulary declared, stakes are driven entirely by shape — how much is
152
+ * removed, how broadly, how close to the root.
153
+ */
154
+ export declare const defaultGatePolicy: GatePolicy;
155
+ export declare const ceilingFor: (policy: GatePolicy, origin: IntentOrigin) => StakeLevel;
156
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1,107 @@
1
+ import { z } from "zod";
2
+ import { interactiveTypesSchema } from "../interactivity.js";
3
+ import { primitiveTypeSchema } from "../primitive-type.js";
4
+ import { intentOriginSchema } from "./intent.js";
5
+ import { stakeLevelSchema } from "./stake-level.js";
6
+ /**
7
+ * Everything the Gate needs that is a choice rather than a fact.
8
+ *
9
+ * Two kinds of knob live here. The vocabulary knobs (which primitives and prop
10
+ * keys matter) are host-supplied, because Loom Core cannot know that
11
+ * `commerce.checkout` is more consequential than `layout.stack`. The structural
12
+ * knobs (how big a removal is "large", how close to the root counts as
13
+ * restructuring) are host-independent and ship with defaults.
14
+ */
15
+ export const gatePolicySchema = z.object({
16
+ /**
17
+ * What a disposition says when asked which policy judged the change.
18
+ *
19
+ * Host-declared rather than runtime-minted, like `Provenance.interpreter`:
20
+ * the runtime cannot know what distinguishes a host's two policies, and a
21
+ * name the host chose is one it can find again in its own configuration.
22
+ *
23
+ * The contract that makes it worth recording: **a name identifies content**.
24
+ * A host that changes what a policy contains gives it a new name, because
25
+ * every disposition already written under the old one claims to have been
26
+ * judged by what that name meant then.
27
+ */
28
+ policyId: z.string().min(1).default("default"),
29
+ /** Touching one of these elevates the change. Host vocabulary. */
30
+ protectedPrimitiveTypes: z.array(primitiveTypeSchema).readonly().default([]),
31
+ /**
32
+ * Primitives whose configuration reaches outside the tree — a live payment
33
+ * flow, a sent notification. Reverting the tree does not revert the effect,
34
+ * so changes touching these are never treated as reversible.
35
+ */
36
+ outOfTreeEffectTypes: z.array(primitiveTypeSchema).readonly().default([]),
37
+ /** Prop keys that carry meaning rather than presentation. Host vocabulary. */
38
+ protectedPropKeys: z.array(z.string().min(1)).readonly().default([]),
39
+ /**
40
+ * Primitives that render a target the reader aims at — an anchor, a button —
41
+ * and what makes them one. A change that leaves one of these inside another
42
+ * puts a control where the reader cannot reach it, so the page renders and
43
+ * something on it stops working.
44
+ *
45
+ * Host vocabulary like the lists above, but the host does not have to write
46
+ * it: `interactiveTypesFor(registry)` in the SDK reads what each primitive
47
+ * declared about itself, so the knowledge stays with the component rather
48
+ * than in a policy file that drifts from it. Empty by default, which is
49
+ * exactly today's behaviour — a deployment that declares nothing is judged on
50
+ * shape alone.
51
+ */
52
+ interactiveTypes: interactiveTypesSchema.default({}),
53
+ /**
54
+ * Every primitive this deployment can draw. A change that would insert a node
55
+ * of any other type puts a hole on the page, so the Gate refuses it rather
56
+ * than letting the log keep a revision nothing can render (0173).
57
+ *
58
+ * Host vocabulary like the lists above, and like them the host does not have
59
+ * to write it: `registeredTypesFor(registry)` in the SDK reads it off the
60
+ * registry the renderer already resolves against, so the two cannot drift.
61
+ *
62
+ * **Empty means undeclared, not empty.** A host that leaves this out is not
63
+ * claiming a library of nothing; it is declining to say, and gets exactly
64
+ * today's behaviour — an unrenderable insert is appended and reported at
65
+ * render. The asymmetry with an allowlist is deliberate and is the only way a
66
+ * default can be both additive and safe.
67
+ */
68
+ registeredPrimitiveTypes: z.array(primitiveTypeSchema).readonly().default([]),
69
+ removalThresholds: z
70
+ .object({
71
+ medium: z.number().int().positive(),
72
+ high: z.number().int().positive(),
73
+ })
74
+ .default({ medium: 3, high: 12 }),
75
+ /** Distinct nodes touched before a change counts as broad. */
76
+ breadthThreshold: z.number().int().positive().default(8),
77
+ /** Depth at or above which a structural change counts as restructuring. */
78
+ shallowDepthThreshold: z.number().int().nonnegative().default(1),
79
+ /** Nodes an inverse delta may retain before undo stops being practical. */
80
+ inverseRetentionBudget: z.number().int().positive().default(200),
81
+ /** Below this, the change needs confirmation; below the floor, it is refused. */
82
+ minimumConfidence: z.number().min(0).max(1).default(0.7),
83
+ confidenceFloor: z.number().min(0).max(1).default(0.3),
84
+ /**
85
+ * The highest stakes each origin may apply without asking. An explicit human
86
+ * instruction earns more latitude than an adaptation nobody requested.
87
+ */
88
+ autoApplyCeiling: z
89
+ .record(intentOriginSchema, stakeLevelSchema)
90
+ .default({
91
+ "user-instruction": "medium",
92
+ "system-signal": "low",
93
+ "scheduled-adaptation": "low",
94
+ developer: "high",
95
+ }),
96
+ /** At or above this, the change is refused outright rather than offered. */
97
+ refusalFloor: stakeLevelSchema.default("critical"),
98
+ });
99
+ /**
100
+ * The structural knobs are opinionated; the vocabulary lists are empty because
101
+ * only the host knows which of its primitives are consequential. With no
102
+ * vocabulary declared, stakes are driven entirely by shape — how much is
103
+ * removed, how broadly, how close to the root.
104
+ */
105
+ export const defaultGatePolicy = gatePolicySchema.parse({});
106
+ export const ceilingFor = (policy, origin) => policy.autoApplyCeiling[origin] ?? "low";
107
+ //# sourceMappingURL=policy.js.map