@astryxdesign/cli 0.6.5-canary.8aa0e94 → 0.6.5-canary.8d216bb

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 CHANGED
@@ -69,7 +69,7 @@ Results for "button" (20 of 239):
69
69
 
70
70
  Options:
71
71
 
72
- - `--type <component|hook|doc|template>`: restrict to a single domain
72
+ - `--type <component|hook|doc|template|theme>`: restrict to a single domain (`doc` and `theme` work outside an app too)
73
73
  - `--limit <n>`: cap the number of results (default 20)
74
74
  - `--verbose`: also print each result's match score and reason
75
75
  - `--json`: typed `{ apiVersion, type: 'search', data: { query, matchCount, results } }` envelope — `matchCount` is how many candidates matched in total, `results` the slice `--limit` allowed
@@ -91,7 +91,7 @@ Options:
91
91
  | `init` | Initialize the design system in your project |
92
92
  | `integration` | Author and verify an Astryx integration package |
93
93
  | `layout` | Generate XDS layouts from compressed expressions (XLE/XLO) |
94
- | `search` | Search components, hooks, docs, and templates in one ranked list |
94
+ | `search` | Search components, hooks, docs, templates, and themes in one ranked list |
95
95
  | `swizzle` | Copy component source for customization |
96
96
  | `template` | List, show, or scaffold page and block templates |
97
97
  | `theme` | Create and build themes: add a shipped one, compile to CSS, or list what a theme can override |
