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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/api/build/_adapter.mjs +37 -25
  2. package/api/build/blocks/blocks.d.mts +68 -20
  3. package/api/build/blocks/blocks.mjs +472 -196
  4. package/api/build/blocks/blocks.test.mjs +185 -168
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/build.type.mjs +1 -1
  7. package/api/build/kit/answer.d.mts +4 -1
  8. package/api/build/kit/answer.mjs +11 -3
  9. package/api/build/kit/signals.d.mts +11 -0
  10. package/api/build/kit/signals.mjs +8 -7
  11. package/api/build/tree.mjs +2 -1
  12. package/api/build/tree.test.mjs +27 -27
  13. package/api/component/_adapter.mjs +39 -5
  14. package/api/discover/_adapter.d.mts +1 -2
  15. package/api/discover/_adapter.mjs +6 -8
  16. package/api/discover/discover.mjs +0 -1
  17. package/api/docs/_adapter.mjs +4 -0
  18. package/api/doctor/_adapter.d.mts +24 -10
  19. package/api/doctor/_adapter.mjs +28 -25
  20. package/api/doctor/doctor.d.mts +7 -4
  21. package/api/doctor/doctor.mjs +52 -14
  22. package/api/doctor/doctor.test.mjs +58 -0
  23. package/api/integration/validate-integration-gaps.test.mjs +3 -0
  24. package/api/integration/validateIntegration.doc.mjs +1 -1
  25. package/api/template/template.mjs +5 -1
  26. package/assets/docs/tree/checks.doc.mjs +1 -1
  27. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  28. package/clients/cli/index.mjs +25 -8
  29. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  30. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  31. package/foundation/agent-docs/agent-docs.mjs +5 -5
  32. package/foundation/agent-docs/computer-agent-text.mjs +16 -1
  33. package/foundation/agent-docs/computer-agent-text.test.mjs +23 -2
  34. package/foundation/integrations/public-imports.d.mts +37 -0
  35. package/foundation/integrations/public-imports.mjs +839 -46
  36. package/foundation/integrations/public-imports.test.mjs +971 -46
  37. package/foundation/release/global-state.d.mts +8 -4
  38. package/foundation/release/global-state.mjs +4 -2
  39. package/foundation/release/notices.d.mts +62 -8
  40. package/foundation/release/notices.mjs +136 -25
  41. package/foundation/release/notices.test.mjs +21 -0
  42. package/foundation/text/string-utils.d.mts +2 -1
  43. package/foundation/text/string-utils.mjs +16 -5
  44. package/foundation/text/suggest-order.d.mts +72 -0
  45. package/foundation/text/suggest-order.mjs +363 -0
  46. package/foundation/text/suggest-order.test.mjs +259 -0
  47. package/package.json +9 -9
@@ -77,7 +77,7 @@
77
77
  * @property {boolean} data.directMatch True when the top page template is a confident direct match.
78
78
  * @property {BuildStart | null} data.start The page template to start from: the ranker's pick, else the app shell. Null only when the kit is narrowed to components or hooks (`type`), or when the project has no page template to offer.
79
79
  * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.pages Closest page templates by search (≤3). Each entry's `command` carries `--skeleton` when `directMatch` is false, so it previews the layout; `start.command` is the scaffold.
80
- * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.blocks Drop-in block patterns covering parts of the idea (≤5).
80
+ * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.blocks Drop-in block patterns covering parts of the idea (≤5), best first. A block search returned keeps search's score and reason; any other block carries the block picker's relative score (100 for its best candidate, never below 1) and reason, so the two kinds of score are not comparable.
81
81
  * @property {import('../search/search.type.mjs').SearchResultEntry[]} data.domain Idea-specific components/hooks (≤6), excluding frame/foundation.
82
82
  * @property {string[]} data.frame Always-on page-shell component names. Every page template already uses them.
83
83
  * @property {string[]} data.foundation Always-on layout/typography/action component names. Every page template already uses them.
@@ -10,6 +10,9 @@
10
10
  *
11
11
  * @param {import('./signals.mjs').KitSignals} signals
12
12
  * @param {string[]} [blocks] block names; build's own when omitted
13
+ * @param {Map<string, import('../../search/search.type.mjs').SearchResultEntry>} [picked]
14
+ * the block picker's own entry (its real score and reason) for each named
15
+ * block search did not return
13
16
  * @returns {import('../build.type.mjs').BuildKitResponse}
14
17
  */
15
- export function kitAnswer(signals: import("./signals.mjs").KitSignals, blocks?: string[]): import("../build.type.mjs").BuildKitResponse;
18
+ export function kitAnswer(signals: import("./signals.mjs").KitSignals, blocks?: string[], picked?: Map<string, import("../../search/search.type.mjs").SearchResultEntry>): import("../build.type.mjs").BuildKitResponse;
@@ -32,9 +32,16 @@ const THIN_KIT = 3;
32
32
  *
