Skip to content

llms: RFC-compliant Accept negotiation, absolute llms.txt links, .md link rewriting#13

Merged
shivamsn97 merged 1 commit into
mainfrom
fix/llms-negotiation
Jul 7, 2026
Merged

llms: RFC-compliant Accept negotiation, absolute llms.txt links, .md link rewriting#13
shivamsn97 merged 1 commit into
mainfrom
fix/llms-negotiation

Conversation

@shivamsn97

Copy link
Copy Markdown
Member

Three improvements to the AI-accessibility feature:

  1. Content negotiation now follows RFC 9110. Accept handling was a substring presence check: text/markdownish served markdown, and q-values were ignored entirely — text/html, text/markdown;q=0 returned markdown even though q=0 means not acceptable. The header is now parsed properly (exact media-type matching, q-values honored, q=0 excludes; malformed headers fall back to HTML), which also keeps shared caches keyed on Vary: Accept correct. Browser behavior is unchanged — */*, text/html, and application/json all serve HTML as before.
  2. The generated /llms.txt is now trustworthy. Links are absolute (derived from the request), and .md URLs are only advertised for pages whose markdown actually resolves — pages that would redirect are listed at their canonical HTML URL instead of a dead-end .md link.
  3. Converted markdown keeps agents on the markdown channel. Auto-converted pages (and html_to_markdown(), which gains a rewrite_links parameter, default on) rewrite internal page links to their .md renditions, preserving query strings and fragments; external, mailto:/tel:, /api/, asset, and already-.md links are untouched. wrap_markdown hooks receive the rewritten markdown.

Also: sync llms_txt hooks now run in a worker thread, so a hook calling ctx.render_default() can never block the event loop (async-hook guidance documented).

The llms guide is updated to match. Tests: 2247 passed, coverage 96.47%.

…s.txt, .md link rewriting

- wants_markdown() now parses Accept per RFC 9110: exact media-type
  matching (no substring hits), q-values honored, q=0 excluded —
  'text/html, text/markdown;q=0' gets HTML, 'text/markdownish' no
  longer serves markdown. Malformed headers fall back to HTML.
- The generated /llms.txt emits absolute URLs and links .md only for
  pages whose markdown actually resolves; pages that would redirect
  are listed at their canonical HTML URL instead of a dead-end .md.
- Auto-converted markdown rewrites internal page links to their .md
  renditions (query strings/fragments preserved; external, mailto:,
  /api/, asset, and already-.md links untouched). Public util gains
  html_to_markdown(..., rewrite_links=True); wrap_markdown hooks see
  the rewritten markdown.
- Sync llms_txt hooks now run in a worker thread so hooks calling
  ctx.render_default() never block the event loop; async-hook
  discipline documented on render_default.

Suite: 2247 passed, coverage 96.47%. Ruff clean.
@shivamsn97 shivamsn97 merged commit 2c0ed00 into main Jul 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant