@astryxdesign/cli 0.7.2-canary.7462c41 → 0.7.2-canary.7ae39ea

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 (111) hide show
  1. package/README.md +6 -6
  2. package/api/doctor/doctor.mjs +27 -3
  3. package/api/doctor/doctor.test.mjs +43 -0
  4. package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
  5. package/api/integration/validateIntegration.doc.mjs +3 -1
  6. package/api/search/search.d.mts +59 -6
  7. package/api/search/search.domain-priority.test.mjs +15 -0
  8. package/api/search/search.mjs +468 -28
  9. package/api/search/search.test.mjs +139 -0
  10. package/assets/docs/styling-overview.doc.mjs +1 -1
  11. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  12. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  13. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  14. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  15. package/assets/docs/tree/block-template.doc.mjs +6 -18
  16. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  17. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  18. package/assets/docs/tree/check-your-docs.doc.mjs +10 -5
  19. package/assets/docs/tree/checks.doc.mjs +3 -3
  20. package/assets/docs/tree/codemods.doc.mjs +4 -4
  21. package/assets/docs/tree/component-family.doc.mjs +3 -5
  22. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  23. package/assets/docs/tree/components.doc.mjs +1 -1
  24. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
  25. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  26. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  27. package/assets/docs/tree/docs.doc.mjs +3 -3
  28. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  29. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  30. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  31. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  32. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  33. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  34. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  35. package/assets/docs/tree/integrations.doc.mjs +4 -0
  36. package/assets/docs/tree/links.doc.mjs +5 -4
  37. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  38. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  39. package/assets/docs/tree/migration.doc.mjs +0 -1
  40. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  41. package/assets/docs/tree/page-template.doc.mjs +3 -7
  42. package/assets/docs/tree/publishing.doc.mjs +1 -1
  43. package/assets/docs/tree/quick-start.doc.mjs +7 -19
  44. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  45. package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
  46. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  47. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  48. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  49. package/assets/docs/tree/single-component.doc.mjs +12 -4
  50. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  51. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  52. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  53. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  54. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  55. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  56. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  57. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  58. package/assets/docs/tree/templates.doc.mjs +1 -1
  59. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  60. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  61. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  62. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  63. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  64. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  65. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  66. package/assets/docs/tree/versioning.doc.mjs +6 -6
  67. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
  68. package/authoring/codemod/codemod.doc.mjs +7 -3
  69. package/authoring/config/config.doc.mjs +9 -6
  70. package/authoring/config/type.ts +4 -2
  71. package/authoring/discover/discover.doc.mjs +1 -1
  72. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  73. package/authoring/doctypes/command/command.doc.mjs +14 -12
  74. package/authoring/doctypes/component/component.doc.mjs +28 -25
  75. package/authoring/doctypes/component/type.ts +7 -5
  76. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  77. package/authoring/doctypes/function/function.doc.mjs +9 -8
  78. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  79. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  80. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  81. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  82. package/authoring/doctypes/template/template.doc.mjs +2 -2
  83. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  84. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  85. package/authoring/identity/identity.doc.mjs +3 -3
  86. package/authoring/integration/integration.doc.mjs +4 -3
  87. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  88. package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
  89. package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
  90. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  91. package/clients/cli/commands/swizzle.mjs +5 -3
  92. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  93. package/clients/cli/index.mjs +29 -5
  94. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  95. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  96. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  97. package/foundation/agent-docs/agent-docs.mjs +8 -6
  98. package/foundation/discovery/authoring-self-docs.mjs +1 -1
  99. package/foundation/discovery/doc-types.d.mts +1 -1
  100. package/foundation/discovery/doc-types.mjs +3 -3
  101. package/foundation/discovery/doc-types.test.mjs +48 -0
  102. package/foundation/discovery/project-typescript.d.mts +11 -2
  103. package/foundation/discovery/project-typescript.mjs +32 -4
  104. package/foundation/discovery/prop-drift.d.mts +1 -1
  105. package/foundation/discovery/prop-drift.mjs +2 -2
  106. package/foundation/discovery/prop-drift.test.mjs +55 -2
  107. package/foundation/discovery/type-text.mjs +1 -1
  108. package/foundation/discovery/type-text.test.mjs +1 -1
  109. package/foundation/doc-compiler/doc-loads.test.mjs +6 -2
  110. package/package.json +9 -9
  111. package/scripts/postinstall.mjs +3 -3
