Guide

AI authoring tutorial

How to build a prompt that makes any capable model produce valid Pustaka pages — and why the pustaka check loop, not the prompt, is what actually guarantees quality.

The core idea

Prompts are advisory; validators are binding. Pustaka exists so that a page has a mechanically checkable definition of “correct”. You don't need a perfect prompt — you need a good prompt plus a gate the model must pass.

The four inputs of a good prompt

Every successful generation gives the model exactly four things. Skip one and you get the classic failure modes listed further down.

The role goes in the system prompt: paste ai/SYSTEM_PROMPT.md verbatim. It defines the output contract — complete files only, never fragments — and the rules the model is accountable to.

The standard is ai/AUTHORING_SPEC.md, attached as context. It carries the page skeleton, the component vocabulary, the folder/prefix rule, the registry key order and the changelog policy.

The state is the current registry: docs/assets/toc.js plus every docs/assets/toc/*.js part. Without it the model invents group names, duplicates ids, or registers into a part that doesn't exist.

The task is your one-paragraph brief: the page path, the audience, the sections you want, and which components to use. Be specific about the path — it determines the asset prefix.

A prompt template you can copy

Paste ai/SYSTEM_PROMPT.md as the system prompt, attach the spec and registry files, then send a task message shaped like this:

prompt
TASK
Create guide/rate-limits.html — "API rate limits".

AUDIENCE
Backend integrators who already have an API key.

SECTIONS (h2, in order)
1. quotas-by-plan   — table of Free/Pro/Enterprise limits
2. burst-behaviour  — how the token bucket refills
3. handling-429     — retry pattern, with a code block
4. usage-trends     — ECharts line chart, one series per plan tier

COMPONENTS
- one .adm warning about the 429 retry-after header
- .ctabs for curl vs Node retry examples
- chart id "rl-usage", lazy-init + theme sync per spec §7

REGISTER
Part: assets/toc/guide.js  ·  Group: "Guide"
Place after "authoring", before "charts".

RELEASE
This is a new documented capability ⇒ minor bump: add a changelog
entry and update product.semver.

Why name the h2 ids yourself

Section ids become search anchors and the “on this page” rail — they are part of your information architecture, and they are the one thing that is expensive to change later because external links point at them. Dictate them; let the model write the prose.

The correction loop

This is the whole workflow. Steps 3–5 repeat until the validator is silent.

1 · Promptrole + spec + registry + task
→
2 · Save filescomplete pages & ToC part
→
3 · Checkpustaka check ./docs
→
4 · Paste errorsverbatim, no editing

Paste validator output back exactly as printed. The messages are written to be machine-actionable — they name the file, the rule and the fix — so editing or summarising them only removes information the model needs.

bash
$ ./pustaka check ./docs
  ✗ guide/rate-limits.html — must reference "../assets/site.css"
      (folder depth 1 ⇒ prefix "../")
  ✗ guide/rate-limits.html — 1 of 4 h2 headings missing an id
  ✗ guide/rate-limits.html — link "charts.html" resolves to "guide/charts.html",
      which does not exist
  3 problem(s) found

# paste those three lines to the model, save its re-emitted files, then:
$ ./pustaka check ./docs
  ✓ 14 pages valid, registry consistent

Failure modes and their fixes

These are the mistakes models actually make, in rough order of frequency. All of them are caught by check — this table is for understanding, not for vigilance.

Root-level asset paths on a nested page

The model writes assets/site.css for a page in guide/. Cause: the spec's example skeleton is root-level. Fix: state the page path in the task and remind it of the ../-per-level rule — or scaffold with pustaka new first and ask the model to fill in the body only.

Emitting a registry fragment instead of the whole file

You get “add this entry to your toc part” instead of the file. Cause: conversational drift over long sessions. Fix: the system prompt forbids fragments — re-state it, and ask for the complete assets/toc/<part>.js.

Scripts placed after </main>

Charts work on first load and vanish after an in-site navigation. Cause: normal HTML habit. Fix: page scripts must be the last children inside <main class="doc"> so partial swaps carry and re-execute them.

Missing the chart dispose guard

Re-visiting a chart page leaks ECharts instances. Fix: follow the spec's pattern — dispose window.__pustakaCharts before re-initialising.

Changelog entry without the version bump

The release section is added but product.semver is untouched (or the reverse). Fix: they are one unit; the system prompt says so, and a release isn't done until both land.

Valid but hollow prose

The one failure check cannot catch: structurally perfect pages that explain nothing. Fix: put concrete constraints in the task (“show a worked 429 retry with real header names”) and skim the prose before merging. Validators check form, not insight.

No failure modes match — try a broader word.

Make the gate automatic

The same command that closes the AI loop is your pull-request gate, so human and machine contributions are held to one standard:

yaml
# .github/workflows/docs.yml
name: docs
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with: { go-version: 'stable' }
      - run: go build -o pustaka .
      - run: ./pustaka check ./docs

Proof this works

The three Infrastructure pages came out of this loop: scaffolded with pustaka new, written against the spec, then rejected by check until the asset prefixes and the registered ids agreed.