@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa

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 (229) hide show
  1. package/README.md +12 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +47 -9
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +32 -0
  14. package/api/build/kit/words.mjs +49 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +48 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +491 -186
  34. package/api/render/render.doc.mjs +10 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +38 -0
  46. package/api/theme/build/build.mjs +144 -24
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +35 -0
  50. package/api/theme-edit/_adapter.mjs +477 -41
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1077 -200
  53. package/api/theme-edit/_compiler.mjs +9 -0
  54. package/api/theme-edit/_context.mjs +60 -3
  55. package/api/theme-edit/_css.mjs +21 -1
  56. package/api/theme-edit/_edit.d.mts +22 -0
  57. package/api/theme-edit/_edit.mjs +932 -82
  58. package/api/theme-edit/_how-commands.d.mts +49 -0
  59. package/api/theme-edit/_how-commands.mjs +386 -1
  60. package/api/theme-edit/_how-question.d.mts +56 -0
  61. package/api/theme-edit/_how-question.mjs +3509 -168
  62. package/api/theme-edit/_how.mjs +104 -4
  63. package/api/theme-edit/_marks.d.mts +31 -5
  64. package/api/theme-edit/_marks.mjs +57 -5
  65. package/api/theme-edit/_normal.d.mts +137 -0
  66. package/api/theme-edit/_normal.mjs +612 -0
  67. package/api/theme-edit/_palette.mjs +10 -4
  68. package/api/theme-edit/_parts.d.mts +4 -0
  69. package/api/theme-edit/_parts.mjs +28 -2
  70. package/api/theme-edit/_preview-app.d.mts +7 -1
  71. package/api/theme-edit/_preview-app.mjs +191 -15
  72. package/api/theme-edit/_preview.d.mts +64 -8
  73. package/api/theme-edit/_preview.mjs +401 -83
  74. package/api/theme-edit/_settings.d.mts +139 -5
  75. package/api/theme-edit/_settings.mjs +1659 -112
  76. package/api/theme-edit/_tables.mjs +17 -1
  77. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  78. package/api/theme-edit/theme-edit.type.mjs +4 -1
  79. package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
  80. package/assets/codemods/run-codemod.mjs +73 -6
  81. package/assets/codemods/transforms/next/index.mjs +11 -1
  82. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  83. package/assets/docs/author-a-theme.doc.mjs +1 -0
  84. package/assets/docs/theme.doc.dense.mjs +2 -2
  85. package/assets/docs/theme.doc.mjs +1 -1
  86. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  87. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  88. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  89. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  90. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  91. package/assets/docs/use-a-theme.doc.mjs +1 -1
  92. package/assets/docs.generated.json +2 -2
  93. package/assets/self-audit.generated.json +1 -1
  94. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  95. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  96. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  97. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  98. package/assets/templates/components.generated.json +1 -1
  99. package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
  100. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  101. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  102. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  103. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  104. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  105. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  106. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  107. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  108. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  110. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  111. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  112. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  113. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  114. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  115. package/assets/templates/pages/editor/template.doc.mjs +1 -7
  116. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  117. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  118. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  119. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  120. package/assets/templates/pages/ide/page.tsx +24 -2
  121. package/assets/templates/pages/library/template.doc.mjs +4 -1
  122. package/assets/templates/pages/login/template.doc.mjs +2 -1
  123. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  124. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  125. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  126. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  127. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  128. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  129. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  130. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  131. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  132. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  133. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  134. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  135. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  136. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  137. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  138. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  139. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
  140. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  141. package/authoring/debug/parse.d.mts +3 -3
  142. package/authoring/doctypes/_schema.d.mts +3 -3
  143. package/authoring/doctypes/command/command.doc.mjs +1 -1
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +9 -0
  146. package/clients/cli/bin/astryx.mjs +6 -9
  147. package/clients/cli/build-id.generated.json +1 -1
  148. package/clients/cli/commands/component.doc.mjs +1 -1
  149. package/clients/cli/commands/component.mjs +20 -2
  150. package/clients/cli/commands/docs.doc.mjs +7 -1
  151. package/clients/cli/commands/docs.mjs +3 -1
  152. package/clients/cli/commands/doctor.mjs +22 -14
  153. package/clients/cli/commands/experimental/render.mjs +32 -1
  154. package/clients/cli/commands/experimental/theme.mjs +27 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  156. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  157. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  158. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  159. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  160. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  161. package/clients/cli/commands/search.doc.mjs +2 -1
  162. package/clients/cli/commands/search.mjs +6 -1
  163. package/clients/cli/commands/template.mjs +4 -2
  164. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  165. package/clients/cli/commands/theme.doc.mjs +1 -1
  166. package/clients/cli/commands/theme.mjs +138 -3
  167. package/clients/cli/commands/upgrade.mjs +42 -7
  168. package/clients/cli/index.mjs +1 -1
  169. package/clients/cli/lib/component-format.mjs +205 -98
  170. package/clients/cli/lib/hook-format.mjs +9 -19
  171. package/clients/cli/manifest.generated.json +1 -1
  172. package/foundation/agent-docs/agent-docs.mjs +1 -1
  173. package/foundation/config/theme-state.d.mts +13 -1
  174. package/foundation/config/theme-state.mjs +47 -7
  175. package/foundation/discovery/component-discovery.d.mts +11 -0
  176. package/foundation/discovery/component-discovery.mjs +27 -2
  177. package/foundation/discovery/component-replacement.mjs +130 -1
  178. package/foundation/discovery/entry-name-files.d.mts +43 -0
  179. package/foundation/discovery/entry-name-files.mjs +264 -0
  180. package/foundation/discovery/hook-discovery.d.mts +8 -2
  181. package/foundation/discovery/hook-discovery.mjs +20 -7
  182. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  183. package/foundation/discovery/runner-allowlist.mjs +2 -0
  184. package/foundation/discovery/template-adapter.d.mts +52 -0
  185. package/foundation/discovery/template-adapter.mjs +169 -0
  186. package/foundation/discovery/theme-imports.d.mts +14 -0
  187. package/foundation/discovery/theme-imports.mjs +43 -1
  188. package/foundation/doc-compiler/import.mjs +7 -1
  189. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  190. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  191. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  192. package/foundation/fs/cache-eviction.d.mts +21 -0
  193. package/foundation/fs/cache-eviction.mjs +73 -0
  194. package/foundation/fs/gather-cache.d.mts +25 -4
  195. package/foundation/fs/gather-cache.mjs +138 -52
  196. package/foundation/fs/jiti-cache.d.mts +19 -1
  197. package/foundation/fs/jiti-cache.mjs +130 -6
  198. package/foundation/fs/kept-tree.d.mts +60 -0
  199. package/foundation/fs/kept-tree.mjs +154 -0
  200. package/foundation/fs/module-loader.d.mts +18 -2
  201. package/foundation/fs/module-loader.mjs +92 -20
  202. package/foundation/identity/provider-identity.d.mts +6 -0
  203. package/foundation/identity/provider-identity.mjs +10 -1
  204. package/foundation/render/file-header.d.mts +66 -0
  205. package/foundation/render/file-header.mjs +118 -0
  206. package/foundation/render/host-answer.d.mts +18 -0
  207. package/foundation/render/host-answer.mjs +46 -0
  208. package/foundation/render/host-exit.d.mts +1 -0
  209. package/foundation/render/host-exit.mjs +6 -1
  210. package/foundation/render/html-reader.d.mts +55 -2
  211. package/foundation/render/html-reader.mjs +145 -26
  212. package/foundation/render/markup-edits.d.mts +57 -0
  213. package/foundation/render/markup-edits.mjs +182 -0
  214. package/foundation/render/page-host.mjs +29 -12
  215. package/foundation/render/page-worker.mjs +79 -10
  216. package/foundation/render/render-page.d.mts +34 -2
  217. package/foundation/render/render-page.mjs +210 -29
  218. package/foundation/render/source-block.d.mts +73 -6
  219. package/foundation/render/source-block.mjs +170 -19
  220. package/foundation/render/ts-paths.d.mts +4 -1
  221. package/foundation/render/ts-paths.mjs +7 -3
  222. package/foundation/response/error-codes.d.mts +2 -1
  223. package/foundation/response/error-codes.doc.mjs +7 -1
  224. package/foundation/response/error-codes.mjs +7 -0
  225. package/foundation/text/string-utils.d.mts +3 -2
  226. package/foundation/text/string-utils.mjs +16 -3
  227. package/foundation/text/suggest-order.d.mts +9 -0
  228. package/foundation/text/suggest-order.mjs +13 -0
  229. package/package.json +6 -6
