diff --git a/apps/website/public/llms.txt b/apps/website/public/llms.txt
index 65730c485e0..c5ce5ec68ff 100644
--- a/apps/website/public/llms.txt
+++ b/apps/website/public/llms.txt
@@ -44,9 +44,10 @@ Languages: comfy.org is published in English and Simplified Chinese, with a Japa
- Read this file, then the docs index at https://docs.comfy.org/llms.txt. Every docs page serves markdown when you append `.md` to its URL.
- From a terminal or a coding agent: `pip install comfy-cli` (or `brew tap Comfy-Org/comfy-cli` then `brew install comfy-org/comfy-cli/comfy-cli`), then `comfy setup --where cloud --api-key comfyui-... --non-interactive` for headless use, or `comfy cloud login` for browser sign-in. `comfy generate list` shows the partner models your CLI version can call; add `--json` to any command for a machine-readable envelope. `comfy generate` is in beta, so flag names can change.
- Over MCP: `claude mcp add --transport http comfy-cloud https://cloud.comfy.org/mcp` for Claude Code, or `codex mcp add comfy-cloud --url https://cloud.comfy.org/mcp` for Codex. Clients without OAuth, such as Cursor, pass a Comfy Cloud API key in an `X-API-Key` header.
+- From code, through Comfy Router: one API for hosted image, video, audio, 3D, and text models at `https://api.comfy.org`. Every model is called with `POST /v2/models/{provider}/{model}`, its own JSON body, and an `X-API-Key` header; the same key fetches a model's schema at `/v2/models/{provider}/{model}/openapi.json`. Start with the quickstart at https://docs.comfy.org/development/comfy-router/quickstart.md and look up model IDs at https://docs.comfy.org/development/comfy-router/models.md.
- API keys are created in the browser at https://platform.comfy.org/profile/api-keys, start with `comfyui-`, and are shown once. Store them in `COMFY_API_KEY`.
- Generation on Comfy Cloud spends the account's credits. Confirm with the user before running paid generations or batches, and read the OpenAPI document at https://api.comfy.org/openapi before choosing an API operation.
-- The model catalog changes weekly. Check https://comfy.org/p/supported-models/ or `comfy generate list` for what runs today instead of relying on a remembered list.
+- The model catalog changes weekly. For hosted models you try in the browser or call through Comfy Router, check https://comfy.org/hub/models/ (one page per model); for models that run in ComfyUI, including open-weight models you run locally, check https://comfy.org/p/supported-models/. `comfy generate list` shows what your CLI can call. Check these instead of relying on a remembered list.
## Notes for AI systems
@@ -59,7 +60,9 @@ Languages: comfy.org is published in English and Simplified Chinese, with a Japa
- [Docs index for agents](https://docs.comfy.org/llms.txt): Machine-readable index of the full documentation.
- [Docs full text for agents](https://docs.comfy.org/llms-full.txt): The complete documentation as one markdown file.
-- [Model catalog for agents](https://comfy.org/p/supported-models/llms.txt): Machine-readable index of every supported-model page; each page also has a markdown twin at its URL plus `.md`.
+- [Hosted model catalog for agents](https://comfy.org/hub/models.md): Markdown list of the hosted model pages, grouped by provider; each model page also has a markdown twin at its URL with the trailing slash replaced by `.md`.
+- [Comfy Router models for agents](https://docs.comfy.org/development/comfy-router/models.md): Every model you can call through Comfy Router, with its model ID and input and output modality.
+- [Model catalog for agents](https://comfy.org/p/supported-models/llms.txt): Machine-readable index of every supported-model page; each page also has a markdown twin at its URL with the trailing slash replaced by `.md`.
- [Docs homepage as markdown](https://docs.comfy.org/index.md): Append `.md` to any docs URL for its markdown twin.
- [Developer Platform for agents](https://platform.comfy.org/llms.txt): What platform.comfy.org is for and which of its pages need a browser.
- [Comfy API OpenAPI document](https://api.comfy.org/openapi): OpenAPI specification for api.comfy.org.
@@ -95,7 +98,7 @@ Languages: comfy.org is published in English and Simplified Chinese, with a Japa
## Models
- [Supported Models](https://comfy.org/p/supported-models/): Directory of 380+ models that run in ComfyUI: image, video, audio, 3D, and utility models, each with its own page. Machine-readable catalog at https://comfy.org/p/supported-models/llms.txt.
-- [Models Overview](https://comfy.org/hub/models/): Hosted AI models you can try in the browser and call through the Comfy API, with a page per model. For the full list of models that run in ComfyUI, see Supported Models above.
+- [Models Overview](https://comfy.org/hub/models/): Hosted models you can run in the browser and call through Comfy Router, one page per model. Markdown version at https://comfy.org/hub/models.md. For the full list of models that run in ComfyUI, see Supported Models above.
- [ChatGPT Images 2.5 (OpenAI, image model)](https://comfy.org/chatgpt-image-2.5/): Generate new images, edit existing visuals, and direct results with reference images in repeatable ComfyUI workflows through Partner Nodes.
- [Qwen-Image 2.1 (Alibaba Qwen, image model)](https://comfy.org/qwen-image-2.1/): Open-weights 7B image model that generates and edits in one checkpoint, with native 2K output, RGBA transparency, and accurate English and Chinese text rendering.
- [Flux 3 (Black Forest Labs, video model)](https://comfy.org/flux-3/): Multimodal model: video with native audio, up to 20 seconds per generation, from text, image, video, or keyframes.
diff --git a/apps/website/scripts/validate-llms-txt-links.ts b/apps/website/scripts/validate-llms-txt-links.ts
index 480b4eff96e..d358d84ad2f 100644
--- a/apps/website/scripts/validate-llms-txt-links.ts
+++ b/apps/website/scripts/validate-llms-txt-links.ts
@@ -1,40 +1,64 @@
-import { existsSync, readFileSync } from 'node:fs'
-import { join } from 'node:path'
+import { existsSync, readFileSync, readdirSync } from 'node:fs'
+import { join, relative, sep } from 'node:path'
-import { findCanonicalDrift, parseLlmsTxtLinks } from '@/lib/llms-txt'
+import {
+ findStaleLinks,
+ isLinkedFile,
+ isWorkflowsAppPath,
+ sectionLlmsFiles
+} from '@/lib/llms-txt'
const DIST_DIR = join(process.cwd(), 'dist')
const CANONICAL_LINK = /]*\brel=["']canonical["'][^>]*>/i
const HREF_ATTRIBUTE = /\bhref=["']([^"']+)["']/i
-/** `/download/` -> `dist/download/index.html`, `/` -> `dist/index.html`. */
+/** `/download` -> `dist/download/index.html`, `/hub/models.md` -> `dist/hub/models.md`. */
function distFileFor(pathname: string): string {
const trimmed = pathname.replace(/^\/|\/$/g, '')
- return join(DIST_DIR, trimmed, 'index.html')
+ return isLinkedFile(trimmed)
+ ? join(DIST_DIR, trimmed)
+ : join(DIST_DIR, trimmed, 'index.html')
}
-/** The built page's own `rel="canonical"` href, or undefined if it wasn't built. */
+/** The built page's own `rel="canonical"` href, or undefined for a file or an unbuilt path. */
function canonicalFor(pathname: string): string | undefined {
- let html: string
- try {
- html = readFileSync(distFileFor(pathname), 'utf8')
- } catch {
- return undefined
- }
+ const file = distFileFor(pathname)
+ if (!file.endsWith('.html') || !existsSync(file)) return undefined
+ const html = readFileSync(file, 'utf8')
const canonicalTag = CANONICAL_LINK.exec(html)?.[0]
const canonical =
canonicalTag === undefined
? undefined
: HREF_ATTRIBUTE.exec(canonicalTag)?.[1]
if (canonical === undefined) {
- throw new Error(
- `Built page ${distFileFor(pathname)} has no canonical link.`
- )
+ throw new Error(`Built page ${file} has no canonical link.`)
}
return canonical
}
+function isServed(pathname: string): boolean {
+ return isWorkflowsAppPath(pathname) || existsSync(distFileFor(pathname))
+}
+
+function redirectSources(): string[] {
+ const vercel = JSON.parse(
+ readFileSync(join(process.cwd(), 'vercel.json'), 'utf8')
+ ) as { redirects: { source: string }[] }
+ return vercel.redirects.map(({ source }) => source)
+}
+
+/** `dist/llms-full.txt` plus every `llms.txt` the build wrote, root first. */
+function builtLlmsFiles(): string[] {
+ const sectionFiles = sectionLlmsFiles(
+ readdirSync(DIST_DIR, { recursive: true }).map(String),
+ sep
+ )
+ return ['llms.txt', 'llms-full.txt', ...sectionFiles].map((file) =>
+ join(DIST_DIR, file)
+ )
+}
+
function main(): void {
if (!existsSync(DIST_DIR)) {
console.error(
@@ -43,27 +67,24 @@ function main(): void {
process.exit(1)
}
- const llmsTxt = readFileSync(
- join(process.cwd(), 'public', 'llms.txt'),
- 'utf8'
+ const checks = { redirectSources: redirectSources(), isServed, canonicalFor }
+ const files = builtLlmsFiles()
+ const failures = files.flatMap((file) =>
+ findStaleLinks(readFileSync(file, 'utf8'), checks).map(
+ (problem) => ` ${relative(process.cwd(), file)}: ${problem}`
+ )
)
- const links = parseLlmsTxtLinks(llmsTxt)
- const drift = findCanonicalDrift(links, canonicalFor)
- if (drift.length > 0) {
+ if (failures.length > 0) {
console.error(
- `llms.txt link validation failed (${drift.length} stale link(s)):`
+ `llms.txt link validation failed (${failures.length} stale link(s)):`
)
- for (const { link, canonical } of drift) {
- console.error(
- ` [${link.title}](${link.url}) now canonicalizes to ${canonical}`
- )
- }
+ for (const failure of failures) console.error(failure)
process.exit(1)
}
process.stdout.write(
- `llms.txt link validation passed for ${links.length} link(s).\n`
+ `llms.txt link validation passed for ${files.length} file(s).\n`
)
}
diff --git a/apps/website/src/config/llms-txt.test.ts b/apps/website/src/config/llms-txt.test.ts
index 955b1fc7ece..0bbb8831016 100644
--- a/apps/website/src/config/llms-txt.test.ts
+++ b/apps/website/src/config/llms-txt.test.ts
@@ -6,6 +6,7 @@ import {
findRedirectedLinks,
internalLinks,
isLlmsTxtLinkLine,
+ isWorkflowsAppPath,
normalizePath,
parseLlmsTxtLinks
} from '@/lib/llms-txt'
@@ -18,13 +19,11 @@ import { workshopPagePaths } from './workshop-page-content'
const llmsTxt = readFileSync(join(websiteRoot, 'public', 'llms.txt'), 'utf8')
const pagesDir = join(websiteRoot, 'src', 'pages')
-const vercelRedirectSources = new Set(
- (
- JSON.parse(readFileSync(join(websiteRoot, 'vercel.json'), 'utf8')) as {
- redirects: { source: string }[]
- }
- ).redirects.map((redirect) => normalizePath(redirect.source))
-)
+const vercelRedirectSources = (
+ JSON.parse(readFileSync(join(websiteRoot, 'vercel.json'), 'utf8')) as {
+ redirects: { source: string }[]
+ }
+).redirects.map((redirect) => redirect.source)
/**
* Pages that exist in src/pages but are deliberately kept out of llms.txt.
@@ -79,20 +78,6 @@ function isExcludedPage(page: string): boolean {
*/
const BUILD_ARTIFACTS = new Set(['/sitemap-index.xml', '/llms-full.txt'])
-/**
- * Route shapes of the Comfy Workflows app, which lives in another repo and is
- * served behind the comfy.org router. Only these shapes may be linked; the
- * slugs themselves are verified against the live site, not here.
- */
-const WORKFLOW_APP_ROUTES = [
- /^\/workflows$/,
- /^\/workflows\/creators$/,
- /^\/workflows\/category\/[a-z0-9-]+$/,
- /^\/workflows\/model(\/[a-z0-9-]+)?$/,
- /^\/workflows\/use-cases(\/[a-z0-9-]+)?$/,
- /^\/[a-z]{2}(-[A-Za-z]{2})?\/workflows$/
-]
-
/** Turn `src/pages/learning/[category]/[slug].astro` into a matcher for `/learning/x/y`. */
function pageMatchers(root: string): {
static: Set
@@ -166,13 +151,14 @@ describe('llms.txt', () => {
})
it('only links comfy.org paths that this site (or the workflows app) serves', () => {
- const unknown = internalPaths.filter((path) => {
+ const unknown = internalPaths.filter((linked) => {
+ const path = linked.replace(/\.md$/, '')
if (BUILD_ARTIFACTS.has(path) || modelsPages.has(path)) return false
if (
path.startsWith('/workflows') ||
/^\/[a-z]{2}(-[A-Za-z]{2})?\/workflows/.test(path)
) {
- return !WORKFLOW_APP_ROUTES.some((route) => route.test(path))
+ return !isWorkflowsAppPath(path)
}
if (path.startsWith('/zh-CN')) {
const base = normalizePath(path.slice('/zh-CN'.length))
@@ -209,13 +195,6 @@ describe('llms.txt', () => {
expect(listedButExcluded).toEqual([])
})
- it('uses only literal redirect sources for stale link checks', () => {
- const patternedSources = [...vercelRedirectSources].filter((source) =>
- /[:*(]/.test(source)
- )
- expect(patternedSources).toEqual([])
- })
-
it('links a redirect destination rather than its stale source', () => {
const redirected = findRedirectedLinks(links, vercelRedirectSources)
expect(redirected).toEqual([])
diff --git a/apps/website/src/lib/llms-txt.test.ts b/apps/website/src/lib/llms-txt.test.ts
index 62a1c95bf7f..39bf76eff1d 100644
--- a/apps/website/src/lib/llms-txt.test.ts
+++ b/apps/website/src/lib/llms-txt.test.ts
@@ -3,9 +3,14 @@ import { describe, expect, it } from 'vitest'
import {
findCanonicalDrift,
findRedirectedLinks,
+ findStaleLinks,
internalLinks,
+ isLinkedFile,
+ isWorkflowsAppPath,
normalizePath,
- parseLlmsTxtLinks
+ parseLlmsTxtLinks,
+ redirectSourcePattern,
+ sectionLlmsFiles
} from './llms-txt'
describe('parseLlmsTxtLinks', () => {
@@ -74,9 +79,7 @@ describe('findRedirectedLinks', () => {
}
]
- expect(findRedirectedLinks(links, new Set(['/cloud/enterprise']))).toEqual(
- links
- )
+ expect(findRedirectedLinks(links, ['/cloud/enterprise'])).toEqual(links)
})
it('leaves a link that is not a redirect source alone', () => {
@@ -88,9 +91,7 @@ describe('findRedirectedLinks', () => {
}
]
- expect(findRedirectedLinks(links, new Set(['/cloud/enterprise']))).toEqual(
- []
- )
+ expect(findRedirectedLinks(links, ['/cloud/enterprise'])).toEqual([])
})
it('ignores external links even if their path matches a redirect source', () => {
@@ -98,7 +99,168 @@ describe('findRedirectedLinks', () => {
{ title: 'Docs', url: 'https://docs.comfy.org/pricing', description: '' }
]
- expect(findRedirectedLinks(links, new Set(['/pricing']))).toEqual([])
+ expect(findRedirectedLinks(links, ['/pricing'])).toEqual([])
+ })
+})
+
+const groupedSource = '/p/supported-models/:slug(4x-ultrasharp|flux1-dev-fp8)'
+
+describe('redirectSourcePattern', () => {
+ it.for([
+ ['/cloud/enterprise', '/cloud/enterprise', true],
+ ['/cloud/enterprise/', '/cloud/enterprise', true],
+ ['/cloud/enterprise', '/cloud/enterprise-plans', false],
+ ['/p/supported-models/:slug', '/p/supported-models/flux1-dev-fp8', true],
+ ['/p/supported-models/:slug', '/p/supported-models', false],
+ ['/p/supported-models/:slug', '/p/supported-models/a/b', false],
+ ['/models/:path*', '/models', true],
+ ['/models/:path*', '/models/a/b.md', true],
+ ['/models/:path*', '/models-v2', false],
+ ['/models/:path+', '/models', false],
+ ['/models/:path+', '/models/a/b', true],
+ ['/hub/models.md', '/hub/modelsxmd', false],
+ [`${groupedSource}.md`, '/p/supported-models/flux1-dev-fp8.md', true],
+ [`${groupedSource}.md/`, '/p/supported-models/4x-ultrasharp.md', true],
+ [`${groupedSource}.md`, '/p/supported-models/flux1-dev-fp8', false],
+ [groupedSource, '/p/supported-models/flux1-dev-fp8-extra', false],
+ [groupedSource, '/p/supported-models/xflux1-dev-fp8', false],
+ [groupedSource, '/p/supported-models/flux1-dev-fp8/a', false]
+ ] as const)('%s matches %s: %s', ([source, path, matches]) => {
+ expect(redirectSourcePattern(source).test(path)).toBe(matches)
+ })
+
+ it.for([
+ '/posts/:id(\\d+)',
+ '/payment/(.*)',
+ '/p/:slug(a|b)?',
+ '/p/:slug(a|(b))',
+ '/cloud{/enterprise}',
+ '/docs\\.md'
+ ])('rejects unsupported source syntax %s', (source) => {
+ expect(() => redirectSourcePattern(source)).toThrow(/Unsupported/)
+ })
+})
+
+describe('findRedirectedLinks with constrained slug sources', () => {
+ const link = (path: string) => ({
+ title: 'FLUX.1 Dev fp8',
+ url: `https://comfy.org${path}`,
+ description: ''
+ })
+
+ it.for([
+ [groupedSource, '/p/supported-models/flux1-dev-fp8/', true],
+ [groupedSource, '/p/supported-models/flux1-dev-fp8', true],
+ [groupedSource, '/p/supported-models/flux1-dev-fp8.md', true],
+ [`${groupedSource}/`, '/p/supported-models/flux1-dev-fp8/', true],
+ [`${groupedSource}/`, '/p/supported-models/4x-ultrasharp', true],
+ [`${groupedSource}.md`, '/p/supported-models/flux1-dev-fp8.md', true],
+ [groupedSource, '/p/supported-models/flux-1-dev/', false],
+ [`${groupedSource}/`, '/p/supported-models/flux-1-dev', false],
+ [`${groupedSource}.md`, '/p/supported-models/flux-1-dev.md', false],
+ ['/p/supported-models/:slug', '/p/supported-models/flux-1-dev.md', true],
+ ['/cloud/enterprise', '/cloud/enterprise/', true]
+ ] as const)('source %s flags %s: %s', ([source, path, flagged]) => {
+ expect(findRedirectedLinks([link(path)], [source])).toEqual(
+ flagged ? [link(path)] : []
+ )
+ })
+})
+
+describe('isWorkflowsAppPath', () => {
+ it.for([
+ ['/workflows', true],
+ ['/workflows/use-cases/image-to-3d', true],
+ ['/ja/workflows', true],
+ ['/hub/workflows/flux', false],
+ ['/workflows/unknown/shape', false]
+ ] as const)('%s: %s', ([path, expected]) => {
+ expect(isWorkflowsAppPath(path)).toBe(expected)
+ })
+})
+
+describe('findStaleLinks', () => {
+ const sectionFile = (url: string) =>
+ [
+ '# Supported models in ComfyUI',
+ '',
+ '## Models',
+ '',
+ `- [FLUX.1 Dev](${url}): Open model`,
+ '- [Docs](https://docs.comfy.org/p/supported-models/gone): External'
+ ].join('\n')
+ const builtPages = new Set([
+ '/p/supported-models/flux-1-dev',
+ '/p/supported-models/flux-1-dev.md'
+ ])
+ const checks = {
+ redirectSources: ['/models/:path*', '/cloud/enterprise'],
+ isServed: (path: string) => builtPages.has(path),
+ canonicalFor: () => undefined
+ }
+
+ it('fails a link that matches a pattern redirect source', () => {
+ expect(
+ findStaleLinks(
+ sectionFile('https://comfy.org/models/flux-1-dev.md'),
+ checks
+ )
+ ).toEqual([
+ '[FLUX.1 Dev](https://comfy.org/models/flux-1-dev.md) is a redirect source'
+ ])
+ })
+
+ it('fails the markdown twin of a redirected page', () => {
+ expect(
+ findStaleLinks(
+ sectionFile('https://comfy.org/cloud/enterprise.md'),
+ checks
+ )
+ ).toEqual([
+ '[FLUX.1 Dev](https://comfy.org/cloud/enterprise.md) is a redirect source'
+ ])
+ })
+
+ it('fails a link that matches a literal redirect source', () => {
+ expect(
+ findStaleLinks(sectionFile('https://comfy.org/cloud/enterprise/'), checks)
+ ).toEqual([
+ '[FLUX.1 Dev](https://comfy.org/cloud/enterprise/) is a redirect source'
+ ])
+ })
+
+ it('fails a link the build did not produce', () => {
+ expect(
+ findStaleLinks(
+ sectionFile('https://comfy.org/p/supported-models/removed.md'),
+ { ...checks, redirectSources: [] }
+ )
+ ).toEqual([
+ '[FLUX.1 Dev](https://comfy.org/p/supported-models/removed.md) is not in the build'
+ ])
+ })
+
+ it('fails a built page that canonicalizes elsewhere', () => {
+ expect(
+ findStaleLinks(
+ sectionFile('https://comfy.org/p/supported-models/flux-1-dev/'),
+ {
+ ...checks,
+ canonicalFor: () => 'https://comfy.org/hub/models/flux-1-dev/'
+ }
+ )
+ ).toEqual([
+ '[FLUX.1 Dev](https://comfy.org/p/supported-models/flux-1-dev/) now canonicalizes to https://comfy.org/hub/models/flux-1-dev/'
+ ])
+ })
+
+ it('passes once the link points at the live page', () => {
+ expect(
+ findStaleLinks(
+ sectionFile('https://comfy.org/p/supported-models/flux-1-dev.md'),
+ checks
+ )
+ ).toEqual([])
})
})
@@ -172,3 +334,31 @@ describe('findCanonicalDrift', () => {
])
})
})
+
+describe('isLinkedFile', () => {
+ it.for([
+ ['/hub/models.md', true],
+ ['/hub/models/local/llms.txt', true],
+ ['/sitemap-index.xml', true],
+ ['/models/catalogue.json', true],
+ ['/models/flux.dev', false],
+ ['/models/ltx-2.5', false]
+ ] as const)('%s is a file: %s', ([pathname, isFile]) => {
+ expect(isLinkedFile(pathname)).toBe(isFile)
+ })
+})
+
+describe('sectionLlmsFiles', () => {
+ it.for([
+ ['/', ['llms.txt', 'p/models/llms.txt', 'p/models', 'hub/llms.txt']],
+ ['\\', ['llms.txt', 'p\\models\\llms.txt', 'p\\models', 'hub\\llms.txt']]
+ ] as const)(
+ 'finds the section files with separator %s',
+ ([separator, entries]) => {
+ expect(sectionLlmsFiles(entries, separator)).toEqual([
+ 'hub/llms.txt',
+ 'p/models/llms.txt'
+ ])
+ }
+ )
+})
diff --git a/apps/website/src/lib/llms-txt.ts b/apps/website/src/lib/llms-txt.ts
index 2dd8cfe3f71..aaa37dad600 100644
--- a/apps/website/src/lib/llms-txt.ts
+++ b/apps/website/src/lib/llms-txt.ts
@@ -24,6 +24,24 @@ export function isLlmsTxtLinkLine(line: string): boolean {
return LINK_LINE.test(line)
}
+const LINKED_FILE = /\.(md|txt|xml|json)$/i
+
+/** Whether a linked pathname is a file (`/hub/models.md`), not a page such as `/models/flux.dev`. */
+export function isLinkedFile(pathname: string): boolean {
+ return LINKED_FILE.test(pathname)
+}
+
+/** The section `llms.txt` files among `readdirSync` entries, with `/` separators on every OS. */
+export function sectionLlmsFiles(
+ entries: readonly string[],
+ separator: string
+): string[] {
+ return entries
+ .map((entry) => entry.split(separator).join('/'))
+ .filter((file) => file.endsWith('/llms.txt'))
+ .sort()
+}
+
/** Drop a trailing slash so `/foo/` and `/foo` compare equal; keep `/` as `/`. */
export function normalizePath(path: string): string {
const trimmed = path.replace(/\/+$/, '')
@@ -41,18 +59,94 @@ export function internalLinks(
.map(({ link, url }) => ({ path: normalizePath(url.pathname), link }))
}
+const SOURCE_PARAM = /(\/:\w+\*|:\w+\+|:\w+\([^()]*\)|:\w+)/
+const LITERAL_ALTERNATIVE = /^[\w.~-]+$/
+const UNSUPPORTED_SOURCE_SYNTAX = /[(){}?*+\\]/
+
+function escapeRegExp(text: string): string {
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
+}
+
+function constrainedParamPattern(param: string): string {
+ const alternatives = param.slice(param.indexOf('(') + 1, -1).split('|')
+ if (
+ !alternatives.every((alternative) => LITERAL_ALTERNATIVE.test(alternative))
+ )
+ throw new Error(`Unsupported redirect source constraint: ${param}`)
+ return `(?:${alternatives.map(escapeRegExp).join('|')})`
+}
+
+/**
+ * A Vercel redirect source as a case-sensitive matcher for a normalized
+ * pathname: literal sources plus the `:slug`, `:slug(a|b)`, `:path+` and
+ * `/:path*` params Vercel accepts. Other path-to-regexp syntax throws rather
+ * than silently matching nothing.
+ */
+export function redirectSourcePattern(source: string): RegExp {
+ const pattern = normalizePath(source)
+ .split(SOURCE_PARAM)
+ .map((part, index) => {
+ if (index % 2 === 0) {
+ if (UNSUPPORTED_SOURCE_SYNTAX.test(part))
+ throw new Error(`Unsupported redirect source syntax: ${source}`)
+ return escapeRegExp(part)
+ }
+ if (part.endsWith(')')) return constrainedParamPattern(part)
+ if (part.endsWith('*')) return '(?:/.*)?'
+ if (part.endsWith('+')) return '.+'
+ return '[^/]+'
+ })
+ .join('')
+ return new RegExp(`^${pattern}$`)
+}
+
/**
- * llms.txt links whose path is itself a redirect source (e.g. a Vercel edge
- * redirect). Linking a redirect source instead of its destination means an
- * agent following the link pays an extra hop, and the description sitting
- * next to it describes whatever page the redirect used to point at.
+ * llms.txt links whose path, or the page a `.md` twin copies, matches a
+ * redirect source (e.g. a Vercel edge redirect). Linking a redirect source
+ * instead of its destination means an agent following the link pays an extra
+ * hop, and the description sitting next to it describes whatever page the
+ * redirect used to point at.
*/
export function findRedirectedLinks(
links: LlmsTxtLink[],
- redirectSources: ReadonlySet
+ redirectSources: readonly string[]
+): LlmsTxtLink[] {
+ const patterns = redirectSources.map(redirectSourcePattern)
+ return internalLinks(links)
+ .filter(({ path }) =>
+ [path, path.replace(/\.md$/, '')].some((candidate) =>
+ patterns.some((pattern) => pattern.test(candidate))
+ )
+ )
+ .map(({ link }) => link)
+}
+
+/**
+ * Route shapes of the Comfy Workflows app, which lives in another repo and is
+ * served behind the comfy.org router. Only these shapes may be linked; the
+ * slugs themselves are verified against the live site, not here.
+ */
+const WORKFLOWS_APP_ROUTES = [
+ /^\/workflows$/,
+ /^\/workflows\/creators$/,
+ /^\/workflows\/category\/[a-z0-9-]+$/,
+ /^\/workflows\/model(\/[a-z0-9-]+)?$/,
+ /^\/workflows\/use-cases(\/[a-z0-9-]+)?$/,
+ /^\/[a-z]{2}(-[A-Za-z]{2})?\/workflows$/
+]
+
+/** Whether a normalized pathname is a Comfy Workflows app page, not this site's. */
+export function isWorkflowsAppPath(path: string): boolean {
+ return WORKFLOWS_APP_ROUTES.some((route) => route.test(path))
+}
+
+/** comfy.org links whose path neither the build nor another app behind the router serves. */
+function findMissingLinks(
+ links: LlmsTxtLink[],
+ isServed: (path: string) => boolean
): LlmsTxtLink[] {
return internalLinks(links)
- .filter(({ path }) => redirectSources.has(path))
+ .filter(({ path }) => !isServed(path))
.map(({ link }) => link)
}
@@ -88,3 +182,30 @@ export function findCanonicalDrift(
}
return drift
}
+
+export interface LlmsTxtChecks {
+ redirectSources: readonly string[]
+ isServed: (path: string) => boolean
+ canonicalFor: (path: string) => string | undefined
+}
+
+/** Every stale link in one llms.txt body, one readable line per problem. */
+export function findStaleLinks(
+ llmsTxt: string,
+ { redirectSources, isServed, canonicalFor }: LlmsTxtChecks
+): string[] {
+ const links = parseLlmsTxtLinks(llmsTxt)
+ const redirected = findRedirectedLinks(links, redirectSources)
+ const live = links.filter((link) => !redirected.includes(link))
+ const missing = findMissingLinks(live, isServed)
+ const built = live.filter((link) => !missing.includes(link))
+ const describe = (link: LlmsTxtLink) => `[${link.title}](${link.url})`
+ return [
+ ...redirected.map((link) => `${describe(link)} is a redirect source`),
+ ...missing.map((link) => `${describe(link)} is not in the build`),
+ ...findCanonicalDrift(built, canonicalFor).map(
+ ({ link, canonical }) =>
+ `${describe(link)} now canonicalizes to ${canonical}`
+ )
+ ]
+}