@astryxdesign/cli 0.7.3-canary.f8fad28 → 0.7.3-canary.fba04ed
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.
- package/api/build/_adapter.mjs +37 -25
- package/api/build/blocks/blocks.d.mts +68 -20
- package/api/build/blocks/blocks.mjs +472 -196
- package/api/build/blocks/blocks.test.mjs +185 -168
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.type.mjs +1 -1
- package/api/build/kit/answer.d.mts +4 -1
- package/api/build/kit/answer.mjs +11 -3
- package/api/build/kit/signals.d.mts +11 -0
- package/api/build/kit/signals.mjs +8 -7
- package/api/build/tree.mjs +2 -1
- package/api/build/tree.test.mjs +27 -27
- package/api/component/_adapter.mjs +39 -5
- package/api/discover/_adapter.d.mts +1 -2
- package/api/discover/_adapter.mjs +6 -8
- package/api/discover/discover.mjs +0 -1
- package/api/docs/_adapter.mjs +4 -0
- package/api/doctor/_adapter.d.mts +33 -13
- package/api/doctor/_adapter.mjs +55 -25
- package/api/doctor/doctor.d.mts +23 -5
- package/api/doctor/doctor.mjs +81 -16
- package/api/doctor/doctor.test.mjs +58 -0
- package/api/integration/validate-integration-gaps.test.mjs +3 -0
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_gather-templates.d.mts +0 -1
- package/api/search/_gather-templates.mjs +25 -0
- package/api/search/search.integration-block.test.mjs +100 -0
- package/api/template/template.mjs +5 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/outside-project.test.mjs +99 -0
- package/clients/cli/commands/setup-nudge.test.mjs +17 -0
- package/clients/cli/index.mjs +25 -8
- package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
- package/foundation/agent-docs/agent-doc-state.mjs +24 -2
- package/foundation/agent-docs/agent-docs.mjs +5 -5
- package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
- package/foundation/agent-docs/computer-agent-text.mjs +135 -8
- package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
- package/foundation/integrations/public-imports.d.mts +37 -0
- package/foundation/integrations/public-imports.mjs +839 -46
- package/foundation/integrations/public-imports.test.mjs +971 -46
- package/foundation/release/cache.test.mjs +24 -21
- package/foundation/release/global-state.d.mts +8 -4
- package/foundation/release/global-state.mjs +4 -2
- package/foundation/release/notices.d.mts +62 -8
- package/foundation/release/notices.mjs +136 -25
- package/foundation/release/notices.test.mjs +21 -0
- package/foundation/text/string-utils.d.mts +2 -1
- package/foundation/text/string-utils.mjs +16 -5
- package/foundation/text/suggest-order.d.mts +72 -0
- package/foundation/text/suggest-order.mjs +363 -0
- package/foundation/text/suggest-order.test.mjs +259 -0
- package/package.json +9 -9
|
@@ -392,6 +392,97 @@ describe('doctor: the computer-level agent text', () => {
|
|
|
392
392
|
const A = '/home/me/.agents/skills/astryx/SKILL.md';
|
|
393
393
|
const C = '/home/me/.claude/skills/astryx';
|
|
394
394
|
|
|
395
|
+
it('a skill naming `astryx` with no Astryx CLI on the search path: says whether it is current, and names the step it records', () => {
|
|
396
|
+
const check = (/** @type {Record<string, any>} */ over) =>
|
|
397
|
+
checkComputerAgentText({
|
|
398
|
+
nodeVersion: '22.13.0',
|
|
399
|
+
answeredBy: {cli: '1.2.0', core: '1.2.0', copy: 'carried'},
|
|
400
|
+
latest: null,
|
|
401
|
+
agentText: [{path: A, state: 'current'}],
|
|
402
|
+
agentTextCommand: 'astryx',
|
|
403
|
+
searchPathCommands: [],
|
|
404
|
+
cwd: os.tmpdir(),
|
|
405
|
+
...over,
|
|
406
|
+
});
|
|
407
|
+
const recorded = check({agentTextInstall: 'pnpm add -g @astryxdesign/cli'});
|
|
408
|
+
// A package runner's own copy first on the search path does not count.
|
|
409
|
+
expect(
|
|
410
|
+
check({
|
|
411
|
+
agentTextInstall: 'pnpm add -g @astryxdesign/cli',
|
|
412
|
+
searchPathCommands: [
|
|
413
|
+
/** @type {any} */ ({
|
|
414
|
+
file: '/tmp/_npx/r/node_modules/.bin/astryx',
|
|
415
|
+
astryx: true,
|
|
416
|
+
runner: true,
|
|
417
|
+
}),
|
|
418
|
+
],
|
|
419
|
+
}).fix,
|
|
420
|
+
).toBe(
|
|
421
|
+
'Run `pnpm add -g @astryxdesign/cli`, the step the skill names for when `astryx` is not found.',
|
|
422
|
+
);
|
|
423
|
+
expect(recorded.status).toBe('info');
|
|
424
|
+
expect(recorded.message).toContain(
|
|
425
|
+
`The computer-level agent text matches this release: ${A}. It tells agents to run \`astryx\`, but no \`astryx\` command is on the search path`,
|
|
426
|
+
);
|
|
427
|
+
expect(recorded.fix).toBe(
|
|
428
|
+
'Run `pnpm add -g @astryxdesign/cli`, the step the skill names for when `astryx` is not found.',
|
|
429
|
+
);
|
|
430
|
+
// A skill from an earlier release records no step: npm's, worded as
|
|
431
|
+
// cli-on-path words it.
|
|
432
|
+
const older = check({
|
|
433
|
+
agentText: [{path: A, state: 'differs'}],
|
|
434
|
+
agentTextInstall: null,
|
|
435
|
+
});
|
|
436
|
+
expect(older.message).toContain(
|
|
437
|
+
"The computer-level agent text differs from this release's",
|
|
438
|
+
);
|
|
439
|
+
expect(older.fix).toBe(
|
|
440
|
+
'Install it for the computer: `npm i -g @astryxdesign/cli`.',
|
|
441
|
+
);
|
|
442
|
+
// With the Astryx CLI anywhere on the search path, even behind another
|
|
443
|
+
// program (cli-on-path's to report), or a skill naming a host's command,
|
|
444
|
+
// there is nothing to restore.
|
|
445
|
+
for (const over of [
|
|
446
|
+
{
|
|
447
|
+
searchPathCommands: [
|
|
448
|
+
/** @type {any} */ ({
|
|
449
|
+
file: '/usr/bin/astryx',
|
|
450
|
+
astryx: true,
|
|
451
|
+
version: '1.2.0',
|
|
452
|
+
}),
|
|
453
|
+
],
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
searchPathCommands: [
|
|
457
|
+
/** @type {any} */ ({file: '/opt/other/astryx', astryx: false}),
|
|
458
|
+
/** @type {any} */ ({
|
|
459
|
+
file: '/usr/bin/astryx',
|
|
460
|
+
astryx: true,
|
|
461
|
+
version: '1.2.0',
|
|
462
|
+
}),
|
|
463
|
+
],
|
|
464
|
+
},
|
|
465
|
+
{agentTextCommand: 'acme astryx'},
|
|
466
|
+
// An `astryx` the scan cannot trace (a Volta, asdf or mise shim, or
|
|
467
|
+
// another program): it may run the CLI, so no report here.
|
|
468
|
+
{
|
|
469
|
+
searchPathCommands: [
|
|
470
|
+
/** @type {any} */ ({
|
|
471
|
+
file: '/home/me/.volta/bin/astryx',
|
|
472
|
+
astryx: false,
|
|
473
|
+
runner: false,
|
|
474
|
+
}),
|
|
475
|
+
],
|
|
476
|
+
},
|
|
477
|
+
// Only a package runner's own copy: the CLI is still gone.
|
|
478
|
+
]) {
|
|
479
|
+
const other = check(over);
|
|
480
|
+
expect(other.message).toBe(
|
|
481
|
+
`The computer-level agent text matches this release: ${A}.`,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
395
486
|
it('present and current, linked: no fix', () => {
|
|
396
487
|
const check = at([
|
|
397
488
|
{path: A, state: 'current'},
|
|
@@ -460,6 +551,14 @@ describe('doctor: the computer-level agent text', () => {
|
|
|
460
551
|
const home = tmpDir('home');
|
|
461
552
|
vi.stubEnv('HOME', home);
|
|
462
553
|
vi.stubEnv('USERPROFILE', home);
|
|
554
|
+
// The CLI installed for the computer, first on the search path, as the
|
|
555
|
+
// skill expects.
|
|
556
|
+
const bin = tmpDir('bin');
|
|
557
|
+
fs.symlinkSync(
|
|
558
|
+
path.join(CLI_ROOT, 'clients', 'cli', 'bin', 'astryx.mjs'),
|
|
559
|
+
path.join(bin, 'astryx'),
|
|
560
|
+
);
|
|
561
|
+
vi.stubEnv('PATH', `${bin}${path.delimiter}${process.env.PATH ?? ''}`);
|
|
463
562
|
try {
|
|
464
563
|
const find = r =>
|
|
465
564
|
r.envelope.data.checks.find(c => c.id === 'computer-agent-text');
|
|
@@ -202,6 +202,23 @@ describe('enforcement layer 3 — per-command setup nudge', () => {
|
|
|
202
202
|
expect(r.stderr).toMatch(NUDGE);
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
+
// A nested package.json that is not the project's (spec AST-040 FR9): the
|
|
206
|
+
// reminder sends the person to the project's folder, never adds the CLI to
|
|
207
|
+
// the nested package.json (spec AST-081 FR2).
|
|
208
|
+
it("in a nested package whose package.json is not the project's, says to run from the project's folder", async () => {
|
|
209
|
+
write('package.json', JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '0.7.0'}}));
|
|
210
|
+
write('package-lock.json', '{}');
|
|
211
|
+
write('functions/package.json', '{"name":"functions"}');
|
|
212
|
+
const r = await runCli(['docs', 'tokens'], path.join(tmp, 'functions'));
|
|
213
|
+
// Only `cd` comes first, so the app has no CLI of its own yet: the
|
|
214
|
+
// command is the scoped package at the answering release, never the bare
|
|
215
|
+
// `astryx` name a package runner would fetch from the registry.
|
|
216
|
+
const {version} = JSON.parse(fs.readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'));
|
|
217
|
+
expect(r.stderr.trim()).toBe(
|
|
218
|
+
`Next step: run \`cd ${tmp}\`, then \`npx @astryxdesign/cli@${version} init\` to finish setup and install the Astryx agent prompt.`,
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
205
222
|
// Inside a git repository the project-root check above adds nothing to the
|
|
206
223
|
// walk up to the repository root: the same outcomes as without it.
|
|
207
224
|
it('inside a repository, is quiet in a nested package once init has written the docs at the project root', async () => {
|
package/clients/cli/index.mjs
CHANGED
|
@@ -16,14 +16,12 @@ import {Command, Option} from 'commander';
|
|
|
16
16
|
import {fileURLToPath} from 'node:url';
|
|
17
17
|
import * as fs from 'node:fs';
|
|
18
18
|
import * as path from 'node:path';
|
|
19
|
-
import {formatCliCommand, getCliInvocation} from '../../foundation/env/package-manager.mjs';
|
|
19
|
+
import {formatCliCommand, getCliInvocation, quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
20
20
|
import {hasRecordedProject} from '../../foundation/env/cli-command.mjs';
|
|
21
21
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
22
22
|
import {API_VERSION, setJsonMode} from '../../foundation/response/json.mjs';
|
|
23
23
|
import {answeredBy, runChoice} from '../../foundation/release/run-context.mjs';
|
|
24
|
-
import {
|
|
25
|
-
import {projectRootOf} from '../../foundation/release/choose.mjs';
|
|
26
|
-
import {readReleaseFacts} from '../../foundation/release/project.mjs';
|
|
24
|
+
import {cliInstallAdvice, installFolder} from '../../foundation/release/notices.mjs';
|
|
27
25
|
import {buildManifest} from './lib/manifest.mjs';
|
|
28
26
|
import {cliError} from './lib/cli-error.mjs';
|
|
29
27
|
import {section, text, records} from './formatters/index.mjs';
|
|
@@ -663,14 +661,33 @@ export async function createProgram() {
|
|
|
663
661
|
// A project with no CLI of its own, answered by another release than its
|
|
664
662
|
// Core's: add the CLI at Core's version first, as the daily hint says,
|
|
665
663
|
// then run that CLI's init (spec AST-081 FR2).
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
664
|
+
// A folder that belongs to no project spec:AST-040 FR9 defines gets no
|
|
665
|
+
// reminder, as outside a project.
|
|
666
|
+
const target = installFolder(cwd);
|
|
667
|
+
if (target == null) return;
|
|
668
|
+
// From a folder inside the project whose package.json is not the
|
|
669
|
+
// project's, init runs from the project's folder. Only `cd` comes
|
|
670
|
+
// before it, so the command is the picker's for that folder, never the
|
|
671
|
+
// bare `astryx` name a package runner would fetch from the registry
|
|
672
|
+
// (spec AST-081 FR5).
|
|
673
|
+
if (target.moved) {
|
|
669
674
|
console.error(
|
|
670
|
-
setupNudge(getCliInvocation(
|
|
675
|
+
setupNudge(getCliInvocation(target.dir), {before: `cd ${quoteCommandArgument(target.dir)}`}).trimEnd(),
|
|
671
676
|
);
|
|
672
677
|
return;
|
|
673
678
|
}
|
|
679
|
+
const choice = runChoice(cwd);
|
|
680
|
+
if (choice.copy === 'starting' && choice.coreVersion && choice.coreVersion !== choice.version) {
|
|
681
|
+
// The daily hint's comparison and command: add the CLI at Core's
|
|
682
|
+
// version, then run that CLI's init.
|
|
683
|
+
const add = cliInstallAdvice({cwd, core: choice.coreVersion});
|
|
684
|
+
if (add?.command) {
|
|
685
|
+
console.error(
|
|
686
|
+
setupNudge(getCliInvocation(add.root, {installed: true}), {before: add.command}).trimEnd(),
|
|
687
|
+
);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
674
691
|
console.error(setupNudge(getCliInvocation(cwd)).trimEnd());
|
|
675
692
|
} catch {
|
|
676
693
|
// Never let the nudge break a command.
|
|
@@ -82,6 +82,18 @@ export const GEMINI_MD: "GEMINI.md";
|
|
|
82
82
|
export const CURSOR_RULES: ".cursorrules";
|
|
83
83
|
export const HERMES_DOT_MD: ".hermes.md";
|
|
84
84
|
export const HERMES_MD: "HERMES.md";
|
|
85
|
+
/**
|
|
86
|
+
* The page workflow every Astryx agent text gives, written with the command
|
|
87
|
+
* name `astryx`: the project agent docs and the computer-level skill both
|
|
88
|
+
* render these lines, so the two never drift.
|
|
89
|
+
*/
|
|
90
|
+
export const WORKFLOW_TITLE: "WORKFLOW \u2014 start every page from a template, never from scratch:";
|
|
91
|
+
export const WORKFLOW_STEPS: readonly string[];
|
|
92
|
+
/**
|
|
93
|
+
* The self-check's fix for a project with no StyleX or Tailwind compiler,
|
|
94
|
+
* and for an agent outside a project.
|
|
95
|
+
*/
|
|
96
|
+
export const SELF_CHECK_CSS: "replace any raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or a token";
|
|
85
97
|
export const MARKER_START: "<!-- ASTRYX:START -->";
|
|
86
98
|
export const MARKER_END: "<!-- ASTRYX:END -->";
|
|
87
99
|
export const LEGACY_MARKER_START: "<!-- XDS:START -->";
|
|
@@ -34,6 +34,26 @@ export const CURSOR_RULES = '.cursorrules';
|
|
|
34
34
|
export const HERMES_DOT_MD = '.hermes.md';
|
|
35
35
|
export const HERMES_MD = 'HERMES.md';
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The page workflow every Astryx agent text gives, written with the command
|
|
39
|
+
* name `astryx`: the project agent docs and the computer-level skill both
|
|
40
|
+
* render these lines, so the two never drift.
|
|
41
|
+
*/
|
|
42
|
+
export const WORKFLOW_TITLE =
|
|
43
|
+
'WORKFLOW — start every page from a template, never from scratch:';
|
|
44
|
+
export const WORKFLOW_STEPS = Object.freeze([
|
|
45
|
+
'1. `astryx build "<idea>"` — names the template to scaffold from and the parts it lacks.',
|
|
46
|
+
'2. `astryx template <name> <path>` — scaffold it; keep its frame, gap and padding; replace the content.',
|
|
47
|
+
'3. `astryx template <Block>` for parts it lacks; `astryx component <Name>` to read props before using one.',
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The self-check's fix for a project with no StyleX or Tailwind compiler,
|
|
52
|
+
* and for an agent outside a project.
|
|
53
|
+
*/
|
|
54
|
+
export const SELF_CHECK_CSS =
|
|
55
|
+
'replace any raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or a token';
|
|
56
|
+
|
|
37
57
|
export const MARKER_START = '<!-- ASTRYX:START -->';
|
|
38
58
|
export const MARKER_END = '<!-- ASTRYX:END -->';
|
|
39
59
|
// Legacy markers — read during migration so the script finds existing XDS blocks
|
|
@@ -91,7 +111,9 @@ export function holdsAstryxBlock(content) {
|
|
|
91
111
|
while (at !== -1) {
|
|
92
112
|
const from = at + marker.length;
|
|
93
113
|
const end = content.indexOf('<!--', from);
|
|
94
|
-
const inner = (
|
|
114
|
+
const inner = (
|
|
115
|
+
end === -1 ? content.slice(from) : content.slice(from, end)
|
|
116
|
+
).trim();
|
|
95
117
|
if (!/^@\S+$/.test(inner)) return true;
|
|
96
118
|
at = content.indexOf(marker, from);
|
|
97
119
|
}
|
|
@@ -153,7 +175,7 @@ export function isAstryxPromptInReach(startDir = process.cwd()) {
|
|
|
153
175
|
* @returns {string | null}
|
|
154
176
|
*/
|
|
155
177
|
function findRepositoryRoot(start) {
|
|
156
|
-
for (let dir = start; ;
|
|
178
|
+
for (let dir = start; ;) {
|
|
157
179
|
if (fs.existsSync(path.join(dir, '.git'))) return dir;
|
|
158
180
|
const parent = path.dirname(dir);
|
|
159
181
|
if (parent === dir) return null;
|
|
@@ -58,6 +58,9 @@ import {
|
|
|
58
58
|
discoverAgentDocs,
|
|
59
59
|
isAstryxInitialized,
|
|
60
60
|
isAstryxPromptInReach,
|
|
61
|
+
SELF_CHECK_CSS,
|
|
62
|
+
WORKFLOW_STEPS,
|
|
63
|
+
WORKFLOW_TITLE,
|
|
61
64
|
} from './agent-doc-state.mjs';
|
|
62
65
|
|
|
63
66
|
// The agent-doc locations, markers, and the setup-state predicates
|
|
@@ -762,10 +765,7 @@ export function generateCompressedIndex(
|
|
|
762
765
|
// Workflow — `build` is the front door, and every page starts from the
|
|
763
766
|
// template it names. build/template/component are covered here, so they are
|
|
764
767
|
// intentionally omitted from the command reference below.
|
|
765
|
-
lines.push(
|
|
766
|
-
lines.push('1. `astryx build "<idea>"` — names the template to scaffold from and the parts it lacks.');
|
|
767
|
-
lines.push('2. `astryx template <name> <path>` — scaffold it; keep its frame, gap and padding; replace the content.');
|
|
768
|
-
lines.push('3. `astryx template <Block>` for parts it lacks; `astryx component <Name>` to read props before using one.');
|
|
768
|
+
lines.push(WORKFLOW_TITLE, ...WORKFLOW_STEPS);
|
|
769
769
|
lines.push('Changing an existing page? Keep it: skip step 2 and add blocks/components inside its sections.');
|
|
770
770
|
lines.push('');
|
|
771
771
|
|
|
@@ -793,7 +793,7 @@ export function generateCompressedIndex(
|
|
|
793
793
|
'replace any className=, style={{…}}, raw <div>/<span>, imported .css/@apply, or hardcoded #hex/px with the component or the xstyle prop + a token',
|
|
794
794
|
tailwind:
|
|
795
795
|
'replace any style={{…}}, raw <div>/<span>, imported .css/@apply, or hardcoded/arbitrary value (bg-[#fff], p-[13px]) with the component or a token-backed utility',
|
|
796
|
-
css:
|
|
796
|
+
css: SELF_CHECK_CSS,
|
|
797
797
|
};
|
|
798
798
|
lines.push(
|
|
799
799
|
`- SELF-CHECK: re-read the file; ${selfCheckFix[stylingSystem] ?? selfCheckFix.css}.`,
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* What to do when the `astryx` command the text names is not found, as on a
|
|
6
|
+
* machine whose home folder outlives its system folders: the skill file
|
|
7
|
+
* survives a restart while the CLI installed for the computer does not.
|
|
8
|
+
* @param {string} install the install step
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function computerRestoreLine(install: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* The install step the text names. `judge`: the step a file is judged by, the
|
|
14
|
+
* one it records first, so every copy of one release, two global installs
|
|
15
|
+
* included, finds the same text current. `write`: the step a write records,
|
|
16
|
+
* the global copy's own first, since only the CLI installed for the computer
|
|
17
|
+
* chooses it. Either way npm's when there is no other.
|
|
18
|
+
* @param {{cliRoot?: string, home?: string, for?: 'judge' | 'write'}} [options]
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
export function computerInstallStep({ cliRoot, home, for: use, }?: {
|
|
22
|
+
cliRoot?: string;
|
|
23
|
+
home?: string;
|
|
24
|
+
for?: "judge" | "write";
|
|
25
|
+
}): string;
|
|
26
|
+
/**
|
|
27
|
+
* The install step a skill file's text records, or null when it records
|
|
28
|
+
* none.
|
|
29
|
+
* @param {string} content
|
|
30
|
+
* @returns {string | null}
|
|
31
|
+
*/
|
|
32
|
+
export function skillInstallStepOf(content: string): string | null;
|
|
4
33
|
/**
|
|
5
34
|
* A home-folder path as a person reads it: `~/.claude/skills/astryx`.
|
|
6
35
|
* @param {string} file
|
|
@@ -32,13 +61,21 @@ export function computerSkillLinks(home?: string): Array<{
|
|
|
32
61
|
* @returns {string}
|
|
33
62
|
*/
|
|
34
63
|
export function computerAgentCommand(): string;
|
|
64
|
+
/**
|
|
65
|
+
* The command a skill file's text names: the one in its "Start with" line,
|
|
66
|
+
* or null when the text has none.
|
|
67
|
+
* @param {string} content
|
|
68
|
+
* @returns {string | null}
|
|
69
|
+
*/
|
|
70
|
+
export function skillCommandOf(content: string): string | null;
|
|
35
71
|
/**
|
|
36
72
|
* The full skill file.
|
|
37
|
-
* @param {{command?: string}} [options]
|
|
73
|
+
* @param {{command?: string, install?: string}} [options]
|
|
38
74
|
* @returns {string}
|
|
39
75
|
*/
|
|
40
|
-
export function renderComputerAgentText({ command, }?: {
|
|
76
|
+
export function renderComputerAgentText({ command, install, }?: {
|
|
41
77
|
command?: string;
|
|
78
|
+
install?: string;
|
|
42
79
|
}): string;
|
|
43
80
|
/**
|
|
44
81
|
* Read-only: the state of the skill file against this release's rendering,
|
|
@@ -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 {
|
|
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({
|
|
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
|
-
|
|
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,
|
|
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') {
|