@astryxdesign/cli 0.6.3-canary.2bb99ed → 0.6.3-canary.2bdba84

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 (216) hide show
  1. package/README.md +21 -19
  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/component/_adapter.d.mts +6 -12
  16. package/api/component/_adapter.mjs +20 -10
  17. package/api/component/component.mjs +60 -12
  18. package/api/component/list/list.mjs +3 -2
  19. package/api/docs/_adapter.d.mts +251 -28
  20. package/api/docs/_adapter.mjs +918 -35
  21. package/api/docs/detail/detail.mjs +11 -3
  22. package/api/docs/detail/section/section.mjs +20 -3
  23. package/api/docs/docs.d.mts +5 -3
  24. package/api/docs/docs.doc.mjs +38 -17
  25. package/api/docs/docs.mjs +44 -8
  26. package/api/docs/docs.test.mjs +158 -4
  27. package/api/docs/docs.type.d.mts +181 -2
  28. package/api/docs/docs.type.mjs +117 -3
  29. package/api/docs/index/index.mjs +11 -3
  30. package/api/docs/index/index.test.mjs +1 -1
  31. package/api/docs/integration-tree.test.mjs +555 -0
  32. package/api/docs/integrationDocs.test.mjs +14 -14
  33. package/api/docs/list/list.mjs +25 -5
  34. package/api/docs/node/node.d.mts +43 -0
  35. package/api/docs/node/node.mjs +192 -0
  36. package/api/docs/reference-blocks.test.mjs +406 -0
  37. package/api/doctor/doctor.d.mts +30 -2
  38. package/api/doctor/doctor.mjs +150 -7
  39. package/api/doctor/doctor.test.mjs +89 -1
  40. package/api/index.d.mts +1 -1
  41. package/api/index.mjs +1 -0
  42. package/api/init/init.doc.mjs +1 -1
  43. package/api/integration/add-contribution.d.mts +2 -1
  44. package/api/integration/add-contribution.mjs +107 -5
  45. package/api/integration/add-contribution.test.mjs +137 -0
  46. package/api/integration/authoring-checks.mjs +138 -28
  47. package/api/integration/authoring-checks.test.mjs +171 -3
  48. package/api/integration/authoring-checks.type.mjs +6 -1
  49. package/api/integration/integration-authoring.type.d.mts +2 -0
  50. package/api/integration/integration-authoring.type.mjs +2 -0
  51. package/api/integration/integrationAdd.doc.mjs +6 -0
  52. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  53. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  54. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  55. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  56. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  57. package/api/integration/pack-check.mjs +34 -0
  58. package/api/integration/pack-check.test.mjs +121 -0
  59. package/api/integration/pack-check.type.d.mts +26 -2
  60. package/api/integration/pack-check.type.mjs +14 -1
  61. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  62. package/api/integration/validate-integration.test.mjs +3 -3
  63. package/api/integration/validateIntegration.doc.mjs +1 -1
  64. package/api/json/index.ts +2 -0
  65. package/api/layout/_adapter.mjs +20 -5
  66. package/api/search/search.d.mts +59 -1
  67. package/api/search/search.doc.mjs +4 -3
  68. package/api/search/search.mjs +442 -71
  69. package/api/search/search.test.mjs +91 -2
  70. package/api/search/search.type.d.mts +13 -1
  71. package/api/search/search.type.mjs +4 -1
  72. package/api/template/list/list.mjs +1 -0
  73. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  74. package/api/template/template-integration.test.mjs +1072 -3
  75. package/api/template/template.doc.mjs +27 -7
  76. package/api/template/template.mjs +45 -8
  77. package/api/template/template.type.d.mts +6 -8
  78. package/api/template/template.type.mjs +3 -2
  79. package/api/theme/template/template.test.mjs +5 -0
  80. package/api/theme/themeTemplate.doc.mjs +1 -1
  81. package/assets/docs/getting-started.doc.mjs +2 -2
  82. package/assets/docs/layout.doc.dense.mjs +2 -2
  83. package/assets/docs/layout.doc.mjs +1 -1
  84. package/assets/docs/principles.doc.mjs +6 -6
  85. package/assets/docs/styling-libraries.doc.mjs +3 -3
  86. package/assets/docs/styling.doc.mjs +4 -4
  87. package/assets/docs/theme.doc.mjs +4 -4
  88. package/assets/docs/tokens.doc.mjs +1 -1
  89. package/assets/docs/tree/api.doc.mjs +30 -0
  90. package/assets/docs/tree/cli.doc.mjs +23 -0
  91. package/assets/docs/tree/commands.doc.mjs +25 -0
  92. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  93. package/assets/docs/tree/integrations.test.mjs +62 -0
  94. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  95. package/assets/docs/working-with-ai.doc.mjs +3 -3
  96. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  97. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  98. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  99. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  100. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  101. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  102. package/authoring/debug/parse.d.mts +3 -3
  103. package/authoring/doctypes/_schema.d.mts +72 -0
  104. package/authoring/doctypes/_schema.mjs +25 -1
  105. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  106. package/authoring/doctypes/base/type.ts +6 -5
  107. package/authoring/doctypes/command/command.doc.mjs +1 -1
  108. package/authoring/doctypes/command/type.ts +2 -2
  109. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  110. package/authoring/doctypes/enum/type.ts +1 -1
  111. package/authoring/doctypes/function/function.doc.mjs +3 -2
  112. package/authoring/doctypes/function/type.ts +3 -2
  113. package/authoring/doctypes/load-contract.test.mjs +25 -0
  114. package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
  115. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  116. package/authoring/doctypes/reference/type.ts +23 -5
  117. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  118. package/authoring/doctypes/schema/type.ts +1 -1
  119. package/authoring/doctypes/template/parse.d.mts +2 -0
  120. package/authoring/doctypes/template/parse.mjs +4 -0
  121. package/authoring/doctypes/template/parse.test.mjs +18 -0
  122. package/authoring/doctypes/template/template.doc.mjs +6 -0
  123. package/authoring/doctypes/template/type.ts +8 -0
  124. package/authoring/identity/identity.doc.mjs +2 -2
  125. package/authoring/integration/type.ts +1 -1
  126. package/clients/cli/commands/build-theme.adaptations.test.mjs +100 -1
  127. package/clients/cli/commands/build-theme.mjs +1 -1
  128. package/clients/cli/commands/build.doc.mjs +11 -6
  129. package/clients/cli/commands/build.mjs +105 -67
  130. package/clients/cli/commands/build.text-fields.test.mjs +41 -0
  131. package/clients/cli/commands/component/index.mjs +1 -1
  132. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  133. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  134. package/clients/cli/commands/discover.mjs +1 -1
  135. package/clients/cli/commands/docs.doc.mjs +20 -8
  136. package/clients/cli/commands/docs.mjs +177 -20
  137. package/clients/cli/commands/docs.test.mjs +114 -7
  138. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  139. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  140. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  141. package/clients/cli/commands/doctor.mjs +53 -16
  142. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  143. package/clients/cli/commands/integration.mjs +1 -0
  144. package/clients/cli/commands/search.mjs +11 -2
  145. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  146. package/clients/cli/commands/template.doc.mjs +23 -6
  147. package/clients/cli/commands/template.mjs +4 -91
  148. package/clients/cli/commands/text-json-parity.test.mjs +2 -1
  149. package/clients/cli/index.mjs +8 -0
  150. package/clients/cli/lib/manifest.mjs +9 -2
  151. package/foundation/agent-docs/agent-docs.d.mts +3 -2
  152. package/foundation/agent-docs/agent-docs.mjs +13 -9
  153. package/foundation/agent-docs/agent-docs.test.mjs +19 -1
  154. package/foundation/config/project.d.mts +12 -11
  155. package/foundation/config/project.mjs +73 -59
  156. package/foundation/config/project.test.mjs +141 -5
  157. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  158. package/foundation/discovery/authoring-self-docs.mjs +20 -8
  159. package/foundation/discovery/authoring-self-docs.test.mjs +24 -9
  160. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  161. package/foundation/discovery/cli-self-docs.mjs +91 -115
  162. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  163. package/foundation/discovery/component-discovery.d.mts +38 -0
  164. package/foundation/discovery/component-discovery.mjs +48 -0
  165. package/foundation/discovery/docs-discovery.d.mts +109 -9
  166. package/foundation/discovery/docs-discovery.mjs +217 -19
  167. package/foundation/discovery/docs-discovery.test.mjs +96 -17
  168. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  169. package/foundation/discovery/docs-output-budget.mjs +1 -1
  170. package/foundation/discovery/docs-section-key.d.mts +9 -2
  171. package/foundation/discovery/docs-section-key.mjs +15 -1
  172. package/foundation/discovery/template-adapter.d.mts +92 -6
  173. package/foundation/discovery/template-adapter.mjs +453 -17
  174. package/foundation/discovery/template-adapter.test.mjs +42 -0
  175. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  176. package/foundation/discovery/template-conflict-release.mjs +40 -0
  177. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  178. package/foundation/doc-compiler/bundle.mjs +61 -1
  179. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  180. package/foundation/doc-compiler/compile.d.mts +113 -132
  181. package/foundation/doc-compiler/compile.mjs +52 -6
  182. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  183. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  184. package/foundation/doc-compiler/inputs.d.mts +2 -2
  185. package/foundation/doc-compiler/inputs.mjs +6 -1
  186. package/foundation/doc-compiler/ir.mjs +7 -0
  187. package/foundation/doc-compiler/lenses.d.mts +8 -5
  188. package/foundation/doc-compiler/lenses.mjs +50 -4
  189. package/foundation/doc-compiler/links.d.mts +162 -0
  190. package/foundation/doc-compiler/links.mjs +294 -0
  191. package/foundation/doc-compiler/links.test.mjs +192 -0
  192. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  193. package/foundation/doc-compiler/read.d.mts +3 -2
  194. package/foundation/doc-compiler/read.mjs +6 -1
  195. package/foundation/doc-compiler/tree.d.mts +288 -0
  196. package/foundation/doc-compiler/tree.mjs +876 -0
  197. package/foundation/doc-compiler/tree.test.mjs +598 -0
  198. package/foundation/integrations/autolink.test.mjs +1 -1
  199. package/foundation/integrations/cli-requirement.d.mts +45 -0
  200. package/foundation/integrations/cli-requirement.mjs +154 -0
  201. package/foundation/integrations/cli-requirement.test.mjs +84 -0
  202. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  203. package/foundation/integrations/contribution-inventory.mjs +10 -4
  204. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  205. package/foundation/integrations/integration-warnings.d.mts +9 -2
  206. package/foundation/integrations/integration-warnings.mjs +51 -26
  207. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  208. package/foundation/integrations/validate-contributions.mjs +25 -27
  209. package/foundation/response/response-types.doc.d.mts +5 -1
  210. package/foundation/response/response-types.doc.mjs +19 -10
  211. package/foundation/text/string-utils.d.mts +8 -0
  212. package/foundation/text/string-utils.mjs +18 -0
  213. package/foundation/xle/expand.mjs +1 -1
  214. package/foundation/xle/xle.test.mjs +13 -0
  215. package/package.json +9 -9
  216. package/assets/docs/cli.doc.mjs +0 -15
