# 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 it to the owner and wait for their decision (see "ipal-kit first" below), never patch `node_modules` or fork 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. > **VERY IMPORTANT — seeding after launch.** Once a site is live, **never run a full seed again**: the owner's > edits on the live site must survive. Every later change targets **named records only** — specific pages, > globals, forms or fields — listed in the seed (`only: [...]` / `SEED_ONLY="pages:kontakt,global:header"`). > Never re-seed everything, not even in create-only mode, without the owner's explicit OK. `createSeeder` > refuses a run with no record list against a production or non-local database unless `IPAL_SEED_ALLOW_FULL=1` > (set it only after that OK). **Database names** (MongoDB and Postgres): the site's domain **with the dots removed**, plus `_prod` or `_dev` — `intecion.com` → `intecioncom_prod` / `intecioncom_dev`, `architektimprez.pl` → `architektimprezpl_prod` / `architektimprezpl_dev`. The name is the path of `DATABASE_URI`: `mongodb://…@mongo:27017/intecioncom_prod?authSource=admin`, `postgres://…@db:5432/intecioncom_prod`. You derive the names from the domain and confirm them with the owner (ipal-setup stage 0). `ipalEnvRules({ databaseName: true })` warns when they do not match (deployment.md §4.2a). **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. - After launch: named records only (`only` / `SEED_ONLY`); a full run of a live database is refused without `IPAL_SEED_ALLOW_FULL=1`. - Schema and one-off data fixes → Payload migrations; field renames with content → **ipal-migrate-fields**; content → seeds. ## Ask before you build — architecture questions Before you set up a site (or a new part of one), **ask the owner these questions and wait for the answers**. They decide the architecture; a wrong guess means rework. Ask them as **one list**, once, at the start — the ready-to-send list is in **ipal-setup** stage 0 (ipal-site phase 0 uses the same list). | Topic | What you need to know | |---|---| | Languages | which locales, the default locale, URL structure (`/pl/…` for every language, or the default without a prefix) | | Styling | a design system / `DESIGN.md` or plain Tailwind tokens, brand colours, fonts, light/dark theme | | Content | the pages, the collections (blog, case studies, products…), archive pages | | Forms | which forms, who receives them, e-mail provider (SMTP from the panel or Microsoft Graph) | | Analytics and consent | GA4 / GTM / pixels, Consent Mode basic or advanced, cookie banner mode, cookie scan | | SEO / GEO | market and local business data, AI crawler policy (llms.txt, Markdown, MCP, AI bots) | | Data and media | database (Postgres or MongoDB) and its names (`_prod` / `_dev` — derive, then confirm), media storage (R2 or local disk) | | Admin | 2FA, white-label (client brand in the panel), agency credit | | Hosting | Coolify, the production domain(s), who adds the DNS records (deployment.md §6) | - **A new site starts with `ipal-kit create`** (docs/project-starter.md): `pnpm --config.auto-install-peers=false dlx @intecion/ipal-kit@ create ` asks exactly these questions (or reads them from `--answers file.json`), generates the site from the reference site, writes the answers into `AGENTS.md` and makes the first commit. Ask the owner first, then pass the answers — the command never fills a gap. The manual path (`ipal-setup` stages 1–11) is for an existing project or what the command does not cover yet: **single-language sites, a default language other than `pl`**, sites without `en`, URLs without a prefix, Postgres — the command stops with a message pointing here. - Write every answer into the project's `AGENTS.md` → **"Project decisions"** (one line per topic). - **Do not guess a missing answer.** No answer to an architecture question → do not build that part; ask again. (Only *content* gaps — company data, texts, IDs — may wait: use `[TO FILL: …]` in the panel, §0a.) - An answer that conflicts with these rules → say so straight away and propose a compliant option. ## ipal-kit first — hard rule - **Anything the plugin covers, you build with the plugin's feature.** Always. Look it up first: the **ipal-reference** skill, the module docs (§12), the types in `dist/**/*.d.ts`. - The only exceptions: the plugin's feature **does not work**, or it **is not enough** for this project. - Even then: **report the gap to the owner first** with the **ipal-plugin-gap** skill and **do nothing on your own** for that part until the owner decides (wait for a plugin fix / an approved option / an approved, marked workaround). Work on unrelated parts may go on. - **No hand-built replacements and no silent workarounds.** A workaround exists only after the owner approved it, is marked `// WORKAROUND ipal-kit : docs/plugin-requests/` and is recorded in "Project decisions". ## Reference site — copy the pattern, not from memory Every convention in this file is implemented in the **reference site**: one complete client site on ipal-kit ("Example Studio", made up), kept current with each release and built, seeded and smoke-tested in the plugin's CI. Before you write a file the plugin expects you to wire (payload.config, layout, catch-all page, `lib/content.ts`, proxy, SEO/GEO routes, forms, seeds, `AGENTS.md`, `DESIGN.md`, deploy notes), open `node_modules/@intecion/ipal-kit/docs/agent/reference-site/INDEX.md`, find the matching file and copy its pattern — short wiring files are in the index in full, longer ones are linked at the tag of your plugin version. Change only the project's content (names, texts, blocks the site map needs), never the pattern. The index and this file disagree → report it with **ipal-plugin-gap**: it is a plugin bug. ## Code rules Short version of §8 — every skill follows it. - **Single responsibility:** one job per file, per component, per function. - **Small files, clear names, no dead code** (no commented-out code, unused exports or props). - **No duplicated logic** — extract it once; reuse the plugin's exports instead of rewriting them. - **Typed, no `any`** (no `@ts-ignore`; unknown shape → `unknown` + a type guard). - **Texts in i18n, never literals** — every visible text comes from the panel / localized fields (§2). - **Tests or checks for new behaviour** — a unit test, an `ipal-audit` / `ipal-seo-check` result, or a documented manual check (§8a). ```tsx // BAD — one component fetches, formats and renders; hardcoded text; any export function Offer({ data }: { data: any }) { const p = fetch(…); return

