<!--{"pin": "bottom", "order": 2, "description": "Numbered, dated architectural decisions: why the platform is shaped the way it is."}-->

# Decisions

Numbered, dated, self-contained architectural decisions. **ROADMAP.md is a plan and will be
rewritten; this file is a ledger and is append-only.** When a decision is superseded, the entry
stays and gains a `Superseded by` line — the reasoning is worth more than the conclusion, and a
retracted decision that vanishes teaches nobody.

Each entry names **where it lands**, because several of these constrain repos that do not exist yet
(`tosijs-blog`, `tosijs-assets`) or belong to another leg (`tosijs-ui`, `tjs-lang`). At extraction
time, carry the entry with the code.

| # | decision | lands in |
|---|---|---|
| [D1](#d1) | Three legs; this repo is the service layer | all |
| [D2](#d2) | ajs rules stay pure predicates; transforms → ajs once the host exists | this repo |
| [D3](#d3) | The real root of trust is datastore access | this repo |
| [D4](#d4) | `owner`/`super` add authority over rules, not power | this repo |
| [D5](#d5) | Access is a lattice: boolean visibility × schema projection | this repo |
| [D6](#d6) | Field-level access is a schema, not a field map | this repo |
| [D7](#d7) | Filter before limit | this repo |
| [D8](#d8) | Route contributions replace prefetch/sitemap endpoints | this repo + tosijs-ui + components |
| [D9](#d9) | Libraries as a service vend docs/examples/LLMs.txt | this repo + tosijs-ui |
| [D10](#d10) | SSR is public | this repo + every route contributor |
| [D11](#d11) | One definition of "published" | tosijs-blog |
| [D12](#d12) | Endpoints self-gate on their own tests | this repo |
| [D13](#d13) | Build on demand; validate the design against what is unbuilt | all |
| [D14](#d14) | Collections are data; no compiled authority, not even for owner | this repo |
| [D15](#d15) | Namespaces use `:`; a manifest may declare only its own | this repo |
| [D16](#d16) | Bootstrap by proving datastore access, not by a first-run secret | this repo |
| [D17](#d17) | Install v1 is declarative; `functions` is refused, not ignored | this repo |
| [D18](#d18) | Consumer order: virta, then the tjs-lang platform, then loewald.com | all |
| [D19](#d19) | loewald.com moves ahead of the tjs-lang backend (amends D18) | all |
| [D20](#d20) | An admin suite: data, rules, roles, assets; prompts are documents; RSS | this repo + tosijs-ui + tosijs-blog |
| [D21](#d21) | Files live in storage areas: collections with blob limits | this repo |
| [D22](#d22) | Setup: as few human steps as security allows; IAM only from code | this repo |
| [D23](#d23) | Render on store: SSR pages, nav, blog index, sitemap and RSS are rendered when content is written, served as stored files | this repo (renderers → stored ajs later) |
| [D24](#d24) | A post always names its author: the server fills an empty one from the writer, or refuses the write | this repo + tosijs-blog |
| [D25](#d25) | Server HTML of content is written fresh from an allowlist, never a parser's serialization | this repo (renderers → stored ajs later) |
| [D26](#d26) | Game rooms: one room interface, two backends (our own host, and Firebase as an option whose scale is unproven); relay-only first | this repo + the room client + Manta |
| [D27](#d27) | Rooms v1: our host only, on the preview box, with host-issued guest tokens; Firebase deferred (amends D26) | this repo + tosijs-rooms |
| [D28](#d28) | The blog and asset manager are installable extensions of the core, built and published from this repo (amends D1) | this repo |
| [D29](#d29) | Search for agents: `/.well-known/search` is a core feature, returning exactly what an anonymous listing returns | this repo (mechanism) + each extension (its searchable collections) |

---

## D1
**Three legs; this repo is the service layer.** *(2026-09-10, with tjs-lang)*

tosijs-ui owns build/docs/SEO. tjs-lang owns the transpiler, language and VM. **This repo owns the
service layer**, and its core value is *RBAC · the universal endpoint · the data layer · stored
functions with versioning and tests*. The blog and asset manager become separate front-end libraries
on tosijs-ui — separate projects, not subdirectories.

**Consequence:** `src/blog.ts`, `src/asset-manager.ts` and the editors are not this repo's product.
Work on them is migration preparation, not investment.
**Lands in:** all three repos. → ROADMAP "Three legs".
**Amended by [D28](#d28)** (the blog and asset manager stay in this repo as installable
extensions, and are its product).

## D2
**ajs rules stay pure boolean predicates; transform/field-strain/provenance/unique stay compiled
TCB.** *(2026-09-05, Phase 0)*

The alternative — rules returning transformed `newData` — is exactly the shape
[tjs-lang#52](https://github.com/tonioloewald/tjs-lang/issues/52) corrupts silently: a `beforeWrite`
returning `{...data, revisions}` persists `{revisions}` alone. Data loss with a plausible payload.

**Correction (2026-09-06):** the original claim that predicates are "entirely unaffected" by #52 was
**false and fails open** — [tjs-lang#54](https://github.com/tonioloewald/tjs-lang/issues/54).

**SUPERSEDED (2026-09-12): transforms move to ajs. Blocked on the ajs host, not on a decision.**

#52 and #54 were fixed in 0.13.12 (verified; the tripwires fired and became regression cases), so
the *only* argument for compiled transforms — that ajs silently corrupted them — is gone. Recorded
first as "open for revisit", which was wrong: on inspection nothing argues for keeping them compiled
as a permanent choice, and two things argue against it.

- **§6.1 requires it.** "Policy is not a sidecar" is unsatisfiable while transforms ship with a
  deploy: a client cannot pin a policy version that lives in compiled code. Deploy atomicity depends
  on the transform being part of the versioned endpoint artifact.
- **Blast radius was the counter, and D12 answers it.** A procedure that cannot install unless its
  own tests pass is a stronger gate than `tsc` plus review.

So this is a **settled direction awaiting a prerequisite**, not an open question. The prerequisite is
the ajs host; until it exists, transforms stay compiled because there is nowhere else to put them.

Residual: [#56](https://github.com/tonioloewald/tjs-lang/issues/56) (bare context bindings still
return their own name) — neutralised at our boundary by interpreting rule results as
`result === true`, never `!!result`.

When the port happens: the rule half must also honour
[D13](#d13)(c) — meta-authority operations are unreachable from a procedure (now written into
`UNIVERSAL-ENDPOINT.md` §4.3).
**Lands in:** this repo. → `tjs-lang.baseline.test.ts` §5–§6.

## D3
**The real root of trust is datastore access, not a role we design.** *(2026-09-06)*

Certain IAM roles read and write Firestore with no reference to our endpoints. That is the true root,
it exists by construction, and inventing an out-of-band authority (an earlier draft proposed Firebase
custom claims — **retracted**) would create a second root beneath an existing one.

Two consequences: the break-glass path already exists (and is how the first `owner` is seeded), and
our invariants defend against escalation **through the API only** — never against project-level
access. State that scope plainly.
**Lands in:** this repo. → ROADMAP "Meta-authority".

## D4
**`owner` is the in-system reflection of the Firestore account holder; `super` and `owner` add
authority over the rules, not power over the site.** *(2026-09-06)*

`developer` is already effectively total access (module write ⇒ arbitrary JS via `/esm`), so there is
nothing functional to grant above it. `super` = developer + may write `role`/`config`. `owner` =
super + exclusively adds/removes `super` and transfers `owner`. Neither may assign or remove
`owner`/`super` — that is owner-only.

Circularity is broken by **monotonicity: no write may increase the writer's own authority.**

**Insufficient as stated — see [D13](#d13)(c).** That formulation holds for direct writes and fails
for deferred ones: a procedure installed by a `super` and invoked by an `owner` runs with owner
authority, so it can mint a `super` without its installer ever having raised their own authority.
The correct statement is that monotonicity must hold over the **composition**, and the intended fix
is that meta-authority operations are unreachable from a procedure.

**FIXED AND DEPLOYED 2026-09-12.** `role.ts` is owner-only; the escalation chain is severed at step
one. The privilege-lifecycle tripwires flipped on contact and now assert the denial. Monotonicity
itself — a `super` not being able to mint a peer — still needs D12's `isWriteAllowed`, and D13(c)
records that it must hold over *deferred* execution too.

**Demonstrated 2026-09-11**, no longer inferred: `privilege-lifecycle.integration.test.ts` §12–13
drive it end-to-end — an admin writes the role collection, self-grants `developer`, and the new role
is live on the very next request. Those tests assert the CURRENT (wrong) behaviour deliberately, so
the suite flips the day `role.ts` moves to owner-only.

**Also found by the same file:** removing a uid from `userIds` is **not revocation**. `getUserRoles`
writes during a read — when the uid lookup misses it matches `contacts` by email and *re-appends the
uid*. The grant is still real (roles and contacts are unchanged), so this is an operator footgun
rather than an authorization bug: revoking means clearing `roles` or removing the contact, never just
the uid.
**Lands in:** this repo. → ROADMAP "Meta-authority".

## D5
**Access is a lattice on two independent axes.** *(2026-09-06)*

`AccessFilterFunc` conflated row visibility with field projection, which is why role combination had
no defined join. Split them:

| axis | value | join across roles | top |
|---|---|---|---|
| row visibility | boolean | OR | `true` |
| field projection | schema | union of properties | `ALL` |

Replaces the accidental rule, where precedence came from object-key order in each collection's
`access` literal and a later entry *replaced* an earlier one — so holding more roles could grant
less (demonstrated).

**Audit:** every production `AccessFilterFunc` is already a predicate returning the document
unchanged; only the emulator-only demo fixture projects. So the split is nearly free.

**Incomplete as stated — see [D13](#d13)(b).** This lattice covers the **document** axis only. It has
no notion of a *capability* (migrations, storage, `/gen`, third-party APIs), which is
role × capability → permitted invocation *and arguments*. Do not cite D5 as a complete access model
until that third object type is designed.
**Open:** union over schema *constraints* (`min`/`max`/`pattern`) is not obviously "most permissive".
**Lands in:** this repo. → ROADMAP "The access lattice".

## D6
**Field-level access is a schema, not a `FieldAccessMap`.** *(2026-08, re-affirmed 2026-09-06)*

Schema is guard *and* strainer, and it is type-sound. Critically it resolves the write case: a write
field map would have to **silently drop** fields the author submitted, whereas a write **schema
rejects** them, because tosijs-schema is strict about unexpected properties.

**Interim:** non-`ALL` write configs currently **deny** (fail closed) because the write path never
applied them. That is scaffolding until write-schemas land.
**Lands in:** this repo. → `UNIVERSAL-ENDPOINT.md` §178, TODO F1.

## D7
**Filter before limit.** *(2026-09-06)*

`.limit(n)` ran before the visibility filter, so a request for 10 published posts could return 3
while 50 existed. Asking for n and getting fewer, with more available, is a wrong answer. Paging
until n visible rows is right; if that becomes a performance problem, that is for later — assuming
it is one is premature optimisation.

Bounded by `MAX_FILTER_SCAN`, and **exceeding the bound logs** rather than silently truncating,
because "we stopped looking" and "there is nothing more" must not look alike. Projection happens
*after* filtering (projecting first stripped the field the predicate reads).
**Lands in:** this repo. → `docs.ts`.

## D8
**Prefetch and sitemap stop being endpoints; they become route contributions.** *(2026-09-10)*

A component registers a stored function and the platform invokes it for routes it claims. The blog
provides a prefetch handler for routes matching its idea of a blog route; any component contributes
sitemap entries.

| concern | owner |
|---|---|
| routing, deciding what needs SSR, JIT-vs-static | tosijs-ui |
| hosting, invoking and caching contributed functions | this repo |
| the handlers themselves | the component |

**Why structural, not tidy:** the 2026-09-06 sitemap bugs were *drift* bugs — `sitemap.ts` had its
own notion of "published" and its own notion of the host, both wrong. A contributing component has
only one notion, so there is nothing to drift from.
**Lands in:** this repo (mechanism), tosijs-ui (routing), each component (handlers).

## D9
**Libraries as a service: the same mechanism vends doc pages, examples and LLMs.txt.**
*(2026-09-10)*

A library shipped through the platform contributes its documentation surface as routes backed by
stored functions. With `/esm` already serving modules from Firestore, a library becomes **wholly
data** — code, docs, examples and tests, stored and versioned, served with no deploy. Composes with
D12: a library version whose tests fail should not become servable.
**Lands in:** this repo (mechanism), tosijs-ui (authoring/build).

## D10
**SSR is public.** *(2026-09-10)*

The point of SSR is SEO, not speed — the site is fast, lean and cache-friendly without it, and
authenticated users get the hydrated SPA. So server-rendered output is by definition the public view.

This **retires** the "authority in the read/cache key" question rather than solving it: there is no
per-principal SSR, so no cache needs an authority key.

**Enforced structurally**, at `getPrefetchData`'s single invocation point via `asPublicRequest`, so a
contributed handler cannot render privileged content whoever wrote it. It was reachable before:
`blog.ts` built its post pools with the caller's roles and wrote them to `config/blog-cache`, which
is publicly readable, while `author`/`owner` hold `list: ALL` on `post`.
**Lands in:** this repo (enforcement) + every route contributor (D8).

## D11
**One definition of "published", shared by client and server.** *(2026-09-06)*

`unpublish()` writes `date = ''`; the server's list guard tested `date !== undefined`. `'' !==
undefined` is true, so **57 production drafts were served to anonymous callers**. Three things mean
"empty" here — `undefined`, `''`, and a *boxed tosijs proxy scalar* (an object, therefore truthy) —
and code kept picking one.

`isPublished()` in `functions/shared/post.ts` coerces with `String(v ?? '').trim()`, plus an
`UNPUBLISHED_DATE` sentinel so the written value and the tested value cannot drift. Deliberately
**not** a parseability check: a mistyped date should render oddly, not silently unpublish a live post.

**Related decision:** drafts are **unlisted, not secret** — public `read` on `post` is intentional so
a draft can be shared for comment. The property to protect is *not findable by accident*, which is
why the sitemap must exclude them (it was advertising all 57).
**Lands in:** tosijs-blog. Carry `isPublished` with the blog code.

## D12
**Endpoints self-gate: a stored procedure ships with its own tests and cannot install if they fail.**
*(2026-09-05, elevated 2026-09-10)*

Because a procedure is data, its tests are data too — they version together, with no CI-vs-prod gap.
Because ajs is deterministic with injectable (mockable) capabilities, those tests are pure and
runnable **server-side at install time**. So the server can refuse a procedure whose own tests fail:
a gate inside the install path cannot be skipped at 11pm.

D1 elevates this from a nice property to **stated core value** ("stored functions with versioning
and tests") — it is what a plain Cloud Function cannot offer.

**Caveats to design against:** the gate proves "its own tests pass", not correctness (so §6.1's
*generated* property tests matter more than author-written ones); install-time execution runs author
code and needs its own fuel/quota budget or installing is a denial-of-wallet vector; and mocked
capabilities mean the gate verifies logic, not integration, so the mocks belong to the platform's
trusted surface.
**Lands in:** this repo. → ROADMAP "Self-gating endpoints".

## D13
**Implement only what is needed, when it is needed — but validate the design against the pieces that
are not built yet.** *(2026-09-12)*

The two halves are load-bearing together. Building ahead of evidence is the error the sovereign
analysis argues against; designing without the unbuilt pieces in mind is how a model gets a shape
that cannot express them, discovered at the point where changing it is expensive.

So: no sockets, no rooms, no capability system today. But the RBAC model and the architecture get
checked against them *now*, while a change costs a paragraph rather than a migration.

**First validation pass, 2026-09-12** — checking the current design against sockets, rooms,
migrations, stored procedures and third-party capabilities. Two gaps and one defect found:

**(a) `COLLECTIONS` registers only at import time, so ephemeral collections are unrepresentable.**
*(Closed by [D14](#d14), 2026-09-19 — the registry resolves configs from data, and [D15](#d15) gives
the access model the namespace this paragraph asks for. The prediction was exact.)*
Every collection is a module-scope assignment (`COLLECTIONS.post = {…}`). Rooms (§D-games) and
§7.4's test fixtures both need *runtime* registration. The access model itself is fine; the
**registry** is not — and B3 proved registration is security-relevant, since a demo collection with
`write: ALL` for `public` shipped to production. §8 already requires that an ephemeral backend's
capabilities be "scoped to only its own ephemeral collections — an invariant, not an emergent
property", and a flat global namespace cannot express that. **Implication:** ephemeral collections
need a *namespace the access model understands* (e.g. a hard `ephemeral/<owner-id>/…` prefix rule),
so the scoping is structural rather than a convention someone has to honour.

**(b) The access model has no notion of a capability at all.** It is role × collection × method →
access. Migrations (§7.3's deliberately unusual widen-scope-keep-validation shape), storage, `/gen`
and third-party APIs are all role × **capability** → permitted invocation *and permitted arguments*.
So **D5's lattice is incomplete as stated**: it describes the document axis only. It should either
say so explicitly or grow a third object type. Not urgent — nothing ships on it — but the lattice
should not be cited as complete.

**(c) DEFECT — monotonicity does not survive deferred execution.** D4 states "no write may increase
the writer's own authority", which holds for direct writes. A stored procedure (D12) is a write
*now* that executes *later*, and §2.1 says procedures run with the **caller's** capabilities. So a
`super` may install a procedure that writes to `role`; when an `owner` invokes it, it runs with
owner authority and can mint a `super` — which D4 says only an owner may do. The installer never
increased their own authority, so monotonicity as written is satisfied while the property it exists
to protect is defeated. Classic confused deputy.

*Fix — chosen 2026-09-12 and written into `UNIVERSAL-ENDPOINT.md` §4.3.* The cheapest option: meta-authority operations
(mutating `role`, `super`, `owner`) are **not reachable from a procedure at all**; they require a
direct, attributed write. That keeps D3's "root acts through the paved path" while removing the one
place deferral is dangerous. The alternatives — intersecting caller and installer capabilities, or
refusing to invoke a procedure you cannot read — are more general and more restrictive, and can be
revisited if a case demands them. **The general statement to adopt:** *authority to install is not
authority to execute, and monotonicity must hold over the composition, not over each write
separately.*

**Also noticed:** the join over *constraints* is one open question wearing two hats — schema
projection union (D6) and capability-argument union (b) are the same problem. Solve once.
**Lands in:** all repos (the discipline); this repo (the three findings).


---

## D14
**Collection configuration is DATA, resolved through the privileges model. Nothing about what a host
can do is fixed outside the system — except owner authority, which is outside our control anyway.**
*(2026-09-19, owner)*

`COLLECTIONS` was a module-level map populated by import-time side effects, so a host's capabilities
were fixed at build time. An install system cannot exist on top of that: a collection has to be
definable by writing a document.

Consequences, in order of how much they change:

**There are no platform collections, only installed ones.** The registry makes no distinction
between `post` and `virta:task`; bare names simply belong to the platform's own namespace. This
collapses "dogfood the blog as a manifest" from a milestone into the normal case — there is no other
case.

**No compiled authority, including for `owner`.** There is deliberately no `owner ⇒ ALL` escape
hatch anywhere. Owner's real power is datastore access (D3), which lives outside anything this code
can grant or revoke, and this ledger already retracted one design (Firebase custom claims) for
inventing an in-system second root. A compiled bypass would be exactly that. So an empty or
unreadable config store **fails closed**: every collection undefined, `/doc` denies everything, and
the only way back is the datastore — which is the recovery story D3 already describes.

**The bootstrap is not circular.** Reading configs is a privileged *internal* read, not a `/doc`
request, so it is not governed by the configs it fetches. Not a new mechanism: `getUserRoles` has
always read `role` this way. Internal reads are infrastructure; the access model governs external
requests.

**One bad config must not take down the host.** Configs compile independently and a failure is
isolated to its own collection. Otherwise a typo becomes an outage — and anyone who could get one
malformed document stored could deny the entire service.

**Invalidation has to actually take effect.** `invalidate()` alone clears only the instance that
handled the request; every other instance keeps serving the old rules until its TTL expires, which
for a revocation is precisely the wrong failure. Hence a cheap `epoch()` probe: each instance
re-checks one small value every few seconds and reloads only when it moved. Rules propagate in
seconds. **Identity revocation does not** — `verifyIdToken` is still called without
`checkRevoked: true`, so an already-issued token outlives a revoked role by up to an hour. You can
change what anyone may do almost instantly; you cannot yet instantly stop being someone.

Still outside the data model and still to move: `ROLES` is a closed const, and `PRIVILEGED_ROLES`
(who sees real errors rather than opaque 404s) is a hardcoded list that is already stale —
`configurator` is missing from it.

---

## D15
**A namespace is separated by `:`, and a manifest may declare only its own.** *(2026-09-18)*

`/` was the obvious separator and is wrong: it is already the sub-collection separator.
`collectionPath()` splits document paths on `/` and keeps the even segments, so `virta/task` is
indistinguishable from "sub-collection `task` of collection `virta`" — pinned as a test, because the
collision is silent rather than an error. `:` rides inside one segment, so path parsing, `/doc?p=`,
`/docs?p=` and sub-collections all work unchanged, and it is legal in a Firestore collection id and
in a query value.

The gate has two independent rules: **any bare name belongs to the platform** — not merely the names
on a known list, so adding a platform collection later needs no edit here — and a namespaced name
must match the declaring manifest. Near-miss namespaces (`virta` vs `virta2`) are refused explicitly,
since prefix confusion is how such checks usually leak.

`role` and `module` are the ones that matter: whoever writes `role` rewrites the input to their own
authorization (D4), and `module` documents are served as executable JavaScript by `/esm`. Either
claimed by a manifest is a site takeover, not a name clash.

Logical→physical mapping is the identity function today and exists anyway, so a substrate whose
naming rules differ (Postgres table names cannot contain `:`) is a change in one file.

---

## D16
**A fresh host bootstraps by proving datastore access, not by holding a first-run secret.**
*(2026-09-19)*

The obvious design hands the deployer a secret at first boot. It has a leak window, a
who-holds-it-in-CI problem, and no recovery story once lost.

Instead: the endpoint publishes a **nonce** at an unauthenticated GET; the claimant writes it into a
designated document **directly in the datastore** (console, gcloud, psql); the endpoint compares,
mints `configurator`, rotates the nonce and clears the proof.

Nothing secret is published. The proof is not *knowing* the nonce — it is being able to **write** it
where only the datastore holder can write, and `firestore.rules` is deny-all so no API path reaches
that document. It is therefore re-runnable, which doubles as break-glass recovery, and
substrate-portable, since "console access" becomes "a psql prompt" without changing the ceremony. It
is D3 made operational rather than an authority we invented.

**Rotation is load-bearing.** Without it the proof stays in the datastore and the next authenticated
caller claims for free, converting a one-time ceremony into a standing back door.

Failure directions chosen deliberately: an absent or unparseable `issuedAt` counts as **expired**
rather than fresh; an empty proof does not match an empty nonce; an unauthenticated claim is refused
because a grant must be attributable. Comparison is a plain `===` on purpose — a timing oracle leaks
the nonce, and the nonce is published.

`configurator` is a separate role, not folded into `owner`: a host can then delegate "may install
libraries" without handing over the data, and an install appears in the ledger as its own act. It
cannot appoint another configurator, because `role` is owner-only (D4).

---

## D17
**Install v1 is declarative. A manifest carrying `functions` is REFUSED, not ignored.** *(2026-09-18)*

A manifest carries schemas, an access lattice, unique constraints, derive ops and capability
requests — all serializable. No stored ajs: tjs-lang is a validated but unwired dependency, and
tjs-lang#52/#54 corrupt transforms *and* predicates silently while upstream coerces a corrupted
result to a GRANT. Shipping caller-authored code on that is not a trade worth making.

*Status (2026-11-19):* those bugs are fixed (#52 and #54 in 0.13.12; bare bindings in 0.14.0, now
pinned), so this reason for refusing `functions` is gone. The refusal stands until stored ajs has
a host; lifting it is its own decision.

Refusing rather than ignoring matters: silently dropping the executable half of someone's manifest
and reporting success is the worst available outcome.

Two measured tosijs-schema defects shape the format, and neither is guessable by a manifest author:

- **`$predicate` fails OPEN and is invisible to the gate.** With no evaluator registered it accepts
  anything, and because it is *in* the enforced keyword set `unenforcedKeywords()` returns `[]` for
  it. Refused by name, at any depth. This is the one that could be weaponised deliberately: a schema
  that looks validated and validates nothing.
- **`contains` is accepted but not enforced**, which is precisely the rule `page` and `module` use
  for row visibility. So visibility **cannot** be a schema; it is a small closed predicate vocabulary
  instead. That one *is* caught generically.

Transforms are a closed registry of parameterised ops (`slug`, `shortId`, `now`, `principal`,
`constant`) plus `envelope.version.bumpOn`. The manifest *selects* a transform; it never carries
code. `bumpOn` removes a bug class rather than a bug: the caller cannot send the revision field, so
the hand-written branch that once erased a module's history has nowhere to live.

An unknown visibility op **denies**, and `all: []` is refused — a predicate nobody understands, or a
vacuously true one, must never read as permission.

---

## D18
**Consumer order: virta first, then the tjs-lang platform backend, then loewald.com.** *(2026-09-19,
owner)*

Supersedes the earlier "blog first" ordering, which argued the blog is the better first customer
because it has a known-correct oracle and cannot be bent to fit a weak format.

That reasoning was about *format validation*; it ignored *risk*. loewald.com is a live site with a
decade of real data, so it is the worst place to learn what the install system gets wrong.
**tosijs-virta is greenfield — there is nothing to lose.** It is the guinea pig: unblock it
completely, let it try to get real work rolling, expect immediate adoption pain, and patch rapidly.

The **tjs-lang platform backend** is then the second consumer — languages-as-a-service,
blueprints/components-as-a-service, libraries-as-a-service, unbundled development. It is *lower risk
and higher demand* than loewald.com, which makes it a better second adopter than the blog on both
counts.

loewald.com comes last, after two consumers have shaken the design out, and is migrated to discrete
pieces rather than converted in place.

Immediate consequence: **the `/doc` swap for platform collections is NOT on virta's critical path.**
Installed collections are what virta needs; `post`/`page`/`module` can stay compiled until their
turn. A production-touching migration was about to be done for a consumer that does not require it.

## D19
**loewald.com moves ahead of the tjs-lang platform backend.** *(2026-09-25, owner)* Amends D18's
order: **virta, then loewald.com, then the tjs-lang platform backend.**

D18 put the blog last on risk grounds. Since then virta has exercised everything the blog needs:
collections, public reads, attributed writes, provenance, sequencing and install. The surface the
tjs-lang backend depends on most, `/esm` and libraries-as-a-service, is one the blog barely uses.
So the blog is now the lower-demand consumer of what is already proven, and tjs-lang would be the
first real test of what is not.

D18's other half stands: the blog is migrated in discrete pieces, not converted in place. In
order: a catch-up deploy of current platform code (compiled configs, rehearsed on a clone); then
the deferred swap of the bare-name collections to the registry's seeded configs (measured on the
clone first); client extraction to `tosijs-blog` later, per ROADMAP.

---

## D20
**An admin suite for what every host needs: data, rules, roles and assets.** *(2026-09-28, owner)*

Every host needs to manage its data, its rules, its roles and its files, and most platforms do it
half-heartedly. Firebase's console is a standing annoyance and knows nothing about our schemas or
access rules. So the platform grows its own tools, as exported components:

- a **data manager**: general-purpose, schema-aware CRUD (tosijs-ui `tosiCrud` + `tosiSchemaForm`);
- a **rules manager**: create collections and manage their schemas and access rules;
- the **role manager**, extracted as a component that works on the built-in roles and is designed
  to be extended;
- the **asset manager** (tosijs-assets), alongside them.

**The schema editor goes upstream to tosijs-ui** (tosijs-ui #2454), writing `x-tosi` annotations
that `tosiSchemaForm` honours. They are presentation only, never correctness: hidden, locked,
widget, class, and sections (a named, optionally collapsed grouping; a nested object is an
implicit section). tosijs-schema treats `x-` keywords as annotations, so manifests accept them;
the `ui:*` style other libraries use is refused.

Two content decisions made with it:
- **AI prompts are documents** in a collection, owned or shared like any other. They are not
  hard-coded in the client or in tosijs-blog config. `gen` runs a prompt by reference, under the
  caller's access to that prompt.
- **RSS, with enclosures.** Feed items carry media enclosures, which gives podcasts for free.

Open: where the suite lives and what it is called. Board: #2448 (epic), #2449-#2453.

---

## D21
**Files live in storage areas: collections with blob limits.** *(2026-09-29, owner; shipped in
0.3.0)*

A **storage area** is a namespaced collection with `blob: {maxBytes, contentTypes?}`. Each file has
a metadata document, and the area's access rules are the files' access rules. There is no second
permission system for files (owner: "the namespace/bucket works like a collection for permissions
purposes").

- **Public vs private is derived, not declared.** An area is public when `public` has
  unconditional read. The blog needs two classes, `blog:public` and `blog:private`, and they are
  two areas, not a flag.
- **The server measures size and hash.** Object keys carry the content hash, and metadata is
  committed before an old object is removed. So a metadata document always means its file exists;
  a crash can orphan an object, never corrupt one.
- **Metadata is written only through `/blob`.** `/doc` and `/docs` refuse writes to an area.
- **A caller who cannot read a file gets answers independent of what is stored.** No
  `unchanged`, the same `409` in an immutable area, and no faster path when a guess matches.
- **Everything else that reads the bucket reads an ALLOWLIST** of legacy folders (`blog/`,
  `public/`, `users/`): `storage.rules` and `/stored`. A denylist of area keys was patched twice
  in the 0.3.0 reviews and still missed a reader (`/stored`, which uses the Admin SDK and ignores
  `storage.rules`). Before claiming an area is unreachable, list every reader of the bucket.
- **Files served from the site's origin are sandboxed by Hosting**, not only by the function.
  Hosting's site-wide CSP replaces a CSP a function sets.
- **One bucket for now.** Areas could map to buckets later (owner: namespaces "might even
  correspond to buckets"); the allowlist is what keeps a shared bucket safe meanwhile.
- **Migration renames** (owner, 2026-10-01): existing files whose names `/blob` refuses get clean
  names on the way in. The originals stay, so old links keep working.

The `blob` *capability* in manifests is superseded by this; the installer says so. Reviews:
`reviews/0.3.0-storage-areas*.md`.

---

## D22
**Setup: as few human steps as security allows; cloud IAM only from code.** *(2026-09-30, owner)*

The goal is the simplest setup possible without sacrificing security, and without leaning on
Google Cloud's (or anyone's) convoluted permission model. Our authority model (roles, grants,
tokens, storage areas) is data the platform owns. The cloud's IAM is plumbing.

- **The only human steps are the ones that are about a human:** creating the project and billing
  (money); enabling the Google sign-in provider (Firebase only creates its OAuth client in the
  console); and claiming the host (authority starts with a person signing in, D16).
- **Every cloud permission the platform needs is declared in code or applied by the provisioner**,
  never by hand afterwards. Endpoints declare `invoker: 'public'` and every deploy re-applies it;
  a one-off binding was lost twice in practice. A future signed-URL grant goes in the provisioner.
- **Deploying ships the whole host, then checks it from outside** (`bun run deploy`). A release
  that changes code and rules together must ship both.
- **Post-setup ceremonies become pages, not consoles:** a one-click `/claim` (#2489) and an
  install consent page (#2490). `configurator` power never leaves the browser.

Lands as: `functions/src/endpoint-options.ts`, `scripts/deploy.js`, `scripts/provision-sandbox.js`,
and the two board tasks.

---

## D23
**Render on store: pages and shared fragments are rendered when content is written, not when it
is read.** *(2026-10-01, owner)* Refines the SSR half of ROADMAP Phase 3 and D8.

Today every uncached visit re-runs several Firestore queries in `prefetch`: the page, `config/app`,
the visible-pages list for the nav, the blog cache. Its handlers once raced each other (fixed
2026-09-30). The sitemap streams every post on every request, uncached. Instead:

- **On write** (after the commit, from the hooks the registry already names), the affected
  artifacts are re-rendered **as the public user** and stored in a public storage area:
  - the **per-route page**: its `<head>` (title, description, social tags) and its own data;
  - the **nav fragment** (`appConfig` + visible pages): shared by every page, so it is stored
    once, not inlined. Otherwise renaming one nav page would re-render all ~850 pages;
  - the **blog-index fragment** (latest + recent posts), replacing `config/blog-cache` and its
    24-hour expiry;
  - **`sitemap.xml`** and the **RSS feed** (D20), rendered from a small per-post index
    (`{path, date, published}`) kept up to date on each write, not from a full scan.
- **Each content type declares what it affects.** A post edit re-renders its page and, only when
  published state/title/date/summary change, the blog index, sitemap and feed. A nav change
  re-renders one fragment.
- **Serving is reads only:** `prefetch` combines page + nav + blog-index (no queries) and returns
  it with CDN caching. A miss (e.g. a draft opened by direct link, or a route nobody has visited)
  renders once on demand and is stored. An unknown route has no page and is a real 404.
- **SSR is public by construction** (D10): nothing renders with a visitor's rights.
- **Failure is stale, never broken:** a failed render keeps the previous artifact and logs.
  Artifacts record the document versions they came from; a re-render-everything command (e.g. after
  a template change, or as a backstop) is cheap at blog scale.
- **Renderers are pure** (documents in, string out), tested without emulators, and are the natural
  first real use of stored ajs once it exists; `sitemap.ts` and the blog cache retire.
- **`prefetch` becomes a core platform function** *(owner, same day)*. Once it only reads stored
  artifacts it has no site knowledge, so every host gets it (it joins `PLATFORM_FUNCTIONS`), and
  `sitemap.xml` and the feed are artifacts it serves.
- **Markdown (and syntax highlighting) is a host capability**, not ajs *(owner, same day)*. The
  host offers a vetted, pure `markdown(source)` / `highlight(code, lang)` that renderers call;
  ajs renderers will call them like any capability. The engine is the same `marked` version and
  settings the client components use, so server HTML and client rendering cannot drift. Why: ajs
  refuses classes, `new`, callbacks and `for` loops, so `marked` cannot be transpiled, and a
  hand-written parser would have to match the client exactly (and tjs-lang#59 makes accumulating
  code silently wrong today; *fixed in 0.14.0, 2026-11-19*). Until stored ajs exists, the TypeScript renderers call `marked`
  directly, the same function the capability will wrap.

Board: #2698 (design + prototype).

## D24
**A post always names its author. The server fills an empty `author` from the writer's published
name, or refuses the write.** *(2026-11-13, owner)*

The editor set `author` from the signed-in user's name when it created a post, and sent `''` when
that name had not loaded yet. "From 1994 sprites to a game-ready 3D Character…" was published on
2026-11-12 with no byline, though the server had recorded the writer (`_by.name`) correctly.

- **Where:** the post collection's write transform. In the registry it is the `principal` derive op
  with the new `required: true`: `{ op: 'principal', to: 'author', field: 'name', required: true }`.
  `blog.ts`'s TypeScript `validate` mirrors it for the non-registry path.
- **Filled from** `principalIdentity`, the same name `_by` records. It is never an email address or
  one of the writer's contacts.
- **Refused** when the field is empty (blank counts as empty) and the writer has no publishable
  name. A writer with no name must type one.
- **A supplied author is kept.** Posting under another name (a guest post) stays possible; `_by`
  records who actually wrote it.
- **Rejected alternative:** falling back to `_by.name` at display time. It fixes the byline, but
  leaves stored data that every renderer (page, feed, client) has to remember to repair. The rule
  lives once, at write.
- **Existing posts are not migrated.** A post with an empty author gains one the next time it is
  saved.

Board: #4063 (found while deploying it).

## D25
**The HTML the server renders from content is written fresh from an allowlist of tags and
attributes, every text and value escaped. It never forwards a parser's serialization.**
*(2026-11-13, owner)* Refines D23's "server HTML and client rendering cannot drift".

A published post's page carries the post as plain HTML (`<article data-ssr>`), so a reader or
crawler without JavaScript gets the text (#4063). The client renders the same post with `<tosi-md>`:
`marked`, then tosijs-kilpi's sanitizer, in the browser that then displays the result. The server
has no browser. It parses with linkedom, which is not a spec-compliant HTML parser, and the
visitor's browser re-parses whatever the server emits. A gap between the parser that sanitized and
the one that renders is how mutation XSS gets past sanitizers. Run through both renderers, 114 of
860 production posts already came out with different markup. And this HTML is served to every
visitor before any client code runs, so a script that got through (an author account taken over)
would run for everyone.

- **The pipeline:** `marked` (the client's version, which a test pins), then kilpi under linkedom
  (the client's URL rules for `href` and `src`), then `render/markdown.ts`'s own serializer.
- **Allowed:** text-structure tags (headings, paragraphs, lists, quotes, tables, code, emphasis,
  links, images, `time`…) and a few attributes (`a`: href, title; `img`: src, alt, title, width,
  height; `td`/`th`: colspan, rowspan; `time`: datetime).
- **Unwrapped:** any other element, custom elements included. Its text is kept.
- **Dropped with their contents:** raw-text and foreign elements (`script`, `style`, `template`,
  `noscript`, `svg`, `math`…), embeds and forms. Comments are dropped too.
- **The parity that matters is meaning, not markup.** `ssr-parity.test.ts` checks that server and
  client give the same text, link targets and images. All 860 posts match. The server copy is
  plainer on purpose (no classes, no styling), and the client replaces it when it mounts.
- **Rejected:** serving linkedom's `innerHTML` (the parser gap above), and a second, hand-written
  Markdown parser (it would drift from the client's).
- **Scope:** every renderer that turns stored content into served HTML. The blog index and pages
  (#4063's next steps) use the same serializer.

Board: #4063.

## D26
**Realtime game rooms have one client interface and two backends, both built: the platform's own
host, and Firebase as an option for people who would rather pay Google. Rooms start relay-only.**
*(2026-11-15, owner)* Takes up SOVEREIGN.md §D. Brings §F's step 5 (rooms) forward, because there
is now a game to point at (Manta, #3374), as D13 asks.

- **Not a stopgap.** The platform's own host comes first and is the reference: a WebSocket on the
  Bun host (`adapters/bun/serve.ts`) with room state in memory. Firebase is built alongside it, as a
  supported option and as the test of how well Firebase does this.
- **Firebase's scale is a question, not a promise** (owner: "quite suspect"). Realtime Database
  documents a limit of roughly 1,000 writes per second per database instance. One room of 8 players
  sending 20 updates a second is 160 writes a second, so an instance holds only a handful of rooms,
  and more means sharding rooms across instances. Bandwidth is billed per GB. The Firebase backend
  is built to measure this (rooms per instance, cost per room-hour) before anyone is told it
  scales.
- **The Firebase backend is Realtime Database.** Cloud Functions end with each request and can't
  hold a socket open, and Firestore's listeners are closed by its deny-all rules.
- **One interface:** join, send, subscribe, leave. A game is written against it, never against
  Realtime Database or the socket, so it runs on either host unchanged.
- **Permissions are checked once, at join** (§D). Joining goes through our endpoint and the usual
  role checks, and only the platform writes a room's member list. Inside the room, only members
  can send. On Realtime Database a rule enforces that on every write, so removing a member cuts
  them off at once.
- **The exception, kept small:** until now every client read and write went through our functions.
  On the Firebase backend, room traffic does not. Realtime Database holds room traffic and member
  lists only, and its rules deny everything else. Nothing durable is kept there.
- **Results go through `/doc`.** A mission's outcome and the unlocks it earns are documents, saved
  through the normal write rules. Positions never reach a database.
- **Relay-only first:** players' machines run the game, and the server passes messages along and
  judges the results. It avoids §D's tick-rate ceiling, and the join and results path stays the
  same when game logic later runs on the server.
  - **The cost is cheating:** a client can report a result it didn't earn. Co-op and friends'
    games accept that. Unlocks are checked for plausibility before they are saved. Leaderboards
    and competitive play require every player's report to agree, or wait for game logic on the
    server.
- **Every room has limits:** a cap on message size and on messages per second, enforced by each
  backend (on Realtime Database, by its rules). This stops a member flooding the room, and it
  bounds the bandwidth a paying host is billed for.
- **Open:** where the room client lives; whether the own-host backend can run on Cloud Run, where
  a room's players are not guaranteed to reach the same instance; and the tick rate that game
  logic on the server can sustain (measure before promising one).

Board: #3374. **Amended by [D27](#d27)** (v1 is our host only; the client is `tosijs-rooms`).

## D27
**Rooms v1 is our own host only, on the preview box, and its players are guests the host signs
tokens for. The Firebase backend is deferred, not dropped.** *(2026-11-19, owner)* Amends D26,
and closes its first open question.

- **No Firebase in v1** (owner). `/room` is a host-only endpoint (`HOST_ONLY_ENDPOINTS` in
  `kernel.ts`): Firebase does not deploy it, because rooms there would have no socket until the
  Realtime Database backend exists. D26's reasoning for that backend stands; it is built when
  someone wants to pay Google for rooms, and its scale is measured then.
- **Where it runs:** the box the tunnel uses, at `rooms.dev.tosijs.net`. It is a rooms-only host
  (`adapters/bun/rooms-host.ts`): `/guest`, `/room` and the `/rooms` socket, on SQLite, and no
  other endpoint, so nothing else on the platform is reachable through it. It is compiled to one
  executable with Bun inside and runs as its own unprivileged systemd service behind Caddy
  (`scripts/deploy-rooms-host.ts`, dry run by default). Live since 2026-11-20.
- **Guests, not accounts** (owner: the first players will almost all be synthetic agents, so the
  host should issue tokens). `POST /guest` returns an HMAC-signed token that lasts as long as a
  room, 24 hours. A guest token proves only that its holder is the same guest as before, which is
  all a relay-only room gated by its code needs. A guest has no claims and can be given none, so
  guest identities must never be installed on a host that grants roles. Deleting the host's secret
  signs every guest out.
- **What that costs:** anyone can mint guests, so the limits do the work: the per-address rate
  limit (100 requests a minute, shared by `/guest` and `/room`; Caddy sets the address, so a client
  cannot claim another), 5 open rooms per guest, and an hourly sweep that deletes expired rooms
  and closes their connections. A swarm of agents from one machine shares one address's limit.
- **The client is `tosijs-rooms`** (its own repo, Apache-2.0), answering D26's "where the room
  client lives". It does not wrap `/guest`; a game or agent posts to it directly.
- **Still open:** room expiry is enforced by the hourly sweep, not at the moment a room expires;
  sign-in for real players (Firebase Auth tokens, or the host's own accounts) when a game needs
  identities that persist; and D26's Cloud Run and tick-rate questions.

Board: #3374.

---

## D28
**The blog and the asset manager are installable extensions of the core, built in this repo and
published from it as components. No `tosijs-blog` or `tosijs-assets` repos.** *(2026-11-27,
owner)* Amends D1 and ROADMAP's "move client out".

- **Why in the core's repo:** basic content management is part of almost any web app, so it
  belongs with the core rather than in more repos to manage (owner).
- **Why installable:** they are the reference extensions, the proof that the core is general. A
  host gets the blog by installing it (a manifest for its collections, rules and storage areas,
  plus its client components), not because the core has it built in. The start is already here:
  `manifests/blog.json` declares the blog's storage areas (#1136).
- **The rule that follows:** the core does not special-case the blog. Whatever the blog needs and a
  manifest cannot express is a gap in the core, to be closed in the core. The known gaps:
  - `post`, `page` and their rules are platform collections (`seed-configs.ts`, the registry),
    not the blog's manifest;
  - server code: render on store (D23) for pages, the blog index, the sitemap and RSS; the plain
    HTML of a post (D25); `/sitemap` and `/prefetch`. Install v1 refuses `functions` (D17), so the
    blog needs stored ajs or render hooks a manifest can declare;
  - delivering an extension's client: nothing yet says how a host gets an installed extension's
    UI (a package the site build imports, `/esm` modules, or a stored build).
- **The client code is product again.** D1's "not this repo's product, migration preparation"
  no longer holds for the blog, its editors and the asset manager. Generic pieces still go
  upstream to tosijs-ui.
- **Lands here:** D11 (one definition of published), and the tosijs-blog parts of D20 and D24.
- **Still open:** the package shape (subpath exports of `service-compris`, or separate packages
  published from this repo); and the order of the gaps, which ROADMAP will plan.

---

## D29
**Sites answer agents' searches themselves. `/.well-known/search` is a core feature, and it
returns exactly what an anonymous listing returns.** *(2026-11-28, owner)*

Cloudflare's Search for Agents (beta, 2026-11-25) gives a site a search endpoint so agents query
it instead of crawling it. It answers `GET /.well-known/search?q=…` (and the `QUERY` method, RFC
10008) in Markdown: ranked passages with their scores, never a generated answer. Four `agent:*`
meta tags in each page's head advertise it. Cloudflare documents it by example, not as a spec.
The platform serves the same contract itself, on every host it runs on, without Cloudflare.

- **Core, not the blog** (owner: a feature to provide "intrinsically"). Search works the same way
  for any collection whose documents are public pages, so it belongs to content management, and
  under D28 the core may not make it a blog feature. A manifest switches it on for its
  collections; the blog does so for `blog:post` and `blog:page`.
- **Search is public, as SSR is (D10).** The index holds what an anonymous listing returns and
  nothing else. It is built as the public principal, at one enforcement point, with the listing's
  own access check rather than a second one. A draft can be read by its link but is never listed,
  so it is never searchable; a page needs `public` and `visible`. Search over an author's own
  drafts would be a different feature.
- **A searchable collection declares its documents' public URL.** A hit must name the page it
  came from. Today the `/blog/<y>/<m>/<d>/<path>` pattern is written out in three places
  (`functions/src/sitemap.ts`, `functions/src/render/site.ts`, `src/blog.ts`), the kind of drift
  D8 names. The declaration is D8's route contribution: the sitemap, RSS, rendering and search all
  take the URL from it. Its form is the same question as D28's server-side gap (#4309 step 4), so
  the two are designed together.
- **Why not switch Cloudflare's on:** it crawls the rendered site once a day and converts the
  HTML back to Markdown, while the platform holds the Markdown source and knows the moment it
  changes. And the platform runs on Firebase and on its own Bun host; its features do not depend
  on one CDN.
- **Composes with D9:** the agent-facing surface (docs, LLMs.txt, and now search) is served by the
  platform, not bolted on per site.
- **Still open:** keyword ranking first, or keyword and semantic from the start (semantic costs
  an embedding call on every save); updating the index on write, as render on store does (D23);
  the meta tags in every rendered page, under a switch in `config`; answering
  `Accept: text/markdown` with a post's Markdown (Cloudflare's Markdown for Agents); and whether
  Firebase Hosting passes `QUERY` to a function at all.

Board: #4388.
