Skip to content

Turn on GitHub

A project’s repos can live on GitHub while pipelines stay on the forge. On gomoe.dev GitHub is always on, since every deploy writes AGENTS_GITHUB_DIR, AGENTS_GITHUB_API and AGENTS_GITHUB_GIT into the server’s .env. People’s tokens are kept in /data/agents-app/github on the data volume. What a person can do with GitHub depends on which of the GitHub App’s settings are in SSM.

SSM parameter Setting the deploy writes What it turns on
/agents/github/client-id AGENTS_GITHUB_CLIENT_ID Each person connects their own GitHub account from Repos, through GitHub’s device flow.
/agents/github/client-secret AGENTS_GITHUB_CLIENT_SECRET Continue with GitHub on the sign-in page, beside the client id.
/agents/github/app-slug AGENTS_GITHUB_APP_SLUG The link in the import dialog that installs the GitHub App on another account or organization. Without it, the dialog says to install the app and gives no link. The slug must be lower-case letters, digits and -, at most 100 characters, or the API stops at start.

Without a client id, Connect GitHub is not offered on Repos, so nobody can connect an account. An admin’s team token still reaches GitHub, and so does a person’s token saved earlier, until it runs out.

  1. Put each value in SSM as a SecureString, from a new file in a folder only you can open, so it is in no shell history or process list. mktemp -d makes the folder, as ops/aws-deploy/forge.ts does for the forge’s tokens.

    Terminal window
    dir=$(mktemp -d)
    umask 077; pbpaste > "$dir/value"
    aws ssm put-parameter --profile gomoe --region us-east-1 --name /agents/github/client-secret --type SecureString --overwrite --value "file://$dir/value"
    rm -rf "$dir"
  2. Do the same for /agents/github/client-id and /agents/github/app-slug.

  3. Deploy, so host.ts writes them into the .env and restarts the API. Once following is on, a merge to main deploys by itself, and node ops/aws-deploy/deploy.ts deploys by hand. See Deploy a change.

The GitHub App must allow GitHub’s device flow. The device flow sends no client secret, so the client id alone lets people connect. For Continue with GitHub, the app’s callback URL must be https://gomoe.dev/v1/auth/oauth/github/callback, since the server sends GitHub that address.

Each person opens Repos and chooses Connect GitHub. The page shows a code. The person enters it at GitHub’s device page, and the page changes when they finish. The server keeps their token in people/<person id>.json inside AGENTS_GITHUB_DIR, with mode 600. It never puts a token in Postgres, a log, a machine or a browser response. A person can Sign out, which deletes the file but leaves the token valid at GitHub until they revoke it there.

The server renews a token that is about to expire, using its refresh token. When the refresh token has run out or GitHub refuses it, the person connects again.

A team token lets projects make repos before every person has connected. It is a fine-grained personal access token that starts with github_pat_. The server refuses a classic token, which reaches every repo its account can.

  1. Sign in as an admin and open Repos.
  2. Under GitHub, choose Set a team token. When one exists, the button reads Replace the team’s token.
  3. Pick or type the organization or account the token acts for.
  4. Paste the token and choose Save the token.

The server asks GitHub whose token it is, and for an organization it checks that the token can see it. It keeps the token in stopgaps/<team id>.json inside AGENTS_GITHUB_DIR, with mode 600.

server/admin.ts github-token reads a token from standard input, and ops/aws-deploy/admin.ts sends no standard input over SSM, so on gomoe.dev the app is the way to save one.

A person’s own sign-in is used first, and the team token when they have none. Calls a repo makes for agents and the server use the sign-in of the person who brought the repo into its project, then the team token. A repo that came in through the team token uses only the team token. When there is neither, the page says to connect GitHub on Repos.

New repos go under the person’s own account, or under the team token’s organization when they have not signed in.

The server follows each repo by asking GitHub, not through GitHub’s webhooks. It starts a round 60 seconds after the last one ended, or AGENTS_GITHUB_POLL_SEC seconds. A pipeline that starts from issues starts only from a label that begins with agent:, put on an open issue by someone with write, maintain or admin access. Opening an issue starts nothing. For the Repos page, the server also reads each repo’s open pull requests and task branches, and keeps each answer for 30 seconds, or AGENTS_REPOS_CACHE_SEC seconds.

Setting AGENTS_RUNNER=off turns this polling off along with the runner. The same rounds read the ship loop’s posts on each open pull request the app opened for a task, and keep a row for each failure or stop. A failure’s row wakes the task’s agent in a turn nobody watches, where it can only read and edit the task’s files. When the agent reports the findings fixed, the server has the machine commit and push the edits to the pull request’s branch, and when a wake ends without a push a person reads one line, in the chat the task came from or in the direct message between the task’s owner and the agent. AGENTS_SHIP_WAKE=off stops all of that. host.ts sets neither, so gomoe.dev runs it.

On a head the ship loop never posted on, the same rounds read the head’s checks. Once none still runs and one failed in the last 24 hours, the task’s agent is woken the same way with each failed check’s name and summary, once a head. A team member’s review or line comment on the head that asks for changes or comments wakes the agent the same way, once 2 minutes pass with none newer. All three kinds share the 6 wakes a pull request gets.

A wake’s push needs ops/policies/agents.json in the server’s files, the list of paths no wake’s push may change. gomoe.dev runs from a full checkout in /srv/agents, which holds it. Each machine’s daemon must also be as new as the server, since an older daemon ignores that list and stops nothing. A computer keeps the daemon it started with until it moves to a newer image, as The image says.