@astryxdesign/cli 0.7.3-canary.ca48bb7 → 0.7.3-canary.cac3d8d

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 (53) 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/kit/weights.d.mts +8 -22
  12. package/api/build/kit/weights.mjs +87 -8
  13. package/api/build/kit/weights.test.mjs +96 -0
  14. package/api/build/tree.mjs +2 -1
  15. package/api/build/tree.test.mjs +27 -27
  16. package/api/component/_adapter.mjs +39 -5
  17. package/api/discover/_adapter.d.mts +1 -2
  18. package/api/discover/_adapter.mjs +6 -8
  19. package/api/discover/discover.mjs +0 -1
  20. package/api/docs/_adapter.mjs +4 -0
  21. package/api/doctor/_adapter.d.mts +33 -13
  22. package/api/doctor/_adapter.mjs +55 -25
  23. package/api/doctor/doctor.d.mts +23 -5
  24. package/api/doctor/doctor.mjs +81 -16
  25. package/api/doctor/doctor.test.mjs +58 -0
  26. package/api/search/_gather-templates.d.mts +0 -1
  27. package/api/search/_gather-templates.mjs +25 -0
  28. package/api/search/search.integration-block.test.mjs +100 -0
  29. package/api/template/template.mjs +5 -1
  30. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  31. package/clients/cli/commands/doctor.doc.mjs +1 -1
  32. package/clients/cli/commands/outside-project.test.mjs +99 -0
  33. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  34. package/clients/cli/index.mjs +25 -8
  35. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  36. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  37. package/foundation/agent-docs/agent-docs.mjs +5 -5
  38. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  39. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  40. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  41. package/foundation/integrations/public-imports.mjs +1 -1
  42. package/foundation/release/cache.test.mjs +24 -21
  43. package/foundation/release/global-state.d.mts +8 -4
  44. package/foundation/release/global-state.mjs +4 -2
  45. package/foundation/release/notices.d.mts +62 -8
  46. package/foundation/release/notices.mjs +136 -25
  47. package/foundation/release/notices.test.mjs +21 -0
  48. package/foundation/text/string-utils.d.mts +2 -1
  49. package/foundation/text/string-utils.mjs +16 -5
  50. package/foundation/text/suggest-order.d.mts +72 -0
  51. package/foundation/text/suggest-order.mjs +363 -0
  52. package/foundation/text/suggest-order.test.mjs +259 -0
  53. package/package.json +9 -9
@@ -43,7 +43,17 @@ import {createHash} from 'node:crypto';
43
43
  import {cliDoor} from '../env/cli-command.mjs';
44
44
  import {astryxCommandsOnSearchPath} from '../env/search-path.mjs';
45
45
  import {samePath} from '../fs/path-compare.mjs';
46
- import {MARKER_START, MARKER_END} from './agent-doc-state.mjs';
46
+ import {CLI_ROOT} from '../fs/paths.mjs';
47
+ import {CLI_PACKAGE} from '../env/package-manager.mjs';
48
+ import {isGlobalCopy} from '../release/choose.mjs';
49
+ import {globalUpgradeCommand} from '../release/notices.mjs';
50
+ import {
51
+ MARKER_START,
52
+ MARKER_END,
53
+ SELF_CHECK_CSS,
54
+ WORKFLOW_STEPS,
55
+ WORKFLOW_TITLE,
56
+ } from './agent-doc-state.mjs';
47
57
 
48
58
  /** The command the computer-level text uses when no host door is set. */
49
59
  export const COMPUTER_COMMAND = 'astryx';
@@ -51,6 +61,83 @@ export const COMPUTER_COMMAND = 'astryx';
51
61
  /** The install step for the CLI copy the computer-level text relies on. */
52
62
  export const COMPUTER_INSTALL_STEP = 'npm i -g @astryxdesign/cli';
53
63
 
