@astryxdesign/cli 0.7.3-canary.0bf23bd → 0.7.3-canary.0fd4f9e

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 (78) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.mjs +37 -25
  3. package/api/build/blocks/blocks.d.mts +68 -18
  4. package/api/build/blocks/blocks.mjs +475 -116
  5. package/api/build/blocks/blocks.test.mjs +191 -61
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.type.mjs +1 -1
  8. package/api/build/kit/answer.d.mts +9 -5
  9. package/api/build/kit/answer.mjs +123 -13
  10. package/api/build/kit/answer.test.mjs +73 -3
  11. package/api/build/kit/signals.d.mts +19 -0
  12. package/api/build/kit/signals.mjs +18 -7
  13. package/api/build/kit/weights.d.mts +8 -22
  14. package/api/build/kit/weights.mjs +87 -8
  15. package/api/build/kit/weights.test.mjs +96 -0
  16. package/api/build/tree.mjs +2 -1
  17. package/api/build/tree.test.mjs +37 -29
  18. package/api/component/_adapter.mjs +39 -5
  19. package/api/component/component-replacement.test.mjs +1 -0
  20. package/api/discover/_adapter.d.mts +1 -2
  21. package/api/discover/_adapter.mjs +6 -8
  22. package/api/discover/discover.mjs +0 -1
  23. package/api/docs/_adapter.mjs +4 -0
  24. package/api/doctor/_adapter.d.mts +33 -13
  25. package/api/doctor/_adapter.mjs +55 -25
  26. package/api/doctor/doctor.d.mts +23 -5
  27. package/api/doctor/doctor.mjs +81 -16
  28. package/api/doctor/doctor.test.mjs +58 -0
  29. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  30. package/api/integration/validate-integration-gaps.test.mjs +12 -1
  31. package/api/integration/validate-integration.d.mts +4 -0
  32. package/api/integration/validate-integration.mjs +48 -7
  33. package/api/integration/validate-integration.type.d.mts +36 -5
  34. package/api/integration/validate-integration.type.mjs +27 -6
  35. package/api/integration/validateIntegration.doc.mjs +1 -1
  36. package/api/search/_entries.d.mts +11 -0
  37. package/api/search/_entries.mjs +35 -17
  38. package/api/search/_entries.test.mjs +48 -0
  39. package/api/search/_gather-templates.d.mts +0 -1
  40. package/api/search/_gather-templates.mjs +25 -0
  41. package/api/search/search.integration-block.test.mjs +100 -0
  42. package/api/template/template.mjs +5 -1
  43. package/assets/docs/tree/checks.doc.mjs +1 -1
  44. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  45. package/assets/docs/tree/versioning.doc.mjs +4 -0
  46. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  47. package/clients/cli/commands/doctor.doc.mjs +1 -1
  48. package/clients/cli/commands/doctor.mjs +10 -0
  49. package/clients/cli/commands/outside-project.test.mjs +99 -0
  50. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  51. package/clients/cli/index.mjs +25 -8
  52. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  53. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  54. package/foundation/agent-docs/agent-docs.mjs +5 -5
  55. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  56. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  57. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  58. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  59. package/foundation/integrations/cli-peer-version.mjs +132 -0
  60. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  61. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  62. package/foundation/integrations/exports-subpaths.mjs +113 -0
  63. package/foundation/integrations/public-imports.d.mts +118 -0
  64. package/foundation/integrations/public-imports.mjs +1769 -0
  65. package/foundation/integrations/public-imports.test.mjs +1793 -0
  66. package/foundation/release/cache.test.mjs +24 -21
  67. package/foundation/release/global-state.d.mts +8 -4
  68. package/foundation/release/global-state.mjs +4 -2
  69. package/foundation/release/notices.d.mts +62 -8
  70. package/foundation/release/notices.mjs +136 -25
  71. package/foundation/release/notices.test.mjs +21 -0
  72. package/foundation/response/response-types.doc.mjs +1 -1
  73. package/foundation/text/string-utils.d.mts +2 -1
  74. package/foundation/text/string-utils.mjs +16 -5
  75. package/foundation/text/suggest-order.d.mts +72 -0
  76. package/foundation/text/suggest-order.mjs +363 -0
  77. package/foundation/text/suggest-order.test.mjs +259 -0
  78. package/package.json +9 -9
