@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
@@ -44,6 +44,10 @@ import {Project} from '../../foundation/config/project.mjs';
44
44
  import {loadComponentDoc as loadValidatedComponentDoc} from '../../foundation/discovery/component-loader.mjs';
45
45
  import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
46
46
  import {searchComponents} from '../../foundation/text/string-utils.mjs';
47
+ import {
48
+ rankComponentSuggestions,
49
+ synonymMatches,
50
+ } from '../../foundation/text/suggest-order.mjs';
47
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
48
52
  import {
49
53
  componentLinkProvider,
@@ -51,6 +55,28 @@ import {
51
55
  loadDocsCatalog,
52
56
  } from '../docs/_adapter.mjs';
53
57
 
58
+ /** @type {Record<string, {synonyms?: string[]}> | undefined} */
59
+ let cards;
60
+ /**
61
+ * Search's component cards (each component's other names), read once.
62
+ * @returns {Record<string, {synonyms?: string[]}>}
63
+ */
64
+ function searchCards() {
65
+ if (!cards) {
66
+ try {
67
+ cards = JSON.parse(
68
+ fs.readFileSync(
69
+ new URL('../search/_cards.json', import.meta.url),
70
+ 'utf8',
71
+ ),
72
+ );
73
+ } catch {
74
+ cards = {};
75
+ }
76
+ }
77
+ return /** @type {Record<string, {synonyms?: string[]}>} */ (cards);
78
+ }
79
+
54
80
  export {CORE_PACKAGE, unscopedComponentOwners};
55
81
 
56
82
  /**
@@ -463,12 +489,20 @@ export async function resolveUnscopedDoc(dirName, {coreDir, cwd, name}) {
463
489
  resolvedOwnerPackage = CORE_PACKAGE;
464
490
  resolvedSourcePath = findComponentSource(coreDir, resolvedName);
465
491
  } else {
492
+ // How many to suggest: the near-top results, at most five and at
493
+ // least two. Which ones, and in what order, is the suggestion
494
+ // ranking's call.
466
495
  const threshold = Math.max(topScore - 20, 1);
467
- const candidates = results
468
- .filter(r => r.score >= threshold)
469
- .slice(0, 5);
470
- if (candidates.length < 2)
471
- candidates.push(...results.slice(candidates.length, 2));
496
+ const count = Math.max(
497
+ results.filter(r => r.score >= threshold).slice(0, 5).length,
498
+ Math.min(2, results.length),
499
+ );
500
+ const candidates = rankComponentSuggestions(
501
+ dirName,
502
+ results,
503
+ Object.values(components).flat(),
504
+ synonymMatches(dirName, searchCards()),
505
+ ).slice(0, count);
472
506
  throw new AstryxError(
473
507
  `No component named "${name}"`,
474
508
  candidates.map(c => ({name: c.name, reason: c.reason})),
@@ -43,12 +43,11 @@ export function hasSources(project: Project | undefined): boolean;
43
43
  * @param {Project | undefined} project
44
44
  * @param {Array<{name: string}>} installed
45
45
  * @param {Set<string>} declared
46
- * @param {(name: string, version?: string) => string} add
47
46
  * @returns {Promise<import('./discover.type.mjs').DiscoverAvailableEntry[]>}
48
47
  */
49
48
  export function computerAvailableEntries(project: Project | undefined, installed: Array<{
50
49
  name: string;
51
- }>, declared: Set<string>, add: (name: string, version?: string) => string): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
50
+ }>, declared: Set<string>): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
52
51
  /**
53
52
  * Package names the project's package.json declares in any dependency field.
54
53
  * @param {Project | undefined} project
@@ -25,6 +25,7 @@ import {
25
25
  availableComputerIntegrations,
26
26
  } from '../../foundation/config/project.mjs';
27
27
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
28
+ import {projectAddCommand} from '../../foundation/release/notices.mjs';
28
29
  import {hostedRun} from '../../foundation/runtime/package-root.mjs';
29
30
  import {
30
31
  scanAllPackages,
@@ -274,17 +275,14 @@ const COMPUTER_SOURCE = 'installed for this computer';
274
275
  * @param {Project | undefined} project
275
276
  * @param {Array<{name: string}>} installed
276
277
  * @param {Set<string>} declared
277
- * @param {(name: string, version?: string) => string} add
278
278
  * @returns {Promise<import('./discover.type.mjs').DiscoverAvailableEntry[]>}
279
279
  */