64
+ /**
65
+ * What to do when the `astryx` command the text names is not found, as on a
66
+ * machine whose home folder outlives its system folders: the skill file
67
+ * survives a restart while the CLI installed for the computer does not.
68
+ * @param {string} install the install step
69
+ * @returns {string}
70
+ */
71
+ export function computerRestoreLine(install) {
72
+ return `If \`${COMPUTER_COMMAND}\` is not found, run \`${install}\` first.`;
73
+ }
74
+
75
+ /**
76
+ * The step the CLI installed for the computer names for itself: the command
77
+ * that installs it again with the same package manager into the same folder,
78
+ * as the update notice names it but with no version. Null for any other copy.
79
+ * @param {string} [cliRoot]
80
+ * @returns {string | null}
81
+ */
82
+ function ownInstallStep(cliRoot = CLI_ROOT) {
83
+ try {
84
+ if (isGlobalCopy(cliRoot)) {
85
+ return globalUpgradeCommand(cliRoot).replace(
86
+ `${CLI_PACKAGE}@latest`,
87
+ CLI_PACKAGE,
88
+ );
89
+ }
90
+ } catch {
91
+ // A copy whose install cannot be read names none of its own.
92
+ }
93
+ return null;
94
+ }
95
+
96
+ /**
97
+ * The step the skill file in `home` records, or null.
98
+ * @param {string} home
99
+ * @returns {string | null}
100
+ */
101
+ function recordedInstallStep(home) {
102
+ try {
103
+ return skillInstallStepOf(fs.readFileSync(computerSkillFile(home), 'utf8'));
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * The install step the text names. `judge`: the step a file is judged by, the
111
+ * one it records first, so every copy of one release, two global installs
112
+ * included, finds the same text current. `write`: the step a write records,
113
+ * the global copy's own first, since only the CLI installed for the computer
114
+ * chooses it. Either way npm's when there is no other.
115
+ * @param {{cliRoot?: string, home?: string, for?: 'judge' | 'write'}} [options]
116
+ * @returns {string}
117
+ */
118
+ export function computerInstallStep({
119
+ cliRoot = CLI_ROOT,
120
+ home = os.homedir(),
121
+ for: use = 'write',
122
+ } = {}) {
123
+ const own = ownInstallStep(cliRoot);
124
+ const recorded = recordedInstallStep(home);
125
+ return (
126
+ (use === 'judge' ? (recorded ?? own) : (own ?? recorded)) ??
127
+ COMPUTER_INSTALL_STEP
128
+ );
129
+ }
130
+
131
+ /**
132
+ * The install step a skill file's text records, or null when it records
133
+ * none.
134
+ * @param {string} content
135
+ * @returns {string | null}
136
+ */
137
+ export function skillInstallStepOf(content) {
138
+ return /is not found, run `(.+?)` first\./u.exec(content)?.[1] ?? null;
139
+ }
140
+
54
141
  /** The skill folder, relative to the home folder, that holds the one file. */
55
142
  const SKILL_FOLDER = path.join('.agents', 'skills', 'astryx');
56
143
 
@@ -164,27 +251,52 @@ export function computerAgentCommand() {
164
251
  }
165
252
 
166
253
  /**
167
- * The body lines, with `run` as the command.
254
+ * The body lines, with `run` as the command and `install` as the step that
255
+ * installs it.
168
256
  * @param {string} run
257
+ * @param {string} install
169
258
  * @returns {string[]}
170
259
  */
171
- function bodyLines(run) {
260
+ function bodyLines(run, install) {
172
261
  return [
173
262
  'Astryx, a design system and UI library, is available on this computer.',
174
263
  'Use it when you build or change UI, pick components, or style or theme an app.',
175
264
  `Its docs, components, templates, and themes are all reachable through \`${run}\`. Start with \`${run} search '<what you need>'\`.`,
176
265
  `Then read \`${run} component <Name>\` or \`${run} docs <topic>\`, not the package's files.`,
177
266
  "In a project, the project's version of Astryx answers automatically.",
267
+ // How to build, which discovery alone leaves to the agent's own page
268
+ // route: in a project, from the template, with the project agent docs'
269
+ // own workflow lines.
270
+ // A project that already installs Core gets the CLI at that version, as
271
+ // the CLI's own hint for that state says, never a newer CLI beside it.
272
+ `To build UI, work in a project folder (create one if there is none). Add \`@astryxdesign/core\` and \`@astryxdesign/cli\` to a new project or one without \`@astryxdesign/core\`; to a project that already has \`@astryxdesign/core\`, add \`@astryxdesign/cli\` at the same version. Run \`${run} init\` there and follow the agent docs it writes.`,
273
+ WORKFLOW_TITLE,
274
+ ...WORKFLOW_STEPS.map(step => step.replaceAll('`astryx ', `\`${run} `)),
275
+ `Before you deliver, re-read each file; ${SELF_CHECK_CSS}. Then build the project and deliver that build, not a description of it.`,
276
+ // A host's door is the host's to restore; only the global command has an
277
+ // install step to name.
278
+ ...(run === COMPUTER_COMMAND ? [computerRestoreLine(install)] : []),
178
279
  ];
179
280
  }
180
281
 
282
+ /**
283
+ * The command a skill file's text names: the one in its "Start with" line,
284
+ * or null when the text has none.
285
+ * @param {string} content
286
+ * @returns {string | null}
287
+ */
288
+ export function skillCommandOf(content) {
289
+ return /Start with `(.+?) search '/u.exec(content)?.[1] ?? null;
290
+ }
291
+
181
292
  /**
182
293
  * The full skill file.
183
- * @param {{command?: string}} [options]
294
+ * @param {{command?: string, install?: string}} [options]
184
295
  * @returns {string}
185
296
  */
186
297
  export function renderComputerAgentText({
187
298
  command = computerAgentCommand(),
299
+ install = COMPUTER_INSTALL_STEP,
188
300
  } = {}) {
189
301
  return withHash(
190
302
  [
@@ -196,7 +308,7 @@ export function renderComputerAgentText({
196
308
  '---',
197
309
  '',
198
310
  MARKER_START,
199
- ...bodyLines(command),
311
+ ...bodyLines(command, install),
200
312
  MARKER_END,
201
313
  '',
202
314
  ].join('\n'),
@@ -404,7 +516,10 @@ export function inspectComputerAgentText({
404
516
  command,
405
517
  links = [],
406
518
  } = {}) {
407
- const expected = renderComputerAgentText({command});
519
+ const expected = renderComputerAgentText({
520
+ command,
521
+ install: computerInstallStep({home, for: 'judge'}),
522
+ });
408
523
  const folder = path.join(home, SKILL_FOLDER);
409
524
  const made = new Set(links);
410
525
  return [
@@ -517,12 +632,24 @@ function writeCopy(at, expected) {
517
632
  * @returns {{rows: import('../../api/init/init.type.mjs').InitUserFile[], links: string[]}}
518
633
  */
519
634
  export function writeComputerAgentText({home = os.homedir(), command} = {}) {
520
- const expected = renderComputerAgentText({command});
635
+ // Judged by the step the file records, so a file another copy of this
636
+ // release wrote stays as it is; a write records this copy's own step.
637
+ const judged = renderComputerAgentText({
638
+ command,
639
+ install: computerInstallStep({home, for: 'judge'}),
640
+ });
521
641
  const file = computerSkillFile(home);
522
642
  const folder = path.dirname(file);
523
643
  /** @type {import('../../api/init/init.type.mjs').InitUserFile[]} */
524
644
  const rows = [];
525
- const state = stateOf(file, expected);
645
+ const state = stateOf(file, judged);
646
+ const expected =
647
+ state === 'current'
648
+ ? judged
649
+ : renderComputerAgentText({
650
+ command,
651
+ install: computerInstallStep({home, for: 'write'}),
652
+ });
526
653
  if (state === 'foreign' || state === 'edited') {
527
654
  rows.push({path: file, action: 'kept', reason: keptReason(state)});
528
655
  } else if (state === 'current') {
@@ -24,10 +24,18 @@ import {
24
24
  computerSkillLinks,
25
25
  inspectComputerAgentText,
26
26
  removeComputerAgentText,
27
+ computerInstallStep,
27
28
  renderComputerAgentText,
29
+ skillInstallStepOf,
28
30
  writeComputerAgentText,
29
31
  } from './computer-agent-text.mjs';
30
- import {MARKER_END, MARKER_START} from './agent-doc-state.mjs';
32
+ import {
33
+ MARKER_END,
34
+ MARKER_START,
35
+ SELF_CHECK_CSS,
36
+ WORKFLOW_STEPS,
37
+ WORKFLOW_TITLE,
38
+ } from './agent-doc-state.mjs';
31
39
  import {runWithCliDoor} from '../env/cli-command.mjs';
32
40
  import {runCli} from '../../test-utils/run-cli.mjs';
33
41
  import {parse as parseYaml} from 'yaml';
@@ -123,17 +131,106 @@ describe('renderComputerAgentText', () => {
123
131
 
124
132
  it('stays short, and tells agents to read docs through the CLI', () => {
125
133
  const text = renderComputerAgentText({command: 'astryx'});
126
- expect(text.split('\n').length).toBeLessThanOrEqual(15);
134
+ expect(text.split('\n').length).toBeLessThanOrEqual(22);
127
135
  expect(text).toContain(
128
136
  "Then read `astryx component <Name>` or `astryx docs <topic>`, not the package's files.",
129
137
  );
130
138
  });
131
139
 
140
+ // Discovery alone leaves the build to the agent's own page route, which
141
+ // may not install packages; the skill names the route and the project
142
+ // agent docs' own workflow lines.
143
+ it('gives the build workflow: a project with Astryx installed and init run, the shared template steps, then check and deliver the build', () => {
144
+ const text = renderComputerAgentText({command: 'astryx'});
145
+ expect(text).toContain(
146
+ 'To build UI, work in a project folder (create one if there is none). Add `@astryxdesign/core` and `@astryxdesign/cli` to a new project or one without `@astryxdesign/core`; to a project that already has `@astryxdesign/core`, add `@astryxdesign/cli` at the same version. Run `astryx init` there and follow the agent docs it writes.',
147
+ );
148
+ for (const line of [WORKFLOW_TITLE, ...WORKFLOW_STEPS]) {
149
+ expect(text).toContain(line);
150
+ }
151
+ expect(text).toContain(`re-read each file; ${SELF_CHECK_CSS}.`);
152
+ expect(text).toContain('deliver that build');
153
+ });
154
+
132
155
  it("uses the host's door when one is set", () => {
133
156
  const text = runWithCliDoor('acme astryx', () => renderComputerAgentText());
134
157
  expect(text).toContain("`acme astryx search '<what you need>'`");
135
158
  expect(text).not.toMatch(/`astryx /u);
136
159
  });
160
+
161
+ // A machine can keep the home folder and lose the CLI installed for the
162
+ // computer, so the skill says how to get it back, with no version.
163
+ it('names the install step for when `astryx` is not found, and only for the global command', () => {
164
+ expect(
165
+ renderComputerAgentText({
166
+ command: 'astryx',
167
+ install: 'npm i -g @astryxdesign/cli',
168
+ }),
169
+ ).toContain(
170
+ 'If `astryx` is not found, run `npm i -g @astryxdesign/cli` first.',
171
+ );
172
+ // It repeats the step that installed the copy writing it, which doctor
173
+ // reads back.
174
+ const bun = renderComputerAgentText({
175
+ command: 'astryx',
176
+ install: 'bun add -g @astryxdesign/cli',
177
+ });
178
+ expect(bun).toContain(
179
+ 'If `astryx` is not found, run `bun add -g @astryxdesign/cli` first.',
180
+ );
181
+ expect(skillInstallStepOf(bun)).toBe('bun add -g @astryxdesign/cli');
182
+ });
183
+
184
+ // Rendering is pure: its default step never depends on the skill in the
185
+ // home folder of the computer the test runs on.
186
+ it("renders npm's step by default, whatever skill the caller's home folder holds", () => {
187
+ const home = tmp('caller-home');
188
+ const file = computerSkillFile(home);
189
+ fs.mkdirSync(path.dirname(file), {recursive: true});
190
+ fs.writeFileSync(
191
+ file,
192
+ renderComputerAgentText({
193
+ command: 'astryx',
194
+ install: 'pnpm add -g @astryxdesign/cli',
195
+ }),
196
+ );
197
+ const saved = process.env.HOME;
198
+ process.env.HOME = home;
199
+ try {
200
+ expect(renderComputerAgentText({command: 'astryx'})).toContain(
201
+ 'run `npm i -g @astryxdesign/cli` first.',
202
+ );
203
+ } finally {
204
+ process.env.HOME = saved;
205
+ }
206
+ });
207
+
208
+ // Only the CLI installed for the computer chooses the step; every other
209
+ // copy of the release, such as a project's own CLI, keeps the one the file
210
+ // records, so it neither reports the file as different nor rewrites it.
211
+ it('keeps the step the file records for a copy that is not installed for the computer', () => {
212
+ const home = tmp('home');
213
+ const file = computerSkillFile(home);
214
+ fs.mkdirSync(path.dirname(file), {recursive: true});
215
+ const pnpm = renderComputerAgentText({
216
+ command: 'astryx',
217
+ install: 'pnpm add -g @astryxdesign/cli',
218
+ });
219
+ fs.writeFileSync(file, pnpm);
220
+ expect(computerInstallStep({home})).toBe('pnpm add -g @astryxdesign/cli');
221
+ expect(inspectComputerAgentText({home, command: 'astryx'})[0].state).toBe(
222
+ 'current',
223
+ );
224
+ writeComputerAgentText({home, command: 'astryx'});
225
+ expect(fs.readFileSync(file, 'utf8')).toBe(pnpm);
226
+ // No file yet: npm's step.
227
+ expect(computerInstallStep({home: tmp('empty-home')})).toBe(
228
+ 'npm i -g @astryxdesign/cli',
229
+ );
230
+ expect(renderComputerAgentText({command: 'acme astryx'})).not.toContain(
231
+ 'npm i -g',
232
+ );
233
+ });
137
234
  });
