<p align="center"><img src="https://variance-authority.dev/mark.svg" alt="Variance Authority mark" width="72"></p>

# @variance-authority/help

> Find the public name, signature, documentation, consumers and import sites of an exported workspace symbol, over MCP.

Part of [Variance Authority](https://variance-authority.dev).
Point your coding agent at [`llms.txt`](https://variance-authority.dev/llms.txt).

## What this is for

Install this if you maintain a repository and want a person or a
coding agent to be able to ask what a name in it is, where it is declared, who
imports it, and where the repository already writes it.

Use `rg` when the answer is text outside the source — a YAML, JSON, Markdown or
shell file no parsed file imports — beside this package rather than after it,
and `git grep <tree>` when the answer is an arbitrary string in committed
source. Use this package when the answer depends on parsed names or relations: which
export matches a description, which exact signature it has, who imports it,
which names are used by the files reachable from one path, or which of those
files hold a string. `search --from` and
`search --to` remove names outside that import closure; they do not merely put
nearby text first.

Search and traversal have separate jobs. The query text finds candidate names.
`from` walks from a known path along its resolved imports; `to` walks in the
other direction to the files that depend on a known path. Carry the path your
editor, ticket or stack trace already supplied into the first search, then ask
`symbol` and `uses` about the remaining name.

The generation contains a compact bidirectional module graph beside the names;
there is no graph database service to deploy. This graph records module and
asset relations, not function calls. `uses` reports where a name is imported,
not where code calls it at runtime.

It answers from a dated generation published through a [source
index](https://variance-authority.dev/docs/source-index). Most of its questions are about exported
names; the rest run ripgrep over the files a path imports, cross whole sets of
files — what a path reaches, who imports or declares a name — start from the words
of a task before you know any name, list the third-party packages a location
can already use, map the code the recorded tests ran around one file, and list
the test files the latest recorded run spent longest in. It reads JavaScript and TypeScript, Python, Rust, Java, Kotlin and Swift.
It does not yet read framework file formats or bundler-only aliases: not a Vue
or Svelte single-file component, not the files an Angular component names in
`templateUrl` and `styleUrls`, and not an alias declared only in a bundler's
configuration, where one declared as `paths` in a `tsconfig` resolves. [The
source scan's limits](https://variance-authority.dev/docs/source#limits) say
what each leaves out.
The two verbs that answer for a *published* specifier read a `package.json`, so
in a repository with none they answer out of what the files themselves export.
The repository itself does not have to be built and no API site is required.
Point it at any checkout with `--root`.

Producing a generation scans the checkout; answering one does not. A question
on the command line answers from the generation `variance index` last
published, at any age, and does nothing else: no Git status, no look at the
files an answer rests on, no index written. So after you edit, run `variance
index`, then ask. Every answer and refusal says when its generation was produced
and that the checkout was not compared with it, and with no generation the
question refuses in one line that names `variance index`. The server keeps its
own expiry, below. The detailed cost model, including why Git's packed objects
beat opening hundreds of thousands of small files, is in [find code through the workspace
index](https://variance-authority.dev/agents/workspace-api#choose-the-cheapest-entrance).

It answers two different questions about a name. What the name is supposed to be
comes off the declaration — its signature and the block comment above it. How
the name enters files here comes off the import sites, and that is the
answer a stale doc comment cannot spoil.

This package has nothing to do with taking or comparing screenshots. If you came
here looking for the visual regression runner, that is
[`@variance-authority/cli`](https://variance-authority.dev/reference/packages/cli);
nothing on this page is a step in that workflow.

## Requirements

Node 22.15 or newer. The package is ESM-only (`"type": "module"`), so a CommonJS
project loads it through `import()`. There are no peer dependencies and no
configuration file. It works on a checkout that is not a git repository, is not
a workspace, and has no `package.json` at all — with no manifest there is
nothing published, so every answer comes from what the source exports.

## Ask one question

The binary is `variance-authority-help`. Installed as a devDependency, it runs
through your package manager:

```bash
npm install --save-dev @variance-authority/help
variance-authority-help search viewport
variance-authority-help search viewport --from packages/app/
```

The verbs each take the same arguments as the tool of the same name below:
`packages`, `entrypoint`, `symbol`, `uses`, `search`, `grep`, `discover`,
`intersection`, `orient`, `slowest-tests`, `retried-tests`, `not-run`, `journey-map`, `test-composition`, `containment`, `stack`, `gaps`. An entrypoint is
one import specifier a package's `exports` map opens — `@scope/pkg` and
`@scope/pkg/deep` are two of them. Add `--root <dir>` when you are not standing
in the repository you are asking about.

An answer that points you at another question names it the way the binary you
asked takes it — `--limit`, `variance-authority-help symbol` — where the same
answer over MCP says `limit` and `docs_symbol`.

The same questions are on `variance ask` wherever
[`@variance-authority/cli`](https://variance-authority.dev/reference/packages/cli)
is installed — `variance ask search --query viewport` — and, with a
`variance.config.json`, the same tools are on `variance serve`, beside the ones
about a run. A workspace that runs the visual suite needs nothing from this
package over either transport. This package is for the workspace that does not
run one.

### What you get

Text, on stdout. `search` answers in two sections. The first holds the names a
manifest publishes, ranked by where they hold your words: the name, then the
doc's first paragraph, then the rest of it. Each is labelled with the places
that import it and the packages those places sit in, counted as `uses` counts
them, and the rows shown are ordered by those packages, then those places. The
second holds the names the source exports without publishing. A third follows
when your words match a name they do not contain.

What `search` prints is candidates, not every match; `git grep -i <word>` prints
every tracked line that writes your word.

Run against this repository, abridged to the first few lines of each section:

```
16 published matches for `viewport`

@variance-authority/core/format · Viewport [interface] imported in 68 places in 18 packages — UNDOCUMENTED
@variance-authority/storybook · StoryViewport [interface] imported in 1 place in 1 package — A per-story viewport override.
@variance-authority/storybook · declarationOf [function] imported in 2 places in 2 packages — One story's `parameters.variance`, checked against the run's viewport.
@variance-authority/core/format · documentDigest [function] imported in 33 places in 13 packages — Content address of a document: *what is to be painted*.
@variance-authority/core/format · PageRegion [interface] imported in 16 places in 6 packages — The timezone a page's clock reads in and the language it formats for, as Playwright names them.

22 more names are exported somewhere in the repository without being published:

viewport — site · site/app/layout.tsx:48
CORPUS_VIEWPORT — @variance-authority/example-kitchen-sink · examples/kitchen-sink/src/jsdom-profile.ts:21
parseViewport — @variance-authority/cli · packages/cli/src/config-sections.ts:194
```

A published name is API and comes with the specifier you would import it from.
An exported name shows a file and a line, because nothing else was read for it.

`symbol` answers with the one thing you asked about, in full.
Run `variance-authority-help symbol Viewport`:

```
Viewport [interface]
import { Viewport } from '@variance-authority/core/format';
declared at packages/core/src/format/environment.ts:93
used by 17 packages: @variance-authority/example-kitchen-sink, @variance-authority/example-todomvc, @variance-authority/cli, @variance-authority/dom, @variance-authority/observe, @variance-authority/playwright-test, @variance-authority/playwright, @variance-authority/presentation, @variance-authority/raster, @variance-authority/remote, @variance-authority/route-collector, @variance-authority/session, and 5 more — 67 imports by published path

interface Viewport

Nothing is written above this declaration.

Members:
packages/core/src/format/environment.ts:94 — readonly width: number;
packages/core/src/format/environment.ts:95 — readonly height: number;
packages/core/src/format/environment.ts:96 — readonly deviceScaleFactor: number;
packages/core/src/format/environment.ts:98 — readonly colorScheme: 'light' | 'dark';

`variance-authority-help uses` names the 68 places that import this: 67 from other packages and 1 inside @variance-authority/core, nearest to a file you name first.
```

## The questions

Ranking counts the other packages that import the name by a published path: a
frequently imported name leads; a name nothing outside its own package imports
stays available without taking space from the first answer. A `search` row is
labelled with every place that imports it and the packages those places sit in,
and the rows on a page are reordered by that label.

| verb / tool | takes | answers |
|---|---|---|
| `packages` / `docs_packages` | nothing | every import specifier the repository publishes, with how heavily used and how well documented each is, for each package that declares no entry, how many of its names and files other packages import by path, and for each package that declares one, how many imports reach past it; then the `entrypoint --package` questions for the most-imported specifier and the first row of each count |
| `entrypoint` / `docs_entrypoint` | a package name, optionally a subpath | the names that one specifier opens, most-imported first. Asked by a package's name, also the imports that reach past its entry, or, for a package that declares no entry, the imports of its files by path, counted one row per file; asked by one of those files' specifiers, how many files import each name through it; for a package that opens only subpaths, the specifiers it opens in place of the names. Ends with the narrower questions: the first row's specifier, and `uses` on the name the most files take through it |
| `symbol` / `docs_symbol` | a name, or several, each answered in turn | the import line, the place, the signature, the doc — or the README passage that names it — and who imports it, then the members of an interface, a type alias or a class, one line each; for a name a file exports and no entry publishes, the file, the line and how many imports reach that file, directly or through a file that passes it on, and the declaration an `export … from` passes on; the files that import it under another name with `as`. For a name an import binds with `as`, that import and the original it names, followed to its declaration and its members the same way |
| `uses` / `docs_uses` | a name, optionally the file you are in | every place that imports it, stories and tests listed apart, nearest first: an import from another package by its published path, and every import the source index resolved to the file that declares it, or to a file that passes it on with `export … from`, within its own package as well, each marked `(as x)` where it knows the name as `x`. For a name a file exports and no entry publishes, the imports the source index resolved, and the declaration an `export … from` passes on. Then the lines of a TypeScript, JavaScript or Rust file that use a name it declares, by its scope rules. Twelve rows of each list, unless `limit` says more |
| `search` / `docs_search` | a string, optionally a path to answer from | candidates, not every match: published names whose name or doc contains it, or whose name is written in its words, then the names exported without being published, matched by the same rule, then the names and files holding most of its words by stem, the rarer words counting for more, and the names only a looser reading finds |
| `grep` / `docs_grep` | a pattern, and a path to answer from | the lines ripgrep matches in the files that path imports, or that import it, nearest first |
| `discover` / `docs_discover` | two or more sets of files: what paths reach (`from`) or what reaches them (`to`, also `file#name` for what rests on one name, starting at its imports), who imports a `module#name`, who declares a name matching a pattern, a path pattern, each also as `except…` to take it out; optionally a `text` pattern | the files in every set, each read whole, nearest the paths first, with the line that put each file in each set, and for `to` one shortest chain of imports, each step that is not a plain import marked; `text` keeps the files with a line ripgrep matches |
| `intersection` / `docs_intersection` | two or more whole questions whose answers are sets of files — `symbol`, `uses`, `search`, `grep`, `discover` — each with its own input; on a shell, each one quoted word | the files every question answers, each question read whole, with the lines that put each file in each question |
| `orient` / `docs_orient` | nothing, an area id, or files you already have as paths from the root | with no files, the code map `variance index` keeps beside the source index: areas of packages with their size, dependency layers, most-imported packages and the areas they import from. With files, what each file declares at its top level with its line, a class's or interface's members under it, the package each file is in with the names it imports from other packages and the names they import from it, the recorded test cases that ran each file, the functions in other files that call into it and those it calls, with how each call is known, the [package flows](https://variance-authority.dev/docs/orientation#choose-the-entrance-from-what-you-have) those cases take through it, and the narrower questions to ask next; `path:line` narrows the calls to the function holding that line |
| `slowest-tests` / `docs_slowest_tests` | optionally test paths to keep (`from`), code paths the tests must have run (`to`), a time the cases ran at least (`over`), and how many rows to list | the record it read, whose run, at which commit and how old; the cases closest to their limit, each as its run and its limit; then the test files and cases that run spent longest in, a file by what running it cost before and during its cases, and how many recorded files and cases have no duration or limit; with `over`, cases alone |
| `retried-tests` / `docs_retried_tests` | optionally how many cases to list (`limit`) | the record it read, whose run, at which commit and how old; the cases the runner retried whose attempts ended differently, each with its limit and every attempt: how it ended as its runner said and, where the runner says them, how long it ran and, for one that did not pass, the frame inside the checkout and the message; how many retried cases ended the same way every attempt; a record that kept no attempts says so, which is not that no case was retried |
| `not-run` / `docs_not_run` | nothing | the record it read, whose run, at which commit and how old; each check a case declared with the `variance:check` annotation that an attempt passed without executing as a step, with the file and line declaring the case, its project, and the attempt when it ran more than once; how many declared checks were entered; the scope the run covered. A run stopped before its runner ended it is incomplete and names no check; a record that kept no checks says so, which is not that every check ran |
| `journey-map` / `docs_journey_map` | one file, optionally words of the task | how many recorded tests entered that file, the paths through each of its functions, then the code beyond it those tests entered, nearest first |
| `test-composition` / `docs_test_composition` | a test file, optionally the test's name or a word of it | the smaller tests whose recorded regions sit inside this test's (its pieces), the larger tests holding it (its wholes), and the regions no piece entered: modules only it enters, and paths through a piece's modules only it takes. Regions more than half the suite entered are counted apart as structure. [Ask what one test is made of](https://variance-authority.dev/docs/own-fewer-tests#ask-what-one-test-is-made-of) |
| `containment` / `docs_containment` | optionally the first day counted (`after`), two weeks ago when left out | from `git log` and the workspace list: the share of source-changing commits that touched one package, that edited a test in another package, among commits that did and did not edit their own tests, and that edited a test in a test-only tree, each as a count over its denominator, with what was left out counted by reason |
| `stack` / `docs_stack` | a file or folder | every third-party package that location can already use: its role, how the owning manifest declares it, its version, how many times the code imports it, and each agent skill it ships in `skills/<name>/SKILL.md`, with the file to read. [Use the packages your project already installed](https://variance-authority.dev/docs/tech-stack) |
| `gaps` / `docs_gaps` | nothing | names other packages import that carry no documentation |

`packages` needs no argument and returns one row per specifier, then an
indented row per package other packages import by path: a file inside the
package rather than an entry its manifest publishes. It counts and lists no
import site. Either row goes to `entrypoint --package` exactly as printed: a
specifier lists the names it opens, and a package name counts the import sites
behind its count per file. Each file's specifier is the question that counts
its imports per name, and `uses` lists the sites of one name.

Every answer ends with the UTC time of the generation it used. A generation is
manifests and module records, not a compilation, and the module records come
from the source index
[`@variance-authority/sense`](https://variance-authority.dev/reference/packages/sense)
keeps. A question on the command line reads that generation at any age. The
server reuses a generation less than one hour old, and after that the next call
refreshes it; start it with `--just-answer` when a watcher or CI step owns
production and a call must do no freshness work. On `variance ask`,
`--changed-file` belongs to the producer side: it supplies an authoritative
newline-delimited file of scan-root-relative changed paths, and is the one way a
question has the index updated. An empty file states that nothing changed. A
listed file gives its names at the lines it holds now. With no generation to
refresh, the read is whole and the list is not used.

### Say where you are standing

On a few thousand names a substring is enough. On a large repository it is not,
and no ranking rescues it: `order` really is written into four hundred names,
you wanted the nine in one service, and the text does not separate those because
the text is the same.

What separates them is something you know and the query never named — which
part of the repository you are in. So `docs_search` takes it as a path:

```
docs_search  query: order  from: src/fulfilment/
```

Spelled `--from` on the command line, and the same on `variance ask search`:

```bash
variance-authority-help search order --from src/fulfilment/
```

`from` follows the imports at any depth, then answers with published names those
files actually import. Results are ordered by the number of importing files in
that area, and each line reports those files by import distance from the start
point beside the workspace-wide count. `to` walks the other direction and does
the same for files that reach the path — the one to use when you have the
helper and want its dependents. Give both and you get both areas, unioned: two entry
points of one application share almost no file, so intersecting them would
answer nothing about a question that named two places. Internal exports have no
import-site count, so they are admitted by the declaring file instead.

A path is a path, at three widths and no others — `src/a/File.ts` is that file,
`src/a/*` is that folder's own files, `src/a/` is everything under it. A path
that holds no source file is refused by name. You are never quietly answered
about the whole repository under a heading you would read as *your area*. That
vocabulary is one rule for every question here that takes a path, spelled out
in full under [say where to
look](https://variance-authority.dev/docs/locate#say-where-to-look).

This removes names rather than ranking them down, which is the point: an empty
answer is then a fact about the area, and the answer prints how many files it
looked in so you can place the count it gives you.

### When the word you typed is not the word that was written

A substring answers the string you gave it and nothing else. Two questions it
cannot answer at all: a word one character off the name that was written, and
two words that are both written about a name but not written beside each
other — `read span` appears in no text anywhere, and the declaration you wanted
has both.

Those get a third section, and only those. Ask for `meesure` in this
repository's own fixture and the substring finds nothing, which is printed
first, as a miss of the text you typed rather than of the code:

```
No export, top-level declaration or member of a class, an interface or a type in this repository, nor the doc of one, nor a function inside a function, writes `meesure`. The nearest follow.

1 more name matches loosely, the words apart or a character off:

alpha · measure [function] imported in 1 place in 1 package — Measures the thing, and says how much of it there was.

Next: `variance-authority-help symbol --name measure --package alpha`
```

It may only add. Nothing the two sections above answered is scored, reordered,
promoted, demoted or removed by it, a name they already returned can never
appear in it, and when it has nothing to add it prints nothing — so an answer to
a word that was written stays exactly as short as it was. It obeys `from` and
`to` as they are: the looser reading runs over the files the area allows, so it
can find a name you did not type and never a file you ruled out. A name its file
declares and does not export is reached the same way, after every exported one.

Search also reads the case names each suite's last run recorded, one row per case
whose full name holds every word, as a word, the start of one or its stem, printed
as `<name> [test] — <file>`. They are what ran, not what the source spells, so a
title is found however it was registered. A case added since that run is missing
and one removed since is still listed, until a run of that suite writes its
record; when nothing in the repository answered, a suite with no record is
named under the answer, with the reason.

Inside it the order is the order above — by the other packages that import the
name by a published path, then within the page by the places and packages its
label counts, then by name. Membership is the only decision the looser reading makes, because
you can check why a name is on a list and can only trust where it sits on one.

### Where the declaration is undocumented

A name with no block comment above it is reported as undocumented. Before
reporting it, the nearest `README.md` above the declaring file is searched, and
where that prose names the symbol as a whole word the passage comes back
labelled with the file and line it was read from. The passage is never presented
as the symbol's documentation, and it never removes the name from `gaps`.

`gaps` turns the same ranking into a work queue.
Run `variance-authority-help gaps`, abridged to the first three lines:

```
111 names cross a package boundary with nothing written above the declaration:

Viewport [interface] packages/core/src/format/environment.ts:73 — used by 17 packages: @variance-authority/example-kitchen-sink, @variance-authority/example-todomvc, @variance-authority/cli, @variance-authority/dom, @variance-authority/observe, and 12 more
collect [function] packages/dom/src/collect.ts:197 — used by 14 packages: @variance-authority/case-incumbent, @variance-authority/example-agent-claim, @variance-authority/example-dynamic-route-flake, @variance-authority/example-kitchen-sink, @variance-authority/example-layout-impact, and 9 more
normalize [function] packages/core/src/rules/normalize/index.ts:59 — used by 14 packages: @variance-authority/case-incumbent, @variance-authority/example-agent-claim, @variance-authority/example-dynamic-route-flake, @variance-authority/example-kitchen-sink, @variance-authority/example-layout-impact, and 9 more
```

### Where the repository already writes it

`uses` answers with the file and line of every import, and it separates the
files written to *show* a name in use — stories and tests — from the ones that
depend on it. Both are pointed at rather than quoted: the path and the line are
what an editor opens.

Pass `--from` — the file you are working in — and the sites come back ordered by
how many leading path segments they share with it. This is not the `--from`
above: it is not a start point, it filters nothing, and every site of the name
still comes back. It only decides which of them you read first.

```bash
variance-authority-help uses collect --from packages/cli/src/index.ts
```

```
`collect` [function] is imported in 32 places: 25 from other packages and 7 inside @variance-authority/dom, 1 through import(), which loads the module when the call runs.
Nearest to packages/cli/src/index.ts first.

Tests, from other packages:

examples/todomvc/src/changeset.test.tsx:13 — @variance-authority/example-todomvc; used on line 50
examples/todomvc/src/closure.test.tsx:6 — @variance-authority/example-todomvc; used on line 22

Tests, inside @variance-authority/dom:

packages/dom/src/attributed.test.ts:7 — @variance-authority/dom; used on lines 31, 101
packages/dom/src/generated-box.test.ts:5 — @variance-authority/dom; used on lines 31, 36

Source, from other packages:

packages/playwright-test/src/page-agent.ts:1 — @variance-authority/playwright-test; used on line 201
packages/presentation/src/browser-agent.ts:3 — @variance-authority/presentation; used on line 58
```

That ordering is a claim about the filesystem, not about the import graph.
`uses --from` does not spend the graph merely to reorder a complete list; graph
distance belongs to the scoped `search` answer, where it decides which names are
admitted.

## On a repository you are passing through

```bash
npx @variance-authority/help search session --root ../shadow
```

Install it where you will ask more than once, and use `npx` where you will
not: a checkout you are passing through, a colleague's repository, a tree you
are reading to decide whether to work in it. The index survives either way — it
is kept per checkout in [your cache](https://variance-authority.dev/docs/cache), not inside the tree
being read — so a second `npx` run answers
out of what the first one learned.

Ask `npx` for the package, not for the binary. `@variance-authority/help` is the
name on the registry; `variance-authority-help` is the name of the command it
installs, and passing a command name where a package name goes is how `npx`
ends up reporting that a package does not exist.

## Serve it to an MCP client

With no verb, the binary speaks the protocol on stdio:

```bash
npm install --save-dev @variance-authority/help
variance-authority-help .
```

```json
{
  "mcpServers": {
    "workspace-api": {
      "command": "npx",
      "args": ["variance-authority-help", "."]
    }
  }
}
```

The tools are named `docs_packages`, `docs_entrypoint`, `docs_symbol`,
`docs_uses`, `docs_search`, `docs_grep`, `docs_discover`, `docs_intersection`, `docs_orient`, `docs_slowest_tests`, `docs_retried_tests`, `docs_not_run`,
`docs_journey_map`, `docs_test_composition`, `docs_containment`, `docs_stack` and `docs_gaps`, and they answer in the same
words as the verbs above. `docs_orient` with no files needs the code map `variance
index` makes, so install the CLI beside this package: [connect your
agent](https://variance-authority.dev/agents/workspace-api#connect-your-agent)
prints the whole sequence and how to confirm the tools are listed. With a
`variance.config.json`, `variance serve` serves the same tools under the same
names, so a workspace with the CLI and a config declares one server and asks it
about both the run and the source.

## Write the answers to files

For readers that cannot call a tool — a chat window with a URL box, a crawler, a
person:

```bash
npm install --save-dev @variance-authority/help
variance-authority-help write . --out docs/api
```

Four files, and the command prints each with its size:

| file | is |
|---|---|
| `llms.txt` | the [convention](https://llmstxt.org): a title, a summary, and one link per import specifier |
| `help-index.md` | every name, its signature, its doc and who imports it |
| `help-gaps.md` | the undocumented ones anybody imports |
| `help.json` | the reading itself |

The head of a generated `llms.txt`, run against this repository:

```
# variance-authority

> Composable evidence tools for software that changes.

## @variance-authority/cli

- [@variance-authority/cli](packages/cli/src/index.ts): 103 names, 1 used across a package boundary, 69 documented

## @variance-authority/core

- [@variance-authority/core](packages/core/src/index.ts): 2 names, 1 used across a package boundary, 2 documented
- [@variance-authority/core/format](packages/core/src/format/index.ts): 102 names, 73 used across a package boundary, 70 documented
```

`--base https://github.com/you/repo/blob/main/` puts a prefix in front of every
path, for pages that will be read away from the checkout.

`help.json` contains the same reading the other three files render, so a
caller can build a different rendering without re-reading the repository.

## From a program

Two import specifiers:

| specifier | needs | exports |
|---|---|---|
| `@variance-authority/help` | a stdio pair, to serve | `serveWorkspace` and `writePages` |
| `@variance-authority/help/tools` | nothing | the answers, as pure functions from a reading to text |

The functions in `@variance-authority/help/tools` have no MCP dependency, so
you can call them directly, test them in isolation, or embed them in another
interface without speaking the protocol.

```bash
npm install --save-dev @variance-authority/help
```

`writePages` takes the root, the output directory, and options: `base`, the path
prefix above, and `page`, the title and summary for the generated files,
overriding what they would otherwise take from the root manifest. It returns
what it wrote.

```ts
import { writePages } from '@variance-authority/help';

for (const file of writePages('.', 'docs/api', {
  base: 'https://github.com/you/repo/blob/main/',
  page: { title: 'Our API', summary: 'What every package here publishes.' },
})) {
  console.log(`${file.at} — ${file.bytes} bytes`);
}
```

`readWorkspace` is the reading the answers are computed from, for a program that
runs more than one of them or runs them through its own interface. It
takes the root and returns the workspace: every package, what each publishes,
and who imports it. Seven options, all optional: `index`, the path of the source
index the scan keeps its parses in, when you would rather it shared one you
already have than kept its own under the checkout; `packs`, whether the scan
reads file bytes from Git's object store, on unless you say otherwise; `changed`, the authoritative scan-root-relative file list an editor,
watcher or orchestrator already has, which skips Git status discovery, and is not used when no generation is there to refresh; `taints`,
addition-only Sense taints for declarative module loads the language's imports
do not express; and `records`, a function handed the import
graph the scan drew on the way, for a caller that needs the arrows between files
as well as the names, so it does not scan the checkout a second time to get them;
`tree`, a function handed that graph as the path-query surface directly;
and `progress`, a function told each step's name as it starts, which returns
the function to call when that step ends, for a caller that shows a slow
reading as it happens.
A workspace whose `workspaces` list names members outside its own directory is
read over its directory and each listed member, named from the top of the Git
checkout, and keeps that scope's records in a second index next to `index`.
Every reading saves the index it scanned and publishes from it, so a second
reading starts where the first stopped; an index that cannot be saved is thrown
as an `UnsavedRead`, and nothing is published.
Taints change which files a path question reaches and never manufacture symbol
bindings or usage counts. A subtractive taint is refused: a mock is relative to
one file's run and cannot be flattened into a workspace-wide source tree.

```ts
import { readWorkspace } from '@variance-authority/help';
import { search, searchIndexOf, searchNames, symbol } from '@variance-authority/help/tools';

const workspace = await readWorkspace('.');

console.log(search.run(workspace, { query: 'viewport' }));
console.log(symbol.run(workspace, { name: 'Viewport' }));

const answer = searchNames(searchIndexOf(workspace), { query: 'viewport' });
console.log(answer.published?.shown[0]?.specifier);
```

`searchNames` is the answer `search` prints, as a value: `published`,
`exported` and `loose` sections, each with a `total` and the rows `shown`. A
section that was not run is missing rather than empty, and a start point that
did not resolve returns `refused` with no sections. `variance-authority-help
search viewport --format json` and `variance ask search --format json` print
it.

`refreshWorkspace` takes a previous reading and reads the workspace again from
its index: the scan updates the index with the files that changed, and the whole
value — symbol usage, exported names, signatures, comments, README mentions,
unreadable files and the source graph — is published from it again, so a
reading never gives a published name's old line or text.

`readWorkspaceForAnswer` reads the published generation while it is less than
one hour old and refreshes it after that. `justAnswer` disables that expiry;
`refreshAfterMs` changes it. `readWorkspaceSnapshot` is the unconditional
artifact read used underneath that mode, and `workspaceGeneration` returns the
UTC production time attached to a recorded value.

`serveWorkspace` starts the stdio server and returns a function that stops it.
`input` and `output` are the two streams the protocol is spoken over and default
to this process's own; override them when the host owns the transport. It uses
the same one-hour policy, and on every call reads the published generation's
head: one published since the generation it holds, by `variance index` or another
reader, is read before the call is answered, with or without `justAnswer`.
`readAgain` is that decision. It asks a `docs_symbol`, `docs_uses` or `docs_search`
whose files changed again of a generation made now, or serves only the recorded generation when `justAnswer` is true. A refused call answers from the generation it was refused from. A host
of its own asks `outlived` whether the files a found answer names changed after
its generation, and `caughtUp` to ask that answer again of a generation made
now; it is handed what it asked again and, when the checkout could not be
compared, why. `madeBefore` says whether a refusal's generation predates the
question, so that the checkout was not compared with it; `refusalFooter` is the
line a refusal then ends with; `snapshotLine` dates an answer. A name nothing declares
is thrown as a `FoundNothing`, a refusal whose
message is the answer: what was read, and where else the name may be written.
`foundNothingAnswer` is that answer, under the lines `foundNothingFooter`
gives: `variance ask` and `variance-authority-help` print it on stdout and exit
`0`, and this server and `variance serve` return it as a result, not an error.
A server of your own passes it as `serve`'s `answered`.

```ts
import { serveWorkspace } from '@variance-authority/help';

const stop = serveWorkspace('.', {
  input: process.stdin,
  output: process.stdout,
  justAnswer: true,
});

process.on('SIGINT', stop);
```

## What it does not do

It does not read `dist`. A `types` target of `./dist/index.d.ts` is mapped back
through that package's own `rootDir` and `outDir` to `src/index.ts`, so what it
reports is what somebody wrote.

It does not infer. A name with no block comment above it is reported as having
none, and a search that matches nothing prints that before it offers anything
near it — the near ones arrive under their own heading, counted and labelled,
never mixed into the answer to the word you typed. A README passage is returned
only where the prose writes the name as a whole word, and it arrives labelled
with the file it came from.

It does not serve source. `uses` names the story, the test and the file, with
the line to open; reading them is your job, against the file as it is rather
than as it was when the reading was taken.

It does not rank on prose. `search` matches the query case-insensitively as a
substring of a name or its doc, and a name also matches when it is written in
every word of the query, each word by its start or its stem, so `instrumenting`
reaches `instrumentModule`. A doc also matches when one of its paragraphs
writes the query as a phrase: its words in order by stem, each as many words
after the last as in the query. A function word such as `of`, or a word under three
letters, holds its place and any word fills it; a possessive or punctuation holds
none. So "installs the page's sink" matches `page sink`, "a page and its sink"
does not, and "the text of the file" matches `text of a file`. A match is a
fact about the text rather than an opinion about the query. When it matches nothing, the names holding most of
the query, stemmed as installed packages are, in any order
across the name and its doc, follow under their own heading, each with the
words it holds. Most is a weight: the words a row holds, each counted by how few
names in the repository hold it, come to at least half of what the whole query
comes to, and a word nothing holds counts for the most. So a row sharing one
common word is left out, and a query of two words, one of which the repository
never writes, is told as a none; two common words still outweigh a third word
nothing holds, because a word's weight varies little across a large repository. A start point narrows the rows and not the weight: a
row carrying the query everywhere carries it there. A name its file declares and does not export is among them, and
so is a file, by its own name and the doc it opens with. They are ordered by
the words each holds, each counted by how few of the names and files found
hold it, three times over when the name holds it and twice when a doc of the
mean length or a shorter one does, less for a longer one, and a half when only
its signature does — the words it writes before its body, its parameters, the
types they are written with and a comment among them — and that sum times
how much of the query the row holds wherever it holds it, the same rarities
summed alone — then by how many of them its name holds, then by how many of the query's
adjacent word pairs its doc writes as a phrase, by the same rule: counts, never a score. A name
published by two packages or exported from two files is weighed and shown
through one of them, never through both docs added up: the one its words weigh
most through, then the one writing more of those pairs. The published and
exported sections instead show a name's published row before its exported one,
whatever either says. A word most docs say in passing tells you little about which of them
you meant, so `stopwords of a package` puts `describedNames`, whose doc says
`stopword`, before `packageOf`, whose name says `package`. Every word one of them holds is held by a row shown, so the
one name holding a rare word is shown however many holding a common one sort
before it. A word only a signature holds reaches no name and shows no row on its
own: it adds weight to a name the name or a doc reached. A type alias writes no
signature, since what follows its `=` is its body. A name holding less than most of the query,
which the loose reading reaches by every word, is told there instead.
The words every package says about itself — `package`, `module`, `use`,
`tool`, `get` and the like — are stopwords for an installed package and words
for your own code, which is named in them.

It does not stop at what a manifest publishes. Most code in any checkout was
never meant to be published — 1,826 names are published in this repository and
5,540 more are exported without being published — so `search` answers in two
sections and labels which is which.

---

**[@variance-authority/help](https://variance-authority.dev/reference/packages/help)** is part of [Variance Authority](https://variance-authority.dev) — [documentation](https://variance-authority.dev/docs) · [GitHub](https://github.com/Variance-Authority/variance-authority/tree/main/packages/help) · MIT
