# Installing and syncing

docspack is a CLI. Run it with `npx docspack <command>`, or install it as a dev dependency
to pin the version your team uses.

## Requirements

Node 22.5 or newer. The index uses `node:sqlite` from the Node standard library, so there
is no native module to compile and `npx docspack` starts without a build step.

## Adding a documentation package

Documentation packages are ordinary npm dependencies. Add one the way you add anything
else:

```bash
pnpm add -D @acme/docspack
npx docspack sync
```

`docspack sync` reads `dependencies` and `devDependencies` from the project's
`package.json`, keeps the entries named `@vendor/docspack`, `@vendor/<name>-docspack` or
`@docspack-community/*`, resolves each one in `node_modules`, and indexes its chunks.

A dependency that ships a `.llms/manifest.json` under any other name is not indexed, and
`sync` says so rather than passing over it: it names the package, the number of chunks its
manifest declares, and the shapes it would have matched. A pack nobody can read is nearly
always a publishing mistake, and the alternative to reporting it is a question answered
confidently from the wrong corpus.

It then reads the other dependencies — the ordinary libraries — and indexes one entry per
name their type declarations export, so a question about something nobody documented can
still be answered from the installed build. See
[answers from the installed build](10-answers-from-the-installed-build.md).

Both halves of that walk upwards from the working directory: the declaration is read from
the nearest `package.json` and from every ancestor, and the install is resolved through
every `node_modules` above. So a monorepo that declares its documentation once in the
repository root is found from any workspace member, which is where an agent usually is.

## What sync does on the second run

Indexing is keyed by name and version. A package already present in the index is reported
as `cached` and its files are not read again:

```
+ @acme/docspack@1.4.0  128 chunks  indexed
= @other/docspack@2.0.0  44 chunks  cached
```

Bump a dependency and the new version is indexed as a new entry; the old one stays in the
database for any project still using it. To re-read a package whose contents changed
without a version bump, which happens while authoring, pass `--force`.

## Inspecting a project

`docspack list` shows the documentation packages this project depends on and whether each
is in the index:

```
@acme/docspack@1.4.0  128 chunks  indexed
```

Problems are reported rather than hidden. A package that is declared but not installed, or
installed but missing its manifest, is named on stderr so it does not silently disappear
from search results.

## Choosing where the index lives

The default is `~/.docspack/store.db`. Override it with `--store <path>` on any command, or
by setting the `DOCSPACK_STORE` environment variable. A per-project index is occasionally
useful in CI, where a clean database makes runs reproducible:

```bash
DOCSPACK_STORE=.cache/docspack.db npx docspack sync
```

The database is safe to delete. Everything in it can be rebuilt from `node_modules` with
`docspack sync`.
