# Beam operations

Run all first-party operations from the composed, runnable edition checkout
with the shared RER command path. To get a runnable checkout, run
`npx -y @runeditrun/rer install just-every/run-beam` (or start it directly with
`npx -y @runeditrun/rer dev just-every/run-beam`). The detailed flags and effects are in
`RUN-LOCALLY.md` and `SEED-COMMAND-CONTRACT.md`.

```sh
rer setup --owner-email you@example.com
rer dev
```

Use the setup prompt instead of the owner-email flag when entering the real
mailbox. Open the printed `RER_OPEN` link to arrive signed in; no external
email is sent. Stop `dev` with
`rer dev --stop` or Ctrl-C, and stop `preview` with
`rer preview --stop` before build or verification.

```sh
rer verify
rer reset --yes
rer export --output exports/installation.rer
rer import --input exports/installation.rer --yes
rer deploy
rer describe
```

Use `rer describe` to inspect the checkout's actual
capabilities. `rer check --profile first-party` validates the
declared command contract; it does not run application journeys or contact a
provider.

## Local data and recovery

Setup and development use explicit owner identity and real local migrations.
Dev and preview use the same owner and canonical `.wrangler/state`; local dev
sign-in answers only a request holding the checkout key in `.rer/local/`. Any
process with access to the machine can read that key and sign in as the owner. Private settings are
kept in `.dev.vars` with mode 0600 and are not copied into build output.

Local export creates a private archive with an integrity receipt and explicit
exclusions. Beam's archive holds every `beam_*` table (business, members, teams,
sources, courses and revisions, paths, assignments, progress, attempts,
decisions, completions, certificates, notices, proposals, imported history and
audit), the import kit's `ik_*` journal with retained originals, and every
object in the `FILES` bucket (source versions and evidence files, keyed by
SHA-256). Beam has no background jobs. Owner/auth, outbox, bookkeeping, private settings and
transient runtime state are excluded. Import validates and restores atomically
into an empty destination; confirmed reset preserves export archives. Run setup
after restore to establish a fresh owner. Each first-party seed verifies local
export/import/export equivalence across its supported resources. Remote transfer
is available only when the adapter declares complete resource coverage.

Preserve ambiguous state and applied migration history. Never place a remote
credential, owner secret or local resource ID in source. A schema change needs
a forward migration and verified transition/recovery.

## Deployment

Start with a fresh Beam checkout and run `rer install`. Run `rer setup` and
enter the real owner's email address when prompted. Then plan the deployment
with email off.

```sh
MAIL_PROVIDER=none rer deploy --dry-run
```

The dry run builds locally and prints the Cloudflare resources it would create.
For the real deploy, supply `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`
privately through the Business connection or an owned mode-0600 environment
file passed as `--env-file` to both commands. The token needs Workers Scripts Edit, D1 Edit and Workers R2 Storage Edit
for the target account. Supply any inputs named by the dry run. Leave
`MAIL_FROM` and `MAIL_API_KEY` unset for mail off.

```sh
MAIL_PROVIDER=none rer deploy
rer signin
```

Run `rer signin` from the same checkout with the same Cloudflare credentials
and environment. Open the one-time owner link it prints and keep it private.
Mail off disables email sign-in links, invitations, email verification and
outbound reminders. For a new deployment with mail on, set `MAIL_PROVIDER` to your chosen
provider, supply its verified `MAIL_FROM` and privately supply its
`MAIL_API_KEY`. See the offline configuration diagnostics below for
provider-specific inputs.

## Provider connections on a local install (OPS-006)

A fresh checkout runs the whole native learning journey with no provider account: setup, dev, a published course
completed by a learner, build, `rer deploy --dry-run`, `rer export` and `rer import` into a second fresh clone
(`BEAM_TEST_CHECKOUT=1 pnpm run test:journey`, nightly and on release tags). Features that need a provider never
simulate one. Before the owner connects a model account, a draft request is refused (409, `model_disabled`) and the
generation page says the owner must enable the AI preparation account in Settings; no draft, answer or cost is created.
After the owner connects their own key through Settings, one approved request returns a real provider answer with its
actual model, response id and USD estimate; revoking removes the sealed key. A hosted install without its mail credential
is reported by `pnpm run diagnose:configuration` with the setting named (`MAIL_API_KEY`) and the action to take
when a sending provider is configured. `tests/beam/live-install-provider.mjs` is the
held-key qualification of this sequence in a fresh clone; it runs outside push Verify.

## Offline configuration diagnostics (OPS-007)

Before starting a hosted installation, put its authentication/mail settings in a
private JSON object (file mode 0600, outside public assets) and run:

```sh
pnpm run diagnose:configuration < exports/configuration.json
```

The command reads only standard input; it does not discover environment files,
contact a provider or print setting values. A nonzero exit identifies each
missing/invalid setting with its corrective action. Correct those settings in
the installation secret store and run it again. A successful result checks
syntax only: verify sender ownership and credentials with the real provider
and exercise ordinary sign-in before relying on delivery. Hosted installations
need AUTH_ORIGIN, OWNER_EMAIL, SESSION_SECRET and MAIL_PROVIDER. Sending
providers need MAIL_FROM and MAIL_API_KEY. Cloudflare mail also needs
MAIL_ACCOUNT_ID, and the RER relay needs MAIL_RELAY_URL. SETUP_TOKEN is checked
when supplied (Base permits it to be absent after ownership is claimed).
AUTH_LOCAL=true selects the existing local loopback/development-mail rules;
local and demo mail do not require hosted provider credentials.

