Zig docgen

From zolotukhin/zinc · View interactive version

Zig docgen is an AI agent skill from the GitHub repository zolotukhin/zinc. Use when adding or editing Zig code in ZINC and you want it to remain compatible with the auto-generated Zig API docs. Covers the comment format, supported tags, parser limitations, section naming, and validation steps needed for reliable HTML, JSON, text, and llms exports.

How to use this skill

Skill file

Zig Docgen

Use this when you touch src/**/*.zig and the public surface should stay extractable by site/src/lib/zig-api-loader.ts.

Authoring Contract

  1. Every documentable module starts with //! comments.

Required shape:

  1. Every public symbol gets a /// doc block immediately above it.

Include:

  1. Every pub fn inside an exported struct, enum, or union also gets a /// doc block.
  1. Keep public API extraction simple.

The generator supports:

  1. Do not rely on nested public declarations other than methods.

Example:

  1. Reuse the existing section names unless you are intentionally changing the docs taxonomy.

Current sections (must match SECTION_META slugs in site/src/lib/zig-api-loader.ts):

  1. If you add a new section name or a new public declaration pattern, update site/src/lib/zig-api-loader.ts and its tests in site/src/lib/zig-api-loader.test.ts in the same change.
  1. Keep raw bindings and generated glue out of the authored API surface.

src/vulkan/vk.zig and src/regression_tests.zig are intentionally excluded from generated docs (EXCLUDED_MODULES in the loader).

  1. Files that import build-system modules (@import("gguf"), @import("zinc_rt"), etc.) cannot have their struct runtime layout (@sizeOf / @alignOf / @offsetOf) extracted by the standalone analyzer, because zig run does not resolve those imports. Add such files to EXCLUDED_STRUCT_EXTRACTOR_MODULES in the loader so the rest of the struct-layout extraction still succeeds. Their doc summary, field declarations, params, and returns continue to render.

Good Pattern

//! Create reusable compute command pools and command buffers.
//! @section Vulkan Runtime
//! The decode runtime uses these wrappers to record dispatches and synchronize compute work.

/// Command pool for allocating command buffers.
pub const CommandPool = struct {
    /// Create a command pool bound to the selected compute queue family.
    /// @param instance Active Vulkan instance and logical device.
    /// @returns A CommandPool ready to allocate compute command buffers.
    pub fn init(instance: *const Instance) !CommandPool {
        // ...
    }
};

Editing Checklist

Validation

Run these after doc-related Zig changes:

zig build test
cd site && bun test
cd site && npm run build

Success means:

Coverage Audit

Run this from the repo root to surface every place the contract is violated:

python3 .claude/skills/zig-docgen/scripts/audit_doc_coverage.py

The script walks src/**/*.zig and reports four classes of issue:

immediately above it

/// block

Exit code is 0 when clean, 1 when issues remain. Full machine-readable report

lands in /tmp/zig_doc_audit.json.

What the audit excludes

If you add new generated trees or non-Zig sources under src/, extend

EXCLUDE_DIR_PARTS in the audit script.

What the audit doesn't catch (yet)

Treat the audit as a floor, not a ceiling: passing it means you have some

doc-block on every public symbol, not that the prose is good.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.