Development
Requirements: Node 24 or newer, pnpm 12, git, and Pi >=1.4.0 <1.8.0 on PATH. For feature placement, failure behavior and compatibility expectations, see the core/plugin ownership contract.
pnpm ipnpm build # tsc -b for every TypeScript package, then the web bundlepnpm lint # Biomepnpm test # Vitest, all packagespnpm test:fast # Vitest on the fast tier's files only (no coordinator, Pi or processes), secondspnpm test:slow # slow files except pinned plugin compatibilitypnpm test:tiers # validate the CI partition and its negative controlspnpm test:e2e # Playwright: every spec on desktop, layout specs at compact and phone sizespnpm test:e2e:smoke # the @smoke subset CI runsRegister the pre-push check once per clone (worktrees share it): git config hook.pifi-check.command scripts/pre-push.sh && git config hook.pifi-check.event pre-push. It runs Biome, tsc -b, the test-tier check, the site’s doc listing and pnpm test:fast, in about 10 s.
Test files that start a coordinator, Pi, a mock model, a child process or a worker, or listen on a port, begin with // @module-tag slow. Tag by hand any other file that takes more than about half a second. The pinned plugin compatibility files under packages/host-agent/test/compat/ also carry // @module-tag compat. CI partitions the configured Vitest inventory into fast (!slow), core slow (slow && !compat, five shards), and pinned compatibility (that path, across the required Pi matrix). pnpm test:tiers (run by the hook and CI) checks the inventory, tags and selectors; pnpm test remains unfiltered.
For a live development loop, run node packages/cli/dist/main.js up --dev and, in another terminal, pnpm --filter @pifi/web dev (Vite proxies the API and WebSockets to port 7400).
Tests against real Pi
Most runtime, host and integration tests start the real pi --mode rpc with an isolated agent directory and a scripted OpenAI-compatible mock model from packages/test-fixtures, so they cost nothing and need no network. Only the model is fake.
| Variable | Effect |
|---|---|
PIFI_PI_BIN |
Pi binary to test against (default pi) |
PIFI_SKIP_REAL_PI=1 |
Skip tests that need Pi; without it, a missing Pi fails them |
PIFI_PI_PLUGINS_DIR |
Pi suite checkout for plugin compatibility tests; direct Vitest invocation can skip when absent, but the required cross-repository check cannot |
The browser tests start a real coordinator and host with the mock model, and use a mock OpenID Connect provider and a virtual WebAuthn authenticator for the sign-in flows. Fixtures must dispose their own terminals and other resources; a hard worker death bypasses finally and disposal, and is not a reason to sweep unrelated processes globally. Run a real-Pi test locally only to debug one that fails, or to iterate on the runtime or integration path it covers: one file at a time under /usr/bin/lockf -k "$HOME/Library/Caches/agent-heavy.lock", for example pnpm exec vitest run --maxWorkers=1 <test-file> inside the lock. Leave the slow shards, the pinned compatibility matrix and the browser tests to CI.
Plugin development skill
The public plugin-development skill bundles authoring and verification references for portable use outside this repository. For example, install copies for Codex and Claude Code (choose the agents you use):
npx skills add justmytwospence/pifi -s pifi-plugin-development -a codex claude-code --copy -yFor reproducible installations, replace the repository shorthand with https://github.com/justmytwospence/pifi/tree/<full-commit-sha>/skills/pifi-plugin-development. Update deliberately by reinstalling the skill from a reviewed new commit, rather than editing installed copies. Run pnpm skill:check to validate the source and its validator tests. Publishing guidance on the public development branch requires no runtime release or production promotion.
Adapter development and cross-repository checks
After pnpm build, run the portable preview with an explicitly selected trusted adapter and a fixture:
pnpm adapter:preview -- --adapter packages/adapter-examples/src/hello --fixture packages/adapter-examples/fixtures/hello.json > /tmp/hello-preview.jsonUpload the JSON file in Settings > Adapters > Portable UI preview. It validates and renders desktop and phone portable UI and logs simulated actions locally as labeled fields. Use read-only simulation to disable actions and Clear preview to discard the preview and log; it does not run custom HTML or dispatch to Pi. The CLI executes adapter code with ordinary Node privileges in a separate process, not a sandbox; the runner creates no live Pi, model or host, but trusted adapter code can. See the example and adapter reload and discovery.
The required PiFi-side compatibility check is pnpm test:plugins after building PiFi and installing the suite dependencies. It uses .github/compat-pi-plugins.json’s immutable commit and version, real Pi, and a clean suite and PiFi checkout; the suite defaults to ../pi-plugins or PIFI_PI_PLUGINS_DIR. CI checks out the pin and does not permit dirty overrides or skipping real Pi. For local paired development, explicitly set PIFI_PI_PLUGINS_DIR and use pnpm test:plugins -- --allow-dirty; add --current-suite to check a clean unpinned suite. These modes are not evidence for the pinned CI pair. In pi-plugins, node scripts/check-pifi.mjs runs the reverse check, selecting the core checkout with PIFI_DIR; CI enforces its own immutable core pin and clean checkouts. Both scripts print the revisions they check.
Building the npm package
The published package, @spencerboucher/pifi, is one bundled CLI: scripts/build-npm.mjs inlines the @pifi/* workspace packages into dist/pifi.mjs with esbuild, keeps third-party dependencies as ordinary npm dependencies, and ships the Pi bridge extension and the web app alongside.
pnpm build && pnpm build:npm # writes dist-npm/bash scripts/smoke-npm.sh # packs it, installs it into a temp prefix, runs `pifi up`pnpm build:client-npm # writes dist-client-npm/ for the typed Node SDKpnpm test:client-npm # packs and checks SDK imports, declarations, REST and WSWorkflow
-
Change on
dev(the main checkout’s branch), or on a branch in.worktrees/<branch>fromdevfor larger or parallel work, merged back intodev. Never commit tomaindirectly. -
Check. The pre-push hook is the local gate: lint, the TypeScript build, the tier and site checks and the fast tier, about 10 s. Do not run it, or parts of it, by hand before pushing, and do not run
pnpm build,pnpm test,pnpm test:slow, whole--projectruns orpnpm test:e2eas routine checks. While you work, run only the test files you changed or that cover what you changed (pnpm exec vitest run <file>; a slow one per the real-Pi rule above;pnpm exec playwright test <spec> --project=desktop-1440x900for a browser spec you changed). CI runs everything on every push in about 2.5 minutes: fast checks, five core-slow shards, the pinned compatibility matrix and a browser smoke test. Push, deploy for review and look at CI’s result afterwards; a red run blocks onlypromote.sh. -
Preview a branch. CI builds, lints and tests every push, and every push to a branch other than
mainanddevpublishesghcr.io/justmytwospence/pifi:br-<slug>(the coordinator) and:web-br-<slug>(the web app alone, Caddy on port 8080), each with a:sha-<short>/:web-sha-<short>tag (linux/amd64;scripts/preview-slug.sh <branch>gives the slug), as soon as the images build (about 1.5 minutes), while the tests keep running.scripts/preview.sh up, run from the branch’s worktree, picks a form from what the branch changes:- frontend (only
packages/web/,docs/,site/or top-level*.md; or--frontend): the branch’s web app athttps://<slug>.<domain>against the one real backend, signed in like the main web app (they share a sign-in domain). It acts on real data. - backend (anything else; or
--backend): a throwaway coordinator on the development server athttps://<slug>.<preview domain>with its own data and pairing-only sign-in (PIFI_PAIRING_ONLY, auth.md), plus a host agent on your workstation running the worktree’s build (launchdcom.pifi.host.pv-<slug>). It prints a single-use sign-in link;pairprints another.
downremoves a preview,lslists them andpruneremoves those whose branch is gone or merged intodev. - frontend (only
-
Deploy
dev. There is one PiFi backend, runningdevwith your real data: the coordinator and the NUC’s host on:dev, and the host agent on your workstation. A push todevpublishes:devand:web-dev(and theshatags) once the images build (the tests run alongside).scripts/deploy-dev.sh, run from any checkout whose HEAD isorigin/dev(the main checkout, or a worktree right aftergit push origin HEAD:dev), waits until ghcr’s:devand:web-devare that commit, backs up the coordinator database todata/backup/pre-<sha7>.dbwhen the new image has migrations the running one lacks (it keeps the last two), recreates the coordinator, the NUC host and the dev web app (https://dev.<domain>) from homelab’spifistack, checks each runs the commit, builds that commit (alongside CI, fromgit archive, into~/Library/Application Support/pifi-app) and restarts your workstation’s host agent (launchdcom.pifi.host) on it, and prints where the still-running tests can be followed. It touches no checkout, so a worktree session never has to update the main checkout to deploy. Anything handed over for review goes to a preview or dev first (see AGENTS.md).A deploy restarts the backend: terminal sessions reattach, and sessions running in the background are interrupted if they are mid-turn. The main web app (
https://<domain>) keeps working against the new backend, so a backend change must stay compatible with the previous web app: bumpWEB_API_LEVEL, orMIN_WEB_API_LEVELonce an old web app can no longer be served (packages/protocol/src/index.ts). A web app that falls outside the backend’s range shows a banner. -
Promote.
scripts/promote.shfast-forwardsmainto the CI-greendev(the whole run, tests and browser smoke included, must have passed), waits for theweb-mainworkflow to retag:web-mainto that commit’s web image, and recreates the main web app (https://<domain>) from it. Do it once what is on dev is approved. AvX.Y.Ztag is a separate step (see Releases) and moves nothing at home.
Rolling back
Deploys use rolling tags (dev, web-dev, web-main); homelab’s pifi/docker-compose.yaml reads PIFI_TAG, PIFI_WEB_DEV_TAG and PIFI_WEB_MAIN_TAG to override them. Find the previous commit’s sha-<short> and web-sha-<short> tags.
- Backend:
ssh nuc 'cd ~/Projects/homelab && PIFI_TAG=sha-<previous> docker compose -f pifi/docker-compose.yaml up -d pifi pifi-host'. If that deploy brought migrations, restore the backup first, with the coordinator stopped:docker compose -f pifi/docker-compose.yaml stop pifi, thendocker run --rm -v ~/Projects/homelab/pifi/data:/data ghcr.io/justmytwospence/pifi:sha-<previous> coordinator restore /data/backup/pre-<sha7>.db --data-dir /data. - Web apps: the same with
PIFI_WEB_MAIN_TAG=web-sha-<previous>orPIFI_WEB_DEV_TAG=web-sha-<previous>, runningup -d pifi-web-mainorpifi-web-dev.
The next deploy-dev.sh or promote.sh returns to the rolling tags.
Coordinators and hosts are upgraded independently, so the coordinator must keep working with hosts one release behind: keep changes to the host wire protocol (packages/protocol/src/host-wire.ts) backward compatible, or release them so the coordinator moves first.
Releases
Pushing a v* tag publishes a public release and deploys nothing at home (only after promotion and explicit release approval). It runs .github/workflows/release.yml:
- image: builds the container on native linux/amd64 and linux/arm64 runners and publishes one multi-platform tag to GHCR;
- npm: builds and smoke-tests both the CLI and
@spencerboucher/pifi-clientSDK, then publishes each with npm trusted publishing (GitHub OIDC, with provenance), skipping an exact version that is already on npm. First publication of the SDK may require configuring its trusted publisher in npm; do not substitute a long-lived npm token. See client-sdk.md.
Every package shares the version in its package.json. A release also bumps the image tag pinned in deploy/ (deploy/compose.yaml and every recipe in deploy/compose/); pnpm test:deploy fails until they match.