Nasza oferta

} // GOOD — data comes in typed props (enhanceProps / lib/content), text from the panel, one job export function Offer({ header, items }: OfferBlockProps) { return
} ``` --- ## 0. COMPASS (if you remember only this) 0. **Ask first.** Architecture questions before you build ("Ask before you build" above) — never guess. 1. **ipal-kit is mandatory.** A feature the plugin has goes through the plugin. Missing or broken → report it (plugin gap, §1.3) and wait for the owner's decision — no 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). **Sections from the block library first:** `libraryBlocks` + `createBlockRegistry` (15 ready blocks, docs/block-library.md); an own block only when no library block, variant or option fits. 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) | a library block first: `blockOptions` → `libraryBlocks` in `src/blocks/configs.ts`, `createBlockRegistry(content, { Image, Link, sendForm })` in `blocks/registry.ts` (docs/block-library.md). None fits → `src/blocks//config.ts` + `Component.tsx`, `extra` in the registry, `pageBlocks` → `pnpm generate:types` (+ `pnpm payload generate:importmap` with `rowLabel`) — **ipal-block** | | a standard page (home, about, services, contact, legal, 404…) | `pageTemplates` from `@intecion/ipal-kit/templates` in the content seed (after launch only with `SEED_ONLY`) — **ipal-site** phase 6 | | 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** → *Approve cookies* → **Approve and add**; or cookie-scan → import) — feeds `` on the policy page **and** the lists in the `detailed` window; Cookies → 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 | | 19 | **Design tokens** | `DESIGN.md` + `src/design/tokens.ts` → `pnpm exec ipal-tokens` → `src/design/tokens.css`; `styles.css` imports `fluid-wide.css`, `tokens.css`, `tailwind.css`, the brand file (§6.11); fonts in `--font-family-body` / `--font-family-heading` | `defineTokens`, `ipal-tokens` | A (`ipal-tokens --check`), browser (both themes) | **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 `