@@ -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
+ });
@@ -1,7 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /** @typedef {import('./_lexical.mjs').Candidate} Candidate */
5
4
  /**
6
5
  * Build template candidates (page + block) from the template discovery API.
7
6
  * @param {string} cwd
@@ -8,9 +8,31 @@ import {CORE_PACKAGE} from '../../foundation/discovery/component-discovery.mjs';
8
8
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
9
9
  import {listAvailableThemes} from '../theme/_adapter.mjs';
10
10
  import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
11
+ import {sameWord, wordsOf} from './_words.mjs';
11
12
 
12
13
  /** @typedef {import('./_lexical.mjs').Candidate} Candidate */
13
14
 
15
+ /**
16
+ * A template's authored display name as another name and title of it, when the
17
+ * name stands for the template: two words or more that hold every word of the
18
+ * component the block shows (`exampleFor`), as "Rich Text Editor" does for
19
+ * RichTextEditor. A query that is the name then names the entry whole, and one
20
+ * that holds it as a phrase ("rich text") reaches search's title tier, above
21
+ * entries that match one of its words. A label of the variant alone ("Inside a
22
+ * card" for a Comments block) does not name the block, so it stays out.
23
+ * @param {{displayName?: string, exampleFor?: string}} t
24
+ * @returns {{aliases?: string[], titles?: string[]}}
25
+ */
26
+ function subjectName(t) {
27
+ const name = String(t.displayName ?? '').trim();
28
+ const words = wordsOf(name);
29
+ const subject = wordsOf(String(t.exampleFor ?? ''));
30
+ if (words.length < 2 || subject.length === 0) return {};
31
+ return subject.every(s => words.some(w => sameWord(s, w)))
32
+ ? {aliases: [name], titles: [name]}
33
+ : {};
34
+ }
35
+
14
36
  /**
15
37
  * Build template candidates (page + block) from the template discovery API.
16
38
  * @param {string} cwd
@@ -67,6 +89,9 @@ export async function gatherTemplates(cwd) {
67
89
  // as its prose does, not as a name: one of them matching one word of a
68
90
  // short idea is not a direct match.
69
91
  prose: t.keywords ?? [],
92
+ // A display name that names the block's subject is another name of it
93
+ // and its title (subjectName).
94
+ ...subjectName(t),
70
95
  _displayName: t.name,
71
96
  _package: t.package ?? CORE_PACKAGE,
72
97
  _kind: t.type, // 'page' | 'block'
@@ -0,0 +1,100 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file An integration's own block answers a query that names it, though no
5
+ * learned table lists it: its authored display name is a title search reads,
6
+ * so "rich text editor" finds the rich text package's block first and build
7
+ * offers it, while a variant label that does not name the block (Lab's "Inside
8
+ * a card") captures nothing.
9
+ */
10
+
11
+ import fs from 'node:fs';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ import {fileURLToPath} from 'node:url';
15
+ import {afterAll, beforeAll, describe, expect, it} from 'vitest';
16
+ import {search} from './search.mjs';
17
+ import {build} from '../build/build.mjs';
18
+
19
+ const SLOW = 60_000;
20
+ const packages = path.resolve(
21
+ path.dirname(fileURLToPath(import.meta.url)),
22
+ '../../..',
23
+ );
24
+
25
+ describe('an integration block found by its display name', () => {
26
+ /** @type {string} */
27
+ let dir;
28
+ beforeAll(() => {
29
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-integration-block-'));
30
+ fs.writeFileSync(
31
+ path.join(dir, 'package.json'),
32
+ JSON.stringify({
33
+ name: 'consumer',
34
+ dependencies: {
35
+ '@astryxdesign/core': '*',
36
+ '@astryxdesign/richtext': '*',
37
+ '@astryxdesign/lab': '*',
38
+ },
39
+ }),
40
+ );
41
+ const scope = path.join(dir, 'node_modules', '@astryxdesign');
42
+ fs.mkdirSync(scope, {recursive: true});
43
+ for (const name of ['core', 'richtext', 'lab'])
44
+ fs.symlinkSync(path.join(packages, name), path.join(scope, name), 'dir');
45
+ });
46
+ afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
47
+
48
+ it.each(['rich text editor', 'rich text', 'text editor'])(
49
+ '`%s` ranks the rich text block first among templates',
50
+ async query => {
51
+ const {results} = (await search(query, {cwd: dir, type: 'template'}))
52
+ .data;
53
+ expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
54
+ name: 'RichTextEditorShowcase',
55
+ });
56
+ },
57
+ SLOW,
58
+ );
59
+
60
+ it(
61
+ 'a whole display name names the block outright',
62
+ async () => {
63
+ const {results} = (
64
+ await search('rich text editor', {cwd: dir, type: 'template'})
65
+ ).data;
66
+ expect(results[0]).toMatchObject({
67
+ name: 'RichTextEditorShowcase',
68
+ reason: 'exact name',
69
+ });
70
+ },
71
+ SLOW,
72
+ );
73
+
74
+ it(
75
+ "a variant label that does not name the block's subject is no title",
76
+ async () => {
77
+ const {results} = (
78
+ await search('table inside a card', {cwd: dir, type: 'template'})
79
+ ).data;
80
+ expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
81
+ name: 'TableInCard',
82
+ });
83
+ const kit = (await build('a settings form inside a card', {cwd: dir}))
84
+ .data;
85
+ expect(kit.blocks[0]?.name).not.toBe('CommentsInCard');
86
+ },
87
+ SLOW,
88
+ );
89
+
90
+ it(
91
+ 'build offers the rich text block for a request that names it',
92
+ async () => {
93
+ const kit = (
94
+ await build('a comment box with a rich text editor', {cwd: dir})
95
+ ).data;
96
+ expect(kit.blocks.map(b => b.name)).toContain('RichTextEditorShowcase');
97
+ },
98
+ SLOW,
99
+ );
100
+ });
@@ -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`). 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`',
@@ -24,6 +24,9 @@ export const docs = {
24
24
  'docker',
25
25
  'read-only home',
26
26
  'cache the release cache',
27
+ 'agent machine',
28
+ 'restart',
29
+ 'ephemeral machine',
27
30
  ],
