@supa-media/tex-contract 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/package.json +16 -4
  4. package/texContract/aboutLines.cjs +117 -0
  5. package/texContract/aboutLines.d.cts +14 -0
  6. package/texContract/aboutNoteLimits.cjs +41 -0
  7. package/texContract/aboutNoteLimits.d.cts +5 -0
  8. package/texContract/actionManual.cjs +104 -0
  9. package/texContract/activityHint.cjs +40 -0
  10. package/texContract/activityHint.d.cts +4 -0
  11. package/texContract/asks.cjs +16 -0
  12. package/texContract/asks.d.cts +6 -0
  13. package/texContract/asksToFile.cjs +20 -0
  14. package/texContract/asksToFile.d.cts +2 -0
  15. package/texContract/attention.cjs +138 -0
  16. package/texContract/attention.d.cts +20 -0
  17. package/texContract/browserHandback.cjs +13 -0
  18. package/texContract/browserHandback.d.cts +3 -0
  19. package/texContract/browserOwner.cjs +31 -0
  20. package/texContract/browserOwner.d.cts +2 -0
  21. package/texContract/bytes.cjs +12 -0
  22. package/texContract/capabilities.cjs +47 -0
  23. package/texContract/capabilities.d.cts +27 -0
  24. package/texContract/capabilities.generated.json +77 -0
  25. package/texContract/chatHistoryPath.cjs +38 -0
  26. package/texContract/chatHistoryPath.d.cts +5 -0
  27. package/texContract/chatLedger.cjs +91 -0
  28. package/texContract/chatLedger.d.cts +21 -0
  29. package/texContract/computerTool.cjs +102 -0
  30. package/texContract/computerTool.d.cts +16 -0
  31. package/texContract/consentYes.cjs +22 -0
  32. package/texContract/consentYes.d.cts +5 -0
  33. package/texContract/contextGateway.cjs +52 -0
  34. package/texContract/contextGateway.d.cts +19 -0
  35. package/texContract/deskEligible.cjs +20 -0
  36. package/texContract/deskEligible.d.cts +3 -0
  37. package/texContract/downloads.cjs +129 -0
  38. package/texContract/downloads.d.cts +15 -0
  39. package/texContract/egressLedger.cjs +114 -0
  40. package/texContract/egressLedger.d.cts +14 -0
  41. package/texContract/emailRead.cjs +38 -0
  42. package/texContract/emailRead.d.cts +5 -0
  43. package/texContract/eventWords.cjs +35 -0
  44. package/texContract/eventWords.d.cts +4 -0
  45. package/texContract/fileParts.cjs +43 -0
  46. package/texContract/fileParts.d.cts +6 -0
  47. package/texContract/fileTables.cjs +243 -0
  48. package/texContract/fileWords.cjs +169 -0
  49. package/texContract/folded.cjs +16 -0
  50. package/texContract/folded.d.cts +3 -0
  51. package/texContract/googleAiAccess.cjs +12 -0
  52. package/texContract/googleAiAccess.d.cts +2 -0
  53. package/texContract/graphWires.cjs +18 -0
  54. package/texContract/graphWires.d.cts +5 -0
  55. package/texContract/groupSession.cjs +28 -0
  56. package/texContract/groupSession.d.cts +7 -0
  57. package/texContract/guestNames.cjs +136 -0
  58. package/texContract/guestNames.d.cts +35 -0
  59. package/texContract/heard.cjs +19 -0
  60. package/texContract/heard.d.cts +4 -0
  61. package/texContract/heldOffer.cjs +57 -0
  62. package/texContract/heldOffer.d.cts +8 -0
  63. package/texContract/helperCallers.cjs +29 -0
  64. package/texContract/helperCallers.d.cts +4 -0
  65. package/texContract/identity.cjs +179 -0
  66. package/texContract/identity.d.cts +8 -0
  67. package/texContract/jobLogEntries.cjs +93 -0
  68. package/texContract/jobLogEntries.d.cts +12 -0
  69. package/texContract/judgedActions.cjs +20 -0
  70. package/texContract/judgedActions.d.cts +4 -0
  71. package/texContract/labSandboxGate.cjs +63 -0
  72. package/texContract/labSandboxGate.d.cts +9 -0
  73. package/texContract/ledgerReadChars.cjs +4 -0
  74. package/texContract/ledgerReadChars.d.cts +3 -0
  75. package/texContract/mailCheck.cjs +90 -0
  76. package/texContract/mailCheck.d.cts +12 -0
  77. package/texContract/mailEntries.cjs +64 -0
  78. package/texContract/mailEntries.d.cts +13 -0
  79. package/texContract/mailHealth.cjs +60 -0
  80. package/texContract/mailHealth.d.cts +10 -0
  81. package/texContract/notePath.cjs +99 -0
  82. package/texContract/notePath.d.cts +4 -0
  83. package/texContract/noteRunFacts.cjs +136 -0
  84. package/texContract/noteRunFacts.d.cts +32 -0
  85. package/texContract/objectEtag.cjs +84 -0
  86. package/texContract/objectEtag.d.cts +4 -0
  87. package/texContract/objectPlace.cjs +32 -0
  88. package/texContract/objectPlace.d.cts +5 -0
  89. package/texContract/pageJobs.cjs +226 -0
  90. package/texContract/pageJobs.d.cts +13 -0
  91. package/texContract/pdfLinks.cjs +135 -0
  92. package/texContract/pdfLinks.d.cts +4 -0
  93. package/texContract/personHub.cjs +38 -0
  94. package/texContract/personHub.d.cts +5 -0
  95. package/texContract/personNameText.cjs +18 -0
  96. package/texContract/personNameText.d.cts +3 -0
  97. package/texContract/pinnedContext.cjs +12 -0
  98. package/texContract/pinnedContext.d.cts +3 -0
  99. package/texContract/quietHoursWindow.cjs +36 -0
  100. package/texContract/quietHoursWindow.d.cts +3 -0
  101. package/texContract/reactEmoji.cjs +79 -0
  102. package/texContract/reactEmoji.d.cts +2 -0
  103. package/texContract/scopeClamp.cjs +117 -0
  104. package/texContract/scopeClamp.d.cts +5 -0
  105. package/texContract/scopes.cjs +29 -0
  106. package/texContract/scopes.d.cts +7 -0
  107. package/texContract/searchSettings.cjs +54 -0
  108. package/texContract/searchSettings.d.cts +6 -0
  109. package/texContract/settingHabits.cjs +87 -0
  110. package/texContract/settingHabits.d.cts +20 -0
  111. package/texContract/settingsNotes.cjs +217 -0
  112. package/texContract/settingsNotes.d.cts +26 -0
  113. package/texContract/shownEmail.cjs +181 -0
  114. package/texContract/texClients.cjs +53 -0
  115. package/texContract/texClients.d.cts +12 -0
  116. package/texContract/texGraph.cjs +593 -0
  117. package/texContract/texGraph.d.cts +55 -0
  118. package/texContract/texKeys.cjs +100 -0
  119. package/texContract/texKeys.d.cts +13 -0
  120. package/texContract/texNumber.cjs +20 -0
  121. package/texContract/texNumber.d.cts +3 -0
  122. package/texContract/texOwnSources.cjs +9 -0
  123. package/texContract/texOwnSources.d.cts +3 -0
  124. package/texContract/texSettings.cjs +22 -0
  125. package/texContract/texSettings.d.cts +20 -0
  126. package/texContract/texSettings.generated.json +25 -0
  127. package/texContract/texStateFiles.cjs +22 -0
  128. package/texContract/texStateFiles.d.cts +9 -0
  129. package/texContract/texSteps.cjs +27 -0
  130. package/texContract/texSteps.d.cts +14 -0
  131. package/texContract/texSteps.generated.json +41 -0
  132. package/texContract/texStoreNames.cjs +26 -0
  133. package/texContract/texStoreNames.d.cts +12 -0
  134. package/texContract/texStoreWire.cjs +306 -0
  135. package/texContract/texStoreWire.d.cts +32 -0
  136. package/texContract/threadsFold.cjs +75 -0
  137. package/texContract/threadsFold.d.cts +22 -0
  138. package/texContract/toolActions.cjs +253 -0
  139. package/texContract/toolCatalog.cjs +49 -0
  140. package/texContract/toolCatalog.generated.json +90 -0
  141. package/texContract/toolContract.cjs +52 -0
  142. package/texContract/toolContract.d.cts +12 -0
  143. package/texContract/toolShapes.cjs +14 -0
  144. package/texContract/transcription.cjs +101 -0
  145. package/texContract/transcription.d.cts +3 -0
  146. package/texContract/treeJobs.cjs +31 -0
  147. package/texContract/treeJobs.d.cts +3 -0
  148. package/texContract/turnSession.cjs +90 -0
  149. package/texContract/turnSession.d.cts +19 -0
  150. package/texContract/turnWords.cjs +90 -0
  151. package/texContract/turnWords.d.cts +9 -0
  152. package/texContract/uploadImages.cjs +131 -0
  153. package/texContract/uploadImages.d.cts +13 -0
  154. package/texContract/v2Names.cjs +41 -0
  155. package/texContract/v2SearchFetch.cjs +316 -0
  156. package/texContract/v2Translate.cjs +123 -0
  157. package/texContract/vaultTools.cjs +112 -0
  158. package/texContract/vaultTools.d.cts +15 -0
  159. package/texContract/yesWords.cjs +91 -0
  160. package/texShared/argumentCoercion.cjs +93 -0
  161. package/texShared/cellComments.cjs +122 -0
  162. package/texShared/cellComments.d.cts +21 -0
  163. package/texShared/comments.cjs +586 -0
  164. package/texShared/comments.d.cts +115 -0
  165. package/texShared/contentTypes.cjs +85 -0
  166. package/texShared/fileKinds.cjs +123 -0
  167. package/texShared/flags.cjs +159 -0
  168. package/texShared/flags.d.cts +23 -0
  169. package/texShared/folderJobInfo.cjs +301 -0
  170. package/texShared/folderJobInfo.d.cts +40 -0
  171. package/texShared/folderRoles.cjs +512 -0
  172. package/texShared/folderRoles.d.cts +73 -0
  173. package/texShared/githubOidc.ts +98 -0
  174. package/texShared/groupRunQuestions.cjs +98 -0
  175. package/texShared/groupRunQuestions.d.cts +4 -0
  176. package/texShared/inboxFolders.cjs +49 -0
  177. package/texShared/inboxFolders.d.cts +5 -0
  178. package/texShared/ink/drawing.cjs +474 -0
  179. package/texShared/ink/texFigure.cjs +252 -0
  180. package/texShared/ink/texFigure.d.cts +36 -0
  181. package/texShared/ink/texPoses.cjs +180 -0
  182. package/texShared/ink/texPoses.d.cts +20 -0
  183. package/texShared/jobPartEnd.cjs +133 -0
  184. package/texShared/jobPartEnd.d.cts +13 -0
  185. package/texShared/jobResume.cjs +31 -0
  186. package/texShared/jobResume.d.cts +5 -0
  187. package/texShared/jobSplit.cjs +90 -0
  188. package/texShared/jobSplit.d.cts +6 -0
  189. package/texShared/jobStart.cjs +56 -0
  190. package/texShared/jobStart.d.cts +9 -0
  191. package/texShared/mail.cjs +400 -0
  192. package/texShared/mail.d.cts +56 -0
  193. package/texShared/messageAnchors.cjs +38 -0
  194. package/texShared/models/aiKeys.cjs +137 -0
  195. package/texShared/models/aiKeys.d.cts +42 -0
  196. package/texShared/models/aiKeys.json +56 -0
  197. package/texShared/models/creditRest.cjs +269 -0
  198. package/texShared/models/promptBudget.cjs +295 -0
  199. package/texShared/models/promptSections.cjs +29 -0
  200. package/texShared/noteAppLink.cjs +23 -0
  201. package/texShared/notePreview.cjs +219 -0
  202. package/texShared/notePreview.d.cts +21 -0
  203. package/texShared/pages/blocks.cjs +215 -0
  204. package/texShared/pages/cover.cjs +164 -0
  205. package/texShared/pages/css.cjs +181 -0
  206. package/texShared/pages/cssBlocks.cjs +264 -0
  207. package/texShared/pages/draw.cjs +212 -0
  208. package/texShared/pages/drawRich.cjs +232 -0
  209. package/texShared/pages/html.cjs +168 -0
  210. package/texShared/pages/inline.cjs +251 -0
  211. package/texShared/pages/layout.cjs +76 -0
  212. package/texShared/pages/parse.cjs +418 -0
  213. package/texShared/pages/render.cjs +200 -0
  214. package/texShared/pages/skill.cjs +147 -0
  215. package/texShared/pages/skill.d.cts +5 -0
  216. package/texShared/pages/templates.cjs +336 -0
  217. package/texShared/r2Store.cjs +163 -0
  218. package/texShared/remoteImage.cjs +177 -0
  219. package/texShared/routines.cjs +656 -0
  220. package/texShared/routines.d.cts +86 -0
  221. package/texShared/servedListing.cjs +250 -0
  222. package/texShared/servedListing.d.cts +17 -0
  223. package/texShared/sheetCsv.cjs +566 -0
  224. package/texShared/sheetCsv.d.cts +91 -0
  225. package/texShared/storageLayout.cjs +88 -0
  226. package/texShared/storeKeys.cjs +144 -0
  227. package/texShared/toolArguments.cjs +323 -0
