@mechane-ai/elements 0.47.0 → 0.49.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 (250) hide show
  1. package/README.md +288 -5
  2. package/bin/mechane-elements-catalog.mjs +104 -12
  3. package/dist/ai.js +5 -5
  4. package/dist/article-yyNPg6VU.js +1904 -0
  5. package/dist/article.js +1 -0
  6. package/dist/catalog.json +1691 -163
  7. package/dist/{categorical-values-DdfGIowV.js → categorical-values-DCznViFp.js} +1 -1
  8. package/dist/{cells--Bd1fQFR.js → cells-CNZE4us2.js} +2 -2
  9. package/dist/charts/cartesian.js +1 -1
  10. package/dist/charts/cells.js +1 -1
  11. package/dist/charts/comparison.js +1 -1
  12. package/dist/charts/distribution.js +1 -1
  13. package/dist/charts/figure.js +12 -12
  14. package/dist/charts/graph.js +1 -1
  15. package/dist/charts/hierarchy.js +1 -1
  16. package/dist/charts/image.js +1 -1
  17. package/dist/charts/matrix.js +3 -2
  18. package/dist/charts/plot.js +6 -6
  19. package/dist/charts/relationship.js +1 -1
  20. package/dist/charts/text.js +1 -1
  21. package/dist/charts/timeline.js +1 -1
  22. package/dist/charts/trend.js +1 -1
  23. package/dist/charts.js +2 -2
  24. package/dist/clock-DSm5lkNE.js +16 -0
  25. package/dist/{code-block-DioAM2bZ.js → code-block-BZsY2sh3.js} +1 -1
  26. package/dist/collections.js +1 -1
  27. package/dist/content/code.js +1 -1
  28. package/dist/content/diff.js +3 -3
  29. package/dist/content/link.js +1 -1
  30. package/dist/content/markdown.js +2 -2
  31. package/dist/content/tree.js +1 -1
  32. package/dist/{content-link-NWuHp5rC.js → content-link-PnpcnTCx.js} +1 -1
  33. package/dist/content.js +1 -1
  34. package/dist/{dates-Cww8UR_n.js → dates-ckJdYF7t.js} +1 -1
  35. package/dist/describe-lesson-BmREzDpt.js +175 -0
  36. package/dist/{dumbbell-plot-B2ZTgQaI.js → dumbbell-plot-CMv9llfd.js} +9 -7
  37. package/dist/{embedding-map-CGM_k6lC.js → embedding-map-DC-lgzCq.js} +8 -8
  38. package/dist/feedback.js +1 -1
  39. package/dist/{figure-frame-wRkIEAwe.js → figure-frame-BjFzbl3m.js} +3 -3
  40. package/dist/forms/dates.js +1 -1
  41. package/dist/forms.js +3 -3
  42. package/dist/{image-grid-CVA4SOy_.js → image-grid-DHqtj_zs.js} +4 -4
  43. package/dist/index.js +1 -1
  44. package/dist/kits/evaluation.js +5 -5
  45. package/dist/kits/interpretability.js +320 -302
  46. package/dist/kits/operations.js +6 -6
  47. package/dist/kits/research.js +558 -0
  48. package/dist/kits/training.js +6 -6
  49. package/dist/layout.js +205 -110
  50. package/dist/lesson/agent.js +811 -0
  51. package/dist/lesson/spec.js +661 -0
  52. package/dist/lesson.js +5 -0
  53. package/dist/mdx.js +227 -0
  54. package/dist/navigation.js +2 -2
  55. package/dist/packages/charts/src/cartesian/index.d.ts +1 -1
  56. package/dist/packages/charts/src/cartesian/scatter-plot.d.ts +18 -0
  57. package/dist/packages/charts/src/chart-theme.d.ts +1 -1
  58. package/dist/packages/charts/src/matrix/index.d.ts +1 -0
  59. package/dist/packages/charts/src/plot/plot-marks.d.ts +7 -3
  60. package/dist/packages/charts/src/plot/plot-surface.d.ts +3 -1
  61. package/dist/packages/collections/src/index.d.ts +1 -1
  62. package/dist/packages/collections/src/metrics.d.ts +9 -1
  63. package/dist/packages/content/src/index.d.ts +2 -0
  64. package/dist/packages/content/src/text-match.d.ts +22 -0
  65. package/dist/packages/core/src/index.d.ts +1 -0
  66. package/dist/packages/core/src/surfaces.d.ts +12 -2
  67. package/dist/packages/forms/src/index.d.ts +2 -0
  68. package/dist/packages/forms/src/token-input.d.ts +24 -0
  69. package/dist/packages/kits/src/interpretability/index.d.ts +1 -1
  70. package/dist/packages/kits/src/interpretability/logit-lens.d.ts +10 -1
  71. package/dist/packages/kits/src/research/finding-card.d.ts +43 -0
  72. package/dist/packages/kits/src/research/index.d.ts +8 -0
  73. package/dist/packages/kits/src/research/milestone-path.d.ts +36 -0
  74. package/dist/packages/kits/src/research/specimen-diff.d.ts +41 -0
  75. package/dist/packages/kits/src/research/work-heartbeat.d.ts +34 -0
  76. package/dist/packages/layout/src/figure-grid.d.ts +8 -0
  77. package/dist/packages/layout/src/index.d.ts +4 -1
  78. package/dist/packages/layout/src/sidebar.d.ts +7 -0
  79. package/dist/packages/layout/src/workbench.d.ts +4 -1
  80. package/dist/packages/teaching/src/agent/index.d.ts +11 -0
  81. package/dist/packages/teaching/src/agent/learner-trace.d.ts +84 -0
  82. package/dist/packages/teaching/src/agent/lesson-bridge.d.ts +59 -0
  83. package/dist/packages/teaching/src/agent/lesson-tour.d.ts +63 -0
  84. package/dist/packages/teaching/src/agent/tutor-tools.d.ts +86 -0
  85. package/dist/packages/teaching/src/article/article-checks.d.ts +9 -0
  86. package/dist/packages/teaching/src/article/article-context.d.ts +49 -0
  87. package/dist/packages/teaching/src/article/article-error.d.ts +12 -0
  88. package/dist/packages/teaching/src/article/article-labels.d.ts +54 -0
  89. package/dist/packages/teaching/src/article/article-layout.stylex.d.ts +14 -0
  90. package/dist/packages/teaching/src/article/article-outline.d.ts +9 -0
  91. package/dist/packages/teaching/src/article/article.d.ts +42 -0
  92. package/dist/packages/teaching/src/article/beat-steps.d.ts +18 -0
  93. package/dist/packages/teaching/src/article/beat.d.ts +16 -0
  94. package/dist/packages/teaching/src/article/challenge.d.ts +29 -0
  95. package/dist/packages/teaching/src/article/exercise-styles.d.ts +76 -0
  96. package/dist/packages/teaching/src/article/figure.d.ts +51 -0
  97. package/dist/packages/teaching/src/article/index.d.ts +31 -0
  98. package/dist/packages/teaching/src/article/lesson-values.d.ts +5 -0
  99. package/dist/packages/teaching/src/article/notes.d.ts +36 -0
  100. package/dist/packages/teaching/src/article/outline-types.d.ts +73 -0
  101. package/dist/packages/teaching/src/article/predict.d.ts +58 -0
  102. package/dist/packages/teaching/src/article/progress-store.d.ts +64 -0
  103. package/dist/packages/teaching/src/article/scrolly.d.ts +26 -0
  104. package/dist/packages/{kits/src/explainers → teaching/src/article}/term.d.ts +8 -2
  105. package/dist/packages/teaching/src/article/tex.d.ts +12 -0
  106. package/dist/packages/teaching/src/article/view-essay.d.ts +13 -0
  107. package/dist/packages/teaching/src/article/view-present.d.ts +8 -0
  108. package/dist/packages/teaching/src/article/view-sheet.d.ts +7 -0
  109. package/dist/packages/teaching/src/article/view-static.d.ts +7 -0
  110. package/dist/packages/teaching/src/article/walk.d.ts +34 -0
  111. package/dist/packages/teaching/src/lesson/define-lesson.d.ts +136 -0
  112. package/dist/packages/teaching/src/lesson/index.d.ts +24 -0
  113. package/dist/packages/teaching/src/lesson/inline-choice.d.ts +12 -0
  114. package/dist/packages/teaching/src/lesson/lesson-context.d.ts +18 -0
  115. package/dist/packages/teaching/src/lesson/lesson-error.d.ts +12 -0
  116. package/dist/packages/teaching/src/lesson/lesson-locale.d.ts +4 -0
  117. package/dist/packages/teaching/src/lesson/lesson-persistence.d.ts +17 -0
  118. package/dist/packages/teaching/src/lesson/lesson-player.d.ts +51 -0
  119. package/dist/packages/teaching/src/lesson/lesson-store.d.ts +84 -0
  120. package/dist/packages/teaching/src/lesson/lesson.d.ts +39 -0
  121. package/dist/packages/teaching/src/lesson/param-controls.d.ts +14 -0
  122. package/dist/packages/teaching/src/lesson/param.d.ts +34 -0
  123. package/dist/packages/teaching/src/lesson/playback.d.ts +42 -0
  124. package/dist/packages/teaching/src/lesson/transport.d.ts +19 -0
  125. package/dist/packages/teaching/src/lesson/use-lesson.d.ts +36 -0
  126. package/dist/packages/teaching/src/mdx/essay-components.d.ts +79 -0
  127. package/dist/packages/teaching/src/mdx/essay-markdown.d.ts +41 -0
  128. package/dist/packages/teaching/src/mdx/essay.d.ts +32 -0
  129. package/dist/packages/teaching/src/mdx/index.d.ts +9 -0
  130. package/dist/packages/teaching/src/mdx/requested-view.d.ts +6 -0
  131. package/dist/packages/teaching/src/scene/flow/flow-layout.d.ts +38 -0
  132. package/dist/packages/teaching/src/scene/flow/flow-pulse.d.ts +16 -0
  133. package/dist/packages/teaching/src/scene/flow/scene-flow.d.ts +81 -0
  134. package/dist/packages/teaching/src/scene/index.d.ts +77 -0
  135. package/dist/packages/teaching/src/scene/morph/morph-scope.d.ts +28 -0
  136. package/dist/packages/teaching/src/scene/plane/plane-hit.d.ts +22 -0
  137. package/dist/packages/teaching/src/scene/plane/plane-label.d.ts +23 -0
  138. package/dist/packages/teaching/src/scene/plane/plane-labels.d.ts +42 -0
  139. package/dist/packages/teaching/src/scene/plane/plane-math.d.ts +45 -0
  140. package/dist/packages/teaching/src/scene/plane/scene-axes.d.ts +30 -0
  141. package/dist/packages/teaching/src/scene/plane/scene-curve.d.ts +42 -0
  142. package/dist/packages/teaching/src/scene/plane/scene-point.d.ts +59 -0
  143. package/dist/packages/teaching/src/scene/plane/scene-projection.d.ts +27 -0
  144. package/dist/packages/teaching/src/scene/plane/scene-region.d.ts +38 -0
  145. package/dist/packages/teaching/src/scene/plane/scene-rule.d.ts +35 -0
  146. package/dist/packages/teaching/src/scene/plane/scene-vector.d.ts +39 -0
  147. package/dist/packages/teaching/src/scene/scene-bracket.d.ts +24 -0
  148. package/dist/packages/teaching/src/scene/scene-callout.d.ts +26 -0
  149. package/dist/packages/teaching/src/scene/scene-context.d.ts +179 -0
  150. package/dist/packages/teaching/src/scene/scene-custom.d.ts +31 -0
  151. package/dist/packages/teaching/src/scene/scene-geometry.d.ts +181 -0
  152. package/dist/packages/teaching/src/scene/scene-group.d.ts +28 -0
  153. package/dist/packages/teaching/src/scene/scene-highlight.d.ts +19 -0
  154. package/dist/packages/teaching/src/scene/scene-layer.d.ts +16 -0
  155. package/dist/packages/teaching/src/scene/scene-node.d.ts +67 -0
  156. package/dist/packages/teaching/src/scene/scene-obstacles.d.ts +27 -0
  157. package/dist/packages/teaching/src/scene/scene-registry.d.ts +79 -0
  158. package/dist/packages/teaching/src/scene/scene-stagger.d.ts +43 -0
  159. package/dist/packages/teaching/src/scene/scene-style.d.ts +14 -0
  160. package/dist/packages/teaching/src/scene/scene-validate.d.ts +65 -0
  161. package/dist/packages/teaching/src/scene/scene-wire.d.ts +45 -0
  162. package/dist/packages/teaching/src/scene/scene.d.ts +36 -0
  163. package/dist/packages/teaching/src/scene/shapes/cell-color.d.ts +11 -0
  164. package/dist/packages/teaching/src/scene/shapes/cell-grid.d.ts +69 -0
  165. package/dist/packages/teaching/src/scene/shapes/scene-card.d.ts +114 -0
  166. package/dist/packages/teaching/src/scene/shapes/scene-cells.d.ts +84 -0
  167. package/dist/packages/teaching/src/scene/shapes/scene-slot.d.ts +37 -0
  168. package/dist/packages/teaching/src/scene/shapes/scene-stack.d.ts +46 -0
  169. package/dist/packages/teaching/src/scene/shapes/scene-token.d.ts +63 -0
  170. package/dist/packages/teaching/src/scene/shapes/scene-tokens.d.ts +40 -0
  171. package/dist/packages/teaching/src/scene/shapes/stack-book.d.ts +35 -0
  172. package/dist/packages/teaching/src/scene/shapes/stack-layout.d.ts +63 -0
  173. package/dist/packages/teaching/src/scene/shapes/token-layout.d.ts +39 -0
  174. package/dist/packages/teaching/src/spec/advice.d.ts +23 -0
  175. package/dist/packages/teaching/src/spec/chart-names.d.ts +2 -0
  176. package/dist/packages/teaching/src/spec/describe-lesson.d.ts +85 -0
  177. package/dist/packages/teaching/src/spec/explainer-guide.d.ts +21 -0
  178. package/dist/packages/teaching/src/spec/findings.d.ts +39 -0
  179. package/dist/packages/teaching/src/spec/index.d.ts +14 -0
  180. package/dist/packages/teaching/src/spec/lesson-plan.d.ts +43 -0
  181. package/dist/packages/teaching/src/spec/validate-plan.d.ts +11 -0
  182. package/dist/packages/teaching/src/time/clock.d.ts +7 -0
  183. package/dist/packages/teaching/src/time/tween.d.ts +19 -0
  184. package/dist/packages/teaching/src/time/use-tween.d.ts +6 -0
  185. package/dist/param-BE3VMSkH.js +450 -0
  186. package/dist/{pierre-diff-DlvjyuJn.js → pierre-diff-aGyQK5xK.js} +1 -1
  187. package/dist/{plot-axes-DJkLW4wk.js → plot-axes-D5S9BnBa.js} +1 -1
  188. package/dist/{plot-layout-BEuoOHbs.js → plot-layout-Bqe4-0qZ.js} +4 -3
  189. package/dist/{plot-marks-A64v7aTw.js → plot-marks-FVsbFkUs.js} +18 -15
  190. package/dist/{plot-surface-CJTIqtck.js → plot-surface-DON6WUmk.js} +11 -11
  191. package/dist/{plot-width-DcqtSgzb.js → plot-width-D3hTycYX.js} +1 -1
  192. package/dist/{reference-lines-CWA8VeUR.js → reference-lines-hjuD1rRZ.js} +2 -2
  193. package/dist/scene-BP0Ue0R5.js +4938 -0
  194. package/dist/scene.js +1 -0
  195. package/dist/{slope-chart-DT22h_ym.js → slope-chart-C8eeSgL4.js} +7 -7
  196. package/dist/{src-CpdJlDhO.js → src-9EJskqB_.js} +73 -31
  197. package/dist/{src-D5NXRJZe.js → src-B2rgpWap.js} +48 -14
  198. package/dist/{src-BPTDJqt0.js → src-Ci8DeY8J.js} +1 -1
  199. package/dist/{src-CGc_hjxJ.js → src-DFW49IAs.js} +143 -111
  200. package/dist/{src-1EHkSFS-.js → src-Dxs3Buo_.js} +205 -139
  201. package/dist/{src-CExIrXPC.js → src-npqwq3Sa.js} +1 -1
  202. package/dist/styles2.css +542 -21
  203. package/dist/{time-series-IB3CB93O.js → time-series-BL933QyA.js} +787 -715
  204. package/dist/{token-heatmap-C00DnoNO.js → token-heatmap-BB65awva.js} +4 -4
  205. package/dist/{token-predictions-Cxx29iDr.js → token-predictions-Pa8eUGan.js} +6 -6
  206. package/dist/transport-DzyxVXbL.js +715 -0
  207. package/dist/{tree-diagram-DsckNKaW.js → tree-diagram-DJhKBiia.js} +6 -6
  208. package/dist/{treemap-9_DpLCW9.js → treemap-CxxgABUg.js} +5 -5
  209. package/dist/use-tween-5HZ55_9d.js +72 -0
  210. package/dist/{violin-plot-BhPHKXsN.js → violin-plot-CoAEF_7Z.js} +7 -6
  211. package/dist/{waterfall-CGksuTy5.js → waterfall-DdoEXEkT.js} +7 -7
  212. package/package.json +30 -5
  213. package/recipes/counting-cards.tsx +656 -0
  214. package/recipes/explorable-essay.tsx +172 -0
  215. package/skills/extend-elements/SKILL.md +21 -0
  216. package/skills/plan-lesson/SKILL.md +86 -0
  217. package/skills/plan-lesson/references/plan-format.md +114 -0
  218. package/skills/plan-lesson/references/worked-plan.md +171 -0
  219. package/skills/review-elements/SKILL.md +4 -2
  220. package/skills/review-explainer/SKILL.md +97 -0
  221. package/skills/upgrade-elements/references/releases.md +65 -0
  222. package/skills/use-elements/SKILL.md +18 -16
  223. package/skills/use-elements/references/kits.md +9 -26
  224. package/skills/use-elements/references/teaching.md +36 -0
  225. package/skills/write-explainer/SKILL.md +112 -0
  226. package/skills/write-explainer/references/article.md +164 -0
  227. package/skills/write-explainer/references/lesson.md +148 -0
  228. package/skills/write-explainer/references/mdx.md +78 -0
  229. package/skills/write-explainer/references/scene-parts.md +273 -0
  230. package/skills/write-explainer/references/scene.md +168 -0
  231. package/skills/write-explainer/references/tutor.md +104 -0
  232. package/skills/write-explainer/references/worked-essay.md +459 -0
  233. package/templates/essay/AGENTS.md +14 -0
  234. package/templates/essay/README.md +59 -0
  235. package/templates/essay/index.html +17 -0
  236. package/templates/essay/package.template.json +21 -0
  237. package/templates/essay/plan.json +96 -0
  238. package/templates/essay/src/essay.mdx +97 -0
  239. package/templates/essay/src/figures.tsx +92 -0
  240. package/templates/essay/src/lesson.ts +83 -0
  241. package/templates/essay/src/main.tsx +53 -0
  242. package/templates/essay/src/mdx.d.ts +7 -0
  243. package/templates/essay/tsconfig.template.json +15 -0
  244. package/templates/essay/vite.config.template.txt +8 -0
  245. package/dist/kits/explainers.js +0 -452
  246. package/dist/packages/kits/src/explainers/figures.d.ts +0 -31
  247. package/dist/packages/kits/src/explainers/index.d.ts +0 -8
  248. package/dist/packages/kits/src/explainers/story-steps.d.ts +0 -46
  249. /package/dist/packages/{kits/src/explainers → teaching/src/article}/linked-target.d.ts +0 -0
  250. /package/dist/packages/{kits/src/explainers → teaching/src/lesson}/bound-value.d.ts +0 -0
