WORKFLOW · multi-agent-orchestration
Workflow: generated llms.txt, checked in CI
A build script that generates llms.txt from the docs tree plus a CI job that fails when the committed file goes stale, so the machine-readable index is a build product, not a chore.
✓ verified 2026-07-18 · stack: github-actions, github · source
llms.txt is a proposed convention: a markdown file at the site root that
gives language models a curated index of what matters and where
(llmstxt.org). The failure mode is not writing one,
it is writing one once: a hand-maintained index drifts from the docs it
indexes and then misleads every agent that trusts it. Generate it from the
tree and gate staleness in CI. This site does exactly that for its own
surface (the index at /llms.txt is built from the content collections on
every deploy); the version below is the generic form for a docs repo.
#!/usr/bin/env node// Generates llms.txt from docs/ frontmatter. Deterministic: stable// ordering, no timestamps, so the diff is meaningful and CI can compare.import { readdirSync, readFileSync, writeFileSync } from 'node:fs';import { join } from 'node:path';
const DOCS = 'docs';const SITE = 'https://docs.example.com';
const entries = [];for (const f of readdirSync(DOCS, { recursive: true })) { if (!String(f).endsWith('.md')) continue; const raw = readFileSync(join(DOCS, String(f)), 'utf8'); const title = /^#\s+(.+)$/m.exec(raw)?.[1]; const summary = /^>\s+(.+)$/m.exec(raw)?.[1] ?? ''; if (!title) continue; const path = String(f).replace(/\.md$/, '/').replaceAll('\\', '/'); entries.push(`- [${title}](${SITE}/${path})${summary ? `: ${summary}` : ''}`);}
const body = [ '# Example Docs', '', '> Curated index for language models: the load-bearing pages, one line each.', '', '## Docs', ...entries.sort(), '',].join('\n');
writeFileSync('llms.txt', body);console.log(`llms.txt: ${entries.length} entries`);name: llms-txt
on: pull_request: paths: - "docs/**" - "llms.txt" - "scripts/generate-llms-txt.mjs"
permissions: contents: read
jobs: fresh: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 24 - run: node scripts/generate-llms-txt.mjs # The committed file must match what the tree generates. A diff here # means someone edited docs without regenerating (or hand-edited # llms.txt, which is the same mistake from the other side). - name: Fail if llms.txt is stale run: | if ! git diff --exit-code llms.txt; then echo "llms.txt is stale: run scripts/generate-llms-txt.mjs and commit." >&2 exit 1 fiWhat it does
- Generates the index from frontmatter and first headings, deterministically (stable sort, no timestamps), so regeneration is idempotent and the PR diff shows exactly which entries a docs change added or removed.
- The CI job regenerates and compares: a stale committed
llms.txtfails the PR with the one-line fix. The index cannot drift from the tree, which is the property that makes it trustworthy to agents at all. - The format follows the llms.txt proposal: an H1, a blockquote summary, then sections of one-line markdown links (llmstxt.org). Curation lives in what the generator includes, not in hand edits.
- Static-site variants can skip the committed file entirely and build the
index as a route at deploy time; this site’s own
/llms.txtis that variant, and it is the receipt that the pattern holds in production.
Failure modes
- Generation is curation by rule, and rules over-include. An index of everything is as useless to a model as no index. Add an exclusion list (drafts, changelogs, internal notes) to the generator rather than trusting the tree to stay clean.
- Summaries matter more than titles. The one-line description after each link is what a model selects on; docs without a blockquote summary produce bare entries, and the generator makes that visible rather than inventing text.
- The proposal is a convention, not a standard. Adoption and consumer behaviour vary; publish it because it is cheap and self-maintaining once gated, not because every crawler reads it today.
- Hand edits are load-bearing mistakes. The CI gate treats a
hand-edited
llms.txtas stale by construction; that is deliberate, and the error message says where the change belongs.
Verified against the llms.txt format proposal at llmstxt.org and this
site’s own generated /llms.txt route as the working example, 2026-07-18.