TEHAS

A GitHub App for a factory

A factory acts on GitHub as one identity: it labels, comments, pushes branches and opens pull requests. That identity is a GitHub App, one app for everything this factory does. A machine user (a second GitHub account with a personal access token) is not used: GitHub can suspend a user account that automation drives hard, and then everything the account wrote is hidden and every poll fails. That happened to tehas-tehas on 2026-10-24.

An app is not a user. Its installation tokens last one hour, reach only the repositories it is installed on, and its writes show as <slug>[bot]. tehas makes and renews the tokens itself: nothing on the host holds a long-lived GitHub token. The factory is named by one setting, TEHAS_GITHUB_APP_ID. The installation and the bot's login are looked up at GitHub and kept in ~/tehas/state/github; they are not settings.

Make the app with tehas setup

tehas setup --new-app

Setup prints one link. Open it in a browser signed in to the account that should own the app: GitHub shows the app's name and permissions, filled in. Press Create GitHub App. GitHub then opens a page whose address ends in ?code=...&state=.... Paste that address (or the code alone) at setup's prompt. Setup turns the code into the app, writes the key to ~/.config/tehas/github-app.pem (mode 600) and the app's ID to instance.env as TEHAS_GITHUB_APP_ID, keeps the app's client id and client secret beside the key for the plugins' sign-in, and prints the install link. Install the app on the product repository, and on the repository review findings go to if it is another one. Setup waits up to 10 minutes for that, then goes on.

--app-owner <login> sets the organisation or user that owns the app (the repository's owner by default) and --app-name <name> its name (<repository>-factory by default; the slug of the name becomes the bot's login). The code lasts an hour and works once. Run tehas setup again to start over.

To use an app you already have, give its ID and key:

tehas setup --app-id <App ID> --app-key-file <downloaded>.private-key.pem

The client, for the plugins' sign-in

A plugin's view is served only to a person GitHub says has access to the repository, who signs in through the app's web flow (the gate of the views). That needs two things of the app: a callback URL and a client secret. tehas setup --new-app sets the callback in the manifest when instance.env has TEHAS_DOMAIN, and keeps the client id and secret GitHub returns in ~/.config/tehas/github-app.client-id and github-app.client-secret, mode 600. With TEHAS_EDGE_ONE_LEVEL=on the name is plugins-<sub>.<domain>.

An app made before has neither. On the app's settings page, General:

  1. Under Callback URL, add https://plugins.<domain>/_auth/callback and save.
  2. Note the Client ID.
  3. Under Client secrets, press Generate a new client secret and copy it into a file. GitHub shows it once.

Then, as the tehas user:

tehas setup --app-client-id <Client ID> --app-secret-file <file>

Setup checks the rest as on any run, then writes the two files, mode 600. Remove the file you copied the secret into. Plugins are still being built in this release: nothing reads the two files until the gate runs.

tehas setup lists every step. Setup ends with tehas github check.

Make the app by hand

Do this on a host that was set up before the wizard, or to see what the wizard asks for. In the organisation (or account) that owns the product repository: Settings, Developer settings, GitHub Apps, New GitHub App.

Field Value
GitHub App name <product>-factory, for example. Its slug becomes the bot's login, <slug>[bot]
Homepage URL The product repository's URL. Nothing calls it
Callback URL https://plugins.<domain>/_auth/callback, with the instance's TEHAS_DOMAIN, for the plugins' sign-in. Empty without a domain
Setup URL Empty
Expire user authorization tokens Leave on. tehas uses installation tokens, which always last one hour
Request user authorization (OAuth) during installation Off
Enable Device Flow Off
Webhook, Active Off. tehas polls; it needs no public address
Where can this GitHub App be installed? Only on this account

Repository permissions, everything else "No access":

Permission Access What tehas does with it
Contents Read and write Push cycle branches, read the code and releases
Issues Read and write Labels, comments, issue edits, closing
Pull requests Read and write Open, edit and ready pull requests
Metadata Read-only Required by GitHub
Actions Read-only Read CI runs
Checks Read-only Read a pull request's checks
Commit statuses Read and write Read a pull request's statuses; a plugin's hook posts one (plugins)

Leave Workflows at "No access" on purpose: with it off, no cycle can push a change to .github/workflows/. No organisation or account permissions, and subscribe to no events.

Create the app. On its General page note the App ID, and under Private keys generate one: a .pem file downloads. Keep it secret; it is the app's only credential. Install the app (Install App, then Install next to the organisation) on the product repository, and on the repository review findings go to if it is another one.

Then give the app to the host with tehas setup --app-id <App ID> --app-key-file <key>, or by hand as the tehas user:

install -m 600 <downloaded>.private-key.pem ~/.config/tehas/github-app.pem

and one line in the instance's instance.env:

TEHAS_GITHUB_APP_ID=<App ID>