280
- export async function computerAvailableEntries(
281
- project,
282
- installed,
283
- declared,
284
- add,
285
- ) {
280
+ export async function computerAvailableEntries(project, installed, declared) {
286
281
  const cwd = project?.cwd ?? process.cwd();
287
282
  if (isOutsideProject(cwd)) return [];
283
+ // The same command doctor names: in the project spec:AST-040 FR9 defines,
284
+ // and none where FR9 finds no project.
285
+ const add = projectAddCommand(cwd);
288
286
  const have = new Set([...installed.map(pkg => pkg.name), ...declared]);
289
287
  return (await availableComputerIntegrations(cwd, have)).map(c => ({
290
288
  name: c.name,
@@ -292,7 +290,7 @@ export async function computerAvailableEntries(
292
290
  ...(c.version ? {version: c.version} : {}),
293
291
  ...(c.description ? {description: c.description} : {}),
294
292
  source: COMPUTER_SOURCE,
295
- install: add(c.name),
293
+ ...(add ? {install: add(c.name)} : {}),
296
294
  }));
297
295
  }
298
296
 
@@ -223,7 +223,6 @@ export async function discover(query, options = {}) {
223
223
  project,
224
224
  packages,
225
225
  declared,
226
- add,
227
226
  );
228
227
  const fromSources = officialFirst(
229
228
  availableEntries(catalog, packages, declared, {
@@ -71,6 +71,7 @@ import {
71
71
  import {findCoreDir} from '../../foundation/fs/paths.mjs';
72
72
  import {AstryxError} from '../error.mjs';
73
73
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
74
+ import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
74
75
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
75
76
 
76
77
  export {OVERLAY_LANGUAGES, overlayLanguages};
@@ -1622,6 +1623,9 @@ export async function unknownTopicError(topic, catalog) {
1622
1623
  ...catalog.names().map(name => ({name, reason: 'available topic'})),
1623
1624
  ];
1624
1625
  }
1626
+ if (typeof topic === 'string') {
1627
+ suggestions = orderRouteSuggestions(topic, suggestions);
1628
+ }
1625
1629
  // A route that moved names where it went, ahead of the usual suggestions
1626
1630
  // (spec:AST-046 FR9, FR6).
1627
1631
  const moved = movedRoute(topic, tree);
@@ -108,13 +108,14 @@ export function outsideProject(cwd: string): boolean;
108
108
  /**
109
109
  * The commands that bring a project's own CLI and Core to one release, with
110
110
  * the project's package manager: Core up to the CLI, then its codemods, when
111
- * the CLI is newer; else the CLI to the Core's release.
111
+ * the CLI is newer; else the CLI to the Core's release. Null when no
112
+ * command fits (see `alignCliAndCore`).
112
113
  * @param {string} cwd
113
114
  * @param {string} cli
114
115
  * @param {string} core
115
- * @returns {string}
116
+ * @returns {string | null}
116
117
  */
117
- export function alignCommand(cwd: string, cli: string, core: string): string;
118
+ export function alignCommand(cwd: string, cli: string, core: string): string | null;
118
119
  /**
119
120
  * The Core release the project at `cwd` names: installed, else locked, else
120
121
  * declared; the version the daily hint and notice compare against (spec
@@ -131,19 +132,32 @@ export function projectCoreVersion(cwd: string): string | null;
131
132
  export function projectHasOwnCli(cwd: string): boolean;
132
133
  /**
133
134
  * The command that adds the CLI at `version` with the project's package
134
- * manager.
135
+ * manager, and the Core it matches: from a folder whose package.json declares
136
+ * no Astryx package, in the Astryx project above at that project's Core; null
137
+ * when there is none (see `cliInstallAdvice`).
135
138
  * @param {string} cwd
136
139
  * @param {string} version
137
- * @returns {string}
140
+ * @returns {{command: string, core: string} | null}
138
141
  */
139
- export function addCliCommandFor(cwd: string, version: string): string;
142
+ export function addCliCommandFor(cwd: string, version: string): {
143
+ command: string;
144
+ core: string;
145
+ } | null;
140
146
  /**
141
- * The command that adds a package with the folder's package manager, read
142
- * from its lockfiles and `packageManager` field.
147
+ * The command that adds a package to the project of `cwd`; null in a folder
148
+ * that belongs to no project or whose package.json is not the project's (see
149
+ * `projectAddCommand`).
143
150
  * @param {string} cwd
144
- * @returns {(name: string) => string}
151
+ * @returns {((name: string) => string) | null}
152
+ */
153
+ export function installCommandFor(cwd: string): ((name: string) => string) | null;
154
+ /**
155
+ * Whether `cwd` is inside a project whose package.json is not the project's,
156
+ * so advice points at the project's folder (see `installFolder`).
157
+ * @param {string} cwd
158
+ * @returns {boolean}
145
159
  */
146
- export function installCommandFor(cwd: string): (name: string) => string;
160
+ export function insideProjectElsewhere(cwd: string): boolean;
147
161
  export { resolveRecordedTheme } from "../theme/theme.mjs";
148
162
  export { collectUnloadedFonts } from "../theme/build/font-warning.mjs";
149
163
  export const SOURCE_EXTENSIONS: Set<string>;
@@ -10,20 +10,17 @@ import {
10
10
  stateLockHolder,
11
11
  } from '../../foundation/release/global-state.mjs';
12
12
  import {
13
- addCliCommand,
14
13
  alignCliAndCore,
14
+ cliInstallAdvice,
15
+ installFolder,
16
+ projectAddCommand,
15
17
  globalBehind,
16
18
  globalUpgradeCommand,
17
19
  lastNoticeSkip,
18
20
  projectLag,
19
21
  } from '../../foundation/release/notices.mjs';
20
- import {
21
- coreVersionOf,
22
- isGlobalCopy,
23
- projectRootOf,
24
- } from '../../foundation/release/choose.mjs';
22
+ import {coreVersionOf, isGlobalCopy} from '../../foundation/release/choose.mjs';
25
23
  import {readReleaseFacts} from '../../foundation/release/project.mjs';
26
- import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
27
24
  import {astryxCommandsOnSearchPath} from '../../foundation/env/search-path.mjs';
28
25
  import {readDeclaredDependencies} from '../../foundation/integrations/autolink.mjs';
29
26
  import {
@@ -348,11 +345,12 @@ export function outsideProject(/** @type {string} */ cwd) {
348
345
  /**
349
346
  * The commands that bring a project's own CLI and Core to one release, with
350
347
  * the project's package manager: Core up to the CLI, then its codemods, when
351
- * the CLI is newer; else the CLI to the Core's release.
348
+ * the CLI is newer; else the CLI to the Core's release. Null when no
349
+ * command fits (see `alignCliAndCore`).
352
350
  * @param {string} cwd
353
351
  * @param {string} cli
354
352
  * @param {string} core
355
- * @returns {string}
353
+ * @returns {string | null}
356
354
  */
357
355
  export function alignCommand(cwd, cli, core) {
358
356
  return alignCliAndCore({cwd, cli, core});
@@ -380,30 +378,35 @@ export function projectHasOwnCli(cwd) {
380
378
 
381
379
  /**
382
380
  * The command that adds the CLI at `version` with the project's package
383
- * manager.
381
+ * manager, and the Core it matches: from a folder whose package.json declares
382
+ * no Astryx package, in the Astryx project above at that project's Core; null
383
+ * when there is none (see `cliInstallAdvice`).
384
384
  * @param {string} cwd
385
385
  * @param {string} version
386
- * @returns {string}
386
+ * @returns {{command: string, core: string} | null}
387
387
  */
388
388
  export function addCliCommandFor(cwd, version) {
389
- return addCliCommand(projectRootOf(readReleaseFacts(cwd)) ?? cwd, version);
389
+ const advice = cliInstallAdvice({cwd, core: version});
390
+ return advice?.command ? {command: advice.command, core: advice.core} : null;
390
391
  }
391
392
 
392
393
  /**
393
- * The command that adds a package with the folder's package manager, read
394
- * from its lockfiles and `packageManager` field.
394
+ * The command that adds a package to the project of `cwd`; null in a folder
395
+ * that belongs to no project or whose package.json is not the project's (see
396
+ * `projectAddCommand`).
395
397
  * @param {string} cwd
396
- * @returns {(name: string) => string}
398
+ * @returns {((name: string) => string) | null}
397
399
  */
398
400
  export function installCommandFor(cwd) {
399
- const pm = detectPackageManager(cwd);
400
- const verb =
401
- pm === 'pnpm'
402
- ? 'pnpm add'
403
- : pm === 'yarn'
404
- ? 'yarn add'
405
- : pm === 'bun'
406
- ? 'bun add'
407
- : 'npm install';
408
- return name => `${verb} ${name}`;
401
+ return projectAddCommand(cwd);
402
+ }
403
+
404
+ /**
405
+ * Whether `cwd` is inside a project whose package.json is not the project's,
406
+ * so advice points at the project's folder (see `installFolder`).
407
+ * @param {string} cwd
408
+ * @returns {boolean}
409
+ */
410
+ export function insideProjectElsewhere(cwd) {
411
+ return installFolder(cwd)?.moved === true;
409
412
  }
@@ -259,15 +259,18 @@ export function checkComputerIntegrations(ctx: ComputerContext): DoctorCheck;
259
259
  * Inside a project, the integrations installed for the computer that the
260
260
  * project does not install: available, never used (spec AST-081 FR12).
261
261
  * Always info.
262
- * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: (name: string) => string}} input
262
+ * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: ((name: string) => string) | null, elsewhere?: boolean}} input
263
263
  * `install`: the command that adds a package with the project's package
264
- * manager (read by the adapter)
264
+ * manager (read by the adapter); null when the folder belongs to no
265
+ * project, or `elsewhere`: its package.json is not the project's, where the
266
+ * fix points at the project's folder
265
267
  * @returns {DoctorCheck}
266
268
  */
267
- export function checkComputerIntegrationsAvailable({ installed, candidates, install }: {
269
+ export function checkComputerIntegrationsAvailable({ installed, candidates, install, elsewhere }: {
268
270
  installed: Set<string>;
269
271
  candidates: import("../../foundation/integrations/computer-integrations.mjs").ComputerIntegrationCandidate[];
270
- install: (name: string) => string;
272
+ install: ((name: string) => string) | null;
273
+ elsewhere?: boolean;
271
274
  }): DoctorCheck;
272
275
  /**
273
276
  * Run all diagnostic checks and return a structured report.
@@ -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([]);
@@ -70,7 +70,12 @@ import {
70
70
  rootProblem,
71
71
  } from '../../foundation/integrations/validate-contributions.mjs';
72
72
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
73
+ import {cliPeerVersionProblem} from '../../foundation/integrations/cli-peer-version.mjs';
73
74
  import {publicImportIssues} from '../../foundation/integrations/public-imports.mjs';
75
+ import {runChoice} from '../../foundation/release/run-context.mjs';
76
+
77
+ /** The running CLI is outside the package's `@astryxdesign/cli` peer range. */
78
+ const CLI_PEER_VERSION = 'cli_peer_version';
74
79
 
75
80
  export {validateLoadedIntegration, isListedIssue};
76
81
 
@@ -281,13 +286,15 @@ async function findUnreachableContributionIssues(
281
286
  * Shared core for the local and installed entry points.
282
287
  * @param {string} packageDir
283
288
  * @param {{name: string, version?: string}} identity
284
- * @param {{scanUnreachable?: boolean}} [options]
289
+ * @param {{scanUnreachable?: boolean, own?: boolean, cwd?: string}} [options]
290
+ * `own`: the package is the one being authored in the current folder;
291
+ * `cwd`: the folder whose package manager an install command names
285
292
  * @returns {Promise<ValidateResult>}
286
293
  */
287
294
  async function validateAtPackageDir(
288
295
  packageDir,
289
296
  identity,
290
- {scanUnreachable = false} = {},
297
+ {scanUnreachable = false, own = false, cwd = packageDir} = {},
291
298
  ) {
292
299
  /** @type {Issue[]} */
293
300
  const issues = [];
@@ -429,6 +436,24 @@ async function validateAtPackageDir(
429
436
  issues.push(issue);
430
437
  }
431
438
  }
439
+ // The running CLI outside the package's `@astryxdesign/cli` peer range is a
440
+ // note for the same reason. It is built here, not among the contribution
441
+ // checks, so `integration verify` (which reports their layout findings)
442
+ // does not see it.
443
+ // The version an upgrade starts from is the project's: its own CLI's, or,
444
+ // with none, its Core's, as the project-upgrade notice takes it.
445
+ const choice = runChoice(cwd);
446
+ const from =
447
+ choice.inProject && choice.copy === 'starting' && choice.coreVersion
448
+ ? choice.coreVersion
449
+ : undefined;
450
+ const peerProblem = cliPeerVersionProblem(loaded, undefined, cwd, {
451
+ own,
452
+ from,
453
+ });
454
+ if (peerProblem) {
455
+ (result.notes ??= []).push({code: CLI_PEER_VERSION, message: peerProblem});
456
+ }
432
457
  if (loaded.themes && !rootProblem(loaded.themes))
433
458
  issues.push(...unreadThemeFolderIssues(packageDir, loaded));
434
459
  // What the docs say that no reader serves: a prop listed twice, an
@@ -518,7 +543,7 @@ export async function validateLocalIntegration(cwd = process.cwd()) {
518
543
  const result = await validateAtPackageDir(
519
544
  packageDir,
520
545
  {name, version: pkg.version},
521
- {scanUnreachable: true},
546
+ {scanUnreachable: true, own: true},
522
547
  );
523
548
  (result.listed ??= []).unshift(
524
549
  ...fields,
@@ -653,10 +678,11 @@ export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
653
678
  };
654
679
  }
655
680
 
656
- return validateAtPackageDir(packageDir, {
657
- name: pkg.name ?? spec,
658
- version: pkg.version,
659
- });
681
+ return validateAtPackageDir(
682
+ packageDir,
683
+ {name: pkg.name ?? spec, version: pkg.version},
684
+ {cwd},
685
+ );
660
686
  }
661
687
 
662
688
  /**
@@ -37,7 +37,9 @@ export type ValidateIntegrationResponse = {
37
37
  type: "integration.validate";
38
38
  /**
39
39
  * `notes`: information beside the issues that fails nothing, such as
40
- * `invalid_cli_command`, a `cliCommand` that was ignored as malformed, and
40
+ * `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
41
+ * `cli_peer_version`, the running CLI outside the package's
42
+ * `@astryxdesign/cli` peer range; and
41
43
  * the package layout findings added after the last minor release, each with
42
44
  * its fix in the message: two docs for one component
43
45
  * (`duplicate_component_doc`), a root reached through a symlink
@@ -41,7 +41,9 @@
41
41
  * @property {'integration.validate'} type
42
42
  * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport, publicImports?: PublicImportsReport}} data
43
43
  * `notes`: information beside the issues that fails nothing, such as
44
- * `invalid_cli_command`, a `cliCommand` that was ignored as malformed, and
44
+ * `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
45
+ * `cli_peer_version`, the running CLI outside the package's
46
+ * `@astryxdesign/cli` peer range; and
45
47
  * the package layout findings added after the last minor release, each with
46
48
  * its fix in the message: two docs for one component
47
49
  * (`duplicate_component_doc`), a root reached through a symlink