diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0a52398..a3901fb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,21 @@ versions at once, go through every "Requires project changes" section in order, version you have. A new release = a new section at the top; we remove the oldest ones only once there are more than 20. +## Unreleased + +### Fixed +- **ipal-doctor finds the frontend by structure, not by the name `(frontend)`.** A site with its pages in another route + group (`src/app/(site)/[locale]`) was treated as single-language: false "missing" routes and a demand for the + single-language Markdown route. `layout-required` now takes any `app/()` (or `app` itself) that holds the + catch-all page, a localized one first; two candidates give a warning naming both. The lazy 404's server action may be + `notFoundView.ts` or `notFoundView.tsx` (pages.md), and the other required files accept their usual extensions + (`.ts`/`.tsx`, route `.js`). New: `ipal-doctor.json` `"layout": { "frontend": "src/app/(site)" }` for a layout the + doctor cannot tell; new export `findFrontend`. + +### What projects must update +- Nothing. After upgrading, drop any temporary `layout-required` silence in `ipal-doctor.json` that was added for a + route group with another name or a `notFoundView.tsx`, and run `pnpm exec ipal-doctor` again. + ## 1.15.1 A seed run that stops early now fails loudly instead of looking like a success. diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index efe768a..ff7cb30 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -422,7 +422,7 @@ CDN preconnect: `` (from env). Media: `normalizeFilenameHook` ``` src/ app/ - (frontend)/ + (frontend)/ # any route group name works ((site) …); ipal-doctor finds it by structure styles.css # Tailwind + @source on node_modules/@intecion/ipal-kit/dist [locale]/ # single-language: no [locale] (see i18n.md) layout.tsx # no ; + Header/Footer diff --git a/docs/agent/skills/ipal-doctor/SKILL.md b/docs/agent/skills/ipal-doctor/SKILL.md index 2f424b4..d0ce788 100644 --- a/docs/agent/skills/ipal-doctor/SKILL.md +++ b/docs/agent/skills/ipal-doctor/SKILL.md @@ -27,7 +27,8 @@ Full reference: `node_modules/@intecion/ipal-kit/docs/doctor.md`. { "rules": { "i18n-literals": { "off": true, "files": ["src/components/design/**"], "reason": "approved exception: styleguide labels" } } } ``` Keys: `off`, `severity`, `reason` (required), `until` (ISO date), `files` (globs). Top level: `domain`, `launched`, - `layout.allow`, `seen` (written by the doctor), `extraRules`. + `layout.allow`, `layout.frontend` (the pages' folder, e.g. `src/app/(site)` — found by structure otherwise; any route + group name works), `seen` (written by the doctor), `extraRules`. 5. Run again until it reports what the project expects (a new site: `--strict` → `0 error(s), 0 warning(s), 0 info`). ## Options and exit codes diff --git a/docs/agent/skills/ipal-reference/SKILL.md b/docs/agent/skills/ipal-reference/SKILL.md index 78d5554..87b070c 100644 --- a/docs/agent/skills/ipal-reference/SKILL.md +++ b/docs/agent/skills/ipal-reference/SKILL.md @@ -144,7 +144,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip ## 3. What the project wires itself -Mandatory set: AGENT.md §0b, skill **ipal-setup**; checks: **ipal-audit**, **ipal-seo-check**, **ipal-doctor** (`pnpm exec ipal-doctor` — the whole site against the team standard; `ipal-doctor.json` silences a rule with a reason, docs/doctor.md). +Mandatory set: AGENT.md §0b, skill **ipal-setup**; checks: **ipal-audit**, **ipal-seo-check**, **ipal-doctor** (`pnpm exec ipal-doctor` — the whole site against the team standard; `ipal-doctor.json` silences a rule with a reason; the pages may sit in any route group — `layout.frontend` names it when two qualify; docs/doctor.md). `$U` = `NEXT_PUBLIC_SERVER_URL` (e.g. `http://localhost:3000`). | element | file | minimal example | how to check | details | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index cc83792..9954564 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -810,13 +810,14 @@ Bin: `ipal-doctor` (`pnpm exec ipal-doctor [dir] [--json] [--md] [--strict] [--f | `planSkills({ dest, source })` | `@intecion/ipal-kit/doctor` | What `ipal-skills` would change: `missing`, `stale`, `retired` ipal-* folders. | | `parseToolOutput(text)`, `AUDIT_RULE_MAP` | `@intecion/ipal-kit/doctor` | Reads `[ERROR] title (n) — rule` output of `audit.sh` / `seo-check.mjs`; audit titles that are a doctor rule. | | `DEFAULT_SRC_ALLOW` | `@intecion/ipal-kit/doctor` | Top-level `src/` entries the convention allows (`layout.allow` extends it). | +| `findFrontend(ctx)` | `@intecion/ipal-kit/doctor` | The folder of the site's pages (`FrontendLayout`: `dir`, `multi`, `ambiguous`, `missingOverride`) — found by structure (any route group with the catch-all page, a localized one first); `layout.frontend` in `ipal-doctor.json` wins. | | `createLiveFetcher(url, { adminRoute, staging })` | `@intecion/ipal-kit/doctor` | Cached GET-only fetcher for the live rules. | | `runDeepProbe(ctx)` | `@intecion/ipal-kit/doctor` | `pnpm exec payload run …/dist/modules/doctor/probe.js` in the project → `DoctorStatus`. | | `collectDoctorStatus(payload)` | `@intecion/ipal-kit/doctor` | Read-only counts: `usersWithout2fa`, `pendingCookies`, `plugin`, `node`. | | `buildDoctorEndpoint({ tokenVar, access })` | `@intecion/ipal-kit/doctor` | `GET /ipal/doctor` (`/api/ipal/doctor`): 404 until the token variable (default `IPAL_DOCTOR_TOKEN`, ≥ 32 chars) is set, Bearer token or `access`, rate-limited. Added by `ipalKit` unless `doctor: false`. | **Types:** `DoctorRule`, `DoctorFinding`, `RuleFinding`, `DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`, -`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`. +`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`. ## Turnstile (`turnstile`) — details: `node_modules/@intecion/ipal-kit/docs/turnstile.md` diff --git a/docs/doctor.md b/docs/doctor.md index 2e2128b..3edffaf 100644 --- a/docs/doctor.md +++ b/docs/doctor.md @@ -84,7 +84,7 @@ Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'M | | `node-22` | warning | `engines.node` only 22 (`">=22 <23"`), `.nvmrc` / `.node-version` = 22; with `--deep`, the running Node | | | `pnpm-pinned` | info | `packageManager` is set | | | `deps-audit` | error on critical/high, info on moderate/low | `pnpm audit --prod` (registry) | -| layout | `layout-required` | error | the AGENT.md §3 files (proxy, i18n config, instrumentation, `lib/content`, every route, the `(frontend)` files, `blocks/registry.ts`, `collections/{Pages,Media}.ts`, `components/layout`, `components/forms/formClasses.ts`); an `ipal-audit-skip` key (`llms`, `llms-full`, `markdown`, `mcp`, `indexnow`) drops its file | +| layout | `layout-required` | error | the AGENT.md §3 files (proxy, i18n config, instrumentation, `lib/content`, every route, the frontend files — `layout`, `actions`, `not-found`, `notFoundView` (`.ts` or `.tsx`), the catch-all page — in the route group found by structure: any `app/()` (or `app` itself) holding `[locale]/[[...slug]]/page.tsx` or `[[...slug]]/page.tsx`, a localized one first, `(frontend)` on a tie (two matches → a warning naming both); `layout.frontend` sets it, `blocks/registry.ts`, `collections/{Pages,Media}.ts`, `components/layout`, `components/forms/formClasses.ts`); an `ipal-audit-skip` key (`llms`, `llms-full`, `markdown`, `mcp`, `indexnow`) drops its file | | | `layout-forbidden` | error | no `middleware.ts`, no `lib/{pages,locales,navigation}.ts`, `fields/{link,sectionHeader,sectionSettings}.ts` | | | `layout-extra` | info | `src/` entries outside the allow list (AGENT.md §3 + `seed/`, `design/`, `db.ts`, `env.rules.ts`, `content.config.ts`; extend with `layout.allow`) | | | `naming` | warning | block folders, collection and global files PascalCase, `scripts/*` kebab-case, no `index.ts` barrels | @@ -128,7 +128,7 @@ Every rule can be silenced, lowered or raised — **with a reason** — in `ipal { "domain": "example-studio.pl", "launched": false, - "layout": { "allow": ["scripts"] }, + "layout": { "allow": ["scripts"], "frontend": "src/app/(site)" }, "rules": { "csp": { "off": true, "reason": "new site: report-only until the reports are clean", "until": "2026-12-01" }, "i18n-literals": { "off": true, "files": ["src/components/design/**"], "reason": "approved exception: the styleguide labels" }, @@ -144,6 +144,7 @@ Every rule can be silenced, lowered or raised — **with a reason** — in `ipal | `domain` | the production domain (dots allowed) — the base of the database names. Without it: a non-local `NEXT_PUBLIC_SERVER_URL`, else the folder name minus `-web` | | `launched` | the site is live: seeds must then name their records. Also true when "Project decisions" has a line with "launch" and a date | | `layout.allow` | more top-level `src/` entries the convention allows | +| `layout.frontend` | the folder that holds the site's pages, e.g. `src/app/(site)` — only for a layout the doctor cannot tell (two route groups with pages); the route group's name is otherwise free | | `rules.` | `off` (silence), `severity` (`error` / `warning` / `info`), `reason` (**required** — an entry without one is ignored and reported), `until` (ISO date; after it the entry stops applying and the report says so), `files` (globs: only findings in those files). The id is the rule (`csp`) or an audit finding (`audit:collections-present`); `audit` covers all audit findings | | `seen` | first-seen dates the doctor stores itself (`csp-report-only`, for the 4-week CSP rule). It writes this key only outside CI (`CI` unset), not with `--json`, and only when the file exists | | `extraRules` | your own rule modules (paths relative to the project), each exporting `rules: DoctorRule[]` | @@ -199,10 +200,10 @@ console.log(formatReport(report)) `runDoctor`, `runDoctorCli`, `doctorRules`, `applySettings`, `runDeepProbe`, `createDoctorContext`, `loadDoctorConfig`, `formatReport`, `formatDriftTable`, `planSkills`, `parseToolOutput`, `AUDIT_RULE_MAP`, `AUDIT_SKIP_RULES`, -`DEFAULT_SRC_ALLOW`, `createLiveFetcher`, `buildDoctorEndpoint`, `collectDoctorStatus`, `globToRegExp`, `parseEnvFile`, +`DEFAULT_SRC_ALLOW`, `findFrontend`, `createLiveFetcher`, `buildDoctorEndpoint`, `collectDoctorStatus`, `globToRegExp`, `parseEnvFile`, `readAuditSkips`, `bareHost`, `expandSites`, `parseDoctorArgs`, `DOCTOR_USAGE`; types `DoctorRule`, `DoctorFinding`, `DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`, `DoctorSource`, `DoctorStatus`, `DoctorContext`, -`RuleFinding`, `RunDoctorOptions`, `DoctorEndpointOptions`. +`RuleFinding`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`. ## Environment variables diff --git a/reference/.agents/skills/ipal-doctor/SKILL.md b/reference/.agents/skills/ipal-doctor/SKILL.md index 2f424b4..d0ce788 100644 --- a/reference/.agents/skills/ipal-doctor/SKILL.md +++ b/reference/.agents/skills/ipal-doctor/SKILL.md @@ -27,7 +27,8 @@ Full reference: `node_modules/@intecion/ipal-kit/docs/doctor.md`. { "rules": { "i18n-literals": { "off": true, "files": ["src/components/design/**"], "reason": "approved exception: styleguide labels" } } } ``` Keys: `off`, `severity`, `reason` (required), `until` (ISO date), `files` (globs). Top level: `domain`, `launched`, - `layout.allow`, `seen` (written by the doctor), `extraRules`. + `layout.allow`, `layout.frontend` (the pages' folder, e.g. `src/app/(site)` — found by structure otherwise; any route + group name works), `seen` (written by the doctor), `extraRules`. 5. Run again until it reports what the project expects (a new site: `--strict` → `0 error(s), 0 warning(s), 0 info`). ## Options and exit codes diff --git a/reference/.agents/skills/ipal-reference/SKILL.md b/reference/.agents/skills/ipal-reference/SKILL.md index 78d5554..87b070c 100644 --- a/reference/.agents/skills/ipal-reference/SKILL.md +++ b/reference/.agents/skills/ipal-reference/SKILL.md @@ -144,7 +144,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip ## 3. What the project wires itself -Mandatory set: AGENT.md §0b, skill **ipal-setup**; checks: **ipal-audit**, **ipal-seo-check**, **ipal-doctor** (`pnpm exec ipal-doctor` — the whole site against the team standard; `ipal-doctor.json` silences a rule with a reason, docs/doctor.md). +Mandatory set: AGENT.md §0b, skill **ipal-setup**; checks: **ipal-audit**, **ipal-seo-check**, **ipal-doctor** (`pnpm exec ipal-doctor` — the whole site against the team standard; `ipal-doctor.json` silences a rule with a reason; the pages may sit in any route group — `layout.frontend` names it when two qualify; docs/doctor.md). `$U` = `NEXT_PUBLIC_SERVER_URL` (e.g. `http://localhost:3000`). | element | file | minimal example | how to check | details | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index cc83792..9954564 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -810,13 +810,14 @@ Bin: `ipal-doctor` (`pnpm exec ipal-doctor [dir] [--json] [--md] [--strict] [--f | `planSkills({ dest, source })` | `@intecion/ipal-kit/doctor` | What `ipal-skills` would change: `missing`, `stale`, `retired` ipal-* folders. | | `parseToolOutput(text)`, `AUDIT_RULE_MAP` | `@intecion/ipal-kit/doctor` | Reads `[ERROR] title (n) — rule` output of `audit.sh` / `seo-check.mjs`; audit titles that are a doctor rule. | | `DEFAULT_SRC_ALLOW` | `@intecion/ipal-kit/doctor` | Top-level `src/` entries the convention allows (`layout.allow` extends it). | +| `findFrontend(ctx)` | `@intecion/ipal-kit/doctor` | The folder of the site's pages (`FrontendLayout`: `dir`, `multi`, `ambiguous`, `missingOverride`) — found by structure (any route group with the catch-all page, a localized one first); `layout.frontend` in `ipal-doctor.json` wins. | | `createLiveFetcher(url, { adminRoute, staging })` | `@intecion/ipal-kit/doctor` | Cached GET-only fetcher for the live rules. | | `runDeepProbe(ctx)` | `@intecion/ipal-kit/doctor` | `pnpm exec payload run …/dist/modules/doctor/probe.js` in the project → `DoctorStatus`. | | `collectDoctorStatus(payload)` | `@intecion/ipal-kit/doctor` | Read-only counts: `usersWithout2fa`, `pendingCookies`, `plugin`, `node`. | | `buildDoctorEndpoint({ tokenVar, access })` | `@intecion/ipal-kit/doctor` | `GET /ipal/doctor` (`/api/ipal/doctor`): 404 until the token variable (default `IPAL_DOCTOR_TOKEN`, ≥ 32 chars) is set, Bearer token or `access`, rate-limited. Added by `ipalKit` unless `doctor: false`. | **Types:** `DoctorRule`, `DoctorFinding`, `RuleFinding`, `DoctorReport`, `DoctorConfig`, `DoctorRuleSetting`, `DoctorSeverity`, -`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`. +`DoctorSource`, `DoctorStatus`, `DoctorContext`, `RunDoctorOptions`, `DoctorEndpointOptions`, `FrontendLayout`. ## Turnstile (`turnstile`) — details: `node_modules/@intecion/ipal-kit/docs/turnstile.md` diff --git a/src/exports/doctor.ts b/src/exports/doctor.ts index f07fd38..db85f77 100644 --- a/src/exports/doctor.ts +++ b/src/exports/doctor.ts @@ -10,7 +10,8 @@ export { formatDriftTable, formatReport } from '../modules/doctor/format.js' export { bareHost, createDoctorContext, loadDoctorConfig, parseEnvFile, readAuditSkips } from '../modules/doctor/project.js' export type { DoctorContext } from '../modules/doctor/project.js' export { planSkills } from '../modules/doctor/rules/agents.js' -export { DEFAULT_SRC_ALLOW } from '../modules/doctor/rules/layout.js' +export { DEFAULT_SRC_ALLOW, findFrontend } from '../modules/doctor/rules/layout.js' +export type { FrontendLayout } from '../modules/doctor/rules/layout.js' export { createLiveFetcher } from '../modules/doctor/rules/live.js' export { AUDIT_RULE_MAP, parseToolOutput } from '../modules/doctor/rules/tooling.js' export { applySettings, AUDIT_SKIP_RULES, doctorRules, globToRegExp, runDeepProbe, runDoctor } from '../modules/doctor/run.js' diff --git a/src/modules/doctor/rules/layout.ts b/src/modules/doctor/rules/layout.ts index ef1e926..a3c5e22 100644 --- a/src/modules/doctor/rules/layout.ts +++ b/src/modules/doctor/rules/layout.ts @@ -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/()` 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', diff --git a/src/modules/doctor/types.ts b/src/modules/doctor/types.ts index 7089f3a..9ab7f68 100644 --- a/src/modules/doctor/types.ts +++ b/src/modules/doctor/types.ts @@ -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 /** First time a condition was seen (ISO date), e.g. `{ "csp-report-only": "2026-10-29" }`. */ seen?: Record diff --git a/test/doctor.test.ts b/test/doctor.test.ts index 0b33416..d170b30 100644 --- a/test/doctor.test.ts +++ b/test/doctor.test.ts @@ -145,6 +145,44 @@ describe('db-name', () => { }) }) +/** Every AGENT.md §3 file outside the frontend folder; `frontend` lists the files inside it. */ +function layoutProject(group: string, frontend: Record, extra: Record = {}) { + const files: Record = { ...base() } + for (const f of ['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', 'app/llms-full.txt/route.ts', 'app/md/[locale]/[[...slug]]/route.ts', 'app/api/mcp/route.ts', 'app/api/health/route.ts', 'app/indexnow-key.txt/route.ts', 'blocks/registry.ts', 'collections/Pages.ts', 'collections/Media.ts', 'components/layout/Header.tsx', 'components/forms/formClasses.ts']) {files[`src/${f}`] = ''} + for (const [f, content] of Object.entries(frontend)) {files[`src/app/${group}/${f}`] = content} + return project({ ...files, ...extra }) +} +const localizedFrontend = { '[locale]/[[...slug]]/page.tsx': '', '[locale]/actions.ts': '', '[locale]/layout.tsx': '', '[locale]/not-found.tsx': '', '[locale]/notFoundView.tsx': '' } + +describe('frontend route group (layout-required)', () => { + test('a (site) group with [locale] and notFoundView.tsx passes — the group name does not matter', async () => { + const report = await doctor(layoutProject('(site)', localizedFrontend), ['layout-required']) + expect(report.findings).toEqual([]) + }) + test('pages without a route group (app/[locale]) are found too', async () => { + expect((await doctor(layoutProject('', localizedFrontend), ['layout-required'])).findings).toEqual([]) + }) + test('layout.frontend wins; a folder that does not exist is reported', async () => { + const root = layoutProject('(web)', localizedFrontend, { 'src/app/(other)/[[...slug]]/page.tsx': '' }) + expect((await doctor(root, ['layout-required'], { config: { layout: { frontend: 'src/app/(web)' } } })).findings).toEqual([]) + const wrong = await doctor(root, ['layout-required'], { config: { layout: { frontend: 'src/app/(nope)' } } }) + expect(wrong.findings.map((f) => f.message)[0]).toBe('layout.frontend "src/app/(nope)" does not exist') + }) + test('two localized groups: the ambiguity is reported, (frontend) is checked', async () => { + const root = layoutProject('(site)', localizedFrontend, Object.fromEntries(Object.keys(localizedFrontend).map((f) => [`src/app/(frontend)/${f}`, '']))) + const report = await doctor(root, ['layout-required']) + expect(report.findings.map((f) => `${f.severity}: ${f.message}`)).toEqual([ + 'warning: several folders hold the site\'s pages: src/app/(frontend), src/app/(site) — checked src/app/(frontend)', + ]) + }) + test('a localized group wins over a single-language one; a missing page names the group it checked', async () => { + const { '[locale]/actions.ts': _, ...withoutActions } = localizedFrontend + const root = layoutProject('(site)', withoutActions, { 'src/app/(landing)/[[...slug]]/page.tsx': '' }) + const report = await doctor(root, ['layout-required']) + expect(report.findings.map((f) => f.message)).toEqual(['missing: src/app/(site)/[locale]/actions.ts']) + }) +}) + describe('layout, blocks, seeds, agents', () => { test('missing convention files and forbidden copies', async () => { const root = project({ ...base(), 'src/middleware.ts': '', 'src/payload.config.ts': '', 'src/scripts/x.ts': '' })