Documentation Maintenance
This guide explains how the paiOS documentation system is structured and how to maintain it. Understanding this is crucial for keeping our documentation synchronized with the code.
Architecture Overview
Section titled “Architecture Overview”The project uses a Hybrid Documentation Strategy for the codebase to provide the best developer experience:
- Native Starlight Integration: Rustdoc JSON is converted to MDX files. This provides a consistent look and feel, native search, and integrated navigation.
- Standard rustdoc HTML (GitHub Pages): The traditional
cargo docoutput is generated via GitHub Actions and hosted on GitHub Pages ataurintex.github.io/pai-os/rustdoc/. This provides the deep-dive technical details Rust developers are familiar with, including private/internal items. - Protocol Buffer Documentation: Proto files are automatically parsed and converted to MDX, providing integrated gRPC API documentation with the same look and feel as the rest of the documentation.
Directory Structure
Section titled “Directory Structure”docs/scripts/: Contains the logic for generating documentation.rustdoc-gen.mjs: Converts Rustdoc JSON (unstable) to MDX.proto-doc-gen.mjs: Parses Protocol Buffer files and generates MDX documentation.
.github/workflows/rustdoc.yml: GitHub Actions workflow that generates standard rustdoc HTML and deploys to GitHub Pages.docs/src/content/docs/reference/rust/: Where the generated Rust MDX files are stored.docs/src/content/docs/reference/api.mdx: Where the generated Protocol Buffer documentation is stored.
Local Development
Section titled “Local Development”To work on the documentation site locally:
# Install dependenciesnpm install
# Start development server (available at http://localhost:4321)npm run dev
# Build for productionnpm run build
# Preview production buildnpm run previewIf the build fails with Received protocol 'astro:' (Node 24+), use Node 20 LTS for the docs build. A docs/.node-version file is provided for fnm/nvm (fnm install then fnm use in docs/).
Common Tasks
Section titled “Common Tasks”Generating Documentation
Section titled “Generating Documentation”Documentation generation is automatically part of the main build process:
# From the docs directorynpm run buildTo run only the documentation generation:
# Generate Rust MDX documentation (for Starlight integration)npm run gen:rustdoc
# Generate Protocol Buffer documentationnpm run gen:proto
# Generate all local documentationnpm run gen:rustdoc && npm run gen:protoNote: Standard rustdoc HTML (with private items) is generated automatically via GitHub Actions on push to
mainand deployed to GitHub Pages. See.github/workflows/rustdoc.yml.
Updating the Generation Logic
Section titled “Updating the Generation Logic”For Rust Documentation:
If you add new Rust modules or change the crate structure:
- Check
docs/scripts/rustdoc-gen.mjsto ensure the module hierarchy is still handled correctly. - The script uses the
nightlytoolchain for JSON export. You need to set up your environment:
# Install nightly toolchainrustup toolchain install nightly
# Add the required JSON documentation componentrustup component add rust-docs-json --toolchain nightlyNote: Documentation generation will automatically use the +nightly modifier when running through our scripts.
For Protocol Buffer Documentation:
If you add or modify .proto files:
- Place your
.protofiles inapi/grpc/. - The
proto-doc-gen.mjsscript will automatically detect and parse them. - The script supports two modes:
- protoc-gen-doc (if installed): Uses the external tool for better formatting
- Built-in parser (fallback): Parses proto files directly without external dependencies
- Generated documentation is written to
docs/src/content/docs/reference/api.mdx.
To install protoc-gen-doc for enhanced formatting (optional):
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latestRouting and Redirects
Section titled “Routing and Redirects”To provide clean URLs like /reference/rustdoc/engine/index, we use Astro’s native redirect system in astro.config.mjs. These redirects point to the external GitHub Pages site where the standard rustdoc HTML is hosted.
Important:
- Standard rustdoc HTML is generated via GitHub Actions and deployed to
aurintex.github.io/pai-os/rustdoc/. - The redirects in
astro.config.mjspoint to this external URL.
Deployment
Section titled “Deployment”The documentation can be deployed to:
- GitHub Pages: Recommended for separate hosting from the main website. Configure the repository settings to deploy from the
docs/directory. - Vercel/Netlify: Can be integrated with the main website (aurintex.com).
CI/CD Behavior
Section titled “CI/CD Behavior”The documentation build is designed to work in different environments:
- Local Development: Requires Rust nightly toolchain. Run
npm run gen:rustdocto generate MDX from rustdoc JSON. - Vercel/CI: Rustdoc generation is automatically skipped when Cargo is not available. The pre-generated MDX files in
docs/src/content/docs/reference/rust/are used instead. - GitHub Actions: Standard rustdoc HTML is generated on push to
mainand deployed to GitHub Pages.
For Contributors: You only need Rust installed if you’re modifying the engine crate and want to regenerate the Rust API documentation. Otherwise, the existing MDX files will be used.
Preventing Regressions (AI Agents)
Section titled “Preventing Regressions (AI Agents)”When working with AI agents like Cursor or TaskMaster:
- Ensure they are aware of the
docs-maintenancerule set. - If an agent modifies the documentation structure, verify that
npm run buildcompletes successfully. - Verify that
api.mdxis generated correctly when proto files are present. - Standard rustdoc HTML is generated separately via GitHub Actions, not during the main build.