@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
@@ -59,51 +59,51 @@ const PINNED = [
59
59
  [
60
60
  'analytics dashboard with a KPI row and a sortable table',
61
61
  [
62
- 'PaginationPageSize',
63
- 'GridDashboardLayout',
64
- 'TableBulkActionsTable',
62
+ 'TableSortableTable',
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
- 'ToolbarTableFilter',
84
+ 'EmptyStateCompact',
85
+ 'EmptyStateActions',
86
+ 'CommandPaletteEmptyShowcase',
87
87
  ],
88
88
  ],
89
89
  [
90
90
  'login form with single sign-on buttons',
91
91
  [
92
+ 'ButtonWithIcon',
92
93
  'CardWithInnerLayout',
93
- 'BottomSheetMobileKeyboard',
94
- 'ButtonGroupBasic',
95
- 'CollapsibleControlledAccordion',
96
- 'BottomSheetSwitcherReviewFlow',
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
  [
@@ -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,12 +165,21 @@ describe('build tree', () => {
166
165
  expect(answer.data.start?.alternatives).toEqual(
167
166
  own.data.start?.alternatives,
168
167
  );
169
- // The picker only re-orders build's own blocks: each keeps build's
170
- // entry (its real score and reason), none is added, none is dropped.
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
- for (const b of answer.data.blocks)
173
- expect(own.data.blocks.find(o => o.name === b.name)).toEqual(b);
172
+ for (const b of answer.data.blocks) {
173
+ expect(b.score).toBeGreaterThan(0);
174
+ expect(typeof b.reason).toBe('string');
175
+ const mine = own.data.blocks.find(o => o.name === b.name);
176
+ if (mine) expect(mine).toEqual(b);
177
+ }
174
178
  expect(answer.data.blocks.map(b => b.name)).toEqual(blocks);
179
+ // Never longer than build's own answer for the same request.
180
+ expect(Buffer.byteLength(JSON.stringify(answer))).toBeLessThanOrEqual(
181
+ Buffer.byteLength(JSON.stringify(own)),
182
+ );
175
183
  });
176
184
  }
177
185
  });
@@ -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})),
@@ -64,6 +64,7 @@ function writeIntegration(name, components, peers) {
64
64
  type: 'component',
65
65
  name: componentName,
66
66
  displayName: componentName,
67
+ import: `${name}/components/${componentName}`,
67
68
  ...(replaces ? {replaces} : {}),
68
69
  keywords: ['acme'],
69
70
  usage: {description: `${componentName} for Acme apps.`},
@@ -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);
@@ -64,8 +64,11 @@ export function computerIntegrationsOutside(cwd: string): Promise<{
64
64
  */
65
65
  export function computerIntegrationsToAdd(cwd: string, loadedNames: string[]): Promise<import("../../foundation/integrations/computer-integrations.mjs").ComputerIntegrationCandidate[]>;
66
66
  /**
67
- * The computer-level agent text's setting and its state on disk.
68
- * @returns {{settings: import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings, entries: Array<{path: string, state: import('../../foundation/agent-docs/computer-agent-text.mjs').ComputerAgentTextState, link?: true}>}}
67
+ * The computer-level agent text's setting, its state on disk, and the command
68
+ * the skill file tells agents to run and the install step it records for when
69
+ * that command is not found (each null when there is no file, or it names
70
+ * none).
71
+ * @returns {{settings: import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings, entries: Array<{path: string, state: import('../../foundation/agent-docs/computer-agent-text.mjs').ComputerAgentTextState, link?: true}>, command: string | null, install: string | null}}
69
72
  */
70
73
  export function computerAgentTextState(): {
71
74
  settings: import("../../foundation/env/user-settings.mjs").ComputerAgentTextSettings;
@@ -74,6 +77,8 @@ export function computerAgentTextState(): {
74
77
  state: import("../../foundation/agent-docs/computer-agent-text.mjs").ComputerAgentTextState;
75
78
  link?: true;
76
79
  }>;
80
+ command: string | null;
81
+ install: string | null;
77
82
  };
78
83
  /**
79
84
  * The release facts doctor reports, read here so the checks stay pure
@@ -83,7 +88,7 @@ export function computerAgentTextState(): {
83
88
  * command that upgrades it.
84
89
  * @param {string} cwd
85
90
  * @param {{project: boolean}} options
86
- * @returns {{answeredBy: {cli: string, core: string | null, copy: string}, latest: string | null, globalBehind: ReturnType<typeof globalBehind> | null, projectLag: ReturnType<typeof projectLag> | null, lastNoticeSkip: ReturnType<typeof lastNoticeSkip>, lastCheckFailure: ReturnType<typeof lastCheckFailure>, stateLock: ReturnType<typeof stateLockHolder>, searchPathCommands: Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade: string | null}>}}
91
+ * @returns {{answeredBy: {cli: string, core: string | null, copy: string}, latest: string | null, globalBehind: ReturnType<typeof globalBehind> | null, projectLag: ReturnType<typeof projectLag> | null, lastNoticeSkip: ReturnType<typeof lastNoticeSkip>, lastCheckFailure: ReturnType<typeof lastCheckFailure>, stateLock: ReturnType<typeof stateLockHolder>, searchPathCommands: Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade: string | null, runner: boolean}>}}
87
92
  */
88
93
  export function releaseFacts(cwd: string, { project }: {
89
94
  project: boolean;
@@ -101,6 +106,7 @@ export function releaseFacts(cwd: string, { project }: {
101
106
  stateLock: ReturnType<typeof stateLockHolder>;
102
107
  searchPathCommands: Array<import("../../foundation/env/search-path.mjs").SearchPathCommand & {
103
108
  upgrade: string | null;
109
+ runner: boolean;
104
110
  }>;
105
111
  };
106
112
  /** Whether `cwd` is outside every project. */
@@ -108,13 +114,14 @@ export function outsideProject(cwd: string): boolean;
108
114
  /**
109
115
  * The commands that bring a project's own CLI and Core to one release, with
110
116
  * 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.
117
+ * the CLI is newer; else the CLI to the Core's release. Null when no
118
+ * command fits (see `alignCliAndCore`).
112
119
  * @param {string} cwd
113
120
  * @param {string} cli
114
121
  * @param {string} core
115
- * @returns {string}
122
+ * @returns {string | null}
116
123
  */
117
- export function alignCommand(cwd: string, cli: string, core: string): string;
124
+ export function alignCommand(cwd: string, cli: string, core: string): string | null;
118
125
  /**
119
126
  * The Core release the project at `cwd` names: installed, else locked, else
120
127
  * declared; the version the daily hint and notice compare against (spec
@@ -131,19 +138,32 @@ export function projectCoreVersion(cwd: string): string | null;
131
138
  export function projectHasOwnCli(cwd: string): boolean;
132
139
  /**
133
140
  * The command that adds the CLI at `version` with the project's package
134
- * manager.
141
+ * manager, and the Core it matches: from a folder whose package.json declares
142
+ * no Astryx package, in the Astryx project above at that project's Core; null
143
+ * when there is none (see `cliInstallAdvice`).
135
144
  * @param {string} cwd
136
145
  * @param {string} version
137
- * @returns {string}
146
+ * @returns {{command: string, core: string} | null}
138
147
  */
139
- export function addCliCommandFor(cwd: string, version: string): string;
148
+ export function addCliCommandFor(cwd: string, version: string): {
149
+ command: string;
150
+ core: string;
151
+ } | null;
140
152
  /**
141
- * The command that adds a package with the folder's package manager, read
142
- * from its lockfiles and `packageManager` field.
153
+ * The command that adds a package to the project of `cwd`; null in a folder
154
+ * that belongs to no project or whose package.json is not the project's (see
155
+ * `projectAddCommand`).
143
156
  * @param {string} cwd
144
- * @returns {(name: string) => string}
157
+ * @returns {((name: string) => string) | null}
158
+ */
159
+ export function installCommandFor(cwd: string): ((name: string) => string) | null;
160
+ /**
161
+ * Whether `cwd` is inside a project whose package.json is not the project's,
162
+ * so advice points at the project's folder (see `installFolder`).
163
+ * @param {string} cwd
164
+ * @returns {boolean}
145
165
  */
146
- export function installCommandFor(cwd: string): (name: string) => string;
166
+ export function insideProjectElsewhere(cwd: string): boolean;
147
167
  export { resolveRecordedTheme } from "../theme/theme.mjs";
148
168
  export { collectUnloadedFonts } from "../theme/build/font-warning.mjs";
149
169
  export const SOURCE_EXTENSIONS: Set<string>;
@@ -10,8 +10,10 @@ 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,
@@ -19,16 +21,18 @@ import {
19
21
  } from '../../foundation/release/notices.mjs';
20
22
  import {
21
23
  coreVersionOf,
24
+ installPlaceOf,
22
25
  isGlobalCopy,
23
- projectRootOf,
24
26
  } from '../../foundation/release/choose.mjs';
25
27
  import {readReleaseFacts} from '../../foundation/release/project.mjs';
26
- import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
27
28
  import {astryxCommandsOnSearchPath} from '../../foundation/env/search-path.mjs';
28
29
  import {readDeclaredDependencies} from '../../foundation/integrations/autolink.mjs';
29
30
  import {
31
+ computerSkillFile,
30
32
  displayHomePath,
31
33
  inspectComputerAgentText,
34
+ skillCommandOf,
35
+ skillInstallStepOf,
32
36
  } from '../../foundation/agent-docs/computer-agent-text.mjs';
33
37
  import {computerAgentTextSettings} from '../../foundation/env/user-settings.mjs';
34
38
  import * as fs from 'node:fs';
@@ -291,12 +295,29 @@ function declaredPackageNames(cwd) {
291
295
  }
292
296
 
293
297
  /**
294
- * The computer-level agent text's setting and its state on disk.
295
- * @returns {{settings: import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings, entries: Array<{path: string, state: import('../../foundation/agent-docs/computer-agent-text.mjs').ComputerAgentTextState, link?: true}>}}
298
+ * The computer-level agent text's setting, its state on disk, and the command
299
+ * the skill file tells agents to run and the install step it records for when
300
+ * that command is not found (each null when there is no file, or it names
301
+ * none).
302
+ * @returns {{settings: import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings, entries: Array<{path: string, state: import('../../foundation/agent-docs/computer-agent-text.mjs').ComputerAgentTextState, link?: true}>, command: string | null, install: string | null}}
296
303
  */
297
304
  export function computerAgentTextState() {
298
305
  const settings = computerAgentTextSettings();
299
- return {settings, entries: inspectComputerAgentText({links: settings.links})};
306
+ let command = null;
307
+ let install = null;
308
+ try {
309
+ const text = fs.readFileSync(computerSkillFile(), 'utf8');
310
+ command = skillCommandOf(text);
311
+ install = skillInstallStepOf(text);
312
+ } catch {
313
+ // No skill file, or one that cannot be read: no command to check.
314
+ }
315
+ return {
316
+ settings,
317
+ entries: inspectComputerAgentText({links: settings.links}),
318
+ command,
319
+ install,
320
+ };
300
321
  }
301
322
 
302
323
  export {displayHomePath};
@@ -309,7 +330,7 @@ export {displayHomePath};
309
330
  * command that upgrades it.
310
331
  * @param {string} cwd
311
332
  * @param {{project: boolean}} options
312
- * @returns {{answeredBy: {cli: string, core: string | null, copy: string}, latest: string | null, globalBehind: ReturnType<typeof globalBehind> | null, projectLag: ReturnType<typeof projectLag> | null, lastNoticeSkip: ReturnType<typeof lastNoticeSkip>, lastCheckFailure: ReturnType<typeof lastCheckFailure>, stateLock: ReturnType<typeof stateLockHolder>, searchPathCommands: Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade: string | null}>}}
333
+ * @returns {{answeredBy: {cli: string, core: string | null, copy: string}, latest: string | null, globalBehind: ReturnType<typeof globalBehind> | null, projectLag: ReturnType<typeof projectLag> | null, lastNoticeSkip: ReturnType<typeof lastNoticeSkip>, lastCheckFailure: ReturnType<typeof lastCheckFailure>, stateLock: ReturnType<typeof stateLockHolder>, searchPathCommands: Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade: string | null, runner: boolean}>}}
313
334
  */
314
335
  export function releaseFacts(cwd, {project}) {
315
336
  const answered = answeredBy(cwd);
@@ -336,6 +357,9 @@ export function releaseFacts(cwd, {project}) {
336
357
  searchPathCommands: astryxCommandsOnSearchPath().map(row => ({
337
358
  ...row,
338
359
  upgrade: row.cliRoot ? globalUpgradeCommand(row.cliRoot) : null,
360
+ // A package runner's temporary install, which it puts first on the
361
+ // search path only for the run it starts.
362
+ runner: row.cliRoot ? installPlaceOf(row.cliRoot).runner : false,
339
363
  })),
340
364
  };
341
365
  }
@@ -348,11 +372,12 @@ export function outsideProject(/** @type {string} */ cwd) {
348
372
  /**
349
373
  * The commands that bring a project's own CLI and Core to one release, with
350
374
  * 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.
375
+ * the CLI is newer; else the CLI to the Core's release. Null when no
376
+ * command fits (see `alignCliAndCore`).
352
377
  * @param {string} cwd
353
378
  * @param {string} cli
354
379
  * @param {string} core
355
- * @returns {string}
380
+ * @returns {string | null}
356
381
  */
357
382
  export function alignCommand(cwd, cli, core) {
358
383
  return alignCliAndCore({cwd, cli, core});
@@ -380,30 +405,35 @@ export function projectHasOwnCli(cwd) {
380
405
 
381
406
  /**
382
407
  * The command that adds the CLI at `version` with the project's package
383
- * manager.
408
+ * manager, and the Core it matches: from a folder whose package.json declares
409
+ * no Astryx package, in the Astryx project above at that project's Core; null
410
+ * when there is none (see `cliInstallAdvice`).
384
411
  * @param {string} cwd
385
412
  * @param {string} version
386
- * @returns {string}
413
+ * @returns {{command: string, core: string} | null}
387
414
  */
388
415
  export function addCliCommandFor(cwd, version) {
389
- return addCliCommand(projectRootOf(readReleaseFacts(cwd)) ?? cwd, version);
416
+ const advice = cliInstallAdvice({cwd, core: version});
417
+ return advice?.command ? {command: advice.command, core: advice.core} : null;
390
418
  }
391
419
 
392
420
  /**
393
- * The command that adds a package with the folder's package manager, read
394
- * from its lockfiles and `packageManager` field.
421
+ * The command that adds a package to the project of `cwd`; null in a folder
422
+ * that belongs to no project or whose package.json is not the project's (see
423
+ * `projectAddCommand`).
395
424
  * @param {string} cwd
396
- * @returns {(name: string) => string}
425
+ * @returns {((name: string) => string) | null}
397
426
  */
398
427
  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}`;
428
+ return projectAddCommand(cwd);
429
+ }
430
+
431
+ /**
432
+ * Whether `cwd` is inside a project whose package.json is not the project's,
433
+ * so advice points at the project's folder (see `installFolder`).
434
+ * @param {string} cwd
435
+ * @returns {boolean}
436
+ */
437
+ export function insideProjectElsewhere(cwd) {
438
+ return installFolder(cwd)?.moved === true;
409
439
  }
@@ -188,6 +188,10 @@ export function checkCliCommand(ctx: DoctorContext): DoctorCheck;
188
188
  * each file of the computer-level agent text against this release's rendering
189
189
  * @property {import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings} [agentTextSettings]
190
190
  * the person's choices about the computer-level agent text
191
+ * @property {string | null} [agentTextCommand] the command the skill file
192
+ * tells agents to run, or null
193
+ * @property {string | null} [agentTextInstall] the install step the skill
194
+ * file records for when that command is not found, or null
191
195
  * @property {string} [cwd] the folder doctor runs in, for the printed fix
192
196
  * @property {import('../../foundation/release/notices.mjs').GlobalBehind | null} [globalBehind]
193
197
  * the CLI installed for the computer, when it is older than the newest
@@ -200,7 +204,7 @@ export function checkCliCommand(ctx: DoctorContext): DoctorCheck;
200
204
  * the newest update notice that did not print, and why (diagnostic only)
201
205
  * @property {{pid: number | null, host: string | null, since: number} | null} [stateLock]
202
206
  * who holds the state file's lock now (diagnostic only)
203
- * @property {Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade?: string | null}>} [searchPathCommands]
207
+ * @property {Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade?: string | null, runner?: boolean}>} [searchPathCommands]
204
208
  * every `astryx` on the search path, with the command that upgrades it
205
209
  * the `astryx` commands on the search path, in order
206
210
  * @property {import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[]} [computerIntegrations]
@@ -259,15 +263,18 @@ export function checkComputerIntegrations(ctx: ComputerContext): DoctorCheck;
259
263
  * Inside a project, the integrations installed for the computer that the
260
264
  * project does not install: available, never used (spec AST-081 FR12).
261
265
  * Always info.
262
- * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: (name: string) => string}} input
266
+ * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: ((name: string) => string) | null, elsewhere?: boolean}} input
263
267
  * `install`: the command that adds a package with the project's package
264
- * manager (read by the adapter)
268
+ * manager (read by the adapter); null when the folder belongs to no
269
+ * project, or `elsewhere`: its package.json is not the project's, where the
270
+ * fix points at the project's folder
265
271
  * @returns {DoctorCheck}
266
272
  */
267
- export function checkComputerIntegrationsAvailable({ installed, candidates, install }: {
273
+ export function checkComputerIntegrationsAvailable({ installed, candidates, install, elsewhere }: {
268
274
  installed: Set<string>;
269
275
  candidates: import("../../foundation/integrations/computer-integrations.mjs").ComputerIntegrationCandidate[];
270
- install: (name: string) => string;
276
+ install: ((name: string) => string) | null;
277
+ elsewhere?: boolean;
271
278
  }): DoctorCheck;
272
279
  /**
273
280
  * Run all diagnostic checks and return a structured report.
@@ -443,6 +450,16 @@ export type ComputerContext = {
443
450
  * the person's choices about the computer-level agent text
444
451
  */
445
452
  agentTextSettings?: import("../../foundation/env/user-settings.mjs").ComputerAgentTextSettings | undefined;
453
+ /**
454
+ * the command the skill file
455
+ * tells agents to run, or null
456
+ */
457
+ agentTextCommand?: string | null | undefined;
458
+ /**
459
+ * the install step the skill
460
+ * file records for when that command is not found, or null
461
+ */
462
+ agentTextInstall?: string | null | undefined;
446
463
  /**
447
464
  * the folder doctor runs in, for the printed fix
448
465
  */
@@ -484,6 +501,7 @@ export type ComputerContext = {
484
501
  */
485
502
  searchPathCommands?: (import("../../foundation/env/search-path.mjs").SearchPathCommand & {
486
503
  upgrade?: string | null;
504
+ runner?: boolean;
487
505
  })[] | undefined;
488
506
  /**
489
507
  * the integrations installed beside the running CLI