Files
supabase/apps/www/ard-catalog.test.ts
Anthony Lio 0daddc4551 feat(docs): agent feedback capabilities (#53115)
## Problem

- an agent that finds a wrong docs page leading to use a different
method gets no report
- mcp server and the cli can send feedback, but no page tells agents to
report docs problems

## Solution

- adds a note for ai agents at the top of each guide's markdown version,
so agents report wrong pages
- adds an agent-only instructions page with a disabled nav entry, so
agents learn how to write and send a report
- adds a "report documentation problems" section to the ai tools guide,
so users can approve, turn off or delete reports
- changes the mcp guide to say that `submit_feedback` takes
documentation feedback, so the tool list matches the new use
- adds the instructions page to `llms.txt`, so agents that start from
supabase.com find it

Linear: DEPR-698

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. open the preview
[/docs/guides/auth.md](https://docs-git-anthonylio-depr-698-explore-agent-feed-2bdb50-supabase.vercel.app/docs/guides/auth.md),
and make sure that the page starts with the "Note for AI agents"
blockquote
2. make sure that the note links to `agent-feedback.md`, tells the agent
to read it before the final reply, and asks "Send this report to
Supabase?"
3. open the preview
[/docs/guides/ai-tools/agent-feedback.md](https://docs-git-anthonylio-depr-698-explore-agent-feed-2bdb50-supabase.vercel.app/docs/guides/ai-tools/agent-feedback.md),
and make sure that the page has the five-line report template and no
agent note
4. open the preview
[/llms.txt](https://zone-www-dot-com-git-anthonylio-depr-698-explor-a825b7-supabase.vercel.app/llms.txt),
and make sure that it lists "Report documentation problems" with the
`.md` link

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-11 14:38:47 +02:00

167 lines
5.9 KiB
TypeScript

import { existsSync, promises as fs } from 'node:fs'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import { AGENT_RESOURCES } from './lib/agent-resources'
import rewrites from './lib/rewrites'
const CANONICAL_ORIGIN = 'https://supabase.com'
const NOT_AGENT_RESOURCES: Record<string, string> = {
'ard.json': 'the catalog itself',
'api-catalog':
'peer catalog (RFC 9727); its resources, the Management API spec and the MCP server, have their own entries',
'ai-catalog.json': 'legacy ARD alias, rewritten to ard.json',
'mcp-registry-auth': 'domain-ownership verification token',
'openai-apps-challenge': 'domain-ownership verification token',
'security.txt': 'vulnerability disclosure contact',
vercel: 'Vercel toolbar dev tooling',
}
type ArdEntry = { identifier: string; url: string }
type LinksetLink = { href: string }
type LinksetMember = { anchor: string } & Record<string, string | LinksetLink[]>
const rewriteSources: string[] = rewrites.map((rewrite: { source: string }) => rewrite.source)
async function loadArdCatalog(): Promise<{ entries: ArdEntry[] }> {
const raw = await fs.readFile(
path.join(process.cwd(), 'public', '.well-known', 'ard.json'),
'utf-8'
)
return JSON.parse(raw)
}
async function loadApiCatalog(): Promise<{ linkset: LinksetMember[] }> {
const raw = await fs.readFile(
path.join(process.cwd(), 'public', '.well-known', 'api-catalog'),
'utf-8'
)
return JSON.parse(raw)
}
function wellKnownRewriteSources(): string[] {
return rewriteSources
.filter((source) => source.startsWith('/.well-known/'))
.map((source) => source.replace('/.well-known/', ''))
}
function sameOriginPathname(url: string): string | null {
const parsed = new URL(url)
return parsed.origin === CANONICAL_ORIGIN ? parsed.pathname : null
}
function docsGuideSource(pathname: string): string | null {
const prefix = '/docs/guides/'
if (!pathname.startsWith(prefix)) return null
return path.join(
process.cwd(),
'..',
'docs',
'content',
'guides',
`${pathname.slice(prefix.length).replace(/\.md$/, '')}.mdx`
)
}
function resolvesLocally(pathname: string): boolean {
const publicFile = path.join(process.cwd(), 'public', pathname)
const appRoute = path.join(process.cwd(), 'app', pathname, 'route.ts')
const docsGuide = docsGuideSource(pathname)
return (
existsSync(publicFile) ||
existsSync(appRoute) ||
rewriteSources.includes(pathname) ||
(docsGuide !== null && existsSync(docsGuide))
)
}
const RESOLVES_TO = 'a file in public/, an app route, a rewrite source, or a docs guide'
describe('agent discovery catalog (.well-known/ard.json)', () => {
it('every .well-known surface is cataloged or explicitly marked as not an agent resource', async () => {
const { entries } = await loadArdCatalog()
const catalogedUrls = entries.map((entry) => entry.url)
const wellKnownDir = path.join(process.cwd(), 'public', '.well-known')
const dirents = await fs.readdir(wellKnownDir, { withFileTypes: true })
const surfaces = [...dirents.map((dirent) => dirent.name), ...wellKnownRewriteSources()]
expect(surfaces.length).toBeGreaterThan(0)
for (const surface of surfaces) {
if (surface in NOT_AGENT_RESOURCES) continue
const cataloged = catalogedUrls.some((url) =>
url.startsWith(`${CANONICAL_ORIGIN}/.well-known/${surface}`)
)
expect(
cataloged,
`new .well-known surface "${surface}": add an entry for it to public/.well-known/ard.json, or add it to NOT_AGENT_RESOURCES in this test with the reason it doesn't belong in the catalog`
).toBe(true)
}
})
it('every same-origin catalog entry resolves to a public file, app route, or rewrite', async () => {
const { entries } = await loadArdCatalog()
expect(entries.length).toBeGreaterThan(0)
for (const entry of entries) {
const pathname = sameOriginPathname(entry.url)
if (pathname === null) continue
expect(
resolvesLocally(pathname),
`ard.json entry "${entry.identifier}" points at ${entry.url}, but ${pathname} is not ${RESOLVES_TO}: the catalog is advertising a dead URL`
).toBe(true)
}
})
})
describe('API catalog (.well-known/api-catalog)', () => {
it('lists every described API as a catalog item and describes every listed item', async () => {
const [catalog, ...apis] = (await loadApiCatalog()).linkset
expect(catalog.anchor).toBe(`${CANONICAL_ORIGIN}/.well-known/api-catalog`)
const itemHrefs = (catalog.item as LinksetLink[]).map((link) => link.href).sort()
const apiAnchors = apis.map((api) => api.anchor).sort()
expect(apiAnchors.length).toBeGreaterThan(0)
expect(itemHrefs).toEqual(apiAnchors)
})
it('every same-origin link resolves to a public file, app route, rewrite, or docs guide', async () => {
const { linkset } = await loadApiCatalog()
const hrefs = linkset.flatMap((member) =>
Object.entries(member).flatMap(([relation, value]) =>
relation === 'anchor'
? [value as string]
: (value as LinksetLink[]).map((link) => link.href)
)
)
expect(hrefs.length).toBeGreaterThan(0)
for (const href of hrefs) {
const pathname = sameOriginPathname(href)
if (pathname === null) continue
expect(
resolvesLocally(pathname),
`api-catalog links to ${href}, but ${pathname} is not ${RESOLVES_TO}`
).toBe(true)
}
})
})
describe('llms.txt agent resources', () => {
it('every same-origin resource resolves to a public file, app route, rewrite, or docs guide', () => {
expect(AGENT_RESOURCES.length).toBeGreaterThan(0)
for (const resource of AGENT_RESOURCES) {
const pathname = sameOriginPathname(resource.url)
if (pathname === null) continue
expect(
resolvesLocally(pathname),
`llms.txt lists ${resource.url}, but ${pathname} is not ${RESOLVES_TO}`
).toBe(true)
}
})
})