@astryxdesign/cli 0.6.5-canary.c3016f8 → 0.6.5-canary.f261d2f

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 (96) hide show
  1. package/api/build/_adapter.d.mts +36 -2
  2. package/api/build/_adapter.mjs +41 -10
  3. package/api/build/build.doc.mjs +2 -2
  4. package/api/build/build.test.mjs +38 -2
  5. package/api/build/kit/kit.mjs +65 -21
  6. package/api/build/kit/rank.d.mts +24 -8
  7. package/api/build/kit/rank.mjs +277 -97
  8. package/api/build/kit/rank.test.mjs +231 -48
  9. package/api/docs/docs.test.mjs +279 -0
  10. package/api/docs/integration-tree.test.mjs +572 -0
  11. package/api/docs/integrationDocs.test.mjs +336 -0
  12. package/api/integration/add-contribution.test.mjs +3 -3
  13. package/api/integration/add-theme.mjs +3 -2
  14. package/api/integration/add-theme.test.mjs +1 -1
  15. package/api/integration/pack-check.mjs +12 -3
  16. package/api/integration/pack-check.test.mjs +52 -3
  17. package/api/search/search.d.mts +24 -0
  18. package/api/search/search.mjs +71 -1
  19. package/api/search/search.test.mjs +710 -0
  20. package/api/template/template-integration.test.mjs +14 -0
  21. package/assets/docs/theme.doc.mjs +1 -1
  22. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  23. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  24. package/assets/docs/tree/checks.doc.mjs +1 -1
  25. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  26. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  27. package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
  28. package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
  29. package/assets/docs/tree/versioning.doc.mjs +7 -6
  30. package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
  31. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
  32. package/assets/templates/pages/blank/template.doc.mjs +3 -1
  33. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
  34. package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
  35. package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
  36. package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
  37. package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
  38. package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
  39. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
  40. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
  41. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
  42. package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
  43. package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
  44. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
  45. package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
  46. package/assets/templates/pages/documentation/template.doc.mjs +10 -1
  47. package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
  48. package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
  49. package/assets/templates/pages/editor/template.doc.mjs +9 -1
  50. package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
  51. package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
  52. package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
  53. package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
  54. package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
  55. package/assets/templates/pages/ide/template.doc.mjs +9 -1
  56. package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
  57. package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
  58. package/assets/templates/pages/library/template.doc.mjs +15 -1
  59. package/assets/templates/pages/login/template.doc.mjs +10 -1
  60. package/assets/templates/pages/login-card/template.doc.mjs +11 -1
  61. package/assets/templates/pages/login-split/template.doc.mjs +10 -1
  62. package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
  63. package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
  64. package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
  65. package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
  66. package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
  67. package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
  68. package/assets/templates/pages/settings/template.doc.mjs +3 -1
  69. package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
  70. package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
  71. package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
  72. package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
  73. package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
  74. package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
  75. package/assets/templates/pages/table/template.doc.mjs +11 -1
  76. package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
  77. package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
  78. package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
  79. package/assets/templates/pages/table-page/template.doc.mjs +20 -1
  80. package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
  81. package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
  82. package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
  83. package/authoring/doctypes/template/parse.d.mts +2 -0
  84. package/authoring/doctypes/template/parse.mjs +1 -0
  85. package/authoring/doctypes/template/parse.test.mjs +21 -0
  86. package/authoring/doctypes/template/template.doc.mjs +6 -0
  87. package/authoring/doctypes/template/type.ts +10 -0
  88. package/clients/cli/commands/docs.test.mjs +383 -0
  89. package/foundation/agent-docs/agent-docs.test.mjs +1160 -0
  90. package/foundation/discovery/template-adapter.d.mts +1 -0
  91. package/foundation/discovery/template-adapter.mjs +5 -0
  92. package/foundation/doc-compiler/tree.test.mjs +649 -0
  93. package/foundation/integrations/cli-requirement.d.mts +57 -13
  94. package/foundation/integrations/cli-requirement.mjs +84 -22
  95. package/foundation/integrations/cli-requirement.test.mjs +135 -8
  96. package/package.json +9 -9
@@ -7,8 +7,15 @@
7
7
  * @property {string} name The template's own id, as search reports it.
8
8
  * @property {string} command `astryx template <id> --type page`, the command that selects exactly this template: an integration replacement is selected by the Core id it replaces, and `--type page` keeps a block with the same id from making it ambiguous. Search prints template commands the same way.