## Base and component qualification (OPS-007)

Keep Base-copy and source-lock verification enabled. For each current capability
and each proposed component replacement, run these public-door checks on the
baseline and the candidate before accepting it:

```sh
node scripts/edition-authoring/cli.mjs check
node scripts/edition-authoring/cli.mjs verify-base --offline
pnpm exec rer check --profile first-party
pnpm run build
node tests/email-link.mjs
node tests/beam/regressions.mjs --only=OPS-007
```

The historical-producer journey also uses real commands against a separate,
fresh checkout of the earlier published application. Prepare that checkout at
`71a1245e5c29e5a0f6e71969bf7dac31d69db6fd` (the published pre-0070 producer),
then run from the candidate:

```sh
BEAM_TEST_CHECKOUT=1 pnpm run test:legacy-restore -- /absolute/path/to/fresh-producer
```

The producer runs unchanged. New data enters through its public doors; it
writes its own archive through `rer export`. Today's empty destination restores
that archive through `rer import`, preserving learning, original source bytes
and decision lineage while disabling all old grants. The owner rotates application credentials and issues new report links; the
restored learner creates a new verification link for their own certificate. The same ordinary sign-in, rejected-mail recovery
and session-isolation HTTP checks run against both emitted Workers; the offline
diagnostic command qualifies the candidate. Tests capture mail only at the
provider network edge. `BEAM_EVIDENCE_DIR` adds Access/report browser checks at
1440 and 390; use the host's current Playwright via `BEAM_PLAYWRIGHT_MODULE` and
`BEAM_BROWSER_EXECUTABLE` when needed. Both checkout and temporary volumes must
meet Base's disk guard; select a sufficiently large run-owned TMPDIR if needed.

A proposed replacement must additionally repeat the relevant import-custody
journeys (BEAM-15) and retained command journey (BEAM-16); its exact candidate
requires the full branch Verify before landing. Future identity, mail, native
client, provider and importer clauses inherit this qualification as they ship.

## Hosted delivery

`packaging.json` declares Beam's frozen installation, build, verification, recovery,
D1 migration sources and R2 files. After a real build, run `pnpm delivery:spec`
to refresh the committed deployment specification and `pnpm check:deployment-spec`
to check freshness. Package with
`node scripts/delivery/base/cli.mjs package --config packaging.json --output rer-package`
or generate the delivery artifact with
`node scripts/delivery/base/cli.mjs artifact --config packaging.json`.
Generated package and artifact directories are disposable. Managed delivery is
dispatch only and uses the pinned trusted workflow.

Hosted mail supports Resend, SendGrid, Cloudflare and the RER managed relay.
Assisted setup requests the selected provider, verified sender and private API
credential; Cloudflare also needs its account ID. RER assigns MAIL_PROVIDER,
MAIL_FROM and MAIL_RELAY_URL and provisions the private MAIL_API_KEY. Relay
URLs must use HTTPS without credentials, queries or fragments. Local development
and demo runs send no external mail. Keep the existing installation
identity so existing archives and import records remain addressable.

## Service health and capacity

The human owner opens Settings, then Service health, at
`/app/business/health`; the equivalent read is `GET /api/beam/operations`.
Managers, learning administrators, preparation credentials and signed-out
callers cannot read these installation-wide observations. CT approved this
aggregate diagnostic scope on 23 October 2026 for the current human owner only;
there is no delegated or agent access. Each successful page or JSON read appends
a value-free access audit event identifying the actor and door, never the
diagnostic values. Reads neither contact external providers nor retry jobs.

The page distinguishes known unsuccessful attempts, unknown outcomes and
recorded provider successes. An interrupted webhook may have been accepted by
the receiver; an unknown outcome never counts as a known unsuccessful attempt.
It also distinguishes retained job states from successful provider attempts,
and roster receipt freshness from the last applied reviewed batch. A held
preview is not a successful synchronization. Source-version usage is logical
bytes, not physical storage or a provider quota. Empty history is unknown
health. External provider availability is not probed.

Source uploads accept nonempty files up to 25 MB. Package admission accepts a
25 MB archive with at most 20 MB per expanded file and 100 MB total expanded
content. Oversize uploads are refused whole; choose a smaller file and upload
again. These limits do not qualify a hosted employer's capacity.

Beam's provider fee, employer-day USD reservations and the existing provider
cost boundary appear before the owner connects or uses a provider. Hosting,
mail, video, models and licensed content can carry separate employer-account
charges; actual prices, invoices and remaining quotas are unknown here. Confirm
them with the provider before purchase or use. Reservations are estimates,
including failed or unknown attempts, and never an invoice.

For bounded native capacity qualification, build a clean committed checkout and
run `node tests/beam/capacity.mjs` with a hard 20-minute timeout. It uses isolated
D1 and R2 with ordinary authenticated HTTP doors: 200 active employee rows,
retained history, a 20-person cohort, ten concurrent learners, synthetic owned
mixed media and package resume. It prints the exact candidate SHA and workload
receipt. Run it outside push Verify. It does not establish production media
sizes, sustained hosted throughput, provider quota exhaustion or actual billing;
OPS-008 remains partial until those named qualification gaps are closed.
