Build your knowledge base

Generating the wiki

Turn the graph into grounded, council-verified prose per repo: searchable, enrichment-aware, with a provenance footer.

On this page

For maintainers who want grounded, reviewed prose about each repository.

Every indexed repository gets one wiki page per scope, and it exists the moment the repo is indexed. contextlake kb wiki writes a structural page built entirely from the graph, the manifests and the checkout, with no language model involved. If an LLM is configured, it then drafts prose from that page, and the prose replaces it only when the prose is at least as accurate and as complete.

So the page you read is one of two things, and it always says which. The diagram below is the per-repository path. A cluster page (--namespace) skips the "accurate and at least as complete" step, because it has no structural page to replace. It goes from the structural check straight to the council. See cluster pages.

flowchart TD
  G[("the graph")] -->|"entry points, modules, ownership,
public surface, install, dependencies"| ST["render the structural page
no model call"] ST --> W[("the repository's wiki page")] W --> P[("the @wiki partition,
embedded and searchable")] ST --> Q{"is an LLM configured?"} Q -->|no| DONE(["done, the page is complete"]) Q -->|yes| DR["draft prose FROM the structural page"] DR --> SG{"structurally sound?
no model call"} SG -->|no| K(["the structural page stays,
the reason is reported"]) SG -->|yes| RG{"accurate and at least
as complete?"} RG -->|no| K RG -->|yes| C["the verification council,
one review per lens"] C --> S{"mean score at or above accept_score?"} S -->|no| K S -->|yes| W
a rectangle is something that runs a cylinder is something that persists a rounded box is a start or an end point a diamond is a decision

The structural page#

It carries seven sections, and any section with nothing in it is omitted and named at the end, so an absence never reads as an oversight:

  1. Entry points and how to run it: main and its equivalents, HTTP routes, Make targets, Dockerfile stages.
  2. Getting started, the ordered path a newcomer takes: install what the repo declares, run its entry point, read the symbol everything routes through, run the tests, and find who to ask.

Three rules keep it honest. Every step restates a fact from another section and links to it, instead of copying detail that could drift. A step with no evidence is dropped, not written as "none found". The section says up front that it was assembled from the graph, because nobody wrote this procedure and a reader who thinks otherwise will trust it too far. 3. Architecture: the repository's modules and their sizes. 4. Ownership and activity: who has been working here lately, as a share instead of a commit scoreboard. Pseudonymised when [kb] anonymize = "always", with a key made fresh for each kb wiki run: one person reads the same on every page of one run, and can read differently on pages from another run. 5. The public surface: the named symbols, most-referenced first, with an incoming-reference count where the graph records any. The count covers every relation, so a symbol that is only declared in its file already has 1. It is not a caller count. 6. Installation and usage: the build and packaging files the repository has. 7. What this repository contains: languages, node kinds, and the repositories it depends on and that depend on it. That last pair is a cross-repository answer no single-repo tool can give, and it is always labelled as describing the whole repository even on a module page, because it cannot be scoped to one.

Large repositories also get one structural page per module, under wiki/_modules/.

When prose may replace it#

Passing the council is not enough, and cannot be: a council judges a page on its own terms and has never seen the page it would displace. Prose must also be

Strict on purpose. A page covering four of seven sections would otherwise replace one that covered seven. Expect drafts to fail this, and expect to keep reading the structural page on some repositories even with a strong model configured. That is the bar working rather than the feature failing; the reason is printed either way.

A rejected or failed generation leaves the structural page where it was.

The council can be pointed at a different, usually stronger, backend than the one that drafted the page, which is what makes publishing from a cheap local generator safe.

Prerequisites#

Running it#

Two ways to turn the tier on.

For example, contextlake kb wiki acme/forecast-api --llm builtin enables the tier and scopes generation to that repo.

A repo id you name must be indexed, with a graph shard on disk. If any id matches no indexed repo, or matches a repo whose shard is gone (after a partial copy of the store, for example), the run exits 1 and writes nothing. Re-index the repo with contextlake kb index.

auto picks for you, in order: a reachable local Ollama that already has the model pulled, else the built-in CPU model, else it skips the tier. See Model providers.

On a pip install, --llm builtin needs one extra step first, contextlake doctor --fix llm-local (see Install and upgrade); --llm ollama needs no compiler at all.

