@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,70 @@
1
+ import { type ZodTypeAny } from "zod";
2
+ import type { BindingName } from "./data/source.js";
3
+ import type { PrimitiveType, SlotName } from "./primitive-type.js";
4
+ import type { BindingDeclaration } from "./render/reads.js";
5
+ /**
6
+ * What a deployment can build with, as data.
7
+ *
8
+ * A registry knows which primitives exist, what props each declares, and which
9
+ * slots each projects. Several things need that knowledge and none of them
10
+ * should reach into a registry's internals for it: the interpreter has to tell a
11
+ * model what it may create, a portal has to offer an insert menu, and telemetry
12
+ * has to record what was available when a proposal was made.
13
+ *
14
+ * So the catalogue is a projection — the same relationship the model-facing
15
+ * reply schema has to the AST (0004). It is deliberately shallower than the Zod
16
+ * schemas it comes from: prop names and whether each is required, not their
17
+ * types. A structural description of arbitrary Zod is a second schema language
18
+ * to maintain, and the model already sees concrete prop values in the tree
19
+ * outline, so the marginal value is small next to the cost of keeping it honest.
20
+ */
21
+ export type CataloguedProp = {
22
+ readonly name: string;
23
+ readonly required: boolean;
24
+ };
25
+ export type CataloguedPrimitive = {
26
+ readonly type: PrimitiveType;
27
+ /** One line, written by the primitive's author, about what it is for. */
28
+ readonly description: string;
29
+ /**
30
+ * Declared props, name-sorted. `undefined` when the declared schema is not an
31
+ * object schema and its keys therefore cannot be enumerated — unknown, which
32
+ * is not the same claim as "none".
33
+ */
34
+ readonly props: readonly CataloguedProp[] | undefined;
35
+ readonly slots: readonly SlotName[];
36
+ /**
37
+ * The binding names this primitive reads an answer under, in declaration
38
+ * order. `undefined` when its author has not said — which, like `props`, is
39
+ * not the same claim as "none" and is not rounded to one.
40
+ *
41
+ * An entry is a name, or the prop that gives one and the name it falls back
42
+ * to (0184). The second form is carried out rather than flattened to its
43
+ * default, because the two say different things to a model: one name it must
44
+ * write, against one name it may replace by setting a prop.
45
+ *
46
+ * It is the one field here that is about what the primitive *asks the
47
+ * deployment for* rather than about what a tree may write on it, and it is
48
+ * here because the name in a binding belongs to the primitive. A model is
49
+ * told which sources exist by the data catalogue; without this it was never
50
+ * told which names those answers may be filed under, so the only name it
51
+ * could write was one it had seen on the page already.
52
+ */
53
+ readonly reads: readonly BindingDeclaration<BindingName>[] | undefined;
54
+ };
55
+ export type PrimitiveCatalogue = readonly CataloguedPrimitive[];
56
+ export declare const catalogueFields: (schema: ZodTypeAny) => readonly CataloguedProp[] | undefined;
57
+ /**
58
+ * A prop whose accepted values can be listed rather than invented.
59
+ *
60
+ * The values are `string | boolean` and never a number, because those are the
61
+ * two shapes a schema closes over by construction: an enum names its members
62
+ * and a boolean has exactly two. `z.number()` has no enumerable set, and
63
+ * choosing one would make anything read off it a function of the guess.
64
+ */
65
+ export type ClosedChoice = {
66
+ readonly name: string;
67
+ readonly options: readonly (string | boolean)[];
68
+ };
69
+ export declare const closedChoices: (schema: ZodTypeAny) => readonly ClosedChoice[];
70
+ //# sourceMappingURL=catalogue.d.ts.map
@@ -0,0 +1,88 @@
1
+ import { ZodBoolean, ZodDefault, ZodEffects, ZodEnum, ZodNullable, ZodObject, ZodOptional, } from "zod";
2
+ /**
3
+ * Field names for the catalogue, when the declared schema is an object schema
4
+ * and its keys can therefore be enumerated. Anything else — a union of shapes, a
5
+ * refined record — answers `undefined` rather than an empty list, because "I
6
+ * cannot tell you" and "there are none" are different facts and a model reading
7
+ * the catalogue would act on them differently.
8
+ *
9
+ * It lives here rather than beside either of its two callers because both
10
+ * `definePrimitive` and `defineSource` project a Zod schema into this shape, and
11
+ * the second one arriving is what turned a private helper into the catalogue's
12
+ * own job. Only public Zod surface is used: `instanceof`, `.shape`,
13
+ * `.innerType()`, and `.isOptional()`.
14
+ */
15
+ /**
16
+ * The object schema inside whatever wraps it, or nothing when there is none.
17
+ *
18
+ * A cross-field rule — "alt text is required unless the image is decorative" —
19
+ * is a `.refine()`, and refining an object schema returns a `ZodEffects` around
20
+ * it rather than another `ZodObject`. Stopping at the wrapper would answer
21
+ * "I cannot enumerate these" for exactly the schemas that most need explaining
22
+ * to a model, so the wrapper is unwrapped and the constraint lives where it
23
+ * always did: in validation, not in the catalogue.
24
+ */
25
+ const objectSchemaWithin = (schema) => {
26
+ if (schema instanceof ZodObject)
27
+ return schema;
28
+ if (schema instanceof ZodEffects)
29
+ return objectSchemaWithin(schema.innerType());
30
+ return undefined;
31
+ };
32
+ export const catalogueFields = (schema) => {
33
+ const object = objectSchemaWithin(schema);
34
+ if (!object)
35
+ return undefined;
36
+ const shape = object.shape;
37
+ return Object.keys(shape)
38
+ .sort()
39
+ .flatMap((name) => {
40
+ const member = shape[name];
41
+ return member ? [{ name, required: !member.isOptional() }] : [];
42
+ });
43
+ };
44
+ /**
45
+ * The closed choices a declared schema names, by prop, name-sorted.
46
+ *
47
+ * This is not the catalogue and is deliberately not part of it — a model reads
48
+ * concrete prop values in the tree outline, which is the reason the catalogue
49
+ * stops at names. It lives here anyway because it reads the same object schema
50
+ * through the same public Zod surface, and the alternative is a second copy of
51
+ * `objectSchemaWithin` in another file.
52
+ *
53
+ * What wants it is the conformance probe (0075): a primitive whose children
54
+ * depend on a prop cannot be classified from one render, and these are the
55
+ * props whose values the probe can vary without making anything up.
56
+ */
57
+ const choicesWithin = (schema) => {
58
+ if (schema instanceof ZodEnum)
59
+ return schema.options;
60
+ if (schema instanceof ZodBoolean)
61
+ return [false, true];
62
+ /**
63
+ * Wrappers, not shapes. `.optional()` and `.default()` change whether a prop
64
+ * must be present, not which values it accepts, so a `type` that is an
65
+ * optional enum closes over exactly the enum's members.
66
+ */
67
+ if (schema instanceof ZodOptional)
68
+ return choicesWithin(schema.unwrap());
69
+ if (schema instanceof ZodNullable)
70
+ return choicesWithin(schema.unwrap());
71
+ if (schema instanceof ZodDefault)
72
+ return choicesWithin(schema.removeDefault());
73
+ return undefined;
74
+ };
75
+ export const closedChoices = (schema) => {
76
+ const object = objectSchemaWithin(schema);
77
+ if (!object)
78
+ return [];
79
+ const shape = object.shape;
80
+ return Object.keys(shape)
81
+ .sort()
82
+ .flatMap((name) => {
83
+ const member = shape[name];
84
+ const options = member ? choicesWithin(member) : undefined;
85
+ return options ? [{ name, options }] : [];
86
+ });
87
+ };
88
+ //# sourceMappingURL=catalogue.js.map
@@ -0,0 +1,17 @@
1
+ import { type Result } from "../result.js";
2
+ import type { CliCommand, CliError } from "./plan.js";
3
+ /**
4
+ * Argument parsing, by hand rather than by dependency.
5
+ *
6
+ * The surface is two commands and one option, and a parser for that is smaller
7
+ * than the code needed to configure a parser library. It is also pure, so the
8
+ * grammar is asserted directly rather than through a framework's behaviour.
9
+ *
10
+ * This is also where a primitive type is validated, because whether a type is
11
+ * well-formed is a property of the string and of nothing else. Checking it here
12
+ * means a typo is reported as a typo — a directory that cannot be read is a
13
+ * different failure, and a mistyped type should not have to wait on one.
14
+ */
15
+ export declare const DEFAULT_DIRECTORY = "loom";
16
+ export declare const parseArguments: (argv: readonly string[]) => Result<CliCommand, CliError>;
17
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1,83 @@
1
+ import { primitiveTypeSchema } from "../primitive-type.js";
2
+ import { err, ok } from "../result.js";
3
+ import { isFrameworkNamespaced } from "./namespace.js";
4
+ import { RESERVED_PRIMITIVE_TYPES } from "./templates.js";
5
+ /**
6
+ * Argument parsing, by hand rather than by dependency.
7
+ *
8
+ * The surface is two commands and one option, and a parser for that is smaller
9
+ * than the code needed to configure a parser library. It is also pure, so the
10
+ * grammar is asserted directly rather than through a framework's behaviour.
11
+ *
12
+ * This is also where a primitive type is validated, because whether a type is
13
+ * well-formed is a property of the string and of nothing else. Checking it here
14
+ * means a typo is reported as a typo — a directory that cannot be read is a
15
+ * different failure, and a mistyped type should not have to wait on one.
16
+ */
17
+ export const DEFAULT_DIRECTORY = "loom";
18
+ const DIRECTORY_FLAG = "--dir";
19
+ const parseOptions = (argv) => {
20
+ const positional = [];
21
+ let directory = DEFAULT_DIRECTORY;
22
+ for (let index = 0; index < argv.length; index += 1) {
23
+ const argument = argv[index];
24
+ if (argument === DIRECTORY_FLAG) {
25
+ const value = argv[index + 1];
26
+ if (value === undefined || value.startsWith("-")) {
27
+ return err({ code: "missing-argument", argument: DIRECTORY_FLAG });
28
+ }
29
+ directory = value;
30
+ index += 1;
31
+ continue;
32
+ }
33
+ if (argument.startsWith("-"))
34
+ return err({ code: "unknown-command", given: argument });
35
+ positional.push(argument);
36
+ }
37
+ return ok({ directory, positional });
38
+ };
39
+ export const parseArguments = (argv) => {
40
+ const [first] = argv;
41
+ if (first === undefined || first === "--help" || first === "-h" || first === "help") {
42
+ return ok({ kind: "help" });
43
+ }
44
+ const options = parseOptions(argv);
45
+ if (!options.ok)
46
+ return options;
47
+ const [command, ...rest] = options.value.positional;
48
+ if (command === "init") {
49
+ const [unexpected] = rest;
50
+ if (unexpected !== undefined)
51
+ return err({ code: "unexpected-argument", given: unexpected });
52
+ return ok({ kind: "init", directory: options.value.directory });
53
+ }
54
+ if (command === "add") {
55
+ const [subject, type, ...extra] = rest;
56
+ if (subject !== "primitive") {
57
+ return err({ code: "unknown-command", given: `add ${subject ?? ""}`.trim() });
58
+ }
59
+ if (type === undefined)
60
+ return err({ code: "missing-argument", argument: "<type>" });
61
+ const [unexpected] = extra;
62
+ if (unexpected !== undefined)
63
+ return err({ code: "unexpected-argument", given: unexpected });
64
+ if (!primitiveTypeSchema.safeParse(type).success) {
65
+ return err({ code: "invalid-primitive-type", type });
66
+ }
67
+ if (RESERVED_PRIMITIVE_TYPES.includes(type)) {
68
+ return err({ code: "reserved-primitive-type", type });
69
+ }
70
+ /**
71
+ * Refused here rather than at planning, because a name belonging to the
72
+ * framework is a property of the string — the same reason a malformed type
73
+ * is refused here. It costs a directory read the host was never going to
74
+ * benefit from.
75
+ */
76
+ if (isFrameworkNamespaced(type)) {
77
+ return err({ code: "framework-namespace", type });
78
+ }
79
+ return ok({ kind: "add-primitive", directory: options.value.directory, type });
80
+ }
81
+ return err({ code: "unknown-command", given: command ?? "" });
82
+ };
83
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1,15 @@
1
+ import { type Result } from "../result.js";
2
+ /**
3
+ * The CLI's only impure seam.
4
+ *
5
+ * Two operations, both fallible, both returning a Result — so `run.ts` stays a
6
+ * function of a listing and a plan, and its tests need no temporary directories.
7
+ * A missing directory lists as empty rather than failing: "nothing here yet" is
8
+ * the ordinary case for `init`, not an error.
9
+ */
10
+ export interface FileSystem {
11
+ readonly list: (directory: string) => Promise<Result<readonly string[], string>>;
12
+ readonly write: (path: string, contents: string) => Promise<Result<void, string>>;
13
+ }
14
+ export declare const nodeFileSystem: FileSystem;
15
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { mkdir, readdir, writeFile } from "node:fs/promises";
2
+ import { err, ok } from "../result.js";
3
+ const describe = (thrown) => (thrown instanceof Error ? thrown.message : String(thrown));
4
+ const isMissing = (thrown) => typeof thrown === "object" && thrown !== null && "code" in thrown && thrown.code === "ENOENT";
5
+ const directoryOf = (path) => path.slice(0, path.lastIndexOf("/"));
6
+ export const nodeFileSystem = {
7
+ list: async (directory) => {
8
+ try {
9
+ const entries = await readdir(directory, { withFileTypes: true, recursive: true });
10
+ return ok(entries
11
+ .filter((entry) => entry.isFile())
12
+ .map((entry) => `${entry.parentPath}/${entry.name}`.replaceAll("//", "/")));
13
+ }
14
+ catch (thrown) {
15
+ return isMissing(thrown) ? ok([]) : err(describe(thrown));
16
+ }
17
+ },
18
+ write: async (path, contents) => {
19
+ try {
20
+ const parent = directoryOf(path);
21
+ if (parent !== "")
22
+ await mkdir(parent, { recursive: true });
23
+ await writeFile(path, contents, "utf8");
24
+ return ok(undefined);
25
+ }
26
+ catch (thrown) {
27
+ return err(describe(thrown));
28
+ }
29
+ },
30
+ };
31
+ //# sourceMappingURL=filesystem.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The commands `loom` runs.
3
+ *
4
+ * Scaffolding a new project, and driving a proposal from the terminal against the
5
+ * same runtime a server would use.
6
+ */
7
+ export * from "./args.js";
8
+ export * from "./filesystem.js";
9
+ export * from "./plan.js";
10
+ export * from "./run.js";
11
+ export * from "./templates.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The commands `loom` runs.
3
+ *
4
+ * Scaffolding a new project, and driving a proposal from the terminal against the
5
+ * same runtime a server would use.
6
+ */
7
+ export * from "./args.js";
8
+ export * from "./filesystem.js";
9
+ export * from "./plan.js";
10
+ export * from "./run.js";
11
+ export * from "./templates.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { nodeFileSystem } from "./filesystem.js";
3
+ import { describeCliError, runCli } from "./run.js";
4
+ /**
5
+ * The executable entry point, and the only module here that touches the process.
6
+ *
7
+ * Everything it does is decide an exit code and choose a stream: usage and
8
+ * progress go to stdout, failures to stderr. Keeping that here is what lets the
9
+ * rest of the CLI be ordinary tested functions.
10
+ *
11
+ * The shebang runs it through `tsx`, because this package has no build step and
12
+ * Node's own type stripping does not resolve the `.js` import specifiers the
13
+ * repo uses to their `.ts` sources. That makes `tsx` a real dependency of the
14
+ * executable rather than a convenience — when a build step exists, `bin` should
15
+ * point at the emitted entry and this line should go.
16
+ */
17
+ const main = async () => {
18
+ const result = await runCli(process.argv.slice(2), nodeFileSystem);
19
+ if (!result.ok) {
20
+ process.stderr.write(`${describeCliError(result.error)}\n`);
21
+ return 1;
22
+ }
23
+ for (const path of result.value.written)
24
+ process.stdout.write(`wrote ${path}\n`);
25
+ for (const note of result.value.notes)
26
+ process.stdout.write(`${note}\n`);
27
+ return 0;
28
+ };
29
+ process.exitCode = await main();
30
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The one namespace the CLI will not write into, and the one it writes instead.
3
+ *
4
+ * `loom.` is the framework's. Every primitive `@jam-overture/loom/primitives`
5
+ * registers is named under it, and a registry refuses two definitions with one
6
+ * type — so a host primitive called `loom.page` is not a shadow or an override,
7
+ * it is a registry that cannot be built at all. The failure lands on whoever
8
+ * combines the two, which is the host, at the moment they follow the
9
+ * documentation as written.
10
+ *
11
+ * The scaffold used to write `loom.page`, so that host was every host.
12
+ *
13
+ * Refusing the whole namespace rather than the types the library happens to hold
14
+ * today is deliberate. A list of taken names would have to be maintained against
15
+ * a library that grows every week, and the run that added the seventy-sixth
16
+ * primitive would break a scaffold written months earlier. A namespace cannot go
17
+ * stale: a name under `loom.` is the framework's whether or not anything answers
18
+ * to it yet, and a name outside it is the host's forever. `starter-collision.test.ts`
19
+ * is what holds the two halves of that promise together.
20
+ */
21
+ /** Reserved in full: `loom` itself, and everything beneath it. */
22
+ export declare const FRAMEWORK_NAMESPACE = "loom";
23
+ /**
24
+ * What the CLI names things instead — `app.page`, `app.card`.
25
+ *
26
+ * It reads as *yours*, which is the lesson the scaffolded file exists to teach:
27
+ * the primitive in it is a component the host owns and edits, not a piece of the
28
+ * framework that happens to live in their repository.
29
+ */
30
+ export declare const HOST_NAMESPACE = "app";
31
+ export declare const isFrameworkNamespaced: (type: string) => boolean;
32
+ /**
33
+ * The same name under the host's namespace, offered in the refusal.
34
+ *
35
+ * `loom.card` → `app.card`, and a bare `loom` → `app`. Somebody who typed
36
+ * `loom.card` wanted a card; telling them the namespace is taken and leaving
37
+ * them to invent a replacement is a worse answer than handing them one.
38
+ */
39
+ export declare const hostAlternativeFor: (type: string) => string;
40
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The one namespace the CLI will not write into, and the one it writes instead.
3
+ *
4
+ * `loom.` is the framework's. Every primitive `@jam-overture/loom/primitives`
5
+ * registers is named under it, and a registry refuses two definitions with one
6
+ * type — so a host primitive called `loom.page` is not a shadow or an override,
7
+ * it is a registry that cannot be built at all. The failure lands on whoever
8
+ * combines the two, which is the host, at the moment they follow the
9
+ * documentation as written.
10
+ *
11
+ * The scaffold used to write `loom.page`, so that host was every host.
12
+ *
13
+ * Refusing the whole namespace rather than the types the library happens to hold
14
+ * today is deliberate. A list of taken names would have to be maintained against
15
+ * a library that grows every week, and the run that added the seventy-sixth
16
+ * primitive would break a scaffold written months earlier. A namespace cannot go
17
+ * stale: a name under `loom.` is the framework's whether or not anything answers
18
+ * to it yet, and a name outside it is the host's forever. `starter-collision.test.ts`
19
+ * is what holds the two halves of that promise together.
20
+ */
21
+ /** Reserved in full: `loom` itself, and everything beneath it. */
22
+ export const FRAMEWORK_NAMESPACE = "loom";
23
+ /**
24
+ * What the CLI names things instead — `app.page`, `app.card`.
25
+ *
26
+ * It reads as *yours*, which is the lesson the scaffolded file exists to teach:
27
+ * the primitive in it is a component the host owns and edits, not a piece of the
28
+ * framework that happens to live in their repository.
29
+ */
30
+ export const HOST_NAMESPACE = "app";
31
+ export const isFrameworkNamespaced = (type) => type === FRAMEWORK_NAMESPACE || type.startsWith(`${FRAMEWORK_NAMESPACE}.`);
32
+ /**
33
+ * The same name under the host's namespace, offered in the refusal.
34
+ *
35
+ * `loom.card` → `app.card`, and a bare `loom` → `app`. Somebody who typed
36
+ * `loom.card` wanted a card; telling them the namespace is taken and leaving
37
+ * them to invent a replacement is a worse answer than handing them one.
38
+ */
39
+ export const hostAlternativeFor = (type) => [HOST_NAMESPACE, ...type.split(".").slice(1)].join(".");
40
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1,84 @@
1
+ import { type Result } from "../result.js";
2
+ import { type PrimitiveNames } from "./templates.js";
3
+ /**
4
+ * What a command would write, decided before anything is written.
5
+ *
6
+ * Planning is a pure function of the command and the directory's current
7
+ * contents, which is what makes the CLI testable without a filesystem and what
8
+ * makes "refuse to overwrite" reliable: the decision is made once, against a
9
+ * listing, rather than per-file midway through writing.
10
+ */
11
+ export type CliCommand = {
12
+ readonly kind: "init";
13
+ readonly directory: string;
14
+ } | {
15
+ readonly kind: "add-primitive";
16
+ readonly directory: string;
17
+ readonly type: string;
18
+ } | {
19
+ readonly kind: "help";
20
+ };
21
+ export type CliError = {
22
+ readonly code: "unknown-command";
23
+ readonly given: string;
24
+ } | {
25
+ readonly code: "missing-argument";
26
+ readonly argument: string;
27
+ } | {
28
+ readonly code: "unexpected-argument";
29
+ readonly given: string;
30
+ } | {
31
+ readonly code: "invalid-primitive-type";
32
+ readonly type: string;
33
+ } | {
34
+ readonly code: "reserved-primitive-type";
35
+ readonly type: string;
36
+ } | {
37
+ readonly code: "framework-namespace";
38
+ readonly type: string;
39
+ } | {
40
+ readonly code: "already-registered";
41
+ readonly type: string;
42
+ } | {
43
+ readonly code: "file-exists";
44
+ readonly path: string;
45
+ } | {
46
+ readonly code: "filesystem-failed";
47
+ readonly path: string;
48
+ readonly detail: string;
49
+ };
50
+ export type CliErrorCode = CliError["code"];
51
+ /**
52
+ * Every way a command can refuse, in the order a user meets them.
53
+ *
54
+ * The fourth and last of the unions that could be reacted to and not walked.
55
+ * `scaffold.ts` on the documentation site already keys a table off
56
+ * `CliError["code"]`, so a tenth code takes that page red rather than letting it
57
+ * quietly describe nine of ten — which is the best a lane outside `src/` can do,
58
+ * and is not the same as the runtime publishing the list itself.
59
+ *
60
+ * The order follows a command's own path: what is wrong with the words typed,
61
+ * then what is wrong with the primitive type they name, then what is already on
62
+ * disk, then the filesystem failing underneath all of it.
63
+ */
64
+ export declare const CLI_ERROR_CODES: readonly CliErrorCode[];
65
+ export type PlannedFile = {
66
+ readonly path: string;
67
+ readonly contents: string;
68
+ };
69
+ export type WritePlan = {
70
+ readonly files: readonly PlannedFile[];
71
+ /** Lines for the caller to print — what happened, and what to do next. */
72
+ readonly notes: readonly string[];
73
+ };
74
+ export declare const PRIMITIVES_DIRECTORY = "primitives";
75
+ /**
76
+ * The primitive modules already in the directory, recovered from their names.
77
+ *
78
+ * Anything that is not a `.ts` file, and the two reserved modules, are skipped —
79
+ * as is a name that is not a valid primitive type, so a stray file cannot make
80
+ * the generated registry reference a module that will not compile.
81
+ */
82
+ export declare const existingPrimitives: (paths: readonly string[]) => readonly PrimitiveNames[];
83
+ export declare const planCommand: (command: CliCommand, existing: readonly string[]) => Result<WritePlan, CliError>;
84
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1,113 @@
1
+ import { everyMemberOf } from "../closed-set.js";
2
+ import { primitiveTypeSchema } from "../primitive-type.js";
3
+ import { err, ok } from "../result.js";
4
+ import { HOST_NAMESPACE } from "./namespace.js";
5
+ import { CONFORMANCE_TEST_MODULE, conformanceTest, namesFor, primitiveModule, REGISTRY_MODULE, registryModule, } from "./templates.js";
6
+ /**
7
+ * Every way a command can refuse, in the order a user meets them.
8
+ *
9
+ * The fourth and last of the unions that could be reacted to and not walked.
10
+ * `scaffold.ts` on the documentation site already keys a table off
11
+ * `CliError["code"]`, so a tenth code takes that page red rather than letting it
12
+ * quietly describe nine of ten — which is the best a lane outside `src/` can do,
13
+ * and is not the same as the runtime publishing the list itself.
14
+ *
15
+ * The order follows a command's own path: what is wrong with the words typed,
16
+ * then what is wrong with the primitive type they name, then what is already on
17
+ * disk, then the filesystem failing underneath all of it.
18
+ */
19
+ export const CLI_ERROR_CODES = everyMemberOf()([
20
+ "unknown-command",
21
+ "missing-argument",
22
+ "unexpected-argument",
23
+ "invalid-primitive-type",
24
+ "reserved-primitive-type",
25
+ "framework-namespace",
26
+ "already-registered",
27
+ "file-exists",
28
+ "filesystem-failed",
29
+ ]);
30
+ export const PRIMITIVES_DIRECTORY = "primitives";
31
+ const join = (...segments) => segments.join("/");
32
+ const basenameOf = (path) => path.slice(path.lastIndexOf("/") + 1);
33
+ /**
34
+ * The primitive modules already in the directory, recovered from their names.
35
+ *
36
+ * Anything that is not a `.ts` file, and the two reserved modules, are skipped —
37
+ * as is a name that is not a valid primitive type, so a stray file cannot make
38
+ * the generated registry reference a module that will not compile.
39
+ */
40
+ export const existingPrimitives = (paths) => paths.flatMap((path) => {
41
+ const basename = basenameOf(path);
42
+ if (!basename.endsWith(".ts"))
43
+ return [];
44
+ if (basename === REGISTRY_MODULE || basename === CONFORMANCE_TEST_MODULE)
45
+ return [];
46
+ const type = basename.slice(0, -".ts".length);
47
+ return primitiveTypeSchema.safeParse(type).success ? [namesFor(type)] : [];
48
+ });
49
+ /**
50
+ * The one primitive `init` writes, named in the host's namespace rather than the
51
+ * framework's.
52
+ *
53
+ * It was `loom.page` until 29 August, which is also the name of the starter
54
+ * primitive that mounts a theme — so a host who scaffolded a project and then
55
+ * built a registry the way *Rendering a tree* documents got
56
+ * `duplicate-primitive-type` and a name they had not chosen. See `namespace.ts`.
57
+ */
58
+ const STARTER_TYPE = `${HOST_NAMESPACE}.page`;
59
+ const planInit = (directory, existing) => {
60
+ const primitives = join(directory, PRIMITIVES_DIRECTORY);
61
+ const starter = namesFor(STARTER_TYPE);
62
+ const files = [
63
+ { path: join(primitives, starter.module), contents: primitiveModule(starter) },
64
+ { path: join(primitives, REGISTRY_MODULE), contents: registryModule([starter]) },
65
+ { path: join(primitives, CONFORMANCE_TEST_MODULE), contents: conformanceTest() },
66
+ ];
67
+ /**
68
+ * `init` refuses if any of its files exist, including the registry it would
69
+ * otherwise own — re-running it over a populated directory would silently
70
+ * discard every registration but the starter.
71
+ */
72
+ const clash = files.find((file) => existing.includes(file.path));
73
+ if (clash)
74
+ return err({ code: "file-exists", path: clash.path });
75
+ return ok({
76
+ files,
77
+ notes: [
78
+ `Scaffolded ${primitives} with one primitive, a generated registry, and a conformance test.`,
79
+ `Wire the registry into your renderer as both the resolver and the validator, then run the test.`,
80
+ ],
81
+ });
82
+ };
83
+ /** The type has already been validated by `args.ts`, which is the boundary for it. */
84
+ const planAddPrimitive = (directory, type, existing) => {
85
+ const names = namesFor(type);
86
+ const primitives = join(directory, PRIMITIVES_DIRECTORY);
87
+ const modulePath = join(primitives, names.module);
88
+ if (existing.includes(modulePath))
89
+ return err({ code: "already-registered", type });
90
+ const registered = [...existingPrimitives(existing), names];
91
+ return ok({
92
+ files: [
93
+ { path: modulePath, contents: primitiveModule(names) },
94
+ { path: join(primitives, REGISTRY_MODULE), contents: registryModule(registered) },
95
+ ],
96
+ notes: [
97
+ `Declared ${type} in ${modulePath}.`,
98
+ `Regenerated ${join(primitives, REGISTRY_MODULE)} with ${registered.length} primitive${registered.length === 1 ? "" : "s"}.`,
99
+ `Give it a description and a prop schema — the description is what a model reads when it chooses between primitives.`,
100
+ ],
101
+ });
102
+ };
103
+ export const planCommand = (command, existing) => {
104
+ switch (command.kind) {
105
+ case "init":
106
+ return planInit(command.directory, existing);
107
+ case "add-primitive":
108
+ return planAddPrimitive(command.directory, command.type, existing);
109
+ case "help":
110
+ return ok({ files: [], notes: [] });
111
+ }
112
+ };
113
+ //# sourceMappingURL=plan.js.map