@astryxdesign/cli 0.7.3-canary.b74cf21 → 0.7.3-canary.ca48bb7

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 (213) hide show
  1. package/README.md +68 -68
  2. package/api/build/blocks/blocks.d.mts +6 -4
  3. package/api/build/blocks/blocks.mjs +103 -20
  4. package/api/build/blocks/blocks.test.mjs +126 -13
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/kit/answer.d.mts +5 -4
  7. package/api/build/kit/answer.mjs +114 -12
  8. package/api/build/kit/answer.test.mjs +73 -3
  9. package/api/build/kit/signals.d.mts +8 -0
  10. package/api/build/kit/signals.mjs +10 -0
  11. package/api/build/tree.test.mjs +19 -11
  12. package/api/component/component-replacement.test.mjs +1 -0
  13. package/api/component/component.mjs +17 -3
  14. package/api/component/component.test.mjs +15 -0
  15. package/api/component/doc-links.test.mjs +2 -2
  16. package/api/docs/_adapter.d.mts +2 -2
  17. package/api/docs/_adapter.mjs +61 -18
  18. package/api/docs/docs-homes.test.mjs +127 -0
  19. package/api/docs/docs.doc.mjs +3 -3
  20. package/api/docs/docs.test.mjs +28 -18
  21. package/api/docs/integration-tree.test.mjs +20 -20
  22. package/api/docs/integrationDocs.test.mjs +1 -1
  23. package/api/docs/namespace-section.test.mjs +6 -6
  24. package/api/docs/reference-blocks.test.mjs +2 -2
  25. package/api/doctor/doctor.mjs +16 -12
  26. package/api/doctor/doctor.test.mjs +37 -12
  27. package/api/hook/hook.mjs +1 -1
  28. package/api/integration/_adapter.d.mts +8 -0
  29. package/api/integration/_adapter.mjs +21 -1
  30. package/api/integration/authoring-checks.test.mjs +220 -0
  31. package/api/integration/pack-check.mjs +110 -4
  32. package/api/integration/pack-check.test.mjs +69 -0
  33. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  34. package/api/integration/validate-integration-gaps.test.mjs +304 -1
  35. package/api/integration/validate-integration.d.mts +6 -1
  36. package/api/integration/validate-integration.mjs +82 -13
  37. package/api/integration/validate-integration.type.d.mts +37 -4
  38. package/api/integration/validate-integration.type.mjs +28 -5
  39. package/api/integration/validateIntegration.doc.mjs +1 -1
  40. package/api/search/_adapter.d.mts +16 -0
  41. package/api/search/_adapter.mjs +39 -0
  42. package/api/search/_adapter.test.mjs +173 -0
  43. package/api/search/_candidate-score.mjs +1 -1
  44. package/api/search/_entries.d.mts +11 -0
  45. package/api/search/_entries.mjs +77 -3
  46. package/api/search/_entries.test.mjs +48 -0
  47. package/api/search/_gather-docs.mjs +3 -3
  48. package/api/search/search.doc.mjs +1 -1
  49. package/api/search/search.mjs +6 -2
  50. package/api/search/search.test.mjs +14 -14
  51. package/api/upgrade/_adapter.d.mts +57 -3
  52. package/api/upgrade/_adapter.mjs +149 -27
  53. package/api/upgrade/registry/registry.d.mts +10 -4
  54. package/api/upgrade/registry/registry.mjs +33 -16
  55. package/api/upgrade/registry/registry.test.mjs +85 -0
  56. package/api/upgrade/run/run.d.mts +4 -2
  57. package/api/upgrade/run/run.mjs +13 -2
  58. package/api/upgrade/run/run.test.mjs +417 -3
  59. package/api/upgrade/upgrade.doc.mjs +10 -5
  60. package/api/upgrade/upgrade.mjs +13 -2
  61. package/api/upgrade/upgrade.type.d.mts +5 -3
  62. package/api/upgrade/upgrade.type.mjs +8 -6
  63. package/assets/docs/author-a-theme.doc.mjs +2 -2
  64. package/assets/docs/is-my-code-good.doc.mjs +287 -0
  65. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  66. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  67. package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
  68. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  69. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  70. package/assets/docs/tree/block-template.doc.mjs +1 -1
  71. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  72. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  73. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  74. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  75. package/assets/docs/tree/checks.doc.mjs +3 -3
  76. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  77. package/assets/docs/tree/cli.doc.mjs +1 -1
  78. package/assets/docs/tree/codemods.doc.mjs +1 -1
  79. package/assets/docs/tree/component-family.doc.mjs +1 -1
  80. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  81. package/assets/docs/tree/components.doc.mjs +1 -1
  82. package/assets/docs/tree/configuration.doc.mjs +1 -1
  83. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  84. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  85. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  86. package/assets/docs/tree/docs.doc.mjs +1 -1
  87. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  88. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  89. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  90. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  91. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  92. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  93. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  94. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  95. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  96. package/assets/docs/tree/help.doc.mjs +2 -2
  97. package/assets/docs/tree/links.doc.mjs +1 -1
  98. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  99. package/assets/docs/tree/page-template.doc.mjs +1 -1
  100. package/assets/docs/tree/publishing.doc.mjs +1 -1
  101. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  102. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  103. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  104. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  105. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  106. package/assets/docs/tree/ship.doc.mjs +2 -2
  107. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  108. package/assets/docs/tree/single-component.doc.mjs +1 -1
  109. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  110. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  111. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  112. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  113. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  114. package/assets/docs/tree/template-grading-rubric.doc.mjs +17 -38
  115. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  116. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  117. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  118. package/assets/docs/tree/templates.doc.mjs +1 -1
  119. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  120. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  121. package/assets/docs/tree/themes.doc.mjs +1 -1
  122. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  123. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  124. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  125. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  126. package/assets/docs/tree/versioning.doc.mjs +5 -1
  127. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  128. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  129. package/assets/docs/use-integrations.doc.mjs +120 -0
  130. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  131. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  132. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  133. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  134. package/authoring/integration/integration.doc.mjs +1 -1
  135. package/authoring/integration/type.ts +1 -1
  136. package/clients/cli/command-result-coverage.test.mjs +6 -5
  137. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  138. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  139. package/clients/cli/commands/component.test.mjs +6 -6
  140. package/clients/cli/commands/docs.doc.mjs +2 -2
  141. package/clients/cli/commands/docs.mjs +1 -1
  142. package/clients/cli/commands/docs.test.mjs +14 -14
  143. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  144. package/clients/cli/commands/doctor.mjs +10 -0
  145. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  146. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  147. package/clients/cli/commands/integration-check.test.mjs +48 -0
  148. package/clients/cli/commands/integration.doc.mjs +1 -1
  149. package/clients/cli/commands/manifest.doc.mjs +1 -1
  150. package/clients/cli/commands/manifest.mjs +67 -0
  151. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  152. package/clients/cli/commands/postinstall.mjs +31 -0
  153. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  154. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  155. package/clients/cli/commands/upgrade.mjs +9 -2
  156. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  157. package/clients/cli/index.mjs +10 -85
  158. package/clients/cli/lib/component-format.mjs +1 -1
  159. package/clients/cli/lib/define-command.mjs +12 -7
  160. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  161. package/clients/cli/lib/manifest.test.mjs +12 -0
  162. package/clients/cli/lib/welcome-box.mjs +50 -0
  163. package/foundation/agent-docs/agent-docs.mjs +2 -1
  164. package/foundation/agent-docs/agent-docs.test.mjs +5 -4
  165. package/foundation/config/project.mjs +5 -20
  166. package/foundation/config/project.test.mjs +56 -0
  167. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  168. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  169. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  170. package/foundation/discovery/authoring-surface.d.mts +1 -1
  171. package/foundation/discovery/authoring-surface.mjs +2 -2
  172. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  173. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  174. package/foundation/discovery/cli-self-docs.mjs +4 -3
  175. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  176. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  177. package/foundation/discovery/runner-allowlist.mjs +2 -4
  178. package/foundation/discovery/runner-commands.d.mts +77 -0
  179. package/foundation/discovery/runner-commands.mjs +294 -0
  180. package/foundation/discovery/runner-commands.test.mjs +128 -0
  181. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  182. package/foundation/discovery/template-adapter.mjs +18 -1
  183. package/foundation/discovery/template-needs.mjs +1 -44
  184. package/foundation/discovery/theme-discovery.mjs +147 -3
  185. package/foundation/doc-compiler/doc-loads.test.mjs +25 -9
  186. package/foundation/doc-compiler/read.mjs +59 -1
  187. package/foundation/doc-compiler/read.test.mjs +11 -2
  188. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  189. package/foundation/doc-compiler/tree.d.mts +32 -6
  190. package/foundation/doc-compiler/tree.mjs +77 -43
  191. package/foundation/doc-compiler/tree.test.mjs +7 -7
  192. package/foundation/fs/paths.d.mts +70 -8
  193. package/foundation/fs/paths.mjs +526 -35
  194. package/foundation/fs/paths.test.mjs +430 -54
  195. package/foundation/fs/read-record.d.mts +18 -0
  196. package/foundation/fs/read-record.mjs +131 -0
  197. package/foundation/fs/read-record.test.mjs +77 -0
  198. package/foundation/integrations/autolink.d.mts +2 -1
  199. package/foundation/integrations/autolink.mjs +4 -13
  200. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  201. package/foundation/integrations/cli-peer-version.mjs +132 -0
  202. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  203. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  204. package/foundation/integrations/exports-subpaths.mjs +113 -0
  205. package/foundation/integrations/integrations.d.mts +20 -1
  206. package/foundation/integrations/integrations.mjs +59 -2
  207. package/foundation/integrations/public-imports.d.mts +118 -0
  208. package/foundation/integrations/public-imports.mjs +1769 -0
  209. package/foundation/integrations/public-imports.test.mjs +1793 -0
  210. package/foundation/integrations/validate-contributions.d.mts +19 -0
  211. package/foundation/integrations/validate-contributions.mjs +172 -3
  212. package/foundation/response/response-types.doc.mjs +1 -1
  213. package/package.json +9 -9
@@ -2,10 +2,11 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * The kit for a request. `blocks` re-orders the blocks build names itself:
6
- * each keeps build's own entry (its score and reason), and a name build did
7
- * not give is dropped, so the kit never lists more blocks than build's own.
8
- * Blocks of the same name from two packages are both kept.
5
+ * The kit for a request. `blocks` names the blocks to list, best first: a
6
+ * block build names itself keeps build's entry, another keeps search's own
7
+ * entry (its real score and reason), a name search did not return is
8
+ * dropped, and the kit never lists more blocks than build's own. Blocks of
9
+ * the same name from two packages are both kept.
9
10
  *
10
11
  * @param {import('./signals.mjs').KitSignals} signals
11
12
  * @param {string[]} [blocks] block names; build's own when omitted
@@ -10,6 +10,7 @@
10
10
  * calls it with the block picker's list.
11
11
  */
12
12
 
13
+ import {firstSentence} from '../../../foundation/text/string-utils.mjs';
13
14
  import {FOUNDATION, FRAME} from './signals.mjs';
14
15
 
15
16
  /**
@@ -23,10 +24,11 @@ import {FOUNDATION, FRAME} from './signals.mjs';
23
24
  const THIN_KIT = 3;
24
25
 
25
26
  /**
26
- * The kit for a request. `blocks` re-orders the blocks build names itself:
27
- * each keeps build's own entry (its score and reason), and a name build did
28
- * not give is dropped, so the kit never lists more blocks than build's own.
29
- * Blocks of the same name from two packages are both kept.
27
+ * The kit for a request. `blocks` names the blocks to list, best first: a
28
+ * block build names itself keeps build's entry, another keeps search's own
29
+ * entry (its real score and reason), a name search did not return is
30
+ * dropped, and the kit never lists more blocks than build's own. Blocks of
31
+ * the same name from two packages are both kept.
30
32
  *
31
33
  * @param {import('./signals.mjs').KitSignals} signals
32
34
  * @param {string[]} [blocks] block names; build's own when omitted
@@ -40,10 +42,22 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
40
42
  const own = new Map();
41
43
  for (const b of signals.blocks)
42
44
  own.set(b.name, [...(own.get(b.name) ?? []), b]);
43
- const named = blocks.flatMap(name => {
44
- const entry = own.get(name)?.shift();
45
- return entry ? [entry] : [];
46
- });
45
+ /** @type {Set<string>} */
46
+ const added = new Set();
47
+ const named = blocks
48
+ .flatMap(name => {
49
+ const entry = own.get(name)?.shift();
50
+ if (entry) return [entry];
51
+ // A block build does not name itself keeps search's own entry, once.
52
+ const found =
53
+ own.has(name) || added.has(name)
54
+ ? undefined
55
+ : signals.searchedEntries.get(name);
56
+ if (!found) return [];
57
+ added.add(name);
58
+ return [found];
59
+ })
60
+ .slice(0, signals.blocks.length);
47
61
 
48
62
  // What to try when the kit comes back thin. Keyword search over a design
49
63
  // system misses in a predictable way — the reader's words and the package's
@@ -64,8 +78,8 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
64
78
  }
65
79
  : undefined;
66
80
 
67
- return {
68
- type: 'build.kit',
81
+ const answer = (/** @type {typeof named} */ list) => ({
82
+ type: /** @type {const} */ ('build.kit'),
69
83
  data: {
70
84
  query: signals.query,
71
85
  // Distinguishes "search found nothing" from a weak-but-non-empty result
@@ -75,11 +89,99 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
75
89
  directMatch: signals.directMatch,
76
90
  start: signals.start,
77
91
  pages: signals.pages,
78
- blocks: named,
92
+ blocks: list,
79
93
  domain: signals.domain,
80
94
  frame: FRAME,
81
95
  foundation: FOUNDATION,
82
96
  hint,
83
97
  },
84
- };
98
+ });
99
+
100
+ // An added block must not make the answer longer than build's own, as JSON
101
+ // or as text: trim the added blocks' descriptions, never which blocks are
102
+ // listed.
103
+ const fitted = fitDescriptions(named, signals.blocks, {
104
+ json: list => bytes(answer(list)),
105
+ text: textSize,
106
+ });
107
+ return answer(fitted);
108
+ }
109
+
110
+ /** @param {unknown} value */
111
+ const bytes = value => Buffer.byteLength(JSON.stringify(value));
112
+
113
+ /**
114
+ * What the blocks add to the text answer, which prints each block's name,
115
+ * package, and the first sentence of its description.
116
+ * @param {{name: string, package?: string, description?: string}[]} list
117
+ */
118
+ const textSize = list =>
119
+ list.reduce(
120
+ (n, b) =>
121
+ n +
122
+ Buffer.byteLength(
123
+ `${b.name}${b.package ?? ''}${firstSentence(b.description ?? '')}`,
124
+ ),
125
+ 0,
126
+ );
127
+
128
+ /** An added block keeps at least this much of its description. */
129
+ const MIN_DESCRIPTION = 24;
130
+
131
+ /**
132
+ * A description cut to about `keep` characters (never fewer than
133
+ * {@link MIN_DESCRIPTION}) at a word boundary, with an ellipsis. Never empty:
134
+ * a description already that short is kept whole.
135
+ * @param {string} description
136
+ * @param {number} keep
137
+ */
138
+ function cutTo(description, keep) {
139
+ const room = Math.max(keep, MIN_DESCRIPTION);
140
+ if (description.length <= room) return description;
141
+ const cut = description.slice(0, room);
142
+ const at = cut.lastIndexOf(' ');
143
+ return `${(at > 0 ? cut.slice(0, at) : cut).trimEnd()}…`;
144
+ }
145
+
146
+ /**
147
+ * The listed blocks with the added blocks' descriptions shortened until
148
+ * neither the JSON nor the text answer is longer than with build's own
149
+ * blocks, or every added description is as short as it may get. A
150
+ * description is never emptied, and build's own entries never change.
151
+ * @template {{name: string, package?: string, description?: string}} B
152
+ * @param {B[]} list
153
+ * @param {B[]} own build's own entries
154
+ * @param {{json: (list: B[]) => number, text: (list: B[]) => number}} size
155
+ * @returns {B[]}
156
+ */
157
+ function fitDescriptions(list, own, size) {
158
+ const limit = {json: size.json(own), text: size.text(own)};
159
+ let out = list;
160
+ /** The bytes over each limit; 0 when within. */
161
+ const over = (/** @type {B[]} */ l) => ({
162
+ text: Math.max(0, size.text(l) - limit.text),
163
+ json: Math.max(0, size.json(l) - limit.json),
164
+ });
165
+ // The last added block first, each cut by what is still over and never
166
+ // below MIN_DESCRIPTION; when one is as short as it may get, the next one
167
+ // up is cut, and passes repeat while any cut still helps.
168
+ for (let changed = true; changed;) {
169
+ changed = false;
170
+ for (let k = out.length - 1; k >= 0; k--) {
171
+ const o = over(out);
172
+ if (o.text === 0 && o.json === 0) return out;
173
+ const b = out[k];
174
+ if (own.includes(b) || !b.description) continue;
175
+ const first = firstSentence(b.description);
176
+ const keep = Math.min(
177
+ o.text > 0 ? first.length - o.text - 1 : b.description.length,
178
+ o.json > 0 ? b.description.length - o.json - 1 : b.description.length,
179
+ );
180
+ const description = cutTo(b.description, keep);
181
+ if (description.length >= b.description.length) continue;
182
+ out = out.map((x, i) => (i === k ? {...x, description} : x));
183
+ changed = true;
184
+ }
185
+ }
186
+ return out;
85
187
  }
@@ -3,8 +3,11 @@
3
3
  import {describe, it, expect} from 'vitest';
4
4
  import {kitAnswer} from './answer.mjs';
5
5
 
6
- /** @param {any[]} blocks */
7
- const signals = blocks =>
6
+ /**
7
+ * @param {any[]} blocks
8
+ * @param {any[]} [searched] blocks search returned that build did not name
9
+ */
10
+ const signals = (blocks, searched = []) =>
8
11
  /** @type {any} */ ({
9
12
  query: 'q',
10
13
  matchCount: blocks.length,
@@ -14,6 +17,7 @@ const signals = blocks =>
14
17
  blocks,
15
18
  kitBlocks: blocks.map(b => b.name),
16
19
  domain: [],
20
+ searchedEntries: new Map(searched.map(b => [b.name, b])),
17
21
  });
18
22
 
19
23
  describe('kitAnswer', () => {
@@ -31,8 +35,74 @@ describe('kitAnswer', () => {
31
35
  expect(kit.data.blocks).toEqual([c, a, b]);
32
36
  });
33
37
 
34
- it('never lists a block build did not give, or more than it gave', () => {
38
+ it('never lists a block neither build nor search gave, or more than build gave', () => {
35
39
  const kit = kitAnswer(signals([a, c]), ['Hero', 'Hero', 'Nav', 'Footer']);
36
40
  expect(kit.data.blocks).toEqual([a, c]);
37
41
  });
42
+
43
+ it('lists a block search returned with search’s own entry, within build’s count', () => {
44
+ const nav = {name: 'Nav', package: '@a/one', score: 60, reason: 'keyword'};
45
+ const kit = kitAnswer(signals([a, c], [nav]), [
46
+ 'Nav',
47
+ 'Nav',
48
+ 'Hero',
49
+ 'Footer',
50
+ ]);
51
+ expect(kit.data.blocks).toEqual([nav, a]);
52
+ });
53
+
54
+ it('trims an added block’s description so the answer is never longer than build’s own', () => {
55
+ const hero = {
56
+ ...a,
57
+ description: 'A wide hero with a title and two buttons.',
58
+ };
59
+ const foot = {...c, description: 'A footer with links in three columns.'};
60
+ const nav = {
61
+ name: 'Nav',
62
+ package: '@a/one',
63
+ score: 60,
64
+ reason: 'keyword',
65
+ description: 'word '.repeat(200).trim(),
66
+ };
67
+ const own = kitAnswer(signals([hero, foot]));
68
+ const kit = kitAnswer(signals([hero, foot], [nav]), ['Nav', 'Hero']);
69
+ expect(kit.data.blocks.map(b => b.name)).toEqual(['Nav', 'Hero']);
70
+ expect(kit.data.blocks[1]).toEqual(hero);
71
+ expect(Buffer.byteLength(JSON.stringify(kit))).toBeLessThanOrEqual(
72
+ Buffer.byteLength(JSON.stringify(own)),
73
+ );
74
+ expect(kit.data.blocks[0].description).toMatch(/…$/);
75
+ });
76
+ it('trims an added block’s first sentence so the text answer is never longer either', () => {
77
+ const long = ' More words follow here. '.repeat(20);
78
+ const hero = {...a, description: `A hero.${long}`};
79
+ const foot = {...c, description: `A footer.${long}`};
80
+ const nav = {
81
+ name: 'Nav',
82
+ package: '@a/one',
83
+ score: 60,
84
+ reason: 'keyword',
85
+ description:
86
+ 'A navigation bar with a logo, five links, a search box and a menu.',
87
+ };
88
+ const kit = kitAnswer(signals([hero, foot], [nav]), ['Nav', 'Hero']);
89
+ const d = kit.data.blocks[0].description;
90
+ expect(d).toMatch(/…$/);
91
+ expect(d.length).toBeLessThan(nav.description.length);
92
+ expect(nav.description.startsWith(d.slice(0, -1))).toBe(true);
93
+ expect(kit.data.blocks[1]).toEqual(hero);
94
+ });
95
+ it('never empties an added block’s description', () => {
96
+ const nav = {
97
+ name: 'Nav',
98
+ package: '@a/one',
99
+ score: 60,
100
+ reason: 'keyword',
101
+ description:
102
+ 'A navigation bar with a logo, five links, a search box and a menu.',
103
+ };
104
+ const kit = kitAnswer(signals([a, c], [nav]), ['Nav', 'Hero']);
105
+ expect(kit.data.blocks[0].name).toBe('Nav');
106
+ expect(kit.data.blocks[0].description.length).toBeGreaterThan(0);
107
+ });
38
108
  });
@@ -53,6 +53,14 @@ export type KitSignals = {
53
53
  * every block search returned, in its order
54
54
  */
55
55
  searched: BlockScore[];
56
+ /**
57
+ * search's entry for each of those blocks (the first of a name)
58
+ */
59
+ searchedEntries: Map<string, SearchResultEntry>;
60
+ /**
61
+ * each of those blocks' display name and description, from the catalog
62
+ */
63
+ blockText: Map<string, string>;
56
64
  /**
57
65
  * the blocks, named, searched or scaffoldable, whose package is not Core's
58
66
  */
@@ -100,6 +100,8 @@ const ALWAYS = new Set([...FRAME, ...FOUNDATION]);
100
100
  * @property {SearchResultEntry[]} domain
101
101
  * @property {string[]} kitBlocks the names of `blocks`
102
102
  * @property {BlockScore[]} searched every block search returned, in its order
103
+ * @property {Map<string, SearchResultEntry>} searchedEntries search's entry for each of those blocks (the first of a name)
104
+ * @property {Map<string, string>} blockText each of those blocks' display name and description, from the catalog
103
105
  * @property {string[]} foreign the blocks, named, searched or scaffoldable, whose package is not Core's
104
106
  */
105
107
 
@@ -273,6 +275,14 @@ export async function kitSignals(query, options = {}) {
273
275
  domain: domainKept,
274
276
  kitBlocks: blocksKept.map(r => r.name),
275
277
  searched: searchedBlocks.map(blockScore),
278
+ searchedEntries: new Map(
279
+ [...searchedBlocks].reverse().map(r => [r.name, r]),
280
+ ),
281
+ blockText: new Map(
282
+ templates.blocks
283
+ .filter(b => searchedBlocks.some(r => r.name === b.name))
284
+ .map(b => [b.name, `${b.displayName} ${b.description}`]),
285
+ ),
276
286
  foreign: [
277
287
  ...new Set(
278
288
  [...blocksKept, ...searchedBlocks, ...templates.blocks]
@@ -59,8 +59,8 @@ const PINNED = [
59
59
  [
60
60
  'analytics dashboard with a KPI row and a sortable table',
61
61
  [
62
- 'PaginationPageSize',
63
- 'GridDashboardLayout',
62
+ 'TableSortableTable',
63
+ 'TableRichCellTable',
64
64
  'TableBulkActionsTable',
65
65
  'TableGridDividersTable',
66
66
  'TableRowExpansionTable',
@@ -83,17 +83,17 @@ const PINNED = [
83
83
  'EmptyStateCompact',
84
84
  'EmptyStateContainer',
85
85
  'EmptyStateShowcase',
86
- 'ToolbarTableFilter',
86
+ 'BannerWithActionButton',
87
87
  ],
88
88
  ],
89
89
  [
90
90
  'login form with single sign-on buttons',
91
91
  [
92
+ 'DialogFormDialog',
92
93
  'CardWithInnerLayout',
93
- 'BottomSheetMobileKeyboard',
94
94
  'ButtonGroupBasic',
95
- 'CollapsibleControlledAccordion',
96
- 'BottomSheetSwitcherReviewFlow',
95
+ 'ToggleButtonGroup',
96
+ 'BannerWithActionButton',
97
97
  ],
98
98
  ],
99
99
  [
@@ -108,7 +108,7 @@ const PINNED = [
108
108
  ],
109
109
  [
110
110
  'kanban board for sprint tasks with a filter bar',
111
- ['ToolbarTableFilter', 'PowerSearchShowcase'],
111
+ ['ToolbarTableFilter', 'PowerSearchFullFeatured'],
112
112
  ],
113
113
  ];
114
114
 
@@ -166,12 +166,20 @@ describe('build tree', () => {
166
166
  expect(answer.data.start?.alternatives).toEqual(
167
167
  own.data.start?.alternatives,
168
168
  );
169
- // The picker only re-orders build's own blocks: each keeps build's
170
- // entry (its real score and reason), none is added, none is dropped.
169
+ // Every block is build's own entry or one search returned, with its real
170
+ // score and reason; never more blocks than build's own.
171
171
  expect(answer.data.blocks.length).toBe(own.data.blocks.length);
172
- for (const b of answer.data.blocks)
173
- expect(own.data.blocks.find(o => o.name === b.name)).toEqual(b);
172
+ for (const b of answer.data.blocks) {
173
+ expect(b.score).toBeGreaterThan(0);
174
+ expect(typeof b.reason).toBe('string');
175
+ const mine = own.data.blocks.find(o => o.name === b.name);
176
+ if (mine) expect(mine).toEqual(b);
177
+ }
174
178
  expect(answer.data.blocks.map(b => b.name)).toEqual(blocks);
179
+ // Never longer than build's own answer for the same request.
180
+ expect(Buffer.byteLength(JSON.stringify(answer))).toBeLessThanOrEqual(
181
+ Buffer.byteLength(JSON.stringify(own)),
182
+ );
175
183
  });
176
184
  }
177
185
  });
@@ -64,6 +64,7 @@ function writeIntegration(name, components, peers) {
64
64
  type: 'component',
65
65
  name: componentName,
66
66
  displayName: componentName,
67
+ import: `${name}/components/${componentName}`,
67
68
  ...(replaces ? {replaces} : {}),
68
69
  keywords: ['acme'],
69
70
  usage: {description: `${componentName} for Acme apps.`},
@@ -293,7 +293,7 @@ async function componentRead(name, options = {}) {
293
293
  const selectorList = Array.isArray(name) ? name : null;
294
294
  const noName = selectorList == null && !name;
295
295
 
296
- // Default detail level mirrors the CLI (see commands/component/index.mjs):
296
+ // Default detail level mirrors the CLI (see commands/component.mjs):
297
297
  // single-component views default to 'full', list-style views (--list,
298
298
  // --category, or no name) default to 'brief' (scannable name lists).
299
299
  // An explicit array remains a batch even when it is empty or a caller also
@@ -461,8 +461,22 @@ async function componentRead(name, options = {}) {
461
461
  return componentDetailBlocks(dirName, cwd, owner.package);
462
462
  }
463
463
  const loaded = await loadComponentDoc(owner.docPath, docOpts);
464
- // A family member an integration lists under its own name reads as that
465
- // member, the way a Core sub-component does below.
464
+ // A family member reads as that member, scoped the way the unscoped
465
+ // lookup scopes it: an integration member by its own entry, a Core
466
+ // sub-component (HStack in the Stack doc) by scopeSubComponent.
467
+ const sub =
468
+ scoped.kind === 'core'
469
+ ? scopeSubComponent(loaded, dirName, coreDir)
470
+ : null;
471
+ if (sub) {
472
+ if (props) {
473
+ return componentDetailProps(
474
+ {props: sub.matchingComponent.props},
475
+ owner.package,
476
+ );
477
+ }
478
+ return componentDetail(sub.scoped, owner, dirName, coreDir);
479
+ }
466
480
  const docs =
467
481
  scoped.kind === 'integration'
468
482
  ? scopeIntegrationMember(loaded, owner, dirName)
@@ -135,6 +135,21 @@ describe('component list — components whose docs live in a family folder', ()
135
135
  });
136
136
  }, SLOW);
137
137
 
138
+ it('answers a Core-scoped lookup of a member with that member, as the unscoped lookup does', async () => {
139
+ for (const name of ['HStack', 'VStack']) {
140
+ const unscoped = await component(name, {cwd});
141
+ const scoped = await component(name, {
142
+ cwd,
143
+ package: '@astryxdesign/core',
144
+ });
145
+ expect(scoped.data.name).toBe(name);
146
+ expect(scoped.data.parentDoc).toBe('Stack');
147
+ expect(scoped.data.import).toBe(`@astryxdesign/core/${name}`);
148
+ expect(scoped.data.props).toEqual(unscoped.data.props);
149
+ expect(scoped.data.props.length).toBeGreaterThan(0);
150
+ }
151
+ }, SLOW);
152
+
138
153
  it('prints each one\'s own import path in the list, the detail, and search', async () => {
139
154
  // The path `component <Name>` prints is the one docs and examples teach:
140
155
  // the component's own entry point, never its family's (/Stack, /Text) or
@@ -250,14 +250,14 @@ describe("a link in a guide's description, as the docs tree shows it", () => {
250
250
  'Document a theme by extending the core theme topic, so an app reads it in `astryx docs theme`.';
251
251
  const guide = /** @type {any} */ (
252
252
  await docs(
253
- 'cli/integrations/building-blocks/themes/document-the-theme',
253
+ 'authoring/building-blocks/themes/document-the-theme',
254
254
  undefined,
255
255
  {cwd: tmpDir, full: true},
256
256
  )
257
257
  );
258
258
  expect(guide.data.description).toBe(expected);
259
259
  const namespace = /** @type {any} */ (
260
- await docs('cli/integrations/building-blocks/themes', undefined, {
260
+ await docs('authoring/building-blocks/themes', undefined, {
261
261
  cwd: tmpDir,
262
262
  })
263
263
  );
@@ -226,7 +226,7 @@ export function topicUp(entry: import("../../foundation/discovery/docs-discovery
226
226
  export function placeLinks(tree: DocsTree, node: TreeNode): import("./docs.type.mjs").DocsLinks;
227
227
  /**
228
228
  * The moves a topic read offers: from its place in the tree, where a guide
229
- * sits in its namespace and a flat topic in the Unorganized level.
229
+ * sits in its namespace and a flat topic in its topic level.
230
230
  * @param {DocsCatalog} catalog
231
231
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
232
232
  * @returns {Promise<import('./docs.type.mjs').DocsLinks>}
@@ -290,7 +290,7 @@ export function holdsOwnName(tree: DocsTree, catalog: DocsCatalog, entry: import
290
290
  /**
291
291
  * The doc that took a flat topic's route in the docs tree, when it is not
292
292
  * that topic (spec:AST-046 FR11): the CLI keeps its routes, such as `cli`
293
- * and `unorganized`, and a namespace keeps its route over a topic of the same
293
+ * and `guides`, and a namespace keeps its route over a topic of the same
294
294
  * name. Null when the topic owns its route, or the tree has no node there.
295
295
  * @param {DocsTree} tree
296
296
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
@@ -52,6 +52,7 @@ import {
52
52
  cliDocSection,
53
53
  } from '../../foundation/discovery/cli-self-docs.mjs';
54
54
  import {
55
+ AUTHORING_REFERENCE_ROUTE,
55
56
  loadAuthoringSelfDocs,
56
57
  schemaFieldTable,
57
58
  selfDocSection,
@@ -385,7 +386,7 @@ export function projectTree(catalog, {fresh = false} = {}) {
385
386
  let cliTreeInputs;
386
387
 
387
388
  /**
388
- * Every flat topic in the catalog, as the tree's Unorganized level reads it.
389
+ * Every flat topic in the catalog, as the tree's topic levels read it.
389
390
  * @param {DocsCatalog} catalog
390
391
  * @returns {Promise<import('../../foundation/doc-compiler/tree.mjs').TreeTopicInput[]>}
391
392
  */
@@ -394,12 +395,13 @@ async function flatTopicInputs(catalog) {
394
395
  const topics = [];
395
396
  for (const entry of catalog.entries()) {
396
397
  const aliases = catalog.aliasesOf(entry);
397
- let {title, description} = entry;
398
- if (title == null || description == null) {
398
+ let {title, description, category} = entry;
399
+ if (title == null || description == null || category === undefined) {
399
400
  try {
400
401
  const file = await loadTopicFile(entry.path, null);
401
402
  title ??= file.doc?.title;
402
403
  description ??= file.doc?.description;
404
+ category ??= file.doc?.category;
403
405
  } catch {
404
406
  // A topic that does not load is reported where it is read.
405
407
  }
@@ -410,6 +412,7 @@ async function flatTopicInputs(catalog) {
410
412
  name: entry.name,
411
413
  title: title ?? entry.name,
412
414
  summary: description ?? '',
415
+ category: category ?? null,
413
416
  source: `${entry.package}:${entry.name}`,
414
417
  ...(aliases.length > 0 ? {aliases} : {}),
415
418
  });
@@ -419,7 +422,7 @@ async function flatTopicInputs(catalog) {
419
422
 
420
423
  /**
421
424
  * The CLI's tree, each configured integration's namespaces and guides, and
422
- * every flat topic in the generated Unorganized level.
425
+ * every flat topic in the generated level for its category.
423
426
  * @param {DocsCatalog} catalog
424
427
  * @param {boolean} fresh
425
428
  * @returns {Promise<DocsTree>}
@@ -509,23 +512,22 @@ function identitiesOf(tree) {
509
512
  }
510
513
 
511
514
  /**
512
- * The CLI's authoring docs, by kind and name. `astryx docs authoring` reads
513
- * each as one section keyed by its name, so a link to one opens that section.
514
- * Loaded once per process, like the CLI's tree files.
515
+ * The CLI's authoring docs, by kind and name. The field reference under
516
+ * `astryx docs authoring` reads each as one section keyed by its name, so a
517
+ * link to one opens that section. Loaded once per process, like the CLI's
518
+ * tree files.
515
519
  * @type {Promise<Map<string, any>> | undefined}
516
520
  */
517
521
  let authoringDocs;
518
522
 
519
523
  /**
520
- * The CLI authoring doc a link names, while `astryx docs authoring` is the
521
- * CLI's own topic.
522
- * @param {DocsCatalog} catalog
524
+ * The CLI authoring doc a link names. The `authoring` namespace is the CLI's
525
+ * own, so no integration can take its route.
523
526
  * @param {string} kind
524
527
  * @param {string} name
525
528
  * @returns {Promise<any | null>}
526
529
  */
527
- async function authoringDoc(catalog, kind, name) {
528
- if (catalog.resolve('authoring')?.package !== CLI_PROVIDER_ID) return null;
530
+ async function authoringDoc(kind, name) {
529
531
  authoringDocs ??= loadAuthoringSelfDocs().then(
530
532
  ({loaded}) =>
531
533
  new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
@@ -611,14 +613,14 @@ function docFinderOver(catalog, tree, fromProvider, summaries = true) {
611
613
  }
612
614
  const authored =
613
615
  provider === CLI_PROVIDER_ID
614
- ? await authoringDoc(catalog, parsed.kind, parsed.name)
616
+ ? await authoringDoc(parsed.kind, parsed.name)
615
617
  : null;
616
618
  if (authored) {
617
619
  return {
618
620
  link: {
619
621
  target,
620
622
  id: createDocId(provider, authored.type, authored.name),
621
- route: 'authoring',
623
+ route: AUTHORING_REFERENCE_ROUTE,
622
624
  title: authored.displayName ?? authored.name,
623
625
  summary: authored.description ?? '',
624
626
  command: `astryx docs authoring ${authored.name}`,
@@ -1428,7 +1430,7 @@ export function placeLinks(tree, node) {
1428
1430
 
1429
1431
  /**
1430
1432
  * The moves a topic read offers: from its place in the tree, where a guide
1431
- * sits in its namespace and a flat topic in the Unorganized level.
1433
+ * sits in its namespace and a flat topic in its topic level.
1432
1434
  * @param {DocsCatalog} catalog
1433
1435
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
1434
1436
  * @returns {Promise<import('./docs.type.mjs').DocsLinks>}
@@ -1526,7 +1528,7 @@ function treeArgument(catalog, tree, node) {
1526
1528
  /**
1527
1529
  * The doc that took a flat topic's route in the docs tree, when it is not
1528
1530
  * that topic (spec:AST-046 FR11): the CLI keeps its routes, such as `cli`
1529
- * and `unorganized`, and a namespace keeps its route over a topic of the same
1531
+ * and `guides`, and a namespace keeps its route over a topic of the same
1530
1532
  * name. Null when the topic owns its route, or the tree has no node there.
1531
1533
  * @param {DocsTree} tree
1532
1534
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
@@ -1540,6 +1542,35 @@ export function routeOwner(tree, entry) {
1540
1542
  : node;
1541
1543
  }
1542
1544
 
1545
+ /**
1546
+ * Routes that moved, old prefix first: the integration guides moved from
1547
+ * `cli/integrations` (and, before that, the `cli-integrations` topic) into
1548
+ * `authoring`, the one home for integration authors.
1549
+ * Only the not-found error reads this, to name where a doc went; an old route
1550
+ * opens nothing.
1551
+ */
1552
+ const MOVED_ROUTES = [
1553
+ ['cli/integrations', 'authoring'],
1554
+ ['cli-integrations', 'authoring'],
1555
+ ];
1556
+
1557
+ /**
1558
+ * The node an old route moved to, or null.
1559
+ * @param {unknown} topic
1560
+ * @param {DocsTree} tree
1561
+ * @returns {TreeNode | null}
1562
+ */
1563
+ function movedRoute(topic, tree) {
1564
+ if (typeof topic !== 'string') return null;
1565
+ const wanted = topic.toLowerCase();
1566
+ for (const [from, to] of MOVED_ROUTES) {
1567
+ if (wanted !== from && !wanted.startsWith(`${from}/`)) continue;
1568
+ const node = tree.getFolded(`${to}${wanted.slice(from.length)}`);
1569
+ if (node) return node;
1570
+ }
1571
+ return null;
1572
+ }
1573
+
1543
1574
  /**
1544
1575
  * The error for a docs argument that names nothing. For a route, it suggests
1545
1576
  * the children of the deepest namespace the route reaches; otherwise, every
@@ -1572,8 +1603,7 @@ export async function unknownTopicError(topic, catalog) {
1572
1603
  }
1573
1604
  if (suggestions.length === 0 && typeof topic === 'string') {
1574
1605
  // The docs whose own name it is (`doctor` is cli/commands/doctor), or whose
1575
- // route it spells with hyphens (`cli-integrations`, the guide's name before
1576
- // it moved to cli/integrations).
1606
+ // route it spells with hyphens (`cli-host-entry` is cli/host-entry).
1577
1607
  const wanted = topic.toLowerCase();
1578
1608
  suggestions = [...tree.nodes.values()]
1579
1609
  .filter(
@@ -1592,6 +1622,19 @@ export async function unknownTopicError(topic, catalog) {
1592
1622
  ...catalog.names().map(name => ({name, reason: 'available topic'})),
1593
1623
  ];
1594
1624
  }
1625
+ // A route that moved names where it went, ahead of the usual suggestions
1626
+ // (spec:AST-046 FR9, FR6).
1627
+ const moved = movedRoute(topic, tree);
1628
+ if (moved) {
1629
+ return new AstryxError(
1630
+ `Unknown topic "${String(topic)}". It moved to "${moved.route}"${notLoaded(catalog)}`,
1631
+ [
1632
+ {name: moved.route, reason: moved.summary},
1633
+ ...suggestions.filter(entry => entry.name !== moved.route),
1634
+ ],
1635
+ ERROR_CODES.ERR_UNKNOWN_TOPIC,
1636
+ );
1637
+ }
1595
1638
  return new AstryxError(
1596
1639
  `Unknown topic "${String(topic)}"${notLoaded(catalog)}`,
1597
1640
  suggestions,