@@ -7,14 +7,25 @@
7
7
  * it, and its JSON holds each file base64-encoded with its SHA-256, so no text
8
8
  * in the source (`</script>` included) can end the block early.
9
9
  *
10
+ * The block's `version` is the render format. A CLI reads every format up to
11
+ * its own. The number goes up only when a CLI that reads the current number
12
+ * would read a new file wrong; a new optional field keeps the number, so older
13
+ * CLIs keep reading newer files. A CLI that meets a higher number refuses and
14
+ * names the CLI version that wrote the file.
15
+ *
10
16
  * @position foundation/render — used by render-page.mjs and the render subject
11
17
  */
12
18
 
13
19
  import {createHash} from 'node:crypto';
20
+ import {isValidSemver} from '../env/semver.mjs';
21
+ import {decode, readTag, scanHtml} from './html-reader.mjs';
14
22
 
15
23
  /** The script type of the embedded-source block. */
16
24
  export const SOURCE_TYPE = 'application/x-astryx-source';
17
25
 
26
+ /** The render format this CLI writes, and the newest one it reads. */
27
+ export const RENDER_FORMAT = 1;
28
+
18
29
  /**
19
30
  * @typedef {object} EmbeddedFile
20
31
  * @property {string} path - Path relative to the folder that holds every embedded file, `/`-separated; the page itself first.
@@ -23,31 +34,53 @@ export const SOURCE_TYPE = 'application/x-astryx-source';
23
34
  */
