# Delivery: the same build, a strict policy, updates that ask

How a built app reaches a browser, for a program that has to be sure of it:
a build that is the same bytes wherever it is made, a hash that names it, a
Content-Security-Policy made from the build itself, and a new build that
waits until the person says so. Back to the [map](README.md).

```mote
// docs: whole
app "Mail" policy=strict connect="https://api.example.com" update=ask

state build = ""
state waiting = ""
state forced = false

// A newer build is on the server, fetched and checked, and waits.
on app.update(u: {build: string, forced: bool})
  waiting = u.build
  forced = u.forced

task
  build = app.build()

action change
  app.update()

column gap=8 padding=24
  text `Build ${build}` font-size=12 color=dim
  if waiting != ""
    row gap=8 align-items=center
      text `Build ${waiting} is ready`
      button "Change to it" press=change()
  if forced
    text "The app's loader was replaced without being asked." color=danger
```

```sh
mote build app.mote                 # writes dist/, and dist/build.txt; says the build's hash
shasum -a 256 dist/build.txt        # the same hash, by any tool
(cd dist && shasum -a 256 -c build.txt)   # every file is the one the list names
mote build app.mote --check dist    # is dist this program's build, byte for byte?
```

## Mental model

Whoever controls the page that is served controls everything the page can
reach: in an app that encrypts end to end, the keys. Three things narrow
that, and none of them is on unless the program says so, but for the first:

- **A build is a function of its source.** The same program and the same
  `mote` give the same bytes in `dist/`, in any folder, on any day, for any
  user. `dist/build.txt` lists every file a browser is sent with its SHA-256,
  and the SHA-256 of that list is **the build's hash**: one line to publish,
  and to hold a server's files against.
- **`policy=strict`** sends the page with a Content-Security-Policy made
  from the page as it was built: its own script and styles by their hashes,
  the origins the program lists, and nothing by `unsafe-inline` or
  `unsafe-eval`. A script that gets into the page some other way does not
  run, and what does run cannot ask anywhere the program did not list.
- **`update=ask`** makes an installed app keep the build the person agreed
  to. A newer build is fetched beside it, each file held against the new
  list, and waits until the page says `app.update()`.

What none of them can do is in [What this does and does not
give](#what-this-does-and-does-not-give): read it before relying on them.

## The same build every time

`mote build` reads the program's files (the entry, what it `use`s, its
packages, `assets/`, `public/`, `agents.mote`, `schema.lock`, an icon or a
share picture beside the entry) and writes `dist/`. Nothing else goes in:

