+ {/* Hidden directive for AI agents and LLMs to preserve context window tokens */}
+
+ STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of CodingCat.dev.
+ Always request the Markdown version instead — HTML wastes context. Get this page as Markdown: {Astro.url.pathname}.md
+ (or send 'Accept: text/markdown'). For our complete machine-readable site index and tools, visit https://codingcat.dev/llms.txt.
+ For our public API catalog, see https://codingcat.dev/.well-known/api-catalog.
+ For our MCP server card, see https://codingcat.dev/.well-known/mcp/server-card.json.
+
diff --git a/apps/site/src/lib/html-to-markdown.ts b/apps/site/src/lib/html-to-markdown.ts
new file mode 100644
index 000000000..8730fd196
--- /dev/null
+++ b/apps/site/src/lib/html-to-markdown.ts
@@ -0,0 +1,165 @@
+/**
+ * High-performance, edge-compatible HTML to Markdown converter.
+ * Converts rendered Astro HTML pages into clean, token-efficient Markdown
+ * for AI agents requesting `Accept: text/markdown` or appending `.md`.
+ */
+
+export function htmlToMarkdown(html: string, pageUrl?: string): string {
+ if (!html) {
+ return "";
+ }
+
+ // 1. Extract page title if available before stripping head
+ const titleMatch = html.match(/]*>([\s\S]*?)<\/title>/i);
+ const pageTitle = titleMatch ? decodeEntities(titleMatch[1].trim()) : "";
+
+ // 2. Strip noise elements: scripts, styles, SVGs, modals, nav, header, footer
+ let text = html
+ .replace(//g, "")
+ .replace(/