oficina / docs Public
Building and checking native Docs
The native editor uses SwiftUI with AppKit/UIKit text controls and a bounded WASM interpreter for the shared Yjs-compatible CRDT. It does not load a web editor.
Requirements: Xcode 26, XcodeGen, Swift 6.2+, Node/npm, and Rust with the wasm32-unknown-unknown, aarch64-apple-darwin, x86_64-apple-darwin, aarch64-apple-ios, aarch64-apple-ios-sim, and x86_64-apple-ios targets. The server gate additionally requires the Go version in go.mod.
Run the native gate from the repository root:
native/scripts/check-native.shIt builds the CRDT WASM, runs Rust editor and bounded-host tests (including opening and typing in a generated 200-page edited document on the host's production fuel budget; see fuel_budget in host/src/lib.rs), checks native and browser updates in both directions (including every list-rule reversal delta and its authoritative snapshot, the undo-kept garbage-collection repro of discussion #145, whose collected units must match Yjs's, and that each command's update carries only its own change, as the browser's per-transaction updates do), prepares the Apple XCFramework, and runs Swift adapter/actor tests. --core-only runs the Rust and wire checks on Linux. CI invokes this through .amadan/ci.d/20-native, alongside the existing server/web gate. --mutations additionally proves representative faulty changes are caught, restoring every changed source and saving logs under native/build/mutation-logs. Do not run mutations concurrently with builds.
native/scripts/test-iphone.sh runs the tests that need UIKit's text view (DocsPhoneTests in ios/project.yml: the editor render-loop regression of TestFlight 0.1.10 (12), and the redesign's S1a tests of DocumentSurface: the flush triggers, delta safety, the block index, block render equivalence, render isolation with §7's counters; their Mac half runs in swift test) in the iOS 27.0 simulator. It is not in CI, which has no simulator: run it before changing NativeDocumentTextView, DocumentSurface or the render.
§7's counters (DocsKit/DocsProbes.swift) compile under DOCS_PROBES: Package.swift defines it for debug builds, so swift test and test-iphone.sh hold the hard counters as gates (RenderIsolationTests); a release build, the one that ships, carries none of it. The timings are measured by native/benchmarks/realtime (its README), and the numbers are in native/benchmarks/README.md.
The apps bundle every font in Docs' shared list (internal/fonts/fonts.json): native/apple/Sources/DocsKit/Fonts is a copy of the manifest, each family's TTFs and its licence, made by native/scripts/sync-fonts.py. Rerun it whenever internal/fonts changes; the native gate runs it with --check, on Linux too, and fails on any drift. Git stores the identical files once. The apps register every face synchronously before their first window and draw each run from its bundled file, never from a copy of the same name installed on the machine.
CARGO can select a non-default Cargo executable; put its matching Rust toolchain on PATH. If that toolchain needs an explicit LLVM runtime lookup path, set DOCS_LLVM_LIBRARY_PATH. No generated native framework is committed.
Build individual applications:
native/scripts/build-mac.sh
native/scripts/build-iphone.sh simulator
OFICINA_DEVELOPMENT_TEAM=YOUR_TEAM native/scripts/build-iphone.sh deviceThe suite's build-native-apps.py prepares the native framework and Xcode projects once, then runs Docs and Sheets builds concurrently with separate platform logs and a combined results.json. Its default targets are Mac and iOS Simulator; --platforms mac simulator device also builds signed device applications when OFICINA_DEVELOPMENT_TEAM is set. It does not install or publish applications.
Native UI tests use fresh local credentials and isolated databases. See REVIEW.md for their runner, exact evidence, and untested behavior. Performance measurements and their limits are in benchmarks/README.md.
Oficina ID: entitlements, profiles and the launch check
Docs signs in with Oficina ID first (Home's docs/superpowers/specs/2026-11-14-oficina-id-native.md, slice A), through rastrillo/native's RastrilloApple/OficinaID kit. "Other ways to sign in…" keeps the server address and browser approval. The kit needs these grants on every build:
| Build | File | App group | | --- | --- | --- | | Mac, Sparkle (Developer ID) | macos/DeveloperID.entitlements, named by mac-updates.json | 9U4A84C4WK.works.oficina | | Mac App Store | macos/AppStore.entitlements | 9U4A84C4WK.works.oficina | | iPhone and iPad | ios/DocsPhone.entitlements | group.works.oficina |
All three have keychain-access-groups = 9U4A84C4WK.works.oficina.docs first, then 9U4A84C4WK.works.oficina.id (a query that names no group lands in the first, and Docs' own items must never land in the group every Oficina app reads), and webcredentials:id.oficina.works.
A Developer ID Mac app that claims these without an embedded provisioning profile is killed at launch. mac-updates.json names the profile by its local path, ~/private_keys/oficina/profiles/Oficina-Docs-macOS-Developer-ID.provisionprofile; the profile itself is never committed. Elsewhere, pass --provisioning-profile <path>, which wins over the configuration, to scripts/build-mac.sh and to rastrillo's release_mac.py. A signed build:
native/scripts/build-mac.sh --updates-config mac-updates.json \
--sign-identity 'Developer ID Application: Team Tito Limited (9U4A84C4WK)'An ad hoc build (no --sign-identity) drops those grants and says so on stderr. It still runs, but Oficina ID cannot read the keychain there (-34018), so Welcome says it couldn't be read. Simulator builds (CODE_SIGNING_ALLOWED=NO) are the same.
The launch check is the spec's launch gate (§13): before any Sparkle publish, run the final signed, notarised artifact's executable with --oficina-id-launch-check.
"native/build/Oficina Docs.app/Contents/MacOS/DocsMac" --oficina-id-launch-checkmacOS checks the embedded profile as the process starts. The check then reads the signed entitlements (the keychain groups in order, the App Group, the associated domain) and both keychain groups, prints counts (never an identity or a session) and exits 0 only if all of them work. An ad hoc build, or the unsigned test runner (OficinaIDAdoptionTests), fails every line.
With one Oficina ID on the device Docs goes straight in, with no screen (Paul, 2026-11-19; spec §9 "Straight in", rule 0); several ask which. While "Other ways to sign in…" is the route, nothing goes straight in: the home window suspends it at launch and on every route change (routeChanged, from .onChange(of: route)), and resumes it when the route is Oficina ID again. A signed-in session is never disturbed by either. The account menu (the Teams sheet, and Docs ▸ in the Mac menu bar) offers "Use another Oficina ID" only while signed in; the kit confirms (oficinaReplaceConfirmation, on the signed-in screen only), and Docs refuses, and says why, while a document window of the identity is open or its changes are unsent. Those are checked before the kit asks, and a document window of the identity opened while it asks withdraws the question.
Docs' session guards answer a write whose session has ended with 403 signed out (rastrillo's sessions.Require, and the identity guard for a native session past its seven days). DocsSessionWatch reads exactly those bytes as an ended session, re-mints it and surfaces a 401; every other 403 is a refusal of the request. internal/docs/native_contract_test.go pins the bytes on the server.
An Oficina ID team's offline store key is filed under one fixed origin, not the team's, so a team whose address changes (a label moved, a rename, self-hosting by DNS) keeps its store and unsent outbox. Docs refreshes the team list at launch, when the team picker opens (at most every five minutes) and on a 403, through the kit's refreshTeams. Signing out, switching team or replacing the Oficina ID waits for every team's outbox to drain, those a crash left on disk included, and on the Mac for every document window of the identity to close; the picker and Settings say which.
Sign-in itself needs Home's native endpoints at id.oficina.works and the directory at oficina.works; passkeys also need Home's association file. The kit's in-memory FakeOficinaIDService stands in for all of them in OficinaIDAdoptionTests and the screenshot gate.
The screenshot gate
native/scripts/snapshots.sh [compare|record] [mac|iphone|all] draws Docs' key screens (library, Oficina ID onboarding, Other ways to sign in, the team picker, Mac Settings) in light and dark, and on iPhone at AX3 too, and compares them with apple/Tests/DocsSnapshots/__Snapshots__/docs. The contact sheet is apple/.build/snapshots/docs/index.html.
The same run draws the editor's page from fixed fixtures (apple/Tests/DocsSnapshots/EditorSnapshots.swift, baselines in __Snapshots__/docs-editor and, for iPhone at AX3, docs-editor-ax3; sheets apple/.build/snapshots/docs-editor*/index.html). Each screen opens its document through DocsModel and NativeDocumentTextView on an in-memory server, and stays visibly unsettled until it is open, rendered, laid out and scrolled, so the kit never records it half drawn. Rendering work (the native redesign's S1) must leave these pictures unchanged; a screen that changes is re-recorded only with a reason in the branch's discussion.
It is not in .amadan/ci.d: baselines are exact only on the OS and simulator runtime that drew them (ENVIRONMENT beside them; today macOS 27.0.0, Xcode 27.2, and the iOS 27.0 runtime 24A434 on an iPhone 18 Pro). Hub CI builds the snapshot tests but skips them, since they need RASTRILLO_SNAPSHOTS. After an intended change, record, read the contact sheet, and push the pictures one commit per push with git -c http.postBuffer=209715200 push: without it the hub drops a pack over about 1 MB ("unexpected disconnect while reading sideband packet"), and pushes back to back trip its per-IP limit. Batch re-recordings: every one stays in the hub's history.
A screen that hangs the main thread never reaches the kit's own 3 s limit, so the script stops the Mac test run after SNAPSHOT_MAC_LIMIT seconds (default 300) and gives each iPhone test XCTest's 120 s allowance.
Enforcing it
Nothing but this procedure holds a branch to the gate, so:
- Every branch that can change rendering (the redesign's S1a, S1b and later, and any fix to the renderer) pastes the whole output of
native/scripts/snapshots.sh compare allinto its discussion before it asks for review. The script prints the environment each half drew on. - The reviewer re-runs it on their own checkout (about a minute a platform once built) and says so in the review.
- When the environment no longer matches the baselines (the script says "ENVIRONMENT DIFFERS": a macOS, Xcode or simulator runtime update), the failures are drift, not a regression, and can't be told apart from one. Re-record from
main, on a branch of its own whose only change is the baselines, have the contact sheet reviewed, and land it first. Never re-record on a rendering branch: that would bless whatever the branch changed along with the drift. - A rendering fix re-records only the screens it means to change, and its discussion names them.
Known rendering bugs in the baselines
The editor baselines are today's pixels, bugs included, so that rendering work can't fix (or break) them by accident. Each fix is its own branch and re-records only the screens it changes:
- Lists draw no bullet or number, on the Mac or iOS:
NSTextListis set and the items are indented, but no marker is drawn. - Arabic paragraphs are left-aligned:
NativeTextProjectionsets.left, not.natural. - iPhone and iPad width, paged: the text sits about 72 pt above where the page's top margin puts it, so it starts at the paper's top edge and stops well above the page's foot. A paragraph's lines can split across pages (iOS paginates by line).
- The page label differs: the Mac draws "Page 2" at the first break, iOS "Page 1" at the foot of page 1.
- iOS draws no bar beside a blockquote; the Mac does.
- In Mac light appearance the desk around the paper is as white as the paper, so only the dark pictures show the paper's edges and the bands between pages.