@astryxdesign/cli 0.7.3-canary.f94e962 → 0.7.3-canary.fba04ed

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 (201) hide show
  1. package/README.md +68 -68
  2. package/api/build/_adapter.mjs +37 -25
  3. package/api/build/blocks/blocks.d.mts +68 -18
  4. package/api/build/blocks/blocks.mjs +475 -116
  5. package/api/build/blocks/blocks.test.mjs +191 -61
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.type.mjs +1 -1
  8. package/api/build/kit/answer.d.mts +9 -5
  9. package/api/build/kit/answer.mjs +123 -13
  10. package/api/build/kit/answer.test.mjs +73 -3
  11. package/api/build/kit/signals.d.mts +19 -0
  12. package/api/build/kit/signals.mjs +18 -7
  13. package/api/build/tree.mjs +2 -1
  14. package/api/build/tree.test.mjs +37 -29
  15. package/api/component/_adapter.mjs +39 -5
  16. package/api/component/component-replacement.test.mjs +1 -0
  17. package/api/component/component.mjs +1 -1
  18. package/api/component/doc-links.test.mjs +2 -2
  19. package/api/discover/_adapter.d.mts +1 -2
  20. package/api/discover/_adapter.mjs +6 -8
  21. package/api/discover/discover.mjs +0 -1
  22. package/api/docs/_adapter.d.mts +2 -2
  23. package/api/docs/_adapter.mjs +65 -18
  24. package/api/docs/docs-homes.test.mjs +127 -0
  25. package/api/docs/docs.doc.mjs +3 -3
  26. package/api/docs/docs.test.mjs +28 -18
  27. package/api/docs/integration-tree.test.mjs +20 -20
  28. package/api/docs/integrationDocs.test.mjs +1 -1
  29. package/api/docs/namespace-section.test.mjs +6 -6
  30. package/api/docs/reference-blocks.test.mjs +2 -2
  31. package/api/doctor/_adapter.d.mts +33 -13
  32. package/api/doctor/_adapter.mjs +55 -25
  33. package/api/doctor/doctor.d.mts +23 -5
  34. package/api/doctor/doctor.mjs +97 -28
  35. package/api/doctor/doctor.test.mjs +67 -9
  36. package/api/hook/hook.mjs +1 -1
  37. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  38. package/api/integration/validate-integration-gaps.test.mjs +12 -1
  39. package/api/integration/validate-integration.d.mts +4 -0
  40. package/api/integration/validate-integration.mjs +48 -7
  41. package/api/integration/validate-integration.type.d.mts +36 -5
  42. package/api/integration/validate-integration.type.mjs +27 -6
  43. package/api/integration/validateIntegration.doc.mjs +1 -1
  44. package/api/search/_adapter.d.mts +16 -0
  45. package/api/search/_adapter.mjs +39 -0
  46. package/api/search/_adapter.test.mjs +173 -0
  47. package/api/search/_candidate-score.mjs +1 -1
  48. package/api/search/_entries.d.mts +11 -0
  49. package/api/search/_entries.mjs +35 -17
  50. package/api/search/_entries.test.mjs +48 -0
  51. package/api/search/_gather-docs.mjs +3 -3
  52. package/api/search/_gather-templates.d.mts +0 -1
  53. package/api/search/_gather-templates.mjs +25 -0
  54. package/api/search/search.doc.mjs +1 -1
  55. package/api/search/search.integration-block.test.mjs +100 -0
  56. package/api/search/search.mjs +6 -2
  57. package/api/search/search.test.mjs +14 -14
  58. package/api/template/template.mjs +5 -1
  59. package/assets/docs/author-a-theme.doc.mjs +2 -2
  60. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  61. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  62. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  63. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  64. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  65. package/assets/docs/tree/block-template.doc.mjs +1 -1
  66. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  67. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  68. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  69. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  70. package/assets/docs/tree/checks.doc.mjs +2 -2
  71. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  72. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  73. package/assets/docs/tree/cli.doc.mjs +1 -1
  74. package/assets/docs/tree/codemods.doc.mjs +1 -1
  75. package/assets/docs/tree/component-family.doc.mjs +1 -1
  76. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  77. package/assets/docs/tree/components.doc.mjs +1 -1
  78. package/assets/docs/tree/configuration.doc.mjs +1 -1
  79. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  80. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  81. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  82. package/assets/docs/tree/docs.doc.mjs +1 -1
  83. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  84. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  85. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  86. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  87. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  88. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  89. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  90. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  91. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  92. package/assets/docs/tree/help.doc.mjs +2 -2
  93. package/assets/docs/tree/links.doc.mjs +1 -1
  94. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  95. package/assets/docs/tree/page-template.doc.mjs +1 -1
  96. package/assets/docs/tree/publishing.doc.mjs +1 -1
  97. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  98. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  99. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  100. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  101. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  102. package/assets/docs/tree/ship.doc.mjs +2 -2
  103. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  104. package/assets/docs/tree/single-component.doc.mjs +1 -1
  105. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  106. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  107. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  108. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  109. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  110. package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
  111. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  112. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  113. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  114. package/assets/docs/tree/templates.doc.mjs +1 -1
  115. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  116. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  117. package/assets/docs/tree/themes.doc.mjs +1 -1
  118. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  119. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  120. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  121. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  122. package/assets/docs/tree/versioning.doc.mjs +5 -1
  123. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  124. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  125. package/assets/docs/use-integrations.doc.mjs +120 -0
  126. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  127. package/authoring/integration/integration.doc.mjs +1 -1
  128. package/authoring/integration/type.ts +1 -1
  129. package/clients/cli/command-result-coverage.test.mjs +6 -5
  130. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  131. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  132. package/clients/cli/commands/component.test.mjs +6 -6
  133. package/clients/cli/commands/docs.doc.mjs +2 -2
  134. package/clients/cli/commands/docs.mjs +1 -1
  135. package/clients/cli/commands/docs.test.mjs +14 -14
  136. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  137. package/clients/cli/commands/doctor.doc.mjs +1 -1
  138. package/clients/cli/commands/doctor.mjs +10 -0
  139. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  140. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  141. package/clients/cli/commands/integration.doc.mjs +1 -1
  142. package/clients/cli/commands/manifest.doc.mjs +1 -1
  143. package/clients/cli/commands/manifest.mjs +67 -0
  144. package/clients/cli/commands/outside-project.test.mjs +99 -0
  145. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  146. package/clients/cli/commands/postinstall.mjs +31 -0
  147. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  148. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  149. package/clients/cli/index.mjs +35 -93
  150. package/clients/cli/lib/component-format.mjs +1 -1
  151. package/clients/cli/lib/define-command.mjs +12 -7
  152. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  153. package/clients/cli/lib/manifest.test.mjs +12 -0
  154. package/clients/cli/lib/welcome-box.mjs +50 -0
  155. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  156. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  157. package/foundation/agent-docs/agent-docs.mjs +7 -6
  158. package/foundation/agent-docs/agent-docs.test.mjs +5 -4
  159. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  160. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  161. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  162. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  163. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  164. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  165. package/foundation/discovery/authoring-surface.d.mts +1 -1
  166. package/foundation/discovery/authoring-surface.mjs +2 -2
  167. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  168. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  169. package/foundation/discovery/cli-self-docs.mjs +4 -3
  170. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  171. package/foundation/discovery/runner-commands.mjs +1 -0
  172. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  173. package/foundation/doc-compiler/doc-loads.test.mjs +21 -9
  174. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  175. package/foundation/doc-compiler/tree.d.mts +32 -6
  176. package/foundation/doc-compiler/tree.mjs +77 -43
  177. package/foundation/doc-compiler/tree.test.mjs +7 -7
  178. package/foundation/fs/read-record.d.mts +18 -0
  179. package/foundation/fs/read-record.mjs +131 -0
  180. package/foundation/fs/read-record.test.mjs +77 -0
  181. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  182. package/foundation/integrations/cli-peer-version.mjs +132 -0
  183. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  184. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  185. package/foundation/integrations/exports-subpaths.mjs +113 -0
  186. package/foundation/integrations/public-imports.d.mts +118 -0
  187. package/foundation/integrations/public-imports.mjs +1769 -0
  188. package/foundation/integrations/public-imports.test.mjs +1793 -0
  189. package/foundation/release/cache.test.mjs +24 -21
  190. package/foundation/release/global-state.d.mts +8 -4
  191. package/foundation/release/global-state.mjs +4 -2
  192. package/foundation/release/notices.d.mts +62 -8
  193. package/foundation/release/notices.mjs +136 -25
  194. package/foundation/release/notices.test.mjs +21 -0
  195. package/foundation/response/response-types.doc.mjs +1 -1
  196. package/foundation/text/string-utils.d.mts +2 -1
  197. package/foundation/text/string-utils.mjs +16 -5
  198. package/foundation/text/suggest-order.d.mts +72 -0
  199. package/foundation/text/suggest-order.mjs +363 -0
  200. package/foundation/text/suggest-order.test.mjs +259 -0
  201. package/package.json +9 -9