24
35
 
25
36
  /**
26
- * @typedef {object} EmbeddedSource
27
- * @property {1} version
28
- * @property {string} entry - The page's file name.
29
- * @property {EmbeddedFile[]} files
37
+ * What the render records about itself beside the files. Every field is
38
+ * optional: files from older CLIs have none of them.
39
+ * @typedef {object} RenderRecord
40
+ * @property {string} [cli] - The version of the CLI that rendered the file.
41
+ * @property {string} [page] - The page's path from its project's root, `/`-separated.
42
+ * @property {string} [title] - The title given with --title, which a render again needs too.
43
+ * @property {Record<string, string>} [packages] - The packages the page rendered with, by name: their versions.
44
+ * @property {{sha256: string, style?: string, text?: string}} [markup] - The page as rendered, so a reverse can tell what changed after the render: the SHA-256 of the markup in <body> and of the <style> element, and `text`, the base64 of the JSON `{title, runs}` (the title and the markup's runs of text in order). The text stays encoded so that a find-and-replace over the page's text cannot change the record too.
45
+ */
46
+
47
+ /**
48
+ * @typedef {RenderRecord & {version: number, entry: string, files: EmbeddedFile[]}} EmbeddedSource
30
49
  */
31
50
 
32
- /** @param {Buffer} bytes */
51
+ /** @param {Buffer | string} bytes */
33
52
  export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
34
53
 
54
+ /**
55
+ * Text as a browser's HTML parser reads it: a CR LF pair or a lone CR is a
56
+ * line feed. A copy whose line ends a mailer, an editor or git changed reads
57
+ * the same.
58
+ * @param {string} text
59
+ */
60
+ export const asParsed = text => text.replace(/\r\n?/g, '\n');
61
+
35
62
  /**
36
63
  * The data block for a page's files.
37
64
  * @param {string} entry the page's file name
38
65
  * @param {{path: string, bytes: Buffer}[]} files the page first
66
+ * @param {RenderRecord} [record] what the render records about itself
39
67
  * @returns {string}
40
68
  */
