@astryxdesign/cli 0.7.3-canary.cde6233 → 0.7.3-canary.d421aed

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 (47) hide show
  1. package/api/build/_adapter.mjs +37 -25
  2. package/api/build/blocks/blocks.d.mts +68 -20
  3. package/api/build/blocks/blocks.mjs +472 -196
  4. package/api/build/blocks/blocks.test.mjs +185 -168
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/build.type.mjs +1 -1
  7. package/api/build/kit/answer.d.mts +4 -1
  8. package/api/build/kit/answer.mjs +11 -3
  9. package/api/build/kit/signals.d.mts +11 -0
  10. package/api/build/kit/signals.mjs +8 -7
  11. package/api/build/tree.mjs +2 -1
  12. package/api/build/tree.test.mjs +27 -27
  13. package/api/component/_adapter.mjs +39 -5
  14. package/api/discover/_adapter.d.mts +1 -2
  15. package/api/discover/_adapter.mjs +6 -8
  16. package/api/discover/discover.mjs +0 -1
  17. package/api/docs/_adapter.mjs +4 -0
  18. package/api/doctor/_adapter.d.mts +24 -10
  19. package/api/doctor/_adapter.mjs +28 -25
  20. package/api/doctor/doctor.d.mts +7 -4
  21. package/api/doctor/doctor.mjs +52 -14
  22. package/api/doctor/doctor.test.mjs +58 -0
  23. package/api/integration/validate-integration-gaps.test.mjs +3 -0
  24. package/api/integration/validateIntegration.doc.mjs +1 -1
  25. package/api/template/template.mjs +5 -1
  26. package/assets/docs/tree/checks.doc.mjs +1 -1
  27. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  28. package/clients/cli/index.mjs +25 -8
  29. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  30. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  31. package/foundation/agent-docs/agent-docs.mjs +5 -5
  32. package/foundation/agent-docs/computer-agent-text.mjs +16 -1
  33. package/foundation/agent-docs/computer-agent-text.test.mjs +23 -2
  34. package/foundation/integrations/public-imports.d.mts +37 -0
  35. package/foundation/integrations/public-imports.mjs +839 -46
  36. package/foundation/integrations/public-imports.test.mjs +971 -46
  37. package/foundation/release/global-state.d.mts +8 -4
  38. package/foundation/release/global-state.mjs +4 -2
  39. package/foundation/release/notices.d.mts +62 -8
  40. package/foundation/release/notices.mjs +136 -25
  41. package/foundation/release/notices.test.mjs +21 -0
  42. package/foundation/text/string-utils.d.mts +2 -1
  43. package/foundation/text/string-utils.mjs +16 -5
  44. package/foundation/text/suggest-order.d.mts +72 -0
  45. package/foundation/text/suggest-order.mjs +363 -0
  46. package/foundation/text/suggest-order.test.mjs +259 -0
  47. package/package.json +9 -9
@@ -65,8 +65,8 @@ import {typedEdges} from '../docs/node/node.mjs';
65
65
  import {detailView, indexView} from '../../foundation/doc-compiler/lenses.mjs';
66
66
  import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env/semver.mjs';
67
67
  import {checkAppThemes, checkThemes} from './theme-checks.mjs';
68
- import {availableLine, upgradeLine} from '../../foundation/release/notices.mjs';
69
- import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts} from './_adapter.mjs';
68
+ import {availableLine, RUN_FROM_PROJECT, upgradeLine} from '../../foundation/release/notices.mjs';
69
+ import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, insideProjectElsewhere, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts} from './_adapter.mjs';
70
70
 