@@ -8,9 +8,16 @@
8
8
  * transient fetch (path _npx or npm_command=exec), and once set up.
9
9
  */
10
10
 
11
- import {describe, it, expect} from 'vitest';
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 {fileURLToPath} from 'node:url';
12
17
  import {shouldNudge} from '../../../scripts/postinstall.mjs';
13
18
 
19
+ const CLI = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
20
+
14
21
  const DEP = '/proj/node_modules/@astryxdesign/cli/scripts/postinstall.mjs'; // real dep install
15
22
  const NPX = '/Users/x/.npm/_npx/a1b2/node_modules/@astryxdesign/cli/scripts/postinstall.mjs';
16
23
  const REPO = '/repo/packages/cli/scripts/postinstall.mjs'; // monorepo/source
@@ -40,3 +47,44 @@ describe('cli postinstall — shouldNudge', () => {
40
47
  expect(shouldNudge({})).toBe(false);
41
48
  });
42
49
  });
50
+
51
+ // Install time, end to end: the real script and the leaf it loads, installed
52
+ // under a monorepo's node_modules, run the way npm runs them for a package.
53
+ describe('cli postinstall — inside a monorepo package', () => {
54
+ let repo;
55
+ beforeEach(() => {
56
+ repo = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-cli-postinstall-'));
57
+ fs.mkdirSync(path.join(repo, '.git'));
58
+ fs.mkdirSync(path.join(repo, 'packages/app'), {recursive: true});
59
+ fs.writeFileSync(path.join(repo, 'packages/app/package.json'), '{"name":"app"}');
60
+ const installed = path.join(repo, 'node_modules/@astryxdesign/cli');
61
+ for (const rel of ['scripts/postinstall.mjs', 'foundation/agent-docs/agent-doc-state.mjs']) {
62
+ fs.mkdirSync(path.dirname(path.join(installed, rel)), {recursive: true});
63
+ fs.copyFileSync(path.join(CLI, rel), path.join(installed, rel));
64
+ }
65
+ });
66
+ afterEach(() => fs.rmSync(repo, {recursive: true, force: true}));
67
+
68
+ const install = () =>
69
+ spawnSync(
70
+ process.execPath,
71
+ [path.join(repo, 'node_modules/@astryxdesign/cli/scripts/postinstall.mjs')],
72
+ {
73
+ env: {...process.env, INIT_CWD: path.join(repo, 'packages/app'), npm_command: 'install'},
74
+ encoding: 'utf8',
75
+ },
76
+ );
77
+
78
+ it('stays quiet when init ran at the repository root', () => {
79
+ fs.writeFileSync(path.join(repo, 'AGENTS.md'), '<!-- ASTRYX:START -->\n');
80
+ const r = install();
81
+ expect(r.status).toBe(0);
82
+ expect(r.stdout).toBe('');
83
+ });
84
+
85
+ it('still nudges when no folder up to the repository root ran init', () => {
86
+ const r = install();
87
+ expect(r.status).toBe(0);
88
+ expect(r.stdout).toMatch(/finish setup and install the Astryx agent prompt/);
89
+ });
90
+ });
@@ -20,7 +20,9 @@ export const doc = {
20
20
  'Core component is an error. In a package without that range they are warnings, ' +
21
21
  'with a warning for each such component, naming the range to declare. ' +
22
22
  "Then it compares each component doc's props with the component's TypeScript " +
23
- "props, using the project's own `typescript`, and warns about a documented prop " +
23
+ "props, using the project's own `typescript` (or, where `typescript` is missing or " +
24
+ 'has no JavaScript compiler API, as TypeScript 7 does, the `@typescript/typescript6` ' +
25
+ 'it installs), and warns about a documented prop ' +
24
26
  'the code lacks, a prop the package declares that the doc omits, a wrong ' +
25
27
  '`required`, and a type that does not match where both sides read exactly ' +
26
28
  '(it lists every other documented type as not compared, with the reason). ' +
@@ -16,7 +16,9 @@ export const doc = {
16
16
  'installed package resolved by name. It schema-checks the manifest, verifies ' +
17
17
  'every declared contribution root, and reports every finding. Safe as a CI gate. ' +
18
18
  'It then checks every doc the package ships under its roots against the ' +
19
- "published authoring type for its kind, with the project's own `typescript`, and " +
19
+ "published authoring type for its kind, with the project's own `typescript` (or, " +
20
+ 'where `typescript` is missing or has no JavaScript compiler API, as TypeScript 7 ' +
21
+ 'does, the `@typescript/typescript6` it installs), and ' +
20
22
  'warns about each field that does not match, naming the field and a fix. A doc ' +
21
23
  'it cannot fully check is listed with the reason, and test fixtures under ' +
22
24
  '`__tests__` in the components or docs root are counted, not checked. Without ' +
@@ -16,9 +16,24 @@ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
16
16
  import * as fs from 'node:fs';
17
17
  import * as path from 'node:path';
18
18
  import * as os from 'node:os';
19
- import {isAstryxInitialized} from '../../../foundation/agent-docs/agent-docs.mjs';
19
+ import {fileURLToPath} from 'node:url';
20
+ import {
21
+ isAstryxInitialized,
22
+ isAstryxPromptInReach,
23
+ } from '../../../foundation/agent-docs/agent-docs.mjs';
20
24
  import {runCli} from '../../../test-utils/run-cli.mjs';
21
25
 
26
+ /** This source checkout: the tests run the CLI from it. */
27
+ const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../..');
28
+
29
+ /** Is `dir` inside a git repository? The temp folder normally is not. */
30
+ function insideRepository(dir) {
31
+ for (let d = path.resolve(dir); ; d = path.dirname(d)) {
32
+ if (fs.existsSync(path.join(d, '.git'))) return true;
33
+ if (path.dirname(d) === d) return false;
34
+ }
35
+ }
36
+
22
37
  const MARKER = '<!-- ASTRYX:START -->';
23
38
  const NUDGE = /finish setup and install the Astryx agent prompt/;
24
39
 
@@ -61,6 +76,41 @@ describe('isAstryxInitialized — centralized setup check (one place)', () => {
61
76
  });
62
77
  });