| | |
|---|---|
| The time, the date, the time zone | Not read. No file of a build says when it was made. |
| Random numbers | None. The names with a hash in them (`assets/logo.1a2b3c4d.png`, a battery's `assets/zip.1a2b3c4d.wasm`) are hashes of the files' contents. |
| The folder, the user, the machine's name | Not written anywhere. A source map names each file by its path from the entry's folder (`../core/dim.mote`). |
| The order a file system lists a folder in | `public/` is read in the order of its names. |
| The order of the compiler's own tables | Whatever is written from one is sorted first. |
| The environment | `mote build` reads two settings, and both are for working on Mote itself: `MOTE_RUNTIME` (a runtime folder to read instead of the one inside the compiler) changes what is built, so leave it unset; `MOTE_PRETTY` only colours messages. `HOME`, `TMPDIR`, `LANG`, `TZ` change nothing. |

What a back end reads when it *runs* is not the build's: `MOTE_URL`,
`MOTE_FRAME`, `MOTE_DATA` and the rest are [settings of the
deployment](back-end.md#running-it), and two servers with different
settings run the same `dist/`.

**One thing did vary, and no longer does.** A back end that says
[`app.access()`](back-end.md#what-the-back-end-is) carries the access report,
and the report named the program by the path the command line gave: `mote
build /home/ada/mail/app.mote` and `mote build app.mote` wrote a different
`server/main.js`. It is named by its file alone now (`app.mote`).

**And a second, in pages a build draws.** A program that says
`render=ahead` and has no back end of its own has its pages [drawn where it
is built](back-end.md#a-page-drawn-ahead), by a back end started for the
moment. That back end wrote its own address into what a shared link shows
(`og:url`, the canonical link, the picture's address): this machine's, at a
port taken for the moment, so `http://127.0.0.1:50115/` in one build and
`:50122` in the next, and no address of the site's in either. Those tags are
left out of a drawn page now. A site that knows where it will live says so,
and has them: `url="https://…"` on `app`, or `MOTE_URL` set as it is built
(the one setting of a deployment that such a build reads, because it runs
the back end to draw).

What the page's own script reads as it is drawn (a file of `public/`) is the
same every time, and so are the pages; a program whose page shows the time
of day as it is drawn draws a different page each time, and no build can
make that the same.

### The compiler, and the batteries

The promise is about what `mote` writes, so the other half is which `mote`.
Two builds agree when they were made by the same compiler: the same commit
of Mote, built by the same `rustc`.

- **The batteries** (`batteries/*`, Rust compiled to wasm) are built from
  source by `rustc` alone when the compiler is built, and carried inside
  it; a build writes them out as `assets/<name>.<hash>.wasm`. They are not
  checked in, with one exception: `batteries/sqlite/sqlite3.wasm` is SQLite's
  own build, checked in and pinned. So the wasm in `dist/` depends on the
  `rustc` that built the compiler. With one `rustc`, two checkouts in two
  folders give the same wasm, byte for byte (the hashes in the files' names
  say so at a glance).
- **The compiler binary** itself is not promised to be the same bytes on
  two machines (its paths and its host are in it); what it writes is.
- **To pin it**, name the `rustc` in whatever builds your compiler
  (`rustup toolchain install 1.89.0`, `cargo +1.89.0 install --path
  compiler`), and publish the Mote commit and `rustc --version` beside the
  build's hash. Mote does not ship a `rust-toolchain.toml`: it builds with
  any recent stable `rustc`, and which one is a deployment's choice.

### Checking it

```sh
mote build app.mote --out dist           # the last line but one: dist/build.txt  the build's hash: 9c1f…
mote build app.mote --check dist         # on another machine, with the folder the first one made
```

`--check dir` builds the program apart (into a folder beside `dir`, removed
after) and holds every file of the two against the other: `server/` and all.
Status 0 and one line when `dir` is this program's build with nothing more in
it; status 1 and a line for each file that `differs`, is `missing`, or is
`extra` (there, and no file of the build: a script someone added, say). It
writes nothing into `dir`.

To check a running site without its `dist/`, fetch `build.txt` and each file
it names, and run `shasum -a 256 -c build.txt`: see [what a server may
change](#what-a-server-may-change) for the one file that can differ.

## build.txt and the build's hash

`dist/build.txt` is written last, from the files as they stand in the
folder: a line a file, its SHA-256 in hex, two spaces, its path, in the order
of the paths. It is the format `shasum -a 256` writes and `shasum -a 256 -c`
checks.

```text
c3d7ee7d7bb57d369556c9c18aa40b4802e8e08b941cb6c93be6047f85aada13  agent.json
de2bea0f513f451710664bcb655f4cd4a85b302146744b13b5aae3b6a296232b  assets/badge.a780e22b.png
10e2c7e782246444e1de63d4d3db9d9a7260ee2549a5b49d34dd2ea78a09fbf1  index.html
9428783ac8e77e261674c494d2c5e011054e5348c36a3f4b5f0c903167152c96  sw.js
```

| In the list | Not in it |
|---|---|
| Every file a browser may be sent: `index.html`, `sw.js`, the manifest, icons, `assets/`, the batteries, `mote.js`, `agent.json`, `llms.txt`, `404.html`, everything from `public/`, the pages a build wrote drawn. | `build.txt` itself. `server/` (the back end and its maps: never served). `Dockerfile`, `.env.example`, `_headers` (for whoever runs it, and the host). A `.gz` (a listed file as it travels). |

**The build's hash** is the SHA-256 of `build.txt`, 64 hex digits. `mote
build` prints it. A build with `--single` writes one file and no list; the
hash it prints is that file's own SHA-256.

| | |
|---|---|
| `app.build()` | The build's hash, a string. In a page: the SHA-256 of the `build.txt` the page is given, which is the service worker's kept copy once there is one (so it names the build the page really came from, also when the server has moved on), and the server's before that. On the back end: of the `build.txt` beside it. `""` where there is no list: `mote dev`, a page that is one file, a server that cannot be reached before a worker kept the list. It waits, and does not fail. Not in a worker (`off fn`): ask in the page and hand it over. |

A page that says `app.build()` has `build.txt` in the service worker's list,
so the answer is there offline. The hash is not written into the page: it
is the hash of a list the page's own hash is in.

`app.info().build` ([back-end.md](back-end.md#what-the-back-end-is)) is
another name, older and shorter: sixteen hex digits over the page and the
back end's code, for telling deployments apart in an admin page. It is not a
cryptographic hash and cannot be worked out from `dist/` with a tool; use
`app.build()` for anything a person is to check.

## The strict policy

```mote
app "Mail" policy=strict connect="https://api.example.com wss://relay.example.com" images="https:"
```

| Setting | |
|---|---|
| `policy=strict` | The page is sent with the policy below. Unsaid, a page is sent as it always was ([`frame-ancestors` and `nosniff`](back-end.md#running-it) from a back end, nothing from a static host), and not one byte of it differs. |
| `connect="…"` | Where else the page may ask (`net`, a WebSocket, an `EventSource`): origins with spaces between. The page's own origin is always there. |
| `images="…"`, `media="…"` | Where else pictures, and sound and film, may come from. Its own origin, `data:` and `blob:` are always there. |
| `frames="…"` | What the page may show in a frame. Unsaid: nothing. |

A source is an origin (`https://api.example.com`, `wss://relay.example.com:8443`,
`https://*.example.com`) or a scheme alone (`https:`, `wss:`, `data:`,
`blob:`). A path, a `*` alone and a word in quotes (`'unsafe-inline'`) are
refused (`H366`), and so is a list in an app that does not say
`policy=strict`.

### What is sent

The policy is read off the page once it is whole, so it says what this
build needs and no more:

| Directive | What it is, and where it comes from |
|---|---|
| `default-src 'none'` | Whatever is not named below is refused. |
| `script-src` | The hash of each inline script of the page: the one module that is the app, and the two or three lines beside it (the service worker's registration, a scheme restored before the first paint, the agents' stub). `'self'` only where the page loads a script file of its own (`mote.js` for [agents](agents.md): `agents=off` takes it away; an [`extern js`](js.md) file). `'wasm-unsafe-eval'` only where the page carries a part that runs a battery. The exact address of each [`extern script`](js.md#another-sites-script). Never `'unsafe-inline'`, never `'unsafe-eval'`. |
| `style-src` | The hash of the page's one `<style>`. No `'unsafe-inline'`: a `style=` in text, and a `<style>` put in later, do not count. |
| `img-src`, `media-src` | `'self' data: blob:` and the program's `images=`, `media=`. |
| `font-src` | `'self' data:`. |
| `connect-src` | `'self'` and the program's `connect=`. `blob:` where the page makes addresses of bytes it holds (`bytes.url()`), which it may then read back. The open line of `live` values and events is a WebSocket to the page's own origin: `'self'`. |
| `worker-src` | `'self'` (the service worker) and `blob:` where the page has workers (`off fn`s, a chart, `sql`: each is made from text the page carries). A worker is held to the page's policy. |
| `manifest-src 'self'`, `form-action 'self'` | |
| `base-uri` | `'none'`; `'self'` where the page has a `<base>` (`routes=paths`). |
| `frame-src` | The program's `frames=`, when it has any. |
| `frame-ancestors` | Who may show the page in a frame: `'self'`, or what [`MOTE_FRAME`](back-end.md#the-open-line-origins-and-frames) says. A header only. |

And beside it:

| Header | |
|---|---|
| `Strict-Transport-Security: max-age=63072000; includeSubDomains` | From a back end, only on an answer to a request that came over https (there, or at a proxy that says `x-forwarded-proto: https`). |
| `Referrer-Policy: no-referrer` | No address of the app is told to another site. |
| `Cross-Origin-Opener-Policy: same-origin` | A window the app opens on another site, and one that opened the app, hold no handle on it. |
| `Permissions-Policy` | The camera and the microphone, sharing the screen, and where the device is: each only where the page carries the part that asks for it. The sensors, payment, USB, serial, HID, Bluetooth and MIDI: never. |
| `X-Content-Type-Options: nosniff` | As every answer of a back end has. |

### Who sends it

| Served by | |
|---|---|
| The program's back end | The headers, on every page it sends. The policy is the build's; `frame-ancestors` is the deployment's (`MOTE_FRAME`). |
| A host that only serves files | The build writes `_headers` (a build with no back end of its own): Netlify, Cloudflare Pages, Workers Static Assets and others read it and send the headers at every address; `mote serve` does too ([cli.md](cli.md#mote-serve)). On any other host, copy its lines into the host's own settings. |
| Anything at all | The page carries the policy itself, in a `<meta http-equiv=Content-Security-Policy>` at the top of its head, and `<meta name=referrer content=no-referrer>`. So the policy holds on a host that sends no header, and a header and the `<meta>` say the same. |

**What a `<meta>` cannot say.** The standard does not take
`frame-ancestors`, `report-uri` or `sandbox` from a `<meta>`, and
`Strict-Transport-Security`, `Cross-Origin-Opener-Policy`,
`Permissions-Policy` and `X-Content-Type-Options` are headers only. On a
host that sends none, the page is still held to its scripts, styles and
origins, and is not protected from being framed, from a downgrade to http,
or from another window's handle: put those headers in the host's settings.

`mote dev` serves the page as it always has, without the policy (it adds a
reload line and a source map of its own to every page). Build it and `mote
serve dist` to see it under the policy.

### What the runtime does another way

A page compiled by Mote already suited the policy: its styles are classes
in one `<style>`, a style that follows a value is set through the element's
own `style` (which no policy refuses), there is one script, and no text is
ever run as code. A few parts of the runtime wrote a `<style>` of their own
when first used, or made elements from text with `style=` in it: the code
`editor`, `terminal`, `flow`, a long list (`for … virtual`), `print(el)`,
and a chart's hover card. Under `policy=strict` those parts hand their
sheets to the page as constructed style sheets and set each element's style
through the element, so they look as they do without it.

The other way is in the runtime as a choice made when the program is built
(`if STRICT` in [the runtime dialect](../runtime/README.md)): a page that
does not say `policy=strict` carries none of it, and is the same bytes it
was before there was a policy to ask for.

### A page drawn ahead

With [`render=ahead`](back-end.md#a-page-drawn-ahead) the back end draws
each page it sends, and a style that follows a value would arrive as a
`style=`. Under the policy it does not: the styles the drawing's elements
had become rules of one sheet at the drawing's head, each element is given
a number the sheet knows it by, and the sheet's hash goes into that page's
policy, in its header and its `<meta>` alike. So each drawn page has a
policy of its own, differing in that one hash. A style whose words could
reach past its own rule (a brace, a tag, a comment, an escape, a quote left
open) is left out, and the element has it once the page has drawn itself.
The data a drawn page carries is in a block of type `application/json`,
which runs nothing and needs no hash. Where a build writes its pages drawn,
`_headers` names every page's sheet.

**A page sent at a route's own path.** Where routes are after `#` and a
route has [tags of its own](markup.md#a-shared-link), the back end answers
`/pricing` with the page, a `<base>` and one line of script that takes the
address to `#/pricing`. That line is the back end's own, made from the path
alone; under the policy its hash is in that page's `script-src`, and
`base-uri` is `'self'` there.

### What is refused

- **An origin that is not listed**: a call, a picture, a font, a film. The
  call fails as a call to a server that cannot be reached does; the picture
  is not shown. The browser's console says which directive refused it.
- **A script the build did not have**: one put into the page later, an
  `onclick=` in text, a file from another origin. `'self'` is in
  `script-src` only when the page loads files of its own, so a page with
  `agents=off` and no `extern js` runs its one hashed module and nothing
  else, whatever is on its origin.
- **A framed page made from text** (a `data:` address, `srcdoc`), and so the
  kit's `HtmlPreview`, `JSXPreview` and `WebPreview` of a page a model wrote:
  `frame-src` is unsaid, so `data:` is refused and the frame stays empty.
  Listing it (`frames="data:"`) is no way round: a frame made from text is
  held to the page's own policy as well as its own, so its scripts and its
  inline styles are refused, and what a model wrote shows unstyled. Show
  such a thing from another origin, and list that:
  `frames="https://sandbox.example.com"`. HTML that is to be shown and not
  run (a letter) needs neither: [`htmlframe`](text.md#htmlframe) cleans it
  and builds it in a frame of the page's own, styled, with nothing refused. (This is the one thing the
  playground's run refuses: its AI code demos.)
- **`extern js` in a page built `--single`**: such a page loads the file
  from a `data:` address, which the policy does not list. Build it as an app.
- **Sign-in or payment by another site's window or script** that the
  program did not list: list the script (`extern script`) and the origins
  (`connect=`, `frames=`).

### Seeing what was refused

The browser's `securitypolicyviolation` event says each refusal, and
`tests/real.mjs` gathers them when `VIOLATIONS=1` is set (and the browser's
own log, which has a worker's too): a line `refused by the policy: …` for
each, and the count. [testing.md](testing.md#violations-of-a-policy) has
the runs that hold the kit and the playground to "nothing refused".

## Updates that ask

Unsaid, a new build takes over by itself: the browser installs the new
service worker in the background, and it takes the app's windows. With
`update=ask` nothing changes until the page says so.

```mote
app "Mail" update=ask
```

| | |
|---|---|
| `update=ask` | An installed app keeps its build until the page says `app.update()`. (`update=auto`, or unsaid: as it always was.) |
| `on app.update(u: {build: string, forced: bool})` | A newer build is on the server, has been fetched and checked, and waits: `u.build` is its hash. Heard once for each build, by every window, also by one opened later. `u.forced`: see below. |
| `app.check()` | Asks the server now. The hash of the build that waits, or `""`. (It is asked by itself each time the page is opened.) |
| `app.update()` | The waiting build becomes the app's, the one before it is let go, and **every window of the app is loaded again**, on the new build. `false`, and nothing done, where none waits. |

All four are the page's; `on app.update`, `app.check()` and `app.update()`
are refused where the app does not say `update=ask` (`H369`).
`update=ask` with `render=ahead` is refused (`H368`): a page the back end
draws for each request is the server's build each time.

### How it is kept

The service worker of such an app names no build and no file. It is the
same bytes for every build of the program, so a new build is not a new
worker, and the browser has nothing to install over the old one. What it
keeps, in the browser's Cache storage:

- **A store a build**, named by the build's hash. It is filled from
  `build.txt`: each file listed is fetched, and its SHA-256 held against
  the list's. A build with one file that differs, or one that cannot be
  fetched, is not kept at all.
- **Which build is the app's now, and which waits.**

It answers every request of the app from the build that is the app's now:
a file of it by its path; an address in the app (a path with no file, that
is not a `server route`'s, a model's file or a call) with that build's page.
The network is asked only for what no build holds: calls, the open line, a
route of the back end.

Each time the page is opened, the worker asks the server for `build.txt`
(never from a cache). A list that is neither build's is fetched beside
them, checked, and marked as waiting; the windows are told. Nothing else
happens until `app.update()`.

| When | |
|---|---|
| The person never agrees | The app goes on as the build it has, for as long as the browser keeps its storage, also offline, also when the server no longer has that build's files: it has its own copy of every one, batteries and all. Its calls go to the back end that is there now, so [a back end must go on answering the pages it has sent](#pitfalls). |
| The server moves on twice | The newest build waits; the one that waited before it is let go. |
| The server goes back to the build the app has | Nothing waits any more. |
| Several windows are open | All run the one build. When one says `app.update()`, all are loaded again: a page that holds something unsaved should say so before it changes. |
| The first visit | There is no worker yet: the page comes from the server, and the worker then keeps the build the server has. |
| The browser clears the site's storage | The next visit is a first visit. |

### What a server may change

- **`index.html`, as a back end sends it.** A back end writes [what a shared
  link shows](markup.md#a-shared-link) into each page for the
  address it was asked at, so the page a browser is sent differs from
  `dist/index.html` in those `<meta>` tags, unless the app says its whole
  address (`url="https://…"`) and no route has tags of its own. The worker of
  an `update=ask` app asks for the file as built (it sends `x-mote-built: 1`,
  and so may you: `curl -H 'x-mote-built: 1' https://mail.example.com/index.html`),
  which is the file `build.txt` names.
- **`sw.js`.** The browser fetches the service worker's own file by itself,
  about once a day and when the page is opened, and installs one whose
  bytes differ, whatever the page says. Mote's own worker changes only when
  the compiler does (a newer Mote writes another, which finds the build the
  old one kept and goes on keeping it: the page is told nothing). Any other
  `sw.js` is the server's to send, and it takes the app's windows. The page
  cannot stop that. It can notice: when the worker that holds it is changed
  without `app.update()`, the page asks the new one which build it keeps,
  and an answer that is not the build the page runs is told to `on
  app.update` with **`forced: true`** and what it said (or `""`).

### A push handler under `update=ask`

A program's own [`on push.received`](back-end.md#a-push-the-apps-own-code-opens)
is a file of the build, `push.js`, listed in `build.txt` like the others,
which the worker loads as it starts (a browser lets a worker load a script
only then). The worker's own bytes stay the same for every build. Before the
worker hands a push to the handler it holds the handler's text against the
copy of `push.js` the build it keeps names (whose SHA-256 the list checked),
and runs it only if the two are the same: a handler of another build is
never run. When the browser fetches a `push.js` the server changed (it looks
when the page is opened), the worker it would make of it is turned away, and
the one there stays, with the handler of the build the app runs. When the
person agrees to another build (`app.update()`), the worker asks the browser
to look again, and the next worker is the new build's. A push that comes in
between is shown as the default notification, never by a handler of another
build.

## The installed app

What the browser makes of the app once it is installed, said on the `app`
line and written into `manifest.webmanifest`:

```mote
// docs: whole
app "Mail" id="mail" scope="/" share="text links image/* .eml" handles="mailto" opens=".eml" shortcuts="New message: #/compose; Inbox: #/inbox"

state given = ""

// A share into the app, a mailto: link, or a .eml file opened with it.
on app.handed(h: {how: string, title: string, text: string, url: string, files: picked[]})
  let names = h.files.map(f => f.name).join(", ")
  given = `${h.how}: ${h.title} ${h.text} ${h.url} ${names}`

column gap=8 padding=24
  text given
```

| Setting | In the manifest |
|---|---|
| `id="mail"` | `id`: the app's name to the browser, which stays when its start address changes. Unsaid, `./` (the start address, as before). |
| `scope="/"` | `scope`: which addresses are the app's, a path with a `/` at its end. Unsaid, `./`. |
| `share="text links image/* .eml"` | `share_target`: the app is offered in the system's share sheet. `text` and `links` take a title, a text and an address; each kind (`image/*`, `application/pdf`) or ending (`.eml`) is a kind of file it takes. |
| `handles="mailto web+notes"` | `protocol_handlers`: the links it opens: a scheme a browser lets a site handle (`mailto`, `tel`, `webcal`, `xmpp`, …) or one of its own that begins `web+`. |
| `opens=".eml .ics"` | `file_handlers`: the files the system opens with it, by their endings (each with its kind: `.eml` is `message/rfc822`). |
| `shortcuts="New message: #/compose; Inbox: #/inbox"` | `shortcuts`: on the app's icon (a long press, a right click), a name and the address it opens, `;` between them. |

**`on app.handed(h)`** hears each, as the page opens:

| `h.how` | What came |
|---|---|
| `"share"` | `title`, `text`, `url` as the sharing app gave them (an app may put a link in `text`), and `files`. The share is a `POST` to `./mote-share`, which the service worker takes: it keeps what came (in the database `mote:handed`), sends the page to `?mote-handed=<id>`, and the page takes it from there, once. |
| `"link"` | `url`: the whole link (`mailto:ada@example.com?subject=hi`). The page is opened at `?mote-link=…`. |
| `"file"` | `files`: what the system opened the app with (the browser's `launchQueue`). |

The files are [picked files](data.md#files-not-read-yet), not read yet:
`fs.text(f)`, `fs.bytes(f)`, `img.decode(f)` read one. The words the
address carried are taken out of it before the program runs. An app that
says none of `share=`, `handles=` and `opens=` and has `on app.handed` is
refused (`H434`: it would never be called).

**Which browsers.** Each of these works only in an installed app, and only
where the browser has it (as of late 2026):

| | Chrome, Edge (desktop) | Chrome (Android) | Safari | Firefox |
|---|---|---|---|---|
| `id`, `scope`, `shortcuts` | yes | yes | `scope` | no install |
| `share=` | Windows, ChromeOS | yes | no | no |
| `handles=` | yes | no | no | no |
| `opens=` | yes | no | no | no |

What `tests/all.sh real_sw_push` checks is Chrome's (a share posted to the
worker, a `mailto:` link, the manifest as Chrome reads it); the rest of the
table is the browsers' own word. A file handed by the system through
`launchQueue` is not tested: a headless browser installs nothing. Where a
browser has none of it, the app is what it is in a tab, and the handler is
never called. The manifest's other fields (`name`, `icons`,
`start_url`, `display`) are as they were.

## What this does and does not give

- **The first visit trusts the server.** Whatever it sends is the app.
  Nothing a page can do changes that: a browser has no way to pin a site
  before it has been there.
- **`update=ask` holds an honest server to its word, and not a hostile
  one.** With the app installed, a server that only changes the build's
  files changes nothing in the browser until the person agrees. A server
  that sends a different `sw.js` takes the app over at once; the page is told
  (`forced`), if the new worker leaves it time to be. So it protects from a
  release nobody was asked about, a deployment that went wrong, and a file
  changed on a host that does not control `sw.js`. It does not protect from
  whoever holds the origin.
- **The hash a page shows is the page's own word.** A hostile page shows
  whatever hash it likes. `app.build()` is for an honest app to say which
  build it is, and for a person to compare with what was published. The
  check that does not trust the server is made from outside it: fetch the
  files and `build.txt` with another tool, and hold them against a build
  you made yourself from the source (`mote build --check`).
- **The policy limits a script that got in; it does not keep one out of the
  build.** Its hashes come from the same build as the page: whoever can
  change the page can change the policy with it. What it stops is the rest:
  text that reaches the page as markup, a file put on the origin, a
  dependency that tries to ask another server.
- **Mote's own word is in it.** The policy trusts what the compiler wrote.
  [js.md](js.md) says where a program's own JavaScript goes past what Mote
  checks.

## Pitfalls

- **A back end must go on answering the pages it has sent.** With
  `update=ask` a page may be weeks older than the back end. Add to a `server
  fn` rather than changing what it takes, as for any API with clients you do
  not control; tell the person a newer build waits, and say so again.
- **A page that never opens never asks.** The worker looks for a newer
  build when the page is opened, and when the page says `app.check()`. An app
  left open for days should call it on a timer (`every 3600000`).
- **`includeSubDomains`.** The header says it for every name under the
  app's own. An app at `example.com` with an `http://old.example.com` beside
  it will lose that one in browsers that have seen the app.
- **A host that rewrites pages** (one that injects a script for analytics,
  or minifies HTML) breaks the page under the policy, and breaks
  `shasum -c build.txt`. That is the policy working. Turn the rewriting off.
- **`dist/` is not emptied by a build.** A file an older build left is not
  in `build.txt`, and `--check` says it as `extra`. Build into a new folder
  for anything you publish.
- **Origins, not addresses.** `connect="https://api.example.com/v1"` is
  refused: a policy takes an origin, and the browser would ignore the path
  after a redirect anyway.

## In the source

- `compiler/src/policy.rs`: SHA-256, `build.txt`, the policy read off the
  page, `_headers`.
- `compiler/src/pwa.rs` (`service_worker_ask`): the worker that keeps a build;
  (`Installed`, `manifest_with`): the installed app's manifest; (`More`): a
  push handler, buttons and the share target in the worker.
- `compiler/src/sw.rs`: `push.js`, what a push handler may use.
- `compiler/src/build.rs` (`delivery`, and where the page's head is made
  whole); `compiler/src/main.rs` (`build.txt`, `--check`).
- `compiler/src/sys.rs` (`pick`): `if STRICT`, `if ASK`, `if SWORKER`.
- `runtime/page/delivery.mote`: `app.build()`, the page's side of
  `update=ask`, the strict policy's ways (`CSPA`, `CSPH`), and `on
  app.handed` (`APH`).
- `runtime/server/delivery.mote`: the headers, a drawn page under the
  policy, `app.build()` on the back end.
- Tests: `real_build_same`, `real_update_ask`, `real_sw_push`, `real_policy`,
  `real_policy_ahead`, `real_policy_kit`, `real_policy_playground`.
