@astryxdesign/cli 0.6.5-canary.24fe2cd → 0.6.5-canary.2ad3b83
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.
- package/README.md +13 -14
- package/api/build/_adapter.d.mts +2 -36
- package/api/build/_adapter.mjs +10 -41
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +2 -38
- package/api/build/kit/kit.mjs +21 -65
- package/api/build/kit/rank.d.mts +8 -24
- package/api/build/kit/rank.mjs +97 -277
- package/api/build/kit/rank.test.mjs +48 -231
- package/api/error.d.mts +0 -22
- package/api/error.mjs +0 -42
- package/api/integration/add-contribution.d.mts +1 -2
- package/api/integration/add-contribution.mjs +3 -7
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +22 -243
- package/api/integration/add-theme.test.mjs +0 -213
- package/api/integration/authoring-checks.mjs +7 -10
- package/api/integration/authoring-checks.type.d.mts +0 -8
- package/api/integration/authoring-checks.type.mjs +3 -7
- package/api/integration/integration-authoring.type.d.mts +1 -4
- package/api/integration/integration-authoring.type.mjs +1 -6
- package/api/integration/integrationAdd.doc.mjs +0 -6
- package/api/integration/integrationAddTheme.doc.mjs +0 -10
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +2 -11
- package/api/integration/pack-check.test.mjs +1 -38
- package/api/integration/validate-integration.d.mts +2 -4
- package/api/integration/validate-integration.mjs +2 -7
- package/api/integration/validate-integration.test.mjs +0 -55
- package/api/integration/validate-integration.type.d.mts +0 -5
- package/api/integration/validate-integration.type.mjs +1 -5
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +7 -12
- package/api/layout/layout.type.d.mts +0 -1
- package/api/layout/layout.type.mjs +0 -1
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +0 -24
- package/api/search/search.mjs +1 -71
- package/api/swizzle/copy/copy.mjs +3 -66
- package/api/swizzle/swizzle.doc.mjs +0 -4
- package/api/template/copy/copy.mjs +8 -14
- package/api/template/show/show.mjs +4 -15
- package/api/template/template-integration.test.mjs +0 -14
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +2 -6
- package/api/template/template.mjs +0 -1
- package/api/template/template.type.d.mts +0 -2
- package/api/template/template.type.mjs +0 -2
- package/api/theme/build/build.d.mts +0 -24
- package/api/theme/build/build.mjs +8 -235
- package/api/upgrade/run/run.mjs +3 -20
- package/api/upgrade/run/run.test.mjs +1 -45
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +0 -1
- package/api/upgrade/upgrade.type.mjs +0 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -13
- package/assets/docs/tree/troubleshooting.doc.mjs +3 -7
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/templates/pages/ai-chat/template.doc.mjs +1 -16
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +1 -9
- package/assets/templates/pages/blank/template.doc.mjs +1 -3
- package/assets/templates/pages/canvas-editor/template.doc.mjs +1 -9
- package/assets/templates/pages/centered-hero/template.doc.mjs +1 -3
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +0 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -3
- package/assets/templates/pages/contact-form/template.doc.mjs +1 -16
- package/assets/templates/pages/dashboard/template.doc.mjs +1 -15
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +1 -23
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +1 -10
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +1 -9
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +1 -10
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +1 -17
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +1 -2
- package/assets/templates/pages/detail-page/template.doc.mjs +0 -8
- package/assets/templates/pages/documentation/template.doc.mjs +1 -10
- package/assets/templates/pages/documentation-design/template.doc.mjs +1 -10
- package/assets/templates/pages/documentation-technical/template.doc.mjs +1 -10
- package/assets/templates/pages/editor/template.doc.mjs +1 -9
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -3
- package/assets/templates/pages/form-two-column/template.doc.mjs +1 -17
- package/assets/templates/pages/form-wizard/template.doc.mjs +1 -14
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +0 -1
- package/assets/templates/pages/gallery-hero/template.doc.mjs +1 -10
- package/assets/templates/pages/ide/template.doc.mjs +1 -9
- package/assets/templates/pages/incident-console/template.doc.mjs +1 -10
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -11
- package/assets/templates/pages/library/template.doc.mjs +1 -15
- package/assets/templates/pages/login/template.doc.mjs +1 -10
- package/assets/templates/pages/login-card/template.doc.mjs +1 -11
- package/assets/templates/pages/login-split/template.doc.mjs +1 -10
- package/assets/templates/pages/login-sso/template.doc.mjs +1 -10
- package/assets/templates/pages/messaging-shell/template.doc.mjs +1 -11
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +1 -10
- package/assets/templates/pages/payment-form/template.doc.mjs +1 -3
- package/assets/templates/pages/product-detail/template.doc.mjs +1 -9
- package/assets/templates/pages/product-gallery/template.doc.mjs +1 -10
- package/assets/templates/pages/settings/template.doc.mjs +1 -3
- package/assets/templates/pages/settings-dialog/template.doc.mjs +1 -9
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +1 -9
- package/assets/templates/pages/shell-nav/template.doc.mjs +1 -10
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +1 -14
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +1 -11
- package/assets/templates/pages/side-gallery/template.doc.mjs +1 -3
- package/assets/templates/pages/table/template.doc.mjs +1 -11
- package/assets/templates/pages/table-filter/template.doc.mjs +1 -21
- package/assets/templates/pages/table-grouped/template.doc.mjs +1 -15
- package/assets/templates/pages/table-inbox/template.doc.mjs +6 -18
- package/assets/templates/pages/table-page/template.doc.mjs +1 -20
- package/assets/templates/pages/table-tree/template.doc.mjs +1 -14
- package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -10
- package/assets/templates/pages/work-item-detail/template.doc.mjs +0 -10
- package/authoring/doctypes/template/parse.d.mts +0 -2
- package/authoring/doctypes/template/parse.mjs +0 -1
- package/authoring/doctypes/template/parse.test.mjs +0 -21
- package/authoring/doctypes/template/template.doc.mjs +0 -6
- package/authoring/doctypes/template/type.ts +0 -10
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/integration-add.doc.mjs +0 -10
- package/clients/cli/commands/integration-authoring.test.mjs +2 -12
- package/clients/cli/commands/integration.mjs +1 -3
- package/clients/cli/commands/layout-expand.doc.mjs +1 -3
- package/clients/cli/commands/layout.mjs +0 -16
- package/clients/cli/commands/template.mjs +5 -19
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -14
- package/clients/cli/lib/manifest.mjs +165 -44
- package/clients/cli/lib/manifest.test.mjs +7 -98
- package/foundation/discovery/template-adapter.d.mts +0 -14
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +1 -37
- package/foundation/discovery/template-adapter.mjs +1 -21
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
- package/foundation/integrations/cli-requirement.d.mts +11 -23
- package/foundation/integrations/cli-requirement.mjs +18 -40
- package/foundation/integrations/cli-requirement.test.mjs +15 -66
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +9 -9
- package/api/docs/docs.test.mjs +0 -279
- package/api/docs/integration-tree.test.mjs +0 -572
- package/api/docs/integrationDocs.test.mjs +0 -336
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/search/search.test.mjs +0 -710
- package/api/template/copy/copy.receipt.test.mjs +0 -77
- package/api/template/show/show.test.mjs +0 -76
- package/api/theme/build/build.project-core.test.mjs +0 -165
- package/clients/cli/commands/docs.test.mjs +0 -383
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/template.copy-receipt.test.mjs +0 -60
- package/clients/cli/commands/template.show-media.test.mjs +0 -62
- package/clients/cli/commands/write-failure.test.mjs +0 -175
- package/foundation/agent-docs/agent-docs.test.mjs +0 -1160
- package/foundation/doc-compiler/tree.test.mjs +0 -649
package/api/build/kit/rank.mjs
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file The page ranker behind `build`'s START: which page template an idea
|
|
5
|
-
* should start from
|
|
5
|
+
* should start from.
|
|
6
6
|
*
|
|
7
|
-
* @input A free-text idea
|
|
8
|
-
* name, description,
|
|
9
|
-
*
|
|
7
|
+
* @input A free-text idea and the project's ready page templates (id, display
|
|
8
|
+
* name, description, `Family - Variant` category), all read from each
|
|
9
|
+
* template's own descriptor.
|
|
10
10
|
* @output Every template, ranked, with the query terms it matched and whether
|
|
11
|
-
* the idea names its family; `
|
|
12
|
-
* part of one, or a change to a page the builder has; `pickStart` turns both
|
|
13
|
-
* into a template or null.
|
|
11
|
+
* the idea names its family; `pickStart` turns that into a template or null.
|
|
14
12
|
* @position Beside kit.mjs (api/build/kit/). Search ranks components, docs,
|
|
15
13
|
* blocks and pages against short lookups; this ranks only page templates,
|
|
16
14
|
* against the long descriptions builders actually write ("ops dashboard with
|
|
@@ -38,27 +36,8 @@
|
|
|
38
36
|
* next one counts half, unless the template names the same pair
|
|
39
37
|
* ("executive summary").
|
|
40
38
|
* - The family base. A template whose id is its family's name (`dashboard`,
|
|
41
|
-
* `settings`) is that family's default
|
|
42
|
-
*
|
|
43
|
-
* dashboard the comparison dashboard), and a base too weak to start on its
|
|
44
|
-
* own displaces no variant ("a funnel for a dashboard" is the funnel).
|
|
45
|
-
*
|
|
46
|
-
* Parts (spec:AST-048/FR3). "A date range picker" asks for a part of a page,
|
|
47
|
-
* not a page, and the system's own components say what a part is: an idea
|
|
48
|
-
* whose head noun is a word of a component's name or keywords, Core's or an
|
|
49
|
-
* integration's, asks for that part, unless the noun is a family word ("a data
|
|
50
|
-
* table") or the idea lists a page's worth of pieces. Words search drops as
|
|
51
|
-
* stopwords ("page", "screen", "app", "view") name no component, so "a calendar
|
|
52
|
-
* page" asks for a page and "a calendar" for a part. A part starts from the
|
|
53
|
-
* base template of the family the idea names ("an empty state for a settings
|
|
54
|
-
* page"), else from the app shell. An idea that changes a page or part the
|
|
55
|
-
* builder already has starts from the app shell too: that page is the
|
|
56
|
-
* builder's to keep (FR9), and no template scaffolds it. "Existing" marks one
|
|
57
|
-
* when its phrase names a page family or a component ("add a column to the
|
|
58
|
-
* existing table"), unless the idea asks for a new page ("a new dashboard like
|
|
59
|
-
* the existing dashboard", "clone the existing dashboard as a new page"). A
|
|
60
|
-
* bare "existing" phrase that names a page ("existing reports dashboard with a
|
|
61
|
-
* date filter") reads as the builder's own page.
|
|
39
|
+
* `settings`) is that family's default; it wins when no variant's own words
|
|
40
|
+
* outweigh it.
|
|
62
41
|
*
|
|
63
42
|
* Family words come from the templates' own ids — a word in the ids of two or
|
|
64
43
|
* more templates of one family, plus the family's name when a template carries
|
|
@@ -71,68 +50,79 @@ import {stem, STOPWORDS, SYNONYMS} from '../../search/search.mjs';
|
|
|
71
50
|
|
|
72
51
|
/**
|
|
73
52
|
* How much a term counts by where the template names it. The id and category
|
|
74
|
-
* are the author's own label for what the page is;
|
|
75
|
-
* it serves; its
|
|
53
|
+
* are the author's own label for what the page is; the description's last
|
|
54
|
+
* sentence lists the ideas it serves; its body describes the layout.
|
|
76
55
|
*/
|
|
77
56
|
const FIELD_WEIGHT = {
|
|
78
57
|
id: 3,
|
|
79
58
|
variant: 3,
|
|
80
59
|
family: 2,
|
|
81
60
|
display: 2,
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
intent: 2,
|
|
62
|
+
body: 1,
|
|
84
63
|
};
|
|
85
|
-
/**
|
|
86
|
-
* A synonym hit counts half a direct hit: a synonym says the idea is near the
|
|
87
|
-
* page, not that it names it.
|
|
88
|
-
*/
|
|
64
|
+
/** A synonym hit counts at this share of a direct hit. */
|
|
89
65
|
const SYNONYM_SHARE = 0.5;
|
|
90
|
-
/**
|
|
91
|
-
* A container word ("in a modal") counts double: it names the page's frame,
|
|
92
|
-
* which is what a template is.
|
|
93
|
-
*/
|
|
66
|
+
/** A container word ("in a modal") counts this many times over. */
|
|
94
67
|
const CONTAINER = 2;
|
|
95
|
-
/**
|
|
96
|
-
* A word that only modifies another ("product" in "product response") counts
|
|
97
|
-
* half: it describes its head, not the page.
|
|
98
|
-
*/
|
|
68
|
+
/** A word that only modifies another ("product" in "product response"). */
|
|
99
69
|
const MODIFIER = 0.5;
|
|
100
|
-
/**
|
|
101
|
-
* Added when the idea's head names the template's family: more than any one
|
|
102
|
-
* word scores (an id word only one template carries is worth about ten), so the
|
|
103
|
-
* head's family outranks a rarer word among the parts.
|
|
104
|
-
*/
|
|
70
|
+
/** Added when the idea's head names the template's family. */
|
|
105
71
|
const HEAD_FAMILY = 12;
|
|
106
|
-
/**
|
|
107
|
-
* Added when the family is named anywhere else in the idea: about a description
|
|
108
|
-
* word, enough to settle a near tie.
|
|
109
|
-
*/
|
|
72
|
+
/** Added when the family is named anywhere else in the idea. */
|
|
110
73
|
const BODY_FAMILY = 2;
|
|
111
|
-
/**
|
|
112
|
-
* Added to a family's base template when the idea names that family: settles a
|
|
113
|
-
* near tie toward the family's default page.
|
|
114
|
-
*/
|
|
74
|
+
/** Added to a family's base template when the idea names that family. */
|
|
115
75
|
const FAMILY_BASE = 2;
|
|
116
76
|
/**
|
|
117
77
|
* The least a start must score, and the evidence it needs: two matched terms,
|
|
118
78
|
* or the idea naming its family. One rare word alone is how a tic-tac-toe game
|
|
119
|
-
* board became a kanban board
|
|
120
|
-
* displace its family's base template.
|
|
79
|
+
* board became a kanban board.
|
|
121
80
|
*/
|
|
122
81
|
const START_SCORE = 10;
|
|
123
82
|
const START_TERMS = 2;
|
|
124
|
-
/**
|
|
125
|
-
* How many listed pieces make an idea a page: a part is one thing with a detail
|
|
126
|
-
* or two ("a status pill with a tooltip"), while three pieces, two commas
|
|
127
|
-
* apart, describe a page.
|
|
128
|
-
*/
|
|
129
|
-
const PAGE_PIECES = 3;
|
|
130
83
|
|
|
131
84
|
/**
|
|
132
85
|
* Words search drops that name layout: "side navigation", "side by side".
|
|
133
86
|
*/
|
|
134
87
|
const LAYOUT_WORDS = new Set(['side']);
|
|
135
88
|
|
|
89
|
+
/** Filler that search keeps but that says nothing about a page's layout. */
|
|
90
|
+
const FILLER = new Set([
|
|
91
|
+
'per',
|
|
92
|
+
'each',
|
|
93
|
+
'every',
|
|
94
|
+
'using',
|
|
95
|
+
'via',
|
|
96
|
+
'into',
|
|
97
|
+
'onto',
|
|
98
|
+
'about',
|
|
99
|
+
'above',
|
|
100
|
+
'below',
|
|
101
|
+
'across',
|
|
102
|
+
'within',
|
|
103
|
+
'without',
|
|
104
|
+
'between',
|
|
105
|
+
'plus',
|
|
106
|
+
'also',
|
|
107
|
+
'then',
|
|
108
|
+
'them',
|
|
109
|
+
'they',
|
|
110
|
+
'which',
|
|
111
|
+
'while',
|
|
112
|
+
'when',
|
|
113
|
+
'all',
|
|
114
|
+
'any',
|
|
115
|
+
'new',
|
|
116
|
+
'use',
|
|
117
|
+
'used',
|
|
118
|
+
'show',
|
|
119
|
+
'shows',
|
|
120
|
+
'showing',
|
|
121
|
+
'display',
|
|
122
|
+
'displays',
|
|
123
|
+
'displaying',
|
|
124
|
+
]);
|
|
125
|
+
|
|
136
126
|
/**
|
|
137
127
|
* Where an idea's head ends: its first clause, before the parts it lists.
|
|
138
128
|
*/
|
|
@@ -152,24 +142,6 @@ const OVERLAY_FRAMES = new Set([
|
|
|
152
142
|
'overlay',
|
|
153
143
|
]);
|
|
154
144
|
|
|
155
|
-
/**
|
|
156
|
-
* The word that marks a page or part the builder already has, when its phrase
|
|
157
|
-
* names one (see `changesExistingPage`).
|
|
158
|
-
*/
|
|
159
|
-
const EXISTING = /\bexisting\b/i;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* The word that marks an idea asking for a new page ("a new dashboard", "as a
|
|
163
|
-
* new page"), which is never a change to one the builder has.
|
|
164
|
-
*/
|
|
165
|
-
const NEW = /\bnew\b/;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The family whose templates are app chrome rather than page content: the
|
|
169
|
-
* explicit `Shell -` category (architecture:template-authoring/INV7).
|
|
170
|
-
*/
|
|
171
|
-
const SHELL_FAMILY = 'Shell';
|
|
172
|
-
|
|
173
145
|
/** A container phrase: "in a modal", "inside the side panel". */
|
|
174
146
|
const CONTAINER_PHRASE =
|
|
175
147
|
/\b(?:in|inside|within)\s+(?:a|an|the)\s+([a-z-]+)(?:\s+([a-z-]+))?/gi;
|
|
@@ -183,11 +155,12 @@ const PHRASE_END =
|
|
|
183
155
|
|
|
184
156
|
/** @param {string} t */
|
|
185
157
|
const isContentWord = t =>
|
|
186
|
-
t.length >= 2 &&
|
|
158
|
+
t.length >= 2 &&
|
|
159
|
+
(LAYOUT_WORDS.has(t) || (!STOPWORDS.has(t) && !FILLER.has(t)));
|
|
187
160
|
|
|
188
161
|
/**
|
|
189
|
-
* Content terms of a text: lowercase alphanumeric words, stopwords
|
|
190
|
-
* stemmed.
|
|
162
|
+
* Content terms of a text: lowercase alphanumeric words, stopwords and filler
|
|
163
|
+
* removed, stemmed.
|
|
191
164
|
* @param {string} text
|
|
192
165
|
* @returns {string[]}
|
|
193
166
|
*/
|
|
@@ -289,44 +262,8 @@ const SYNONYMS_OF = (() => {
|
|
|
289
262
|
|
|
290
263
|
/**
|
|
291
264
|
* @typedef {import('../_adapter.mjs').PageTemplate} PageTemplate
|
|
292
|
-
* @typedef {
|
|
293
|
-
* @typedef {{name: string, score: number, hits: number, familyNamed: boolean, containerMatched: boolean, family: string, base: boolean, matched: Set<string>}} RankedPage
|
|
294
|
-
* @typedef {'page' | 'part' | 'edit'} IdeaKind
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
/** @param {PageTemplate} page */
|
|
298
|
-
const familyOf = page => (page.category.split(' - ')[0] ?? '').trim();
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Family words, from the templates' own ids: a word in the ids of two or more
|
|
302
|
-
* templates of one family, plus the family's name when a template carries it.
|
|
303
|
-
* Each word maps to its family.
|
|
304
|
-
* @param {PageTemplate[]} pages
|
|
305
|
-
* @returns {Map<string, string>}
|
|
265
|
+
* @typedef {{name: string, score: number, hits: number, familyNamed: boolean, containerMatched: boolean}} RankedPage
|
|
306
266
|
*/
|
|
307
|
-
function familyWordsOf(pages) {
|
|
308
|
-
/** @type {Map<string, Map<string, number>>} */
|
|
309
|
-
const idWords = new Map();
|
|
310
|
-
for (const page of pages) {
|
|
311
|
-
const family = familyOf(page);
|
|
312
|
-
const counts = idWords.get(family) ?? new Map();
|
|
313
|
-
for (const w of new Set(page.name.split('-'))) {
|
|
314
|
-
if (w.length >= 3) counts.set(stem(w), (counts.get(stem(w)) ?? 0) + 1);
|
|
315
|
-
}
|
|
316
|
-
idWords.set(family, counts);
|
|
317
|
-
}
|
|
318
|
-
/** @type {Map<string, string>} */
|
|
319
|
-
const familyOfWord = new Map();
|
|
320
|
-
for (const [family, counts] of idWords) {
|
|
321
|
-
const heads = [...counts].filter(([, c]) => c >= 2).map(([w]) => w);
|
|
322
|
-
const name = normalized(family).split(' ').pop() ?? '';
|
|
323
|
-
if (name.length >= 3 && counts.has(stem(name))) heads.push(stem(name));
|
|
324
|
-
for (const head of heads) {
|
|
325
|
-
if (!familyOfWord.has(head)) familyOfWord.set(head, family);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return familyOfWord;
|
|
329
|
-
}
|
|
330
267
|
|
|
331
268
|
/**
|
|
332
269
|
* Rank page templates against an idea, best first. Ties go to the template
|
|
@@ -339,15 +276,20 @@ function familyWordsOf(pages) {
|
|
|
339
276
|
export function rankPages(query, pages) {
|
|
340
277
|
const docs = pages.map(page => {
|
|
341
278
|
const [family = '', ...variantParts] = page.category.split(' - ');
|
|
279
|
+
const sentences = page.description.trim().split(/(?<=[.!?])\s+/);
|
|
280
|
+
const intent = sentences.length > 1 ? sentences[sentences.length - 1] : '';
|
|
281
|
+
const body =
|
|
282
|
+
sentences.length > 1
|
|
283
|
+
? sentences.slice(0, -1).join(' ')
|
|
284
|
+
: page.description;
|
|
342
285
|
/** @type {Record<keyof typeof FIELD_WEIGHT, string>} */
|
|
343
286
|
const fields = {
|
|
344
287
|
id: page.name.replace(/-/g, ' '),
|
|
345
288
|
variant: variantParts.join(' - '),
|
|
346
289
|
family,
|
|
347
290
|
display: page.displayName,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
description: page.description,
|
|
291
|
+
intent,
|
|
292
|
+
body,
|
|
351
293
|
};
|
|
352
294
|
/** @type {Map<string, number>} */
|
|
353
295
|
const bag = new Map();
|
|
@@ -378,7 +320,26 @@ export function rankPages(query, pages) {
|
|
|
378
320
|
return d ? Math.log(1 + (n - d + 0.5) / (d + 0.5)) : 0;
|
|
379
321
|
};
|
|
380
322
|
|
|
381
|
-
|
|
323
|
+
// Family words, from the templates' own ids.
|
|
324
|
+
/** @type {Map<string, Map<string, number>>} */
|
|
325
|
+
const idWords = new Map();
|
|
326
|
+
for (const {page, family} of docs) {
|
|
327
|
+
const counts = idWords.get(family) ?? new Map();
|
|
328
|
+
for (const w of new Set(page.name.split('-'))) {
|
|
329
|
+
if (w.length >= 3) counts.set(stem(w), (counts.get(stem(w)) ?? 0) + 1);
|
|
330
|
+
}
|
|
331
|
+
idWords.set(family, counts);
|
|
332
|
+
}
|
|
333
|
+
/** @type {Map<string, string>} */
|
|
334
|
+
const familyOfWord = new Map();
|
|
335
|
+
for (const [family, counts] of idWords) {
|
|
336
|
+
const heads = [...counts].filter(([, c]) => c >= 2).map(([w]) => w);
|
|
337
|
+
const name = normalized(family).split(' ').pop() ?? '';
|
|
338
|
+
if (name.length >= 3 && counts.has(stem(name))) heads.push(stem(name));
|
|
339
|
+
for (const head of heads) {
|
|
340
|
+
if (!familyOfWord.has(head)) familyOfWord.set(head, family);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
382
343
|
/** @param {string[]} ts */
|
|
383
344
|
const familiesIn = ts =>
|
|
384
345
|
new Set(ts.filter(t => familyOfWord.has(t)).map(t => familyOfWord.get(t)));
|
|
@@ -391,13 +352,11 @@ export function rankPages(query, pages) {
|
|
|
391
352
|
const modifiers = modifiersOf(query);
|
|
392
353
|
const containers = containersOf(query);
|
|
393
354
|
|
|
394
|
-
|
|
355
|
+
return docs
|
|
395
356
|
.map(({page, family, bag, pairs}) => {
|
|
396
357
|
let score = 0;
|
|
397
358
|
let hits = 0;
|
|
398
359
|
let containerMatched = false;
|
|
399
|
-
/** @type {Set<string>} */
|
|
400
|
-
const matched = new Set();
|
|
401
360
|
for (const t of queryTerms) {
|
|
402
361
|
// A modifier is discounted where the template names it outright; a
|
|
403
362
|
// synonym hit is already discounted by SYNONYM_SHARE.
|
|
@@ -419,25 +378,16 @@ export function rankPages(query, pages) {
|
|
|
419
378
|
if (value > 0) {
|
|
420
379
|
score += value;
|
|
421
380
|
hits++;
|
|
422
|
-
matched.add(t);
|
|
423
381
|
if (containers.has(t)) containerMatched = true;
|
|
424
382
|
}
|
|
425
383
|
}
|
|
426
384
|
const familyNamed = namedFamilies.has(family);
|
|
427
385
|
if (headFamilies.has(family)) score += HEAD_FAMILY;
|
|
428
386
|
else if (familyNamed) score += BODY_FAMILY;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
score,
|
|
434
|
-
hits,
|
|
435
|
-
familyNamed,
|
|
436
|
-
containerMatched,
|
|
437
|
-
family,
|
|
438
|
-
base,
|
|
439
|
-
matched,
|
|
440
|
-
};
|
|
387
|
+
if (familyNamed && normalized(page.name) === normalized(family)) {
|
|
388
|
+
score += FAMILY_BASE;
|
|
389
|
+
}
|
|
390
|
+
return {name: page.name, score, hits, familyNamed, containerMatched};
|
|
441
391
|
})
|
|
442
392
|
.sort(
|
|
443
393
|
(a, b) =>
|
|
@@ -445,123 +395,6 @@ export function rankPages(query, pages) {
|
|
|
445
395
|
a.name.split('-').length - b.name.split('-').length ||
|
|
446
396
|
a.name.localeCompare(b.name),
|
|
447
397
|
);
|
|
448
|
-
return baseFirst(ranked);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Put a named family's base template ahead of the variant that outranks it,
|
|
453
|
-
* unless the variant matched START_TERMS terms the base did not, or the base
|
|
454
|
-
* scores too little to start on its own.
|
|
455
|
-
* @param {RankedPage[]} ranked
|
|
456
|
-
* @returns {RankedPage[]}
|
|
457
|
-
*/
|
|
458
|
-
function baseFirst(ranked) {
|
|
459
|
-
const top = ranked[0];
|
|
460
|
-
if (!top || top.base || !top.familyNamed) return ranked;
|
|
461
|
-
const base = ranked.find(r => r.base && r.family === top.family);
|
|
462
|
-
if (!base || base.score < START_SCORE) return ranked;
|
|
463
|
-
const own = [...top.matched].filter(t => !base.matched.has(t)).length;
|
|
464
|
-
return own >= START_TERMS
|
|
465
|
-
? ranked
|
|
466
|
-
: [base, ...ranked.filter(r => r !== base)];
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* What an idea asks for (spec:AST-048/FR3): a whole `page`; a `part` of one,
|
|
471
|
-
* when its head noun names one of the system's components and it lists fewer
|
|
472
|
-
* than PAGE_PIECES pieces; or an `edit` of a page the builder already has.
|
|
473
|
-
*
|
|
474
|
-
* @param {string} query
|
|
475
|
-
* @param {PageTemplate[]} pages
|
|
476
|
-
* @param {ComponentWords[]} components
|
|
477
|
-
* @returns {IdeaKind}
|
|
478
|
-
*/
|
|
479
|
-
export function ideaKind(query, pages, components) {
|
|
480
|
-
const text = String(query);
|
|
481
|
-
const familyWords = familyWordsOf(pages);
|
|
482
|
-
if (changesExistingPage(text, familyWords, components)) return 'edit';
|
|
483
|
-
// The head's last word, page words included: "calendar" is the noun of "a
|
|
484
|
-
// calendar", "page" the noun of "a calendar page". An overlay frame names
|
|
485
|
-
// where the thing lives, not the thing: "drafts" is the noun of "drafts in
|
|
486
|
-
// a modal".
|
|
487
|
-
const head = (text.split(HEAD_END)[0] ?? '').replace(CONTAINER_PHRASE, m =>
|
|
488
|
-
containersOf(m).size > 0 ? ' ' : m,
|
|
489
|
-
);
|
|
490
|
-
const words = (head.toLowerCase().match(/[a-z0-9]+/g) ?? []).filter(
|
|
491
|
-
w => w.length >= 2,
|
|
492
|
-
);
|
|
493
|
-
const noun = stem(words[words.length - 1] ?? '');
|
|
494
|
-
if (familyWords.has(noun)) return 'page';
|
|
495
|
-
const pieces = (text.match(/,/g) ?? []).length + 1;
|
|
496
|
-
if (pieces >= PAGE_PIECES) return 'page';
|
|
497
|
-
return components.some(c => componentTerms(c).includes(noun))
|
|
498
|
-
? 'part'
|
|
499
|
-
: 'page';
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Whether an idea changes a page or part the builder already has: "existing"
|
|
504
|
-
* in the same phrase as a word that names a family of page templates or one of
|
|
505
|
-
* the system's components ("the existing incidents table", "the existing
|
|
506
|
-
* banner"). A new page "inspired by the existing one", or "existing users" on a
|
|
507
|
-
* new page, names neither, and an idea that asks for a new page is no change
|
|
508
|
-
* whatever it names.
|
|
509
|
-
* @param {string} text
|
|
510
|
-
* @param {Map<string, string>} familyWords
|
|
511
|
-
* @param {ComponentWords[]} components
|
|
512
|
-
* @returns {boolean}
|
|
513
|
-
*/
|
|
514
|
-
function changesExistingPage(text, familyWords, components) {
|
|
515
|
-
const componentWords = new Set(components.flatMap(nameTerms));
|
|
516
|
-
const phrases = text.toLowerCase().split(PHRASE_END);
|
|
517
|
-
if (asksNewPage(phrases, familyWords)) return false;
|
|
518
|
-
return phrases.some(phrase => {
|
|
519
|
-
const at = phrase.search(EXISTING);
|
|
520
|
-
return (
|
|
521
|
-
at >= 0 &&
|
|
522
|
-
terms(phrase.slice(at)).some(
|
|
523
|
-
t => familyWords.has(t) || componentWords.has(t),
|
|
524
|
-
)
|
|
525
|
-
);
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Whether an idea asks for a new page: "new" before a word that names a family
|
|
531
|
-
* of page templates ("a new dashboard"), or before only words search drops,
|
|
532
|
-
* such as "page" ("as a new page"). "A new column" asks for a part.
|
|
533
|
-
* @param {string[]} phrases
|
|
534
|
-
* @param {Map<string, string>} familyWords
|
|
535
|
-
* @returns {boolean}
|
|
536
|
-
*/
|
|
537
|
-
function asksNewPage(phrases, familyWords) {
|
|
538
|
-
return phrases.some(phrase => {
|
|
539
|
-
const at = phrase.search(NEW);
|
|
540
|
-
if (at < 0) return false;
|
|
541
|
-
const after = terms(phrase.slice(at + 'new'.length));
|
|
542
|
-
return after.length === 0 || familyWords.has(after[0]);
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* The words of a component's name: "DateRangeInput" is date, range, input.
|
|
548
|
-
* @param {ComponentWords} component
|
|
549
|
-
* @returns {string[]}
|
|
550
|
-
*/
|
|
551
|
-
function nameTerms(component) {
|
|
552
|
-
return terms(component.name.replace(/([a-z0-9])([A-Z])/g, '$1 $2'));
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* The terms a component answers to: the words of its name and of its keywords.
|
|
557
|
-
* @param {ComponentWords} component
|
|
558
|
-
* @returns {string[]}
|
|
559
|
-
*/
|
|
560
|
-
function componentTerms(component) {
|
|
561
|
-
return [
|
|
562
|
-
...nameTerms(component),
|
|
563
|
-
...component.keywords.flatMap(keyword => terms(keyword)),
|
|
564
|
-
];
|
|
565
398
|
}
|
|
566
399
|
|
|
567
400
|
/**
|
|
@@ -583,27 +416,14 @@ export function pickAlternatives(ranked, startName, count = 2) {
|
|
|
583
416
|
}
|
|
584
417
|
|
|
585
418
|
/**
|
|
586
|
-
* The template to start from, or null
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
* the idea places it in, else from the app shell (spec:AST-048/FR3); an edit of
|
|
590
|
-
* a page the builder already has starts from the app shell (FR9). Either way,
|
|
591
|
-
* the app shell is the shell template the idea describes when one leads.
|
|
419
|
+
* The template to start from, or null when the best one has too little
|
|
420
|
+
* evidence to lead and the page should start from the app shell. Evidence is
|
|
421
|
+
* two matched terms, the idea naming the template's family, or its container.
|
|
592
422
|
*
|
|
593
423
|
* @param {RankedPage[]} ranked
|
|
594
|
-
* @param {IdeaKind} [kind]
|
|
595
424
|
* @returns {RankedPage | null}
|
|
596
425
|
*/
|
|
597
|
-
export function pickStart(ranked
|
|
598
|
-
if (kind !== 'page') {
|
|
599
|
-
const host = kind === 'part' && ranked.find(r => r.base && r.familyNamed);
|
|
600
|
-
if (host) return host;
|
|
601
|
-
// Otherwise the app shell (FR2): the shell template the idea describes
|
|
602
|
-
// when one leads ("a frame with sidebar navigation"), else none, for the
|
|
603
|
-
// kit's neutral fallback.
|
|
604
|
-
const lead = pickStart(ranked);
|
|
605
|
-
return lead?.family === SHELL_FAMILY ? lead : null;
|
|
606
|
-
}
|
|
426
|
+
export function pickStart(ranked) {
|
|
607
427
|
const top = ranked[0];
|
|
608
428
|
if (!top || top.score < START_SCORE) return null;
|
|
609
429
|
return top.hits >= START_TERMS || top.familyNamed || top.containerMatched
|