jevstrudel.git / tools / dev / README.md
1# tools/dev
2
3The launchers behind the buck targets, in Node.
4
5| File | What it is |
6|---|---|
7| `dev.mjs` | `buck2 run //:dev`: the working tree with hot reload. |
8| `preview.mjs` | `buck2 run //:preview`: what a deploy would publish. |
9| `supervise.mjs` | Runs the Worker under `wrangler dev` and restarts it when it exits or stops answering; both launchers use it. |
10| `migrate.mjs` | Applies the Worker's D1 migrations to its local database before it starts; both launchers use it. |
11| `worker.mjs` | `wrangler dev` itself, started inside `op-env-run` with only the Jev key and what wrangler needs in its environment. |
12
13## `//:dev`
14
15Installs the pnpm workspace, regenerates `doc.json` as upstream's
16`pnpm dev` does, then runs two processes:
17
18- the jevstrudel Worker (`worker/`) under `wrangler dev --env dev`, on port
19  4323: the Jev relay and the MCP hub. It runs with `--test-scheduled`,
20  since `wrangler dev` fires no cron triggers: `curl
21  localhost:4323/__scheduled` runs the Worker's sweep of the screening and
22  scoring Jev owes listeners' content.
23- Astro's dev server for the site, on http://localhost:4322/, which proxies
24  the Worker's paths (`/jev/…`, `/strudel/ws`, `/strudel/status`) to it.
25  The proxy keeps the page's `Host`, so the Worker's passkey relying party
26  is `localhost` with the page's own origin.
27
28Before the Worker starts, its local D1 database (`worker/.wrangler/state`)
29gets any migration it has not had (`migrate.mjs`), so a fresh checkout has
30its tables. The preview does the same to its own
31(`worker/.wrangler/preview`).
32
33Stopping it stops both.
34
35## `//:preview`
36
37The last listen before `nix run .#deploy`, on http://localhost:4324/. It
38builds the flake's `static` package, the same derivation the deploy
39uploads, and serves it as the assets of the Worker in its production
40environment (`--env ""`): the Jev relay with your key, and no MCP hub, so
41`/mcp` answers 404 as it does on the public site. It installs the Worker's
42own dependencies first (`pnpm install --filter @jevstrudel/worker`), from
43the lockfile the deploy bundles them from. There is no hot reload;
44run it again after a change. It can run beside `//:dev`.
45
46Run either inside the devshell, which provides node, pnpm, wrangler, nix
47and buck2.