ipal-doctor: find the frontend route group by structure, accept notFoundView.tsx

layout-required no longer assumes src/app/(frontend): any app/(<group>) (or app itself) holding the
catch-all page is the frontend, a localized one first; two candidates give a warning naming both.
notFoundView.ts or .tsx, and the usual extensions for the other required files. New
ipal-doctor.json layout.frontend override and export findFrontend. Reported by Say Diamonds
(1.15.1, route group (site)).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-03 15:00:05 +01:00
co-authored by Claude Opus 5.5
parent a515bd6851
commit b80770bc2e
13 changed files with 154 additions and 45 deletions
+78 -32
View File
@@ -33,35 +33,72 @@ export const DEFAULT_SRC_ALLOW = [
/** The project renders blocks through the library registry — then components/ui/ only holds overrides. */
export const usesBlockRegistry = (ctx: DoctorContext) => /createBlockRegistry\s*\(/.test(stripComments(ctx.read(`${ctx.src}blocks/registry.ts`)))
/** Files AGENT.md §3 expects, with the `ipal-audit-skip` key that drops each one. */
function requiredFiles(ctx: DoctorContext): Array<[string, string?]> {
const multi = ctx.exists(`${ctx.src}app/(frontend)/[locale]`)
const fe = multi ? 'app/(frontend)/[locale]' : 'app/(frontend)'
/** Where the site's pages live: the route group (any name) and whether it has a `[locale]` segment. */
export type FrontendLayout = {
/** Other folders that look like the frontend too (set `layout.frontend` to choose). */
ambiguous: string[]
/** Folder relative to src/, e.g. `app/(site)`, `app/(frontend)` or `app` (no route group). */
dir: string
/** `layout.frontend` names a folder that does not exist. */
missingOverride?: string
multi: boolean
}
const PAGE = ['page.tsx', 'page.ts', 'page.jsx', 'page.js']
const has = (ctx: DoctorContext, dir: string, names: string[]) => names.some((n) => ctx.exists(`${ctx.src}${dir}/${n}`))
/**
* The frontend folder, found by structure rather than by name (a route group's name never reaches the URL):
* `ipal-doctor.json` `layout.frontend` wins; else every `app/(<group>)` except `(payload)`, and `app` itself,
* holding the catch-all page — one with a `[locale]` page first. No match → `app/(frontend)` (the convention).
*/
export function findFrontend(ctx: DoctorContext): FrontendLayout {
const override = ctx.config.layout?.frontend?.trim()
if (override) {
const dir = override.replace(/^\.?\//, '').replace(/^src\//, '').replace(/\/+$/, '')
return { ambiguous: [], dir, missingOverride: ctx.exists(`${ctx.src}${dir}`) ? undefined : override, multi: ctx.exists(`${ctx.src}${dir}/[locale]`) }
}
const groups = ['app', ...ctx.list(`${ctx.src}app`).filter((n) => /^\(.+\)$/.test(n) && n !== '(payload)').map((n) => `app/${n}`)]
const localized = groups.filter((g) => has(ctx, `${g}/[locale]/[[...slug]]`, PAGE))
const single = groups.filter((g) => has(ctx, `${g}/[[...slug]]`, PAGE))
const best = localized.length ? localized : single
if (!best.length) {return { ambiguous: [], dir: 'app/(frontend)', multi: ctx.exists(`${ctx.src}app/(frontend)/[locale]`) }}
const dir = best.includes('app/(frontend)') ? 'app/(frontend)' : best[0]
return { ambiguous: best.filter((g) => g !== dir), dir, multi: localized.length > 0 }
}
/** Files AGENT.md §3 expects — each as its accepted names — with the `ipal-audit-skip` key that drops it. */
function requiredFiles(ctx: DoctorContext, frontend: FrontendLayout): Array<[string[], string?]> {
const fe = frontend.multi ? `${frontend.dir}/[locale]` : frontend.dir
const ts = (base: string) => [`${base}.ts`, `${base}.tsx`]
const tsx = (base: string) => [`${base}.tsx`, `${base}.ts`, `${base}.jsx`, `${base}.js`]
const route = (dir: string) => [`${dir}/route.ts`, `${dir}/route.js`]
return [
['proxy.ts'],
['i18n.config.ts'],
['instrumentation.ts'],
['payload.config.ts'],
['lib/content.ts'],
['app/manifest.ts'],
['app/robots.ts'],
['app/sitemap.xml/route.ts'],
['app/llms.txt/route.ts', 'llms'],
['app/llms-full.txt/route.ts', 'llms-full'],
[multi ? 'app/md/[locale]/[[...slug]]/route.ts' : 'app/md/[[...slug]]/route.ts', 'markdown'],
['app/api/mcp/route.ts', 'mcp'],
['app/api/health/route.ts'],
['app/indexnow-key.txt/route.ts', 'indexnow'],
[`${fe}/layout.tsx`],
[`${fe}/actions.ts`],
[`${fe}/not-found.tsx`],
[`${fe}/notFoundView.ts`],
[`${fe}/[[...slug]]/page.tsx`],
['blocks/registry.ts'],
['collections/Pages.ts'],
['collections/Media.ts'],
['components/layout'],
['components/forms/formClasses.ts'],
[ts('proxy')],
[ts('i18n.config')],
[ts('instrumentation')],
[ts('payload.config')],
[ts('lib/content')],
[tsx('app/manifest')],
[tsx('app/robots')],
[route('app/sitemap.xml')],
[route('app/llms.txt'), 'llms'],
[route('app/llms-full.txt'), 'llms-full'],
[route(frontend.multi ? 'app/md/[locale]/[[...slug]]' : 'app/md/[[...slug]]'), 'markdown'],
[route('app/api/mcp'), 'mcp'],
[route('app/api/health')],
[route('app/indexnow-key.txt'), 'indexnow'],
[tsx(`${fe}/layout`)],
[ts(`${fe}/actions`)],
[tsx(`${fe}/not-found`)],
// the lazy 404's server action: .tsx when its fallback holds JSX (pages.md)
[ts(`${fe}/notFoundView`)],
[tsx(`${fe}/[[...slug]]/page`)],
[ts('blocks/registry')],
[ts('collections/Pages')],
[ts('collections/Media')],
[['components/layout']],
[ts('components/forms/formClasses')],
// components/ui/: blocks-ui-required (only without createBlockRegistry)
]
}
@@ -74,10 +111,19 @@ export const layoutRules: DoctorRule[] = [
id: 'layout-required',
check: (ctx) => {
if (!ctx.src) {return [{ message: 'no src/ folder (AGENT.md §3)', severity: 'error' }]}
const missing = requiredFiles(ctx).filter(([file, key]) => !(key && ctx.auditSkips.has(key)) && !ctx.exists(`${ctx.src}${file}`))
return missing.length
? [{ fix: 'the ipal-setup skill (stage named by the file)', message: `missing: ${missing.map(([f]) => `${ctx.src}${f}`).join(', ')}`, severity: 'error' }]
: []
const frontend = findFrontend(ctx)
const out: RuleFinding[] = []
if (frontend.missingOverride) {
out.push({ file: 'ipal-doctor.json', fix: 'point layout.frontend at the folder that holds the pages, e.g. "src/app/(site)"', message: `layout.frontend "${frontend.missingOverride}" does not exist`, severity: 'error' })
}
if (frontend.ambiguous.length) {
out.push({ fix: `set "layout": { "frontend": "${ctx.src}${frontend.dir}" } in ipal-doctor.json (or the other one)`, message: `several folders hold the site's pages: ${[frontend.dir, ...frontend.ambiguous].map((d) => `${ctx.src}${d}`).join(', ')} — checked ${ctx.src}${frontend.dir}`, severity: 'warning' })
}
const missing = requiredFiles(ctx, frontend).filter(([names, key]) => !(key && ctx.auditSkips.has(key)) && !names.some((n) => ctx.exists(`${ctx.src}${n}`)))
if (missing.length) {
out.push({ fix: 'the ipal-setup skill (stage named by the file)', message: `missing: ${missing.map(([names]) => `${ctx.src}${names[0]}`).join(', ')}`, severity: 'error' })
}
return out
},
docs: 'docs/agent/AGENT.md#3-project-structure-and-naming',
group: 'layout',
+5 -1
View File
@@ -42,7 +42,11 @@ export type DoctorConfig = {
extraRules?: string[]
/** true once the site is live: seeds must then name their records. */
launched?: boolean
layout?: { allow?: string[] }
/**
* `allow`: more top-level src/ entries. `frontend`: the folder that holds the site's pages, e.g. `src/app/(site)` —
* by default the doctor finds it by structure (any route group with the catch-all page).
*/
layout?: { allow?: string[]; frontend?: string }
rules?: Record<string, DoctorRuleSetting>
/** First time a condition was seen (ISO date), e.g. `{ "csp-report-only": "2026-10-29" }`. */
seen?: Record<string, string>