71
71
  /**
72
72
  * @typedef {'pass'|'warn'|'fail'|'info'} DoctorStatus
@@ -286,15 +286,25 @@ export function checkVersionAlignment(ctx) {
286
286
  // the run (spec AST-081 FR2): say so, and how to add the CLI at Core's
287
287
  // version.
288
288
  if (ctx.ownCli === false) {
289
+ // The same comparison as the daily hint: the CLI against the Core the
290
+ // run reads (spec AST-081 FR2). The command adds the CLI in the project
291
+ // spec:AST-040 FR9 defines; from a folder inside it whose package.json
292
+ // is not the project's, or in no project, the fix says how to reach one.
293
+ const add = addCliCommandFor(ctx.cwd, coreVersion);
294
+ const matches = coreVersion === cliVersion;
295
+ const fix = add
296
+ ? `${matches ? 'To pin it for the team and CI' : 'To match'}, run: ${add.command}.`
297
+ : matches
298
+ ? null
299
+ : NO_PROJECT_FIX;
289
300
  return {
290
301
  id: 'version-alignment',
291
302
  label: '@astryxdesign/core <-> @astryxdesign/cli alignment',
292
- status: coreVersion === cliVersion ? 'info' : 'warn',
293
- message:
294
- coreVersion === cliVersion
295
- ? `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered and matches its Core.`
296
- : `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered while its Core is ${coreVersion}.`,
297
- fix: `${coreVersion === cliVersion ? 'To pin it for the team and CI' : 'To match'}, run: ${addCliCommandFor(ctx.cwd, coreVersion)}.`,
303
+ status: matches ? 'info' : 'warn',
304
+ message: matches
305
+ ? `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered and matches its Core.`
306
+ : `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered while its Core is ${coreVersion}.`,
307
+ ...(fix ? {fix} : {}),
298
308
  };
299
309
  }
300
310
  // The project's own CLI answers this project whatever its version
@@ -308,10 +318,31 @@ export function checkVersionAlignment(ctx) {
308
318
  message: drift
309
319
  ? `This project's CLI ${cliVersion} answers it, but its Core is ${coreVersion}: templates, docs, and agent text come from CLI ${cliVersion}, components from Core ${coreVersion}.`
310
320
  : `@astryxdesign/core v${coreVersion} is in step with @astryxdesign/cli v${cliVersion}.`,
311
- ...(drift ? {fix: `To align them, run: ${alignCommand(ctx.cwd, cliVersion, coreVersion)}.`} : {}),
321
+ ...(drift ? alignFix(ctx.cwd, cliVersion, coreVersion) : {}),
312
322
  };
313
323
  }
314
324
 
325
+ /**
326
+ * The fix for a CLI and Core on different releases, when a command fits.
327
+ * @param {string} cwd
328
+ * @param {string} cli
329
+ * @param {string} core
330
+ * @returns {{fix?: string}}
331
+ */
332
+ function alignFix(cwd, cli, core) {
333
+ // From a folder inside a project whose package.json is not the project's,
334
+ // aligning the project would leave this warning in place, so no command
335
+ // fits there (alignCommand returns none): point at the project instead.
336
+ const command = alignCommand(cwd, cli, core);
337
+ return {fix: command ? `To align them, run: ${command}.` : NO_PROJECT_FIX};
338
+ }
339
+
340
+ /**
341
+ * The fix where no install command fits: the folder's package.json is not an
342
+ * Astryx project's (spec AST-040 FR9), and adding there would make it one.
343
+ */
344
+ const NO_PROJECT_FIX = RUN_FROM_PROJECT;
345
+
315
346
  /**
316
347
  * Check 5 — astryx.config.mjs (if present) loads and has a valid shape.
317
348
  * @param {DoctorContext} ctx
@@ -1559,6 +1590,7 @@ function checkFailureNote(failed) {
1559
1590
  const SKIP_REASONS = {
1560
1591
  'already-shown': 'it had already printed that day',
1561
1592
  'no-newer': 'no newer release was known',
1593
+ 'no-project': 'the folder belongs to no Astryx project, so no install command fits',
1562
1594
  };
1563
1595
 
1564
1596
  /**
@@ -1764,12 +1796,14 @@ export function checkComputerIntegrations(ctx) {
1764
1796
  * Inside a project, the integrations installed for the computer that the
1765
1797
  * project does not install: available, never used (spec AST-081 FR12).
1766
1798
  * Always info.
1767
- * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: (name: string) => string}} input
1799
+ * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: ((name: string) => string) | null, elsewhere?: boolean}} input
1768
1800
  * `install`: the command that adds a package with the project's package
1769
- * manager (read by the adapter)
1801
+ * manager (read by the adapter); null when the folder belongs to no
1802
+ * project, or `elsewhere`: its package.json is not the project's, where the
1803
+ * fix points at the project's folder
1770
1804
  * @returns {DoctorCheck}
1771
1805
  */
