Repository navigation
refactor(cli): build and search answer through one shared dispatcher/searcher pattern - #7752
Conversation
…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.
|
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 Regression40 of 486 shot(s) changed. A change here is a question, not a failure: check whether the after is the
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.
There was a problem hiding this comment.
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 400now ranks theneutralandmatchathemes, which match only through their descriptions, above keyword matches, whichspec:AST-050FR14 rules out.- Doc sections now fold into their topic (
astryx search illustrationreturns 2 results whilematchCountsays 5, anddark mode --type docloses both "Light/Dark Mode" sections), so search no longer returns the smallest part that answers (spec:AST-046FR10). - CI's
test-nodejob fails at this head, in the new whole-response hash inbuild/tree.test.mjsand inintegrationDocs.test.mjs'stroubleshoot integrationcheck. - Ten search tests were moved from
search()tosearchCore(), and eight of them fail when pointed back atsearch(), so please keep them on the shipped path and updatesearch()'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]
| ['content', ['matcha', 'neutral']], | ||
| ]) { | ||
| const {results} = (await search(query, {cwd, limit: 400})).data; | ||
| const {results} = (await searchCore(query, {cwd, limit: 400})).data; |
There was a problem hiding this comment.
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.
| // 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}); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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").
| .map(k => { | ||
| const id = table.ids[k]; | ||
| return ( | ||
| own.get(id) ?? toResult(table.candidate[k], 0, 'related words', 0, 0) |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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.jsonand 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 thescoredescription 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'), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.jsonand the weights files are produced; - key each run in
_order.mjson the match's own band, since the running maximum on line 63 lets weaker matches pass stronger ones (foraccount settings, 77-score doc sections now sit above two 158-score docs); - make the new
scoredescription andsearch()'s doc describe the order that ships, because a lower band can still sort above a higher one in search and ascore: 0block can lead build's blocks.
[Automated review]
| /** @type {string} */ | ||
| let last = ''; | ||
| const items = all.map((res, i) => { | ||
| band = Math.max(band, bandOf(res.score ?? 0)); |
There was a problem hiding this comment.
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.
| * @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. |
There was a problem hiding this comment.
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.
| * 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-083writes its requirements and decisions asFR1:andDEC-1:, while the template'sFR1 —form is the oneextractKnowledgeClaimsreads, so it finds none of the record's claims today.search.doc.mjssays domain priority can lift a weaker template or component above a stronger doc, but hooks and themes move the same way (fordark mode,useImageModeanduseThemesit above the Light/Dark Mode sections), so naming every non-doc kind would make it exact.
[Automated review]
|
|
||
| ## Requirements | ||
|
|
||
| - **FR1: search answers with the lexical matches.** Every result is an entry |
There was a problem hiding this comment.
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.
| '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 ' + |
There was a problem hiding this comment.
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.
|
/approve-spec c5c7ea9 |
There was a problem hiding this comment.
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.mjslines 84–96), soastryx search "editable date"leads withBadge(58) aboveDateTimeInput(78) andTimestamp(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.mdsays search ordering is owned there and its refresh steps leave outspec:AST-083FR6, so please point it at the record and add that step.
[Automated review]
| /** @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, | ||
| ); |
There was a problem hiding this comment.
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.
|
|
||
| ## 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. |
There was a problem hiding this comment.
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.
|
/approve-spec 8cf2498 |
There was a problem hiding this comment.
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.mjslines 88–92) lets whichever name sorts first decide where the whole block goes, soastryx search togglenow showsToggleButton16th 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); |
There was a problem hiding this comment.
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.
|
/approve-spec 040a290 |
There was a problem hiding this comment.
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], whichspec:AST-017FR5 and FR7 classify as[feat]. packages/cli/README.mdstill says name and keyword matches outrank incidental prose mentions, which no longer holds inside a band (for exampleastryx search "empty state with an action").
[Automated review]
| '@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. |
There was a problem hiding this comment.
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.
|
/approve-spec 1894f2c |
There was a problem hiding this comment.
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.mdnow says results keep the order of their score bands, but domain priority still lists weaker templates above stronger docs (astryx search "account settings"putsloginat 93 above two 158-score docs), so please reuse the wording fromsearch()'s doc.
[Automated review]
| 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 |
There was a problem hiding this comment.
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.
|
/approve-spec 3c823d9 |
There was a problem hiding this comment.
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]
Maintainer decision: one PR (see the decision comment). Every other review item is resolved on 3c823d9.
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.
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.search()and passes unchanged.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:
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):packages/cli/api/search/ORDERING.mddescribes the data files;spec:AST-048keeps owning which blocks build lists and now delegates their order to this record (one sentence in its FR8).Writing rubric results
spec:AST-048FR8 gains one present-tense sentence delegating block order; R1–R6: none.Primary intent
astryx buildandastryx searchnow 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: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
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):defineSearcheranddefineDispatcherdefine the two node kinds, a typed union onkind.defineClassifieris 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.defineTreechecks for duplicate ids, missing children or fallbacks, a non-searcher fallback, and cycles.runTreetries 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 optionaltuning(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.routeKitlets 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 tomain, the kit ranker.build()validates, then runs the tree.kit/kit.mjs(the kit),kit/start.mjs(the start pick), and the page ranker'skit/words.mjs,kit/kind.mjsandkit/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._gather-components,_gather-hooks,_gather-docs,_gather-templates, with_module-docand_doc-texthelpers)._synonyms,_words,_query,_compound,_titles,_score(a whole query),_candidate-score(one term),_priority,_result, and_lexical, which merges and orders.search.mjsre-exports only what build and the command handler read.Structure check (
scripts/check-cli-structure.mjs):search/search.mjsleaves the environment-import allowlist. The check fails on an allowlist entry that no longer applies, andsearch.mjsno longer reads the disk itself.Search ordering (
api/search/):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; otherwisemainkeeps it.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._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.mjsand 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._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._adapter.mjs. They are deterministic, and there is no model runtime and no network access.Build blocks (fourth commit,
api/build/):kit/signals.mjs(what search and the page ranker found),kit/answer.mjs(the response), andkit/kit.mjs.blocks/blocks.mjsre-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.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):
buildrequest: 13,472 of 13,472;searchquery: 8,231 of 8,231, including the 37 that error, which error the same way.Scope
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.mjstsc -p packages/cli/tsconfig.strict.json,tsc -p packages/cli/tsconfig.api-dts.jsonpnpm check:cli-structure,pnpm check:changesets