@astryxdesign/cli 0.7.3-canary.2468b8a → 0.7.3-canary.296edaf

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/README.md +63 -63
  2. package/api/component/_adapter.mjs +39 -5
  3. package/api/discover/_adapter.d.mts +1 -2
  4. package/api/discover/_adapter.mjs +6 -8
  5. package/api/discover/discover.mjs +0 -1
  6. package/api/docs/_adapter.mjs +4 -0
  7. package/api/doctor/_adapter.d.mts +24 -10
  8. package/api/doctor/_adapter.mjs +28 -25
  9. package/api/doctor/doctor.d.mts +7 -4
  10. package/api/doctor/doctor.mjs +52 -14
  11. package/api/doctor/doctor.test.mjs +58 -0
  12. package/api/integration/validate-integration-gaps.test.mjs +3 -0
  13. package/api/integration/validate-integration.mjs +33 -7
  14. package/api/integration/validate-integration.type.d.mts +3 -1
  15. package/api/integration/validate-integration.type.mjs +3 -1
  16. package/api/integration/validateIntegration.doc.mjs +1 -1
  17. package/api/search/_entries.d.mts +11 -0
  18. package/api/search/_entries.mjs +35 -17
  19. package/api/search/_entries.test.mjs +48 -0
  20. package/api/template/template.mjs +5 -1
  21. package/assets/docs/tree/checks.doc.mjs +1 -1
  22. package/assets/docs/tree/versioning.doc.mjs +4 -0
  23. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  24. package/clients/cli/index.mjs +25 -8
  25. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  26. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  27. package/foundation/agent-docs/agent-docs.mjs +5 -5
  28. package/foundation/agent-docs/computer-agent-text.mjs +16 -1
  29. package/foundation/agent-docs/computer-agent-text.test.mjs +23 -2
  30. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  31. package/foundation/integrations/cli-peer-version.mjs +132 -0
  32. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  33. package/foundation/integrations/public-imports.d.mts +37 -0
  34. package/foundation/integrations/public-imports.mjs +839 -46
  35. package/foundation/integrations/public-imports.test.mjs +971 -46
  36. package/foundation/release/global-state.d.mts +8 -4
  37. package/foundation/release/global-state.mjs +4 -2
  38. package/foundation/release/notices.d.mts +62 -8
  39. package/foundation/release/notices.mjs +136 -25
  40. package/foundation/release/notices.test.mjs +21 -0
  41. package/foundation/response/response-types.doc.mjs +1 -1
  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
@@ -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 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: [
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
13
13
  synonyms?: string[];
14
14
  props?: string[];
15
15
  }>): EntryTable;