1772
- export function checkComputerIntegrationsAvailable({installed, candidates, install}) {
1806
+ export function checkComputerIntegrationsAvailable({installed, candidates, install, elsewhere = false}) {
1773
1807
  const available = candidates.filter(c => !installed.has(c.name));
1774
1808
  const base = {id: 'computer-integrations', label: 'Integrations installed for this computer', status: /** @type {const} */ ('info')};
1775
1809
  if (available.length === 0) {
@@ -1779,7 +1813,11 @@ export function checkComputerIntegrationsAvailable({installed, candidates, insta
1779
1813
  return {
1780
1814
  ...base,
1781
1815
  message: `Installed for this computer but not in this project, so not used here: ${available.map(c => c.name).join(', ')}.`,
1782
- fix: `To use one in this project, run ${available.map(c => `\`${add(c.name)}\``).join(' or ')}.`,
1816
+ ...(add
1817
+ ? {fix: `To use one in this project, run ${available.map(c => `\`${add(c.name)}\``).join(' or ')}.`}
1818
+ : elsewhere
1819
+ ? {fix: NO_PROJECT_FIX}
1820
+ : {}),
1783
1821
  };
1784
1822
  }
1785
1823
 
@@ -2038,7 +2076,7 @@ export async function runChecks(options = {}) {
2038
2076
  {
2039
2077
  const loadedNames = (project?.loadedIntegrations ?? []).map((/** @type {{name: string}} */ i) => i.name);
2040
2078
  const candidates = await computerIntegrationsToAdd(cwd, loadedNames);
2041
- checks.push(checkComputerIntegrationsAvailable({installed: new Set(loadedNames), candidates, install: installCommandFor(cwd)}));
2079
+ checks.push(checkComputerIntegrationsAvailable({installed: new Set(loadedNames), candidates, install: installCommandFor(cwd), elsewhere: insideProjectElsewhere(cwd)}));
2042
2080
  }
2043
2081
  checks.push(await checkAuthoringDocs(ctx));
2044
2082
  checks.push(await checkCliDocs(ctx));
@@ -31,7 +31,9 @@ import {
31
31
  checkIntegrationIssues,
32
32
  checkVersionAlignment,
33
33
  checkPackageManager,
34
+ checkComputerIntegrationsAvailable,
34
35
  } from './doctor.mjs';
36
+ import {installCommandFor} from './_adapter.mjs';
35
37
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
36
38
  import {Project} from '../../foundation/config/project.mjs';
37
39
 
@@ -223,7 +225,13 @@ describe("doctor — the project's own CLI and Core on different releases", () =
223
225
  ).version;
224
226
  /** @param {string} core */
225
227
  const at = core => {
228
+ // A project as spec:AST-040 FR9 defines it: its package.json declares
229
+ // an Astryx package.
226
230
  const dir = mkProject({
231
+ 'package.json': JSON.stringify({
232
+ name: 'app',
233
+ dependencies: {'@astryxdesign/core': core},
234
+ }),
227
235
  'package-lock.json': '{}',
228
236
  'node_modules/@astryxdesign/core/package.json': JSON.stringify({
229
237
  name: '@astryxdesign/core',
@@ -257,6 +265,10 @@ describe("doctor — the project's own CLI and Core on different releases", () =
257
265
 
258
266
  it('in a project with no CLI of its own, warns that the started copy answered and names the command that adds the CLI at Core', () => {
259
267
  const dir = mkProject({
268
+ 'package.json': JSON.stringify({
269
+ name: 'app',
270
+ dependencies: {'@astryxdesign/core': '0.0.1'},
271
+ }),
260
272
  'package-lock.json': '{}',
261
273
  'node_modules/@astryxdesign/core/package.json': JSON.stringify({
262
274
  name: '@astryxdesign/core',
@@ -279,6 +291,52 @@ describe("doctor — the project's own CLI and Core on different releases", () =
279
291
  });
280
292
  });
281
293
 
294
+ describe('the command that adds an integration installed for the computer', () => {
295
+ const app = () =>
296
+ mkProject({
297
+ 'package.json': JSON.stringify({
298
+ name: 'app',
299
+ dependencies: {'@astryxdesign/core': '0.7.0'},
300
+ }),
301
+ 'pnpm-lock.yaml': '',
302
+ 'tools/codegen/package.json': JSON.stringify({name: 'codegen'}),
303
+ });
304
+
305
+ it('adds it in the project, with its package manager', () => {
306
+ const dir = app();
307
+ expect(installCommandFor(dir)?.('@acme/a')).toBe('pnpm add @acme/a');
308
+ });
309
+
310
+ // A package.json that is not the project's (spec AST-040 FR9): a run
311
+ // there loads integrations from it, so a package added to the project
312
+ // stays unused there. No command; the fix points at the project.
313
+ it("from a tool folder inside the project, names no command and points at the project's folder", () => {
314
+ const dir = app();
315
+ expect(installCommandFor(path.join(dir, 'tools', 'codegen'))).toBeNull();
316
+ const c = checkComputerIntegrationsAvailable({
317
+ installed: new Set(),
318
+ candidates: [/** @type {any} */ ({name: '@acme/a'})],
319
+ install: null,
320
+ elsewhere: true,
321
+ });
322
+ expect(c.fix).toBe(
323
+ "Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.",
324
+ );
325
+ });
326
+
327
+ it('in a folder that belongs to no project, names no command', () => {
328
+ const dir = mkProject({'package.json': JSON.stringify({name: 'tool'})});
329
+ expect(installCommandFor(dir)).toBeNull();
330
+ const c = checkComputerIntegrationsAvailable({
331
+ installed: new Set(),
332
+ candidates: [/** @type {any} */ ({name: '@acme/a'})],
333
+ install: null,
334
+ });
335
+ expect(c.status).toBe('info');
336
+ expect(c).not.toHaveProperty('fix');
337
+ });
338
+ });
339
+
282
340
  describe('checkCliCommand', () => {
283
341
  it('is informational when no integration declares a command', () => {
284
342
  const dir = mkProject({'pnpm-lock.yaml': ''});
@@ -580,6 +580,9 @@ describe('block component names', () => {
580
580
  ),
581
581
  'templates/account-card.tsx':
582
582
  "import {Helper} from 'some-lib';\nexport default function A() {\n return <Helper />;\n}\n",
583
+ // The package root the doc's derived import names exports the component.
584
+ 'index.tsx':
585
+ "export function Panel() { return null; }\nexport {AcmeWidget} from './components/AcmeWidget';\n",
583
586
  });
584
587
 
585
588
  expect(await allOf(dir)).toEqual([]);
@@ -62,7 +62,7 @@ export const doc = {
62
62
  {
63
63
  type: 'integration.validate',
64
64
  description:
65
- 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `example_import_not_exported`, `template_import_not_exported`, `template_import_outside_root` and `template_private_import`. When the manifest loads, `data.publicImports` is `{status: \'checked\', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package\'s own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.',
65
+ "The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.",
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -24,6 +24,7 @@ import {
24
24
  } from '../../foundation/discovery/template-adapter.mjs';
25
25
  import {AstryxError} from '../error.mjs';
26
26
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
27
+ import {orderByAffinity} from '../../foundation/text/suggest-order.mjs';
27
28
  import {templateList} from './list/list.mjs';
28
29
  import {templateShow} from './show/show.mjs';
29
30
  import {templateSkeleton} from './skeleton/skeleton.mjs';
@@ -188,7 +189,10 @@ export async function template(name, options = {}) {
188
189
  if (name && candidates.length === 0) {
189
190
  throw new AstryxError(
190
191
  `Unknown template "${name}"`,
191
- templates.map(t => ({name: t.dirName, reason: `${t.type} template`})),
192
+ orderByAffinity(name, templates, t => [t.dirName, t.name]).map(t => ({
193
+ name: t.dirName,
194
+ reason: `${t.type} template`,
195
+ })),
192
196
  ERROR_CODES.ERR_UNKNOWN_TEMPLATE,
193
197
  );
194
198
  }
@@ -32,7 +32,7 @@ export const docs = {
32
32
  '`astryx doctor integration validate`',
33
33
  'The manifest loads, each root holds contributions the CLI can read, and each doc matches its authoring type. Notes, which fail nothing, list a malformed `cliCommand` and each command a topic writes with a package runner (`runner_command`)',
34
34
  'A declared root is missing (`missing_root`), a contribution does not load (`invalid_doc`, `invalid_component`, `invalid_theme`), or two templates in the package replace one Core id (`ambiguous_template_replacement`)',
35
- "The manifest has a key this CLI does not know (`unknown_manifest_key`), or a doc field does not match the doc's authoring type: a field the type does not have, a missing required field, or a value outside the field's type. It also warns on what no reader can serve: a prop listed twice (`duplicate_prop`), a `propDescriptions` key that names no documented prop (`unknown_translated_prop`), a section with no content (`empty_section`), two sections of a topic with one key (`duplicate_section_key`), or a `.doc.zh.mjs` or `.doc.dense.mjs` overlay beside no topic file (`orphan_doc_overlay`). Since 0.7.3 it also lists, from source and without failing, what the package tells apps to import that they cannot: a component's import (the doc's `import`, or the one the CLI derives) or a template's public import whose subpath package.json `exports` does not declare (`component_import_not_exported`, `template_import_not_exported`) or that names another package (`component_import_other_package`); an example that imports an undeclared subpath (`example_import_not_exported`); a template that imports a path outside the templates root (`template_import_outside_root`) or a path its package or Core does not export (`template_private_import`). Each is a note, printed with its fix, that fails `--strict` from the next minor; an import it cannot judge, such as a deep path into a `dist/` not built yet, is listed under `publicImports` as not checked. It checks docs with your installed `typescript`, or, where that is missing or has no JavaScript compiler API (TypeScript 7), with an installed `@typescript/typescript6`; without either, it prints `[skip] Docs not type-checked`. With no `astryx.integration.mjs` it prints a hint and exits 0",
35
+ "The manifest has a key this CLI does not know (`unknown_manifest_key`), or a doc field does not match the doc's authoring type: a field the type does not have, a missing required field, or a value outside the field's type. It also warns on what no reader can serve: a prop listed twice (`duplicate_prop`), a `propDescriptions` key that names no documented prop (`unknown_translated_prop`), a section with no content (`empty_section`), two sections of a topic with one key (`duplicate_section_key`), or a `.doc.zh.mjs` or `.doc.dense.mjs` overlay beside no topic file (`orphan_doc_overlay`). Since 0.7.3 it also lists, from source and without failing, what the package tells apps to import that they cannot: a component's import (the doc's `import`, or the one the CLI derives) or a template's public import whose subpath package.json `exports` does not declare (`component_import_not_exported`, `template_import_not_exported`) or that names another package (`component_import_other_package`); an example that imports an undeclared subpath (`example_import_not_exported`); a template that imports a path outside the templates root (`template_import_outside_root`) or a path its package or Core does not export (`template_private_import`). It lists the same way a component's import whose module does not export the component (`component_import_missing_name`), an example or a template that imports a name its package does not export (`example_import_missing_name`, `template_import_missing_name`), and a template source with no default export (`template_no_default_export`). Each is a note, printed with its fix, that fails `--strict` from the next minor; an import it cannot judge, such as an `exports` target not built yet or a deep path into a `dist/` not built yet, is listed under `publicImports` as not checked. It checks docs with your installed `typescript`, or, where that is missing or has no JavaScript compiler API (TypeScript 7), with an installed `@typescript/typescript6`; without either, it prints `[skip] Docs not type-checked`. With no `astryx.integration.mjs` it prints a hint and exits 0",
36
36
  ],
37
37
  [
38
38
  '`astryx doctor integration components`',
@@ -202,6 +202,23 @@ describe('enforcement layer 3 — per-command setup nudge', () => {
202
202
  expect(r.stderr).toMatch(NUDGE);
203
203
  });
204
204
 
205
+ // A nested package.json that is not the project's (spec AST-040 FR9): the
206
+ // reminder sends the person to the project's folder, never adds the CLI to
207
+ // the nested package.json (spec AST-081 FR2).
208
+ it("in a nested package whose package.json is not the project's, says to run from the project's folder", async () => {
209
+ write('package.json', JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '0.7.0'}}));
210
+ write('package-lock.json', '{}');
211
+ write('functions/package.json', '{"name":"functions"}');
212
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'functions'));
213
+ // Only `cd` comes first, so the app has no CLI of its own yet: the
214
+ // command is the scoped package at the answering release, never the bare
215
+ // `astryx` name a package runner would fetch from the registry.
216
+ const {version} = JSON.parse(fs.readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'));
217
+ expect(r.stderr.trim()).toBe(
218
+ `Next step: run \`cd ${tmp}\`, then \`npx @astryxdesign/cli@${version} init\` to finish setup and install the Astryx agent prompt.`,
219
+ );
220
+ });
221
+
205
222
  // Inside a git repository the project-root check above adds nothing to the
206
223
  // walk up to the repository root: the same outcomes as without it.
207
224
  it('inside a repository, is quiet in a nested package once init has written the docs at the project root', async () => {
@@ -16,14 +16,12 @@ import {Command, Option} from 'commander';
16
16
  import {fileURLToPath} from 'node:url';
17
17
  import * as fs from 'node:fs';
18
18
  import * as path from 'node:path';
19
- import {formatCliCommand, getCliInvocation} from '../../foundation/env/package-manager.mjs';
19
+ import {formatCliCommand, getCliInvocation, quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
20
20
  import {hasRecordedProject} from '../../foundation/env/cli-command.mjs';
21
21
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
22
22
  import {API_VERSION, setJsonMode} from '../../foundation/response/json.mjs';
23
23
  import {answeredBy, runChoice} from '../../foundation/release/run-context.mjs';
24
- import {addCliCommand} from '../../foundation/release/notices.mjs';
25
- import {projectRootOf} from '../../foundation/release/choose.mjs';
26
- import {readReleaseFacts} from '../../foundation/release/project.mjs';
24
+ import {cliInstallAdvice, installFolder} from '../../foundation/release/notices.mjs';
27
25
  import {buildManifest} from './lib/manifest.mjs';
28
26
  import {cliError} from './lib/cli-error.mjs';
29
27
  import {section, text, records} from './formatters/index.mjs';
@@ -663,14 +661,33 @@ export async function createProgram() {
663
661
  // A project with no CLI of its own, answered by another release than its
664
662
  // Core's: add the CLI at Core's version first, as the daily hint says,
665
663
  // then run that CLI's init (spec AST-081 FR2).
666
- const choice = runChoice(cwd);
667
- if (choice.copy === 'starting' && choice.coreVersion && choice.coreVersion !== choice.version) {
668
- const root = projectRootOf(readReleaseFacts(cwd)) ?? cwd;
664
+ // A folder that belongs to no project spec:AST-040 FR9 defines gets no
665
+ // reminder, as outside a project.
666
+ const target = installFolder(cwd);
667
+ if (target == null) return;
668
+ // From a folder inside the project whose package.json is not the
669
+ // project's, init runs from the project's folder. Only `cd` comes
670
+ // before it, so the command is the picker's for that folder, never the
671
+ // bare `astryx` name a package runner would fetch from the registry
672
+ // (spec AST-081 FR5).
673
+ if (target.moved) {
669
674
  console.error(
670
- setupNudge(getCliInvocation(root, {installed: true}), {before: addCliCommand(root, choice.coreVersion)}).trimEnd(),
675
+ setupNudge(getCliInvocation(target.dir), {before: `cd ${quoteCommandArgument(target.dir)}`}).trimEnd(),
671
676
  );
672
677
  return;
673
678
  }
679
+ const choice = runChoice(cwd);
680
+ if (choice.copy === 'starting' && choice.coreVersion && choice.coreVersion !== choice.version) {
681
+ // The daily hint's comparison and command: add the CLI at Core's
682
+ // version, then run that CLI's init.
683
+ const add = cliInstallAdvice({cwd, core: choice.coreVersion});
684
+ if (add?.command) {
685
+ console.error(
686
+ setupNudge(getCliInvocation(add.root, {installed: true}), {before: add.command}).trimEnd(),
687
+ );
688
+ return;
689
+ }
690
+ }
674
691
  console.error(setupNudge(getCliInvocation(cwd)).trimEnd());
675
692
  } catch {
676
693
  // Never let the nudge break a command.
@@ -82,6 +82,18 @@ export const GEMINI_MD: "GEMINI.md";
82
82
  export const CURSOR_RULES: ".cursorrules";
83
83
  export const HERMES_DOT_MD: ".hermes.md";
84
84
  export const HERMES_MD: "HERMES.md";
85
+ /**
86
+ * The page workflow every Astryx agent text gives, written with the command
87
+ * name `astryx`: the project agent docs and the computer-level skill both
88
+ * render these lines, so the two never drift.
89
+ */
90
+ export const WORKFLOW_TITLE: "WORKFLOW \u2014 start every page from a template, never from scratch:";
91
+ export const WORKFLOW_STEPS: readonly string[];
92
+ /**
93
+ * The self-check's fix for a project with no StyleX or Tailwind compiler,
94
+ * and for an agent outside a project.
95
+ */
96
+ export const SELF_CHECK_CSS: "replace any raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or a token";
85
97
  export const MARKER_START: "<!-- ASTRYX:START -->";
86
98
  export const MARKER_END: "<!-- ASTRYX:END -->";
87
99
  export const LEGACY_MARKER_START: "<!-- XDS:START -->";
@@ -34,6 +34,26 @@ export const CURSOR_RULES = '.cursorrules';
34
34
  export const HERMES_DOT_MD = '.hermes.md';
35
35
  export const HERMES_MD = 'HERMES.md';
36
36
 
37
+ /**
38
+ * The page workflow every Astryx agent text gives, written with the command
39
+ * name `astryx`: the project agent docs and the computer-level skill both
40
+ * render these lines, so the two never drift.
41
+ */
42
+ export const WORKFLOW_TITLE =
43
+ 'WORKFLOW — start every page from a template, never from scratch:';
44
+ export const WORKFLOW_STEPS = Object.freeze([
45
+ '1. `astryx build "<idea>"` — names the template to scaffold from and the parts it lacks.',
46
+ '2. `astryx template <name> <path>` — scaffold it; keep its frame, gap and padding; replace the content.',
47
+ '3. `astryx template <Block>` for parts it lacks; `astryx component <Name>` to read props before using one.',
48
+ ]);
49
+
50
+ /**
51
+ * The self-check's fix for a project with no StyleX or Tailwind compiler,
52
+ * and for an agent outside a project.
53
+ */
54
+ export const SELF_CHECK_CSS =
55
+ 'replace any raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or a token';
56
+
37
57
  export const MARKER_START = '<!-- ASTRYX:START -->';
38
58
  export const MARKER_END = '<!-- ASTRYX:END -->';
39
59
  // Legacy markers — read during migration so the script finds existing XDS blocks
@@ -91,7 +111,9 @@ export function holdsAstryxBlock(content) {
91
111
  while (at !== -1) {
92
112
  const from = at + marker.length;
93
113
  const end = content.indexOf('<!--', from);
94
- const inner = (end === -1 ? content.slice(from) : content.slice(from, end)).trim();
114
+ const inner = (
115
+ end === -1 ? content.slice(from) : content.slice(from, end)
116
+ ).trim();
95
117
  if (!/^@\S+$/.test(inner)) return true;
96
118
  at = content.indexOf(marker, from);
97
119
  }
@@ -153,7 +175,7 @@ export function isAstryxPromptInReach(startDir = process.cwd()) {
153
175
  * @returns {string | null}
154
176
  */
155
177
  function findRepositoryRoot(start) {
156
- for (let dir = start; ; ) {
178
+ for (let dir = start; ;) {
157
179
  if (fs.existsSync(path.join(dir, '.git'))) return dir;
158
180
  const parent = path.dirname(dir);
159
181
  if (parent === dir) return null;
@@ -58,6 +58,9 @@ import {
58
58
  discoverAgentDocs,
59
59
  isAstryxInitialized,
60
60
  isAstryxPromptInReach,
61
+ SELF_CHECK_CSS,
62
+ WORKFLOW_STEPS,
63
+ WORKFLOW_TITLE,
61
64
  } from './agent-doc-state.mjs';
62
65
 
63
66
  // The agent-doc locations, markers, and the setup-state predicates
@@ -762,10 +765,7 @@ export function generateCompressedIndex(
762
765
  // Workflow — `build` is the front door, and every page starts from the
763
766
  // template it names. build/template/component are covered here, so they are
764
767
  // intentionally omitted from the command reference below.
765
- lines.push('WORKFLOW — start every page from a template, never from scratch:');
766
- lines.push('1. `astryx build "<idea>"` — names the template to scaffold from and the parts it lacks.');
767
- lines.push('2. `astryx template <name> <path>` — scaffold it; keep its frame, gap and padding; replace the content.');
768
- lines.push('3. `astryx template <Block>` for parts it lacks; `astryx component <Name>` to read props before using one.');
768
+ lines.push(WORKFLOW_TITLE, ...WORKFLOW_STEPS);
769
769
  lines.push('Changing an existing page? Keep it: skip step 2 and add blocks/components inside its sections.');
770
770
  lines.push('');
771
771
 
@@ -793,7 +793,7 @@ export function generateCompressedIndex(
793
793
  'replace any className=, style={{…}}, raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or the xstyle prop + a token',
794
794
  tailwind:
795
795
  'replace any style={{…}}, raw <div>/<span>, imported .css/@apply, or hardcoded/arbitrary value (bg-[#fff], p-[13px]) with the component or a token-backed utility',
796
- css: 'replace any raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or a token',
796
+ css: SELF_CHECK_CSS,
797
797
  };
798
798
  lines.push(
799
799
  `- SELF-CHECK: re-read the file; ${selfCheckFix[stylingSystem] ?? selfCheckFix.css}.`,
@@ -43,7 +43,13 @@ import {createHash} from 'node:crypto';
43
43
  import {cliDoor} from '../env/cli-command.mjs';
44
44
  import {astryxCommandsOnSearchPath} from '../env/search-path.mjs';
45
45
  import {samePath} from '../fs/path-compare.mjs';
46
- import {MARKER_START, MARKER_END} from './agent-doc-state.mjs';
46
+ import {
47
+ MARKER_START,
48
+ MARKER_END,
49
+ SELF_CHECK_CSS,
50
+ WORKFLOW_STEPS,
51
+ WORKFLOW_TITLE,
52
+ } from './agent-doc-state.mjs';
47
53
 
48
54
  /** The command the computer-level text uses when no host door is set. */
49
55
  export const COMPUTER_COMMAND = 'astryx';
@@ -175,6 +181,15 @@ function bodyLines(run) {
175
181
  `Its docs, components, templates, and themes are all reachable through \`${run}\`. Start with \`${run} search '<what you need>'\`.`,
176
182
  `Then read \`${run} component <Name>\` or \`${run} docs <topic>\`, not the package's files.`,
177
183
  "In a project, the project's version of Astryx answers automatically.",
184
+ // How to build, which discovery alone leaves to the agent's own page
185
+ // route: in a project, from the template, with the project agent docs'
186
+ // own workflow lines.
187
+ // A project that already installs Core gets the CLI at that version, as
188
+ // the CLI's own hint for that state says, never a newer CLI beside it.
189
+ `To build UI, work in a project folder (create one if there is none). Add \`@astryxdesign/core\` and \`@astryxdesign/cli\` to a new project or one without \`@astryxdesign/core\`; to a project that already has \`@astryxdesign/core\`, add \`@astryxdesign/cli\` at the same version. Run \`${run} init\` there and follow the agent docs it writes.`,
190
+ WORKFLOW_TITLE,
191
+ ...WORKFLOW_STEPS.map(step => step.replaceAll('`astryx ', `\`${run} `)),
192
+ `Before you deliver, re-read each file; ${SELF_CHECK_CSS}. Then build the project and deliver that build, not a description of it.`,
178
193
  ];
179
194
  }
180
195
 
@@ -27,7 +27,13 @@ import {
27
27
  renderComputerAgentText,
28
28
  writeComputerAgentText,
29
29
  } from './computer-agent-text.mjs';
30
- import {MARKER_END, MARKER_START} from './agent-doc-state.mjs';
30
+ import {
31
+ MARKER_END,
32
+ MARKER_START,
33
+ SELF_CHECK_CSS,
34
+ WORKFLOW_STEPS,
35
+ WORKFLOW_TITLE,
36
+ } from './agent-doc-state.mjs';
31
37
  import {runWithCliDoor} from '../env/cli-command.mjs';
32
38
  import {runCli} from '../../test-utils/run-cli.mjs';
33
39
  import {parse as parseYaml} from 'yaml';
@@ -123,12 +129,27 @@ describe('renderComputerAgentText', () => {
123
129
 
124
130
  it('stays short, and tells agents to read docs through the CLI', () => {
125
131
  const text = renderComputerAgentText({command: 'astryx'});
126
- expect(text.split('\n').length).toBeLessThanOrEqual(15);
132
+ expect(text.split('\n').length).toBeLessThanOrEqual(22);
127
133
  expect(text).toContain(
128
134
  "Then read `astryx component <Name>` or `astryx docs <topic>`, not the package's files.",
129
135
  );
130
136
  });
131
137
 
138
+ // Discovery alone leaves the build to the agent's own page route, which
139
+ // may not install packages; the skill names the route and the project
140
+ // agent docs' own workflow lines.
141
+ it('gives the build workflow: a project with Astryx installed and init run, the shared template steps, then check and deliver the build', () => {
142
+ const text = renderComputerAgentText({command: 'astryx'});
143
+ expect(text).toContain(
144
+ 'To build UI, work in a project folder (create one if there is none). Add `@astryxdesign/core` and `@astryxdesign/cli` to a new project or one without `@astryxdesign/core`; to a project that already has `@astryxdesign/core`, add `@astryxdesign/cli` at the same version. Run `astryx init` there and follow the agent docs it writes.',
145
+ );
146
+ for (const line of [WORKFLOW_TITLE, ...WORKFLOW_STEPS]) {
147
+ expect(text).toContain(line);
148
+ }
149
+ expect(text).toContain(`re-read each file; ${SELF_CHECK_CSS}.`);
150
+ expect(text).toContain('deliver that build');
151
+ });
152
+
132
153
  it("uses the host's door when one is set", () => {
133
154
  const text = runWithCliDoor('acme astryx', () => renderComputerAgentText());
134
155
  expect(text).toContain("`acme astryx search '<what you need>'`");
@@ -18,6 +18,24 @@ export function splitSpecifier(specifier: string): {
18
18
  * @returns {ImportStatement[]}
19
19
  */
20
20
  export function readImports(text: string): ImportStatement[];
21
+ /**
22
+ * Every name (runtime or type) a module exports, and whether the list is
23
+ * complete: an `export *` from another package, `export =`, or a module that
24
+ * does not parse leaves it incomplete, and then no name is judged missing.
25
+ * @param {string} file
26
+ * @param {ExportNameCache} [cache] export lists already read in this check
27
+ * @returns {{names: Set<string>, complete: boolean, types: Set<string>, typed: boolean}}
28
+ * `types`: the names exported only as types (an interface, a type alias,
29
+ * `export type`); `typed`: the list includes every type the module
30
+ * exports (TypeScript source, or a JavaScript module whose declaration
31
+ * file was read in full), so a name absent from it is absent as a type too
32
+ */
33
+ export function moduleExportNames(file: string, cache?: ExportNameCache): {
34
+ names: Set<string>;
35
+ complete: boolean;
36
+ types: Set<string>;
37
+ typed: boolean;
38
+ };
21
39
  /**
22
40
  * Every public-import finding for one package, as notes, and the report of
23
41
  * what could not be judged. It returns no issues: the notes are listed
@@ -56,6 +74,16 @@ export type ImportStatement = {
56
74
  */
57
75
  typeOnly?: boolean | undefined;
58
76
  };
77
+ /**
78
+ * Export lists read during one public-import check, by file. Scoped to that
79
+ * check, so a later check in the same process rereads every module.
80
+ */
81
+ export type ExportNameCache = Map<string, {
82
+ names: Set<string>;
83
+ complete: boolean;
84
+ types: Set<string>;
85
+ typed: boolean;
86
+ }>;
59
87
  export type Context = {
60
88
  packageDir: string;
61
89
  /**
@@ -70,6 +98,15 @@ export type Context = {
70
98
  * what could not be judged
71
99
  */
72
100
  unchecked: PublicImportUnchecked[];
101
+ /**
102
+ * export lists read in this check
103
+ */
104
+ exportNames: ExportNameCache;
105
+ /**
106
+ * why no name is judged missing
107
+ * (a module augmentation in the package); null when none, unset until read
108
+ */
109
+ augmentation?: string | null | undefined;
73
110
  /**
74
111
  * the package.json `files` entries, normalized
75
112
  */