@@ -12,6 +12,7 @@ import {
12
12
  integrationAddTemplate,
13
13
  } from './add-contribution.mjs';
14
14
  import {validateLocalIntegration} from './validate-integration.mjs';
15
+ import {DOCS_TREE_CLI} from '../../foundation/integrations/cli-requirement.mjs';
15
16
 
16
17
  let tmpDir;
17
18
 
@@ -314,6 +315,142 @@ describe('integrationAdd doc', () => {
314
315
  expect(docErrors).toEqual([]);
315
316
  });
316
317
 
318
+ it('refuses to write from a folder with no package.json into the package above it', async () => {
319
+ setupBare();
320
+ const inside = path.join(tmpDir, 'kit');
321
+ fs.mkdirSync(inside);
322
+ await expect(
323
+ integrationAdd('doc', 'my-guide', {cwd: inside, parent: 'acme'}),
324
+ ).rejects.toMatchObject({
325
+ code: 'ERR_INVALID_ARGUMENT',
326
+ message: expect.stringContaining('has no package.json'),
327
+ });
328
+ expect(fs.existsSync(path.join(tmpDir, 'docs'))).toBe(false);
329
+ expect(fs.existsSync(path.join(tmpDir, 'astryx.integration.mjs'))).toBe(false);
330
+ });
331
+
332
+ it('finds an integration from a folder inside it', async () => {
333
+ setup();
334
+ const inside = path.join(tmpDir, 'src');
335
+ fs.mkdirSync(inside);
336
+ const result = await integrationAdd('doc', 'my-guide', {cwd: inside});
337
+ expect(result.data.files).toContain('docs/my-guide.doc.mjs');
338
+ expect(fs.existsSync(path.join(tmpDir, 'docs/my-guide.doc.mjs'))).toBe(true);
339
+ });
340
+
341
+ it('places a guide in a namespace of the package, writing the namespace once', async () => {
342
+ setup();
343
+ const first = await integrationAdd('doc', 'deploying', {
344
+ cwd: tmpDir,
345
+ parent: 'acme',
346
+ });
347
+ expect(first.data.files).toEqual(
348
+ expect.arrayContaining(['docs/deploying.doc.mjs', 'docs/acme.doc.mjs']),
349
+ );
350
+ const guide = fs.readFileSync(path.join(tmpDir, 'docs/deploying.doc.mjs'), 'utf-8');
351
+ expect(guide).toContain("placement: {parent: 'namespace:acme', slot: 'guides'}");
352
+ const namespace = fs.readFileSync(path.join(tmpDir, 'docs/acme.doc.mjs'), 'utf-8');
353
+ expect(namespace).toContain("type: 'namespace'");
354
+ expect(namespace).toContain("guides: {title: 'Guides', accepts: {kinds: ['generic']}}");
355
+
356
+ // The namespace doc needs a CLI that reads it, declared as an optional peer.
357
+ const pkg = JSON.parse(fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'));
358
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': `>=${DOCS_TREE_CLI}`});
359
+ expect(pkg.peerDependenciesMeta).toEqual({'@astryxdesign/cli': {optional: true}});
360
+
361
+ const second = await integrationAdd('doc', 'upgrading', {
362
+ cwd: tmpDir,
363
+ parent: 'acme',
364
+ });
365
+ expect(second.data.files).not.toContain('docs/acme.doc.mjs');
366
+
367
+ const validation = await validateLocalIntegration(tmpDir);
368
+ expect(validation.issues.filter(i => i.code === 'invalid_doc')).toEqual([]);
369
+ });
370
+
371
+ it('finds the --parent namespace by its name, wherever its file is, and uses its slot', async () => {
372
+ setup({manifest: "export default {docs: './docs'};\n"});
373
+ fs.mkdirSync(path.join(tmpDir, 'docs', 'ns'), {recursive: true});
374
+ fs.writeFileSync(
375
+ path.join(tmpDir, 'docs', 'ns', 'acme.doc.mjs'),
376
+ "export default {type: 'namespace', name: 'acme', title: 'Acme', summary: 'Acme.', slots: {items: {title: 'Items', accepts: {kinds: ['generic']}}}};\n",
377
+ );
378
+ const result = await integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'acme'});
379
+ expect(result.data.files).not.toContain('docs/acme.doc.mjs');
380
+ expect(fs.existsSync(path.join(tmpDir, 'docs', 'acme.doc.mjs'))).toBe(false);
381
+ expect(fs.readFileSync(path.join(tmpDir, 'docs', 'deploying.doc.mjs'), 'utf-8')).toContain(
382
+ "placement: {parent: 'namespace:acme', slot: 'items'}",
383
+ );
384
+ });
385
+
386
+ it('refuses --parent when its file is not that namespace, or the namespace has no slot for a guide', async () => {
387
+ setup({manifest: "export default {docs: './docs'};\n"});
388
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
389
+ const nsFile = path.join(tmpDir, 'docs', 'acme.doc.mjs');
390
+ fs.writeFileSync(
391
+ nsFile,
392
+ "export default {type: 'generic', name: 'acme', title: 'Acme', description: 'A topic.', sections: [{title: 'Only', content: [{type: 'prose', text: 'x'}]}]};\n",
393
+ );
394
+ await expect(
395
+ integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'acme'}),
396
+ ).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
397
+ // A fresh file: the module loader keeps the first import of a path.
398
+ fs.writeFileSync(
399
+ path.join(tmpDir, 'docs', 'beta.doc.mjs'),
400
+ "export default {type: 'namespace', name: 'beta', title: 'Beta', summary: 'Beta.', slots: {items: {title: 'Items', accepts: {kinds: ['function']}}}};\n",
401
+ );
402
+ await expect(
403
+ integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'beta'}),
404
+ ).rejects.toMatchObject({
405
+ code: 'ERR_INVALID_ARGUMENT',
406
+ message: expect.stringContaining('no slot that takes a guide'),
407
+ });
408
+ fs.writeFileSync(
409
+ path.join(tmpDir, 'docs', 'gamma.doc.mjs'),
410
+ "export default {type: 'namespace', name: 'gamma', title: 'Gamma', summary: 'Gamma.', slots: {guides: {title: 'Guides', accepts: {kinds: ['function']}}, more: {title: 'More', accepts: {kinds: ['generic']}}, extra: {title: 'Extra', accepts: {kinds: ['generic']}}}};\n",
411
+ );
412
+ await expect(
413
+ integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'gamma'}),
414
+ ).rejects.toMatchObject({
415
+ code: 'ERR_INVALID_ARGUMENT',
416
+ message: expect.stringContaining('more than one slot that takes a guide (more, extra)'),
417
+ });
418
+ expect(fs.existsSync(path.join(tmpDir, 'docs', 'deploying.doc.mjs'))).toBe(false);
419
+ });
420
+
421
+ it('raises a CLI peer that admits a CLI too old for namespace docs, and keeps one that does not', async () => {
422
+ setup();
423
+ const file = path.join(tmpDir, 'package.json');
424
+ const write = (/** @type {string} */ range) => {
425
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
426
+ pkg.peerDependencies = {'@astryxdesign/cli': range};
427
+ fs.writeFileSync(file, `${JSON.stringify(pkg, null, 2)}\n`);
428
+ };
429
+ write('^0.6.0');
430
+ await integrationAdd('doc', 'deploying', {cwd: tmpDir, parent: 'acme'});
431
+ expect(JSON.parse(fs.readFileSync(file, 'utf-8')).peerDependencies).toEqual({
432
+ '@astryxdesign/cli': `>=${DOCS_TREE_CLI}`,
433
+ });
434
+ write('^9.1.0');
435
+ await integrationAdd('doc', 'upgrading', {cwd: tmpDir, parent: 'acme'});
436
+ expect(JSON.parse(fs.readFileSync(file, 'utf-8')).peerDependencies).toEqual({
437
+ '@astryxdesign/cli': '^9.1.0',
438
+ });
439
+ });
440
+
441
+ it('refuses --parent with a relationship, or a namespace name that is not a route segment', async () => {
442
+ setup();
443
+ await expect(
444
+ integrationAdd('doc', 'x', {cwd: tmpDir, parent: 'acme', replaces: 'getting-started'}),
445
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
446
+ await expect(
447
+ integrationAdd('doc', 'x', {cwd: tmpDir, parent: 'Acme Kit'}),
448
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
449
+ await expect(
450
+ integrationAdd('template', 'x', {cwd: tmpDir, parent: 'acme'}),
451
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
452
+ });
453
+
317
454
  it('includes replaces in the generated doc', async () => {
318
455
  setup();
319
456
  const result = await integrationAdd('doc', 'my-tokens', {
@@ -3,13 +3,22 @@
3
3
  /**
4
4
  * @file Integration authoring diagnostics against the built-in Core catalog.
5
5
  *
6
- * Components and templates may intentionally share a Core identity, but
7
- * unqualified lookup then fails closed and callers must select the package.
8
- * Docs have explicit `replaces` / `extends` relationships, so the check can
9
- * distinguish intentional ownership from an accidental same-name shadow.
6
+ * Templates may intentionally replace Core identities; undeclared same-id
7
+ * overlaps stay fail-closed and require package selection. The CLI package
8
+ * version gates replacement-specific fields so 0.6.x keeps its released shape.
9
+ * Docs have explicit `replaces` / `extends` relationships with parallel
10
+ * validation semantics.
11
+ *
12
+ * @input Integration packages, built-in catalogs, and the CLI release boundary.
13
+ * @output Typed template, component, and documentation authoring diagnostics.
14
+ * @position Public integration-authoring API over private discovery adapters.
10
15
  */
11
16
 
12
17
  import {getCliInvocation} from '../../foundation/env/package-manager.mjs';
18
+ import {
19
+ packageDocsProblems,
20
+ packageReferenceProblems,
21
+ } from '../docs/_adapter.mjs';
13
22
  import {findCoreDir} from '../../foundation/fs/paths.mjs';
14
23
  import {
15
24
  discoverIntegrationComponents,
@@ -20,9 +29,11 @@ import {
20
29
  discoverIntegrationDocs,
21
30
  } from '../../foundation/discovery/docs-discovery.mjs';
22
31
  import {
32
+ applyTemplateReplacements,
23
33
  discoverCoreTemplates,
24
34
  discoverIntegrationTemplatesForOne,
25
35
  } from '../../foundation/discovery/template-adapter.mjs';
36
+ import {expandedTemplateConflictSchemaActive} from '../../foundation/discovery/template-conflict-release.mjs';
26
37
  import {
27
38
  validateInstalledIntegration,
28
39
  validateLocalIntegration,
@@ -48,16 +59,27 @@ async function resolveIntegration(pkg, cwd) {
48
59
  /**
49
60
  * Add discovery errors once to an issue list.
50
61
  * @param {Array<{code: string, severity: 'warning' | 'error', message: string}>} issues
51
- * @param {Array<{message: string} | Error>} errors
62
+ * @param {Array<{message: string, code?: string, severity?: 'warning' | 'error'} | Error>} errors
52
63
  * @param {string} code
53
64
  */
54
65
  function addErrors(issues, errors, code) {
55
66
  for (const error of errors) {
56
67
  const message = error.message;
57
- if (issues.some(issue => issue.code === code && issue.message === message)) {
68
+ const issueCode =
69
+ 'code' in error && typeof error.code === 'string' ? error.code : code;
70
+ const severity =
71
+ 'severity' in error &&
72
+ (error.severity === 'warning' || error.severity === 'error')
73
+ ? error.severity
74
+ : 'error';
75
+ if (
76
+ issues.some(
77
+ issue => issue.code === issueCode && issue.message === message,
78
+ )
79
+ ) {
58
80
  continue;
59
81
  }
60
- issues.push({code, severity: 'error', message});
82
+ issues.push({code: issueCode, severity, message});
61
83
  }
62
84
  }
63
85
 
@@ -74,7 +96,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
74
96
  const version = resolved.found ? (resolved.version ?? null) : null;
75
97
  const issues = [...resolved.issues];
76
98
 
77
- if (!resolved.integration?.templates || name == null) {
99
+ if (!resolved.integration || name == null) {
78
100
  return {
79
101
  type: 'integration.template-conflicts',
80
102
  data: {name, version, conflicts: [], issues},
@@ -87,6 +109,32 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
87
109
  ]);
88
110
  addErrors(issues, errors, 'invalid_template');
89
111
 
112
+ const expandedConflictSchema = expandedTemplateConflictSchemaActive();
113
+ const replacementResolution = applyTemplateReplacements(
114
+ [...coreTemplates, ...templates],
115
+ errors.filter(error => error.replacementTarget != null),
116
+ );
117
+ for (const error of replacementResolution.errors) {
118
+ if (
119
+ !issues.some(
120
+ issue => issue.code === error.code && issue.message === error.message,
121
+ )
122
+ ) {
123
+ issues.push({
124
+ code: error.code,
125
+ severity: error.severity,
126
+ message: error.message,
127
+ });
128
+ }
129
+ }
130
+ const activeReplacementIds = new Set(
131
+ replacementResolution.templates
132
+ .filter(
133
+ template => template.package === name && template.replaces != null,
134
+ )
135
+ .map(template => template.dirName),
136
+ );
137
+
90
138
  /** @type {Map<string, Array<{type: 'page' | 'block', name: string}>>} */
91
139
  const coreById = new Map();
92
140
  for (const template of coreTemplates) {
@@ -101,30 +149,69 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
101
149
  }
102
150
 
103
151
  const run = getCliInvocation(cwd);
104
- const conflicts = templates
105
- .flatMap(template => {
106
- const coreMatches = coreById.get(template.dirName);
107
- if (!coreMatches) return [];
108
- const command = `${run} template ${shellArg(template.dirName)} --package ${shellArg(name)}`;
109
- const coreKinds = coreMatches
110
- .map(match => `${match.type} "${match.name}"`)
111
- .join(', ');
112
- return [
113
- {
152
+ /** @type {import('./authoring-checks.type.mjs').IntegrationTemplateConflict[]} */
153
+ const conflicts = [];
154
+ for (const template of templates) {
155
+ const sameIdCore = coreById.get(template.dirName);
156
+ const replacementIsActive = activeReplacementIds.has(template.dirName);
157
+
158
+ if (
159
+ expandedConflictSchema &&
160
+ replacementIsActive &&
161
+ template.replaces != null
162
+ ) {
163
+ // This branch is unreachable before the package reaches 0.7.0. Keep the
164
+ // published 0.6.x conflict typedef narrow until the activation change.
165
+ conflicts.push(
166
+ /** @type {any} */ ({
114
167
  id: template.dirName,
115
- severity: /** @type {const} */ ('warning'),
168
+ severity: 'info',
169
+ relationship: 'replaces',
170
+ replaces: template.replaces,
116
171
  integrationPackage: name,
117
172
  integrationType: template.type,
118
173
  integrationName: template.name,
119
- coreMatches,
174
+ coreMatches: coreById.get(template.replaces) ?? [],
120
175
  message:
121
- `Template id "${template.dirName}" conflicts with Core (${coreKinds}). ` +
122
- 'Consider renaming the integration template. If you keep it, always select it with --package.',
123
- command,
124
- },
125
- ];
126
- })
127
- .sort((a, b) => a.id.localeCompare(b.id));
176
+ `Intentional replacement: "${template.dirName}" replaces the Core template ` +
177
+ `"${template.replaces}" for unqualified lookup.`,
178
+ command: `${run} template ${shellArg(template.replaces)} --package ${shellArg('@astryxdesign/core')}`,
179
+ }),
180
+ );
181
+ }
182
+
183
+ if (
184
+ sameIdCore &&
185
+ !(replacementIsActive && template.replaces === template.dirName)
186
+ ) {
187
+ const coreKinds = sameIdCore
188
+ .map(match => `${match.type} "${match.name}"`)
189
+ .join(', ');
190
+ const compatibleKind = sameIdCore.some(
191
+ match => match.type === template.type,
192
+ );
193
+ conflicts.push({
194
+ id: template.dirName,
195
+ severity: 'warning',
196
+ ...(expandedConflictSchema ? {relationship: 'accidental'} : {}),
197
+ integrationPackage: name,
198
+ integrationType: template.type,
199
+ integrationName: template.name,
200
+ coreMatches: sameIdCore,
201
+ message: expandedConflictSchema
202
+ ? compatibleKind
203
+ ? `Template id "${template.dirName}" conflicts with Core (${coreKinds}). Consider renaming it, or set replaces: ${JSON.stringify(template.dirName)} in its metadata to replace the Core template.`
204
+ : `Template id "${template.dirName}" conflicts with Core (${coreKinds}), but a ${template.type} template cannot replace a different template kind. Rename the integration template.`
205
+ : `Template id "${template.dirName}" conflicts with Core (${coreKinds}). Consider renaming the integration template. If you keep it, always select it with --package.`,
206
+ command: `${run} template ${shellArg(template.dirName)} --package ${shellArg(name)}`,
207
+ });
208
+ }
209
+ }
210
+ conflicts.sort((a, b) =>
211
+ `${a.id}:${'relationship' in a ? a.relationship : ''}`.localeCompare(
212
+ `${b.id}:${'relationship' in b ? b.relationship : ''}`,
213
+ ),
214
+ );
128
215
 
129
216
  return {
130
217
  type: 'integration.template-conflicts',
@@ -211,10 +298,11 @@ export async function integrationDocConflicts(pkg, options = {}) {
211
298
  };
212
299
  }
213
300
 
214
- const [{records, errors}, builtinTopics] = await Promise.all([
301
+ const [discovered, builtinTopics] = await Promise.all([
215
302
  discoverIntegrationDocs(resolved.integration),
216
303
  Promise.resolve(discoverBuiltinTopics()),
217
304
  ]);
305
+ const {records, errors} = discovered;
218
306
  addErrors(issues, errors, 'invalid_doc');
219
307
  const coreTopicsByKey = new Map(
220
308
  Object.keys(builtinTopics).map(topic => [topic.toLowerCase(), topic]),
@@ -276,6 +364,28 @@ export async function integrationDocConflicts(pkg, options = {}) {
276
364
  ),
277
365
  );
278
366
 
367
+ // The same graph checks `astryx doctor` runs in a project: the namespaces
368
+ // and placed guides this package adds to the docs tree, and every link in
369
+ // its docs (spec:AST-046, spec:AST-047).
370
+ if (errors.length === 0) {
371
+ for (const message of await packageDocsProblems(
372
+ /** @type {{name: string}} */ (resolved.integration),
373
+ discovered,
374
+ )) {
375
+ issues.push({code: 'invalid_doc_graph', severity: 'warning', message});
376
+ }
377
+
378
+ // A reference block includes content rather than linking to it, so one
379
+ // that cannot include what it names loses that content for every reader:
380
+ // an error, where a link that names no doc still prints as written.
381
+ for (const message of await packageReferenceProblems(
382
+ /** @type {{name: string}} */ (resolved.integration),
383
+ discovered,
384
+ )) {
385
+ issues.push({code: 'invalid_doc_reference', severity: 'error', message});
386
+ }
387
+ }
388
+
279
389
  return {
280
390
  type: 'integration.doc-conflicts',
281
391
  data: {name, version, findings, issues},
@@ -2,9 +2,16 @@
2
2
 
3
3
  /**
4
4
  * @file Hermetic integration authoring checks against the real Core catalogs.
5
+ * @input Integration fixtures and the post-0.7 conflict projection.
6
+ * @output Coverage for replacement validation and public diagnostics.
7
+ * @position Unit coverage; the 0.6.x compatibility shape has its own fixture.
5
8
  */
6
9
 
7
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
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 {discoverCoreTemplates} from '../../foundation/discovery/template-adapter.mjs';
@@ -20,7 +27,14 @@ import {
20
27
 
21
28
  let tmpDir;
22
29
 
23
- function writeIntegration({id, name, type = 'block', root = tmpDir}) {
30
+ function writeIntegration({
31
+ id,
32
+ name,
33
+ type = 'block',
34
+ root = tmpDir,
35
+ replacements,
36
+ withSource = true,
37
+ }) {
24
38
  fs.mkdirSync(root, {recursive: true});
25
39
  fs.writeFileSync(
26
40
  path.join(root, 'package.json'),
@@ -34,8 +48,9 @@ function writeIntegration({id, name, type = 'block', root = tmpDir}) {
34
48
  fs.mkdirSync(path.dirname(stem), {recursive: true});
35
49
  fs.writeFileSync(
36
50
  `${stem}.doc.mjs`,
37
- `export default {type: '${type}', name: ${JSON.stringify(name)}, description: 'fixture'};\n`,
51
+ `export default {type: '${type}', name: ${JSON.stringify(name)}, description: 'fixture'${replacements?.[id] == null ? '' : `, replaces: ${JSON.stringify(replacements[id])}`}};\n`,
38
52
  );
53
+ if (!withSource) return;
39
54
  fs.writeFileSync(
40
55
  `${stem}.tsx`,
41
56
  'export default function Fixture() { return null; }\n',
@@ -158,6 +173,159 @@ describe('integrationTemplateConflicts', () => {
158
173
  );
159
174
  });
160
175
 
176
+ it('classifies a valid replacement and points to the Core original', async () => {
177
+ const core = (await discoverCoreTemplates()).find(
178
+ template => template.type === 'page',
179
+ );
180
+ expect(core).toBeDefined();
181
+ writeIntegration({
182
+ id: 'acme-app-shell',
183
+ name: 'Acme app shell',
184
+ type: core.type,
185
+ replacements: {'acme-app-shell': core.dirName},
186
+ });
187
+
188
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
189
+
190
+ expect(result.data.issues).toEqual([]);
191
+ expect(result.data.conflicts).toEqual([
192
+ expect.objectContaining({
193
+ id: 'acme-app-shell',
194
+ severity: 'info',
195
+ relationship: 'replaces',
196
+ replaces: core.dirName,
197
+ }),
198
+ ]);
199
+ expect(result.data.conflicts[0].command).toContain(
200
+ `template ${core.dirName} --package @astryxdesign/core`,
201
+ );
202
+ });
203
+
204
+ it('reports a replacement target that Core does not provide', async () => {
205
+ writeIntegration({
206
+ id: 'acme-app-shell',
207
+ name: 'Acme app shell',
208
+ type: 'page',
209
+ replacements: {'acme-app-shell': 'missing-core-shell'},
210
+ });
211
+
212
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
213
+
214
+ expect(result.data.issues).toEqual(
215
+ expect.arrayContaining([
216
+ expect.objectContaining({
217
+ code: 'missing_template_replacement_target',
218
+ severity: 'error',
219
+ }),
220
+ ]),
221
+ );
222
+ });
223
+
224
+ it('reports a replacement declared by a template that cannot be used', async () => {
225
+ const [core] = await discoverCoreTemplates();
226
+ expect(core).toBeDefined();
227
+ writeIntegration({
228
+ id: 'broken-template',
229
+ name: 'Broken template',
230
+ type: core.type,
231
+ replacements: {'broken-template': core.dirName},
232
+ withSource: false,
233
+ });
234
+
235
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
236
+
237
+ expect(result.data.issues).toEqual(
238
+ expect.arrayContaining([
239
+ expect.objectContaining({
240
+ code: 'invalid_template_replacement',
241
+ severity: 'error',
242
+ message: expect.stringContaining('cannot be used'),
243
+ }),
244
+ ]),
245
+ );
246
+ });
247
+
248
+ it('reports two templates that replace the same Core target as ambiguous', async () => {
249
+ const [core] = await discoverCoreTemplates();
250
+ expect(core).toBeDefined();
251
+ const replacements = {
252
+ 'acme-app-shell-a': core.dirName,
253
+ 'acme-app-shell-b': core.dirName,
254
+ };
255
+ writeIntegration({
256
+ id: 'acme-app-shell-a',
257
+ name: 'Acme app shell A',
258
+ type: core.type,
259
+ replacements,
260
+ });
261
+ writeIntegration({
262
+ id: 'acme-app-shell-b',
263
+ name: 'Acme app shell B',
264
+ type: core.type,
265
+ replacements,
266
+ });
267
+
268
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
269
+
270
+ expect(result.data.issues).toEqual(
271
+ expect.arrayContaining([
272
+ expect.objectContaining({
273
+ code: 'ambiguous_template_replacement',
274
+ severity: 'error',
275
+ }),
276
+ ]),
277
+ );
278
+ });
279
+
280
+ it('reports a replacement whose template kind differs from Core', async () => {
281
+ const corePage = (await discoverCoreTemplates()).find(
282
+ template => template.type === 'page',
283
+ );
284
+ expect(corePage).toBeDefined();
285
+ writeIntegration({
286
+ id: 'acme-app-shell',
287
+ name: 'Acme app shell',
288
+ type: 'block',
289
+ replacements: {'acme-app-shell': corePage.dirName},
290
+ });
291
+
292
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
293
+
294
+ expect(result.data.issues).toEqual(
295
+ expect.arrayContaining([
296
+ expect.objectContaining({
297
+ code: 'invalid_template_replacement',
298
+ severity: 'error',
299
+ message: expect.stringContaining('same type'),
300
+ }),
301
+ ]),
302
+ );
303
+ });
304
+
305
+ it('does not recommend an impossible replacement for a different Core kind', async () => {
306
+ const corePage = (await discoverCoreTemplates()).find(
307
+ template => template.type === 'page',
308
+ );
309
+ expect(corePage).toBeDefined();
310
+ writeIntegration({
311
+ id: corePage.dirName,
312
+ name: 'Acme block with a page id',
313
+ type: 'block',
314
+ });
315
+
316
+ const result = await integrationTemplateConflicts(undefined, {cwd: tmpDir});
317
+ const conflict = result.data.conflicts.find(
318
+ item => item.id === corePage.dirName,
319
+ );
320
+
321
+ expect(conflict?.relationship).toBe('accidental');
322
+ expect(conflict?.message).toContain(
323
+ 'cannot replace a different template kind',
324
+ );
325
+ expect(conflict?.message).toContain('Rename');
326
+ expect(conflict?.message).not.toContain('set replaces');
327
+ });
328
+
161
329
  it('shell-quotes unusual ids instead of allowing command substitution', () => {
162
330
  expect(shellArg('safe/id')).toBe('safe/id');
163
331
  expect(shellArg('my$thing')).toBe("'my$thing'");
@@ -1,6 +1,11 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- /** @file Colocated types for integration authoring diagnostics. */
3
+ /**
4
+ * @file Colocated public types for integration authoring diagnostics.
5
+ * @input Stable response fields exposed by integration-authoring APIs.
6
+ * @output JSDoc typedefs consumed by declarations, commands, and callers.
7
+ * @position Public type boundary for integration diagnostics.
8
+ */
4
9
 
5
10
  /**
6
11
  * @typedef {object} IntegrationAuthoringOptions
@@ -10,6 +10,7 @@ export type IntegrationAddComponentOptions = IntegrationAddBaseOptions;
10
10
  export type IntegrationAddDocOptions = IntegrationAddBaseOptions & {
11
11
  replaces?: string;
12
12
  extends?: string;
13
+ parent?: string;
13
14
  };
14
15
  export type IntegrationAddTemplateOptions = IntegrationAddBaseOptions & {
15
16
  type?: "page" | "block";
@@ -29,6 +30,7 @@ export type IntegrationAddOptions = {
29
30
  templateType?: "page" | "block" | undefined;
30
31
  replaces?: string | undefined;
31
32
  extends?: string | undefined;
33
+ parent?: string | undefined;
32
34
  to?: string | undefined;
33
35
  };
34
36
  /**
@@ -20,6 +20,7 @@
20
20
  * @typedef {IntegrationAddBaseOptions & {
21
21
  * replaces?: string,
22
22
  * extends?: string,
23
+ * parent?: string,
23
24
  * }} IntegrationAddDocOptions
24
25
  */
25
26
 
@@ -48,6 +49,7 @@
48
49
  * @property {'page'|'block'} [templateType]
49
50
  * @property {string} [replaces]
50
51
  * @property {string} [extends]
52
+ * @property {string} [parent]
51
53
  * @property {string} [to]
52
54
  */
53
55
 
@@ -67,6 +67,12 @@ export const doc = {
67
67
  description:
68
68
  'Existing topic to extend. Only valid for doc, and not with options.replaces.',
69
69
  },
70
+ {
71
+ name: 'options.parent',
72
+ type: 'string',
73
+ description:
74
+ "Namespace of this package to place the doc in, as a guide in its `guides` slot; the namespace doc is written when missing. Only valid for doc, and not with options.replaces or options.extends.",
75
+ },
70
76
  {
71
77
  name: 'options.to',
72
78
  type: 'string',
@@ -9,7 +9,7 @@ export const doc = {
9
9
  displayName: 'integrationAddDoc()',
10
10
  summary: 'Add a complete reference-doc contribution.',
11
11
  description:
12
- 'Creates a valid generic topic, declares the docs root on first use, and supports an intentional replaces or extends relationship.',
12
+ 'Creates a valid generic topic, declares the docs root on first use, and supports an intentional replaces or extends relationship, or places the doc as a guide in a namespace of the package.',
13
13
  importPath: '@astryxdesign/cli/api',
14
14
  signature:
15
15
  'integrationAddDoc(name: string, options?: IntegrationAddDocOptions): Promise<IntegrationAddResponse>',
@@ -42,6 +42,12 @@ export const doc = {
42
42
  type: 'string',
43
43
  description: 'Existing topic this topic extends.',
44
44
  },
45
+ {
46
+ name: 'options.parent',
47
+ type: 'string',
48
+ description:
49
+ "Namespace of this package to place the doc in, as a guide in its `guides` slot; the namespace doc is written when missing, and package.json declares the CLI that reads it as an optional `@astryxdesign/cli` peer. Only valid for doc, and not with options.replaces or options.extends.",
50
+ },
45
51
  ],
46
52
  returns: [
47
53
  {