@astryxdesign/cli 0.7.2-canary.621784f → 0.7.2-canary.64e1dde
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/README.md +12 -12
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/gap-report/gap-report.d.mts +3 -0
- package/api/gap-report/gap-report.doc.mjs +11 -3
- package/api/gap-report/gap-report.mjs +152 -48
- package/api/gap-report/gap-report.test.mjs +233 -0
- package/api/gap-report/gap-report.type.d.mts +41 -0
- package/api/gap-report/gap-report.type.mjs +18 -0
- package/api/integration/_adapter.d.mts +10 -0
- package/api/integration/_adapter.mjs +13 -0
- package/api/integration/authoring-checks.mjs +14 -3
- package/api/integration/authoring-checks.test.mjs +326 -0
- package/api/integration/authoring-checks.type.d.mts +50 -0
- package/api/integration/authoring-checks.type.mjs +21 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
- package/api/integration/integrationDocConflicts.doc.mjs +17 -5
- package/api/integration/pack-check.mjs +292 -7
- package/api/integration/pack-check.test.mjs +341 -0
- package/api/integration/validateIntegration.doc.mjs +3 -1
- package/api/search/search.d.mts +72 -12
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.mjs +501 -37
- package/api/search/search.test.mjs +139 -0
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +110 -13
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/api/upgrade/_adapter.d.mts +40 -2
- package/api/upgrade/_adapter.mjs +117 -4
- package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
- package/api/upgrade/run/run.mjs +30 -1
- package/api/upgrade/status/status.d.mts +21 -5
- package/api/upgrade/status/status.mjs +45 -8
- package/api/upgrade/upgrade.doc.mjs +5 -3
- package/api/upgrade/upgrade.type.d.mts +23 -0
- package/api/upgrade/upgrade.type.mjs +16 -1
- package/assets/codemods/runner.mjs +7 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +6 -18
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +2 -2
- package/assets/docs/tree/check-your-docs.doc.mjs +16 -7
- package/assets/docs/tree/checks.doc.mjs +7 -7
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +3 -5
- package/assets/docs/tree/component-imports.doc.mjs +2 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +8 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/links.doc.mjs +5 -4
- package/assets/docs/tree/migration-setup.doc.mjs +3 -2
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +3 -7
- package/assets/docs/tree/publishing.doc.mjs +2 -2
- package/assets/docs/tree/quick-start.doc.mjs +37 -21
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
- package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +12 -4
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
- package/assets/docs/tree/upgrading.doc.mjs +4 -4
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +29 -26
- package/authoring/doctypes/component/type.ts +7 -5
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/template.doc.mjs +2 -2
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/integration/integration.doc.mjs +4 -3
- package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +17 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +34 -3
- package/clients/cli/commands/gap-report.doc.mjs +14 -2
- package/clients/cli/commands/gap-report.mjs +24 -2
- package/clients/cli/commands/gap-report.test.mjs +79 -0
- package/clients/cli/commands/integration-check.test.mjs +65 -0
- package/clients/cli/commands/integration.mjs +2 -3
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- package/clients/cli/index.mjs +29 -5
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/discovery/authoring-self-docs.mjs +1 -1
- package/foundation/discovery/copied-passages.d.mts +208 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-types.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +3 -3
- package/foundation/discovery/doc-types.test.mjs +48 -0
- package/foundation/discovery/docs-discovery.d.mts +7 -0
- package/foundation/discovery/docs-discovery.mjs +26 -2
- package/foundation/discovery/project-typescript.d.mts +11 -2
- package/foundation/discovery/project-typescript.mjs +32 -4
- package/foundation/discovery/prop-drift.d.mts +1 -1
- package/foundation/discovery/prop-drift.mjs +2 -2
- package/foundation/discovery/prop-drift.test.mjs +55 -2
- package/foundation/discovery/type-text.mjs +1 -1
- package/foundation/discovery/type-text.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +10 -2
- package/foundation/env/package-manager.d.mts +32 -0
- package/foundation/env/package-manager.mjs +47 -0
- package/foundation/env/package-manager.test.mjs +194 -7
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/response/response-types.doc.mjs +7 -6
- package/package.json +11 -11
- package/scripts/postinstall.mjs +3 -3
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx upgrade` with a CLI older than the installed Core: the human
|
|
5
|
+
* output never says the code is up to date, warns once with the same upgrade
|
|
6
|
+
* pinned to the CLI release that matches the Core, and keeps the exit status;
|
|
7
|
+
* `--json` carries the same facts in `cliBehindCore`. Pasted anywhere, the
|
|
8
|
+
* printed command runs that upgrade in the same project.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
12
|
+
import {spawnSync} from 'node:child_process';
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as os from 'node:os';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
17
|
+
import {CLI_ROOT} from '../../../foundation/fs/paths.mjs';
|
|
18
|
+
import {
|
|
19
|
+
commandInFolder,
|
|
20
|
+
getDlxPrefix,
|
|
21
|
+
quoteCommandArgument,
|
|
22
|
+
} from '../../../foundation/env/package-manager.mjs';
|
|
23
|
+
|
|
24
|
+
const CLI_VERSION = JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf8'),
|
|
26
|
+
).version;
|
|
27
|
+
const [MAJOR, MINOR] = CLI_VERSION.split('.').map(Number);
|
|
28
|
+
const NEWER_CORE = `${MAJOR}.${MINOR + 1}.0`;
|
|
29
|
+
const NON_ASCII = /[\u0080-\uFFFF]/;
|
|
30
|
+
|
|
31
|
+
let tmpDir;
|
|
32
|
+
|
|
33
|
+
/** @param {string} rel @param {string} body */
|
|
34
|
+
function write(rel, body) {
|
|
35
|
+
const file = path.join(tmpDir, rel);
|
|
36
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
37
|
+
fs.writeFileSync(file, body);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-upgrade-older-cli-'));
|
|
42
|
+
write('package.json', JSON.stringify({name: 'consumer', private: true}));
|
|
43
|
+
write(
|
|
44
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
45
|
+
JSON.stringify({name: '@astryxdesign/core', version: NEWER_CORE}),
|
|
46
|
+
);
|
|
47
|
+
write('src/index.ts', 'export const x = 1;\n');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The pinned command the CLI prints for this project. It names the folder the
|
|
56
|
+
* CLI ran in and the source directory as the CLI resolved them.
|
|
57
|
+
* @param {...string} rest the arguments after `--path <dir>`
|
|
58
|
+
*/
|
|
59
|
+
function pinned(...rest) {
|
|
60
|
+
const project = fs.realpathSync(tmpDir);
|
|
61
|
+
return commandInFolder(
|
|
62
|
+
project,
|
|
63
|
+
[
|
|
64
|
+
getDlxPrefix(tmpDir),
|
|
65
|
+
`@astryxdesign/cli@${NEWER_CORE}`,
|
|
66
|
+
'upgrade',
|
|
67
|
+
'--from',
|
|
68
|
+
CLI_VERSION,
|
|
69
|
+
'--path',
|
|
70
|
+
quoteCommandArgument(path.join(project, 'src')),
|
|
71
|
+
...rest,
|
|
72
|
+
].join(' '),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stand-ins for the package runners: each drops its own words and the pinned
|
|
78
|
+
* package, then runs this CLI with the rest of the command.
|
|
79
|
+
*/
|
|
80
|
+
const RUNS_THIS_CLI = [
|
|
81
|
+
['npx', 1],
|
|
82
|
+
['bunx', 1],
|
|
83
|
+
['pnpm', 2],
|
|
84
|
+
['yarn', 2],
|
|
85
|
+
]
|
|
86
|
+
.map(
|
|
87
|
+
([name, words]) =>
|
|
88
|
+
`${name}() { shift ${words}; "$0" ${quoteCommandArgument(path.join(CLI_ROOT, 'clients', 'cli', 'bin', 'astryx.mjs'))} "$@"; }`,
|
|
89
|
+
)
|
|
90
|
+
.join('; ');
|
|
91
|
+
|
|
92
|
+
describe('astryx upgrade with a CLI older than the installed Core', () => {
|
|
93
|
+
it('says it cannot finish and prints the upgrade pinned to the matching CLI', async () => {
|
|
94
|
+
const r = await runCli(['upgrade', '--from', CLI_VERSION, '--apply'], {
|
|
95
|
+
cwd: tmpDir,
|
|
96
|
+
});
|
|
97
|
+
const output = `${r.stdout}\n${r.stderr}`;
|
|
98
|
+
|
|
99
|
+
expect(r.status).toBe(0);
|
|
100
|
+
expect(output).not.toMatch(/up to date/i);
|
|
101
|
+
expect(output).not.toContain('No codemods available');
|
|
102
|
+
expect(r.stderr).toContain(
|
|
103
|
+
`This CLI (${CLI_VERSION}) is older than the installed @astryxdesign/core (${NEWER_CORE})`,
|
|
104
|
+
);
|
|
105
|
+
// The command has a line of its own, so it copies exactly.
|
|
106
|
+
expect(r.stderr).toContain(
|
|
107
|
+
`the CLI that matches your Core:\n ${pinned('--apply')}\n`,
|
|
108
|
+
);
|
|
109
|
+
expect(r.stdout.trim().split('\n').at(-1)).toBe('Upgrade incomplete');
|
|
110
|
+
expect(output.split('\n').filter(line => NON_ASCII.test(line))).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('carries cliBehindCore in --json with the same exit status', async () => {
|
|
114
|
+
const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
|
|
115
|
+
cwd: tmpDir,
|
|
116
|
+
});
|
|
117
|
+
const parsed = JSON.parse(r.stdout);
|
|
118
|
+
|
|
119
|
+
expect(r.status).toBe(0);
|
|
120
|
+
expect(parsed.type).toBe('upgrade.status');
|
|
121
|
+
expect(parsed.data.status).toBe('no_codemods');
|
|
122
|
+
expect(parsed.data.cliBehindCore).toEqual({
|
|
123
|
+
cliVersion: CLI_VERSION,
|
|
124
|
+
command: pinned(),
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Where an upgrade runs decides what it finds: the installed Core is read
|
|
129
|
+
// from that folder, and --path must stay inside it. Printed without its
|
|
130
|
+
// folder, the command exited 1 when pasted in a subfolder
|
|
131
|
+
// (ERR_PATH_TRAVERSAL) or in the folder above (ERR_VERSION_DETECT).
|
|
132
|
+
it.skipIf(process.platform === 'win32')(
|
|
133
|
+
'prints a command that upgrades the same project wherever it is pasted',
|
|
134
|
+
async () => {
|
|
135
|
+
write('src/deep/index.ts', 'export const y = 2;\n');
|
|
136
|
+
const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
|
|
137
|
+
cwd: tmpDir,
|
|
138
|
+
});
|
|
139
|
+
const {command} = JSON.parse(r.stdout).data.cliBehindCore;
|
|
140
|
+
|
|
141
|
+
for (const pastedIn of [
|
|
142
|
+
path.join(tmpDir, 'src', 'deep'),
|
|
143
|
+
path.dirname(tmpDir),
|
|
144
|
+
]) {
|
|
145
|
+
const ran = spawnSync(
|
|
146
|
+
'/bin/sh',
|
|
147
|
+
['-c', `${RUNS_THIS_CLI}; ${command}`, process.execPath],
|
|
148
|
+
{cwd: pastedIn, encoding: 'utf8'},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(ran.status, ran.stderr).toBe(0);
|
|
152
|
+
expect(ran.stdout).toContain(`Installed target: ${NEWER_CORE}`);
|
|
153
|
+
expect(ran.stdout).toContain(
|
|
154
|
+
`Scanning ${path.join(fs.realpathSync(tmpDir), 'src')} `,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
30_000,
|
|
159
|
+
);
|
|
160
|
+
});
|
package/clients/cli/index.mjs
CHANGED
|
@@ -26,7 +26,8 @@ import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
|
26
26
|
import {installJsonShim} from './lib/json-shim.mjs';
|
|
27
27
|
import {addDocHelp, markReportsResult} from './lib/define-command.mjs';
|
|
28
28
|
import {doc as manifestDoc} from './commands/manifest.doc.mjs';
|
|
29
|
-
import {isAstryxInitialized} from '../../foundation/agent-docs/agent-docs.mjs';
|
|
29
|
+
import {isAstryxInitialized, isAstryxPromptInReach} from '../../foundation/agent-docs/agent-docs.mjs';
|
|
30
|
+
import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
|
|
30
31
|
import * as debug from '../../foundation/debug/index.mjs';
|
|
31
32
|
|
|
32
33
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -277,6 +278,26 @@ const commands = [
|
|
|
277
278
|
];
|
|
278
279
|
|
|
279
280
|
const SETUP_NUDGE_EXEMPT = new Set(['init', 'agent-docs']);
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Is `cwd` inside the CLI's own source checkout while the CLI runs from it?
|
|
284
|
+
* An installed CLI always lives under `node_modules`; a CLI running from source
|
|
285
|
+
* does not, and its checkout is the pnpm workspace that holds it. Developing
|
|
286
|
+
* Astryx is not an app to set up, so the setup nudge stays quiet there.
|
|
287
|
+
* @param {string} cwd
|
|
288
|
+
* @returns {boolean}
|
|
289
|
+
*/
|
|
290
|
+
function inOwnSourceCheckout(cwd) {
|
|
291
|
+
if (CLI_ROOT.split(path.sep).includes('node_modules')) return false;
|
|
292
|
+
let checkout = CLI_ROOT;
|
|
293
|
+
while (!fs.existsSync(path.join(checkout, 'pnpm-workspace.yaml'))) {
|
|
294
|
+
const parent = path.dirname(checkout);
|
|
295
|
+
if (parent === checkout) return false;
|
|
296
|
+
checkout = parent;
|
|
297
|
+
}
|
|
298
|
+
const rel = path.relative(checkout, path.resolve(cwd));
|
|
299
|
+
return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
300
|
+
}
|
|
280
301
|
/** An integration package's manifest: the package is not an app to set up. */
|
|
281
302
|
const INTEGRATION_MANIFEST_FILES = [
|
|
282
303
|
'astryx.integration.ts',
|
|
@@ -528,8 +549,9 @@ export async function createProgram() {
|
|
|
528
549
|
|
|
529
550
|
/**
|
|
530
551
|
* Enforcement layer 3 — setup nudge. If this project hasn't run `astryx init`
|
|
531
|
-
* yet (no Astryx marker in any agent-doc file
|
|
532
|
-
* the user/agent that
|
|
552
|
+
* yet (no Astryx marker in any agent-doc file between the project and its
|
|
553
|
+
* repository root — see isAstryxPromptInReach), remind the user/agent that
|
|
554
|
+
* setup is missing.
|
|
533
555
|
*
|
|
534
556
|
* Uses `preAction` (not postAction) so it fires for EVERY valid command — even
|
|
535
557
|
* ones whose action errors or calls process.exit (postAction is skipped then).
|
|
@@ -539,7 +561,8 @@ export async function createProgram() {
|
|
|
539
561
|
* consumers parse stdout, not stderr — a stderr nudge would not reach them anyway.
|
|
540
562
|
* The core/cli postinstall layers already nudge at install time regardless of
|
|
541
563
|
* --json; a machine-readable nudge could later be an envelope field. Also skipped
|
|
542
|
-
* for the installer commands themselves
|
|
564
|
+
* for the installer commands themselves, outside a project (no package.json),
|
|
565
|
+
* and inside the CLI's own source checkout when it runs from there.
|
|
543
566
|
*/
|
|
544
567
|
program.hook('preAction', (thisCommand, actionCommand) => {
|
|
545
568
|
try {
|
|
@@ -549,7 +572,8 @@ export async function createProgram() {
|
|
|
549
572
|
if (!fs.existsSync(path.join(cwd, 'package.json'))) return; // not a project
|
|
550
573
|
// An integration package is not an app: `init` is not its next step.
|
|
551
574
|
if (INTEGRATION_MANIFEST_FILES.some(file => fs.existsSync(path.join(cwd, file)))) return;
|
|
552
|
-
if (
|
|
575
|
+
if (inOwnSourceCheckout(cwd)) return; // developing Astryx itself, not an app
|
|
576
|
+
if (isAstryxPromptInReach(cwd)) return; // already set up — stay quiet
|
|
553
577
|
// Same wording as the core/cli postinstall nudges. #4151's getCliInvocation()
|
|
554
578
|
// renders the correct form for THIS project — scoped `npx @astryxdesign/cli`
|
|
555
579
|
// one-off, or `<pm> astryx` when installed — never the bare `npx astryx` footgun.
|
|
@@ -20,6 +20,20 @@ export function discoverAgentDocs(targetDir: string): string[];
|
|
|
20
20
|
* @returns {boolean}
|
|
21
21
|
*/
|
|
22
22
|
export function isAstryxInitialized(targetDir?: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Does an agent working in `startDir` already have the Astryx prompt in reach?
|
|
25
|
+
*
|
|
26
|
+
* Coding agents read the agent docs between the repository root and the folder
|
|
27
|
+
* they work in. So inside a git repository, init's block in any folder from
|
|
28
|
+
* `startDir` up to the repository root counts: a workspace package of a
|
|
29
|
+
* monorepo initialized at its root is set up. Outside a repository only
|
|
30
|
+
* `startDir` itself is checked, as {@link isAstryxInitialized} does. Both the
|
|
31
|
+
* per-command nudge and the postinstall nudges ask this.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} [startDir=process.cwd()]
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
export function isAstryxPromptInReach(startDir?: string): boolean;
|
|
23
37
|
/**
|
|
24
38
|
* Pure decision: should a postinstall print the setup nudge? Shared by BOTH
|
|
25
39
|
* postinstall layers, so the matrix cannot drift between them, and unit-testable
|
|
@@ -96,6 +96,44 @@ export function isAstryxInitialized(targetDir = process.cwd()) {
|
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Does an agent working in `startDir` already have the Astryx prompt in reach?
|
|
101
|
+
*
|
|
102
|
+
* Coding agents read the agent docs between the repository root and the folder
|
|
103
|
+
* they work in. So inside a git repository, init's block in any folder from
|
|
104
|
+
* `startDir` up to the repository root counts: a workspace package of a
|
|
105
|
+
* monorepo initialized at its root is set up. Outside a repository only
|
|
106
|
+
* `startDir` itself is checked, as {@link isAstryxInitialized} does. Both the
|
|
107
|
+
* per-command nudge and the postinstall nudges ask this.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} [startDir=process.cwd()]
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
export function isAstryxPromptInReach(startDir = process.cwd()) {
|
|
113
|
+
const start = path.resolve(startDir);
|
|
114
|
+
const repositoryRoot = findRepositoryRoot(start);
|
|
115
|
+
if (!repositoryRoot) return isAstryxInitialized(start);
|
|
116
|
+
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
117
|
+
if (isAstryxInitialized(dir)) return true;
|
|
118
|
+
if (dir === repositoryRoot) return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The nearest folder at or above `start` that holds `.git` (a folder, or the
|
|
124
|
+
* file a worktree uses), or null outside a repository.
|
|
125
|
+
* @param {string} start
|
|
126
|
+
* @returns {string | null}
|
|
127
|
+
*/
|
|
128
|
+
function findRepositoryRoot(start) {
|
|
129
|
+
for (let dir = start; ; ) {
|
|
130
|
+
if (fs.existsSync(path.join(dir, '.git'))) return dir;
|
|
131
|
+
const parent = path.dirname(dir);
|
|
132
|
+
if (parent === dir) return null;
|
|
133
|
+
dir = parent;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
99
137
|
/**
|
|
100
138
|
* The one-line next-step both postinstall nudges print. Kept here so layer 1
|
|
101
139
|
* (core) and layer 2 (cli) can never word it differently.
|
|
@@ -226,4 +226,5 @@ export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, on
|
|
|
226
226
|
}): string[];
|
|
227
227
|
import { discoverAgentDocs } from './agent-doc-state.mjs';
|
|
228
228
|
import { isAstryxInitialized } from './agent-doc-state.mjs';
|
|
229
|
-
|
|
229
|
+
import { isAstryxPromptInReach } from './agent-doc-state.mjs';
|
|
230
|
+
export { discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach };
|
|
@@ -42,15 +42,17 @@ import {
|
|
|
42
42
|
LEGACY_MARKER_END,
|
|
43
43
|
discoverAgentDocs,
|
|
44
44
|
isAstryxInitialized,
|
|
45
|
+
isAstryxPromptInReach,
|
|
45
46
|
} from './agent-doc-state.mjs';
|
|
46
47
|
|
|
47
48
|
// The agent-doc locations, markers, and the setup-state predicates
|
|
48
|
-
// (discoverAgentDocs, isAstryxInitialized) are the ONE
|
|
49
|
-
// live in the dependency-free leaf
|
|
50
|
-
// nudge (enforcement layer 2) can load
|
|
51
|
-
//
|
|
52
|
-
// clients/cli/index.mjs, tests)
|
|
53
|
-
|
|
49
|
+
// (discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach) are the ONE
|
|
50
|
+
// canonical contract. They live in the dependency-free leaf
|
|
51
|
+
// ./agent-doc-state.mjs so the postinstall nudge (enforcement layer 2) can load
|
|
52
|
+
// them safely at install time. Re-exported here so existing importers
|
|
53
|
+
// (init/upgrade commands, the layer-3 nudge in clients/cli/index.mjs, tests)
|
|
54
|
+
// keep their `from './agent-docs.mjs'` paths.
|
|
55
|
+
export {discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach};
|
|
54
56
|
|
|
55
57
|
const MAX_PROJECT_AGENT_DOC_LINES = 32;
|
|
56
58
|
const MANAGED_MARKER_TEXT = /(?:ASTRYX|XDS):(START|END)/u;
|
|
@@ -193,7 +193,7 @@ export function buildAuthoringReferenceDoc(docs) {
|
|
|
193
193
|
title: 'Authoring Reference',
|
|
194
194
|
category: 'guide',
|
|
195
195
|
description:
|
|
196
|
-
'Every file an integration author writes, field by field: the integration manifest, astryx.config, codemods, identity, and each doc type.',
|
|
196
|
+
'Every file an integration author writes, field by field: the integration manifest, astryx.config, codemods, identity, and each doc type. The step-by-step guides are under `astryx docs cli/integrations`.',
|
|
197
197
|
sections: docs.map(selfDocSection),
|
|
198
198
|
});
|
|
199
199
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The number of distinct content words in a run: words that are not function
|
|
6
|
+
* words, with surrounding punctuation set aside.
|
|
7
|
+
*
|
|
8
|
+
* @param {{word: string}[]} words
|
|
9
|
+
* @param {number} start
|
|
10
|
+
* @param {number} length
|
|
11
|
+
*/
|
|
12
|
+
export function contentWords(words: {
|
|
13
|
+
word: string;
|
|
14
|
+
}[], start: number, length: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* The words a passage is compared by: lowercase, with links and Markdown
|
|
17
|
+
* emphasis set aside. A token with no letter or digit (the `.` after a link)
|
|
18
|
+
* is not a word.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} text
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function passageWords(text: string): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Every word of a doc file, in order, with its 1-based line. Words are runs of
|
|
26
|
+
* letters and digits, so punctuation, code ticks, quotes and escapes in the
|
|
27
|
+
* source neither join nor split them.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} source
|
|
30
|
+
* @returns {{word: string, line: number}[]}
|
|
31
|
+
*/
|
|
32
|
+
export function fileWords(source: string): {
|
|
33
|
+
word: string;
|
|
34
|
+
line: number;
|
|
35
|
+
}[];
|
|
36
|
+
/**
|
|
37
|
+
* The words of a string the way {@link fileWords} reads a file, each with its
|
|
38
|
+
* offset in the string.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} text
|
|
41
|
+
* @returns {{word: string, at: number}[]}
|
|
42
|
+
*/
|
|
43
|
+
export function textWords(text: string): {
|
|
44
|
+
word: string;
|
|
45
|
+
at: number;
|
|
46
|
+
}[];
|
|
47
|
+
/**
|
|
48
|
+
* Where a string's whole run of words starts among a file's words, looking
|
|
49
|
+
* from `from` on, or -1.
|
|
50
|
+
*
|
|
51
|
+
* @param {{word: string}[]} file
|
|
52
|
+
* @param {{word: string}[]} words
|
|
53
|
+
* @param {number} [from]
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
export function locateWords(file: {
|
|
57
|
+
word: string;
|
|
58
|
+
}[], words: {
|
|
59
|
+
word: string;
|
|
60
|
+
}[], from?: number): number;
|
|
61
|
+
/**
|
|
62
|
+
* The file line of the character at offset `at` of a string whose words start
|
|
63
|
+
* at `index` among the file's words.
|
|
64
|
+
*
|
|
65
|
+
* @param {{line: number}[]} file
|
|
66
|
+
* @param {number} index
|
|
67
|
+
* @param {{at: number}[]} words the string's words
|
|
68
|
+
* @param {number} at
|
|
69
|
+
* @returns {number | null}
|
|
70
|
+
*/
|
|
71
|
+
export function lineAtOffset(file: {
|
|
72
|
+
line: number;
|
|
73
|
+
}[], index: number, words: {
|
|
74
|
+
at: number;
|
|
75
|
+
}[], at: number): number | null;
|
|
76
|
+
/**
|
|
77
|
+
* A shared run with the boilerplate trimmed off its ends, judged window by
|
|
78
|
+
* window: every word a leading boilerplate window covers, and every word from
|
|
79
|
+
* the first trailing one on. A lead-in many topics open with thus never hides
|
|
80
|
+
* the copy after it. Null when less than {@link PASSAGE_WORDS} words are left.
|
|
81
|
+
*
|
|
82
|
+
* @param {{start: number, length: number}} run
|
|
83
|
+
* @param {(at: number) => boolean} boilerplate whether the window of
|
|
84
|
+
* {@link PASSAGE_WORDS} words starting at `at` is boilerplate
|
|
85
|
+
* @returns {{start: number, length: number} | null}
|
|
86
|
+
*/
|
|
87
|
+
export function trimBoilerplate({ start, length }: {
|
|
88
|
+
start: number;
|
|
89
|
+
length: number;
|
|
90
|
+
}, boilerplate: (at: number) => boolean): {
|
|
91
|
+
start: number;
|
|
92
|
+
length: number;
|
|
93
|
+
} | null;
|
|
94
|
+
/**
|
|
95
|
+
* The words of one string as passageWords reads them, each with where it sits
|
|
96
|
+
* in the string as written, so a passage can be quoted with its case,
|
|
97
|
+
* punctuation and code ticks.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} text
|
|
100
|
+
* @returns {{word: string, start: number, end: number}[]}
|
|
101
|
+
*/
|
|
102
|
+
export function wordSpans(text: string): {
|
|
103
|
+
word: string;
|
|
104
|
+
start: number;
|
|
105
|
+
end: number;
|
|
106
|
+
}[];
|
|
107
|
+
/**
|
|
108
|
+
* Each prose string of a doc, in order, with the title of the section it is
|
|
109
|
+
* in (null before the first section). Code, examples, reference blocks, and
|
|
110
|
+
* identifier fields are left out.
|
|
111
|
+
*
|
|
112
|
+
* @param {unknown} doc an authored doc object
|
|
113
|
+
* @returns {{text: string, section: string | null}[]}
|
|
114
|
+
*/
|
|
115
|
+
export function proseStrings(doc: unknown): {
|
|
116
|
+
text: string;
|
|
117
|
+
section: string | null;
|
|
118
|
+
}[];
|
|
119
|
+
/**
|
|
120
|
+
* Each prose word of a doc, in order, with the title of the section it is in
|
|
121
|
+
* (null before the first section) and the number of the string it came from.
|
|
122
|
+
* A passage never runs from one string into the next, so two fields that
|
|
123
|
+
* happen to sit side by side are not read as one sentence.
|
|
124
|
+
*
|
|
125
|
+
* @param {unknown} doc an authored doc object
|
|
126
|
+
* @returns {{word: string, section: string | null, block: number}[]}
|
|
127
|
+
*/
|
|
128
|
+
export function proseWords(doc: unknown): {
|
|
129
|
+
word: string;
|
|
130
|
+
section: string | null;
|
|
131
|
+
block: number;
|
|
132
|
+
}[];
|
|
133
|
+
/**
|
|
134
|
+
* The runs of at least `size` words that both docs have, each inside one
|
|
135
|
+
* string of each doc, longest first, as its start in `mine` and its length.
|
|
136
|
+
*
|
|
137
|
+
* @param {{word: string, block?: number}[]} mine
|
|
138
|
+
* @param {{word: string, block?: number}[]} other
|
|
139
|
+
* @param {number} [size]
|
|
140
|
+
* @returns {{start: number, length: number}[]}
|
|
141
|
+
*/
|
|
142
|
+
export function sharedPassages(mine: {
|
|
143
|
+
word: string;
|
|
144
|
+
block?: number;
|
|
145
|
+
}[], other: {
|
|
146
|
+
word: string;
|
|
147
|
+
block?: number;
|
|
148
|
+
}[], size?: number): {
|
|
149
|
+
start: number;
|
|
150
|
+
length: number;
|
|
151
|
+
}[];
|
|
152
|
+
/**
|
|
153
|
+
* One entry for each pair of topics that repeat a passage word for word: two
|
|
154
|
+
* of the package's own topics, or one of them and a Core topic, except the
|
|
155
|
+
* Core topic it replaces (a replacement takes that topic's place, so it may
|
|
156
|
+
* carry its text).
|
|
157
|
+
*
|
|
158
|
+
* @param {{records: {name: string, path: string, replaces?: string | null, extendsTopic?: string | null}[], guides?: {name: string, ref?: {topicFile?: string}}[]}} discovered
|
|
159
|
+
* the package's docs, as discoverIntegrationDocs returns them
|
|
160
|
+
* @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').CopiedPassage[]>}
|
|
161
|
+
*/
|
|
162
|
+
export function findCopiedPassages(discovered: {
|
|
163
|
+
records: {
|
|
164
|
+
name: string;
|
|
165
|
+
path: string;
|
|
166
|
+
replaces?: string | null;
|
|
167
|
+
extendsTopic?: string | null;
|
|
168
|
+
}[];
|
|
169
|
+
guides?: {
|
|
170
|
+
name: string;
|
|
171
|
+
ref?: {
|
|
172
|
+
topicFile?: string;
|
|
173
|
+
};
|
|
174
|
+
}[];
|
|
175
|
+
}): Promise<import("../../api/integration/authoring-checks.type.mjs").CopiedPassage[]>;
|
|
176
|
+
/** The shortest run of identical words reported as a copy. */
|
|
177
|
+
export const PASSAGE_WORDS: 10;
|
|
178
|
+
/**
|
|
179
|
+
* A copy carries at least this many distinct content words, so a run of
|
|
180
|
+
* glue words ("and it is in the way that you can…") is a phrase, not a fact.
|
|
181
|
+
*/
|
|
182
|
+
export const MIN_CONTENT_WORDS: 4;
|
|
183
|
+
/**
|
|
184
|
+
* A run that this many topics share is boilerplate, such as a lead-in every
|
|
185
|
+
* guide of a series opens with, not a copy of one topic's fact.
|
|
186
|
+
*/
|
|
187
|
+
export const BOILERPLATE_TOPICS: 3;
|
|
188
|
+
export type GuideWords = {
|
|
189
|
+
name: string;
|
|
190
|
+
title?: string;
|
|
191
|
+
file?: string;
|
|
192
|
+
doc?: unknown;
|
|
193
|
+
words: {
|
|
194
|
+
word: string;
|
|
195
|
+
section: string | null;
|
|
196
|
+
block: number;
|
|
197
|
+
}[];
|
|
198
|
+
replaces: string | null;
|
|
199
|
+
extendsTopic?: string | null;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Guides with an index from each run of words to the guides that have it, so
|
|
203
|
+
* a topic is compared in full only with the guides it shares a run with.
|
|
204
|
+
*/
|
|
205
|
+
export type IndexedGuides = {
|
|
206
|
+
guides: GuideWords[];
|
|
207
|
+
index: Map<string, number[]>;
|
|
208
|
+
};
|