@@ -0,0 +1,200 @@
1
+ /**
2
+ * A parsed page (`parse.cjs`) as HTML.
3
+ *
4
+ * One renderer for every place a page is drawn: the page runtime's frame
5
+ * (`apps/mobile/page-frame/`), and the gateway's cover picture of a page that
6
+ * Tex texts. It returns a string, and every word in it went through `esc`:
7
+ * nothing from the note reaches the markup except as escaped text, a number
8
+ * this file computed, or a class name it chose. The note's own CSS and boxes
9
+ * are not in it; the runtime adds those, the CSS to its own sealed document
10
+ * and each box to a sealed frame of its own.
11
+ *
12
+ * Every run of words carries `data-f`/`data-t`, its range in the source, and
13
+ * every element whose words can be typed over carries `data-edit`. That is the
14
+ * whole source map: the runtime turns typing in an element into replacements
15
+ * of its runs' ranges, and a selection into a comment's range.
16
+ */
17
+
18
+ const { BLOCK_KINDS } = require("./blocks.cjs");
19
+ const { esc, runsHtml, plain } = require("./html.cjs");
20
+ const { DRAW } = require("./draw.cjs");
21
+ const { RICH } = require("./drawRich.cjs");
22
+ const { coverHtml } = require("./cover.cjs");
23
+ const { drawingSvg } = require("../ink/drawing.cjs");
24
+ const { slotKey } = require("./layout.cjs");
25
+
26
+ const DRAWN = { ...DRAW, ...RICH };
27
+
28
+ function blockHtml(block, ctx) {
29
+ const caption = block.title && block.kind !== "vote" ? `<div class="pg-k pg-caption">${esc(block.title)}</div>` : "";
30
+ if (block.problems.length > 0) {
31
+ return `<div class="pg-block pg-broken" data-node="${block.from}">${caption}<p class="pg-problem">${esc(block.problems[0].message)}</p><pre>${esc(block.items.map((item) => item.label ? `${item.label.text}: ${item.parts.map((p) => p.text).join(" | ")}` : item.parts.map((p) => p.text).join(" | ")).join("\n"))}</pre></div>`;
32
+ }
33
+ return `<div class="pg-block pg-${block.kind}-block" data-node="${block.from}">${caption}${DRAWN[block.kind](block, ctx)}</div>`;
34
+ }
35
+
36
+ /**
37
+ * A ```` ```drawing ```` block: Tex's ink, drawn from the shapes `parse.cjs`
38
+ * read, in both inks so the page's own theme picks one (`--pg-ink-light`,
39
+ * `--pg-ink-dark`), cropped to the scene. Inline, so its words are set in the
40
+ * page's face; each copy's ids are its own, so two drawings never share a
41
+ * hatch. Nothing the writer typed reaches it but numbers and escaped words.
42
+ */
43
+ function drawingFigure(node, ctx) {
44
+ if (node.scene === null) return `<pre class="pg-code" data-node="${node.from}"><code>${esc(node.problems?.[0]?.message ?? "")}</code></pre>`;
45
+ ctx.drawings = (ctx.drawings ?? 0) + 1;
46
+ const one = (dark) => {
47
+ const id = `d${ctx.drawings}${dark ? "n" : "l"}-`;
48
+ return drawingSvg(node.scene, { dark, seed: `${node.from}` })
49
+ .replace(/\bink-(rough|paper|hatch)\b/g, `${id}$1`)
50
+ .replace(/^<svg [^>]*>/, `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${DRAWING_CROP}" role="img" aria-label="${esc(node.caption || "A drawing")}" class="${dark ? "pg-ink-dark" : "pg-ink-light"}">`);
51
+ };
52
+ const caption = node.caption ? `<figcaption>${esc(node.caption)}</figcaption>` : "";
53
+ return `<figure class="pg-ink-figure" data-node="${node.from}">${one(false)}${one(true)}${caption}</figure>`;
54
+ }
55
+
56
+ /** The part of a drawing the scene is in (`SAFE` in `ink/drawing.cjs`), with room for Tex at its foot. */
57
+ const DRAWING_CROP = "90 110 1020 820";
58
+
59
+ /** One node as HTML. `boxes` collects the code boxes, which the runtime fills. */
60
+ function nodeHtml(node, ctx, boxes) {
61
+ const open = ctx.open;
62
+ switch (node.type) {
63
+ case "heading": {
64
+ const level = node.level;
65
+ return `<h${level} data-edit data-node="${node.from}">${runsHtml(node.runs, open)}</h${level}>`;
66
+ }
67
+ case "paragraph":
68
+ return `<p data-edit data-node="${node.from}">${runsHtml(node.runs, open)}</p>`;
69
+ case "rule":
70
+ return `<hr>`;
71
+ case "quote":
72
+ return `<blockquote class="${node.alert ? `pg-alert pg-alert-${node.alert}` : ""}" data-node="${node.from}"><p data-edit>${runsHtml(node.runs, open)}</p></blockquote>`;
73
+ case "list": {
74
+ const tag = node.ordered ? "ol" : "ul";
75
+ const tasks = node.items.some((item) => item.task);
76
+ return `<${tag} class="${tasks ? "pg-tasks" : ""}" data-node="${node.from}">${node.items
77
+ .map((item) => {
78
+ const box = item.task
79
+ ? `<input type="checkbox" data-task="${item.task.at}"${item.task.checked ? " checked" : ""} aria-label="Done">`
80
+ : "";
81
+ return `<li class="${item.task && item.task.checked ? "done" : ""}" style="margin-left:${item.depth * 1.25}em">${box}<span data-edit>${runsHtml(item.runs, open)}</span></li>`;
82
+ })
83
+ .join("")}</${tag}>`;
84
+ }
85
+ case "table": {
86
+ // Four columns or more, a phone draws each row as a card, every cell under its column's name (`css.cjs`).
87
+ const labels = node.head.map((cell) => esc(plain(cell)));
88
+ return `<div class="pg-table${node.head.length >= 4 ? " pg-table-cards" : ""}" data-node="${node.from}"><table><thead><tr>${node.head.map((cell) => `<th data-edit>${runsHtml(cell, open)}</th>`).join("")}</tr></thead><tbody>${node.rows
89
+ .map((row) => `<tr>${row.map((cell, i) => `<td data-edit data-label="${labels[i] ?? ""}">${runsHtml(cell, open)}</td>`).join("")}</tr>`)
90
+ .join("")}</tbody></table></div>`;
91
+ }
92
+ case "code":
93
+ return `<pre class="pg-code" data-node="${node.from}"><code>${esc(node.text)}</code></pre>`;
94
+ case "block":
95
+ return blockHtml(node, ctx);
96
+ case "drawing":
97
+ return drawingFigure(node, ctx);
98
+ case "box":
99
+ boxes.push(node);
100
+ return `<div class="pg-box" data-box="${boxes.length - 1}" data-node="${node.from}" style="height:${node.height ?? 240}px"></div>`;
101
+ default:
102
+ return "";
103
+ }
104
+ }
105
+
106
+ /**
107
+ * The whole page: a cover (`cover.cjs`: the kicker, the title, the words
108
+ * before anything else, a status line, photos or a number by the page's
109
+ * kind), then the rest of the words before the first `##`, then one section
110
+ * per `##`. With `layout: tabs` in the front matter, the sections are tabs.
111
+ * Returns the HTML, the boxes to fill, the note's CSS, and its layout with the parts
112
+ * that fill it (`layout.cjs`), or null for both.
113
+ *
114
+ * `images` (src → data URL) hands a cover the pictures it cannot ask the app
115
+ * for; `me` is the reader's name, so their own vote shows as theirs.
116
+ */
117
+ function renderPage(page, { open = new Set(), cover = false, images = null, me = null } = {}) {
118
+ const ctx = { open, images, me };
119
+ const boxes = [];
120
+ const css = page.nodes.filter((node) => node.type === "css").map((node) => node.text);
121
+ const nodes = page.nodes.filter((node) => node.type !== "css" && node.type !== "layout");
122
+ // The page's own layout (`layout.cjs`), drawn by the runtime around the parts below; one that can't be drawn is left out, and the page reads as it would without it.
123
+ const layoutNode = page.nodes.find((node) => node.type === "layout");
124
+ const layout = layoutNode && layoutNode.problems.length === 0 ? layoutNode.html : null;
125
+ const firstSection = nodes.findIndex((node) => node.type === "heading" && node.level === 2);
126
+ const head = firstSection === -1 ? nodes : nodes.slice(0, firstSection);
127
+ const body = firstSection === -1 ? [] : nodes.slice(firstSection);
128
+
129
+ // The cover takes the note's own title and opening words, so they stay editable where they are drawn.
130
+ const h1 = head.find((node) => node.type === "heading" && node.level === 1);
131
+ const dekNode = head.find((node) => node.type === "paragraph");
132
+ const firstBlock = head.findIndex((node) => node.type === "block" || node.type === "box");
133
+ const dek = dekNode && (firstBlock === -1 || head.indexOf(dekNode) < firstBlock) ? dekNode : null;
134
+ const title = h1 ? nodeHtml(h1, ctx, boxes) : page.title ? `<h1>${esc(page.title)}</h1>` : "";
135
+ const dekHtml = dek ? `<p class="pg-dek" data-edit data-node="${dek.from}">${runsHtml(dek.runs, open)}</p>` : "";
136
+ const top = coverHtml(page, nodes, { title, dek: dekHtml }, ctx);
137
+ const rest = head.filter((node) => node !== h1 && node !== dek);
138
+
139
+ if (cover) {
140
+ // The first screen: what a reader sees before scrolling, and the picture texted with the link.
141
+ const first = rest.find((node) => node.type === "block") ?? body.find((node) => node.type === "block");
142
+ return { html: `${top}<div class="pg-in pg-body">${first ? nodeHtml(first, ctx, []) : ""}</div>`, boxes: [], css };
143
+ }
144
+
145
+ const sections = [];
146
+ let current = null;
147
+ for (const node of body) {
148
+ if (node.type === "heading" && node.level === 2) {
149
+ current = { heading: node, nodes: [] };
150
+ sections.push(current);
151
+ } else current.nodes.push(node);
152
+ }
153
+ const tabs = layout === null && /^tabs$/i.test(page.fields.layout ?? "") && sections.length > 1;
154
+ const sectionParts = sections.map((section, i) => {
155
+ // The words right under a section's heading are its dek, drawn under it in the heading's quieter voice.
156
+ const [lead, ...after] = section.nodes;
157
+ const dekOf = lead && lead.type === "paragraph" ? `<p class="pg-dek" data-edit data-node="${lead.from}">${runsHtml(lead.runs, open)}</p>` : "";
158
+ const restOf = dekOf ? after : section.nodes;
159
+ return {
160
+ key: slotKey(plain(section.heading.runs)),
161
+ html: `<section class="pg-section" data-section="${i}"${tabs && i > 0 ? " hidden" : ""}><div class="pg-sec-h">${nodeHtml(section.heading, ctx, boxes)}${dekOf}</div>${restOf.map((node) => nodeHtml(node, ctx, boxes)).join("")}</section>`,
162
+ };
163
+ });
164
+ const sectionHtml = sectionParts.map((part) => part.html).join("");
165
+ const tabBar = tabs
166
+ ? `<nav class="pg-tabs" role="tablist">${sections.map((section, i) => `<button type="button" role="tab" data-tab="${i}" aria-selected="${i === 0}">${esc(plain(section.heading.runs))}</button>`).join("")}</nav>`
167
+ : "";
168
+ const lead = rest.map((node) => nodeHtml(node, ctx, boxes)).join("");
169
+ return {
170
+ html: `${top}<div class="pg-in pg-body">${lead}${tabBar}${sectionHtml}</div>`,
171
+ boxes,
172
+ css,
173
+ layout,
174
+ // What a layout's `data-from` slots are filled with: the cover with the words before the first `##`, and each section by its heading.
175
+ parts: layout === null ? null : { cover: `${top}${lead ? `<div class="pg-in pg-lead">${lead}</div>` : ""}`, sections: sectionParts },
176
+ };
177
+ }
178
+
179
+ /** The data a box's script is handed as `window.page`: the front matter and every block's items as plain words. */
180
+ function pageData(page) {
181
+ return {
182
+ title: page.title,
183
+ fields: { ...page.fields },
184
+ blocks: page.nodes
185
+ .filter((node) => node.type === "block")
186
+ .map((block) => ({
187
+ kind: block.kind,
188
+ title: block.title,
189
+ settings: Object.fromEntries(Object.entries(block.settings).map(([key, value]) => [key, value.value])),
190
+ words: plain(block.words ?? []),
191
+ items: block.items.map((item) => ({
192
+ label: item.label ? plain(item.label.runs) : null,
193
+ parts: item.parts.map((p) => plain(p.runs)),
194
+ fields: Object.fromEntries((item.fields ?? []).map((field) => [field.key, plain(field.value.runs)])),
195
+ })),
196
+ })),
197
+ };
198
+ }
199
+
200
+ module.exports = { renderPage, pageData, esc, BLOCK_NAMES: Object.keys(BLOCK_KINDS) };
@@ -0,0 +1,147 @@
1
+ /**
2
+ * THE PAGE DESIGN SKILL: WHAT AN AGENT READS BEFORE IT WRITES A PAGE.
3
+ *
4
+ * Owner, 2026-10-27: pages looked like "a glorified markdown page", and "we
5
+ * should probably create a skill we force the agent to use to create UX/UI
6
+ * components just to make sure we are creating helpful pages"; then "skill
7
+ * should be required when making pages". So it is: this text is served by
8
+ * `orient about: "pages"` (every client, Tex included, has orient), it ends with a
9
+ * stamp, and a `.page.md` write without the current stamp in its front matter
10
+ * is refused (`pages.js`), naming where to read it. The stamp is a hash of
11
+ * the skill itself, so changing the skill makes every agent read it again.
12
+ *
13
+ * It teaches design, not syntax: what a page is for, what goes first, which
14
+ * part fits which shape of facts, the hard cases from the round 2 artboard,
15
+ * and the checks a page must pass before it is sent. The format reference is
16
+ * appended from the block kinds themselves, so it never drifts from the
17
+ * checks. Decision: `docs/decisions/app-and-console/pages.md`.
18
+ */
19
+
20
+ const { BLOCK_KINDS } = require("./blocks.cjs");
21
+ const { templateLines } = require("./templates.cjs");
22
+
23
+ const DESIGN = `# Page design skill
24
+
25
+ Read all of this before you write any \`.page.md\`. A page is what people open from a text or a link to decide something or see where things stand. It should look like a real page somebody designed, not a document. You write words and rows of facts; the page draws the photos, map, colors and layout from them.
26
+
27
+ ## 0. Start from a template
28
+
29
+ Pick the shape before you write. Their own templates come first: list \`tex/templates/\` in their personal workspace, and \`templates/\` in a shared workspace you are writing in; a \`.page.md\` there is a page to copy and fill. Otherwise read the built-in that fits with \`orient about: "template <name>"\`:
30
+
31
+ ${templateLines().join("\n")}
32
+
33
+ Fill every \`[gap]\`, put real numbers where a template holds 0 or \`?\`, drop a part the facts don't need, and add one they do. A page with a \`[bracket]\` left in it isn't finished. When they ask to keep a page as a template, copy it to \`tex/templates/<name>.page.md\` in their personal workspace (a shared workspace's page goes to its \`templates/\`, so everyone there gets it), with every fact that belongs to this one case turned back into a \`[gap]\`, its photos and \`drawing\` lines dropped, and the stamp kept.
34
+
35
+ ## 1. Lead with the answer
36
+
37
+ Order, top to bottom:
38
+ 1. Front matter: \`kind\` (research, plan or status), \`for\` (who it is for), \`status\` (one short line: "Nothing booked yet", "On track"), \`cover\` (a photo file, or leave it out to use the first photo below). A status page also has \`number: 412 of 1,000\`.
39
+ 2. \`# Title\`: the outcome in a few words ("Sunday services, sorted"), not the topic ("Research on venues").
40
+ 3. One sentence under it: what this page answers, with the key numbers.
41
+ 4. If there is a decision, a \`vote\` block right here: your pick as the caption, one line of why, the options. Never leave the decision at the bottom.
42
+ 5. A \`stats\` block of the 2 to 4 numbers that frame everything (seats needed, budget, people, deadline).
43
+ 6. One \`##\` section per question, each headed by its own answer ("Three rooms that seat 200", "Lunch for 30, from $420"), then one sentence, then its block.
44
+ 7. Next steps as \`- [ ]\` tasks, and contacts last.
45
+
46
+ ## 2. Pick the part that fits the facts
47
+
48
+ - A choice someone has to make: \`vote\` (2 to 6 options). Budgets or packages: \`tiers\` (2 to 4).
49
+ - Places (venues, restaurants, churches, offices, stops to visit: anything with an address): \`places\`, with price, seats and facts under each. One to six get photo spreads; seven or more become a shortlist on their own.
50
+ - The same kind of price from several sellers: \`prices\`, with \`per\` and \`for\` so the group total is worked out for you. Never a table of prices.
51
+ - A day or a night out: \`itinerary\`, with a \`walk\` under each stop. Deadlines or milestones: \`timeline\`, with \`state: done\` or \`now\`.
52
+ - Numbers over time: \`chart\`. One number against a goal: a status page's \`number\`, or \`progress\`.
53
+ - Who does what this week: \`board\`. Who to call or write: \`contacts\`, with phone, email or site fields.
54
+ - How something works, flows or fits together (a route, a floor plan, who hands what to whom, the steps of a setup): a \`drawing\`, your simple line drawing of it in Tex's ink, beside the words that explain it. One per section at most; never a drawing of words you could write.
55
+ - Two things compared row by row: \`versus\`. Anything no block draws (a calculator, a bill splitter): a \`box\` of your own HTML and CSS.
56
+ - Plain prose only for what is really prose. A paragraph that lists options, prices or times is a block you have not written yet.
57
+
58
+ ## 3. Write it well
59
+
60
+ - Labels short, names exact, numbers real and from what you read. A price you did not find is \`?\` (or Ask), drawn as one to ask about. Never 0, never a guess.
61
+ - Facts as \`key: yes|no|?|word\` under a place (\`on the L: yes; kitchen: ?\`), the same keys on every place so they line up.
62
+ - Photos make the page. For every place, dish or stop, use the real pictures you found on its own pages (or a picture search): pass each in the write's \`images\` as \`{ name: "stand-1.jpg", url: "<the picture's address>" }\` and name it in a field (\`photo: stand-1.jpg\`, \`photos: stand-1.jpg, stand-2.jpg\`, \`cover:\`). They are saved with the note and exported with it. Name a photo only when you attach it in the same write; a name with no picture behind it is taken off, so leave the field out and one is found for you. Every option compared (a place, dish, country, hotel, product) gets a real picture: when its pages have none, search_web with pictures: true for its name, or open its page in your browser; never save a comparison page with no pictures because the first try found none. Give a place two to four photos (\`photos: a.jpg, b.jpg, c.jpg\`): they swipe as a carousel. A wrong photo is worse than none, so check the name matches.
63
+ - Every option, place, price, stop, person and timeline row gets \`source: <the page you read it on>\`, drawn as a link out to that site. Facts with no source are guesses. A web address written in the words is a link too.
64
+ - A page is visual: people get their photo (\`photo:\` under each, or one is found for them), named things in a timeline get theirs, organisations their logo or building. A page with no picture at all is sent back for its drawing; the cover call is never optional.
65
+ - A map: draw the places with \`draw_visual\` (template map) and keep that picture as the block's \`map: map.png\`, passing \`images: [{ name: "map.png", data: "picture:N" }]\`. Without one, each place still opens in a map app.
66
+ - One idea per section. Five sections at most; move the rest to a linked note.
67
+ - \`accent\` only if the subject has a color of its own; otherwise leave it.
68
+
69
+ ## 4. Hard cases
70
+
71
+ - Two options: still a \`vote\`; they face off. Twelve: shortlist the best 3 to 6 in the vote, the rest in \`places\` or \`prices\`.
72
+ - Nothing decided yet: \`status: Nothing booked yet\`, and the vote's \`action\` says the next step ("Ask {pick} for a quote").
73
+ - Mixed prices (per head and per event): two \`prices\` blocks, or put the per-event ones in \`places\` as \`price:\`.
74
+ - Unknowns: say so once in the dek or a \`> [!NOTE]\`, not in every row.
75
+
76
+ ## 5. Check before you send
77
+
78
+ 1. The title and the first sentence answer the question without scrolling.
79
+ 2. The decision (if any) is a vote near the top, with your pick and why.
80
+ 3. Every list of options, prices, places or times is a block, not prose or a table.
81
+ 4. No invented numbers; unknowns are \`?\`.
82
+ 5. Every place has an address and a source; every contact has a phone, email or site.
83
+ 6. Section headings are answers, not topics.
84
+ 7. It reads on a phone: short labels, nothing that needs a wide screen.
85
+ 8. Your stamp is in the front matter (below).`;
86
+
87
+ /** One line per block kind, from the kinds themselves, so the reference never drifts from the checks. */
88
+ const KIND_LINES = Object.entries(BLOCK_KINDS).map(([kind, { about }]) => `- \`${kind}\`: ${about}`);
89
+
90
+ const FORMAT = [
91
+ "## Format",
92
+ "",
93
+ "A note whose name ends in `.page.md` is drawn as a page: words, pictures and choices people read, vote on, tick and comment on in the app. It is still Markdown, so every word stays editable and searchable.",
94
+ "",
95
+ "- **Words** are ordinary Markdown: `#` title, `##` sections (each a section, or a tab with `layout: tabs`), lists, `- [ ]` tasks people tick, tables, `> [!NOTE]` callouts, links and `[[wiki links]]`.",
96
+ "- **Front matter**: `skill` (the stamp below, required), `kind` (research, plan, status), `for`, `status`, `updated`, `cover` (photo files, comma separated), `number` (a status page's big number, `412 of 1,000`), `kicker` (replaces the kind line), `theme` (light, dark; else the reader's), `accent` (indigo, green, orange, plum, red, ink), `layout: tabs`. `drawing` and `drawing-dark` are the picture Tex draws for a page with none (draw_visual template page with a scene saves them): keep them as they are.",
97
+ "- **Blocks** are fenced data the page draws: the fence names the kind and a caption, then one `- ` line per item and `key: value` settings. An item is `|`-separated parts, and the first may start with `Label: `. Lines indented under an item are its fields (`photo: stand.jpg`, `seats: 300-500`, or facts split with `; `). Example:",
98
+ "",
99
+ " ```places Three rooms that seat 200",
100
+ " need: 200 seats",
101
+ " - The Stand: 116 E 16th St, New York | Own kitchen and a stage",
102
+ " price: Ask",
103
+ " seats: 300-500",
104
+ " on the L: yes; kitchen: yes",
105
+ " ```",
106
+ "",
107
+ ...KIND_LINES,
108
+ "",
109
+ "- **Drawings**: a ```` ```drawing <caption> ```` fence holds SVG shapes on a 1200 x 900 canvas (`rect`, `circle`, `ellipse`, `line`, `path`, `polyline`, `polygon`, `text` of a few words, `g`, and one `<tex x y size>` for Tex himself). Fills are `none`, `ink`, `paper` or `hatch`; every stroke is Tex's ink, in light and dark. No colours, styles, links, images or background rectangle (the paper is already there): anything else is refused with what to fix.",
110
+ "- **Look**: a ```` ```css ```` fence restyles the page (`--pg-accent`, `.pg-nums`, `h1`); it can load nothing from the network.",
111
+ "- **Layout**: a ```` ```layout ```` fence holds HTML (and a `<style>`) that places the page's parts, for work that should look designed: an editorial review with numbered findings beside their exhibits, a research brief in two columns. `data-from=\"cover\"` is the title, opening line and cover; `data-from=\"<a ## heading>\"` is that section; `data-from=\"rest\"` is every section not named. The words stay in the Markdown, so editing and comments still work, and a section you don't place is added at the end. No script, form, link, picture address, `on...=`, `@import` or `url(`: refused with what to fix. Pictures and drawings in a page enlarge when tapped. Use a layout only when the shape matters; most pages read best without one.",
112
+ "- **Code boxes**: a ```` ```box height=320 ```` fence holds HTML and script for something no block draws (a calculator, a quiz, a custom chart). It runs sealed in its own frame, loads nothing, and reads the page's blocks as `window.page.blocks`. Prefer a block; reach for a box only when none fits.",
113
+ "- A write with a block that cannot be drawn is refused with the line to fix. A `choose`, `vote` or `tiers` block's decision comes back as its `chosen:` line, and votes as `votes:` under each option: read the note again to see them.",
114
+ ].join("\n");
115
+
116
+ /** FNV-1a, 32 bits, as hex: a stamp that is the same everywhere this runs, with no Web Crypto round trip. */
117
+ function fnv(text) {
118
+ let hash = 0x811c9dc5;
119
+ for (let i = 0; i < text.length; i += 1) {
120
+ hash ^= text.charCodeAt(i);
121
+ hash = Math.imul(hash, 0x01000193) >>> 0;
122
+ }
123
+ return hash.toString(16).padStart(8, "0");
124
+ }
125
+
126
+ /** What a page's front matter must say to be saved: proof its writer read this skill as it is now. */
127
+ const PAGE_SKILL_STAMP = `pages-${fnv(`${DESIGN}\n${FORMAT}`)}`;
128
+
129
+ /** The whole skill, as `orient about: "pages"` answers it. */
130
+ const PAGE_SKILL = [
131
+ DESIGN,
132
+ "",
133
+ FORMAT,
134
+ "",
135
+ "## Your stamp",
136
+ "",
137
+ `Every page you write carries this line in its front matter, or the write is refused: \`skill: ${PAGE_SKILL_STAMP}\``,
138
+ ].join("\n");
139
+
140
+
141
+ /** The line a background job is told about writing its result as a page. */
142
+ const PAGE_JOB_LINE =
143
+ "Write the deliverable as a page: a note named `<name>.page.md`. Read the page design skill first (orient about: \"pages\"): " +
144
+ "it says what goes first (the answer, then your pick as a vote), which block fits which facts (places, prices, tiers, itinerary, stats, timeline, contacts), " +
145
+ "and the stamp a page must carry; a page without it, or with a block that cannot be drawn, is refused with what to fix.";
146
+
147
+ module.exports = { PAGE_SKILL, PAGE_SKILL_STAMP, PAGE_JOB_LINE };
@@ -0,0 +1,5 @@
1
+ /** Types for `skill.cjs` (the page design skill and its job line); see that file for the reasons. */
2
+
3
+ export declare const PAGE_SKILL: string;
4
+ export declare const PAGE_SKILL_STAMP: string;
5
+ export declare const PAGE_JOB_LINE: string;