# The command line

`mote build`, `dev`, `serve`, `check`, `card`, `runtime`: flags, what each
writes, the folders a project has, and `mote.toml`. Back to the
[map](README.md).

```text
mote build [entry] [--out dir]   write an installable app into dir (default: app.mote, dist)
           [--single]            one HTML file: no manifest, no service worker
           [--api]               beside server/api.json (always written), openapi.json and client.ts
mote serve [dir] [--port n]      serve a built directory (default: dist, 4870)
           [--404]               an address with no file gets 404.html, with the status 404
mote dev   [entry] [--port n]    serve it and reload on every save (default: 4870)
mote check [entry] [--json]      report what is wrong, and the fix
           [--perf]              what is copied to workers, and what `mote dev` measured
           [--strict]            what is only a warning (a `server fn` with no `requires`) is an error
           [--access [Name]]     who may do what: every model operation, call and route with its rule, in
                                 words, and what is worth a look (one model or call: its name; --json: as data)
           [--disk]              what the back end keeps on its own disk, and what keeps each elsewhere
           [--against other]     against another program (its entry, or its dist/server/api.json): the models
                                 both keep in one database (MOTE_SQL), and its `extern server fn`s
mote migrate [entry] --plan      the SQL the models' last changes ask of a database, and nothing done
             [--drop Name.field] say that a removed field (or model: Name) may go, with what it held
mote migrate [entry] --to postgres [--data dir] [--dry-run] [--replace]
                                 move the data folder's SQLite stores into MOTE_SQL's Postgres, checked
mote restore <snapshot> <data>   put a snapshot's databases and files (MOTE_BACKUP) back into a data folder; stop the back end first
mote editor [name]               set an editor up for Mote: vscode, cursor, neovim, vim, helix, emacs…
mote api expand app.mote [Name]  the Mote an `api Name from "spec.json"` is made into (services.md)
mote tree app.mote [--json]      the file's syntax tree: every part, its kind, name, start and end
mote lsp                         the language server an editor talks to (editor-plugin.md)
mote card                        the language in brief (the whole of it: docs/README.md)
mote runtime [part] [--server]   the runtime's parts and their sizes, or one part's JavaScript
mote --version                   which version this is ("mote 0.1.0")
```

## Mental model