9
9
  * @property {string} displayName Human-facing name.
10
- * @property {string} description What the page is: its layout and the ideas it serves.
10
+ * @property {string} description What the page is and how it is laid out.
11
11
  * @property {string} category The template's own `Family - Variant` label; empty when it declares none.
12
+ * @property {string[]} keywords The ideas the page serves, as its own descriptor names them; empty when it declares none.
13
+ */
14
+ /**
15
+ * A component the project can use, as the ranker reads it.
16
+ * @typedef {object} ComponentWords
17
+ * @property {string} name The component's name, e.g. `DateRangeInput`.
18
+ * @property {string[]} keywords The keywords its own doc declares.
12
19
  */
13
20
  /**
14
21
  * Every ready page template the project can scaffold, in discovery order. This
@@ -23,6 +30,16 @@
23
30
  * @returns {Promise<PageTemplate[]>}
24
31
  */
25
32
  export function loadPageTemplates(cwd: string): Promise<PageTemplate[]>;
33
+ /**
34
+ * The components the project can use, Core's and its integrations', each with
35
+ * the keywords its own doc declares: what the ranker reads to tell a part of a
36
+ * page from a page. Search's own discovery, so both agree on what exists; empty
37
+ * when Core cannot be found.
38
+ *
39
+ * @param {string} cwd
40
+ * @returns {Promise<ComponentWords[]>}
41
+ */
42
+ export function loadComponents(cwd: string): Promise<ComponentWords[]>;
26
43
  /**
27
44
  * A page template the kit can recommend starting from.
28
45
  */
@@ -40,11 +57,28 @@ export type PageTemplate = {
40
57
  */
41
58
  displayName: string;
42
59
  /**
43
- * What the page is: its layout and the ideas it serves.
60
+ * What the page is and how it is laid out.
44
61
  */
45
62
  description: string;
46
63
  /**
47
64
  * The template's own `Family - Variant` label; empty when it declares none.
48
65
  */
49
66
  category: string;
67
+ /**
68
+ * The ideas the page serves, as its own descriptor names them; empty when it declares none.
69
+ */
70
+ keywords: string[];
71
+ };
72
+ /**
73
+ * A component the project can use, as the ranker reads it.
74
+ */
75
+ export type ComponentWords = {
76
+ /**
77
+ * The component's name, e.g. `DateRangeInput`.
78
+ */
79
+ name: string;
80
+ /**
81
+ * The keywords its own doc declares.
82
+ */
83
+ keywords: string[];
50
84
  };
@@ -2,20 +2,23 @@
2
2
 
3
3
  /**
4
4
  * @file The build subject's environment access: the page templates a project
5
- * can scaffold.
5
+ * can scaffold, and the components it can use.
6
6
  *
7
- * @input Template discovery for `cwd` — the CLI's own templates plus any that
8
- * the project's configured integrations contribute.
7
+ * @input Template and component discovery for `cwd` — the CLI's own templates
8
+ * and Core's components, plus any that the project's configured integrations
9
+ * contribute.
9
10
  * @output Ready page templates as `{name, displayName, description, category,
10
- * command}`, where `command` is the `astryx template` command that selects
11
- * exactly that template.
12
- * @position Beside build.mjs (api/build/). The kit leaf reads templates only
13
- * through here, because a subject's `_adapter.mjs` is its only environment
14
- * access. Search keeps its own discovery; this adds none of its own, it
15
- * reuses the template subject's.
11
+ * keywords, command}`, where `command` is the `astryx template` command that
12
+ * selects exactly that template; components as `{name, keywords}`.
13
+ * @position Beside build.mjs (api/build/). The kit leaf reads templates and
14
+ * components only through here, because a subject's `_adapter.mjs` is its
15
+ * only environment access. This adds no discovery of its own: templates come
16
+ * from the template subject's, components from search's.
16
17
  */
17
18
 
18
19
  import {discoverTemplates} from '../template/template.mjs';
20
+ import {componentKeywords} from '../search/search.mjs';
21
+ import {findCoreDir} from '../../foundation/fs/paths.mjs';
19
22
 
20
23
  /**
21
24
  * A page template the kit can recommend starting from.
@@ -23,8 +26,16 @@ import {discoverTemplates} from '../template/template.mjs';
23
26
  * @property {string} name The template's own id, as search reports it.
24
27
  * @property {string} command `astryx template <id> --type page`, the command that selects exactly this template: an integration replacement is selected by the Core id it replaces, and `--type page` keeps a block with the same id from making it ambiguous. Search prints template commands the same way.
25
28
  * @property {string} displayName Human-facing name.
26
- * @property {string} description What the page is: its layout and the ideas it serves.
29
+ * @property {string} description What the page is and how it is laid out.
27
30
  * @property {string} category The template's own `Family - Variant` label; empty when it declares none.
31
+ * @property {string[]} keywords The ideas the page serves, as its own descriptor names them; empty when it declares none.
32
+ */
33
+
34
+ /**
35
+ * A component the project can use, as the ranker reads it.
36
+ * @typedef {object} ComponentWords
37
+ * @property {string} name The component's name, e.g. `DateRangeInput`.
38
+ * @property {string[]} keywords The keywords its own doc declares.
28
39
  */
29
40
 
30
41
  /**
@@ -53,8 +64,28 @@ export async function loadPageTemplates(cwd) {
53
64
  displayName: t.displayName || t.name,
54
65
  description: t.description || '',
55
66
  category: t.category || '',
67
+ keywords: t.keywords ?? [],
56
68
  // The id `template()` resolves back to this entry: an active replacement
57
69
  // owns the Core id it names, so that id selects it, not its own.
58
70
  command: `astryx template ${t.replaces ?? t.dirName} --type page`,
59
71
  }));
60
72
  }
73
+
74
+ /**
75
+ * The components the project can use, Core's and its integrations', each with
76
+ * the keywords its own doc declares: what the ranker reads to tell a part of a
77
+ * page from a page. Search's own discovery, so both agree on what exists; empty
78
+ * when Core cannot be found.
79
+ *
80
+ * @param {string} cwd
81
+ * @returns {Promise<ComponentWords[]>}
82
+ */
83
+ export async function loadComponents(cwd) {
84
+ const coreDir = findCoreDir(cwd);
85
+ if (!coreDir) return [];
86
+ try {
87
+ return await componentKeywords(coreDir, cwd);
88
+ } catch {
89
+ return [];
90
+ }
91
+ }
@@ -19,8 +19,8 @@ export const doc = {
19
19
  'The "build a page" entry point. Called with no query it returns the ' +
20
20
  'how-to-build-a-page playbook as data: the workflow steps with their ' +
21
21
  'commands, the on-system rules, and related lookups. Called with a query it names the page template to ' +
22
- 'START from (always one: the page template a ranker built for long descriptions puts first, else the app ' +
23
- 'shell) and the next two templates, ' +
22
+ 'START from (always one: the page template a ranker built for long descriptions puts first; for a part ' +
23
+ 'of a page, the page it names; else the app shell) and the next two templates, ' +
24
24
  'and the unified search grouped around it: the other close page templates, drop-in blocks, and ' +
25
25
  'idea-specific components/hooks, plus the always-on frame + foundation. A template carries the page ' +
26
26
  'frame and spacing, so the kit never recommends composing a page from components.',
@@ -8,7 +8,7 @@ import {describe, it, expect, vi} from 'vitest';
8
8
  import * as path from 'node:path';
9
9
  import {fileURLToPath} from 'node:url';
10
10
  import {build} from './build.mjs';
11
- import {search} from '../search/search.mjs';
11
+ import {search, searchedComponents} from '../search/search.mjs';
12
12
 
13
13
  // api/build/ -> up 3 = packages/cli, up 4 = repo root (has packages/core).
14
14
  const REPO = path.resolve(
@@ -152,6 +152,16 @@ describe('build API', () => {
152
152
  });
153
153
  });
154
154
 