41
- export function sourceBlock(entry, files) {
69
+ export function sourceBlock(entry, files, record = {}) {
42
70
  /** @type {EmbeddedSource} */
43
71
  const payload = {
44
- version: 1,
72
+ version: RENDER_FORMAT,
45
73
  entry,
74
+ ...(record.cli ? {cli: record.cli} : {}),
75
+ ...(record.page ? {page: record.page} : {}),
76
+ ...(record.title === undefined ? {} : {title: record.title}),
77
+ ...(record.packages ? {packages: record.packages} : {}),
46
78
  files: files.map(f => ({
47
79
  path: f.path,
48
80
  sha256: sha256(f.bytes),
49
81
  base64: f.bytes.toString('base64'),
50
82
  })),
83
+ ...(record.markup ? {markup: record.markup} : {}),
51
84
  };
52
85
  const json = JSON.stringify(payload)
53
86
  .replace(/</g, '\\u003c')
@@ -56,31 +89,105 @@ export function sourceBlock(entry, files) {
56
89
  return `<script type="${SOURCE_TYPE}">${json}</script>`;
57
90
  }
58
91
 
92
+ /**
93
+ * The parts of a rendered file a reverse reads, found as a browser finds them:
94
+ * outside comments (the note is one, and it may quote a path that looks like
95
+ * a tag) and outside the text of a style, script, title or textarea element
96
+ * (a stylesheet may hold any text).
97
+ * @param {string} html
98
+ * @returns {{title: string | null, style: string | null, body: number}} the
99
+ * text of the first title and the first style element before <body>, and
100
+ * where the content of <body> starts (-1 without a <body> tag)
101
+ */
102
+ function pageParts(html) {
103
+ /** @type {string | null} */
104
+ let title = null;
105
+ /** @type {string | null} */
106
+ let style = null;
107
+ let styleStart = -1;
108
+ let titleNext = false;
109
+ for (const token of scanHtml(html)) {
110
+ if (token.kind === 'start') {
111
+ if (token.tag === 'body') return {title, style, body: token.end};
112
+ titleNext = token.tag === 'title' && title === null;
113
+ if (token.tag === 'style' && styleStart < 0) styleStart = token.start;
114
+ } else if (token.kind === 'raw' && titleNext) {
115
+ title = html.slice(token.start, token.end);
116
+ titleNext = false;
117
+ } else if (token.kind === 'end' && token.tag === 'style' && styleStart >= 0 && style === null) {
118
+ style = html.slice(styleStart, token.end);
119
+ }
120
+ }
121
+ return {title, style, body: -1};
122
+ }
123
+
124
+ /**
125
+ * Whether a script tag's attributes give it the source type. A MIME type is
126
+ * matched without regard to letter case.
127
+ * @param {Array<[string, string]>} attrs
128
+ */
129
+ const isSourceType = attrs => {
130
+ const type = attrs.find(([name]) => name === 'type')?.[1];
131
+ return type !== undefined && decode(type).trim().toLowerCase() === SOURCE_TYPE;
132
+ };
133
+
134
+ /**
135
+ * Every embedded-source block in a file's body, in order: each script
136
+ * element whose type is the source type, its tag read as a browser reads a
137
+ * tag, with its attributes in any order, quoted or not, in any letter case
138
+ * (a minifier rewrites it so). Every `<script` from the start of the body on
139
+ * is read this way, inside a comment or other text too, so a hand edit that
140
+ * leaves a comment or a textarea open before the block does not hide it. The
141
+ * note in <head> may quote a title or a path with any text, so the search
142
+ * starts at <body>.
143
+ * @param {string} html
144
+ * @returns {{index: number, json: string, closed: boolean}[]} where each
145
+ * opening tag starts, the text of the block, and whether its end tag is
146
+ * there (a file cut inside the block has none)
147
+ */
148
+ const blocksIn = html => {
149
+ /** @type {{index: number, json: string, closed: boolean}[]} */
150
+ const blocks = [];
151
+ const opening = /<script(?=[\t\n\f\r />])/gi;
152
+ opening.lastIndex = Math.max(0, pageParts(html).body);
153
+ for (let m = opening.exec(html); m; m = opening.exec(html)) {
154
+ const tag = readTag(html, m.index + 1);
155
+ if (typeof tag !== 'object' || !isSourceType(tag.attrs)) continue;
156
+ const closing = /<\/script/gi;
157
+ closing.lastIndex = tag.end;
158
+ const end = closing.exec(html)?.index;
159
+ blocks.push({index: m.index, json: html.slice(tag.end, end ?? html.length), closed: end !== undefined});
160
+ opening.lastIndex = end ?? html.length;
161
+ }
162
+ return blocks;
163
+ };
164
+
59
165
  /**
60
166
  * Read the embedded source from a rendered file.
61
167
  * @param {string} html
62
- * @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string}}
168
+ * @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string} | {found: true, newer: {format: number, cli: string | null}}}
63
169
  */
64
170
  export function readSourceBlock(html) {
65
- const all = [
66
- ...html.matchAll(
67
- new RegExp(
68
- `<script\\s+type=["']${SOURCE_TYPE.replace(/[/+.-]/g, c => `\\${c}`)}["'][^>]*>([\\s\\S]*?)</script>`,
69
- 'gi',
70
- ),
71
- ),
72
- ];
73
171
  // The block is written last in the body; a page's own markup cannot end
74
172
  // it, so the last one is the CLI's.
75
- const m = all.at(-1);
76
- if (!m) return {found: false};
173
+ const block = blocksIn(html).at(-1);
174
+ if (!block) return {found: false};
175
+ if (!block.closed) return {found: true, damaged: 'its embedded source is cut short: the file ends inside it'};
77
176
  /** @type {any} */
78
177
  let payload;
79
178
  try {
80
- payload = JSON.parse(m[1]);
179
+ payload = JSON.parse(block.json);
81
180
  } catch {
82
181
  return {found: true, damaged: 'its embedded source is not valid JSON'};
83
182
  }
183
+ // A CLI version that is not a semantic version is never a render's: the
184
+ // file was changed, and the value would reach a printed command.
185
+ if (payload?.cli !== undefined && !isValidSemver(payload.cli)) {
186
+ return {found: true, damaged: 'its embedded source names a CLI version that is not a release version'};
187
+ }
188
+ if (Number.isInteger(payload?.version) && payload.version > RENDER_FORMAT) {
189
+ return {found: true, newer: {format: payload.version, cli: isValidSemver(payload.cli) ? payload.cli : null}};
190
+ }
84
191
  if (
85
192
  payload?.version !== 1 ||
86
193
  typeof payload.entry !== 'string' ||
@@ -104,3 +211,47 @@ export function readSourceBlock(html) {
104
211
  }
105
212
  return {found: true, source: payload};
106
213
  }
214
+
215
+ /**
216
+ * The markup between `<body>` and the embedded source: what a render wrote
217
+ * there, unless someone changed it since. Null when the file no longer has
218
+ * that shape.
219
+ * @param {string} html
220
+ * @returns {string | null}
221
+ */
222
+ export function renderedMarkupOf(html) {
223
+ const block = blocksIn(html).at(-1);
224
+ if (!block) return null;
225
+ const start = pageParts(html).body;
226
+ return start < 0 || start > block.index ? null : html.slice(start, block.index);
227
+ }
228
+
229
+ /**
230
+ * The title and the <style> element a render wrote in <head>, unless someone
231
+ * changed them since.
232
+ * @param {string} html
233
+ * @returns {{title: string | null, style: string | null}}
234
+ */
235
+ export function renderedHeadOf(html) {
236
+ const {title, style} = pageParts(html);
237
+ return {title, style};
238
+ }
239
+
240
+ /**
241
+ * The title and the runs of text a record keeps, or null when the record
242
+ * keeps none or they do not decode.
243
+ * @param {{text?: unknown}} markup
244
+ * @returns {{title: string | null, runs: string[]} | null}
245
+ */
246
+ export function recordedText(markup) {
247
+ if (typeof markup.text !== 'string') return null;
248
+ try {
249
+ const parsed = JSON.parse(Buffer.from(markup.text, 'base64').toString('utf8'));
250
+ return {
251
+ title: typeof parsed?.title === 'string' ? parsed.title : null,
252
+ runs: Array.isArray(parsed?.runs) ? parsed.runs.filter((/** @type {unknown} */ r) => typeof r === 'string') : [],
253
+ };
254
+ } catch {
255
+ return null;
256
+ }
257
+ }
@@ -23,9 +23,10 @@ export function matchPath(patterns: PathPattern[], spec: string): {
23
23
  * The file a candidate path stands for: itself, with an extension, or its
24
24
  * folder's index; null when none exists.
25
25
  * @param {string} candidate
26
+ * @param {readonly string[]} [extensions] the extensions to try, in order (default: TypeScript's)
26
27
  * @returns {string | null}
27
28
  */
28
- export function existingFile(candidate: string): string | null;
29
+ export function existingFile(candidate: string, extensions?: readonly string[]): string | null;
29
30
  /**
30
31
  * Resolve a specifier through path patterns: the first target that names an
31
32
  * existing file wins.
@@ -35,6 +36,8 @@ export function existingFile(candidate: string): string | null;
35
36
  * pattern or no target exists
36
37
  */
37
38
  export function resolvePath(patterns: PathPattern[], spec: string): string | null;
39
+ /** The extensions the render's module loader tries for an extensionless import, in its order. */
40
+ export const LOAD_EXTENSIONS: string[];
38
41
  export function candidatesOf(match: {
39
42
  pattern: PathPattern;
40
43
  capture: string;
@@ -27,6 +27,9 @@ import * as path from 'node:path';
27
27
  /** Extensions an extensionless candidate may stand for, in resolution order. */
28
28
  const EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.mts', '.cts', '.json'];
29
29
 
30
+ /** The extensions the render's module loader tries for an extensionless import, in its order. */
31
+ export const LOAD_EXTENSIONS = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts', '.json'];
32
+
30
33
  /**
31
34
  * The path patterns of the config in `dir` (tsconfig.json, else
32
35
  * jsconfig.json), or none. Comments and trailing commas are allowed.
@@ -103,9 +106,10 @@ export const candidatesOf = match => match.pattern.targets.map(t => t.replace('*
103
106
  * The file a candidate path stands for: itself, with an extension, or its
104
107
  * folder's index; null when none exists.
105
108
  * @param {string} candidate
109
+ * @param {readonly string[]} [extensions] the extensions to try, in order (default: TypeScript's)
106
110
  * @returns {string | null}
107
111
  */
108
- export function existingFile(candidate) {
112
+ export function existingFile(candidate, extensions = EXTENSIONS) {
109
113
  const isFile = (/** @type {string} */ f) => {
110
114
  try {
111
115
  return fs.statSync(f).isFile();
@@ -114,8 +118,8 @@ export function existingFile(candidate) {
114
118
  }
115
119
  };
116
120
  if (isFile(candidate)) return candidate;
117
- for (const ext of EXTENSIONS) if (isFile(candidate + ext)) return candidate + ext;
118
- for (const ext of EXTENSIONS) if (isFile(path.join(candidate, `index${ext}`))) return path.join(candidate, `index${ext}`);
121
+ for (const ext of extensions) if (isFile(candidate + ext)) return candidate + ext;
122
+ for (const ext of extensions) if (isFile(path.join(candidate, `index${ext}`))) return path.join(candidate, `index${ext}`);
119
123
  return null;
120
124
  }
121
125
 
@@ -111,6 +111,7 @@ export function allErrorCodes(): string[];
111
111
  * | 'ERR_RENDER_FAILED'
112
112
  * | 'ERR_RENDER_NOT_ASTRYX'
113
113
  * | 'ERR_RENDER_SOURCE_DAMAGED'
114
+ * | 'ERR_RENDER_NEWER_FORMAT'
114
115
  * | 'ERR_THEME_BAD_VALUE'
115
116
  * | 'ERR_THEME_NO_MODE'
116
117
  * | 'ERR_THEME_UNKNOWN_PART'
@@ -134,4 +135,4 @@ export const ERROR_CODES: Readonly<Record<ErrorCode, ErrorCode>>;
134
135
  /**
135
136
  * Stable error-code string union. Append-only.
136
137
  */
137
- export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_THEME_STALE" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
138
+ export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_THEME_STALE" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_RENDER_NEWER_FORMAT" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
@@ -349,7 +349,13 @@ export const doc = {
349
349
  value: 'ERR_RENDER_SOURCE_DAMAGED',
350
350
  stability: 'experimental',
351
351
  description:
352
- '`render --reverse` refused the received file, and nothing was written: its embedded source was removed (a file a render wrote, with no Astryx components left to rebuild from) or is damaged (not valid, or a file does not match its checksum), lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its own imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds: a dotfile or dot-folder, anything under node_modules, a package manifest, lockfile or tool configuration, a file a test, story or benchmark runner would run, or any kind but a page module, stylesheet, JSON file or image. Raised only by the experimental render command.',
352
+ '`render --reverse` refused the received file, and nothing was written: its embedded source was removed (a file a render wrote, with no Astryx components left to rebuild from), is cut short (also a file a render wrote that ends before it), or is damaged (not valid, a file does not match its checksum, or it names a CLI version that is not a release version), the page holds merge conflict markers, lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its own imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds: a dotfile or dot-folder, anything under node_modules, a package manifest, lockfile or tool configuration, a file a test, story or benchmark runner would run, or any kind but a page module, stylesheet, JSON file or image. Raised only by the experimental render command.',
353
+ },
354
+ {
355
+ value: 'ERR_RENDER_NEWER_FORMAT',
356
+ stability: 'experimental',
357
+ description:
358
+ '`render --reverse` was given a file in a newer render format than this CLI reads. Nothing was written. The message names the version of the CLI that wrote the file, which reads it. Raised only by the experimental render command.',
353
359
  },
354
360
  {
355
361
  value: 'ERR_THEME_BAD_VALUE',
@@ -100,6 +100,7 @@
100
100
  * | 'ERR_RENDER_FAILED'
101
101
  * | 'ERR_RENDER_NOT_ASTRYX'
102
102
  * | 'ERR_RENDER_SOURCE_DAMAGED'
103
+ * | 'ERR_RENDER_NEWER_FORMAT'
103
104
  * | 'ERR_THEME_BAD_VALUE'
104
105
  * | 'ERR_THEME_NO_MODE'
105
106
  * | 'ERR_THEME_UNKNOWN_PART'
@@ -331,6 +332,12 @@ export const ERROR_CODES = Object.freeze({
331
332
  * was written.
332
333
  */
333
334
  ERR_RENDER_SOURCE_DAMAGED: 'ERR_RENDER_SOURCE_DAMAGED',
335
+ /**
336
+ * `render --reverse` was given a file in a newer render format than this
337
+ * CLI reads. Nothing was written. The message names the CLI version that
338
+ * wrote the file, which reads it.
339
+ */
340
+ ERR_RENDER_NEWER_FORMAT: 'ERR_RENDER_NEWER_FORMAT',
334
341
  /**
335
342
  * A value does not fit what it sets: not a color for a color token, not a size for a size, a step (`more`/`less`) on something that is not a dial, or a word a dial does not take. Nothing was changed. Raised only by `experimental theme`.
336
343
  */
@@ -43,8 +43,9 @@ export function searchComponents(needle: string, coreDir: string, components: Re
43
43
  }[]>;
44
44
  /**
45
45
  * The first sentence of a text, whitespace collapsed. A period after "e.g" or
46
- * "i.e" does not end the sentence. Used where a description has to fit on one
47
- * line: `build`'s alternatives and its text kit.
46
+ * "i.e", or inside an open quote (a quoted date such as "2. Nov. 2026"), does
47
+ * not end the sentence. Used where a description has to fit on one line:
48
+ * `build`'s text kit, and the text views of `search` and `template --list`.
48
49
  * @param {string} text
49
50
  * @returns {string}
50
51
  */
@@ -255,8 +255,9 @@ export async function searchComponents(needle, coreDir, components) {
255
255
 
256
256
  /**
257
257
  * The first sentence of a text, whitespace collapsed. A period after "e.g" or
258
- * "i.e" does not end the sentence. Used where a description has to fit on one
259
- * line: `build`'s alternatives and its text kit.
258
+ * "i.e", or inside an open quote (a quoted date such as "2. Nov. 2026"), does
259
+ * not end the sentence. Used where a description has to fit on one line:
260
+ * `build`'s text kit, and the text views of `search` and `template --list`.
260
261
  * @param {string} text
261
262
  * @returns {string}
262
263
  */
@@ -264,9 +265,21 @@ export function firstSentence(text) {
264
265
  const flat = String(text ?? '').replace(/\s+/g, ' ').trim();
265
266
  const ends = /[.!?](?=\s|$)/g;
266
267
  for (let m = ends.exec(flat); m; m = ends.exec(flat)) {
267
- if (!/\b(e\.g|i\.e)$/i.test(flat.slice(0, m.index))) {
268
+ const before = flat.slice(0, m.index);
269
+ if (!/\b(e\.g|i\.e)$/i.test(before) && !insideQuote(before)) {
268
270
  return flat.slice(0, m.index + 1);
269
271
  }
270
272
  }
271
273
  return flat;
272
274
  }
275
+
276
+ /**
277
+ * Whether a text ends inside a quote it opened: an odd count of straight
278
+ * double quotes, or more opening curly quotes than closing ones.
279
+ * @param {string} text
280
+ * @returns {boolean}
281
+ */
282
+ function insideQuote(text) {
283
+ const count = (/** @type {RegExp} */ re) => (text.match(re) ?? []).length;
284
+ return count(/"/g) % 2 === 1 || count(/\u201C/g) > count(/\u201D/g);
285
+ }
@@ -35,6 +35,15 @@ export function orderByAffinity<T>(typedName: string, items: T[], namesOf: (item
35
35
  closest?: boolean;
36
36
  typos?: boolean;
37
37
  }): T[];
38
+ /**
39
+ * Whether a name carries a typed word longer than one character: the words
40
+ * the `closest` cut of {@link orderByAffinity} counts. When no candidate
41
+ * carries one, that cut leaves every candidate in.
42
+ * @param {string} typedName
43
+ * @param {string} name
44
+ * @returns {boolean}
45
+ */
46
+ export function carriesTypedWord(typedName: string, name: string): boolean;
38
47
  /**
39
48
  * Docs route suggestions, closest to the typed route first. When every
40
49
  * suggestion sits under one namespace the typed route also starts with, that
@@ -206,6 +206,19 @@ function orderByWords(typedName, items, namesOf, options) {
206
206
  return scored.filter((_, i) => tiers[i] >= need).map(s => s.item);
207
207
  }
208
208
 
209
+ /**
210
+ * Whether a name carries a typed word longer than one character: the words
211
+ * the `closest` cut of {@link orderByAffinity} counts. When no candidate
212
+ * carries one, that cut leaves every candidate in.
213
+ * @param {string} typedName
214
+ * @param {string} name
215
+ * @returns {boolean}
216
+ */
217
+ export function carriesTypedWord(typedName, name) {
218
+ const words = nameWords(typedName).filter(w => w.length > 1);
219
+ return affinityOf(words, name) >= 10;
220
+ }
221
+
209
222
  /**
210
223
  * Docs route suggestions, closest to the typed route first. When every
211
224
  * suggestion sits under one namespace the typed route also starts with, that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.16",
3
+ "version": "0.7.17-canary.g9a957aa",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -127,7 +127,7 @@
127
127
  "zod": "^4.6.7"
128
128
  },
129
129
  "peerDependencies": {
130
- "@astryxdesign/core": "*"
130
+ "@astryxdesign/core": "0.7.17-canary.g9a957aa"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/core": {
@@ -135,10 +135,10 @@
135
135
  }
136
136
  },
137
137
  "devDependencies": {
138
- "@astryxdesign/charts": "*",
139
- "@astryxdesign/core": "*",
140
- "@astryxdesign/lab": "*",
141
- "@astryxdesign/theme-neutral": "*",
138
+ "@astryxdesign/charts": "0.7.17-canary.g9a957aa",
139
+ "@astryxdesign/core": "0.7.17-canary.g9a957aa",
140
+ "@astryxdesign/lab": "0.7.17-canary.g9a957aa",
141
+ "@astryxdesign/theme-neutral": "0.7.17-canary.g9a957aa",
142
142
  "@heroicons/react": "^2.2.0",
143
143
  "@stylexjs/stylex": "^0.19.1",
144
144
  "@types/babel__core": "^7.20.5",