@astryxdesign/cli 0.6.5-canary.d6fa1d6 → 0.6.5-canary.e5d11eb
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 +2 -2
- package/api/build/_adapter.d.mts +0 -14
- package/api/build/_adapter.mjs +1 -58
- package/api/build/build.test.mjs +1 -74
- package/api/build/kit/kit.mjs +7 -39
- package/api/build/kit/rank.d.mts +0 -8
- package/api/build/kit/rank.mjs +0 -14
- package/api/docs/docs.d.mts +0 -6
- package/api/docs/docs.doc.mjs +2 -31
- package/api/docs/docs.mjs +1 -44
- package/api/docs/docs.type.d.mts +1 -38
- package/api/docs/docs.type.mjs +1 -18
- package/api/docs/node/node.d.mts +3 -28
- package/api/docs/node/node.mjs +23 -146
- package/api/gap-report/gap-report.d.mts +1 -3
- package/api/gap-report/gap-report.mjs +2 -12
- package/api/gap-report/gap-report.test.mjs +0 -106
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-theme.mjs +3 -93
- package/api/integration/add-theme.test.mjs +0 -100
- package/api/integration/integrationAddTheme.doc.mjs +1 -1
- package/api/search/search.d.mts +5 -12
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +53 -123
- package/api/search/search.test.mjs +8 -123
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/theme/build/build.mjs +69 -146
- package/api/theme/build/build.test.mjs +1 -190
- package/api/theme/themeBuild.doc.d.mts +1 -4
- package/api/theme/themeBuild.doc.mjs +3 -14
- package/assets/docs/theme.doc.mjs +1 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +0 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.mjs +2 -8
- package/clients/cli/commands/discover.mjs +1 -29
- package/clients/cli/commands/docs.doc.mjs +2 -15
- package/clients/cli/commands/docs.mjs +5 -222
- package/clients/cli/commands/gap-report.mjs +0 -12
- package/clients/cli/commands/gap-report.test.mjs +0 -63
- package/clients/cli/commands/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +4 -5
- package/clients/cli/commands/search.mjs +6 -30
- package/clients/cli/commands/search.test.mjs +16 -60
- package/foundation/agent-docs/agent-docs.mjs +1 -2
- package/foundation/agent-docs/agent-docs.test.mjs +0 -8
- package/foundation/discovery/theme-discovery.d.mts +0 -6
- package/foundation/discovery/theme-discovery.mjs +0 -9
- package/foundation/doc-compiler/doc-loads.test.mjs +1 -1
- package/package.json +9 -9
- package/api/build/kit/weights.d.mts +0 -82
- package/api/build/kit/weights.json +0 -1
- package/api/build/kit/weights.mjs +0 -305
- package/api/build/kit/weights.test.mjs +0 -190
- package/api/docs/docs.depth.test.mjs +0 -132
- package/api/theme/build/build.icon-lineage.test.mjs +0 -117
- package/api/theme/build/build.icon-preservation.test.mjs +0 -639
- package/api/theme/build/icon-imports.d.mts +0 -47
- package/api/theme/build/icon-imports.mjs +0 -691
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +0 -15
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +0 -38
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +0 -20
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +0 -48
- package/clients/cli/commands/discover.no-source.test.mjs +0 -75
- package/clients/cli/commands/docs.depth.test.mjs +0 -219
- package/clients/cli/commands/theme-list.behavior.test.mjs +0 -41
|
@@ -14,7 +14,7 @@ export const doc = {
|
|
|
14
14
|
namespace: 'cli/api',
|
|
15
15
|
displayName: 'search()',
|
|
16
16
|
summary:
|
|
17
|
-
'Unified ranked search across components, hooks, docs,
|
|
17
|
+
'Unified ranked search across components, hooks, docs, and templates.',
|
|
18
18
|
description:
|
|
19
19
|
'The single "I\'m looking for X" entry point across every content domain. ' +
|
|
20
20
|
'Ranking is keyword + fuzzy (not embeddings); name and keyword signals outrank ' +
|
|
@@ -35,7 +35,7 @@ export const doc = {
|
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
name: 'options.type',
|
|
38
|
-
type: "'component' | 'hook' | 'doc' | 'template'
|
|
38
|
+
type: "'component' | 'hook' | 'doc' | 'template'",
|
|
39
39
|
description: 'Restrict results to a single domain.',
|
|
40
40
|
},
|
|
41
41
|
{
|
|
@@ -48,14 +48,14 @@ export const doc = {
|
|
|
48
48
|
name: 'options.cwd',
|
|
49
49
|
type: 'string',
|
|
50
50
|
description:
|
|
51
|
-
"Directory to resolve @astryxdesign/core from. A docs-only
|
|
51
|
+
"Directory to resolve @astryxdesign/core from. A docs-only search (`type: 'doc'`) does not need it, and a search with no `type` covers the docs alone when core is missing.",
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
returns: [
|
|
55
55
|
{
|
|
56
56
|
type: 'search',
|
|
57
57
|
description:
|
|
58
|
-
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, `displayName` and `kind` for templates
|
|
58
|
+
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, and `displayName` and `kind` for templates. A doc result is the smallest part that answers: one section (with `section`, and a command that reads only it), one docs-tree route, or a topic, whose command lists its sections. `parent` is the command that opens the level above it: the section list of its topic, the namespace a tree node sits in, the Unorganized level for a flat topic, or the topic list for a top-level namespace. Every doc result also carries `package`, the npm package that authored it (for a section, the package its file came from).',
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
throws: [
|
package/api/search/search.mjs
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* outputs. The CLI command handler is a thin wrapper around this function.
|
|
8
8
|
*
|
|
9
9
|
* `search(query)` is the single "I'm looking for X" entry point across ALL
|
|
10
|
-
* content domains — components, hooks, docs topics, templates (page +
|
|
11
|
-
*
|
|
12
|
-
* (`component --list`, `hook --list`, `docs`, `template --list
|
|
13
|
-
*
|
|
10
|
+
* content domains — components, hooks, docs topics, and templates (page +
|
|
11
|
+
* block). Today, finding the right thing requires four separate list calls
|
|
12
|
+
* (`component --list`, `hook --list`, `docs`, `template --list`) plus manual
|
|
13
|
+
* scanning; this collapses them into one ranked, typed result set.
|
|
14
14
|
*
|
|
15
15
|
* Scoring is keyword + fuzzy ranking (NOT semantic / embeddings — that is a
|
|
16
16
|
* deliberate future follow-up). It reuses the same signal weighting as the
|
|
@@ -89,7 +89,6 @@ import {loadIntegrationsSafely} from '../component/_adapter.mjs';
|
|
|
89
89
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
90
90
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
91
91
|
import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
|
|
92
|
-
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
93
92
|
import {
|
|
94
93
|
guideEntry,
|
|
95
94
|
loadDocsCatalog,
|
|
@@ -111,10 +110,8 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
111
110
|
* A search candidate gathered from one content domain. Extra underscore-
|
|
112
111
|
* prefixed fields carry domain-specific payload used only by {@link toResult}.
|
|
113
112
|
* @typedef {object} Candidate
|
|
114
|
-
* @property {'component'|'hook'|'doc'|'template'
|
|
113
|
+
* @property {'component'|'hook'|'doc'|'template'} domain
|
|
115
114
|
* @property {string} name
|
|
116
|
-
* @property {string[]} [aliases] - Other names the candidate answers to, scored
|
|
117
|
-
* with the same name signals: a theme's display name.
|
|
118
115
|
* @property {string[]} [keywords]
|
|
119
116
|
* @property {string[]} [weakKeywords]
|
|
120
117
|
* @property {string} [description]
|
|
@@ -294,13 +291,7 @@ const isTypo = (a, b, dist) =>
|
|
|
294
291
|
TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
|
|
295
292
|
|
|
296
293
|
/** Valid domain filters for `--type`. */
|
|
297
|
-
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* The domains a search reads without @astryxdesign/core. An open search outside
|
|
301
|
-
* an app covers these alone.
|
|
302
|
-
*/
|
|
303
|
-
const CORELESS_DOMAINS = ['doc', 'theme'];
|
|
294
|
+
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
304
295
|
|
|
305
296
|
/**
|
|
306
297
|
* Filler words stripped from multi-word queries so natural-language phrasing
|
|
@@ -627,7 +618,6 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
627
618
|
// strong hits, then reward coverage so candidates matching more terms win.
|
|
628
619
|
let strongest = 0;
|
|
629
620
|
let matched = 0;
|
|
630
|
-
let tokenSum = 0;
|
|
631
621
|
/** @type {string[]} */
|
|
632
622
|
const hitTerms = [];
|
|
633
623
|
for (const tok of tokens) {
|
|
@@ -636,7 +626,6 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
636
626
|
if (h.score > strongest) strongest = h.score;
|
|
637
627
|
matched++;
|
|
638
628
|
hitTerms.push(tok);
|
|
639
|
-
tokenSum += h.score;
|
|
640
629
|
}
|
|
641
630
|
}
|
|
642
631
|
// The reverse of the title tier, a step lower: the query holds a whole title
|
|
@@ -661,25 +650,14 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
661
650
|
// (50 + bonus + coverage = 77) lost to thirty docs that each match
|
|
662
651
|
// `integration` alone, by name or in a code tick (98-108). The reader asked for
|
|
663
652
|
// both; a candidate that has both comes first, ordered among its peers by
|
|
664
|
-
// how strong its
|
|
653
|
+
// how strong its strongest match is. It needs one keyword-strength hit:
|
|
665
654
|
// every word mentioned in prose, or rendered by a page, is breadth, and
|
|
666
655
|
// stays on the token sum below an exact hit on one word.
|
|
667
|
-
//
|
|
668
|
-
// The TOTAL quality of matches orders candidates within this tier, not
|
|
669
|
-
// just the strongest single hit. A doc matching both words by keyword
|
|
670
|
-
// (90 + 90 = 180) outranks one matching keyword + prose (90 + 50 = 140).
|
|
671
|
-
// Before this, every all-word match whose strongest hit was a keyword (90)
|
|
672
|
-
// scored 157, burying the better match among dozens of ties.
|
|
673
656
|
if (matched === tokens.length && strongest >= STRONG_TOKEN_SCORE) {
|
|
674
657
|
return {
|
|
675
658
|
score:
|
|
676
659
|
FULL_COVERAGE_SCORE +
|
|
677
|
-
Math.
|
|
678
|
-
Math.floor(
|
|
679
|
-
(tokenSum - matched * MIN_TOKEN_SCORE) / (matched * 5),
|
|
680
|
-
),
|
|
681
|
-
8,
|
|
682
|
-
),
|
|
660
|
+
Math.floor((strongest - MIN_TOKEN_SCORE) / 6.25),
|
|
683
661
|
reason,
|
|
684
662
|
matched,
|
|
685
663
|
total,
|
|
@@ -719,7 +697,6 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
719
697
|
* @param {string} term - Lowercased search term.
|
|
720
698
|
* @param {object} candidate
|
|
721
699
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
722
|
-
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
723
700
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
724
701
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
725
702
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -734,7 +711,6 @@ export function scoreCandidate(
|
|
|
734
711
|
term,
|
|
735
712
|
{
|
|
736
713
|
name,
|
|
737
|
-
aliases = [],
|
|
738
714
|
domain,
|
|
739
715
|
keywords = [],
|
|
740
716
|
weakKeywords = [],
|
|
@@ -757,44 +733,40 @@ export function scoreCandidate(
|
|
|
757
733
|
}
|
|
758
734
|
};
|
|
759
735
|
|
|
736
|
+
const nameLower = name.toLowerCase();
|
|
737
|
+
// A placed guide's name is its route, and the route's last segment is its
|
|
738
|
+
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
739
|
+
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
740
|
+
|
|
760
741
|
// ── Name signals ────────────────────────────────────────────────
|
|
761
|
-
//
|
|
762
|
-
//
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
//
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
if (fuzzy) {
|
|
791
|
-
const dist = levenshteinDistance(term, nameLower);
|
|
792
|
-
if (isTypo(term, nameLower, dist)) {
|
|
793
|
-
consider(
|
|
794
|
-
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
795
|
-
`similar name (distance ${dist})`,
|
|
796
|
-
);
|
|
797
|
-
}
|
|
742
|
+
// A plural of the name is the name: `integration` is the `integrations`
|
|
743
|
+
// guides, `tab` the `tabs` doc.
|
|
744
|
+
// A component, hook, or template name typed as words is its name:
|
|
745
|
+
// `command palette` is CommandPalette. A doc's name is a route or key,
|
|
746
|
+
// matched as written.
|
|
747
|
+
const spelled =
|
|
748
|
+
domain !== 'doc' &&
|
|
749
|
+
!/[\s_-]/.test(nameLower) &&
|
|
750
|
+
nameLower === term.replace(/\s+/g, '');
|
|
751
|
+
if (nameLower === term || leafLower === term || spelled) {
|
|
752
|
+
consider(100, 'exact name');
|
|
753
|
+
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
754
|
+
// One point under the exact spelling, so the doc named `tokens` still
|
|
755
|
+
// outranks the Token component for `tokens`.
|
|
756
|
+
consider(99, 'plural of the name');
|
|
757
|
+
} else {
|
|
758
|
+
if (sameWord(term, nameLower)) consider(95, `name "${name}"`);
|
|
759
|
+
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
760
|
+
else if (startsAWordOf(term, name)) {
|
|
761
|
+
consider(60, `name contains "${term}"`);
|
|
762
|
+
}
|
|
763
|
+
if (fuzzy) {
|
|
764
|
+
const dist = levenshteinDistance(term, nameLower);
|
|
765
|
+
if (isTypo(term, nameLower, dist)) {
|
|
766
|
+
consider(
|
|
767
|
+
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
768
|
+
`similar name (distance ${dist})`,
|
|
769
|
+
);
|
|
798
770
|
}
|
|
799
771
|
}
|
|
800
772
|
}
|
|
@@ -1491,36 +1463,6 @@ async function gatherTemplates(cwd) {
|
|
|
1491
1463
|
});
|
|
1492
1464
|
}
|
|
1493
1465
|
|
|
1494
|
-
/**
|
|
1495
|
-
* Build theme candidates from bundled and integration-provided themes. Without
|
|
1496
|
-
* this, an integration's themes are invisible to `search` even though
|
|
1497
|
-
* `theme list` and `discover` already resolve them.
|
|
1498
|
-
*
|
|
1499
|
-
* A theme's slug and display name are its names, and its description is prose
|
|
1500
|
-
* (`spec:AST-050/FR14`). A theme declares no keywords, so a word it shares with
|
|
1501
|
-
* the query only through its description is a description mention: read as a
|
|
1502
|
-
* keyword, every word of the description would outrank the components and docs
|
|
1503
|
-
* that declare that word.
|
|
1504
|
-
* @param {string} cwd
|
|
1505
|
-
* @returns {Promise<Candidate[]>}
|
|
1506
|
-
*/
|
|
1507
|
-
async function gatherThemes(cwd) {
|
|
1508
|
-
let themes;
|
|
1509
|
-
try {
|
|
1510
|
-
themes = await listAvailableThemes(cwd);
|
|
1511
|
-
} catch {
|
|
1512
|
-
return [];
|
|
1513
|
-
}
|
|
1514
|
-
return themes.map(t => ({
|
|
1515
|
-
domain: 'theme',
|
|
1516
|
-
name: t.slug,
|
|
1517
|
-
aliases: t.displayName ? [t.displayName] : [],
|
|
1518
|
-
description: t.description || '',
|
|
1519
|
-
_displayName: t.displayName,
|
|
1520
|
-
_package: t.package,
|
|
1521
|
-
}));
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
1466
|
/**
|
|
1525
1467
|
* Map a scored candidate to its public, actionable result shape. Each result
|
|
1526
1468
|
* carries enough to act on it: the domain, name, a one-line description, and
|
|
@@ -1577,14 +1519,6 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1577
1519
|
command: `astryx template ${c._commandName ?? c.name} --type ${c._kind}`,
|
|
1578
1520
|
};
|
|
1579
1521
|
break;
|
|
1580
|
-
case 'theme':
|
|
1581
|
-
result = {
|
|
1582
|
-
...base,
|
|
1583
|
-
displayName: c._displayName,
|
|
1584
|
-
command: `astryx theme add ${c.name}`,
|
|
1585
|
-
...(c._package ? {package: c._package} : {}),
|
|
1586
|
-
};
|
|
1587
|
-
break;
|
|
1588
1522
|
default:
|
|
1589
1523
|
result = base;
|
|
1590
1524
|
}
|
|
@@ -1592,12 +1526,12 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1592
1526
|
}
|
|
1593
1527
|
|
|
1594
1528
|
/**
|
|
1595
|
-
* Unified ranked search across components, hooks, docs,
|
|
1529
|
+
* Unified ranked search across components, hooks, docs, and templates.
|
|
1596
1530
|
*
|
|
1597
1531
|
* @param {string} query - Free-text search term.
|
|
1598
1532
|
* @param {object} [options]
|
|
1599
1533
|
* @param {string} [options.cwd]
|
|
1600
|
-
* @param {'component'|'hook'|'doc'|'template'
|
|
1534
|
+
* @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
|
|
1601
1535
|
* @param {number} [options.limit] - Max results (default 20).
|
|
1602
1536
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
1603
1537
|
*/
|
|
@@ -1634,14 +1568,12 @@ export async function search(query, options = {}) {
|
|
|
1634
1568
|
const term = String(query).trim().toLowerCase();
|
|
1635
1569
|
const tokens = tokenizeQuery(term);
|
|
1636
1570
|
|
|
1637
|
-
// `astryx docs` reads docs without @astryxdesign/core,
|
|
1638
|
-
//
|
|
1639
|
-
//
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
const coreDir = needsCore ? findCoreDir(cwd) : null;
|
|
1644
|
-
if (type && needsCore && !coreDir) {
|
|
1571
|
+
// `astryx docs` reads docs without @astryxdesign/core, so a docs-only
|
|
1572
|
+
// search must too. Every other domain reads core: asked for by name, it is
|
|
1573
|
+
// an error without core; an open search then covers the docs alone.
|
|
1574
|
+
const docsOnly = type === 'doc';
|
|
1575
|
+
const coreDir = docsOnly ? null : findCoreDir(cwd);
|
|
1576
|
+
if (type && !docsOnly && !coreDir) {
|
|
1645
1577
|
throw new AstryxError(
|
|
1646
1578
|
'Could not find @astryxdesign/core package',
|
|
1647
1579
|
undefined,
|
|
@@ -1651,19 +1583,17 @@ export async function search(query, options = {}) {
|
|
|
1651
1583
|
|
|
1652
1584
|
// Gather candidates from each requested domain in parallel.
|
|
1653
1585
|
/** @param {string} d */
|
|
1654
|
-
const wants = d =>
|
|
1655
|
-
|
|
1656
|
-
const [components, hooks, docTopics, templates, themes] = await Promise.all([
|
|
1586
|
+
const wants = d => (!type && (coreDir != null || d === 'doc')) || type === d;
|
|
1587
|
+
const [components, hooks, docTopics, templates] = await Promise.all([
|
|
1657
1588
|
wants('component')
|
|
1658
1589
|
? gatherComponents(/** @type {string} */ (coreDir), cwd)
|
|
1659
1590
|
: [],
|
|
1660
1591
|
wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
|
|
1661
1592
|
wants('doc') ? gatherDocs(cwd) : [],
|
|
1662
1593
|
wants('template') ? gatherTemplates(cwd) : [],
|
|
1663
|
-
wants('theme') ? gatherThemes(cwd) : [],
|
|
1664
1594
|
]);
|
|
1665
1595
|
|
|
1666
|
-
const all = [...components, ...hooks, ...docTopics, ...templates
|
|
1596
|
+
const all = [...components, ...hooks, ...docTopics, ...templates];
|
|
1667
1597
|
|
|
1668
1598
|
// Score every candidate on its own merits. The consumer groups results by
|
|
1669
1599
|
// role (page / block / component) and takes the top of each, so there's no
|
|
@@ -1680,7 +1610,7 @@ export async function search(query, options = {}) {
|
|
|
1680
1610
|
|
|
1681
1611
|
// Sort by score desc, then domain (stable order), then name.
|
|
1682
1612
|
/** @type {Record<string, number>} */
|
|
1683
|
-
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3
|
|
1613
|
+
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3};
|
|
1684
1614
|
scored.sort(
|
|
1685
1615
|
(a, b) =>
|
|
1686
1616
|
b.score - a.score ||
|
|
@@ -25,8 +25,6 @@ import * as os from 'node:os';
|
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {fileURLToPath} from 'node:url';
|
|
27
27
|
import {docs} from '../docs/docs.mjs';
|
|
28
|
-
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
29
|
-
import {doc as themeAddCommandDoc} from '../../clients/cli/commands/theme-add.doc.mjs';
|
|
30
28
|
import {
|
|
31
29
|
headingWithPhrase,
|
|
32
30
|
titleInQuery,
|
|
@@ -77,11 +75,8 @@ describe('search leaf — envelope + ranking', () => {
|
|
|
77
75
|
});
|
|
78
76
|
|
|
79
77
|
describe('search leaf — per-domain result fields', () => {
|
|
80
|
-
it('carries import for components and hooks, title for docs, displayName and kind for templates
|
|
81
|
-
|
|
82
|
-
// description, a prose mention below every name and keyword hit, so read
|
|
83
|
-
// the whole result list.
|
|
84
|
-
const r = await search('theme', {cwd, limit: 400});
|
|
78
|
+
it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
|
|
79
|
+
const r = await search('theme', {cwd, limit: 60});
|
|
85
80
|
expect(new Set(r.data.results.map(res => res.domain))).toEqual(
|
|
86
81
|
new Set(SEARCH_DOMAINS),
|
|
87
82
|
);
|
|
@@ -94,12 +89,9 @@ describe('search leaf — per-domain result fields', () => {
|
|
|
94
89
|
expect(res.title).toMatch(/\S/);
|
|
95
90
|
const read = `astryx docs ${res.name}`;
|
|
96
91
|
expect([read, `${read} --index`, `${read} ${res.section}`]).toContain(res.command);
|
|
97
|
-
} else
|
|
92
|
+
} else {
|
|
98
93
|
expect(res.displayName).toMatch(/\S/);
|
|
99
94
|
expect(['page', 'block']).toContain(res.kind);
|
|
100
|
-
} else if (res.domain === 'theme') {
|
|
101
|
-
expect(res.displayName).toMatch(/\S/);
|
|
102
|
-
expect(res.command).toMatch(/^astryx theme add /);
|
|
103
95
|
}
|
|
104
96
|
}
|
|
105
97
|
}, SLOW);
|
|
@@ -405,10 +397,11 @@ describe('search leaf — a candidate that matches every word outranks a partial
|
|
|
405
397
|
expect(score(q, all)).toBeLessThan(160);
|
|
406
398
|
});
|
|
407
399
|
|
|
408
|
-
// Among candidates that match every word, the stronger match
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
|
|
400
|
+
// Among candidates that match every word, the stronger match should come
|
|
401
|
+
// first. Today every all-word match with a keyword hit gets the same score,
|
|
402
|
+
// so this records the order without enforcing it: it fails, as expected,
|
|
403
|
+
// until the scoring tells the two apart.
|
|
404
|
+
it.fails('ranks the stronger of two all-word matches first', () => {
|
|
412
405
|
const all = {name: 'x', keywords: ['alphas'], description: 'alpha beta gamma delta'};
|
|
413
406
|
const q = 'alpha beta gamma delta';
|
|
414
407
|
expect(score(q, {name: 'y', keywords: ['alpha'], description: 'beta gamma delta'})).toBeGreaterThan(
|
|
@@ -504,114 +497,6 @@ describe('search leaf — limit validation (API matches the CLI contract)', () =
|
|
|
504
497
|
}, SLOW);
|
|
505
498
|
});
|
|
506
499
|
|
|
507
|
-
describe('search leaf — a theme is found by its names; its description is prose (AST-050 FR14)', () => {
|
|
508
|
-
/** A result that answers the query by a name or a declared keyword, not a typo or a mention. */
|
|
509
|
-
const matchesByNameOrKeyword = (/** @type {{reason: string}} */ result) =>
|
|
510
|
-
/^(exact name|plural of the name|name "|name contains ")/.test(result.reason) ||
|
|
511
|
-
/^keyword "[^"]*"$/.test(result.reason);
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* The `theme add` command AST-050 FR12 and FR13 name for the stage that
|
|
515
|
-
* `theme add` itself declares: no `--import` yet, a deprecated copy default
|
|
516
|
-
* beside `--import`, or the cleanup, which keeps `--import` and drops the
|
|
517
|
-
* copy's `--overwrite`.
|
|
518
|
-
* @param {string} slug
|
|
519
|
-
*/
|
|
520
|
-
function themeAddCommandForStage(slug) {
|
|
521
|
-
const flags = themeAddCommandDoc.options.flatMap(option => option.flag.split(/[\s,]+/));
|
|
522
|
-
if (!flags.includes('--import')) return `astryx theme add ${slug}`;
|
|
523
|
-
if (flags.includes('--overwrite')) return `astryx theme add --import ${slug}`;
|
|
524
|
-
return `astryx theme add ${slug}`;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
it(
|
|
528
|
-
'ranks a theme found only through its description below every name and keyword match',
|
|
529
|
-
async () => {
|
|
530
|
-
for (const [query, slugs] of [
|
|
531
|
-
['focus', ['neutral']],
|
|
532
|
-
['content', ['matcha', 'neutral']],
|
|
533
|
-
]) {
|
|
534
|
-
const {results} = (await search(query, {cwd, limit: 400})).data;
|
|
535
|
-
const strong = results.filter(
|
|
536
|
-
result => result.domain !== 'theme' && matchesByNameOrKeyword(result),
|
|
537
|
-
);
|
|
538
|
-
expect(strong.length).toBeGreaterThan(0);
|
|
539
|
-
const lastStrong = Math.max(...strong.map(result => results.indexOf(result)));
|
|
540
|
-
for (const slug of slugs) {
|
|
541
|
-
const at = results.findIndex(result => result.domain === 'theme' && result.name === slug);
|
|
542
|
-
expect(at).toBeGreaterThan(-1);
|
|
543
|
-
expect(results[at].reason).toMatch(/^description mentions /);
|
|
544
|
-
expect(at).toBeGreaterThan(lastStrong);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
SLOW,
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
it(
|
|
552
|
-
'scores a word in a theme description the same as a word in a component description',
|
|
553
|
-
async () => {
|
|
554
|
-
const {results} = (await search('minimal', {cwd, limit: 400})).data;
|
|
555
|
-
const neutral = results.find(result => result.domain === 'theme' && result.name === 'neutral');
|
|
556
|
-
const topNav = results.find(result => result.domain === 'component' && result.name === 'TopNav');
|
|
557
|
-
expect(neutral?.reason).toMatch(/^description mentions /);
|
|
558
|
-
expect(topNav?.reason).toMatch(/^description mentions /);
|
|
559
|
-
expect(neutral?.score).toBe(topNav?.score);
|
|
560
|
-
},
|
|
561
|
-
SLOW,
|
|
562
|
-
);
|
|
563
|
-
|
|
564
|
-
it(
|
|
565
|
-
'keeps a theme that matches every word only in its description below results with a keyword hit',
|
|
566
|
-
async () => {
|
|
567
|
-
// Overlay and Dialog declare `focus` and mention `content`; neutral only
|
|
568
|
-
// mentions both, in "so the content stays the focus".
|
|
569
|
-
const {results} = (await search('content focus', {cwd, limit: 400})).data;
|
|
570
|
-
const neutral = results.findIndex(result => result.domain === 'theme' && result.name === 'neutral');
|
|
571
|
-
expect(neutral).toBeGreaterThan(-1);
|
|
572
|
-
for (const name of ['Overlay', 'Dialog']) {
|
|
573
|
-
const at = results.findIndex(result => result.domain === 'component' && result.name === name);
|
|
574
|
-
expect(at).toBeGreaterThan(-1);
|
|
575
|
-
expect(at).toBeLessThan(neutral);
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
SLOW,
|
|
579
|
-
);
|
|
580
|
-
|
|
581
|
-
it(
|
|
582
|
-
'still finds a theme first by its slug or its display name',
|
|
583
|
-
async () => {
|
|
584
|
-
for (const query of ['neutral', 'Matcha', 'Y2K']) {
|
|
585
|
-
const [first] = (await search(query, {cwd})).data.results;
|
|
586
|
-
expect(first).toMatchObject({domain: 'theme', name: query.toLowerCase(), reason: 'exact name'});
|
|
587
|
-
}
|
|
588
|
-
},
|
|
589
|
-
SLOW,
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
it('scores a display name with the same name signals as the slug', () => {
|
|
593
|
-
const theme = {name: 'ocean', aliases: ['Ocean Blue'], description: 'Deep blues for calm reading.'};
|
|
594
|
-
expect(scoreCandidate('ocean blue', theme)).toEqual(scoreCandidate('ocean', theme));
|
|
595
|
-
expect(scoreCandidate('ocean blue', {...theme, aliases: []})?.score ?? 0).toBeLessThan(
|
|
596
|
-
scoreCandidate('ocean', theme).score,
|
|
597
|
-
);
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it(
|
|
601
|
-
'names the theme add command for the stage theme add declares',
|
|
602
|
-
async () => {
|
|
603
|
-
const themes = await listAvailableThemes(cwd);
|
|
604
|
-
expect(themes.length).toBeGreaterThan(0);
|
|
605
|
-
for (const {slug} of themes) {
|
|
606
|
-
const {results} = (await search(slug, {cwd, type: 'theme'})).data;
|
|
607
|
-
const result = results.find(entry => entry.name === slug);
|
|
608
|
-
expect(result?.command).toBe(themeAddCommandForStage(slug));
|
|
609
|
-
}
|
|
610
|
-
},
|
|
611
|
-
SLOW,
|
|
612
|
-
);
|
|
613
|
-
});
|
|
614
|
-
|
|
615
500
|
describe('search leaf — integration components', () => {
|
|
616
501
|
/**
|
|
617
502
|
* A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* The domain a search result belongs to.
|
|
6
6
|
*/
|
|
7
|
-
export type SearchDomain = "component" | "hook" | "doc" | "template"
|
|
7
|
+
export type SearchDomain = "component" | "hook" | "doc" | "template";
|
|
8
8
|
/**
|
|
9
9
|
* A single ranked search result, tagged with its domain.
|
|
10
10
|
*/
|
|
@@ -14,7 +14,7 @@ export type SearchResultEntry = {
|
|
|
14
14
|
*/
|
|
15
15
|
domain: SearchDomain;
|
|
16
16
|
/**
|
|
17
|
-
* - Primary identifier (component/hook name, doc topic or docs-tree route, template dir
|
|
17
|
+
* - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
18
18
|
*/
|
|
19
19
|
name: string;
|
|
20
20
|
/**
|
|
@@ -30,7 +30,7 @@ export type SearchResultEntry = {
|
|
|
30
30
|
*/
|
|
31
31
|
description: string;
|
|
32
32
|
/**
|
|
33
|
-
* - Follow-up command to act on this result (e.g. `astryx component Button
|
|
33
|
+
* - Follow-up command to act on this result (e.g. `astryx component Button`).
|
|
34
34
|
*/
|
|
35
35
|
command: string;
|
|
36
36
|
/**
|
|
@@ -46,7 +46,7 @@ export type SearchResultEntry = {
|
|
|
46
46
|
*/
|
|
47
47
|
section?: string | undefined;
|
|
48
48
|
/**
|
|
49
|
-
* - The npm package that authored a doc result
|
|
49
|
+
* - The npm package that authored a doc result; for a section, the package whose file the section came from.
|
|
50
50
|
*/
|
|
51
51
|
package?: string | undefined;
|
|
52
52
|
/**
|
|
@@ -54,7 +54,7 @@ export type SearchResultEntry = {
|
|
|
54
54
|
*/
|
|
55
55
|
parent?: string | undefined;
|
|
56
56
|
/**
|
|
57
|
-
* - Friendly display name — present for template
|
|
57
|
+
* - Friendly display name — present for template results.
|
|
58
58
|
*/
|
|
59
59
|
displayName?: string | undefined;
|
|
60
60
|
/**
|
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The domain a search result belongs to.
|
|
12
|
-
* @typedef {'component' | 'hook' | 'doc' | 'template'
|
|
12
|
+
* @typedef {'component' | 'hook' | 'doc' | 'template'} SearchDomain
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A single ranked search result, tagged with its domain.
|
|
17
17
|
* @typedef {object} SearchResultEntry
|
|
18
18
|
* @property {SearchDomain} domain - Which content domain this result came from.
|
|
19
|
-
* @property {string} name - Primary identifier (component/hook name, doc topic or docs-tree route, template dir
|
|
19
|
+
* @property {string} name - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
20
20
|
* @property {number} score - Relevance score (higher is better).
|
|
21
21
|
* @property {string} reason - Human-readable reason the candidate matched (e.g. `keyword "button"`).
|
|
22
22
|
* @property {string} description - One-line description, when available.
|
|
23
|
-
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button
|
|
23
|
+
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`).
|
|
24
24
|
* @property {string} [import] - Import path — present for component and hook results.
|
|
25
25
|
* @property {string} [title] - Doc title — present for doc results.
|
|
26
26
|
* @property {string} [section] - Section key — present when a doc result is one section of a topic; `command` reads only that section.
|
|
27
|
-
* @property {string} [package] - The npm package that authored a doc result
|
|
27
|
+
* @property {string} [package] - The npm package that authored a doc result; for a section, the package whose file the section came from.
|
|
28
28
|
* @property {string} [parent] - Command that opens the level above a doc result — its topic's section list for a section, the docs-tree namespace it sits in for a tree node — so a reader can see the siblings and open another.
|
|
29
|
-
* @property {string} [displayName] - Friendly display name — present for template
|
|
29
|
+
* @property {string} [displayName] - Friendly display name — present for template results.
|
|
30
30
|
* @property {'page' | 'block'} [kind] - Template kind (`page` | `block`) — present for template results.
|
|
31
31
|
*/
|
|
32
32
|
|