Skip to content

refactor(cli): build and search answer through one shared dispatcher/searcher pattern - #7752

Merged
josephfarina merged 24 commits into
mainfrom
josephfarina/build-search-routing
Oct 21, 2026
Merged

josephfarina merged 24 commits into
mainfrom
josephfarina/build-search-routing

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Before → after

Before = main; after = this head. The first two commits change no output; the later commits re-order search's matches and re-rank build's blocks. Paired 95% confidence intervals for the change are in brackets. Numbers come from an independent re-grade of this head's answers against main's; the synthetic search cells come from the search tests' own measurement.

Goal number Held-out evaluation set Fresh evaluation set Synthetic test set
build: page-or-block call same same same
build: right page template same same same
build: right block, first 16.1 → 18.7 [+0.9, +4.3] 18.2 → 21.2 [−1.5, +7.6] 17.6 → 22.6 [+3.4, +6.4]
build: right block, top 3 31.3 → 32.8 [−0.2, +3.0] 33.3 → 34.1 33.6 → 35.6
search: % good where something fits 81.9 → 83.1 79.1 → 83.9 [+2.0, +8.0] 69.6 → 76.0 [+3.0, +10.3] (an earlier head; this head ranks the labeled answer higher still)
search: % good of all searches 65.7 → 66.7 [−1.2, +3.1] 66.8 → 70.8 [+1.7, +6.8] 61.0 → 66.7 [+2.7, +9.0] (an earlier head)
search: % good of all searches, every real query (7,933) 68.4 → 71.6 [+2.6, +3.7]
search: % good where today's first result is a doc held-out and fresh pooled (44 queries): 40.9 → 40.9 [−6.8, +6.8]; the same without any query looked at while tuning (22): 36.4 → 40.9 [0.0, +13.6]; held-out alone (23): 43.5 → 39.1 [−13.0, 0.0] (pooled with held-out) —
searched again without using a top-3 result measured after release measured after release measured after release
answers worse / better build 7 / 23; search 10 / 16 of 414 build 3 / 7; search 4 / 14 of 295 build 5 / 55; search 5 / 22; every real search query: 172 / 429 of 7,933
ordering invariants broken, every real and synthetic request and query (target 0) search: a result that is not a lexical match 0; a changed score or reason 0; a match moved past one of another band or kind 0; a changed match count 0; more results than main 0 (8,407 real + 6,017 synthetic). Build: a block not in build's own list or with a changed entry 0; a block the request names moved 0; more blocks 0 (18,721 real + synthetic)
output bytes per answer: median / p95 / max / % longer build, every real request: text median 3,068 → 3,074, p95 3,424 → 3,438, max 3,850 → 3,850. Only the order of build's own blocks moves; its reported search match count follows search's docs. Search, every real query (text output): median 9,118 → 9,060, p95 11,923 → 11,964, max 15,409 → 15,409; 18.9% longer, 25.4% shorter; total −0.4% (in every real query) —
  • What counts as worse. A row is worse when the paired 95% confidence interval of its change lies entirely below zero. The doc-answer row is judged out-of-sample: held-out and fresh doc queries pooled, with no query that tuning used. The all-real doc row counts only with tuning queries removed. A cell under 50 queries that cannot be pooled is shown but does not judge.
  • Doc queries that lost their right answer (held-out and fresh): two, both held-out. A multi-part screen question keeps the side-panels doc first, but the Tab component now ranks second, above the editor template. A stylesheet setup question now leads with the migration setup doc, above the styling overview.
  • Search never returns more results than before, and build never returns more blocks. Build's call, start page and alternatives are unchanged. Build only re-orders the blocks it already lists, each with its own score and reason, and keeps blocks of the same name from two packages; a block the request names, a block from an integration package, and a block the weights do not know keep their places.
  • Search returns exactly the entries main matches, each with main's score and reason; only the order inside a score band changes, and search()'s doc says so. The bands are scores 195 and up, 188–194, 170–187, 160–169, 151–159, 100–150, 55–99, and under 55; a band can be wide (55–99 holds keyword matches beside one-word description hits), so inside one a lower score can lead a higher one. Doc sections remain separate results.
  • A query that is an entry's whole name gets the same answer as main: that entry first, and nothing added beside it.
  • On held-out and fresh queries whose first result today is a doc, the pooled change is zero, and without any query looked at while tuning it is 36.4 → 40.9, within noise; the held-out part alone loses one query and gains none, which is within noise.
  • Every search test that exists on main runs against search() and passes unchanged.
  • Maintainer decision: one PR. The parts depend on each other. The shared answer-picking structure only proves itself with the commands it serves, so landing it alone was rejected as unproven. Search's in-band order and build's block re-rank are built on that structure and cannot land before it. The parity, invariant and before → after measurements cover the parts together against main. This repository has no PR size limit; please review the content.