138
235
 
139
236
  describe('the link table', () => {
@@ -1439,7 +1439,7 @@ async function componentIssues(ctx, integration) {
1439
1439
  ...MODULE_EXTENSIONS,
1440
1440
  ...MODULE_EXTENSIONS.map(ext => `/index${ext}`),
1441
1441
  ]
1442
- .map(ext => path.resolve(ctx.packageDir, `${subpath.slice(2)}${ext}`))
1442
+ .map(ext => path.resolve(ctx.packageDir, subpath.slice(2) + ext))
1443
1443
  .find(
1444
1444
  file =>
1445
1445
  file.startsWith(path.resolve(ctx.packageDir) + path.sep) &&
@@ -802,8 +802,28 @@ describe('stopped and damaged installs heal', () => {
802
802
  });
803
803
  });
804
804
 
805
+ /** @param {number} pid */
806
+ const alive = pid => {
807
+ try {
808
+ process.kill(pid, 0);
809
+ return true;
810
+ } catch {
811
+ return false;
812
+ }
813
+ };
814
+
815
+ /** @param {() => boolean} done @param {number} ms */
816
+ const waitFor = async (done, ms) => {
817
+ const end = Date.now() + ms;
818
+ while (Date.now() < end) {
819
+ if (done()) return true;
820
+ await new Promise(r => setTimeout(r, 100));
821
+ }
822
+ return done();
823
+ };
824
+
805
825
  describe('runNpm time limit', () => {
806
- it('ends a package manager that ignores SIGTERM, leaving no process behind', () => {
826
+ it('ends a package manager that ignores SIGTERM, leaving no process behind', async () => {
807
827
  const marker = tempDir('npm-pid');
808
828
  const pidFile = path.join(marker, 'pid');
809
829
  const result = runNpm([], {
@@ -819,30 +839,13 @@ describe('runNpm time limit', () => {
819
839
  });
820
840
  expect(/** @type {any} */ (result.error)?.code).toBe('ETIMEDOUT');
821
841
  const pid = Number(fs.readFileSync(pidFile, 'utf-8'));
822
- expect(() => process.kill(pid, 0)).toThrow();
842
+ // The guard sends SIGKILL and exits at once; the killed process can still
843
+ // exist for a moment (the signal in flight, or awaiting reaping).
844
+ expect(await waitFor(() => !alive(pid), 5_000)).toBe(true);
823
845
  });
824
846
  });
825
847
 
826
848
  describe('no install outlives its run', () => {
827
- /** @param {number} pid */
828
- const alive = pid => {
829
- try {
830
- process.kill(pid, 0);
831
- return true;
832
- } catch {
833
- return false;
834
- }
835
- };
836
- /** @param {() => boolean} done @param {number} ms */
837
- const waitFor = async (done, ms) => {
838
- const end = Date.now() + ms;
839
- while (Date.now() < end) {
840
- if (done()) return true;
841
- await new Promise(r => setTimeout(r, 100));
842
- }
843
- return done();
844
- };
845
-
846
849
  it('ends npm when the run that started it is killed outright, and removes its process-id record', async () => {
847
850
  const dir = tempDir('orphan');
848
851
  const pidFile = path.join(dir, 'npm-pid');
@@ -20,9 +20,11 @@
20
20
  */
21
21
  /**
22
22
  * Why an update notice did not print: `already-shown` (it printed within the
23
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
23
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
24
+ * installs Core but belongs to no Astryx project, so no install command
25
+ * fits). Recorded only while the run
24
26
  * holds the state file's lock.
25
- * @typedef {{reason: 'already-shown' | 'no-newer', at: number}} NoticeSkip
27
+ * @typedef {{reason: 'already-shown' | 'no-newer' | 'no-project', at: number}} NoticeSkip
26
28
  */
27
29
  /**
28
30
  * The state file.
@@ -242,11 +244,13 @@ export type GlobalState = {
242
244
  };
243
245
  /**
244
246
  * Why an update notice did not print: `already-shown` (it printed within the
245
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
247
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
248
+ * installs Core but belongs to no Astryx project, so no install command
249
+ * fits). Recorded only while the run
246
250
  * holds the state file's lock.
247
251
  */
248
252
  export type NoticeSkip = {
249
- reason: "already-shown" | "no-newer";
253
+ reason: "already-shown" | "no-newer" | "no-project";
250
254
  at: number;
251
255
  };
252
256
  /**
@@ -68,9 +68,11 @@ export const CHECK_INTERVAL_MS = 24 * 60 * 60_000;
68
68
 
69
69
  /**
70
70
  * Why an update notice did not print: `already-shown` (it printed within the
71
- * day) or `no-newer` (nothing newer is known). Recorded only while the run
71
+ * day), `no-newer` (nothing newer is known), or `no-project` (the folder
72
+ * installs Core but belongs to no Astryx project, so no install command
73
+ * fits). Recorded only while the run
72
74
  * holds the state file's lock.
73
- * @typedef {{reason: 'already-shown' | 'no-newer', at: number}} NoticeSkip
75
+ * @typedef {{reason: 'already-shown' | 'no-newer' | 'no-project', at: number}} NoticeSkip
74
76
  */
75
77
 
76
78
  /**
@@ -91,24 +91,71 @@ export function globalBehind({ self, stateDir }: {
91
91
  };
92
92
  stateDir?: string;
93
93
  }): GlobalBehind | null;
94
+ /**
95
+ * The command that adds a package to the project of a run in `cwd`, with the
96
+ * project's package manager (spec AST-081 FR12). Null when `cwd` belongs to
97
+ * no project `spec:AST-040` FR9 defines, and in a folder inside the project
98
+ * whose package.json is not the project's (see {@link installFolder}): a run
99
+ * there loads integrations from that package.json, so a package added to the
100
+ * project would stay unused there, and the advice is
101
+ * {@link RUN_FROM_PROJECT}.
102
+ * @param {string} cwd
103
+ * @returns {((name: string) => string) | null}
104
+ */
105
+ export function projectAddCommand(cwd: string): ((name: string) => string) | null;
94
106
  /**
95
107
  * The commands that bring a project's own CLI and Core to one release, with
96
108
  * the project's package manager: when the CLI is newer, Core up to it and then
97
109
  * the codemods from Core's release; otherwise the CLI to Core's release.
110
+ * Null in a folder that belongs to no project, or whose package.json is not
111
+ * the project's (see {@link installFolder}).
98
112
  * @param {{cwd: string, cli: string, core: string}} options
99
- * @returns {string}
113
+ * @returns {string | null}
100
114
  */
101
115
  export function alignCliAndCore({ cwd, cli, core }: {
102
116
  cwd: string;
103
117
  cli: string;
104
118
  core: string;
105
- }): string;
119
+ }): string | null;
120
+ /**
121
+ * Where a command that adds an Astryx package runs, for a run in `cwd`: in
122
+ * the project `spec:AST-040` FR9 defines, which stops at a repository root
123
+ * and never counts the home folder (spec AST-081 FR2, FR10). Null when `cwd`
124
+ * belongs to no such project, so no command adds anything. When `cwd`'s
125
+ * nearest package.json is not the project's, as in a tool folder that
126
+ * installs its own Core, a package manager would add to the tool's
127
+ * package.json, so `moved` says the command runs in the project's folder.
128
+ * @param {string} cwd
129
+ * @returns {{dir: string, moved: boolean} | null}
130
+ */
131
+ export function installFolder(cwd: string): {
132
+ dir: string;
133
+ moved: boolean;
134
+ } | null;
135
+ /**
136
+ * The command that adds the CLI at Core's version, for a run in `cwd` whose
137
+ * Core is `core`, with the project's package manager in the project root.
138
+ * `command` is null in a folder inside the project whose package.json is not
139
+ * the project's (see {@link installFolder}), where the advice is
140
+ * {@link RUN_FROM_PROJECT}. Null when the folder belongs to no project.
141
+ * @param {{cwd: string, core: string}} options
142
+ * @returns {{root: string, core: string, command: string | null} | null}
143
+ */
144
+ export function cliInstallAdvice({ cwd, core }: {
145
+ cwd: string;
146
+ core: string;
147
+ }): {
148
+ root: string;
149
+ core: string;
150
+ command: string | null;
151
+ } | null;
106
152
  /**
107
153
  * The hint for a project with no CLI of its own, answered by `answered` while
108
154
  * its Core is `core`: the command that adds the CLI at Core's version, with
109
- * the project's package manager.
155
+ * the project's package manager (see {@link cliInstallAdvice}). Null when no
156
+ * command fits, or when the project the command adds to already matches.
110
157
  * @param {{cwd: string, answered: string, core: string}} options
111
- * @returns {{root: string, line: string}}
158
+ * @returns {{root: string, line: string} | null}
112
159
  */
113
160
  export function noCliHint({ cwd, answered, core }: {
114
161
  cwd: string;
@@ -117,15 +164,16 @@ export function noCliHint({ cwd, answered, core }: {
117
164
  }): {
118
165
  root: string;
119
166
  line: string;
120
- };
167
+ } | null;
121
168
  /**
122
169
  * The hint's text.
123
170
  * @param {string} answered
124
171
  * @param {string} core
125
- * @param {string} command the command that adds the CLI at Core's version
172
+ * @param {string | null} command the command that adds the CLI at Core's
173
+ * version; null in a folder whose package.json is not the project's
126
174
  * @returns {string}
127
175
  */
128
- export function noCliHintLine(answered: string, core: string, command: string): string;
176
+ export function noCliHintLine(answered: string, core: string, command: string | null): string;
129
177
  /**
130
178
  * The command that installs the CLI at `version` in the project at `root`,
131
179
  * with its package manager.
@@ -140,7 +188,7 @@ export function addCliCommand(root: string, version: string): string;
140
188
  * @param {{cwd: string, current: string, stateDir?: string}} options
141
189
  * @returns {ProjectLag | null}
142
190
  */
143
- export function projectLag({ cwd, current, stateDir }: {
191
+ export function projectLag({ cwd, current: given, stateDir }: {
144
192
  cwd: string;
145
193
  current: string;
146
194
  stateDir?: string;
@@ -207,6 +255,12 @@ export function noticeLines({ cwd, self, choice, json, stateDir, cacheDir, now,
207
255
  }): string[];
208
256
  /** A notice prints at most once in this long. */
209
257
  export const NOTICE_INTERVAL_MS: number;
258
+ /**
259
+ * What to tell a run in a folder inside a project whose package.json is not
260
+ * the project's: run from the project's folder, since adding there would make
261
+ * the folder a project of its own (spec AST-081 FR2).
262
+ */
263
+ export const RUN_FROM_PROJECT: "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.";
210
264
  export type GlobalBehind = {
211
265
  /**
212
266
  * the global copy's version