@astryxdesign/cli 0.7.3-canary.cde6233 → 0.7.3-canary.d421aed

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 (47) hide show
  1. package/api/build/_adapter.mjs +37 -25
  2. package/api/build/blocks/blocks.d.mts +68 -20
  3. package/api/build/blocks/blocks.mjs +472 -196
  4. package/api/build/blocks/blocks.test.mjs +185 -168
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/build.type.mjs +1 -1
  7. package/api/build/kit/answer.d.mts +4 -1
  8. package/api/build/kit/answer.mjs +11 -3
  9. package/api/build/kit/signals.d.mts +11 -0
  10. package/api/build/kit/signals.mjs +8 -7
  11. package/api/build/tree.mjs +2 -1
  12. package/api/build/tree.test.mjs +27 -27
  13. package/api/component/_adapter.mjs +39 -5
  14. package/api/discover/_adapter.d.mts +1 -2
  15. package/api/discover/_adapter.mjs +6 -8
  16. package/api/discover/discover.mjs +0 -1
  17. package/api/docs/_adapter.mjs +4 -0
  18. package/api/doctor/_adapter.d.mts +24 -10
  19. package/api/doctor/_adapter.mjs +28 -25
  20. package/api/doctor/doctor.d.mts +7 -4
  21. package/api/doctor/doctor.mjs +52 -14
  22. package/api/doctor/doctor.test.mjs +58 -0
  23. package/api/integration/validate-integration-gaps.test.mjs +3 -0
  24. package/api/integration/validateIntegration.doc.mjs +1 -1
  25. package/api/template/template.mjs +5 -1
  26. package/assets/docs/tree/checks.doc.mjs +1 -1
  27. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  28. package/clients/cli/index.mjs +25 -8
  29. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  30. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  31. package/foundation/agent-docs/agent-docs.mjs +5 -5
  32. package/foundation/agent-docs/computer-agent-text.mjs +16 -1
  33. package/foundation/agent-docs/computer-agent-text.test.mjs +23 -2
  34. package/foundation/integrations/public-imports.d.mts +37 -0
  35. package/foundation/integrations/public-imports.mjs +839 -46
  36. package/foundation/integrations/public-imports.test.mjs +971 -46
  37. package/foundation/release/global-state.d.mts +8 -4
  38. package/foundation/release/global-state.mjs +4 -2
  39. package/foundation/release/notices.d.mts +62 -8
  40. package/foundation/release/notices.mjs +136 -25
  41. package/foundation/release/notices.test.mjs +21 -0
  42. package/foundation/text/string-utils.d.mts +2 -1
  43. package/foundation/text/string-utils.mjs +16 -5
  44. package/foundation/text/suggest-order.d.mts +72 -0
  45. package/foundation/text/suggest-order.mjs +363 -0
  46. package/foundation/text/suggest-order.test.mjs +259 -0
  47. package/package.json +9 -9
@@ -1,221 +1,238 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Unit tests for build's block picker on small hand-written weights: its
5
- * blocks come from build's own list or search's results (never another,
6
- * never more), a block search returned joins only if it shares a content word
7
- * with the request, a block the request names keeps its slot, as does a block
8
- * the weights do not know or an integration ships, and ties keep the order.
4
+ * @file Unit tests for build's block picker on small hand-written weights: it
5
+ * lists as many blocks as build's own, from the block catalog, each once; a
6
+ * block search did not return gets the picker's own entry with a real score
7
+ * and reason; a block the request writes out by its exact name keeps its slot,
8
+ * as does a block an integration ships; a block the weights were never fitted
9
+ * with is still ranked from its own docs; and ties keep build's order.
9
10
  */
10
11
 
11
12
  import {describe, expect, it} from 'vitest';
12
- import {pickBlocks} from './blocks.mjs';
13
+ import {pickBlocks, stemOf, termsOf, wordsOf} from './blocks.mjs';
14
+
15
+ /** Two dims, each byte a weight offset by 128: "chart" words on the first, "table" words on the second. */
16
+ const MATRIX = 'goCBgICCgIGAgICAgoA=';
13
17
 
14
18
  /** @type {import('./blocks.mjs').BlockPickerWeights} */
15
- const WORDS = {
16
- vocab: {chart: 1024, table: 2048, sales: 1536, 'sales chart': 3072, row: 512},
17
- classes: ['ChartBar', 'TableBasic', 'CardStat', 'ListPlain', 'CalendarBasic'],
18
- bias: [10, -20, 0, -64, 0],
19
- words: {
20
- chart: [0, 90, 2, 30],
21
- table: [1, 120, 3, -40],
22
- 'sales chart': [0, 60, 2, 50],
23
- row: [2, 80],
19
+ const WEIGHTS = {
20
+ vocab: ['chart', 'sale', 'table', 'row', 'toggle', 'switch', 'sale_chart'],
21
+ idf: [1024, 1024, 1024, 1024, 2048, 2048, 1024],
22
+ dims: 2,
23
+ request: MATRIX,
24
+ requestScale: 1,
25
+ doc: MATRIX,
26
+ docScale: 1,
27
+ lexical: 2,
28
+ known: ['ChartBar', 'TableBasic', 'CardStat', 'ListPlain'],
29
+ theta: {
30
+ g: 1,
31
+ grank: 0,
32
+ gmargin: 0,
33
+ seen: 0,
34
+ lex: 1,
35
+ sscore: 0,
36
+ scov: 0,
37
+ srank: 0,
38
+ inkit: 0,
39
+ kitpos: 0,
40
+ mention: 0,
41
+ show: 0,
24
42
  },
25
- theta: [0.5, 0.25, 0.5, 0.4, 1.5],
26
43
  };
44
+
45
+ /** @type {import('./blocks.mjs').CatalogBlock[]} */
46
+ const CATALOG = [
47
+ {
48
+ name: 'ChartBar',
49
+ package: '@astryxdesign/core',
50
+ displayName: 'Chart — Bar',
51
+ description: 'A bar chart of sales by month.',
52
+ command: 'astryx template ChartBar --type block',
53
+ },
54
+ {
55
+ name: 'TableBasic',
56
+ package: '@astryxdesign/core',
57
+ displayName: 'Table — Basic',
58
+ description: 'A table of rows.',
59
+ command: 'astryx template TableBasic --type block',
60
+ },
61
+ {
62
+ name: 'CardStat',
63
+ package: '@astryxdesign/core',
64
+ displayName: 'Card — Stat',
65
+ description: 'A card with one number.',
66
+ command: 'astryx template CardStat --type block',
67
+ },
68
+ {
69
+ name: 'ListPlain',
70
+ package: '@astryxdesign/core',
71
+ displayName: 'List — Plain',
72
+ description: 'A plain list.',
73
+ command: 'astryx template ListPlain --type block',
74
+ },
75
+ {
76
+ name: 'SwitchToggle',
77
+ package: '@astryxdesign/core',
78
+ displayName: 'Switch — Toggle',
79
+ description: 'A toggle switch.',
80
+ command: 'astryx template SwitchToggle --type block',
81
+ },
82
+ ];
83
+
84
+ /** @type {import('./blocks.mjs').CatalogComponent[]} */
85
+ const COMPONENTS = [
86
+ {name: 'Chart', keywords: ['graph']},
87
+ {name: 'Table', keywords: ['grid']},
88
+ {name: 'Card'},
89
+ {name: 'List'},
90
+ {name: 'Switch', keywords: ['toggle']},
91
+ ];
92
+
27
93
  /** @type {[string, number, number, number][]} */
28
94
  const SEARCHED = [
29
95
  ['TableBasic', 96, 1, 3],
30
96
  ['ListPlain', 64, 1, 3],
31
- ['ChartBar', 50, 1, 3],
32
97
  ['CardStat', 40, 1, 3],
33
98
  ];
34
99
 
35
- /**
36
- * Two blocks, no words, and a theta that prefers a block build did not name:
37
- * a block search returned wins the slot whenever the word check lets it in.
38
- * @type {import('./blocks.mjs').BlockPickerWeights}
39
- */
40
- const TIES_ALL = {
41
- vocab: {},
42
- classes: ['ListPlain', 'CardStat'],
43
- bias: [0, 0],
44
- words: {},
45
- theta: [0, 0, -1, 0, 0],
46
- };
47
-
48
- /** @type {import('./blocks.mjs').BlockPickerWeights} */
49
- const TIES = {
50
- vocab: {alpha: 1024},
51
- classes: ['X', 'Y', 'Z'],
52
- bias: [0, 0, 0],
53
- words: {},
54
- theta: [0, 0, 0, 0, 1],
55
- };
56
-
57
100
  /**
58
101
  * @param {string[]} kitBlocks
59
102
  * @param {string[]} [foreign]
60
103
  */
61
- const signals = (kitBlocks, foreign = [], searched = SEARCHED) => ({
104
+ const signals = (kitBlocks, foreign = []) => ({
62
105
  kitBlocks,
63
- searched,
106
+ searched: SEARCHED,
64
107
  foreign,
65
- blockText: new Map([
66
- ['ChartBar', 'Bar chart A bar chart of sales by month.'],
67
- ['CardStat', 'Stat card A card with one number.'],
68
- ['ListPlain', 'Plain list A list of rows.'],
69
- ['TableBasic', 'Basic table A table of rows.'],
70
- ]),
108
+ catalog: CATALOG,
109
+ components: COMPONENTS,
71
110
  });
72
111
 
73
112
  describe('pickBlocks', () => {
74
- it('names only blocks from build’s list or search’s, as many as build’s', () => {
113
+ it('lists as many blocks as build’s own, from the catalog, each once', () => {
75
114
  const own = ['TableBasic', 'ListPlain', 'CardStat'];
76
- const picks = pickBlocks('sales chart with a row', signals(own), WORDS);
77
- const allowed = new Set([...own, ...SEARCHED.map(s => s[0])]);
78
- expect(picks).toHaveLength(own.length);
79
- for (const b of picks) expect(allowed.has(b)).toBe(true);
80
- expect(new Set(picks).size).toBe(picks.length);
115
+ const {names} = pickBlocks('sales chart', signals(own), WEIGHTS);
116
+ expect(names).toHaveLength(own.length);
117
+ expect(new Set(names).size).toBe(names.length);
118
+ for (const b of names) expect(CATALOG.some(c => c.name === b)).toBe(true);
81
119
  });
82
120
 
83
- it('adds a block search returned that shares a word with the request', () => {
84
- const picks = pickBlocks(
85
- 'sales chart chart chart',
86
- signals(['TableBasic', 'ListPlain']),
87
- WORDS,
121
+ it('puts the block that means what the request asks first, even one search did not return', () => {
122
+ const own = ['TableBasic', 'ListPlain'];
123
+ const {names, entries} = pickBlocks('sales chart', signals(own), WEIGHTS);
124
+ expect(names[0]).toBe('ChartBar');
125
+ const entry = entries.get('ChartBar');
126
+ expect(entry?.score).toBeGreaterThan(0);
127
+ expect(entry?.reason).toMatch(/chart|sales/);
128
+ expect(entry?.description).toBe('A bar chart of sales by month.');
129
+ // Blocks search returned keep search's entry: the picker adds none.
130
+ for (const b of names)
131
+ if (SEARCHED.some(s => s[0] === b)) expect(entries.has(b)).toBe(false);
132
+ });
133
+
134
+ it('keeps a block the request writes out by its exact name in its slot', () => {
135
+ const own = ['ListPlain', 'TableBasic'];
136
+ const {names} = pickBlocks(
137
+ 'sales chart beside a ListPlain',
138
+ signals(own),
139
+ WEIGHTS,
88
140
  );
89
- expect(picks).toContain('ChartBar');
90
- expect(picks).toHaveLength(2);
141
+ expect(names[0]).toBe('ListPlain');
91
142
  });
92
143
 
93
- it('never adds a block search did not return, or one sharing no word', () => {
94
- const searched = /** @type {[string, number, number, number][]} */ ([
95
- ['TableBasic', 96, 1, 3],
96
- ['CardStat', 90, 1, 3],
97
- ]);
98
- const picks = pickBlocks(
99
- 'sales chart chart chart',
100
- signals(['TableBasic', 'ListPlain'], [], searched),
101
- WORDS,
144
+ it('keeps a block with a long name in its slot when the request writes it out', () => {
145
+ const long = {
146
+ name: 'ListPlainWithSixWordName',
147
+ package: '@astryxdesign/core',
148
+ displayName: 'List — Plain with a long name',
149
+ description: 'A plain list.',
150
+ command: 'astryx template ListPlainWithSixWordName --type block',
151
+ };
152
+ const s = {
153
+ ...signals(['ListPlainWithSixWordName', 'TableBasic']),
154
+ catalog: [...CATALOG, long],
155
+ };
156
+ const {names} = pickBlocks(
157
+ 'sales chart starting from ListPlainWithSixWordName',
158
+ s,
159
+ WEIGHTS,
102
160
  );
103
- expect(picks).not.toContain('ChartBar');
104
- expect(picks).not.toContain('CardStat');
105
- expect([...picks].sort()).toEqual(['ListPlain', 'TableBasic']);
161
+ expect(names[0]).toBe('ListPlainWithSixWordName');
106
162
  });
107
163
 
108
- it('keeps a block the request names in its slot', () => {
109
- const own = ['TableBasic', 'CalendarBasic', 'CardStat'];
110
- for (const request of [
111
- 'sales chart with a calendar',
112
- 'sales chart with two calendars',
113
- 'sales chart, calendar basic',
114
- ]) {
115
- expect(pickBlocks(request, signals(own), WORDS)[1]).toBe('CalendarBasic');
116
- }
164
+ it('does not pin a block for its component’s word alone', () => {
165
+ const own = ['ListPlain', 'TableBasic'];
166
+ const {names} = pickBlocks('sales chart list', signals(own), WEIGHTS);
167
+ expect(names[0]).toBe('ChartBar');
117
168
  });
118
169
 
119
- it('keeps a block the weights do not know or an integration ships in its slot', () => {
120
- const own = ['TableBasic', 'AcmeCallout', 'CardStat', 'ListPlain'];
121
- const picks = pickBlocks(
122
- 'sales chart with a row',
170
+ it('keeps a block an integration ships in its slot', () => {
171
+ const own = ['ListPlain', 'TableBasic'];
172
+ const {names} = pickBlocks(
173
+ 'sales chart',
123
174
  signals(own, ['ListPlain']),
124
- WORDS,
175
+ WEIGHTS,
125
176
  );
126
- expect(picks[1]).toBe('AcmeCallout');
127
- expect(picks[3]).toBe('ListPlain');
128
- expect(picks).toHaveLength(own.length);
177
+ expect(names[0]).toBe('ListPlain');
129
178
  });
130
179
 
131
- it('keeps build’s order on ties and when no word is known', () => {
132
- const own = ['X', 'Y', 'Z'];
133
- expect(
134
- pickBlocks(
135
- '??',
136
- {kitBlocks: own, searched: [], foreign: [], blockText: new Map()},
137
- TIES,
138
- ),
139
- ).toEqual(own);
180
+ it('ranks a block the weights were never fitted with from its own docs', () => {
181
+ expect(WEIGHTS.known).not.toContain('SwitchToggle');
182
+ const own = ['TableBasic', 'ListPlain'];
183
+ const {names, entries} = pickBlocks('toggle switch', signals(own), WEIGHTS);
184
+ expect(names[0]).toBe('SwitchToggle');
185
+ expect(entries.get('SwitchToggle')?.reason).toMatch(/toggle|switch/);
186
+ });
187
+
188
+ it('keeps build’s order when nothing in the request is known', () => {
189
+ const own = ['ListPlain', 'TableBasic', 'CardStat'];
190
+ const {names} = pickBlocks('zzz qqq', signals(own), WEIGHTS);
191
+ expect(names).toEqual(own);
140
192
  });
141
193
 
142
194
  it('returns nothing when build names no block, and does not change its input', () => {
143
- expect(pickBlocks('sales chart', signals([]), WORDS)).toEqual([]);
195
+ const s = signals([]);
196
+ const before = JSON.stringify(s);
197
+ expect(pickBlocks('sales chart', s, WEIGHTS)).toEqual({
198
+ names: [],
199
+ entries: new Map(),
200
+ });
144
201
  const own = ['TableBasic', 'ListPlain'];
145
- const copy = [...own];
146
- pickBlocks('sales chart', signals(own), WORDS);
147
- expect(own).toEqual(copy);
202
+ const s2 = signals(own);
203
+ const before2 = JSON.stringify(s2);
204
+ pickBlocks('sales chart', s2, WEIGHTS);
205
+ expect(JSON.stringify(s)).toBe(before);
206
+ expect(JSON.stringify(s2)).toBe(before2);
148
207
  });
208
+ });
149
209
 
150
- it('reads a request word and a block word as the same up to plural and stem', () => {
151
- for (const [word, blockWord] of [
152
- ['settings', 'setting'],
153
- ['statuses', 'status'],
154
- ['tables', 'table'],
155
- ['classes', 'class'],
156
- ['files', 'file'],
157
- ['categories', 'category'],
158
- ]) {
159
- const sig = {
160
- kitBlocks: ['ListPlain'],
161
- searched: /** @type {[string, number, number, number][]} */ ([
162
- ['ListPlain', 96, 1, 3],
163
- ['CardStat', 90, 1, 3],
164
- ]),
165
- foreign: [],
166
- blockText: new Map([['CardStat', `Stat card. A ${blockWord} panel.`]]),
167
- };
168
- expect(pickBlocks(`one ${word} view`, sig, TIES_ALL)).toEqual([
169
- 'CardStat',
170
- ]);
171
- }
172
- const none = {
173
- kitBlocks: ['ListPlain'],
174
- searched: /** @type {[string, number, number, number][]} */ ([
175
- ['ListPlain', 96, 1, 3],
176
- ['CardStat', 90, 1, 3],
177
- ]),
178
- foreign: [],
179
- blockText: new Map([['CardStat', 'Stat card. A setting panel.']]),
180
- };
181
- expect(pickBlocks('one widget view', none, TIES_ALL)).toEqual([
182
- 'ListPlain',
183
- ]);
210
+ describe('the picker’s words', () => {
211
+ it('stems plurals and verb endings of longer words only', () => {
212
+ expect(stemOf('tables')).toBe('table');
213
+ expect(stemOf('classes')).toBe('class');
214
+ expect(stemOf('entries')).toBe('entry');
215
+ expect(stemOf('class')).toBe('class');
216
+ expect(stemOf('rows')).toBe('rows');
184
217
  });
185
218
 
186
- it('never adds a block that shares only a function word with the request', () => {
187
- const searched = /** @type {[string, number, number, number][]} */ ([
188
- ['TableBasic', 96, 1, 3],
189
- ['CardStat', 90, 1, 3],
219
+ it('splits identifiers into words', () => {
220
+ expect(wordsOf('SideNavNestedItems')).toEqual([
221
+ 'side',
222
+ 'nav',
223
+ 'nested',
224
+ 'items',
190
225
  ]);
191
- const sig = {
192
- kitBlocks: ['TableBasic', 'ListPlain'],
193
- searched,
194
- foreign: [],
195
- blockText: new Map([['CardStat', 'Stat card Each card under a header.']]),
196
- };
197
- const picks = pickBlocks('each row under which', sig, WORDS);
198
- expect(picks).not.toContain('CardStat');
226
+ expect(wordsOf('KPICard')).toEqual(['kpi', 'card']);
199
227
  });
200
- it('never adds a block for a function word alone', () => {
201
- const sig = {
202
- kitBlocks: ['ListPlain'],
203
- searched: /** @type {[string, number, number, number][]} */ ([
204
- ['ListPlain', 96, 1, 3],
205
- ['CardStat', 90, 1, 3],
206
- ]),
207
- foreign: [],
208
- blockText: new Map([
209
- [
210
- 'CardStat',
211
- 'Shows which one is done. Each, every, any, some, all, both, either, neither, few, many, much, several, such, that, who, whom, whose.',
212
- ],
213
- ]),
214
- };
215
- for (const w of 'which that who whom whose each every any some all both either neither few many much several such'.split(
216
- ' ',
217
- ))
218
- expect(pickBlocks(`a ${w} b`, sig, TIES_ALL)).toEqual(['ListPlain']);
219
- expect(pickBlocks('each, which', sig, TIES_ALL)).toEqual(['ListPlain']);
228
+
229
+ it('reads content words and their adjacent pairs, never a function word', () => {
230
+ expect(termsOf('the sales charts for a team')).toEqual([
231
+ 'sale',
232
+ 'chart',
233
+ 'team',
234
+ 'sale_chart',
235
+ 'chart_team',
236
+ ]);
220
237
  });
221
238
  });