# Operating Pencil

Use `rer VERB`, the command family on the Run page. Package-script aliases are documented in RUN-LOCALLY.md. `describe` lists actual capabilities and effects. `check --profile first-party` validates command contract 1 before dependencies or private configuration exist. OPERATIONS.json declares the first-party adapter.

## Local operation

Start Pencil with one line, `npx -y @runeditrun/rer dev just-every/run-pencil` (set up only: `npx -y @runeditrun/rer setup just-every/run-pencil`; without Node: `curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-pencil`). It needs Node.js 22 or later including npm, and Git, on `PATH`. rer installs Pencil's pinned runtime and pnpm for its own commands; global pnpm is not required. To start it again, run `rer dev` in the checkout it made. Dev installs locked dependencies and prepares a local owner automatically. The global launcher uses the exact checkout `@runeditrun/rer` version in `package.json` and its lockfile; `rer --version` may show different launcher and checkout versions. Preserve the checkout pin.

Local `rer setup --owner-email EMAIL --owner-name NAME` is optional. Installation is frozen. Setup builds, applies ordered migrations, creates the real owner through Base operator-auth and checks local owner entry, then stops its temporary production runtime. Dev serves assets and HMR, printing readiness after application health and sign-in. Open the private RER_OPEN link and finish `/setup`. Local dev/demo mail is silently suppressed. Other app routes send an unfinished owner there; completed setup enters the app.

Private bindings are in `.dev.vars` (0600); canonical data is `.wrangler/state`. CLI bookkeeping is `.rer/local`; drafts and captures are `.seed/installer`. Setup preserves existing owner, rows and exact private bytes. Conflicting identity, ambiguous legacy state, unsafe symlinks and occupied ports fail before effects. Preserve any reported legacy location: export with compatible source, verify restoration into an empty canonical database and remove legacy state only after explicit recovery. Rer moves or deletes no ambiguous state.

Use `--port PORT` for an explicit loopback port. `preview` serves fixed production output. `outbox` prints the viewer and requests sign-in only with explicit `--owner-email EMAIL`. Remote viewer access is refused. Ctrl-C or the corresponding `--stop` tears down owned processes. `doctor` performs no provider request. `build` excludes private settings temporarily and restores their bytes and permissions.

## Reset and recovery

`rer reset --yes` prints and removes `.wrangler/state`, `.rer/local`, `.seed/installer`, `.dev.vars` and `.dev.vars.previous` when present. Active runtimes and unsafe inventory are refused. Source, dependencies, `exports` and `.rer/deploy` receipts survive. Setup after reset starts a fresh empty installation.

Create `exports` with mode 0700. `rer export --output exports/installation.rer` creates a new 0600 typed integrity archive. `rer import --input exports/installation.rer --yes` applies ordered schema and restores atomically only into an empty database. This uses Pencil's maintained archive engine. Product data, including form graphs, response history, import custody and safe provenance (not original file bytes), contacts, invitations and operators, remains; sessions, sign-in links, credentials, plaintext secrets, captured mail and private settings are excluded, so everyone signs in again after a restore. Historical notification eligibility is disabled and no mail is replayed. Source paths and archives in other checkouts are refused; this checkout's ignored `exports` is permitted.

These rer commands support local state and refuse remote targets. Hosted recovery uses `node scripts/deployment-data-cli.mjs`, requires all routes, schedules and other writers to be stopped, and requires separately provisioning and attaching an empty migration-only D1 target. The script does not provision it, and a normal owner-claimed deployment is not empty. Read [Backup and restore](docs/guide/backup.md) before a hosted move.

Restore before setup, since setup creates owner/workspace records. Supply the retained owner's email when preparing fresh private settings after restore and sign in again. Check recovered forms, ledger, import resume/undo and delivery states before choosing the recovered installation. Never overwrite owner data or replay mail.

## Verification and release

