BUCKYVERSE

Knowledge Layer Loader — Design (Sub-project 4)

Date: 2026-07-06
Status: Approved for planning
Sub-project: SP4 of the Wiki.js → Astro migration (docs/superpowers/specs/2026-07-06-wikijs-to-astro-migration-program-design.md). SP1 (reader), SP2 (library/home/downloads), SP3 (dictionary) are live at future.buckyverse.org.
App: apps/reader/ (Astro 5 + pnpm, deploy via wrangler pages deploy).


1. Goal & success criteria

Render the compiled llm-wiki knowledge layer (.wiki/wiki/ — topics, concepts, references) as a browsable, searchable, cross-linked /knowledge/* section of the static Astro site, at parity with what the Wiki.js projection serves — rendering whatever content exists today (not gated on ingest completeness).

Done when:

2. Source & the canonical URL scheme (reuse the projector)

3. Architecture — port the projector to a static loader

Pure, tested TS modules in apps/reader/src/lib/knowledge/ (mirrors src/lib/dictionary/):

knowledgeLoader (src/loaders/knowledgeLoader.ts): walk .wiki/wiki/{topics,concepts,references}/**/*.md (exclude _index.md), parse frontmatter, build the slug index (first pass), then emit one knowledge collection entry per article:
{ slug, category, path, title, summary, tags, updated, confidence, volatility, aliases, html, sources }.

Collection (src/content.config.ts): add knowledge with a zod schema matching the entry.

4. Routes & pages

Citations helper (src/lib/knowledge/citeSource.ts): called by rewriteLinks (§3) for relative links that resolve into a repo book/source dir — maps to /read/<book-slug> when the source is a hosted book (present in books.config/catalog), otherwise returns plain text. Best-effort; unmatched → text. (Deep cross-corpus linking is SP5.)

5. Math (KaTeX)

Only 2 articles use inline $…$. Add a KaTeX markdown-it plugin (e.g. @vscode/markdown-it-katex or markdown-it-katex) in renderArticle, and include KaTeX CSS once in SiteLayout (self-hosted CSS asset, no external CDN — CSP-safe). Rendered at build; no client JS required.

6. Design system

Reuse SiteLayout + the reader's theme/typography so /knowledge/* is visually one site with /read and /dictionary. Article body reuses the readable measure (~72ch).

7. Redirects (for SP6)

Because Astro /knowledge/<cat>/<slug> mirrors the projector's Wiki.js paths, the map is a passthrough. Add to public/_redirects at SP6:

8. Scope

In: 378 articles (topics/concepts/references) as static pages; landing + 3 category indexes; ported link/path/slug logic + tests; KaTeX; light metadata + tags; ## Sources citations with best-effort /read linking; graph link; Pagefind.

Out: raw/, inventory/, datasets/, _index.md, empty theses/; cross-corpus deep links (SP5); rebuilding the relationship graph (link only); editing/ingesting .wiki/ content (ongoing parallel track).

9. Testing

10. Risks

11. Definition of done

/knowledge/ is live on future.buckyverse.org: all 378 articles browsable by category and cross-linked (wikilinks + relative links resolved, dead links degraded to text), math rendered, sources cited (with /read links where hosted), the graph linked, Pagefind covering knowledge, the build fully static and ~382 files heavier, and the near-identity redirect approach recorded for SP6.