Repository navigation
feat(docsite): search panel runs the CLI's own search - #7830
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 486 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
The docs site's search button and panel now answer with `astryx search`: the same module, ranking and catalog, run in a browser worker. - CLI: `searchCatalog()` (new `@astryxdesign/cli/search` entry, no Node imports) ranks a catalog from `gatherSearchCatalog()` (`./api`); `search()` ranks through the same module. - Site: the build writes public/search-index.json from the CLI the site builds with and fails on a version or format mismatch; the panel loads it on first open and opens each result through the site's pages, redirects and section anchors. - Tests: the panel's results equal `astryx search --json` for a fixed list of queries; `searchCatalog()` equals `search()`; every result opens a page the site has.
Per review direction: the panel calls the site's /api/search, which calls the CLI's `search()` (the function behind `astryx search --json`) in the site's project. No CLI change, no browser copy of the engine. - Drops the browser catalog, the worker, the new CLI export and its docs. - Section links key by the guide that owns the section, so a page that repeats a section key opens each guide's own anchor.
A long-running caller (the docs site's search API) gathered every component, doc, template and theme again for each query (~0.6-1.2 s). search() now reuses the candidates it gathered for the same folder and type while no package.json, Astryx config, lockfile or node_modules folder there or above changes, for up to five minutes. Results are unchanged; warm site queries take ~0.06-0.3 s. The site API also asks for more results when its build leaves out an integration, and cuts to 20 after dropping that integration's results.
8a10e74 to
cc65449
Compare
…is unchanged Record every file the gather reads through fs and every folder it lists or probes (foundation/fs/read-record.mjs), and reuse the catalog only while a stat of each shows no change. This also covers a linked workspace package. The five-minute cap is gone. The check costs ~60 ms on the docs site's project (~11k paths); a gather costs 0.6-1.2 s.
There was a problem hiding this comment.
This needs a maintainer decision before it can be approved: the docs-site contract (spec:AST-033 FR2 and DEC-1) has the site's search derive its results from the generated registries, so making the CLI's search() the data owner of the site search, served by a new public /api/search endpoint, needs a maintainer to amend that spec or identify the record that governs it, including how production stays pinned to the published release (FR5). Independently of that decision, these need fixing:
- The Vercel deployment fails on this head, as it did on the earlier heads with the route, while the base and
maindeploy. - On production, the route searches the workspace packages instead of the published release that the production pages document.
- Deleting
search-palette.test.tsalso removes the only test of the sidebar's canary grouping, which this change does not touch, so please keep that test. - Doc results are labelled with the CLI's docs-tree path, so most of them read "Unorganized › …" on the site.
search()now replacesnode:fsread functions for the whole process on first use, which the changeset does not mention, and two file headers still name@astryxdesign/cli/searchandscripts/generate-search-index.mjs, which do not exist.
[Automated review]
| // results before cutting to the panel's 20; otherwise this is exactly | ||
| // `astryx search <query>`. | ||
| const response = await search(query, { | ||
| cwd: process.cwd(), |
There was a problem hiding this comment.
On the production (latest) build this searches the site's own node_modules, which link to the workspace packages, while the production pages come from the published tarballs (scripts/resolve-content-root.mjs). spec:AST-033 FR5 pins latest to the published package documentation, so the first unreleased keyword, description or component on main would reach production search ahead of the pages. Consider running the search against the release snapshot the latest registries read on that target.
| ): CliSearchItem { | ||
| const label = | ||
| result.domain === 'doc' | ||
| ? (result.title ?? result.name) |
There was a problem hiding this comment.
The CLI's title carries its docs-tree path, so on the site most doc rows read "Unorganized › Theme System", "Unorganized › Use a theme › Dark mode", and so on, a grouping the site's sidebar does not have (it files these under Guide and Foundations). Labelling doc rows with the site's page and section titles, or dropping the tree path, would avoid it.
| return original.apply(this, args); | ||
| }; | ||
| Object.assign(wrapped, original); | ||
| fs[name] = wrapped; |
There was a problem hiding this comment.
From the first search() call on, this replaces eight node:fs sync functions for the whole host process, and syncBuiltinESMExports() rewrites every ESM module's bindings to them (fs.readFileSync.length also goes from 2 to 0). In-process callers of @astryxdesign/cli/api, this site's server included, get that without notice; the changeset only says search() got faster. Recording through the CLI's own fs helpers, the way listing-cache.mjs scopes listings, would keep it inside the CLI; otherwise please state it in the changeset and search()'s doc.
| * @input A result of the CLI's search (`@astryxdesign/cli/search`) and the | ||
| * site's link tables, built with the site by searchLinkTables(). | ||
| * @output The site path the result opens: a component, template, theme, or | ||
| * doc page, with the anchor of a doc section. | ||
| * @position Shared by scripts/generate-search-index.mjs (builds the tables) |
There was a problem hiding this comment.
@astryxdesign/cli/search and scripts/generate-search-index.mjs do not exist at this head; the tables are built by scripts/generate-data.mjs from results of @astryxdesign/cli/api. The same stale script name appears in generate-data.mjs's generateSearchLinks doc comment.
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('keeps ready families unified and groups canary components by package', () => { |
There was a problem hiding this comment.
This test covers getComponentSidebarData()'s canary categories, the unified Chat family and Lab's 3D group, and no other test does. The sidebar is unchanged by this pull request, so please keep it, moved into a sidebar test file.
…h in AST-033 - The CLI stays an external module of the server build, so its code and dependencies are traced as installed; the includes list only the files it reads from disk (its docs and templates, each documented package's docs and sources). A standalone build answers exactly as astryx search. - AST-033: FR2 says site search answers with the CLI's own search; FR5 says which CLI production search runs; DEC-8 records the decision. - Keeps the sidebar canary-grouping test from the removed palette test. - Changeset names the fs wrapping; stale file headers fixed.
…unction The CLI imports bundlers, compilers, browsers and test runners for other commands; a search loads none of them. Excluding them (and built output the search never reads) cuts the traced function from ~100 MB to ~54 MB. A traced-files-only build still answers deep-equal to astryx search.
There was a problem hiding this comment.
This needs a maintainer decision before it can be approved: the pull request intentionally amends spec:AST-033 so the docs site's search answers with the CLI's search(), and that amendment (FR2, DEC-1 and the new DEC-8) still needs an engineering owner's approval on the current head, which also has to settle FR5, since the record still pins production package docs to the published release while production search reads the workspace packages. Independently of that decision, please fix:
- Lab, Charts and RichText example blocks open
/templatesinstead of their component page, becausesearchLinks.mjskeys blocks by their prefixeddirNamewhile search names them by file name. - The description says FR5 is amended, but the record leaves FR5 unchanged; make the two agree.
- Doc results read "Unorganized › …" in the panel; labelling them with the site's page and section titles would match the sidebar.
- On production,
matchCountstill counts the results the route drops for undocumented integrations.
[Automated review]
| : owner && templates.has(owner) | ||
| ? `/templates/${owner}` | ||
| : null; | ||
| // Search names a block by its file name, which a Core block's dirName is. |
There was a problem hiding this comment.
Search names an integration block by its file name (EmojiPickerInPopover), but an integration block's dirName is prefixed (-astryxdesign-lab-EmojiPickerInPopover) and its name is its display title, so neither key matches and searchResultHref falls back to /templates for all 14 Lab, Charts and RichText blocks; on the head, /api/search?q=date%20picker returns /templates for both EmojiPicker blocks. Keying each block by its source file name as well would open the component page that shows it. The link test accepts /templates as a served page, so it does not catch this.
| href: searchResultHref(result, links as SearchLinkTables), | ||
| })); | ||
| return Response.json( | ||
| {...response, data: {...response.data, results}}, |
There was a problem hiding this comment.
On filtered builds this passes the CLI's matchCount through after dropping the undocumented integrations' results, so production answers count canary-only matches the site never offers; spec:AST-033 FR6 asks API output to stay consistent with the same channel facts. Recounting over the documented packages would keep it truthful.
… states search's source - Integration example blocks open their component page (the site keys them by package and name). - Doc results carry the title the site shows (page and section), never the docs tree's placeholder level. - When a build leaves out an integration, matchCount counts only what the panel can show. - AST-033 FR5: site search is workspace-backed on both targets, the same source as the site's CLI reference pages; DEC-8 says why.
|
/approve-spec 03cfa95 |
Other tests that change a folder a gather read (the temp folder, the repository root) rightly make the next call gather again; a reuse check now gathers once more and expects the following call to reuse it.
|
/approve-spec 1917896 |
There was a problem hiding this comment.
The CLI-backed site search and its spec:AST-033 amendment are approved by an engineering owner on this head, and the parity test, result links and production filtering check out; two small fixes remain before this can be approved.
- The search select event logs the CLI's names as
item(for exampleuse-a-themeorcli/commands/searchfor a doc), whilespec:AST-033FR13 asks for registry identifiers, such as the doc topic the result opens. - Different doc results can share one label in the panel ("Theme System" and "Theme System › Dark mode" each appear twice for "dark mode"), so title a guide result by the section its link opens.
[Automated review]
| } | ||
| trackSearch({ | ||
| target: 'select', | ||
| item: result.name, |
There was a problem hiding this comment.
This logs the CLI’s name, which for a doc is its topic or docs-tree route (use-a-theme, cli/commands/search) and for an integration block its file name. spec:AST-033 FR13 asks for canonical registry identifiers here; the base logged the registry topic or slug from the link. Logging the identifier of what the result opens (for example the doc topic from result.href) would keep the event meaning.
| ) { | ||
| return tables.titles[`${slug}#${result.section}`]; | ||
| } | ||
| if (Object.hasOwn(tables.titles, slug)) return tables.titles[slug]; |
There was a problem hiding this comment.
A guide result with no section falls through to its page’s title even when its link opens a section, so for "dark mode" the theme page and the "Use a theme" guide both read "Theme System" (one opens /docs/theme, the other #wrap-your-app-in-a-theme), and both "Dark mode" sections read "Theme System › Dark mode". Titling the result by the section its link opens would keep the rows distinct.
- A selected result is reported by what it opens, as the registries name it (component name, template slug, doc topic), per AST-033 FR13. - Doc rows are titled by the page and section their link opens, and the panel lists each place once at its first result, so no two rows share a label.
|
/approve-spec d112cca |
There was a problem hiding this comment.
The CLI-backed site search and its spec:AST-033 amendment are approved by an engineering owner as they stand. The parity test, result links, production filtering and both fixes from the last review check out; one fix remains. search()'s reuse stamps a gather's inputs only after the gather finishes (packages/cli/api/search/_adapter.mjs:128), so a long-running process that sees a file added or edited during a gather keeps serving stale candidates. Stamping each path when it is first read, or not storing a gather whose inputs changed after it started, plus a test, would close it.
[Automated review]
| throw error; | ||
| } | ||
| const paths = [...seen].sort(); | ||
| gathered.set(key, {paths, stamp: stampOf(paths), value}); |
There was a problem hiding this comment.
This stamps the recorded paths only after the gather has finished, so an edit made while it ran is already in the stamp. If a file is added to a folder the gather listed, or a file it read changes, later searches keep reusing the stale gather until some other recorded path changes. A probe that adds a component to a linked integration's components folder right after it is listed gets it from a fresh gatherCandidates, never from gatherCandidatesReused. Taking each path's mtimeMs and size when the recorder first sees it, or not storing a gather when any recorded path changed after it started, would make the reuse exact, and that case would make a good test.
search()'s reuse stamped a gather's inputs after the gather finished, so an edit made during a gather could leave a long-running process serving stale candidates. Each path's state is now taken as it is first read, before the read, so such an edit shows as a change on the next call.
|
/approve-spec 2b77813 |
Concurrent tests change shared folders a gather reads, so a real reuse check stays timing-dependent at full load. The reuse case now holds read-record's answer at unchanged (read-record.test.mjs covers that answer); the other cases only check that a change forces a new gather.
|
/approve-spec 7e5ed71 |
There was a problem hiding this comment.
The CLI-backed site search and its spec:AST-033 amendment are approved by an engineering owner on this revision, and the reuse fix from the last review holds: a component added while a gather runs is picked up by the next search, and the parity, link and production tests pass. Nothing more is needed for approval. Two optional follow-ups are worth tracking: search() keeps every folder's gathered catalog until the process exits (about 6.5–12 MB each), and the site's /mcp search tool still ranks registry entries on its own, so agents using it can get a different answer from the panel.
[Automated review]
| } | ||
| // Each path's state was taken as it was first read, so an edit made while | ||
| // the gather ran shows as a change on the next call. | ||
| gathered.set(key, {reads: seen, value}); |
There was a problem hiding this comment.
Non-blocking: gathered keeps one entry per folder and type for the life of the process, and nothing evicts it. Measured here at about 6.5 MB for a folder whose search reads only the CLI's docs and themes and 12.4 MB for the docs site's project, so a long-running host that searches many folders (an agent harness across worktrees, say) grows by that much per folder. Keeping only the most recent entry per type, or a small LRU, would bound it.
Primary intent
New feature: the docs site's search button and panel answer with
astryx searchitself. The panel sends each query to the site's/api/search, which calls the CLI'ssearch(), the function behindastryx search --json, in the site's project. People on the site and agents running the CLI get the same answer, and every future change to the CLI's search reaches the site on its next build. There is no copy of the engine to keep in sync.User or maintainer impact
packages/cli/api/search. The site has no ranking code, and the only CLI change is a speedup that leaves results unchanged.Authority
Ranking and the rules for search answers are unchanged (AST-083, AST-046).
This PR amends
spec:AST-033for site search:latestit leaves out integrations without published docs, and a result whose page isn't published opens the nearest published index page.Change
src/app/api/search/route.ts:GET /api/search?q=<query>runssearch(query, {cwd: <site project>})and returns the CLI's response. Each result gets the site path it opens. On builds that document fewer integrations (production), results from undocumented packages are dropped. The CLI is an external module of the server build: its code and dependencies are traced as installed.outputFileTracingIncludesadds only the files it reads from disk: its docs and templates, and each documented package's docs and sources. A standalone build (traced files only) gathers the same 1,681 entries as the workspace, and answers exactly asastryx search --jsonfor the queries checked. Packages the CLI imports for other commands but a search never loads (bundlers, compilers, browsers, test runners) are excluded, so the traced function is about 54 MB. Responses carrys-maxage, so the CDN answers repeated queries.SearchPalette.tsx+lib/cliSearchSource.ts: the panel's source calls the API with a short debounce and cancels the previous request, so only the last query typed is sent. Items carry no group, soCommandPalettekeeps the CLI's order.toSearchItemshows each result as a title (or name) plus its kind.lib/searchLinks.mjs: decides where each result opens, through the generated pages, redirects and section anchors, never by building/docs/<route>. A namespace page holds several guides' sections, and section keys are unique only within a guide. So each section is keyed by the guide that owns it, using each guide's redirect to its first section. A route with no page of its own opens its nearest parent page.generate-data.mjswrites the tables tosrc/generated/searchLinks.json.packages/cli/api/search/_adapter.mjs,foundation/fs/read-record.mjs):search()gathered every component, doc, template and theme on each call, about 0.6–1.2 s.type, but only while nothing that gather read has changed. During a gather, the CLI records every file it reads through fs and every folder it lists or probes (about 11k paths on this site's project). Each path's state (change time and size) is taken as it is first read, so an edit made while a gather runs also counts. A later call re-checks every path (about 60 ms) and gathers again on any difference, including in a linked workspace package. Tests:read-record.test.mjsand_adapter.test.mjs.astryx searchgathers once, as before._adapter.test.mjs; a patch changeset is included..doc.mjs, with or without this reuse. Node caches imported modules per process, and the doc compiler hands readers that same module object (pinned byread.test.mjs). Adding or removing doc files is seen. Fixing that changes doc loading for every command, so it is tracked separately.search()for every match, drops that integration's results, then counts (matchCount) and cuts to 20.siteTitle, the title of the page and section their link opens, so the panel never shows the docs tree's placeholder level. The panel lists each place once, at its first result, in the CLI's order. A selection is reported to analytics by what it opens, as the registries name it (AST-033 FR13). Integration example blocks open their component page.searchPaletteData.tsand its palette test are removed. The palette test's sidebar canary-grouping cases move tocomponent-sidebar-data.test.ts. The hidden-production ShadCN test now queries the site search: no registry discovery, and ShadCN named only inside the CLI's own docs (the migration guide), the same rule the MCP search test uses.Evidence
src/__tests__/cli-search.test.ts): for a fixed list of public, made-up queries, the API's response deep-equals whatastryx search <query> --jsonprints from the site's project. That covers the query, the match count, and every result in order, apart from the addedhrefandsiteTitle.next start(10 queries):Writing rubric results
Scope
Testing
vitest runinapps/docsite(afterpnpm generate): 660 passed.check:knowledgepasses.next buildwith only traced files:/api/searchanswers deep-equal toastryx search --jsonfor date picker, authoring, sidebar layout, how do I theme my app, and tokens spacing._adapter.test.mjspasses.typecheck:strict,check:cli-structureandcheck:changesetsall pass.tsc --noEmitinapps/docsite.next build --webpack, thennext startwith/api/searchchecked by curl and in a browser.