@@ -4,7 +4,9 @@
4
4
  /**
5
5
  * Collect the effective handler set in delivery order: project config first,
6
6
  * then integrations in config order. Valid handlers dedupe by handle identity;
7
- * malformed integration exports retain their position as failed deliveries.
7
+ * malformed integration exports and integrations that failed to load retain
8
+ * their position as failed deliveries. An unloadable integration may export a
9
+ * handler, so it never counts as an empty set that enables the fallback.
8
10
  *
9
11
  * @param {Project} project
10
12
  * @returns {HandlerEntry[]}
@@ -189,7 +189,9 @@ async function selectTarget(project, component, packageName) {
189
189
  /**
190
190
  * Collect the effective handler set in delivery order: project config first,
191
191
  * then integrations in config order. Valid handlers dedupe by handle identity;
192
- * malformed integration exports retain their position as failed deliveries.
192
+ * malformed integration exports and integrations that failed to load retain
193
+ * their position as failed deliveries. An unloadable integration may export a
194
+ * handler, so it never counts as an empty set that enables the fallback.
193
195
  *
194
196
  * @param {Project} project
195
197
  * @returns {HandlerEntry[]}
@@ -214,7 +216,15 @@ export function collectGapReportHandlers(project) {
214
216
  }
215
217
 
216
218
  for (const integration of project.loadedIntegrations) {
217
- if (integration.__loadError) continue;
219
+ if (integration.__loadError) {
220
+ entries.push({
221
+ kind: 'malformed',
222
+ handlerType: 'integration',
223
+ handlerName: integration.name,
224
+ error: `Integration failed to load, so it could not receive this report: ${integration.__loadError}. Fix the package or remove it from integrations in astryx.config, then rerun.`,
225
+ });
226
+ continue;
227
+ }
218
228
  if (integration.__gapReportError) {
219
229
  entries.push({
220
230
  kind: 'malformed',
@@ -105,6 +105,45 @@ function addIntegration({
105
105
  return {dir};
106
106
  }
107
107
 
108
+ /**
109
+ * Add an integration whose module throws on import, so it never loads.
110
+ * @param {string} name
111
+ */
112
+ function addBrokenIntegration(name) {
113
+ const dir = packageDir(name);
114
+ fs.mkdirSync(dir, {recursive: true});
115
+ fs.writeFileSync(
116
+ path.join(dir, 'package.json'),
117
+ JSON.stringify({name, version: '1.0.0', type: 'module'}),
118
+ );
119
+ fs.writeFileSync(
120
+ path.join(dir, 'astryx.integration.mjs'),
121
+ "throw new Error('intentional integration load failure');\n",
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Put a fake `gh` first on PATH that records its arguments if it is called.
127
+ * @returns {string} the file the fake writes when invoked
128
+ */
129
+ function stubGh() {
130
+ const binDir = path.join(projectDir, 'bin');
131
+ const argsFile = path.join(projectDir, 'gh-args.json');
132
+ fs.mkdirSync(binDir, {recursive: true});
133
+ fs.writeFileSync(
134
+ path.join(binDir, 'gh'),
135
+ `#!/usr/bin/env node
136
+ import fs from 'node:fs';
137
+ fs.writeFileSync(${JSON.stringify(argsFile)}, JSON.stringify(process.argv.slice(2)));
138
+ console.log('https://github.com/acme/core/issues/42');
139
+ `,
140
+ {mode: 0o755},
141
+ );
142
+ fs.chmodSync(path.join(binDir, 'gh'), 0o755);
143
+ vi.stubEnv('PATH', `${binDir}${path.delimiter}${process.env.PATH ?? ''}`);
144
+ return argsFile;
145
+ }
146
+
108
147
  const reportOptions = {
109
148
  category: 'missing_variant',
110
149
  reason: 'Need a compact size',
@@ -681,6 +720,73 @@ describe('gapReport handler isolation', () => {
681
720
  });
682
721
  });
683
722
 
723
+ it('an integration that fails to load is a failed delivery, not a missing handler', async () => {
724
+ addBrokenIntegration('@test/broken');
725
+ configure(['@test/broken'], {
726
+ issuesUrl: 'https://github.com/acme/core/issues/new',
727
+ });
728
+
729
+ const result = await gapReport('General', {
730
+ ...reportOptions,
731
+ cwd: projectDir,
732
+ });
733
+
734
+ expect(result.data.status).toBe('failed');
735
+ expect(result.data.deliveries).toEqual([
736
+ {
737
+ handlerType: 'integration',
738
+ handler: '@test/broken',
739
+ audience: null,
740
+ status: 'failed',
741
+ url: null,
742
+ message: expect.stringContaining(
743
+ 'intentional integration load failure',
744
+ ),
745
+ },
746
+ ]);
747
+ });
748
+
749
+ it('an integration that fails to load keeps the public fallback off, even with consent', async () => {
750
+ addBrokenIntegration('@test/broken');
751
+ configure(['@test/broken'], {
752
+ issuesUrl: 'https://github.com/acme/core/issues/new',
753
+ });
754
+ const argsFile = stubGh();
755
+
756
+ const result = await gapReport('General', {
757
+ ...reportOptions,
758
+ confirmPublic: true,
759
+ cwd: projectDir,
760
+ });
761
+
762
+ expect(result.data.status).toBe('failed');
763
+ expect(result.data.deliveries.map(d => d.handlerType)).toEqual([
764
+ 'integration',
765
+ ]);
766
+ expect(fs.existsSync(argsFile)).toBe(false);
767
+ });
768
+
769
+ it('an integration that fails to load keeps its place beside working handlers', async () => {
770
+ addBrokenIntegration('@test/broken');
771
+ addIntegration({
772
+ name: '@test/valid',
773
+ audience: 'internal',
774
+ handleBody: "return {status: 'filed', message: 'ok'};",
775
+ });
776
+ configure(['@test/broken', '@test/valid']);
777
+
778
+ const result = await gapReport('General', {
779
+ ...reportOptions,
780
+ cwd: projectDir,
781
+ });
782
+
783
+ expect(result.data.status).toBe('partial');
784
+ expect(result.data.deliveries.map(d => [d.handler, d.status])).toEqual([
785
+ ['@test/broken', 'failed'],
786
+ ['@test/valid', 'filed'],
787
+ ]);
788
+ });
789
+
684
790
  it('invalid handler receipt is recorded as failed delivery', async () => {
685
791
  addIntegration({
686
792
  name: '@test/bad-receipt',
@@ -115,18 +115,18 @@ export function componentKeywords(coreDir: string, cwd: string): Promise<{
115
115
  keywords: string[];
116
116
  }[]>;
117
117
  /**
118
- * Unified ranked search across components, hooks, docs, and templates.
118
+ * Unified ranked search across components, hooks, docs, templates, and themes.
119
119
  *
120
120
  * @param {string} query - Free-text search term.
121
121
  * @param {object} [options]
122
122
  * @param {string} [options.cwd]
123
- * @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
123
+ * @param {'component'|'hook'|'doc'|'template'|'theme'} [options.type] - Restrict to one domain.
124
124
  * @param {number} [options.limit] - Max results (default 20).
125
125
  * @returns {Promise<import('./search.type.mjs').SearchResponse>}
126
126
  */
127
127
  export function search(query: string, options?: {
128
128
  cwd?: string | undefined;
129
- type?: "component" | "hook" | "template" | "doc" | undefined;
129
+ type?: "theme" | "component" | "hook" | "template" | "doc" | undefined;
130
130
  limit?: number | undefined;
131
131
  }): Promise<import("./search.type.mjs").SearchResponse>;
132
132
  export namespace SYNONYMS {
@@ -159,7 +159,7 @@ export const STOPWORDS: Set<string>;
159
159
  * prefixed fields carry domain-specific payload used only by {@link toResult}.
160
160
  */
161
161
  export type Candidate = {
162
- domain: "component" | "hook" | "doc" | "template";
162
+ domain: "component" | "hook" | "doc" | "template" | "theme";
163
163
  name: string;
164
164
  keywords?: string[] | undefined;
165
165
  weakKeywords?: string[] | undefined;
@@ -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, and templates.',
17
+ 'Unified ranked search across components, hooks, docs, templates, and themes.',
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' | 'theme'",
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 search (`type: 'doc'`) does not need it, and a search with no `type` covers the docs alone when core is missing.",
51
+ "Directory to resolve @astryxdesign/core from. A docs-only or themes-only search (`type: 'doc'` or `type: 'theme'`) does not need it, and a search with no `type` covers the docs and themes 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, 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).',
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, and `displayName` for themes. 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). A theme result is one theme you can add: `name` is its slug, its command is the `astryx theme add` that copies it into the app, and `package` is the npm package that ships it (`@astryxdesign/cli` for the CLI\'s own themes).',
59
59
  },
60
60
  ],
61
61
  throws: [
@@ -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, 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.
10
+ * content domains — components, hooks, docs topics, templates (page + block),
11
+ * and themes. Finding the right thing otherwise takes separate list calls
12
+ * (`component --list`, `hook --list`, `docs`, `template --list`, `theme list`)
13
+ * plus manual 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,6 +89,7 @@ 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';
92
93
  import {
93
94
  guideEntry,
94
95
  loadDocsCatalog,
@@ -110,7 +111,7 @@ import {setResultCoverage} from './coverage.mjs';
110
111
  * A search candidate gathered from one content domain. Extra underscore-
111
112
  * prefixed fields carry domain-specific payload used only by {@link toResult}.
112
113
  * @typedef {object} Candidate
113
- * @property {'component'|'hook'|'doc'|'template'} domain
114
+ * @property {'component'|'hook'|'doc'|'template'|'theme'} domain
114
115
  * @property {string} name
115
116
  * @property {string[]} [keywords]
116
117
  * @property {string[]} [weakKeywords]
@@ -291,7 +292,13 @@ const isTypo = (a, b, dist) =>
291
292
  TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
292
293
 
293
294
  /** Valid domain filters for `--type`. */
294
- export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
295
+ export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template', 'theme'];
296
+
297
+ /**
298
+ * The domains a search reads without @astryxdesign/core. An open search outside
299
+ * an app covers these alone.
300
+ */
301
+ const CORELESS_DOMAINS = ['doc', 'theme'];
295
302
 
296
303
  /**
297
304
  * Filler words stripped from multi-word queries so natural-language phrasing
@@ -618,6 +625,7 @@ export function scoreQuery(term, tokens, candidate) {
618
625
  // strong hits, then reward coverage so candidates matching more terms win.
619
626
  let strongest = 0;
620
627
  let matched = 0;
628
+ let tokenSum = 0;
621
629
  /** @type {string[]} */
622
630
  const hitTerms = [];
623
631
  for (const tok of tokens) {
@@ -626,6 +634,7 @@ export function scoreQuery(term, tokens, candidate) {
626
634
  if (h.score > strongest) strongest = h.score;
627
635
  matched++;
628
636
  hitTerms.push(tok);
637
+ tokenSum += h.score;
629
638
  }
630
639
  }
631
640
  // The reverse of the title tier, a step lower: the query holds a whole title
@@ -650,14 +659,25 @@ export function scoreQuery(term, tokens, candidate) {
650
659
  // (50 + bonus + coverage = 77) lost to thirty docs that each match
651
660
  // `integration` alone, by name or in a code tick (98-108). The reader asked for
652
661
  // both; a candidate that has both comes first, ordered among its peers by
653
- // how strong its strongest match is. It needs one keyword-strength hit:
662
+ // how strong its matches are. It needs one keyword-strength hit:
654
663
  // every word mentioned in prose, or rendered by a page, is breadth, and
655
664
  // stays on the token sum below an exact hit on one word.
665
+ //
666
+ // The TOTAL quality of matches orders candidates within this tier, not
667
+ // just the strongest single hit. A doc matching both words by keyword
668
+ // (90 + 90 = 180) outranks one matching keyword + prose (90 + 50 = 140).
669
+ // Before this, every all-word match whose strongest hit was a keyword (90)
670
+ // scored 157, burying the better match among dozens of ties.
656
671
  if (matched === tokens.length && strongest >= STRONG_TOKEN_SCORE) {
657
672
  return {
658
673
  score:
659
674
  FULL_COVERAGE_SCORE +
660
- Math.floor((strongest - MIN_TOKEN_SCORE) / 6.25),
675
+ Math.min(
676
+ Math.floor(
677
+ (tokenSum - matched * MIN_TOKEN_SCORE) / (matched * 5),
678
+ ),
679
+ 8,
680
+ ),
661
681
  reason,
662
682
  matched,
663
683
  total,
@@ -1463,6 +1483,33 @@ async function gatherTemplates(cwd) {
1463
1483
  });
1464
1484
  }
1465
1485
 
1486
+ /**
1487
+ * Build theme candidates from bundled and integration-provided themes. Without
1488
+ * this, an integration's themes are invisible to `search` even though
1489
+ * `theme list` and `discover` already resolve them.
1490
+ * @param {string} cwd
1491
+ * @returns {Promise<Candidate[]>}
1492
+ */
1493
+ async function gatherThemes(cwd) {
1494
+ let themes;
1495
+ try {
1496
+ themes = await listAvailableThemes(cwd);
1497
+ } catch {
1498
+ return [];
1499
+ }
1500
+ return themes.map(t => ({
1501
+ domain: 'theme',
1502
+ name: t.slug,
1503
+ keywords: [
1504
+ t.displayName,
1505
+ ...(t.description ? t.description.split(/[^A-Za-z0-9]+/).filter(w => w.length > 3) : []),
1506
+ ],
1507
+ description: t.description || '',
1508
+ _displayName: t.displayName,
1509
+ _package: t.package,
1510
+ }));
1511
+ }
1512
+
1466
1513
  /**
1467
1514
  * Map a scored candidate to its public, actionable result shape. Each result
1468
1515
  * carries enough to act on it: the domain, name, a one-line description, and
@@ -1519,6 +1566,14 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
1519
1566
  command: `astryx template ${c._commandName ?? c.name} --type ${c._kind}`,
1520
1567
  };
1521
1568
  break;
1569
+ case 'theme':
1570
+ result = {
1571
+ ...base,
1572
+ displayName: c._displayName,
1573
+ command: `astryx theme add ${c.name}`,
1574
+ ...(c._package ? {package: c._package} : {}),
1575
+ };
1576
+ break;
1522
1577
  default:
1523
1578
  result = base;
1524
1579
  }
@@ -1526,12 +1581,12 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
1526
1581
  }
1527
1582
 
1528
1583
  /**
1529
- * Unified ranked search across components, hooks, docs, and templates.
1584
+ * Unified ranked search across components, hooks, docs, templates, and themes.
1530
1585
  *
1531
1586
  * @param {string} query - Free-text search term.
1532
1587
  * @param {object} [options]
1533
1588
  * @param {string} [options.cwd]
1534
- * @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
1589
+ * @param {'component'|'hook'|'doc'|'template'|'theme'} [options.type] - Restrict to one domain.
1535
1590
  * @param {number} [options.limit] - Max results (default 20).
1536
1591
  * @returns {Promise<import('./search.type.mjs').SearchResponse>}
1537
1592
  */
@@ -1568,12 +1623,14 @@ export async function search(query, options = {}) {
1568
1623
  const term = String(query).trim().toLowerCase();
1569
1624
  const tokens = tokenizeQuery(term);
1570
1625
 
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) {
1626
+ // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
1627
+ // list` reads themes without it (bundled themes need no project), so a
1628
+ // search of either must too. Every other domain reads core: asked for by
1629
+ // name, it is an error without core; an open search then covers the docs
1630
+ // and themes alone.
1631
+ const needsCore = !type || !CORELESS_DOMAINS.includes(type);
1632
+ const coreDir = needsCore ? findCoreDir(cwd) : null;
1633
+ if (type && needsCore && !coreDir) {
1577
1634
  throw new AstryxError(
1578
1635
  'Could not find @astryxdesign/core package',
1579
1636
  undefined,
@@ -1583,17 +1640,19 @@ export async function search(query, options = {}) {
1583
1640
 
1584
1641
  // Gather candidates from each requested domain in parallel.
1585
1642
  /** @param {string} d */
1586
- const wants = d => (!type && (coreDir != null || d === 'doc')) || type === d;
1587
- const [components, hooks, docTopics, templates] = await Promise.all([
1643
+ const wants = d =>
1644
+ (!type && (coreDir != null || CORELESS_DOMAINS.includes(d))) || type === d;
1645
+ const [components, hooks, docTopics, templates, themes] = await Promise.all([
1588
1646
  wants('component')
1589
1647
  ? gatherComponents(/** @type {string} */ (coreDir), cwd)
1590
1648
  : [],
1591
1649
  wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
1592
1650
  wants('doc') ? gatherDocs(cwd) : [],
1593
1651
  wants('template') ? gatherTemplates(cwd) : [],
1652
+ wants('theme') ? gatherThemes(cwd) : [],
1594
1653
  ]);
1595
1654
 
1596
- const all = [...components, ...hooks, ...docTopics, ...templates];
1655
+ const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
1597
1656
 
1598
1657
  // Score every candidate on its own merits. The consumer groups results by
1599
1658
  // role (page / block / component) and takes the top of each, so there's no
@@ -1610,7 +1669,7 @@ export async function search(query, options = {}) {
1610
1669
 
1611
1670
  // Sort by score desc, then domain (stable order), then name.
1612
1671
  /** @type {Record<string, number>} */
1613
- const domainOrder = {component: 0, hook: 1, doc: 2, template: 3};
1672
+ const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
1614
1673
  scored.sort(
1615
1674
  (a, b) =>
1616
1675
  b.score - a.score ||
@@ -75,7 +75,7 @@ describe('search leaf — envelope + ranking', () => {
75
75
  });
76
76
 
77
77
  describe('search leaf — per-domain result fields', () => {
78
- it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
78
+ it('carries import for components and hooks, title for docs, displayName and kind for templates, displayName for themes', async () => {
79
79
  const r = await search('theme', {cwd, limit: 60});
80
80
  expect(new Set(r.data.results.map(res => res.domain))).toEqual(
81
81
  new Set(SEARCH_DOMAINS),
@@ -89,9 +89,12 @@ describe('search leaf — per-domain result fields', () => {
89
89
  expect(res.title).toMatch(/\S/);
90
90
  const read = `astryx docs ${res.name}`;
91
91
  expect([read, `${read} --index`, `${read} ${res.section}`]).toContain(res.command);
92
- } else {
92
+ } else if (res.domain === 'template') {
93
93
  expect(res.displayName).toMatch(/\S/);
94
94
  expect(['page', 'block']).toContain(res.kind);
95
+ } else if (res.domain === 'theme') {
96
+ expect(res.displayName).toMatch(/\S/);
97
+ expect(res.command).toMatch(/^astryx theme add /);
95
98
  }
96
99
  }
97
100
  }, SLOW);
@@ -397,11 +400,10 @@ describe('search leaf — a candidate that matches every word outranks a partial
397
400
  expect(score(q, all)).toBeLessThan(160);
398
401
  });
399
402
 
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', () => {
403
+ // Among candidates that match every word, the stronger match comes first:
404
+ // the all-words tier uses total match quality (sum of token scores), not
405
+ // just the strongest, so an exact keyword outranks a stem-form keyword.
406
+ it('ranks the stronger of two all-word matches first', () => {
405
407
  const all = {name: 'x', keywords: ['alphas'], description: 'alpha beta gamma delta'};
406
408
  const q = 'alpha beta gamma delta';
407
409
  expect(score(q, {name: 'y', keywords: ['alpha'], description: 'beta gamma delta'})).toBeGreaterThan(
@@ -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" | "theme";
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, theme slug).
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`, or `astryx theme add neutral` for a theme).
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; for a section, the package whose file the section came from.
49
+ * - The npm package that authored a doc result (for a section, the package whose file the section came from), or that ships a theme result.
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 results.
57
+ * - Friendly display name — present for template and theme 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'} SearchDomain
12
+ * @typedef {'component' | 'hook' | 'doc' | 'template' | 'theme'} 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, theme slug).
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`, or `astryx theme add neutral` for a theme).
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; for a section, the package whose file the section came from.
27
+ * @property {string} [package] - The npm package that authored a doc result (for a section, the package whose file the section came from), or that ships a theme result.
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 results.
29
+ * @property {string} [displayName] - Friendly display name — present for template and theme results.
30
30
  * @property {'page' | 'block'} [kind] - Template kind (`page` | `block`) — present for template results.
31
31
  */
32
32
 
@@ -6,8 +6,9 @@ export const docs = {
6
6
  name: 'theme',
7
7
  title: 'Theme System',
8
8
  category: 'guide',
9
+ keywords: ['use', 'apply', 'setup'],
9
10
  description:
10
- 'Theme provider, custom themes, theme build for production/SSR, light/dark mode, and component style overrides.',
11
+ 'How to use and apply themes in your app: providers, custom themes, light/dark mode, production builds, and component style overrides.',
11
12
 
12
13
  sections: [
13
14
  {
@@ -174,7 +174,7 @@ message: Rerun with --confirm-public to file this report.`,
174
174
  },
175
175
  {
176
176
  type: 'prose',
177
- text: 'One handler anywhere in the app, from the app or from any package, turns the fallback off for every report. See {@link command:gap-report}.',
177
+ text: 'One handler anywhere in the app, from the app or from any package, turns the fallback off for every report. So does a listed package that fails to load: the CLI cannot tell whether it has a handler, so the report fails for that package instead of going to another tracker. See {@link command:gap-report}.',
178
178
  },
179
179
  ],
180
180
  },
@@ -209,11 +209,16 @@ async function warnOnThemeIntegrationIssues(json) {
209
209
  * @param {import('../../../api/theme/theme.type.mjs').ThemeListEntry[]} themes
210
210
  */
211
211
  function printThemeList(themes) {
212
+ const run = getCliInvocation();
213
+ // `theme list` shows what this project can add now. Themes in packages it
214
+ // has not installed are `discover`'s.
215
+ const more = text(
216
+ `More themes in packages you could add: ${run} discover theme`,
217
+ );
212
218
  if (themes.length === 0) {
213
- emit(text('No themes are available in this project.'));
219
+ emit(text('No themes are available in this project.'), more);
214
220
  return;
215
221
  }
216
- const run = getCliInvocation();
217
222
  emit(
218
223
  section('Themes'),
219
224
  list(
@@ -226,6 +231,7 @@ function printThemeList(themes) {
226
231
  text(
227
232
  `Usage:\n ${run} theme add <slug> [target-path] Scaffold a theme file you own`,
228
233
  ),
234
+ more,
229
235
  );
230
236
  }
231
237
 
@@ -268,19 +268,47 @@ export function registerDiscover(program) {
268
268
  // No discover source: the list of what this project has, as always.
269
269
  if (available === undefined) {
270
270
  if (result.data.length === 0) {
271
- if (result.meta && result.meta.configured === false) {
271
+ if (options.available) {
272
+ // The user specifically asked for available packages but
273
+ // there is no source to answer from. Say so honestly.
274
+ emit(
275
+ text('No discover source is configured.'),
276
+ text(
277
+ [
278
+ 'Available integrations are listed by discover sources.',
279
+ 'A project can set one in astryx.config.mjs, and installed',
280
+ 'integrations can provide one.',
281
+ ].join(' '),
282
+ ),
283
+ text(
284
+ [
285
+ `Find Astryx packages on npm: npm search @astryxdesign`,
286
+ `Learn more: ${run} docs cli/integrations`,
287
+ ].join('\n'),
288
+ ),
289
+ );
290
+ } else if (result.meta && result.meta.configured === false) {
272
291
  emit(
273
292
  text('No integrations configured.'),
274
293
  text('Add integration package names to astryx.config.mjs:'),
275
294
  code(
276
295
  "export default {\n integrations: ['@scope/your-integration'],\n};",
277
296
  ),
297
+ text(
298
+ [
299
+ `Find Astryx packages on npm: npm search @astryxdesign`,
300
+ `Learn more: ${run} docs cli/integrations`,
301
+ ].join('\n'),
302
+ ),
278
303
  );
279
304
  } else {
280
305
  emit(
281
306
  text(
282
307
  'No external components found in configured integrations.',
283
308
  ),
309
+ text(
310
+ `Find more packages: ${run} discover --available (needs a discover source)`,
311
+ ),
284
312
  );
285
313
  }
286
314
  break;
@@ -0,0 +1,75 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx discover` when no discover source is configured and no
5
+ * integration provides one.
6
+ *
7
+ * In a fresh public app with no integrations, `discover --available` used to
8
+ * print "No integrations configured. Add integration package names..." — a
9
+ * message that told users to add names they had no way to find. These tests
10
+ * pin the honest replacement.
11
+ */
12
+
13
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import * as os from 'node:os';
17
+ import {runCli} from '../../../test-utils/run-cli.mjs';
18
+
19
+ let tmpDir;
20
+ let project;
21
+
22
+ beforeEach(() => {
23
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-discover-nosource-'));
24
+ project = path.join(tmpDir, 'project');
25
+ fs.mkdirSync(project, {recursive: true});
26
+ fs.writeFileSync(
27
+ path.join(project, 'package.json'),
28
+ JSON.stringify({name: 'my-app', version: '1.0.0'}),
29
+ );
30
+ });
31
+
32
+ afterEach(() => {
33
+ fs.rmSync(tmpDir, {recursive: true, force: true});
34
+ });
35
+
36
+ describe('astryx discover --available with no source', () => {
37
+ it('explains what discover sources are and where to find packages', async () => {
38
+ const {status, stdout} = await runCli(['discover', '--available'], {
39
+ cwd: project,
40
+ });
41
+
42
+ expect(status).toBe(0);
43
+ expect(stdout).toContain('No discover source is configured.');
44
+ expect(stdout).toContain('discover sources');
45
+ expect(stdout).toContain('npm search @astryxdesign');
46
+ expect(stdout).toContain('docs cli/integrations');
47
+ // Must not show the old misleading message
48
+ expect(stdout).not.toContain('Add integration package names');
49
+ });
50
+
51
+ it('returns an empty list with configured=false in --json', async () => {
52
+ const {status, stdout} = await runCli(
53
+ ['discover', '--available', '--json'],
54
+ {cwd: project},
55
+ );
56
+
57
+ expect(status).toBe(0);
58
+ const result = JSON.parse(stdout);
59
+ expect(result.type).toBe('discover.list');
60
+ expect(result.data).toEqual([]);
61
+ expect(result.meta).toEqual({configured: false});
62
+ });
63
+ });
64
+
65
+ describe('astryx discover with nothing configured', () => {
66
+ it('shows the config snippet and a pointer to npm and docs', async () => {
67
+ const {status, stdout} = await runCli(['discover'], {cwd: project});
68
+
69
+ expect(status).toBe(0);
70
+ expect(stdout).toContain('No integrations configured.');
71
+ expect(stdout).toContain("integrations: ['@scope/your-integration']");
72
+ expect(stdout).toContain('npm search @astryxdesign');
73
+ expect(stdout).toContain('docs cli/integrations');
74
+ });
75
+ });
@@ -55,6 +55,18 @@ export function registerGapReport(program) {
55
55
  result.type === 'gap-report.file' &&
56
56
  (result.data.status === 'failed' || result.data.status === 'partial');
57
57
 
58
+ // stderr in both modes, so a caller that reads only the exit code or the
59
+ // JSON envelope still sees which delivery failed and why.
60
+ if (isFailure && result.type === 'gap-report.file') {
61
+ for (const delivery of result.data.deliveries) {
62
+ if (delivery.status === 'failed') {
63
+ console.error(
64
+ `gap-report: delivery to ${delivery.handler} failed: ${delivery.message ?? 'no message'}`,
65
+ );
66
+ }
67
+ }
68
+ }
69
+
58
70
  if (program.opts().json) {
59
71
  jsonOut(result);
60
72
  if (isFailure) process.exitCode = 1;
@@ -172,6 +172,69 @@ export default {};\n`,
172
172
  }
173
173
  });
174
174
 
175
+ it('exits nonzero and names the integration on stderr when one fails to load', async () => {
176
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gap-broken-'));
177
+ try {
178
+ fs.writeFileSync(
179
+ path.join(cwd, 'package.json'),
180
+ JSON.stringify({name: 'fixture-app'}),
181
+ );
182
+ fs.writeFileSync(
183
+ path.join(cwd, 'astryx.config.mjs'),
184
+ "export default {integrations: ['@test/broken']};\n",
185
+ );
186
+ const integrationDir = path.join(cwd, 'node_modules', '@test', 'broken');
187
+ fs.mkdirSync(integrationDir, {recursive: true});
188
+ fs.writeFileSync(
189
+ path.join(integrationDir, 'package.json'),
190
+ JSON.stringify({
191
+ name: '@test/broken',
192
+ version: '1.0.0',
193
+ type: 'module',
194
+ }),
195
+ );
196
+ fs.writeFileSync(
197
+ path.join(integrationDir, 'astryx.integration.mjs'),
198
+ "throw new Error('intentional integration load failure');\n",
199
+ );
200
+
201
+ const cli = await runCli(
202
+ [
203
+ 'gap-report',
204
+ 'General',
205
+ '--category',
206
+ 'docs_gap',
207
+ '--reason',
208
+ 'Need a keyboard example',
209
+ '--json',
210
+ ],
211
+ {cwd},
212
+ );
213
+
214
+ expect(cli.status).toBe(1);
215
+ expect(JSON.parse(cli.stdout)).toMatchObject({
216
+ type: 'gap-report.file',
217
+ data: {
218
+ status: 'failed',
219
+ filedCount: 0,
220
+ deliveries: [
221
+ {
222
+ handlerType: 'integration',
223
+ handler: '@test/broken',
224
+ status: 'failed',
225
+ },
226
+ ],
227
+ },
228
+ });
229
+ expect(cli.stderr).toContain(
230
+ 'gap-report: delivery to @test/broken failed:',
231
+ );
232
+ expect(cli.stderr).toContain('intentional integration load failure');
233
+ } finally {
234
+ fs.rmSync(cwd, {recursive: true, force: true});
235
+ }
236
+ });
237
+
175
238
  it('reports missing required fields through the JSON error contract', async () => {
176
239
  const cli = await runCli(['gap-report', 'Button', '--json']);
177
240
  expect(cli.status).toBe(1);
@@ -13,11 +13,11 @@ export const doc = {
13
13
  name: 'search',
14
14
  displayName: 'astryx search',
15
15
  namespace: 'cli/commands',
16
- summary: 'Search components, hooks, docs, and templates in one ranked list',
16
+ summary: 'Search components, hooks, docs, templates, and themes in one ranked list',
17
17
  description:
18
18
  'Terminal front-end to search(): prints one ranked, greppable list across ' +
19
19
  'every content domain, each row carrying a follow-up command to act on it. ' +
20
- 'Outside an app, where @astryxdesign/core is not installed, it searches the docs.',
20
+ 'Outside an app, where @astryxdesign/core is not installed, it searches the docs and themes.',
21
21
  fn: 'search',
22
22
  // Every word after `search` is the query: `astryx search dark mode` searches
23
23
  // for "dark mode", with no quotes needed.
@@ -26,8 +26,8 @@ export const doc = {
26
26
  {
27
27
  flag: '--type <domain>',
28
28
  param: 'options.type',
29
- choices: ['component', 'hook', 'doc', 'template'],
30
- description: 'Filter to one domain (component|hook|doc|template)',
29
+ choices: ['component', 'hook', 'doc', 'template', 'theme'],
30
+ description: 'Filter to one domain (component|hook|doc|template|theme)',
31
31
  },
32
32
  {
33
33
  flag: '--limit <n>',
@@ -49,6 +49,7 @@ export const doc = {
49
49
  label: 'Filter + JSON',
50
50
  cli: 'astryx search "data table" --type template --json',
51
51
  },
52
+ {label: 'Themes you can add', cli: 'astryx search warm --type theme'},
52
53
  ],
53
54
  exitCodes: [
54
55
  {code: 0, when: 'success (including zero matches)'},
@@ -4,9 +4,9 @@
4
4
  * @file search command — unified ranked search with a stable result summary.
5
5
  *
6
6
  * One "I'm looking for X" entry point spanning components, hooks, docs topics,
7
- * and templates (page + block). Results are ranked by relevance and tagged
8
- * with their domain, with a follow-up command so the user knows what to run
9
- * next.
7
+ * templates (page + block), and themes. Results are ranked by relevance and
8
+ * tagged with their domain, with a follow-up command so the user knows what to
9
+ * run next.
10
10
  *
11
11
  * The command surface (description, args, flags) is sourced from the colocated
12
12
  * `search.doc.mjs` CommandDoc via `defineCommand`; this file supplies only the
@@ -104,13 +104,13 @@ export function registerSearch(program) {
104
104
  // ── Text output ──────────────────────────────────────────────
105
105
  const run = getCliInvocation();
106
106
  const {query: q, matchCount, results} = result.data;
107
- // Outside an app an open search covers the docs alone. Say so, so a
108
- // docs-only list does not read as "Astryx has no such component".
107
+ // Outside an app an open search covers the docs and themes alone. Say
108
+ // so, so that list does not read as "Astryx has no such component".
109
109
  const note =
110
110
  !options.type && !findCoreDir(process.cwd())
111
111
  ? [
112
112
  text(
113
- '@astryxdesign/core is not installed here, so only the docs were searched.',
113
+ '@astryxdesign/core is not installed here, so only the docs and themes were searched.',
114
114
  ),
115
115
  ]
116
116
  : [];
@@ -123,6 +123,7 @@ export function registerSearch(program) {
123
123
  text(
124
124
  `Try a broader term, or browse: ${run} ${note.length > 0 ? 'docs' : 'component --list'}`,
125
125
  ),
126
+ ...discoverHint(run, q, options.type),
126
127
  );
127
128
  return answered;
128
129
  }
@@ -174,11 +175,34 @@ export function registerSearch(program) {
174
175
  format: {command: formatCliCommand, parent: formatCliCommand},
175
176
  }),
176
177
  ...note,
178
+ ...discoverHint(run, q, options.type),
177
179
  );
178
180
  return answered;
179
181
  },
180
182
  });
181
183
  }
182
184
 
185
+ /**
186
+ * Search reads only what is installed. Point at `discover` for the packages
187
+ * that could add more, except for hooks, which no integration adds.
188
+ * @param {string} run - The caller's CLI invocation prefix.
189
+ * @param {string} query
190
+ * @param {string | undefined} type
191
+ */
192
+ function discoverHint(run, query, type) {
193
+ if (type === 'hook') return [];
194
+ return [
195
+ text(`More in packages you could add: ${run} discover ${shellWord(query)}`),
196
+ ];
197
+ }
198
+
199
+ /**
200
+ * One shell word: the value itself when it is plain, else single-quoted.
201
+ * @param {string} value
202
+ */
203
+ function shellWord(value) {
204
+ return /^[\w@./:-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
205
+ }
206
+
183
207
  // Re-export the API for external consumers.
184
208
  export {search, SEARCH_DOMAINS} from '../../../api/search/search.mjs';
@@ -118,6 +118,15 @@ describe('search() API — filters', () => {
118
118
  }
119
119
  });
120
120
 
121
+ it('--type theme returns only themes, each with the command that adds it', async () => {
122
+ const {data} = await search('warm', {...OPTS, type: 'theme'});
123
+ expect(data.results.map(r => r.name)).toContain('neutral');
124
+ for (const r of data.results) {
125
+ expect(r.domain).toBe('theme');
126
+ expect(r.command).toBe(`astryx theme add ${r.name}`);
127
+ }
128
+ });
129
+
121
130
  it('respects --limit', async () => {
122
131
  const {data} = await search('button', {...OPTS, limit: 3});
123
132
  expect(data.results.length).toBeLessThanOrEqual(3);
@@ -279,7 +288,7 @@ describe('search CLI — exit codes + JSON contract', () => {
279
288
  });
280
289
 
281
290
  it('prints every result field under its JSON key (score and reason with --verbose)', async () => {
282
- // One query that reaches all four domains, so every per-domain field shows.
291
+ // One query that reaches every domain, so every per-domain field shows.
283
292
  const args = ['search', 'theme', '--limit', '60'];
284
293
  const env = JSON.parse((await runCli(['--json', ...args], REPO_ROOT)).stdout);
285
294
  expect(new Set(env.data.results.map(r => r.domain))).toEqual(new Set(SEARCH_DOMAINS));
@@ -311,16 +320,42 @@ describe('search CLI — exit codes + JSON contract', () => {
311
320
  expect(r.stdout).toContain('reason:');
312
321
  });
313
322
 
314
- it('searches the docs when no @astryxdesign/core is reachable, and exits 1 for --type component', async () => {
323
+ it('points at discover for packages that could add more, except for hooks', async () => {
324
+ const open = await runCli(['search', 'data', 'table'], REPO_ROOT);
325
+ expect(open.status).toBe(0);
326
+ expect(open.stdout).toMatch(/^More in packages you could add: .*discover 'data table'$/m);
327
+ const none = await runCli(['search', 'zzqqxxnomatch'], REPO_ROOT);
328
+ expect(none.stdout).toMatch(/^More in packages you could add: .*discover zzqqxxnomatch$/m);
329
+ const hooks = await runCli(['search', 'click', '--type', 'hook'], REPO_ROOT);
330
+ expect(hooks.status).toBe(0);
331
+ expect(hooks.stdout).not.toContain('More in packages you could add');
332
+ const json = await runCli(['--json', 'search', 'button'], REPO_ROOT);
333
+ expect(json.stdout).not.toContain('More in packages you could add');
334
+ });
335
+
336
+ it('searches the docs and themes when no @astryxdesign/core is reachable, and exits 1 for --type component', async () => {
315
337
  const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-cli-no-core-'));
316
338
  try {
317
339
  const open = await runCli(['--json', 'search', 'make', 'an', 'integration'], empty);
318
340
  expect(open.status).toBe(0);
319
341
  expect(JSON.parse(open.stdout).data.results[0]).toMatchObject({domain: 'doc'});
320
- // The text says the search covered the docs alone.
342
+ // Bundled themes need no project, so an open search finds them too.
343
+ const theme = await runCli(['--json', 'search', 'neutral'], empty);
344
+ expect(theme.status).toBe(0);
345
+ expect(JSON.parse(theme.stdout).data.results[0]).toMatchObject({
346
+ domain: 'theme',
347
+ name: 'neutral',
348
+ });
349
+ // The text says the search covered the docs and themes alone.
321
350
  const text = await runCli(['search', 'button'], empty);
322
351
  expect(text.status).toBe(0);
323
- expect(text.stdout).toContain('only the docs were searched');
352
+ expect(text.stdout).toContain('only the docs and themes were searched');
353
+ // A themes-only search needs no core, like a docs-only one.
354
+ const themes = await runCli(['--json', 'search', 'warm', '--type', 'theme'], empty);
355
+ expect(themes.status).toBe(0);
356
+ const found = JSON.parse(themes.stdout).data.results;
357
+ expect(found.map(r => r.name)).toContain('neutral');
358
+ expect(found.every(r => r.domain === 'theme')).toBe(true);
324
359
  const json = await runCli(['--json', 'search', 'button', '--type', 'component'], empty);
325
360
  expect(json.status).toBe(1);
326
361
  expect(JSON.parse(json.stdout)).toMatchObject({code: 'ERR_CORE_NOT_FOUND'});
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file CLI behavior for `astryx theme list`.
5
+ *
6
+ * `theme list` shows the themes this project can add now. Themes in packages
7
+ * it has not installed are `discover`'s, so the list ends by pointing there:
8
+ * an agent that never learns `discover` exists searches the registry instead.
9
+ */
10
+
11
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
12
+ import * as fs from 'node:fs';
13
+ import * as path from 'node:path';
14
+ import * as os from 'node:os';
15
+ import {runCli} from '../../../test-utils/run-cli.mjs';
16
+
17
+ let tmpDir;
18
+ beforeEach(() => {
19
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-cli-theme-list-'));
20
+ });
21
+ afterEach(() => {
22
+ fs.rmSync(tmpDir, {recursive: true, force: true});
23
+ });
24
+
25
+ describe('astryx theme list', () => {
26
+ it('lists the bundled themes and points at discover for more', async () => {
27
+ const {status, stdout} = await runCli(['theme', 'list'], {cwd: tmpDir});
28
+
29
+ expect(status).toBe(0);
30
+ expect(stdout).toMatch(/^- neutral \(maintained, @astryxdesign\/cli\)/m);
31
+ expect(stdout).toMatch(/More themes in packages you could add: .*discover theme$/m);
32
+ });
33
+
34
+ it('keeps the JSON envelope free of the hint', async () => {
35
+ const {status, stdout} = await runCli(['--json', 'theme', 'list'], {cwd: tmpDir});
36
+
37
+ expect(status).toBe(0);
38
+ expect(stdout).not.toContain('discover');
39
+ expect(JSON.parse(stdout).type).toBe('theme.list');
40
+ });
41
+ });
@@ -472,7 +472,8 @@ export function generateCompressedIndex(
472
472
 
473
473
  // Command reference — build/template/component are covered in WORKFLOW above.
474
474
  lines.push('MORE CLI:');
475
- lines.push(' search "<query>" find any component / hook / doc / template / block');
475
+ lines.push(' search "<query>" find any component / hook / doc / template / block / theme');
476
+ lines.push(' discover <words> integrations you could add, and the ones you have');
476
477
  lines.push(` component --list ${componentCount} components by category`);
477
478
  lines.push(' template --list page + block recipes');
478
479
  const docsDir = path.join(CLI_ROOT, 'assets', 'docs');
@@ -110,6 +110,14 @@ describe('generateCompressedIndex', () => {
110
110
  expect(result).toMatch(/after any Astryx or integration dependency bump/);
111
111
  });
112
112
 
113
+ it('points agents at discover for integrations they could add', () => {
114
+ const result = generateCompressedIndex('1.0.0');
115
+ // Without this line no surface an agent reads names `discover`, and agents
116
+ // look for a theme in the package registry instead.
117
+ expect(result).toMatch(/^ {2}discover <words> {3}integrations you could add, and the ones you have$/m);
118
+ expect(result).toMatch(/^ {2}search "<query>" .*\/ theme$/m);
119
+ });
120
+
113
121
  it('states the invocation once in the CLI header (yarn)', () => {
114
122
  const result = generateCompressedIndex('1.0.0', {invocation: 'yarn astryx'});
115
123
  expect(result).toContain('yarn astryx <cmd>');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.5-canary.8aa0e94",
3
+ "version": "0.6.5-canary.8d216bb",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.6.5-canary.8aa0e94",
105
- "@astryxdesign/core": "0.6.5-canary.8aa0e94",
106
- "@astryxdesign/lab": "0.6.5-canary.8aa0e94",
107
- "@astryxdesign/theme-neutral": "0.6.5-canary.8aa0e94"
104
+ "@astryxdesign/charts": "0.6.5-canary.8d216bb",
105
+ "@astryxdesign/core": "0.6.5-canary.8d216bb",
106
+ "@astryxdesign/lab": "0.6.5-canary.8d216bb",
107
+ "@astryxdesign/theme-neutral": "0.6.5-canary.8d216bb"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.5-canary.8aa0e94",
125
- "@astryxdesign/core": "0.6.5-canary.8aa0e94",
126
- "@astryxdesign/lab": "0.6.5-canary.8aa0e94",
127
- "@astryxdesign/theme-neutral": "0.6.5-canary.8aa0e94",
124
+ "@astryxdesign/charts": "0.6.5-canary.8d216bb",
125
+ "@astryxdesign/core": "0.6.5-canary.8d216bb",
126
+ "@astryxdesign/lab": "0.6.5-canary.8d216bb",
127
+ "@astryxdesign/theme-neutral": "0.6.5-canary.8d216bb",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",