Run contextlake kb wiki. For each repo it writes a Markdown page grounded strictly in graph facts: top symbols, dependencies and files.

When the repo's own checkout is available, it also uses an excerpt of the README and which conventional entry-point or config files exist, such as package.json, Dockerfile or manage.py.

Every page carries a provenance footer citing the commit and the sources. It also records how many connected-source items the prompt carried (Connector items: N). A network key without connector access does not see a page whose count is above 0 or missing (see kb keys).

The draft then goes through a verification council. Reviewers score it for accuracy, completeness and clarity, and a chairman publishes only pages above a configurable threshold. Nothing that fails review is written.

By default the council reviews with the same model that wrote the page, so a small local model both drafts and grades its own work, and the tiny built-in 0.5B in particular tends to rubber-stamp almost everything. To gate a cheap local generator with a stronger judge, point the council at its own provider:

[llm]
provider = "builtin"           # keep generation local and free
review_provider = "anthropic"  # …but have a real model decide what gets published
review_model = "claude-haiku-4-5"   # optional; defaults to the provider's own default

review_provider takes the same values as provider, and always wins. So the reverse split also works: generate with a strong model, review with a cheap one.

The reviewer is sent the same source facts as the generator, ownership section included. When review_provider is a remote provider and [kb] anonymize is not "always", kb wiki prints one warning that names every remote provider that will see contributor names.

A .contextlake.kb.toml found by walking up from the current directory cannot set review_provider to openai or anthropic, because that file picks the vendor that receives your API key. Set it in ~/.contextlake/kb.toml, or pass --config PATH. See Workspace trust.

It is strictly opt-in, and never inferred from a stray API key in your environment, because it is not free. A run makes pages x council_size review calls against that provider. The default is 3 lenses per page. Set council_size = 1 to cut that threefold.

One thing to watch: contextlake doctor checks the generation provider only. A missing key for a hosted review provider (anthropic, openai) does not reject pages. The provider's refusal reaches kb wiki as an HTTP error, and the page fails. A review CLI that is installed but exits with an error rejects every page that reaches the council instead, with N reviewer(s) returned nothing parseable. A review CLI that is not on PATH fails the page, with llm provider=cli: command '<name>' not found on PATH.

The number of symbols sampled into that grounding set scales with the repo's size, rather than being a flat 15:

max(15, min(80, node_count // 1500))

Inside that sample:

The provenance footer states the result as a fact: "Grounded in N/M file-backed symbols (X%)". That is how many distinct symbols the sample touched, against the repo's file-backed symbol count. Both sides count file-backed nodes only, so the ratio means the same thing on a whole-repo page and on a per-subsystem page.

The page has a fixed section order: Overview, Setup & Run, Architecture, Dependencies, Gotchas, Decisions.

A section is written only when the graph has something to ground it. A repo with no signal for a section gets fewer sections, never an empty heading.

What each one needs:

setup_signals also counts legacy C and C++ project files such as .vcxproj and .dsp, and reports them by category ("3 legacy MSVC6 project (.dsp) file(s) detected"). Those extensions are not in the indexed language set and never reach the graph, so the count comes from a bounded scan of the live checkout. That is the same way setup_signals already finds package.json and Dockerfile.

"External context", covered below, is a separate block layered on top of that list. It is always conditional, and it is not one of the named sections.

For the LLM backends behind this (built-in CPU model, Ollama, OpenAI, Anthropic, or a local agent CLI), see Model providers.

Verification#

  1. Read the summary line at the end of the run. It counts the pages and names the folder:
✓ Wiki: N written, N rejected, N unchanged (skipped) → <store>/wiki  (--force to regenerate)
  1. Open the page in <store>/wiki. The footer cites the commit and states the result as a fact: "Grounded in N/M file-backed symbols (X%)".
  2. A page the council refuses is not written. The run prints the reasons under the page's name and counts it under rejected.

Why a page was rejected#

A rejection always names the rule that fired, because a page that fails to appear leaves you staring at a missing file. Two of the reasons come from a structural gate that runs before the council and makes no model call at all:

Reason What the draft did
prompt leakage Reproduced one of its own instructions verbatim, so the page describes how it was asked to write rather than the repository.
degenerate repetition Repeated one span over and over, which is what a model that has run out of grounded material tends to emit.

Both are mechanically visible, so they are decided without asking a reviewer. That is deliberate: a weak model acting as its own council rubber-stamps these defects, which contextlake, explained records with the measurement behind it. Rejecting them early also saves the council's round trips on a page that could not have passed.

Anything else is a council verdict: the mean score across the lenses came in under accept_score, and the reported issues are the reviewers' own. In every case the page is skipped, not rewritten, so a rejection costs you that page rather than another round of model calls. Re-run with a stronger backend, or a stronger reviewer, and it is attempted again from scratch.

A page can also fail, which is not a rejection. A backend that returns no text fails it. Causes include an agent CLI that exits non-zero (an expired login, say), times out, or cannot start for an OS reason such as a permission error. A CLI in those states logs a reason on the line before. Other empty replies, such as a CLI that exits zero with no output or an API or local model reply with no text, log only that the model returned no text.

The summary counts the page under failed, and the page on disk stays as it was. If a page fails and nothing is written or rejected, kb wiki exits 1.

A separate review_provider that returns nothing is not a failed page. It still shows as a rejection, with the count of reviewers whose reply did not parse.

Steering it from the repository: .contextlake/wiki.toml#

A repository can have a say in its own page. Drop a .contextlake/wiki.toml in its root:

# Free text the page quotes, attributed, above the sections.
notes = "This is a thin client. The behaviour lives in the server repo; prefer its docs."

# Optional. Names the subsystems that get their own page, replacing the automatic choice.
pages = ["api", "workers"]

notes is quoted, never absorbed. Everything else on the page is derived from the graph; this is the repository asserting something about itself, and the page says so in those words rather than blending it into its own voice. It is bounded (2000 characters, 10 notes) because it lands verbatim in generated output. A note that is not a string is dropped rather than having its repr printed into a wiki page.

There is no separate "send the notes to the model" step, and that is deliberate: the structural page IS the prompt, so putting the notes on that page is what puts them in front of the model on the prose path. One insertion point, both paths, and the replacement gate keeps working: a name the notes introduce becomes a name a draft may legitimately cite.

pages steers, it cannot invent. Names are matched against the modules the graph found; anything unmatched is dropped with a warning. A file inside a cloned repository is untrusted input, and this is the line that keeps it unable to fabricate a page.

When every name is unknown, the automatic heuristic runs instead of producing nothing. So one typo cannot silently delete a repository's whole module set on the next prune. The list is the whole set on both paths: a run writes and keeps exactly the listed module pages, and prunes the pages of modules that are not on it. A run with no LLM prunes too, because pruning needs no model.

At most 50 names are used, and a name repeated in the list counts once. A longer list is cut at 50 and the run warns with the number ignored. A cut list is not the whole set, so no module page is pruned on that run. Trim the list to 50 names to resume pruning.

Nothing here runs a program, which is why it is honoured from an in-repo file at all: settings that would execute something are refused from files found this way (kb/trust.py). Quoting a repository's own prose is the same trust level as the README excerpt the page has always carried.

The file is read contained. A wiki.toml that is a symlink to a file outside the clone, or that sits under a .contextlake directory linked outside the clone, is not read, and the page is generated as if the file were absent. The notes land in a stored page that every key that may read the repo can see, so a link must not pull in a file from elsewhere on the machine. A link that stays inside the clone is read.

Per-subsystem pages for large, federated repos#

A repo qualifies as federated when it has at least 5,000 graph nodes and no single top-level module owns more than 60% of them. One big source directory does not qualify. A repo split into several comparable subsystems does.

For those, contextlake kb wiki writes one extra page per subsystem automatically. No new flag. These are added to the whole-repo page, never used instead of it.

Each subsystem page:

They live under wiki/_modules/ with their own @wiki:<repo>::<module> partition. A natural-language question can land on a subsystem's own explanation, cited back to that page.

Generation is capped at 20 subsystem pages per run, so one wiki call on a large repo stays bounded.

Which 20 depends on what is already on disk:

  1. Subsystems with no page yet, largest first by node count.
  2. Then subsystems that already have a page.

A first run has no pages, so it becomes exactly "the 20 largest". Every run after that works through the never-paged tail. This is how repeated runs cover the whole repo, instead of re-picking the same top 20 forever.

The run says how many are still waiting, rather than going quiet about it:

N qualifying modules, generating 20 this run (M deferred to a later run)

Once subsystem pages exist, the whole-repo overview names and briefly describes each one and links to it, instead of summarising their internals inline.

The overview names only the subsystems that have a page on disk or are picked for one in that run. This matters above 200 qualifying modules: the structural pages cover the largest 200, and the overview names those until later runs reach the rest. On an unchanged commit it is not regenerated.

One catch: the overview only picks that up the next time it is regenerated. A repo already wiki'd at its current commit has its overview skipped as unchanged, though subsystem pages still generate. So an existing store gets the naming after its next commit, or on a --force run (the dashboard's Regenerate button has a force option too).

Searchable prose#

Accepted pages also become searchable prose. Each page's sections are stored in an isolated @wiki:<repo> partition, and embedded alongside the code vectors when the semantic tier is on.

So a natural-language question can land on the wiki's explanation of a subsystem. The answer is cited back to the page file and labelled advisory, with kind wiki, so it never outranks extracted code facts.

Pages written before this existed are backfilled on the next wiki run, with no LLM calls.

Each section is also linked to the symbols it names, with a documented_by edge. So "where is this function explained?" is one graph hop from the symbol, not a text search.

Cluster (namespace) wiki#

contextlake kb wiki --namespace acme/stations writes one cluster page for a whole group of repos, meaning everything under that repo-id prefix. Use --namespaces --depth N to generate one page per namespace at that depth.

A cluster page narrates how the repos fit together:

It splits coupling inside the namespace from coupling to repos outside it.

It grounds strictly in cross-repo edges the graph already resolved. No new extraction happens. It reuses the same review council and provenance footer as a per-repo page, so it stays advisory and cited. When the graph shows no coupling, it says so instead of inventing a link.

Cluster pages get the same fixed sections and the same nothing-invented rule. That includes a "Gotchas" section when there is a real coupling risk to ground it:

Both come straight off data the cluster brief already computes. No new metric.

You can reach cluster pages over MCP by passing a namespace to get_wiki, and they appear per group in the dashboard's fleet overview.

A cluster page's sections are searchable like any other, and they cite the page file under wiki/_clusters/. One case is not stored for search: a namespace that is also a repo id, such as --namespace acme/stations/api when that repo exists. It is a cluster of one. The page is written, but its sections share their search key with the repo's own page, and storing them would replace the repo's rows. The run says so. If an earlier release already did this, run contextlake kb wiki --force <repo id> to restore the repo's rows.

Incorporating connector enrichment#

Once contextlake kb enrich has populated a repo's @enrich:<repo> documents, from Atlassian or MCP search sources, the wiki adds an External context section to that repo's page.

Every external fact is quoted directly from its source, a Confluence page, a Jira issue or an MCP search result, and attributed by URL or name. None of it is presented as a free assertion or passed off as a code fact.

The council still gates the enriched page before it is written. External context supplements code-backed facts, and never displaces them.

The result renders directly in the dashboard's Wiki tab, with no click-through: grounded strictly in real symbols, carrying a provenance footer, and showing a STALE badge if the indexed commit has since moved.

The page below is the model-free page, the one contextlake kb wiki writes with no --llm. Its footer names the commit. Add --llm and the same tab shows prose sections on top of these facts.

The Wiki tab: a generated page for acme/forecast-api, grounded in the repo's own symbols, under a "not ground truth" advisory bannerThe Wiki tab: a generated page for acme/forecast-api, grounded in the repo's own symbols, under a "not ground truth" advisory banner

With contextlake kb dashboard --serve --allow-mutations, both the per-repo Wiki tab and the fleet-wide Settings tab also carry a Regenerate button that runs this same command from the browser, in the background, see The dashboard → Write actions you can turn on.

Recorded decisions#

A repo's own ADR/decision docs (see Index & Code Graph) are authored facts, not connector content, so they don't need attribution the way "External context" does: each becomes a "Recorded decisions" section citing the decision's title, file, and body directly. No enrich/connect step needed, these are picked up automatically whenever the repo is indexed.

See also#

Next steps