Decision: learned ordering inside a score band

The CLI owner approved ordering search's results with static, reviewed weights inside today's score bands, in their words:

"Can't we keep pushing the alg versions higher tho? Like add tree branches out for weaknesses and tune it there?"

"...strongly typed and uniform... Then we can hill climb and keep boosting the numbers"

"we're gonna have these branch approach"

The CLI owner also set the bar for future changes: "search order is mostly only important as long as it is tested against our data and is better or same as before".

This PR records both in a current record, spec:AST-083 (docs/specs/AST-083-result-order/spec.md):

  • each answer's facts are the contract: the result set, scores, reasons and counts equal the lexical ranker's; whole-name queries keep today's answer; matches never cross bands or kinds; build re-orders only its own blocks, and named blocks keep their place;
  • the order inside a score band is measured, not fixed: it may change when the held-out, fresh and synthetic evaluation sets show no row worse by the paired-CI rule;
  • the order is local, deterministic and static, with no model runtime; packages/cli/api/search/ORDERING.md describes the data files;
  • spec:AST-048 keeps owning which blocks build lists and now delegates their order to this record (one sentence in its FR8).

Writing rubric results

  • R1 narration: none; the record states what search and build guarantee and how the order may change.
  • R2 research: none in the record; measurements live in this description.
  • R3 evidence naming a change: none; the verification names the tests and the evaluation sets.
  • R4 rejected alternatives: one, a model runtime, one line inside DEC-1.
  • R5 pull request or issue references: none.
  • R6 ruled open questions still listing options: none; the record has no open questions.
  • spec:AST-048 FR8 gains one present-tense sentence delegating block order; R1–R6: none.
  • Byte parity for the first two commits covers 13,472 real build requests, 8,231 real search queries, 8,569 synthetic build requests and 6,017 synthetic search queries.

Primary intent

astryx build and astryx search now answer through the same small pattern, so each command's answering can be split into parts that are measured and improved one at a time:

  • a dispatcher decides which searcher should answer a request;
  • a searcher answers in the command's existing JSON shape.

The first commits change no output: each command's tree is a root with one searcher, the command's current ranker. Then search gains a classifier root and topic searchers that re-order its matches within each match strength, and build re-ranks its blocks.

User or maintainer impact

  • Search answers better (see the table); the JSON shape is unchanged, and search never returns more results than before. Build answers are unchanged until its block commit.
  • Maintainers:
    • add a searcher by writing one function and listing it as a child of the dispatcher;
    • the scoring stays in plain code in each command's folder;
    • the shared part is one small file both commands import.

Authority

None found that settles how a picking command is structured. The JSON shapes stay as their existing records define them, and this change keeps them.

Change

