Skip to content

feat: serve markdown to agents via content negotiation - #28

Open
atinux wants to merge 1 commit into
mainfrom
feat/agent-friendly-markdown
Open

feat: serve markdown to agents via content negotiation#28
atinux wants to merge 1 commit into
mainfrom
feat/agent-friendly-markdown

Conversation

@atinux

@atinux atinux commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Improves the is-agentic score for comark.dev (currently 67/100) for every site built on this layer.

Written by an AI agent (OpenCode), reviewed by @atinux.

What changed

Markdown content negotiation (essential check, was failing)

  • New modules/markdown-rewrite.ts injects rewrites into .vercel/output/config.json after Nitro compiles, same approach as Docus' markdown-rewrite.
  • Accept: text/markdown (or a curl/* user-agent) on any page URL serves its /raw/** mirror; / serves /llms.txt. Responses carry content-type: text/markdown and vary: Accept.
  • Rewrites happen at the routing layer, before the ISR cache, so HTML and markdown variants are cached under different paths and can't poison each other. Docus enumerates pages from a prerendered llms.txt; this layer reads content at request time, so the rewrites use generic patterns instead (unit-tested in test/markdown-rewrite.test.ts).

Raw mirrors for versioned previews

  • /raw/tree/:branch/<page>.md and /raw/blob/:sha/<page>.md, sharing the preview-content instances (and ref validation) of the existing /api/content preview routes.
  • The "Copy page" / "Open in Chat" aside actions already built these URLs — they're now enabled on preview pages.

Agent-friendly 404s (essential check, was partial)

  • /raw/** misses return a real 404 with a short markdown body pointing at /llms.txt, /llms-full.txt, /raw/index.md, and the sitemap. Combined with the rewrites, an agent that guesses a wrong page URL gets a recoverable markdown 404.
  • app/error.vue gains home/documentation links.

llms.txt "when to use" section (recommended check)

  • New docs.llms.whenToUse app-config key, emitted as the first llms.txt section.

Organization JSON-LD (recommended check)

  • New docs.schemaOrg.organization sub-key, emitted as a top-level Organization node on the landing page (for contactPoint, address, sameAs).

Docs

  • New Markdown for agents section, updated configuration reference with an "Agent metadata" example, corrected the preview mirror URL shape in versioned-previews.

Verification

  • pnpm lint (no new warnings), pnpm test (130 passed, 6 new), pnpm typecheck clean.
  • NITRO_PRESET=vercel pnpm build → 8 routes injected into config.json (verified shape).
  • Dev-server smoke test: raw page 200 text/markdown + Vary: Accept, missing page 404 markdown body, /raw/tree/main/... 200.

Out of scope (needs changes in the comark.dev content repo)

  • "Flat heading structure" finding: comark.dev's homepage SSR has h1/h2/h3, but the hero demo renders a second <h1 id="hello-world"> which likely confuses the scanner.
  • Trust pages (/about, /contact, /privacy), docs.llms.whenToUse / organization values, OpenAPI spec decision.

Vercel routing-layer rewrites (Docus-style) send Accept: text/markdown
and curl requests to the /raw/** mirrors, ahead of the ISR cache.
Adds raw mirrors for /tree and /blob previews, markdown 404 bodies with
recovery links, an llms.txt when-to-use section, and an Organization
JSON-LD node.
@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark-docs-layer Ready Ready Preview Aug 22, 2026 6:13pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 22, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/comarkdown/comark-docs@28

commit: 2c33358

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