@@ -77,7 +77,7 @@
77
77
  * @property {boolean} data.directMatch True when the top page template is a confident direct match.
78
78
  * @property {BuildStart | null} data.start The page template to start from: the ranker's pick, else the app shell. Null only when the kit is narrowed to components or hooks (`type`), or when the project has no page template to offer.
79
79
  * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.pages Closest page templates by search (≤3). Each entry's `command` carries `--skeleton` when `directMatch` is false, so it previews the layout; `start.command` is the scaffold.
80
- * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.blocks Drop-in block patterns covering parts of the idea (≤5).
80
+ * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.blocks Drop-in block patterns covering parts of the idea (≤5), best first. A block search returned keeps search's score and reason; any other block carries the block picker's relative score (100 for its best candidate, never below 1) and reason, so the two kinds of score are not comparable.
81
81
  * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.domain Idea-specific components/hooks (≤6), excluding frame/foundation.
82
82
  * @property {string[]} data.frame Always-on page-shell component names. Every page template already uses them.
83
83
  * @property {string[]} data.foundation Always-on layout/typography/action component names. Every page template already uses them.
@@ -2,13 +2,17 @@
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
13
+ * @param {Map<string, import('../../search/search.type.mjs').SearchResultEntry>} [picked]
14
+ * the block picker's own entry (its real score and reason) for each named
15
+ * block search did not return
12
16
  * @returns {import('../build.type.mjs').BuildKitResponse}
13
17
  */
14
- export function kitAnswer(signals: import("./signals.mjs").KitSignals, blocks?: string[]): import("../build.type.mjs").BuildKitResponse;
18
+ export function kitAnswer(signals: import("./signals.mjs").KitSignals, blocks?: string[], picked?: Map<string, import("../../search/search.type.mjs").SearchResultEntry>): import("../build.type.mjs").BuildKitResponse;
@@ -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,16 +24,24 @@ 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
35
+ * @param {Map<string, import('../../search/search.type.mjs').SearchResultEntry>} [picked]
36
+ * the block picker's own entry (its real score and reason) for each named
37
+ * block search did not return
33
38
  * @returns {import('../build.type.mjs').BuildKitResponse}
34
39
  */
35
- export function kitAnswer(signals, blocks = signals.kitBlocks) {
40
+ export function kitAnswer(
41
+ signals,
42
+ blocks = signals.kitBlocks,
43
+ picked = new Map(),
44
+ ) {
36
45
  // Entries by name, in build's order: two packages can ship a block with the
37
46
  // same name, and each name in `blocks` takes the next entry of that name, so
38
47
  // both stay listed.
@@ -40,10 +49,23 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
40
49
  const own = new Map();
41
50
  for (const b of signals.blocks)
42
51
  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
- });
52
+ /** @type {Set<string>} */
53
+ const added = new Set();
54
+ const named = blocks
55
+ .flatMap(name => {
56
+ const entry = own.get(name)?.shift();
57
+ if (entry) return [entry];
58
+ // A block build does not name itself keeps search's own entry, once;
59
+ // one search did not return keeps the picker's entry.
60
+ const found =
61
+ own.has(name) || added.has(name)
62
+ ? undefined
63
+ : (signals.searchedEntries.get(name) ?? picked.get(name));
64
+ if (!found) return [];
65
+ added.add(name);
66
+ return [found];
67
+ })
68
+ .slice(0, signals.blocks.length);
47
69
 
48
70
  // What to try when the kit comes back thin. Keyword search over a design
49
71
  // system misses in a predictable way — the reader's words and the package's
@@ -64,8 +86,8 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
64
86
  }
65
87
  : undefined;
66
88
 
67
- return {
68
- type: 'build.kit',
89
+ const answer = (/** @type {typeof named} */ list) => ({
90
+ type: /** @type {const} */ ('build.kit'),
69
91
  data: {
70
92
  query: signals.query,
71
93
  // Distinguishes "search found nothing" from a weak-but-non-empty result
@@ -75,11 +97,99 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
75
97
  directMatch: signals.directMatch,
76
98
  start: signals.start,
77
99
  pages: signals.pages,
78
- blocks: named,
100
+ blocks: list,
79
101
  domain: signals.domain,
80
102
  frame: FRAME,
81
103
  foundation: FOUNDATION,
82
104
  hint,
83
105
  },
84
- };
106
+ });
107
+
108
+ // An added block must not make the answer longer than build's own, as JSON
109
+ // or as text: trim the added blocks' descriptions, never which blocks are
110
+ // listed.
111
+ const fitted = fitDescriptions(named, signals.blocks, {
112
+ json: list => bytes(answer(list)),
113
+ text: textSize,
114
+ });
115
+ return answer(fitted);
116
+ }
117
+
118
+ /** @param {unknown} value */
119
+ const bytes = value => Buffer.byteLength(JSON.stringify(value));
120
+
121
+ /**
122
+ * What the blocks add to the text answer, which prints each block's name,
123
+ * package, and the first sentence of its description.
124
+ * @param {{name: string, package?: string, description?: string}[]} list
125
+ */
126
+ const textSize = list =>
127
+ list.reduce(
128
+ (n, b) =>
129
+ n +
130
+ Buffer.byteLength(
131
+ `${b.name}${b.package ?? ''}${firstSentence(b.description ?? '')}`,
132
+ ),
133
+ 0,
134
+ );
135
+
136
+ /** An added block keeps at least this much of its description. */
137
+ const MIN_DESCRIPTION = 24;
138
+
139
+ /**
140
+ * A description cut to about `keep` characters (never fewer than
141
+ * {@link MIN_DESCRIPTION}) at a word boundary, with an ellipsis. Never empty:
142
+ * a description already that short is kept whole.
143
+ * @param {string} description
144
+ * @param {number} keep
145
+ */
146
+ function cutTo(description, keep) {
147
+ const room = Math.max(keep, MIN_DESCRIPTION);
148
+ if (description.length <= room) return description;
149
+ const cut = description.slice(0, room);
150
+ const at = cut.lastIndexOf(' ');
151
+ return `${(at > 0 ? cut.slice(0, at) : cut).trimEnd()}…`;
152
+ }
153
+
154
+ /**
155
+ * The listed blocks with the added blocks' descriptions shortened until
156
+ * neither the JSON nor the text answer is longer than with build's own
157
+ * blocks, or every added description is as short as it may get. A
158
+ * description is never emptied, and build's own entries never change.
159
+ * @template {{name: string, package?: string, description?: string}} B
160
+ * @param {B[]} list
161
+ * @param {B[]} own build's own entries
162
+ * @param {{json: (list: B[]) => number, text: (list: B[]) => number}} size
163
+ * @returns {B[]}
164
+ */
165
+ function fitDescriptions(list, own, size) {
166
+ const limit = {json: size.json(own), text: size.text(own)};
167
+ let out = list;
168
+ /** The bytes over each limit; 0 when within. */
169
+ const over = (/** @type {B[]} */ l) => ({
170
+ text: Math.max(0, size.text(l) - limit.text),
171
+ json: Math.max(0, size.json(l) - limit.json),
172
+ });
173
+ // The last added block first, each cut by what is still over and never
174
+ // below MIN_DESCRIPTION; when one is as short as it may get, the next one
175
+ // up is cut, and passes repeat while any cut still helps.
176
+ for (let changed = true; changed;) {
177
+ changed = false;
178
+ for (let k = out.length - 1; k >= 0; k--) {
179
+ const o = over(out);
180
+ if (o.text === 0 && o.json === 0) return out;
181
+ const b = out[k];
182
+ if (own.includes(b) || !b.description) continue;
183
+ const first = firstSentence(b.description);
184
+ const keep = Math.min(
185
+ o.text > 0 ? first.length - o.text - 1 : b.description.length,
186
+ o.json > 0 ? b.description.length - o.json - 1 : b.description.length,
187
+ );
188
+ const description = cutTo(b.description, keep);
189
+ if (description.length >= b.description.length) continue;
190
+ out = out.map((x, i) => (i === k ? {...x, description} : x));
191
+ changed = true;
192
+ }
193
+ }
194
+ return out;
85
195
  }
