@todo-labs/openkb-renderer Package
The Astro-powered static documentation renderer for OpenKB: layouts, MDX components, navigation, theme utilities, and its package export map.
@todo-labs/openkb-renderer
@todo-labs/openkb-renderer is the Astro-based static documentation renderer shipped inside the OpenKB repository at packages/renderer. It provides the layouts, MDX components, navigation helpers, and theming utilities that turn an OpenKB content bundle into a documentation site. Its declared name, purpose, and metadata are recorded in packages/renderer/package.json (name @todo-labs/openkb-renderer, version 0.1.0, description “Astro-based static documentation renderer for OpenKB”, MIT license, type: "module").
Package export map
The package defines two kinds of entry points in packages/renderer/package.json:
- Programmatic (built) entry:
"."resolvestypesto./dist/index.d.tsandimportto./dist/index.js. The build script is plaintsc("build": "tsc"), so thedistoutput is produced by TypeScript compilation rather than an Astro build;"typecheck": "tsc --noEmit"is the type-checking script. - Source-path subpath exports:
"./layouts/*","./components/*","./lib/*", and"./styles/*"each map directly into the matchingsrc/directory. This is why the README example imports@todo-labs/openkb-renderer/layouts/DocsLayout.astrodirectly from source.
The files field limits published content to dist, src, and README.md. The runtime dependencies (from dependencies) are astro (^5.3.0), @astrojs/mdx, @astrojs/react, @astrojs/tailwind, react/react-dom (^19), tailwindcss (^3.4.17) with tailwind-merge and clsx, gray-matter and js-yaml for frontmatter parsing, pagefind for search indexing, lucide-react for icons, and zod (^3.24.1) for schema validation.
Module surface (src/index.ts)
packages/renderer/src/index.ts is the barrel that re-exports four library modules and one component group:
export * from './components/mdx';
export * from './lib/config';
export * from './lib/okf';
export * from './lib/navigation';
export * from './lib/theme';
MDX components (src/components/mdx/)
The index.ts under src/components/mdx/ re-exports eight components: Card, Tabs, Accordion, Steps, CodeGroup, Callout, ParamField, and ProvenanceBadge. Each maps to a .tsx file in the same directory, matching the README’s claim that the package “exports MDX components such as Card, Tabs, Callout, Steps, and ProvenanceBadge”. ProvenanceBadge is the component that renders the OKF provenance display controlled by okf.showProvenance (see below).
Configuration schema (src/lib/config.ts)
config.ts defines the Zod schema for the site configuration file that the renderer reads at runtime, called docs.json (or openkb.json).
loadDocsConfig(rootDir) and file resolution
loadDocsConfig(rootDir = process.cwd()) looks for docs.json then openkb.json under the root directory (using fs.existsSync). It parses the first existing file with JSON.parse and validates it with DocsConfigSchema.parse. On any parse/validation failure it logs [OpenKB] Warning: Failed to parse ... and falls back to defaults; if no config file exists it returns DocsConfigSchema.parse({}) with defaulted values. This matches the README statement that “The renderer reads docs.json (or openkb.json) from the current working directory.”
The DocsConfig schema
DocsConfigSchema validates and defaults the following top-level keys:
name(default"OpenKB Docs") anddescription.theme— one ofemerald|sapphire|obsidian|amber|rose, defaultemerald.colors— optional{ primary, light, dark }, defaulting toprimary: '#10b981'.style— a nested object defaulting to{ preset: 'atlas', typography: 'sans', density: 'comfortable', radius: 'soft', layout: 'standard' }, wherepresetisatlas|terminal|notebook, and an optionalstyle.colorsmap of surface overrides (background,backgroundSubtle,text,textMuted,border,codeBackground). The README’s example config (preset: "atlas",typography: "sans",density: "comfortable",radius: "soft",layout: "standard") validates directly against this schema.logo(light/dark image paths,hrefdefault/, optionaltext),favicon(default/favicon.svg).appearance—{ default: 'system' | 'light' | 'dark', strict }, default{ default: 'system', strict: false }.navigation— viaNavigationSchema, defaulting to{ pages: ['index'] }. Navigation supports three shapes:tabs(each tab withtab, optionalicon/href, and optionalgroups/pages),groups(each group withgroup, optionalicon/expanded, and a recursivepageslist of page strings or nestedNavGroups), and a flatpageslist.navbar— optionallinks({ label, href, target? }[], default[]) and optionalprimaryaction ({ type: 'button' | 'github', label, href }).footer— optionalsocials(github,x,discord,linkedin),copyright, andlinks.okf—{ version: '0.2', bundleRoot: './content', showProvenance: true }.bundleRootnames the directory the content bundle lives in andshowProvenancetoggles the provenance badge.generate— optional{ outputDir: './openwiki' }.
Theme utilities (src/lib/theme.ts)
theme.ts converts a DocsConfig into CSS custom properties.
STYLE_PRESETSis aRecord<'atlas' | 'terminal' | 'notebook', SurfaceTokens>with full surface token sets (background, backgroundSubtle, elevated, text, textMuted, textFaint, border, borderSubtle, codeBackground, navbar) —atlas“a calm reading surface … the default for knowledge bases”,terminal“Dense, high-signal treatment for APIs and operational runbooks”,notebook“Warm paper for explanatory guides and learning material”. This backs the README’s claim that “atlas,terminal, andnotebookare supplied presets. Surface colors can be individually overridden throughstyle.colors.”THEME_PRESETSmaps the five theme names to primary/light/dark color triplets (emerald,sapphire,obsidian,amber,rose).resolveThemeColors(config)mergesconfig.colorsover the theme preset and derives derivative tokens (primary50,primary100viacolor-mix(...)), returning aThemeColorsobject.generateCssVariables(config)emits a:root { ... }block setting--primary-*,--bg-base/--bg-subtle/--bg-elevated,--navbar-bg,--text-main/--text-muted/--text-faint,--border-color/--border-subtle,--code-bg,--font-body(Inter, system, or JetBrains Mono depending onstyle.typography), density-driven--prose-size/--prose-leading/--section-space,--control-radius/--card-radius, and--docs-max-width(96remforwide, else84rem). Individual style tokens always win over the preset (custom.background || preset.background), matching the schema comment “individual tokens below always take precedence”.
Navigation helpers (src/lib/navigation.ts)
navigation.ts derives nav structures from a DocsConfig:
formatNavHref(slug, baseUrl)normalizes a slug into a trailing-slash href, mappingindex/empty to the base path.flattenNavigation(config, pagesMetadata, baseUrl)walks tabs → groups → flat pages to produce a linearFlatNavItem[](slug, title, href, icon?, tag?, group?, tab?), deriving default titles from the last slug segment with dashes/underscores replaced and title-cased. Used for prev/next traversal.getSidebarSections(config, currentSlug, pagesMetadata, baseUrl)determines the active tab by locating which tab (or group) contains the normalized current slug — defaulting to the first tab when nothing matches — then buildsSidebarSection[]with nested subgroup recursion and per-itemactiveflags.getPrevNextNavigation(flatNav, currentSlug)finds the previous and nextFlatNavItemby index in the flattened list.
OKF frontmatter handling (src/lib/okf.ts)
okf.ts implements Google OKF v0.2 parsing on top of gray-matter and zod:
- Schemas:
OkfSourceSchema(uri + optional author/usage_count/last_modified/usage_window, §5.1),OkfVerificationSchema(by/at/notes, §5.3),OkfGenerationSchema(by/at, §5.2), andOkfFrontmatterSchema— a full OKF v0.2 frontmatter validator with the requiredtype(default'Concept'),title,description,tags,status(draft|stable|deprecated, defaultstable),sources,generated,verified, attested-computation fields (runtime,computation,executor,attester, §10), plus OpenKB presentation fields (sidebarTitle,icon,mode—default|wide|custom|center,deprecated,hidden,tag). The schema is.passthrough()to preserve unknown keys per OKF §11. parseOkfDocument(rawContent)splits frontmatter withmatter(), validates it, extracts internal relative markdown links[Label](/target)(excludinghttp/https/anchor targets), and estimatesreadingTimeMinutesat 200 wpm.formatActorLabel(actor)classifies an OKF actor string ashuman:/process:prefixes or a bareagentlabel.
Layout shell (src/layouts/DocsLayout.astro)
DocsLayout.astro composes the full page shell and is the component used in the README usage example. Its Props are config: DocsConfig, frontmatter: OkfFrontmatter, currentSlug, optional headings ({ depth, slug, text }[]), sections: SidebarSection[], flatNav: FlatNavItem[], plus optional activeTab, prev, next.
The page title is derived as ${frontmatter.title} — ${config.name} (or just config.name), and the description falls back to config.description or the default “Open-source documentation powered by OpenKB and Google OKF”. It renders:
- A
<head>with thegenerateCssVariablesoutput injected via<style set:html>, Google Fonts links for Inter and JetBrains Mono, and an inline FOUC-prevention script that readsopenkb-themefromlocalStorageand setsdata-theme/darkclass. Navbar, then a.docs-shellgrid containingSidebar, a<main data-pagefind-body>(the Pagefind-indexed content region) withBreadcrumbs, an<article class="prose max-w-none">slot, andPageNavigation(prev/next).TableOfContentsrendered only whenfrontmatter.mode !== 'wide'andheadings.length > 0.Footer,SearchModalwithclient:load, and an inline script that lazily imports${cleanBase}pagefind/pagefind.jsand assignswindow.pagefind(swallowing the rejection when pagefind isn’t built yet, e.g. in dev).
The html element gets data-docs-style={config.style.preset} and class="scroll-smooth".
Behavior summary
End to end, an OpenKB site calls loadDocsConfig() from the root of the project, builds sections/flatNav from the navigation helpers, parses each content file with parseOkfDocument, and renders pages through DocsLayout, which layers theme CSS variables, navbar/sidebar/toc chrome, the prose article slot, and pagefind-powered search. The [...slug].astro page (in src/pages/) and the llms.txt / llms-full.txt endpoints (in src/pages/) are additional renderer pages present in this package, but their implementations were not inspected for this document.
Limitations
src/styles/global.cssand the remaining layout components (Navbar.astro,Sidebar.astro,TableOfContents.astro,Breadcrumbs.astro,Footer.astro,PageNavigation.astro,SearchModal.tsx) are listed by the export map but were not read during this research pass; claims about their internal behavior are therefore not made here.