diff --git a/docs/dev/ipal-doctor-proposal.md b/docs/dev/ipal-doctor-proposal.md index c8c00f4..4755946 100644 --- a/docs/dev/ipal-doctor-proposal.md +++ b/docs/dev/ipal-doctor-proposal.md @@ -1,6 +1,6 @@ # ipal-doctor — proposal -Status: **design, not built.** Waiting for the owner's go-ahead. +Status: **design approved 2026-10-29** (all of D1–D9, with the adjustments in §6). Not built; waiting for the go-ahead to build. Date: 2026-10-29 · plugin version at the time: 1.14.6. ## 1. What it is @@ -49,8 +49,8 @@ Source tags: **S** = static (files only, no network, no database), **R** = regis | `plugin-installed` | error | S | the version in `node_modules` satisfies `package.json` (a stale install hides the real state) | `pnpm install` | | `next-min` | error | S | installed `next` ≥ 16.4.1 and `eslint-config-next` on the same 16.4.x (AGENT.md §4 item 11) | `pnpm add next@16.4.x eslint-config-next@16.4.x` | | `sharp-min` | error | S | resolved `sharp` ≥ 0.35.5 | `pnpm add sharp@^0.35.5` / override | -| `node-22` | warning | S | `engines.node` allows only 22 (`>=22 <23`); `.nvmrc` / `.node-version` / `Dockerfile FROM node:` say 22 when they exist. With `--deep`, also the running `process.version` | set `"engines": { "node": ">=22 <23" }` and `.nvmrc` = `22` | -| `pnpm-pinned` | info | S | `packageManager` is set (Coolify then uses the same pnpm) | `corepack use pnpm@10` | +| `node-22` | warning | S | `engines.node` allows only 22 (`>=22 <23`); `.nvmrc` / `.node-version` say 22 when they exist. With `--deep`, also the running `process.version`. No Dockerfile or image check: sites are built locally and Coolify deploys the app, with MongoDB as a separate container on the same network | set `"engines": { "node": ">=22 <23" }` and `.nvmrc` = `22` | +| `pnpm-pinned` | info | S | `packageManager` is set (every build uses the same pnpm) | `corepack use pnpm@10` | | `deps-audit` | error on critical/high, info on moderate/low | R | `pnpm audit --prod --json` has no critical or high advisory | `pnpm up ` or a `pnpm.overrides` entry (AGENT.md §4 item 12); upgrade the plugin first | ### 2.2 Project layout and naming @@ -68,10 +68,10 @@ Source tags: **S** = static (files only, no network, no database), **R** = regis | Id | Sev | Src | Check | Fix hint | |---|---|---|---|---| -| `db-name` | error | S | `DATABASE_URI` database = `_dev` in `.env` and `.env.example`; `_prod` only in production. A local `.env` pointing at `_prod` is an **error**. The domain comes from `NEXT_PUBLIC_SERVER_URL` (not localhost), else `doctor.domain` in the config, else the folder name minus `-web`. With `--env-file prod.env` (an export of the Coolify variables) it checks the `_prod` name too | rename the database (deployment.md backup + restore) and update the env | +| `db-name` | error | S | `DATABASE_URI` database = `_dev` in `.env` and `.env.example`; `_prod` only in production. A local `.env` pointing at `_prod` is an **error**. The domain comes from `NEXT_PUBLIC_SERVER_URL` (not localhost), else `doctor.domain` in the config, else the folder name minus `-web`. With `--env-file prod.env` (an export of the Coolify variables) it checks the `_prod` name too | rename the database (deployment.md backup + restore) and update the env. The rule calls the plugin's own `databaseNamesFor` / `databaseNameFromUri` / `checkDatabaseName` (`@intecion/ipal-kit/env`), so the doctor and `ipalEnvRules({ databaseName })` cannot disagree; it also suggests `ipalEnvRules({ databaseName: true })` | | `env-rules` | error | S | `instrumentation.ts` calls `assertEnv(ipalEnvRules({…}))` from `@intecion/ipal-kit/env`, and the flags match what the config uses: `storage` when `buildR2Storage`, `cookieCrawl` when `cookieScanner.crawl`, `ipHeader: true` | the line from env.md | | `env-example` | warning | S | `.env.example` lists every variable those rules name, with placeholder values (no real host, no credentials) | add the names | -| `env-live` | error | D | with `--deep`, runs the project's own `ipalEnvRules` against the real environment (in the Coolify container) | set the variable in Coolify → redeploy | +| `env-live` | error | D | with `--deep`, runs the project's own `ipalEnvRules` against the real environment (in the Coolify container) | set the variable (Coolify → Environment Variables) → redeploy | ### 2.4 Security and admin @@ -91,7 +91,7 @@ Source tags: **S** = static (files only, no network, no database), **R** = regis |---|---|---|---|---| | `agents-md` | error | S | `AGENTS.md` exists and has a non-empty `## Project decisions` section; the `ipal-kit:start…end` pointer block names the installed version; `CLAUDE.md` exists (with `@AGENTS.md`) | AGENT.md §13; `pnpm exec ipal-skills` | | `skills-current` | warning | S | the `ipal-*` folders equal the ones shipped by the installed plugin (the same content, none missing, none retired) — the diff logic of `ipal-skills --dry-run` | `pnpm exec ipal-skills` | -| `seed-named` | error | S | every `seed*` package script uses the ipal-kit seed helper, deletes nothing (`payload.delete`, `deleteMany`, `--fresh`, `seed:fresh`) and **takes a named-record list** (see decision D5). After launch (`doctor.launched: true` in the config, or `--url` answers 200) a seed without a list is an error | seeding.md; rewrite on `createSeeder` | +| `seed-named` | error | S | every `seed*` package script runs a file that uses `createSeeder` from `@intecion/ipal-kit/seed` (so `only` / `SEED_ONLY` and the full-seed guard apply), deletes nothing (`payload.delete(`, `deleteMany`, `dropDatabase`, a `fresh`/`reset` script), and does not switch the guard off: no `guard: false`, no `guard.allowFull`, no `IPAL_SEED_ALLOW_FULL=1` in a package script or a committed env file. After launch (`launched` in `ipal-doctor.json`, or a launch date under "Project decisions" in AGENTS.md) a seed file that sets no `only` list is a warning — the run then needs `SEED_ONLY` | seeding.md; rewrite on `createSeeder` | | `i18n-literals` | error in blocks, warning in components | S | no literal UI text where the panel or i18n is expected — runs `ipal-audit`'s `jsx-text.mjs` and its Polish-literal check | move the text to a localized field | | `audit` | as reported | S | `ipal-audit --quick` from the **installed package** (not the project's copy, which may be stale) — every `[ERROR]` / `[WARNING]` becomes a finding `audit:` | the `ipal-audit` skill | @@ -157,8 +157,8 @@ Some rules need the real data: users without TOTP, cookies waiting for approval, environment. Two ways, decision D3: - **A. `ipal-doctor --deep`** runs `pnpm payload run node_modules/@intecion/ipal-kit/bin/doctor/deep.ts`: the Local - API, read-only queries (`count`), in the Coolify container's terminal or locally with the dev database. No new - route. + API, read-only queries (`count`), locally with the dev database (sites are built and checked locally), or in the Coolify app container's terminal + against the MongoDB container. No new route. - **B. A status endpoint** `GET /api/ipal/doctor`, **off unless `IPAL_DOCTOR_TOKEN` is set** (≥ 32 chars, bearer, constant-time compare, rate-limited). It returns counts and booleans only — never names, e-mails or values: `{ plugin, node, usersWithout2fa, pendingCookies, envMissing: ['R2_BUCKET'], importMapCurrent, siteSettings: { name, logo } }`. @@ -237,19 +237,25 @@ done": audit; "before deploy / weekly": doctor), an `ipal-doctor` skill (run, re `ipal-setup` ending with "doctor: 0 errors", and the rule list as `docs/agent/doctor-rules.md` generated from the modules so docs and code cannot disagree. -## 6. Decisions for the owner +## 6. Decisions (owner, 2026-10-29) -| # | Decision | Recommendation | -|---|---|---| -| D1 | Ship as a bin in the plugin, or a separate `@intecion/ipal-doctor` package | **bin in the plugin**; newest rules via `pnpm dlx --package=@intecion/ipal-kit@latest` | -| D2 | How strict is `plugin-latest` | **warning naming the newer version; error two or more minors behind** (a site the starter generated stays clean until a release, then shows a warning, not an error) | -| D3 | Deep checks: `payload run` only, a token endpoint only, or both | **both**, endpoint off until `IPAL_DOCTOR_TOKEN` is set | -| D4 | The Node pin form | **`"engines": { "node": ">=22 <23" }` + `.nvmrc` = `22`** | -| D5 | "Seeds take a named-record list" needs a **new seed-helper option**: today `createSeeder` has no way to pick records. Proposal: `SEED_ONLY=pages:home,forms:Contact` (or `--only pages:home`) filtering every `seed.collection/global` call by its natural key, and refusing a run without a list on a `_prod` database unless `SEED_ALL=1` and the owner's OK. Build it in this track or a separate one? | **separate small track, before the doctor's release**; until then `seed-named` checks only helper use + no deletes | -| D6 | The domain behind the database name when `.env` has only localhost: `NEXT_PUBLIC_SERVER_URL` → `ipal-doctor.json` `domain` → folder name | as listed | -| D7 | CI: is `pnpm exec ipal-doctor --offline` added to every site's pipeline / pre-deploy step in Coolify? | **yes, `--fail-on error`**, after the sites are brought to zero errors | -| D8 | `--fix` for the mechanical ones (`ipal-skills`, `generate:importmap`, `.nvmrc`, `engines`) | **not in v1** — hints only; v2 maybe | -| D9 | CSP report-only: info, or a warning after N weeks (the audit skill says "more than a few weeks") | **warning after 4 weeks** from the first doctor run that saw it (stored in `ipal-doctor.json` `seen`), or set by the project | +The owner accepted every recommendation, with two adjustments (D5, D7) and one deployment note. + +| # | Decision | +|---|---| +| D1 | **A bin in the plugin** (`bin/ipal-doctor.mjs`); newest rules through `pnpm dlx --package=@intecion/ipal-kit@latest ipal-doctor` | +| D2 | `plugin-latest`: **warning naming the newer version; error two or more minors behind** | +| D3 | Deep checks: **both** — `--deep` through `payload run`, and the status endpoint `GET /api/ipal/doctor`, off until `IPAL_DOCTOR_TOKEN` is set | +| D4 | Node: **`"engines": { "node": ">=22 <23" }` + `.nvmrc` = `22`** | +| D5 | **Already built and merged (main 0ed3898):** `createSeeder({ only })` / `SEED_ONLY="pages:kontakt,global:header"`, and a guard that refuses a full seed of production or a non-local database unless `IPAL_SEED_ALLOW_FULL=1` (or `guard.allowFull`). There is no `SEED_ALL`. `seed-named` checks for that helper and that the guard is not switched off (§2.5) | +| D6 | Domain for the database name: `NEXT_PUBLIC_SERVER_URL` → `ipal-doctor.json` `domain` → folder name; computed with the plugin's `databaseNamesFor` | +| D7 | **CI on new sites only:** sites generated by the starter and the reference site run `ipal-doctor --strict` (`--offline` where the registry is out of reach). **Existing client sites stay untouched** — no plan to bring them to zero; the dry run in §7 is information only. A read-only `--sites` sweep stays available as a report, never as a gate | +| D8 | **No `--fix` in v1** — hints only | +| D9 | CSP report-only: **info, then a warning after 4 weeks** from the first run that saw it (`ipal-doctor.json` `seen`), or as the project sets it | + +**Deployment note:** sites are built and checked locally; Coolify deploys the app; MongoDB runs as a separate container +on the same network. The doctor has no Dockerfile or image rules, and `--deep` runs locally or in the app +container's terminal. ## 7. Dry run — what it would report today @@ -321,7 +327,7 @@ A throwaway prototype of the static rules and the live header/admin rules, run * sites* session may have changed this on branches not in these checkouts. - **Four sites lack "Project decisions"** in AGENTS.md and three have no pointer block or CLAUDE.md — their skills are 14 folders out of date and miss `ipal-reference`. -- **No site can run a seed for named records only**, because the helper cannot (D5). Four sites have seeds that +- **No site could run a seed for named records only** at the time of the dry run (the helper gained `only` / `SEED_ONLY` in main 0ed3898 afterwards). Four sites have seeds that delete (`payload.delete`, `seed:fresh`). - **False-positive lessons from the prototype** (fixed in it, to carry into the real rules): matching words like "fresh" or "drop" in seed *content* is wrong — look only for code (`payload.delete(`, `deleteMany`, script name