oficina / mapa Public

Mapa level-up spec, revision 3: Fable's approval conditions N1-N5 and round-2 lows

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

Prompt

Fable APPROVED rev 2 (ad06a4e) on condition that N1-N5 go into the spec. Make revision 3: apply them, fold in the Lows, add a round-2 table to section 14, push, then 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

relinked/marked on team pages only, private bulk edits excluded by transaction; opaque never-reused origins with neighbours and seams, fresh origins on paste, table updates outside undo; conflict replies carry hunks and Resolve answers JSON, conflicted blocks locked until chosen; rebuild against M then check parse(M), bounded retries; em/strong overlap with four pinned HTML outputs; lows applied; round-2 table added.
Agent notes
Checked: index.go and gate 8 never branch on Event.Verb; S1 (item 6) is not built.
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 49a7d0acede4795e533c915069f41e89d556c8c5 parent ad06a4e
1 file changed, +204 −93
  • docs/superpowers/specs/2026-11-14-mapa-level-up.md +204 −93

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	8.466s
?   	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 956d165..cd0c334 100644
--- a/docs/superpowers/specs/2026-11-14-mapa-level-up.md
+++ b/docs/superpowers/specs/2026-11-14-mapa-level-up.md
@@ -1,9 +1,10 @@
# Mapa level-up: Contexto with Página's rail, and a page you write on
-**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".
+**Status:** revision 3, 2026-11-14. Nothing is built.
+- **Round 1.** Claude Fable 5.2 reviewed revision 1 (`4027e10`) and found CHANGES REQUIRED: 4 high, 10 medium and 11 low findings. Revision 2 (`ad06a4e`) answered them.
+- **Round 2.** Fable **approved revision 2 on condition** that N1–N5 and its lows go in. This revision makes those changes.
+- §14 maps every finding from both rounds to what changed.
+- §11's questions to Paul are still open. The proposed answers are written in and marked "awaiting Paul".
**Branch:** `design/level-up` (Mapa). Later, an estilo branch for the floating panel (§9).
@@ -82,7 +83,10 @@ He was shown three directions: Página, Estante and Contexto. He ruled: **"Let's
- **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.
+ - Bulk edits do not count (§8, "Event verbs"):
+ - On team pages, "Update links" and "Link it" log `relinked`, and "Link to this block" logs `marked`. Neither verb counts.
+ - On private pages these edits still log `edited`, so that the plaintext log says nothing about a private link graph. They are left out by their write instead. An "Update links" write commits several pages in one transaction, and its events share one actor and one `at` (`tx.at`). Any transaction that logs more than one `edited` event is bulk, and does not count. Make team page logs one `created` and one `edited`, so both of its pages count.
+ - "Link it" on a private note edits one page, so it counts. It is an edit the person made to that note.
- 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.
@@ -239,11 +243,11 @@ Slice 2's estilo card partial replaces the embed chip (§10, D7).
| Event verb | Summary |
|---|---|
| `created` | "Created this page" (§10, D8) |
- | `renamed` | "Renamed from <the old title>" |
+ | `renamed` | "Renamed from <the old title>". If the revision before has aged out, "Renamed to <the new title>" |
| `reverted` | "Restored the version from <date>" |
| `restored` | "Brought back after it was deleted" |
- | `relinked` | "Updated links" |
- | `marked` | "Made a block linkable" |
+ | `relinked` (team pages only) | "Updated links" |
+ | `marked` (team pages only) | "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.
@@ -295,6 +299,7 @@ Slice 2's estilo card partial replaces the embed chip (§10, D7).
- 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.
+- **The trailing paragraph:** a body whose last block is not a paragraph ends with the editor's empty paragraph (§6.2).
- **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.
@@ -303,10 +308,18 @@ Slice 2's estilo card partial replaces the embed chip (§10, D7).
- `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).
+- **Emphasis.** One fix, and the rest pinned as they render today:
+ - **The fix:** today `***x***` renders as the mis-nested `<strong><em>x</strong></em>`. A triple-star pass runs before the strong and em passes and pins it to `<em><strong>x</strong></em>`. That is the nesting the schema holds (§6.3).
+ - **Every other emphasis case** keeps its exact HTML. There is a golden test over the corpus.
+ - **Emphasis never crosses a link, an atom or code,** as now.
+ - **The corpus pins these four outputs.** L4 compares Go, `markup.mjs` and the editor's `toDOM` against them:
+
+ | Source | HTML |
+ |---|---|
+ | `*a **b** c*` | `<p><em>a <strong>b</strong> c</em></p>` (unchanged) |
+ | `***x***` | `<p><em><strong>x</strong></em></p>` (fixed) |
+ | `**a** ***b*** **c**` | `<p><strong>a</strong> <em><strong>b</strong></em> <strong>c</strong></p>`, the form the editor writes for "a b c" in bold with "b" also in italics |
+ | `**a *b* c**` | `<p>**a <em>b</em> c**</p>` (unchanged). Go cannot render bold around a partial italic, so the editor never writes it. A stored one keeps its source and reads as it does today |
So Phase 2 changes no reader's view, and moves nothing when the editor mounts.
@@ -337,6 +350,7 @@ The bundle is built the way Docs builds its bundles (Slides copied it).
- **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).
+ - **The server renders that trailing paragraph too.** When a body's last block is not a paragraph, the server emits the editor's own empty paragraph after it, so mounting adds nothing. Its exact markup is pinned in L4.
- **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.
@@ -371,16 +385,17 @@ The bundle is built the way Docs builds its bundles (Slides copied it).
**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***`.
+- **They may overlap wherever Go draws well-formed HTML** (N5). That replaces revision 2's rule that they excluded each other, which contradicted §5 on `*a **b** c*`.
+ - `em` comes before `strong` in the schema's mark order, so `toDOM` always nests `em` outside `strong`. That is the nesting Go draws for `*a **b** c*`, and the nesting Phase 1 pins for `***x***` (§5).
+ - **Serialisation:** wherever both marks apply, the `*` goes outside the `**`.
+ - Bold that is only partly italic is closed and reopened around the italic part: `**a** ***b*** **c**`. Go cannot draw `**a *b* c**`, so the editor never writes it.
+ - Whitespace at a mark's edge is moved outside its delimiters, because a closing `*` needs a non-space before it.
+ - The reparse rule (§6.4, step 6) settles anything else the editor's document cannot round-trip. The block takes the shape Go draws before it is saved.
- `code` excludes every mark.
-- `link` (`[text](url)`, or `bare` for an autolink) excludes `strong` and `em`.
+- `link` (`[text](url)`, or `bare` for an autolink) excludes `strong` and `em`, because Go escapes a web link's text and draws no emphasis inside it.
- 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.
+- So a mark never spans a link, an atom or code: Go's `words()` marks only inside one text span. The serialiser closes marks before those, and reopens them after.
+- §5's table is the mark corpus that L4 holds Go, the port and `toDOM` to.
**Mapa's inline atoms:**
- `wikilink {target, anchor, shown, source, origin}` → `[[target#^anchor|shown]]`.
@@ -404,17 +419,31 @@ The bundle is built the way Docs builds its bundles (Slides copied it).
**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).
+1. **Origins.** On mount, `markup.mjs` parses the body into the same blocks that Go's `Parse` gives, with `Start` and `End` in UTF-8 bytes.
+ - Each textblock, and each rule, gets an `origin` attribute. The attribute is never serialised.
+ - **Origins are opaque, monotonic and never reused.** A counter in the editor's state issues them, starting at 1 for each page load, and every new origin is fresh.
+ - Revision 2 used block indices, which a rebuild reuses. Undo after a rebase could then pair an old node with another block's source (N2).
+ - **The side table never forgets.** It records each origin once and keeps the entry for the life of the page load. An entry holds:
+ - the original **node** and its exact **source**;
+ - its **context**: kind, level, list attributes, depth and list kind;
+ - its **neighbours**: the origins of the blocks before and after it;
+ - its **seams**: the exact bytes between it and each neighbour, and the leading or trailing bytes for the first and last block.
+ - Because no entry is ever overwritten, a node that undo brings back still finds the entry it came from.
- 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.
+ - **The first holder keeps the origin.** When a split or a copy-drag gives a second node the same origin, the first holder in document order keeps it. Every later holder is treated as new and gets a fresh origin, with no source.
+ - **Only the first holder keeps a marker.** A later block whose `^id` is already in the document loses it.
+ - **Pasted blocks get fresh origins.** Paste from Mapa's own clipboard (§6.6) brings each block's source, and the seams between the pasted blocks. Those enter the table under new origins.
+ - **Table updates stay out of undo.** Assigning origins at mount, after paste, or after a rebase (§6.5) is done in a transaction marked `addToHistory: false`. It changes only `origin` attributes, which are never serialised. Undo therefore never replays a table update.
+2. **"Untouched"** means three things:
+ - the node is the first holder of its origin;
+ - `node === original || node.eq(original)` for that origin's entry;
+ - 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**.
+3. **Seams.** Two adjacent blocks keep the seam bytes recorded between them, **whether or not either block was edited**, when:
+ - the table records them as each other's neighbours, under their current origins.
- 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 recorded leading and trailing bytes are kept while the blocks that carried them are still 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);
@@ -424,6 +453,7 @@ The bundle is built the way Docs builds its bundles (Slides copied it).
- 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.
+ - Empty blocks, which serialise as nothing (step 4), are left out of the count. So is the trailing paragraph the editor keeps (§6.2).
- 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.
@@ -447,80 +477,98 @@ The bundle is built the way Docs builds its bundles (Slides copied it).
**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**:
+- `Merge3` records, for each settled block, its index in theirs (or in mine), so `Settle` knows which blocks were neighbours.
- 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`.
+- **`Settle` runs the same structure check as the editor:** `Parse` of its result must give the settled blocks. If it does not, it falls back to today's `Join`, which is correct but tidies spacing. For example, a kept seam might join two paragraphs.
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, gate 11 and build note 31 (`Kept`) hold.
+The base spec's §5, gate 11 and build note 31 (`Kept`) all hold.
**Autosave:**
-- It fires 1.2s after typing stops, and only once the §6.4 structure check passes.
+- It fires 1.2s after typing stops, 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).
+**A tab's own draft.** The editor tracks whether **this tab has typed into the page**.
+- **Remembered in the tab.** `sessionStorage`, which is per tab and survives a reload, keeps the last draft version the tab wrote, keyed by page or by day (`mapa-draft:<key>`).
+- **Own or offered.** On load, a draft whose version matches that entry is the tab's own. So "reload, then close" still commits. Any other draft is **offered**: it is from another tab or an earlier session.
+- **Committing.** Only an own draft commits by itself. An offered draft commits only on **Save** (§6.8). Typing into an offered draft makes it the tab's own from then on.
-**Commit,** for a draft this tab typed into, happens:
+**Commit,** for an own draft, 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.
+- **when the person leaves the page inside Mapa**, by a link or the sidebar. The editor flushes the autosave, commits, then navigates. If that fails:
+ - **Saved or `Merged`:** it navigates.
+ - **Conflict:** it stays on the page and shows the inline choice (below), with "Leave and decide later". Leaving keeps the draft, which the next visit offers.
+ - **The flush failed** (offline, or a server error): it stays, shows Failed, and offers "Leave anyway". The person is told that what they typed since the last save will be lost.
+ - **The commit failed, but the draft is stored:** it navigates. The draft is the tab's own, so the next visit from this tab commits it by the usual triggers.
+- **when the tab closes,** on `pagehide` (§10, D3):
+ - One `keepalive` POST to `…/draft` carries `commit=1`, the tab's draft `version`, and any text not yet sent.
- 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.
+ - Otherwise 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.
+ - 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 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).
+- Teammates see it from the next commit, and see "Ana is editing" until then (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:
+**Learning of a teammate's revision.** There is no separate rebase GET. The autosave reply carries:
+- `version` and `revision`, the page's current revision.
+- `merge`, when the draft's base is not current. It is computed over **exactly the text this request carried**, and takes one of these forms:
- `{against: R2, body: M}` when the merge is clean;
- - `{against: R2, conflict: true}` when it is not;
+ - `{against: R2, conflict: true, hunks: […]}` 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).
+ - Each conflicting hunk carries `{at, count, base, mine, theirs}`. `at` and `count` are the hunk's blocks in the text sent. `base`, `mine` and `theirs` are the Markdown of the three sides.
+
+**Clean: applying `M`** (N4):
+1. **Precondition:** the editor's serialised body **still equals the text that autosave sent**. If anything was typed since, it does nothing, autosaves again and asks again.
+2. **Apply.** One transaction replaces every block that differs between the document and `parse(M)`, aligned by `markup.mjs`.
+ - **A block the teammate changed is applied, including the block under the caret.** The caret and the selection are mapped through, so they survive.
+ - Undo survives too: the transaction is an ordinary one, and undoing it brings back the person's own earlier text.
+3. **Rebuild the table against `M` first,** before anything is checked.
+ - Every block of `parse(M)` gets a fresh origin, with its source, context, neighbours and seams taken from `M`.
+ - This is done in an `addToHistory: false` transaction (§6.4, step 1).
+4. **Check** that the document's blocks equal `parse(M)` block for block: in kind, level, count, and each block's source. When they do, serialising the document gives exactly `M`.
+5. **Move 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 of this page** inside the window. Otherwise it refuses and moves nothing.
+6. **If step 4 fails,** for example after a teammate's spacing-only change that the editor cannot represent, the base does not move.
+ - The editor retries on the next two autosaves, so three tries in all, then stops trying.
+ - The draft keeps base R1, and **the server's byte-preserving merge settles it at commit** (§6.4). Nothing is lost and nothing loops.
+
+**Conflict** (N3):
+- **The inline choice.** The hunks' blocks are marked in place, each showing Yours, Theirs and Both (yours first, base build note 24), with the three sides from the reply.
+- **Locked until chosen.** The conflicted blocks are **read-only** until the person chooses. The rest of the page stays editable.
+ - An edit elsewhere autosaves as usual. Its reply carries the hunks again, for the new version.
+ - The choice shown always belongs to the version whose reply carried it.
+- **Posting.** Choosing posts to the **existing `POST /p/{id}/resolve`**, with `current=R2`, the `version` that reply belonged to, 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 answer.** Resolve answers **JSON when asked**: `{outcome, revision, body}`.
+ - **Saved:** the editor applies `body` and rebuilds the table against it, as steps 2–4 do. Its base becomes `revision`.
+ - **Conflicted again** (another revision landed, or the draft changed in another tab): the editor autosaves and shows the new hunks.
+ - Without script, the existing conflict page and its redirect stand.
+- **No commit of its own.** Until the person chooses, the base stays at R1 and the editor makes no commit of its own. Nothing nobody chose is committed.
+
+**The other answers:**
+- **`noBase`:** the existing side-by-side choice, keep mine whole or keep theirs.
+- **`gone`:** the existing "Save as a scratch page" or Discard.
+- **A stale version:** the existing 409, and the tab loads the newer draft (build note 31). That draft is then offered, not the tab's own.
- **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.
+ - An unwritten day's `/d/{date}/draft` has no revision and no merge.
+ - A written day behaves as its page does.
+ - A note created meanwhile by another tab takes the existing `NoBase` path.
-**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).
+**A commit that merged** (`Merged`, body returned) follows steps 1–4 against the merged body. With nothing typed since the send, the editor applies it, rebuilds against it and takes the new revision as its base. No `rebase` POST is needed: the commit dropped the draft. 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.
+- With no unsaved text, the editor reloads the page.
+- Otherwise it autosaves at once, which brings `revision` and `merge` back.
### 6.6 Typing: `[[`, `/`, input rules and the bubble
@@ -531,7 +579,7 @@ The cases:
- 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).
+ - The state of a newly typed chip comes from `POST /links/resolve` (§6.8).
- **`/`** at the start of an empty block, or after a space, offers:
- Heading 1, 2 and 3 (`#`, `##`, `###`);
- List (`-`), Numbered (`1.`) and Checklist (`- [ ]`);
@@ -539,7 +587,7 @@ The cases:
- Link to a page (`[[`);
- Date, a picker that inserts a `datelink`.
- Card from Fichas is hidden until slice 2.
-- **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.
+- **Input rules:** the same Markdown shortcuts work typed at the start of a block. `**x**`, `*x*` and `` `x` `` become marks, under §6.3's rules. A URL pasted over a selection makes a link.
- **The selection bubble:** B, I, code and link, then **Make team page** (private notes only).
- It sits above the selection, or below it on coarse pointers (§6.11).
- **Keys:**
@@ -547,10 +595,11 @@ The cases:
- **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.
+ - **Within Mapa:** copy and cut put **Mapa Markdown** on the clipboard (`text/plain`) beside the HTML. They also put a private `application/x-mapa` slice carrying each block's source and the seams between the copied blocks.
+ - A paste gives those blocks **fresh origins** that carry their source and seams (§6.4, step 1).
- 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.
+ - **Markers:** a pasted block's `^id` is stripped **only when that id is already in the document**. Only the first holder keeps it (§6.4, step 1). A cut and paste keeps its marker, so links to the block still work.
### 6.7 Make team page from a selection
@@ -573,8 +622,11 @@ The cases:
- 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;
+ - Whether the draft is the tab's own or offered is the tab's own knowledge, from `sessionStorage` (§6.5). The server cannot know it.
- the **chip resolutions** for every link in the source: `{target → kind, href, current title}`, under the viewer's scope.
+- **Encoding.** The island is written with Go's `encoding/json`, which escapes `<`, `>` and `&` as `\u003c`, `\u003e` and `\u0026`, plus U+2028 and U+2029.
+ - So a body holding `</script>` or `<!--` cannot end the element early.
+ - A test renders a page whose body is `</script><script>alert(1)</script>` and checks the island parses back to the same text.
**A person with a draft:**
- The server renders **the draft's text** as the page body, so the editor mounts over identical markup.
@@ -582,9 +634,14 @@ The cases:
- 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.
+**`POST /links/resolve`** answers the state of up to 32 link targets, for chips typed after mount.
+- It is a POST so that the targets travel in the body, not in a URL that logs and history keep. It writes nothing, like `/preview`.
+- It answers JSON, is scoped like `/links/suggest`, and is inside L6 and L7.
+
+**The Links panel reads committed text.**
+- The panel, the map, backlinks and mentions come from the in-memory index, which is fed only by committed revisions (base §3.2). A person's draft never enters the index.
+- So links typed into a draft appear in the panel after the next commit, and the panel is redrawn then.
+- With script, the panel is refetched after each commit.
### 6.9 No shift, no flash
@@ -686,10 +743,16 @@ Each quirk gets a WebKit case in `make browser` where possible, and a check by h
- **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`.
+ - **Origins** (N2):
+ - undo after a rebase, a paste, a split or a copy-drag never pairs a node with another origin's source;
+ - pasted blocks keep their copied bytes and seams;
+ - table updates never appear in undo history.
- 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, mark cases included.
+ - The editor's `toDOM` HTML equals Go's `Render` HTML.
+ - That includes the four pinned emphasis outputs in §5, word for word.
+ - It includes the trailing paragraph's markup.
- Go writes the golden file (`go test -run Golden -update`). Node compares against it. CI fails when the golden file is stale.
### The page
@@ -708,7 +771,8 @@ Each quirk gets a WebKit case in `make browser` where possible, and a check by h
- history summaries.
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;
+ - every new GET: panel and history fragments, the calendar month, `/search/suggest`'s date row;
+ - `POST /links/resolve`, which writes nothing;
- 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.
@@ -726,11 +790,25 @@ Each quirk gets a WebKit case in `make browser` where possible, and a check by h
### 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`.
+ - **Clean rebase.** A teammate's revision landing mid-edit merges by block.
+ - **Every block the teammate changed is applied,** the one under the caret included, and **the caret survives**.
+ - The table is rebuilt against `M`, and the document's blocks equal `parse(M)`.
+ - The base moves through the version-checked `rebase` POST.
+ - The next commit is `Saved`, not `Merged`, and keeps `M`'s bytes.
- **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.
+ - **When the check never passes:** a teammate's spacing-only change the editor cannot represent stops after three tries. The base stays put, and the commit's byte-preserving merge settles it.
+ - **Inline choice:**
+ - The reply carries each hunk's base, mine and theirs.
+ - The conflicted blocks are read-only until chosen.
+ - Yours goes through `Resolve`, commits once with no repeat conflict, and answers `{outcome, revision, body}` as JSON.
+ - An edit elsewhere while the choice is open re-sends the hunks for the new version.
+ - **The rebase POST is refused** with a stale version, with a revision outside the window, and with a revision of another page.
- **Offered drafts** commit only on Save, never on idle, leave or close.
+ - **Reload, then close:** a tab that typed, reloaded and then closed still commits, because `sessionStorage` remembers its version.
+ - **Leaving inside Mapa:**
+ - a conflict keeps the person on the page with the choice;
+ - a failed flush offers "Leave anyway";
+ - a stored draft whose commit failed lets them leave.
- **`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.
@@ -773,10 +851,14 @@ Each quirk gets a WebKit case in `make browser` where possible, and a check by h
- 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.
+- **New verbs, on team pages only.** `relinked` is for "Update links" and "Link it". `marked` is for "Link to this block". All three log `edited` today.
+- **Private pages keep `edited`.** A `relinked` row on a private page would tell the plaintext log that the page links to something, a fact that is otherwise sealed. That reasoning was Fable's, and the coordinator decided it (N1). Private bulk edits are kept out of Recently edited by their transaction (§3.2).
+- `marked` can only ever be on a team page anyway: base §3.2 mints markers only in the page that holds the block, and "Link to this block" is offered on team pages only.
+- **What a team-page verb says:** that the page's links were updated, which teammates can already read in its history. Each new verb replaces an `edited` row the same write already logged, so no row is added.
+- **Who reads verbs, checked against the code:**
+ - **The index** (`index.go`) catches up by object and revision, and never branches on a verb.
+ - **Gate 8** counts events per write, not verbs.
+ - **S1** (slice 1 item 6, not yet built) is fed from the event log by object and revision. It treats `deleted` as `gone` and every other verb as a change, so new verbs need nothing from it. Its conformance run will show this when it is built.
**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.
@@ -792,23 +874,29 @@ Each quirk gets a WebKit case in `make browser` where possible, and a check by h
**⌘K:** `/search/suggest` gains the groups and the typed-date row.
-**New endpoint:** `GET /links/resolve?t=…`, as JSON.
+**New endpoint:** `POST /links/resolve`, which writes nothing and answers JSON.
+
+**Resolve:** `POST /p/{id}/resolve` answers JSON `{outcome, revision, body}` when asked (`Accept: application/json`). The form path's redirect is unchanged.
**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.
+- The reply's `merge` carries each conflicting hunk's `{at, count, base, mine, theirs}`.
+- `rebase=R` moves an **existing** draft's `BaseRevision`. Today `SaveDraft` sets the base only when it creates the row.
+ - It is version-checked.
+ - It is refused unless R is **a revision of this page** inside the window.
- `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).
+- `markup.Merge3` records each settled block's index in theirs or in mine. `markup.Settle` is byte-preserving, runs the structure check, and falls back to `Join` when the check fails (§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.
+- They carry the `no-store` JSON island, escaped as §6.8 says.
+- Bodies whose last block is not a paragraph get the editor's trailing empty paragraph (§6.2).
- 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.
@@ -949,7 +1037,9 @@ Each phase ends in review on its branch. Nothing is merged or deployed from here
None yet. The build records its choices here, as base §15 does.
-## 14. Revision 2: Fable's findings and what changed
+## 14. Findings and what changed
+
+### Round 1: Fable on revision 1 (`4027e10`), answered in revision 2
| Finding | Change | Where |
|---|---|---|
@@ -979,3 +1069,24 @@ None yet. The build records its choices here, as base §15 does.
| **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 |
+
+### Round 2: Fable's conditional approval of revision 2 (`ad06a4e`), answered in revision 3
+
+| Finding | Change | Where |
+|---|---|---|
+| **N1** A `relinked` event on a private page puts a sealed link-graph fact into the plaintext log | `relinked` and `marked` are logged on team pages only, and private pages keep `edited` (the coordinator's decision). Private bulk edits are left out of Recently edited by their transaction: one actor, one `at`, more than one `edited`. The index, gate 8 and S1 are confirmed to need nothing for the new verbs | §3.2, §4.5, §8 |
+| **N2** Origins were block indices that a rebuild reuses, so undo, paste and split could pair a node with the wrong source | Origins are opaque, monotonic and never reused. The table never forgets, and keeps each origin's neighbours and seams. Pasted blocks get fresh origins with their source and seams. Only the first holder keeps a marker. Table updates are `addToHistory: false` | §6.4 step 1, §6.6, L3 |
+| **N3** The conflict reply carried no hunks | Each hunk carries `{at, count, base, mine, theirs}`. Resolve answers `{outcome, revision, body}` as JSON. Conflicted blocks are read-only until chosen; the rest of the page stays editable, and the hunks are re-sent for each new version | §6.5, §8, L9 |
+| **N4** "Serialises to exactly M" could fail forever | The table is rebuilt against `M` first, then the document's blocks are checked against `parse(M)`. Three tries at most, then the server's merge settles it at commit. Wording fixed: rebuilt against `M`; the caret survives; a block the teammate changed is applied | §6.5, L9 |
+| **N5** §5 and §6.3 disagreed on nested emphasis, and L4 failed its own corpus | The schema holds `em` and `strong` together wherever Go draws well-formed HTML, with `em` outside. `***x***` is pinned to `<em><strong>x</strong></em>`. Four outputs are stated exactly in §5 and held by L4 | §5, §6.3, L4 |
+| **L** `/links/resolve` as a GET | `POST /links/resolve`, which writes nothing, like `/preview` | §6.6, §6.8, §8, L7 |
+| **L** The structure check counted empty blocks and the trailing paragraph | Both are left out | §6.4 step 5 |
+| **L** The server should render the trailing paragraph | It does, and L4 pins its markup | §5, §6.2, §8, L4 |
+| **L** `Settle`'s check; `Merge3`'s indices | `Settle` runs the structure check and falls back to `Join`. `Merge3` records each block's index in theirs or mine | §6.4, §8 |
+| **L** `rebase=R` must belong to this page | Refused unless R is a revision of this page inside the window | §6.5, §8, L9 |
+| **L** Reload then close left an offered draft | `sessionStorage` keeps the tab's draft version, so the tab still knows the draft is its own | §6.5, §6.8, L9 |
+| **L** Does the Links panel read the draft? | Committed text only. The panel is refetched after each commit | §6.8 |
+| **L** "Renamed from…" when the prior revision has aged out | "Renamed to <the new title>" | §4.5 |
+| **L** Leaving inside Mapa when the commit fails or conflicts | A conflict stays on the page with the choice and "Leave and decide later". A failed flush offers "Leave anyway". A stored draft whose commit failed leaves | §6.5, L9 |
+| **L** Escape `<` in the JSON island | `encoding/json` escaping, with a `</script>` test | §6.8 |
+