16
+ /**
17
+ * @param {any[]} all
18
+ * @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
19
+ * @returns {EntryTable}
20
+ */
21
+ export function buildTable(all: any[], cards: Record<string, {
22
+ what?: string;
23
+ synonyms?: string[];
24
+ props?: string[];
25
+ }>): EntryTable;
16
26
  export function entryOf(table: {
17
27
  index: Map<string, number>;
18
28
  }, res: {
@@ -22,6 +32,7 @@ export function entryOf(table: {
22
32
  section?: string;
23
33
  }): number | undefined;
24
34
  export function entryId(c: any): string;
35
+ export const HASHED_FIELDS: readonly string[];
25
36
  export type EntryTable = {
26
37
  /**
27
38
  * every returnable `<domain>:<name>`, in code-point order
@@ -77,6 +77,29 @@ let last = null;
77
77
  const cardIds = new WeakMap();
78
78
  let nextCardId = 0;
79
79
 
80
+ /**
81
+ * The candidate fields buildTable reads, all of them hashed by fingerprint;
82
+ * `_entries.test.mjs` fails if buildTable starts reading another.
83
+ */
84
+ /** How many guidance lines and prose paragraphs of a candidate the index reads. */
85
+ const GUIDANCE_LINES = 10;
86
+ const PROSE_PARAGRAPHS = 4;
87
+
88
+ export const HASHED_FIELDS = Object.freeze([
89
+ 'domain',
90
+ 'name',
91
+ '_topic',
92
+ '_section',
93
+ '_resultName',
94
+ '_package',
95
+ 'description',
96
+ 'keywords',
97
+ 'aliases',
98
+ 'titles',
99
+ 'guidance',
100
+ 'prose',
101
+ ]);
102
+
80
103
  /**
81
104
  * Everything the table reads from the catalog, hashed.
82
105
  * @param {any[]} all
@@ -89,20 +112,15 @@ function fingerprint(all, cards) {
89
112
  h.update(String(cardIds.get(cards)));
90
113
  for (const c of all) {
91
114
  h.update(
92
- JSON.stringify([
93
- c.domain,
94
- c.name,
95
- c._topic,
96
- c._section,
97
- c._resultName,
98
- c._package,
99
- c.description,
100
- c.keywords,
101
- c.aliases,
102
- c.titles,
103
- (c.guidance ?? []).slice(0, 10),
104
- (c.prose ?? []).slice(0, 4),
105
- ]),
115
+ JSON.stringify(
116
+ HASHED_FIELDS.map(f =>
117
+ f === 'guidance'
118
+ ? (c.guidance ?? []).slice(0, GUIDANCE_LINES)
119
+ : f === 'prose'
120
+ ? (c.prose ?? []).slice(0, PROSE_PARAGRAPHS)
121
+ : c[f],
122
+ ),
123
+ ),
106
124
  );
107
125
  }
108
126
  return h.digest('hex');
@@ -113,7 +131,7 @@ function fingerprint(all, cards) {
113
131
  * @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
114
132
  * @returns {EntryTable}
115
133
  */
116
- function buildTable(all, cards) {
134
+ export function buildTable(all, cards) {
117
135
  /** @type {Map<string, any[]>} */
118
136
  const by = new Map();
119
137
  /** @type {Map<string, string>} each id's first package */
@@ -164,8 +182,8 @@ function buildTable(all, cards) {
164
182
  ...(c.titles ?? []),
165
183
  );
166
184
  text.push(
167
- ...(c.guidance ?? []).slice(0, 10),
168
- ...(c.prose ?? []).slice(0, 4),
185
+ ...(c.guidance ?? []).slice(0, GUIDANCE_LINES),
186
+ ...(c.prose ?? []).slice(0, PROSE_PARAGRAPHS),
169
187
  );
170
188
  }
171
189
  const card =
@@ -0,0 +1,48 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The entry index is reused while the catalog's text is unchanged, so
5
+ * every field it reads must be part of the hash that decides reuse.
6
+ */
7
+
8
+ import {describe, it, expect} from 'vitest';
9
+ import * as path from 'node:path';
10
+ import {fileURLToPath} from 'node:url';
11
+ import {gatherCandidates, loadSearchData} from './_adapter.mjs';
12
+ import {HASHED_FIELDS, buildTable, entryTable} from './_entries.mjs';
13
+
14
+ const cwd = path.resolve(
15
+ path.dirname(fileURLToPath(import.meta.url)),
16
+ '../../../..',
17
+ );
18
+
19
+ describe('entry index cache', () => {
20
+ it('hashes every candidate field the index reads', async () => {
21
+ const {all} = await gatherCandidates({cwd});
22
+ /** @type {Set<string>} */
23
+ const read = new Set();
24
+ const watched = all.map(
25
+ c =>
26
+ new Proxy(c, {
27
+ get(target, key, receiver) {
28
+ if (typeof key === 'string') read.add(key);
29
+ return Reflect.get(target, key, receiver);
30
+ },
31
+ }),
32
+ );
33
+ buildTable(watched, loadSearchData().cards);
34
+ const unhashed = [...read].filter(k => !HASHED_FIELDS.includes(k));
35
+ expect(unhashed).toEqual([]);
36
+ }, 60_000);
37
+
38
+ it('rebuilds when a candidate text changes and reuses it otherwise', async () => {
39
+ const {all} = await gatherCandidates({cwd});
40
+ const {cards} = loadSearchData();
41
+ const first = entryTable([...all], cards);
42
+ expect(entryTable([...all], cards)).toBe(first);
43
+ const changed = all.map((c, i) =>
44
+ i === 0 ? {...c, description: `${c.description ?? ''} changed`} : c,
45
+ );
46
+ expect(entryTable(changed, cards)).not.toBe(first);
47
+ }, 60_000);
48
+ });
@@ -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`',
@@ -120,6 +120,10 @@ export const docs = {
120
120
  type: 'prose',
121
121
  text: '`integration verify` fails a package that needs the CLI peer and lacks it, or whose range admits a stable CLI too old for what it ships. `integration add doc --parent` and `integration add theme` write the peer for you.',
122
122
  },
123
+ {
124
+ type: 'prose',
125
+ text: "When the CLI is outside that range, `doctor integration validate` and `integration check` list a `cli_peer_version` note naming your package. A note fails nothing, `--strict` included, and `integration verify` does not report it. Below the range the note gives the commands that install a newer Core and CLI together, as dev dependencies in your own package folder, and then run `upgrade --apply`. Above it, in an app the note asks for a release of your package that supports that CLI, and in your own package folder it asks you to test your package with that CLI and widen the range.",
126
+ },
123
127
  ],
124
128
  },
125
129
  {
@@ -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>'`");
@@ -0,0 +1,36 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The running CLI version.
6
+ * @returns {string}
7
+ */
8
+ export function cliVersion(): string;
9
+ /**
10
+ * Why the running CLI is outside an integration's declared
11
+ * `@astryxdesign/cli` peer range, or null when it is inside it (or when no
12
+ * peer is declared or the package.json cannot be read).
13
+ *
14
+ * A CLI below the range is told to upgrade Core and the CLI together, with
15
+ * the project's own install command, and then to run the upgrade codemods.
16
+ * A CLI above it (the range has an upper bound, such as `^0.6.0`) is
17
+ * told to look for a release of the package that supports it, since
18
+ * upgrading the CLI cannot help there; the author of the package in the
19
+ * current folder is told to test with this CLI and widen the range.
20
+ *
21
+ * @param {import('./integrations.mjs').LoadedIntegration} integration
22
+ * @param {string} [version] the running CLI version; defaults to this CLI's
23
+ * own package.json version
24
+ * @param {string} [cwd] where the install command would run; decides the
25
+ * package manager it names
26
+ * @param {{own?: boolean, from?: string}} [options] `own`: the package is
27
+ * the one being authored in the current folder, so above the range its
28
+ * author is told to test with this CLI and widen the range instead; `from`:
29
+ * the version the project's upgrade starts from when it is not the running
30
+ * CLI's, such as the Core of a project with no CLI of its own
31
+ * @returns {string | null}
32
+ */
33
+ export function cliPeerVersionProblem(integration: import("./integrations.mjs").LoadedIntegration, version?: string, cwd?: string, { own, from }?: {
34
+ own?: boolean;
35
+ from?: string;
36
+ }): string | null;