63
78
 
79
+ // Agents read the agent docs between the repository root and the folder they
80
+ // work in, so a monorepo initialized at its root is set up in every package.
81
+ describe('isAstryxPromptInReach — up to the repository root', () => {
82
+ it('finds init\'s block at the repository root from a workspace package', () => {
83
+ fs.mkdirSync(path.join(tmp, '.git'));
84
+ write('AGENTS.md', MARKER);
85
+ write('packages/app/package.json', '{"name":"app"}');
86
+ expect(isAstryxPromptInReach(path.join(tmp, 'packages/app'))).toBe(true);
87
+ });
88
+
89
+ it('treats a worktree .git file as the repository root', () => {
90
+ write('.git', 'gitdir: /elsewhere\n');
91
+ write('CLAUDE.md', MARKER);
92
+ write('packages/app/package.json', '{"name":"app"}');
93
+ expect(isAstryxPromptInReach(path.join(tmp, 'packages/app'))).toBe(true);
94
+ });
95
+
96
+ it('does not look above the repository root', () => {
97
+ write('AGENTS.md', MARKER);
98
+ fs.mkdirSync(path.join(tmp, 'repo/.git'), {recursive: true});
99
+ write('repo/pkg/package.json', '{"name":"pkg"}');
100
+ expect(isAstryxPromptInReach(path.join(tmp, 'repo/pkg'))).toBe(false);
101
+ });
102
+
103
+ it.skipIf(insideRepository(os.tmpdir()))(
104
+ 'checks only the folder itself outside a repository',
105
+ () => {
106
+ write('AGENTS.md', MARKER);
107
+ write('pkg/package.json', '{"name":"pkg"}');
108
+ expect(isAstryxPromptInReach(tmp)).toBe(true);
109
+ expect(isAstryxPromptInReach(path.join(tmp, 'pkg'))).toBe(false);
110
+ },
111
+ );
112
+ });
113
+
64
114
  describe('enforcement layer 3 — per-command setup nudge', () => {
65
115
  const asProject = () => write('package.json', '{"name":"t"}');
66
116
 
@@ -99,4 +149,32 @@ describe('enforcement layer 3 — per-command setup nudge', () => {
99
149
  asProject();
100
150
  expect((await runCli(['init'], tmp)).stderr).not.toMatch(NUDGE);
101
151
  });
152
+
153
+ it('is quiet in a workspace package when init\'s block is at the repository root', async () => {
154
+ fs.mkdirSync(path.join(tmp, '.git'));
155
+ write('AGENTS.md', MARKER);
156
+ write('packages/app/package.json', '{"name":"app"}');
157
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'packages/app'));
158
+ expect(r.stderr).not.toMatch(NUDGE);
159
+ });
160
+
161
+ it('still nudges in a workspace package with no block up to the repository root', async () => {
162
+ fs.mkdirSync(path.join(tmp, '.git'));
163
+ write('AGENTS.md', 'project notes, no astryx block');
164
+ write('packages/app/package.json', '{"name":"app"}');
165
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'packages/app'));
166
+ expect(r.stderr).toMatch(NUDGE);
167
+ });
168
+
169
+ // The tests run the CLI from this checkout, so a project inside it is the
170
+ // contributor flow. The same project in the temp folder nudges (above).
171
+ it('is quiet inside the source checkout the CLI runs from', async () => {
172
+ const inside = fs.mkdtempSync(path.join(REPO, '.astryx-setup-nudge-'));
173
+ try {
174
+ fs.writeFileSync(path.join(inside, 'package.json'), '{"name":"t"}');
175
+ expect((await runCli(['docs', 'tokens'], inside)).stderr).not.toMatch(NUDGE);
176
+ } finally {
177
+ fs.rmSync(inside, {recursive: true, force: true});
178
+ }
179
+ });
102
180
  });
