agentleFS
hyperloguehyperlogue/r3/.claude/skills/build-and-distribution/SKILL.md

build-and-distribution

Skill39 starsChanged 2 months agoMITView on GitHub

How r3 is built and shipped — the single-file Bun.build --compile binary and its browser-target Tailwind CSS pre-pass, the two release channels (GitHub Releases + the npm launcher with per-platform optional-dependency packages), the `bun` → empty-npm-package override, and the frontend-only browser demo deployed to GitHub Pages. Use when touching scripts/ (compile, spa-css, release-binaries, stage-npm-packages, wait-for-npm-packages, build-demo, stage-pages, gen-artifact-demo), npm/, web/demo/, bunfig.toml, the nix build, the Pages or release workflows, or debugging a broken binary/demo build.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Only publish uses environment: release, so each attempt requires one approval.

    line 80

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Building and shipping r3

This file is the design source of truth for r3's build + distribution — update it here when the pipeline changes. (Cutting an actual release — changelog, version bump, tag — is the separate release skill.)

The single-file binary

bun run build runs one Bun.build({ compile }) (scripts/compile.ts) over the CLI entry — which imports the daemon, which imports the SPA via import index from "../web/index.html". That embeds the Bun runtime, all JS deps, bun:sqlite, and the bundled SPA (as Bun.embeddedFiles) into one ./r3 executable that serves its own UI. application-assets.ts indexes embedded files and serves them behind the application Host guard. A source daemon bundles the same assets once at startup; frontend edits need a restart. Native Bun HMR routes are not exposed outside the guards. The CLI is the binary; the hidden __daemon subcommand re-execs it to serve.

The CSS pre-pass is load-bearing. The SPA stylesheet is Tailwind-compiled first in a separate browser-target pass (scripts/spa-css.ts, shared with release-binaries.ts). A compile build is target:"bun", whose CSS printer keeps Tailwind's native nesting verbatim — and un-lowered nesting breaks in browsers (& {…} under ::placeholder is unmatchable, so placeholders lose their dimming). The pre-pass lowers it flat; the compile build embeds it as-is. Don't remove it.

Two release channels, one tag-driven pipeline

scripts/release-binaries.ts cross-compiles the four r3-<os>-<arch> binaries. From there:

  • GitHub Releases carry the raw assets (curl / Homebrew). No checksum manifest ships with them — GitHub publishes a sha256 digest per asset, and the build job verifies against those digests on the reuse path.
  • npm ships a tiny launcher (@hyperlogue/r3, npm/launch.mjs) whose per-platform binaries are optional-dependency packages (@hyperlogue/r3-<os>-<arch>, staged by scripts/stage-npm-packages.ts). npm installs only the matching package, so bunx/npx @hyperlogue/r3@x.y.z resolves-and-execs that version's binary with no runtime download — the launcher only does createRequire().resolve + spawn.

npm auth is trusted publishing (OIDC) — there is no npm token. Each of the five packages registers release.yml by filename as its trusted publisher on npmjs.com, and npm mints a short-lived publish-only credential from the runner's OIDC identity. So: renaming .github/workflows/release.yml breaks publishing until all five registrations are updated, publishing can't move to another workflow or a self-hosted runner, and a brand-new package name (adding a platform target) has no trusted publisher yet — its first publish is manual, then register release.yml on it. Requires npm ≥ 11.5.1, which is why the npm steps upgrade npm and omit setup-node's registry-url (its .npmrc placeholder token would shadow OIDC).

Three jobs, one approval gate

release.yml is verify → build → publish. The single publish job creates or reuses the GitHub Release, publishes the four platform packages, waits for all exact platform pins to become visible, then publishes the launcher. Re-run failed jobs repeats this job safely: an existing published release and its assets stay untouched, and npm versions already on the registry are skipped.

  • verify checks the tag shape (plain SemVer — a git ref may contain $( ), backticks and ;, so an unvalidated tag reaching a run: block is an injection vector) and the tag ↔ npm/package.json lockstep, then exports the verified version. A missing ## [X.Y.Z] changelog section only warns — the release falls back to --generate-notes.
  • build compiles (or re-downloads and digest-verifies this tag's existing assets), execs the linux-x64 binary as a smoke test, and hands dist/r3-* to publish as an artifact. It can only read.
  • publish checks for the GitHub Release before downloading the build artifact. Only a 404 permits creation; other API failures and an unfinished draft stop publication. If the release exists, skip the artifact download, binary check, and creation. Never re-upload assets on a retry: immutable releases reject that write before npm can resume.

Only publish uses environment: release, so each attempt requires one approval. Each npm package's trusted publisher names that environment and the release.yml workflow; keep both names. Configure the environment's required reviewers (GitHub creates it implicitly, so it runs ungated until configured) and a tag ruleset on v*. A tag push bypasses branch protection: without the gate, anyone with write access could tag an arbitrary commit into an npm publish. The workflow defaults to contents: read; only the gated job receives contents: write and id-token: write.

npm packages always stage the published GitHub assets, including on the first attempt. Clear the downloaded build binaries before fetching those assets, so a missing release asset cannot be silently supplied by a different build. Stage once to produce all four packages and the launcher's exact pins. Keep platform publication, registry visibility, and launcher publication in that order.

scripts/wait-for-npm-packages.sh gives the launcher one ten-minute deadline for every exact platform pin. Each poll revalidates npm metadata (--prefer-online) and bounds the registry request, so a stall cannot outlive the deadline. Run bun test scripts/wait-for-npm-packages.test.mjs when changing that wait; a bare bun test does not discover .mjs. The workflow retry checks in scripts/release-workflow.test.ts exercise publication with fake GitHub and npm commands. CI runs both suites without publishing.

The publish job never execs a release binary. It only stats staged exec bits; build already ran the natively-runnable target. Executing an unverified binary with publish credentials could let it rewrite the other platform packages. The build artifact's retention-days: 7 bounds how long initial approval may idle. Past that, re-run the workflow so build can compile again. Once the GitHub Release exists, npm retries skip that artifact and work after it expires.

package.json overrides bun → empty-npm-package

bun-plugin-tailwind peer-depends on the bun npm package, which would pull Oven's wrapper + 16 platform binaries into bun.lock (and thus bun.nix and the nix build's fetch set), and whose broken bin shim shadows bun on install-script PATHs. The override pins that name to an empty stub.