@@ -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,8 +53,27 @@ 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
  */
59
67
  foreign: string[];
68
+ /**
69
+ * every block the project can scaffold
70
+ */
71
+ catalog: import("../_adapter.mjs").BlockTemplate[];
72
+ /**
73
+ * every component, with its keywords
74
+ */
75
+ components: {
76
+ name: string;
77
+ keywords?: string[];
78
+ }[];
60
79
  };
@@ -100,7 +100,11 @@ 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
106
+ * @property {import('../_adapter.mjs').BlockTemplate[]} catalog every block the project can scaffold
107
+ * @property {{name: string, keywords?: string[]}[]} components every component, with its keywords
104
108
  */
105
109
 
106
110
  /**
@@ -230,13 +234,10 @@ export async function kitSignals(query, options = {}) {
230
234
  // A part of a page starts where it lives (spec:AST-048/FR3); the project's
231
235
  // own components say what a part is. The search above already gathered them
232
236
  // unless it was narrowed to templates.
233
- const kind = wantsPages
234
- ? ideaKind(
235
- query,
236
- catalog,
237
- searchedComponents(result) ?? (await loadComponents(cwd)),
238
- )
239
- : 'page';
237
+ const components = wantsPages
238
+ ? (searchedComponents(result) ?? (await loadComponents(cwd)))
239
+ : [];
240
+ const kind = wantsPages ? ideaKind(query, catalog, components) : 'page';
240
241
  const chosen = wantsPages
241
242
  ? chooseStart(ranked, kind, matchedPages, directMatch, catalog, query)
242
243
  : null;
@@ -273,6 +274,16 @@ export async function kitSignals(query, options = {}) {
273
274
  domain: domainKept,
274
275
  kitBlocks: blocksKept.map(r => r.name),
275
276
  searched: searchedBlocks.map(blockScore),
277
+ searchedEntries: new Map(
278
+ [...searchedBlocks].reverse().map(r => [r.name, r]),
279
+ ),
280
+ blockText: new Map(
281
+ templates.blocks
282
+ .filter(b => searchedBlocks.some(r => r.name === b.name))
283
+ .map(b => [b.name, `${b.displayName} ${b.description}`]),
284
+ ),
285
+ catalog: templates.blocks,
286
+ components,
276
287
  foreign: [
277
288
  ...new Set(
278
289
  [...blocksKept, ...searchedBlocks, ...templates.blocks]
@@ -35,7 +35,8 @@ const main = defineSearcher({
35
35
  run: async (request, ctx) => {
36
36
  const signals = await kitSignals(request.query, request.options);
37
37
  if (!ctx.blocks) return kitAnswer(signals);
38
- return kitAnswer(signals, pickBlocks(request.query, signals, ctx.blocks));
38
+ const picked = pickBlocks(request.query, signals, ctx.blocks);
39
+ return kitAnswer(signals, picked.names, picked.entries);
39
40
  },
40
41
  });
41
42
 
@@ -59,51 +59,51 @@ const PINNED = [
59
59
  [
60
60
  'analytics dashboard with a KPI row and a sortable table',
61
61
  [
62
- 'PaginationPageSize',
63
- 'GridDashboardLayout',
64
- 'TableBulkActionsTable',
62
+ 'TableSortableTable',
65
63
  'TableGridDividersTable',
66
- 'TableRowExpansionTable',
64
+ 'TableShowcase',
65
+ 'TableGroupedRowsTable',
66
+ 'TableStripedTable',
67
67
  ],
68
68
  ],
69
69
  [
70
70
  'settings page with notification toggles and a save bar',
71
71
  [
72
- 'ToggleButtonColor',
73
- 'ToggleButtonGroup',
74
- 'ToggleButtonGroupShowcase',
75
- 'ToggleButtonGroupVertical',
76
- 'ToggleButtonIconSwap',
72
+ 'SwitchShowcase',
73
+ 'SwitchSettingsPanel',
74
+ 'ToggleButtonShowcase',
75
+ 'ToggleButtonStates',
76
+ 'SwitchWithDescription',
77
77
  ],
78
78
  ],
79
79
  [
80
80
  'empty state for a question bank with an import button',
81
81
  [
82
- 'EmptyStateActions',
83
- 'EmptyStateCompact',
84
82
  'EmptyStateContainer',
85
83
  'EmptyStateShowcase',
86
- 'ToolbarTableFilter',
84
+ 'EmptyStateCompact',
85
+ 'EmptyStateActions',
86
+ 'CommandPaletteEmptyShowcase',
87
87
  ],
88
88
  ],
89
89
  [
90
90
  'login form with single sign-on buttons',
91
91
  [
92
+ 'ButtonWithIcon',
92
93
  'CardWithInnerLayout',
93
- 'BottomSheetMobileKeyboard',
94
- 'ButtonGroupBasic',
95
- 'CollapsibleControlledAccordion',
96
- 'BottomSheetSwitcherReviewFlow',
94
+ 'ButtonVariants',
95
+ 'FormLayoutShowcase',
96
+ 'FormLayoutMixedControls',
97
97
  ],
98
98
  ],
99
99
  [
100
100
  'calendar for booking appointments',
101
101
  [
102
- 'CalendarRangeWithValue',
103
102
  'CalendarSingle',
104
- 'CalendarTwoMonths',
105
- 'CalendarConstraints',
106
103
  'CalendarShowcase',
104
+ 'CalendarConstraints',
105
+ 'CalendarRangeWithValue',
106
+ 'CalendarTwoMonths',
107
107
  ],
108
108
  ],
109
109
  [
@@ -125,16 +125,15 @@ afterAll(() => {
125
125
  });
126
126
 
127
127
  describe('build tree', () => {
128
- it('keeps the blocks a request names in build’s slots', async () => {
129
- const phrase = 'calendar for booking appointments';
128
+ it('keeps a block the request names by its exact name in build’s slot', async () => {
129
+ const phrase = 'calendar for booking appointments with CalendarTwoMonths';
130
130
  const answer = await build(phrase, {cwd: REPO});
131
131
  const own = await withListingCache(() => buildKit(phrase, {cwd: REPO}));
132
132
  if (answer?.type !== 'build.kit' || own.type !== 'build.kit')
133
133
  throw new Error('expected a kit');
134
- own.data.blocks.forEach((b, k) => {
135
- if (b.name.startsWith('Calendar'))
136
- expect(answer.data.blocks[k].name).toBe(b.name);
137
- });
134
+ const k = own.data.blocks.findIndex(b => b.name === 'CalendarTwoMonths');
135
+ expect(k).toBeGreaterThanOrEqual(0);
136
+ expect(answer.data.blocks[k].name).toBe('CalendarTwoMonths');
138
137
  });
139
138
 
140
139
  it('runs with the network and subprocesses blocked', async () => {
@@ -166,12 +165,21 @@ describe('build tree', () => {
166
165
  expect(answer.data.start?.alternatives).toEqual(
167
166
  own.data.start?.alternatives,
168
167
  );
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.
168
+ // Every block is build's own entry, one search returned, or the picker's
169
+ // own, each with its real score and reason; never more blocks than
170
+ // 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
  });
@@ -44,6 +44,10 @@ import {Project} from '../../foundation/config/project.mjs';
44
44
  import {loadComponentDoc as loadValidatedComponentDoc} from '../../foundation/discovery/component-loader.mjs';
45
45
  import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
46
46
  import {searchComponents} from '../../foundation/text/string-utils.mjs';
47
+ import {
48
+ rankComponentSuggestions,
49
+ synonymMatches,
50
+ } from '../../foundation/text/suggest-order.mjs';
47
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
48
52
  import {
49
53
  componentLinkProvider,
@@ -51,6 +55,28 @@ import {
51
55
  loadDocsCatalog,
52
56
  } from '../docs/_adapter.mjs';
53
57
 
58
+ /** @type {Record<string, {synonyms?: string[]}> | undefined} */
59
+ let cards;
60
+ /**
61
+ * Search's component cards (each component's other names), read once.
62
+ * @returns {Record<string, {synonyms?: string[]}>}
63
+ */
64
+ function searchCards() {
65
+ if (!cards) {
66
+ try {
67
+ cards = JSON.parse(
68
+ fs.readFileSync(
69
+ new URL('../search/_cards.json', import.meta.url),
70
+ 'utf8',
71
+ ),
72
+ );
73
+ } catch {
74
+ cards = {};
75
+ }
76
+ }
77
+ return /** @type {Record<string, {synonyms?: string[]}>} */ (cards);
78
+ }
79
+
54
80
  export {CORE_PACKAGE, unscopedComponentOwners};
