Skip to content

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.

Terminal window
pnpm i
pnpm build # tsc -b for every TypeScript package, then the web bundle
pnpm lint # Biome
pnpm test # Vitest, all packages
pnpm test:fast # Vitest on the fast tier's files only (no coordinator, Pi or processes), seconds
pnpm test:slow # slow files except pinned plugin compatibility
pnpm test:tiers # validate the CI partition and its negative controls
pnpm test:e2e # Playwright: every spec on desktop, layout specs at compact and phone sizes
pnpm test:e2e:smoke # the @smoke subset CI runs

Register 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):

Terminal window
npx skills add justmytwospence/pifi -s pifi-plugin-development -a codex claude-code --copy -y

For 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:

Terminal window
pnpm adapter:preview -- --adapter packages/adapter-examples/src/hello --fixture packages/adapter-examples/fixtures/hello.json > /tmp/hello-preview.json

Upload 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.

Terminal window
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 SDK
pnpm test:client-npm # packs and checks SDK imports, declarations, REST and WS

Workflow

  1. Change on dev (the main checkout’s branch), or on a branch in .worktrees/<branch> from dev for larger or parallel work, merged back into dev. Never commit to main directly.

  2. 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 --project runs or pnpm test:e2e as 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-1440x900 for 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 only promote.sh.

  3. Preview a branch. CI builds, lints and tests every push, and every push to a branch other than main and dev publishes ghcr.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 at https://<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 at https://<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 (launchd com.pifi.host.pv-<slug>). It prints a single-use sign-in link; pair prints another.

    down removes a preview, ls lists them and prune removes those whose branch is gone or merged into dev.

  4. Deploy dev. There is one PiFi backend, running dev with your real data: the coordinator and the NUC’s host on :dev, and the host agent on your workstation. A push to dev publishes :dev and :web-dev (and the sha tags) once the images build (the tests run alongside). scripts/deploy-dev.sh, run from any checkout whose HEAD is origin/dev (the main checkout, or a worktree right after git push origin HEAD:dev), waits until ghcr’s :dev and :web-dev are that commit, backs up the coordinator database to data/backup/pre-<sha7>.db when 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’s pifi stack, checks each runs the commit, builds that commit (alongside CI, from git archive, into ~/Library/Application Support/pifi-app) and restarts your workstation’s host agent (launchd com.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: bump WEB_API_LEVEL, or MIN_WEB_API_LEVEL once 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.

  5. Promote. scripts/promote.sh fast-forwards main to the CI-green dev (the whole run, tests and browser smoke included, must have passed), waits for the web-main workflow to retag :web-main to that commit’s web image, and recreates the main web app (https://<domain>) from it. Do it once what is on dev is approved. A vX.Y.Z tag 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, then docker 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> or PIFI_WEB_DEV_TAG=web-sha-<previous>, running up -d pifi-web-main or pifi-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-client SDK, 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.