155
+ describe('build kit — reuses the components its search gathered', () => {
156
+ it('keeps them beside the search response, out of its JSON', async () => {
157
+ const all = await search('date picker', {cwd: REPO});
158
+ expect(searchedComponents(all)?.map(c => c.name)).toContain('DateRangeInput');
159
+ expect(JSON.stringify(all)).not.toContain('"keywords"');
160
+ const pagesOnly = await search('date picker', {cwd: REPO, type: 'template'});
161
+ expect(searchedComponents(pagesOnly)).toBeNull();
162
+ }, 60_000);
163
+ });
164
+
155
165
  describe('build kit — coverage gates the pages group', () => {
156
166
  it('does not call a one-word coincidence a direct match', async () => {
157
167
  // A page's keywords include every component its source renders, so any
@@ -259,7 +269,7 @@ describe('build kit — a thin kit says what to try next', () => {
259
269
  // A skeleton is a 35-line excerpt: a reader who studies it and composes
260
270
  // the rest loses the spacing the template exists to carry. A loose match
261
271
  // is still the best start there is, so `start` scaffolds it.
262
- const r = await build('executive summary', {cwd: REPO});
272
+ const r = await build('quarterly business review', {cwd: REPO});
263
273
  expect(r.type).toBe('build.kit');
264
274
  if (r.type !== 'build.kit') return;
265
275
  expect(r.data.directMatch).toBe(false);
@@ -357,9 +367,35 @@ describe('build kit — every page starts from a template', () => {
357
367
  const placed = await build('an empty state for a settings page', {cwd: REPO});
358
368
  if (placed.type !== 'build.kit') throw new Error(placed.type);
359
369
  expect(placed.data.start).toMatchObject({name: 'settings', basis: 'closest'});
370
+ expect(placed.data.start?.reason).toMatch(/part of a page, so it starts from the page it names/);
360
371
  const loose = await build('a date range picker', {cwd: REPO});
361
372
  if (loose.type !== 'build.kit') throw new Error(loose.type);
362
373
  expect(loose.data.start).toMatchObject({name: 'shell-top-nav', basis: 'fallback'});
374
+ expect(loose.data.start?.reason).toMatch(/part of a page and names no page, so it starts from the app shell/);
375
+ });
376
+
377
+ it('starts a change to an existing page from the app shell', async () => {
378
+ // The page is the builder's to keep; no template scaffolds it.
379
+ const r = await build('add a sort toggle to the existing reports dashboard', {cwd: REPO});
380
+ if (r.type !== 'build.kit') throw new Error(r.type);
381
+ expect(r.data.start).toMatchObject({name: 'shell-top-nav', basis: 'fallback'});
382
+ expect(r.data.start?.reason).toMatch(/changes a page you already have, so keep it/);
383
+ expect(r.data.start?.reason).not.toMatch(/too little of the idea fits/);
384
+ // A direct match the response reports is still named.
385
+ if (r.data.directMatch) expect(r.data.start?.reason).toContain(`\`${r.data.pages[0].name}\``);
386
+ });
387
+
388
+ it('does not call a new page that mentions something existing a change', async () => {
389
+ for (const idea of [
390
+ 'a new dashboard inspired by the existing one',
391
+ 'a new dashboard based on the existing dashboard',
392
+ 'clone the existing dashboard as a new page',
393
+ ]) {
394
+ const r = await build(idea, {cwd: REPO});
395
+ if (r.type !== 'build.kit') throw new Error(r.type);
396
+ expect(r.data.start?.name).toBe('dashboard');
397
+ expect(r.data.start?.reason).not.toMatch(/already have/);
398
+ }
363
399
  });
364
400
 
365
401
  it('names a direct match the ranker outweighed in the reason', async () => {
@@ -27,13 +27,13 @@
27
27
  * the invocation stays the renderer's job.
28
28
  */
29
29
 
30
- import {search} from '../../search/search.mjs';
30
+ import {search, searchedComponents} from '../../search/search.mjs';
31
31
  import {findCoreDir} from '../../../foundation/fs/paths.mjs';
32
32
  import {AstryxError} from '../../error.mjs';
33
33
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
34
34
  import {getResultCoverage} from '../../search/coverage.mjs';
35
- import {loadPageTemplates} from '../_adapter.mjs';
36
- import {pickAlternatives, pickStart, rankPages} from './rank.mjs';
35
+ import {loadComponents, loadPageTemplates} from '../_adapter.mjs';
36
+ import {ideaKind, pickAlternatives, pickStart, rankPages} from './rank.mjs';
37
37
 
38
38
  /** A page at/above this score is a confident direct match. */
39
39
  const PAGE_DIRECT = 95;
@@ -118,6 +118,24 @@ const asTemplate = t => ({
118
118
  command: `${t.command} <path>`,
119
119
  });
120
120
 
121
+ /**
122
+ * Why a part of a page, or a change to a page the builder already has, starts
123
+ * where it does (spec:AST-048/FR3, FR9): the rest of the start's reason, or
124
+ * null for a whole page.
125
+ * @param {import('./rank.mjs').IdeaKind} kind
126
+ * @param {boolean} inPage whether the start is the page the idea names
127
+ * @returns {string | null}
128
+ */
129
+ function placement(kind, inPage) {
130
+ if (kind === 'edit')
131
+ return 'the idea changes a page you already have, so keep it and add blocks to it; a new page starts from the app shell.';
132
+ if (kind === 'part')
133
+ return inPage
134
+ ? 'the idea is a part of a page, so it starts from the page it names.'
135
+ : 'the idea is a part of a page and names no page, so it starts from the app shell.';
136
+ return null;
137
+ }
138
+
121
139
  /**
122
140
  * The template to start from: the ready page the ranker puts first when it
123
141
  * has the evidence to lead, else the first fallback shell the project can
@@ -129,12 +147,13 @@ const asTemplate = t => ({
129
147
  * the reason names it, so the reader knows why the kit starts elsewhere.
130
148
  *
131
149
  * @param {import('./rank.mjs').RankedPage[]} ranked
150
+ * @param {import('./rank.mjs').IdeaKind} kind
132
151
  * @param {SearchResultEntry[]} pages
133
152
  * @param {boolean} directMatch
134
153
  * @param {PageTemplate[]} catalog
135
154
  * @returns {Omit<BuildStart, 'alternatives'> | null}
136
155
  */
137
- function chooseStart(ranked, pages, directMatch, catalog) {
156
+ function chooseStart(ranked, kind, pages, directMatch, catalog) {
138
157
  const direct = directMatch ? pages[0].name : null;
139
158
  const unready =
140
159
  direct && !catalog.some(t => t.name === direct) ? direct : null;
@@ -142,20 +161,32 @@ function chooseStart(ranked, pages, directMatch, catalog) {
142
161
  // match the ranker outweighed is named, and so are the loose page matches
143
162
  // search listed when the kit falls back to the shell.
144
163
  const loose = pages.map(p => `\`${p.name}\``).join(', ');
145
- const pick = pickStart(ranked);
164
+ /**
165
+ * A part's or an edit's reason, naming a direct match that is not the start.
166
+ * @param {string} place
167
+ * @param {string} startName
168
+ */
169
+ const placed = (place, startName) =>
170
+ direct && direct !== startName
171
+ ? `Search matched \`${direct}\` by name, but ${place}`
172
+ : place[0].toUpperCase() + place.slice(1);
173
+ const pick = pickStart(ranked, kind);
146
174
  const closest = pick && catalog.find(t => t.name === pick.name);
147
- if (closest) {
175
+ if (pick && closest) {
148
176
  const agrees = closest.name === direct;
177
+ const place = placement(kind, pick.base && pick.familyNamed);
149
178
  return {
150
179
  ...asTemplate(closest),
151
180
  basis: agrees ? 'direct' : 'closest',
152
- reason: agrees
153
- ? 'Matches the idea.'
154
- : unready
155
- ? `\`${unready}\` matches but is not ready yet; this is the closest ready template.`
156
- : direct
157
- ? `Search matched \`${direct}\` by name, but this template fits more of the idea.`
158
- : 'The closest template; none is exactly this page.',
181
+ reason: unready
182
+ ? `\`${unready}\` matches but is not ready yet; this is the closest ready template.`
183
+ : place
184
+ ? placed(place, closest.name)
185
+ : agrees
186
+ ? 'Matches the idea.'
187
+ : direct
188
+ ? `Search matched \`${direct}\` by name, but this template fits more of the idea.`
189
+ : 'The closest template; none is exactly this page.',
159
190
  };
160
191
  }
161
192
  for (const id of FALLBACK_STARTS) {
@@ -164,18 +195,21 @@ function chooseStart(ranked, pages, directMatch, catalog) {
164
195
  // The shell can also be the ranker's best guess without the evidence to
165
196
  // lead ("horizontal site navigation"); say so rather than "no match".
166
197
  const nearest = ranked[0]?.name === shell.name && ranked[0].hits > 0;
198
+ const place = placement(kind, false);
167
199
  return {
168
200
  ...asTemplate(shell),
169
201
  basis: 'fallback',
170
202
  reason: unready
171
203
  ? `\`${unready}\` matches but is not ready yet, so start from the app shell.`
172
- : direct
173
- ? `Search matched \`${direct}\` by name, but too little of the idea fits it, so start from the app shell.`
174
- : nearest
175
- ? 'No template is a clear match; the app shell is the closest.'
176
- : loose
177
- ? `Search matched ${loose} only loosely, so start from the app shell.`
178
- : 'No template matched, so start from the app shell.',
204
+ : place
205
+ ? placed(place, shell.name)
206
+ : direct
207
+ ? `Search matched \`${direct}\` by name, but too little of the idea fits it, so start from the app shell.`
208
+ : nearest
209
+ ? 'No template is a clear match; the app shell is the closest.'
210
+ : loose
211
+ ? `Search matched ${loose} only loosely, so start from the app shell.`
212
+ : 'No template matched, so start from the app shell.',
179
213
  };
180
214
  }
181
215
  }
@@ -301,8 +335,18 @@ export async function buildKit(query, options = {}) {
301
335
  const wantsPages = !type || type === 'template';
302
336
  const catalog = wantsPages ? await loadPageTemplates(cwd) : [];
303
337
  const ranked = wantsPages ? rankPages(query, catalog) : [];
338
+ // A part of a page starts where it lives (spec:AST-048/FR3); the project's
339
+ // own components say what a part is. The search above already gathered them
340
+ // unless it was narrowed to templates.
341
+ const kind = wantsPages
342
+ ? ideaKind(
343
+ query,
344
+ catalog,
345
+ searchedComponents(result) ?? (await loadComponents(cwd)),
346
+ )
347
+ : 'page';
304
348
  const chosen = wantsPages
305
- ? chooseStart(ranked, matchedPages, directMatch, catalog)
349
+ ? chooseStart(ranked, kind, matchedPages, directMatch, catalog)
306
350
  : null;
307
351
  // Name the ranker's next two templates beside the start: the reader judges
308
352
  // meaning better than keywords do, and an acceptable template is in these
@@ -1,10 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /**
5
- * @typedef {import('../_adapter.mjs').PageTemplate} PageTemplate
6
- * @typedef {{name: string, score: number, hits: number, familyNamed: boolean, containerMatched: boolean}} RankedPage
7
- */
8
4
  /**
9
5
  * Rank page templates against an idea, best first. Ties go to the template
10
6
  * with the shorter id (the family's broader page), then by name.
@@ -14,6 +10,17 @@
14
10
  * @returns {RankedPage[]}
15
11
  */
16
12
  export function rankPages(query: string, pages: PageTemplate[]): RankedPage[];
13
+ /**
14
+ * What an idea asks for (spec:AST-048/FR3): a whole `page`; a `part` of one,
15
+ * when its head noun names one of the system's components and it lists fewer
16
+ * than PAGE_PIECES pieces; or an `edit` of a page the builder already has.
17
+ *
18
+ * @param {string} query
19
+ * @param {PageTemplate[]} pages
20
+ * @param {ComponentWords[]} components
21
+ * @returns {IdeaKind}
22
+ */
23
+ export function ideaKind(query: string, pages: PageTemplate[], components: ComponentWords[]): IdeaKind;
17
24
  /**
18
25
  * The next closest templates after the start, best first: the ones a reader
19
26
  * should check the idea against when the start's shape is wrong. Each matched
@@ -26,19 +33,28 @@ export function rankPages(query: string, pages: PageTemplate[]): RankedPage[];
26
33
  */
27
34
  export function pickAlternatives(ranked: RankedPage[], startName: string, count?: number): RankedPage[];
28
35
  /**
29
- * The template to start from, or null when the best one has too little
30
- * evidence to lead and the page should start from the app shell. Evidence is
31
- * two matched terms, the idea naming the template's family, or its container.
36
+ * The template to start from, or null for the kit's neutral app shell. A page
37
+ * needs evidence to lead: two matched terms, the idea naming the template's
38
+ * family, or its container. A part starts from the base template of the family
39
+ * the idea places it in, else from the app shell (spec:AST-048/FR3); an edit of
40
+ * a page the builder already has starts from the app shell (FR9). Either way,
41
+ * the app shell is the shell template the idea describes when one leads.
32
42
  *
33
43
  * @param {RankedPage[]} ranked
44
+ * @param {IdeaKind} [kind]
34
45
  * @returns {RankedPage | null}
35
46
  */
36
- export function pickStart(ranked: RankedPage[]): RankedPage | null;
47
+ export function pickStart(ranked: RankedPage[], kind?: IdeaKind): RankedPage | null;
37
48
  export type PageTemplate = import("../_adapter.mjs").PageTemplate;
49
+ export type ComponentWords = import("../_adapter.mjs").ComponentWords;
38
50
  export type RankedPage = {
39
51
  name: string;
40
52
  score: number;
41
53
  hits: number;
42
54
  familyNamed: boolean;
43
55
  containerMatched: boolean;
56
+ family: string;
57
+ base: boolean;
58
+ matched: Set<string>;
44
59
  };
60
+ export type IdeaKind = "page" | "part" | "edit";