The first two commits change no output; the third changes search's ranking.

  • Shared helper (foundation/route/route.mjs):

    • defineSearcher and defineDispatcher define the two node kinds, a typed union on kind.
    • defineClassifier is a dispatcher whose route is a static word-weight classifier. The request's tokens vote for a class, and that class's searcher takes the request when its probability reaches the floor; otherwise the fallback keeps it. Its weights reach it through the command's adapter.
    • defineTree checks for duplicate ids, missing children or fallbacks, a non-searcher fallback, and cycles.
    • runTree tries a dispatcher's routed children in order. Below the floor, or when none answers, it runs the fallback, and it recurses through nested dispatchers. It takes an optional tuning (per-node weights and a step trace) for measurement code that imports a tree directly. That option is not exposed through any command, flag, or output.
    • routeKit lets a tree file type its nodes once, so each node reads as plain {id, summary, run}.
  • Build (api/build/):

    • tree.mjs: a root classifier with one class today (tree.weights.json, read by _adapter.mjs), so every request goes to main, the kit ranker.
    • build() validates, then runs the tree.
    • The kit splits into kit/kit.mjs (the kit), kit/start.mjs (the start pick), and the page ranker's kit/words.mjs, kit/kind.mjs and kit/rank.mjs.
  • Search (api/search/):

    • tree.mjs: a root dispatcher → main, the lexical ranker.
    • search() validates, gathers through _adapter.mjs, then runs the tree. searchCore() is the lexical ranker alone. Build reads it, so build's output does not move when search's tree does.
    • The adapter gathers candidates through one file per domain (_gather-components, _gather-hooks, _gather-docs, _gather-templates, with _module-doc and _doc-text helpers).
    • The lexical ranker splits by concern: _synonyms, _words, _query, _compound, _titles, _score (a whole query), _candidate-score (one term), _priority, _result, and _lexical, which merges and orders.
    • search.mjs re-exports only what build and the command handler read.
  • Structure check (scripts/check-cli-structure.mjs): search/search.mjs leaves the environment-import allowlist. The check fails on an allowlist entry that no longer applies, and search.mjs no longer reads the disk itself.

  • Search ordering (api/search/):

    • The root is a classifier (tree.weights.json). The query's words vote for the domain it wants, and the doc or template searcher takes the query when the vote reaches 0.4; otherwise main keeps it.
    • Search's results are exactly the lexical ranker's matches, with its scores and reasons and its matchCount. A searcher only re-orders matches inside a run of one score band (the same score band and the same kind, doc or not); equal-score matches move together in lexical order, so a name or keyword match always stays above a match in prose alone. Doc sections are separate entries.
    • Inside a band, each searcher (_main-searcher.mjs, _doc-searcher.mjs, _template-searcher.mjs) orders matches by a weighted sum of plain signals (_features.mjs, over the entry table in _entries.mjs and the query words in _query-words.mjs): the lexical ranker's score and rank, BM25 over each entry's name, docs text and a card built from its source (_cards.json), query-word coverage, whether the query holds the entry's name, and the classifier's domain guess.
    • A query that is an entry's whole name or title, read with dashes and spaces alike, is answered by the lexical ranker unchanged.
    • Otherwise an entry the query names (by name, plural, alias, or the Core name it replaces) leads, in lexical order (_order.mjs). Entries of the same name from two packages stay separate, and an integration's entries that the lexical ranker scored the same keep its order.
    • All weights are static JSON beside each node, 353 KB in total, read by _adapter.mjs. They are deterministic, and there is no model runtime and no network access.
  • Build blocks (fourth commit, api/build/):

    • The kit splits into kit/signals.mjs (what search and the page ranker found), kit/answer.mjs (the response), and kit/kit.mjs.
    • blocks/blocks.mjs re-orders the blocks build already lists with static word weights (blocks/blocks.weights.json, read by _adapter.mjs). It never adds a block, and each keeps its own score and reason.
    • A block the request names, a block the weights do not know, and one an integration package contributes or replaces keep the place build's ranking gave them.

Evidence

For the first two commits, old and new produce byte-identical JSON on every distinct real request (the sha256 of each response is compared):

  • every real build request: 13,472 of 13,472;
  • every real search query: 8,231 of 8,231, including the 37 that error, which error the same way.

Scope

  • This PR has one primary intent.
  • Independently removable API, visual, layout, behavior, cleanup, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run --project node packages/cli/api/search packages/cli/api/build packages/cli/api/discover packages/cli/foundation/route packages/cli/foundation/doc-compiler/doc-loads.test.mjs packages/cli/clients/cli/commands/json-contract.test.mjs
  • tsc -p packages/cli/tsconfig.strict.json, tsc -p packages/cli/tsconfig.api-dts.json
  • pnpm check:cli-structure, pnpm check:changesets
  • Byte-parity replay of build and search, old vs new, on all real inputs

…r pattern

A small shared helper (foundation/route/route.mjs) defines two node kinds,
dispatcher and searcher, and runs a tree of them. build and search each get
a tree: a root dispatcher with one searcher, the command's current ranker.
search splits into an adapter that gathers candidates and a lexical ranker;
build reads the lexical ranker directly. No output changes.
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 21, 2026 5:19pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 20, 2026
@astracat-bot

astracat-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Oct 21, 2026, 5:48 PM UTC

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

40 of 486 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 20 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