Publication inspection uses the complete maintained Base scanner on a byte-exact parentless export. It requires Gitleaks 8.30.1; `bash scripts/install-gitleaks.sh` installs the reviewed binary after checksum verification. CI installs it before `pnpm verify:publication`. This inspection creates no tag, runs no scale case and publishes nothing.

Install Chromium with `npx --no-install playwright install chromium --only-shell`. `rer verify` runs types, product units, isolated Worker/D1, the entire recursive portable onboarding suite, native rer journeys, source provenance, archives, populated predecessor upgrades, boundaries, production build and desktop/mobile contract journeys. Internal targets have distinct names to prevent recursion. CI retains the functional and high-stakes wall.

Run **`pnpm run verify:release` before every release** for unchanged capacity, maximum-isolate memory, browser maximum heap and load workloads/assertions/thresholds. They are absent from CI and default verify. The maintained Base producer at 6b19df1343fe21e38262790185492f46f7eca36b or a descendant runs default verify and declared `verify:release`; either failure blocks release.

`pnpm run release -- --repo . --ref HEAD --project just-every/pencil --repository https://github.com/just-every/run-pencil --onto https://github.com/just-every/run-pencil#main --tag vVERSION --dry-run --output ../pencil-release` (with the committed `RELEASE.json` version) produces one child of the public repository's current `main`, with that commit as its sole parent and a tree equal to the source tree, and runs the complete scanner over it and the public history. Edition baselines retain copied origins, and source checks compare their actual bytes. Require PASS, complete scan, zero findings and zero reviews without exclusions or allowlists. Dry run tags no source commit and pushes nothing; its `PUBLISH.md` holds the fast-forward push. No clause is deferred: `contract-profile.json` declares none, and ANLY-009, NOTIFY-001 and NOTIFY-003 are implemented.

## Hosted operation

`rer deploy --dry-run --environment pencil-check` builds real Worker/assets/migrations and validates deploy.json with zero provider calls. Names have at most 32 characters, start with a lowercase letter and contain lowercase letters or digits separated by single hyphens, with no leading, trailing or repeated hyphens. `pencil-check` is a dry-run example; choose the intended deployment name before creating resources and retain it for all later operations. Validate the intended environment before real deployment.

Actual deployment needs the intended `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`, `MAIL_FROM` and `MAIL_API_KEY`. Set `OWNER_EMAIL` to the hosted owner’s email and use `SEED_ADMIN_EMAIL="$OWNER_EMAIL" rer deploy --environment production`; Pencil’s current declaration reads `SEED_ADMIN_EMAIL`. rer generates hosted `SESSION_SECRET` and one-time `SETUP_TOKEN` when omitted, claims the hosted owner automatically and removes the setup token. Sign in by email at the printed hosted address and finish `/setup`. Updates keep the owner and existing secrets; leave `SETUP_TOKEN` unset after successful retirement. The declaration selects production mail and disables sample data and local capture. Keep secrets out of argv and output. Health does not prove hosted installation, delivery, permissions or capacity. Read docs/HOSTING.md.

The Base importer row identifies public just-every/pencil, whose source is https://github.com/just-every/run-pencil. Point Base at a reachable public guide commit on its `main` and verify its bytes.

## Managed delivery

`pnpm run build:delivery` builds production artifacts and `pnpm run verify:admission` exercises the actual package, signed admission and owner editor at both viewports. The trusted build workflow uses the project’s pinned Node. Apply migrations through `0036_owner_signin.sql` before serving this source. The consumed-claim ledger survives export and restore; initialized stores refuse further claims. Optional management configuration comes from the intended installation’s issuer and origin. A native owner session gates editor configuration; expiry and sign-out revoke the widget. Hosted install, issuer/account configuration and real management-edge proof require the owner.

For recovery into a fresh clone, run `rer install`, copy the archive into private `exports/`, then import before setup or build. The committed `wrangler.jsonc` supplies the schema configuration. Run setup afterwards with the restored owner email.
