import type { Spelling, Tool, ToolInvocation, Tree } from '@variance-authority/mcp/tools'; import type { Help } from '@variance-authority/package/help'; import type { SearchIndex } from '../search-index.js'; import type { SearchQuestion } from './search-matches.js'; import { type ImportingOf } from './published-match.js'; /** * `docs_search` — the name for a thing somebody can only describe. * * Substring, case-insensitive, over the name and over what was written about * it; and several words, over the words a name is written in, each word * matching one that starts with it or shares its stem. A match there is a fact * about the text, so it is reported first, ordered first by where it * was found — the whole name, as written and then in another case, part of the * name, the doc's opening paragraph, the rest of the doc — and then by who * imports it: a name that is the word is what was asked for, a name holding it * is that thing, and a doc saying it three paragraphs down only mentions it. * * ## Two halves, because most code is not published * * The published surface is a few hundred names. The repository exports several * thousand, and the extra ones are not private — they are what one file in a * package takes from another, and they are where the answer lives whenever the * thing being looked for was never something to publish. A search that stopped * at the surface would answer *nothing matched* for most of the code in the * checkout, which is the same failure as having no search at all. * * So the answer has two sections and says which is which. A published name is * API: it carries a specifier, a doc comment and a count of who imports it, and * it can be handed straight to `docs_symbol`. An exported one carries a file and * a line and nothing else, because nothing else was read for it — reading three * thousand declarations to rank them would cost the whole repository on every * question, and the file and the line are enough to go and look. * * Published names come first and are never repeated below, so a name that is * both is reported once, as the API it is. * * ## A third section, which may only add * * Substring answers the word you typed and nothing else. It cannot answer a * word one character off the name, and it cannot answer two words that are * both written about a name but not written next to each other — `read span` * matches no text anywhere, and the declaration it was asking for says both. * * Those two cases are what the loose pass is for, and they are the whole of * what it is for. It is not a better ranking of the sections above: it never * scores, reorders, promotes, demotes or removes anything they answered, and it * cannot be reached by a name they already returned. It appends names they did * not, under a heading that says how they were matched, and when it has nothing * to append it prints nothing at all. So an answer that used to be clean stays * clean, and the line above what it appends still says the substring matched * nothing — as a miss of the text typed, since *nothing* over a list of names * would read as a miss of the code. * * The order inside it is the order the sections above use, by consumers and * then by name. The index decides membership; it is never allowed to decide * position, because a caller who can see why a name is in a list can check it, * and a caller reading a rank has to trust it. * * ## A description, stemmed the way a package's is * * An agent that cannot name the thing describes it, and a description holds * words the name does not: `which tests entered a file`. Beside the loose pass * runs the reading the installed packages already get — the question cut into * stems, stopwords dropped — with one difference: a package answers when it * holds half of them, and the repository's own name when it holds any. So the * repository's own names answer before any package that says the same * words, and a name holding one word of three is answered rather than reported * as nothing. A file answers beside them, by its own name and the doc it opens with, * since what a file is for is said once at its top and by no one declaration * in it. Its order is counts, written next to each row as the words it holds: * a caller can check `[holds: file, tests]`, and could not check a score. * Between two that hold as many, the one whose name holds more of them comes * first, then the one whose doc writes more of the question's adjacent word * pairs adjacent. Every word one of them holds is held by a row shown, so a name * holding the one rare word is shown however many holding a common one sort * before it. It prints first, so a name holding at least half the stems * is not offered again by the loose pass. A name holding fewer is the loose * pass's when that pass reaches it, by every word, so on three words or more a * long list of names holding one stem cannot sort it past the rows shown. * * ## Where the substring stops being enough * * On a repository of a few thousand names it is. On a large one it is not, and * no ranking fixes that: `order` really is written into four hundred names, the * reader wanted the nine in one service, and the text cannot tell those apart * because the text is the same. What separates them is a fact the caller holds * and the query never carried — which part of the repository they are standing * in — so `from` and `to` take it as a path and the closure decides what may be * answered. Published names are admitted only when a file in that closure * imports them, then ranked by the number of importing files there. Internal * exports have no import-site rows, so their declaring file remains the fact * that admits them. See [`area.ts`](./area.ts): a boundary, not a preference. * * The loose pass is inside that boundary and not beside it. It is built from * the files the area already allows, so a widening can reach a name the caller * did not type and can never reach a file they ruled out. */ /** * The question `search` is asked by `input`, as its schema accepted it; a * `limit` that is no whole number of rows is refused as `spell` names it. */ export declare function searchQuestionOf(input: Readonly>, spell?: Spelling): SearchQuestion; /** The search over an opened index — what `docs_search` answers, without the Help value; `spell` names `limit` in its cuts. */ export declare function answerSearch(index: SearchIndex, input: Readonly>, tree?: Tree, root?: string, importing?: ImportingOf, spell?: Spelling): string; /** * The search, as a tool: a `query` and an optional start point, answered in * two halves — published names first, then the ones a file exports for its * neighbours — as the header above sets out. * * The word is required and the place is not, never the other way round. A * place without a word is not a question, it is a request to be shown * everything in reach — and in reach of a folder on a large repository is * fifty thousand files' worth of names. Nothing here answers without a * question. */ export declare const search: Tool; /** * The files of the rows `run` prints, and the entries and barrels that make a * row published, which the count of that row walked already. `search.files` is * every match, a set another question crosses; a row past the cap is no part of * this answer, so the count printed above the rows stays the generation's. A * recorded case is none of them: it rests on the last run, not the generation, * so a test file gone since then says nothing about the generation's age. */ export declare function printedFiles(help: Help, input: Readonly>, invocation?: ToolInvocation): ReadonlySet; //# sourceMappingURL=search.d.ts.map