@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,285 @@
1
+ import { DATA_PROP_KEY, SUBMIT_PROP_KEY, THEME_PROP_KEY } from "../reserved-props.js";
2
+ import { renderCatalogue, renderDelta, renderFrameCatalogue, renderSourceCatalogue, renderSubmissionCatalogue, renderThemeCatalogue, renderTree, } from "./render.js";
3
+ /**
4
+ * Prompt assembly, kept pure so the exact bytes sent to a model are a value a
5
+ * test can assert on rather than a side effect of calling one.
6
+ *
7
+ * The system prompt is deliberately a constant: it is the same for every intent
8
+ * and every tree, so it sits at the front of the request where a cache can hold
9
+ * it, and so that "what were we asking the model to do" is answerable by
10
+ * reading one string rather than reconstructing a template.
11
+ */
12
+ export const INTERPRETER_SYSTEM_PROMPT = `You translate a request about a user interface into discrete edits to a component tree.
13
+
14
+ The tree is given as an indented outline. Every line starts with a node id. There are three node kinds:
15
+ - element — an instance of a primitive, with props and ordered children
16
+ - text — a leaf string
17
+ - slot — a named region whose children are fallback content
18
+
19
+ You reply with one of three outcomes:
20
+ - "change" — the intent is satisfiable, and you give the operations that satisfy it
21
+ - "no-change" — you understood the intent and the tree already satisfies it
22
+ - "not-understood" — the intent is ambiguous, or asks for something the operations cannot express
23
+
24
+ There are exactly four operations:
25
+ - insert — a new node at a position under an existing parent
26
+ - remove — an existing node and its whole subtree
27
+ - move — an existing node to a new parent and position
28
+ - configure — set or unset props on an existing node
29
+
30
+ Rules you must follow:
31
+ - Address existing nodes only by ids copied exactly from the outline. Never invent an id.
32
+ - Never give an id to a node you are inserting. The runtime assigns it.
33
+ - Operations apply in order, and each one sees the effects of the ones before it.
34
+ - move is a detach followed by an insert, so its index counts positions in the child list the node has already left.
35
+ - props is the node's props as a JSON object, JSON-encoded into a string: "{\"tone\":\"quiet\",\"count\":2}". Use "{}" for no props. configure's set is written the same way. Values are ordinary JSON — strings, numbers, booleans, null, arrays, objects — with no tags or wrappers.
36
+ - You may insert element and text nodes. You cannot insert a slot: a slot is a region a primitive declares, not content an edit adds. Slots already in the tree can be configured, moved into, and inserted into like anything else.
37
+ - Propose the smallest set of operations that satisfies the intent. Do not tidy, restructure, or improve anything you were not asked about.
38
+ - Reuse primitive types already present in the tree unless the intent clearly calls for a new one.
39
+ - confidence is your own estimate that these operations satisfy the intent, from 0 to 1. Report it honestly; a low number is more useful than a wrong high one.
40
+
41
+ Sometimes you will be shown a proposal that was refused, and the reason. You get one revision, and the rules above still apply. A revision must be a more conservative way to satisfy the same request — smaller in what it destroys, or narrower in what it touches. It must not be the same change split into a smaller piece so that the remainder can be asked for again: if the request cannot be satisfied within the stated objection, say "not-understood" and explain what would have to change. Reproposing what was already refused, or working around the objection rather than respecting it, is the one thing a revision must never do.`;
42
+ /**
43
+ * The catalogue block, and why it leads the message rather than following the
44
+ * tree: it is the most stable thing here — a property of the deployment, not of
45
+ * the request — so it sits where a cache can hold it across intents.
46
+ *
47
+ * Absent when the host wired no catalogue, in which case the model is told
48
+ * nothing about what exists beyond what the tree already shows. That is the
49
+ * honest fallback: inventing a list would be worse than admitting there isn't
50
+ * one, and the closing instruction below only applies when a list was given.
51
+ */
52
+ const catalogueBlock = (catalogue) => catalogue === undefined || catalogue.length === 0
53
+ ? ""
54
+ : `Primitives this deployment has registered. A prop marked with "?" is optional; every other listed prop is required.
55
+
56
+ ${renderCatalogue(catalogue)}
57
+
58
+ Insert only primitives from that list — a type that is not on it has nothing to render it, so the node would be dropped. Set only props a primitive declares, and put children in the slots it names.
59
+
60
+ `;
61
+ /**
62
+ * The theme block, and the one instruction that makes it actionable.
63
+ *
64
+ * A model shown three lists of ids and nothing else would have no way to use
65
+ * them: the theme is not a primitive, not a slot, and not a prop any primitive
66
+ * declares — it is a reserved key on the root node, and every rule above tells
67
+ * the model to set only props a primitive declares. So the exception is stated
68
+ * where the vocabulary is given, or the vocabulary is decoration.
69
+ *
70
+ * All three ids are required together because the selection schema requires
71
+ * all three; a `configure` that set one would fail to resolve and the page
72
+ * would render unthemed, which is a worse answer than "I did not understand".
73
+ */
74
+ const themeBlock = (themes) => {
75
+ const rendered = themes === undefined ? "" : renderThemeCatalogue(themes);
76
+ if (rendered === "")
77
+ return "";
78
+ return `Themes this deployment has registered. A theme is three registered ids — one palette, one font pack, one style preset — carried on the root node under the reserved prop "${THEME_PROP_KEY}". It is the one prop that is not declared by a primitive.
79
+
80
+ ${rendered}
81
+
82
+ To re-theme the page, configure the root node and set "${THEME_PROP_KEY}" to an object with all three keys: {"${THEME_PROP_KEY}":{"palette":"…","fontPack":"…","stylePreset":"…"}}. Give all three every time, even when only one changes — a selection missing a key does not resolve and the page renders unthemed. Use only ids from the lists above. Colours, fonts and spacing come from the theme; never set a colour on a primitive.
83
+
84
+ `;
85
+ };
86
+ /**
87
+ * The data block: what this deployment can be asked about, and the one
88
+ * instruction that stops the answer being a guess.
89
+ *
90
+ * 0058 put the reason in the record — *"a source a model was never told about is
91
+ * one it can only guess at"* — and `dataCatalogue` has projected exactly that
92
+ * since, for a prompt that never carried it. A model asked to put somebody's
93
+ * services on a page had no way to know `catalogue.services` exists, so the only
94
+ * reachable answers were a binding it invented, refused at the seam as
95
+ * `no-such-source`, or no binding at all.
96
+ *
97
+ * The closing paragraph says three things because the seam refuses on three
98
+ * different grounds, and only one of them is visible in *this* list: an
99
+ * unregistered source is refused, a param the source did not declare is refused,
100
+ * and a binding *name* nothing reads is accepted and then read by nobody.
101
+ *
102
+ * The third used to end in a flat instruction not to invent one, because a name
103
+ * belongs to the primitive rather than to the source and nothing could enumerate
104
+ * it. A primitive can now say which names it reads (0181), so the sentence names
105
+ * where to look instead — and has to teach the three-way reading of that clause,
106
+ * because a primitive whose author has not declared is silent rather than
107
+ * claiming to read nothing.
108
+ */
109
+ const dataBlock = (sources) => sources === undefined || sources.length === 0
110
+ ? ""
111
+ : `Data this deployment can answer questions about. A node asks under the reserved prop "${DATA_PROP_KEY}", which maps a binding name to a registered source and the params to ask it with. A param marked with "?" is optional; every other listed param is required.
112
+
113
+ ${renderSourceCatalogue(sources)}
114
+
115
+ A binding is written {"${DATA_PROP_KEY}":{"<binding name>":{"source":"<id>","params":{…}}}}, and "params" may be left out when the source declares none. Use only source ids from the list above — one that is not on it is refused and the node renders without data. The binding *name* is how the primitive reading the answer finds it, so it is not yours to choose: bind only under a name the node's own primitive lists as "reads" in the primitive catalogue. A name it does not read is answered and then read by nobody, and nothing on the page changes. "reads: none" means the primitive reads no data at all; a primitive whose line says nothing about reading has not declared either way, so on one of those repoint or re-param a name already on the node rather than adding one of your own. Where a line reads \`the name in "x" (default y)\`, the primitive looks under whatever its "x" prop says and under "y" when that prop is absent — so bind under "y" and leave the prop off, or set the prop and bind under the same name.
116
+
117
+ `;
118
+ /**
119
+ * The submission block: where a form may post, and nowhere else.
120
+ *
121
+ * Thinner than the data block because the seam is thinner (0065). A binding carries
122
+ * params because a read genuinely varies; a write does not, so the whole of what
123
+ * a model may say here is one registered id. The closing paragraph spends its
124
+ * length on the two things the declaration schema is strict about — the single
125
+ * `to` key, and the address that is not in the tree — because a model that
126
+ * writes `{"to":…,"action":…}` is refused outright rather than having the extra
127
+ * key stripped.
128
+ */
129
+ const submissionBlock = (endpoints) => endpoints === undefined || endpoints.length === 0
130
+ ? ""
131
+ : `Where this deployment will accept a form submission. A node says where it posts under the reserved prop "${SUBMIT_PROP_KEY}".
132
+
133
+ ${renderSubmissionCatalogue(endpoints)}
134
+
135
+ To point a form at one, configure the node and set "${SUBMIT_PROP_KEY}" to {"to":"<id>"}. Use only ids from the list above. "to" is the only key the declaration accepts, and an address never appears in the tree — the deployment resolves the id to one after the choice is made.
136
+
137
+ `;
138
+ /**
139
+ * The framing block, and the sentence that keeps it from being read as the other
140
+ * two.
141
+ *
142
+ * `frameCatalogue`'s own comment makes the distinction and it has to survive into
143
+ * the prompt: an endpoint catalogue is the whole of what a model may name,
144
+ * because an address never appears in a tree, and this one is not, because a
145
+ * frame's URL does. Which video belongs on the page is a content decision the
146
+ * model is supposed to make. What it cannot do is pick a host, and a model shown
147
+ * a list with no word about which kind of list it is would reasonably read these
148
+ * as the only values it may write.
149
+ */
150
+ const framingBlock = (origins) => origins === undefined || origins.length === 0
151
+ ? ""
152
+ : `Whose documents this deployment will put inside a frame.
153
+
154
+ ${renderFrameCatalogue(origins)}
155
+
156
+ Those are origins rather than addresses. The URL of a framed document is an ordinary prop and it is yours to choose, but its scheme, host and port must match one of the lines above, or the primitive renders a refusal where the document would have been.
157
+
158
+ `;
159
+ const NO_VOCABULARIES = Object.freeze({});
160
+ const userMessageParts = (intent, tree, vocabularies) => {
161
+ const scopeLine = intent.scopeNodeId
162
+ ? `\nConfine the change to the subtree rooted at ${intent.scopeNodeId}, marked "<- scope" above.`
163
+ : "";
164
+ return {
165
+ primitives: catalogueBlock(vocabularies.catalogue),
166
+ themes: themeBlock(vocabularies.themeCatalogue),
167
+ sources: dataBlock(vocabularies.dataCatalogue),
168
+ endpoints: submissionBlock(vocabularies.submissionCatalogue),
169
+ frames: framingBlock(vocabularies.frameCatalogue),
170
+ tree: `Current tree:\n\n${renderTree(tree, intent.scopeNodeId)}\n\n`,
171
+ request: `Request (${intent.origin}): ${intent.utterance}${scopeLine}`,
172
+ };
173
+ };
174
+ /**
175
+ * The five vocabulary blocks lead, then the tree, then the sentence somebody
176
+ * typed.
177
+ *
178
+ * The order is by how often a part changes, least often first, so that the
179
+ * longest stable prefix sits where a provider's cache can hold it: a deployment
180
+ * registers once and asks many times, the tree changes with every accepted
181
+ * change, and the request is different every time by definition.
182
+ */
183
+ export const buildUserMessage = (intent, tree, vocabularies = NO_VOCABULARIES) => {
184
+ const parts = userMessageParts(intent, tree, vocabularies);
185
+ return `${parts.primitives}${parts.themes}${parts.sources}${parts.endpoints}${parts.frames}${parts.tree}${parts.request}`;
186
+ };
187
+ /**
188
+ * Measures a request without sending it.
189
+ *
190
+ * A host deciding what to register is the intended caller: `createThemeRegistry`
191
+ * and the primitive registry both take exactly what a deployment wants, and this
192
+ * is how the cost of taking all of it becomes a number rather than a feeling
193
+ * (0077's cost, made countable).
194
+ */
195
+ export const measurePrompt = (intent, tree, vocabularies = NO_VOCABULARIES) => {
196
+ const parts = userMessageParts(intent, tree, vocabularies);
197
+ const measured = {
198
+ system: INTERPRETER_SYSTEM_PROMPT.length,
199
+ primitives: parts.primitives.length,
200
+ themes: parts.themes.length,
201
+ sources: parts.sources.length,
202
+ endpoints: parts.endpoints.length,
203
+ frames: parts.frames.length,
204
+ tree: parts.tree.length,
205
+ request: parts.request.length,
206
+ };
207
+ return {
208
+ ...measured,
209
+ total: Object.values(measured).reduce((sum, part) => sum + part, 0),
210
+ };
211
+ };
212
+ /**
213
+ * Measures a vocabulary without sending it.
214
+ *
215
+ * The intended caller is a host deciding what to register, holding the answer
216
+ * against what it is prepared to spend — which is a judgment about the model it
217
+ * sends to and the latency it will accept, and therefore a deployment's to make
218
+ * rather than this package's to enforce.
219
+ *
220
+ * An empty catalogue costs nothing, because a request that has no vocabulary to
221
+ * offer omits the block entirely rather than sending an empty heading.
222
+ */
223
+ export const measureCatalogue = (catalogue) => {
224
+ const byType = catalogue.map((primitive) => ({
225
+ type: primitive.type,
226
+ characters: renderCatalogue([primitive]).length + 1,
227
+ }));
228
+ const listed = byType.reduce((sum, entry) => sum + entry.characters, 0);
229
+ return {
230
+ entries: catalogue.length,
231
+ characters: catalogueBlock(catalogue).length,
232
+ perEntry: catalogue.length === 0 ? 0 : Math.round(listed / catalogue.length),
233
+ byType,
234
+ };
235
+ };
236
+ const repairMessageParts = (request, tree, vocabularies) => ({
237
+ proposal: buildUserMessage(request.intent, tree, vocabularies),
238
+ refused: `
239
+
240
+ You proposed this, and it was refused:
241
+
242
+ ${renderDelta(request.refused.delta)}
243
+
244
+ Your reasoning was: ${request.refused.rationale}`,
245
+ objection: `
246
+
247
+ It was refused because — ${request.disposition.reason.code}: ${request.disposition.reason.detail}`,
248
+ instruction: `
249
+
250
+ Propose a more conservative way to satisfy the same request, or say "not-understood" if there is none.`,
251
+ });
252
+ export const buildRepairMessage = (request, tree, vocabularies = NO_VOCABULARIES) => {
253
+ const parts = repairMessageParts(request, tree, vocabularies);
254
+ return `${parts.proposal}${parts.refused}${parts.objection}${parts.instruction}`;
255
+ };
256
+ /**
257
+ * Measures a repair without sending it, on the same terms as `measurePrompt`.
258
+ *
259
+ * The intended caller is a host or a report deciding whether a refusal is worth
260
+ * offering a second go on: a repair is never cheaper than the request it
261
+ * revises, and how much dearer is a property of the page rather than a constant
262
+ * (0108).
263
+ */
264
+ export const measureRepairPrompt = (request, tree, vocabularies = NO_VOCABULARIES) => {
265
+ const parts = repairMessageParts(request, tree, vocabularies);
266
+ const proposal = measurePrompt(request.intent, tree, vocabularies);
267
+ const measured = {
268
+ refused: parts.refused.length,
269
+ objection: parts.objection.length,
270
+ instruction: parts.instruction.length,
271
+ };
272
+ const total = proposal.total + Object.values(measured).reduce((sum, part) => sum + part, 0);
273
+ return { proposal, ...measured, total, episode: proposal.total + total };
274
+ };
275
+ const HEX = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0"));
276
+ /**
277
+ * Provenance records a hash rather than the prompt, so an audit trail can prove
278
+ * two proposals came from the same question without storing what was asked.
279
+ */
280
+ export const hashPrompt = async (system, userMessage) => {
281
+ const encoded = new TextEncoder().encode(`${system}\n\n${userMessage}`);
282
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", encoded);
283
+ return Array.from(new Uint8Array(digest), (byte) => HEX[byte] ?? "00").join("");
284
+ };
285
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1,76 @@
1
+ import type { PrimitiveCatalogue } from "../catalogue.js";
2
+ import type { DataCatalogue } from "../data/catalogue.js";
3
+ import type { FrameCatalogue } from "../frame/catalogue.js";
4
+ import type { SubmissionCatalogue } from "../submit/catalogue.js";
5
+ import type { ThemeCatalogue } from "../theme/registry.js";
6
+ import type { NodeId } from "../ids.js";
7
+ import type { TreeDelta } from "../tree/delta.js";
8
+ import type { LoomTree } from "../tree/tree.js";
9
+ /**
10
+ * A scoped request sends the scope, not the page it sits on.
11
+ *
12
+ * Without a scope the whole tree is rendered, which is the only honest answer to
13
+ * "change this page". With one, the intent has already said the change is
14
+ * confined to a subtree, and sending the rest costs a request that grows with a
15
+ * page the model has been told not to touch — the outline is linear in the node
16
+ * count and it is re-sent on every proposal and again on every repair
17
+ * ([0083](../../decisions/0083-a-scoped-request-sends-the-scope.md)).
18
+ *
19
+ * A scope naming a node this tree does not contain renders the whole tree, which
20
+ * is the same thing that happened before there was anything to elide. It is a
21
+ * caller error rather than a shape the renderer can resolve, and a total
22
+ * projection does not get to throw (0008).
23
+ */
24
+ export declare const renderTree: (tree: LoomTree, scopeNodeId?: NodeId) => string;
25
+ /**
26
+ * The catalogue as the model sees it: one line per primitive, in registration
27
+ * order, so the deployment's own ordering is what the model reads first.
28
+ *
29
+ * A trailing `?` marks an optional prop, mirroring how the same fact is written
30
+ * in TypeScript, which is a notation a model has seen far more of than any
31
+ * convention invented here.
32
+ */
33
+ export declare const renderCatalogue: (catalogue: PrimitiveCatalogue) => string;
34
+ /**
35
+ * The theme vocabulary as the model sees it — three lists of ids with the
36
+ * sentence their author wrote about each.
37
+ *
38
+ * Without it, "make it warmer" resolves against a vocabulary the model was
39
+ * never shown: the tree carries `palette: "editorial"` and nothing says which
40
+ * other palettes exist, so the only reachable answers are the one already
41
+ * mounted and an invented id that fails to resolve. The hex is deliberately not
42
+ * here. A model choosing between registered palettes by description is the
43
+ * bargain 0049 struck; a model choosing colours is the thing it rules out.
44
+ */
45
+ export declare const renderThemeCatalogue: (catalogue: ThemeCatalogue) => string;
46
+ /**
47
+ * The sources as the model sees it — one line per registered source, with the
48
+ * params it declares written the way a primitive's props are.
49
+ *
50
+ * Registration order, like the primitive catalogue and for the same reason: the
51
+ * deployment's own ordering is what the model reads first, and sorting here
52
+ * would silently overrule a host that put its most-used source at the top.
53
+ */
54
+ export declare const renderSourceCatalogue: (catalogue: DataCatalogue) => string;
55
+ /**
56
+ * The endpoints as the model sees it — an id and a line, and deliberately
57
+ * nothing else.
58
+ *
59
+ * `submissionCatalogue` is thin because there is nothing else a model may
60
+ * supply (0065): where a form posts to, whether it posts or gets, and what it
61
+ * carries are resolved after the choice is made. Rendering anything more here
62
+ * would be putting an address in front of a model that must never name one.
63
+ */
64
+ export declare const renderSubmissionCatalogue: (catalogue: SubmissionCatalogue) => string;
65
+ /**
66
+ * The framable origins as the model sees it — scheme, host and port, and the
67
+ * sentence whoever runs the deployment wrote about each.
68
+ *
69
+ * Unlike the two above, this list is not the set of values a model may write.
70
+ * A frame's URL is a content decision and stays in the tree (0095); what the
71
+ * list constrains is the origin that URL must be on. So the line is an origin
72
+ * rather than an address, and the block below says which of the two it is.
73
+ */
74
+ export declare const renderFrameCatalogue: (catalogue: FrameCatalogue) => string;
75
+ export declare const renderDelta: (delta: TreeDelta) => string;
76
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1,272 @@
1
+ import { assertNever } from "../result.js";
2
+ /**
3
+ * The tree as the model sees it.
4
+ *
5
+ * An indented outline rather than the JSON document, for two reasons: it costs
6
+ * a fraction of the tokens, and it puts each node's id at the start of its own
7
+ * line, which is what the model has to copy to address anything. Rendering is
8
+ * pure and deterministic — props are key-sorted — so the same tree always
9
+ * produces the same prompt, which keeps prompt hashes comparable and leaves the
10
+ * door open to prompt caching.
11
+ */
12
+ const INDENT = " ";
13
+ const renderPropValue = (value) => JSON.stringify(value);
14
+ const renderProps = (props) => {
15
+ const keys = Object.keys(props).sort();
16
+ if (keys.length === 0)
17
+ return "";
18
+ const rendered = keys.map((key) => `${key}=${renderPropValue(props[key])}`);
19
+ return ` ${rendered.join(" ")}`;
20
+ };
21
+ const renderHeading = (node) => {
22
+ switch (node.kind) {
23
+ case "element":
24
+ return `${node.id} element ${node.type}${renderProps(node.props)}`;
25
+ case "text":
26
+ return `${node.id} text ${JSON.stringify(node.value)}`;
27
+ case "slot":
28
+ return `${node.id} slot ${node.name}`;
29
+ default:
30
+ return assertNever(node, "renderHeading");
31
+ }
32
+ };
33
+ const renderNode = (node, depth, scopeNodeId) => {
34
+ const marker = node.id === scopeNodeId ? " <- scope" : "";
35
+ const line = `${INDENT.repeat(depth)}${renderHeading(node)}${marker}`;
36
+ const children = node.kind === "text" ? [] : node.children;
37
+ return [line, ...children.flatMap((child) => renderNode(child, depth + 1, scopeNodeId))];
38
+ };
39
+ const childrenOf = (node) => (node.kind === "text" ? [] : node.children);
40
+ /**
41
+ * The nodes from the root down to `nodeId` inclusive, or `undefined` when the
42
+ * id is not in this tree.
43
+ *
44
+ * Depth-first and stopping at the first match, which is exact rather than merely
45
+ * adequate: an id appears at most once in a tree, and a delta that would
46
+ * duplicate one is refused before it can be applied (0038).
47
+ */
48
+ const chainTo = (node, nodeId) => {
49
+ if (node.id === nodeId)
50
+ return [node];
51
+ for (const child of childrenOf(node)) {
52
+ const below = chainTo(child, nodeId);
53
+ if (below !== undefined)
54
+ return [node, ...below];
55
+ }
56
+ return undefined;
57
+ };
58
+ const omitted = (count, where) => `… ${count} ${where} ${count === 1 ? "child" : "children"} omitted`;
59
+ /**
60
+ * The spine down to the scope, and the scope's subtree in full.
61
+ *
62
+ * Each ancestor contributes its own heading and nothing else — its other
63
+ * children collapse to a count, above and below, so that the elision is visible
64
+ * rather than silent. Two separate counts rather than one because the preceding
65
+ * count *is* the scope node's index among its siblings, which is what an insert
66
+ * beside it would have to name; a single total would take that away.
67
+ */
68
+ const renderChain = (chain, depth) => {
69
+ const [node, ...rest] = chain;
70
+ if (node === undefined)
71
+ return [];
72
+ const next = rest[0];
73
+ if (next === undefined)
74
+ return renderNode(node, depth, node.id);
75
+ const children = childrenOf(node);
76
+ const index = children.findIndex((child) => child.id === next.id);
77
+ const following = children.length - index - 1;
78
+ const childIndent = INDENT.repeat(depth + 1);
79
+ return [
80
+ `${INDENT.repeat(depth)}${renderHeading(node)}`,
81
+ ...(index > 0 ? [`${childIndent}${omitted(index, "preceding")}`] : []),
82
+ ...renderChain(rest, depth + 1),
83
+ ...(following > 0 ? [`${childIndent}${omitted(following, "following")}`] : []),
84
+ ];
85
+ };
86
+ /**
87
+ * A scoped request sends the scope, not the page it sits on.
88
+ *
89
+ * Without a scope the whole tree is rendered, which is the only honest answer to
90
+ * "change this page". With one, the intent has already said the change is
91
+ * confined to a subtree, and sending the rest costs a request that grows with a
92
+ * page the model has been told not to touch — the outline is linear in the node
93
+ * count and it is re-sent on every proposal and again on every repair
94
+ * ([0083](../../decisions/0083-a-scoped-request-sends-the-scope.md)).
95
+ *
96
+ * A scope naming a node this tree does not contain renders the whole tree, which
97
+ * is the same thing that happened before there was anything to elide. It is a
98
+ * caller error rather than a shape the renderer can resolve, and a total
99
+ * projection does not get to throw (0008).
100
+ */
101
+ export const renderTree = (tree, scopeNodeId) => {
102
+ const chain = scopeNodeId === undefined ? undefined : chainTo(tree.root, scopeNodeId);
103
+ const body = chain === undefined ? renderNode(tree.root, 0, scopeNodeId) : renderChain(chain, 0);
104
+ return [`tree ${tree.treeId} revision ${tree.revision}`, ...body].join("\n");
105
+ };
106
+ /**
107
+ * Declared fields, as a catalogue line writes them.
108
+ *
109
+ * Shared by primitives and sources because the two projections answer the same
110
+ * three-way question in the same shape — a list, an empty list, or `undefined`
111
+ * meaning the schema could not be enumerated — and a second copy of the
112
+ * `not declared` / `none` distinction is a second chance to collapse it.
113
+ *
114
+ * The label is a parameter rather than a constant because the two are not the
115
+ * same word to a reader: a primitive takes props and a source takes params, and
116
+ * telling a model a source has `props` invites it to set them on the node.
117
+ */
118
+ const renderDeclaredFields = (label, fields) => {
119
+ if (fields === undefined)
120
+ return ` ${label}: not declared`;
121
+ if (fields.length === 0)
122
+ return ` ${label}: none`;
123
+ const rendered = fields.map((field) => (field.required ? field.name : `${field.name}?`));
124
+ return ` ${label}: ${rendered.join(", ")}`;
125
+ };
126
+ const renderCataloguedProps = (primitive) => renderDeclaredFields("props", primitive.props);
127
+ const renderCataloguedSlots = (primitive) => primitive.slots.length === 0 ? "" : ` slots: ${primitive.slots.join(", ")}`;
128
+ /**
129
+ * The binding names a primitive reads, where its author has said.
130
+ *
131
+ * The three-way distinction `renderDeclaredFields` spells out is kept, and
132
+ * spelled differently: a declared list and a declared `none` are written, and
133
+ * *nobody has said* is written by saying nothing. That is the opposite of what
134
+ * props do, and the difference is which answer is the common one. Every
135
+ * primitive declares a props schema, so `props: not declared` is the rare line
136
+ * and is worth its words; `reads` is absent on every primitive whose author has
137
+ * not thought about data, which today is nearly all of them, and a catalogue
138
+ * carrying `reads: not declared` on ninety-six consecutive lines would spend
139
+ * real tokens on every proposal to tell a model nothing at all.
140
+ *
141
+ * The distinction survives because absence of the clause *is* the third
142
+ * answer — the model is told in the data block how to read it.
143
+ */
144
+ const renderCataloguedReads = (primitive) => {
145
+ if (primitive.reads === undefined)
146
+ return "";
147
+ if (primitive.reads.length === 0)
148
+ return " reads: none";
149
+ return ` reads: ${primitive.reads.map(renderCataloguedRead).join(", ")}`;
150
+ };
151
+ /**
152
+ * One entry of that clause: a name, or the prop that gives one.
153
+ *
154
+ * The prop-named form is spelled out rather than shortened to its default,
155
+ * because the default is the less useful half of what a model needs. A model
156
+ * binding one thing writes the default and says nothing; a model binding a
157
+ * second thing to the same primitive has to know that the prop is what makes
158
+ * the two names differ, and the only place it could learn that is here.
159
+ */
160
+ const renderCataloguedRead = (read) => typeof read === "string"
161
+ ? read
162
+ : `the name in "${read.fromProp}" (default ${read.default})`;
163
+ /**
164
+ * A description ends its own sentence, and the renderer finishes one that does
165
+ * not.
166
+ *
167
+ * Every description in the starter library already ends in a full stop, so
168
+ * appending one unconditionally gave the model sixty-one lines reading
169
+ * `…in one column.. props: fills?` on every proposal and again on every repair.
170
+ * Nothing renders this string and no snapshot can look wrong, which is why it
171
+ * survived until a documentation page printed the real request.
172
+ *
173
+ * Refusing to append at all was the other way, and it is worse for the case
174
+ * this does not control: a host's own primitive may be described without
175
+ * terminal punctuation, and `— A banner props: tone?` runs the sentence into
176
+ * the props with nothing between them.
177
+ */
178
+ const TERMINAL_PUNCTUATION = new Set([".", "!", "?"]);
179
+ const renderCataloguedDescription = (description) => TERMINAL_PUNCTUATION.has(description.slice(-1)) ? description : `${description}.`;
180
+ /**
181
+ * The catalogue as the model sees it: one line per primitive, in registration
182
+ * order, so the deployment's own ordering is what the model reads first.
183
+ *
184
+ * A trailing `?` marks an optional prop, mirroring how the same fact is written
185
+ * in TypeScript, which is a notation a model has seen far more of than any
186
+ * convention invented here.
187
+ */
188
+ export const renderCatalogue = (catalogue) => catalogue
189
+ .map((primitive) => `- ${primitive.type} — ${renderCataloguedDescription(primitive.description)}${renderCataloguedProps(primitive)}${renderCataloguedSlots(primitive)}${renderCataloguedReads(primitive)}`)
190
+ .join("\n");
191
+ const renderThemeGroup = (label, entries) => entries.length === 0
192
+ ? []
193
+ : [`${label}:`, ...entries.map((entry) => `- ${entry.id} — ${entry.name}. ${entry.description}`)];
194
+ /**
195
+ * The theme vocabulary as the model sees it — three lists of ids with the
196
+ * sentence their author wrote about each.
197
+ *
198
+ * Without it, "make it warmer" resolves against a vocabulary the model was
199
+ * never shown: the tree carries `palette: "editorial"` and nothing says which
200
+ * other palettes exist, so the only reachable answers are the one already
201
+ * mounted and an invented id that fails to resolve. The hex is deliberately not
202
+ * here. A model choosing between registered palettes by description is the
203
+ * bargain 0049 struck; a model choosing colours is the thing it rules out.
204
+ */
205
+ export const renderThemeCatalogue = (catalogue) => [
206
+ ...renderThemeGroup("Palettes", catalogue.palettes),
207
+ ...renderThemeGroup("Font packs", catalogue.fontPacks),
208
+ ...renderThemeGroup("Style presets", catalogue.stylePresets),
209
+ ].join("\n");
210
+ /**
211
+ * The sources as the model sees it — one line per registered source, with the
212
+ * params it declares written the way a primitive's props are.
213
+ *
214
+ * Registration order, like the primitive catalogue and for the same reason: the
215
+ * deployment's own ordering is what the model reads first, and sorting here
216
+ * would silently overrule a host that put its most-used source at the top.
217
+ */
218
+ export const renderSourceCatalogue = (catalogue) => catalogue
219
+ .map((source) => `- ${source.id} — ${renderCataloguedDescription(source.description)}${renderDeclaredFields("params", source.params)}`)
220
+ .join("\n");
221
+ /**
222
+ * The endpoints as the model sees it — an id and a line, and deliberately
223
+ * nothing else.
224
+ *
225
+ * `submissionCatalogue` is thin because there is nothing else a model may
226
+ * supply (0065): where a form posts to, whether it posts or gets, and what it
227
+ * carries are resolved after the choice is made. Rendering anything more here
228
+ * would be putting an address in front of a model that must never name one.
229
+ */
230
+ export const renderSubmissionCatalogue = (catalogue) => catalogue
231
+ .map((endpoint) => `- ${endpoint.id} — ${renderCataloguedDescription(endpoint.description)}`)
232
+ .join("\n");
233
+ /**
234
+ * The framable origins as the model sees it — scheme, host and port, and the
235
+ * sentence whoever runs the deployment wrote about each.
236
+ *
237
+ * Unlike the two above, this list is not the set of values a model may write.
238
+ * A frame's URL is a content decision and stays in the tree (0095); what the
239
+ * list constrains is the origin that URL must be on. So the line is an origin
240
+ * rather than an address, and the block below says which of the two it is.
241
+ */
242
+ export const renderFrameCatalogue = (catalogue) => catalogue
243
+ .map((entry) => `- ${entry.origin} — ${renderCataloguedDescription(entry.description)}`)
244
+ .join("\n");
245
+ const renderPropKeys = (label, keys) => keys.length === 0 ? "" : ` ${label} ${keys.join(", ")}`;
246
+ /**
247
+ * One operation per line, in the order they apply. Used to show a model the
248
+ * proposal the Gate refused, so a repair is a revision of something specific
249
+ * rather than a second guess at the same utterance.
250
+ */
251
+ const renderOperation = (operation, position) => {
252
+ const prefix = `${position + 1}. `;
253
+ switch (operation.op) {
254
+ case "insert":
255
+ return [
256
+ `${prefix}insert into ${operation.parentId} at ${operation.index}:`,
257
+ ...renderNode(operation.node, 2),
258
+ ];
259
+ case "remove":
260
+ return [`${prefix}remove ${operation.nodeId} and its subtree`];
261
+ case "move":
262
+ return [`${prefix}move ${operation.nodeId} into ${operation.parentId} at ${operation.index}`];
263
+ case "configure":
264
+ return [
265
+ `${prefix}configure ${operation.nodeId}${renderPropKeys("set", Object.keys(operation.set).sort())}${renderPropKeys("unset", operation.unset)}`,
266
+ ];
267
+ default:
268
+ return assertNever(operation, "renderOperation");
269
+ }
270
+ };
271
+ export const renderDelta = (delta) => delta.operations.flatMap((operation, position) => renderOperation(operation, position)).join("\n");
272
+ //# sourceMappingURL=render.js.map