@astryxdesign/cli 0.6.3-canary.ee13359 → 0.6.3-canary.eedc844

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 (77) hide show
  1. package/README.md +3 -3
  2. package/api/build/_adapter.d.mts +50 -0
  3. package/api/build/_adapter.mjs +60 -0
  4. package/api/build/build.doc.mjs +13 -7
  5. package/api/build/build.test.mjs +184 -6
  6. package/api/build/build.type.d.mts +57 -2
  7. package/api/build/build.type.mjs +30 -7
  8. package/api/build/help/help.d.mts +4 -0
  9. package/api/build/help/help.mjs +24 -11
  10. package/api/build/kit/kit.d.mts +4 -1
  11. package/api/build/kit/kit.mjs +165 -49
  12. package/api/build/kit/rank.d.mts +44 -0
  13. package/api/build/kit/rank.mjs +432 -0
  14. package/api/build/kit/rank.test.mjs +196 -0
  15. package/api/docs/_adapter.d.mts +49 -7
  16. package/api/docs/_adapter.mjs +284 -33
  17. package/api/docs/docs.doc.mjs +4 -3
  18. package/api/docs/docs.type.d.mts +21 -5
  19. package/api/docs/docs.type.mjs +21 -5
  20. package/api/docs/integration-tree.test.mjs +9 -1
  21. package/api/docs/reference-blocks.test.mjs +406 -0
  22. package/api/doctor/doctor.mjs +5 -1
  23. package/api/integration/authoring-checks.mjs +56 -23
  24. package/api/integration/authoring-checks.test.mjs +8 -1
  25. package/api/integration/authoring-checks.type.d.mts +1 -3
  26. package/api/integration/authoring-checks.type.mjs +7 -4
  27. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  28. package/api/integration/integrationTemplateConflicts.doc.mjs +8 -6
  29. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  30. package/api/search/search.d.mts +33 -0
  31. package/api/search/search.mjs +134 -42
  32. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  33. package/api/template/template-integration.test.mjs +50 -0
  34. package/assets/docs/layout.doc.dense.mjs +2 -2
  35. package/assets/docs/layout.doc.mjs +1 -1
  36. package/assets/docs/working-with-ai.doc.mjs +3 -3
  37. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  38. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  39. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  40. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  41. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  42. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  43. package/authoring/doctypes/_schema.d.mts +72 -0
  44. package/authoring/doctypes/_schema.mjs +25 -1
  45. package/authoring/doctypes/load-contract.test.mjs +25 -0
  46. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  47. package/authoring/doctypes/reference/type.ts +20 -5
  48. package/clients/cli/commands/build.doc.mjs +11 -6
  49. package/clients/cli/commands/build.mjs +105 -70
  50. package/clients/cli/commands/build.text-fields.test.mjs +41 -0
  51. package/clients/cli/commands/docs.mjs +2 -2
  52. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  53. package/clients/cli/commands/doctor-integration.test.mjs +7 -0
  54. package/clients/cli/commands/doctor.mjs +39 -17
  55. package/foundation/agent-docs/agent-docs.d.mts +3 -2
  56. package/foundation/agent-docs/agent-docs.mjs +12 -9
  57. package/foundation/agent-docs/agent-docs.test.mjs +9 -0
  58. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  59. package/foundation/discovery/authoring-self-docs.mjs +20 -8
  60. package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
  61. package/foundation/discovery/docs-discovery.d.mts +4 -1
  62. package/foundation/discovery/docs-discovery.mjs +40 -6
  63. package/foundation/discovery/docs-discovery.test.mjs +40 -0
  64. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  65. package/foundation/discovery/template-conflict-release.mjs +40 -0
  66. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  67. package/foundation/doc-compiler/lenses.d.mts +5 -3
  68. package/foundation/doc-compiler/lenses.mjs +48 -3
  69. package/foundation/doc-compiler/links.d.mts +30 -3
  70. package/foundation/doc-compiler/links.mjs +46 -5
  71. package/foundation/doc-compiler/links.test.mjs +53 -0
  72. package/foundation/integrations/cli-requirement.test.mjs +17 -42
  73. package/foundation/response/response-types.doc.d.mts +5 -1
  74. package/foundation/response/response-types.doc.mjs +8 -4
  75. package/foundation/text/string-utils.d.mts +8 -0
  76. package/foundation/text/string-utils.mjs +18 -0
  77. package/package.json +9 -9