33
33
  * @param {import('./signals.mjs').KitSignals} signals
34
34
  * @param {string[]} [blocks] block names; build's own when omitted
35
+ * @param {Map<string, import('../../search/search.type.mjs').SearchResultEntry>} [picked]
36
+ * the block picker's own entry (its real score and reason) for each named
37
+ * block search did not return
35
38
  * @returns {import('../build.type.mjs').BuildKitResponse}
36
39
  */
37
- export function kitAnswer(signals, blocks = signals.kitBlocks) {
40
+ export function kitAnswer(
41
+ signals,
42
+ blocks = signals.kitBlocks,
43
+ picked = new Map(),
44
+ ) {
38
45
  // Entries by name, in build's order: two packages can ship a block with the
39
46
  // same name, and each name in `blocks` takes the next entry of that name, so
40
47
  // both stay listed.
@@ -48,11 +55,12 @@ export function kitAnswer(signals, blocks = signals.kitBlocks) {
48
55
  .flatMap(name => {
49
56
  const entry = own.get(name)?.shift();
50
57
  if (entry) return [entry];
51
- // A block build does not name itself keeps search's own entry, once.
58
+ // A block build does not name itself keeps search's own entry, once;
59
+ // one search did not return keeps the picker's entry.
52
60
  const found =
53
61
  own.has(name) || added.has(name)
54
62
  ? undefined
55
- : signals.searchedEntries.get(name);
63
+ : (signals.searchedEntries.get(name) ?? picked.get(name));
56
64
  if (!found) return [];
57
65
  added.add(name);
58
66
  return [found];
@@ -65,4 +65,15 @@ export type KitSignals = {
65
65
  * the blocks, named, searched or scaffoldable, whose package is not Core's
66
66
  */
67
67
  foreign: string[];
68
+ /**
69
+ * every block the project can scaffold
70
+ */
71
+ catalog: import("../_adapter.mjs").BlockTemplate[];
72
+ /**
73
+ * every component, with its keywords
74
+ */
75
+ components: {
76
+ name: string;
77
+ keywords?: string[];
78
+ }[];
68
79
  };
@@ -103,6 +103,8 @@ const ALWAYS = new Set([...FRAME, ...FOUNDATION]);
103
103
  * @property {Map<string, SearchResultEntry>} searchedEntries search's entry for each of those blocks (the first of a name)
104
104
  * @property {Map<string, string>} blockText each of those blocks' display name and description, from the catalog
105
105
  * @property {string[]} foreign the blocks, named, searched or scaffoldable, whose package is not Core's
106
+ * @property {import('../_adapter.mjs').BlockTemplate[]} catalog every block the project can scaffold
107
+ * @property {{name: string, keywords?: string[]}[]} components every component, with its keywords
106
108
  */
107
109
 
108
110
  /**
@@ -232,13 +234,10 @@ export async function kitSignals(query, options = {}) {
232
234
  // A part of a page starts where it lives (spec:AST-048/FR3); the project's
233
235
  // own components say what a part is. The search above already gathered them
234
236
  // unless it was narrowed to templates.
235
- const kind = wantsPages
236
- ? ideaKind(
237
- query,
238
- catalog,
239
- searchedComponents(result) ?? (await loadComponents(cwd)),
240
- )
241
- : 'page';
237
+ const components = wantsPages
238
+ ? (searchedComponents(result) ?? (await loadComponents(cwd)))
239
+ : [];
240
+ const kind = wantsPages ? ideaKind(query, catalog, components) : 'page';
242
241
  const chosen = wantsPages
243
242
  ? chooseStart(ranked, kind, matchedPages, directMatch, catalog, query)
244
243
  : null;
@@ -283,6 +282,8 @@ export async function kitSignals(query, options = {}) {
283
282
  .filter(b => searchedBlocks.some(r => r.name === b.name))
284
283
  .map(b => [b.name, `${b.displayName} ${b.description}`]),
285
284
  ),
285
+ catalog: templates.blocks,
286
+ components,
286
287
  foreign: [
287
288
  ...new Set(
288
289
  [...blocksKept, ...searchedBlocks, ...templates.blocks]
@@ -35,7 +35,8 @@ const main = defineSearcher({
35
35
  run: async (request, ctx) => {
36
36
  const signals = await kitSignals(request.query, request.options);
37
37
  if (!ctx.blocks) return kitAnswer(signals);
38
- return kitAnswer(signals, pickBlocks(request.query, signals, ctx.blocks));
38
+ const picked = pickBlocks(request.query, signals, ctx.blocks);
39
+ return kitAnswer(signals, picked.names, picked.entries);
39
40
  },
40
41
  });
41
42
 
@@ -60,55 +60,55 @@ const PINNED = [
60
60
  'analytics dashboard with a KPI row and a sortable table',
61
61
  [
62
62
  'TableSortableTable',
63
- 'TableRichCellTable',
64
- 'TableBulkActionsTable',
65
63
  'TableGridDividersTable',
66
- 'TableRowExpansionTable',
64
+ 'TableShowcase',
65
+ 'TableGroupedRowsTable',
66
+ 'TableStripedTable',
67
67
  ],
68
68
  ],
69
69
  [
70
70
  'settings page with notification toggles and a save bar',
71
71
  [
72
- 'ToggleButtonColor',
73
- 'ToggleButtonGroup',
74
- 'ToggleButtonGroupShowcase',
75
- 'ToggleButtonGroupVertical',
76
- 'ToggleButtonIconSwap',
72
+ 'SwitchShowcase',
73
+ 'SwitchSettingsPanel',
74
+ 'ToggleButtonShowcase',
75
+ 'ToggleButtonStates',
76
+ 'SwitchWithDescription',
77
77
  ],
78
78
  ],
79
79
  [
80
80
  'empty state for a question bank with an import button',
81
81
  [
82
- 'EmptyStateActions',
83
- 'EmptyStateCompact',
84
82
  'EmptyStateContainer',
85
83
  'EmptyStateShowcase',
86
- 'BannerWithActionButton',
84
+ 'EmptyStateCompact',
85
+ 'EmptyStateActions',
86
+ 'CommandPaletteEmptyShowcase',
87
87
  ],
88
88
  ],
89
89
  [
90
90
  'login form with single sign-on buttons',
91
91
  [
92
- 'DialogFormDialog',
92
+ 'ButtonWithIcon',
93
93
  'CardWithInnerLayout',
94
- 'ButtonGroupBasic',
95
- 'ToggleButtonGroup',
96
- 'BannerWithActionButton',
94
+ 'ButtonVariants',
95
+ 'FormLayoutShowcase',
96
+ 'FormLayoutMixedControls',
97
97
  ],
98
98
  ],
99
99
  [
100
100
  'calendar for booking appointments',
101
101
  [
102
- 'CalendarRangeWithValue',
103
102
  'CalendarSingle',
104
- 'CalendarTwoMonths',
105
- 'CalendarConstraints',
106
103
  'CalendarShowcase',
104
+ 'CalendarConstraints',
105
+ 'CalendarRangeWithValue',
106
+ 'CalendarTwoMonths',
107
107
  ],
108
108
  ],
109
109
  [
110
110
  'kanban board for sprint tasks with a filter bar',
111
- ['ToolbarTableFilter', 'PowerSearchFullFeatured'],
111
+ ['ToolbarTableFilter', 'PowerSearchShowcase'],
112
112
  ],
113
113
  ];
114
114
 
@@ -125,16 +125,15 @@ afterAll(() => {
125
125
  });
126
126
 
127
127
  describe('build tree', () => {
128
- it('keeps the blocks a request names in build’s slots', async () => {
129
- const phrase = 'calendar for booking appointments';
128
+ it('keeps a block the request names by its exact name in build’s slot', async () => {
129
+ const phrase = 'calendar for booking appointments with CalendarTwoMonths';
130
130
  const answer = await build(phrase, {cwd: REPO});
131
131
  const own = await withListingCache(() => buildKit(phrase, {cwd: REPO}));
132
132
  if (answer?.type !== 'build.kit' || own.type !== 'build.kit')
133
133
  throw new Error('expected a kit');
134
- own.data.blocks.forEach((b, k) => {
135
- if (b.name.startsWith('Calendar'))
136
- expect(answer.data.blocks[k].name).toBe(b.name);
137
- });
134
+ const k = own.data.blocks.findIndex(b => b.name === 'CalendarTwoMonths');
135
+ expect(k).toBeGreaterThanOrEqual(0);
136
+ expect(answer.data.blocks[k].name).toBe('CalendarTwoMonths');
138
137
  });
139
138
 
140
139
  it('runs with the network and subprocesses blocked', async () => {
@@ -166,8 +165,9 @@ describe('build tree', () => {
166
165
  expect(answer.data.start?.alternatives).toEqual(
167
166
  own.data.start?.alternatives,
168
167
  );
169
- // Every block is build's own entry or one search returned, with its real
170
- // score and reason; never more blocks than build's own.
168
+ // Every block is build's own entry, one search returned, or the picker's
169
+ // own, each with its real score and reason; never more blocks than
170
+ // build's own.
171
171
  expect(answer.data.blocks.length).toBe(own.data.blocks.length);
172
172
  for (const b of answer.data.blocks) {
173
173
  expect(b.score).toBeGreaterThan(0);
@@ -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.