Publish the dynamic Lean viewer: doc-gen4 declaration data as knowledge-graph shards
Ingest doc-gen4’s per-module declaration data (.lake/build/doc-data/declaration-data-<Module>.bmp) into JSON-LD shards — one per module, with declaration nodes, imports edges and formalizes edges to the content blocks whose lean.ref names each declaration — and publish them under the folio’s site with a single viewer page that loads modules, signature chunks and the search list on demand. Signatures are chunked 500 declarations per file so a 12,804-declaration module stays usable. With --base it writes a STAGING overlay: only modules whose content hash differs from the published base, plus overlay.json; the viewer loads the rest from the base. Rails the viewer page with the same pass as lean-render-publish.
Skills it satisfies
A skill states the capability; this Tool is one way to exercise it. Each skill’s declared input and output contract follows, where it has one.
lean-html-docs
Build and publish the visualiser of a folio’s declared lean directory: the package’s doc-gen4 HTML render, staged under the folio’s site and wrapped in the harness navbar and rail. Use when a folio’s Lean docs are missing, stale, or published without the harness chrome, or when declaring a lean directory and its coverage.visualiser.
Source: folio-assistant-sci/skills/lean/lean-html-docs.md.
Also satisfied by: lean-html-docs, lean-render-publish.
The skill declares no I/O contract (schemas/skills/lean-html-docs/{input,output}.schema.json).
Inputs and outputs
Each port names a shared type by IRI, so two Tools for one skill can be checked for interchangeability.
| port | type | required | description | constraint | |
|---|---|---|---|---|---|
| in | docData | RepoPath | yes | doc-gen4’s .lake/build/doc-data from lean-html-docs. | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. |
| in | site | RepoPath | yes | The folio’s built site. | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. |
| in | route | Slug | Where under the site. Default lean. | string · pattern ^[a-z0-9][a-z0-9-]*$ · A folio slug, e.g. quantum-observable-universe | |
| in | module | PackageName | A module root to keep (qou keeps QOU). Repeat for several. | string · pattern ^[a-z][a-z0-9-]*$ · A skill package, e.g. folio-core | |
| in | contentRoot | RepoPath | Content tree whose blocks’ lean.ref become formalizes edges. | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. | |
| in | repo | RepoFullName | owner/repo for block links. | string · pattern ^[A-Za-z0-9][A-Za-z0-9._-]*\\/[A-Za-z0-9][A-Za-z0-9._-]*$ · A forge repository’s full name, owner/name | |
| in | ref | Branch | Branch or sha for block links. | string · pattern ^[A-Za-z0-9][A-Za-z0-9._/-]*$ · A git branch name | |
| in | contentPrefix | RepoPath | Path of the content root inside the repo, for block links. | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. | |
| in | base | Url | Published data/ of the base graph; enables the STAGING overlay. | string · format uri · An absolute http(s) URL | |
| in | externalBase | Url | Where links into pruned modules go. Default the community mathlib4 docs. | string · format uri · An absolute http(s) URL | |
| in | homeLabel | InstanceId | The rail’s home row. | string · pattern ^[A-Za-z0-9][A-Za-z0-9._-]*$ · A workflow instance id — the stem of a file in the bean graph’s workflow-state node | |
| in | instance | InstanceId | As rail-standalone-pages.ts –instance. | string · pattern ^[A-Za-z0-9][A-Za-z0-9._-]*$ · A workflow instance id — the stem of a file in the bean graph’s workflow-state node | |
| in | platform | RepoPath | The index checkout holding the rail pass. | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. | |
| in | noRail | Flag | Publish only; the caller rails the site. | boolean · A boolean switch — projects to a bare flag, with no value word | |
| out | viewer | RepoPath | <site>/<route>/: index.html, viewer.js/css, extracted signature styles, config.json and data/ (index.json, names.json, m/ | string · pattern ^[A-Za-z0-9._][A-Za-z0-9._/-]*$ · A path relative to the repository root. No .. segments. |
Processes and tasks
Steps this Tool can carry out, because each names a skill it satisfies:
| process | step | lane | via skill |
|---|---|---|---|
| Publish a folio’s Lean render with the harness chrome | Build the doc-gen4 render over the warm cache | Lean toolchain | lean-html-docs |
| Publish a folio’s Lean render with the harness chrome | Stage the render under the site and rail every page | CI/CD Pipeline | lean-html-docs |
How it is deployed and reached
- Command line. From the repository root:
bun run folio-assistant-sci/adapters/paper/lean/lean-kg-publish.ts. - GitHub Actions. No workflow in this checkout runs its command.
As an API: its operation in the OpenAPI document and the MCP tool list of its layer.
| install | none |
| runtime | bun |
| network | no |
| when to choose it | |
|---|---|
| when | Instead of lean-render-publish when the folio publishes its Lean as a dynamic viewer over graph shards, and for STAGING branches with --base. |
| limits | doc-gen4 still has to elaborate: the shards come from its doc-data, so lean-html-docs (or a restored doc-gen4 cache) runs first. Links into pruned modules go to the community docs, built from their Mathlib. Docstrings are rendered client-side with marked and MathJax from CDNs. |
| cost | Measured on qou 2026-10-11: 3,011 modules, 53,565 declarations, 651 formalizing a block; 6,005 files / 171 MB / 13 s; a no-change overlay writes 0 module files. |
What it is made of
| role | file | |
|---|---|---|
| definition | folio-assistant-sci/tools/lean-kg-publish/lean-kg-publish.ts | |
| script | folio-assistant-sci/adapters/paper/lean/lean-kg-publish.ts |
Linked data
The Tool is published as its own JSON-LD document at its IRI, https://litlfred.github.io/folio-assistant/folio-assistant-sci/tools/lean-kg-publish.jsonld, partOf its layer’s document. The node below is the definition this page was drawn from, and is embedded in the page as application/ld+json.
{
"@context": "https://litlfred.github.io/folio-assistant/folio-assistant-sci/folio-assistant-sci.context.jsonld",
"@id": "https://litlfred.github.io/folio-assistant/folio-assistant-sci/tools/lean-kg-publish.jsonld",
"@type": "https://litlfred.github.io/cat-harness/v0/ns/Tool",
"partOf": "https://litlfred.github.io/folio-assistant/folio-assistant-sci/folio-assistant-sci.jsonld",
"name": "lean-kg-publish",
"title": "Publish the dynamic Lean viewer: doc-gen4 declaration data as knowledge-graph shards",
"description": "Ingest doc-gen4's per-module declaration data (`.lake/build/doc-data/declaration-data-<Module>.bmp`) into JSON-LD shards — one per module, with declaration nodes, `imports` edges and `formalizes` edges to the content blocks whose `lean.ref` names each declaration — and publish them under the folio's site with a single viewer page that loads modules, signature chunks and the search list on demand. Signatures are chunked 500 declarations per file so a 12,804-declaration module stays usable. With `--base` it writes a STAGING overlay: only modules whose content hash differs from the published base, plus `overlay.json`; the viewer loads the rest from the base. Rails the viewer page with the same pass as `lean-render-publish`.",
"install": {
"none": true
},
"invoke": {
"shell": "bun run folio-assistant-sci/adapters/paper/lean/lean-kg-publish.ts"
},
"io": {
"inputs": [
{
"name": "docData",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "doc-gen4's `.lake/build/doc-data` from `lean-html-docs`.",
"required": true,
"arg": {
"flag": "--doc-data"
}
},
{
"name": "site",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "The folio's built site.",
"required": true,
"arg": {
"flag": "--site"
}
},
{
"name": "route",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/Slug",
"description": "Where under the site. Default `lean`.",
"required": false,
"arg": {
"flag": "--route"
}
},
{
"name": "module",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/PackageName",
"description": "A module root to keep (`qou` keeps `QOU`). Repeat for several.",
"required": false,
"arg": {
"flag": "--module"
}
},
{
"name": "contentRoot",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "Content tree whose blocks' `lean.ref` become `formalizes` edges.",
"required": false,
"arg": {
"flag": "--content-root"
}
},
{
"name": "repo",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoFullName",
"description": "`owner/repo` for block links.",
"required": false,
"arg": {
"flag": "--repo"
}
},
{
"name": "ref",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/Branch",
"description": "Branch or sha for block links.",
"required": false,
"arg": {
"flag": "--ref"
}
},
{
"name": "contentPrefix",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "Path of the content root inside the repo, for block links.",
"required": false,
"arg": {
"flag": "--content-prefix"
}
},
{
"name": "base",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/Url",
"description": "Published `data/` of the base graph; enables the STAGING overlay.",
"required": false,
"arg": {
"flag": "--base"
}
},
{
"name": "externalBase",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/Url",
"description": "Where links into pruned modules go. Default the community mathlib4 docs.",
"required": false,
"arg": {
"flag": "--external-base"
}
},
{
"name": "homeLabel",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/InstanceId",
"description": "The rail's home row.",
"required": false,
"arg": {
"flag": "--home-label"
}
},
{
"name": "instance",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/InstanceId",
"description": "As rail-standalone-pages.ts --instance.",
"required": false,
"arg": {
"flag": "--instance"
}
},
{
"name": "platform",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "The index checkout holding the rail pass.",
"required": false,
"arg": {
"flag": "--platform"
}
},
{
"name": "noRail",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/Flag",
"description": "Publish only; the caller rails the site.",
"required": false,
"arg": {
"flag": "--no-rail"
}
}
],
"outputs": [
{
"name": "viewer",
"schema": "https://litlfred.github.io/folio-assistant/cat-harness/tool-types.schema.json#/$defs/RepoPath",
"description": "`<site>/<route>/`: index.html, viewer.js/css, extracted signature styles, config.json and `data/` (index.json, names.json, m/<Module>.jsonld, m/<Module>.<k>.sig.json, overlay.json)."
}
]
},
"satisfies": [
"lean-html-docs"
],
"requirements": {
"runtime": [
"bun"
],
"network": false
},
"selection": {
"when": "Instead of `lean-render-publish` when the folio publishes its Lean as a dynamic viewer over graph shards, and for STAGING branches with `--base`.",
"limits": "doc-gen4 still has to elaborate: the shards come from its doc-data, so `lean-html-docs` (or a restored doc-gen4 cache) runs first. Links into pruned modules go to the community docs, built from their Mathlib. Docstrings are rendered client-side with marked and MathJax from CDNs.",
"cost": "Measured on qou 2026-10-11: 3,011 modules, 53,565 declarations, 651 formalizing a block; 6,005 files / 171 MB / 13 s; a no-change overlay writes 0 module files."
}
}