Tired of explaining to my agent how to get zig stdlib documentation, I decided to create a tool to mimic how zig generates html docs. I call it zigdoc. It does a couple of special things:
- It is version aware. It’ll run
zig versionbefore doing anything, because it will also runzig envto find the stdlib directory. In 0.14 this is in json, in 0.15 its zon…thus we must know the version. - It is LLM friendly. Output is intentionally sparse. You are intended to keep calling
zigdocwith ever growing accessors to explore the public API. It gives an LLM all of the public api, the symbol signature, and location to source file on disc + line number - agents can do pretty much anything with that info. - It is import friendly.
zigdocruns a custom build runner when it detects abuild.zigin the current working directory. That build runner is also version aware. It spits out a json dump of ALL module import names and resolved paths. From there, it indexes the root and any imported file for all public api. This way, you can get generated documentation for any module your project imports.
Say I’m making a project and have imported zeit. But I don’t know how to use it
$ zigdoc zeit
Symbol: zeit
Location: /Users/tim/.cache/zig/p/zeit-0.6.0-5I6bk4t8AgCP0UGGHVF_khlmWZkAF5XtfQWEKCyLoptU/src/zeit.zig:1Category: namespace
Type: namespace (file root)
Types:
timezone
TimeZone
Location
Instant
Month
Duration
Weekday
Date
TimeComparison
Time
Functions:
local
loadTimeZone
instant
daysSinceEpoch
isLeapYear
weekdayFromDays
civilFromDays
daysFromCivil
Constants:
utc
Oh, I wonder what that Date type is?
$ zigdoc zeit.Date
Symbol: zeit.Date
Location: /Users/tim/.cache/zig/p/zeit-0.6.0-5I6bk4t8AgCP0UGGHVF_khlmWZkAF5XtfQWEKCyLoptU/src/zeit.zig:479
Category: container
Type: struct
Documentation:
Fields:
year: i32
month: Month
day: u5
Functions:
eql
compare