llms: RFC-compliant Accept negotiation, absolute llms.txt links, .md link rewriting#13
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three improvements to the AI-accessibility feature:
Accepthandling was a substring presence check:text/markdownishserved markdown, and q-values were ignored entirely —text/html, text/markdown;q=0returned markdown even thoughq=0means not acceptable. The header is now parsed properly (exact media-type matching, q-values honored,q=0excludes; malformed headers fall back to HTML), which also keeps shared caches keyed onVary: Acceptcorrect. Browser behavior is unchanged —*/*,text/html, andapplication/jsonall serve HTML as before./llms.txtis now trustworthy. Links are absolute (derived from the request), and.mdURLs 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.mdlink.html_to_markdown(), which gains arewrite_linksparameter, default on) rewrite internal page links to their.mdrenditions, preserving query strings and fragments; external,mailto:/tel:,/api/, asset, and already-.mdlinks are untouched.wrap_markdownhooks receive the rewritten markdown.Also: sync
llms_txthooks now run in a worker thread, so a hook callingctx.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%.