| 1 | # Docs native redesign: slice plan |
| 2 | |
| 3 | Spec: `../specs/2026-11-22-native-redesign-design.md` (revision 3). |
| 4 | |
| 5 | **Status:** revision 3. Claude Fable 5.2 re-reviewed on oficina/docs #157: APPROVE AFTER FIXES, with no third pass. Revision 3 applies the fixes, and S1 is split into S1a and S1b (coordinator's ruling). |
| 6 | |
| 7 | **Ground rules for every slice:** |
| 8 | - One worktree and branch per slice, a branch discussion, and a whole-branch review by the highest available model. |
| 9 | - Paul approves anything that was his call. |
| 10 | - Hub CI exits 0 before the squash merge. |
| 11 | - Each slice is shippable on its own, as a Docs native release (Mac plus TestFlight) through the existing release process. Releasing still needs Paul's go-ahead. |
| 12 | - **iPad:** from S3 until S5, iPad keeps today's layout behind the idiom gate (spec §5). No slice ships the phone layout to iPad. |
| 13 | |
| 14 | **Order:** S0 → S1a → S1b → S2a → S2b → S3 → S4 → S5. |
| 15 | |
| 16 | **Acceptance shared by every slice:** |
| 17 | - **Copy review:** every new English string the slice introduces has been through copy review (the `paulca/agent-skills` copy-review skill, `serve.sh`; check `result.json` before re-upping), and the result is recorded in the slice's discussion before it lands. The twelve translations follow the reviewed English. |
| 18 | - **Physical devices:** one pass on a physical Mac and iPhone (and iPad from S5), recorded in `native/REVIEW.md` before the release (spec §11). |
| 19 | - **Gates:** |
| 20 | - `make ci` |
| 21 | - `native/scripts/check-native.sh` (including the 200-page document) |
| 22 | - `native/scripts/snapshots.sh compare` (re-recorded only where the slice changes a screen, with the contact sheet reviewed) |
| 23 | - `test-document-window.py`, `test-home-loading.py`, `test-offline-kill.py`, `test-sync-latency.py` |
| 24 | - `WorkspaceInitTests`, `SignedInLaunchTests`, `OfflineDurabilityTests`, `OficinaIDAdoptionTests` |
| 25 | - §7's hard counters (from S1a on; the line-fragment counter from S1b) |
| 26 | - **Tests fail first:** each new test was seen to fail for the intended reason (AGENTS.md). |
| 27 | |
| 28 | ## S0: editor snapshots on main |
| 29 | |
| 30 | Branch `test/editor-snapshots`. Small, and first. Spec §11 "Editor snapshots". |
| 31 | |
| 32 | **Work:** |
| 33 | 1. Add the fixed-fixture editor screens to `DocsSnapshots`, drawn by today's renderer: |
| 34 | - Mac paged and pageless at 100% and 150%; |
| 35 | - iPhone paged and pageless; |
| 36 | - an iPad-width editor (today's iPad layout); |
| 37 | - an "after a scripted edit" screen on Mac and iPhone (type a line before the first break, apply a peer insert in a later block); |
| 38 | - light and dark, iPhone at default and AX3. |
| 39 | 2. The fixture is laid out synchronously before capture. Remove the "editor is not here" exclusion comment. |
| 40 | 3. If `RastrilloSnapshots` cannot set a per-screen locale (needed from S2a for ar and ru), add that to rastrillo/native and re-pin. |
| 41 | |
| 42 | **Acceptance:** |
| 43 | - The new baselines are recorded and reviewed. |
| 44 | - They are stable across three consecutive `compare` runs. |
| 45 | - A deliberate one-point change to the paper margin reddens them. |
| 46 | |
| 47 | ## S1a: projection log, surface, per-block rendering, render isolation |
| 48 | |
| 49 | Branch `perf/native-render-isolation`. No visible change. Spec §7 Design and Measurement. |
| 50 | |
| 51 | **Work:** |
| 52 | 1. Bring the audit probes onto the branch from `perf/native-realtime-audit`, under the `DOCS_PROBES` compilation condition, and add the new counters. |
| 53 | - **Record the post-phase-2 baseline** for every §7 row in `native/benchmarks/README.md`. |
| 54 | - Confirm or adjust the timing targets, with reasons, in the S1a discussion before step 2. |
| 55 | 2. `CRDTReplica`: |
| 56 | - `presentedRevision`; |
| 57 | - the bounded dirty log, with unknown entries on every full `project` branch; |
| 58 | - `presentation(…, since:)` returning `(projection, resultRevision, dirty)` atomically. |
| 59 | 3. `DocumentSurface`: |
| 60 | - `appliedRevision`, stale-drop, `pendingDirty` and `fullDiff` (`CRDTNode: Equatable`); |
| 61 | - the block index over `.docsTopBlock` runs, kept in `didProcessEditing`, with provisional blocks; |
| 62 | - the two-pointer block walk; |
| 63 | - `renderBlock` with neighbour spacing; |
| 64 | - image- and font-scoped re-render; |
| 65 | - `flushIfDeferred()` wired to triggers (a)–(d). |
| 66 | 4. Per-block reconciliation on both platforms. iOS assigns `attributedText` only at open. |
| 67 | 5. Isolate the text view's host: |
| 68 | - the sync row and the toolbar read their own facets; |
| 69 | - `DocumentToolbarSelection` becomes one equality-guarded observed value; |
| 70 | - `DocumentCommands`, `DocsToolsControls` and `DocsEditorContext` read the live storage; |
| 71 | - equality-guard every observed assignment in `DocsModel`. |
| 72 | |
| 73 | Pagination is unchanged in S1a: today's `updatePagination` still runs. |
| 74 | |
| 75 | **Acceptance:** |
| 76 | - **Hard counters:** whole-document renders, block renders, host body evaluations and `attributedText` assignments meet the §7 gates at p20 and p200h. |
| 77 | - **Timings:** the confirmed targets that S1a alone can move (iPhone per publication, peer main-thread) are met. The Mac paged keyDown target waits for S1b. |
| 78 | - **Tests:** |
| 79 | - the block render equivalence property test; |
| 80 | - the block-index-under-optimistic-typing test; |
| 81 | - the delta-safety test through the real text view (dropped and delayed publications, extra projections, ja and zh marked text with peer edits, log overflow); |
| 82 | - the four deferred-flush trigger tests with no later publication. |
| 83 | |
| 84 | Each was seen to fail with its mechanism broken (a skipped neighbour re-spacing; a flush wired to `didRender` only). |
| 85 | - **No visual change:** S0's editor snapshots, including the after-scripted-edit screens, are unchanged, as are all other baselines. |
| 86 | |
| 87 | ## S1b: incremental pagination and lazy layout |
| 88 | |
| 89 | Branch `perf/native-pagination`. No visible change. Spec §7 Incremental pagination, iPhone layout, Fallback. |
| 90 | |
| 91 | **Work:** |
| 92 | 1. The measurement layout manager on the same storage, and the per-block `advance`/`usedBottom` caches with splices. The full path runs at open (visible-first, then idle chunks), when Pages is turned on, on a font registration affecting every block, and on a text-width change. |
| 93 | 2. The break table keyed by block id. The lookup is `max(proposed.minY, topU + X)` from the cache. The break algorithm runs from the first dirty block's page until convergence, coalesced once per run-loop turn before display. |
| 94 | 3. Range invalidation from the first block whose top changed; non-contiguous live layout; frame height from the caches; no whole-container `ensureLayout` in `layout()`. |
| 95 | 4. Today's measurement moves into the test target as `DocumentPageLayoutOracle`. |
| 96 | 5. iOS: no whole-document `ensureLayout` in `layoutSubviews`; non-contiguous layout. |
| 97 | 6. The line-fragment request counter. |
| 98 | 7. Run both large-document checks. If either platform fails, implement the §7 fallback for it (contiguous to the visible bottom) and record the choice in the discussion. |
| 99 | |
| 100 | **Acceptance:** |
| 101 | - **Hard counters:** every §7 hard counter, including line-fragment requests, at p20 and p200h. |
| 102 | - **Timings:** the confirmed Mac paged keyDown and stall targets, and the Pages-toggle bound. |
| 103 | - **Pagination equivalence:** |
| 104 | - The property test passes, typed through the real text view, before and after publication. |
| 105 | - Its cases are Return, Backspace at a block's start, block delete, multi-block paste, multi-dirty flushes, typing in a block taller than a page, and the large-heading and image-after-break fixtures. |
| 106 | - Production's breaks, live line origins (within 0.5pt) and frame height match a fresh oracle run. |
| 107 | - It was seen to fail with a break keyed by character index, and with a relative offset applied twice. |
| 108 | - **Large documents:** the Mac p200h check (both variants) and the iPhone p200h check pass, on non-contiguous layout or on the recorded fallback. |
| 109 | - **Caret:** the smoke test's caret-against-glyph checks and the composition-before-separator regression pass. |
| 110 | - **No visual change:** all S0 editor snapshots are unchanged. |
| 111 | |
| 112 | **S1b amendments (#173, coordinator's rulings, 2026-11-26):** |
| 113 | - **iPhone:** work item 5 and the iPhone p200h check are withdrawn from S1b. UIKit's TextKit 1 lays the rest of the document out inside any edit that changes a line count, and the only lever found is private API (not used). iPhone pagination is unchanged; the work moves to S3 (TextKit 2). See spec §7 "iPhone layout". |
| 114 | - **Known gap:** Pages off or on at the end of a 200-page document takes 0.50–0.63 s (measured at load 450–600), against the ≤ 250 ms Pages-toggle bound: the Mac's live layout is contiguous (§7 fallback), so the toggle re-lays out from the first break to the visible end. At the top of a document it is cheap. |
| 115 | |
| 116 | ## S2a: Mac document window, floating inspector, subtitle |
| 117 | |
| 118 | Branch `native/mac-document-window`. Spec §1 (except Share and Delete), §6, §8, §9. |
| 119 | |
| 120 | **Work:** |
| 121 | 1. **Header spike (half a day):** a custom title area with the system title hidden but set, run through the spec's six-item checklist (drag, double-click, overflow, full screen, tabs, VoiceOver). Record the result and the chosen contract (or the fallback, with Rename by sheet) in the S2a discussion before step 2. |
| 122 | 2. **rastrillo/native:** export `SyncStatusAnnouncer`, then re-pin the kit. |
| 123 | 3. **The header:** |
| 124 | - the title area with rename in place; |
| 125 | - the subtitle with every §6 row and the 1 s debounce in a `.task`; |
| 126 | - the undo/redo pill; |
| 127 | - the Format toggle. |
| 128 | |
| 129 | The `.principal` item is deleted. Share… keeps today's sheet until S2b. |
| 130 | 4. **`refreshAccess`:** |
| 131 | - 403 and 404 → "No longer available", left again on a later 200 (with `retry()`); |
| 132 | - 401 pauses input without touching `can_write`, and resumes on the post-re-mint 200; |
| 133 | - a 200 with `can_write == false` → View only in place. |
| 134 | 5. **The floating inspector:** sections, glass and rim; app-wide `docs.inspector.open`, default open; focus stays in the text view. |
| 135 | 6. **Page centring by translation:** |
| 136 | - the container becomes a fixed paper band; |
| 137 | - a flipped `DocsDeskView` becomes the scroll view's document view and draws the desk; |
| 138 | - the text view is its subview at `x = leading / m`; |
| 139 | - the web's clamp in window points. |
| 140 | 7. **Reader mode.** |
| 141 | 8. **Menus:** |
| 142 | - View: Show/Hide Format ⌥⌘I, the Paged/Infinite pair, native-only Zoom; |
| 143 | - Format: relabelled to the web keys, H1–3; |
| 144 | - Tools: Word count…; |
| 145 | - Help: Keyboard shortcuts…, Colophon; |
| 146 | - File: Open a document… ⌘K as a sheet over the focused window. |
| 147 | 9. **Remove** the Mac strip, the inspector column and the sync row. |
| 148 | 10. **Strings and snapshots:** |
| 149 | - the §8 keys this slice uses, after copy review, in twelve languages; |
| 150 | - orphaned `Mac.strings` keys deleted; |
| 151 | - snapshots: Mac document with the inspector open and closed, and reader, in light, dark, ar and ru. |
| 152 | |
| 153 | **Acceptance:** |
| 154 | - **Header:** the window title equals the document title, there is exactly one visible title, and a launch test asserts there is no `.principal` item. |
| 155 | - **Subtitle:** each §6 row is reachable by a unit test, including 401, 403 and 404. |
| 156 | - **Format:** ⌥⌘I flips it in all windows and persists across relaunch. It is disabled for readers and in the home window. |
| 157 | - **Centring:** hosted-window frames match the rule at all six widths, including the 1,108pt boundary. Inspector toggle and live resize meet the §7 per-frame target, with no layout invalidated. |
| 158 | - **Performance:** the §7 hard counters still hold. |
| 159 | |
| 160 | ## S2b: Share popover and Delete… |
| 161 | |
| 162 | Branch `native/share-and-delete`. Spec §1 Share popover and Delete…. |
| 163 | |
| 164 | **Work:** |
| 165 | 1. **Server:** |
| 166 | - `deletePost` answers native JSON (`{"ok":true}`, no re-read); |
| 167 | - the Go matrix: owner, writer grantee, reader, guest, team non-owner, already deleted, lookup-failure JSON, browser 303 unchanged, suite feed. |
| 168 | 2. **The Share popover** over the `docs.share.panel.*` model: |
| 169 | - the team switch and the link switch; |
| 170 | - hold, revert, the 500 ms spinner, a single submit; |
| 171 | - the once-only URL, non-transient while it shows; |
| 172 | - focus rules; |
| 173 | - disabled offline and for drafts. |
| 174 | |
| 175 | It replaces `DocsSharingView`'s sheet on the Mac, and iPhone gets the same panel as a sheet. |
| 176 | 3. **The Delete… client:** |
| 177 | - the version-skew rule (non-JSON → re-GET; 404 = deleted); |
| 178 | - a POST 404 is re-GOT too (404 = deleted; 200 = failed, nothing dropped); |
| 179 | - refused with unsent changes; |
| 180 | - after a delete: drop the lane and replica; close the window or pop to the library; refresh the list, Recent and thumbnails. |
| 181 | 4. **Strings and snapshots:** |
| 182 | - `docs.share.panel.*`, `docs.delete.*`, `native.share.offline`, `native.export.offline` and `native.delete.unsent`, after copy review; |
| 183 | - snapshot: the share popover in light, dark, ar and ru. |
| 184 | |
| 185 | **Acceptance:** |
| 186 | - **Server:** the Go matrix passes, and the server change is deployed to prod and lagged before the client is released (`curl /api/version` on each). |
| 187 | - **Delete client:** the Swift client-rule tests pass: JSON `ok`; 303 then 404; 303 then 200; POST 404 then GET 404; POST 404 then GET 200, with lane and replica kept. |
| 188 | - **Popover:** the once-only URL shows once and survives an outside click. Share while open is a no-op. Esc returns focus to Share…. |
| 189 | |
| 190 | ## S3: iPhone document |
| 191 | |
| 192 | Branch `native/iphone-document`. Spec §3, §6. Behind the iPad gate: iPad unchanged. |
| 193 | |
| 194 | **Work:** |
| 195 | 1. **iPhone navigation:** the library becomes a `NavigationStack` root and the document is pushed. iPad keeps the `NavigationSplitView`. |
| 196 | 2. **The header:** |
| 197 | - the large title hosted inside the text view's scroll view, through `DocumentHeaderState`; |
| 198 | - collapse on scroll, keyboard and sheet; |
| 199 | - back, the undo/redo pill, Aa and •••; |
| 200 | - Rename by alert; |
| 201 | - no Share pill. |
| 202 | 3. **The ••• menu** per capability, with the Paged/Infinite pair and Help ▸ Keyboard shortcuts…, Colophon. |
| 203 | 4. **The Format sheet:** |
| 204 | - the `.medium` detent with background interaction; |
| 205 | - the empty `inputView` keeping first responder and the selection; |
| 206 | - the inset following the sheet; |
| 207 | - typing marks; |
| 208 | - styles Body text and Heading 1–3 in their own faces; |
| 209 | - font, the size stepper, marks, alignment, lists and indent; |
| 210 | - the AX re-flow. |
| 211 | 5. **The keyboard bar** as `inputAccessoryView`, writers only. |
| 212 | 6. **The reader layout.** |
| 213 | 6a. **TextKit 2 for the iPhone text view** (S1b ruling, #173; spec §7 "iPhone layout"): the iPhone editor is rebuilt on TextKit 2, so neither opening nor typing lays out the whole document. Investigate the possible 72.7 pt caret offset at the end of a 200-page document (`PhoneLargeDocumentTests`). |
| 214 | 7. **Remove** the iOS strip, the toolbar items and the sync row on iPhone only. |
| 215 | 8. **Strings and snapshots:** |
| 216 | - `native.more`, `native.keyboard.hide` and the sheet's labels, after copy review; |
| 217 | - snapshots: the iPhone document, reader, format sheet and share sheet, at default and AX3, in light, dark, ar and ru. |
| 218 | |
| 219 | **Acceptance:** |
| 220 | - **XCUITest:** |
| 221 | - the keyboard bar appears with the keyboard, writers only, and with a hardware keyboard; |
| 222 | - Aa opens the sheet with the selection highlight still visible; |
| 223 | - the collapse triggers work; |
| 224 | - the ••• items match each capability. |
| 225 | - **iPad:** an iPad simulator still shows today's layout. |
| 226 | - **VoiceOver:** a peer edit does not move the cursor (spec §11). |
| 227 | - **Accessibility:** `performAccessibilityAudit()` passes on the document, sheet and share sheet. |
| 228 | - **Performance:** the iOS §7 counters and targets hold, and (carried from S1b, #173) at p200h paged in the simulator: |
| 229 | - per key, main-thread time ≤ 8 ms median, and no stall over 16.7 ms on a key that changes a line count (TextKit 1 today: 250–500 ms); |
| 230 | - opening lays out no further than the visible bottom, ≤ 250 ms main-thread to the first screen (today 0.6–1.5 s, the whole document); |
| 231 | - the §7 iPhone check: jump to the end before layout passes the first screen; caret against glyph, no line across a page gap, line origins equal to a whole layout's. |
| 232 | - **Caret:** the 72.7 pt end-of-document caret offset is explained, and fixed if real. |
| 233 | |
| 234 | ## S4: Mac home and iPhone library |
| 235 | |
| 236 | Branch `native/home-and-library`. Spec §2, §4. The iPad library is unchanged (gate). |
| 237 | |
| 238 | **Work:** |
| 239 | 1. Decode `thumbnail.Excerpt`. Add the shared `LibraryModel`: the shelf of five, the four groups in the device calendar, searching ungrouped. |
| 240 | 2. **Mac home:** the window toolbar has "Documents", search, the filled + and the avatar with its menu. The content is the shelf, then the grouped rows card. Remove the sidebar and the large title. |
| 241 | 3. **iPhone library:** the large title and avatar (with Colophon); search and compose in the bottom toolbar; the shelf and rows; pull to refresh. |
| 242 | 4. **States:** empty, no results and failure on both. |
| 243 | 5. **Strings and snapshots:** |
| 244 | - `native.list.recent`, after copy review; |
| 245 | - snapshot baselines: home and library (default, empty, no results), replacing `library*`, in light, dark, ar and ru. |
| 246 | |
| 247 | **Acceptance:** |
| 248 | - **Library model:** grouping and shelf tests in a fixed time zone; excerpt decoded. |
| 249 | - **Avatar menu:** the guards are unchanged (`OficinaIDAdoptionTests`, the team-picker-blocked snapshot). |
| 250 | - **Launch tests:** building the home body changes nothing it watches, and the home-loading test passes. |
| 251 | |
| 252 | ## S5: iPad, and polish |
| 253 | |
| 254 | Branch `native/ipad-and-polish`. Spec §5, §9, §11. |
| 255 | |
| 256 | **Work:** |
| 257 | 1. **Remove the iPad gate.** |
| 258 | - **Regular width:** the library in the Mac home's form; the document with the Mac header contract in the navigation bar, the floating inspector (with the centring rule in the text view's points), the Share popover and •••; `.commands` in the iPadOS 26 menu bar. |
| 259 | - **Compact width:** the iPhone layout. |
| 260 | 2. **Size-class transitions** keep the text view, selection, scroll and undo. The inspector and sheet hand-off is as specified. |
| 261 | 3. **Delete** the old iPad chrome (`EditorToolbar` and the `NavigationSplitView` path), now that nothing uses it. |
| 262 | 4. **A pass** over Dynamic Type, Reduce Motion, Reduce Transparency, Increase Contrast and RTL on every new screen. |
| 263 | 5. **iPad snapshot screens** (regular and compact, light, dark, ar, ru), and a full re-record review. |
| 264 | 6. **Update `native/PARITY.md` and `native/REVIEW.md`:** iPad's geometric pagination, its scenes and restoration, and what was verified on devices. |
| 265 | |
| 266 | **Acceptance:** |
| 267 | - **Size changes:** an iPad simulator test splits to compact and back with text selected. The selection and scroll survive, with no whole-document render. |
| 268 | - **Keyboard:** the hardware-keyboard shortcuts work through the menu bar. |
| 269 | - **Accessibility:** the audit passes at regular and compact. |
| 270 | - **Performance:** the §7 counters and targets still hold. |
| 271 | |