@astryxdesign/cli 0.6.1 → 0.6.2-canary.bc93547
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/CHANGELOG.md +34 -0
- package/README.md +1 -1
- package/api/component/_adapter.mjs +64 -23
- package/api/component/component.doc.mjs +1 -1
- package/api/component/component.type.d.mts +8 -2
- package/api/component/component.type.mjs +5 -2
- package/api/component/integration-import-agreement.test.mjs +162 -6
- package/api/component/list/list.mjs +91 -15
- package/api/doctor/doctor.mjs +5 -16
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.type.d.mts +1 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/run/run.mjs +1 -1
- package/api/integration/add-helpers.mjs +2 -1
- package/api/integration/pack-check.mjs +9 -3
- package/api/search/search.d.mts +1 -1
- package/api/search/search.mjs +135 -41
- package/api/theme/build/build.d.mts +45 -17
- package/api/theme/build/build.family.test.mjs +435 -0
- package/api/theme/build/build.mjs +681 -121
- package/api/theme/build/build.packed-old-core.test.mjs +25 -9
- package/api/theme/build/build.test.mjs +142 -0
- package/api/theme/build/core-interception.d.mts +14 -2
- package/api/theme/build/core-interception.mjs +38 -14
- package/api/theme/build/family.d.mts +15 -0
- package/api/theme/build/family.mjs +442 -0
- package/api/theme/palette/generate/generate.mjs +2 -1
- package/assets/docs/theme.doc.dense.mjs +12 -0
- package/assets/docs/theme.doc.mjs +37 -0
- package/assets/docs/working-with-ai.doc.mjs +2 -1
- package/clients/cli/commands/build-theme.mjs +63 -5
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/init.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +28 -10
- package/foundation/agent-docs/agent-doc-state.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/agent-docs/agent-docs.test.mjs +14 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.d.mts +24 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.mjs +19 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.d.mts +14 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.mjs +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.d.mts +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.mjs +11 -0
- package/foundation/discovery/component-discovery.d.mts +5 -3
- package/foundation/discovery/component-discovery.mjs +25 -9
- package/foundation/discovery/component-loader.mjs +4 -1
- package/foundation/discovery/component-loader.test.mjs +48 -0
- package/foundation/discovery/theming-targets.test.mjs +29 -0
- package/foundation/fs/paths.d.mts +19 -0
- package/foundation/fs/paths.mjs +54 -0
- package/foundation/fs/paths.test.mjs +102 -1
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +62 -0
- package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +107 -0
- package/foundation/fs/publish-file.d.mts +22 -0
- package/foundation/fs/publish-file.mjs +68 -0
- package/foundation/fs/publish-file.test.mjs +136 -0
- package/foundation/integrations/manifest-writer.mjs +2 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +15 -10
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
discoverIntegrationComponents,
|
|
19
19
|
findComponentReadme,
|
|
20
20
|
resolveImportPath,
|
|
21
|
+
resolveIntegrationImportPath,
|
|
21
22
|
} from '../../../foundation/discovery/component-discovery.mjs';
|
|
22
23
|
import {discoverExternalPackages} from '../../../foundation/fs/paths.mjs';
|
|
23
24
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
@@ -44,7 +45,10 @@ import {loadComponentDoc, loadIntegrationsSafely} from '../_adapter.mjs';
|
|
|
44
45
|
* @param {string|null} opts.lang
|
|
45
46
|
* @returns {Promise<ComponentListResponse>}
|
|
46
47
|
*/
|
|
47
|
-
export async function componentList(
|
|
48
|
+
export async function componentList(
|
|
49
|
+
coreDir,
|
|
50
|
+
{cwd, category, detail, zh, dense, lang},
|
|
51
|
+
) {
|
|
48
52
|
const components = discoverComponents(coreDir);
|
|
49
53
|
|
|
50
54
|
if (category) {
|
|
@@ -67,15 +71,30 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
67
71
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
68
72
|
try {
|
|
69
73
|
const docs = await loadComponentDoc(readme, {zh, lang});
|
|
70
|
-
entries.push({
|
|
74
|
+
entries.push({
|
|
75
|
+
name: comp,
|
|
76
|
+
description: docs.usage?.description || docs.description || '',
|
|
77
|
+
import: resolveImportPath(coreDir, comp),
|
|
78
|
+
});
|
|
71
79
|
} catch {
|
|
72
|
-
entries.push({
|
|
80
|
+
entries.push({
|
|
81
|
+
name: comp,
|
|
82
|
+
description: '',
|
|
83
|
+
import: resolveImportPath(coreDir, comp),
|
|
84
|
+
});
|
|
73
85
|
}
|
|
74
86
|
} else {
|
|
75
|
-
entries.push({
|
|
87
|
+
entries.push({
|
|
88
|
+
name: comp,
|
|
89
|
+
description: '',
|
|
90
|
+
import: resolveImportPath(coreDir, comp),
|
|
91
|
+
});
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
type: 'component.list',
|
|
96
|
+
data: {detail: 'compact', components: {[match[0]]: entries}},
|
|
97
|
+
};
|
|
79
98
|
}
|
|
80
99
|
|
|
81
100
|
if (detail === 'full') {
|
|
@@ -93,7 +112,10 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
93
112
|
entries.push({name: `XDS${comp}`, description: ''});
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
|
-
return {
|
|
115
|
+
return {
|
|
116
|
+
type: 'component.list',
|
|
117
|
+
data: {detail: 'full', components: {[match[0]]: entries}},
|
|
118
|
+
};
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
// Default: brief — package-qualified object list for the category.
|
|
@@ -101,7 +123,12 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
101
123
|
// strings, so consumers can disambiguate ownership.
|
|
102
124
|
return {
|
|
103
125
|
type: 'component.list',
|
|
104
|
-
data: {
|
|
126
|
+
data: {
|
|
127
|
+
detail: 'names',
|
|
128
|
+
components: {
|
|
129
|
+
[match[0]]: match[1].map(n => ({name: n, package: CORE_PACKAGE})),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
105
132
|
};
|
|
106
133
|
}
|
|
107
134
|
|
|
@@ -116,16 +143,31 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
116
143
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
117
144
|
try {
|
|
118
145
|
const docs = await loadComponentDoc(readme, {zh, lang});
|
|
119
|
-
result[cat].push({
|
|
146
|
+
result[cat].push({
|
|
147
|
+
name: comp,
|
|
148
|
+
description: docs.usage?.description || docs.description || '',
|
|
149
|
+
import: resolveImportPath(coreDir, comp),
|
|
150
|
+
});
|
|
120
151
|
} catch {
|
|
121
|
-
result[cat].push({
|
|
152
|
+
result[cat].push({
|
|
153
|
+
name: comp,
|
|
154
|
+
description: '',
|
|
155
|
+
import: resolveImportPath(coreDir, comp),
|
|
156
|
+
});
|
|
122
157
|
}
|
|
123
158
|
} else {
|
|
124
|
-
result[cat].push({
|
|
159
|
+
result[cat].push({
|
|
160
|
+
name: comp,
|
|
161
|
+
description: '',
|
|
162
|
+
import: resolveImportPath(coreDir, comp),
|
|
163
|
+
});
|
|
125
164
|
}
|
|
126
165
|
}
|
|
127
166
|
}
|
|
128
|
-
return {
|
|
167
|
+
return {
|
|
168
|
+
type: 'component.list',
|
|
169
|
+
data: {detail: 'compact', components: result},
|
|
170
|
+
};
|
|
129
171
|
}
|
|
130
172
|
|
|
131
173
|
if (detail === 'full') {
|
|
@@ -151,7 +193,7 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
151
193
|
|
|
152
194
|
// Default: brief — package-qualified object list (core + integrations).
|
|
153
195
|
// Pre-1.0 JSON contract: each group's members are {name, package} objects.
|
|
154
|
-
/** @type {Record<string,
|
|
196
|
+
/** @type {Record<string, ComponentListEntry[]>} */
|
|
155
197
|
const listData = {};
|
|
156
198
|
for (const [cat, comps] of Object.entries(components)) {
|
|
157
199
|
listData[cat] = comps.map(n => ({name: n, package: CORE_PACKAGE}));
|
|
@@ -166,13 +208,44 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
166
208
|
// Group integration components by their doc `group`, falling back to the
|
|
167
209
|
// package name. Keys are package-qualified so they never collide with
|
|
168
210
|
// core groups or each other.
|
|
169
|
-
/** @type {Map<string, Array<{name: string, package: string}>>} */
|
|
211
|
+
/** @type {Map<string, Array<{name: string, package: string, import?: string}>>} */
|
|
170
212
|
const byGroup = new Map();
|
|
171
213
|
for (const rec of owned) {
|
|
172
214
|
const groupLabel = rec.group ?? integration.name;
|
|
173
215
|
const key = `${groupLabel} (${integration.name})`;
|
|
174
216
|
if (!byGroup.has(key)) byGroup.set(key, []);
|
|
175
|
-
|
|
217
|
+
// Use the doc-authored import when present; otherwise resolve the package
|
|
218
|
+
// export so list, detail, search, JSON, and human output all agree.
|
|
219
|
+
const fallbackImport = resolveIntegrationImportPath(
|
|
220
|
+
{
|
|
221
|
+
exportsMap: integration.__packageExports,
|
|
222
|
+
packageDir: integration.__packageDir,
|
|
223
|
+
docPath: rec.docPath,
|
|
224
|
+
packageName: integration.name,
|
|
225
|
+
},
|
|
226
|
+
rec.name,
|
|
227
|
+
);
|
|
228
|
+
let importPath = fallbackImport;
|
|
229
|
+
try {
|
|
230
|
+
const docs = await loadComponentDoc(rec.docPath, {zh, lang});
|
|
231
|
+
importPath = resolveIntegrationImportPath(
|
|
232
|
+
{
|
|
233
|
+
exportsMap: integration.__packageExports,
|
|
234
|
+
packageDir: integration.__packageDir,
|
|
235
|
+
docPath: rec.docPath,
|
|
236
|
+
packageName: integration.name,
|
|
237
|
+
},
|
|
238
|
+
rec.name,
|
|
239
|
+
docs.import,
|
|
240
|
+
);
|
|
241
|
+
} catch {
|
|
242
|
+
// Keep list resilient; validation owns malformed integration docs.
|
|
243
|
+
}
|
|
244
|
+
byGroup.get(key)?.push({
|
|
245
|
+
name: rec.name,
|
|
246
|
+
package: integration.name,
|
|
247
|
+
import: importPath,
|
|
248
|
+
});
|
|
176
249
|
}
|
|
177
250
|
for (const [key, members] of byGroup) {
|
|
178
251
|
members.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -211,5 +284,8 @@ export async function componentList(coreDir, {cwd, category, detail, zh, dense,
|
|
|
211
284
|
}
|
|
212
285
|
}
|
|
213
286
|
}
|
|
214
|
-
return {
|
|
287
|
+
return {
|
|
288
|
+
type: 'component.list',
|
|
289
|
+
data: {detail: 'names', components: listData},
|
|
290
|
+
};
|
|
215
291
|
}
|
package/api/doctor/doctor.mjs
CHANGED
|
@@ -22,16 +22,13 @@
|
|
|
22
22
|
|
|
23
23
|
import * as fs from 'node:fs';
|
|
24
24
|
import * as path from 'node:path';
|
|
25
|
-
import {createRequire} from 'node:module';
|
|
26
25
|
|
|
27
26
|
import {MIN_NODE_VERSION, isNodeVersionSupported} from '../../foundation/env/node-version.mjs';
|
|
28
|
-
import {CLI_ROOT, findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
27
|
+
import {CLI_ROOT, findCoreDir, findInstalledPackage} from '../../foundation/fs/paths.mjs';
|
|
29
28
|
import {explainPackageManager, getCliInvocation} from '../../foundation/env/package-manager.mjs';
|
|
30
29
|
import {findConfigPath, Project} from '../../foundation/config/project.mjs';
|
|
31
30
|
import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env/semver.mjs';
|
|
32
31
|
|
|
33
|
-
const _require = createRequire(import.meta.url);
|
|
34
|
-
|
|
35
32
|
/**
|
|
36
33
|
* @typedef {'pass'|'warn'|'fail'|'info'} DoctorStatus
|
|
37
34
|
*
|
|
@@ -527,23 +524,15 @@ export function checkPeerDeps(ctx) {
|
|
|
527
524
|
const mismatched = [];
|
|
528
525
|
for (const name of peerNames) {
|
|
529
526
|
const want = peers[name];
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
} catch {
|
|
534
|
-
// package.json isn't exported — fall back to entry resolution for
|
|
535
|
-
// presence only (we then can't read the version to range-check it).
|
|
536
|
-
try {
|
|
537
|
-
_require.resolve(name, {paths: [ctx.cwd]});
|
|
538
|
-
} catch {
|
|
539
|
-
missing.push(`${name}@${want}`);
|
|
540
|
-
}
|
|
527
|
+
const installedDir = findInstalledPackage(ctx.cwd, name);
|
|
528
|
+
if (!installedDir) {
|
|
529
|
+
missing.push(`${name}@${want}`);
|
|
541
530
|
continue;
|
|
542
531
|
}
|
|
543
532
|
// Present and version-readable: verify it actually satisfies the range,
|
|
544
533
|
// not just that the package exists (a bare `npm install` can resolve an
|
|
545
534
|
// out-of-range version from a stale consumer range and still "look" fine).
|
|
546
|
-
const have = pkgVersion(
|
|
535
|
+
const have = pkgVersion(installedDir);
|
|
547
536
|
if (have && !satisfiesRange(have, want)) {
|
|
548
537
|
mismatched.push({name, want, have});
|
|
549
538
|
}
|
package/api/init/init.doc.mjs
CHANGED
|
@@ -46,7 +46,7 @@ export const doc = {
|
|
|
46
46
|
{
|
|
47
47
|
name: 'options.agent',
|
|
48
48
|
type: 'string',
|
|
49
|
-
description: 'Agent preset: claude, cursor, codex, hermes, all.',
|
|
49
|
+
description: 'Agent preset: claude, cursor, codex, hermes, muse, all.',
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
name: 'options.agentDocsPath',
|
|
@@ -76,7 +76,7 @@ export const doc = {
|
|
|
76
76
|
throws: [
|
|
77
77
|
{
|
|
78
78
|
code: 'ERR_UNKNOWN_AGENT',
|
|
79
|
-
when: '`agent` is not one of claude, cursor, codex, hermes, all',
|
|
79
|
+
when: '`agent` is not one of claude, cursor, codex, hermes, muse, all',
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
code: 'ERR_UNKNOWN_FEATURE',
|
package/api/init/init.type.d.mts
CHANGED
package/api/init/init.type.mjs
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* @property {string} [features] Comma-separated features to install (agents, theme, template).
|
|
39
39
|
* @property {boolean} [all] Install all features.
|
|
40
40
|
* @property {boolean} [removeAgents] Remove the managed agent-docs block instead of installing.
|
|
41
|
-
* @property {string} [agent] Agent preset: claude, cursor, codex, hermes, all.
|
|
41
|
+
* @property {string} [agent] Agent preset: claude, cursor, codex, hermes, muse, all.
|
|
42
42
|
* @property {string | string[]} [agentDocsPath] Explicit agent-docs file path(s).
|
|
43
43
|
* @property {string} [templateName] Scaffold a named page template (programmatic only; the CLI never sets it).
|
|
44
44
|
*/
|
package/api/init/run/run.mjs
CHANGED
|
@@ -30,7 +30,7 @@ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
|
30
30
|
import {logger} from '../../logger.mjs';
|
|
31
31
|
|
|
32
32
|
const VALID_FEATURES = ['agents', 'theme', 'template'];
|
|
33
|
-
const VALID_AGENTS = ['claude', 'cursor', 'codex', 'hermes', 'all'];
|
|
33
|
+
const VALID_AGENTS = ['claude', 'cursor', 'codex', 'hermes', 'muse', 'all'];
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Build the "Next steps" lines printed at the end of `astryx init`.
|
|
@@ -13,6 +13,7 @@ import * as fs from 'node:fs';
|
|
|
13
13
|
import * as path from 'node:path';
|
|
14
14
|
import {randomUUID} from 'node:crypto';
|
|
15
15
|
import {AstryxError} from '../error.mjs';
|
|
16
|
+
import {publishNewFile} from '../../foundation/fs/publish-file.mjs';
|
|
16
17
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
18
|
|
|
18
19
|
/** @param {string} value */
|
|
@@ -310,7 +311,7 @@ export function applyWrites(plans) {
|
|
|
310
311
|
|
|
311
312
|
for (const plan of staged) {
|
|
312
313
|
if (plan.original == null) {
|
|
313
|
-
|
|
314
|
+
publishNewFile(plan.temporary, plan.path);
|
|
314
315
|
published.push(plan);
|
|
315
316
|
removeTemporary(plan.temporary);
|
|
316
317
|
continue;
|
|
@@ -353,13 +353,21 @@ function resolveConsumerSpecifiers(specifiers, scratchBase) {
|
|
|
353
353
|
*/
|
|
354
354
|
async function validatePackedComponentExports(integration, scratchBase) {
|
|
355
355
|
const records = discoverIntegrationComponents(integration);
|
|
356
|
+
/** @type {Issue[]} */
|
|
357
|
+
const issues = [];
|
|
356
358
|
/** @type {Array<{name: string, specifier: string}>} */
|
|
357
359
|
const components = [];
|
|
358
360
|
for (const record of records) {
|
|
359
361
|
let docs;
|
|
360
362
|
try {
|
|
361
363
|
docs = await loadComponentDoc(record.docPath);
|
|
362
|
-
} catch {
|
|
364
|
+
} catch (err) {
|
|
365
|
+
issues.push(
|
|
366
|
+
error(
|
|
367
|
+
'component_doc_unloadable',
|
|
368
|
+
`Component "${record.name}" doc at "${record.docPath}" could not be loaded: ${err instanceof Error ? err.message : String(err)}`,
|
|
369
|
+
),
|
|
370
|
+
);
|
|
363
371
|
continue;
|
|
364
372
|
}
|
|
365
373
|
const specifier =
|
|
@@ -380,8 +388,6 @@ async function validatePackedComponentExports(integration, scratchBase) {
|
|
|
380
388
|
components.map(component => component.specifier),
|
|
381
389
|
scratchBase,
|
|
382
390
|
);
|
|
383
|
-
/** @type {Issue[]} */
|
|
384
|
-
const issues = [];
|
|
385
391
|
for (const {name, specifier} of components) {
|
|
386
392
|
const result = resolved.get(specifier);
|
|
387
393
|
if (!result?.url || result.error) {
|
package/api/search/search.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
49
49
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
50
50
|
* @returns {{score: number, reason: string} | null}
|
|
51
51
|
*/
|
|
52
|
-
export function scoreCandidate(term: string, { name, keywords, weakKeywords, description, prose, guidance }: {
|
|
52
|
+
export function scoreCandidate(term: string, { name, keywords, weakKeywords, description, prose, guidance, }: {
|
|
53
53
|
name: string;
|
|
54
54
|
keywords?: string[] | undefined;
|
|
55
55
|
weakKeywords?: string[] | undefined;
|
package/api/search/search.mjs
CHANGED
|
@@ -59,7 +59,10 @@ import {
|
|
|
59
59
|
resolveImportPath,
|
|
60
60
|
resolveIntegrationImportPath,
|
|
61
61
|
} from '../../foundation/discovery/component-discovery.mjs';
|
|
62
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
discoverHooks,
|
|
64
|
+
findHookDoc,
|
|
65
|
+
} from '../../foundation/discovery/hook-discovery.mjs';
|
|
63
66
|
import {loadIntegrationsSafely} from '../component/_adapter.mjs';
|
|
64
67
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
65
68
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
@@ -92,7 +95,17 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
92
95
|
* and its siblings). Lowercase, single words or short phrases.
|
|
93
96
|
*/
|
|
94
97
|
const SYNONYMS = {
|
|
95
|
-
dashboard: [
|
|
98
|
+
dashboard: [
|
|
99
|
+
'overview',
|
|
100
|
+
'analytics',
|
|
101
|
+
'kpi',
|
|
102
|
+
'kpis',
|
|
103
|
+
'metrics',
|
|
104
|
+
'stats',
|
|
105
|
+
'reporting',
|
|
106
|
+
'insights',
|
|
107
|
+
'control',
|
|
108
|
+
],
|
|
96
109
|
login: ['signin', 'auth', 'authentication', 'sso', 'credentials', 'account'],
|
|
97
110
|
signup: ['register', 'registration', 'onboarding'],
|
|
98
111
|
payment: ['checkout', 'billing', 'card', 'pay', 'purchase', 'order'],
|
|
@@ -153,7 +166,6 @@ export function stem(w) {
|
|
|
153
166
|
return s;
|
|
154
167
|
}
|
|
155
168
|
|
|
156
|
-
|
|
157
169
|
/** Valid domain filters for `--type`. */
|
|
158
170
|
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
159
171
|
|
|
@@ -162,12 +174,66 @@ export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
|
162
174
|
* ("a page where you can see business stats") ranks on its content words.
|
|
163
175
|
*/
|
|
164
176
|
const STOPWORDS = new Set([
|
|
165
|
-
'a',
|
|
166
|
-
'
|
|
167
|
-
'
|
|
168
|
-
'
|
|
169
|
-
'
|
|
170
|
-
'
|
|
177
|
+
'a',
|
|
178
|
+
'an',
|
|
179
|
+
'the',
|
|
180
|
+
'of',
|
|
181
|
+
'for',
|
|
182
|
+
'to',
|
|
183
|
+
'with',
|
|
184
|
+
'and',
|
|
185
|
+
'or',
|
|
186
|
+
'in',
|
|
187
|
+
'on',
|
|
188
|
+
'at',
|
|
189
|
+
'by',
|
|
190
|
+
'that',
|
|
191
|
+
'this',
|
|
192
|
+
'my',
|
|
193
|
+
'your',
|
|
194
|
+
'our',
|
|
195
|
+
'their',
|
|
196
|
+
'is',
|
|
197
|
+
'are',
|
|
198
|
+
'be',
|
|
199
|
+
'it',
|
|
200
|
+
'its',
|
|
201
|
+
'as',
|
|
202
|
+
'from',
|
|
203
|
+
'page',
|
|
204
|
+
'screen',
|
|
205
|
+
'app',
|
|
206
|
+
'application',
|
|
207
|
+
'view',
|
|
208
|
+
'where',
|
|
209
|
+
'you',
|
|
210
|
+
'can',
|
|
211
|
+
'some',
|
|
212
|
+
'like',
|
|
213
|
+
'just',
|
|
214
|
+
'basically',
|
|
215
|
+
'kinda',
|
|
216
|
+
'want',
|
|
217
|
+
'wants',
|
|
218
|
+
'need',
|
|
219
|
+
'needs',
|
|
220
|
+
'something',
|
|
221
|
+
'thing',
|
|
222
|
+
'things',
|
|
223
|
+
'build',
|
|
224
|
+
'make',
|
|
225
|
+
'create',
|
|
226
|
+
'i',
|
|
227
|
+
'me',
|
|
228
|
+
'we',
|
|
229
|
+
'us',
|
|
230
|
+
'so',
|
|
231
|
+
'up',
|
|
232
|
+
'out',
|
|
233
|
+
'over',
|
|
234
|
+
'side',
|
|
235
|
+
'one',
|
|
236
|
+
'big',
|
|
171
237
|
]);
|
|
172
238
|
|
|
173
239
|
/**
|
|
@@ -178,12 +244,14 @@ const STOPWORDS = new Set([
|
|
|
178
244
|
* @returns {string[]}
|
|
179
245
|
*/
|
|
180
246
|
export function tokenizeQuery(term) {
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
247
|
+
return (
|
|
248
|
+
term
|
|
249
|
+
.split(/\s+/)
|
|
250
|
+
// Strip only leading/trailing punctuation; keep joined identifiers intact
|
|
251
|
+
// (e.g. "foo_bar" stays one token) so gibberish stays gibberish.
|
|
252
|
+
.map(t => t.replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, ''))
|
|
253
|
+
.filter(t => t.length >= 2 && !STOPWORDS.has(t))
|
|
254
|
+
);
|
|
187
255
|
}
|
|
188
256
|
|
|
189
257
|
/**
|
|
@@ -227,7 +295,8 @@ function bestForToken(tok, candidate) {
|
|
|
227
295
|
const h = scoreCandidate(s, candidate);
|
|
228
296
|
if (h) {
|
|
229
297
|
const score = Math.round(h.score * 0.85);
|
|
230
|
-
if (!best || score > best.score)
|
|
298
|
+
if (!best || score > best.score)
|
|
299
|
+
best = {score, reason: `${h.reason} (~${tok})`};
|
|
231
300
|
}
|
|
232
301
|
}
|
|
233
302
|
}
|
|
@@ -259,7 +328,8 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
259
328
|
// single words), but if stopwords left exactly one DIFFERENT token (e.g.
|
|
260
329
|
// "pricing page" → "pricing"), score that token too and take the stronger.
|
|
261
330
|
if (tokens.length <= 1) {
|
|
262
|
-
const single =
|
|
331
|
+
const single =
|
|
332
|
+
tokens.length === 1 ? bestForToken(tokens[0], candidate) : null;
|
|
263
333
|
if (full && (!single || full.score >= single.score)) return asFull(full);
|
|
264
334
|
return single ? asFull(single) : null;
|
|
265
335
|
}
|
|
@@ -313,7 +383,9 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
313
383
|
// terms can never score lower, since every term of the expression is
|
|
314
384
|
// non-decreasing in the set of matched tokens.
|
|
315
385
|
const coverage = matched / tokens.length;
|
|
316
|
-
const tokenScore = Math.round(
|
|
386
|
+
const tokenScore = Math.round(
|
|
387
|
+
strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
|
|
388
|
+
);
|
|
317
389
|
|
|
318
390
|
if (full && full.score >= tokenScore) return asFull(full);
|
|
319
391
|
return {
|
|
@@ -341,7 +413,14 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
341
413
|
*/
|
|
342
414
|
export function scoreCandidate(
|
|
343
415
|
term,
|
|
344
|
-
{
|
|
416
|
+
{
|
|
417
|
+
name,
|
|
418
|
+
keywords = [],
|
|
419
|
+
weakKeywords = [],
|
|
420
|
+
description = '',
|
|
421
|
+
prose = [],
|
|
422
|
+
guidance = [],
|
|
423
|
+
},
|
|
345
424
|
) {
|
|
346
425
|
let best = 0;
|
|
347
426
|
let reason = '';
|
|
@@ -365,7 +444,11 @@ export function scoreCandidate(
|
|
|
365
444
|
// Substring (both directions), min 4 chars, >=50% coverage.
|
|
366
445
|
const shorter = term.length < nameLower.length ? term : nameLower;
|
|
367
446
|
const longer = term.length < nameLower.length ? nameLower : term;
|
|
368
|
-
if (
|
|
447
|
+
if (
|
|
448
|
+
shorter.length >= 4 &&
|
|
449
|
+
longer.includes(shorter) &&
|
|
450
|
+
shorter.length / longer.length >= 0.5
|
|
451
|
+
) {
|
|
369
452
|
consider(60, `name contains "${shorter}"`);
|
|
370
453
|
}
|
|
371
454
|
const dist = levenshteinDistance(term, nameLower);
|
|
@@ -453,7 +536,8 @@ export function scoreCandidate(
|
|
|
453
536
|
async function loadModuleDoc(docPath, exportName = 'docs') {
|
|
454
537
|
try {
|
|
455
538
|
const mod = await import(pathToFileURL(docPath).href);
|
|
456
|
-
|
|
539
|
+
// Support both the stamped default export and the legacy named export.
|
|
540
|
+
return mod?.default ?? mod[exportName] ?? null;
|
|
457
541
|
} catch {
|
|
458
542
|
return null;
|
|
459
543
|
}
|
|
@@ -480,12 +564,20 @@ async function loadModuleDoc(docPath, exportName = 'docs') {
|
|
|
480
564
|
function guidanceFrom(doc) {
|
|
481
565
|
if (!doc) return [];
|
|
482
566
|
const features = Array.isArray(doc.features) ? doc.features : [];
|
|
483
|
-
const practices = Array.isArray(doc.usage?.bestPractices)
|
|
567
|
+
const practices = Array.isArray(doc.usage?.bestPractices)
|
|
568
|
+
? doc.usage.bestPractices
|
|
569
|
+
: [];
|
|
484
570
|
return [...features, ...practices]
|
|
485
571
|
.map(entry =>
|
|
486
572
|
typeof entry === 'string'
|
|
487
573
|
? entry
|
|
488
|
-
: [
|
|
574
|
+
: [
|
|
575
|
+
entry?.title,
|
|
576
|
+
entry?.text,
|
|
577
|
+
entry?.description,
|
|
578
|
+
entry?.do,
|
|
579
|
+
entry?.dont,
|
|
580
|
+
]
|
|
489
581
|
.filter(Boolean)
|
|
490
582
|
.join(' '),
|
|
491
583
|
)
|
|
@@ -560,17 +652,16 @@ async function gatherIntegrationComponents(cwd) {
|
|
|
560
652
|
// Reporting the bare package name here handed out a path that does not
|
|
561
653
|
// resolve, and disagreed with what `component <Name>` said about the
|
|
562
654
|
// very same component.
|
|
563
|
-
_import:
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
),
|
|
655
|
+
_import: resolveIntegrationImportPath(
|
|
656
|
+
{
|
|
657
|
+
exportsMap: integration.__packageExports,
|
|
658
|
+
packageDir: integration.__packageDir,
|
|
659
|
+
docPath: rec.docPath,
|
|
660
|
+
packageName: rec.package,
|
|
661
|
+
},
|
|
662
|
+
rec.name,
|
|
663
|
+
doc?.import,
|
|
664
|
+
),
|
|
574
665
|
});
|
|
575
666
|
}
|
|
576
667
|
}
|
|
@@ -701,7 +792,9 @@ async function gatherTemplates(cwd) {
|
|
|
701
792
|
// category words are a deliberate statement of what the template is for,
|
|
702
793
|
// while scraped JSX tags only say what it happens to render. See the
|
|
703
794
|
// scoring table at the top of this file for why the derived set is capped.
|
|
704
|
-
const keywords = Array.isArray(t.componentsUsed)
|
|
795
|
+
const keywords = Array.isArray(t.componentsUsed)
|
|
796
|
+
? [...t.componentsUsed]
|
|
797
|
+
: [];
|
|
705
798
|
/** @type {string[]} */
|
|
706
799
|
let weakKeywords = [];
|
|
707
800
|
if (t.type === 'page') {
|
|
@@ -712,7 +805,8 @@ async function gatherTemplates(cwd) {
|
|
|
712
805
|
// Best-effort: skip keyword enrichment if the source can't be read.
|
|
713
806
|
}
|
|
714
807
|
}
|
|
715
|
-
if (t.category)
|
|
808
|
+
if (t.category)
|
|
809
|
+
keywords.push(...t.category.split(/[^A-Za-z0-9]+/).filter(Boolean));
|
|
716
810
|
}
|
|
717
811
|
return {
|
|
718
812
|
domain: 'template',
|
|
@@ -814,10 +908,7 @@ export async function search(query, options = {}) {
|
|
|
814
908
|
// Validate limit here (not just in the CLI) so direct API callers get the same
|
|
815
909
|
// contract: a non-positive or non-integer limit is an error, never a silent
|
|
816
910
|
// "return everything". (Previously `limit <= 0` fell through to the full set.)
|
|
817
|
-
if (
|
|
818
|
-
limit != null &&
|
|
819
|
-
(!Number.isInteger(limit) || limit <= 0)
|
|
820
|
-
) {
|
|
911
|
+
if (limit != null && (!Number.isInteger(limit) || limit <= 0)) {
|
|
821
912
|
throw new AstryxError(
|
|
822
913
|
`Invalid limit "${limit}". Must be a positive integer.`,
|
|
823
914
|
undefined,
|
|
@@ -852,7 +943,10 @@ export async function search(query, options = {}) {
|
|
|
852
943
|
const scored = [];
|
|
853
944
|
for (const candidate of all) {
|
|
854
945
|
const hit = scoreQuery(term, tokens, candidate);
|
|
855
|
-
if (hit)
|
|
946
|
+
if (hit)
|
|
947
|
+
scored.push(
|
|
948
|
+
toResult(candidate, hit.score, hit.reason, hit.matched, hit.total),
|
|
949
|
+
);
|
|
856
950
|
}
|
|
857
951
|
|
|
858
952
|
// Sort by score desc, then domain (stable order), then name.
|