28
31
  description:
29
32
  "What Astryx does in CI and containers: no update checks or notices, the project's version as always, and how to cache versions or work with a read-only home folder.",
@@ -74,6 +77,16 @@ export const docs = {
74
77
  },
75
78
  ],
76
79
  },
80
+ {
81
+ id: 'short-lived',
82
+ title: 'Machines that keep only the home folder',
83
+ content: [
84
+ {
85
+ type: 'prose',
86
+ text: 'Some agent machines keep the home folder across restarts but not system folders. A global install there disappears on restart while the agent guide in the home folder stays, so agents are told to run a global astryx command that is gone; the guide says to run the command that installed the CLI, such as `npm i -g @astryxdesign/cli`, when that command is not found, and `astryx doctor` names the same step. To keep the CLI across restarts, install it into a folder in your home and put its `bin` folder on your PATH, as for a permission error ({@link generic:install-once}), or run that command when the machine starts.',
87
+ },
88
+ ],
89
+ },
77
90
  {
78
91
  id: 'more',
79
92
  title: 'More on global mode',
@@ -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
  {
@@ -19,7 +19,10 @@ import {Command} from 'commander';
19
19
  import {discoverCoreTemplates} from '../../../foundation/discovery/template-adapter.mjs';
20
20
  import {discoverOwnedComponents} from '../../../foundation/discovery/component-discovery.mjs';
21
21
  import {discoverBuiltinTopics} from '../../../foundation/discovery/docs-discovery.mjs';
22
- import {findCoreDir, findProjectCoreDir} from '../../../foundation/fs/paths.mjs';
22
+ import {
23
+ findCoreDir,
24
+ findProjectCoreDir,
25
+ } from '../../../foundation/fs/paths.mjs';
23
26
  import {registerDoctor} from './doctor.mjs';
24
27
  import {expectRecordsCarry} from '../../../test-utils/text-projection.mjs';
25
28
 
@@ -674,6 +677,51 @@ describe('doctor integration — command', () => {
674
677
  }
675
678
  });
676
679
 
680
+ it('validate prints the public-import findings as listed only, and still exits 0', async () => {
681
+ writeIntegration({id: 'hero', name: 'Hero', type: 'block'});
682
+ fs.writeFileSync(
683
+ path.join(tmpDir, 'package.json'),
684
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3', exports: {}}),
685
+ );
686
+ process.chdir(tmpDir);
687
+
688
+ await createProgram().parseAsync([
689
+ 'node',
690
+ 'astryx',
691
+ 'doctor',
692
+ 'integration',
693
+ 'validate',
694
+ ]);
695
+
696
+ const output = logCalls.join('\n');
697
+ expect(output).toContain('note (template_import_not_exported):');
698
+ expect(output).toContain('Fix:');
699
+ expect(output).toContain('[ok] No integration issues found.');
700
+ expect(process.exitCode).toBeUndefined();
701
+ });
702
+
703
+ it('validate lists, as not checked, the imports it cannot judge when package.json has no name', async () => {
704
+ writeIntegration({id: 'hero', name: 'Hero', type: 'block'});
705
+ fs.writeFileSync(
706
+ path.join(tmpDir, 'package.json'),
707
+ JSON.stringify({version: '1.2.3'}),
708
+ );
709
+ process.chdir(tmpDir);
710
+
711
+ await createProgram().parseAsync([
712
+ 'node',
713
+ 'astryx',
714
+ 'doctor',
715
+ 'integration',
716
+ 'validate',
717
+ ]);
718
+
719
+ const output = logCalls.join('\n');
720
+ expect(output).toMatch(/\[info\] Imports not checked: 1:/);
721
+ expect(output).toContain('package.json has no "name"');
722
+ expect(process.exitCode).toBeUndefined();
723
+ });
724
+
677
725
  it('templates warns on a Core id and writes the exact --package command', async () => {
678
726
  const [core] = await discoverCoreTemplates();
679
727
  expect(core).toBeDefined();
@@ -21,7 +21,7 @@ export const doc = {
21
21
  "the docs the CLI reads, the newest release the computer knows of, with the install and upgrade commands when the project's release is older, and every `astryx` command on the search path, warning when the first one is not the Astryx CLI or predates the hand-off. It writes nothing, but loading astryx.config runs that file's code. " +
22
22
  'The `integration` subcommands provide authoring checks for one integration package. ' +
23
23
  'Outside a project it checks the computer instead: the Node version, the release that answered, ' +
24
- 'the newest release this computer knows of, with the command that upgrades the CLI installed for the computer when it is older, the astryx commands on the search path, the integrations installed for the computer (warning about one it skips), and whether the computer-level agent text (`astryx init --user`) is present, matches this release, was edited, or is turned off (info only). ' +
24
+ "the newest release this computer knows of, with the command that upgrades the CLI installed for the computer when it is older, the astryx commands on the search path, the integrations installed for the computer (warning about one it skips), and whether the computer-level agent text (`astryx init --user`) is present, matches this release, was edited, or is turned off (info only); when that text names `astryx` and no `astryx` command is on the search path, apart from a package runner's own copy, it says so and names the install step the text records, or npm's when it records none. " +
25
25
  'It never fails a check because the folder has no project.',
26
26
  fn: 'doctor',
27
27
  subcommands: ['integration'],
@@ -234,6 +234,16 @@ function printIntegrationValidation(data) {
234
234
  ...docTypesBlocks(data.docTypes, errors > 0),
235
235
  ...docNamesBlocks(data.docNames),
236
236
  ...blockComponentsBlocks(data.blockComponents),
237
+ ...(data.publicImports && data.publicImports.unchecked.length > 0
238
+ ? [
239
+ text(
240
+ `[info] Imports not checked: ${data.publicImports.unchecked.length}:`,
241
+ ),
242
+ records(data.publicImports.unchecked, {
243
+ fields: ['file', 'specifier', 'reason'],
244
+ }),
245
+ ]
246
+ : []),
237
247
  );
238
248
  }
239
249
 
@@ -392,6 +392,97 @@ describe('doctor: the computer-level agent text', () => {
392
392
  const A = '/home/me/.agents/skills/astryx/SKILL.md';
393
393
  const C = '/home/me/.claude/skills/astryx';
394
394
 
395
+ it('a skill naming `astryx` with no Astryx CLI on the search path: says whether it is current, and names the step it records', () => {
396
+ const check = (/** @type {Record<string, any>} */ over) =>
397
+ checkComputerAgentText({
398
+ nodeVersion: '22.13.0',
399
+ answeredBy: {cli: '1.2.0', core: '1.2.0', copy: 'carried'},
400
+ latest: null,
401
+ agentText: [{path: A, state: 'current'}],
402
+ agentTextCommand: 'astryx',
403
+ searchPathCommands: [],
404
+ cwd: os.tmpdir(),
405
+ ...over,
406
+ });
407
+ const recorded = check({agentTextInstall: 'pnpm add -g @astryxdesign/cli'});
408
+ // A package runner's own copy first on the search path does not count.
409
+ expect(
410
+ check({
411
+ agentTextInstall: 'pnpm add -g @astryxdesign/cli',
412
+ searchPathCommands: [
413
+ /** @type {any} */ ({
414
+ file: '/tmp/_npx/r/node_modules/.bin/astryx',
415
+ astryx: true,
416
+ runner: true,
417
+ }),
418
+ ],
419
+ }).fix,
420
+ ).toBe(
421
+ 'Run `pnpm add -g @astryxdesign/cli`, the step the skill names for when `astryx` is not found.',
422
+ );
423
+ expect(recorded.status).toBe('info');
424
+ expect(recorded.message).toContain(
425
+ `The computer-level agent text matches this release: ${A}. It tells agents to run \`astryx\`, but no \`astryx\` command is on the search path`,
426
+ );
427
+ expect(recorded.fix).toBe(
428
+ 'Run `pnpm add -g @astryxdesign/cli`, the step the skill names for when `astryx` is not found.',
429
+ );
430
+ // A skill from an earlier release records no step: npm's, worded as
431
+ // cli-on-path words it.
432
+ const older = check({
433
+ agentText: [{path: A, state: 'differs'}],
434
+ agentTextInstall: null,
435
+ });
436
+ expect(older.message).toContain(
437
+ "The computer-level agent text differs from this release's",
438
+ );
439
+ expect(older.fix).toBe(
440
+ 'Install it for the computer: `npm i -g @astryxdesign/cli`.',
441
+ );
442
+ // With the Astryx CLI anywhere on the search path, even behind another
443
+ // program (cli-on-path's to report), or a skill naming a host's command,
444
+ // there is nothing to restore.
445
+ for (const over of [
446
+ {
447
+ searchPathCommands: [
448
+ /** @type {any} */ ({
449
+ file: '/usr/bin/astryx',
450
+ astryx: true,
451
+ version: '1.2.0',
452
+ }),
453
+ ],
454
+ },
455
+ {
456
+ searchPathCommands: [
457
+ /** @type {any} */ ({file: '/opt/other/astryx', astryx: false}),
458
+ /** @type {any} */ ({
459
+ file: '/usr/bin/astryx',
460
+ astryx: true,
461
+ version: '1.2.0',
462
+ }),
463
+ ],
464
+ },
465
+ {agentTextCommand: 'acme astryx'},
466
+ // An `astryx` the scan cannot trace (a Volta, asdf or mise shim, or
467
+ // another program): it may run the CLI, so no report here.
468
+ {
469
+ searchPathCommands: [
470
+ /** @type {any} */ ({
471
+ file: '/home/me/.volta/bin/astryx',
472
+ astryx: false,
473
+ runner: false,
474
+ }),
475
+ ],
476
+ },
477
+ // Only a package runner's own copy: the CLI is still gone.
478
+ ]) {
479
+ const other = check(over);
480
+ expect(other.message).toBe(
481
+ `The computer-level agent text matches this release: ${A}.`,
482
+ );
483
+ }
484
+ });
485
+
395
486
  it('present and current, linked: no fix', () => {
396
487
  const check = at([
397
488
  {path: A, state: 'current'},
@@ -460,6 +551,14 @@ describe('doctor: the computer-level agent text', () => {
460
551
  const home = tmpDir('home');
461
552
  vi.stubEnv('HOME', home);
462
553
  vi.stubEnv('USERPROFILE', home);
554
+ // The CLI installed for the computer, first on the search path, as the
555
+ // skill expects.
556
+ const bin = tmpDir('bin');
557
+ fs.symlinkSync(
558
+ path.join(CLI_ROOT, 'clients', 'cli', 'bin', 'astryx.mjs'),
559
+ path.join(bin, 'astryx'),
560
+ );
561
+ vi.stubEnv('PATH', `${bin}${path.delimiter}${process.env.PATH ?? ''}`);
463
562
  try {
464
563
  const find = r =>
465
564
  r.envelope.data.checks.find(c => c.id === 'computer-agent-text');
@@ -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 -->";