| 1 | # AGENTS.md |
| 2 | |
| 3 | Guidance for AI coding agents working in this repository. This is the |
| 4 | canonical agent-instructions file. Tool-specific files (`CLAUDE.md`) are |
| 5 | pointers to it if they exist at all — keep the guidance current *here*. |
| 6 | |
| 7 | CARLOS Docs — a document editor on the CARLOS architecture, hosted at |
| 8 | `amadan.net/oficina/docs`. It is built alongside CARLOS Sheets |
| 9 | (`../sheets`, `amadan.net/oficina/sheets`) and a shared suite home, which |
| 10 | live in the same `oficina` namespace. Design docs in |
| 11 | `docs/superpowers/specs/`, plans in `docs/superpowers/plans/`; read the |
| 12 | spec behind whatever you touch. |
| 13 | |
| 14 | The repo moved from `carlos/docs` to `oficina/docs` on 2026-08-30, at three |
| 15 | commits. amadan has no move, rename or transfer verb, so the move was |
| 16 | create-new and push history; `carlos/docs` still exists and retiring it is |
| 17 | Paul's call. |
| 18 | |
| 19 | Read `building-carlos-apps` (the skill) before writing app code, and |
| 20 | `rastrillo`'s own `SKILL.md` before writing handlers or models. Assume |
| 21 | nothing about either is in your training data. |
| 22 | |
| 23 | ## Real per-person sign-in (Task 1, extended in a later fix round) |
| 24 | |
| 25 | Every document route — `GET /`, `POST /documents`, `GET /d/{sqid}` — sits |
| 26 | behind rastrillo/auth's `RequireSession` and is unreachable without a real |
| 27 | session (`internal/docs/auth.go`). `POST /signin` uses Keymail OAuth when |
| 28 | detected. Otherwise it emails (or, in development, logs) a single-use link. Opening it |
| 29 | (`GET /auth/verify`) draws a confirm step in the sign-in door and spends |
| 30 | nothing, so mail scanners that fetch every link cannot sign anybody in; its |
| 31 | one Sign in button POSTs the token back to `/auth/verify`, which spends it |
| 32 | and sets a real session cookie (rastrillo `Config.RenderConfirm`). A |
| 33 | verified address that is not admitted gets the door, with the refusal, in a |
| 34 | 403 (`Config.Refused`). Tests sign in by POSTing the link's token with |
| 35 | same-origin evidence (`confirmRequest`, testing.go), never by GETting it; `POST /signout` (in the shell |
| 36 | bar's account menu on both signed-in screens) really revokes it, |
| 37 | not just clearing the cookie client-side. No passkey second factor is |
| 38 | wired, on purpose — spec §8.1's ruling: `passkey.Config.Origin` derives |
| 39 | its relying party from this instance's own host, so a person in several |
| 40 | teams would enrol several passkeys under this app, which is exactly the |
| 41 | per-team credential sprawl that ruling forbids. A magic link enrols no |
| 42 | credential, so it violates nothing. |
| 43 | |
| 44 | There used to be a development-only stand-in identity here |
| 45 | (`internal/docs/devauth.go`, turned on with `-dev-auth`, compiled out of a |
| 46 | release build with `-tags release`) for exactly the gap real sign-in has |
| 47 | now closed. It had zero readers the moment `RequireSession` started |
| 48 | guarding every route unconditionally — no handler ever consulted it — and |
| 49 | was deleted in a fix round on Task 1 rather than left as dead code and an |
| 50 | unreachable trap for whoever next assumed `-dev-auth` still did something. |
| 51 | The `release` build tag it was the only user of is gone with it; there is |
| 52 | no longer a release/non-release distinction anywhere in this app. |
| 53 | |
| 54 | `Config.Env` still exists (`"development"` or `"production"`), but it now |
| 55 | governs exactly one thing, independent of any identity flag: whether |
| 56 | `InstanceKey` and `Mailer` (`internal/docs/auth.go`) may default — an |
| 57 | empty `$DOCS_INSTANCE_KEY` or unconfigured mail is fine only in |
| 58 | development (a fixed dev key, and magic links logged instead of mailed, |
| 59 | clearly marked); anywhere else it is a startup refusal, the same |
| 60 | fail-closed shape `Origin` already used. `cmd/docs/main.go`'s `-env` flag |
| 61 | sets it; `$DOCS_ENV` is consulted too but can never select |
| 62 | `"development"` on its own (fix round 2 on Task 1 — platform instance |
| 63 | config *is* environment variables, so a bare `$DOCS_ENV=development` |
| 64 | sitting beside `$DOCS_ORIGIN`/`$DOCS_INSTANCE_KEY`/`$DOCS_SMTP_*` would |
| 65 | be a production-reachable path to the public dev `InstanceKey` and to |
| 66 | every magic link, token included, landing in the instance's own log — |
| 67 | see `chooseEnv`'s own doc comment). The default, with no flag and no |
| 68 | env var (or with `$DOCS_ENV=development` and no flag), is |
| 69 | `"production"` — `"development"` always takes an explicit `-env` |
| 70 | flag, never a silent fallback. |
| 71 | |
| 72 | ### Sign-in allowlist (Task 4 security fix, pre-launch) |
| 73 | |
| 74 | Real sign-in above closed "who can get a session" but left a separate |
| 75 | hole open: `rastrillo/auth`'s `Config.Authorize` — the admission gate — |
| 76 | is consulted only in its own callback handler, after `POST /signin` |
| 77 | (`Begin`) has already emailed the link. With `Authorize` left `nil` (as |
| 78 | it was through Task 3), that meant anyone who could reach the instance |
| 79 | could POST any address and get a working sign-in link mailed to it — |
| 80 | an open relay on our own SES sending identity, and unrestricted account |
| 81 | creation on an app whose whole premise is instance-per-team. Found by |
| 82 | the CARLOS Sheets session on their own deployed instance; every existing |
| 83 | test passed because they all tested admission, none tested delivery. |
| 84 | |
| 85 | The fix is `$DOCS_ALLOWED_ADDRESSES` (`docs.Config.AllowedAddresses`, |
| 86 | `internal/docs/auth.go`), a normalized allowlist checked by both |
| 87 | `rauth.Config.Authorize` and `admissionMailer`. The mailer suppresses delivery |
| 88 | for refused addresses and failed grant lookups. Classification and rate limits |
| 89 | run independently of admission, so an OAuth start does not disclose membership. |
| 90 | Refused email starts still receive `303 ?sent=1`; their expiring tokens are never |
| 91 | delivered. Callback authorization and per-request admission remain required. |
| 92 | |
| 93 | Detected Keymail addresses use OAuth, as §8.1 requires and Paul reaffirmed on |
| 94 | 2026-09-09. `force=1` remains an explicit email fallback. The OAuth start ends |
| 95 | with a `200` continuation page (meta refresh plus link), preserving the pending |
| 96 | cookie and the existing CSP: Safari enforces `form-action` across redirects. |
| 97 | Never widen that directive to arbitrary Keymail hosts. Account linking still |
| 98 | requires a fresh provider `AuthTime`; an ordinary OAuth session is not enough. |
| 99 | |
| 100 | Empty is allowed only in development (admits everyone, so `TestSignIn` |
| 101 | and `run-dev.sh` need no setup); anywhere else it is a startup refusal, |
| 102 | the same fail-closed shape `Origin`/`InstanceKey`/`Mailer` already use, |
| 103 | chosen over silently admitting nobody because a silently-empty allowlist |
| 104 | would boot looking identical to a working instance. |
| 105 | |
| 106 | ### Suite consumers (`$DOCS_SUITE_CONSUMERS`, spec §8.2.2) |
| 107 | |
| 108 | The siblings allowed to call Docs' suite routes (memoria, today). Strict |
| 109 | JSON, one entry per consumer, one or two tokens each (two only while a |
| 110 | token is being rotated): |
| 111 | |
| 112 | [{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"<64 hex>"}]}] |
| 113 | |
| 114 | `sha256` is the hex SHA-256 of the bearer token the operator minted for |
| 115 | that consumer — `server.TokenHash(token)` in `amadan.net/oficina/suite/server` |
| 116 | — never the token itself. Unset or empty: no consumers, and `/suite/*` |
| 117 | answers 404 like any unknown path. Anything malformed (not a list, an |
| 118 | empty list, `null`, an unknown field, a non-hex or wrong-length hash, a |
| 119 | repeated or empty `consumer_id`, three tokens) refuses boot. |
| 120 | |
| 121 | ## The suite producer: invariants (spec §8.2.2) |
| 122 | |
| 123 | Docs serves suite S1/S2/S3 to memoria and holds every live document to the |
| 124 | suite revision 10 rules. Break one of these and memoria can show somebody a |
| 125 | document they may no longer read; the reasoning and the review history are |
| 126 | in spec §8.2.2. |
| 127 | |
| 128 | - **Every write that changes what S3 serves moves the revision in the same |
| 129 | transaction**: call `bumpRevision` (`internal/docs/suite_feed.go`) inside |
| 130 | the transaction that makes the change — content, title, visibility, |
| 131 | deletion, and anything new that changes the title or the text. It draws a |
| 132 | new random revision and writes the `suite_feed` row; if either fails the |
| 133 | change must not commit. Creation goes through `createDocument`. |
| 134 | - **Any delete verb goes through `softDelete`** (suite_feed.go): the |
| 135 | person's way is `Store.Delete` (delete.go, behind the owner's guard), the |
| 136 | tests' is `Store.deleteDocument`. It announces the document gone; a delete |
| 137 | that only sets `deleted_at` leaves memoria holding it. |
| 138 | - **Revisions and feed nonces come only from `randomSource`** |
| 139 | (`crypto/rand`). A failed read is an error that stops the change; never |
| 140 | fall back to a clock, a counter or `math/rand`, which a restore or |
| 141 | anybody else can reproduce. Revisions have no order: S2's `STALE` is read |
| 142 | from `suite_feed`, never from comparing numbers. |
| 143 | - **S2 never caches** — not an answer, not a person's standing, not across |
| 144 | pairs of one call. Team standing is asked again after the last database |
| 145 | read (`suiteProducer.Rule`). |
| 146 | - **Exactly three suite routes sit on the outer mux** (`mountSuite`): |
| 147 | `GET /suite/s1`, `POST /suite/s2`, `GET /suite/s3/{item}`, outside the |
| 148 | session, admission and `homeCSRF` layers. Never a prefix, and nothing |
| 149 | else outside the router. |
| 150 | |
| 151 | ## Running it locally |
| 152 | |
| 153 | `./scripts/run-dev.sh` builds and runs the app in one command: `-env |
| 154 | development`, a fixed port (`localhost:8099`, override with |
| 155 | `$DOCS_DEV_PORT`), and a scratch SQLite database that starts empty every |
| 156 | run. It prints the URL to open, and signing in there gets a real session |
| 157 | via a magic link logged to the terminal instead of mailed — the same flow |
| 158 | a real deployment uses, just not actually delivered anywhere. |
| 159 | |
| 160 | **Origin is not optional in anything but development — but know what it |
| 161 | actually guards.** rastrillo v0.21.0's `csrf.Protect` checks |
| 162 | `Sec-Fetch-Site` *first*, when a browser sends it — which every current |
| 163 | browser does on a state-changing request. `same-origin`/`none` pass |
| 164 | immediately, anything else is refused immediately, and `Config.Origin` is |
| 165 | never read in that path at all. Only when `Sec-Fetch-Site` is entirely |
| 166 | absent (a legacy browser, or a non-browser client like curl) does the |
| 167 | check fall back to comparing `Origin`/`Referer` against `Config.Origin` |
| 168 | exactly. So a wrong `Config.Origin` does not make a real browser's genuine |
| 169 | same-origin request fail, and it does not open up a genuine cross-site |
| 170 | request either — both are decided by `Sec-Fetch-Site` alone. What it |
| 171 | actually breaks is the legacy fallback path, silently: a misconfigured |
| 172 | origin will not show up as "the app looks broken" in ordinary manual |
| 173 | testing with a real browser, which is exactly why it still needs to be |
| 174 | right rather than merely untested. `cmd/docs/main.go` reads `$DOCS_ORIGIN` |
| 175 | (the real per-instance origin belongs there — spec §9.2's |
| 176 | `<team>.docs.oficina.works`) and falls back to deriving one from `-addr` |
| 177 | only for local/dev use; with neither set, or with a value that cannot |
| 178 | parse as an absolute `http(s)://host[:port]`, `internal/docs.New` refuses |
| 179 | to start rather than silently defaulting or booting on something |
| 180 | malformed. `run-dev.sh` never needs `$DOCS_ORIGIN` set by hand — its fixed |
| 181 | `-addr` derives it. |
| 182 | |
| 183 | ## Review by the highest available capability model (Paul's rule, 2026-08-30) |
| 184 | |
| 185 | **Specs and whole branches are reviewed by the highest capability model |
| 186 | available at the time.** Today that is **Fable** (`claude-fable-5`). The |
| 187 | rule is "the highest available", not "Fable" — when a more capable model |
| 188 | ships, the rule follows it up the ladder without an edit here. |
| 189 | |
| 190 | Two things get that review, and they are the two where a mistake is |
| 191 | expensive to unwind: |
| 192 | |
| 193 | - **A spec, before it becomes a plan.** A spec is the document every |
| 194 | later decision inherits from. Reviewing it after implementation means |
| 195 | reviewing the code's rationalisation of it. |
| 196 | - **A branch, before it squash-merges to `main`.** Read as a single |
| 197 | diff, not commit by commit — that is the one reading that catches a |
| 198 | branch which is individually-sensible commits adding up to the wrong |
| 199 | thing. |
| 200 | |
| 201 | Name the model explicitly when dispatching a review. An omitted model |
| 202 | silently inherits the session's, which is how a review quietly happens on |
| 203 | a weaker model than the rule requires. |
| 204 | |
| 205 | The rest of the delegation ladder, unchanged from the family's policy: |
| 206 | |
| 207 | - **Haiku** — transcription-grade work: the plan contains the exact code, |
| 208 | single-file mechanical fixes, doc edits. |
| 209 | - **Sonnet** — implementation from a precise brief: 1–3 files, clear |
| 210 | interfaces, established conventions to follow. |
| 211 | - **Opus** — design judgment, multi-file integration, anything security- |
| 212 | or production-touching. |
| 213 | - **Fable** — spec review, whole-branch review, and implementation whose |
| 214 | correctness rests on several interacting invariants at once. It burns |
| 215 | usage budget fastest; never spend it where a precise Sonnet brief plus |
| 216 | an Opus review already fits. |
| 217 | |
| 218 | A precise brief beats a capable model. Exact values, file paths and |
| 219 | interfaces go in the brief. |
| 220 | |
| 221 | ## Shipping cadence (Paul's rule, 2026-08-30) |
| 222 | |
| 223 | **Work happens on a worktree, on a branch. Never on `main`.** |
| 224 | |
| 225 | 1. **Worktree per piece of work.** `git worktree add` (or the harness's |
| 226 | worktree isolation) so `main` stays clean and two pieces of work never |
| 227 | share a checkout. The branch is created with the worktree, not after. |
| 228 | 2. **Push regular commits to the branch.** Commit as you go and push |
| 229 | often — small commits, pushed, so the work is visible, recoverable, |
| 230 | and reviewable as a sequence. Do not sit on a large uncommitted |
| 231 | working tree, and do not squash locally as you go; the branch's |
| 232 | history is the record of how the work happened. |
| 233 | 3. **Squash merge to `main` when, and only when, all three are true:** |
| 234 | - the work is **done** — not "done except", not "done pending a |
| 235 | follow-up commit"; |
| 236 | - it is **approved** — the branch has had its highest-capability-model |
| 237 | review above, and Paul has approved anything that was his call; |
| 238 | - **CI is green** — `amadan ci status -branch <n>` exits 0. Exit 2 is |
| 239 | pending, not green. Exit 3 means nothing has run, which is not green |
| 240 | either. |
| 241 | |
| 242 | Nothing reaches `main` any other way: no direct commit, no local |
| 243 | fast-forward, no "it's only a docs change". That includes doc-only edits, |
| 244 | one-line fixes, and reverts. |
| 245 | |
| 246 | The reason is timing rather than ceremony. A change merged locally still |
| 247 | faces the same gates, but only *after* it is on `main`, where a red run is |
| 248 | an incident to clean up instead of a merge that simply does not happen. |
| 249 | |
| 250 | **The review record lives on amadan.** The pull-request equivalent is a |
| 251 | branch discussion — see below. **CI is `.amadan/ci.d/10-gate`**, triggered |
| 252 | by a push to the remote, and it is the same script you can run locally. It |
| 253 | covers the Rust crate, the wasm artifact, Yjs wire compatibility in both |
| 254 | directions, and the Go build and tests. When you change anything under |
| 255 | `core/`, run `./scripts/build-wasm.sh`, copy the module into |
| 256 | `internal/core/testdata/` and commit it with its `.stamp`; the gate checks |
| 257 | that stamp on every host (`.amadan/README.md` explains why). `amadan ci status -branch <n>` |
| 258 | exit 0 is the merge gate; exit 2 is pending and exit 3 means nothing ran, |
| 259 | and neither is green. |
| 260 | |
| 261 | **Finishing a branch is always the same two steps, in this order** (Paul's |
| 262 | rule, 2026-08-30): **push and open the branch discussion, then squash-merge |
| 263 | to `main`.** Never merge without the discussion existing first, and never |
| 264 | merge locally instead of pushing. |
| 265 | |
| 266 | The order is the point rather than the ceremony. A squash merge deliberately |
| 267 | flattens the commit history that carried the branch's reasoning — the |
| 268 | rulings, the reversals, the things that turned out to be wrong twice. The |
| 269 | discussion is where that survives. If it does not exist before the merge, |
| 270 | the reasoning is not scattered, it is gone. |
| 271 | |
| 272 | ## Working through amadan |
| 273 | |
| 274 | This repo is hosted on an amadan hub (`AMADAN_HUB=https://amadan.net`), |
| 275 | not GitHub. There is no `gh`, no pull request, and no GitHub Actions. The |
| 276 | full house rules are installed as a skill at |
| 277 | `.claude/skills/amadan/SKILL.md` — read it. What follows is what this repo |
| 278 | does with them. |
| 279 | |
| 280 | **Post as the agent account, never as Paul.** An agent account is |
| 281 | `<name>~<operator keymail>`; everything it writes is badged and |
| 282 | attributable. The CLI detects a harness and refuses a human credential. |
| 283 | `-as-human` exists for a person genuinely typing, and it warns every time |
| 284 | — an agent reaching for it is the antipattern the badge exists to prevent. |
| 285 | |
| 286 | **The prompt ledger is on, at `prompts` level.** `amadan ledger init` has |
| 287 | installed the post-commit hook, the Claude Code hooks in |
| 288 | `.claude/settings.json`, and the ledger refspecs, so prompts record to |
| 289 | `refs/amadan/ledger/<branch>` with nothing to do per commit. Two |
| 290 | consequences worth knowing: |
| 291 | |
| 292 | - **A bare `git push` now pushes HEAD *and* the ledger refs**, because |
| 293 | `remote.origin.push` is set and `push.default` no longer applies. |
| 294 | - **Never edit ledger refs by hand.** `amadan ledger redact` and |
| 295 | `amadan ledger withhold` are the only sanctioned removals, and both |
| 296 | leave a visible mark. That is the point of them. |
| 297 | |
| 298 | **Every branch gets a discussion, and it is the review record.** |
| 299 | `amadan discuss new <ns>/docs -branch <n>` opens it; that thread is where |
| 300 | the branch is read as one piece, where the highest-capability-model review |
| 301 | is posted, and where approval is recorded. One thread per topic — reply on |
| 302 | it rather than opening a sibling. Branch discussions belong to the branch; |
| 303 | repo-level ones are for anything wider. Close what you opened. |
| 304 | |
| 305 | **Tasks are a checklist, not a log.** `amadan task add -branch <n>` for |
| 306 | work someone will do, `amadan task advance` when it is done. Commentary |
| 307 | belongs in the discussion, not in task titles. A branch with real work on |
| 308 | it should have tasks that a reader can scan to see what is left. |
| 309 | |
| 310 | **Rebuilding the editor bundle is not hand-mergeable** (branch |
| 311 | convention, agreed 2026-08-31 between the three sessions then working in |
| 312 | this repo). `internal/docs/static/editor.<hash>.js` is a single |
| 313 | committed artifact whose name is the hash of its own contents, and |
| 314 | `assets.go` panics at init if it finds more or fewer than one. Two |
| 315 | branches that both ran `fixtures/build-bundles.mjs` therefore conflict |
| 316 | mechanically even when no source line overlaps. Whoever squash-merges |
| 317 | second discards their own bundle from the merge and re-runs the build on |
| 318 | top of `main`. Never reconcile the minified file by hand. |
| 319 | |
| 320 | **When something is refused, say so in the discussion rather than working |
| 321 | around it.** An `agent` grant is writer-equivalent within one namespace: |
| 322 | push, post, manage tasks, nothing beyond. Refusals are usually a missing |
| 323 | grant or a genuine boundary, and both are worth surfacing rather than |
| 324 | routing around. |
| 325 | |
| 326 | ## Working with the sibling sessions |
| 327 | |
| 328 | Docs is one of three moving parts and the other two are live: |
| 329 | |
| 330 | - **`../sheets`** (`amadan.net/oficina/sheets`) — shares the suite home, |
| 331 | the design-system primitives, and several rulings. Its spec is |
| 332 | `docs/superpowers/specs/2026-08-30-sheets-design.md`. Docs is a |
| 333 | declared consumer of the home contract in its §9. |
| 334 | - **The design system** — `rastrillo.org/design-system`, spec at |
| 335 | `docs/superpowers/specs/2026-08-28-design-system-design.md` in the |
| 336 | rastrillo repo. Vendor tokens through `ui.TokensCSS()` and |
| 337 | `ui.ThemeCSS(name)` rather than copying files by hand. |
| 338 | |
| 339 | When a decision affects one of them, tell that session rather than |
| 340 | writing around it. Several of this project's better decisions came from |
| 341 | one session's question exposing another's bug. |
| 342 | |
| 343 | ## Conventions that are already settled |
| 344 | |
| 345 | - **Markup uses the bare `rst-*` attribute grammar** (`<div rst-inspector>`), |
| 346 | variants in the value matched with `~=`. Unparked by Paul 2026-08-31, once |
| 347 | both of his conditions were met and verified: `rastrillo v0.21.0` styles |
| 348 | **both** spellings (`ui/tokens.css` carries 343 bare-attribute selectors |
| 349 | alongside 398 class ones), and the design-system guidance exists. |
| 350 | Two constraints come with it. **Adopt per screen, not per element** — |
| 351 | mixed authoring inside one component matches neither spelling by design. |
| 352 | And **pin `v0.21.0` or later**, because on anything earlier attributes |
| 353 | render unstyled. |
| 354 | *(This reversed twice before landing here, both times by applying a |
| 355 | conclusion drawn about one repo to a different one without re-deriving it. |
| 356 | The reasoning is in spec §10.1.1.)* |
| 357 | - **Anything Docs contributes to estilo takes an `estilo-*` prefix, never |
| 358 | `rst-*`.** That namespace is the framework's and a future version may claim |
| 359 | a name we took — rastrillo's own migration found `rst-form__foot` and |
| 360 | `rst-form-foot` both live inside `ui`. |
| 361 | |
| 362 | - **A spec ruling, code on `main`, and code in the latest release are three |
| 363 | different things.** Reading one tells you nothing about the other two. |
| 364 | `v0.19.0` (2026-08-24) is 18 commits behind rastrillo's `main` and lacks |
| 365 | the themes, shells and locales the design-system spec describes, so |
| 366 | `go get` alone will not give you them. Say which of the three you mean |
| 367 | whenever you cite the framework, and stamp any commit count with the sha |
| 368 | and date you took it at — a bare number ages into a wrong fact. |
| 369 | |
| 370 | ### Watch for tools that answer wrongly instead of failing |
| 371 | |
| 372 | A tool that errors teaches you something. A tool that returns a confident |
| 373 | wrong answer does not, and both of the ones below cost this project real |
| 374 | time in a single afternoon: |
| 375 | |
| 376 | - **Citing your working tree instead of `origin/main`.** A checkout parked |
| 377 | on a feature branch gives you *true statements about the wrong tree*, |
| 378 | complete with real line numbers that verify. Cite `origin/main` after a |
| 379 | fetch, or a tag, and say which. Never your checkout. |
| 380 | - **`git branch --merged` against a squash-merging repo.** It returns an |
| 381 | empty list that reads as "never merged" while `main` carries every line, |
| 382 | because a squashed branch is not an ancestor. Compare content, not |
| 383 | ancestry. |
| 384 | - **`carlos channels` after a promote.** It reports which release a |
| 385 | channel *points at*, which is not the same question as which release |
| 386 | the box is *serving*. Adoption runs on an hourly timer, so the two can |
| 387 | disagree for up to an hour after `carlos promote`: observed |
| 388 | 2026-09-01, `edge` reading the new version while the live host served |
| 389 | the previous one for five minutes straight, closed within seconds by |
| 390 | `carlos restart`. Neither command fails and nothing says "not live |
| 391 | yet". Trust `x-carlos-version` on the real host, or use `carlos |
| 392 | deploy`, which ships, promotes and then watches the URL until it |
| 393 | actually serves the new version. `carlos channels` cannot distinguish |
| 394 | "serving it" from "pointed at it". |
| 395 | *(Recorded from the live-sync deploy; not re-verified since, so the |
| 396 | timer's exact behaviour is one observation rather than a measurement.)* |
| 397 | - **Ship with `--mail submit`.** It declares that the build sends through |
| 398 | CARLOS mail submission (`mail.FromCarlos`, `platformMailer` in |
| 399 | `cmd/docs`, From `$DOCS_MAIL_FROM`). Until `carlos email submission on |
| 400 | --app docs` runs Docs keeps sending over `DOCS_SMTP_*`; after it the |
| 401 | agent sets `CARLOS_MAIL=submit`, Docs holds no SMTP credential, and |
| 402 | every instance must run a build shipped with the flag. `carlos deploy` |
| 403 | has no `--mail` flag yet (carlos main 9eec0236), so until it does use |
| 404 | `carlos ship --app docs --mail submit <binary>`, then `carlos promote` |
| 405 | (or `carlos deploy --mail submit` once that ships), and check |
| 406 | `x-carlos-version` on the real host as above. |
| 407 | |
| 408 | - **A library function that ignores its own "dry run" argument.** |
| 409 | `y-prosemirror`'s exported `undo` is `state => ...undoManager?.undo()` |
| 410 | — it takes no `dispatch` and undoes immediately. ProseMirror's command |
| 411 | contract says a null `dispatch` performs nothing and only reports |
| 412 | whether it could, which is how any toolbar decides whether to grey a |
| 413 | button out — on every state update, because that is when the answer |
| 414 | changes. So the formatting bar asked "could I undo?" after every |
| 415 | change and the library answered by undoing it: typing did nothing, |
| 416 | every command did nothing, no error anywhere, Go suite green. |
| 417 | (`undoCommand`/`redoCommand` are the dispatch-aware pair.) The general |
| 418 | form: **a convention is not a guarantee**, and the functions that break |
| 419 | one are the ones that look most like they honour it. Found 2026-09-01 |
| 420 | on the formatting-and-export branch, by a browser drive, after an |
| 421 | evening of looking at the wrong file. |
| 422 | |
| 423 | The shape to watch for is a verification that cannot distinguish "no" from |
| 424 | "I can't see it". When you catch one, write it here rather than resolving |
| 425 | to be more careful — care is not a mechanism. |
| 426 | |
| 427 | **A new test must be seen to fail.** Corollary of the above, and cheap: |
| 428 | after writing one, break the thing it covers and watch it go red, then |
| 429 | put it back. `scripts/browser-drive.sh` was kept only after it was |
| 430 | confirmed to fail on the build whose bug it had just found — without |
| 431 | that step a green run means "passed" and "could not see" equally. |
| 432 | |
| 433 | **And it must fail for the right reason.** Watching it go red is not |
| 434 | enough — read *why* it went red. Three of these were found in one |
| 435 | evening on the `list-thumbnails` branch, in three different shapes: |
| 436 | |
| 437 | - A test that could not fail at all. `TestPageOneDoesNotDisturbPDFExport` |
| 438 | exported a document, ran the thumbnail layout, exported again and |
| 439 | compared bytes — but the two calls share no state, so only a |
| 440 | package-level global could ever have reddened it. It stayed green |
| 441 | while a deliberate `l.cursor += 100` inside the code it claimed to |
| 442 | guard reddened a different test. Two comments and a commit message |
| 443 | cited it as proof. Deleted. |
| 444 | - A mutation that reddened the right test for the wrong reason. Proving |
| 445 | a canary test could fail, the injected leak used a template variable |
| 446 | that was not in scope, so the page 500ed and the test failed on its |
| 447 | status check without the canary ever firing — a red test proving |
| 448 | nothing. Redone with a leak that actually renders. **If your mutation |
| 449 | changes the response code, you have tested the mutation, not the |
| 450 | test.** |
| 451 | - A hit test that measured something else. Recorded in `list.html`: |
| 452 | restated declarations "fixed" row clicking, and the probe was hitting |
| 453 | rastrillo's own overlay both before and after. |
| 454 | |
| 455 | The generalisation, and the question worth asking of any gate: **what |
| 456 | would make this go red, and have I actually done it?** A CSS rule keyed |
| 457 | on an attribute nothing writes is the same defect in another costume — |
| 458 | it matches no element, so it is invisible to every test and every |
| 459 | screenshot, and any bug inside it is unreachable. The Sheets session |
| 460 | found one of those the same night, hiding a second defect behind it. |
| 461 | Worth a grep when touching a stylesheet; not worth a permanent gate, |
| 462 | because it has enough false positives (comments quoting old selectors, |
| 463 | framework-emitted hooks) that people would learn to skim it — and a |
| 464 | gate nobody reads is another probe that answers the same in both |
| 465 | worlds. |
| 466 | |
| 467 | **Do not pass on somebody else's finding as your own verification.** A |
| 468 | report from another session is evidence about what they saw, not a fact |
| 469 | you have checked, and relaying it flatly launders it into one. Say where |
| 470 | it came from, or check it — and note that "two of us noticed |
| 471 | independently" is not corroboration when the second of you is the one |
| 472 | who mentioned it first. (Written after exactly that: a merge commit on |
| 473 | `main` was reported here as a breach of the shipping cadence and passed |
| 474 | on to Paul as one, when `amadan branch merge` produces a merge commit |
| 475 | itself and the branch had landed correctly. One minute with the tool |
| 476 | would have caught it.) |
| 477 | - **rastrillo is `amadan.net/rastrillo/rastrillo`.** The old path, |
| 478 | `github.com/carlosframework/rastrillo`, stops at v0.23.0: code importing |
| 479 | it gets no fix, and its own checks cannot tell (Docs zoomed iOS on every |
| 480 | tap for a month that way). `TestNoPreMoveRastrillo` (internal/lint) |
| 481 | allows one import of it, native.go's bridge to rastrillo/native's |
| 482 | server, until that server moves. The CLI is pinned as a `tool` in |
| 483 | go.mod: run it as `go tool rastrillo …`, never a `rastrillo` from PATH. |
| 484 | `scripts/build-release.sh` stamps `amadan.net/rastrillo/rastrillo.BuildVersion`; |
| 485 | the old symbol leaves `/api/version` answering "dev" |
| 486 | (`TestReleaseBinaryReportsItsVersion`). |
| 487 | - **Docs serves rastrillo's and estilo's assets from memory** |
| 488 | (render.go's `vendoredStaticFS`), so `go tool rastrillo doctor` finds |
| 489 | nothing vendored to check. If a future `doctor --fix` ever writes a |
| 490 | rastrillo.js, busy.js or tokens.css to disk, delete it: doctor's shim |
| 491 | carries the old busy rule, which fights estilo's busy.js. |
| 492 | `TestBusyRuleIsLinkedAndServed` fails if one is left behind. |
| 493 | - **iOS zooms into any text control under 16px.** tokens.css lifts |
| 494 | controls to 16px under `(pointer: coarse)`; a Docs rule that sets a |
| 495 | control's font with a heavier selector must restate |
| 496 | `font-size: max(1rem, 1em)` there too. `TestNoZoomOnTap` (browser tag: |
| 497 | `go test -tags browser -run OnTap ./internal/docs/`, needs a Chromium via |
| 498 | `RASTRILLO_CHROME` or a Playwright cache) measures every field. |
| 499 | - **Re-copy `tokens.css` deliberately on every rastrillo upgrade.** It is |
| 500 | frozen into `static/` at scaffold time while the partials upgrade with the |
| 501 | module. `rastrillo doctor` will make this mechanical; until it lands it is |
| 502 | a manual step in the upgrade runbook. |
| 503 | - **A save is a keepalive request, at most 32KiB, and gzipped from 1KB** |
| 504 | (`fixtures/save-queue.mjs`; Paul's "Trouble saving" in Safari, |
| 505 | 2026-10-26, #94). While a link the page opened is waiting for its answer, |
| 506 | WebKit refuses every ordinary `fetch`, XHR and Blob read the page starts, |
| 507 | at once and with nothing sent, and the page stays editable all the while; |
| 508 | keepalive requests and `sendBeacon` still go. Keepalive requests and |
| 509 | beacons share one 64KiB quota, so the unload beacon never repeats a |
| 510 | keepalive save already on the wire. WebKit never settles a keepalive save |
| 511 | answered while its page is in the back/forward cache, so the queue sends |
| 512 | again on `pageshow` and gives up on a save left unanswered. A save |
| 513 | refused with no answer is "Trouble saving" only if a probe of `/healthz` |
| 514 | cannot reach the server either, and quiet retries back off to 4s. |
| 515 | Compress through `CompressionStream`'s writer, never a Blob. A gzipped |
| 516 | save answered 400, 415 or 422 (a server that does not gunzip: a rollback, |
| 517 | or a hop that strips `Content-Encoding`) is sent again uncompressed, and |
| 518 | the page stops gzipping, before the queue, which drops a batch a 4xx |
| 519 | answers, sees it. Corrupt gzip is a 400 in Docs and Slides alike. An edit |
| 520 | still too large for a keepalive request waits, silently, for the link to |
| 521 | be answered. |
| 522 | - **Docs drains its live streams on SIGTERM** (`cmd/docs/main.go`, |
| 523 | `app.Drain`). `net/http`'s graceful shutdown cancels no request, so an |
| 524 | open editor's stream held it for rastrillo's whole ten seconds and the |
| 525 | process exited 1 (the platform's stop of every instance, 2026-10-26 |
| 526 | 12:49). `rastrillo.Serve` owns the signal and has no hook, so Docs |
| 527 | registers its own: every `signal.Notify` channel receives it. Any new |
| 528 | long-lived handler must also return on `hub.draining()`. |
| 529 | - **Every user-visible string is a catalog key**, resolved at render time. |
| 530 | Twelve base locales; a hardcoded English string is a bug. |
| 531 | - **WCAG 2.2 AA, no exemptions**: 24×24 targets, 320px reflow, and colour |
| 532 | never carries meaning alone. |
| 533 | - **An ARIA role is a promise about behaviour, and an unimplemented one |
| 534 | is worse than none.** `role="toolbar"` says "this is a single tab stop |
| 535 | and the arrow keys move within it". Written without the roving |
| 536 | tabindex behind it — as the formatting bar was, on this branch, until |
| 537 | it was caught in review — it tells a screen-reader user that arrow |
| 538 | keys are the way in, so those are what they try first, and the silence |
| 539 | that follows reads as their own mistake rather than as a missing |
| 540 | feature. Omitting the role would have been more honest and less |
| 541 | harmful. Whenever you write a role, implement its keyboard contract in |
| 542 | the same commit or do not write it. |
| 543 | Two things that pattern hides, both found the same way: |
| 544 | **a roving tab stop parked on a `disabled` control makes the whole |
| 545 | group unreachable**, not merely awkward, and disabled is often the |
| 546 | *default* state (undo and redo start that way on every page load) — so |
| 547 | the "which control is the tab stop" decision has to re-run whenever |
| 548 | anything is enabled or disabled, not on load. And **a closed native |
| 549 | `<select>` changes its own value on Left/Right**, so a toolbar |
| 550 | containing one must consume those keys and leave Up/Down alone. |
| 551 | Neither is in the ARIA practices; both are unmissable in a browser and |
| 552 | invisible in a unit test, which is what `scripts/browser-drive.sh` is |
| 553 | for. |
| 554 | |
| 555 | ## Fonts: one manifest, and never a flash (Paul, 2026-10-24) |
| 556 | |
| 557 | The default font is **Carlito** ("it kind of has to be Carlito": Calibri's |
| 558 | metrics, so documents break lines in Word as they do here). **There is |
| 559 | never a flash of unstyled text, ever**, and that includes a visible gap of |
| 560 | invisible text. The font menu shows each font in its own face. The design |
| 561 | is `polish-audit/fonts/NO-FOUT.md`; this is how it is built. |
| 562 | |
| 563 | - **`internal/fonts/fonts.json` is the vocabulary.** It holds sixteen |
| 564 | families in picker order, with each key (mark `font_<key>`), name, Word |
| 565 | name and fallback. internal/fonts embeds it and `fixtures/fonts.mjs` |
| 566 | imports it. `core/tests/fragment.rs` holds MARKS to it through |
| 567 | `families.bin`. `sans`, `serif` and `mono` are Liberation, for ever. To |
| 568 | add a family, add a manifest entry and a MARKS row, rerun the vendoring |
| 569 | and the two generators below, then regenerate the fragment vectors. |
| 570 | - **Files come from `scripts/vendor-fonts.py`** (fontTools, outside the |
| 571 | repo's Python), using `sources.json` and `files/SOURCES.lock`. |
| 572 | `--check` rebuilds everything into a scratch copy and fails unless every |
| 573 | file is byte-identical, so run it after any change. The script forces |
| 574 | fontTools' own GSUB/GPOS serialiser: with uharfbuzz importable, |
| 575 | fontTools uses HarfBuzz's repacker instead, and 52 files come out |
| 576 | different. A family whose licence reserves its name is its authors' |
| 577 | static files, unchanged. Each style is a TTF (PDF and Mac) plus a |
| 578 | lossless woff2 of it (browser). The picker previews are renamed subsets. |
| 579 | - **The PDF shapes with go-text/typesetting**, pinned past v0.3.5, which |
| 580 | applied none of Inter's kerning. `TestShapingMatchesHarfBuzz` holds it |
| 581 | to HarfBuzz's own advances (`scripts/harfbuzz-golden.py`); rerun that |
| 582 | script whenever the fonts change. |
| 583 | - **No web face without the gate.** The stylesheet's own rules are the |
| 584 | system faces, and the web faces apply only under |
| 585 | `<html data-docs-faces="web">`. So a reader without JavaScript, or one |
| 586 | whose script never arrived, gets the system faces for the whole visit, |
| 587 | with nothing held, fetched for the text, or swapped. |
| 588 | - **The hold.** `fixtures/fonts-hold.js` is a plain blocking script in |
| 589 | `<head>`. It sets `data-docs-fonts="pending"`, which hides the sheet, |
| 590 | and `data-docs-previews="pending"`, which hides the font control, and |
| 591 | arms a 6 s fail-safe that shows the page as it stands. The server never |
| 592 | renders the hold. |
| 593 | - **The gate**, `fixtures/fonts-gate.mjs`: |
| 594 | 1. Waits for every style of every family `export.FamiliesUsed` lists, up |
| 595 | to 2.5 s, and commits each family still missing one. Nothing is on |
| 596 | screen yet, so nothing moves. |
| 597 | 2. Turns the web faces on. |
| 598 | 3. On a paged editor page, waits up to 3.5 s for the editor to |
| 599 | paginate; past that it freezes the layout for the visit |
| 600 | (`data-docs-layout="frozen"`). |
| 601 | 4. Shows the sheet, once. |
| 602 | |
| 603 | The previews have their own state and never hold the paper. |
| 604 | - **After the reveal, a family on screen is never committed. A wait for a |
| 605 | font is a short modal.** Every local change passes one check, |
| 606 | `fontGatePlugin` in `fixtures/editor-entry.js`, a ProseMirror |
| 607 | transaction filter. A user action (typing, paste, drop, input rule, |
| 608 | command, font pick, code toggle, undo, redo) that would put text in a |
| 609 | family whose faces have not all loaded is cancelled before anything |
| 610 | changes. The editor, the formatting bar and the menu bar go `inert`, |
| 611 | and the status strip over the formatting bar (`[docs-fonts-status]`, |
| 612 | `fixtures/font-status.mjs`, a polite live region) says a font is |
| 613 | loading, at once. When the family is in, the original action is |
| 614 | performed once. Input during the wait goes nowhere: nothing is queued |
| 615 | or replayed (review 7 showed a replayed key is not the key), and other |
| 616 | controls (the title, dialogs, comments) keep their input; focus comes |
| 617 | back to the document only if it was there and nobody moved it. With |
| 618 | the editor inert, focus is on the page, so Backspace, Space, the |
| 619 | arrows, Page Up/Down, Home and End are held there during the wait |
| 620 | (WebKit's Backspace went back in history and lost the action), and |
| 621 | leaving the page asks first (`beforeunload`). A |
| 622 | family that fails or misses the three-second deadline drops the action |
| 623 | and says so. One wait at a time: anything else that would change the |
| 624 | document during it is refused, and the strip says that. A wait never |
| 625 | begins in an IME composition; a change in a cold family during one is |
| 626 | drawn in that family's fallback instead. Remote updates are checked |
| 627 | before they reach Yjs, in arrival order (FIFO, never reordered or |
| 628 | dropped), and wait for a local wait to end. |
| 629 | - **A refused save loses only what was refused** (#88 and this branch). |
| 630 | When the server refuses a batch (4xx), the editor diverges and |
| 631 | rebuilds from the server's log (`resync-controller.mjs`), and nothing |
| 632 | is sent meanwhile. From the refusal on the document writes each change |
| 633 | under a fresh Yjs client id, so what is written then depends only on |
| 634 | what it touches; it is kept as its Yjs updates (`unsaved` in |
| 635 | `editor-entry.js`). The resync waits for a change that is waiting for |
| 636 | its font, runs it on its own view, and then carries `unsaved` onto the |
| 637 | rebuilt document before the new view is mounted, so the words are |
| 638 | never off the sheet for a frame (`fixtures/carry.mjs`). Each update is |
| 639 | judged from its own structs and delete ranges — a delete range |
| 640 | counting as taken in part once the rebuilt doc holds its start, since |
| 641 | Yjs deletes up to what it holds and keeps the rest pending: one of |
| 642 | which nothing integrates (written on top of the refused text) is not |
| 643 | posted; of one that partly integrates, only the part that did is |
| 644 | posted, so the server holds what the sheet shows and nothing of it |
| 645 | pending. Client ids while diverged come from the keeper |
| 646 | (`createKeeper`, driven by the doc's `beforeTransaction`): Yjs |
| 647 | integrates one client's structs in clock order, so one change held |
| 648 | back would strand every later one under its id. A ProseMirror change |
| 649 | takes a fresh id once per 500 ms window (every later ProseMirror |
| 650 | change has its transactions to replay, so it is never stranded); any |
| 651 | other — an undo, a redo — takes one of its own. A fresh id per change |
| 652 | was quadratic over a long divergence and left a client per keystroke |
| 653 | in the document; `carry` is linear too (clocks read from the struct |
| 654 | store, one running probe copy), and `carry.test.mjs` holds its |
| 655 | growth to linear (4000 changes against 1000). |
| 656 | Local changes made while diverged — typing, a paste, a |
| 657 | delete, a change that waited for its font — are also kept as their |
| 658 | ProseMirror transactions (the one dispatched and every one the plugins |
| 659 | appended: the view's `dispatchTransaction` hands them to |
| 660 | `aroundDispatch`; transactions ySync makes to mirror Yjs are left |
| 661 | alone), because Paul ranks a lost edit worse than a flash. When a |
| 662 | change's updates cannot integrate — written on the refused text, or on |
| 663 | an earlier change that could not be carried as its own updates — it is |
| 664 | replayed: its steps mapped through the one span where the rebuilt |
| 665 | document differs from what it was made on (the two ends moved past any |
| 666 | overlap, as prosemirror-view's `findDiff` does), written back with |
| 667 | y-prosemirror in a `carried` transaction (`yUndoPlugin` gets an |
| 668 | `UndoManager` tracking `carried`), and that update posted. The carried |
| 669 | changes undo in the steps they were made in: the keeper stamps each, |
| 670 | and the undo manager stops capturing where two were made further apart |
| 671 | than its 500 ms window. A multi-step change (an autoformat rule |
| 672 | deletes its marker, then wraps or retypes the block) is mapped |
| 673 | prosemirror-collab's way (each step through the inverses of those |
| 674 | before it, the span, and their replayed forms), not every step through |
| 675 | the one span map. An undo or a redo made while diverged is the undo |
| 676 | manager's Yjs change, kept with a replay derived from ySync's mirror of |
| 677 | it (`carry.mjs`'s `derivedStep`: one step from the mirror's before and |
| 678 | after, set in `aroundDispatch` and taken by the next `keep` in the same |
| 679 | Yjs transaction), so the resync makes it again as the person saw it — |
| 680 | taking text away or putting it back — whatever ids the change it |
| 681 | undoes was replayed under; that includes bringing the refused text |
| 682 | back when an undo or a redo put it back on screen. Where ProseMirror |
| 683 | refuses a mapped step (typing |
| 684 | into a paragraph the refused change made) the change falls back to |
| 685 | what of its own updates integrates — nothing, there — and is left out: |
| 686 | nothing posted for it, the save line saying failed, the clipboard as |
| 687 | it was; the changes after it are still carried. An edit made between a batch |
| 688 | leaving and its refusal arriving is lost with it (same client id, |
| 689 | after the refused clocks). A tab closed while diverged beacons |
| 690 | `unsaved` with the queue's bytes. `carry.test.mjs` (in the gate), |
| 691 | `resync_browser_test.go`, `carry_browser_test.go`, |
| 692 | `TestFontEnginesAWaitingPasteSurvivesARefusedSave` (Claude Fable's |
| 693 | eleven paste cases) and `TestEnginesEveryChangeWhileARefusalIsPendingIsKept` |
| 694 | (mixed edits, undo, a change that cannot be kept in the middle), both |
| 695 | in Chromium and WebKit (`fixtures/engines/replay.mjs`, `diverged.mjs`), |
| 696 | and `TestEnginesUndoAndRedoWhileARefusalIsPendingEndAsSeen` (Claude |
| 697 | Fable's seventeen undo and redo cases, `undo.mjs`) hold it. **What is |
| 698 | still not kept:** a change whose replay cannot be made (the |
| 699 | structural case above), and a change made elsewhere in the same |
| 700 | 500 ms id window as one on the refused text when its own replay |
| 701 | cannot be made either. `replay.mjs` holds the code face until the |
| 702 | case's refusal has landed and waits for the saves to settle, rather |
| 703 | than for fixed times: under load a fixed hold raced the refusal. |
| 704 | - **Waits are rare: the prefetch.** On an editor page, once the page is |
| 705 | shown and the default's faces are in, `fonts-gate.mjs` fetches every |
| 706 | picker family's faces one at a time when the page is idle, at low |
| 707 | priority, and loads each from the cache (about 5.9 MB beyond the |
| 708 | page's own, once). Not with Save-Data or on 2G. It never commits |
| 709 | anything; `data-docs-fonts-prefetch="done"` marks the end. |
| 710 | - **The font notes hang just under the bars, over the tray and the |
| 711 | page's top margin: never over text, a control or the focus.** The |
| 712 | strip takes no space and is always in the page, transparent when |
| 713 | empty, so nothing moves when it speaks; it wraps rather than clipping. |
| 714 | The tray keeps room for one line of it at every width, and the gate |
| 715 | makes more room for the substitutes note before the page is shown. It |
| 716 | sits under the bars' own menus. The substitutes note (10 s) and the |
| 717 | unavailable note (8 s) go away on their own or when dismissed. |
| 718 | - **Families come from the schema** (`fixtures/schema.mjs` |
| 719 | `familyOfNode`/`familyOfMark`): a `font_<key>` mark is its family, and |
| 720 | a node or mark with `code: true` (the code mark, `code_block`) is |
| 721 | code's. Go's `export.CodeNodes` is held to the schema by a test, and |
| 722 | the server renders `code_block` as the editor does, `<pre><code>`. |
| 723 | - **Tests:** `TestFontEveryInputPathWaitsForItsFamily` is one table of |
| 724 | input paths, each given a cold family; `TestFontAWaitIsAShortModal` |
| 725 | types, deletes, moves, composes, undoes, uses the title and receives a |
| 726 | collaborator's edit during a wait; `TestFontEnginesAWaitKeepsThePage` |
| 727 | presses Backspace and the scrolling keys during a wait in Chromium and |
| 728 | WebKit. The engines check |
| 729 | (`fixtures/engines/first-reveal.mjs`) must not add anything to the page |
| 730 | it captures: a stylesheet inserted per screenshot makes WebKit report |
| 731 | loaded faces as unloaded. The generator |
| 732 | (`fixtures/generate-random-docs.mjs`) walks the schema's own content |
| 733 | expressions and fails unless every node and mark appears. The |
| 734 | generative test checks the server-rendered DOM and the mounted editor's |
| 735 | DOM. |
| 736 | - **The chrome uses no webfont at all**, so the toolbar glyphs, page |
| 737 | numbers and the rest of the chrome are system faces; keep it that way. |
| 738 | estilo's Onest was the one exception until 2026-10-25, when estilo moved |
| 739 | the chrome to the system UI face (estilo AGENTS.md row 9, Paul: "No |
| 740 | flashing, ever!"). The layout no longer links it; estilo's v1 font URLs |
| 741 | stay mounted only for pages cached before that. |
| 742 | `TestNoPageLinksOrPreloadsAChromeWebfont` fails if any served page |
| 743 | links, preloads or declares a font outside Docs' own `/static/fonts/`. |
| 744 | - **A page that was never held keeps its first layout.** The editor |
| 745 | freezes pagination if the sheet is already in view when it could first |
| 746 | paginate. That happens with no hold, or a gate that found none. |
| 747 | - **A pasted font-family stack maps the native app's way** |
| 748 | (`fonts.mjs` `familyForStack`, from the same manifest). Read the names |
| 749 | in order and take the first that maps: Docs' private name, then the Word |
| 750 | name, then the family's own name, then a name in its fallback stack, in |
| 751 | picker order. Anything else is the default. An explicit font-family |
| 752 | that maps to the default or to nothing clears an inherited font. The |
| 753 | shared cases are in `fixtures/vectors/font-stacks.json`. |
| 754 | - **The gate waits for families, not faces** (review 4, after three |
| 755 | rounds of finding faces the face list missed: a space-only run, a |
| 756 | block's strut, a bold run's wrapper). A family is used if the document |
| 757 | references it anywhere: the default, a font mark on any run, wrapper or |
| 758 | break, or code. For each used family the gate waits for every style |
| 759 | before the reveal, and the editor, pastes and collaborators' changes |
| 760 | wait the same way. `TestFontTheGateCoversEveryFaceTheDocumentUses` |
| 761 | generates random documents (`fixtures/generate-random-docs.mjs`). It |
| 762 | holds the gate's families equal to those the rendered DOM computes on |
| 763 | every element and text node, and every face the DOM draws in to one the |
| 764 | gate waited for. The cost is the family's other three styles before the |
| 765 | first reveal: a plain Carlito page waits for 796 KB instead of 190 KB, |
| 766 | once (the files are cached as immutable). |
| 767 | - **WebKit too:** `TestFontEnginesFirstRevealIsTheFinalLayout` drives |
| 768 | Chromium and WebKit through Playwright (`fixtures/engines`; run `npm ci` |
| 769 | and `npx playwright install chromium webkit` there once). Every capture |
| 770 | must be either "nothing painted yet" or the final picture, and a control |
| 771 | page that flashes on purpose must be caught, or the check fails as |
| 772 | blind. |
| 773 | - **The browser checks** (`go test -tags browser -run Font ./internal/docs/`) |
| 774 | run through the production middleware with fonts, scripts or the editor |
| 775 | slowed or blocked. They fail on any frame that shows text in a face that |
| 776 | has not loaded, and on a first layout that is not the final one. |
| 777 | |
| 778 | **Pushing a branch that adds fonts:** the hub drops a chunked |
| 779 | receive-pack and answers 200 with an empty body, which git reports as |
| 780 | "unexpected disconnect while reading sideband packet". Push with |
| 781 | `git -c http.postBuffer=157286400 push` so the pack goes out with a |
| 782 | length. |
| 783 | |
| 784 | ## Spacing (Paul, 2026-11-22: no ad-hoc spacing) |
| 785 | |
| 786 | Every margin, padding and gap is a `var(--rst-sp-N)` step of Fiesta's |
| 787 | scale, or says why not where it is written: `/* spacing-allow: why */`. |
| 788 | Page content goes in Fiesta's stack (`rst-stack`, with `rst-section` and |
| 789 | `rst-actions`), which spaces a page's blocks by one table; a page adds |
| 790 | no margins between them of its own. Two checks hold it: |
| 791 | |
| 792 | - **The spacing check**, in the gate: `go tool fiesta spacing |
| 793 | internal/docs/brand` for the stylesheets on disk, and |
| 794 | `TestEveryStylesheetIsOnTheSpacingScale` for the `<style>` blocks in |
| 795 | `views/`, which the tool does not read. |
| 796 | - **The rhythm audit**, `TestEveryScreenKeepsTheRhythm`, in `make |
| 797 | browser` (run by hand: the gate cannot start a browser). It reads |
| 798 | every screen at 1280 and 390px, around the editor's bar and canvas and |
| 799 | the published document's body, which are not the page's to space. |
| 800 | The Colophon is estilo's page and is left to estilo. |
| 801 | |
| 802 | ## The Colophon: exhaustive by construction (Paul, 2026-10-26) |
| 803 | |
| 804 | Help → Colophon (web, `/help/colophon`) and the Apple apps' Colophon |
| 805 | (Help menu on the Mac, the library's menu on iPhone) list every |
| 806 | open-source project Docs is made with: "I'd be happy if that were |
| 807 | exhaustive." Help → Fonts (`/help/fonts`) explains the fonts drawn to |
| 808 | Word's measurements, from `fonts.json`'s `twin`. |
| 809 | |
| 810 | - **Nothing is listed by hand.** `internal/shipped` collects what ships: |
| 811 | `go list -deps ./cmd/docs` (linux/arm64), the npm packages esbuild reads |
| 812 | for `fixtures/bundles.mjs` (`fixtures/colophon-inputs.mjs`), `cargo |
| 813 | metadata` for `core/` and, for the apps, `native/crdt` and `native/host`, |
| 814 | the fonts, Lucide, the Swift pins in `Package.resolved` and the HTML |
| 815 | entities table, plus the pinned tools. `go run ./cmd/docs-colophon` |
| 816 | writes `internal/docs/colophon.json` and DocsKit's `Colophon.json`. |
| 817 | - **The words are estilo's** (`colophon/projects.json`): one entry per |
| 818 | project, with a usage note per app key (`docs`, `docs-native`). |
| 819 | `colophon.Build` refuses an unknown package, a missing or stale usage |
| 820 | note, and a shipped package without its licence text. |
| 821 | - **So a dependency change fails `TestColophonsMatchWhatShips`** until the |
| 822 | catalog has the project (an estilo commit, then re-pin estilo here) and |
| 823 | the generator has been rerun. Do not loosen the test to get past it. |
| 824 | - **Licences a package does not carry are vendored with provenance**: |
| 825 | `native/notices/<swift-pin>/` (checked against `Package.resolved`'s |
| 826 | revision) and `native/notices/crates/<crate>/` (checked by sha256 and |
| 827 | exact crate version). |
| 828 | - **Tools are the pinned dev dependencies plus the toolchains the scripts |
| 829 | run**, each found by its invocation in the script that runs it |
| 830 | (`webToolchains`, `nativeToolchains`); a tool's own dependencies are |
| 831 | its own. The toolchain list is kept by hand and checked one way (a |
| 832 | script that stops running one fails), so its scope is stated rather |
| 833 | than claimed exhaustive: the open-source language toolchains, package |
| 834 | managers, browsers and sandboxes that build or test what ships (Go, |
| 835 | Rust and rustup, Node and npm, Python, Swift, XcodeGen, Chromium, |
| 836 | Docker, bubblewrap); not the shell, git, curl, or Apple's proprietary |
| 837 | Xcode tools (xcodebuild, lipo, xcrun). Adding a script that runs a new |
| 838 | one means adding it here and in `internal/shipped`. Proc-macros and |
| 839 | build dependencies are tools too (estilo's `CollectCargo`): they run |
| 840 | in the compiler and are not linked. |
| 841 | - **The Apple host crates are marked by platform** per target graph, so a |
| 842 | crate on one target alone shows in that app alone. |
| 843 | - The pages need no script and load no font |
| 844 | (`TestNoPageLinksOrPreloadsAChromeWebfont`, and |
| 845 | `TestColophonPagesReflowAndNeedNoScriptOrFont` with `-tags browser`). |
| 846 | |
| 847 | ## Work in a worktree, and catch main up first |
| 848 | |
| 849 | Take a worktree for the work. Do not work in the shared checkout. |
| 850 | |
| 851 | git -C <repo> fetch origin |
| 852 | git -C <repo> worktree add ../<repo>-<task> -b <branch> origin/main |
| 853 | |
| 854 | Both halves matter, for different reasons. |
| 855 | |
| 856 | **The worktree**, because several sessions share this machine and some |
| 857 | share this repository, and a checkout has one HEAD, one index and one |
| 858 | working tree between all of them. A branch switch under somebody else's |
| 859 | uncommitted work destroys it with nothing on screen to say so, and two |
| 860 | sessions editing the same paths disagree quietly instead of conflicting |
| 861 | loudly. A worktree gives the work its own HEAD and its own files, and |
| 862 | costs a directory. |
| 863 | |
| 864 | **From `origin/main`, after a fetch** — not from whatever the checkout |
| 865 | happens to be sitting on. A branch cut from a stale main is a merge |
| 866 | conflict scheduled for later, against files somebody else has renamed in |
| 867 | the meantime. A branch cut from another task's branch is worse: it |
| 868 | carries that task's commits into yours, where they are reviewed as |
| 869 | though you wrote them, and the two can only be separated by hand. |
| 870 | |
| 871 | Remove it when the work has landed — `git worktree remove` — so that |
| 872 | `git worktree list` keeps saying something true. |
| 873 | |
| 874 | Written down because of 2026-09-17, in `meet`. The shared checkout was |
| 875 | sitting on one task's branch while holding a *different* task's feature |
| 876 | uncommitted on disk — some four hundred lines, a new migration among |
| 877 | them — put there by a session nobody else knew was working in that tree. |
| 878 | Two other sessions were meanwhile coordinating over the same checkout by |
| 879 | asking each other not to touch it, which is the arrangement a worktree |
| 880 | makes unnecessary. Nothing was lost. Nothing about the arrangement would |
| 881 | have said so if it had been, and by then the same feature existed twice, |
| 882 | once on each side of a rename, because the two sessions had branched |
| 883 | from different starting points. |
| 884 | |