search's lexical ranker splits by concern (synonyms, words, query reading,
compound names, title tier, query score, term score, domain priority,
results) and its adapter by domain (_gather-*.mjs). build's kit splits into
the kit, its start pick, and the page ranker's words, kind, and rank. The
route helper gains defineClassifier (a static word-weight classifier as a
dispatcher) and routeKit, so tree files type their nodes once. build's root
becomes a one-class classifier (every request still goes to main). search.mjs
re-exports only what build and the command handler read. No output changes.
search's root is now a classifier: the query's words vote for the domain it
wants (tree.weights.json), and the doc or template searcher takes the query
when the vote is sure enough; otherwise the main searcher keeps it. Each
searcher ranks entries by a weighted sum of plain signals: the lexical
ranker's score and rank, BM25 over each entry's name, docs text and a
source-built card, query-word coverage, whether the query holds the entry's
name, and the classifier's domain guess. All weights are static JSON beside
each searcher, read by the adapter. A response never holds more results than
the lexical ranker's. searchCore stays the lexical ranker; build reads it,
and the lexical ranking-rule tests run against it.
kit/signals.mjs computes what build weighs for a request once and
kit/answer.mjs turns those signals and a block list into the build.kit
response; buildKit is the two with build's own blocks. The main searcher
re-ranks the kit's blocks with checked-in word weights
(blocks/blocks.weights.json, read by the adapter into the tree's context),
keeping build's block count; the start, alternatives, and every other field
are unchanged.
A query that is an entry's whole name (the lexical ranker's exact gate:
the query equals a candidate's name or another name of it, or for anything
but a doc, its spaces removed) now gets the lexical answer unchanged: that
entry first, with no near siblings added beside it. The gate is one
exported predicate, namesWhole, used by both.

Among an integration's entries that the lexical ranker scored the same,
the lexical order stands: they have no cards, so the learned order would
only guess between them.
The whole build answer carries search results, which change whenever the
docs change, so its byte length and sha256 broke on unrelated doc edits.
The test now pins the blocks the picker names (and their count) for each
phrase, still compares every other field with build's own kit, and still
runs with the network and subprocesses blocked.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval needs a maintainer decision first: no current spec owns how astryx search ranks, so a maintainer has to approve or reject learned-weight ranking for search (including results no keyword rule matched and one result per doc topic) and name the record that will own it. Whatever that decision is, these need changes:

  • astryx search content --limit 400 now ranks the neutral and matcha themes, which match only through their descriptions, above keyword matches, which spec:AST-050 FR14 rules out.
  • Doc sections now fold into their topic (astryx search illustration returns 2 results while matchCount says 5, and dark mode --type doc loses both "Light/Dark Mode" sections), so search no longer returns the smallest part that answers (spec:AST-046 FR10).
  • CI's test-node job fails at this head, in the new whole-response hash in build/tree.test.mjs and in integrationDocs.test.mjs's troubleshoot integration check.
  • Ten search tests were moved from search() to searchCore(), and eight of them fail when pointed back at search(), so please keep them on the shipped path and update search()'s doc to whatever ranking is approved.
  • The change bundles a byte-identical refactor, search ranking and build's block picker in more than 15,000 changed lines, so please split it so each part can be reviewed on its own.

[Automated review]

Comment thread packages/cli/api/search/search.test.mjs Outdated
['content', ['matcha', 'neutral']],
]) {
const {results} = (await search(query, {cwd, limit: 400})).data;
const {results} = (await searchCore(query, {cwd, limit: 400})).data;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the spec:AST-050 FR14 check. Run against search(), which is what astryx search ships, it fails: for content, neutral sits 178th and matcha 181st, both matched only by their descriptions, above keyword matches down to 228th. Please keep this test on search() and make the learned ranking pass it.

Comment thread packages/cli/api/search/search.test.mjs Outdated
// combined token-sum score outranked Outline's single exact match,
// pushing it out of the results entirely at the default limit.
const r = await search('table of contents', {cwd});
const r = await searchCore('table of contents', {cwd});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Against search() this fails: Table (156) now outranks Outline (190, keyword "table of contents"), the regression issue #5239 fixed. searchCore() is now only build's input, so this test no longer covers astryx search.

Comment thread packages/cli/api/search/_features.mjs Outdated
for (const res of lexical.data.results) {
const k = entryOf(table, res);
const id = k === undefined ? '' : table.ids[k];
if (!own.has(id)) own.set(id, res);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A doc topic and all its sections share one id (entryId in _entries.mjs), so only the first lexical result per topic survives. astryx search illustration returns 2 results with matchCount: 5, and astryx search dark mode --type doc loses both "Light/Dark Mode" sections, against spec:AST-046 FR10 ("Search finds the smallest part that answers").

Comment thread packages/cli/api/search/_features.mjs Outdated
.map(k => {
const id = table.ids[k];
return (
own.get(id) ?? toResult(table.candidate[k], 0, 'related words', 0, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entries no keyword rule matched are returned with score: 0 and reason: "related words", while search.doc.mjs still says "name and keyword signals outrank incidental prose mentions, so an exact match always sorts first". Whichever ranking is approved, the doc and SearchResultEntry.score need to say how results are now ordered.

Comment thread packages/cli/api/build/tree.test.mjs Outdated
expect(answer.data.blocks.map(b => b.name)).toEqual(blocks);
const json = JSON.stringify(answer);
expect(Buffer.byteLength(json)).toBe(bytes);
expect(createHash('sha256').update(json).digest('hex')).toBe(sha);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pin hashes the whole build response, and it fails in CI's test-node (a different hash with the same byte length and block names) while passing locally. The block-name assertion above already pins the picker, so drop the whole-response hash and byte pins, or limit them to the fields the picker owns.

josephfarina and others added 3 commits October 20, 2026 17:30
Two cases where the learned order could only lose to the lexical one now
keep the lexical answer:

- A query that, read with dashes, underscores and slashes as spaces, is an
  entry's name, title or the last part of its route (a doc named
  add-a-theme typed as words, a template id) gets the lexical answer
  unchanged, like a whole-name query. The lexical ranker's own gate
  (namesWhole) is untouched.
- In a query of one or two words, the entries the lexical ranker put in its
  every-word top tier keep their lexical order among the places the
  learned order gave them. Longer queries keep the learned order: on
  synthetic queries the rule helps two-word queries and hurts longer ones.
Search answers only with what the lexical ranker matched, each result with
its own lexical score and reason, and matchCount is the lexical count. The
learned order now acts only inside runs of consecutive lexical matches in one
band and of one kind (doc or not): a whole-query name or keyword match, a
title or phrase match, a match on every word, a strong partial match, a name
or keyword match, and a prose-only match each stay above the bands below
them, and a doc never passes a component the lexical ranker placed above it,
or the reverse. Matches that scored the same move as one block in lexical
order, and an entry the query names leads its run.

A doc section is its own entry again, with its own result, as the lexical
ranker returns it.

Every pre-existing search test runs against search() unchanged; search.mjs
again exports the scoring helpers those tests import.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval needs a maintainer decision first: no current spec owns how astryx search orders its results, so a maintainer has to approve or reject ordering matches inside a score band with the learned weights and _cards.json, and name the record that will own that ordering. At this head search keeps main's matches, scores and reasons, the theme and doc-section rules (spec:AST-050 FR14, spec:AST-046 FR10) hold, and build's block picker fits spec:AST-048. Whatever the decision, please:

  • split the change into the output-preserving refactor, search ordering and build's block picker, since together they are over 15,000 changed lines;
  • commit or document how _cards.json and the weights files are produced, so the shipped order can be reproduced and refreshed when components change;
  • once the ordering is settled, update search()'s doc and the score description to say how results inside a match band are ordered.

[Automated review]

const read = file =>
JSON.parse(readFileSync(new URL(file, import.meta.url), 'utf8'));
searchData = {
cards: read('./_cards.json'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order astryx search ships depends on _cards.json and the four weights files read here, but nothing in the repository produces them. Please commit or document how they are generated, so the order can be reproduced and refreshed when Core adds a component: a component without a card gets no card signal (_entries.mjs lines 114–130).

…at the static files are

search()'s doc and the score field now say that results are ordered by score
band, and within a band by search's static ordering weights. The adapter says
what _cards.json and the weights files hold, that they never decide whether
an entry matches or its score, and how new Core items get theirs.
search()'s doc is itself a search result, so editing its text moves
answers. The ordering is described on the score field and in the adapter
instead.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval needs a maintainer decision first: no current spec owns how astryx search orders its results, so a maintainer has to approve or reject ordering matches with the learned weights and _cards.json, and name the record that will own that ordering. Search keeps main's matches, scores and reasons, and the theme and doc-section rules (spec:AST-050 FR14, spec:AST-046 FR10) hold. Whatever the decision, please:

  • split the change into the output-preserving refactor, search ordering and build's block picker, and commit or document how _cards.json and the weights files are produced;
  • key each run in _order.mjs on the match's own band, since the running maximum on line 63 lets weaker matches pass stronger ones (for account settings, 77-score doc sections now sit above two 158-score docs);
  • make the new score description and search()'s doc describe the order that ships, because a lower band can still sort above a higher one in search and a score: 0 block can lead build's blocks.

[Automated review]

Comment thread packages/cli/api/search/_order.mjs Outdated
/** @type {string} */
let last = '';
const items = all.map((res, i) => {
band = Math.max(band, bandOf(res.score ?? 0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This keeps a run's band at the running maximum, and the lexical merge puts lower-band entries ahead of higher-band docs (domain and doc priority), so later docs of several bands share one run and the learned order mixes them. For account settings, three 77-score doc sections now sit at 8–10 above authoring#config and building-blocks/configuration (158, every word matched). Keying the run on the match's own band (bandOf(res.score ?? 0)) keeps every move inside one band, as the file header promises.

Comment thread packages/cli/api/search/search.type.mjs Outdated
Comment on lines +20 to +22
* @property {number} score - How strongly the query matched this entry (higher is
* stronger). Results are ordered by score band; within a band, by search's
* static ordering weights, so a lower score never sorts above a higher band.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lower band does sort above a higher one: search's domain-priority merge does it (for account settings, templates at 93 and 85 sit above docs at 158), and build's blocks, typed as this entry, can lead with a score: 0 block (astryx build "calendar for booking appointments"). Please describe the order that ships rather than this guarantee.

Comment thread packages/cli/api/search/_adapter.mjs Outdated
Comment on lines +84 to +91
* These files are reviewed data, not computed at run time. `_cards.json` holds
* one card per Core component and hook (what it is, the words people type for
* it, its main props), written from that item's source. Each `*.weights.json`
* holds one number per signal the code computes. They only order matches inside
* a band of equal match strength: whether an entry matches, and its score,
* never depend on them. An entry without a card is ordered by its other
* signals; cards for new Core items and refreshed weights land as their own
* reviewed change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says what the files hold, but nothing in the repository produces them, so the next refresh cannot be reproduced or checked against anything. Please commit the generator, or its documented procedure and inputs, beside the data.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, the band, whole-name and block-order guarantees hold, and the earlier same-name-block finding is fixed, so what remains is scope plus two small fixes.

  • The output-preserving refactor, search's in-band order and build's block picker each land on their own and together exceed 15,000 changed lines, so please split them; the one-PR decision is noted, but it does not show that the parts depend on each other.
  • spec:AST-083 writes its requirements and decisions as FR1: and DEC-1:, while the template's FR1 — form is the one extractKnowledgeClaims reads, so it finds none of the record's claims today.
  • search.doc.mjs says domain priority can lift a weaker template or component above a stronger doc, but hooks and themes move the same way (for dark mode, useImageMode and useTheme sit above the Light/Dark Mode sections), so naming every non-doc kind would make it exact.

[Automated review]

Comment thread docs/specs/AST-083-result-order/spec.md Outdated

## Requirements

- **FR1: search answers with the lexical matches.** Every result is an entry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system-spec template and every record on main write - **FR1 — …** and ### DEC-1 — …; extractKnowledgeClaims in scripts/check-knowledge.mjs matches only that form, so it finds 0 claims in this record (32 in spec:AST-048). Using — after each FR and DEC id changes no requirement text.

Comment thread packages/cli/api/search/search.doc.mjs Outdated
Comment on lines +21 to +22
'results keep the lexical order, whose domain priority can put a weaker ' +
'template or component above a stronger doc, and a query that is an entry\'s exact name answers ' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooks and themes move the same way: for astryx search "dark mode", the hooks useImageMode and useTheme (159) sit above the "Light/Dark Mode" sections (190). "a weaker component, hook, template or theme", or the score description's "a weaker non-doc match", would be exact.

…doc names every non-doc kind

Main's single-install change edited search's and build's Core lookup, which
this branch splits into files: search/_adapter.mjs now resolves Core with
requireSearchCoreDir, an open search without Core answers from the rest with
meta.partial, a theme result outside a project points at `theme eject`, and
build's kit asks for Core through requireBuildCoreDir. search()'s doc keeps
main's global-mode, cwd, return and error text beside the ordering text.

spec:AST-083 writes its claims as 'FR1 —' and 'DEC-1 —', the form the
knowledge tools read. search()'s doc names every kind (component, hook,
template, theme) that domain priority can lift above a stronger doc.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 21, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec c5c7ea9

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 21, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, and the match, band, whole-name and block-order guarantees hold on the outputs checked, so what remains is scope and two fixes.

  • The output-preserving refactor, search's in-band order and build's block picker land in sequence and together exceed 15,000 changed lines, so please split them; the one-PR decision is noted, but it does not show the parts cannot land apart.
  • Equal-score matches move as one block placed by their best member (packages/cli/api/search/_order.mjs lines 84–96), so astryx search "editable date" leads with Badge (58) above DateTimeInput (78) and Timestamp (98), which both the lexical ranker and the weights rank higher; placing each match by its own learned position would fix it.
  • packages/cli/api/search/ORDERING.md says search ordering is owned there and its refresh steps leave out spec:AST-083 FR6, so please point it at the record and add that step.

[Automated review]

Comment on lines +84 to +96
/** @type {Map<string, number>} */
const block = new Map();
const blockOf = (/** @type {Item} */ it) => `${it.band}:${it.res.score}`;
for (const it of items) {
const at = named(it) ? -1 : it.learned;
block.set(blockOf(it), Math.min(block.get(blockOf(it)) ?? Infinity, at));
}
let ranked = [...items].sort(
(x, y) =>
x.band - y.band ||
(block.get(blockOf(x)) ?? 0) - (block.get(blockOf(y)) ?? 0) ||
x.i - y.i,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equal-score matches move as one block placed at its best member's learned position, so members the searcher ranks low ride along above higher-scored matches it ranks higher. For editable date the main searcher ranks DateInput first and Badge 9th, yet the answer leads with Badge (58) above DateTimeInput (78) and Timestamp (98), which the lexical ranker and the weights both place higher. Placing each match by its own learned position inside its run (lexical order only between equal positions, keeping the named-entry lead) avoids this; the change would need the spec:AST-083 FR6 measurement.

Comment thread packages/cli/api/search/ORDERING.md Outdated

## Rule

Search ordering is owned here. Inside one score band, a searcher's static weights decide the order. Matches never cross bands or kinds. There is no model runtime: every number is a plain static value read at load time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-083 owns the order and the rule for changing it, and its FR6 lets a refresh ship only when the held-out, fresh and synthetic sets show no row worse; the Refreshing list below leaves that step out. Pointing here to the record and adding the FR6 step would keep a refresh from skipping it.

…ints at AST-083

A block of equal-score matches is placed in its run by the learned position
of its first match rather than its best member's, so one strong member no
longer lifts a whole block of weak ones (`editable date` now leads with
DateTimeInput and Timestamp). ORDERING.md says spec:AST-083 owns the order
and adds the FR6 measurement step to its refresh rules.
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 8cf2498

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, and search keeps main's matches, scores and counts while build keeps everything but its block order, so what remains is scope and one ordering fix.

  • The output-preserving refactor with the route helper, search's in-band order and build's block picker land in sequence and together exceed 15,000 changed lines, so please split them; the one-PR decision is noted, but it does not show the parts cannot land apart.
  • Placing each equal-score block by its first match (packages/cli/api/search/_order.mjs lines 88–92) lets whichever name sorts first decide where the whole block goes, so astryx search toggle now shows ToggleButton 16th instead of 7th although the weights rank it first; ordering each match by its own learned position would fix it.

[Automated review]

for (const it of items) {
const at = named(it) ? -1 : it.learned;
const k = blockOf(it);
if (!block.has(k) || at === -1) block.set(k, at);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block's place now comes from its first match, and the first match is whichever name sorts first in the lexical ranker's domain order (byScore in _lexical.mjs), so the weights of every other member never count. For astryx search toggle the main searcher ranks ToggleButton (90, keyword "toggle") first, but its 90-point block starts with CheckboxInput (ranked 8th), so the 70-point ToggleButtonGroup block (2nd, carrying eight blocks ranked 11th–23rd) goes above it and ToggleButton falls from 7th on main to 16th. For astryx search Tabs, TabList (90, ranked 2nd) falls from 3rd to 14th below ten 60-point page templates riding on TabMenu's block. Ordering each match by its own learned position inside its run (lexical order only between equal positions, plus the named-entry lead) would avoid both, and a toggle case in _order.test.mjs would pin it.

Moving each tied match on its own breaks search's existing rules for tied
matches (`file required` leads with Field, `ci` with the integration check)
and grows answers, so ties move together, and where the block lands is
measured as spec:AST-083 FR6 requires. Comments and ORDERING.md only; no
answer changes.
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 040a290

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, and search keeps main's matches, scores and counts while build keeps everything but its block order, so what remains is scope and two small corrections.

  • The output-preserving refactor with the route helper, search's in-band order and build's block picker land in sequence and together change about 15,500 lines, so please land them as that stack; the one-PR decision is noted, but it does not show the parts cannot land apart.
  • The changeset tags an intentional change to search()'s documented ranking as [fix], which spec:AST-017 FR5 and FR7 classify as [feat].
  • packages/cli/README.md still says name and keyword matches outrank incidental prose mentions, which no longer holds inside a band (for example astryx search "empty state with an action").

[Automated review]

Comment thread .changeset/build-search-routing.md Outdated
'@astryxdesign/cli': patch
---

[fix] `astryx search` orders the matches inside each score band so the entry you are after comes first more often; every result keeps its match score and reason, and a query that is an entry's exact name still answers with that entry first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change intentionally replaces search()'s documented order ("name and keyword signals outrank incidental prose mentions" becomes "a description match can lead a keyword match in the same band"), and spec:AST-017 FR5 says such a proposal "is not a fix"; FR7 tags compatible capabilities [feat]. Please retag this [feat] (patch stays the tier) and say what the old and new order are.

The CLI README says matches are scored by keyword and fuzzy matching, keep
the order of their score bands, and are ordered inside a band by fixed
weights. The changeset is [feat]: search's documented order changes on
purpose.
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 1894f2c

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, the changeset is now [feat], and search keeps main's matches, scores and counts while build keeps everything but its block order, so what remains is scope and one README sentence.

  • The output-preserving refactor with the route helper, search's in-band order and build's block picker land in sequence and together change about 15,550 lines, so please land them as that stack; the one-PR decision is noted, but it does not show the parts cannot land apart.
  • packages/cli/README.md now says results keep the order of their score bands, but domain priority still lists weaker templates above stronger docs (astryx search "account settings" puts login at 93 above two 158-score docs), so please reuse the wording from search()'s doc.

[Automated review]

Comment thread packages/cli/README.md Outdated
Comment on lines +54 to +55
relevance: keyword and fuzzy matching (typos included) score each match, results
keep the order of their score bands, and inside a band fixed weights decide the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads as if a higher band always comes first, but between bands the lexical order, with its domain priority, still holds: astryx search "account settings" lists login (93) and login-card, login-split and login-sso (85) above authoring#config and cli/integrations/building-blocks/configuration (158). search()'s doc already words it exactly; something like "between score bands results keep the lexical order, whose domain priority can put a weaker component, hook, template, or theme above a stronger doc" would fix this sentence.

Between score bands results keep the lexical order, whose domain priority can
put a weaker component, hook, template, or theme above a stronger doc.
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 3c823d9

astracat-bot[bot]
astracat-bot Bot previously requested changes Oct 21, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are requested before approval: spec:AST-083 and the new spec:AST-048 FR8 sentence are approved for this head, and on the queries checked search keeps today's matches, scores, reasons and counts while build changes only its block order, so what remains is scope. The output-preserving route helper and file split, search's in-band order, and build's block picker land in sequence and together change 15,554 lines; please land them as that stack, so each part can be reviewed on its own. The earlier wording, changeset and ordering findings are fixed on this head.

[Automated review]

@josephfarina
josephfarina dismissed astracat-bot[bot]’s stale review October 21, 2026 18:12

Maintainer decision: one PR (see the decision comment). Every other review item is resolved on 3c823d9.

@josephfarina
josephfarina merged commit b7e33f1 into main Oct 21, 2026
58 of 60 checks passed
@github-actions
github-actions Bot deleted the josephfarina/build-search-routing branch October 22, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 3c823d9b Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant