oficina / mapa Public

Mapa level-up spec, revision 2: answer Fable's review of revision 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Human

Prompt

Fable (claude-fable-5-2) reviewed spec rev 1 at 4027e10: CHANGES REQUIRED (H1-H4, M1-M10, lows). Revise the spec to rev 2 on the same branch, add a findings-to-changes table at the end, write Fable's recommended answers to Q1-Q4 as proposed and awaiting Paul, push and report. No code yet.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Rebase now moves the draft's base through a version-checked autosave and resolves through Resolve; autosave's reply merges exactly the text sent; offered drafts commit only on Save; fidelity keyed on origin ids with eq, kept seams and a structure check; byte-preserving Settle; marks, lists, whitespace, clipboard, history verbs, scratch first commit and corpus curation specified; section 14 maps every finding.
Agent notes
Verified against code: SaveDraft sets BaseRevision only on create; Settle re-joins with Join; bulk edits log VerbEdited; Go renders ***x*** as <strong><em>x</strong></em> and drops **a *b* c**.
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ad06a4e5aea4a5222fe37df2371a1423f1adb4c4 parent 4027e10
1 file changed, +779 −401
  • docs/superpowers/specs/2026-11-14-mapa-level-up.md +779 −401

CI passed — run details

CI log
=== 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	(cached)
?   	amadan.net/oficina/mapa/internal/mapa/icons	[no test files]
ok  	amadan.net/oficina/mapa/internal/mapa/markup	(cached)
ok  	amadan.net/oficina/mapa/internal/mapa/seal	(cached)
ok  	amadan.net/oficina/mapa/internal/mapatest	7.678s
?   	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
diff --git a/docs/superpowers/specs/2026-11-14-mapa-level-up.md b/docs/superpowers/specs/2026-11-14-mapa-level-up.md
index 954ce13..956d165 100644
--- a/docs/superpowers/specs/2026-11-14-mapa-level-up.md
+++ b/docs/superpowers/specs/2026-11-14-mapa-level-up.md
@@ -1,62 +1,107 @@
# Mapa level-up: Contexto with Página's rail, and a page you write on
-**Status:** revision 1, 2026-11-14, for review. Nothing is built.
+**Status:** revision 2, 2026-11-14. Nothing is built.
+- Revision 1 (`4027e10`) was reviewed by Claude Fable 5.2: CHANGES REQUIRED, with 4 high, 10 medium and 11 low findings. It agreed with the direction.
+- This revision answers every finding. §14 maps each finding to its change.
+- Paul has not yet answered §11's questions. The proposed answers are written in and marked "awaiting Paul".
+
**Branch:** `design/level-up` (Mapa). Later, an estilo branch for the floating panel (§9).
-**Base spec:** `2026-11-12-mapa-design.md`, approved. It still binds. This spec changes the surface (base §6) and the editor. It changes no trust property. §10 lists every place it departs from the base spec or the mock-ups.
-**Mock-ups:** `oficina/polish-audit/mapa-ux/` (`c.html`, `a.html`, `README.md`, `shots/`). They are the reference for look and measurement. They move things with script and fake their data; the build renders everything on the server.
+
+**Base spec:** `2026-11-12-mapa-design.md`, approved. It still binds.
+- This spec changes the surface (base §6), the editor, and a few store rules that make existing promises stricter.
+- It changes no trust property.
+- §10 lists every departure from the base spec and from the mock-ups.
+
+**Mock-ups:** `oficina/polish-audit/mapa-ux/` (`c.html`, `a.html`, `README.md`, `shots/`).
+- They are the reference for look and measurement.
+- They move things with script and fake their data. The build renders everything on the server.
## 1. Why
Paul, 2026-11-14, after using the slice 1 preview: *"it needs some serious levelling up. It should have WYSIWYG. Let's not copy Notion outright, but the page should be full-screen, the sidebar icons should line up etc. etc. It needs a serious UX pass."*
-He was shown three directions (Página, Estante, Contexto) and ruled: **"Let's do it Contexto, with Página's rail."** He accepted the small map that comes with Contexto.
+He was shown three directions: Página, Estante and Contexto. He ruled: **"Let's do it Contexto, with Página's rail."** He accepted the small map that comes with Contexto.
## 2. What was chosen
-- **Header:** Docs' and Slides' I2 stacked header (estilo `Bar.Menubar` and `Bar.Lead`, from `39792ae`): Mapa's mark, the title with rename in place, and the Page, Edit, Insert, View and Help menus.
-- **Sidebar:** Today, Search ⌘K, All pages, Scratch, then Pinned and Recent, and "New team page" at the foot. Every row is one grid: a 16px icon column and a label, centred on one axis. ⌘\ folds it to Página's 56px icon rail, and back.
-- **The page is the window:** full-width white, a 42rem measure, a large title, and WYSIWYG writing. There is no form, no label and no Save button. Autosave goes through the existing drafts (base §5).
-- **Links panel:** Docs' floating glass inspector, toggled from the header. It holds "Around this page" (the map), Linked from (with each sentence), Mentioned without a link (with Link it) and Links out. On a daily note it is the week.
+- **Header:** Docs' and Slides' I2 stacked header, from estilo `39792ae`.
+ - It uses `Bar.Menubar` and `Bar.Lead`.
+ - It shows Mapa's mark, the title with rename in place, and the Page, Edit, Insert, View and Help menus.
+- **Sidebar:** Today, Search ⌘K, All pages and Scratch; then Pinned and Recently edited; then "New team page" at the foot.
+ - Every row is one grid: a 16px icon column and a label, centred on one axis.
+ - ⌘\ folds it to Página's 56px icon rail, and back.
+- **The page is the window:** full-width white, a 42rem measure, a large title, and WYSIWYG writing.
+ - There is no form, no label and no Save button.
+ - Autosave goes through the existing drafts (base §5).
+- **Links panel:** Docs' floating glass inspector, toggled from the header. It holds:
+ - "Around this page", the map;
+ - Linked from, with each sentence;
+ - Mentioned without a link, with Link it;
+ - Links out.
+ On a daily note, it is the week.
- **Day navigation:** ‹ Today › and a month calendar.
-- **History:** a side panel. Choosing a version shows its diff, with Restore.
+- **History:** a side panel. A chosen version shows its diff, with Restore.
- **⌘K:** one box over titles, aliases, text and dates.
- **Phone:** the Links panel becomes a sheet with a peek line.
-The work comes in two phases. **Phase 1** builds the chrome around today's editor. **Phase 2** replaces the textarea with a ProseMirror editor that stores Markdown (§6).
+**Two phases:**
+- **Phase 1** builds the chrome around today's editor. It also makes the server's HTML match what the editor will draw.
+- **Phase 2** replaces the textarea with a ProseMirror editor that stores Markdown (§6).
## 3. The shell
### 3.1 Header
- **estilo's stacked `Bar`**, exactly as Docs uses it:
- - `Bar.Menubar` holds Page, Edit, Insert, View and Help (§3.4).
- - `Bar.Lead` holds presence ("Ana is editing", team pages only, base §5), then estilo's `savestatus`, then the day pill on daily notes (§4.4).
- - The actions are Search ⌘K, History and Links. Links is a `WideOnly` toggle action with `aria-expanded` and `aria-controls`, like Docs' Format.
- - The account comes last, after estilo's divider.
-- **Mark and hue:** Mapa's own mark at hue 125, from estilo `f724edb`. The Oficina fallback in `render.go`'s `themeSlug` goes, and so does the AGENTS.md follow-up about it.
+ - **Menubar:** `Bar.Menubar` holds Page, Edit, Insert, View and Help (§3.4).
+ - **Lead:** `Bar.Lead` holds, in order:
+ - presence, "Ana is editing", on team pages only (base §5);
+ - estilo's `savestatus`;
+ - the day pill, on daily notes (§4.4).
+ - **Actions:** Search ⌘K, History and Links.
+ - Links is a `WideOnly` toggle action, with `aria-expanded` and `aria-controls`, like Docs' Format.
+ - **Account:** last, after estilo's divider.
+- **Mark and hue:**
+ - Mapa gets its own mark at hue 125, from estilo `f724edb`.
+ - `render.go`'s `themeSlug` fallback goes.
+ - So does the AGENTS.md follow-up about it.
- **Title row:**
- - A team page's title is estilo's sized title field, renamed in place. It posts the existing `POST /p/{id}/rename`, so the old title becomes an alias (base §3.4).
- - A daily note shows its long date ("Saturday 14 November") as plain text. A scratch page shows its first line as plain text. Neither has a title in the namespace (base §3.3), so neither can be renamed.
+ - A team page's title is estilo's sized title field, renamed in place.
+ - It posts the existing `POST /p/{id}/rename`.
+ - The old title becomes an alias (base §3.4).
+ - A daily note shows its long date ("Saturday 14 November") as plain text.
+ - A scratch page shows its first line as plain text.
+ - Daily notes and scratch pages have no title in the namespace (base §3.3), so neither can be renamed.
- **Below 800px:** estilo's second row, untouched (estilo review #34).
### 3.2 Sidebar and rail
- **Rows:**
- Places: Today, Search ⌘K, All pages, Scratch.
- - **Pinned:** the viewer's pins (§10, D1).
- - **Recent:** the six pages the viewer last committed a revision to, team pages and their own (§10, D2).
+ - **Pinned:** the viewer's own pins (§11, Q1).
+ - **Recently edited:** the six pages the viewer last committed a revision to.
+ - Team pages and their own private pages are included. Pages that are deleted or out of scope are not.
+ - It is drawn from the event log, with verbs `created`, `edited` and `reverted`.
+ - Bulk edits do not count. "Update links", "Link it" and "Link to this block" log their own verbs (§8), so they are left out.
- At the foot: **New team page**.
-- **Alignment:** each row is `display: grid; grid-template-columns: 16px 1fr; align-items: center`. Today's misalignment comes from rastrillo's `[rst-shell-nav] a`: it is not a flex row, so the icon sits on the text's baseline about 3px high. Mapa stops using `rst-shell-sidebar`. The estilo bar sits on top, and Mapa's own `[mapa-side]` sits below it. The rastrillo bug is reported upstream, because Fichas still has it.
+- **Alignment:** each row is `display: grid; grid-template-columns: 16px 1fr; align-items: center`.
+ - Today's misalignment comes from rastrillo's `[rst-shell-nav] a`. It is not a flex row, so the icon sits on the text's baseline, about 3px high.
+ - Mapa stops using `rst-shell-sidebar`. The estilo bar sits on top, and Mapa's own `[mapa-side]` sits below it.
+ - The rastrillo bug is reported upstream, because Fichas still has it.
- **The rail:**
- - 56px wide, with the same rows drawn as icons only, each a 40×38px target.
- - Labels stay in the accessibility tree, visually hidden, and show as a tooltip on hover and focus.
- - The current place has a 3px accent bar at the inline start. Pinned and Recent are hidden in the rail.
+ - 56px wide. Rows are icons only, with 40×38px targets.
+ - Labels stay in the accessibility tree, visually hidden. They show as a tooltip on hover and on focus.
+ - The current place has a 3px accent bar at the inline start.
+ - Pinned and Recently edited are hidden.
- A fold button sits at the rail's foot.
- **Folding:**
- - ⌘\ (Ctrl+\ elsewhere) folds the sidebar to the rail and opens it again. So do View → Sidebar and the fold button.
+ - ⌘\ (Ctrl+\ elsewhere) folds and unfolds the sidebar. So do View → Sidebar and the fold button.
- The state is the cookie `mapa-sidebar`, set to `open` or `rail`. The server renders it, so first paint is already right.
- - With no cookie, CSS decides: open from 80rem, the rail below that.
- - Without script, the fold button is a form that sets the cookie and redirects back. It is a view preference: it writes no row and logs no event.
+ - With no cookie, CSS decides: open from 80rem, the rail below that (§11, Q4).
+ - Without script, the fold button is a `POST /view/sidebar` form.
+ - It carries a `return` path, which is checked to be a local path. Anything else falls back to `/`.
+ - It sets the cookie and redirects back.
+ - It is a view preference: it writes no row and logs no event.
### 3.3 Breakpoints
@@ -64,540 +109,873 @@ These follow estilo's breakpoints (I2 revision 2, P1.3).
| Width | Sidebar | Links | Day pill |
|---|---|---|---|
-| 64rem and wider | open or rail (cookie) | floating panel, toggled (cookie `mapa-links`, open by default) | lead slot |
-| 800px to 64rem | rail by default; the cookie may open it | at the page's foot; the toggle is hidden (`WideOnly`) | lead slot |
-| Below 800px | none; its places are rows in estilo's Menu sheet | a bottom sheet with a peek line | the page's kicker line |
+| 64rem and wider | open or rail (cookie) | a floating panel, toggled. Cookie `mapa-links`, open by default | lead slot |
+| 800px to 64rem | rail by default; the cookie may open it | at the page's foot. The toggle is hidden (`WideOnly`) | lead slot |
+| Below 800px | none. Its places are rows in estilo's Menu sheet | a bottom sheet with a peek line | the page's kicker line |
-When the panel is off, at any width, the same lists render at the page's foot. Nothing about the page is ever out of reach.
+When the panel is off, at any width, the same lists render at the page's foot.
### 3.4 Menus
-The menus are estilo's `menubar`, with keyboard shortcuts shown. An entry that does not apply is not drawn; it is never shown disabled with no reason.
+The menus are estilo's `menubar`, with their keyboard shortcuts shown. An entry that does not apply is not drawn.
- **Page:**
- - New team page, New scratch page.
- - Rename (team), Pin / Unpin.
+ - New team page and New scratch page.
+ - Rename (team) and Pin / Unpin.
- Make team page (private notes).
- Link to this block (team).
- - History, Delete…, Deleted pages.
-- **Edit:** Undo, Redo, Select all.
+ - History, Delete… and Deleted pages.
+- **Edit:** Undo, Redo and Select all.
- **Insert:** the `/` menu's blocks (§6.6), with their Markdown shortcuts shown.
- **View:**
- Sidebar ⌘\.
- Links.
- Edit as Markdown: the scriptless textarea, kept as the floor (§6.10).
-- **Help:** Keyboard shortcuts, "Markdown in Mapa" (the subset), and Colophon (with ProseMirror once Phase 2 ships).
+- **Help:**
+ - Keyboard shortcuts.
+ - "Markdown in Mapa": the subset.
+ - Colophon, with ProseMirror once Phase 2 ships.
## 4. The screens
### 4.1 A page
-- **Kicker line**, muted and above the title. It is one of:
+- **Kicker line:** muted, above the title. One of:
- "Team page · Edited by Ana at 11:40 · Also called Brightwater";
- "Your note. Only you can open it.";
- "Scratch. Only you can open it."
- **Title:** an H1 at 2.5rem, or 1.875rem on a phone.
- - A team page's in-page title edits through the same rename POST as the header. One pending state covers both, so nobody renames twice (mock-up risk 9).
- - After a rename, "Update links to the new title" becomes a notice on the page with its own POST. Its count follows base §3.4 and is unchanged.
-- **Body:**
- - The rendered Markdown in Phase 1. The editor in Phase 2.
- - An empty body shows a placeholder: "Write, or type / for blocks and [[ to link". It is drawn by CSS on the server's own empty paragraph, so it causes no shift.
-- **The draft offer** (base §5) stays. In Phase 2 the editor mounts over the draft's text, with the offer above it as a bar (§6.8).
+ - A team page's in-page title edits through the same rename POST as the header, with one pending state shared by both. That way nobody renames twice (mock-up risk 9).
+ - After a rename, "Update links to the new title" becomes a notice on the page, with its own POST. The count it reports is unchanged (base §3.4).
+- **Body:** the rendered Markdown in Phase 1, and the editor in Phase 2.
+ - An empty body shows a placeholder: "Write, or type / for blocks and [[ to link".
+ - The placeholder is CSS on the server's own empty paragraph, so it causes no shift.
+- **A person with a draft on the page** sees their draft's text (§6.8).
- **"Make team page":**
- Phase 1 keeps today's form, restyled.
- Phase 2 starts it from a selection (§6.7).
-- **Layout:**
- - The page column is centred.
- - It moves left only when the open panel needs the room. This is Docs' sheet-centring rule, measured on the container, not `100vw`.
+- **Layout:** the page column is centred. It moves left only when the open panel needs the room.
+ - This is Docs' sheet-centring rule.
+ - It is measured on the container, not on `100vw`.
-### 4.2 Chips (the server renders them in Phase 1)
+### 4.2 Chips
-Links render as chips. Phase 2's editor draws the same markup (§6.9).
+The server renders chips from Phase 1. The editor draws the same markup (§6.9).
| Kind | Look | Accessible name |
|---|---|---|
-| Team page | a pill; the page glyph in Mapa's accent; ink text | "Halden Robotics, team page" |
-| Through an alias | as a team page; the title shows as typed; a tooltip "Now called Halden Robotics" | "Halden Automation, now called Halden Robotics" |
-| Pending | no fill, a dashed rim, a "page +" glyph, muted text: three cues | "Pricing 2027, page not written yet" |
-| Date | a calendar glyph and "Thursday 12 November", never the ISO text | "Thursday 12 November, your note" |
-| Block link | a team chip with a ¶ glyph; "block removed" when the block has gone (base §3.2) | "…, a block in Acme" |
-| Broken date (`[[2026-02-30]]`) | plain text, as today | |
-| Embed (slice 1) | a quiet chip showing the reference (`fichas:…`) | "Embedded item, not shown yet" |
+| Team page | A pill. The page glyph is in Mapa's accent and the text is ink | "Halden Robotics, team page" |
+| Through an alias | As a team page. The title shows as typed, with a tooltip: "Now called Halden Robotics" | "Halden Automation, now called Halden Robotics" |
+| Pending | No fill, a dashed rim, a "page +" glyph, and muted text. That is three cues | "Pricing 2027, page not written yet" |
+| Date | A calendar glyph and "Thursday 12 November", never the ISO date | "Thursday 12 November, your note" |
+| Block link | A team chip with a ¶ glyph. Shows "block removed" when the block has gone (base §3.2) | "…, a block in Acme" |
+| Broken date (`[[2026-02-30]]`) | Plain text, as today | |
+| Embed (slice 1) | A quiet chip showing the reference (`fichas:…`) | "Embedded item, not shown yet" |
-Slice 2's estilo card partial replaces the embed chip. The mock-up's Fichas card waits for slice 2 (§10, D7).
+Slice 2's estilo card partial replaces the embed chip (§10, D7).
### 4.3 The Links panel
- **Panel:**
- - 312px wide, glass, 12px under the header and 12px in from the inline end. Docs' inspector recipe: a 14px radius, the rim, the shadow, and much fainter in dark.
- - It is `<aside aria-label="Links">`. Its state lives in the cookie `mapa-links`: open by default, closed only for an exact `closed`, and rendered by the server.
+ - 312px of glass, 12px under the header and 12px in from the inline end.
+ - It follows Docs' inspector recipe: a 14px radius, the rim and the shadow, and much fainter in dark.
+ - It is `<aside aria-label="Links">`.
+ - The cookie `mapa-links` holds its state. It is open by default and closed only for an exact `closed`. The server renders it.
- **Sections, in order:**
- 1. **Around this page**, the map (below).
- 2. **Linked from N**, grouped by source page, with each block that links here. The link is marked inside the sentence. The viewer's own private notes carry "Only you" and a lock glyph.
- 3. **Mentioned without a link N**, each with the sentence and a Link it button (the existing POST).
- 4. **Links out N**: chips, pending ones included, in body order with duplicates removed.
+ 1. **Around this page:** the map (below).
+ 2. **Linked from N:** grouped by source page, with each block that links here and the link marked inside it.
+ - The viewer's own private notes carry "Only you" and a lock glyph.
+ 3. **Mentioned without a link N:** each with its sentence and a Link it button, which uses the existing POST.
+ 4. **Links out N:** chips in body order, without duplicates. Pending links are included.
- **On a daily note:**
- - **This week** comes first: Monday to Sunday (Europe/Dublin, or the viewer's zone), with ‹ › for the week. A dot marks a day the viewer wrote a note, today is ringed, and the day on screen is filled.
- - A "November" button opens the month (§4.4).
+ - **This week** comes first: Monday to Sunday, in the viewer's zone, with ‹ › to move a week.
+ - A dot marks a day the viewer wrote a note. Today is ringed, and the day on screen is filled.
+ - A "November" button opens the month (§4.4).
- Then Links out, then Linked from ("No page links to this day yet…").
- **The map:**
- - An SVG drawn by the server, not a simulation. This page sits at the centre and its neighbours sit on a ring.
- - Neighbours are the pages in Linked from, Links out (pending ones as dashed circles) and Mentioned. Linked pages come first, in a stable order (by public id), capped at 12. Past that there is no node and no count. The lists below are complete.
- - **Edges:** solid for a link, dashed for a link to a page not written yet, dotted for a mention. Edges between two neighbours are drawn when one links to the other in the viewer's scope.
+ - An SVG the server draws. There is no simulation.
+ - This page is at the centre, and its neighbours sit on a ring.
+ - **Neighbours:** Linked from, Links out (pending links as dashed circles) and Mentioned.
+ - Linked pages come first, in a stable order (by public id).
+ - At most 12 are drawn. There is no "more" node and no count; the lists below are complete.
+ - **Edges:**
+ - solid for a link;
+ - dashed for a link to a page not written yet;
+ - dotted for a mention.
+ - An edge between two neighbours is drawn when one links to the other in the viewer's scope.
- Only "here" carries the accent (Calma).
- - It is `role="img"`, with a label that names the counts and the neighbours. Its nodes are pointer shortcuts to links that are also in the lists, so they take no tab stop (`tabindex="-1"`).
- - A key below it reads "Linked", "Not written" and "Mentioned", drawn in the edge styles.
-- **Scope:** every list, count, node and edge is read from the in-memory index under the viewer's scope (base §3.3 and §6.3). The panel is inside gate 1 (§7, L6).
-- **Phone:** a bottom sheet with a grabber and a peek line ("Linked from 3, mentioned in 1", or "This week, and links out" on a daily note).
- - Its counts are scoped like the lists.
- - Tapping the line or dragging it opens the sheet to 74% of the height. It is a modal `<dialog>` while open, and closes on Esc or a drag down.
- - It is hidden while the keyboard is up.
+ - **Accessibility:** the SVG is `role="img"`, with a label that names the counts and the neighbours.
+ - Its nodes are pointer shortcuts to links that are also in the lists, so they take no tab stop (`tabindex="-1"`).
+ - A key below the map reads "Linked", "Not written" and "Mentioned".
+- **Scope:** every list, count, node and edge is read through **one scoped accessor** (§8). Gate L6 covers it.
+- **Phone:** a bottom sheet with a grabber and a peek line.
+ - The peek line reads "Linked from 3, mentioned in 1", or "This week, and links out" on a daily note. Its counts are scoped like the lists.
+ - A tap or a drag opens it to 74% of the screen. While open it is a modal `<dialog>`.
+ - Esc or a drag down closes it. It hides while the keyboard is up.
### 4.4 Day navigation and the calendar
-- **The day pill:** ‹ Today › on daily notes. "Today" shows the date when you are on another day.
+- **The day pill:** ‹ Today › on daily notes. On any other day, "Today" shows that day's date.
- It sits in the lead slot from 800px, and in the kicker line on phones.
- ‹ and › are links to `/d/<date>`.
- - The pill stays in the header when the panel's week strip is open, because the strip leaves when Links is off (§10, D5).
-- **The calendar:**
- - The pill's middle opens a month calendar that starts on Monday. So does "November" in the week strip.
- - Dots, the ring and the fill mean what they mean in the week strip. Its foot holds "• A note you wrote" and Today.
+ - The pill stays when the panel's week strip is open, because the strip leaves when Links is off (§10, D5).
+- **The month calendar:** the pill's middle and the strip's "November" both open it. Weeks start on Monday.
+ - Dots, the ring and the fill mean what they mean in the week strip.
+ - Its foot holds "• A note you wrote" and Today.
- It is a server-rendered `<details>` popover: a grid of links, with ‹ › month links (`?month=2026-10`).
- - With script it has a roving tabindex, arrow keys and Esc. Without script it still works.
- - It is styled like rastrillo's `calendar.js` month grid, but it is navigation, not a date field, so it does not reuse that script.
+ - With script, it gains a roving tabindex, arrow keys and Esc. Without script it still works.
+ - It is styled like rastrillo's `calendar.js` month grid, but it is navigation, not a date field.
- Dots are the viewer's own daily notes only, from their own partition of the index.
### 4.5 History
-- **The panel:**
- - History in the header opens a side panel, 360px, full height under the header. It replaces the Links panel while open, and the Links toggle shows unpressed.
- - Without script, the same panel is the page `/p/{id}/history`, laid out beside the page. With script, it is fetched as a fragment (`?panel=1`) under Docs' rule: a request with `Sec-Fetch-Dest: document`, or with no `Sec-Fetch-*`, gets the full page.
-- **The list:**
- - Versions grouped by day. Each shows the author ("You" for the viewer), the time, and a one-line summary.
- - Summaries are worked out on the server by diffing each revision against the one before. The forms are "Edited <the nearest heading above the first changed block>", "Added <n> blocks", "Removed …", "Restored a version from …" and "Created".
- - The first 30 versions are summarised. "Show older" pages on from there.
- - The oldest version reads "Created this page" (§10, D8).
+- **The panel:** History in the header opens a 360px side panel, full height under the header.
+ - It replaces the Links panel while open.
+ - Without script, the same panel is the page `/p/{id}/history`, laid out beside the page.
+ - With script, it is fetched as a fragment (`?panel=1`) under Docs' rule: a request with `Sec-Fetch-Dest: document`, or with no `Sec-Fetch-*`, gets the full page.
+- **The list:** versions grouped by day. Each shows the author ("You" for the viewer), the time and a one-line summary.
+- **Summaries:** the verb comes from that revision's **event row**. Only an `edited` revision is diffed.
+
+ | Event verb | Summary |
+ |---|---|
+ | `created` | "Created this page" (§10, D8) |
+ | `renamed` | "Renamed from <the old title>" |
+ | `reverted` | "Restored the version from <date>" |
+ | `restored` | "Brought back after it was deleted" |
+ | `relinked` | "Updated links" |
+ | `marked` | "Made a block linkable" |
+ | `edited` | "Edited <the nearest heading above the first changed block>", or "Added <n> blocks", or "Removed …", from a diff against the revision before |
+
+ - The first 30 versions are summarised. "Show older" pages through the rest.
+ - If the 90-day window has dropped earlier revisions, the list ends with "Earlier history has aged out". Nothing is ever diffed against a revision past the window.
- **Choosing a version:**
- - The page shows that version, with a banner: "Bo's version, Friday 13 November at 16:15. Marked: what changed from the version before" and **Back to current**.
- - The diff is per block (the merge's alignment, `markup/merge.go`), then per word inside a changed block. Insertions are underlined and tinted. Deletions are struck through and tinted. Underline and strike carry the meaning, so colour never carries it alone. A chip is diffed as one word.
- - The panel's foot holds **Back to current** and **Restore this version**. Restore is the existing POST: a new revision, held for 650ms (the busy rule).
-- **The editor during history:** it is read-only while an old version is on screen. Back to current returns the editor and the caret.
+ - The page shows that version, under a banner: "Bo's version, Friday 13 November at 16:15. Marked: what changed from the version before". The banner has **Back to current**.
+ - **The diff:** block by block (the merge's alignment), then word by word inside a changed block.
+ - Insertions are `<ins>`, underlined and tinted. Deletions are `<del>`, struck through and tinted.
+ - A chip is diffed as one word.
+ - The panel's foot holds **Back to current** and **Restore this version**.
+ - Restore is the existing POST: a new revision, held for 650ms.
+ - The editor is read-only while an old version is on screen.
### 4.6 ⌘K
-- **The box:** ⌘K (Ctrl+K) opens a modal `<dialog>`. Today's `mapa.js` palette is restyled into one box with groups:
- - **Pages:** titles and aliases, with alias hits labelled "Old title of …".
+- **The box:** ⌘K (Ctrl+K) opens a modal `<dialog>`. Results are in groups:
+ - **Pages:** titles and aliases. Alias hits read "Old title of …".
- **In the text:** the block, with the match marked.
- **Your notes:** daily and scratch, labelled "Only you see these".
-- **The last row:** "Create '<query>'", shown only when nothing in scope matches the title exactly. This is base §6.3, unchanged.
-- **Keyboard:** ↑ ↓ to move, ↵ to open, ⌘↵ to create. The hints are in the foot, which phones hide.
-- **Typed dates:** "today", "yesterday", "tomorrow", a weekday ("friday" is the most recent Friday, today included; "next friday" is the coming one), "12 nov" and ISO dates. They resolve in the viewer's zone, on the server, and add one row: "Friday 13 November, your note".
-- **Without script:** `GET /search?q=` as a page in the new shell, as now.
-- **Endpoint:** the existing `/search/suggest`, which already answers within base §6.1's budget, gains the groups and the date row.
+- **The last row** is "Create '<query>'". It appears only when nothing in scope has exactly that title (base §6.3).
+- **Keyboard:** ↑ ↓, ↵ to open, ⌘↵ to create. The hint foot is hidden on phones.
+- **Typed dates:** "today", "yesterday" and "tomorrow"; a weekday ("friday" is the most recent Friday, today included; "next friday" is the coming one); "12 nov"; and ISO dates.
+ - They resolve in the viewer's zone, on the server.
+ - They add one row: "Friday 13 November, your note".
+- **Without script:** `GET /search?q=`, a page in the new shell.
+- **Endpoint:** the existing `/search/suggest`, which gains the groups and the date row.
### 4.7 The other screens
-- **Inside the new shell, restyled:** All pages, Scratch, Search, Settings, Deleted pages, and every confirm page (delete, free alias, restore deleted, conflict, the textarea editor).
-- **New team page:**
- - A popover from the sidebar foot or the Page menu holds one title field. It posts the existing `POST /pages` (650ms), then opens the new page with the caret in its body.
- - Because the page now exists before its first keystroke, its text autosaves from the start. That retires build note 25 for team pages.
- - Without script it is `/new`.
-- **New scratch page:**
- - It opens the empty editor.
- - Its first autosave is the commit that creates it (base build note 13: it is "created by its first save"). Every later autosave is a draft.
- - So a scratch page that is never typed into leaves no row.
+- **Restyled into the new shell:** All pages, Scratch, Search, Settings, Deleted pages, and every confirm page (delete, free alias, restore deleted, conflict, the textarea editor).
+- **New team page:** a popover with one title field, from the sidebar foot or the Page menu.
+ - It posts the existing `POST /pages`, held for 650ms.
+ - It then opens the new page with the caret in its body.
+ - The page exists before its first keystroke, so its text autosaves from the start (§10, D4).
+ - Without script, it is `/new`.
+- **New scratch page:** opens the empty editor. The page is created by a commit, under §6.5's rules (§10, D12).
## 5. Phase 1 on the existing editor
-Phase 1 ships everything in §3 and §4 around today's textarea:
-
-- **The page:** the rendered body, with chips. The editing screen `/p/{id}/edit` and the daily note's edit state move into the full-window layout: a borderless textarea at the page's measure, in the body's face and size, with no "Text" label, and Insert putting Markdown in at the caret. Autosave, the commit after two minutes idle, ⌘S and Save are as now. Save shows in the lead slot without script, and the status is estilo's `savestatus`.
-- **The server's HTML is final in Phase 1.** It is the markup the Phase 2 editor draws (§6.9).
- - Chips, as in §4.2.
- - Date links in their long form.
- - List items as `<li><p>`.
- - The body under `white-space: pre-wrap`, so a reader sees exactly the spaces the editor will. Today's renderer collapses them (§10, D9).
- - So Phase 2 changes no reader's view and moves nothing on mount.
+**The chrome:** everything in §3 and §4, around today's textarea.
+- `/p/{id}/edit` and the daily note's edit state move into the full-window layout.
+- The textarea is borderless, at the page's measure, in the body's face and size, with no "Text" label.
+- Insert puts Markdown in at the caret.
+- Autosave, the commit after two minutes idle, ⌘S and Save work as now.
+- Save shows in the lead slot without script. The status is estilo's `savestatus`.
+
+**The renderer becomes the editor's DOM.** These changes are behind gate L4 (§7):
+- **The spike comes first** (Phase 1, step 0). `editor/schema.mjs`, its `toDOM` and the parts of `markup.mjs` that `toDOM` needs are written before the renderer changes.
+ - L4's HTML half runs over the corpus.
+ - The HTML is called final only once L4 passes.
+- **Chips,** as in §4.2. **Date links** in their long form.
+- **Lists:**
+ - **Markup:** items render as `<li><p>`.
+ - **Mixed kinds:** `renderList` opens a new list when the item kind (bullet or ordered) changes at the same depth. Today the first item's tag wins.
+ - **Level skips** clamp as today.
+- **Whitespace:**
+ - `white-space: pre-wrap` is set on textblocks only: `p`, `h2`–`h6`, `li > p`, `blockquote p` and `pre`.
+ - No whitespace text is emitted between blocks.
+ - A continuation line's leading spaces or tabs (`- item\n more`) are not shown, just as normal white-space hides them today. The renderer emits `<br>` and then the line without its indent. The indent is kept in the source (§6.3).
+- **Emphasis:**
+ - `***x***` renders today as mis-nested `<strong><em>x</strong></em>`. The renderer is fixed to emit well-formed HTML.
+ - Cases already well-formed keep their exact HTML. That is a golden test over the corpus.
+ - Emphasis never crosses a link, an atom or code, as now (§6.3).
+
+So Phase 2 changes no reader's view, and moves nothing when the editor mounts.
## 6. The editor (Phase 2)
### 6.1 The rule
-**Markdown is the stored format, and the editor owns no other format.** Drafts, revisions, the block merge, S3 and export see Markdown, exactly as now. The editor reads Markdown when it mounts and writes Markdown when it saves.
-
-**The grammar is Mapa's own subset, not CommonMark** (base build note 10, `markup/blocks.go` and `spans.go`). There is no Markdown library:
+**Markdown is the stored format.** Drafts, revisions, the block merge, S3 and export see Markdown, exactly as now. The editor reads Markdown when it mounts and writes Markdown when it saves.
-- Mapa's blocks are not CommonMark's. A list item is its own block. A paragraph's line breaks are hard breaks. There is no indented code, no `_` emphasis and no escapes.
-- A CommonMark parser would disagree with the Go side on real pages.
+**The grammar is Mapa's own subset**, not CommonMark (base build note 10; `markup/blocks.go` and `spans.go`).
+- A list item is its own block, and a paragraph's line breaks are hard breaks.
+- There is no indented code, no `_` emphasis and no escapes.
-The editor carries a JavaScript port of those two Go files. A corpus gate holds the port to Go (§6.4).
+The editor carries a JavaScript port of those two Go files, `markup.mjs`. A corpus gate holds it to Go (L4). The editor uses no Markdown library.
### 6.2 Build and bundle
-The bundle is built the way Docs builds its bundles, which Slides copied:
-
-- **Layout:** `editor/` at the repo root holds `package.json`, `package-lock.json`, `bundles.mjs` and `build-bundles.mjs`, plus the sources:
- - `markup.mjs`, the port;
- - `schema.mjs`;
- - `serialize.mjs`;
- - `editor-entry.js`;
- - the plugins.
-- **Output:** esbuild writes a minified bundle with its content hash in the name, `internal/mapa/static/editor.<hash>.js`, which is committed and embedded. The app runs no build step.
-- **Dependencies:** `prosemirror-model`, `-state`, `-view`, `-transform`, `-commands`, `-keymap`, `-history`, `-inputrules` and `-schema-list`, at the versions Docs pins. There is no `prosemirror-markdown`, no markdown-it and no Yjs.
-- **Size:** measured and recorded in the build note, not promised. Expect 60 to 80KB gzipped.
-- **Loading:** the bundle loads `defer`, only on a page the viewer may edit, so old versions, deleted pages and confirm pages do not load it. `mapa.js` stays a small classic script for the chrome: ⌘K, the sidebar fold, the panels, the calendar, and the time zone offer.
-- **CI:** CI runs `npm ci`, rebuilds, and fails on any byte of drift (Docs' `10-gate`), then runs `node --test`. **Mapa's CI gains Node**, which it does not need today. `.amadan/ci` and the Makefile (`make editor`, and `make ci` calling it) change with it.
-- **Colophon:** it gains the ProseMirror packages (MIT), through estilo's catalog, as Docs did.
+The bundle is built the way Docs builds its bundles (Slides copied it).
+
+- **Where it lives:** `editor/` at the repo root holds:
+ - `package.json`, `package-lock.json`, `bundles.mjs` and `build-bundles.mjs`;
+ - the sources: `markup.mjs`, `schema.mjs`, `serialize.mjs`, `fidelity.mjs`, `editor-entry.js` and the plugins.
+- **The output:** esbuild writes `internal/mapa/static/editor.<hash>.js`, minified and content-hashed. It is committed and embedded. The app runs no build step.
+- **Dependencies:**
+ - `prosemirror-model`, `-state`, `-view`, `-transform`, `-commands`, `-keymap`, `-inputrules` and `-schema-list`, at the versions Docs pins.
+ - `prosemirror-history`, `-gapcursor` and `-dropcursor`, pinned exactly in the lockfile. Docs does not use these; it undoes through Yjs.
+ - No `prosemirror-markdown`, no markdown-it and no Yjs.
+- **Gap cursor and trailing paragraph:** the gap cursor lets the caret sit before or after a code block or rule.
+ - The document always ends in a paragraph, so there is somewhere to type.
+ - An empty trailing paragraph serialises as nothing (§6.4).
+- **Size:** measured and recorded, not promised. Expect 60–80KB gzipped.
+- **Loading:** the bundle loads `defer`, only on pages the viewer may edit.
+ - `mapa.js` stays a small classic script for the chrome: ⌘K, the fold, the panels, the calendar and the time zone offer.
+- **CI:** CI runs `npm ci`, rebuilds, and fails on any byte of drift (Docs' `10-gate`). Then it runs `node --test`.
+ - **Mapa's CI gains Node.**
+ - `.amadan/ci` and the Makefile change with it: `make editor` is added, and `make ci` calls it.
+- **Colophon:** the ProseMirror packages (MIT) are added through estilo's catalog.
### 6.3 The schema
-The schema is deliberately the subset Mapa renders, and nothing else.
+**Blocks.** The editor holds only the subset Mapa renders. Each Mapa block is exactly one textblock, or one rule.
-| Mapa block (`markup.Block`) | Node | Attributes kept for fidelity |
+| Mapa block | Node | Kept for fidelity |
|---|---|---|
-| paragraph | `paragraph` (inline content, `hard_break` for `\n`) | none |
-| heading (`#` to `######`) | `heading`, drawn as `h2` to `h6`; the page title is the H1 | `level` |
-| list item | `list_item > paragraph` inside `bullet_list` or `ordered_list` | `indent` (exact), `bullet` (`-` `*` `+`), `number` and `delim` (`.` `)`), `task` and `checked` (`[ ]`, `[x]`, `[X]`) |
-| quote | `blockquote > paragraph` | `prefix` per line (`>` or `> `) |
-| code fence | `code_block` | `fence` (` ``` ` or `~~~`, and its length), `info`, `closed` |
+| paragraph | `paragraph`. Inline content, with `hard_break` for each `\n` | the `hard_break`'s `indent`: the next line's leading whitespace, which is not shown |
+| heading `#`…`######` | `heading`, drawn as `h2`–`h6`. The page title is the H1 | `level`, `source` |
+| list item | `list_item > paragraph`, with an optional nested list (below) | on `list_item`: `indent` (exact), `bullet` (`-` `*` `+`), `number`, `delim` (`.` or `)`), `task`, `checked` (`[ ]`, `[x]`, `[X]`) |
+| quote | `blockquote > paragraph`. One Mapa quote block is one `blockquote` | `prefix` for each line (`>` or `> `) |
+| code fence | `code_block` | `fence` (the characters and their length), `info`, `closed` |
| rule | `horizontal_rule` | `source` (`---`, `* * *`…) |
-- **Marks:** `strong` and `em` (always `**` and `*`, the only ones the subset has), `code` and `link` (`[text](url)`, or `bare` for an autolink).
- - `code` excludes every other mark.
- - `link` excludes `strong` and `em`, because the Go renderer escapes a web link's text and draws no emphasis inside it.
-- **Mapa's inline atoms:**
- - `wikilink {target, anchor, shown, source}` serialises to `[[target#^anchor|shown]]`. An untouched link re-emits its `source`.
- - `datelink {date, source}` serialises to `[[2026-11-12]]`.
- - `embed {ref, source}` serialises to `![[app:item]]`.
-- **The block anchor:** `^id` is a `marker` attribute on every block that may carry one (not code, not rule). It serialises as ` ^id` at the end of the block's last line.
- - It is drawn as a ¶ handle on hover, with "Copy link to this block".
- - It is minted only by "Link to this block" on a team page, as an attributed edit to that page (base §3.2).
- - Markers are stripped from pasted blocks, so a paste cannot duplicate an id.
-- **Not representable** (a list item holding two paragraphs, a quote holding a list):
- - The schema forbids it.
- - Paste maps it onto the nearest thing the subset can say.
- - Text outside the subset (tables, raw HTML, footnotes) is already a paragraph to Mapa's parser, and stays one. Its pipes and angle brackets are text, drawn under `pre-wrap` (§10, D10).
-
-### 6.4 Markdown fidelity: re-emit by block
-
-**The danger.** A serialiser that normalises (list markers, numbering, indentation, blank lines, fence style, trailing spaces) rewrites blocks nobody touched on every save. That produces:
-
-- noise in history;
-- false conflicts in the block merge;
-- churn in S3;
-- a breach of doctrine §6.6 in spirit: one byte sequence per revision, and no needless revisions.
-
-**The mechanism. Untouched blocks are re-emitted from their source, byte for byte.**
-
-1. **On mount**, the editor parses the body with `markup.mjs`. That gives the same blocks, with `Start` and `End` in bytes, that Go's `markup.Parse` gives. It builds the document, with one textblock (or rule) per Mapa block. Then it records, in a `WeakMap` keyed by the **node object**, each block's index, its exact source, and its context (kind, level, list attributes).
-2. **ProseMirror shares structure.** A transaction that does not touch a node keeps the same node object. So "untouched" means: the node is the same object as at mount, **and** its context is unchanged (a re-indent changes the context without changing the node).
- - Chip state (team, alias, pending) lives in a plugin and a NodeView, never in node attributes. So a link's state changing, after a rename say, never makes a block look edited.
-3. **On serialise**, the editor walks the blocks in order:
- - An untouched block emits its recorded source.
- - Between two untouched blocks that were neighbours at mount, it emits the **original bytes between them**.
- - Anywhere else, it emits `markup.Join`'s rule: one blank line, or one newline between two list items.
- - The original leading and trailing bytes are kept while the first and last blocks are the original ones.
- - The result goes through `cleanBody`'s rule (`\n` line endings, trailing space trimmed), as every stored body does.
-4. **An edited block** is serialised from its node. Its block syntax comes from its kept attributes: the same bullet, number, indent, fence and quote prefix. Only the inline text is rewritten. Its untouched atoms re-emit their `source`.
-5. **Reparse on edit.**
- - After each transaction that edits a block, the editor serialises that block and parses it again with `markup.mjs`.
- - If the parse is not exactly that block, the block is replaced by what the parse says. That happens when the text now starts with `- ` after a hard break, or holds `*word*` typed literally.
- - So what the editor shows is always what the stored Markdown means. The textarea, the reader and the editor never disagree.
- - Mapa has no escapes, so `*word*` typed in the editor becomes emphasis, exactly as it does in the textarea (§10, D11).
-6. **Nothing commits nothing.**
- - The editor autosaves only when the serialised body differs from the last one it saved, and commits only when it differs from the base revision's body.
- - On the server, a commit whose body equals the current body, over the current revision, writes no revision. It just drops the draft. Today `tx.commit` would mint an identical revision.
- - Empty paragraphs (Enter twice) have no Markdown form and serialise as nothing. The editor keeps them on screen while you are there.
-
-**Parity hazards the port must not trip over,** each with a corpus case:
-
-- Go's RE2 `\s` and `\S` are ASCII, while JavaScript's are Unicode (NBSP, U+2028, U+3000). The port spells out ASCII classes.
-- Go's `strings.TrimSpace` and JavaScript's `trim()` trim different sets (U+0085, U+FEFF).
-- Go offsets are bytes and JavaScript's are UTF-16. `Start` and `End` are compared in UTF-8 bytes.
+**Lists:**
+- A run of consecutive items of the same kind (bullet or ordered) at the same depth is one `bullet_list` or `ordered_list`. A change of kind starts a new list, matching Phase 1's `renderList`.
+- `list_item`'s content is `paragraph (bullet_list | ordered_list)?`. An item never holds a second paragraph or a code block, because Mapa's item is one block.
+- **Depth:** the depth Go computes, `min(level, open lists)`, gives the nesting.
+ - The item's exact `indent` is an attribute. A level skip keeps its source even though it nests one deep.
+- **Moving an item:** sinking or lifting an item (Tab and ⇧Tab) rewrites its `indent` as two spaces per depth.
+ - That makes the item edited.
+- **Fidelity is keyed on the item's paragraph** (§6.4).
+ - Its context is the `list_item` attributes, the depth and the list kind.
+ - A nested list changing never touches its parent item's paragraph.
+
+**Marks:**
+- `strong` and `em` are always written `**` and `*`, the only forms the subset has.
+ - They **exclude each other**. Applying one to a range that has the other replaces it.
+ - The Go renderer cannot nest them safely: it drops `**a *b* c**` and mis-nests `***x***`.
+- `code` excludes every mark.
+- `link` (`[text](url)`, or `bare` for an autolink) excludes `strong` and `em`.
+- Atoms take no marks.
+- So a mark never spans a link, an atom or code, which is what Go's `words()` can draw.
+ - Mark commands split their range at those boundaries.
+- A block that is already stored with nested emphasis is shown as the fixed renderer draws it (§5). It keeps its source while untouched.
+ - When edited, it serialises under the exclusion rule.
+ - The reparse rule (§6.4, step 6) shows the result before anything is saved. L4 holds the mark corpus.
+
+**Mapa's inline atoms:**
+- `wikilink {target, anchor, shown, source, origin}` → `[[target#^anchor|shown]]`.
+- `datelink {date, source, origin}` → `[[2026-11-12]]`.
+- `embed {ref, source, origin}` → `![[app:item]]`.
+- Untouched atoms re-emit their `source`.
+
+**Block anchors:**
+- `^id` is a `marker` attribute on every block that may carry one (not code, not rule). It serialises as ` ^id` at the end of the block's last line.
+- It shows as a ¶ handle on hover: "Copy link to this block".
+- It is minted only by "Link to this block" on a team page, as an attributed edit to that page. That edit logs `marked` (base §3.2, §8).
+
+**Outside the subset:**
+- The schema has no node for anything the subset can't say.
+- Paste maps it onto the nearest thing the subset can say.
+- Text outside the subset (tables, raw HTML, footnotes) is already a paragraph to Mapa's parser, and stays one (§10, D10).
+
+### 6.4 Markdown fidelity
+
+**The danger.** A serialiser that normalises things would rewrite blocks nobody touched on every save. Things it might normalise: list markers, numbering, indents, blank lines, fences, trailing spaces. That rewriting causes noise in history, false merge conflicts and churn in S3.
+
+**Untouched blocks are re-emitted from their source, byte for byte:**
+
+1. **Origins.** On mount, `markup.mjs` parses the body into the same blocks, with `Start` and `End` in UTF-8 bytes, that Go's `Parse` gives.
+ - Each textblock, and each rule, gets an `origin` attribute: its block index. The attribute is never serialised.
+ - A side table keeps, for each origin, the original **node**, its exact **source** and its **context** (kind, level, list attributes, depth, list kind).
+ - Attributes survive text edits.
+ - When a split or a copy creates a second node with the same origin, **the first holder in document order keeps the origin**. Every later holder is new.
+2. **"Untouched"** means the node is the origin's first holder, `node === original || node.eq(original)`, and the context is unchanged.
+ - `eq`, not identity, so undo, Enter then Backspace, and a no-op `setNodeMarkup` all count as untouched again.
+ - Chip state (team, alias, pending) lives in a plugin and a NodeView, never in attributes.
+3. **Seams.** Between blocks with origins k and k+1 that are still adjacent, the **original bytes between them** are kept, **whether or not either block was edited**.
+ - Anywhere else, `markup.Join`'s rule applies: one blank line, or one newline between two list items.
+ - The original leading and trailing bytes are kept while origins 0 and n−1 are first and last.
+ - The result goes through `cleanBody`'s rule.
+4. **Edited blocks** are serialised from their node:
+ - the block syntax comes from the kept attributes (the same bullet, number, indent, fence and quote prefix);
+ - the inline text is rewritten;
+ - untouched atoms re-emit their `source`.
+ - **Empty blocks** have no Markdown form, so they serialise as **nothing**. That covers an empty paragraph, list item or heading, and a heading of only `#`s.
+ - Otherwise `cleanBody`'s trim turns a trailing `- ` into `-`, which `itemLine` reads as part of the paragraph above it.
+ - The editor keeps empty blocks on screen while you are there. The corpus has these cases.
+5. **The structure check, before every autosave.** `parse(serialise(doc))` must give the document's blocks in the same kind, level and order, and the same number of them.
+ - If it does not, the editor re-serialises the offending blocks from their nodes. For example, an unclosed fence, reused from source, that is no longer last gets its closing fence, and becomes edited.
+ - If the check still fails, the editor adopts the parse as its document (step 6).
+ - **Nothing is autosaved that would reload as a different document.** L3 asserts this on documents, not bytes.
+6. **Reparse on edit.** After each transaction that edits a block, the editor serialises that block and parses it again.
+ - If the result is not exactly that block, the block becomes what the parse says. For example, text that now starts with `- ` after a hard break, or `*word*` typed literally.
+ - So what the editor shows is always what the stored Markdown means.
+ - **While an IME is composing**, the reparse waits until `compositionend`.
+ - The reparse is idempotent: applying it twice is applying it once (L3).
+ - Mapa has no escapes, so a literal `*word*` becomes emphasis, exactly as in the textarea (§10, D11).
+7. **A save that changes nothing writes nothing:**
+ - **The editor** autosaves only when the serialised body differs from what it last saved.
+ - **The store** writes no revision for a commit whose final body equals the current body. That covers a `Merged` result as well as a plain save, and the draft is dropped. Today `tx.commit` mints a revision with the same body.
+
+**Parity hazards.** The port must not trip on these, and each has corpus cases:
+- Go's RE2 `\s` and `\S` are ASCII; JavaScript's are Unicode. The port spells out ASCII classes.
+- `strings.TrimSpace` and `trim()` trim different sets (U+0085, U+FEFF).
+- Offsets are compared in UTF-8 bytes.
- `strings.ReplaceAll(indent, "\t", " ")` decides list levels.
-- The emphasis regexes run over HTML-escaped text in Go.
+- Go runs its emphasis regexes over HTML-escaped text.
+
+**Merges keep bytes too.** `markup.Settle` re-joins every block with `Join` today (base build note 23), so any merged commit rewrites the whole body's spacing.
+
+Phase 2 makes `Settle` **byte-preserving**:
+- It anchors on the current revision's text ("theirs").
+- Theirs' blocks, and the bytes between theirs' adjacent blocks, are emitted as they are.
+- Blocks taken from mine bring their own source.
+- Only the seams where the two sides meet follow `Join`.
+
+The same rule applies when Resolve settles chosen hunks. This revises build note 23's "a merged save can tidy blank lines" (§10, D13).
### 6.5 Saving: autosave, commit and rebase
-The base spec's §5 and gate 11 are unchanged, and the textarea's reviewed rules (`mapa.js`) carry over.
-
-- **Draft:** autosave 1.2s after typing stops, through `POST …/draft`, with the version check against other tabs. It never touches the page or its revision.
-- **Commit:**
- - On ⌘S, after two minutes idle, and when the person leaves the page inside Mapa (a link or the sidebar). The editor commits before it navigates.
- - Closing the tab is new: on `pagehide`, the editor sends one `keepalive` POST that writes the draft **and** commits it (`POST …/draft` with `commit=1`, one request so the order cannot be lost). If that commit cannot happen (a same-block conflict, or a beacon that never arrived), the draft stays, and the next visit offers it as Save or Discard, as now (§10, D3).
- - Browsers cap a `keepalive` body at 64KB. When the text not yet autosaved would pass that, the POST carries only `commit=1` and the draft version, and commits the last autosave. Anything typed in the final 1.2s is then lost on a very long page. That is measured, and noted as a limit.
-- **Status:** `savestatus` shows Saving…, Saved, Retrying and Failed. "Saved" means the text is stored. Teammates see it from the next commit, and see "Ana is editing" until then (base §5).
-- **Learning of a teammate's revision:**
- - Autosave's reply gains `revision`, the page's current revision.
- - When it differs from the editor's base, the editor asks `GET /p/{id}/rebase?base=R&version=V`.
- - That runs `Merge3(base body, the person's stored draft, current body)` and answers JSON: the merged body, or the hunks. It writes nothing, so it is inside gate 10.
-- **Clean merge:**
- - The editor applies the merged body as one transaction that replaces only the blocks the teammate changed, aligned by `markup.mjs`.
- - The caret, the selection and undo survive.
- - The base moves to the current revision, and the next autosave writes the draft with that base.
- - The fidelity map is rebuilt against the new base body.
-- **Same block:**
- - The editor shows that block's conflict inline: Yours, Theirs, or Both, yours first (base build note 24).
- - Until the person chooses, the base stays where it was, so no commit can overwrite the teammate.
- - Nothing is committed that nobody chose.
-- **A commit that merged** (outcome `Merged`, body returned, as today) follows the textarea's rule:
- - With nothing typed since the commit was sent, the editor takes the merged body by the same block transaction.
- - With typing since, it keeps its base, so the next commit merges again.
-- **Two tabs:** a stale tab is refused and loads the newer draft, as now (base build note 31).
+The base spec's §5, gate 11 and build note 31 (`Kept`) hold.
+
+**Autosave:**
+- It fires 1.2s after typing stops, and only once the §6.4 structure check passes.
+- It goes through `POST …/draft` with `base`, `version` and `body`, and the two-tab version check.
+- It never touches the page or its revision.
+
+**A tab's own draft.** The editor tracks whether **this tab has typed into the page in this session**.
+- Only then does it commit by itself.
+- A draft that was only offered, from an earlier session or another tab, commits only on **Save** (§6.8).
+
+**Commit,** for a draft this tab typed into, happens:
+- on ⌘S;
+- after two minutes idle;
+- when the person leaves the page inside Mapa (a link or the sidebar): the editor commits, then navigates;
+- when the tab closes, on `pagehide` (§10, D3).
+ - One `keepalive` POST to `…/draft` carries `commit=1`, the draft `version` the tab holds, and the pending text if any.
+ - The store requires `version` to be the **current** draft version. If it is not, it writes nothing and commits nothing.
+ - The text is written as the draft and committed in one request.
+ - If the commit cannot happen (a same-block conflict, or the request never arrived), the draft stays. The next visit offers it as Save or Discard, as now.
+ - Browsers cap a `keepalive` body at 64KB. Over that, the POST carries no text and commits the last autosave.
+ - Up to 1.2s of typing on a very long page is then not committed by the close. It is still in the tab if the tab is restored.
+ - This is a measured, written-down limit.
+
+**Status:** `savestatus` shows Saving…, Saved, Retrying and Failed.
+- "Saved" means the text is stored.
+- Teammates see it from the next commit. Until then they see "Ana is editing" (base §5).
+
+**Learning of a teammate's revision.**
+
+There is no separate rebase GET. The autosave reply carries:
+- `version`;
+- `revision`: the page's current revision;
+- when the draft's base is not current, `merge`, computed over exactly the text this request carried:
+ - `{against: R2, body: M}` when the merge is clean;
+ - `{against: R2, conflict: true}` when it is not;
+ - `{noBase: true}` when the base has aged out of the window;
+ - `{gone: true}` when the page has been deleted.
+
+The cases:
+- **Clean.** The editor applies `M` only if its serialised body **still equals the text that autosave sent**.
+ - It applies `M` as one transaction that replaces only the blocks that differ. The caret, the selection and undo survive.
+ - It then **moves the base** with a version-checked `POST …/draft` carrying `rebase=R2`, `body=M` and `version`.
+ - The store sets the existing draft's `BaseRevision` to R2 only if `version` is current and R2 is a revision inside the window. Otherwise it refuses and moves nothing.
+ - The fidelity table is rebuilt against R2's body.
+ - **The base never moves unless the document, after applying, serialises to exactly `M`.**
+ - If anything was typed since the send, or a block could not be applied, nothing moves. The editor autosaves again and asks again.
+- **Conflict.** The editor shows the hunks inline: Yours, Theirs, or Both, yours first (base build note 24).
+ - The choice is posted to the **existing `POST /p/{id}/resolve`**, with `current=R2`, `version`, and one `choice-N` for each hunk.
+ - That path commits the chosen text over the revision shown (`Store.Resolve`), so it is a commit made by the person's own choice.
+ - The editor first makes sure the stored draft is its on-screen text (an autosave whose version is then held), so the hunks Resolve settles are the hunks shown.
+ - Until the person chooses, the base stays at R1 and the editor makes no commit of its own. Nothing nobody chose is committed.
+- **`noBase`.** The editor offers the existing side-by-side choice: keep mine whole, or keep theirs.
+- **`gone`.** The editor offers the existing "Save as a scratch page" or Discard.
+- **Stale version.** The tab gets the existing 409 and loads the newer draft (build note 31).
+- **Daily notes:**
+ - **Unwritten day:** `/d/{date}/draft` has no revision and no merge.
+ - **Written day:** it behaves as its page does.
+ - **A note created by another tab** in the meantime: the existing `NoBase` path applies.
+
+**A commit that merged** (`Merged`, body returned) follows the same rule. With nothing typed since the send, the editor takes the merged body by the block transaction and moves its base to the new revision. With typing since, it keeps its base, so the next commit merges again (today's `mapa.js` rule).
+
+**Returning from the back/forward cache** (`pageshow` with `persisted`):
+- **No unsaved text:** the editor reloads the page.
+- **Unsaved text:** it autosaves at once, which brings `revision` and `merge` back.
### 6.6 Typing: `[[`, `/`, input rules and the bubble
-- **`[[`** opens a combobox under the caret. It shows team titles, aliases ("Old title of Halden Robotics"), the viewer's own pending link texts (base §6.3 and build note 20), and the last row, "Link 'Hal', a page not written yet".
- - It uses `/links/suggest`, unchanged, so its scope is unchanged.
- - ↵ inserts a `wikilink`, and `|` lets you type shown text.
- - A typed `[[2026-11-12]]` or a picked date makes a `datelink`.
- - Backspace into a chip turns it back into its `[[text` source, for editing.
- - A plain click on a chip follows the link, as chips are links.
-- **`/`** at the start of an empty block, or after a space, opens the block menu. It offers:
+- **`[[`** opens a combobox under the caret.
+ - It offers team titles, aliases ("Old title of Halden Robotics"), the viewer's own pending link texts (base §6.3, build note 20), and a last row, "Link 'Hal', a page not written yet".
+ - It uses `/links/suggest`, unchanged.
+ - ↵ inserts a `wikilink`. Typing `|` lets you set shown text.
+ - A typed or picked date makes a `datelink`.
+ - Backspace into a chip turns it back into its `[[text` source.
+ - A plain click on a chip follows the link.
+ - The state of a newly typed chip comes from `/links/resolve` (§6.8).
+- **`/`** at the start of an empty block, or after a space, offers:
- Heading 1, 2 and 3 (`#`, `##`, `###`);
- - List (`-`), Numbered (`1.`), Checklist (`- [ ]`);
- - Quote (`>`), Code (```` ``` ````), Divider (`---`);
+ - List (`-`), Numbered (`1.`) and Checklist (`- [ ]`);
+ - Quote (`>`), Code (```` ``` ````) and Divider (`---`);
- Link to a page (`[[`);
- - Date: a picker. Choosing a day inserts a `datelink`, which opens the viewer's own note for that day.
+ - Date, a picker that inserts a `datelink`.
- Card from Fichas is hidden until slice 2.
-- **Input rules:** the Markdown shortcuts above, typed at the start of a block, become those blocks. `**x**`, `*x*` and `` `x` `` become marks. A pasted or typed URL over a selection makes a link (today's paste rule).
+- **Input rules:** the same Markdown shortcuts work typed at the start of a block. `**x**`, `*x*` and `` `x` `` become marks, under §6.3's exclusions. A URL pasted over a selection makes a link.
- **The selection bubble:** B, I, code and link, then **Make team page** (private notes only).
- - On fine pointers it sits above the selection.
- - On coarse pointers it sits below, clear of iOS's own callout (§6.11).
-- **Keys:** ⌘B, ⌘I, ⌘E (code), ⌘K is search (not link), ⌘⇧K is link, ⌘S, ⌘Z and ⌘⇧Z, and Tab and ⇧Tab to indent list items.
-- **Paste:**
- - `text/plain` is parsed as Mapa Markdown.
- - `text/html` is mapped onto the schema (headings, lists, emphasis, links, code), and anything else becomes text.
- - Markers are stripped.
- - Links pasted from Mapa's own pages arrive as `wikilink`s.
+ - It sits above the selection, or below it on coarse pointers (§6.11).
+- **Keys:**
+ - ⌘B, ⌘I, ⌘E (code), ⌘⇧K (link), ⌘S, ⌘Z, ⌘⇧Z. ⌘K stays search.
+ - **Tab and ⇧Tab** indent and outdent list items, and only list items. Anywhere else Tab leaves the editor.
+ - **Esc, then Tab** always leaves, even inside a list. This is the keyboard way out, listed in Help.
+- **Copy, cut and paste:**
+ - **Within Mapa:** copy and cut put **Mapa Markdown** on the clipboard (`text/plain`) beside the HTML, plus a private `application/x-mapa` slice carrying each block's source.
+ - Paste prefers that slice. Copied blocks keep their source bytes, so cut and paste within a page re-emits the same bytes.
+ - **From outside:** `text/plain` is parsed as Mapa Markdown. `text/html` is mapped onto the schema, and anything else becomes text.
+ - **Markers:** a pasted block's `^id` is stripped **only when that id is already in the document**. A cut and paste keeps its marker, so links to the block still work.
### 6.7 Make team page from a selection
-1. **A selection is characters, and Make team page works on blocks.**
- - The command widens the selection to every block it touches, and tints those whole blocks before anything is confirmed. That is the mock-up's highlight.
- - A selection inside one paragraph therefore moves the whole paragraph, and the tint shows it.
+1. **Widen to blocks.** The command widens the selection to every block it touches, and tints those whole blocks before anything is confirmed.
2. **The confirm popover:**
- - A title, prefilled from the first heading in the blocks, or the first words.
- - The sentence: "These blocks move to a new team page everyone can open. Your note keeps a link in their place. Nothing else in your note is shared."
+ - a title, prefilled from the first heading or the first words;
+ - "These blocks move to a new team page everyone can open. Your note keeps a link in their place. Nothing else in your note is shared.";
- Make team page, held for 650ms.
-3. **On confirm**, the editor commits the draft first (an ordinary commit by the person). Then it posts the existing `MakeTeamPage` with the block indices **and the revision they index**.
- - `MakeTeamPage` gains that `revision` and refuses a stale one. Today it takes indices into whatever the body is now.
- - A daily note that has never been committed is created by that first commit, as any first save creates it.
-4. **Refusals** are as today and gate 2's:
- - a taken title asks for another;
- - so does a date-shaped one.
- - Embeds the blocks carry get base §7.4's check once slice 2 exists.
-5. **Afterwards**, the note shows the link chip where the blocks were. Then "Moved to [[Pilot logins]]." stays as a notice until the page is next opened.
-
-### 6.8 The draft offer, and drafts in the editor
-
-- When the viewer has a draft on the page, the editor mounts over **the draft's text**, with its base revision. A bar above the page reads "Unsaved changes from 2 hours ago" with Save and Discard (the existing POSTs).
-- Typing continues the draft.
-- Without script, the page shows the committed text and today's offer.
+3. **On confirm:**
+ - The editor commits the draft as an ordinary commit by the person. A daily note's first commit creates it.
+ - It then takes the block indices from **the body it just committed**, parsed by `markup.mjs`. They are not taken from the editor's own tree.
+ - It posts `MakeTeamPage` with those indices and the revision they index. `MakeTeamPage` gains that `revision` and refuses a stale one.
+4. **Refusals** follow gate 2. A taken title or a date-shaped one asks for another. Base §7.4's embed check applies once slice 2 exists.
+5. **Afterwards,** the link chip is where the blocks were. "Moved to [[Pilot logins]]." shows until the page is next opened.
+
+### 6.8 What the editor is given
+
+**Data the page carries.** Every editable page carries `<script type="application/json" id="mapa-editor">`.
+- Pages that carry it are served `Cache-Control: no-store`.
+- It holds:
+ - the **source** it mounts over, and the **base revision**;
+ - the person's **draft**, if they have one: its version and base revision. Its text is the source;
+ - an **offered** flag: true when the draft was not written by this tab;
+ - the **chip resolutions** for every link in the source: `{target → kind, href, current title}`, under the viewer's scope.
+
+**A person with a draft:**
+- The server renders **the draft's text** as the page body, so the editor mounts over identical markup.
+- A bar above the body reads: "Unsaved changes from 2 hours ago. You're seeing your unsaved version." It offers Save, Discard and "Show the saved version".
+- Without script this is still true, and the bar's buttons are the existing POSTs.
+- Typing continues the draft. The draft is still "offered" until this tab types into it (§6.5).
+
+**`GET /links/resolve?t=…`** answers the state of up to 32 link targets, for chips typed after mount.
+- It is JSON, scoped like `/links/suggest`, and writes nothing.
+- It is inside L6 and L7.
### 6.9 No shift, no flash
-- **The server's HTML is the editor's DOM.** Phase 1 changes the renderer to draw exactly the schema's `toDOM`: chips, `<li><p>`, `pre-wrap`, and `h2` to `h6` for the heading levels.
-- **Mount:** the editor mounts `{mount: article}` on the same element, so its first render replaces identical markup.
-- **Before mount:** the body is `contenteditable` only after mount. Before that it is the readable page, and the bundle loads with `defer`.
- - A key pressed before mount is not lost silently. The page is not yet a text field, and the caret appears on mount.
- - This window is measured, and the gate holds it under 100ms on a warm cache.
-- **Panels and the sidebar** come from their cookies at first paint. The lead slot's `savestatus` reserves its width, and so does the presence line.
-- **Never FOUT:** the system UI face only, `ui-monospace` for code, and no webfont, as now. The editor's CSS is in `mapa.css` and is never injected by script.
-- **Gate L5** (§7) measures it.
+- **The server's HTML is the editor's DOM** (§5, L4).
+- **Mounting:** the editor mounts on the `<article>` itself (`{mount: article}`).
+ - Before mount the body is the readable page, not yet `contenteditable`.
+ - A key pressed before mount types nothing.
+ - The window before mount is measured (L5).
+- **First paint:** the panels and the sidebar come from their cookies.
+ - The lead slot's `savestatus` and the presence line reserve their width.
+- **Never FOUT:**
+ - The system UI face only, and `ui-monospace` for code. No webfont.
+ - The editor's CSS is in `mapa.css`, never injected.
### 6.10 The scriptless floor
-- **Without script:** a page reads as rendered Markdown. "Edit as Markdown" (View, and a link in the page's kicker) opens today's textarea with Save and its revision check. Every gate-7 walk still passes.
-- **With script:** View → Edit as Markdown is still there, for anyone who wants the source. It opens the same textarea screen.
-- **Agreement:** every Mapa node survives a trip through the textarea as text, because `[[ ]]`, `^id` and `![[ ]]` are plain text by design.
+- **Without script:** a page reads as rendered Markdown. "Edit as Markdown" (View, and a link in the page's kicker) opens today's textarea, with Save and its revision check.
+- **With script:** View → Edit as Markdown stays.
+- **Round-trips:** every Mapa node survives the textarea as text.
### 6.11 iOS and touch
-Known quirks. Each one gets a WebKit case in `make browser` where that is possible, and a check by hand on a real iPhone through Safari's Web Inspector. `devicectl` hangs on this Mac (Calls notes), so automated device runs are not promised.
+Each quirk gets a WebKit case in `make browser` where possible, and a check by hand on a real iPhone through Safari's Web Inspector. `devicectl` hangs on this Mac, so automated device runs are not promised.
-1. **Composition and autocorrect next to atoms.** Chips are non-editable inline atoms. IME composition (kana, pinyin), dictation and autocorrect replacements next to them are a known ProseMirror and WebKit weak spot.
- - Test each against a chip on both sides.
+1. **Composition and autocorrect next to atoms.** IME composition, dictation and autocorrect beside non-editable chips are a known weak spot of ProseMirror on WebKit.
+ - Test each with a chip on both sides.
- Never act on Enter while `isComposing`.
-2. **The selection callout.** iOS draws Copy and Paste above the selection, so the bubble goes below it on coarse pointers.
-3. **The keyboard.**
- - `visualViewport` keeps the bubble, the `[[` and `/` lists and the accessory row above the keyboard.
+ - The reparse waits for `compositionend` (§6.4).
+2. **The selection callout:** the bubble goes below the selection on coarse pointers, clear of iOS's callout.
+3. **The keyboard:**
+ - `visualViewport` keeps the bubble, the lists and the accessory row above the keyboard.
- The Links sheet hides while the keyboard is up.
- - The header stays put: no `100vh` traps, and `dvh` is used.
-4. **Zoom on focus.** Editable text is at least 16px on phones, or Safari zooms (the suite's iOS input-zoom fix).
-5. **Smart punctuation.**
- - iOS turns `--` into an en or em dash and straight quotes into curly ones.
- - The rule and code-fence input rules also accept `—-`, `–-` and the like.
+ - Heights use `dvh`.
+4. **Zoom on focus:** editable text is at least 16px on phones (the suite's iOS input-zoom fix).
+5. **Smart punctuation:** iOS turns `--` into a dash and quotes into curly quotes.
+ - The rule and fence input rules also accept `—-`, `–-` and the like.
- The `/` menu is the dependable path.
-6. **Checkboxes:** task boxes are NodeView buttons with names ("Done: Send Tom the summary"). A tap toggles the box; it does not place the caret.
-7. **The accessory row.** Página's keyboard row is adopted on phones while writing (§10, D6). It holds `[[`, `/`, B, I, list, checklist, and Make team page on private notes.
+6. **Checkboxes:** task boxes are NodeView buttons with names ("Done: Send Tom the summary"). A tap toggles; it does not place the caret.
+7. **The accessory row:** Página's keyboard row is adopted on phones while writing (§10, D6). It holds `[[`, `/`, B, I, list, checklist, and Make team page on private notes.
### 6.12 Accessibility
-- **The editor:** `role="textbox"`, `aria-multiline="true"`, and named "Page text, <title>". Chips carry the names in §4.2. A block's ¶ handle is a button named "Link to this block".
-- **`[[`, `/` and ⌘K:** combobox and listbox, with `aria-activedescendant`, `aria-expanded` and `aria-controls` on the editor while a list is open, and results announced in a polite live region ("3 pages").
+- **The editor:** `role="textbox"`, `aria-multiline="true"`, named "Page text, <title>".
+ - Chips have the names in §4.2.
+ - The ¶ handle is a button, "Link to this block".
+- **`[[`, `/` and ⌘K:**
+ - Each is a combobox and listbox, with `aria-activedescendant`.
+ - While open, the editor has `aria-expanded` and `aria-controls`.
+ - A polite live region announces counts ("3 pages").
- **Dialogs and regions:**
- ⌘K and the phone sheet are modal `<dialog>`s.
- - The Links panel and History are labelled regions.
- - Esc closes, and focus returns to what opened it.
-- **The sidebar:** `<nav aria-label="Mapa">` with `aria-current`. The rail keeps its labels for assistive technology.
-- **History's diff:** insertions are `<ins>` and deletions `<del>`, so screen readers announce them, and underline and strike carry the meaning.
+ - Links and History are labelled regions.
+ - Esc closes them, and focus returns to what opened them.
+- **The sidebar:** `<nav aria-label="Mapa">` with `aria-current`. The rail keeps its labels in the accessibility tree.
+- **History's diff:** `<ins>` and `<del>`, plus underline and strike.
- **General:**
- - Keyboard shortcuts are listed in Help.
+ - Shortcuts are listed in Help.
- Focus is always visible.
- Targets are at least 24px, and 32px on coarse pointers.
- - The page reflows at 320px (SC 1.4.10).
+ - Content reflows at 320px (SC 1.4.10).
- Reduced motion removes the sheet's and the bubble's transitions.
## 7. Gates
-**Base gates 1 to 12 keep passing, unchanged,** along with `make mutate`'s nine mutations. The new gates are numbered L1 to L12. They run in `make ci` unless they are marked browser.
+**Base gates 1–12 keep passing, unchanged,** and so do `make mutate`'s nine mutations. The new gates are L1–L12. They run in `make ci` unless marked "browser".
-**The corpus.** The level-up gates read one shared corpus, `internal/mapa/markup/testdata/corpus/`:
+### The corpus
+`internal/mapa/markup/testdata/corpus/` holds only text that may be committed:
- every synthetic page `synthetic.go` writes;
-- every Markdown file in the Oficina repos at a pinned commit. That is real prose: specs, READMEs and AGENTS files, with tables, nested lists, HTML, fences, long lines and Unicode;
-- the CommonMark spec's examples (0.31.2), as hostile input;
-- hand-written edges: CRLF and lone CR, tabs in list indents, level skips, `1)`, `*` and `+` bullets, `[X]`, unclosed fences, `~~~`, `***` and `_ _ _` rules, `^id` on every block kind, wiki links with odd spacing and `|` and `#^`, `[[` with no close, empty bodies, a body that is only blank lines, NBSP, U+2028, U+0085, U+FEFF, emoji, RTL text, and zero-width joiners.
-
-**Fidelity (Node, against Go's output):**
-
-- **L1, untouched round trip.** For every corpus body, mount and then serialise gives `cleanBody(body)` byte for byte.
-- **L2, locality.** Editing one block, chosen at random in each body with a fixed seed, changes only the bytes `markup.Replace` would change. Inserting or deleting blocks changes bytes only at the seams, by `Join`'s rule.
-- **L3, stability.** Seeded random edits (typing, marks, splits, joins, list moves, chips) give `serialise(parse(serialise(doc))) = serialise(doc)`. Every edited block reparses, in JavaScript and in Go, to the editor's own content.
+- the CommonMark spec's examples (0.31.2). Its CC BY-SA 4.0 licence is recorded beside them in `LICENSE.commonmark`;
+- fixtures written for the purpose, shaped like real notes: tables, nested and mixed lists, HTML, fences, long lines, Unicode;
+- hand-written edge cases:
+ - CRLF and lone CR;
+ - tabs in list indents, level skips, mixed list kinds;
+ - `1)`, `*` and `+` bullets, `[X]`;
+ - unclosed fences, `~~~`, `***` and `_ _ _` rules;
+ - `^id` on every block kind;
+ - wiki links with odd spacing, `|` and `#^`, and `[[` with no close;
+ - empty and whitespace-only bodies;
+ - a trailing empty item (`- `), a heading of only `#`, an empty quote;
+ - `***x***`, `**a *b* c**`, `*a **b** c*`, emphasis around links and code;
+ - continuation indents;
+ - NBSP, U+2028, U+0085 and U+FEFF;
+ - emoji, RTL text and zero-width joiners.
+
+**Private text is not committed.** `make corpus-local DIR=…` runs L1–L4 over Markdown files read in place, for example the Oficina repos. It commits nothing. Its result is recorded in the build notes.
+
+### Fidelity (Node, against Go's golden file)
+
+- **L1, untouched round trip.** For every corpus body, mounting and then serialising gives `cleanBody(body)` byte for byte.
+- **L2, locality.** In each body, with a fixed seed:
+ - Editing one block changes only the bytes `markup.Replace` changes for that block.
+ - The seams on either side keep their original bytes.
+ - Inserting or deleting blocks changes bytes only at the new seams, by `Join`'s rule.
+ - Undo back to the start gives the original bytes.
+- **L3, stability.** Seeded random edits cover typing, marks, splits, joins, list moves, chips, undo, copy-drag and paste.
+ - `serialise(parse(serialise(doc))) = serialise(doc)`.
+ - **Documents are compared**, not bytes: `parse(serialise(doc))` has the document's blocks, kind for kind, level for level and count for count, in JavaScript and in Go.
+ - The reparse rule is idempotent.
+ - No two blocks share a `^id`.
+ - Byte-preserving `Settle`: a merge changes bytes only in blocks mine changed, and at their seams.
- **L4, parity.**
- - `markup.mjs` equals Go's `Parse` and `Spans` on every corpus body: kinds, levels, markers, and byte offsets.
- - The editor's `toDOM` HTML equals Go's `Render` HTML.
- - Go writes the golden file (`go test -run Golden -update`), Node compares, and CI fails when the golden file is stale.
+ - `markup.mjs` equals Go's `Parse` and `Spans` on every corpus body: kinds, levels, markers and byte offsets.
+ - The editor's `toDOM` HTML equals Go's `Render` HTML, mark cases included.
+ - Go writes the golden file (`go test -run Golden -update`). Node compares against it. CI fails when the golden file is stale.
-**The page:**
+### The page
-- **L5, no shift (browser).** Chromium and WebKit, light and dark, at 1440px, 1000px and 390px.
+- **L5, no shift (browser).** Runs in Chromium and WebKit, light and dark, at 1440px, 1000px and 390px. It covers a page **with and without a draft**.
- Every block's box is identical before and after mount.
- No `layout-shift` entry is recorded from first paint through mount.
- - The cookies for sidebar and Links are honoured at first paint.
- - Mount happens within 100ms of `DOMContentLoaded` on a warm cache.
+ - Cookies are honoured at first paint.
+ - The time from `DOMContentLoaded` to mount is logged on every run. The gate fails only past 1s, which allows for CI machines. The 100ms warm target is checked by hand.
- **L6, scope (extends gate 1).** Bo's output is byte-identical whether or not Ana's private notes hold the term, the link, the pending text or the block reference. That covers:
- - the Links panel's lists and counts, the map's nodes and edges, and the phone's peek line;
- - Recent and Pinned;
+ - the panel's lists, counts, map nodes and edges, and the peek line;
+ - Recently edited and Pinned;
- the calendar's and the week's dots;
- ⌘K's groups and its date row;
- - `[[` suggestions;
- - the editor's link-resolution data;
+ - `[[` suggestions, `/links/resolve`, and the editor's data island;
- history summaries.
- `make mutate` gains a mutation that drops the panel's scope check.
-- **L7, a GET writes nothing (extends gate 10).** Every new GET leaves the database file's bytes unchanged: the panel and history fragments, rebase, the calendar month, and the cookie redirects. So does mounting the editor and leaving without typing: no draft, no row, no event.
-- **L8, scriptless (extends gate 7).** With scripts off, `make browser` walks:
- - the sidebar and its fold form;
+ Every one of those read paths goes through **one scoped accessor** on the index. `make mutate` gains a mutation that removes the scope from that accessor, and the gate must catch it.
+- **L7, nothing written without a write.** This extends gate 10. A dump of every table's rows is hashed before and after; the file's bytes are not compared, because the WAL and checkpoints move them. The hash must be unchanged for:
+ - every new GET: panel and history fragments, the calendar month, `/links/resolve`, `/search/suggest`'s date row;
+ - mounting the editor and leaving without typing;
+ - **opening a page with an offered draft and leaving it**: no revision is created and the draft is unchanged;
+ - opening New scratch page and leaving it.
+- **L8, scriptless (extends gate 7).** `make browser` walks, with JavaScript off:
+ - the sidebar and its fold POST (a foreign `return` falls back to `/`);
- the day pill and the calendar's months;
- the Links lists at the page's foot;
- - the History page and Restore;
+ - History and Restore;
- ⌘K's search page;
- rename in the header;
- - New team page;
- - Make team page;
+ - New team page and Make team page;
+ - the draft bar's Save, Discard and Show saved;
- Edit as Markdown and Save.
-**Saving:**
-
-- **L9, drafts and rebase (extends gate 11).**
- - A teammate's revision landing mid-edit merges by block without touching the block under the caret.
- - A same-block change shows the inline choice and commits nothing until the person chooses.
- - The `pagehide` commit writes and commits in one request.
- - A commit that changes nothing writes no revision.
- - A stale tab cannot overwrite a newer draft.
- - Make team page refuses a stale revision.
-
-**Quality:**
-
-- **L10, accessibility (browser).**
- - Chip names, roles and states.
- - A keyboard-only walk of `[[`, `/`, Make team page, ⌘K, the calendar, History and Restore, checking that focus returns.
- - Reflow at 320px.
+### Saving
+
+- **L9, drafts, rebase and commits (extends gate 11):**
+ - **Clean rebase:** a teammate's revision landing mid-edit merges by block and leaves the block under the caret untouched. The base then moves through the version-checked `rebase` POST, and the next commit is `Saved`, not `Merged`.
+ - **Typing mid-flight:** typing between the autosave's send and its reply means the merge is not applied and the base does not move. The next autosave converges.
+ - **Inline choice:** Yours goes through `Resolve` and commits once, with no repeat conflict.
+ - **The rebase POST is refused** with a stale version, or with a revision outside the window.
+ - **Offered drafts** commit only on Save, never on idle, leave or close.
+ - **`commit=1`** with a stale version writes and commits nothing.
+ - **A save that changes nothing,** including a `Merged` result equal to the current body, writes no revision.
+ - **Make team page** refuses a stale revision. Its indices come from the committed body.
+ - **The first scratch commit:**
+ - it is single-flight: two quick autosaves create one page;
+ - an empty body creates nothing (`ErrEmpty`);
+ - the second autosave is a draft on the new page.
+ - **`noBase` and `gone` replies** lead to the existing choices.
+ - **A stale tab** cannot overwrite a newer draft (build note 31's `Kept` included).
+
+### Quality
+
+- **L10, accessibility (browser).** It checks:
+ - chip names, roles and states;
+ - a keyboard-only walk of `[[`, `/`, Make team page, ⌘K, the calendar, History and Restore, with focus returning each time;
+ - the Esc-Tab way out of the editor;
+ - reflow at 320px;
- axe-core, vendored at a pinned version with no network fetch, finds nothing serious.
-- **L11, the busy rule.** Rename, Restore, Make team page, New team page, Pin and Link it hold their spinner for 650ms. Links, the fold, the calendar and Appearance switch at once.
-- **L12, the bundle.** CI rebuilds from the lockfile and fails on byte drift. The size is logged on every run, and the gate fails if it passes 120KB gzipped.
+- **L11, the busy rule.**
+ - Rename, Restore, Make team page, New team page, Pin and Link it hold their spinner for 650ms.
+ - Links, the fold, the calendar and Appearance switch at once.
+- **L12, the bundle.** CI rebuilds from the lockfile and fails on byte drift. The size is logged. The gate fails past 120KB gzipped.
## 8. Server changes, in one list
-- **The renderer:** chips with their states, long-form date links, `<li><p>`, `pre-wrap`, and the empty-body placeholder (Phase 1).
-- **The sidebar's data:**
- - Recent, from the event log (`actor` = the viewer, the page live and in scope).
- - Pins, if Paul rules them per person (§11, Q1): a sealed list in the member record, with no new plaintext column. A POST changes it and logs an event on the member object (base build note 3).
-- **The Links panel:** the map's layout, and the week's and month's dots, from the in-memory index under the viewer's scope.
-- **History:** per-revision summaries and the word diff. `?panel=1` fragments under Docs' `Sec-Fetch-Dest` rule.
-- **`/search/suggest`:** groups and the typed-date row.
-- **New, a GET, JSON:** `GET /p/{id}/rebase`.
-- **Autosave:** its reply gains `revision`. `POST …/draft` gains `commit=1`.
-- **Commits:** a no-op commit writes no revision. `MakeTeamPage` takes the revision its indices refer to.
-- **Cookies:** `mapa-sidebar` and `mapa-links`, set by script or by a form POST that redirects back.
-- **Unchanged:** §4's plaintext list, the seal, S1, S2 and S3, the event vocabulary apart from what the pin event needs, and every refusal.
+**Rendering (Phase 1):**
+- Chips and their states; date links in long form.
+- `<li><p>`, and a new list when the item kind changes.
+- `pre-wrap` on textblocks only, with no whitespace between blocks.
+- Continuation indents are not shown.
+- Well-formed emphasis HTML.
+- The empty-body placeholder.
+
+**The scoped accessor.** One function on the index returns what the viewer may see: team pages plus the viewer's own pages. Every new read path uses it:
+- the Links panel and the map;
+- the week and month dots;
+- Recently edited;
+- ⌘K's groups and dates;
+- `/links/resolve`;
+- the editor's data island.
+
+**Event verbs:**
+- `relinked`, for "Update links" and "Link it", which today log `edited`.
+- `marked`, for "Link to this block", which today logs `edited`.
+- These feed history summaries and keep bulk edits out of Recently edited.
+- Like every event, they say who did what to which page, and when. They say nothing about content. Each one replaces an `edited` row the same write already logged.
+
+**Pins** (Q1, proposed per person):
+- A sealed list of page ids in the member record. No new plaintext column, so §4's list is unchanged.
+- `POST /pins` changes it, held for 650ms.
+- It logs one event whose object is the **member**, verb `pins`. It never names the page.
+- A deleted or out-of-scope page drops out of the list when it is read.
+
+**History:**
+- Summaries come from event verbs, with the diff for `edited`.
+- "Earlier history has aged out" when the window has dropped revisions.
+- The word diff.
+- `?panel=1` fragments under the `Sec-Fetch-Dest` rule.
+
+**⌘K:** `/search/suggest` gains the groups and the typed-date row.
+
+**New endpoint:** `GET /links/resolve?t=…`, as JSON.
+
+**Autosave (`POST …/draft`):**
+- The reply gains `revision`, and `merge` when the base is behind (§6.5). The merge is computed over the request's own text.
+- `rebase=R` moves an **existing** draft's `BaseRevision`. It is version-checked and refused outside the window. Today `SaveDraft` sets the base only when it creates the row.
+- `commit=1` writes and commits in one request. It requires the current draft version.
+- Data that is not text but describes it (the version, the base) is not plaintext beyond what §4 already lists. The drafts row is `(…, base_revision, version, updated_at)`, as now.
+
+**Commits:**
+- A commit whose final body equals the current body writes no revision. That covers plain saves, `Merged` results and Resolve.
+- `markup.Settle` is byte-preserving (§6.4).
+- `MakeTeamPage` takes the revision its indices refer to, and refuses a stale one.
+
+**Scratch pages:** the first commit is single-flight per tab and per text. `ErrEmpty` is kept.
+
+**Pages with editor data:**
+- They carry the `no-store` JSON island.
+- A person with a draft is served the draft's text as the body, with the draft bar.
+
+**View cookies:** `mapa-sidebar` and `mapa-links`. They are set by script, or by `POST /view/sidebar` and `POST /view/links` with a `return` path that is checked to be local.
+
+**Unchanged:**
+- §4's plaintext list, if Q1 is answered "per person";
+- the seal, and S1, S2 and S3;
+- every refusal.
## 9. estilo and rastrillo
-- **Re-pin estilo** to `f724edb` or later. That brings the bar-stack (`39792ae`) and Mapa's mark at 125.
+- **estilo re-pin:** to `f724edb` or later. That brings the bar-stack (`39792ae`) and Mapa's mark at 125.
- **The floating glass panel moves to estilo.** Mapa is its second adopter after Docs' inspector, which is the "two implementations" rule.
- - An estilo branch extracts `[estilo-float]`: the glass, rim, shadow and dark values, and the centring helper.
+ - An estilo branch extracts `[estilo-float]`: the glass, the rim and shadow, the dark values, and the centring helper.
- Mapa adopts it. Docs adopts it when it next re-pins.
- - The panel needs no light (`light.js`) glow: the Links panel holds no controls that need the back-light.
-- **The sidebar's row grid and the rail** stay Mapa's until a second app wants them. Fichas' rail is the likely one.
-- **rastrillo's `[rst-shell-nav] a` alignment** is reported upstream to rastrillo. Mapa no longer uses that shell.
+ - The Links panel needs no `light.js` glow, because it holds no controls that need back-lighting.
+- **The sidebar's row grid and the rail** stay Mapa's own until a second app wants them. Fichas' rail is the likely one.
+- **rastrillo:** the `[rst-shell-nav] a` alignment bug is reported upstream.
## 10. Departures
-**From the mock-ups:**
-
-- **D1, Pinned.** The mock-up's Pinned has no owner and no storage. This spec proposes per-person pins, sealed in the member record (§11, Q1).
-- **D2, Recent.** "Recent" is **the pages you last wrote in**, not the pages you last opened. Remembering opens would make a GET write, which gate 10 forbids. The browser could keep visits instead, but the server could not render them at first paint without a shift.
-- **D5, the day pill.** The day pill is in the header on daily notes even when the panel's week strip is open. The C mock-up drops it there, but the strip leaves when Links is off.
-- **D6, the phone accessory row.** The phone keyboard row comes from Página. Contexto's mock-up has none, and without it a phone has no way to reach `[[`, `/` or Make team page.
-- **D7, embeds.** Embeds stay reference chips until slice 2. The Fichas card in the mock-up needs S10.
-- **D8, the oldest version.** History's oldest entry says "Created this page", not "Made this page from your note". Saying where a team page came from would need a new event verb in the plaintext log that marks a page as born from private writing, which is a new disclosure.
-- **The map's limits.** The map is capped at 12 neighbours and shows no "more" count. Its nodes take no tab stop, and the lists are the accessible route.
-
-**From the base spec, each for the reviewer:**
-
-- **D3, the tab-close commit.** Closing the tab now commits the draft, by one `keepalive` POST from the person's tab. Base §5 has a closed tab's draft wait for the next visit, which this keeps only as the fallback. The reason is that the page has no Save button, and "Saved" must not turn into "You have unsaved changes" an hour later. Every commit is still a POST made by the person's own tab, and nothing runs on the server (doctrine §13).
-- **D4, title-first team pages.** A new team page exists from its title, before its body. That is what `POST /pages` already does. It retires build note 25's known limit for team pages. Scratch pages keep it, now only as "the first autosave creates the page".
-- **D9, `pre-wrap`.** Reading views render under `pre-wrap`, so runs of spaces show as typed. That is a visible change for pages typed in the textarea with aligned spaces.
-- **D10, no source blocks.** The mock-up README proposed "source blocks" for tables and HTML. This spec drops them, because Mapa's own parser already reads those as paragraphs and stores them byte for byte.
-- **D11, no escapes.** Mapa has no escapes, so the editor cannot keep a literal `*word*` as text. That is how the textarea already behaves. Adding backslash escapes to the subset is possible, but it changes Go's renderer, search, S3 readers and the textarea together. It is left out, and the trigger to revisit it is someone needing literal asterisks.
-- **Two new rules:** a no-op commit writes no revision, and `MakeTeamPage` checks its revision. Both make an existing promise stricter.
-- **Unchanged:** decisions 1 to 15, the rungs and the namespace, the seal boundary (§4's list, unless Q1 is ruled per team), S1, S2 and S3, and slices 2 and 3.
+### From the mock-ups
+
+- **D1, pins.** The mock-up's Pinned list has no owner and no storage. Pins are proposed per person and sealed (§11, Q1).
+- **D2, "Recently edited".** The list shows **pages you last wrote in**, not pages you last opened, and excludes bulk edits.
+ - Remembering opens would make a GET write, which gate 10 forbids.
+ - Keeping visits only in the browser would not be on screen at first paint without a shift.
+- **D5, the day pill.** It stays in the header on daily notes even while the panel's week strip is open. The strip leaves when Links is off.
+- **D6, the accessory row.** The phone keyboard row is Página's. Contexto has no other way for a phone to reach `[[`, `/` or Make team page.
+- **D7, embeds.** Embeds stay reference chips until slice 2. The mock-up's Fichas card needs S10.
+- **D8, the oldest version.** History's oldest entry says "Created this page", not "Made this page from your note".
+ - Recording where a team page came from would need a plaintext event that marks it as born from private writing. That would be a new disclosure.
+- **The map:** at most 12 neighbours, no "more" count, no tab stops. The lists are the accessible route.
+
+### From the base spec, each for the reviewer
+
+- **D3, a closed tab commits.** Closing the tab commits a draft **this tab typed into**, by one `keepalive` POST with the current version. Base §5's "offered on the next visit" becomes the fallback.
+ - The page has no Save button, so "Saved" must not turn into "You have unsaved changes" an hour later.
+ - Offered drafts never commit without Save.
+ - Every commit is still a POST from the person's own tab, and nothing runs on the server (doctrine §13).
+- **D4, title-first team pages.** A new team page exists from its title, which is what `POST /pages` already does. That retires build note 25's known limit for team pages.
+- **D9, whitespace.** Textblocks render under `pre-wrap`, so runs of spaces inside a line show as typed. Continuation indents stay hidden, as now.
+- **D10, no "source blocks".** The mock-up README's source blocks for tables and HTML are dropped. Mapa's parser already reads those as paragraphs and keeps their bytes.
+- **D11, no escapes.** A literal `*word*` becomes emphasis, as in the textarea. Adding backslash escapes would change Go's renderer, search, S3 readers and the textarea together.
+ - The trigger to revisit this is someone needing literal asterisks.
+- **D12, a scratch page is created by its first commit, not its first draft.**
+ - Base build note 13 ("created by its first save") and the textarea keep a new scratch page's text in the tab until Save.
+ - With no Save button, the editor's first autosave on a new scratch page is that save. It is a commit, single-flight, and refused when empty (`ErrEmpty`).
+ - So a scratch page reaches the database about 1.2s after its first words, with a revision and an event. Every later autosave is a draft.
+ - It is not a change to §4: it is the same row and event a Save makes.
+- **D13, byte-preserving merges.** `Settle` keeps the bytes of the current revision outside the blocks mine changed. That revises build note 23's "a merged save can tidy blank lines".
+- **Stricter rules:**
+ - A no-op commit writes no revision.
+ - `MakeTeamPage` checks its revision.
+ - `commit=1` checks the current version.
+ - "Update links", "Link it" and "Link to this block" get their own verbs.
+ - Each of these makes an existing promise stricter, or the event log more exact.
+- **Unchanged:**
+ - decisions 1–15;
+ - the rungs and the namespace;
+ - the seal boundary, S1, S2 and S3;
+ - slices 2 and 3.
## 11. Open questions for Paul
-1. **Q1, Pinned: yours, or the team's?** The recommendation is yours: private, sealed, and never shown to anyone else. Team pins would need a team-visible setting, with history.
-2. **Q2, Recent means "what you last wrote in", not "what you last opened"** (D2). Is that acceptable?
-3. **Q3, closing the tab saves** (D3), so a closed tab no longer leaves "You have unsaved changes" behind except when a conflict or a failed send forces it. Yes?
-4. **Q4, the sidebar's default** with no cookie: open from 80rem and the rail below that. Or always open, or always the rail?
+Fable's recommendations are written in as the proposed answers.
+
+1. **Q1, pins: yours, or the team's?** *Proposed, awaiting Paul:*
+ - Yours. Pins are private, sealed in your member record, and never shown to anyone else.
+ - The pin event names only you, never the page.
+2. **Q2, "Recently edited":** what you last wrote in, not what you last opened. Bulk link updates don't count (D2). *Proposed, awaiting Paul:* yes, labelled "Recently edited".
+3. **Q3, closing the tab saves your writing** (D3). It applies only to writing done in that tab. A draft from an earlier session still waits for your Save. *Proposed, awaiting Paul:* yes, with those conditions.
+4. **Q4, the sidebar's default** with no saved preference. *Proposed, awaiting Paul:* open from 80rem, the rail below that.
## 12. Phasing
**Phase 0:** this spec, reviewed. Then stop.
-**Phase 1: the chrome, on today's editor.** One commit per step, each green on `make ci` and `make browser`.
-
-1. Re-pin estilo; Mapa's mark and hue; drop `themeSlug`'s fallback.
-2. The shell: the stacked header with menus, lead and actions; the sidebar, rail, fold and cookie; the Menu sheet below 800px; New team page.
-3. The page: full window, kicker line, title, rename in both places, chips (the renderer, §4.2 and §5), `pre-wrap`, the textarea screen restyled.
-4. The Links panel: the lists, the map, the foot fallback, the phone sheet, the week on daily notes. Gate L6 for the panel.
+**Phase 1: the chrome, on today's editor.** One commit per step, each green on `make ci` and `make browser`:
+
+0. **The spike:**
+ - `editor/` tooling with Node in CI;
+ - `markup.mjs`'s parse;
+ - `schema.mjs` and `toDOM`;
+ - the Go golden file;
+ - L4's HTML half over the corpus.
+1. Re-pin estilo, take Mapa's mark and hue, and drop `themeSlug`'s fallback.
+2. **The shell:**
+ - the stacked header;
+ - the sidebar, rail, fold and cookie;
+ - the Menu sheet below 800px;
+ - New team page.
+3. **The page:**
+ - full window, the kicker line and the title, with rename in both places;
+ - the renderer changes of §5, until L4 passes;
+ - the restyled textarea screen;
+ - the draft bar.
+4. **The Links panel:**
+ - the scoped accessor and L6's mutation;
+ - the lists and the map;
+ - the foot fallback, the phone sheet, and the week on daily notes.
5. The day pill and the calendar.
-6. The History panel, its summaries and the word diff.
+6. **History:** the event verbs `relinked` and `marked`, summaries, "aged out", and the word diff.
7. ⌘K's groups and dates.
-8. Recent and Pins (after Q1).
+8. Recently edited, and pins (after Q1).
9. Gates L7, L8 and L11 for Phase 1, and a preview on its own tailnet port.
-**Phase 2: the editor.**
-
-1. `editor/` tooling, CI with Node, and an empty bundle served (L12).
-2. `markup.mjs` and the corpus with its Go golden file (L4, parsing).
-3. The schema, `toDOM` and the renderer's agreement (L4, HTML).
-4. The block-source serialiser and the reparse rule (L1 to L3).
-5. Mounting without a shift (L5), drafts in the editor, autosave, commit, `pagehide`, the no-op commit.
-6. Rebase and the inline conflict choice (L9).
-7. Chips, `[[`, `/`, input rules, the bubble, paste, block anchors.
-8. Make team page from a selection.
-9. iOS, the accessory row, and accessibility (L10). Then Edit as Markdown in View.
-
-Each phase ends in review on its branch before anything lands. Nothing is merged or deployed from here.
+**Phase 2: the editor:**
+
+1. The full schema and serialiser:
+ - origins and the side table;
+ - seams;
+ - empty blocks;
+ - the structure check and the reparse rule (L1–L3).
+2. Byte-preserving `Settle` and the no-op commit, in Go (L3, L9).
+3. **Mounting:**
+ - the JSON island and `/links/resolve`;
+ - mounting over the draft;
+ - no shift (L5).
+4. **Saving:**
+ - autosave and the tab's own draft;
+ - commit, `pagehide` with `commit=1`;
+ - the first scratch commit.
+5. **Rebase:**
+ - the merge in autosave's reply;
+ - the `rebase` POST;
+ - the inline choice through Resolve (L9).
+6. **Editing:**
+ - chips, `[[`, `/`, input rules and the bubble;
+ - the clipboard;
+ - block anchors.
+7. Make team page from a selection.
+8. iOS, the accessory row and accessibility (L10), then Edit as Markdown in View.
+
+Each phase ends in review on its branch. Nothing is merged or deployed from here.
+
+## 13. Build notes
+
+None yet. The build records its choices here, as base §15 does.
+
+## 14. Revision 2: Fable's findings and what changed
+
+| Finding | Change | Where |
+|---|---|---|
+| **H1** Rebase can't move the base: `SaveDraft` sets it only on create, `CommitDraft` merges from the old base, Yours conflicts again, and every later commit is `Merged` and loses bytes | `rebase=R` is a version-checked POST that moves an existing draft's base. The inline choice goes through the existing `Resolve`. The reply names the revision it merged against. `Settle` becomes byte-preserving. `Kept` stays pinned | §6.5, §6.4, §8, L9, D13 |
+| **H2** Rebase merged the stored draft, not the text on screen | The GET is dropped. Autosave's reply merges exactly the text it carried. The editor applies it only if that is still its text. The base never moves unless the result serialises to exactly the merge. The race is in L9 | §6.5, §8, L9 |
+| **H3** An offered draft was committed when the page was left | Only a draft this tab typed into commits by itself. An offered draft commits only on Save. `commit=1` needs the current version. L7 covers opening a page with a draft and leaving it | §6.5, §6.8, §8, L7, L9, D3, Q3 |
+| **H4** "Same node object" fails both ways | Each block has an origin id that is not serialised, with a side table. A block is untouched when it is the first holder and `===` or `eq` holds, with an equal context. Seams are kept while origins stay adjacent. A structure check runs before every autosave. L3 compares documents | §6.4, L2, L3 |
+| **M1** An empty trailing item or heading corrupted the block above | Empty blocks serialise as nothing. Corpus cases added | §6.4 step 4, corpus |
+| **M2** Marks: Go cannot nest strong and em, and never crosses spans | The editor makes strong and em exclude each other and never span links, atoms or code. Commands split at those boundaries. Go's `***x***` mis-nesting is fixed so it renders well-formed HTML. L4 holds the mark corpus | §6.3, §5, L4 |
+| **M3** Mounting over a draft shifted; the editor's inputs were unspecified | A `no-store` JSON island carries the source, the draft and chip resolutions. `/links/resolve` is added. The server renders the draft's text. L5 covers the draft case | §6.8, §8, L5, L6, L7 |
+| **M4** Cut and paste went through HTML; stripping markers broke block links | Mapa Markdown and an `application/x-mapa` slice go on the clipboard. A marker is stripped only when its id is already in the document | §6.6, L3 |
+| **M5** The list schema was unspecified | Lists by kind run, `indent` and the list attributes on `list_item`, depth as Go computes it, fidelity keyed on the item's paragraph. `renderList` splits lists when the kind changes | §6.3, §5 |
+| **M6** `pre-wrap` placement; continuation indents | `pre-wrap` on textblocks only, with no whitespace between blocks. Continuation indents are hidden and kept on `hard_break` | §5, §6.3, D9 |
+| **M7** History summaries | The verb comes from the event row. "Renamed" is added, along with `relinked` and `marked`. "Earlier history has aged out" | §4.5, §8 |
+| **M8** The first autosave creating a scratch page was not listed | Listed as D12. Single-flight, `ErrEmpty` kept, gated | §4.7, §6.5, §8, L7, L9, D12 |
+| **M9** Reparse during IME; idempotence | Deferred until `compositionend`. L3 asserts idempotence | §6.4 step 6, §6.11, L3 |
+| **M10** Spike `toDOM` before the renderer changes | Phase 1 step 0 is the spike. The HTML is called final only once L4 passes | §5, §12 |
+| **L** The no-op commit should cover `Merged` | Covered, and Resolve too | §6.4 step 7, §8 |
+| **L** Rebase answers for an aged-out base, a deleted page, a stale version, `/d/{date}` | `noBase`, `gone`, the 409, and the daily note rules | §6.5 |
+| **L** L7 compares file bytes; the fold is a GET with an unchecked return | A logical dump hash. The fold is a POST with a checked local `return` | L7, L8, §3.2, §8 |
+| **L** L5's 100ms | Logged. The gate fails past 1s; the warm target is checked by hand | L5 |
+| **L** `prosemirror-history` pin; gap cursor and trailing paragraph | Pinned exactly, with `-gapcursor` and `-dropcursor`. The document always ends in a paragraph | §6.2 |
+| **L** L6 per-path mutations | One scoped accessor and one mutation on it | §4.3, §8, L6 |
+| **L** Corpus curation and licence | No private text committed. `make corpus-local` reads it in place. The CommonMark licence is recorded | §7 |
+| **L** Recent excludes bulk edits and is labelled | "Recently edited". `relinked` and `marked` are excluded | §3.2, §8, D2, Q2 |
+| **L** Returning from the back/forward cache | Reload if nothing is unsaved, otherwise autosave at once | §6.5 |
+| **L** Make team page indices | From the committed body, parsed | §6.7 |
+| **L** A keyboard way out of Tab | Tab indents only in lists. Esc then Tab always leaves | §6.6, L10 |
+| **Q1–Q4** | Fable's recommendations written in as proposed answers, awaiting Paul | §11 |