55
81
 
56
82
  /**
@@ -463,12 +489,20 @@ export async function resolveUnscopedDoc(dirName, {coreDir, cwd, name}) {
463
489
  resolvedOwnerPackage = CORE_PACKAGE;
464
490
  resolvedSourcePath = findComponentSource(coreDir, resolvedName);
465
491
  } else {
492
+ // How many to suggest: the near-top results, at most five and at
493
+ // least two. Which ones, and in what order, is the suggestion
494
+ // ranking's call.
466
495
  const threshold = Math.max(topScore - 20, 1);
467
- const candidates = results
468
- .filter(r => r.score >= threshold)
469
- .slice(0, 5);
470
- if (candidates.length < 2)
471
- candidates.push(...results.slice(candidates.length, 2));
496
+ const count = Math.max(
497
+ results.filter(r => r.score >= threshold).slice(0, 5).length,
498
+ Math.min(2, results.length),
499
+ );
500
+ const candidates = rankComponentSuggestions(
501
+ dirName,
502
+ results,
503
+ Object.values(components).flat(),
504
+ synonymMatches(dirName, searchCards()),
505
+ ).slice(0, count);
472
506
  throw new AstryxError(
473
507
  `No component named "${name}"`,
474
508
  candidates.map(c => ({name: c.name, reason: c.reason})),
@@ -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
@@ -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
  );
@@ -43,12 +43,11 @@ export function hasSources(project: Project | undefined): boolean;
43
43
  * @param {Project | undefined} project
44
44
  * @param {Array<{name: string}>} installed
45
45
  * @param {Set<string>} declared
46
- * @param {(name: string, version?: string) => string} add
47
46
  * @returns {Promise<import('./discover.type.mjs').DiscoverAvailableEntry[]>}
48
47
  */
49
48
  export function computerAvailableEntries(project: Project | undefined, installed: Array<{
50
49
  name: string;
51
- }>, declared: Set<string>, add: (name: string, version?: string) => string): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
50
+ }>, declared: Set<string>): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
52
51
  /**
53
52
  * Package names the project's package.json declares in any dependency field.
54
53
  * @param {Project | undefined} project