# cli: the verb standard

One binary, one grammar. An agent that has called one house CLI can call
the next without reading its source — because the contract is generated,
not written.

## the grammar

- `verb [flags] [args]` — verbs are lowercase, one word, imperative
  (`serve`, `backup`, `harvest`).
- `--json` on every read verb — machine output is a right, not a favor.
  Human output stays `key: value` lines; the JSON twin carries the same
  facts under the same names.
- Flags are long-form; a short form is a gift to humans, never a second
  contract. clap's derive owns parsing — no hand-rolled argv walks.

## doc comments ARE the docs

`cli/mod.rs` is clap derive (enum + dispatch + the small verbs — a
verb earns its own file at ~100 lines), and `schema --json` walks the
SAME structs the
parser uses. One doc comment is help text AND the schema string — the
contract cannot drift because it is not duplicated. Adding a verb is one
enum variant + one match arm + one `cmd_*` fn, and the schema, the
`--help`, and this corpus all learn it at once.

## stdout = result, stderr = noise

The last stdout line is the result (a path, an id, a verdict). Progress,
journal lines, warnings ride stderr (`util::journal`). A pipe of stdout
into the next command must never carry log noise.

## exit codes: the typed map

Exit codes live ONLY in `error.rs::fail_map` — verbs return
`Result<_, CliErr>`, never call `process::exit`. `0` ok · `1` fail ·
`2` usage (clap's own parse errors land here too — one semantic per
code). Domain extensions are documented, never invented silently.

`error::lanes()` carries the same map machine-readably: `schema --json`
and `/schema.json` ship `error_lanes` — name, exit, meaning — so an agent
reads the whole refusal contract without opening the source. A refusal's
last line NAMES the remedy (`clean` refuses without `--yes` and says so).

## destructive verbs knock first

A verb that destroys state goes through `require_yes`: it refuses
without `--yes`, names the doom, names the flag. `clean` is the worked
example — copy it, don't improvise a confirmation prompt.

## exit codes: ran vs found

A read verb exits 0 with its finding — the call succeeded, the ANSWER is
the answer. Exit codes say whether the verb ran, not what it found, with
ONE carve: `doctor` is a gate. Failed checks exit 1 because `just
deploy` consumes that exit as the ship/no-ship signal — for a gate, the
exit code IS the finding (the four gates, the section below this file's verb standard).

## the observation lane

`span` posts ONE explicit span to the collector and exits — the justfile
calls it after every recipe line (exit, duration, recipe; the verb adds
host). It is best-effort by law: a dark collector never fails a recipe,
so the verb always exits 0 on a post attempt (validation refusals are
exit 2, the usage lane). `MRSN_TELEMETRY_ENDPOINT` decides the posture: `off`
silences, a valid http(s) base wins, a garbage value is refused and the
run skips, unset = the dev machine's collector (an explicit span is an
act of telemetry — the caller asked to be observed; the telemetry lane is the contract).

## the battery pins all of it

`tests/battery.rs` fails the build when a schema verb is missing from the
README, when a refusal is untyped, when a lane drifts from the map. The
docs-drift law: verb in code but not in README = red.

---


# health: the runtime gates

The kit proves health at four depths, each one word from the ladder.
They are not interchangeable — **cargo-green ≠ store-green ≠
host-green** — and no gate stands in for another. Every gate recipe
SELF-SEALS: on a bare host `just test` re-execs ONCE inside the devShell
(`_MRSN_SEALED` guards the loop; a direnv-active shell skips straight
through) — the gates judge on the sealed MSRV toolchain or not at all,
and nobody types `nix develop . -c`:

| gate | verb | proves | depth |
|---|---|---|---|
| the battery | `just test` | the REPO is honest — named tests on a real temp db, route lanes over the real router, the live wire probe (a real bind + real HTTP `/health` round-trip through the full stack, in-process) | seconds |
| doctor | `mrsn doctor` | the DEPLOYMENT is alive — the runtime env resolves where it actually runs | one boot |
| `/health` | `curl :PORT/health` | the PROCESS is serving — `{"status","sha","docs","verbs"}` | live |
| the VM | `just prove` | the HOST config works — a NixOS VM boots with ONLY the module and curls `/health` | minutes, cached forever after |

## doctor — the runtime gate

`doctor` (analytics harvest) runs the checks a boot needs, one line
each, exit 0 = alive: the config env law holds (a bad `MRSN_PORT` dies
loudly), the db opens with the current schema stamp, the template
registry parses, the content corpus is readable, the public vendor
bytes are on disk, and the telemetry lane reports its posture — **off is a
NOTE, never a fail**; when `MRSN_TELEMETRY_ENDPOINT` is set, a 1s TCP probe
(never a POST) answers "is the collector up?"). It reads
the SAME env law as serve, so it fails exactly where serve would fail.

A **store binary carries no manifest dir** — `CARGO_MANIFEST_DIR` is
dead in the nix seal. `just deploy` therefore points doctor at the
store's own lanes before probing:

```bash
just deploy   # nix build, then:
# MRSN_CONTENT_DIR=$PWD/result/docs MRSN_ASSETS_DIR=$PWD/result/assets ./result/bin/mrsn doctor
```

## /health — the process lane

`{"status":"ok","sha":…,"docs":…,"verbs":[…]}` — status is the unit
alive; **sha is the build stamp** (MRSN_SHA, the git rev in a store
build), so the thing you curl is provably the thing you built; docs >
0 proves the import landed; verbs rides `schema_verbs()` — the web
tongue exposes the CLI's verbs. The VM asserts all four (internal/nix.md).

## the port law

**dev 5173 · release 4173** — vite's convention, one const
(`config.rs::DEFAULT_PORT`) split on the build profile; `MRSN_PORT`
overrides both. `just serve` pins :5173 through restarts with the
systemfd socket handoff; the module, the VM and every curl against a
release binary ride :4173. A doc that names another port is stale —
fix the doc, not the const.

## graceful death is part of health

SIGINT AND SIGTERM both drain in-flight requests, and only then does
boot flush the turso wal. Container orchestration sends SIGTERM — a
SIGTERM-only death would skip the flush, so the drain-then-flush law
is what makes the cache honest under `docker stop` / arcane. The
module's `TimeoutStopSec=30` is the grace before SIGKILL; children die
TERM → poll → KILL (`util::kill_grace`), never pkill-by-name.

## the backup twin

Health includes recovery: `mrsn backup` flushes the wal, then the
`.db` + `-wal` + `-shm` trio lands together in a timestamped dir
beside the db. Restore = stop, copy the trio back, start. And the
two-class law bounds what can be lost: CACHE tables refill from git
truth at next boot; a DATA table a user earned rides additive DDL and
survives every stamp bump — if your fork earns one, backup it like
truth.
