oficina / mapa Public

Notion import design, revision 1

Pages into Mapa as team pages, databases into Fichas later; a shared
oficina/notion module lifted from memoria's connector; memoria's
connector retires.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev bb9b30dfeedc80959143c57d16506e9924a42c16 parent 3b20386
1 file changed, +653 −0
  • docs/superpowers/specs/2026-11-17-notion-import.md +653 −0

CI passed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 306ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.c25f62142895a785.js (318737 bytes, 99.5KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (48.622387ms)
ℹ 760 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (65.970608ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (96.976213ms)
ℹ 748 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (107.356721ms)
ℹ 755 inserts, 715 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (3058.581455ms)
ℹ 18240 edits over 760 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (912.982751ms)
ℹ 4124 links over 760 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":610,"A page link can’t show [ or ]]. Select words without them.":370,"Select some words to link them to a page.":163,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":17}
✔ linear: trailing spaces (21.041027ms)
✔ linear: trailing whitespace (14.717125ms)
✔ linear: unclosed web links (13.333917ms)
✔ linear: web links with no address (20.195621ms)
✔ linear: unclosed wiki links (21.944953ms)
✔ linear: unclosed embeds (22.877886ms)
✔ linear: closes only (12.101737ms)
✔ the selected words become the chip's shown text (9.416325ms)
✔ words that are the title make a plain [[Title]] (3.004417ms)
✔ spaces at the selection's edges stay outside the chip (1.472257ms)
✔ a date makes a date link, in a heading, an item and a quote (5.131207ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.023664ms)
✔ only the linked block's bytes change, and undo gives the body back (1.498897ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (0.854724ms)
✔ a target the words cannot be linked to as typed is refused (0.186865ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (1.608345ms)
✔ web-linked words are refused: the address would be lost (review M4) (0.749234ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.30575ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.304508ms)
✔ linkCheck says why it refuses (review low 2) (0.581304ms)
✔ golden file has bodies (0.782717ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (14.541162ms)
✔ markup.mjs strips and spans every block as Go does (27.742495ms)
✔ the schema's toDOM draws every body as Go renders it (53.492528ms)
✔ emphasis draws the four pinned outputs (14.520181ms)
✔ a body ends in the editor's empty paragraph (0.222072ms)
✔ a POST that never answers is aborted after the timeout (21.782406ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.212984ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (9.737957ms)
✔ an offered draft never commits by itself; Save commits it (1.119947ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.482797ms)
✔ closing carries text not yet sent, and the cap leaves it out (19.114376ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (3.349092ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (2.736197ms)
✔ typing mid-flight: the merge is not applied and the base does not move (1.326831ms)
✔ a merge the editor cannot represent stops after three tries (3.787384ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.1268ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.392584ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (0.899839ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.762849ms)
✔ noBase and gone lead to the existing choices (0.749764ms)
✔ a commit that merged is applied when nothing was typed since (0.972618ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (7.284095ms)
✔ an own draft committed meanwhile goes on as a new draft (1.263621ms)
✔ a reload keeps a stored draft; unsent text still commits (0.44776ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (1.13703ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.249783ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (0.960795ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (3.33232ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (1.069792ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.31583ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.796533ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.509107ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.743402ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.557078ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.634215ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.550334ms)
✔ marks close before code, links and atoms, and reopen after (0.423144ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (5.33883ms)
✔ empty blocks are written as nothing (2.434234ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.4475ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.842139ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (2.776114ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (1.848391ms)
✔ a trailing hard break stays on screen and is written as nothing (0.480582ms)
✔ the reparse waits while an IME is composing (0.668449ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (3.176834ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.825057ms)
✔ rebuild changes origins only, outside undo history (1.548291ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.156937ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (3.159552ms)
✔ a duplicate ^id typed above its holder never takes the id from it (0.659162ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (0.808696ms)
✔ a history command that throws is refused, never thrown (2.679499ms)
✔ one rename at a time, from either field (2.049423ms)
✔ an empty or unchanged title sends nothing (0.218606ms)
✔ a refusal keeps what was typed, and the title (0.262198ms)
✔ the pending state holds for the busy rule (5.72807ms)
✔ a failed POST says so and keeps the title (0.394229ms)
✔ Update links posts the confirm page's POST (0.258441ms)
✔ clean is CleanTitle's whitespace rule (0.120679ms)
✔ the saver's base follows a rename made over it, and only that (0.281154ms)
✔ closing sends the rename as one keepalive POST (1.755184ms)
✔ a drag whose anchor the document no longer reaches selects to its end (5.345515ms)
ℹ tests 90
ℹ suites 0
ℹ pass 90
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4413.314226
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
?   	amadan.net/oficina/mapa/cmd/mapa	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa	0.525s
?   	amadan.net/oficina/mapa/internal/mapa/icons	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa/markup	0.055s
ok  	amadan.net/oficina/mapa/internal/mapa/seal	0.002s
ok  	amadan.net/oficina/mapa/internal/mapatest	9.669s
?   	amadan.net/oficina/mapa/scripts/mutate	[no test files]
?   	amadan.net/oficina/mapa/scripts/preview	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
credits: checked
diff --git a/docs/superpowers/specs/2026-11-17-notion-import.md b/docs/superpowers/specs/2026-11-17-notion-import.md
new file mode 100644
index 0000000..67f5698
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-17-notion-import.md
@@ -0,0 +1,653 @@
+# Notion import: pages into Mapa, databases into Fichas later
+
+**Status:** revision 1, 2026-11-17, for review. **Paul approved the import on 2026-11-17**, with his 2026-11-14 defaults (§1) and one overrule: images come in as real Mapa images. Everything marked **Proposed** in this spec is the author's recommendation and has not been ruled. Nothing is built.
+
+**Branch:** `design/notion-import` (Mapa).
+
+**Base specs, which still bind:**
+- Mapa `2026-11-12-mapa-design.md` (approved): §3 model and the shared namespace, §4 the seal boundary, §5 history, §6 index, gate 8.
+- Mapa `2026-11-14-mapa-level-up.md` (approved): §6.3 the editor's subset, §6.4 fidelity.
+- Mapa images, `2026-11-17-mapa-images.md` on `design/images`, **not yet written** when this revision was. §12 states the hook this import needs from it as assumptions A1–A7, for that spec to confirm or change.
+- memoria `2026-09-05-notion-ingest-design.md`: its connector is the code this import lifts (§3) and retires (§16).
+- Fichas `2026-09-19-fichas-design.md` and the type-designer draft on `design/type-designer`: only for §17's sketch.
+- Suite doctrine revision 11 (`91affa1`, as Mapa consumes it): S1–S3, for §16.
+
+---
+
+## 0. The one rule
+
+**The import reads Notion and writes Mapa. It never writes Notion.** Sharing a page with the integration is the act of publishing it to the team. From then on Mapa is the app of record for what it imported (base §0), and nothing that happens in Notion afterwards can delete it from Mapa.
+
+Three things follow, and each has a section:
+- Every imported page is a team page that every member can read (§7).
+- A page that disappears from Notion stays in Mapa (§13).
+- Mapa reaches the network only through one pinned module, only for this, only while an importer runs it (§5).
+
+---
+
+## 1. What Paul ruled
+
+| # | Ruling | Who, when |
+|---|---|---|
+| P1 | Import from Notion. Pages go into Mapa. Databases go into Fichas, after the Fichas level-up | Paul, 2026-11-17 |
+| P2 | Pages become Mapa **team** pages | Paul, 2026-11-14 default, confirmed 2026-11-17 |
+| P3 | Mentions of pages become `[[links]]` | as P2 |
+| P4 | Dates become date links | as P2 |
+| P5 | Nesting becomes links between parent and child. Mapa has one shared namespace and no tree | as P2 |
+| P6 | **Re-runnable until switch-over.** A re-run updates pages untouched in Mapa since the last import, keeps Mapa's version where it was edited, and **never deletes on absence** | as P2 |
+| P7 | Imported pages are credited to whoever ran the import. Notion's original created and edited times are kept in history | as P2 |
+| P8 | The Notion API, not the export zip | as P2 |
+| P9 | **Images come in as real Mapa images.** This overrules the link-back default | Paul, 2026-11-17 |
+| P10 | memoria's own Notion connector retires. memoria reads Mapa through the suite contract instead of holding a copy | Paul, 2026-11-17 |
+
+## 2. Decisions this spec proposes
+
+**All Proposed.** The `Who` column of base §1 applies: none of these is a ruling until Paul says so.
+
+| # | Decision | Rejected | Section |
+|---|---|---|---|
+| D1 | **A new module, `amadan.net/oficina/notion.git`, in a new hub repo `oficina/notion`**, holds the client, the traversal, a typed block tree and the recorded-fixture fake. Mapa and later Fichas import it. Each app maps the tree to its own model | The suite module, rastrillo, a copy in each app, importing from memoria | §4 |
+| D2 | **Mapa's own tree gets no egress exemption at all.** Only the module dials, through two host-pinned transports. Only Mapa's import files may import the module | memoria's shape, which exempts one directory of the app | §5 |
+| D3 | **The token is pasted by an importer, sealed under its own purpose, never rendered, and deleted on Finish, on Disconnect and after 90 idle days** | Holding it in memory only for a run; storing it unsealed in config | §6 |
+| D4 | **Only people named in `MAPA_IMPORTERS` see Import.** Unset means the feature is not there (404) | Every member; a role Mapa does not have | §7 |
+| D5 | **Team pages only.** Whatever the importer shares with the integration becomes a team page. No private import | Importing into the importer's scratch pages | §7 |
+| D6 | **Two phases per run: Survey, then Write.** Survey walks Notion and stages each page's blocks, sealed. Write assigns titles across the whole set, renders and commits | memoria's single pass, which cannot know a link target's final title | §8 |
+| D7 | **The import writes through Mapa's own verbs**, `Store.write` and the namespace checks, with the importer as actor. No side door into the tables | A bulk loader | §8, §14 |
+| D8 | **"Untouched" means the page's revision is still the one the import last wrote.** Any later revision, including a rename, keeps Mapa's version whole | A three-way merge of Notion's change into Mapa's edit | §13 |
+| D9 | **The output is held to the editor's structure check.** Every body the import writes must parse back into exactly the blocks the mapper meant | Trusting the mapper | §10, §11 |
+| D10 | **Nothing is dropped silently.** Each unsupported block becomes visible placeholder text or a counted loss, and the run report lists both | Skipping unknown blocks | §10 |
+| D11 | **Positional links in the parent, and one `In: [[Parent]]` line on the child**, for nesting | A "Pages inside" list appended to the parent; no back-pointer | §9 |
+| D12 | **Title collisions take the parent's name, then a number**: `Week 1`, `Week 1 (Onboarding)`, `Week 1 (Onboarding) 2` | Merging into an existing Mapa page with the same title | §9 |
+| D13 | **Notion-hosted images are downloaded. External images stay links** | Fetching from any host on the internet | §12 |
+| D14 | **memoria retires its connector once it is shown to hold no Notion documents**, before Mapa's producer is live if so, after it if not | Running both | §16 |
+
+---
+
+## 3. What memoria's connector teaches
+
+memoria's connector (`internal/memoria/notion/`, spec 2026-09-05) was designed, reviewed twice by Fable and built. **It never ran against a real workspace.** Every lesson below came from reading Notion's documentation or from review, and every one of them is untested against Notion itself. §19's checklist is where that ends.
+
+**Kept, as they are:**
+- **Traversal from shared roots, never `/v1/search` as an enumerator.** Search is used only to find the directly-shared roots, which Notion guarantees. Children come from `GET /v1/blocks/{id}/children`, cursor by cursor (memoria §6).
+- **Roots and orphans are separate.** A page under a `block_id` parent looks like a root to search. Orphans are walked only after the real traversal drains (memoria §1.3, the blocker).
+- **The total decoder.** `has_more` with no cursor, a repeated cursor, or a 429/529 past the retry budget fails the run. There is no partial result (memoria §6).
+- **`Notion-Version` pinned as a constant, with a gate.** memoria pinned `2026-03-11`, which is real: it replaced `archived` with `in_trash` and renamed `transcription` to `meeting_notes`. Notion's changelog (2026-10-30) announces a later version, not yet named, that makes its Markdown output the default. The build re-reads the changelog and pins the version current then, with fixtures recorded against it.
+- **Never delete on absence** (memoria §3). P6 makes it Paul's.
+- **The token sealed under its own purpose, never rendered, verified on save** with `GET /v1/users/me` (memoria §12).
+- **Admin-triggered, resumable runs**, with boot-time reclaim of a run left active and a 20-second heartbeat (memoria §9, §1.3).
+- **Host and scheme pinned as separate checks, redirects refused** (memoria §11, §1.2).
+- **Error codes, never messages.** A Notion 404 body quotes the page id and the integration's name (memoria §8).
+- **A ledger row is written before the fetch**, so a page that fails has somewhere to be named (memoria §9).
+- **Unknown block types are counted, not swallowed** (memoria §5).
+- **`Retry-After` capped and context-aware** (memoria §1.3).
+
+**Changed, and why:**
+- **The output.** memoria's `markdown.go` flattens to `plain_text`: no emphasis, no link targets, no mention ids, captions only for images. Mapa needs all of those. The module returns a **typed block tree** with rich text runs, annotations and mention targets (§4). Each app renders it.
+- **One pass becomes two** (D6). memoria wrote each page as it was reached. Mapa's links are keyed on titles, and a title is final only once every page's title is known.
+- **Databases leave phase 1.** memoria turned each database row into a document. Here they wait for Fichas (§17). Phase 1 never queries a data source.
+- **The fake becomes a shared, recorded fixture set** (§4, §18). memoria's fake was written from the documentation by the same author as the client. Its own review found the blocker that a fixture written from the same model could not.
+
+## 4. Where the code lives
+
+**Proposed (D1): a new hub repository, `oficina/notion`, module path `amadan.net/oficina/notion.git`**, using the `.git` suffix that estilo uses so `go get` resolves through the hub. Amadan workflow on, as for every new Oficina repo.
+
+**Packages:**
+- `notion` — the client, lifted from memoria:
+ - `client.go`: the pinned transport, the version pin, pacing, retries, error codes;
+ - `traverse.go`: roots, orphans, the walk, the total decoder;
+ - `blocks.go` (new): the typed tree. A `Page` (id, title runs, parent, created and edited times, icon, `in_trash`) and its `Block`s (id, type, `last_edited_time`, `has_children`, the type's payload decoded into typed fields, children). Rich text is `[]Run`, each run with its text, its annotations (bold, italic, strikethrough, underline, code, colour), its link, and a typed mention (page, database, date, user, link preview, template, custom emoji) carrying its target id;
+ - `files.go` (new): the file fetcher (§5);
+ - `verify.go`: `GET /v1/users/me`.
+- `notiontest` — the fake server, exported so both apps run against it, and the fixture set (§18).
+- `cmd/notion-record` — records a real workspace's responses for fixtures, and scrubs them (§18, §19).
+
+**What does not go in the module:** any mapping into an app's model, any storage, any HTML. The module knows Notion. Mapa knows Mapa. Fichas will know Fichas.
+
+**In Mapa:**
+- `internal/mapa/notionmd/` — the mapper: block tree to Mapa Markdown (§10, §11). Pure. It imports `markup` so it can check its own output (D9), and it imports nothing that dials.
+- `internal/mapa/import_*.go` in package `mapa` — the ledger, the run, the handlers and the screens. These are the only files that import the module (§5).
+
+**Why not elsewhere:**
+- **The suite module** has no dependencies on purpose, "so the pin chain from an app is one deep", and every app imports it. A network client there would put Notion's client in Docs', Sheets' and Calendar's builds, and mix a vendor adapter into the contract's review discipline.
+- **rastrillo** is a public framework. Notion is one product's import.
+- **A copy in each app** is the drift that every Oficina AGENTS.md warns about. The second copy would miss the next fix.
+- **memoria** keeps its code under `internal/`, which nothing else may import, and the connector is retiring.
+
+## 5. Egress
+
+**Mapa has no egress today** other than rastrillo's sign-in mail. This adds the first, so the rule is written before the code.
+
+**Proposed (D2):**
+- **Mapa's own tree stays clean.** A new gate, I8, walks `internal/mapa/**` and `cmd/**` and fails on `http.Client`, `http.Transport`, `http.Get` and its siblings, `http.NewRequest`, `net.Dial*` and `net.Resolver`. **No directory is exempt.** rastrillo's mail path lives in rastrillo.
+- **Only the module dials.** I8's second half reads `go list -deps` and fails if any package other than `internal/mapa` imports `amadan.net/oficina/notion.git/...`, and an AST check fails if any file other than `import_*.go` does.
+- **Two transports, both pinned in the module:**
+ - **The API transport** refuses every host but `api.notion.com` and every scheme but `https` (two checks, two gates, memoria §1.2). The base URL is a constant. It refuses every redirect. It sends only `GET`, and `POST` to `/v1/search` (phase 1 never queries a data source). Any other method or path is refused before it dials, so the client cannot write to Notion even if a caller asks it to.
+ - **The file transport** fetches Notion-hosted files. It refuses every URL outside a constant allowlist of **(host, path prefix)** pairs. A host alone is not enough: Notion's documented example is `https://s3.us-west-2.amazonaws.com/secure.notion-static.com/…`, a path-style URL on Amazon's shared regional endpoint, where any AWS customer's bucket also lives. So the pin is that host *and* the `/secure.notion-static.com/` prefix, plus whatever pairs §19's first run finds Notion actually sending (a virtual-hosted bucket such as `prod-files-secure.s3.us-west-2.amazonaws.com` would be its own pair). It refuses every redirect. **It never sends the Notion token**, because a signed file URL needs none and a token in a request to a storage host is a token handed to a third party. It reads at most the images spec's size cap plus one byte, and fails on the extra byte (memoria AGENTS.md's detectable cap).
+- **External URLs are never fetched.** An image or file whose Notion type is `external` stays a link (D13, §12). Fetching it would mean dialling any host a page names, which is a server-side request forgery surface, not a pin.
+- **Nothing dials unless a run is active.** The client is built when a run starts and dropped when it ends. Mapa does not poll Notion.
+
+**Leak list additions** (base §4 and the README):
+- Mapa holds a Notion token while a connection exists, sealed (§6).
+- Mapa dials `api.notion.com` and Notion's file hosts during a run. Notion and its storage provider learn the instance's egress address and when it imports. No team content goes out: content comes in.
+- The ledger's plaintext shows how many Notion pages were imported and when, and how many failed (§15).
+
+## 6. The credential
+
+**Proposed (D3):**
+- **What it is:** a Notion **internal integration token**, made by the importer in Notion's settings with **Read content** only, no insert, no update, no comments, and **user information without email addresses**. Notion offers three user settings: none, names without emails, names with emails. With none, every user mention reads `@Anonymous` (Notion's rich text reference). Names make mentions readable and phase 2's `people` fields possible. Emails are never asked for.
+- **Who enters it:** an importer (§7), on Import's connection form. The setup copy says what to create and what to share, because Mapa cannot enforce Notion's capabilities, only ask for the right ones (memoria §12).
+- **Verified on save** with one `GET /v1/users/me`, so a bad token fails at the form. The workspace name it returns is kept, sealed, for display.
+- **Sealed** under a new purpose, `notion.token`, in a one-row table, `notion_connections`. Never rendered, not even masked. A masked secret is still a secret in the DOM. Gate I11 checks that no 8-character run of it reaches any page.
+- **Replaced** by pasting a new one on the same form (memoria §1.2: rotation needs a form).
+- **Deleted:**
+ - on **Disconnect**, its own confirm page;
+ - on **Finish import** (§8.6);
+ - **after 90 days with no run**, by retention at wake, beside base build note 27's windows. An idle token is a liability with no use.
+- **Revoked at Notion's end by the person.** Mapa cannot revoke an internal integration. Disconnect, Finish and the retention notice all say "Now remove the integration in Notion: Settings, Connections", with the integration's name.
+
+**Rejected: Notion's own Markdown output** (the changelog's "markdown v2"). It would be a second grammar to parse into Mapa's subset, and a mention in it is text, where the mapper needs the target's id to make a `[[link]]`. The typed block tree carries both.
+
+**Rejected: the token in memory only.** No token at rest is a stronger property. But a run that a deploy or a CARLOS swap interrupts would then need the token pasted again to resume, and P6 makes re-runs routine for weeks. Sealing under its own purpose is memoria's precedent and base §4's rule.
+
+## 7. Who may import, and what becomes what
+
+**Proposed (D4): `MAPA_IMPORTERS`**, a list of addresses, each of which must be in `MAPA_OWNERS` (refused at boot otherwise, tested in `config.go`).
+- **Unset:** Import does not exist. Its routes 404 for everyone, and nothing links to it.
+- **Set:** those people see "Import from Notion" in the account menu, beside Settings and Deleted pages. Everyone else gets a 404 on every import route.
+- **Why a list.** Mapa has no roles: in the lone shape every admitted person is equal. memoria wrote "owners only" when its owners list was the whole admission list, and its review found that the guard guarded nothing. A named list is a real restriction and a gate can test it (I13). In the suite shape, the roster's `owner` role (doctrine §5.6) can replace it.
+
+**Proposed (D5): every imported page is a team page.**
+- The importer chooses what to share with the integration in Notion. Sharing is the publish (§0).
+- The connection form says so before the token is entered: *everything you share with this integration becomes a team page that every member of this team can read.* Copy goes through the copy-review skill.
+- **No private import.** Mapa's private pages are daily notes and scratch pages, neither of which has a title in the namespace (base §3.3). A private Notion hierarchy imported as scratch pages would lose every link between its pages.
+- **Daily notes are never written by the import.** A Notion journal page is a team page (§9.3).
+
+## 8. The run
+
+### 8.1 Shape
+
+A run is started by an importer's `POST`, mounted inside the session and CSRF group, and runs in a goroutine the request spawns. As memoria §9 says plainly: **this is not a background worker.** It runs until it finishes or the platform sleeps the process. The status page keeps it awake while it is open.
+
+**Proposed (D6): two phases.**
+
+1. **Survey.** Walk Notion from the roots (§3). For each page:
+ - write or update its ledger row first (memoria §9);
+ - read its blocks, recursively, down to child pages, which are not entered from inside the body;
+ - **stage** what was read: the page's title, times, parent, and its block tree, sealed under `notion.staged`, on the ledger row;
+ - record the child pages found, which the walk visits next.
+ - Pages whose parent is a database or data source are database rows. Phase 1 counts them and does not stage them (§17).
+ - Trashed pages and blocks (`in_trash`) are skipped.
+2. **Write.** With every page surveyed:
+ - assign titles across the whole set (§9.2);
+ - for each page, in survey order, render its body from the staged tree (§10, §11), fetch its new images (§12), and decide what to do (§13);
+ - commit through Mapa's verbs (§14);
+ - clear the staged tree once the row is written.
+ - Then the fix-up pass (§13.6).
+
+**Why two phases.** A `[[link]]` in Mapa is the target's title as text (base decision 9). Page A, written first, may mention page B, whose final title depends on collisions decided later. Writing A then would write a link to the wrong text. memoria never had this problem because its documents did not link.
+
+**What it costs.** Survey reads every block of every shared page on every run, because child pages are found only inside their parent's blocks (memoria §1.2). The staged trees sit sealed in the database until Write consumes them.
+
+### 8.2 Rate
+
+- The client paces itself at one request per 350 ms, below Notion's published average of three per second for most plans (Business and Enterprise get ten). It honours `Retry-After` on 429 and 529, which Notion says is whole seconds and at most 60, capped and cancellable (memoria §1.3).
+- Rough size: three to five requests per page, more for deeply nested toggles and columns. **1,000 pages take about 20 to 30 minutes to survey.** The first real run measures this (§19) and the build notes record it.
+- Image downloads go through the file transport, paced the same way, so one run never bursts at anyone.
+
+### 8.3 Resuming
+
+- **Single-flight.** One run at a time per instance, held by a conditional update on `notion_runs`.
+- **At boot,** a run in `surveying` or `writing` becomes `interrupted`. No run can be live at boot (memoria §9).
+- **A heartbeat every 20 seconds.** A run whose heartbeat is older than two minutes, in a live process, may be reclaimed by the next Start (memoria §1.3: time, not pages).
+- **Resuming a survey** walks the pages already surveyed *in this run* from their staged trees, with no requests, and asks Notion only for the rest. This is cheaper than memoria's resume, which repeated the whole traversal.
+- **Resuming a write** continues from the rows still `staged`. Each page's write is one transaction, so a page is written or it is not.
+- An interrupted run says so, with Resume. It never shows as finished.
+
+### 8.4 Progress, and the scriptless floor
+
+- `/import/notion` is the page: the connection, the current or last run, and its report.
+- **During a run** it refreshes itself with `<meta http-equiv="refresh" content="5">`, so it works with JavaScript off. Script only replaces the refresh with a fetch that keeps scroll position.
+- **What it says:**
+ - Survey: "Reading Notion: 412 pages so far." **The total is not known until the survey ends, and the page says so.** It never shows a total of 0 or a percentage (memoria §1.2).
+ - Write: "Writing pages: 120 of 1,930." Now the total is known.
+ - Interrupted: "Stopped at 412 pages. Resume." Failed: the code's own sentence, never Notion's message.
+- **Start, Resume, Disconnect and Finish** are form buttons, with estilo's busy rule. Disconnect and Finish have their own confirm pages.
+
+### 8.5 The report
+
+The run's report is for importers only. It unseals titles to show them.
+- **Counts:** roots found (named), pages seen, created, updated, renamed, unchanged, **kept because edited in Mapa**, **deleted in Mapa** (not re-created), **not found in Notion this time**, failed (with codes), database rows left for Fichas, images imported, images left as links, images failed, blocks not imported (by type), links to pages not shared with the integration.
+- **Lists,** each title a link to the Mapa page where there is one: titles changed to fit Mapa (§9.2), pages kept, pages failed, pages not found this time, pages holding a placeholder (§10).
+- A count that could not be determined says so. It never renders as 0 (memoria AGENTS.md).
+
+### 8.6 Switch-over: Finish import
+
+**Finish import** is the importer saying Notion is no longer the source. On its confirm page it says what it does:
+- deletes the token (§6);
+- deletes every staged tree;
+- **keeps the sealed map** between Notion ids and Mapa pages, which phase 2 needs (§17). "Forget the import" on the same page deletes the map too, with its own confirm page;
+- after Finish, Import shows only the last report and Connect, which starts over as a new import.
+
+**After Finish, a new import is a new import.** It has no map, so it would create a second copy of every page. The confirm page for Connect after Finish says so.
+
+## 9. What a Notion page becomes
+
+### 9.1 One page, one team page
+
+- A Notion page becomes one Mapa team page: `kind` `page`, `rung` `team`, owner the importer.
+- Its body is the mapped blocks (§10), with the parent line first (§9.4).
+- Its title is the Notion title, made to fit (§9.2).
+- Its sealed record carries the Notion times (§14).
+- The page's icon and cover are not imported. They are counted.
+
+### 9.2 Titles
+
+A Mapa title must be unique across titles and aliases after case and accent folding, at most 120 characters, free of `[ ] | # ^`, and not date-shaped (base §3.4, build note 8). Notion allows all of those, and duplicates are common: "Meeting notes", "Week 1", "Untitled".
+
+**Making a title fit** (applied in this order, deterministic, and each change listed in the report):
+1. `[` and `]` become `(` and `)`. `|` becomes `/`. `#` followed by a digit is removed (`Issue #42` → `Issue 42`); any other `#` becomes a space. `^` is removed. Runs of spaces collapse.
+2. An empty title is `Untitled`.
+3. Over 120 characters: cut at the last word boundary before 119, then `…`.
+4. Date-shaped (`2024-03-05`): §9.3.
+
+**Collisions (D12).** Candidates in order, the first one free in the namespace and not planned for another page in this run:
+1. the title;
+2. the title, then the parent's (fitted) title in brackets: `Week 1 (Onboarding)`;
+3. the same, then ` 2`, ` 3`, and on.
+
+A root page has no parent, so its second candidate is `Week 1 (Notion)`.
+
+- **An existing Mapa page with the same title is never merged into.** Mapa's `Acme` is somebody's page. Notion's `Acme` becomes `Acme (Notion)` and the report lists it.
+- **Assignment is deterministic.** Survey order is the roots sorted by Notion `created_time` then id, then block order inside each page. The same workspace gives the same titles.
+- **Titles already assigned are kept.** On a re-run, a mapped page keeps its Mapa title unless Notion's title changed (§13.3).
+- **The namespace check is the store's.** The import proposes a title and the create or rename verb decides, so a member who takes a title mid-run makes the verb refuse it, and the import takes the next candidate (§13.6).
+
+### 9.3 Date-titled pages
+
+A Notion journal often titles pages by date. Mapa reserves date-shaped text for daily notes (base §3.4), which are private to one person.
+
+**Proposed:** such a page becomes a team page titled `2024-03-05 (Notion)`, and its first line after the parent line is the date link `[[2024-03-05]]`. Every member's daily note for that day then lists it under its backlinks (base build note 14), which is where a person looking at that day would look. **Q3 asks Paul.**
+
+### 9.4 Parent and child (D11)
+
+Mapa has no tree. Notion's tree becomes links, both ways:
+- **In the parent:** Notion puts a `child_page` block where the child sits in the parent's body. The import writes `[[Child title]]` as its own paragraph **in that place**. A parent that lists its children at the bottom keeps them at the bottom. One nested inside a toggle or a column lands where that toggle or column is flattened to (§10). This is the "Pages inside" list, in Notion's own order.
+- **In the child:** the first block is `In: [[Parent title]]`, one paragraph. A root page, or a page whose parent is not shared with the integration, has no such line.
+- **Moves.** When a page moves in Notion, both lines change on the next run, under §13's untouched rule.
+- The Links panel's "Linked from" also shows the parent, among every other page that links there. The `In:` line is what makes the parent the obvious way up.
+- The wording `In:` goes through the copy-review skill. Q4 asks Paul.
+
+## 10. Blocks
+
+**The rule (D9, D10).** Each Notion block maps to Mapa's subset (base build note 10, level-up §6.3): paragraphs, headings, list items with tasks, quotes, code fences and rules, with `*`, `**`, inline code, `[[links]]`, and http, https and mailto links. What the subset cannot say becomes either **placeholder text**, which is visible, editable and listed in the report, or a **counted loss**. A count is shown in the report by type. Nothing is lost silently.
+
+**Placeholders** are one quote block, worded in §10.2. A quote, because it reads as a note about the page, not as the page's own words.
+
+### 10.1 The table
+
+| Notion block | Mapa | What is lost |
+|---|---|---|
+| `paragraph` | paragraph. Line breaks in the text are hard breaks. Blank lines inside the text are collapsed, because a blank line ends a Mapa block | blank lines inside one block (counted) |
+| `heading_1` … `heading_4` | `#` … `####`. The page title is the H1 on screen, so these draw as h2–h5 | — |
+| any deeper heading Notion adds | the matching `#` count, at most `######` | — |
+| toggleable heading (`is_toggleable`) | the heading, then its children as ordinary blocks after it | the collapse (counted as a toggle) |
+| `bulleted_list_item` | `- ` item. Nested items indent two spaces per level | — |
+| `numbered_list_item` | `1. ` item, numbered in sequence within each run of items at each depth | Notion's own start number, if it has one |
+| `to_do` | `- [ ] ` or `- [x] ` | — |
+| a list item's non-list children (a paragraph, a code block) | a paragraph child becomes a continuation line of the item (a hard break). A code block, quote, heading, table or image child is written after the list, at top level | the nesting of those blocks (counted) |
+| a paragraph's children (Notion's indented blocks) | written after it, at top level | the indent (counted) |
+| `toggle` | a paragraph of the summary in `**bold**`, then its children as ordinary blocks after it | the collapse (counted) |
+| `quote` | `> ` quote, one `>` line per line of text. Children's text follows as more `>` lines | the children's own block shapes (a list inside a quote is its text) |
+| `callout` | `> ` quote, the icon's emoji first if it is an emoji: `> 💡 Remember…`. Children's text follows as more `>` lines | the colour, a custom or file icon (counted) |
+| `code` | a fence: ```` ``` ```` plus the language (lowercased, spaces to `-`; `plain text` gives none). If the code holds a line starting ```` ``` ````, the fence is `~~~`. If it holds both, the block is written as a placeholder with the code in it (counted). The caption, if any, follows as an `*italic*` paragraph | — |
+| `divider` | `---` | — |
+| `table`, `table_row` | pipe-table text, one paragraph: a header row, a `\| --- \|` row when Notion marks a header, then one line per row. Mapa shows it as lines of text (level-up D10) and the vault export renders it as a table. A cell's line breaks become spaces; a `\|` inside a cell becomes `/` | layout, column and row header styling. A table that needs sorting or typed columns belongs in Fichas |
+| `column_list`, `column` | each column's blocks in order, left to right | side-by-side layout (counted) |
+| `tab` (a tabbed container) | each tab in order: its label as a `**bold**` paragraph, then its blocks | the tabs (counted) |
+| `synced_block`, original | its children, in place | that it is synced (counted) |
+| `synced_block`, copy | the original's children, in place. **Unverified:** Notion's reference says a copy's children "will be mirrored", and does not say what reading a copy's children returns. The mapper reads the copy's children, and if that is empty or 404s, reads the original's (`synced_from.block_id`). If the original is not shared, a placeholder. §19 step 3 checks against a recording | that it is synced; each copy is its own text from now on (counted) |
+| `child_page` | `[[Child title]]`, in place (§9.4) | — |
+| `link_to_page` | `[[Title]]` if the target is imported; otherwise a placeholder | — |
+| `child_database`, inline or full-page | a placeholder naming the database, in place (§10.2). Phase 2 replaces it (§17) | the database, until phase 2 |
+| `image`, Notion-hosted | a Mapa image (§12) | — |
+| `image`, external | a web link: `[caption](url)`, or the URL bare. Q2 asks Paul | the image is not stored |
+| `video`, `audio`, `pdf`, `file`, external | a web link, captioned | — |
+| `video`, `audio`, `pdf`, `file`, Notion-hosted | a placeholder naming the file. Notion's links to it expire in an hour, so a link would be dead tomorrow | the file (counted). Attachments are their own decision (§20) |
+| `embed`, `bookmark`, `link_preview` | a web link, the caption as its text | the preview |
+| `equation` | a fence with info `math`, the expression inside | the rendering |
+| `breadcrumb` | nothing. The `In:` line does its job | (counted) |
+| `table_of_contents` | nothing | (counted) |
+| `template` | nothing | (counted) |
+| `meeting_notes` (`transcription` before `2026-03-11`) | its child blocks, if the API returns any; otherwise a placeholder | the recording and its AI blocks |
+| `unsupported`, and any type this list does not name | its text, if it has any, as a paragraph; otherwise nothing | (counted by type, as memoria §5) |
+
+**Empty blocks** have no Markdown form (level-up §6.4 step 4) and are written as nothing.
+
+**A body's bytes** follow `markup.Join`'s seams: one blank line between blocks, one newline between list items. A page imported and then opened in the editor and left alone saves nothing (I1).
+
+### 10.2 Placeholder wording
+
+One quote line each, drafted here and settled through the copy-review skill:
+- `> From Notion: the database “Projects” isn't here yet. It will move to Fichas.`
+- `> From Notion: the file “report.pdf” wasn't imported.`
+- `> From Notion: a linked page that wasn't shared with the import.`
+- `> From Notion: a synced block whose original wasn't shared with the import.`
+
+Each placeholder's Notion id is recorded, sealed, on the ledger row, so phase 2 can find it (§17).
+
+## 11. Rich text
+
+### 11.1 Annotations
+
+| Notion | Mapa | Lost |
+|---|---|---|
+| bold | `**…**` | — |
+| italic | `*…*` | — |
+| bold and italic | `***…***`, as the editor writes it (level-up §6.3) | — |
+| code | `` `…` ``. Inline code takes no other mark. A run holding a backtick is written as plain text | the code style, for a run with a backtick (counted) |
+| strikethrough, underline | the text alone | the mark (counted) |
+| colour, background colour | the text alone | the colour (counted) |
+| link (`href`) | §11.3 | — |
+
+**Marks never cross a link, a mention or code** in Mapa (level-up §6.3). The mapper closes a mark before them and reopens it after. A bold link is a link. Whitespace at a mark's edge moves outside its delimiters, because a closing `*` needs a non-space before it.
+
+### 11.2 Mentions
+
+| Mention | Mapa |
+|---|---|
+| page, imported | `[[Mapa title]]`, or `[[Mapa title\|shown]]` when Notion showed different text |
+| page, not shared with the integration | Notion returns only the id, with the text `Untitled`. Mapa writes `(a Notion page not shared with the import)`, plain, and counts it under "links to pages not shared". Its id is recorded sealed, so a later run can link it (§13.5) |
+| page that is a database row | its text, plain, counted under "database rows" (§17) |
+| database | its text, plain, counted. An unshared one reads `Untitled` from Notion and is written like an unshared page |
+| date, a day | `[[2026-11-12]]`, a date link (P4) |
+| date with a time | `[[2026-11-12]] 14:00`. Times are written in the time zone Notion gives; if none, the team's (`MAPA_TIME_ZONE`) |
+| date range | `[[2026-11-12]] – [[2026-11-14]]`, times as above |
+| user | `@Name`, plain, as Notion sends it with the capability §6 asks for. Without it Notion sends `@Anonymous`; §19 checks |
+| link preview | a web link |
+| template mention, custom emoji | Notion's text, plain |
+
+**Date links reach each reader's own daily note** (base §3.4). A team page that says "see `[[2026-11-12]]`" sends Bo to his own note for that day. That is Mapa's ruled behaviour, and the import inherits it.
+
+### 11.3 Links
+
+- **A Notion page URL** (`notion.so/…`, `www.notion.so/…`, a workspace's `*.notion.site/…`, or a bare `/…`), whose last 32 hex digits are the id of an imported page, becomes a `[[link]]` with the run's text as shown text. A link to a block inside it (`#…`) becomes a link to the page, counted.
+- **A Notion URL to a page that is not imported** stays a web link while it is `https`. It works for people with Notion access until switch-over, and the report lists it under "links still pointing at Notion".
+- **Any other link** is `[text](url)` when `markup.SafeURL` accepts it, and the text alone otherwise (counted). Mapa never makes `javascript:` or `data:` clickable, and the import adds no way round that.
+
+### 11.4 Literal text Mapa would read as markup
+
+Mapa has **no escapes** (level-up D11): a literal `*word*` becomes emphasis, as it would if typed. The import follows that rule, with three exceptions where Mapa's reading would write into the namespace, the embed rules or block anchors:
+- **`[[` and `![[`** in Notion's literal text would make a link or an embed reference. The mapper writes the run as inline code. A run that also holds a backtick has a space inserted between the brackets (`[ [`).
+- **A trailing ` ^word`** would make a block marker. Same treatment.
+- **A bare `http(s)://` in text** already becomes a link in Mapa, and stays one.
+
+Everything else Mapa reads differently is accepted and counted: a paragraph that starts `1. ` becomes a list item, `# ` a heading, `> ` a quote, and `*a*` emphasis. The report lists the pages. A Notion user who typed those meant, nine times out of ten, what Mapa shows.
+
+**The structure check (D9).** After a body is rendered, `markup.Parse` must give exactly the blocks the mapper meant, in kind, level and order, with the links and embeds it meant and no others. A body that fails is not written: its page fails with `render_failed`, and a gate (I1) fails on any fixture that produces one. A wrong body is worse than a failed page, because a failed page says so.
+
+## 12. Images
+
+**P9: Notion-hosted images become real Mapa images.**
+
+**The images spec is not written yet.** This spec states what it needs as assumptions. The images spec confirms or changes each, and this section is revised to match before either is built.
+
+- **A1, a verb.** The store has a verb that adds an image, by an actor, with an event, from bytes and a declared type, and returns the Markdown that references it.
+- **A2, one transaction.** That verb runs inside the same `Store.write` as the create or commit whose body references the image, so a page and its images land together or not at all.
+- **A3, the reference is in the subset.** Whatever syntax references an image is parsed by `markup` and by the editor's port, and passes the structure check (D9).
+- **A4, checks.** The images spec decides formats and a size cap, and the image verb checks both by sniffing the bytes, never by trusting the type Notion declares. The file transport (§5) reads at most that cap.
+- **A5, alt text.** An image carries alt text. The import uses the Notion caption.
+- **A6, sealed.** Image bytes are sealed under their own purpose, and base §4's list gains whatever the images spec makes plaintext.
+- **A7, lifetime.** An image is kept while any revision in the window references it, so an import update that replaces an image leaves the old one to retention.
+
+**What the import does:**
+- **When:** during Write, for each image block that is new or whose `last_edited_time` changed since its last import. Notion's file URLs are signed and expire after about an hour, and Survey may finish long after it read the block. So Write fetches the block again (`GET /v1/blocks/{id}`) for a fresh URL, then downloads it through the file transport.
+- **Unchanged images are not downloaded again.** `notion_images` maps a Notion block to the Mapa image it became (§15). An unchanged block reuses it.
+- **A failure is not the page's failure.** An image that fails (host refused, too big, a format the images spec refuses, a 403 from an expired URL) becomes a placeholder, and the page is written. The report counts it by reason.
+- **External images** stay links (D13). **Q2** asks Paul whether he wants a second, stricter fetcher for them: public addresses only, `https`, the same caps, no cookies. It would be the first fetch from a host a page chooses, and it is not proposed here.
+
+## 13. Re-runs and idempotency
+
+### 13.1 The map
+
+`notion_pages` holds one row per Notion page the import has seen, for the life of the import, not per run. Its sealed part names the Notion id and the Mapa page it became. A Notion page becomes at most one Mapa page and a Mapa page comes from at most one Notion page. The map is how a re-run finds a page and never makes a second.
+
+### 13.2 Untouched (D8)
+
+For each mapped page on a re-run:
+
+| Mapa page | Notion page | What happens |
+|---|---|---|
+| revision is still the one the import wrote | rendered body and title equal what Mapa holds | nothing. No revision, no event |
+| revision is still the one the import wrote | changed | **updated**: a commit, and a rename if the title changed (§13.3), as the person running this run |
+| any later revision | anything | **kept**. Mapa's version stays whole. Listed in the report |
+| deleted in Mapa | anything | **not re-created.** Deleting it was a decision in the app of record. Listed |
+| restored as a new page | anything | the map still names the old, deleted page, so it is "deleted in Mapa". The restored page is an ordinary Mapa page |
+
+- **"Changed" is decided by the rendered output**, not by Notion's edit time. Survey reads every block anyway (§8.1), so rendering again costs no requests. That makes a title change in a mentioned page, a page newly shared, a move, or a mapper fix all reach the pages they affect, which an edit-time comparison would miss (memoria §1.1: an ancestor's rename never moved a child's edit time).
+- **Any later revision means edited**, a rename and "Update links" included. A rename leaves the body alone, but the person chose the page's Mapa name, and an import that renamed it back would undo a choice.
+- **A teammate's open draft does not stop an update.** Their draft's base is the import's revision, and their next commit merges against the update by base §5's block merge, as it would against a teammate's save.
+- **Rejected: merging Notion's change into Mapa's edit.** Mapa has the three-way merge. But P6 says Mapa's version is kept where edited, and a merge that happens unseen in a run is a write nobody chose (base §5: "Nothing is committed that nobody chose").
+
+### 13.3 Renames
+
+A Notion rename on an untouched page goes through Mapa's rename verb: the old title becomes an alias, so every link typed with it still resolves (base §3.4). The new title goes through §9.2's fitting and collision rules. Pages that link to it are re-rendered, and their links use the new title where those pages are untouched.
+
+### 13.4 Absence
+
+**Never delete on absence (P6).** A page that a complete survey does not find (unshared, moved out of the shared tree, trashed, deleted, or the token revoked) is left as it is in Mapa. Its row's `seen_run` stops moving, and the report lists it under "not found in Notion this time". Absence is reported only after a **complete** survey: an interrupted one proves nothing about what it did not reach.
+
+### 13.5 Links that heal
+
+A mention of a page that was not shared is plain text on the first run, and its target's id is kept sealed on the row. When a later run imports that target, the mentioning page renders differently, so §13.2 updates it if it is untouched. Sharing more pages with the integration and running again is how a person fixes "links to pages not shared".
+
+### 13.6 The fix-up pass
+
+Write commits pages one at a time while members may be using Mapa. If a member creates a page with a title the import had planned for another page, the create verb refuses it and the import takes the next candidate. Pages written earlier in the run that linked to the planned title would then point at the member's page. So after Write, the import re-renders every page it wrote in this run that links to a page whose title changed from its plan, and commits again where the page is still untouched. The report counts these. The race needs a member to type the exact title during a run, so this is expected to do nothing.
+
+## 14. History and events
+
+- **Every import write is an ordinary Mapa write**, through `Store.write`, in one transaction with its event (gate 8). The verbs are Mapa's existing ones: `created`, `edited`, `renamed`. The actor is the person who pressed Start or Resume (P7). **Mapa is never an actor** (base §2).
+- **No new verb.** An `imported` verb would put "this page came from Notion" into the plaintext event log. The provenance goes in the sealed record instead.
+- **The sealed record gains two optional fields** (base §3.1's `Record`, JSON, additive):
+ - `origin`: `{source: "notion", created, edited}`, Notion's own created and last-edited times for the page. Set by the import, and carried forward unchanged by every later commit, so a page always knows where it came from, even after its imported revision ages out of the 90-day window.
+ - `imported`: `true` on a revision the import wrote. Not carried forward.
+- **History shows it** (level-up §4.5): a revision with `imported` reads "Paul imported this from Notion · edited there 12 Oct 2026". The page's kicker may show "From Notion, created there 3 Mar 2024". Both read sealed fields, at render, for people who may open the page.
+- **S3 does not change.** S3 serves the title and body (base §8), not the record's other fields. memoria sees an imported page exactly as it sees any page.
+- **Revision `at` is the import's time**, never Notion's. The history window, retention, S1's order and "Recently edited" all count from Mapa's clock (base build note 30). Notion's times are history's content, not its clock.
+- **Notion's authors are not credited.** A Notion user is not a Mapa member, and P7 credits the importer. Notion's author names are not kept in history.
+- Every write in a run lands in the importer's "Recently edited". That is honest, and noisy for a day.
+
+## 15. Sealing
+
+**New purposes:** `notion.token`, `notion.workspace`, `notion.coordinate` (a row's Notion id, its Mapa page id, the revision the import last wrote, the ids it mentioned that were not imported, its placeholders' ids), `notion.staged` (a surveyed tree), `notion.image` (an image block's id, edit time and Mapa image). Print keys are derived apart, as base build note 21 does: `oficina/mapa:print:notion.page` and `…:notion.image`.
+
+**New tables and their plaintext,** to be added to base §4's list and to `plaintext_test.go` with the build:
+
+| Table | Plaintext | Sealed | What the plaintext leaks |
+|---|---|---|---|
+| `notion_connections` (one row) | `id`, `created_by` (member id), `created_at`, `verified_at` | token, workspace name | that a Notion connection exists, who made it, when it was last checked |
+| `notion_runs` | `id`, `actor`, `state`, `started_at`, `heartbeat_at`, `finished_at`, the counters, `error_code` | — | when imports ran, who ran them, how many pages each created, kept, failed |
+| `notion_pages` (the map) | `id`, `notion_print` (unique), `state`, `error_code`, `surveyed_run`, `seen_run`, `updated_at` | the coordinate record; the staged tree | how many Notion pages exist and their states. **Not which Mapa page each became**: the Mapa page id and revision are sealed, so the file does not mark which team pages came from Notion |
+| `notion_images` | `id`, `block_print` (unique) | the image record | how many images were imported |
+
+- **Prints are HMACs under the instance key**, equality only, as every print in Mapa (base §4).
+- **The staged tree is content**, held sealed between Survey and Write, then cleared. Finish deletes any that remain.
+- **No Notion content in any log line, error string or metric label** (gate I10, memoria N13). The fake's error bodies carry a canary title and id so the error path is exercised.
+
+## 16. memoria: retiring its connector
+
+**P10:** memoria stops holding Notion content and reads Mapa instead, through S1, S2 and S3.
+
+**What that depends on:**
+1. **The module exists** (§4), with memoria's client and traversal lifted into it. memoria's code is then the old copy.
+2. **Mapa's importer is built and has run** against Paul's workspace (§19).
+3. **Mapa's producer half is live**: base slice 1 item 6 (S1, S2, S3 through `server.Handler`, with pinned conformance), on the team host `paulca.mapa.oficina.works`. Not built today.
+4. **memoria is hooked up to Mapa**: Paul approves the hookup (open in memoria's follow-ups), and memoria's sibling list gains Mapa with a consumer token.
+5. **memoria finds an imported page**: a phrase from an imported page answers in memoria's search, cited to Mapa.
+
+**What the retirement is:**
+- remove `/connectors/notion` and its handlers, `connector.go`, `sync.go`, `internal/memoria/notion/`, and the "Sources" entry where it leads only there;
+- **narrow memoria's egress gate back**: the `internal/memoria/notion` exemption is deleted, so the provider package is the only exemption left;
+- delete any Notion credential row and any `Source = "notion"` documents, through memoria's own delete;
+- leave the tables (memoria's migrations are additive-only), unused;
+- mark memoria's Notion spec **superseded by this one**, and amend its parent's §11 (slice 3) and §4.2 to say Notion arrives through Mapa;
+- grep memoria for `notion` by name before calling it done (memoria AGENTS.md: "When you retire something, grep for it by name").
+
+**In what order (D14).** First check what memoria holds. Its Notion connector has never run against a real workspace, so it is expected to hold nothing.
+- **If live memoria holds no Notion documents and no token:** retire it as soon as step 1 is done. Nothing is lost, and the egress exemption goes sooner.
+- **If it holds any:** retire it only after step 5, so there is never a moment when that content is findable in neither app.
+
+**Until then, memoria's connector is not run.** Paul's real run goes to Mapa (§19).
+
+## 17. Phase 2: databases into Fichas (a sketch)
+
+**Waits on:** the Fichas level-up (the type designer, folders, and "Link to …" fields, `design/type-designer`), Fichas on a team host, Mapa's embeds (base slice 2, S10), and this phase 1. This section is a sketch for that spec, not a design.
+
+**Shape:**
+- **A Notion database becomes a Fichas card type** per data source, in a folder named for the database.
+- **A row becomes a card.** Row bodies (Notion rows are pages and often hold text) go into a Long text field, `Notes`, mapped by Fichas from the same block tree.
+- **Properties become fields:**
+
+| Notion property | Fichas field | Notes |
+|---|---|---|
+| `title` | the title field | — |
+| `rich_text` | Text, or Long text over one line | annotations as Fichas' long text allows |
+| `number` | Number | format (currency, percent) needs a decision |
+| `select` | Choice, options and colours as tones | — |
+| `status` | Choice, marked as the type's status | Notion's status groups are lost |
+| `multi_select` | needs a multi-value Choice, which Fichas does not have | Text until it does |
+| `date` | Date | ranges and times need a decision |
+| `checkbox` | a Yes / No Choice | — |
+| `url`, `email`, `phone_number` | Web address, Email, Phone | — |
+| `people` | a Link to the seeded People type (type designer R5) | names need the user-information capability, which §6 does not ask for |
+| `relation` | Link to … the type the related database became | the property endpoint returns relations past the first 25 |
+| `formula`, `rollup` | not imported as live values. Fichas has no formulas; a snapshot would be "a second calculator" (Fichas §2) | listed per type |
+| `files` | not imported until Fichas has attachments | listed |
+| `created_time`, `last_edited_time`, `created_by`, `last_edited_by` | the card's history, sealed, as §14 does for pages | — |
+| `unique_id` | Text, as a print | — |
+| `button`, `verification`, `place` | not imported | listed |
+
+- **Views.** Notion added view endpoints on 2026-03-19 (list, retrieve, query). A Notion view's filters and sorts can become a Fichas saved view (base §7.6) where each filter maps onto a field Fichas has. A view that cannot map is listed, not approximated.
+- **Mapa's placeholders.** Each database placeholder (§10.2) has its Notion id sealed on its page's row. Once Fichas holds the database, Fichas' import page offers a hand-off (doctrine §7.1: a redirect `POST` in the person's own session) that tells Mapa which Fichas view each database became. Mapa replaces each placeholder with `![[fichas:…]]` on pages still untouched, under §13.2's rule, as the person's edit.
+- **Relations to pages.** A Notion relation targets database rows only. A row's mention of an ordinary page needs Mapa's map: Mapa's import page offers the reverse hand-off (Notion id → Mapa page URL), so Fichas can write a Mapa reference field (base §7.4: team pages only, which every imported page is).
+- **Mapa keeps its map after Finish** for exactly this (§8.6), until "Forget the import".
+
+## 18. Gates
+
+**Base gates 1–12, level-up gates L1–L12 and `make mutate` keep passing.** New gates are I1–I16 in Mapa and M1–M8 in the module. Each is written, broken and reverted per path, with the mutation and date in the test comment. **The mutations are picked by someone who did not write the gate** (memoria AGENTS.md, gate 17).
+
+### The fixtures
+
+- **Written from the documentation:** one fixture per block type in §10.1's table and per annotation and mention in §11, including the unsupported ones, a 404 on one page, a 429 with `Retry-After`, `has_more` with no cursor, a repeated cursor, a page under a `block_id` parent, a search result that returns only roots, a trashed page, a database row shared directly, and an image whose URL has expired.
+- **Recorded, with the shape of a real workspace:** `cmd/notion-record` records responses from a workspace, then **scrubs** them: every text run, title, caption, URL and file name is replaced by deterministic filler of the same length class, and every id by a stable fake. Structure, nesting, block types, annotations and counts survive. **Only scrubbed recordings are committed.** The raw recording stays outside every repository and is deleted after scrubbing. Its block-type counts are recorded in the build notes.
+- **Why recorded fixtures.** memoria's blocker was found by a reviewer reading the documentation, because every fixture was written from its author's model. A recording is the first fixture written by Notion.
+
+### In the module (M)
+
+- **M1, the total decoder.** A missing cursor, a repeated cursor, or retries past budget fail with `traversal_failed`, never a partial tree (memoria N1).
+- **M2, search is not an enumerator.** A fake whose search returns only roots still yields every child (memoria N2).
+- **M3, orphans after the walk.** A page under a `block_id` parent gets its true parent, not a root's place (memoria §1.3's blocker, now with a test).
+- **M4, the API pin.** Another host, another scheme, any redirect, any method but `GET`, and any `POST` path but `/v1/search` are refused before dialling. One mutation each.
+- **M5, the file pin.** A host outside the allowlist, any redirect and an over-cap body are refused. **No request to a file host carries an `Authorization` header.**
+- **M6, one place dials.** Inside the module, only `client.go` and `files.go` build a client or transport.
+- **M7, the version pin.** Every request carries the pinned `Notion-Version`.
+- **M8, the tree is total.** Every block type in the fixture set decodes to a typed block or to `unsupported` with its type name, never to nothing.
+
+### In Mapa (I)
+
+- **I1, fidelity.** For every fixture, the mapper's body equals a committed golden file, passes the structure check (D9), and loses nothing outside §10–§11's tables: each loss is in the counts. **Each imported body opened in the editor and left alone serialises to the same bytes** (L1's rule, run over the import goldens, which join `markup/testdata/corpus/`).
+- **I2, an idempotent re-run.** Run, then run again on the same fixtures: no revision, no event, no image download, every page `unchanged`.
+- **I3, untouched and kept.** Change two pages in the fake. Edit one of them in Mapa, rename a third in Mapa. Re-run: the untouched page updates, as the runner, with one event; the edited and renamed pages are kept and listed.
+- **I4, never delete on absence.** Two pages imported; the fake drops one; the run is `done` and both pages stand. An interrupted survey reports no absence.
+- **I5, links.** Mentions resolve to final titles, collision-renamed ones included. An unshared target is plain text and counted; sharing it and re-running links it where the source is untouched. A Notion URL to an imported page becomes a `[[link]]`.
+- **I6, titles.** Duplicates, `[ ] | # ^`, over-long, empty and date-shaped titles all fit by §9.2. The same fixtures give the same titles twice. An existing Mapa page with the title is never written to. A member taking a planned title mid-run is handled by the fix-up pass.
+- **I7, events.** Every import write logs an event naming the runner, inside gate 8. *Mutation: commit a page without its event.*
+- **I8, egress.** No `http.Client`, transport, request constructor, dialler or resolver anywhere in `internal/mapa/**` or `cmd/**`; the module imported only by `import_*.go`. *Mutations: add an `http.Get` to a handler; import the module from `notionmd`.*
+- **I9, plaintext.** The new tables' plaintext columns are exactly §15's. The file scan runs a full import over fixtures carrying canary titles, bodies, a canary token and canary Notion ids, then reads every byte on disk, WAL included: none appears.
+- **I10, no Notion content in logs**, observed over a run against the fake whose error bodies carry canaries (memoria N13).
+- **I11, the token is never rendered**: no 8-character run of it in any response (memoria N14).
+- **I12, resuming.** A run left `surveying` becomes `interrupted` at boot and the next Start runs. A resumed survey makes no request for a page already surveyed in that run. A resumed write writes no page twice.
+- **I13, who sees Import.** With `MAPA_IMPORTERS` unset every import route 404s for everyone. With it set, a member not named gets 404 on every route, `GET` and `POST`. Nothing outside Import changes for them.
+- **I14, images.** A Notion-hosted image becomes a Mapa image through the images verb; an external one stays a link; an unchanged image block is not downloaded again; an image failure leaves a placeholder and a written page. *Depends on the images spec (§12).*
+- **I15, scriptless.** `make browser` connects, starts, watches the meta refresh, resumes and finishes with JavaScript off, then on.
+- **I16, no write to Notion.** Over a whole run against the fake, the fake records every request: only `GET`s and `POST /v1/search`.
+
+**And the run is looked at in a browser**, at 0%, mid-survey, mid-write, interrupted and finished, before the build is called done. A template test proves markup exists, not that a run reads sensibly at 40% (memoria §13).
+
+## 19. The first real run
+
+Against Paul's workspace. **Read-only on Notion's side**, owned by Paul, and a ship requirement before the import is offered on his real team (memoria §15's requirement, inherited).
+
+**Before**
+1. Paul makes an internal integration, "Oficina import": **Read content** only; no update, no insert, no comments; user information **without email addresses**. He checks the capabilities page shows exactly that.
+2. He shares a small set of top-level pages with it, a few hundred pages at most for the first run, not the workspace root.
+3. `cmd/notion-record` records that set, from Paul's machine, into a directory outside every repository. Scrub it, commit the scrubbed fixtures to the module, delete the raw recording. Compare its block types with §10.1: any type not in the table is added to the table before the run.
+4. Check the image file URLs in the recording against the file transport's (host, path prefix) pairs. Fix the allowlist from what Notion actually sends, not from the documentation's one example.
+5. Check that user mentions carry names (§11.2), and what a synced block's copy returns for its children (§10.1).
+
+**The run, on the `test` team first** (`test.mapa.oficina.works`, disposable)
+6. Connect, run, and watch the status page through to the end.
+7. Check the report: roots named as expected, page count against what Notion shows, failures with codes, blocks not imported by type, images.
+8. Side by side, ten pages chosen for variety (toggles, tables, callouts, code, images, nesting, mentions, a journal page): compare Notion and Mapa.
+9. Run again at once: **nothing written** (I2 on real data).
+10. Edit one page in Notion and a different one in Mapa. Run again: the first updates, the second is kept.
+11. Record the time per page and the number of requests in the build notes.
+
+**On the real team** (`paulca`)
+12. The same run, then Finish only when Paul says Notion is no longer the source.
+13. After Finish: in Notion, Settings, Connections, delete the integration. In Mapa, check the connection row is gone.
+14. After memoria's hookup (§16 step 4): a phrase from an imported page answers in memoria, cited to Mapa.
+
+## 20. Deliberately not built
+
+| Thing | Trigger |
+|---|---|
+| A scheduled or continuous sync | Paul wants Notion and Mapa both live for a long time. The import is a migration |
+| Writing anything to Notion | Never (§0) |
+| Fetching external images | Paul says yes to Q2 |
+| Attachments (PDFs, files, audio, video) | Mapa gets attachments. Until then, placeholders |
+| Comments, page icons and covers | Someone misses them after a real import |
+| Private import | Mapa gets private titled pages, which base decision 7 rules out |
+| Merging Notion's change into a Mapa-edited page | People ask for it after living with "kept" |
+| Undo import (delete every untouched imported page) | The first real run on `test` shows a need. The `test` team is disposable meanwhile |
+| The export zip as a source | The API misses something the zip has |
+| Databases | Phase 2 (§17) |
+
+## 21. Amendments that land with the build
+
+Not made in this commit. Each lands in the same commit as the code it describes.
+- **Mapa base spec:** §12's "Import from Obsidian, Reflect, Notion" row is met for Notion; §4's plaintext list gains §15's rows; §3.1's record gains `origin` and `imported`; §11 lists I1–I16; the leak list gains §5's entries.
+- **Mapa AGENTS.md:** "Mapa reaches the network only through `amadan.net/oficina/notion.git`, only from `import_*.go`, only during a run" joins the rules Mapa holds hard. Layout gains `notionmd/` and the import files.
+- **Mapa README:** the leak list and `MAPA_IMPORTERS`.
+- **memoria:** §16's list, in the commit that retires the connector.
+
+## 22. Build order
+
+0. **This spec, reviewed.** Then Paul's answers to §23. Then the images spec, and §12 revised to match it.
+1. **The module.** The repo; memoria's client and traversal lifted with their history noted; the typed tree; the file fetcher; the fake; the recorder and scrubber; M1–M8.
+2. **The mapper** (`notionmd`), against fixtures only: §10–§11, I1, I5's resolution half, I6.
+3. **The run**: tables, the credential, Survey and Write, the screens, I2–I4, I7–I13, I15, I16.
+4. **Images**, once the images verb exists: I14.
+5. **§19's first real run**, steps 1–11 on `test`.
+6. **memoria's retirement** (§16), at the point D14 says.
+7. **Steps 12–14 on `paulca`**, when Paul says.
+
+Each step is reviewed before the next is merged.
+
+## 23. Open questions for Paul
+
+Recommended answers are written in. None is ruled.
+
+1. **Q1, who may import?** *Recommended:* only the addresses in `MAPA_IMPORTERS`; on your teams, you. Without it, every member could connect a Notion workspace and write hundreds of team pages in their own name.
+2. **Q2, external images** (an image in Notion that points at another website): *Recommended:* keep them as links, not downloaded. Downloading means Mapa fetching from any address a page names, which is a different kind of egress from fetching Notion's own files. If many of your pages use them, say so and a stricter fetcher can be specified.
+3. **Q3, date-titled pages** (a Notion journal): *Recommended:* team pages titled `2024-03-05 (Notion)`, each linking its date, so your daily note for that day lists it. The alternative is importing them as your own private daily notes, which takes them away from the team.
+4. **Q4, parent and child:** *Recommended:* a link to each child where Notion shows it in the parent, and an `In: [[Parent]]` line at the top of each child.
+5. **Q5, toggles:** *Recommended:* opened out: the toggle's line in bold, its contents after it. Mapa has no collapsing block.
+6. **Q6, switch-over:** *Recommended:* "Finish import" deletes the Notion token and the staged copies, and keeps Mapa's private map of which Notion page became which Mapa page until the databases have moved to Fichas.
+7. **Q7, the new repository** `oficina/notion` for the shared Notion code, with the amadan workflow on. *Recommended:* yes.
+8. **Q8, Notion user names:** *Recommended:* the integration may read people's names, never their email addresses, so `@Ana` stays `@Ana` instead of `@Anonymous`.
+9. **Q9, memoria's connector:** *Recommended:* if live memoria holds no Notion content, which is expected because it never ran, remove it as soon as the shared module exists.
+
+## 24. Findings and what changed
+
+*(Filled in by each review round.)*