@@ -91,14 +91,16 @@ export function registerSwizzle(program) {
91
91
  ),
92
92
  ];
93
93
 
94
- // StyleX build requirement — swizzled StyleX source renders unstyled with
95
- // no error unless the consumer's build runs a StyleX compiler.
94
+ // StyleX build requirement — swizzled StyleX source throws on import
95
+ // ("Unexpected 'stylex.create' call at runtime") unless the consumer's
96
+ // build runs a StyleX compiler, so the page does not render at all.
96
97
  if (usesStyleX) {
97
98
  out.push(
98
99
  text(
99
100
  [
100
101
  `${WARN} These components use StyleX and require a StyleX compiler in your build.`,
101
- ' Without one they render unstyled (no error). See setup per framework:',
102
+ ` Without one, importing them throws "Unexpected 'stylex.create' call at runtime"`,
103
+ ' and the page does not render. See setup per framework:',
102
104
  ` ${run} docs styling`,
103
105
  ' Next.js note: the StyleX Babel plugin disables SWC and breaks next/font -',
104
106
  ' use an SWC-based StyleX transform instead (covered in the guide).',
@@ -15,8 +15,16 @@ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
15
15
  import * as fs from 'node:fs';
16
16
  import * as path from 'node:path';
17
17
  import * as os from 'node:os';
18
+ import {createRequire} from 'node:module';
19
+ import {fileURLToPath} from 'node:url';
18
20
  import {runCli} from '../../../test-utils/run-cli.mjs';
19
21
 
22
+ /** The StyleX runtime that Core ships with, resolved the way Core resolves it. */
23
+ const CORE_PACKAGE = path.resolve(
24
+ path.dirname(fileURLToPath(import.meta.url)),
25
+ '../../../../core/package.json',
26
+ );
27
+
20
28
  /**
21
29
  * Build a fake @astryxdesign/core under <project>/node_modules with a single
22
30
  * swizzleable Button component (bare `Button.tsx`, no doc).
@@ -303,12 +311,21 @@ describe('swizzle — StyleX build setup note (#3373)', () => {
303
311
  const humanResult = await runCli(['swizzle', 'Styled', '-f'], project);
304
312
  expect(humanResult.code).toBe(0);
305
313
  expect(humanResult.stdout).toMatch(/StyleX compiler/i);
306
- expect(humanResult.stdout).toMatch(/unstyled/i);
314
+ expect(humanResult.stdout).toMatch(/importing them throws "Unexpected 'stylex\.create' call at runtime"/);
315
+ expect(humanResult.stdout).not.toMatch(/unstyled/i);
307
316
  expect(humanResult.stdout).toMatch(/next\/font/i);
308
317
  // The fixture has no `astryx` bin installed, so the note names the scoped package.
309
318
  expect(humanResult.stdout).toMatch(/@astryxdesign\/cli docs styling/);
310
319
  });
311
320
 
321
+ // The note quotes what StyleX does without a compiler; this keeps it true.
322
+ it('matches what the StyleX runtime does when styles are not compiled', () => {
323
+ const stylex = createRequire(CORE_PACKAGE)('@stylexjs/stylex');
324
+ expect(() => stylex.create({root: {color: 'red'}})).toThrow(
325
+ /Unexpected 'stylex\.create' call at runtime/,
326
+ );
327
+ });
328
+
312
329
  it('does not print the StyleX note for components without StyleX', async () => {
313
330
  buildStyleXCore(project);
314
331
  writeProjectPackageJson(project);
@@ -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));
@@ -277,6 +278,26 @@ const commands = [
277
278
  ];
278
279
 
279
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
+ }
280
301
  /** An integration package's manifest: the package is not an app to set up. */
281
302
  const INTEGRATION_MANIFEST_FILES = [
282
303
  'astryx.integration.ts',
@@ -528,8 +549,9 @@ export async function createProgram() {
528
549
 
529
550
  /**
530
551
  * Enforcement layer 3 — setup nudge. If this project hasn't run `astryx init`
531
- * yet (no Astryx marker in any agent-doc file — see isAstryxInitialized), remind
532
- * 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.
533
555
  *
534
556
  * Uses `preAction` (not postAction) so it fires for EVERY valid command — even
535
557
  * ones whose action errors or calls process.exit (postAction is skipped then).
@@ -539,7 +561,8 @@ export async function createProgram() {
539
561
  * consumers parse stdout, not stderr — a stderr nudge would not reach them anyway.
540
562
  * The core/cli postinstall layers already nudge at install time regardless of
541
563
  * --json; a machine-readable nudge could later be an envelope field. Also skipped
542
- * 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.
543
566
  */
544
567
  program.hook('preAction', (thisCommand, actionCommand) => {
545
568
  try {
@@ -549,7 +572,8 @@ export async function createProgram() {
549
572
  if (!fs.existsSync(path.join(cwd, 'package.json'))) return; // not a project
550
573
  // An integration package is not an app: `init` is not its next step.
551
574
  if (INTEGRATION_MANIFEST_FILES.some(file => fs.existsSync(path.join(cwd, file)))) return;
552
- 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
553
577
  // Same wording as the core/cli postinstall nudges. #4151's getCliInvocation()
554
578
  // renders the correct form for THIS project — scoped `npx @astryxdesign/cli`
555
579
  // one-off, or `<pm> astryx` when installed — never the bare `npx astryx` footgun.
@@ -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;
@@ -193,7 +193,7 @@ export function buildAuthoringReferenceDoc(docs) {
193
193
  title: 'Authoring Reference',
194
194
  category: 'guide',
195
195
  description:
196
- '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`.',
197
197
  sections: docs.map(selfDocSection),
198
198
  });
199
199
  }
@@ -54,7 +54,7 @@ export function checkDocTypes(files: DocFile[], options: {
54
54
  * or not fully checked
55
55
  */
56
56
  /** The line both surfaces print when the compiler is missing. */
57
- export const DOC_TYPES_TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so docs were not checked against the authoring types. Install typescript and run this check again.";
57
+ export const DOC_TYPES_TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so docs were not checked against the authoring types. On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
58
58
  export type DocRoot = "components" | "hooks" | "templates" | "docs" | "docs-overlay" | "themes";
59
59
  export type DocFile = {
60
60
  /**
@@ -41,6 +41,7 @@ import * as path from 'node:path';
41
41
  import {fileURLToPath} from 'node:url';
42
42
  import {
43
43
  resolveProjectTypeScript,
44
+ TYPESCRIPT_FIX,
44
45
  unusableTypeScriptReason,
45
46
  } from './project-typescript.mjs';
46
47
 
@@ -91,8 +92,7 @@ import {
91
92
  */
92
93
 
93
94
  /** The line both surfaces print when the compiler is missing. */
94
- export const DOC_TYPES_TYPESCRIPT_MISSING_REASON =
95
- 'TypeScript is not installed in this project, so docs were not checked against the authoring types. Install typescript and run this check again.';
95
+ export const DOC_TYPES_TYPESCRIPT_MISSING_REASON = `TypeScript is not installed in this project, so docs were not checked against the authoring types. ${TYPESCRIPT_FIX}`;
96
96
 
97
97
  const AUTHORING = '@astryxdesign/cli/authoring';
98
98
  const AUTHORING_TYPES = path.resolve(
@@ -933,7 +933,7 @@ export async function checkDocTypes(files, options) {
933
933
  if (major < needMajor || (major === needMajor && minor < needMinor)) {
934
934
  return {
935
935
  status: 'skipped',
936
- reason: `TypeScript ${version} cannot check ${hasJs ? 'a JavaScript doc' : 'a doc'} against its type (that needs TypeScript ${needMajor}.${needMinor} or later), so docs were not checked. Upgrade typescript and run this check again.`,
936
+ reason: `TypeScript ${version} cannot check ${hasJs ? 'a JavaScript doc' : 'a doc'} against its type (that needs TypeScript ${needMajor}.${needMinor} or later), so docs were not checked. ${TYPESCRIPT_FIX}`,
937
937
  docs: 0,
938
938
  findings: [],
939
939
  unchecked: [],
@@ -40,6 +40,37 @@ function withTypeScript() {
40
40
  );
41
41
  }
42
42
 
43
+ /**
44
+ * TypeScript 7 (no JavaScript compiler API) with the TypeScript 6 API package
45
+ * beside it, which re-exports a real TypeScript.
46
+ */
47
+ function withTypeScript7AndItsTypeScript6Api() {
48
+ const ts7 = path.join(pkg, 'node_modules', 'typescript');
49
+ fs.mkdirSync(ts7, {recursive: true});
50
+ fs.writeFileSync(
51
+ path.join(ts7, 'package.json'),
52
+ JSON.stringify({
53
+ name: 'typescript',
54
+ version: '7.0.2',
55
+ exports: {'./package.json': './package.json'},
56
+ }),
57
+ );
58
+ const ts6 = path.join(pkg, 'node_modules', '@typescript', 'typescript6');
59
+ fs.mkdirSync(ts6, {recursive: true});
60
+ fs.writeFileSync(
61
+ path.join(ts6, 'package.json'),
62
+ JSON.stringify({
63
+ name: '@typescript/typescript6',
64
+ version: '6.0.2',
65
+ main: 'index.js',
66
+ }),
67
+ );
68
+ fs.writeFileSync(
69
+ path.join(ts6, 'index.js'),
70
+ `module.exports = require(${JSON.stringify(TYPESCRIPT_DIR)});\n`,
71
+ );
72
+ }
73
+
43
74
  /**
44
75
  * @param {string} rel
45
76
  * @param {string} text
@@ -117,6 +148,10 @@ describe('checkDocTypes', () => {
117
148
 
118
149
  const report = await check([['components/Badge.doc.mjs', 'components']]);
119
150
 
151
+ // The reason names the version and the fix, so a --strict failure
152
+ // says what to install.
153
+ expect(report.reason).toContain('TypeScript 7.0.0');
154
+ expect(report.reason).toContain('npm install -D @typescript/typescript6');
120
155
  expect(report).toEqual({
121
156
  status: 'skipped',
122
157
  reason: unusableTypeScriptReason('7.0.0', 'docs were not checked'),
@@ -128,6 +163,19 @@ describe('checkDocTypes', () => {
128
163
  }
129
164
  });
130
165
 
166
+ it("checks with TypeScript 7's TypeScript 6 API package when the project has one", async () => {
167
+ write(
168
+ 'components/Badge.doc.mjs',
169
+ `export default ${JSON.stringify(COMPONENT)};\n`,
170
+ );
171
+ withTypeScript7AndItsTypeScript6Api();
172
+
173
+ const report = await check([['components/Badge.doc.mjs', 'components']]);
174
+
175
+ expect(report.status).toBe('checked');
176
+ expect(report.docs).toBe(1);
177
+ });
178
+
131
179
  it('says there is nothing to check when the package has no doc files, with or without TypeScript', async () => {
132
180
  const without = await check([]);
133
181
  withTypeScript();
@@ -2,7 +2,9 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * Resolve the project's own `typescript`, trying each directory in order.
5
+ * Resolve the project's own `typescript`, trying each directory in order;
6
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
7
+ * API package installed beside it.
6
8
  * @param {Array<string | null | undefined>} dirs
7
9
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
8
10
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -16,8 +18,15 @@ export function resolveProjectTypeScript(dirs: Array<string | null | undefined>)
16
18
  } | null;
17
19
  /**
18
20
  * Why a check that needs the compiler did not run, when the TypeScript
19
- * installed has no JavaScript compiler API.
21
+ * installed has no JavaScript compiler API, and what to do.
20
22
  * @param {string} version
21
23
  * @param {string} outcome what was not done, such as `docs were not checked`
22
24
  */
23
25
  export function unusableTypeScriptReason(version: string, outcome: string): string;
26
+ /**
27
+ * What to do when the project's TypeScript is missing or cannot be used:
28
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
29
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
30
+ * JavaScript doc) through 6.
31
+ */
32
+ export const TYPESCRIPT_FIX: "On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
@@ -15,7 +15,16 @@ import * as path from 'node:path';
15
15
  import {createRequire} from 'node:module';
16
16
 
17
17
  /**
18
- * Resolve the project's own `typescript`, trying each directory in order.
18
+ * The package TypeScript publishes beside TypeScript 7 for tools that need a
19
+ * JavaScript compiler API: TypeScript 6's. Kept in a constant so the type
20
+ * check does not treat the load as a static import of an uninstalled package.
21
+ */
22
+ const TYPESCRIPT_6_API = '@typescript/typescript6';
23
+
24
+ /**
25
+ * Resolve the project's own `typescript`, trying each directory in order;
26
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
27
+ * API package installed beside it.
19
28
  * @param {Array<string | null | undefined>} dirs
20
29
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
21
30
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -43,19 +52,38 @@ export function resolveProjectTypeScript(dirs) {
43
52
  unusable ??= installed();
44
53
  } catch {
45
54
  // Not installed from here, or installed without an entry this CLI can
46
- // load; try the next directory.
55
+ // load.
47
56
  unusable ??= installed();
48
57
  }
58
+ // TypeScript 7 has no JavaScript compiler API; the package TypeScript
59
+ // ships beside it for tools that need one carries TypeScript 6's.
60
+ try {
61
+ const ts = require(TYPESCRIPT_6_API);
62
+ if (ts && typeof ts.createProgram === 'function') {
63
+ return {ts, version: String(ts.version)};
64
+ }
65
+ } catch {
66
+ // Not installed from here; try the next directory.
67
+ }
49
68
  }
50
69
  return unusable ? {ts: null, version: unusable} : null;
51
70
  }
52
71
 
72
+ /**
73
+ * What to do when the project's TypeScript is missing or cannot be used:
74
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
75
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
76
+ * JavaScript doc) through 6.
77
+ */
78
+ export const TYPESCRIPT_FIX =
79
+ 'On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.';
80
+
53
81
  /**
54
82
  * Why a check that needs the compiler did not run, when the TypeScript
55
- * installed has no JavaScript compiler API.
83
+ * installed has no JavaScript compiler API, and what to do.
56
84
  * @param {string} version
57
85
  * @param {string} outcome what was not done, such as `docs were not checked`
58
86
  */
59
87
  export function unusableTypeScriptReason(version, outcome) {
60
- return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with, so ${outcome}.`;
88
+ return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with (TypeScript 7 ships none), so ${outcome}. ${TYPESCRIPT_FIX}`;
61
89
  }
@@ -96,7 +96,7 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
96
96
  */
97
97
  export const PROPS_NOT_DOCUMENTED: readonly string[];
98
98
  /** The line both surfaces print when the compiler is missing. */
99
- export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. Install typescript and run this check again.";
99
+ export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
100
100
  export type CodeProp = {
101
101
  name: string;
102
102
  /**