# AGENT.md — rules for AI (Payload 3 + Next 16 + @intecion/ipal-kit) > **Who this is for:** an AI agent (Antigravity, Claude Code, Cursor) working in a client > project built on ipal-kit. **Read all of it before your first change.** The rules are > hard, with no workarounds. API details for each module: `docs/.md` (map in > §12). Installation, deployment, migration and Gitea are covered in the document for humans: > [the developer guide (PROGRAMISTA.md)](../dev/PROGRAMISTA.md). > > **In the project:** > - a short `AGENTS.md` in the root (template in §13) that points to this file in > `node_modules/@intecion/ipal-kit/docs/agent/AGENT.md` — do not copy the rules, a copy goes stale; > (`pnpm exec ipal-skills` adds/refreshes the `ipal-kit:start…end` block with this pointer); > - skills in `.agents/skills/` (§14) — copied from the package with one command, refreshed > after every ipal-kit update; > - **the full plugin map** — every option, env variable, route, layout component, import > map entry, hook, collection, global and every export: the **`ipal-reference`** skill > (`.agents/skills/ipal-reference/SKILL.md` + `resources/api.md`). Before you write > anything "from scratch", check there. --- ## Main rule — the plugin helps, never limits ipal-kit is a plugin: it helps the project and never limits it. Every module can be turned off on its own; every default (access rules, fields, hooks, labels, routes, collections, globals) can be overridden and **the project config wins**; safe defaults have an option to loosen/extend them; the plugin exports building blocks (helpers, builders, hooks), not just finished features; it does not force dependencies, routes, UI or data shape where an option or an exported building block is enough. **In practice:** before you write something from scratch or start fighting the plugin — find the option or the exported builder (module docs §12, types in `dist/**/*.d.ts`). It is missing → **plugin gap** (report + a marked workaround in the project code), never patching `node_modules` or forking the package. **Docs language:** all ipal-kit docs, this guide and the skills are written in English. Write new rules, AGENTS.md entries and plugin-gap reports in English. **Seeding on production** (details: `node_modules/@intecion/ipal-kit/docs/seeding.md`). Write seeds with `createSeeder` from `@intecion/ipal-kit/seed` (the templates do) — it enforces every rule below: - Seeds are create-only and idempotent: match by the default-locale slug / form title / the global, skip what exists. - Never delete; never seed users, passwords or secrets; globals: fill only empty fields; no media uploads. - Every locale written separately with `fallbackLocale: false`; `context: { disableRevalidate: true, ipalSkipIndexNow: true }`. - On production: dry run first (`SEED_DRY_RUN=1`), back up the database (Coolify **Backup now**), then the real run. - `SEED_UPDATE=1` on production / a non-local database only with `IPAL_SEED_ALLOW_PROD_UPDATE=1`, after a backup; records an editor changed are always skipped and reported (`skip (edited)`) — never use `SEED_FORCE=1` there. - Schema and one-off data fixes → Payload migrations; field renames with content → **ipal-migrate-fields**; content → seeds. --- ## 0. COMPASS (if you remember only this) 1. **ipal-kit is mandatory.** A feature the plugin has goes through the plugin. Something is missing → report (§1.3, plugin gap) + a marked workaround, not a silent patch. 2. **Nothing hardcoded.** Text, image, link, file, company data → admin panel. Domains, keys → `.env`. Also in an `||` fallback and in `catch`. 3. **Next 16 = `proxy.ts`.** NEVER `middleware.ts`. 4. **No explicit ``, with ISR and `generateStaticParams`** — otherwise metadata lands in `` and SEO breaks. 5. **Minimum collections.** ipalKit adds Users, company data/navigation are globals, FAQ/hero are blocks. 6. **A section = a composition of UI primitives.** `buildLinksField()` + ``, upload + ``, `
` + ``. No `ctaLabel`/`pdfUrl` fields. **A clear panel** (§6.5a): repeated items = an "+ Add …" array with `rowLabel`, never `cta1`/`cta2`; labels short and in the panel's languages (`{ en, pl }`, guide `docs/dev/admin-ux.md`); no empty "just in case" fields. 7. **Renderers from the plugin:** `RenderBlocks` (not a `switch`), `RenderRichText` (not your own Lexical parser), `useForm` (not hand-made form plumbing). 8. **No `any` and no `@ts-ignore`.** Types from `@/payload-types`, `unknown` + guard. 9. **One source of truth** — `i18n.config.ts`, `lib/content.ts`, never copies. 10. **"Done" only after** a local `pnpm build` + the checks from §11. 11. **Every site has the MANDATORY SET from §0b** — SEO, GEO (llms.txt, Markdown, MCP), R2, Turnstile, forms from the builder. `ipal-audit` checks that it is wired, `ipal-seo-check` — that it works. There is no "I'll do it later". **How to add…** (details in the skill from §14) | What | How | |---|---| | a page | in the panel: Pages + blocks, no code (§5.1) | | a section (block) | `src/blocks//config.ts` + `Component.tsx`, an entry in `blocks/registry.ts`, the block in the Pages `layout` field → `pnpm generate:types` (+ `pnpm payload generate:importmap` with `rowLabel`) — **ipal-block** | | a form | the Forms panel (builder) from the seed `scripts/seed-form-*.ts`, a block with ``, sending via `sendForm` — **ipal-form** | | a language | `i18n.config.ts` (the only place) + a Postgres migration + content in the new language — **ipal-locale-add** | | a collection with URLs | `content: { collections: [...] }` in `ipalKit` and `createContentHelpers` (§5.4) — **ipal-collection** | --- ## 0b. MANDATORY SET — every site, no exceptions These are not options. Every project has **all** the items below, wired through the plugin. Data is missing (domain, keys, bucket)? Wire the code anyway — it works once the values are entered in `.env` / the panel, and you list what is missing in the report. You skip an item **only** on a client decision recorded in `AGENTS.md` (the `ipal-audit-skip:` line, below). The "Check" column: **A** = `ipal-audit` (code), **S** = `ipal-seo-check` (running site), **P** = a test in the panel. Full code: PROGRAMISTA.md §2. | # | Area | What must exist (file) | Plugin API | Check | |---|---|---|---|---| | 1 | i18n + routing | `src/proxy.ts`, `[locale]/[[...slug]]/page.tsx` = `createPageRoute(content, {…})` + a literal `revalidate`, `not-found.tsx` = `createNotFoundPage(content, { load })` + `notFoundView.ts` (`renderNotFoundView`) | `createProxy`, `createContentHelpers`, `createPageRoute`, `createNotFoundPage` (`/rsc`) | A, S | | 2 | **SEO** — meta | `generateMetadata` in every page route; favicon and OG from Site settings; `htmlLimitedBots` in `next.config.ts`; SEO tab + `buildNoindexField` in Pages | `generatePageMetadata`, `buildIconsMetadata`, `buildNoindexField` | A, S | | 3 | **SEO** — maps | `src/app/sitemap.xml/route.ts` (`export { sitemapRoute as GET }` + `force-dynamic`), `src/app/robots.ts` (`export { getRobots as default }` + `force-dynamic` — AI bots from the panel), `src/app/manifest.ts` — re-exports from `lib/content` | `sitemapRoute`, `getRobots` (or `robots` without the panel), `manifest` | A, S | | 3a | **Search Console / Bing** | recommended: **domain verification via DNS** (TXT record, deployment.md §6) — the plugin does nothing, the verification fields stay empty; only for URL-prefix verification: code in **Site settings → Search engines** (Google, Bing, Yandex), `generatePageMetadata` adds the `` itself; sitemap `https:///sitemap.xml` submitted in GSC and Bing | panel (optional), `verificationFrom` | P | | 4 | **SEO** — structured data | layout: `` gives `WebSite` + `Organization` (`sameAs`) from Site settings; local business → `createContentHelpers({ siteJsonLd })` with `buildLocalBusinessJsonLd` (`type`, hours → `formatOpeningHours`); navigation: ``; page: `createPageRoute` adds `getPageJsonLd` (WebPage/BlogPosting, breadcrumbs, FAQ — `pageJsonLd: { faq }`) | `getSiteShell`, `SiteProviders`, `build*JsonLd`, `getPageJsonLd` | A, S | | 5 | **GEO** — llms | `src/app/llms.txt/route.ts` (`llmsRoute`) and `src/app/llms-full.txt/route.ts` (`llmsFullRoute`) from `lib/content`; the `buildSummaryField()` field in Pages, `summaryField: 'aiSummary'` in `createContentHelpers` | `llmsRoute`, `llmsFullRoute`, `buildSummaryField` | A, S | | 6 | **GEO** — Markdown | `src/app/md/[locale]/[[...slug]]/route.ts` (single-language: `src/app/md/[[...slug]]/route.ts`) = `export { markdownRoute as GET } from '@/lib/content'`; `createContentHelpers({ markdownAlternate: true })` (link in ``); `createProxy(…, { NextResponse, markdown: true })` (without it `/md/…` gets redirected to a language) | `markdownRoute`, `markdownAlternate`, `createProxy({ markdown })` | A, S | | 7 | **GEO** — MCP | `src/app/api/mcp/route.ts` = `export { mcpGET as GET, mcpPOST as POST } from '@/lib/content'` (public — AI browses the site: `get_site_info`, `list_pages`, `search_content`, `get_page`); name: `createContentHelpers({ mcp: { serverName } })` | `mcpGET`, `mcpPOST` | A, S | | 8 | **GEO** — AI bots + IndexNow | robots **lets in** AI bots (default `aiBots: 'allow'`; block only on a client decision); AI bot policy and per-bot exceptions — Site settings → Search engines → AI assistants (works only with `getRobots`); `ipalKit({ indexNow: true })` + `src/app/indexnow-key.txt/route.ts` (`indexNowKeyRoute`; publishing → Bing/ChatGPT Search within minutes; IndexNow sends nothing with `IPAL_NOINDEX=1`) | `buildRobots`, `getRobots`, `indexNowKeyRoute` | A, S | | 9 | **Media / R2 / speed** | `Media` with `focalPoint`, `normalizeFilenameHook`, `buildOptimizeUploadHook`, `buildMediaPlaceholderHook` + field; **always** `buildR2Storage(['media'], { s3Storage })` + `@payloadcms/storage-s3`; `R2_*` in `.env.example`; ``; `images: buildImagesConfig()` and `buildUploadSecurityHeaders()` in `next.config.ts`; the project's `` via `mediaImageProps`/`videoProps` (§6.11b) | `buildR2Storage`, `mediaImageProps`, `videoProps`, `buildImagesConfig` | A, S | | 10 | **Forms** | every form from a **seed** (`scripts/seed-form-*.ts`: fields, confirmation, mail to the company **and** confirmation to the customer, every language); a block with `` + `formClasses.ts` (look, once); `actions.ts` = `createSubmitAction({ getCachedPayload, headers })`; `forms: {…}` in `ipalKit`; `email: mailAdapter()` | `RenderForm` (`/rsc`), `createSubmitAction`, `mailAdapter` | A, P | | 11 | **Turnstile** | `` in `[locale]/layout.tsx` (wires `TurnstileProvider` with the key from the panel); `RenderForm` renders the widget; keys in Site integrations | `SiteProviders`, `getTurnstileConfig`, `TurnstileProvider` | A, P | | 12 | Consent + analytics | Consent Mode: `'advanced'` (default — the Google tag loads at once with every signal `denied`) or `'basic'` (`` — no request to Google before consent; a client who wants zero requests), the choice goes to "Project decisions"; `ipalKit({ consentLog: true })` (without it the `/api/ipal/consent` endpoint does not exist) + `}>` (ConsentProvider, banner, CookieButton, Analytics in the right order); settings window mode (`settings`: `inline` / `modal` / `detailed`) per the design, brief is silent → `detailed`, the decision goes to "Project decisions"; tool IDs in the panel; the cookie list from a scan (`cookieScanner: true` → *Cookie review* → **Scan cookies** → the editor accepts; or cookie-scan → import) — feeds `` on the policy page **and** the lists in the `detailed` window; Cookie banner → Settings window → Cookie list headings in every language | consent.md, analytics.md | A, `ipal-consent-check` | | 13 | Security | `buildSecurityHeaders` in `next.config.ts`; `withPayload(withSecurityConfig(nextConfig))` (no `X-Powered-By`); CSP: `buildSecurityHeaders({ csp: { mode: 'report-only', reportUri: '/api/csp-report', … } })` + `buildAdminCspHeaders` on `/admin/:path*` + `src/app/api/csp-report/route.ts` (`createCspReportRoute`) → read the reports → `mode: 'enforce'`; `twoFactor: { issuer, plugin: payloadTotp }` + `generate:importmap` (`TotpRedirectProvider`; check: a new admin lands on `/admin/setup-totp?back=%2Fadmin` with the QR, no reloading); `IPAL_IP_HEADER` in production | security.md, forms.md | A | | 14 | Operations | `src/app/api/health/route.ts` (`healthRoute`); `src/instrumentation.ts` with `assertEnv(ipalEnvRules({ storage: true, ipHeader: true }))`; staging with `IPAL_NOINDEX=1`; smoke tests (§8a) | `healthRoute`, `assertEnv`, `ipalEnvRules` | A | | 15 | System pages | Site settings → System pages: homepage, 404, privacy policy, cookies; legal links in the footer by role (`getSystemLinks(locale)`) | `getSystemLinks`, `getSystemPagePath`, `getNotFoundPage` | P | | 16 | **Nothing hardcoded** | every text, link, image, file, company data from the panel; domains and keys from `.env` (§2) | — | A, P | | 17 | **Content** | one h1, the answer at the start of each section, facts, internal links, FAQ from real questions, `aiSummary`, sameAs, consistent company data (§0c) | — | S, P | | 18 | **Scaling** | `fluid.css` / `fluid-wide.css`, hero on `--ipal-hero-min-h`, the screen list in §6.11a (including 1366×768) | — | A, browser | **Turnstile works by itself:** both keys in the panel (or env) → the widget shows, and `submitForm` **requires** a token; no keys → no widget, the form works. Do not make the provider or the widget conditional in code — always wire them. **R2 works by itself:** the full `R2_*` set in env → media in the bucket; missing → local disk (dev). Always wire the code, so production does not save media to the container disk (they disappear on redeploy). ### Forbidden substitutes (ERROR in `ipal-audit`) | Instead of the plugin | Why not | Use | |---|---|---| | your own form with fields in JSX, `react-hook-form`, `formik`, your own form renderer | the client cannot change the fields; no Turnstile, rate limit, GDPR consent; a copy of the engine passes addresses from the Emails tab into HTML | the builder in the panel + `` (look: `formClasses`, unusual cases: `useBuilderForm`) | | your own `api/contact` / `api/send` / `api/form` route, `nodemailer` / `resend` / `@sendgrid` in the project | bypasses the `submitForm` validation and gates, a second mail transport | the `sendForm` server action → `submitForm`, mails from Forms → Emails via `mailAdapter()` | | reCAPTCHA, hCaptcha, your own captcha | a second mechanism, no status in the panel | Turnstile from the plugin | | a hand-written `