The Index Stops Reaching Into the Server
A map of the codebase caught two quiet lies: an engine importing its own server, and a docstring promising no writes.
Why Care?
corpora-builder has two front doors, the corpora command line and a small
local server the desktop app talks to, and both are meant to stand on one
shared engine. That only works if the engine never leans on either door. When
it does, a change to how the screen lists sources can break corpora reindex
in the terminal, and nobody would think to look there.
We drew a floorplan of the repo (an interactive map of every module, file and
endpoint, connected by real imports and web requests) as groundwork for a new
context-v/mirrors/ doc type: documents that describe what is built and
running now. The map's first useful act was to show us two places where the
code and what we said about it had drifted apart.
What's New?
The index no longer imports the server. Building the source manifest (the one-row-per-source catalogue that keeps listings fast) moved from
src/server/browse.pyto a newsrc/index/build.py.reindexnow finds it in its own layer. Nothing undersrc/index/importssrc/server/any more.The server's docstring tells the truth.
src/server/app.pyopened with "No handler writes." Two do:POST /api/captureandPOST /api/reindex. Both have always been refused unless the server starts writable, so this was a stale claim rather than a hole, but a claim the code contradicts is one a reader can't trust anywhere else either. It now names both, and notes thatGET /api/binarywrites only to this machine's cache, never to the corpus.No behaviour changed. Same listings, same reindex, same 196 green spec IDs on the ledger.
How it happened
The map draws an arrow for every import between modules. One arrow pointed the wrong way:
before after
src/index/rebuild.py src/index/rebuild.py
│ │
▼ ▼
src/server/browse.py ◄── server src/index/build.py
(build_manifest) ▲
│
src/server/browse.py ◄── serverBoth ends of that arrow landed in the same commit (389f7a6, 2026-08-23,
the one that introduced the manifest and Pagefind ranking). build_manifest
was placed in browse.py beside the listing code that reads the manifest,
and rebuild.py imported it from there.
Under the Hood
src/index/build.py takes build_manifest, source_keys, NOT_SOURCES,
and the three helpers they need (select_sources, read_many, entry_for,
previously private to browse.py). Its docstring keeps the rule that matters
most: a file that won't parse still gets a manifest entry carrying its error.
browse.py imports them back and still offers build_manifest,
source_keys and NOT_SOURCES under their old names, so every existing
caller and test keeps working untouched. That mattered here: the loop forbids
editing a test to make a refactor pass, and a refactor that needed one would
not have been a refactor.
src/cli.py's backfill-urls command now imports source_keys from the
index layer directly.
The ladder (scripts/check.sh): black, ruff and design drift clean, mypy
0 errors, pytest 210 passed and 2 skipped, frontend 35 passed, ledger 196
green · 0 red · 5 gated · 0 missing.
What's Next?
The first context-v/mirrors/ document, written from the floorplan, to see
whether "what is built and running now" earns its own directory.
