TEHAS

Installing tehas for a new project

One install serves one project: one host, one Unix user, one product repository. Installing it for another repository is a release, one setup command, a few files in the product, and a label. No script is edited and nothing of tehas is cloned.

What you get is issue to pull request: the queue, cycles, gates, the dashboard and the live console. The effort is settings, plus your toolchain in the sandbox image. This page walks through it with the instance that works on tehas itself: host tehas-tehas, user boss, product tehas-app/tehas.

What the product repository must provide

This is the contract. It lives in the product repository and is written by people. Tehas reads the gate in .pi/verify-cmd of a cycle's clone before the cycle starts, and preview/Dockerfile of a pull request's commit when previews are on; pi-rukas reads the rest of it.

File Purpose Required
AGENTS.md The rules agents work under: architecture rules, how to verify, commit style, what never to touch. No sentence granting merge rights, unless you want auto-merge Yes
.pi/verify-cmd Fast gate. The first line that is not empty or a comment is run in the cycle's worktree, 30 minute limit by default (TEHAS_VERIFY_TIMEOUT). Without it pi-rukas guesses from package.json or Cargo.toml, and for other stacks verifies nothing. tehas work checks the commit the cycle's clone was made at before the cycle starts: with no gate and neither package.json nor Cargo.toml there the cycle parks and nothing is pushed Yes
.pi/verify-cmd-full Full gate, same format; stands in for CI Recommended
.pi/verify-cmd-fast Optional developer's gate, same format. With it, pi-rukas tells the developer to run this command and not .pi/verify-cmd, and runs it ahead of .pi/verify-cmd wherever its driver gates
.pi/smoke-cmd Proves the built product starts, same format Recommended
.pi/worktree-setup POSIX sh script run in each new worktree with no arguments and no environment: install dependencies. Must exit 0. Run as sh .pi/worktree-setup, so its first line and its mode are not read: a bash script fails there If a bare checkout cannot run the gates
.pi/work.json The lean driver's settings: whether lean may merge, its gates, its budgets. Only lean reads it. See .pi/work.json Optional
.pi/install-cmd The install of the product's dependencies, run at the root of the cycle's clone before the cycle, in place of the one tehas finds from the lockfiles (below). Same format as the gate Only when the lockfiles cannot tell it
.pi/settings.json Provider and model of the session, when they are not the instance's Optional
.agents/skills/ Project skills: short instructions plus scripts for things agents get wrong Optional

Dependencies need no file. Before a cycle starts, tehas work installs them in the cycle's clone, in the sandbox image, from the lockfiles at the root of the commit and one directory down. Each runs in its directory:

Lockfile Install
bun.lock, bun.lockb bun install --frozen-lockfile
package-lock.json npm ci
pnpm-lock.yaml pnpm install --frozen-lockfile
yarn.lock yarn install --immutable, --frozen-lockfile on yarn 1
Cargo.lock cargo fetch --locked
uv.lock uv sync --frozen
poetry.lock poetry install --no-root
go.sum go mod download
Gemfile.lock bundle install
composer.lock composer install

One install per kind and directory: a directory with pnpm-lock.yaml and package-lock.json runs pnpm only. A lockfile under node_modules/, vendor/, target/ or a submodule is not the product's. A worktree pi-rukas makes in the clone then finds the installed tree in its main checkout, which is what .pi/worktree-setup scripts that link node_modules from there expect. An install that fails, or a tool the image does not have, stops the cycle before it starts (exit 78). The install has the cycle's limits and security options, the workspace and no token. What goes to the container's home, such as cargo's or go's download cache, is not kept for the cycle.

This repository is a product too, so its own AGENTS.md and .pi/ are a small working example to copy from. pi-rukas's own state files in a cycle's clone (.pi/work-state/, .pi/lean-state/, .pi/permissions.json, .pi/decisions.json) are kept out of git by tehas work, so the product needs no .gitignore lines for them. Make the gates print one line per step and exit non-zero on failure. Before going further, prove them by hand in a clean checkout.

You do not have to write them first: step 4 checks them and proposes the missing ones in a pull request.

A repository with no gate is caught before any model time is spent. tehas work reads .pi/verify-cmd at the commit the cycle's clone was made at; when its first line that is not empty or a comment is missing, and that commit holds neither package.json nor Cargo.toml, the cycle parks with 78, prints one line naming the missing file, and pushes nothing. The clone it made stays on the host beside the workspace of the cycle before it, and neither is removed. With either of those two files a cycle runs as it did before, because pi-rukas derives a gate from them.

Two things follow. Only what is in the commit is read, so a file a person leaves uncommitted or untracked in the product checkout decides nothing about whether a cycle starts. And the check is one of presence, not of validity: pi-rukas takes any file at those paths for a gate, so a stub package.json or a one-line .pi/verify-cmd clears it while the cycle still verifies nothing. It is a guard on the cost of a start, not proof that a real gate exists at merge time.

Work lands on the repository's default branch: pi-rukas branches from it and the pull request targets it. tehas reads the default branch from the checkout. Set TEHAS_BRANCH only to use another one.

The spec block lean needs

A cycle on the lean driver works from one fenced block in the issue's text whose info string is exactly pi-spec v1. Its content is JSON, and it is the whole brief: lean reads no scope, criteria or size from the prose around it. Classic does not read it.

A manual criterion, or a command one the gate could not run, keeps the pull request a draft, and a draft never waits for a merge. An example, for an issue of the tehas-tehas instance:

```pi-spec v1
{
  "problem": "tehas work takes a --driver word it does not know",
  "criteria": [
    { "id": "AC1", "text": "--driver with a word other than lean or classic exits 64", "verify": "test" },
    { "id": "AC2", "text": "--driver with no word exits 64", "verify": "test" }
  ],
  "scope": { "paths": ["console/cycle/src/main.rs"] },
  "size": "S"
}
```

pi-rukas's /plan writes the block into an issue it files. A plan written over an issue with Update this issue keeps the block the issue had and writes none of its own, so an issue written by hand needs a block written by hand. With tehas:lean on an issue that has no block, or not one block of valid JSON, no cycle starts and the poll says why once. A block of valid JSON that lean refuses, for a missing field or a size L, ends the cycle not ready: tehas parks the issue with the rules lean says it failed. See Troubleshooting. The fields are pi-rukas's: its docs/lean.md is the reference.

The lean driver's settings

Only the lean driver reads .pi/work.json, at the run's base commit, never from the working tree. Without it lean takes its defaults, and they name no verify.test: a spec with a test criterion then ends not ready, no test runner configured. tehas's comment on the issue then says the repository needs the setting and that the issue's text is fine. A person writes it: it is under .pi/, so a cycle never changes it (AGENTS.md rule 7).

{
  "version": 1,
  "autoMerge": false,
  "verify": {
    "fast": "scripts/verify.sh --changed",
    "full": "scripts/verify.sh"
  }
}

A file that does not parse, or holds a field lean refuses, stops the run: it is not defaulted. The full reference is pi-rukas's docs/configuration.md.

The install

The steps below install from a release, on one Linux machine that can reach GitHub and an OpenAI-compatible model endpoint. bootstrap.sh supports Ubuntu 26.04 on x86_64 only.

1. The release

As root:

curl -fsSL https://github.com/tehas-app/tehas/releases/latest/download/install | sudo sh -s -- boss

The installer downloads the newest release and checks the tarball against its .sha256 and its minisign signature, with the key written in the installer, not one from the download. A download that fails either check is not unpacked. Then it runs that release's bootstrap.sh root boss: it makes the user when it is missing, installs the packages and Docker, adds the user to the docker group, turns lingering on, installs the slice, and installs the pinned tools as the user in the same run, so no logout is needed. The release ends up in ~boss/tehas/versions/<version>, with ~boss/tehas/current pointing at it. --version vX.Y.Z installs another release, and --version vX.Y.Z-beta.N (or -alpha.N, -rc.N) a prerelease, which is never the newest. Bootstrap a host has what the machine needs.

To install from files you downloaded yourself, for example on a host that cannot reach GitHub, pass their directory. The newest release's tag comes from gh release view -R tehas-app/tehas --json tagName:

gh release download <tag> -R tehas-app/tehas --pattern 'tehas-*' --pattern install -D /tmp/tehas-release
sudo sh /tmp/tehas-release/install --version <tag> --from /tmp/tehas-release boss

The tehas user ends up in the docker group, which makes it root-equivalent on the host. The boundary that matters is the sandbox: agents never get the Docker socket.

2. What setup asks for

3. tehas setup

As the tehas user. tehas is not on the PATH until the first install has put the env.sh line in ~/.bashrc, so the first run names the release:

~/tehas/current/bin/tehas setup --repo tehas-app/tehas --labelers "janit" \
  --new-app --endpoint http://gb1:8086/v1

--new-app prints one link. Paste it into your browser's address bar (or copy ~/.config/tehas/new-app.html from the host to your machine and open it), check the permissions and create the app, then paste the address GitHub opens back at the prompt. Setup writes the app's key and ID, prints the install link and waits for the installation. With an app you have, give --app-id <id> --app-key-file <key> instead. It asks for what it is not given when there is a terminal. In this order, and stopping at the first step that fails, it:

  1. checks that the endpoint offers the model, makes the app with --new-app, checks that the app is installed on the repository and may write its contents, issues and pull requests, names any other repository of the instance it does not reach, and makes the control issue;
  2. writes ~/.config/tehas/instance.env with the required settings and TEHAS_GITHUB_APP_ID, models.json, the app's key in ~/.config/tehas/github-app.pem and the model key in ~/.config/tehas/env, mode 600;
  3. gives git the bot's name and noreply address, unless it has one; the bot is <slug>[bot];
  4. clones the product to ~/tehas/repos/<name>, or fast-forwards the checkout that is there;
  5. runs install.sh from the release, then tehas labels;
  6. builds the sandbox image and runs the product's gates in it with tehas check-product --sandbox;
  7. enables the dispatch timer and path, starts the docs server and prints the dashboard's address.

A second run changes nothing that is right. A setting that is there and differs is not replaced without --force. See tehas setup.

A program that brings a host current without a terminal runs install.sh and then tehas update --pending: the copies, then the follow-ups install.sh recorded in ~/tehas/state/update-pending. --pending runs no git command and no install.sh, so it finishes an install on a host whose checkout is at a release tag or whose remote is not reachable, where tehas update stops. See tehas update.

4. The product's files

tehas check-product
tehas init-product

tehas check-product says which files of the contract above the default branch lacks, and exits 3 when one is missing. tehas init-product writes the missing AGENTS.md, .pi/verify-cmd and .pi/worktree-setup on a branch and opens a pull request with the bot. The gate is guessed from the stack: check it, then merge it. See tehas check-product.

5. The sandbox image

The platform's host/sandbox/Dockerfile adds shellcheck, tehas's jq, TypeScript's native tsc and Playwright's Chromium to the pi-rukas image and remaps the user id. It is part of the release and is replaced by the next one, so your toolchain does not go there.

Put it in sandbox.Dockerfile in your instance directory instead (the one directory instance.env and models.json live in, which you keep writable by the tehas user alone: install.sh --check reports it if instance.env is not). When that file is there, ~/tehas/sandbox/build.sh builds the image above first and then builds your file on top of it, so the tag cycles run is yours. What the file says is run as root inside the image, and the image is what every cycle runs with the bot's token: the file is trusted exactly as much as the platform's own Dockerfile is, so it belongs to the tehas user and nowhere else. It starts with these two lines, which take the image to build on as an argument rather than a name:

ARG TEHAS_BASE
FROM $TEHAS_BASE
RUN apt-get update -qq \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends cmake \
 && rm -rf /var/lib/apt/lists/*

An apt-get install with no version takes whatever the mirror served that day, so the image then depends on a mirror you do not control. The platform's own Dockerfile pins what it fetches and checks each download by checksum; for a tool your gates depend on, name the version (cmake=3.31.6-1) or add an apt pin file beside the file and COPY it in.

The build runs with the instance directory as its context, so the file can COPY a script or a config that lives beside it. A sandbox.Dockerfile that changed since the last install makes install.sh owe the sandbox step, the same as a change to the tracked Dockerfile or versions.env; tehas update or a run of tehas setup then rebuilds. The layer is also labelled with the sum of the file and of the files its COPY and ADD lines name, so build.sh --if-moved, which setup, update and bootstrap.sh user run, rebuilds when either changed since the image was built. A file that does not build, or a layer that fails its smoke run, fails the build and leaves the tag cycles run on the platform image this build made, without your layer, and the build says so. A build killed partway leaves it there too. Until the layer builds, cycles run without what it adds, so fix the file and re-run ~/tehas/sandbox/build.sh.

After a change to the file, rebuild and check the gates again:

~/tehas/sandbox/build.sh
tehas check-product --sandbox

The product's Node

The image's Node is tehas's own, the NODE_VERSION of versions.env, so a tehas update that moves it moves the Node your tests run on. To keep your own, install it in the instance layer, in a prefix of its own, and put it first on PATH. instances/example/product-node.Dockerfile does this: copy it to sandbox.Dockerfile (or add its lines to the one you have), set PRODUCT_NODE_VERSION and its PRODUCT_NODE_SHA256 from the release's SHASUMS256.txt, then rebuild and check the gates as above. A version or a sum left empty fails the layer.

The product's install, its gates and the agents' shell commands then find your node and npm. Pi and the npm tools tehas ships (pi, ctx7, parallel-cli) do not: tehas's Node lives in /opt/tehas-node, and they are started by it by its path, so a product's Node does not run them. Do not unpack your Node over /usr/local or /opt/tehas-node. tehas does not read the product's .nvmrc or engines: a change to the product does not change the image.

tehas index builds the code index the agents search, which needs the image. install.sh does it too, as long as there is no index yet. See tehas index.

6. Prove the gates in the sandbox

tehas setup builds the sandbox image when there is none, it is not on the commit PI_RUKAS_FOLLOW resolves to or it was not built from the instance's sandbox.Dockerfile as it is now, then runs tehas check-product --sandbox once. It runs the product's install and its own gates inside the image, as the unprivileged user, with nothing mounted but a clone made as a cycle's is, with origin/main and origin/HEAD, and checks the contract files first. The install runs at the root of the clone and the gates in a worktree of it, as in a cycle. Both containers get the limits a cycle's container gets on this host (see Limits and concurrency): --memory is the slice's MemoryMax over TEHAS_SLICE_CONTAINERS and --cpus the host's CPUs less one. No cpuset is set, so nproc inside still counts the host's CPUs, as in a cycle. When the slice cannot be used the check stops with 78 and the line tehas work would print, and starts nothing. By hand, for a product whose one lockfile is extension/bun.lock, with $M the memory ceiling and $C the CPUs, it is:

T=~/tehas/tmp/contract-test
git clone -q ~/tehas/repos/<name> "$T/clone"
git -C "$T/clone" worktree add -q --detach "$T/tree"
docker run --rm --cgroup-parent tehas.slice --memory "$M" --memory-swap "$M" --cpus "$C" \
  --user "$(id -u):$(id -g)" \
  -e HOME=/home/vscode -v "$T:$T" -w "$T/clone/extension" --entrypoint bash \
  "$PI_ENSEMBLE_IMAGE" -c 'bun install --frozen-lockfile'
docker run --rm --cgroup-parent tehas.slice --memory "$M" --memory-swap "$M" --cpus "$C" \
  --user "$(id -u):$(id -g)" \
  -e HOME=/home/vscode -v "$T:$T" -w "$T/tree" --entrypoint bash \
  "$PI_ENSEMBLE_IMAGE" -c '
    sh .pi/worktree-setup &&
    sh -c "$(grep -v -e "^#" -e "^$" .pi/verify-cmd-full | head -n 1)" &&
    sh -c "$(grep -v -e "^#" -e "^$" .pi/smoke-cmd | head -n 1)"'
rm -rf "$T"

The container runs in the slice like the factory's own, so the dispatcher counts its memory while it is there.

7. Start

Label one small, well-specified issue with tehas:ready and watch it on the dashboard. Operating tehas takes it from there, and Updating tehas says how a host moves to a new release and back.

Settings by hand

tehas setup writes the instance to ~/.config/tehas, the default place. To write it by hand, or to keep it in a private repository of your own, copy instances/example/ from the release (~/tehas/current/instances/example/) and fill it in. Keep the directory out of ~/tehas: an update replaces what is there. When it is not ~/.config/tehas itself, name it:

echo ~/my-instance >~/.config/tehas/instance-dir

instance.env holds the required settings. optional.env beside it lists the optional ones with their defaults and what each turns on; copy a line over to turn one on.

Setting What to put there
TEHAS_REPO owner/name of the product repository
TEHAS_CONTROL_ISSUE Number of an issue you create for the pause label. Keep it open
TEHAS_ALLOWED_LABELERS Logins whose labels count, space separated: tehas:ready, tehas:plan, tehas:prototype. Never the bot
PI_ENSEMBLE_SUBAGENT_MODEL, _PROVIDER The model the session and every agent role use unless one has its own. Must be listed in models.json
PI_ENSEMBLE_MODEL_<ROLE>, PI_ENSEMBLE_PROVIDER_<ROLE> Optional. A model for one role, such as the lens reviewers, so cycles do not all wait on one model. See A model per role
PI_ENSEMBLE_HOST_ALIASES Optional. name:address pairs the sandbox needs, such as a model host whose name only resolves privately
TEHAS_HOST_ADDR Optional. The host's private address, to reach the dashboard from other devices. Without it: 127.0.0.1

models.json next to it names the provider's baseUrl and the models it serves. List the model you use first: an agent that loses its model setting falls back to the first entry. A model needs only its id: install.sh fills name (the id), input (["text"]), reasoning (false) and a cost of zero, and gives a provider with no compat today's (supportsDeveloperRole and supportsReasoningEffort false). A key you give is kept. The session model is PI_ENSEMBLE_SUBAGENT_MODEL under _PROVIDER, unless the product's .pi/settings.json names another; that one must be listed too. An endpoint that takes a key gets "apiKey": "$TEHAS_MODEL_KEY_MAIN" and the token in ~/.config/tehas/env, never in models.json. A second endpoint for the same models goes in backupBaseUrl: see A backup model endpoint.

Everything else has a default. No setting describes the machine: every sandbox container runs in tehas.slice, which the installer set up and which is limited to three quarters of the host's memory. The dispatcher starts a cycle only while the slice has room for one more TEHAS_CYCLE_RESERVE, 2g by default, and holds fewer than TEHAS_SLICE_CONTAINERS containers, four by default. A host with less than about 11 GiB of memory needs a lower reserve. All settings are on the commands page.

After a change to the instance, run ~/tehas/current/install.sh --check, then tehas update, which runs install.sh and the follow-ups it asks for. Where the checkout cannot be moved - it is at a release tag, or its remote does not answer - tehas update --pending runs the follow-ups install.sh recorded and no git command; see tehas update.

Optional parts

tehas-energy.service is optional: set TEHAS_ENERGY=on only when your model endpoint is a viiwork mesh. It is a switch, on or off, and any other value stops every command with 78. With any other endpoint leave it unset: an update restarts a unit only where it already runs. See the energy sampler.

Aside: the tehas-tehas instance

The instance that works on tehas itself has a few extras. Its settings are in instances/tehas-tehas/ in this repository; the host keeps its own copy in ~/.config/tehas/instance. The start of its instance.env, without its comments:

TEHAS_REPO=tehas-app/tehas
TEHAS_CONTROL_ISSUE=1
TEHAS_ALLOWED_LABELERS="janit"

PI_ENSEMBLE_SUBAGENT_MODEL=qwen3.8-flash-next
PI_ENSEMBLE_SUBAGENT_PROVIDER=fleet
TEHAS_SITE_INDEXING=on

# from ~/.config/tehas/private.env on the host
PI_ENSEMBLE_HOST_ALIASES=gb1:<the model host's private address>
TEHAS_HOST_ADDR=<this host's private address>

TEHAS_SITE_ANALYTICS_SRC=https://ea.trippi.app/ea.js
TEHAS_SITE_ANALYTICS_NAME=tehas
TEHAS_SITE_ANALYTICS_COOKIE=on
{
  "providers": {
    "fleet": {
      "api": "openai-completions",
      "baseUrl": "http://gb1:8086/v1",
      "apiKey": "unused",
      "compat": { "supportsDeveloperRole": false, "supportsReasoningEffort": false },
      "models": [
        {
          "id": "qwen3.8-flash-next",
          "name": "Qwen3.8 Flash Next (fleet)",
          "reasoning": false,
          "input": ["text", "image"],
          "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
          "contextWindow": 262144,
          "maxTokens": 32768,
          "compat": {
            "supportsReasoningEffort": false,
            "supportsDeveloperRole": false,
            "maxTokensField": "max_tokens",
            "thinkingFormat": "qwen-chat-template"
          }
        }
      ]
    }
  }
}

A preview of every pull request

Optional. With TEHAS_PREVIEWS=on and TEHAS_DOMAIN in instance.env, tehas keeps a running copy of the product for every open pull request whose branch is in the product repository and that an owner, member or collaborator of the repository opened. Previews has what the host and the domain need. The product's part is one file:

This repository's own preview/Dockerfile is the example: the manual and the dashboard on sample data, served by the same server a host uses. To try a recipe by hand, from the product's checkout:

git archive HEAD | docker build --network none -f preview/Dockerfile -t tehas-preview:local -
docker run --rm -p 127.0.0.1:18080:8080 --read-only --tmpfs /tmp --tmpfs /config --tmpfs /data \
  --cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges:true \
  --memory 256m --cpus 1 --pids-limit 128 --log-opt max-size=10m --log-opt max-file=2 \
  tehas-preview:local

That is what tehasbot preview does, but for the port: a real preview has none published and is reached through the edge router, on a network that has the other previews on it and leads nowhere else.

What is not there yet