@astryxdesign/cli 0.7.2-canary.b06a093 → 0.7.2-canary.b40ba52

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 (289) hide show
  1. package/README.md +20 -19
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +41 -1
  4. package/api/component/_adapter.mjs +93 -7
  5. package/api/component/component.mjs +22 -5
  6. package/api/component/component.test.mjs +420 -167
  7. package/api/component/integration-export-name.test.mjs +644 -0
  8. package/api/component/list/list.mjs +42 -4
  9. package/api/discover/_adapter.d.mts +119 -12
  10. package/api/discover/_adapter.mjs +449 -10
  11. package/api/discover/_adapter.test.mjs +599 -17
  12. package/api/discover/_catalog-view.d.mts +16 -5
  13. package/api/discover/_catalog-view.mjs +32 -8
  14. package/api/discover/discover.d.mts +11 -0
  15. package/api/discover/discover.doc.mjs +7 -6
  16. package/api/discover/discover.mjs +107 -19
  17. package/api/discover/discover.type.d.mts +18 -7
  18. package/api/discover/discover.type.mjs +15 -7
  19. package/api/discover/list/list.d.mts +4 -3
  20. package/api/discover/list/list.mjs +17 -10
  21. package/api/docs/_adapter.d.mts +11 -0
  22. package/api/docs/_adapter.mjs +244 -1
  23. package/api/docs/integrationDocs.test.mjs +124 -0
  24. package/api/doctor/doctor.mjs +27 -3
  25. package/api/doctor/doctor.test.mjs +43 -0
  26. package/api/doctor/theme-checks.mjs +1 -1
  27. package/api/doctor/theme-checks.test.mjs +136 -0
  28. package/api/gap-report/gap-report.d.mts +3 -0
  29. package/api/gap-report/gap-report.doc.mjs +11 -3
  30. package/api/gap-report/gap-report.mjs +219 -52
  31. package/api/gap-report/gap-report.test.mjs +233 -0
  32. package/api/gap-report/gap-report.type.d.mts +41 -0
  33. package/api/gap-report/gap-report.type.mjs +18 -0
  34. package/api/index.d.mts +2 -0
  35. package/api/index.mjs +2 -0
  36. package/api/init/run/run.mjs +2 -2
  37. package/api/integration/_adapter.d.mts +12 -0
  38. package/api/integration/_adapter.mjs +54 -0
  39. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  40. package/api/integration/add-contribution.mjs +8 -4
  41. package/api/integration/add-contribution.test.mjs +4 -2
  42. package/api/integration/authoring-checks.mjs +11 -2
  43. package/api/integration/authoring-checks.test.mjs +39 -0
  44. package/api/integration/authoring-checks.type.d.mts +9 -0
  45. package/api/integration/authoring-checks.type.mjs +14 -1
  46. package/api/integration/check/check.d.mts +96 -0
  47. package/api/integration/check/check.mjs +357 -0
  48. package/api/integration/check/check.test.mjs +489 -0
  49. package/api/integration/integration-check.type.d.mts +118 -0
  50. package/api/integration/integration-check.type.mjs +84 -0
  51. package/api/integration/integrationCheck.doc.d.mts +10 -0
  52. package/api/integration/integrationCheck.doc.mjs +73 -0
  53. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  54. package/api/integration/pack-check.mjs +353 -114
  55. package/api/integration/pack-check.test.mjs +700 -0
  56. package/api/integration/validate-integration.mjs +8 -0
  57. package/api/integration/validate-integration.test.mjs +11 -0
  58. package/api/integration/validate-integration.type.d.mts +8 -0
  59. package/api/integration/validate-integration.type.mjs +12 -1
  60. package/api/integration/validateIntegration.doc.mjs +19 -3
  61. package/api/search/search.d.mts +81 -12
  62. package/api/search/search.domain-priority.test.mjs +108 -18
  63. package/api/search/search.integration-check.test.mjs +24 -0
  64. package/api/search/search.mjs +609 -53
  65. package/api/search/search.test.mjs +175 -0
  66. package/api/swizzle/copy/copy.mjs +28 -14
  67. package/api/template/template.test.mjs +120 -3
  68. package/api/theme/build/build.family.test.mjs +64 -0
  69. package/api/theme/build/build.mjs +180 -24
  70. package/api/theme/themeBuild.doc.mjs +4 -4
  71. package/api/upgrade/_adapter.d.mts +40 -2
  72. package/api/upgrade/_adapter.mjs +117 -4
  73. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  74. package/api/upgrade/run/run.mjs +30 -1
  75. package/api/upgrade/status/status.d.mts +21 -5
  76. package/api/upgrade/status/status.mjs +45 -8
  77. package/api/upgrade/upgrade.doc.mjs +5 -3
  78. package/api/upgrade/upgrade.type.d.mts +23 -0
  79. package/api/upgrade/upgrade.type.mjs +16 -1
  80. package/assets/codemods/runner.mjs +7 -1
  81. package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
  82. package/assets/codemods/transforms/next/index.mjs +11 -1
  83. package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
  84. package/assets/discover/official-packages.json +367 -0
  85. package/assets/docs/README.md +10 -0
  86. package/assets/docs/author-a-theme.doc.mjs +1 -1
  87. package/assets/docs/getting-started.doc.mjs +3 -3
  88. package/assets/docs/styling-overview.doc.mjs +1 -1
  89. package/assets/docs/theme.doc.dense.mjs +1 -1
  90. package/assets/docs/theme.doc.mjs +1 -1
  91. package/assets/docs/theme.doc.zh.mjs +1 -1
  92. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  93. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  94. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  95. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  96. package/assets/docs/tree/block-template.doc.mjs +8 -20
  97. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  98. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  99. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  100. package/assets/docs/tree/checks.doc.mjs +24 -16
  101. package/assets/docs/tree/codemods.doc.mjs +4 -4
  102. package/assets/docs/tree/component-family.doc.mjs +8 -6
  103. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  104. package/assets/docs/tree/components.doc.mjs +1 -1
  105. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
  106. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  107. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  108. package/assets/docs/tree/docs.doc.mjs +3 -3
  109. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  110. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  111. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  112. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  113. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  114. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  115. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  116. package/assets/docs/tree/integrations.doc.mjs +8 -0
  117. package/assets/docs/tree/links.doc.mjs +6 -5
  118. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  119. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  120. package/assets/docs/tree/migration.doc.mjs +0 -1
  121. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  122. package/assets/docs/tree/page-template.doc.mjs +4 -8
  123. package/assets/docs/tree/publishing.doc.mjs +1 -1
  124. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  125. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  126. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  127. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  128. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  129. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  130. package/assets/docs/tree/single-component.doc.mjs +15 -6
  131. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  132. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  133. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  134. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  135. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  136. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  137. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  138. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  139. package/assets/docs/tree/templates.doc.mjs +1 -1
  140. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  141. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  142. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  143. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  144. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  145. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  146. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  147. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  148. package/assets/docs/tree/versioning.doc.mjs +7 -6
  149. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  150. package/assets/docs/use-a-theme.doc.mjs +2 -2
  151. package/assets/docs/working-with-ai.doc.mjs +43 -4
  152. package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
  153. package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
  154. package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
  155. package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
  156. package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
  157. package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
  158. package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
  159. package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
  160. package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
  161. package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
  162. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
  163. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
  164. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
  165. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
  166. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
  167. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
  168. package/assets/templates/pages/detail-page/page.tsx +3 -3
  169. package/assets/templates/pages/table-inbox/page.tsx +10 -8
  170. package/assets/theme.template.ts +1 -1
  171. package/authoring/codemod/codemod.doc.mjs +7 -3
  172. package/authoring/config/config.doc.mjs +9 -6
  173. package/authoring/config/type.ts +4 -2
  174. package/authoring/discover/discover.doc.mjs +1 -1
  175. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  176. package/authoring/doctypes/base/type.ts +6 -0
  177. package/authoring/doctypes/command/command.doc.mjs +14 -12
  178. package/authoring/doctypes/component/component.doc.mjs +31 -28
  179. package/authoring/doctypes/component/type.ts +13 -8
  180. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  181. package/authoring/doctypes/function/function.doc.mjs +9 -8
  182. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  183. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  184. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  185. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  186. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  187. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  188. package/authoring/doctypes/template/parse.d.mts +6 -2
  189. package/authoring/doctypes/template/parse.mjs +3 -1
  190. package/authoring/doctypes/template/template.doc.mjs +3 -3
  191. package/authoring/doctypes/template/type.ts +22 -0
  192. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  193. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  194. package/authoring/identity/identity.doc.mjs +3 -3
  195. package/authoring/index.d.ts +1 -0
  196. package/authoring/integration/integration.doc.mjs +12 -4
  197. package/authoring/integration/parse.test.mjs +10 -0
  198. package/authoring/integration/schema.d.mts +2 -0
  199. package/authoring/integration/schema.mjs +1 -0
  200. package/authoring/integration/type.ts +4 -0
  201. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  202. package/clients/cli/commands/build-theme.mjs +1 -1
  203. package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
  204. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  205. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  206. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  207. package/clients/cli/commands/discover.doc.mjs +1 -1
  208. package/clients/cli/commands/discover.mjs +144 -93
  209. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  210. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  211. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  212. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  213. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  214. package/clients/cli/commands/doctor.mjs +190 -0
  215. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  216. package/clients/cli/commands/gap-report.mjs +24 -2
  217. package/clients/cli/commands/gap-report.test.mjs +79 -0
  218. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  219. package/clients/cli/commands/integration-check.test.mjs +284 -0
  220. package/clients/cli/commands/integration.doc.mjs +6 -2
  221. package/clients/cli/commands/integration.mjs +106 -1
  222. package/clients/cli/commands/json-contract.test.mjs +5 -1
  223. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  224. package/clients/cli/commands/swizzle.mjs +5 -3
  225. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  226. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  227. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  228. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  229. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  230. package/clients/cli/index.mjs +30 -5
  231. package/clients/cli/lib/component-format.mjs +5 -1
  232. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  233. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  234. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  235. package/foundation/agent-docs/agent-docs.mjs +8 -6
  236. package/foundation/config/project.mjs +82 -0
  237. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  238. package/foundation/discovery/component-discovery.d.mts +190 -10
  239. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  240. package/foundation/discovery/component-discovery.mjs +864 -56
  241. package/foundation/discovery/component-discovery.test.mjs +96 -0
  242. package/foundation/discovery/component-replacement.mjs +18 -0
  243. package/foundation/discovery/component-replacement.test.mjs +40 -0
  244. package/foundation/discovery/doc-types.d.mts +157 -0
  245. package/foundation/discovery/doc-types.mjs +1224 -0
  246. package/foundation/discovery/doc-types.test.mjs +700 -0
  247. package/foundation/discovery/docs-discovery.d.mts +81 -0
  248. package/foundation/discovery/docs-discovery.mjs +57 -0
  249. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  250. package/foundation/discovery/integration-doc-files.mjs +231 -0
  251. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  252. package/foundation/discovery/module-exports.d.mts +27 -0
  253. package/foundation/discovery/module-exports.mjs +356 -31
  254. package/foundation/discovery/module-exports.test.mjs +172 -0
  255. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  256. package/foundation/discovery/package-tsconfig.mjs +228 -0
  257. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  258. package/foundation/discovery/project-typescript.d.mts +32 -0
  259. package/foundation/discovery/project-typescript.mjs +89 -0
  260. package/foundation/discovery/prop-drift.d.mts +278 -0
  261. package/foundation/discovery/prop-drift.mjs +2263 -0
  262. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  263. package/foundation/discovery/template-adapter.mjs +74 -5
  264. package/foundation/discovery/type-match.d.mts +53 -0
  265. package/foundation/discovery/type-match.mjs +660 -0
  266. package/foundation/discovery/type-match.test.mjs +169 -0
  267. package/foundation/discovery/type-text.d.mts +68 -0
  268. package/foundation/discovery/type-text.mjs +658 -0
  269. package/foundation/discovery/type-text.test.mjs +196 -0
  270. package/foundation/discovery/unresolved-references.d.mts +62 -0
  271. package/foundation/discovery/unresolved-references.mjs +790 -0
  272. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  273. package/foundation/doc-compiler/doc-loads.test.mjs +15 -1
  274. package/foundation/doc-compiler/inputs.mjs +23 -0
  275. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  276. package/foundation/doc-compiler/links.d.mts +9 -5
  277. package/foundation/doc-compiler/links.mjs +4 -2
  278. package/foundation/env/package-manager.d.mts +32 -0
  279. package/foundation/env/package-manager.mjs +47 -0
  280. package/foundation/env/package-manager.test.mjs +194 -7
  281. package/foundation/fs/module-loader.d.mts +2 -1
  282. package/foundation/fs/module-loader.mjs +60 -4
  283. package/foundation/fs/module-loader.test.mjs +194 -0
  284. package/foundation/integrations/contribution-inventory.mjs +6 -1
  285. package/foundation/response/response-types.doc.mjs +13 -7
  286. package/foundation/xle/registry.mjs +4 -0
  287. package/foundation/xle/registry.test.mjs +28 -0
  288. package/package.json +10 -10
  289. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,160 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx upgrade` with a CLI older than the installed Core: the human
5
+ * output never says the code is up to date, warns once with the same upgrade
6
+ * pinned to the CLI release that matches the Core, and keeps the exit status;
7
+ * `--json` carries the same facts in `cliBehindCore`. Pasted anywhere, the
8
+ * printed command runs that upgrade in the same project.
9
+ */
10
+
11
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
12
+ import {spawnSync} from 'node:child_process';
13
+ import * as fs from 'node:fs';
14
+ import * as os from 'node:os';
15
+ import * as path from 'node:path';
16
+ import {runCli} from '../../../test-utils/run-cli.mjs';
17
+ import {CLI_ROOT} from '../../../foundation/fs/paths.mjs';
18
+ import {
19
+ commandInFolder,
20
+ getDlxPrefix,
21
+ quoteCommandArgument,
22
+ } from '../../../foundation/env/package-manager.mjs';
23
+
24
+ const CLI_VERSION = JSON.parse(
25
+ fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf8'),
26
+ ).version;
27
+ const [MAJOR, MINOR] = CLI_VERSION.split('.').map(Number);
28
+ const NEWER_CORE = `${MAJOR}.${MINOR + 1}.0`;
29
+ const NON_ASCII = /[\u0080-\uFFFF]/;
30
+
31
+ let tmpDir;
32
+
33
+ /** @param {string} rel @param {string} body */
34
+ function write(rel, body) {
35
+ const file = path.join(tmpDir, rel);
36
+ fs.mkdirSync(path.dirname(file), {recursive: true});
37
+ fs.writeFileSync(file, body);
38
+ }
39
+
40
+ beforeEach(() => {
41
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-upgrade-older-cli-'));
42
+ write('package.json', JSON.stringify({name: 'consumer', private: true}));
43
+ write(
44
+ 'node_modules/@astryxdesign/core/package.json',
45
+ JSON.stringify({name: '@astryxdesign/core', version: NEWER_CORE}),
46
+ );
47
+ write('src/index.ts', 'export const x = 1;\n');
48
+ });
49
+
50
+ afterEach(() => {
51
+ fs.rmSync(tmpDir, {recursive: true, force: true});
52
+ });
53
+
54
+ /**
55
+ * The pinned command the CLI prints for this project. It names the folder the
56
+ * CLI ran in and the source directory as the CLI resolved them.
57
+ * @param {...string} rest the arguments after `--path <dir>`
58
+ */
59
+ function pinned(...rest) {
60
+ const project = fs.realpathSync(tmpDir);
61
+ return commandInFolder(
62
+ project,
63
+ [
64
+ getDlxPrefix(tmpDir),
65
+ `@astryxdesign/cli@${NEWER_CORE}`,
66
+ 'upgrade',
67
+ '--from',
68
+ CLI_VERSION,
69
+ '--path',
70
+ quoteCommandArgument(path.join(project, 'src')),
71
+ ...rest,
72
+ ].join(' '),
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Stand-ins for the package runners: each drops its own words and the pinned
78
+ * package, then runs this CLI with the rest of the command.
79
+ */
80
+ const RUNS_THIS_CLI = [
81
+ ['npx', 1],
82
+ ['bunx', 1],
83
+ ['pnpm', 2],
84
+ ['yarn', 2],
85
+ ]
86
+ .map(
87
+ ([name, words]) =>
88
+ `${name}() { shift ${words}; "$0" ${quoteCommandArgument(path.join(CLI_ROOT, 'clients', 'cli', 'bin', 'astryx.mjs'))} "$@"; }`,
89
+ )
90
+ .join('; ');
91
+
92
+ describe('astryx upgrade with a CLI older than the installed Core', () => {
93
+ it('says it cannot finish and prints the upgrade pinned to the matching CLI', async () => {
94
+ const r = await runCli(['upgrade', '--from', CLI_VERSION, '--apply'], {
95
+ cwd: tmpDir,
96
+ });
97
+ const output = `${r.stdout}\n${r.stderr}`;
98
+
99
+ expect(r.status).toBe(0);
100
+ expect(output).not.toMatch(/up to date/i);
101
+ expect(output).not.toContain('No codemods available');
102
+ expect(r.stderr).toContain(
103
+ `This CLI (${CLI_VERSION}) is older than the installed @astryxdesign/core (${NEWER_CORE})`,
104
+ );
105
+ // The command has a line of its own, so it copies exactly.
106
+ expect(r.stderr).toContain(
107
+ `the CLI that matches your Core:\n ${pinned('--apply')}\n`,
108
+ );
109
+ expect(r.stdout.trim().split('\n').at(-1)).toBe('Upgrade incomplete');
110
+ expect(output.split('\n').filter(line => NON_ASCII.test(line))).toEqual([]);
111
+ });
112
+
113
+ it('carries cliBehindCore in --json with the same exit status', async () => {
114
+ const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
115
+ cwd: tmpDir,
116
+ });
117
+ const parsed = JSON.parse(r.stdout);
118
+
119
+ expect(r.status).toBe(0);
120
+ expect(parsed.type).toBe('upgrade.status');
121
+ expect(parsed.data.status).toBe('no_codemods');
122
+ expect(parsed.data.cliBehindCore).toEqual({
123
+ cliVersion: CLI_VERSION,
124
+ command: pinned(),
125
+ });
126
+ });
127
+
128
+ // Where an upgrade runs decides what it finds: the installed Core is read
129
+ // from that folder, and --path must stay inside it. Printed without its
130
+ // folder, the command exited 1 when pasted in a subfolder
131
+ // (ERR_PATH_TRAVERSAL) or in the folder above (ERR_VERSION_DETECT).
132
+ it.skipIf(process.platform === 'win32')(
133
+ 'prints a command that upgrades the same project wherever it is pasted',
134
+ async () => {
135
+ write('src/deep/index.ts', 'export const y = 2;\n');
136
+ const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
137
+ cwd: tmpDir,
138
+ });
139
+ const {command} = JSON.parse(r.stdout).data.cliBehindCore;
140
+
141
+ for (const pastedIn of [
142
+ path.join(tmpDir, 'src', 'deep'),
143
+ path.dirname(tmpDir),
144
+ ]) {
145
+ const ran = spawnSync(
146
+ '/bin/sh',
147
+ ['-c', `${RUNS_THIS_CLI}; ${command}`, process.execPath],
148
+ {cwd: pastedIn, encoding: 'utf8'},
149
+ );
150
+
151
+ expect(ran.status, ran.stderr).toBe(0);
152
+ expect(ran.stdout).toContain(`Installed target: ${NEWER_CORE}`);
153
+ expect(ran.stdout).toContain(
154
+ `Scanning ${path.join(fs.realpathSync(tmpDir), 'src')} `,
155
+ );
156
+ }
157
+ },
158
+ 30_000,
159
+ );
160
+ });
@@ -26,7 +26,8 @@ import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
26
26
  import {installJsonShim} from './lib/json-shim.mjs';
27
27
  import {addDocHelp, markReportsResult} from './lib/define-command.mjs';
28
28
  import {doc as manifestDoc} from './commands/manifest.doc.mjs';
29
- import {isAstryxInitialized} from '../../foundation/agent-docs/agent-docs.mjs';
29
+ import {isAstryxInitialized, isAstryxPromptInReach} from '../../foundation/agent-docs/agent-docs.mjs';
30
+ import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
30
31
  import * as debug from '../../foundation/debug/index.mjs';
31
32
 
32
33
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -98,6 +99,7 @@ export const JSON_SUPPORTED = new Set([
98
99
  'theme targets',
99
100
  'theme palette generate',
100
101
  'integration add',
102
+ 'integration check',
101
103
  'integration verify',
102
104
  'integration pack',
103
105
  'upgrade',
@@ -276,6 +278,26 @@ const commands = [
276
278
  ];
277
279
 
278
280
  const SETUP_NUDGE_EXEMPT = new Set(['init', 'agent-docs']);
281
+
282
+ /**
283
+ * Is `cwd` inside the CLI's own source checkout while the CLI runs from it?
284
+ * An installed CLI always lives under `node_modules`; a CLI running from source
285
+ * does not, and its checkout is the pnpm workspace that holds it. Developing
286
+ * Astryx is not an app to set up, so the setup nudge stays quiet there.
287
+ * @param {string} cwd
288
+ * @returns {boolean}
289
+ */
290
+ function inOwnSourceCheckout(cwd) {
291
+ if (CLI_ROOT.split(path.sep).includes('node_modules')) return false;
292
+ let checkout = CLI_ROOT;
293
+ while (!fs.existsSync(path.join(checkout, 'pnpm-workspace.yaml'))) {
294
+ const parent = path.dirname(checkout);
295
+ if (parent === checkout) return false;
296
+ checkout = parent;
297
+ }
298
+ const rel = path.relative(checkout, path.resolve(cwd));
299
+ return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
300
+ }
279
301
  /** An integration package's manifest: the package is not an app to set up. */
280
302
  const INTEGRATION_MANIFEST_FILES = [
281
303
  'astryx.integration.ts',
@@ -527,8 +549,9 @@ export async function createProgram() {
527
549
 
528
550
  /**
529
551
  * Enforcement layer 3 — setup nudge. If this project hasn't run `astryx init`
530
- * yet (no Astryx marker in any agent-doc file — see isAstryxInitialized), remind
531
- * the user/agent that setup is missing.
552
+ * yet (no Astryx marker in any agent-doc file between the project and its
553
+ * repository root — see isAstryxPromptInReach), remind the user/agent that
554
+ * setup is missing.
532
555
  *
533
556
  * Uses `preAction` (not postAction) so it fires for EVERY valid command — even
534
557
  * ones whose action errors or calls process.exit (postAction is skipped then).
@@ -538,7 +561,8 @@ export async function createProgram() {
538
561
  * consumers parse stdout, not stderr — a stderr nudge would not reach them anyway.
539
562
  * The core/cli postinstall layers already nudge at install time regardless of
540
563
  * --json; a machine-readable nudge could later be an envelope field. Also skipped
541
- * for the installer commands themselves and outside a project (no package.json).
564
+ * for the installer commands themselves, outside a project (no package.json),
565
+ * and inside the CLI's own source checkout when it runs from there.
542
566
  */
543
567
  program.hook('preAction', (thisCommand, actionCommand) => {
544
568
  try {
@@ -548,7 +572,8 @@ export async function createProgram() {
548
572
  if (!fs.existsSync(path.join(cwd, 'package.json'))) return; // not a project
549
573
  // An integration package is not an app: `init` is not its next step.
550
574
  if (INTEGRATION_MANIFEST_FILES.some(file => fs.existsSync(path.join(cwd, file)))) return;
551
- if (isAstryxInitialized(cwd)) return; // already set up — stay quiet
575
+ if (inOwnSourceCheckout(cwd)) return; // developing Astryx itself, not an app
576
+ if (isAstryxPromptInReach(cwd)) return; // already set up — stay quiet
552
577
  // Same wording as the core/cli postinstall nudges. #4151's getCliInvocation()
553
578
  // renders the correct form for THIS project — scoped `npx @astryxdesign/cli`
554
579
  // one-off, or `<pm> astryx` when installed — never the bare `npx astryx` footgun.
@@ -68,8 +68,12 @@ function formatPropsTable(props) {
68
68
  for (const p of props) {
69
69
  const def = p.default ? `\`${mdCell(p.default)}\`` : '-';