`mote` is one binary with nothing to install beside it: the compiler, the
runtime's source, the kit, the batteries' wasm, the icons and the card are
all inside it (`compiler/build.rs` embeds them when the compiler is built).
It needs no Node and no network. Only a program with a back end needs
something else at run time: [Bun](https://bun.sh).

The **entry** is one `.mote` file. If none is named it is `app.mote` in the
current folder. Everything else is found from it:

```text
my-app/
  app.mote            the entry
  parts.mote          brought in with `use "./parts.mote"`
  agents.mote         notes for agents (optional; agents.md)
  mote.toml           where packages are (optional)
  icon.svg            the app's icon (optional; or icon.png)
  assets/             files a page names: `image "hero.jpg"`, `asset("x.woff2")`
  public/             files that ship whole, as they are
  .data/              the back end's data under `mote dev` (made when needed)
  dist/               what `mote build` writes
```

Exit codes: 0 on success, 1 when the program has errors (or a file cannot be
written), 2 for a wrong command line.

## mote build

```text
mote build app.mote
dist/index.html  6262 bytes (4486 of JavaScript)
dist  9651 bytes in all, with icon-192.png, icon-512.png, manifest.webmanifest, agent.json, llms.txt, sw.js
dist/build.txt  the build's hash: 9c1f6f0c64c3a6b9a54d2a4f0c1f0e1d7b1b3f9d2f0a8c5e6d7b8a9c0d1e2f3a
```

Writes an installable app into `dist` (or `--out dir`):

| File | What |
|---|---|
| `index.html` | The page: HTML, its CSS, and one inline module of JavaScript (the runtime parts it uses, then the program). |
| `manifest.webmanifest` | Name, colours, icons: what makes it installable. |
| `sw.js` | The service worker. It stores the build when installed and answers from that store first, so the app opens offline (a page of a program drawn ahead is asked of the back end first, and taken from the store only offline). A new build is a new store, fetched in the background. |
| `icon.svg` or `icon.png` | The app's icon, if one sits beside the entry. With both, the SVG is the tab's icon and the PNG the home screen's (a phone takes no SVG there). Otherwise `icon-192.png` and `icon-512.png` are made: the app's first letter on its accent colour. |
| `assets/<name>.<hash>.<ext>` | The files in `assets/` that the page names. |
| `assets/<battery>.<hash>.wasm` | Each battery the program can use (`zip`, `img`, `pdf`, `syntax`, `search`, `re`, a chart's `plot`, `sqlite` with its glue as `assets/sqlite.<hash>.js`, …): the wasm as it is, under a name with its contents' hash in it. The page holds none of it and fetches each when something first calls it, once; a page that never calls a battery never downloads it. They are in the service worker's store, so an installed app has them offline. Serve them as `application/wasm`, compressed, and to be kept for good (`cache-control: public, max-age=31536000, immutable`), as the back end and `mote serve` do. |
| everything under `public/` | As it is, under the names it has. |
| `agent.json`, `llms.txt` | What agents are told ([agents.md](agents.md)). |
| `build.txt` | What names the build: a line for each file a browser is sent, with its SHA-256, as `shasum -a 256` writes it. The SHA-256 of this file is **the build's hash**, which `mote build` prints and `app.build()` gives ([delivery.md](delivery.md#buildtxt-and-the-builds-hash)). |
| `_headers` | Only with `policy=strict` and no back end of the program's own: the policy's headers, for a host that only serves files ([delivery.md](delivery.md#who-sends-it)). `mote serve` sends them, and never the file. |
| `server/main.js` | The back end, if the program has one ([back-end.md](back-end.md)). |
| `<route>/index.html`, `server/index.html` | For a program that says `render=ahead` and has no back end of its own: `index.html` and each written-out route's page are written drawn, with their words, for a host that only serves files; `server/index.html` is the page as built ([back-end.md](back-end.md#a-page-drawn-ahead)). Needs Bun where the build runs. |
| `server/main.js.map`, `server/page.map` | Source maps (version 3) of the back end and of the page's script, with a back end: what a fault's stack is read through, so that it names `.mote` lines ([back-end.md](back-end.md#where-a-fault-was-written)). Never served, and no `.gz`. |

With a back end it also prints what it answers, what stayed out of the
page, and how to run it:

```text
dist/server/main.js  8291 bytes: the back end, answering price, pay
  only on the back end, not in the page: secretPrice
  run it with: bun dist/server/main.js --port 4870
  for whoever runs it: dist/Dockerfile and dist/.env.example (2 setting(s) of the program's own); 3 file(s) also as .gz
```

### What a build writes for whoever runs it

Only for a program with a back end. All of it is text the compiler composes
from the program: nothing is downloaded, nothing is run.

| File | What |
|---|---|
| `<file>.gz` | Beside each text file of the page of 1 KB or more (`.html .js .mjs .css .svg .json .webmanifest .txt .xml .map .md .csv`), and each battery's `.wasm`: the same bytes, gzipped by the compiler's own deflate. The back end sends it to a browser that takes gzip ([back-end.md](back-end.md#running-it)). A `.gz` an earlier build left beside a file that no longer gets one is removed. |
| `Dockerfile` | The built folder in a container: `FROM` a named version of the Bun image (never `latest`), the folder copied to `/app`, `MOTE_DATA=/data` as a volume, the user `bun` (not root), `HEALTHCHECK` on `/healthz`, `STOPSIGNAL SIGTERM`, `CMD ["bun", "server/main.js"]`. Build it from `dist`: `docker build -t app dist`. Everything in `dist` is copied, so keep secrets out of it and give them with `--env-file`. |
| `.env.example` | Every `env("KEY")` the program reads with its key written out, each with where it is read (`# app.mote:12`), then the `MOTE_*` settings this program's back end reads (and `PORT`), each with what it is when unset. A key that is worked out (`env(name)`) cannot be listed. |

The back end never serves `Dockerfile`, nor any file whose name begins with
a dot; `mote serve` does not either. Both files are written again by every
build.

**The same source and the same compiler give the same bytes**, in any
folder, on any day ([delivery.md](delivery.md#the-same-build-every-time)).
**`--check dir`** builds the program apart and says whether `dir` is that
build, byte for byte, with nothing more in it: status 0 and a line, or
status 1 and a line for each file that `differs`, is `missing` or is
`extra`. It writes nothing into `dir`.

**`--single`** writes one HTML file and nothing else: no manifest, no
service worker, no icons. Assets are carried inside the page, and so is
every battery the program can use (deflated, as base64: a page with
`Markdown` on it is some 130 KB larger for `syntax` and `re`, which a build
that is not `--single` keeps out of the page). It opens from
`file://`. `public/` files are not copied. (A back end's `server/main.js`
is still written if the program has one.)

A page with nothing dynamic on it ships no JavaScript.

## mote dev

```text
mote dev app.mote --port 4870
http://localhost:4870
```

Serves the page and reloads every open tab when a source file is saved
(any file the entry reaches with `use`, and `agents.mote`). Errors are
printed, and shown in the page in place of the app.

- Files with an extension are served from `public/`, then from beside the
  entry (so `assets/hero.jpg` is served as it lies). A battery's file
  (`assets/zip.<hash>.wasm`), which a build would write, is answered from
  the compiler's own copy: the page fetches its batteries as a built one
  does, when each is first called.
- A program with `server fn`s gets its back end too: run with Bun on the
  next port up (4871), started again on every change, with `/rpc/…` passed
  on to it. Its data is in `.data` beside the entry unless `MOTE_DATA` says
  otherwise. Without Bun the page still loads and its calls fail with a
  message that says so. What the back end logs shows in this terminal, and
  a fault in a `server fn` tells the page its own message (a built back end
  keeps it in its log: [back-end.md](back-end.md#server-fn)).
- The page times every worker call and posts the totals back once a second,
  for `mote check --perf`.

It listens on 127.0.0.1 only.

## mote serve

`mote serve dist --port 4870` serves a built directory as any static host
would. It does not run a back end: for that, `bun dist/server/main.js`.
A file whose name has its contents' hash in it (`assets/logo.1a2b3c4d.png`,
a battery's `assets/zip.1a2b3c4d.wasm`) is sent to be kept for good
(`immutable`), everything else to be asked for each time; text and wasm go
gzipped to a browser that takes it (the `.gz` a build wrote beside the
file, or packed as it is sent); `.wasm` is `application/wasm`, so a battery
is compiled as it arrives.

A `_headers` file in the folder (a build with `policy=strict` and no back
end writes one; so does the docs site's static build) is read as Netlify
and Cloudflare read it: each rule whose pattern matches the path (`/*`,
`/assets/*`, `/docs/:page`) adds its headers, in the order of the file; a
header two rules set is joined with a comma; `! Name` under a rule takes
away what the rules above it gave of that header; and a `Cache-Control` it
gives stands in place of `mote serve`'s own. The file itself is never sent.

An address with no file: `about/index.html` if the build wrote one (a page
[drawn at build](back-end.md#a-page-drawn-ahead)); otherwise, for a page
whose routes are paths, the page as built (`404.html`), with the status
200, as a host that sends every address the page does. **`--404`** answers
it as a host told to send `404.html` with the status 404 does (Workers
Static Assets' `not_found_handling: "404-page"`, GitHub Pages): the page
still reads its route there, and says it has none.

## mote test

`mote test app.mote` runs the program's `test` blocks
([testing.md](testing.md#tests-in-the-program)): the back end is built with
a harness where its listener would be, and Bun runs it, each test in a back
end of its own with its own database (in memory), accounts and clock.

```text
$ mote test app.mote
ok      a muted person cannot post
FAILED  a welcome is queued and sent
        app.mote:61: expect queued(welcome).length == 1
        it does not hold
        left:  0
        right: 1
2 tests: 1 ok, 1 FAILED
```

- `mote test app.mote muted post` runs the tests whose name has every word.
- A [`test "…" page`](testing.md#a-test-of-the-page) drives the program's
  page too: the page is built beside the harness, each such test's back end
  listens at a free port, and one Chrome (`$CHROME`, or the usual places) is
  started for the run. `MOTE_TEST_SHOW=1` shows its window.
- `--json` prints one line, `{tests: [{name, at, ok, ms, line, source,
  words, left, right}], passed, failed}`.
- It ends with status 0 if every test passed, 1 if one failed or the
  program does not compile (the diagnostics are printed, as by `mote
  check`), 2 if Bun could not be started.
- Nothing is written beside the program: what is built and what a test
  keeps are in a temporary folder, removed after. `MOTE_LOG=info` shows the
  back end's log lines among the tests' (it is `off` otherwise); the
  machine's own `MOTE_DATA`, `MOTE_SQL`, `MOTE_ACCOUNTS`, `MOTE_BACKUP` and
  `MOTE_JOBS` are not passed on.
- `mote check`, `build` and `dev` check the tests too, and write none of
  them.

## mote migrate

For a program with models ([models.md](models.md#changing-a-schema)).
`schema.lock` beside the entry holds what the last build made of the models
and every step a database takes to follow them; `mote build` and `mote dev`
keep it up to date by themselves when a change is one the data can follow.

```text
mote migrate app.mote --plan
schema 2: what a database would run
  back end  ALTER TABLE "Room" ADD COLUMN "colour" TEXT DEFAULT 'plain';
  browser   CREATE TABLE IF NOT EXISTS "Draft" ("id" TEXT PRIMARY KEY, "text" TEXT);
```

- `--plan` prints the SQL the source asks for since the lock, and writes
  nothing.
- With no flag it writes the lock, as a build would.
- `--drop Room.topic` (or `--drop Room`, a whole model) is the word that
  lets a removed field or model go, with what it held. Without it (or a
  `dropped` line in the source) the change is refused (`H115`).

The steps are run by the back end when it next starts, and by a page when it
next uses a local model.

### --to postgres

```text
MOTE_SQL='postgres://app:…@db.example.com:5432/shop' mote migrate app.mote --to postgres --data data
```

Moves an app's data from the SQLite files of its data folder (`--data`,
else `MOTE_DATA`, else `data`) into the Postgres database `MOTE_SQL` names,
where the same build then runs on it
([back-end.md](back-end.md#moving-an-app-from-sqlite-to-postgres)): the
schema made as the back end makes it, every store copied in batches that a
second run goes on from, each table counted and summed on both sides, and a
report. Stop the back end first: a data folder one has open is refused.

- `--dry-run` (or `--plan`) prints what it would do, and writes nothing.
- `--replace` drops this program's tables at the target, saying which, and
  moves the data again; without it a target that holds this program's data
  is refused.
- `MOTE_MOVE_BATCH`: rows a transaction (5000).
- Exit 0 when every table is the same on both sides; 1 when it refused or
  a table is not (the report says which); 2 for a wrong command line.

## mote restore

`mote restore data/backups/2026-11-20T14-00-00Z data` puts a
[snapshot](back-end.md#snapshots) back: every `.sqlite` of the snapshot's
folder is copied over the one of that name in the data folder, and the
write-ahead log beside each (`-wal`, `-shm`) is taken away. Stop the back
end first: one that is running has the old files open. Nothing else in the
data folder is touched.

## mote check

`mote check app.mote` compiles without writing anything. It prints nothing
and exits 0 when the program is right, but for one line on stderr for each
place the compiler's checks stop: `mote: outside what is checked: extern js
"./glue.js": mapOf, pay` and `… extern script "https://…"` ([js.md](js.md);
`mote build` and `--access` say the same). Otherwise each problem is one line,
and the exit code is 1:

```text
app.mote:1:6: error[H020]: unknown name `Hello` (quote it: "Hello")
```

`file:line:col: error[id]: what is wrong (the fix)`.

In a terminal each one is followed by its line, with what is wrong
underlined (to a pipe or a file, the one line alone; `MOTE_PRETTY=1` or `0`
says which):

```text
app.mote:2:6: error[H020]: unknown name `Hello` (quote it: "Hello")
 2 | text Hello
   |      ^^^^^
```

`--json` gives each as `{file, line, col, end_line, end_col, id, message, fix}`
(the end is the column just past what it is about, where the
[syntax tree](#mote-tree) knows it).

**A warning** is what does not stop a build: what is worth changing, and
what is not refused yet and will be. There are three: something that waits
inside an [`atomic`](back-end.md#nothing-but-the-data-waits-inside-atomic)
block on the back end and is not the data (`H144`), a `server fn` with
no `requires` in a program where people sign in (`H134`,
[back-end.md](back-end.md#rules)), and a rule whose test is the same answer
for everyone (`H162`, [models.md](models.md#rules)). Each is written to standard error in the
same form, with `warning[id]`, and the exit code stays 0:

```text
app.mote:56:8: warning[H134]: `promote` has no `requires`: anyone who reaches the back end may call it, …
mote: 1 warning: nothing is refused yet (`mote check --strict` refuses them)
```

`--json` lists warnings with `"severity": "warning"` (an error has no
`severity`). `mote build` and `mote dev` say them in one line for each kind
and go on. **`--strict`** makes each an error: exit code 1. Use it in a
project's checks once its fns all say who may call them.

**`--against other`** holds the program against another it works with:
`other` is that program's entry file (compiled, nothing written) or the
`dist/server/api.json` its build wrote. Give it once for each. Both are
checked; then two things are compared, each only where there is something
to compare:

- **The models both declare**, for two programs that are to keep them in
  [one database](back-end.md#several-apps-one-database). Where they
  disagree is said, a line each:

  ```text
  mote check pro/app.mote --against customer/app.mote
  `Price.cents`: `int` in pro/app.mote, `string` in customer/app.mote: the two keep it differently
  ```

  It is what the later of the two to start would be refused for. (A field
  only one declares is fine where it may be none, or has a default that is
  a value: the column has that default too, so the other program's rows get
  it.) Models are compared against an entry file only: an `api.json` says
  a model's rows as a page is given them, not how they are kept, and for
  one that lists a model this program declares too a line says so.
- **Its `extern server fn`s**, each against the back end that answers it
  ([back-end.md](back-end.md#another-back-end)): one line (`H123`) for each
  call that is not there, takes other parameters, returns something else,
  or is open to pages. With several `--against`, a call is looked for in
  all of them.

The exit code is 1 when either found a difference. When what was compared
fits it is 0, with a line for each kind saying what was: `both declare
Price, Staff, and agree`, `planner/app.mote: 3 `extern server fn`s fit
what the other back end declares`. A program with no `extern server fn`
is not wrong for that, nor one that shares no model; only when there is
neither (nothing to compare at all) is that said, and the exit code 2.
With `--json`, one list of both kinds:

```json
[{"kind":"model","against":"customer/app.mote","message":"`Price.cents`: …"},
 {"kind":"extern","id":"H123","message":"`receiveKitchen`: …"}]
```

**`--access`** prints who may do what
([back-end.md](back-end.md#who-may-do-what)): every model operation as a
page may ask for it, every `server fn`, route and call room, and the
runtime's own doors, each with its rule and who that admits in words; then
"Worth a look", facts about the rules set side by side:

```text
Note  (app.mote:14)
  read, remove if exists(Seat, {room: room, who: me})
            = whoever has a `Seat` row (who: me) with room: this row's [not tested here: guest]
  add     if exists(Seat, {room: room, who: me, guest: false})
            = whoever has a `Seat` row (who: me) with room: this row's, guest: false
…
WORTH A LOOK (4)
  2. `exists(Seat, {who: me, …})` alone decides some writes, and not others
     it is all that is asked of who, for: Note.remove
```

`--access Note` (a model) or `--access join` (a call) prints that one, with
what is worth a look about it; a name the back end does not have is exit
code 2. `--access --json` is the same as data. It is a report: the exit code
is 0 for any program that compiles, however much is worth a look, and a
program with no back end is told so in a line.

**`--disk`** prints what the back end keeps in its data folder (the
models' database, accounts, the notifications' key, stored files, logs
and facts, and what its own code writes there with `fs`, `sql.open`,
`net.send(…, {to})` or a route's `{file}`, with the calls that do it),
each with the setting that keeps it elsewhere: what a container whose
disk does not last would lose ([back-end.md](back-end.md#containers-with-an-ephemeral-disk)).
`--disk --json` is the same as data.

**`--json`** gives the same as data, `[]` when there is nothing:

```json
[{"file":"app.mote","line":1,"col":6,"id":"H020","message":"unknown name `Hello`","fix":"quote it: \"Hello\""}]
```

`fix` is `null` when there is none. The ids are stable: tools may match on
them.

**`--perf`** says what crosses to workers and what it costs
([reactivity.md](reactivity.md#workers)):

```text
copied to a worker on every call (the page could use them again):
  perf/app.mote:24:20: `b` in `zip.gzip(…)`
  A value is moved, not copied, when it is a `let` that only ever holds what a
  battery, a worker fn, `net.bytes` or `fs.bytes` just made, and this is its last use.
in a worker when an action calls them: heavy, tiny
kept on the page by `main fn`, or by `fns main` said once for a file or a package (else in a worker): steady
measured in `mote dev`, for each call:
  fn tiny      12 calls  work   0.00 ms  messaging   0.05 ms  messaging dominates: `main fn tiny` keeps it on the page
  fn heavy      1 call   work   3.60 ms  messaging   0.10 ms
  zip           1 call   work   2.40 ms  messaging   0.10 ms
```

The first part comes from the source alone: what is copied, then where the
page's own fns run (those in a worker; and those that loop and use only their
parameters, so would be, but are kept on the page by `main fn`, a file's
`fns main` or `mote.toml`). Then, where there are any, the `live` lists
kept on a model's `find` with no `limit` and no `last`
(`live lists with no bound: app.mote:12:1: \`all\` keeps \`Msg.find(…)\` …`):
each is sent whole, a thousand rows at most, when a page first asks
([models.md](models.md#what-a-write-sends-a-page)). Then, of the back end:
a model's operation or `sql.run` inside a loop of a back-end fn (a `for`, a
`while`), one query each turn where one for them all would do (`P003`:
`` `Order.get(…)` in a loop, in `sums`: one query a turn ``); and a `server
live fn` that reads who is asking (`me`, `auth.me()`), whose value is each
reader's own, so it is run again for every page that keeps it, after every
write it reads (`P004`). These are notes: the same loop over a handful of
rows, or seeding, is fine. The last is there after the
entry has run under `mote dev` and the page has been used; the measurements
are kept in a file in the system's temporary folder, per entry. With
`--json`: `{"copied": […], "live_lists_with_no_bound": […], "back_end": […], "in_a_worker": […], "kept_on_the_page": […], "measured": … }`.

### The ids

| Range | About |
|---|---|
| `H001`–`H004` | Characters: tabs, indentation, unclosed strings. |
| `H010`–`H023` | Syntax, unknown names (`H020`), names declared twice (`H022`). |
| `H030`–`H032` | Writes: a fn or binding that writes (`H030`), assigning a derive (`H031`). |
| `H040`–`H049` | Markup: unknown tag (`H040`), unknown attribute (`H041`), components (`H044`, `H046`), icons (`H045`), `app` settings (`H047`). |
| `H060`–`H074` | Types: a missing type (`H060`, `H061`), a value that may be none (`H062`), no such field or method (`H063`), wrong arguments (`H064`), operators (`H065`, `H066`), a type that does not fit (`H067`), what cannot be shown (`H069`), handlers (`H070`, `H071`), a missing prop (`H072`), unknown type (`H073`). |
| `H080`–`H084` | Calls that can fail (`H081`), waiting where it cannot (`H082`), `off fn` (`H084`). |
| `H101` | A `shortcut` line: no chord, nothing to run, a key's name that is not one. |
| `H102` | Where fns run, said once: a `fns` line after the file's first fn or with a word that is not `main`, `off` or `auto`; the same in `mote.toml`, or a package it does not have. |
| `H090`–`H099` | Files and packages (`H090`, `H091`), assets, and what only the back end has (`env`, `proc`, `fs.folder`, `detach`) (`H092`), the back end (`H093`–`H097`), `surface` (`H098`), `agents.mote` (`H099`). |
| `H110`–`H115` | Models: a declaration (`H110`), a rule (`H111`), what the page may not ask (`H112`), the wrong side (`H113`), `atomic` (`H114`), a change that could lose data (`H115`). |
| `H118` | `readonly`: a line that names no model of the back end, and a write of (or a hook on) a model the program only reads. |
| `H116` | Calls: `server call` (one, taking the room, answering a bool), `on rtc.message`, `on rtc.answer`. |
| `H120` | The back end's routes: a path or a method that is not one, a route that would hide what is already answered. |
| `H121`–`H123` | Calls between back ends: an `extern server fn` that is not well formed (no `at`, a type left out, a body) (`H121`), one called by a page, or a `requires peer` fn called by one (`H122`), a declaration that differs from the other back end's (`mote check --against`) (`H123`). |
| `H124` | Failures: what `fail` takes after its words (`{kind, data}`), a field a failure has not, what `on failure` and `server on failure` are handed (one value). |
| `H125` | The log: `log.debug`, `log.info`, `log.warn`, `log.error` take a message and a record of fields. |
| `H126` | `confirmed` where it cannot stand (not before a write of a `model`, in a `local model`, on the back end, twice in a model); `app … writes=` or `timeout=` with a value that is not one. |
| `H130`–`H133` | Guarding: a `rule` that is not well formed (a name taken, a parameter that is no id, text, number or bool, a rule that leads back to itself, the wrong number of values) (`H130`); after `requires`, a word that is no rule, or `anyone` or `peer` joined to a test (`H131`); what a rule's test or a `requires` cannot say or read (`H132`); a `limit` that is not a count per second, minute, hour or day, by `me`, `ip` or a parameter (`H133`). |
| `H134` | A warning: a `server fn` with no `requires`, where people sign in. |
| `H135`, `H136` | `secret`: its key is written out (`H135`); what it gave would leave the back end (`H136`). |
| `H137` | `auth.as` outside a `server fn` whose `requires` says who may. |
| `H140`–`H142` | Work that is done later: a `job fn` that is not well formed (an answer, bytes or a handle among its parameters, an option that is not one), `.at`/`.in`, `server on jobFailed` (`H140`); a `server at` that names no time of day, day or zone (`H141`); a `job fn` or `jobs.…` called by a page (`H142`). |
| `H143` | A `test`: what `expect`, `as`, `clock`, `given`, `queued` and `sent` take; two tests of one name. |
| `H144` | A warning: inside `atomic` on the back end, something waits that is not the data. (Each warning is an error under `--strict`.) |
| `H145` | `migrate`: no name, two of one name, a block that waits on something other than the data. |
| `H150`–`H153` | [Usage](usage.md): an `app` line's `usage`, `dnt`, `visitors`, `paths`, `geo` or `vitals` that is not one of its words (`H150`); `usage=on` with no `server on usage` block to take it (`H151`); a `server on usage` block handed anything but the one batch (`H152`); a `track` whose name or properties it cannot keep (`H153`). |
| `H160`, `H161` | The back end's words for an admin page, said in a page or said wrongly: [`models.list()`, `models.of(name)`](models.md#models-chosen-at-run-time) (`H160`); [`app.info()`, `app.access()`](back-end.md#what-the-back-end-is) (`H161`). (`auth.list` and `auth.sessions` in a page are `H092`.) |
| `H162` | A warning: a rule whose test can never pass, or passes for anyone (`kind == "a" && kind == "b"`, `kind != "a" \|\| kind != "b"`, `kind in []`). |
| `H163` | A test that reads what it may not: `secret("KEY")` or `env("KEY")` in a rule (it is `setting("KEY")`), `me.` anything but `email`, `setting.list` anywhere but after `in`, a setting's name that is not written out, an address with a capital against `me.email` ([back-end.md](back-end.md#a-rule-that-reads-a-setting)). |
| `H166` | `wants fn`: a program that does not declare a fn a package wants (said at its entry, with the line to write), one declared with other parameters or another type, two packages that want one name two ways, a `wants fn` without its types ([language.md](language.md#what-a-package-wants-of-its-taker)). |
| `H167` | `given env` / `given secret` in a test: the name or the value not written out, `is` left out, or the line inside a block ([testing.md](testing.md#settings-for-one-test)). |
| `H164` | `T.put(row)` whose row gives neither the key nor a whole `unique` set; `inc(n)` anywhere but a field's value in a model's change, on a field that is not a number, or in a row being added ([models.md](models.md#put-and-inc)). |
| `H165` | Rows taken together (`T.count(f, {by})`, `T.sum`, `T.min`, `T.max`) in a page or on a test's line; a field that is not written out, not the model's, hidden from the page, or not a number for `sum`; an option it does not have ([models.md](models.md#rows-taken-together)). |
| `H168`, `H169` | [A shared link](markup.md#a-shared-link): `description=`, `image=` or `url=` that is not a string (or a `url=` that is not a whole address), the description said twice (`H168`); a picture that is an SVG (said, or a `share.svg`/`og.svg` with no PNG beside it), one that is not there, one of the app's own with no `url=` in a program with no back end (`H169`; found by its name, a warning). |
| `H172` | A `route`'s `title=`, `description=` or `image=` that is not a string written out, a setting a route has not, one on `route "*"`. |
| `H173` | [`share`](data.md#share): in a `server fn`, or told anything but one record of `title`, `text`, `url` and `files`. |
| `H240`–`H246` | [JavaScript of the program's own](js.md): an `extern js` line that names no file, or whose block holds anything but `fn` lines without bodies (`H240`); a file that is not there or not `.js`/`.mjs` (`H241`); a declared fn the file does not export (`H242`); a parameter or the answer without a type (`H243`); an `off fn` that calls a fn of a file that does not say `off` (`H244`); an `extern script` whose address is not a whole `https://` one, an `integrity=` that is not a hash, or anything else on its line (`H245`); a field or a key written out that reaches the host's own machinery (`constructor`, `prototype`, `__proto__`, and the fns that read or change those: `getPrototypeOf`, `getOwnPropertyDescriptor`, `defineProperty`, …), or a name that runs text as code (`eval`, `Function`, `globalThis`, `self`, `import(…)`): what it is for is written in Mote's own words (a copy is `{...x}`, the keys `Object.keys(x)`), and `extern js` is the last resort (`H246`; [language.md](language.md#refused-with-the-fix-in-the-message)). |
| `H247` | [Routes as paths](markup.md#routes-as-paths): `routes=` that is not `paths` or `hash`; a `base=` that is not a path with a `/` at each end, or one in an app whose routes are after `#`. |
| `H248`–`H252`, `H254` | [Languages and formats](words.md): `t(…)` whose key is not written out or not one the first `words` has, or whose values are not exactly its `{name}`s, or in an app with no words or on the back end, and `words.choose` likewise (`H248`); a `words` whose language is not a language tag or is said twice, a key said twice, a count's forms with one that is not `zero one two few many other` or without `other` (`H249`); a later language that says a key or a `{name}` the first does not (`H250`); a warning, a key a later language does not say yet (`H251`); `fmt` with no such call, a currency that is not three letters, a `type`, `sign` or `lang` that is not one (`H252`); a line of words that is not `key = "text"` or forms, and a `from` file that is not there (`H254`). |
| `H253` | [Unsaved work](markup.md#unsaved-work): `root unsaved=` that is not a bool or the words to ask with. |
| `H355` | [The fragment](markup.md#the-fragment): `route.fragment`, `route.setFragment` or `route.takeFragment` in an app whose routes are after `#`, where what stands after `#` is the route. |
| `H356` | [`cors=`](back-end.md#other-origins-cors) on a route: an origin that is not a scheme, a host and perhaps a port (or `*`), origins that are neither written out nor a setting's list, a part it has not, a `maxAge` that is not a whole number of seconds up to 86400, `*` with `credentials: true`, one on an `OPTIONS` route. |
| `H170`, `H171` | [`try`](markup.md#try) in markup: a `try` with nothing under it, an `else` that follows no `if` or `try` (`H170`); `again` outside a `try`'s `else` (`H171`). |
| `H180` | `swipe=` and `pointermove=` on one element (or a component whose first element has the other): each would take the pointer from the other ([events.md](events.md#swiping)). |
| `H181`–`H183` | `swipes=` with no `swipe=` beside it (`H181`); a way that is not `x`, `y`, `left`, `right`, `up` or `down` (`H182`); `swipe=` where a drag is the element's own: a field, an `editor`, a `terminal`, a `flow`, a canvas of boxes (`H183`). |
| `H185` | [A file chooser](data.md#the-camera): a `camera` that is not `"back"` or `"front"` written there, or on `fs.pickMany` or `fs.pickFolder`; a `read` that is not `true` or `false` written there; another choice; a chooser in a `server fn`. |
| `H186` | [A file picked unread](data.md#files-not-read-yet) where only data goes: in a `persist` state, a model's field, a `server fn`'s or `job fn`'s parameter or answer. |
| `H187` | [`img.decode(b, {fit})`](media.md#a-photo-that-fits): a `fit` below 1. |
| `H188` | [`app … edges=`](markup.md#the-screens-edges) that is not `cover`. |
| `H190`, `H191` | [`newest`](reactivity.md#newest-a-later-run-calls-an-earlier-one-off): on an action that waits for nothing (`H190`); before the name, or on anything but an action or a named task (`H191`). |
| `H410`–`H413` | [Large files](data.md#large-files): in an `off fn`, a call that needs a window (`fs.pick`, `fs.pickMany`, `fs.pickFolder`, `fs.save`), or a `reader` or `writer` among its parameters (`H410`); `screen.awake` in a `server fn`, or given anything but a bool (`H411`); `progress` on `net.send` on the back end, or on `net.stream` (`H412`); a choice `fs.writer` has not (`H413`). |
| `H475`, `H476` | [Sealed files](data.md#sealed-files): `fs.open` or `fs.writer` given its choices as a value that says `seal`, or `fs.open` given choices that do not say it (`H475`: `seal` is written out where the call is, so that a file meant to be sealed is never written plain); `fs.writer` with `seal` and `append` both (`H476`: a sealed file is written whole). |
| `H270`–`H275` | [`pdf`](pdf.md): a call it has not (`H270`); called another way (`H271`); a word that is not one of its few (a page size, an alignment, a kind of table lines, a cap, a join) (`H272`); a turn that is not a multiple of 90 (`H273`); a colour that is not one (`H274`); a picture given as a text (`H275`). |
| `H195`, `H196` | `wheels=` with no `wheel=` beside it (`H195`); a way that is not `x` or `y` (`H196`) ([events.md](events.md#the-events)). |
| `H200`–`H214` | [Logs and facts](analytics.md#refused): `keep` (`H200`), a model's line in a log or fact (`H201`), `order` and `partition` (`H202`), a rollup (`H203`), `capture` in a fact (`H204`), a consumer (`H205`), asked in the page (`H206`), an operation it has not (`H207`) or its arguments (`H208`), a query's words (`H209`), `by` and `of` (`H210`), a field it cannot keep (`H211`), a name taken (`H212`), a field every log has (`H213`), values written into `sql` (`H214`). |
| `H216`–`H219` | [Long lists](markup.md#long-lists): `sticky=` on a `for` that is not `virtual` (`H216`); `virtual=` that is not a number of pixels (`H217`); anything on a `for` line but `key=`, `virtual` and `sticky=` (`H218`); `seen-margin=` with no `seen=` beside it, or one that is neither pixels nor a margin as CSS writes it (`H219`). |
| `H282`, `H283` | [A row of a long list](events.md#a-row-of-a-long-list): `scroll(list, {…})` with `row` and `index` both, or with `inside` (`H282`); `el.inView` and `el.shown` given what they do not take (`H283`). |
| `H215` | [Usage](usage.md#autocapture): an `app` line's `autocapture` that is not `on` or `off`. |
| `H220`, `H221` | [`wasm fn`](language.md#wasm-fn): something in it, or in a fn it calls, that cannot be compiled to WebAssembly (text, `json`, a fn handed in, a write to what it was handed, a name declared outside it) (`H220`); it does not say what it gives (`H221`). |
| `H231` | `app … lang=` that is not a language tag (`"de"`, `"pt-BR"`, `"zh-Hant"`): the language the page says when it has no [`words`](words.md) ([markup.md](markup.md#values-of-the-whole-page)). |
| `H232` | An `iframe` with `srcdoc` and no `sandbox`, or with `sandbox="allow-scripts allow-same-origin"`: what it holds would run as this page itself ([markup.md](markup.md#html-attributes)). |
| `H280`, `H281` | [A typed read of a table](tables.md#mental-model): the second argument of `csv.records`, `csv.open` or `xlsx.records` names no shape (`H280`); a field of the shape is a list, a record or bytes, which a cell cannot hold (`H281`). |
| `H291`–`H294` | [A connection of the back end's own](back-end.md#connections-of-its-own), written out: a port that is not one (`H291`); a `ws.open` address that is not `ws://` or `wss://`, or a `reconnect` that is neither `true` nor `{tries, wait, most}` (`H292`); how TLS is checked said of a connection that is not TLS, or a `pin` beside `verify: false`, which checks nothing (`H293`); a close code a program may not send (`H294`: 1000, or 3000 to 4999). |
| `H390`–`H393` | [`server listen`](back-end.md#accepting-connections-server-listen): one that does not say its port, says something a listener does not, or is not handed one connection (`H390`); a `limit` that is not a whole number of connections per second, minute, hour or day, or is by anything but `ip` (`H391`); `cert=` without `key=` or the other way, `tls` with no certificate, or `refuse=` on a `tls` listener (`H392`); two listeners on one port (`H393`). |
| `H296`–`H298` | [A picture on a material](scene.md#pictures-on-materials-map), written out: a `map` that is no picture (a number, a list) (`H296`); a `mapSize` that is not two numbers above 0, a `mapOffset` that is not two numbers, a `mapTurn` that is not a number (`H297`); on a `three.mesh`, a `grain` or `faces` that is not `"x"`, `"y"` or `"z"`, or `sides` that is not a material (`H298`). |
| `H290` | A `POST` or `PATCH` with `retries` and no `idempotency` key ([net.send](data.md#netsend)): tried again, it may be done twice. |
| `H300`–`H303` | [Patterns](text.md#patterns) written out, read when the program is built: one that is wrong, with the caret at its character (`H300`); one that asks for what `re` does not run, a backreference or a lookaround (`H301`); flags that are not `i`, `m`, `s`, `u`, `g`, `y` (`H302`); a replacement that names no group of its pattern, or a fn given to `re.replace` that does not give a text (`H303`). |
| `H313` | [`schema(X)`](language.md#a-shape-as-a-json-schema): what it names has no JSON Schema (a fn's type). |
| `H310`, `H311` | [`grammar Name from "file"`](text.md#a-language-of-your-own): the file cannot be read (`H310`); the grammar in it is wrong, said at its line in that file (`H311`). |
| `H316`, `H317` | [`webhook.check`](back-end.md#webhooks): a scheme it has no name for (`H316`, with the nearest); a scheme of your own with a field it has not, a value it does not take, or no `header` (`H317`). |
| `H318` | [`check(value, Shape)`, `schema(Shape)`](data.md#check): no value or no shape, a shape written as something that is not a name, `[T]` or `{field: T}`, or `extra` that is not `"keep"`, `"drop"` or `"refuse"`. |
| `H319` | [`net.lookup(host, kind)`](back-end.md#dns-records): a kind of record there is not (`"mx"`: write `"MX"`), or more than a name, a kind and options. |
| `H320` | [`net.send`'s `to` or a file as its `body`](data.md#to-and-from-files) in a page: the back end's alone. |
| `H321` | [`lock(name)`](back-end.md#lockname-one-run-at-a-time) in a page, outside a fn, or without a name; [`net.pace`, `net.breaker`](back-end.md#a-host-paced-and-a-breaker) with a host that is not a name alone, or without their options. |
| `H322`–`H325` | [`api Name from "spec.json"`](services.md#a-service-with-an-openapi-file): the file cannot be read, is not JSON, or is not OpenAPI 3 (`H322`); `only` names an operation the file has not (`H323`, with the nearest); something in the file that leads nowhere or is not read here (`H324`: a `$ref` to nothing or to another file, a parameter with no `name` or `in`, a path's `{name}` no parameter has, a body that is not JSON, a form or parts); a line of the declaration that is not one (`H325`: not `base`, `auth` or `header`; an `auth` that is not `bearer`, `basic`, `header "…"` or `query "…"`; no server and no `base`). |
| `H326` | [`assume`](reactivity.md#assume-shown-before-the-answer-taken-back-if-it-fails): its block holds something that is not an assignment, or it is written outside an action of the page (a `fn`, a `server fn`). |
| `H327`–`H332` | [`window: n`](models.md#a-long-list-a-window-at-a-time), a model's read kept a window at a time: written in a read that is not a `live` value's own (a `resource`, a `server fn`, a read inside another's arguments: `H327`); no `order`, or one not written out (`H328`); a `local model` (`H329`); beside `limit`, `last`, `after` or `with` (`H330`); a window that is not a whole number from 10 to 1000 (`H331`); no index of the model in that order, after the filter's fields (`H332`). |
| `H333`, `H334` | [`data name from "file.json"`](data.md#a-file-read-as-the-program-is-built): the file cannot be read, or the line names none (`H333`); it is not JSON (`H334`, said of the file). |
| `H335` | [`render=`](back-end.md#a-page-drawn-ahead) takes `ahead` or `page`. |
| `H400`, `H401` | [`richtext`](kit/richtext.md#attributes): a `value=` that cannot be written back, with nothing to hear the edits (`input=`, `change=`, `edit=`) (`H400`); a word in `tools=`, written out, that is not one of its tools (`H401`). |
| `H500` | [`richtext`](kit/richtext.md#several-people-at-once): `log=` with no `send=` (its own edits would never reach the others), or `send=` with no `log=` (it would send one unit and wait for ever). |
| `H365`–`H368` | [How the app is delivered](delivery.md): `policy=` that is not `strict` (`H365`); a list of the policy (`connect=`, `images=`, `media=`, `frames=`) with something that is not an origin or a scheme, that is not a string, or in an app that does not say `policy=strict` (`H366`); `update=` that is not `ask` or `auto` (`H367`); `update=ask` with `render=ahead` (`H368`). |
| `H395` | [`html.clean` or `html.text`](text.md#html) given an option it does not take, `images` that is not `"block"`, `"proxy"` or `"allow"`, or `images: "proxy"` with no `proxy`. |
| `H425`–`H429` | [A push the app's own code opens](back-end.md#a-push-the-apps-own-code-opens): `on push.received` not handed one value (`H425`); it, or a fn it calls, reads a state, a derive or a resource of the page (`H426`); calls an action, names a component, or uses what only a page has (`toast`, `route`, `fs`, `net`, `notify.ask`, an `extern js` fn, …) (`H427`); a battery of `crypto` (`argon2id`, `mlkem768`, `pow`) (`H428`); `on push.received` said twice (`H429`). |
| `H430`–`H434` | [The installed app](delivery.md#the-installed-app): `id=` or `scope=` that is not a string of the right shape (`H430`); `share=`, `handles=` or `opens=` with a word that is not one they take (`H431`); `on app.handed` handed something other than `{how, title, text, url, files: picked[]}` (`H432`); `shortcuts=` that is not `name: address` pairs (`H433`); `on app.handed` in an app that takes nothing (`H434`). |
| `H369`, `H370` | [`on app.update`, `app.check()`, `app.update()`](delivery.md#updates-that-ask) in an app that does not say `update=ask`, or `on app.update` handed something other than `{build: string, forced: bool}` (`H369`); `app.build()`, `app.check()` or `app.update()` given something, or the last two on the back end (`H370`). |
| `H336` | `page` is the browser of a [test of the page](testing.md#a-test-of-the-page): the test says `test "…" page`. |
| `H340`, `H341` | [`crypto`'s own keys](data.md#keys-of-the-pages-own): `crypto.argon2id`'s `bytes` is not written out as `true` or `false`, and what the call gives (bytes, or hex) depends on it (`H340`); `crypto.pow` is asked, in a number written out, for more than 40 zero bits or for a number that is not whole (`H341`). |
| `H460` | [Key bytes kept or shown](data.md#key-bytes-kept-or-shown): what `crypto.hkdf`, `crypto.pbkdf2`, `crypto.argon2id(…, {bytes: true})`, `crypto.x25519.shared`, `crypto.mlkem768.decaps` or `.encaps(…).shared` gave, a key pair's private part, a passkey's PRF output, or random bytes the program uses as a key, reaches a `persist` state, `store.set`, `db.set`, `log`, `toast`, `fail`, the page's text or a `server fn`'s arguments. The message names where it would go and where the bytes came from; the fix is to seal them, keep a handle, or say `crypto.reveal(x)` where it is meant. |
| `H461`–`H463` | [A derived key that is never bytes](data.md#a-derived-key-that-is-never-bytes): `crypto.hkdf`'s `as` not written out, not `"aes"` or `"hkdf"`, or `as: "aes"` with a `length` other than 32 (`H461`); an AES key given as HKDF's key material, or HKDF material given to `crypto.aes` (`H462`); `crypto.reveal` given a handle, which has no bytes to show (`H463`). |
| `H480` | [`body=`](back-end.md#how-much-may-be-sent-body) on a route or a `server fn`: not a whole number of bytes written out (1 to 2147483647), on a `GET`, `HEAD` or `OPTIONS` route (which is sent no body), or on anything that is not a route or a `server fn`. |
| `P001`–`P004` | Notes from `--perf`, not errors: a value copied to a worker; a `live` list with no bound; a query in a loop on the back end; a `server live fn` that reads who is asking. |

## mote tree

```sh
mote tree app.mote            # indented, one part a line
mote tree app.mote --json     # [{kind, name, start: [line, col], end: [line, col], children}]
```

The file's syntax tree as it is written: every declaration, statement, node of
markup, parameter, type and expression, each inside the part that holds it,
with its kind, its name where it has one (a declaration's, a tag's, an
operator) and where it starts and ends (the column just past it). Comments
are in it. It reads one file and does not check it: a file with mistakes
still gives the tree of what could be read.

```text
state total  1:1-1:16
  number 0  1:15-1:16
action go  2:1-3:32
  write =  3:3-3:32
    name total  3:3-3:8
    binary +  3:11-3:32
```

It is what a tool that reads or rewrites Mote stands on (and what gives a
diagnostic its end: `mote check --json` says `end_line` and `end_col` beside
`line` and `col` when the tree knows them). In a terminal, `mote check`
shows the line under each diagnostic with what is wrong underlined; to a
pipe or a file it writes the one line alone (`MOTE_PRETTY=1` or `0` says
which, whatever it writes to).

## mote api expand

```sh
mote api expand app.mote          # every `api … from` of the file
mote api expand app.mote Harbor   # one
```

The Mote an [`api Name from "spec.json"`](services.md#a-service-with-an-openapi-file)
declaration is made into, as the build makes it: the base and call fns, the
shapes, a fn for each operation. Printed, not built: to read what a call
takes, or to start a hand-written extension from (write it to a file, take
the `api` line out, and change what you like).

## mote drive

`mote drive` prints the driver for a built page, and `mote drive --out
mote-drive.mjs` writes it: one file with no dependencies, which starts a
Chrome, finds things on the page by the names the program gave them, sends
real taps, keys, holds and swipes, and comes back from each when the page
is at rest ([agents.md](agents.md#driving-a-mote-page)).

## mote editor, mote lsp


`mote editor vscode` (or `cursor`, `windsurf`, `vscodium`, `neovim`, `vim`,
`helix`, `emacs`) sets that editor up in one line; `mote editor` lists them.
`mote lsp` is the language server they run. Both are in
[editor-plugin.md](editor-plugin.md).

## mote card

Prints [card.md](card.md): the language in brief. The card is inside the
binary (`include_str!` in `compiler/src/main.rs`), so it matches the
compiler that prints it. It names these pages for the whole story.

## mote runtime

For work on the runtime itself ([internals.md](internals.md),
[../runtime/README.md](../runtime/README.md)).

- `mote runtime` compiles the runtime's Mote and lists each part with its
  size and what it needs; `ok: 73 parts, 183018 bytes`.
- `mote runtime core` prints one part's JavaScript.
- `--server`: the back end's parts instead of the page's.
- `--strict`: the part as a program that says `policy=strict` and
  `update=ask` carries it ([the dialect's `if STRICT`](../runtime/README.md#the-dialect)).

With `MOTE_RUNTIME=/some/folder` the compiler reads the runtime from that
folder (with `page/`, `shared/` and `server/` inside) instead of the one
built into it, for every command. So the runtime can be changed and tried
without building the compiler.

## mote.toml

A table read for `use "pkg:name/file.mote"`, and where fns run, said once:

```toml
fns = "main"                      # the project's own files: plain fns stay on the page

[packages]
shop = "../libs/shop"

[fns]
shop = "main"                     # the same for every file of a package
```

Under `[packages]` each line names a local folder, relative to the
`mote.toml`. `#` starts a comment. The nearest `mote.toml` at or above the
file that says `use` is the one read. Nothing is fetched
([language.md](language.md#packages)).

`fns` is `"main"`, `"off"` or `"auto"` (the default: the compiler decides),
as a file's own `fns` line is ([reactivity.md](reactivity.md#said-once-for-a-file-or-a-package)).
The line at the top, before any table, speaks for the files under the
`mote.toml`'s folder that are in no package; a line under `[fns]` for the
files in that package's folder. A package that has no line is `"auto"`,
whatever the top says. The `mote.toml` read for this is the nearest at or
above the entry being built: the project decides, for its packages too. A
file's own `fns` line, and a fn's own `main` or `off`, win over it. A word
that is not one of the three, or a package `[packages]` does not have, is
`H102`.

## Environment

| Variable | Read by | Meaning |
|---|---|---|
| `MOTE_RUNTIME` | the compiler | A folder to read the runtime from. |
| `MOTE_BIN` | `tests/all.sh`, `tests/browser.sh`, `docs/check.sh` | The compiler to use. |
| `MOTE_DATA` | the back end, `mote dev` | The back end's data folder. |
| `MOTE_ACCOUNTS` | the back end | The folder accounts and sessions are kept in, for several apps to share ([back-end.md](back-end.md#accounts-several-apps-share)). Default: the data folder. |
| `MOTE_SQL` | the back end | `file:<folder>`: the folder the models' database and stored files are in, for several apps given the same one to keep the same rows; `?poll=50&wait=5000` after it ([back-end.md](back-end.md#several-apps-one-database)). `postgres://…`: the models, the jobs queue, accounts and sessions, `limit` counts and the back end's other stores of them in Postgres, for several back ends of one program ([back-end.md](back-end.md#models-in-postgres)). Default: the data folder. |
| `MOTE_SQL_DIRECT`, `MOTE_SQL_CA` | the back end | With `MOTE_SQL=postgres://…`: the database reached directly when `MOTE_SQL` goes through a transaction pooler (for LISTEN), and the authority (PEM) its certificate is checked against ([back-end.md](back-end.md#settings)). |
| `MOTE_BACKUP` | the back end | Snapshots of its databases: a folder, then how often and how many to keep, `backups?every=1h&keep=30` ([back-end.md](back-end.md#snapshots)). Default: none taken. |
| `MOTE_STUN`, `MOTE_TURN`, `MOTE_TURN_SECRET`, `MOTE_TURN_TTL`, `MOTE_TURN_USER`, `MOTE_TURN_PASSWORD`, `MOTE_CALL_MAX`, `MOTE_CALL_RECHECK` | the back end | Calls: the ICE servers a call's members are given, and a room's limits ([calls.md](calls.md#deploying)). |
| `MOTE_COOKIE_DOMAIN` | the back end | The session cookie's `Domain` (`.example.com`), for apps on sibling subdomains. Default: none, the host alone. |
| `MOTE_DEV` | the back end | Set by `mote dev`: a fault's own message is sent to the page, and the log is written for a person, not as JSON. |
| `MOTE_LOG` | the back end | The least level its log writes: `debug`, `info` (unset), `warn`, `error`, `off` ([back-end.md](back-end.md#logs)). |
| `MOTE_STOP_MS` | the back end | How long stopping may wait for the calls being answered, in ms (10000) ([back-end.md](back-end.md#health-and-stopping)). |
| `MOTE_USAGE_MS`, `MOTE_USAGE_HELD`, `MOTE_USAGE_ANON`, `MOTE_USAGE_ADDRESS` | the back end | [Usage](usage.md#the-seam): how often what was gathered is handed over, in ms (5000); how many events wait at most (50000); how many a minute are taken from everyone signed out together (3000). |
| `MOTE_BYE_MS` | the back end | Over how long its pages come back after it stops, in ms (1000): each after 0.1 s and a random part of this; `0`: no spread ([back-end.md](back-end.md#health-and-stopping)). |
| `MOTE_JOBS`, `MOTE_JOBS_DONE`, `MOTE_JOBS_FAILED` | the back end | How many [jobs](back-end.md#later-job-fn) it runs at once (4; 0: none), and how long a finished and a failed job's row is kept (`24h`, `30d`). |
| `MOTE_AT_LATE` | the back end | How late a [`server at`](back-end.md#at-a-time-of-day) moment the back end was down for is still made up at start-up (`1h`). |
| `MOTE_TEST_STACK` | `mote test` | Set, a test that broke prints the fault's stack under its line. |
| `MOTE_TEST_SHOW` | `mote test` | Set, the browser of the tests of the page is a window to watch. |
| `MOTE_NET_TIMEOUT` | the back end | How long a request to another machine may take when the program does not say, in ms (30000; 0: no limit). |
| `MOTE_ONCE_MS`, `MOTE_ONCE_MOST` | the back end | How long the answer to a call's id is remembered (600000 ms) and how many are (20000): [a call is answered once](back-end.md#a-call-is-answered-once). |
| `MOTE_MAX_BODY`, `MOTE_MAX_FILE` | the back end | The most a call or a route may be sent (16 MB), and the most a kept file may be (100 MB), in bytes. |
| `PORT` | the back end | Its port, when `--port` is not given. |
| `MOTE_CONTACT` | the back end | The `mailto:` address push services are told. |
| `MOTE_PUSH_ALLOW` | the back end | Push services of your own that a device may be signed up at, besides the public ones: names, `*.names`, addresses, `10.1.0.0/16`, with commas between ([back-end.md](back-end.md#who-can-do-what)). |
| `CHROME`, `CHROME_FLAGS`, `GPU` | the tests | The browser to drive ([testing.md](testing.md)). |

## Building the compiler

```sh
cd compiler && cargo build
```

It needs Rust with the wasm target (`rustup target add
wasm32-unknown-unknown`): the build script compiles the batteries to wasm
with `rustc` alone. No crate is downloaded. The binary is
`compiler/target/debug/mote`.

## Pitfalls

- **`--single` and offline.** A `--single` page has no service worker; it
  works offline because it is one file, opened from disk.
- **A full build needs a server to be installed from.** Service workers and
  manifests do not work from `file://`: use `mote serve dist`.
- **`mote serve` is not the back end.**
- **`mote dev` takes two ports** when there is a back end: its own and the
  next.
- **Flags may come anywhere after the command**; the first plain word after
  the command is the entry (or the directory, for `serve`).

## In the source

| What | Where |
|---|---|
| The commands and flags | `compiler/src/main.rs` |
| Compiling an entry | `compiler/src/build.rs`: `compile`, `finish`, `Mode` |
| `dev` and `serve` | `compiler/src/dev.rs` |
| The manifest, the service worker, the made icon | `compiler/src/pwa.rs` |
| Assets | `compiler/src/assets.rs` |
| `--perf` | `compiler/src/perf.rs`, `compiler/src/moves.rs` |
| Embedding the runtime, icons, batteries | `compiler/build.rs` |
| Recorded behaviour | `tests/all.sh` (`real_pwa`, `real_perf`, `real_batteries`: what a build's page holds and fetches, and when), `tests/expect/real_pwa.txt`, `tests/expect/real_batteries.txt` |
