## Context See `docs/superpowers/specs/2026-12-03-page-anchor-links-design.md`. Blocks are one JSON column on `cms_page`; services-counter validates them; mobile-api passes them through as maps; the portal renders them. Custom HTML runs in an opaque-origin frame (`allow-scripts allow-popups allow-popups-to-escape-sandbox`) whose injected script already posts height reports, which `HtmlFrame` accepts only from its own `contentWindow`. ## Goals / Non-Goals **Goals:** named block targets; `#name` links from buttons, rich text and Custom HTML. **Non-Goals:** automatic ids; any new frame permission; scroll offsets for a sticky header (the public page has none). ## Decisions 1. **Field `anchor` on the block**, pattern `^[a-z0-9][a-z0-9-]{0,39}$`, unique per page. Stored in the blocks JSON, so no DDL. Refusal codes: `PagesBadAnchor`, `PagesAnchorTaken`. 2. **Link rule.** `#` plus the same pattern is a safe link everywhere a link is checked: `CmsBlockValidator.safeLink`, `isSafeLink`, the editor's `SAFE_LINK`, and the sanitiser (sanitize-html already keeps scheme-less hrefs; a test pins it). 3. **Ids.** The block wrapper in `CmsBlocks` gets `id={anchor}` for every type, the HTML frame included. Rendered only when the name matches the pattern, so rows written another way cannot inject odd ids. 4. **Frame bridge.** The injected script adds one click listener: for `a[href^="#"]` with a valid name it prevents the default and posts `{type:"colite-frame-anchor", name, y}`, where `y` is the in-frame element's document offset or `null`. `HtmlFrame` checks the source window as for heights, validates the message in a pure `frameAnchor()` helper, then scrolls the window to `frame top + y`, or to `document.getElementById(name)`, else ignores it. Smooth scroll. 5. **Messages are data only.** The page never navigates or evaluates anything from a frame message; it only scrolls. ## Risks / Trade-offs - A frame script could post anchor requests at will → it can only scroll its own page, which it could already make tall. Accepted. - A link name equal to an id the portal already uses on that page (e.g. `main`) would clash → the public page renders no ids of its own apart from block anchors; the preview shell may, so only behaviour on the public page is specified. - Pages saved by an older release lose link names → only on rollback; noted in the proposal. ## Migration Plan Deploy services-counter and the portal; run `sql/01-anchor-labels.sql`. Rollback: previous images and `sql/99-rollback.sql`.