The key stays in ~/.config/tehas, outside the instance directory, and is never given to a cycle's container. The installation ID and the bot's login are not written down: the first command that needs them asks GitHub with the app's key and keeps the answers in ~/tehas/state/github/installation and ~/tehas/state/github/login. If the app is not installed on TEHAS_REPO, every command says which repository and gives the install link.

Commits a cycle makes are authored as the tehas user's git identity. tehas setup sets it to the app. By hand, the bot's user ID is gh api 'users/<slug>[bot]' --jq .id:

git config --global user.name '<slug>[bot]'
git config --global user.email '<user id>+<slug>[bot]@users.noreply.github.com'

Then check it:

. ~/tehas/env.sh
tehas github check

It prints the app, the installation, the bot's login, when the token runs out and whether the installation reaches TEHAS_REPO, and never the token itself. command -v gh now answers ~/tehas/shim/gh.

Moving a host that used a token

GH_TOKEN in ~/.config/tehas/env, GH_CYCLE_TOKEN and TEHAS_CYCLE_LOGIN are refused: any command stops with exit 78 and says <NAME> is no longer used: the factory acts as a GitHub App. Take them out, make or give the app as above, and run any command again. TEHAS_GITHUB_APP_INSTALLATION, TEHAS_BOT_LOGIN and TEHAS_MILLWRIGHT_LOGIN are not settings: the installation is looked up and both logins are the one in ~/tehas/state/github/login. Since tehas 1.0 a line that sets one stops every command with exit 78; take them out too. tehas setup --token-file and --app-installation are unknown options (exit 64).

What tehas does with it

The shim's gh keeps an account of what the factory writes. A call that writes to GitHub - a comment, a label, an api call that posts, patches, puts or deletes, a GraphQL mutation - appends one tab-separated line to ~/tehas/state/github-writes.log before it hands gh's own output back: the time in UTC, the kind (api POST, issue comment, ...), the repository, the issue or PR number, gh's exit status, and 403 or 429 when gh's error stream says so, else -. It holds nothing else: not the token, not a body, not a field value. Reads are not logged and run as they always did. gh api graphql always sends POST, a query among them, so the shim reads its method for nothing: it reads the first word of the query instead, and logs the call only when that word is mutation. An idle poll asks GitHub nothing but queries, and so adds no line. Which call is a write, and the line, are decided by console gh, which the shim execs; a read goes on to gh at once. A host whose console is missing or cannot be run still has a working gh, with the token, and logs nothing until the console is repaired. The poll line of tehas status counts it, and tehas github writes shows the last day by hour and by its busiest minute against GitHub's limits. A write GitHub refuses for a rate limit is sent once more after a minute, and only that call (the commands page).

The commands page has the details.

What a container's token may do

A cycle's, a planning turn's and a session's container get the narrowed token, never the app's own. It has these permissions on the product repository and on nothing else:

Permission Access
Contents write
Pull requests write
Issues read
Metadata read

GitHub lets a token with Pull requests write manage the repository's labels: create, rename and delete them. GitHub's tables list Issues write or Pull requests write for those calls. So a container can rename a label, though it cannot apply one to an issue or comment on one with this token. The dispatcher does not take a label's name as proof of what it is: it pins each granting label, as the next section says.

Label pins

The dispatcher keeps the GitHub node id of each label whose application grants work (tehas:ready, tehas:plan, tehas:refine, tehas:finish, tehas:blocked, tehas:lean and tehas:classic) in ~/tehas/state/labels, one <name><tab><id> line each. The first page of each poll reads the repository's tehas: labels with their ids, and the label events read from GraphQL carry the id of their label:

tehas labels pins tehas:prototype the same way, and the Protolab publishes no ticket while the label under that name is not the pinned one. The dispatcher does not act on it.

A label renamed into a granting name, for example a person's bug renamed to tehas:ready, therefore grants nothing: its old applications carry the id of the old label.

To delete and recreate a tehas: label, remove its line from ~/tehas/state/labels and delete the label, then run tehas labels: it makes the label and pins it. To pin a label that is there and has no pin, after checking on GitHub that it is the label it should be, add its line (<name><tab><id>, the id tehas labels printed) to the file by hand. tehas labels never changes a pin that is there. Until a label is pinned its applications count for nothing.

The relay is a security channel

The relay is the one way a cycle's container reaches GitHub's issues with more than read access, so it is a host channel and is held to the rule that nothing may widen what a container is given (the mounts and variables of tehas work are pinned by console/cycle/tests/work_container.rs). The container gets a directory to leave requests in. It gets no token for it and no way to ask for anything but the three commands. The host reads each request, checks it and runs it. It refuses, with the reason written back to the cycle:

A title and a body that pass are posted masked as the console masks a log: tokens, keys, passwords, private addresses and the host's names are taken out. Every @ mention gets a zero-width space after the @, so a cycle's text notifies nobody.

The host also takes the marker apart where it quotes an agent's text itself, in its own comments and in the plan, so a marker an agent wrote cannot come back as the factory's.

Things seen on the first app