@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,83 @@
1
+ import { childrenOf } from "./node.js";
2
+ /**
3
+ * Read-only traversal. Every function here takes a root and derives a view;
4
+ * nothing caches, because a cache would be a second source of truth about a
5
+ * structure that changes on every accepted delta.
6
+ */
7
+ export function* walkTree(root) {
8
+ yield root;
9
+ for (const child of childrenOf(root))
10
+ yield* walkTree(child);
11
+ }
12
+ export const collectNodeIds = (root) => Array.from(walkTree(root), (node) => node.id);
13
+ export const findNode = (root, nodeId) => {
14
+ for (const node of walkTree(root)) {
15
+ if (node.id === nodeId)
16
+ return node;
17
+ }
18
+ return null;
19
+ };
20
+ export const containsNode = (root, nodeId) => findNode(root, nodeId) !== null;
21
+ export const findParent = (root, nodeId) => {
22
+ for (const node of walkTree(root)) {
23
+ if (childrenOf(node).some((child) => child.id === nodeId))
24
+ return node;
25
+ }
26
+ return null;
27
+ };
28
+ /**
29
+ * The chain of nodes from the root down to and including `nodeId`, or null when
30
+ * the node is absent. Paths are derived on demand and never persisted — the id
31
+ * is the stable address, the path is the current position.
32
+ */
33
+ export const nodePath = (root, nodeId) => {
34
+ if (root.id === nodeId)
35
+ return [root];
36
+ for (const child of childrenOf(root)) {
37
+ const childPath = nodePath(child, nodeId);
38
+ if (childPath)
39
+ return [root, ...childPath];
40
+ }
41
+ return null;
42
+ };
43
+ /** The same chain as ids, for callers that only need the address. */
44
+ export const pathToNode = (root, nodeId) => nodePath(root, nodeId)?.map((node) => node.id) ?? null;
45
+ export const isDescendantOf = (root, ancestorId, nodeId) => {
46
+ const ancestor = findNode(root, ancestorId);
47
+ if (!ancestor)
48
+ return false;
49
+ return childrenOf(ancestor).some((child) => child.id === nodeId || isDescendantOf(child, child.id, nodeId));
50
+ };
51
+ /**
52
+ * What a node says: every text node under it, in tree order, concatenated.
53
+ *
54
+ * Adjacent text nodes join with nothing between them because that is how they
55
+ * render — two text children of one element are one run of text to a reader,
56
+ * and a separator here would put something on a reader's clipboard that is not
57
+ * on their screen.
58
+ *
59
+ * It reads the **tree**, never the rendered markup. A behaviour that acts on a
60
+ * node's text (`render/behaviour.ts`) is then right before the browser has laid
61
+ * anything out, and cannot pick up a label, a caption or a control that a
62
+ * primitive rendered beside the content rather than as it.
63
+ */
64
+ export const textOf = (root) => {
65
+ let text = "";
66
+ for (const node of walkTree(root)) {
67
+ if (node.kind === "text")
68
+ text += node.value;
69
+ }
70
+ return text;
71
+ };
72
+ /** Ids that appear more than once anywhere under `root`. */
73
+ export const duplicateNodeIds = (root) => {
74
+ const seen = new Set();
75
+ const duplicates = new Set();
76
+ for (const node of walkTree(root)) {
77
+ if (seen.has(node.id))
78
+ duplicates.add(node.id);
79
+ seen.add(node.id);
80
+ }
81
+ return Array.from(duplicates);
82
+ };
83
+ //# sourceMappingURL=navigation.js.map
@@ -0,0 +1,103 @@
1
+ import { z } from "zod";
2
+ import { type NodeId } from "../ids.js";
3
+ import { type JsonObject } from "../json.js";
4
+ import { type PrimitiveType, type SlotName } from "../primitive-type.js";
5
+ /**
6
+ * The component AST.
7
+ *
8
+ * Three node kinds, discriminated on `kind`:
9
+ *
10
+ * - `element` — an instance of a registered primitive. Carries props and an
11
+ * ordered child list. This is the only kind that composes.
12
+ * - `text` — a leaf string. Text is a node rather than a prop so that the
13
+ * runtime can address, move, and re-author a sentence the same way it
14
+ * addresses a card.
15
+ * - `slot` — a named region a host or parent primitive projects into. Its
16
+ * children are the fallback rendered when nothing is projected.
17
+ *
18
+ * Deliberately absent: a `fragment` kind (an element with no visual primitive
19
+ * is expressible as a registered `fragment` primitive, and a second way to
20
+ * express the same thing complicates every traversal) and conditional or
21
+ * looping nodes (adaptation happens by proposing a delta, not by embedding
22
+ * control flow the Gate cannot reason about).
23
+ */
24
+ export type ElementNode = {
25
+ readonly kind: "element";
26
+ readonly id: NodeId;
27
+ readonly type: PrimitiveType;
28
+ readonly props: JsonObject;
29
+ readonly children: readonly LoomNode[];
30
+ };
31
+ export type TextNode = {
32
+ readonly kind: "text";
33
+ readonly id: NodeId;
34
+ readonly value: string;
35
+ };
36
+ export type SlotNode = {
37
+ readonly kind: "slot";
38
+ readonly id: NodeId;
39
+ readonly name: SlotName;
40
+ readonly children: readonly LoomNode[];
41
+ };
42
+ export type LoomNode = ElementNode | TextNode | SlotNode;
43
+ export type NodeKind = LoomNode["kind"];
44
+ export declare const loomNodeSchema: z.ZodType<LoomNode, z.ZodTypeDef, unknown>;
45
+ export declare const elementNodeSchema: z.ZodObject<{
46
+ kind: z.ZodLiteral<"element">;
47
+ id: z.ZodBranded<z.ZodString, "NodeId">;
48
+ type: z.ZodBranded<z.ZodString, "PrimitiveType">;
49
+ props: z.ZodType<JsonObject, z.ZodTypeDef, JsonObject>;
50
+ children: z.ZodReadonly<z.ZodArray<z.ZodType<LoomNode, z.ZodTypeDef, unknown>, "many">>;
51
+ }, "strip", z.ZodTypeAny, {
52
+ type: string & z.BRAND<"PrimitiveType">;
53
+ kind: "element";
54
+ id: string & z.BRAND<"NodeId">;
55
+ props: JsonObject;
56
+ children: readonly LoomNode[];
57
+ }, {
58
+ type: string;
59
+ kind: "element";
60
+ id: string;
61
+ props: JsonObject;
62
+ children: readonly unknown[];
63
+ }>;
64
+ export declare const textNodeSchema: z.ZodObject<{
65
+ kind: z.ZodLiteral<"text">;
66
+ id: z.ZodBranded<z.ZodString, "NodeId">;
67
+ value: z.ZodString;
68
+ }, "strip", z.ZodTypeAny, {
69
+ value: string;
70
+ kind: "text";
71
+ id: string & z.BRAND<"NodeId">;
72
+ }, {
73
+ value: string;
74
+ kind: "text";
75
+ id: string;
76
+ }>;
77
+ export declare const slotNodeSchema: z.ZodObject<{
78
+ kind: z.ZodLiteral<"slot">;
79
+ id: z.ZodBranded<z.ZodString, "NodeId">;
80
+ name: z.ZodBranded<z.ZodString, "SlotName">;
81
+ children: z.ZodReadonly<z.ZodArray<z.ZodType<LoomNode, z.ZodTypeDef, unknown>, "many">>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ name: string & z.BRAND<"SlotName">;
84
+ kind: "slot";
85
+ id: string & z.BRAND<"NodeId">;
86
+ children: readonly LoomNode[];
87
+ }, {
88
+ name: string;
89
+ kind: "slot";
90
+ id: string;
91
+ children: readonly unknown[];
92
+ }>;
93
+ /** Text is a leaf; every other kind holds an ordered child list. */
94
+ export declare const isContainerNode: (node: LoomNode) => node is ElementNode | SlotNode;
95
+ export declare const childrenOf: (node: LoomNode) => readonly LoomNode[];
96
+ /**
97
+ * The node's own name, which is the only thing a reader recognises it by. Ids
98
+ * are minted and carry no meaning, so anything reported to a person names the
99
+ * node as well as addressing it.
100
+ */
101
+ export declare const nodeLabel: (node: LoomNode) => string;
102
+ export declare const withChildren: <TNode extends ElementNode | SlotNode>(node: TNode, children: readonly LoomNode[]) => TNode;
103
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { nodeIdSchema } from "../ids.js";
3
+ import { jsonObjectSchema } from "../json.js";
4
+ import { assertNever } from "../result.js";
5
+ import { primitiveTypeSchema, slotNameSchema } from "../primitive-type.js";
6
+ export const loomNodeSchema = z.lazy(() => z.discriminatedUnion("kind", [elementNodeSchema, textNodeSchema, slotNodeSchema]));
7
+ export const elementNodeSchema = z.object({
8
+ kind: z.literal("element"),
9
+ id: nodeIdSchema,
10
+ type: primitiveTypeSchema,
11
+ props: jsonObjectSchema,
12
+ children: z.array(loomNodeSchema).readonly(),
13
+ });
14
+ export const textNodeSchema = z.object({
15
+ kind: z.literal("text"),
16
+ id: nodeIdSchema,
17
+ value: z.string(),
18
+ });
19
+ export const slotNodeSchema = z.object({
20
+ kind: z.literal("slot"),
21
+ id: nodeIdSchema,
22
+ name: slotNameSchema,
23
+ children: z.array(loomNodeSchema).readonly(),
24
+ });
25
+ /** Text is a leaf; every other kind holds an ordered child list. */
26
+ export const isContainerNode = (node) => node.kind !== "text";
27
+ export const childrenOf = (node) => isContainerNode(node) ? node.children : [];
28
+ /**
29
+ * The node's own name, which is the only thing a reader recognises it by. Ids
30
+ * are minted and carry no meaning, so anything reported to a person names the
31
+ * node as well as addressing it.
32
+ */
33
+ export const nodeLabel = (node) => {
34
+ switch (node.kind) {
35
+ case "element":
36
+ return node.type;
37
+ case "slot":
38
+ return node.name;
39
+ case "text":
40
+ return "text";
41
+ default:
42
+ return assertNever(node, "nodeLabel");
43
+ }
44
+ };
45
+ export const withChildren = (node, children) => ({ ...node, children });
46
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,28 @@
1
+ import type { NodeId } from "../ids.js";
2
+ import { type LoomNode } from "./node.js";
3
+ /**
4
+ * The tree, flattened into the reading order a list renders in.
5
+ *
6
+ * `walkTree` already yields every node, but it drops the two facts a list needs
7
+ * and cannot recover afterwards: how deep a node sits, and where it sits among
8
+ * its siblings. Recomputing either from a bare node requires a second traversal
9
+ * per node, so the traversal that knows them carries them out.
10
+ *
11
+ * This is a view, not a structure. Nothing here is persisted and nothing caches:
12
+ * a delta changes the tree, and the next outline is derived from the new one.
13
+ * `index` is the position among the parent's children, which is the same number
14
+ * an `insert` or a `move` names — an outline row is therefore enough to address
15
+ * a position, not only a node.
16
+ */
17
+ export type OutlineEntry = {
18
+ readonly node: LoomNode;
19
+ /** 0 at the root. */
20
+ readonly depth: number;
21
+ /** null at the root. */
22
+ readonly parentId: NodeId | null;
23
+ /** Position among the parent's children; 0 at the root. */
24
+ readonly index: number;
25
+ };
26
+ /** Pre-order, so a row is always preceded by the row it is nested inside. */
27
+ export declare const outlineTree: (root: LoomNode) => readonly OutlineEntry[];
28
+ //# sourceMappingURL=outline.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { childrenOf } from "./node.js";
2
+ function* walkOutline(node, depth, parentId, index) {
3
+ yield { node, depth, parentId, index };
4
+ for (const [childIndex, child] of childrenOf(node).entries()) {
5
+ yield* walkOutline(child, depth + 1, node.id, childIndex);
6
+ }
7
+ }
8
+ /** Pre-order, so a row is always preceded by the row it is nested inside. */
9
+ export const outlineTree = (root) => Array.from(walkOutline(root, 0, null, 0));
10
+ //# sourceMappingURL=outline.js.map
@@ -0,0 +1,83 @@
1
+ import { z } from "zod";
2
+ import { type IdFactory, type TreeId } from "../ids.js";
3
+ import { type Result } from "../result.js";
4
+ import type { TreeError } from "./errors.js";
5
+ import { type ElementNode } from "./node.js";
6
+ /**
7
+ * The persisted document. A tree is a root element plus a revision counter —
8
+ * no timestamps, because minting one is a side effect and every function in
9
+ * this module is pure. Storage and telemetry stamp their own times.
10
+ *
11
+ * `revision` increments once per accepted delta. A delta names the revision it
12
+ * was authored against, which is how a stale AI proposal is detected instead of
13
+ * being applied to a tree that has moved on underneath it.
14
+ */
15
+ export declare const TREE_SCHEMA_VERSION = 1;
16
+ export declare const loomTreeSchema: z.ZodObject<{
17
+ treeId: z.ZodBranded<z.ZodString, "TreeId">;
18
+ schemaVersion: z.ZodLiteral<1>;
19
+ revision: z.ZodNumber;
20
+ root: z.ZodObject<{
21
+ kind: z.ZodLiteral<"element">;
22
+ id: z.ZodBranded<z.ZodString, "NodeId">;
23
+ type: z.ZodBranded<z.ZodString, "PrimitiveType">;
24
+ props: z.ZodType<import("../json.js").JsonObject, z.ZodTypeDef, import("../json.js").JsonObject>;
25
+ children: z.ZodReadonly<z.ZodArray<z.ZodType<import("./node.js").LoomNode, z.ZodTypeDef, unknown>, "many">>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ type: string & z.BRAND<"PrimitiveType">;
28
+ kind: "element";
29
+ id: string & z.BRAND<"NodeId">;
30
+ props: import("../json.js").JsonObject;
31
+ children: readonly import("./node.js").LoomNode[];
32
+ }, {
33
+ type: string;
34
+ kind: "element";
35
+ id: string;
36
+ props: import("../json.js").JsonObject;
37
+ children: readonly unknown[];
38
+ }>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ treeId: string & z.BRAND<"TreeId">;
41
+ schemaVersion: 1;
42
+ revision: number;
43
+ root: {
44
+ type: string & z.BRAND<"PrimitiveType">;
45
+ kind: "element";
46
+ id: string & z.BRAND<"NodeId">;
47
+ props: import("../json.js").JsonObject;
48
+ children: readonly import("./node.js").LoomNode[];
49
+ };
50
+ }, {
51
+ treeId: string;
52
+ schemaVersion: 1;
53
+ revision: number;
54
+ root: {
55
+ type: string;
56
+ kind: "element";
57
+ id: string;
58
+ props: import("../json.js").JsonObject;
59
+ children: readonly unknown[];
60
+ };
61
+ }>;
62
+ export type LoomTree = {
63
+ readonly treeId: TreeId;
64
+ readonly schemaVersion: typeof TREE_SCHEMA_VERSION;
65
+ readonly revision: number;
66
+ readonly root: ElementNode;
67
+ };
68
+ /**
69
+ * The root is an element rather than any node because a document always has a
70
+ * container: a bare text or slot root has no place to insert into, which would
71
+ * make the first `insert` of every tree a special case.
72
+ */
73
+ export declare const createTree: (root: ElementNode, idFactory: IdFactory) => LoomTree;
74
+ export declare const withRoot: (tree: LoomTree, root: ElementNode) => LoomTree;
75
+ /**
76
+ * Structural invariants Zod cannot express. Currently one: node ids are unique
77
+ * across the whole tree, since ids are the addressing scheme for every
78
+ * downstream operation.
79
+ */
80
+ export declare const validateTreeInvariants: (tree: LoomTree) => Result<LoomTree, TreeError>;
81
+ /** The boundary parse: unknown input in, a validated tree or a TreeError out. */
82
+ export declare const parseTree: (input: unknown) => Result<LoomTree, TreeError>;
83
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { z } from "zod";
2
+ import { treeIdSchema } from "../ids.js";
3
+ import { err, ok } from "../result.js";
4
+ import { duplicateNodeIds } from "./navigation.js";
5
+ import { elementNodeSchema } from "./node.js";
6
+ /**
7
+ * The persisted document. A tree is a root element plus a revision counter —
8
+ * no timestamps, because minting one is a side effect and every function in
9
+ * this module is pure. Storage and telemetry stamp their own times.
10
+ *
11
+ * `revision` increments once per accepted delta. A delta names the revision it
12
+ * was authored against, which is how a stale AI proposal is detected instead of
13
+ * being applied to a tree that has moved on underneath it.
14
+ */
15
+ export const TREE_SCHEMA_VERSION = 1;
16
+ export const loomTreeSchema = z.object({
17
+ treeId: treeIdSchema,
18
+ schemaVersion: z.literal(TREE_SCHEMA_VERSION),
19
+ revision: z.number().int().nonnegative(),
20
+ root: elementNodeSchema,
21
+ });
22
+ /**
23
+ * The root is an element rather than any node because a document always has a
24
+ * container: a bare text or slot root has no place to insert into, which would
25
+ * make the first `insert` of every tree a special case.
26
+ */
27
+ export const createTree = (root, idFactory) => ({
28
+ treeId: idFactory.treeId(),
29
+ schemaVersion: TREE_SCHEMA_VERSION,
30
+ revision: 0,
31
+ root,
32
+ });
33
+ export const withRoot = (tree, root) => ({
34
+ ...tree,
35
+ revision: tree.revision + 1,
36
+ root,
37
+ });
38
+ /**
39
+ * Structural invariants Zod cannot express. Currently one: node ids are unique
40
+ * across the whole tree, since ids are the addressing scheme for every
41
+ * downstream operation.
42
+ */
43
+ export const validateTreeInvariants = (tree) => {
44
+ const [duplicate] = duplicateNodeIds(tree.root);
45
+ if (duplicate)
46
+ return err({ code: "duplicate-node-id", nodeId: duplicate });
47
+ return ok(tree);
48
+ };
49
+ /** The boundary parse: unknown input in, a validated tree or a TreeError out. */
50
+ export const parseTree = (input) => {
51
+ const parsed = loomTreeSchema.safeParse(input);
52
+ if (!parsed.success) {
53
+ const [issue] = parsed.error.issues;
54
+ return err({
55
+ code: "schema-violation",
56
+ path: issue ? issue.path.join(".") : "",
57
+ detail: issue?.message ?? "unknown schema violation",
58
+ });
59
+ }
60
+ return validateTreeInvariants(parsed.data);
61
+ };
62
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1,124 @@
1
+ import type { ProposalId } from "../ids.js";
2
+ import { type Result } from "../result.js";
3
+ import type { Disposition } from "../runtime/disposition.js";
4
+ import type { EditIntent } from "../runtime/intent.js";
5
+ import { type InterpretationError } from "../runtime/interpreter.js";
6
+ import { type CompositionRuntime } from "../runtime/pipeline.js";
7
+ import type { ProposedChange } from "../runtime/proposal.js";
8
+ import { type StoreError } from "../store/errors.js";
9
+ import type { TreeStore } from "../store/store.js";
10
+ import type { TreeDelta } from "../tree/delta.js";
11
+ import { type TreeError } from "../tree/errors.js";
12
+ import type { LoomTree } from "../tree/tree.js";
13
+ import { type HeldProposal, type HoldError, type HoldStore } from "./held.js";
14
+ /**
15
+ * The one write path (0017).
16
+ *
17
+ * `composeChange` decides whether a change may happen; this decides that it
18
+ * happened. Everything that reaches `store.append` comes through here, so there
19
+ * is exactly one place where a delta becomes history, and it is the same place
20
+ * the Gate ran.
21
+ *
22
+ * The two are kept apart on purpose. The composition runtime is a pure-ish
23
+ * function of a tree it was handed; making it read and write a store would give
24
+ * §2 a persistence dependency it does not need and would make every pipeline
25
+ * test set up a store. This module owns the seam instead: read head, refuse a
26
+ * stale intent before spending a model call on it, compose, persist.
27
+ */
28
+ export type WritePath = {
29
+ readonly store: TreeStore;
30
+ readonly holds: HoldStore;
31
+ readonly runtime: CompositionRuntime;
32
+ };
33
+ /**
34
+ * Answering a held proposal names the proposal and whoever answered it.
35
+ *
36
+ * The two travel together rather than the actor being an optional trailing
37
+ * argument, because an answer with no one attached is a decision nobody made —
38
+ * and a parameter that is easy to leave off is one that will be (0027). A host
39
+ * with no identities to name omits it deliberately; it cannot omit it by
40
+ * forgetting there was a second argument.
41
+ */
42
+ export type ProposalAnswer = {
43
+ readonly proposalId: ProposalId;
44
+ readonly actor?: string;
45
+ };
46
+ export type WriteOutcome = {
47
+ readonly kind: "committed";
48
+ readonly tree: LoomTree;
49
+ readonly proposal: ProposedChange;
50
+ readonly disposition: Disposition;
51
+ readonly inverse: TreeDelta;
52
+ } | {
53
+ readonly kind: "held";
54
+ readonly held: HeldProposal;
55
+ } | {
56
+ readonly kind: "refused";
57
+ readonly proposal: ProposedChange;
58
+ readonly disposition: Disposition;
59
+ /**
60
+ * Why no smaller change was offered instead, when a repairer was asked for
61
+ * one and declined. Carried straight through from the composition outcome,
62
+ * where the three endings a refusal can have are set out.
63
+ */
64
+ readonly repairFailure?: InterpretationError;
65
+ } | {
66
+ readonly kind: "not-interpreted";
67
+ readonly error: InterpretationError;
68
+ } | {
69
+ readonly kind: "not-applicable";
70
+ readonly proposal: ProposedChange;
71
+ readonly error: TreeError;
72
+ }
73
+ /** Persistence refused, including the stale-intent case that never reached a model. */
74
+ | {
75
+ readonly kind: "not-written";
76
+ readonly error: StoreError;
77
+ }
78
+ /** The proposal being confirmed is not in custody — answered already, or never held. */
79
+ | {
80
+ readonly kind: "not-answerable";
81
+ readonly error: HoldError;
82
+ };
83
+ export type WriteOutcomeKind = WriteOutcome["kind"];
84
+ /**
85
+ * Every way a write can end, in the order the runtime reaches them.
86
+ *
87
+ * A `switch` over an outcome is exhaustive without this and always was. What
88
+ * needs a list is everything that walks the endings instead of reacting to one:
89
+ * a page that tells a host what it has to handle, a dashboard that wants a
90
+ * bucket per ending to exist before the first request arrives, a conformance
91
+ * check written against the write path. Each of those otherwise keeps its own
92
+ * copy, and a copy is a list that is silently wrong the day an eighth ending
93
+ * lands.
94
+ *
95
+ * The order is the order a request meets them rather than an order of severity:
96
+ * the two endings a healthy deployment produces, then the refusal, then the four
97
+ * ways a request fails to become a change at all.
98
+ */
99
+ export declare const WRITE_OUTCOME_KINDS: readonly WriteOutcomeKind[];
100
+ export declare const describeWriteOutcome: (outcome: WriteOutcome) => string;
101
+ export declare const commitIntent: (path: WritePath, intent: EditIntent) => Promise<WriteOutcome>;
102
+ /**
103
+ * Answers a held proposal with yes.
104
+ *
105
+ * A hold names a revision, so a hold whose tree has moved on can never apply
106
+ * again — it is not stale pending a retry, it is dead. Confirming one therefore
107
+ * releases it and reports the conflict, rather than leaving a proposal in the
108
+ * queue that will refuse every time it is answered.
109
+ *
110
+ * The Gate runs again on the way through (`confirmChange`), against the tree as
111
+ * it stands. A human saying yes is permission to proceed, not permission to skip
112
+ * the check.
113
+ */
114
+ export declare const confirmHeld: (path: WritePath, answer: ProposalAnswer) => Promise<WriteOutcome>;
115
+ /**
116
+ * Answers a held proposal with no.
117
+ *
118
+ * The most informative thing a reviewer does, from §6's point of view: the Gate
119
+ * was willing to offer this change and a human did not want it, which is the
120
+ * only signal that distinguishes a policy that is too permissive from one that
121
+ * is calibrated.
122
+ */
123
+ export declare const discardHeld: (path: WritePath, answer: ProposalAnswer) => Promise<Result<HeldProposal, HoldError>>;
124
+ //# sourceMappingURL=commit.d.ts.map