Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): print every search result field in the text view (#6527)

Joey884f1d88248c
diff --git a/.changeset/cli-spec-search-result-projections.md b/.changeset/cli-spec-search-result-projections.md
new file mode 100644
index 0000000000..79cec5d677
--- /dev/null
+++ b/.changeset/cli-spec-search-result-projections.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx search` text output now prints every field its `--json` results carry: `title` for doc results and `kind` for template results were missing. The `--verbose` help now says what it adds: each result's score and match reason.
+
+@josephfarina
diff --git a/packages/cli/api/search/search.doc.mjs b/packages/cli/api/search/search.doc.mjs
index 36755dcb58..b6ec498b95 100644
--- a/packages/cli/api/search/search.doc.mjs
+++ b/packages/cli/api/search/search.doc.mjs
@@ -53,7 +53,7 @@ export const doc = {
{
type: 'search',
description:
- 'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit` (domain, name, score, reason, description, follow-up command, and import path where relevant).',
+ '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.',
},
],
throws: [
diff --git a/packages/cli/api/search/search.test.mjs b/packages/cli/api/search/search.test.mjs
index c7eb82c52d..6bebf52473 100644
--- a/packages/cli/api/search/search.test.mjs
+++ b/packages/cli/api/search/search.test.mjs
@@ -70,6 +70,28 @@ describe('search leaf — envelope + ranking', () => {
}, SLOW);
});
+describe('search leaf — per-domain result fields', () => {
+ it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
+ const r = await search('theme', {cwd, limit: 60});
+ expect(new Set(r.data.results.map(res => res.domain))).toEqual(
+ new Set(SEARCH_DOMAINS),
+ );
+ for (const res of r.data.results) {
+ expect(typeof res.command).toBe('string');
+ expect(typeof res.description).toBe('string');
+ if (res.domain === 'component' || res.domain === 'hook') {
+ expect(res.import).toMatch(/\S/);
+ } else if (res.domain === 'doc') {
+ expect(res.title).toMatch(/\S/);
+ expect(res.command).toBe(`astryx docs ${res.name}`);
+ } else {
+ expect(res.displayName).toMatch(/\S/);
+ expect(['page', 'block']).toContain(res.kind);
+ }
+ }
+ }, SLOW);
+});
+
describe('search leaf — matchCount is the total, not the cap', () => {
it('reports every match while `results` stays bounded by the limit', async () => {
// The regression: `matchCount` used to be `results.length`, so a query
diff --git a/packages/cli/clients/cli/commands/search.doc.mjs b/packages/cli/clients/cli/commands/search.doc.mjs
index ffd457a6a2..d2b0bce435 100644
--- a/packages/cli/clients/cli/commands/search.doc.mjs
+++ b/packages/cli/clients/cli/commands/search.doc.mjs
@@ -33,7 +33,7 @@ export const doc = {
},
{
flag: '--verbose',
- description: 'Verbose output (include import paths and match reason)',
+ description: "Also print each result's score and match reason",
},
],
examples: [
diff --git a/packages/cli/clients/cli/commands/search.mjs b/packages/cli/clients/cli/commands/search.mjs
index 2eef0e586e..6961379e82 100644
--- a/packages/cli/clients/cli/commands/search.mjs
+++ b/packages/cli/clients/cli/commands/search.mjs
@@ -16,7 +16,7 @@
* astryx search button Ranked results across all domains
* astryx search modal --type component Filter to a single domain
* astryx search forms --limit 5 Cap the result count
- * astryx search button --verbose Verbose (include import / reason)
+ * astryx search button --verbose Also print score / reason
* astryx search button --json Typed JSON envelope
*/
@@ -117,14 +117,25 @@ export function registerSearch(program) {
? [
'name',
'domain',
+ 'title',
'displayName',
+ 'kind',
'score',
'reason',
'import',
'description',
'command',
]
- : ['name', 'domain', 'displayName', 'import', 'description', 'command'];
+ : [
+ 'name',
+ 'domain',
+ 'title',
+ 'displayName',
+ 'kind',
+ 'import',
+ 'description',
+ 'command',
+ ];
// The heading mirrors the JSON: `matchCount` is what matched, and the
// records below are the slice `--limit` allowed. Saying only "(20)" when
diff --git a/packages/cli/clients/cli/commands/search.test.mjs b/packages/cli/clients/cli/commands/search.test.mjs
index 8811e02481..f309e6b452 100644
--- a/packages/cli/clients/cli/commands/search.test.mjs
+++ b/packages/cli/clients/cli/commands/search.test.mjs
@@ -28,6 +28,33 @@ const OPTS = {cwd: REPO_ROOT};
// the vitest per-test timeout. Give both the same generous scan budget.
const SCAN_TIMEOUT = 30_000;
+/**
+ * A JSON value as the formatters print it (they normalize typography to ASCII).
+ * @param {unknown} value
+ */
+function asText(value) {
+ return (Array.isArray(value) ? value.join(', ') : String(value))
+ .replace(/[\u2014\u2013]/g, '-')
+ .replace(/[\u2018\u2019]/g, "'")
+ .replace(/[\u201C\u201D]/g, '"')
+ .replace(/\u2026/g, '...')
+ .replace(/\u00a0/g, ' ')
+ .trimEnd();
+}
+
+/**
+ * Whether some text line prints `key:` with this value. The command field gains
+ * the caller's invocation prefix, so the value is matched as the line's end; a
+ * multi-line value is matched by its first line.
+ * @param {string[]} lines
+ * @param {string} key
+ * @param {unknown} value
+ */
+function printsField(lines, key, value) {
+ const shown = asText(value).split('\n')[0].trimEnd();
+ return lines.some(line => line.startsWith(`${key}:`) && line.trimEnd().endsWith(shown));
+}
+
describe('search() API — ranking', () => {
it('ranks an exact component name match first', async () => {
const {data} = await search('button', OPTS);
@@ -223,6 +250,25 @@ describe('search CLI — exit codes + JSON contract', () => {
expect(r.stdout).toContain('description:');
});
+ it('prints every result field under its JSON key (score and reason with --verbose)', async () => {
+ // One query that reaches all four domains, so every per-domain field shows.
+ const args = ['search', 'theme', '--limit', '60'];
+ const env = JSON.parse((await runCli(['--json', ...args], REPO_ROOT)).stdout);
+ expect(new Set(env.data.results.map(r => r.domain))).toEqual(new Set(SEARCH_DOMAINS));
+ const plain = (await runCli(args, REPO_ROOT)).stdout.split('\n');
+ const verbose = (await runCli([...args, '--verbose'], REPO_ROOT)).stdout.split('\n');
+ for (const result of env.data.results) {
+ for (const [key, value] of Object.entries(result)) {
+ if (value == null || value === '') continue;
+ const label = `${result.domain} ${result.name}: ${key}`;
+ expect(printsField(verbose, key, value), label).toBe(true);
+ if (key !== 'score' && key !== 'reason') {
+ expect(printsField(plain, key, value), label).toBe(true);
+ }
+ }
+ }
+ }, 90_000);
+
it('--verbose exits 0 and prints import/match detail', async () => {
// Regression: the boolean verbose flag was named --detail, which collided
// with the value-taking global `--detail <level>` — a bare `search