Skip to content
brain.GitHub
Developer docs OPEN SOURCE

Development & verification

Set up the workspace, run the verification suite, regenerate contracts, preview the docs site, and see how CI publishes releases.

This guide is for contributors. It covers how to set up a local development environment for Brain, run the full verification suite, regenerate the OpenAPI document and SDK wire types, preview the documentation site, and how CI tests and publishes each release.

Prerequisites

  • Go 1.26+ (go.mod declares go 1.26.0)
  • Node.js 24+ and npm

Python 3.11+ must also be available as python for the sandbox execution fixture.

1. Install workspace dependencies

Install the locked dependencies for the three harness runners, TypeScript SDK, sandbox and browser services, documentation site, and dashboard:

node scripts/setup.mjs

The script installs each workspace lockfile and Chromium for the browser journeys. On Linux, install Chromium's OS dependencies with npm --prefix tools/browser exec -- playwright install-deps chromium.

To build BrainServer from the repository root, run:

npm run build

This builds the Pi harness, TypeScript client, and Go executable together and writes npm archives to dist/server/. Use npm run build -- --all-platforms to cross-compile all six supported platforms.

2. Run all checks

Run node scripts/check.mjs before you commit:

node scripts/check.mjs

It runs these steps in order and stops at the first failure:

  1. go run ./services/brain/cmd/generate -check and node clients/sdks/typescript/scripts/generate.mjs --check: verify the service OpenAPI contract, runtime protocol schema and TypeScript declarations against their Go sources.
  2. npm --prefix runtimes/pi run build: compiles Pi; Codex and OpenCode build commands validate their JavaScript entry points.
  3. npm --prefix clients/sdks/typescript run build: compiles the TypeScript SDK (clients/sdks/typescript/dist/).
  4. node scripts/package-sdks.mjs: packs and installs the npm package in an isolated consumer, then runs client tests, CLI help and a strict TypeScript consumer check. The suite also runs npm run build and node --test tests/server-package.test.mjs. These build the server, Pi harness, and client together, install their npm archives outside the checkout, and exercise model calls, application tools, restart recovery, startup failures, and parent-exit cleanup. Linux CI cross-compiles the six platform executables into the tested server release artifact.
  5. go test -count=1 ./...: runs all Go unit and integration tests across the services, runtimes and shared packages.
  6. go vet ./...: runs Go static analysis.
  7. npm --prefix runtimes/pi test: runs the Pi runner unit and integration tests against a local recording provider.
  8. npm --prefix clients/sdks/typescript test: runs the TypeScript SDK test suite.
  9. The sandbox and browser services run their test suites, including real Chromium network and cancellation checks.
  10. The three suites in tests/journeys/ run the end-to-end journeys through installed clients and all three native harnesses, including browser attachment and the remote service.
  11. node --test tests/platforms.test.mjs: validates the platform deployment examples under examples/platforms/.
  12. node --test tests/registry-artifacts.test.mjs: tests the SDK release workflow's admission checks and registry publication, including partial uploads, registry outages, and version reuse.
  13. npm --prefix sites/docs run build: generates the derived docs pages and builds the static Next.js / Fumadocs export.
  14. npm --prefix sites/docs test: runs sites/docs/scripts/site.test.mjs.
  15. npm --prefix sites/dashboard run build and npm --prefix sites/dashboard test: builds the dashboard and verifies authentication, session workflows, reconnects, usage accounting, and mobile navigation in Chromium.

3. Regenerate contracts and docs

When you edit Go route declarations, wire structs, or shared Markdown sources, regenerate the derived artifacts:

# Regenerate services/brain/api/openapi.json, runtimes/pi/src/generated.ts,
# clients/sdks/typescript/src/generated.ts, and runtimes/host/protocol.json
go run ./services/brain/cmd/generate
node clients/sdks/typescript/scripts/generate.mjs

# Regenerate sites/docs/content/docs/** generated pages and sites/docs/public/openapi.json
npm --prefix sites/docs run generate

4. Preview the documentation site

Regenerate the derived pages and start the local Next.js development server:

npm --prefix sites/docs run dev

Open http://127.0.0.1:3000/docs. To test the static production export locally, build it, run the site tests, and serve sites/docs/out on port 3000:

npm --prefix sites/docs run build
npm --prefix sites/docs test
npm --prefix sites/docs start

Where to edit what

The dashboard lives in sites/dashboard/. Build the TypeScript SDK, then run npm --prefix sites/dashboard run dev to open it on port 3100. See the dashboard guide for connecting to a deployment and using the session workspace.

Don't hand-edit generated files (services/brain/api/openapi.json, runtimes/pi/src/generated.ts, clients/sdks/typescript/src/generated.ts, sites/docs/public/openapi.json, or generated MDX pages). Edit the source of truth and run the corresponding generator:

AreaSource of truthRegenerate with
HTTP routes, summaries, and wire typesservices/brain/internal/http/contract.go & services/brain/api/types.gogo run ./services/brain/cmd/generate, node clients/sdks/typescript/scripts/generate.mjs, then npm --prefix sites/docs run generate
Harness & storage Go interfacesruntimes/host/harness.go, runtimes/host/process.go, services/storage/archive/*.gonpm --prefix sites/docs run generate
Model catalogPinned @earendil-works/pi-coding-agent in runtimes/pi/package.json (runtimes/pi/scripts/model-catalog.mjs)npm --prefix sites/docs run generate
Persistence guidedocs/running-persistence.mdnpm --prefix sites/docs run generate
Local tools walkthroughexamples/tools/README.mdnpm --prefix sites/docs run generate
Sandbox service guidetools/sandbox/README.mdnpm --prefix sites/docs run generate
Resource service guidetools/resources/README.mdnpm --prefix sites/docs run generate
Platform examples guideexamples/platforms/README.mdnpm --prefix sites/docs run generate
Roadmapdocs/roadmap.mdnpm --prefix sites/docs run generate
Docs pages & guidessites/docs/content/docs/**/*.mdxnpm --prefix sites/docs run build

Follow the writing guide when you change the README, a docs page, or a shared Markdown source.

Repository ownership

  • services/<service>/cmd/<program>/ contains Go executable startup and configuration. Each service owns its api/ and private internal/ packages.
  • services/brain/api/openapi.json is generated from Brain's Go types and route declarations using Huma schemas. openapi-typescript generates the TypeScript contract; openapi-fetch implements typed SDK requests.
  • clients/cli/ uses Commander and the public SDK. Its build helper lives in clients/cli/scripts/; repository packaging and verification live in root scripts/.
  • runtimes/ owns agent integrations and runnable payloads. The generic Sandbox service owns their environments and processes. See the runtime layout.
  • services/storage/internal/dirlock/ is Storage's private cross-platform directory ownership lock. Shared exporter configuration lives in services/shared/telemetry/; service instruments stay beside their emitters.

Design documents

The roadmap lists release stages, planned work, and integration status, and links every design document. Start with the Brain intents for ownership boundaries and design decisions, and the implementation plan for how the work is split across runtime, persistence, harnesses, tools, API, and operations.

CI and releases

The CI workflow runs on every push and pull request, and weekly:

  • Checks: node scripts/check.mjs on Linux and Windows. On Linux, the job also builds the Brain and sandbox tool images and smoke-tests both containers.
  • Race detection: go test -race ./... on Linux.
  • PostgreSQL: the session index tests against a real PostgreSQL server.
  • Docs: builds the site for its GitHub Pages path and runs the site tests.
  • CodeQL: code scanning for Go, JavaScript/TypeScript, Python, and GitHub Actions.

Nothing publishes unless every job passes. After that, each push to main:

  1. Publishes the tested images to ghcr.io/aexhq/brain and ghcr.io/aexhq/brain-sandbox-tools, tagged sha-<commit> and main, with build provenance attestations.
  2. Deploys the tested docs site to GitHub Pages, then smoke-tests the published site.
  3. Starts the SDK release, which publishes the SDK archives tested on Linux to npm through registry trusted publishing, without rebuilding them, and attaches the same archives to a GitHub release.

SDK 2.1.0 is the client for the current server and replaces the predecessor's 0.x API. The server's routes and local state have no versioning or compatibility layer, so pin production images by digest and use the SDK version that matches your server commit. SDK delivery covers versioning, the release workflow, and registry setup.

On this page