70
70
  const req = p.required ? ' **(required)**' : '';
71
+ // The text projection of the prop doc's `stability` field: an
72
+ // experimental prop is outside the stable compatibility promise.
73
+ const stability =
74
+ p.stability === 'experimental' ? ' **(experimental)**' : '';
71
75
  lines.push(
72
- `| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
76
+ `| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req}${stability} |`,
73
77
  );
74
78
  }
75
79
  return lines.join('\n');
@@ -20,6 +20,20 @@ export function discoverAgentDocs(targetDir: string): string[];
20
20
  * @returns {boolean}
21
21
  */
22
22
  export function isAstryxInitialized(targetDir?: string): boolean;
23
+ /**
24
+ * Does an agent working in `startDir` already have the Astryx prompt in reach?
25
+ *
26
+ * Coding agents read the agent docs between the repository root and the folder
27
+ * they work in. So inside a git repository, init's block in any folder from
28
+ * `startDir` up to the repository root counts: a workspace package of a
29
+ * monorepo initialized at its root is set up. Outside a repository only
30
+ * `startDir` itself is checked, as {@link isAstryxInitialized} does. Both the
31
+ * per-command nudge and the postinstall nudges ask this.
32
+ *
33
+ * @param {string} [startDir=process.cwd()]
34
+ * @returns {boolean}
35
+ */
36
+ export function isAstryxPromptInReach(startDir?: string): boolean;
23
37
  /**
24
38
  * Pure decision: should a postinstall print the setup nudge? Shared by BOTH
25
39
  * postinstall layers, so the matrix cannot drift between them, and unit-testable
@@ -96,6 +96,44 @@ export function isAstryxInitialized(targetDir = process.cwd()) {
96
96
  return false;
97
97
  }
98
98
 
99
+ /**
100
+ * Does an agent working in `startDir` already have the Astryx prompt in reach?
101
+ *
102
+ * Coding agents read the agent docs between the repository root and the folder
103
+ * they work in. So inside a git repository, init's block in any folder from
104
+ * `startDir` up to the repository root counts: a workspace package of a
105
+ * monorepo initialized at its root is set up. Outside a repository only
106
+ * `startDir` itself is checked, as {@link isAstryxInitialized} does. Both the
107
+ * per-command nudge and the postinstall nudges ask this.
108
+ *
109
+ * @param {string} [startDir=process.cwd()]
110
+ * @returns {boolean}
111
+ */
112
+ export function isAstryxPromptInReach(startDir = process.cwd()) {
113
+ const start = path.resolve(startDir);
114
+ const repositoryRoot = findRepositoryRoot(start);
115
+ if (!repositoryRoot) return isAstryxInitialized(start);
116
+ for (let dir = start; ; dir = path.dirname(dir)) {
117
+ if (isAstryxInitialized(dir)) return true;
118
+ if (dir === repositoryRoot) return false;
119
+ }
120
+ }
121
+
122
+ /**
123
+ * The nearest folder at or above `start` that holds `.git` (a folder, or the
124
+ * file a worktree uses), or null outside a repository.
125
+ * @param {string} start
126
+ * @returns {string | null}
127
+ */
128
+ function findRepositoryRoot(start) {
129
+ for (let dir = start; ; ) {
130
+ if (fs.existsSync(path.join(dir, '.git'))) return dir;
131
+ const parent = path.dirname(dir);
132
+ if (parent === dir) return null;
133
+ dir = parent;
134
+ }
135
+ }
136
+
99
137
  /**
100
138
  * The one-line next-step both postinstall nudges print. Kept here so layer 1
101
139
  * (core) and layer 2 (cli) can never word it differently.
@@ -226,4 +226,5 @@ export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, on
226
226
  }): string[];
227
227
  import { discoverAgentDocs } from './agent-doc-state.mjs';
228
228
  import { isAstryxInitialized } from './agent-doc-state.mjs';
229
- export { discoverAgentDocs, isAstryxInitialized };
229
+ import { isAstryxPromptInReach } from './agent-doc-state.mjs';
230
+ export { discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach };
@@ -42,15 +42,17 @@ import {
42
42
  LEGACY_MARKER_END,
43
43
  discoverAgentDocs,
44
44
  isAstryxInitialized,
45
+ isAstryxPromptInReach,
45
46
  } from './agent-doc-state.mjs';
46
47
 
47
48
  // The agent-doc locations, markers, and the setup-state predicates
48
- // (discoverAgentDocs, isAstryxInitialized) are the ONE canonical contract. They
49
- // live in the dependency-free leaf ./agent-doc-state.mjs so the postinstall
50
- // nudge (enforcement layer 2) can load them safely at install time. Re-exported
51
- // here so existing importers (init/upgrade commands, the layer-3 nudge in
52
- // clients/cli/index.mjs, tests) keep their `from './agent-docs.mjs'` paths.
53
- export {discoverAgentDocs, isAstryxInitialized};
49
+ // (discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach) are the ONE
50
+ // canonical contract. They live in the dependency-free leaf
51
+ // ./agent-doc-state.mjs so the postinstall nudge (enforcement layer 2) can load
52
+ // them safely at install time. Re-exported here so existing importers
53
+ // (init/upgrade commands, the layer-3 nudge in clients/cli/index.mjs, tests)
54
+ // keep their `from './agent-docs.mjs'` paths.
55
+ export {discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach};
54
56
 
55
57
  const MAX_PROJECT_AGENT_DOC_LINES = 32;
56
58
  const MANAGED_MARKER_TEXT = /(?:ASTRYX|XDS):(START|END)/u;
@@ -60,6 +60,7 @@ import {
60
60
  applyTemplateReplacements,
61
61
  effectiveTemplateDiscovery,
62
62
  discoverAllUnresolved as discoverTemplates,
63
+ discoverCoreTemplates,
63
64
  discoverIntegrationTemplatesForOne,
64
65
  } from '../discovery/template-adapter.mjs';
65
66
  import {
@@ -821,6 +822,85 @@ export class Project {
821
822
  });
822
823
  }
823
824
 
825
+ /**
826
+ * The components and templates this project reads, as links name them: by
827
+ * owner provider id, kind, and name (a template by its id).
828
+ * @returns {Promise<import('../discovery/docs-discovery.mjs').LinkableContributions>}
829
+ */
830
+ async #linkableContributions() {
831
+ /** @type {Map<string, string>} */
832
+ const providers = new Map([[CORE_PACKAGE, CORE_PACKAGE]]);
833
+ for (const integration of this.#loadedIntegrations) {
834
+ if (integration?.name) {
835
+ providers.set(
836
+ integration.name,
837
+ integration.providerId ?? integration.name,
838
+ );
839
+ }
840
+ }
841
+ const providerOf = (/** @type {string | undefined} */ pkg) =>
842
+ providers.get(pkg ?? CORE_PACKAGE) ?? pkg ?? CORE_PACKAGE;
843
+ // An active replacement answers to the Core name it replaces, so a link
844
+ // to that Core component has to select Core (spec:AST-035 FR11).
845
+ /** @type {Map<string, string>} */
846
+ const replacing = new Map();
847
+ if (this.#loadedIntegrations.length > 0) {
848
+ const {active} = await resolveComponentReplacements(
849
+ findCoreDir(this.#cwd),
850
+ this.#loadedIntegrations,
851
+ );
852
+ for (const each of active) {
853
+ replacing.set(`${each.package}\0${each.name}`, each.target);
854
+ }
855
+ }
856
+ const components = (await this.components()).map(record => {
857
+ const replaces = replacing.get(`${record.package}\0${record.name}`);
858
+ return {
859
+ providerId: providerOf(record.package),
860
+ package: record.package,
861
+ name: record.name,
862
+ docPath: record.docPath,
863
+ ...(replaces == null ? {} : {replaces}),
864
+ };
865
+ });
866
+ /** @param {any} template @param {string} pkg */
867
+ const linkable = (template, pkg) => ({
868
+ providerId: providerOf(pkg),
869
+ package: pkg,
870
+ type: template.type,
871
+ id: template.dirName,
872
+ name: template.name,
873
+ ...(template.displayName == null
874
+ ? {}
875
+ : {displayName: template.displayName}),
876
+ ...(template.description == null
877
+ ? {}
878
+ : {description: template.description}),
879
+ ...(typeof template.replaces === 'string'
880
+ ? {replaces: template.replaces}
881
+ : {}),
882
+ });
883
+ /** @param {any} template */
884
+ const isPageOrBlock = template =>
885
+ template.type === 'page' || template.type === 'block';
886
+ // Every Core template, a replaced one too, since `--package
887
+ // @astryxdesign/core` still opens it; everyone else's as unqualified
888
+ // lookups see them, an active replacement with the id it takes over.
889
+ const templates = [
890
+ ...(await discoverCoreTemplates())
891
+ .filter(isPageOrBlock)
892
+ .map(template => linkable(template, CORE_PACKAGE)),
893
+ .../** @type {any[]} */ (await this.templates())
894
+ .filter(
895
+ template =>
896
+ isPageOrBlock(template) &&
897
+ (template.package ?? CORE_PACKAGE) !== CORE_PACKAGE,
898
+ )
899
+ .map(template => linkable(template, template.package)),
900
+ ];
901
+ return {components, templates};
902
+ }
903
+
824
904
  /**
825
905
  * The CLI's own doc topics plus the ones the configured integrations
826
906
  * contribute, resolved into one catalog: additions, replacements (with the
@@ -838,6 +918,8 @@ export class Project {
838
918
  async docs() {
839
919
  return this.#memo('docs', async () => {
840
920
  const catalog = DocsCatalog.fromBuiltins();
921
+ // Links name component, page, and block docs too (spec:AST-047 FR9).
922
+ catalog.setContributions(() => this.#linkableContributions());
841
923
  let rank = 0;
842
924
 
843
925
  for (const integration of this.#loadedIntegrations) {
@@ -46,6 +46,7 @@ export const AUTHORING_SELF_DOCS = [
46
46
  'doctypes/reference/reference.doc.mjs',
47
47
  'doctypes/schema/schema.doc.mjs',
48
48
  'doctypes/template/template.doc.mjs',
49
+ 'doctypes/template/integration-template.doc.mjs',
49
50
  'doctypes/theme/theme.doc.mjs',
50
51
  ];
51
52
 
@@ -192,7 +193,7 @@ export function buildAuthoringReferenceDoc(docs) {
192
193
  title: 'Authoring Reference',
193
194
  category: 'guide',
194
195
  description:
195
- 'Every file an integration author writes, field by field: the integration manifest, astryx.config, codemods, identity, and each doc type.',
196
+ 'Every file an integration author writes, field by field: the integration manifest, astryx.config, codemods, identity, and each doc type. The step-by-step guides are under `astryx docs cli/integrations`.',
196
197
  sections: docs.map(selfDocSection),
197
198
  });
198
199
  }