@@ -4,8 +4,9 @@
4
4
  * @file build command — thin wrapper with a stable result summary.
5
5
  *
6
6
  * astryx build → the PLAYBOOK (how to build a page)
7
- * astryx build "<what>" → a COMPOSITION KIT (closest page template,
8
- * blocks, components) with a recommended START.
7
+ * astryx build "<what>" → the TEMPLATE to start from (always one: the
8
+ * closest page, or the app shell), other
9
+ * templates, then blocks and components.
9
10
  *
10
11
  * All grouping/scoring lives in api/build; this file only parses flags and
11
12
  * renders. Command strings are prefixed for the caller's package manager here
@@ -27,6 +28,7 @@ import {
27
28
  records,
28
29
  } from '../formatters/index.mjs';
29
30
  import {cliError} from '../lib/cli-error.mjs';
31
+ import {firstSentence} from '../../../foundation/text/string-utils.mjs';
30
32
  import {defineCommand} from '../lib/define-command.mjs';
31
33
  import {build as buildApi} from '../../../api/build/build.mjs';
32
34
  import {doc as buildCommand} from './build.doc.mjs';
@@ -126,6 +128,7 @@ export function registerBuild(program) {
126
128
  hasResults,
127
129
  matchCount,
128
130
  directMatch,
131
+ start,
129
132
  pages,
130
133
  blocks,
131
134
  domain,
@@ -134,8 +137,8 @@ export function registerBuild(program) {
134
137
  hint,
135
138
  } = result.data;
136
139
  // The kit spans domains, so its kind comes from the pieces themselves.
137
- // `frame` and `foundation` are always-on and deliberately excluded: they
138
- // are not what the query matched.
140
+ // `start` (which may be the fallback shell), `frame` and `foundation`
141
+ // are deliberately excluded: they are not what the query matched.
139
142
  const answered = resultSetOf([...pages, ...blocks, ...domain], {
140
143
  count: matchCount,
141
144
  empty: !hasResults,
@@ -148,7 +151,7 @@ export function registerBuild(program) {
148
151
  return answered;
149
152
  }
150
153
 
151
- if (!hasResults) {
154
+ if (!hasResults && !start) {
152
155
  emit(
153
156
  text(`No matches for "${q}".`),
154
157
  text(`Try a broader term, or browse: ${run} component --list`),
@@ -156,94 +159,126 @@ export function registerBuild(program) {
156
159
  return answered;
157
160
  }
158
161
 
159
- // Same JSON->text projection as search, but leaner: the section header
160
- // already says the kind, so drop `domain`/`import` by default (they're in
161
- // --json and under --verbose). Keeps each item to name/displayName/desc/cmd.
162
- const fields = options.verbose
163
- ? [
164
- 'name',
165
- 'domain',
166
- 'displayName',
167
- 'score',
168
- 'reason',
169
- 'import',
170
- 'description',
171
- 'command',
172
- ]
173
- : ['name', 'displayName', 'description', 'command'];
162
+ // Four sections, one job each: the TEMPLATE to scaffold, OTHER
163
+ // TEMPLATES if its layout is wrong, BLOCKS for parts it lacks, and
164
+ // COMPONENTS for the rest. Descriptions stop at their first sentence and
165
+ // blocks and components share one command line in their heading; the
166
+ // JSON and --verbose carry everything.
167
+ const verbose = Boolean(options.verbose);
174
168
  /** @type {import('../formatters/index.mjs').RecordOptions} */
175
- const recordOpts = {fields, format: {command: formatCliCommand}};
176
-
177
- // `template <name> <path>` scaffolds into your project; <path> is the file
178
- // (or folder) to write it to — a placeholder, since we can't know your
179
- // layout. `--skeleton` and `component <Name>` just print, so no path.
180
- const pageCommand = pages.length
181
- ? formatCliCommand(pages[0].command)
182
- : null;
183
- const startCmd = directMatch
184
- ? `${pageCommand} <path>`
185
- : pages.length
186
- ? pageCommand
187
- : `${run} component AppShell`;
188
- const startNote = directMatch
189
- ? `This \`${pages[0].name}\` page template appears to be the closest to what you want, so we recommend scaffolding it into your project — replace \`<path>\` with the file (or folder) to write it to — then adapting. Otherwise, browse PAGE TEMPLATES first, then BLOCKS and DOMAIN COMPONENTS below.`
190
- : pages.length
191
- ? `No exact match, but \`${pages[0].name}\` is the closest page template — run the above to print its layout as a reference, then compose. Otherwise, browse PAGE TEMPLATES first, then BLOCKS and DOMAIN COMPONENTS below.`
192
- : 'No page template fits — frame with AppShell, then compose from BLOCKS and DOMAIN COMPONENTS below.';
193
-
194
- // A short legend up top: what this output is, how to use it, and the exact
195
- // order of the sections below (only the ones actually present) so it reads
196
- // clearly and parses predictably.
197
- const sectionsOrder = ['RECOMMENDED START'];
198
- if (pages.length) sectionsOrder.push('PAGE TEMPLATES');
199
- if (blocks.length) sectionsOrder.push('BLOCKS');
200
- if (domain.length) sectionsOrder.push('DOMAIN COMPONENTS');
201
- sectionsOrder.push('FRAME + FOUNDATION');
202
- // The legend promises the complete order, so a section emitted after it
203
- // has to be in it.
204
- if (hint) sectionsOrder.push('FEW MATCHES');
169
+ const full = {
170
+ fields: [
171
+ 'name',
172
+ 'domain',
173
+ 'displayName',
174
+ 'score',
175
+ 'reason',
176
+ 'import',
177
+ 'description',
178
+ 'command',
179
+ ],
180
+ format: {command: formatCliCommand},
181
+ };
182
+ /** @param {string[]} fields */
183
+ const brief = fields => ({
184
+ fields,
185
+ format: {command: formatCliCommand, description: firstSentence},
186
+ });
187
+ // Blocks and components are extras: the text names the top few, and
188
+ // says how many more the JSON and --verbose carry.
189
+ const TOP = 3;
190
+ /** @param {unknown[]} items */
191
+ const shown = items => (verbose ? items : items.slice(0, TOP));
192
+ /** @param {unknown[]} items */
193
+ const more = items =>
194
+ !verbose && items.length > TOP
195
+ ? ` (top ${TOP} of ${items.length}; --verbose for all)`
196
+ : '';
205
197
 
206
198
  /** @type {import('../formatters/index.mjs').Block[]} */
207
199
  const out = [
208
200
  section(`Build kit for "${q}"`),
209
201
  text(
210
- 'A recommended set of pieces to assemble this page, in the order to use them. ' +
211
- 'Begin with RECOMMENDED START, then pull from the sections below — each ' +
212
- 'recommended item includes a `command:` to run next.\n' +
213
- `Sections in order: ${sectionsOrder.join(', ')}.`,
202
+ start
203
+ ? 'Start from the TEMPLATE, fill it with BLOCKS, and use COMPONENTS only for what is left.\n' +
204
+ 'Changing a page you already have? Keep it, and use only the blocks and components.'
205
+ : 'This kit is narrowed by --type, so it names no template.',
214
206
  ),
215
- section('RECOMMENDED START', `${startNote}\n${startCmd}`),
216
207
  ];
217
208
 
218
- if (pages.length) {
209
+ if (start) {
219
210
  out.push(
220
211
  section(
221
- 'PAGE TEMPLATES',
222
- directMatch
223
- ? 'Closest full-page templates — scaffold one, then adapt it.'
224
- : 'Closest full-page templates — use as a layout reference.',
212
+ 'TEMPLATE',
213
+ `${start.reason} ${
214
+ start.basis === 'fallback'
215
+ ? 'Scaffold it, then put blocks inside it.'
216
+ : 'Scaffold it, then replace its content. Keep its layout and spacing.'
217
+ }`,
218
+ ),
219
+ record(
220
+ start,
221
+ verbose
222
+ ? {
223
+ fields: ['name', 'displayName', 'description', 'command'],
224
+ format: {command: formatCliCommand},
225
+ }
226
+ : brief(['name', 'description', 'command']),
225
227
  ),
226
- records(pages, recordOpts),
227
228
  );
229
+ if (start.alternatives.length) {
230
+ out.push(
231
+ section(
232
+ 'OTHER TEMPLATES',
233
+ `If the layout is wrong, scaffold one of these instead. All page templates: ${formatCliCommand('template --list --type page')}`,
234
+ ),
235
+ records(
236
+ start.alternatives,
237
+ verbose ? full : brief(['name', 'description', 'command']),
238
+ ),
239
+ );
240
+ }
228
241
  }
229
- if (blocks.length) {
242
+ // Search's own page matches, so the text carries every field the JSON
243
+ // does: one line by default, the full entries under --verbose.
244
+ if (pages.length) {
230
245
  out.push(
231
- section('BLOCKS', 'Drop-in patterns that cover parts of the page.'),
232
- records(blocks, recordOpts),
246
+ verbose
247
+ ? section(
248
+ 'SEARCH MATCHES',
249
+ 'Page templates keyword search matched, best first.',
250
+ )
251
+ : text(
252
+ `Keyword search matched these page templates: ${pages.map(p => p.name).join(', ')}.`,
253
+ ),
233
254
  );
255
+ if (verbose) out.push(records(pages, full));
234
256
  }
235
- if (domain.length) {
257
+ if (blocks.length) {
236
258
  out.push(
237
- section('DOMAIN COMPONENTS', 'Components specific to this idea.'),
238
- records(domain, recordOpts),
259
+ section(
260
+ 'BLOCKS',
261
+ `Ready-made sections for parts the template lacks${more(blocks)}. Print one: ${formatCliCommand('template <name>')}`,
262
+ ),
263
+ records(
264
+ shown(blocks),
265
+ verbose ? full : brief(['name', 'description']),
266
+ ),
239
267
  );
240
268
  }
241
-
242
269
  out.push(
243
270
  section(
244
- 'FRAME + FOUNDATION',
245
- 'Always-available shell + layout/text/action primitives.',
271
+ 'COMPONENTS',
272
+ `For what the template and blocks do not cover${more(domain)}. Read one: ${formatCliCommand('component <name>')}`,
246
273
  ),
274
+ ...(domain.length
275
+ ? [
276
+ records(
277
+ shown(domain),
278
+ verbose ? full : brief(['name', 'description']),
279
+ ),
280
+ ]
281
+ : []),
247
282
  record({frame, foundation}),
248
283
  );
249
284
 
@@ -21,6 +21,8 @@ describe('build kit text fields mirror the JSON keys', () => {
21
21
  const {data} = JSON.parse(json.stdout);
22
22
  const keys = new Set([
23
23
  ...Object.keys(data),
24
+ ...Object.keys(data.start ?? {}),
25
+ ...(data.start?.alternatives ?? []).flatMap(a => Object.keys(a)),
24
26
  ...[...data.pages, ...data.blocks, ...data.domain].flatMap(e => Object.keys(e)),
25
27
  ]);
26
28
 
@@ -35,6 +37,45 @@ describe('build kit text fields mirror the JSON keys', () => {
35
37
  ),
36
38
  ];
37
39
  expect(fields).toContain('frame');
40
+ // The start is printed as a record, so its fields are checked too.
41
+ expect(fields).toContain('command');
42
+ expect(fields).toContain('displayName');
38
43
  for (const field of fields) expect(keys).toContain(field);
39
44
  }, SLOW);
45
+
46
+ it('leads with the start, then the alternatives, blocks and components', async () => {
47
+ const human = await runCli(['build', 'analytics dashboard'], REPO);
48
+ expect(human.status).toBe(0);
49
+ const headings = human.stdout
50
+ .split('\n')
51
+ .filter(line => /^(TEMPLATE|OTHER TEMPLATES|BLOCKS|COMPONENTS)$/.test(line));
52
+ expect(headings).toEqual(['TEMPLATE', 'OTHER TEMPLATES', 'BLOCKS', 'COMPONENTS']);
53
+ // A builder changing a page they already have keeps it.
54
+ expect(human.stdout).toContain(
55
+ 'Changing a page you already have? Keep it, and use only the blocks and components.',
56
+ );
57
+ }, SLOW);
58
+
59
+ it("shortens the start's description by default and prints it whole under --verbose", async () => {
60
+ const json = await runCli(['build', 'quarterly revenue dashboard', '--json'], REPO);
61
+ const {start} = JSON.parse(json.stdout).data;
62
+ const first = start.description.slice(0, start.description.indexOf('. ') + 1);
63
+ expect(first.length).toBeGreaterThan(0);
64
+ expect(first.length).toBeLessThan(start.description.length);
65
+ const line = out => out.split('\n').find(l => l.startsWith('description:'));
66
+ const brief = await runCli(['build', 'quarterly revenue dashboard'], REPO);
67
+ expect(line(brief.stdout)).toBe(`description: ${first}`);
68
+ const whole = await runCli(['build', 'quarterly revenue dashboard', '--verbose'], REPO);
69
+ expect(whole.stdout).toContain(start.description);
70
+ }, SLOW);
71
+
72
+ it("names search's page matches in the default text", async () => {
73
+ const json = await runCli(['build', 'contact form', '--json'], REPO);
74
+ const {data} = JSON.parse(json.stdout);
75
+ expect(data.pages.length).toBeGreaterThan(0);
76
+ const human = await runCli(['build', 'contact form'], REPO);
77
+ expect(human.stdout).toContain(
78
+ `Keyword search matched these page templates: ${data.pages.map(p => p.name).join(', ')}.`,
79
+ );
80
+ }, SLOW);
40
81
  });
@@ -115,7 +115,7 @@ function formatBlock(block, detail) {
115
115
  }
116
116
 
117
117
  /**
118
- * @param {import('@astryxdesign/cli/authoring').ReferenceSection} section
118
+ * @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} section
119
119
  * @param {'full' | 'compact' | 'brief'} detail
120
120
  * @returns {string}
121
121
  */
@@ -135,7 +135,7 @@ function formatSection(section, detail) {
135
135
  }
136
136
 
137
137
  /**
138
- * @param {import('@astryxdesign/cli/authoring').ReferenceDoc} docs
138
+ * @param {import('../../../api/docs/docs.type.mjs').DocsReadDoc} docs
139
139
  * @param {'full' | 'compact' | 'brief'} detail
140
140
  * @returns {string}
141
141
  */
@@ -32,7 +32,7 @@ export const doc = {
32
32
  ],
33
33
  exitCodes: [
34
34
  {code: 0, when: 'all Core overlaps are explicitly declared or no overlap exists'},
35
- {code: 1, when: 'an overlap is accidental, a doc is invalid, or a namespace or placement fails. A link that names no doc is a warning, and does not change the exit code'},
35
+ {code: 1, when: 'an overlap is accidental, a doc is invalid, a namespace or placement fails, or a reference block cannot include what it names. A link that names no doc is a warning, and does not change the exit code'},
36
36
  ],
37
37
  related: ['doctor integration validate', 'docs'],
38
38
  };
@@ -2,9 +2,16 @@
2
2
 
3
3
  /**
4
4
  * @file Command-level coverage for `astryx doctor integration` authoring checks.
5
+ * @input Integration fixtures and the post-0.7 conflict projection.
6
+ * @output Assertions for human and typed command responses.
7
+ * @position CLI adapter coverage; 0.6.x API shape is verified separately.
5
8
  */
6
9
 
7
10
  import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
11
+
12
+ vi.mock('../../../foundation/discovery/template-conflict-release.mjs', () => ({
13
+ expandedTemplateConflictSchemaActive: () => true,
14
+ }));
8
15
  import * as fs from 'node:fs';
9
16
  import * as path from 'node:path';
10
17
  import {Command} from 'commander';
@@ -3,7 +3,12 @@
3
3
  /**
4
4
  * @file `astryx doctor` project health and integration-authoring diagnostics.
5
5
  * Human output uses plain stable tokens; every leaf also has a typed JSON
6
- * response. Exit 1 means a check found an error, while warnings remain exit 0.
6
+ * response. Template-conflict fields follow the package release boundary.
7
+ * Exit 1 means a check found an error, while warnings remain exit 0.
8
+ *
9
+ * @input Typed Doctor and integration-authoring API responses.
10
+ * @output Human-readable records or pass-through typed JSON.
11
+ * @position CLI presentation adapter for project and integration health.
7
12
  */
8
13
 
9
14
  import {runChecks} from '../../../api/doctor/doctor.mjs';
@@ -126,26 +131,41 @@ function printTemplateConflicts(data) {
126
131
  ...issueBlocks(data.issues),
127
132
  ];
128
133
  if (data.conflicts.length === 0 && data.issues.length === 0) {
129
- output.push(
130
- text('[ok] No template replacements or id conflicts with Core.'),
131
- );
134
+ output.push(text('[ok] No template ids conflict with Core.'));
132
135
  } else if (data.conflicts.length > 0) {
136
+ const expanded = data.conflicts.some(
137
+ conflict => 'relationship' in conflict,
138
+ );
133
139
  output.push(
134
140
  records(data.conflicts, {
135
- fields: [
136
- 'severity',
137
- 'relationship',
138
- 'id',
139
- 'replaces',
140
- 'integrationPackage',
141
- 'integrationType',
142
- 'integrationName',
143
- 'message',
144
- 'command',
145
- ],
141
+ fields: expanded
142
+ ? [
143
+ 'severity',
144
+ 'relationship',
145
+ 'id',
146
+ 'replaces',
147
+ 'integrationPackage',
148
+ 'integrationType',
149
+ 'integrationName',
150
+ 'message',
151
+ 'command',
152
+ ]
153
+ : [
154
+ 'severity',
155
+ 'id',
156
+ 'integrationPackage',
157
+ 'integrationType',
158
+ 'integrationName',
159
+ 'message',
160
+ 'command',
161
+ ],
146
162
  format: {severity: statusToken},
147
163
  }),
148
- text(`${data.conflicts.length} Core template relationship(s).`),
164
+ text(
165
+ expanded
166
+ ? `${data.conflicts.length} Core template relationship(s).`
167
+ : `${data.conflicts.length} Core template conflict(s). Renaming is recommended but optional; keep the package-qualified command if the overlap is intentional.`,
168
+ ),
149
169
  );
150
170
  }
151
171
  emit(...output);
@@ -199,7 +219,9 @@ function printDocConflicts(data) {
199
219
  issue => issue.severity === 'error' || issue.code === 'invalid_doc_graph',
200
220
  )
201
221
  ) {
202
- output.push(text('[ok] The docs tree and every link in these docs check out.'));
222
+ output.push(
223
+ text('[ok] The docs tree and every link in these docs check out.'),
224
+ );
203
225
  }
204
226
  if (data.findings.length === 0) {
205
227
  output.push(text('[ok] No doc topics overlap with Core.'));
@@ -78,8 +78,9 @@ export function detectStylingSystem(targetDir: string): "stylex" | "tailwind" |
78
78
  * Generate the agent cheat sheet from live CLI metadata.
79
79
  *
80
80
  * Structured as: workflow (behavioral) → rules (error prevention) → CLI reference.
81
- * Templates are positioned first in the workflow to teach agents the
82
- * "look at reference code" reflex before writing any UI.
81
+ * Templates lead the workflow: every page starts from a scaffolded template,
82
+ * because the template already carries the frame and spacing that an agent
83
+ * composing from components would have to re-derive, and usually gets wrong.
83
84
  *
84
85
  * `stylingSystem` tailors the custom-styling guidance to what the project has
85
86
  * configured (see {@link detectStylingSystem}) so the agent never reaches for a
@@ -354,8 +354,9 @@ export function detectStylingSystem(targetDir) {
354
354
  * Generate the agent cheat sheet from live CLI metadata.
355
355
  *
356
356
  * Structured as: workflow (behavioral) → rules (error prevention) → CLI reference.
357
- * Templates are positioned first in the workflow to teach agents the
358
- * "look at reference code" reflex before writing any UI.
357
+ * Templates lead the workflow: every page starts from a scaffolded template,
358
+ * because the template already carries the frame and spacing that an agent
359
+ * composing from components would have to re-derive, and usually gets wrong.
359
360
  *
360
361
  * `stylingSystem` tailors the custom-styling guidance to what the project has
361
362
  * configured (see {@link detectStylingSystem}) so the agent never reaches for a
@@ -428,17 +429,19 @@ export function generateCompressedIndex(
428
429
  lines.push(' import "@astryxdesign/core/astryx.css";');
429
430
  lines.push('');
430
431
 
431
- // Workflow — `build` is the front door; discover before writing UI.
432
- lines.push("WORKFLOW — discover, don't guess. Before writing UI:");
433
- lines.push('1. `astryx build "<idea>"` — START HERE: returns a kit (closest [page] + [block]s + [component]s). No args = full playbook.');
434
- lines.push('2. `astryx template <name> [--skeleton]` — scaffold the [page]/[block]s it named, or study their layout. Templates are reference code.');
435
- lines.push('3. `astryx component <Name>` — props + examples for every component you use.');
432
+ // Workflow — `build` is the front door, and every page starts from the
433
+ // template it names.
434
+ lines.push('WORKFLOW — start every page from a template. Never lay out a page from scratch:');
435
+ lines.push('1. `astryx build "<idea>"` — START HERE: names the [page] template to start from (always one: the closest match, or the app shell), two other templates, and the [block]s + [component]s for parts it lacks. No args = full playbook.');
436
+ lines.push('2. `astryx template <name> <path>` — scaffold that template into your project. Keep its frame, gap and padding; replace its data, copy and sections; delete sections you do not need.');
437
+ lines.push('3. `astryx template <Block>` for a part the template lacks; `astryx component <Name>` for props + examples before you use or change a component.');
438
+ lines.push('Changing a page you already have? Keep it: skip step 2 and add blocks and components inside its sections.');
436
439
  lines.push('');
437
440
 
438
441
  // Rules — the top error-preventers.
439
442
  lines.push('RULES:');
440
443
  lines.push('- No <div> — components do all layout/spacing, page frame included.');
441
- lines.push('- Frame first: read `astryx docs layout` before writing any page or screen — page frame, region widths, breakpoint behavior.');
444
+ lines.push('- Frame first: the template you scaffold sets the page frame. Read `astryx docs layout` before you change it — region widths, breakpoint behavior.');
442
445
  lines.push('- Dense data = rows (Table, List/Item), never Card-wrapped list items; Card is for standalone widgets. Status = StatusDot/Token; Badge = counts only.');
443
446
  // Styling guidance tailored to the project's configured system — never
444
447
  // recommend a path that isn't compiled here (xstyle needs the StyleX compiler;
@@ -463,7 +466,7 @@ export function generateCompressedIndex(
463
466
  css: 'replace any raw <div>/<span> layout, imported .css/@apply, or hardcoded value (#hex, 16px) with the component or a token (var(--color-*|--spacing-*|…))',
464
467
  };
465
468
  lines.push(
466
- `- SELF-CHECK before you finish: re-read the file and ${selfCheckFix[stylingSystem] ?? selfCheckFix.css}. If unsure a component/prop exists, run \`astryx component <Name>\` / \`astryx search "<thing>"\`; don't hand-roll CSS.`,
469
+ `- SELF-CHECK before you finish: re-read the file and ${selfCheckFix[stylingSystem] ?? selfCheckFix.css}. Confirm the page kept its template's frame, gap and padding. If unsure a component/prop exists, run \`astryx component <Name>\` / \`astryx search "<thing>"\`; don't hand-roll CSS.`,
467
470
  );
468
471
  lines.push('');
469
472
 
@@ -55,6 +55,15 @@ describe('generateCompressedIndex', () => {
55
55
  expect(frameRule).not.toMatch(/https?:/);
56
56
  });
57
57
 
58
+ it('starts every page from a template before any component', () => {
59
+ const lines = generateCompressedIndex('1.0.0').split('\n');
60
+ const workflow = lines.findIndex(l => l.startsWith('WORKFLOW'));
61
+ expect(lines[workflow]).toMatch(/start every page from a template/);
62
+ expect(lines[workflow + 1]).toMatch(/^1\. `astryx build /);
63
+ expect(lines[workflow + 2]).toMatch(/^2\. `astryx template <name> <path>`/);
64
+ expect(lines.join('\n')).not.toMatch(/reference code/);
65
+ });
66
+
58
67
  it('includes the post-generation self-check rule', () => {
59
68
  const result = generateCompressedIndex('1.0.0');
60
69
  expect(result).toContain('SELF-CHECK before you finish');
@@ -24,6 +24,18 @@ export function loadAuthoringSelfDocs(sources?: string[], root?: string): Promis
24
24
  error: string;
25
25
  }[];
26
26
  }>;
27
+ /**
28
+ * A schema's fields as the table its section prints, each nested field on the
29
+ * row after its parent; null when there are none. A reference block that
30
+ * names some of a schema's fields includes this table of just those.
31
+ * @param {any[]} fields
32
+ * @returns {{type: 'table', headers: string[], rows: string[][]} | null}
33
+ */
34
+ export function schemaFieldTable(fields: any[]): {
35
+ type: "table";
36
+ headers: string[];
37
+ rows: string[][];
38
+ } | null;
27
39
  /**
28
40
  * One self-doc as a topic section, keyed by the doc's own name.
29
41
  * @param {any} doc
@@ -133,6 +133,24 @@ function fieldRows(fields) {
133
133
  ]);
134
134
  }
135
135
 
136
+ /**
137
+ * A schema's fields as the table its section prints, each nested field on the
138
+ * row after its parent; null when there are none. A reference block that
139
+ * names some of a schema's fields includes this table of just those.
140
+ * @param {any[]} fields
141
+ * @returns {{type: 'table', headers: string[], rows: string[][]} | null}
142
+ */
143
+ export function schemaFieldTable(fields) {
144
+ const rows = fieldRows(fields);
145
+ return rows.length > 0
146
+ ? {
147
+ type: 'table',
148
+ headers: ['Field', 'Type', 'Required', 'Description'],
149
+ rows,
150
+ }
151
+ : null;
152
+ }
153
+
136
154
  /**
137
155
  * One self-doc as a topic section, keyed by the doc's own name.
138
156
  * @param {any} doc
@@ -144,14 +162,8 @@ export function selfDocSection(doc) {
144
162
  if (doc.appliesTo) {
145
163
  content.push({type: 'prose', text: `Applies to: ${doc.appliesTo}`});
146
164
  }
147
- const rows = fieldRows(doc.fields ?? []);
148
- if (rows.length > 0) {
149
- content.push({
150
- type: 'table',
151
- headers: ['Field', 'Type', 'Required', 'Description'],
152
- rows,
153
- });
154
- }
165
+ const table = schemaFieldTable(doc.fields ?? []);
166
+ if (table) content.push(table);
155
167
  for (const example of doc.examples ?? []) {
156
168
  if (typeof example?.code !== 'string' || example.code.trim() === '')
157
169
  continue;
@@ -82,15 +82,20 @@ describe('what the authoring docs say about the docs tree', () => {
82
82
  expect(graphFieldsDoc.description).toMatch(/not built yet/);
83
83
  });
84
84
 
85
- it('keeps graph blocks behind the separate GraphContentBlock type', () => {
85
+ it('keeps graph blocks behind the separate GraphContentBlock type, and a section takes a reference block', () => {
86
86
  const content = referenceDoc.fields
87
87
  .flatMap(field => [field, ...(field.fields ?? [])])
88
88
  .find(field => field.name === 'sections[].content');
89
- expect(content.type).toBe('ReferenceContentBlock[]');
89
+ expect(content.type).toBe('(ReferenceContentBlock | ReferenceDocBlock)[]');
90
90
  expect(content.description).toContain('GraphContentBlock');
91
91
  for (const type of GRAPH_BLOCK_TYPES) {
92
92
  expect(content.description).toContain(type);
93
93
  }
94
+ // A section's reference block reads as the doc it includes.
95
+ expect(GRAPH_BLOCK_TYPES.has('reference')).toBe(false);
96
+ expect(content.description).toMatch(
97
+ /A `reference` block .* includes another doc/,
98
+ );
94
99
  });
95
100
 
96
101
  it('says where namespace docs live: the CLI tree, and each integration', () => {
@@ -122,7 +122,10 @@ export { withSourceTitle };
122
122
  * unlike component discovery, whose built-ins belong to core.
123
123
  */
124
124
  export const BUILTIN_DOCS_PACKAGE: import("../../authoring/index.js").ProviderId;
125
- /** Blocks that are valid authoring but require the compiled graph renderer. */
125
+ /**
126
+ * Blocks that are valid authoring but require the compiled graph renderer: a
127
+ * namespace doc's `blocks` hold them, a topic section does not.
128
+ */
126
129
  export const GRAPH_BLOCK_TYPES: Set<string>;
127
130
  /**
128
131
  * Doc fields only the docs tree reads. A flat topic that sets one fails to