package/README.md CHANGED
@@ -19,13 +19,16 @@ pnpm exec mechane-elements-catalog --install-skills .claude/skills
19
19
  ```
20
20
 
21
21
  Use `.agents/skills` or another directory for an agent that reads skills from there. Run the command again after each
22
- upgrade; it replaces the three skills with the new version's copies.
22
+ upgrade; it replaces the six skills with the new version's copies.
23
23
 
24
24
  | Skill | Use it to |
25
25
  | ---------------------------------------------------- | ------------------------------------------------------------------------ |
26
26
  | [use-elements](skills/use-elements/SKILL.md) | Choose components and build a page, with a guide for each family. |
27
27
  | [review-elements](skills/review-elements/SKILL.md) | Check a page by keyboard, read state, width, theme and agent access. |
28
28
  | [upgrade-elements](skills/upgrade-elements/SKILL.md) | Move an app to a new version, with the changes each release needs. |
29
+ | [plan-lesson](skills/plan-lesson/SKILL.md) | Plan an explorable essay as a checked lesson plan before writing code. |
30
+ | [write-explainer](skills/write-explainer/SKILL.md) | Write the essay from a valid plan with the teaching layers. |
31
+ | [review-explainer](skills/review-explainer/SKILL.md) | Review an essay as a learner, in all four views. |
29
32
  | [extend-elements](skills/extend-elements/SKILL.md) | Change the library itself. It stays in the package and is not installed. |
30
33
 
31
34
  An agent without skills can read the same files in place. Add one line to its instructions file, such as `AGENTS.md`:
@@ -149,7 +152,12 @@ Every path below belongs to `@mechane-ai/elements`. There is one package, versio
149
152
  | `/charts/transforms` | Bins, densities, fits, quantiles, ranks, smoothing, and sampling that an application calls before drawing. |
150
153
  | `/charts/plot` | The plot kernel: scales, ticks, axes, marks, and states for a chart the library lacks. |
151
154
  | `/charts/figure` | Figure specs as JSON: validate a spec, draw it, describe it, and read the chart guide. |
152
- | `/kits/explainers` | Numbered figures, linked terms, bound values, and guided steps. |
155
+ | `/lesson` | Lessons: named values with ranges, controls in prose, players, one shared clock, and tweens. |
156
+ | `/lesson/spec` | Lesson plans and defined lessons as data: checks, outlines, teaching advice, and the explainer guide. |
157
+ | `/lesson/agent` | Tutor tools, a learner trace, and guided tours over the agent bridge. |
158
+ | `/scene` | Diagrams whose objects keep their identity: nodes, wires, plane marks, cards, cells, tokens, and flows. |
159
+ | `/article` | Explorable essays: beats, figures, predictions, challenges, notes, and four views of one essay. |
160
+ | `/mdx` | An essay written as one MDX file, with every teaching part available without imports. |
153
161
  | `/kits/training` | A run dashboard, a run table, and a sweep overview. |
154
162
  | `/kits/operations` | Service health, budgets against objectives, and an incident timeline. |
155
163
  | `/kits/evaluation` | A model leaderboard, a score breakdown, and a two-model comparison. |
@@ -608,9 +616,9 @@ scale or axis.
608
616
  ### Kits
609
617
 
610
618
  A kit composes charts into a page for one domain: `/kits/training` for runs, `/kits/evaluation` for model comparison,
611
- `/kits/operations` for service health, `/kits/interpretability` for features, attribution, attention and steering, and
612
- `/kits/explainers` for long articles. A kit adds no marks. It decides which figures answer the question and shares one
613
- tone scope and one linked inspection between them. The application supplies every value. The `use-elements` skill's
619
+ `/kits/operations` for service health, `/kits/interpretability` for features, attribution, attention and steering. A kit
620
+ adds no marks. It decides which figures answer the question and shares one tone scope and one linked inspection between
621
+ them. The application supplies every value. The `use-elements` skill's
614
622
  [kits guide](skills/use-elements/references/kits.md) lists each component and the data it takes.
615
623
 
616
624
  ### Renderer limits
@@ -623,6 +631,281 @@ WebGL up to 1,000,000, and `DensityMap` draws its grid on canvas. A canvas or We
623
631
  selection, readout and text alternative as an SVG plot. The WebGL figure was measured in a headless software renderer,
624
632
  not on a GPU.
625
633
 
634
+ ## Explorable explanations
635
+
636
+ A lesson is a set of named values a reader can change, such as a batch size or a temperature, and everything that reads
637
+ them: the sentences, the controls, the figures and an agent. Six entries build an essay in layers. `/lesson` holds the
638
+ values, `/scene` draws diagrams, `/article` arranges beats of prose and figures, and `/mdx` lets one file hold the
639
+ essay. `/lesson/spec` checks a plan before any component exists, and `/lesson/agent` lets a tutor model read and move
640
+ the lesson. The idea:
641
+
642
+ - **One store.** `defineLesson` declares each param with its range, step and format, each derived value as a pure
643
+ function of the values before it, and each beat with its states as plain data. `Lesson` holds the values in one UI SDK
644
+ primitive. A number in a sentence, a slider, a figure, a player and an agent read and set the same names. A value
645
+ outside a param's range is refused with an error that names the param and its bounds.
646
+ - **States, not animations.** You say where things are. A `Scene` object given new props eases to them, a wire follows
647
+ its ends, and an object with the same `id` is the same thing in every state. Every move runs on one shared clock
648
+ (`createTween` and `useTween`), and a reader who asked for reduced motion gets the end state at once.
649
+ - **One kernel.** A `Scene` draws with the plot kernel, so a diagram has the chart's tones, readout and keyboard cursor.
650
+ Every labelled object is an item the arrow keys reach.
651
+ - **Four views of one essay.** An `Article` renders the same children as a scrolling essay, a presentation, a static
652
+ page or a beat sheet. The views differ in arrangement only.
653
+ - **Only the reader's acts count.** Predictions, challenges and hints change the reader's progress only when the reader
654
+ makes them. A change an agent makes never commits a prediction or reaches a challenge.
655
+ - **Agents use the bridge.** The lesson and the reader's progress appear in the UI SDK agent snapshot. Tutor tools, the
656
+ learner trace and tours read and act through `createAgent` and nothing else.
657
+
658
+ Define a lesson, then put its values in a sentence and a diagram. `Param` is a number the reader drags in place, and
659
+ `Value` writes a value in its declared format:
660
+
661
+ ```tsx
662
+ import { defineLesson, Lesson, Param, ParamSlider, useLesson, Value } from '@mechane-ai/elements/lesson';
663
+ import { Scene, SceneNode, SceneWire } from '@mechane-ai/elements/scene';
664
+
665
+ const lesson = defineLesson({
666
+ id: 'batch-noise',
667
+ title: 'Why a bigger batch is quieter',
668
+ params: {
669
+ batch: {
670
+ kind: 'number',
671
+ label: 'Batch size',
672
+ value: 4,
673
+ min: 1,
674
+ max: 256,
675
+ step: 1,
676
+ scale: 'log',
677
+ format: { maximumFractionDigits: 0 },
678
+ },
679
+ },
680
+ derived: {
681
+ noise: {
682
+ label: 'Gradient noise',
683
+ format: { style: 'percent', maximumFractionDigits: 0 },
684
+ from: ({ batch }) => 1 / Math.sqrt(batch),
685
+ },
686
+ },
687
+ beats: [
688
+ {
689
+ id: 'noise',
690
+ title: 'Noise falls with the square root',
691
+ goal: 'Find that four times the examples halves the noise.',
692
+ states: [
693
+ { id: 'four', label: 'Four examples', values: { batch: 4 } },
694
+ { id: 'sixty-four', label: 'Sixty-four examples', values: { batch: 64 } },
695
+ ],
696
+ },
697
+ ],
698
+ });
699
+
700
+ function BatchScene() {
701
+ const { values } = useLesson(lesson);
702
+
703
+ return (
704
+ <Scene title="From a batch to a gradient" x={[0, 2]} y={[0, 1]} height="compact">
705
+ <SceneNode id="batch" at={[0.5, 0.5]} text={`${values.batch} examples`} />
706
+ <SceneNode
707
+ id="gradient"
708
+ at={[1.5, 0.5]}
709
+ shape="pill"
710
+ text="gradient"
711
+ label={`The averaged gradient, ${Math.round(values.noise * 100)}% as noisy as one example`}
712
+ tone={values.noise > 0.5 ? 'negative' : 'positive'}
713
+ />
714
+ <SceneWire from="batch" to="gradient" label="The examples are averaged" />
715
+ </Scene>
716
+ );
717
+ }
718
+
719
+ export function BatchPage() {
720
+ return (
721
+ <Lesson lesson={lesson} locale="en-US" shouldSyncUrl>
722
+ <p>
723
+ A gradient from <Param name="batch" /> examples is <Value name="noise" /> as noisy as one example.
724
+ </p>
725
+ <BatchScene />
726
+ <ParamSlider name="batch" />
727
+ </Lesson>
728
+ );
729
+ }
730
+ ```
731
+
732
+ A state is the whole picture. `showState` (and `show` from `useLesson`) sets every param the state does not name back to
733
+ the lesson's opening value, so a state looks the same live, on the beat sheet and in a tour. `setMany` changes some
734
+ params and keeps the rest.
735
+
736
+ `useLesson(lesson)` types the values from the definition, so `values.noise` is a number and `set('batch', 'high')` does
737
+ not compile. `shouldSyncUrl` keeps the values in the address bar, and `storageKey` keeps them across visits. A `Scene`
738
+ without a `locale` takes the locale of the `Lesson` around it.
739
+
740
+ An `Article` renders the `Lesson` for you and arranges its children as beats. A `Beat` takes the id of a beat the lesson
741
+ declares, so its title, tutor notes, reveal steps and states stay in the definition. `Figure` numbers a figure, gives it
742
+ a caption and a text description, and `Predict` asks the reader to commit a guess before the answer shows:
743
+
744
+ ```tsx
745
+ import { Article, Beat, Figure, Predict } from '@mechane-ai/elements/article';
746
+
747
+ export function BatchEssay() {
748
+ return (
749
+ <Article
750
+ lesson={lesson}
751
+ locale="en-US"
752
+ title="Why a bigger batch is quieter"
753
+ summary="The gradient of a batch is an average. See how its noise falls as the batch grows."
754
+ storageKey="batch-noise"
755
+ >
756
+ <Beat id="noise">
757
+ <p>
758
+ With <Param name="batch" /> examples, the gradient is <Value name="noise" /> as noisy as one example.
759
+ </p>
760
+ <Predict
761
+ id="quadruple"
762
+ prompt="Four times the examples: how does the noise change?"
763
+ options={[
764
+ { id: 'quarter', label: 'It falls to a quarter' },
765
+ { id: 'half', label: 'It halves' },
766
+ ]}
767
+ answer="half"
768
+ >
769
+ <p>Noise falls with the square root of the batch size, so four times the examples halves it.</p>
770
+ </Predict>
771
+ <Figure
772
+ id="batch-scene"
773
+ caption="A batch of examples is averaged into one gradient."
774
+ description="Two boxes joined by an arrow: the batch of examples and the gradient they average into."
775
+ >
776
+ <BatchScene />
777
+ </Figure>
778
+ </Beat>
779
+ </Article>
780
+ );
781
+ }
782
+ ```
783
+
784
+ Give `Article` a `view` of `'article'` (the default scrolling essay with a contents list), `'present'` (one beat at a
785
+ time; Right or Space goes on, and a beat opens at its first declared state), `'static'` (every beat open at its first
786
+ state, each figure followed by its description, no script needed) or `'sheet'` (every beat in each declared state, each
787
+ figure scaled to fit, its tutor notes, and a list of checks). The sheet names a beat with no figure, a figure with no
788
+ description, a player with no `Transport` and a sentence control that changes no figure.
789
+
790
+ `recipes/counting-cards.tsx` (story `Recipes/Counting Cards`) is a full example on every layer, and
791
+ `recipes/explorable-essay.tsx` is a short one.
792
+
793
+ ### Choose an entry
794
+
795
+ Every part has a question it answers; `explainerGuide` from `/lesson/spec` lists them with when to use each and an
796
+ example. The
797
+ [teaching guide](https://github.com/mechane-ai/mechane/blob/main/workspaces/core/docs/ui-teaching.md#choose-a-part)
798
+ writes the guide out.
799
+
800
+ | Entry | Main exports | The author asks |
801
+ | --------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
802
+ | `/lesson` | `defineLesson`, `Lesson`, `useLesson`, `Param`, `Value`, `ParamSlider`, `Playback`, `Transport`, `createTween` | Which values can the reader change, and who reads them? |
803
+ | `/scene` | `Scene`, `SceneNode`, `SceneWire`, `SceneAxes`, `SceneCurve`, `SceneCard`, `SceneCells`, `SceneFlow`, `MorphScope` | What is where, and what moves when a value changes? |
804
+ | `/article` | `Article`, `Beat`, `Figure`, `Scrolly`, `Predict`, `Challenge`, `Term`, `DiagramPart`, `Footnote`, `References` | What is the order of the argument, and what does the reader do? |
805
+ | `/mdx` | `Essay`, `essayComponents` | Is the essay mostly prose? |
806
+ | `/lesson/spec` | `validateLessonPlan`, `checkLesson`, `describeLesson`, `lessonWalk`, `explainerGuide` | Is the plan sound before any component exists? |
807
+ | `/lesson/agent` | `tutorTools`, `createLearnerTrace`, `summarizeTrace`, `playTour`, `validateTour`, `tourFromTrace` | What can a tutor read and do beside the reader? |
808
+
809
+ ### Write an essay as MDX
810
+
811
+ `/mdx` is for an essay that is mostly prose. `Essay` renders a compiled `.mdx` file inside an `Article`, and
812
+ `essayComponents` lets the file use Markdown and every teaching part with no imports. The application brings its own MDX
813
+ compiler, such as `@mdx-js/rollup`, and a math typesetter if it wants one. Start from the starter:
814
+
815
+ ```sh
816
+ pnpm exec mechane-elements-catalog --new-essay my-essay
817
+ cd my-essay
818
+ pnpm install
819
+ pnpm dev
820
+ ```
821
+
822
+ The command copies the starter into a new or empty directory, names the package after it and pins `^` this version of
823
+ Elements. It writes `package.json`, `tsconfig.json`, `vite.config.ts`, `index.html`, `plan.json` (the lesson as plain
824
+ data), `AGENTS.md`, `README.md` and a `src` folder with `lesson.ts`, `figures.tsx`, `essay.mdx`, `main.tsx` and
825
+ `mdx.d.ts`. `pnpm dev` serves the essay at `/`, and `?view=present`, `?view=static` and `?view=sheet` show the other
826
+ views of the same file. In `main.tsx`, `<Essay lesson={lesson} content={Content} locale="en-US" {...meta} />` renders
827
+ the file, and `Content` and `meta` come from `import Content, { meta } from './essay.mdx'`.
828
+
829
+ For math, an essay file uses `<TeX>` (the article's math part, exported as `TeX`), and `Article` typesets it through its
830
+ `math` prop. In the file, a sentence reads `At a rate of <Param name="rate" /> the loss is <Value name="loss" />.` and a
831
+ figure is `<Figure id="curve" caption="…" description="…">…</Figure>` inside `<Beat id="…">`. The `view` address
832
+ parameter chooses the view unless `Essay` gets a `view` prop.
833
+
834
+ ### Plan and check
835
+
836
+ Draft the lesson as plain JSON before writing components. A `LessonPlan` names the audience, the one idea, the params,
837
+ the derived values and the beats, and each beat may name the figure it shows and what it asks of the reader.
838
+ `validateLessonPlan` returns every finding with a path and a sentence, and `checkLesson` gives teaching advice on a
839
+ defined lesson. An error means `defineLesson` would refuse it. Advice, such as a beat with no goal or a beat that
840
+ introduces two params at once, you may decline:
841
+
842
+ ```ts
843
+ import { checkLesson, validateLessonPlan } from '@mechane-ai/elements/lesson/spec';
844
+
845
+ const result = validateLessonPlan(plan);
846
+
847
+ for (const finding of [...result.findings, ...checkLesson(lesson)]) {
848
+ console.log(`${finding.severity} at ${finding.path}: ${finding.message}`);
849
+ }
850
+ ```
851
+
852
+ Three skills cover this work: `plan-lesson`, `write-explainer` and `review-explainer`. `--install-skills` installs them
853
+ with the others.
854
+
855
+ ### Teach with an agent
856
+
857
+ The lesson appears in the UI SDK agent snapshot as a `lesson` entry named by the lesson's title, with the values, the
858
+ beat, the reveal step and the running player. Its actions are `setParam`, `setParams`, `showState`, `reset`, `setBeat`,
859
+ `next`, `previous`, `play` and `pause`. An `Article` adds a `lesson-progress` entry that an agent can read and cannot
860
+ change. `/lesson/agent` builds on that bridge:
861
+
862
+ - `tutorTools({ agent, lesson, locale, article, answers })` returns tools a model can call: `read_outline`,
863
+ `read_place`, `set_param`, `set_params`, `show_state`, `go_to_beat`, `next`, `previous`, `play`, `pause` and
864
+ `inspect_figure`. Each has a name, a description, an `inputSchema` as JSON Schema and an async `run` that returns a
865
+ plain result.
866
+ - `answerSources(articleOutline(children))` from `/article` maps each `Predict` that takes its answer from a lesson
867
+ value (`answerFrom`) to that value. Pass it as `answers`, and the tools leave the value out until the reader commits.
868
+ - `createLearnerTrace` records what the reader did, and `summarizeTrace` writes it as plain facts for a tutor prompt.
869
+ Changes an agent makes are left out.
870
+ - `playTour` plays a list of steps (`beat`, `step`, `state`, `values`, `say`, `hold`) through the bridge and pauses when
871
+ the reader acts. `validateTour` checks a tour against its lesson, and `tourFromTrace` turns a recorded demonstration
872
+ into one.
873
+
874
+ ```ts
875
+ import { createAgent } from '@mechane-ai/elements/agent';
876
+ import { answerSources, articleOutline } from '@mechane-ai/elements/article';
877
+ import type { LessonTour } from '@mechane-ai/elements/lesson/agent';
878
+ import {
879
+ createLearnerTrace,
880
+ playTour,
881
+ summarizeTrace,
882
+ tutorTools,
883
+ validateTour,
884
+ } from '@mechane-ai/elements/lesson/agent';
885
+
886
+ const agent = createAgent();
887
+ const title = 'Why a bigger batch is quieter';
888
+
889
+ // `essay` is the node passed as the children of the `Article`.
890
+ const answers = answerSources(articleOutline(essay));
891
+ const tools = tutorTools({ agent, lesson, locale: 'en-US', article: title, answers });
892
+ const trace = createLearnerTrace({ agent, lesson, article: title });
893
+
894
+ const tour: LessonTour = [
895
+ { beat: 'noise', state: 'four', say: 'Four examples give a noisy gradient.', hold: 'regular' },
896
+ { beat: 'noise', values: { batch: 64 }, say: 'Sixty-four examples cut the noise to an eighth.', hold: 'long' },
897
+ ];
898
+
899
+ const findings = validateTour(tour, lesson);
900
+ const player = playTour({ agent, lesson, tour, onSay: (line) => console.log(line) });
901
+ const facts = summarizeTrace({ record: trace.read(), lesson, locale: 'en-US', answers });
902
+ ```
903
+
904
+ A tutor model calls `tools[0].run()` to read the outline and the others to act. The model never receives a `Predict`
905
+ answer before the reader commits it. The
906
+ [teaching guide](https://github.com/mechane-ai/mechane/blob/main/workspaces/core/docs/ui-teaching.md) has the full
907
+ reference for every entry.
908
+
626
909
  ## Develop and release
627
910
 
628
911
  From `workspaces/core`:
@@ -1,12 +1,19 @@
1
- import { cpSync, readFileSync, rmSync } from 'node:fs';
2
- import { join, resolve } from 'node:path';
1
+ import { cpSync, existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { basename, join, relative, resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { parseArgs } from 'node:util';
5
5
 
6
6
  const ignored = new Set(['a', 'an', 'and', 'are', 'build', 'for', 'in', 'of', 'on', 'page', 'the', 'to', 'with']);
7
7
 
8
8
  /** The skills for an application that uses Elements. The package also ships a skill for changing the library. */
9
- const appSkills = ['use-elements', 'review-elements', 'upgrade-elements'];
9
+ const appSkills = [
10
+ 'use-elements',
11
+ 'review-elements',
12
+ 'upgrade-elements',
13
+ 'plan-lesson',
14
+ 'write-explainer',
15
+ 'review-explainer',
16
+ ];
10
17
 
11
18
  /** @import {Catalog} from './catalog.d.mts' */
12
19
 
@@ -29,6 +36,81 @@ function installSkills(catalog, directory) {
29
36
  return { package: catalog.package, version: catalog.version, installed };
30
37
  }
31
38
 
39
+ const gitignore = 'node_modules\ndist\n';
40
+
41
+ /** Starter files kept under another name so the repository does not read them as its own, and the names they take. */
42
+ const renamedFiles = {
43
+ 'package.template.json': 'package.json',
44
+ 'tsconfig.template.json': 'tsconfig.json',
45
+ 'vite.config.template.txt': 'vite.config.ts',
46
+ };
47
+
48
+ /**
49
+ * The package name an npm package may have, taken from the name of the directory it lives in.
50
+ *
51
+ * @param {string} directory The new project directory.
52
+ */
53
+ function packageNameOf(directory) {
54
+ const name = basename(directory)
55
+ .toLowerCase()
56
+ .replaceAll(/[^a-z0-9._-]+/g, '-')
57
+ .replaceAll(/^[._-]+|-+$/g, '');
58
+
59
+ return name === '' ? 'essay' : name;
60
+ }
61
+
62
+ /**
63
+ * Copies the essay starter into a new directory and names the package after it. The starter pins this version of
64
+ * Elements, and the directory must not exist or must be empty.
65
+ *
66
+ * @param {Catalog} catalog The catalog built from the public package.
67
+ * @param {string} directory The new project directory.
68
+ */
69
+ function newEssay(catalog, directory) {
70
+ const target = resolve(directory);
71
+
72
+ if (existsSync(target) && readdirSync(target).length > 0) {
73
+ throw new Error(`Choose a new or empty directory: ${directory} already has files.`);
74
+ }
75
+
76
+ cpSync(fileURLToPath(new URL('../templates/essay', import.meta.url)), target, { recursive: true });
77
+
78
+ for (const [from, to] of Object.entries(renamedFiles)) {
79
+ renameSync(join(target, from), join(target, to));
80
+ }
81
+
82
+ const name = packageNameOf(target);
83
+ const manifest = join(target, 'package.json');
84
+
85
+ writeFileSync(
86
+ manifest,
87
+ readFileSync(manifest, 'utf8')
88
+ .replaceAll('__PACKAGE_NAME__', name)
89
+ .replaceAll('__ELEMENTS_VERSION__', `^${catalog.version}`),
90
+ );
91
+ writeFileSync(join(target, '.gitignore'), gitignore);
92
+
93
+ const written = readdirSync(target, { recursive: true, withFileTypes: true })
94
+ .filter((entry) => entry.isFile())
95
+ .map((entry) => relative(target, join(entry.parentPath, entry.name)))
96
+ .toSorted();
97
+
98
+ return {
99
+ package: catalog.package,
100
+ version: catalog.version,
101
+ name,
102
+ directory: target,
103
+ written,
104
+ next: [
105
+ `cd ${directory}`,
106
+ 'pnpm install',
107
+ 'pnpm dev',
108
+ 'pnpm skills',
109
+ 'Open /?view=sheet to read the beat sheet and its checks.',
110
+ ],
111
+ };
112
+ }
113
+
32
114
  /**
33
115
  * @param {Catalog} catalog The catalog built from the public package.
34
116
  * @param {string} query Normalized task or public export name.
@@ -71,28 +153,38 @@ function lookup(catalog, query) {
71
153
  const usage = [
72
154
  'Usage: mechane-elements-catalog [task or public export name]',
73
155
  ' mechane-elements-catalog --install-skills <directory>',
156
+ ' mechane-elements-catalog --new-essay <directory>',
74
157
  '',
75
158
  'With a task, prints the matching recipes, public exports and the best example as JSON.',
76
159
  'With --install-skills, copies the Elements skills into an agent skills directory such as .claude/skills.',
160
+ 'With --new-essay, copies the explorable essay starter into a new or empty directory and prints what it wrote.',
77
161
  ].join('\n');
78
162
 
79
163
  /** @param {Catalog} catalog The catalog built from the public package. */
80
164
  export function runCatalog(catalog) {
81
165
  const { positionals, values } = parseArgs({
82
166
  allowPositionals: true,
83
- options: { 'help': { type: 'boolean', short: 'h', default: false }, 'install-skills': { type: 'string' } },
167
+ options: {
168
+ 'help': { type: 'boolean', short: 'h', default: false },
169
+ 'install-skills': { type: 'string' },
170
+ 'new-essay': { type: 'string' },
171
+ },
84
172
  });
85
173
 
86
- const directory = values['install-skills'];
87
-
88
174
  if (values.help) {
89
175
  process.stdout.write(`${usage}\n`);
90
- } else {
91
- const result =
92
- directory === undefined
93
- ? lookup(catalog, positionals.join(' ').trim().toLowerCase())
94
- : installSkills(catalog, directory);
95
176
 
96
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
177
+ return;
178
+ }
179
+
180
+ const skills = values['install-skills'];
181
+ const essay = values['new-essay'];
182
+
183
+ if (skills !== undefined) {
184
+ process.stdout.write(`${JSON.stringify(installSkills(catalog, skills), null, 2)}\n`);
185
+ } else if (essay === undefined) {
186
+ process.stdout.write(`${JSON.stringify(lookup(catalog, positionals.join(' ').trim().toLowerCase()), null, 2)}\n`);
187
+ } else {
188
+ process.stdout.write(`${JSON.stringify(newEssay(catalog, essay), null, 2)}\n`);
97
189
  }
98
190
  }
package/dist/ai.js CHANGED
@@ -1,9 +1,9 @@
1
- import { D as e, O as t, T as n, h as r, i, k as a, m as o, t as s, v as c } from "./src-CpdJlDhO.js";
2
- import { t as l } from "./code-block-DioAM2bZ.js";
3
- import { a as u } from "./src-CGc_hjxJ.js";
4
- import { t as d } from "./content-link-NWuHp5rC.js";
1
+ import { D as e, O as t, T as n, h as r, i, k as a, m as o, t as s, v as c } from "./src-9EJskqB_.js";
2
+ import { t as l } from "./code-block-BZsY2sh3.js";
3
+ import { l as u } from "./src-DFW49IAs.js";
4
+ import { t as d } from "./content-link-PnpcnTCx.js";
5
5
  import { r as f, t as p } from "./src-na2DdkKI.js";
6
- import { c as m, d as h } from "./src-CExIrXPC.js";
6
+ import { c as m, d as h } from "./src-npqwq3Sa.js";
7
7
  import { i as ee, t as g } from "./forms-CEbwzlRR.js";
8
8
  import { t as te } from "./accessibility-P89UG9-r.js";
9
9
  import { r as _ } from "./control-styles-D3q_Qyxi.js";