The plugin has no public source repo — report issues to oven-sh/bun, and drop the override if a release marks the peer optional or moves it to engines.

The frontend-only demo → GitHub Pages

bun run build:demo (scripts/build-demo.ts) produces a static dist/demo/ that runs the whole SPA with no daemon — a third client of the same components, but its "backend" is an in-browser store (web/demo/) over localStorage, with feedback image bytes in IndexedDB.

It uses the same web/index.html and application components. One build plugin aliases five exact imports:

Application moduleDemo replacement
web/src/api.tsweb/demo/application-api.ts — boot/theme and disabled login management
web/src/artifact-api.tsweb/demo/artifact-api.ts — typed artifact API and local event stream
web/src/demo-chrome.tsxweb/demo/demo-chrome.tsx — intro/reset
web/src/artifact-renderer.tsxweb/demo/artifact-renderer.tsx — bundled static previews
web/src/main.cssweb/demo/main.css — also scans demo classes

ArtifactDemoBackend owns seeded publications, conversations, delivery, claims, and lifecycle in browser storage. An async event stream invalidates the same queries as production. There is no global EventSource or fetch shim.

scripts/gen-artifact-demo.ts → web/demo/artifact-fixtures.gen.ts bakes two public demo artifacts: an interactive HTML curve lab and a six-file diff review. Each starts with four already-sent conversations: two human-authored and two agent-authored, with replies, three open threads, and one resolved thread. Saved gallery sessions gain the additional threads once, preserving existing work and later deletions. The curve lab embeds samples/curve-lab.js inline, with no external chart library; its sliders update the approximation, residual plot, and sampled error metrics. The generated workshop seed also retains the Files example for Storybook and the tutorial. Complete versions, original bytes, retained Markdown HTML, theme palettes, and scripted follow-up publications share the same generator. Preview documents are a separate generated export; they are not restored from browser storage. This gallery uses the r3-artifact-demo-curves storage key so returning visitors start with the current examples; the previous practice state is left untouched. Shiki, SQLite, and Git never ship to the browser. Run bun run gen:demo after editing canned content; generated fixtures are excluded from Biome.

Explicit Submit schedules the scripted agent, claims notes, publishes a new version, replies with context, and leaves status for the human. Selection stays on the original version. Archive prevents publication and re-registration while allowing in-flight replies and retaining pending work. The demo implements the public contract directly; its persistence model is separate from wire types.

The build replaces only the default renderer used by ArtifactView. The demo renders immutable build fixtures in srcdoc iframes with sandbox="allow-scripts" and no same-origin privilege. Artifact/version/hash/path identity must match a bundled publication; localStorage cannot provide executable document or asset bytes. CSS and images are embedded from the same bundle, and links resolve only to that publication's documents and fragments. Query routes, external links, arbitrary publication uploads, and the publisher utility/device API are outside this demo. Feedback paste/upload and crop use the shared image controls; message retry keys persist with demo state and image reads verify membership in the selected artifact.

The shared selection/Locate runtime and Markdown theme/height adapters run on a document-specific port exposing only preview UI events. Fragment evidence is retained by a demo navigation adapter because srcdoc has no published URL. A native document switch remounts the iframe, closing the previous port without adding a preview entry to browser history. Loaded Markdown stays mounted across file folding, matching the workspace's existing retained-preview behavior.

CSP restricts resource requests, but the demo has no daemon capability gate or verified Connection Allowlist. Every preview explains that distinction. Do not present it as production security or add a same-origin execution fallback. CAN_MANAGE_TOKENS=false hides access management and sign-out, which have no meaning in this tab.

The Pages layout

.github/workflows/pages.yml builds the demo and deploys on push to main, mounting it at …/r3/demo/ — the project page (/r3/, the repo name, forced by Pages) plus a /demo sub-path.

R3_DEMO_BASE=<base_path>/demo (base_path from configure-pages) bakes that prefix into the router (hrefFor/__R3_BASE__) and asset publicPath. Then scripts/stage-pages.ts lays out dist/pages:

  • the build under demo/,
  • a root→demo redirect,
  • and — because Pages honors only a single site-root 404.html (subdirectory ones are ignored) — the SPA copied to the site-root 404.html, so a deep-link reload of /r3/demo/artifact_x still boots it (its asset URLs are absolute).

Local build:demo defaults to a root base, so bunx serve -s dist/demo just works.

Nix

nix/r3.nix drives the same bun run build with a custom buildPhase on top of stdenv + the bun2nix hook (which installs the pinned deps from bun.nix) — the compile step is more than bun2nix's default module→binary path. bun.nix is generated from bun.lock and committed: any dependency change must regenerate it in the same commit.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.