brainiac-github
GitHub webhook plugin for Brainiac — the multi-agent orchestration layer.
What It Does
- PR Reviews — dispatches agents to address review feedback
- PR Comments — routes PR conversation to the assigned agent
- PR Opens / Pushes — tracks new PRs against work items; redeploys ephemeral envs and emits hooks on new pushes
- PR Merges — cleans up worktrees, emits hooks for card management plugins
-
Workflow Runs — matches workflows by name:
Deploy to Productionfailure → notify;Deploy to UATsuccess → notify;Deploy to Productionsuccess → emits:production_deployed - Issues — logs new issues (no dispatch)
- Agent crashes — posts a crash comment on the PR the agent was working on
Installation
brainiac install github
brainiac restartInstall creates ~/.brainiac/github.json from templates/github.json.example
(or run brainiac github setup to create it later).
Configuration
Config lives at ~/.brainiac/github.json (under $BRAINIAC_DIR if set):
{
"webhook_secret": "your-github-webhook-secret",
"allowed_owners": ["stowzilla", "ardavis"],
"apps": {
"brainiac": {
"id": "100000",
"private_key_path": "~/.brainiac/brainiac.pem",
"installations": {
"stowzilla": "11111111",
"ardavis": "22222222"
}
},
"galen": {
"id": "200000",
"private_key_path": "~/.brainiac/galen-brainiac.pem",
"installations": {
"stowzilla": "33333333",
"ardavis": "44444444"
}
}
},
"repos": {}
}The allowed_owners array restricts which GitHub accounts/orgs can trigger your
agents. Events from repos not owned by a listed account are rejected with a 403
before any processing occurs. If omitted, all owners are accepted (filtered
downstream by project matching instead).
Generate a webhook secret:
ruby -rsecurerandom -e 'puts SecureRandom.hex(20)'GitHub App Setup
The plugin uses GitHub Apps for two purposes:
- Inbound events — a single "Brainiac" app receives webhook events from all repos
- Outbound identity — per-agent apps post comments/reactions with distinct avatars
This mirrors how Discord works: one gateway delivers all messages, each bot responds with its own token and avatar.
Architecture
brainiac (app) → webhook ACTIVE, receives all events
galen-brainiac (app) → webhook DISABLED, Galen's posting identity
glados-brainiac (app)→ webhook DISABLED, GLaDOS's posting identity
The "brainiac" agent in the registry also uses the brainiac app as its posting identity — so the webhook-receiver app doubles as the brainiac agent's identity.
Step 1: Create the Brainiac App (Webhook Receiver)
- Go to Settings → Developer settings → GitHub Apps → New GitHub App
- Set the following:
-
Name:
brainiac(or your preferred orchestrator name) - Homepage URL: your Brainiac instance URL
-
Webhook URL:
https://your-ngrok.ngrok-free.app/github -
Webhook secret: paste the
webhook_secretfrom yourgithub.json
-
Name:
- Under "Where can this GitHub App be installed?", select "Any account" (allows installation on both personal accounts and organizations)
- Set Permissions (under "Repository permissions"):
- Contents: Read-only
- Issues: Read & Write
- Pull requests: Read & Write
-
Subscribe to events:
- Issue comment
- Issues
- Pull request
- Pull request review
- Workflow run
- Create the app and note the App ID
- Generate a private key (see Private Key Details below)
- Upload an avatar for the app
-
Install the app on each account/org where you have repos:
- Go to the app's settings → "Install App" tab
- Install on your personal account (e.g.
ardavis) — note the Installation ID from the URL:https://github.com/settings/installations/INSTALLATION_ID - Install on your org (e.g.
stowzilla) — note that Installation ID too
Step 2: Create Agent Identity Apps (One Per Agent)
For each agent that should have its own avatar on PR comments. This is still
manual: brainiac agent create (in Brainiac core) creates the agent, but this
plugin has no on_agent_created hook, so create the app and add its apps entry
yourself. github.json is re-read when it changes, so no restart is needed.
- Go to Settings → Developer settings → GitHub Apps → New GitHub App
- Set the following:
-
Name:
galen-brainiac,glados-brainiac, etc. - Homepage URL: your Brainiac instance URL
- Webhook: uncheck "Active" (these apps don't receive events)
-
Name:
- Under "Where can this GitHub App be installed?", select "Any account"
- Set Permissions (under "Repository permissions"):
- Contents: Read-only
- Issues: Read & Write
- Pull requests: Read & Write
- Do NOT subscribe to any events (webhook is disabled)
- Create the app and note the App ID
- Generate a private key
- Upload the agent's avatar
- Install the app on each account/org (same as the brainiac app)
- Repeat for each agent
Step 3: Configure github.json
{
"webhook_secret": "your-github-webhook-secret",
"allowed_owners": ["stowzilla", "ardavis"],
"apps": {
"brainiac": {
"id": "100000",
"private_key_path": "~/.brainiac/brainiac.pem",
"installations": {
"stowzilla": "11111111",
"ardavis": "22222222"
}
},
"galen": {
"id": "200000",
"private_key_path": "~/.brainiac/galen-brainiac.pem",
"installations": {
"stowzilla": "33333333",
"ardavis": "44444444"
}
},
"glados": {
"id": "300000",
"private_key_path": "~/.brainiac/glados-brainiac.pem",
"installations": {
"stowzilla": "55555555",
"ardavis": "66666666"
}
}
},
"repos": {}
}Each key in apps matches the agent's registry key (lowercase). The
installations hash maps account/org names to their Installation IDs (a flat
installation_id also works for a single account).
Single-App Mode
Instead of apps, you can configure one shared app under app (the template's
default shape). It's used for any agent without an apps entry:
"app": {
"id": "100000",
"private_key_path": "~/.brainiac/github-app-private-key.pem",
"installation_id": "11111111"
}Private Key Details
The .pem file is generated by GitHub — you don't create it yourself. On your
app's settings page (Settings → Developer settings → GitHub Apps → your app):
- Scroll to the "Private keys" section
- Click "Generate a private key"
- GitHub generates an RSA key pair, keeps the public half, and your browser
downloads the private half as a
.pemfile (named likeyour-app-name.2026-08-06.private-key.pem) - Move it to your brainiac config directory and lock down permissions:
mv ~/Downloads/your-app-name.*.private-key.pem ~/.brainiac/galen-brainiac.pem chmod 600 ~/.brainiac/galen-brainiac.pem
The plugin uses this key to sign JWTs for GitHub API authentication. Never
commit .pem files to version control.
Fallback
If no app credentials are configured for an agent (no apps entry, app
section, or env vars), the plugin falls back to using the gh CLI (which
authenticates as your personal GitHub account).
Environment Variables
Used when the config file doesn't set the value. The GITHUB_APP_* variables
describe one shared app and are the last fallback after apps.<agent> and app:
-
GITHUB_WEBHOOK_SECRET— webhook signature secret -
GITHUB_APP_ID— GitHub App ID -
GITHUB_APP_PRIVATE_KEY_PATH— path to the.pemprivate key file -
GITHUB_APP_INSTALLATION_ID— installation ID
For per-agent apps, use the config file — env vars don't support multiple apps.
GitHub Webhook Setup
The webhook is configured on the Brainiac app itself (Step 1 above) — no per-repo webhook setup is needed. The app-level webhook automatically receives events from all repos where the app is installed.
If you have legacy per-repo webhooks pointing to /github, remove them to
avoid duplicate event deliveries.
CLI
brainiac github setup # Create config file from template (if missing)
brainiac github config # Show webhook secret, repos, and shared `app` credentials
brainiac github status # Check the Brainiac server is up (POST /github active)Hooks Emitted
| Hook | When | Payload |
|---|---|---|
:pr_opened |
PR opened on a tracked work item branch | card_number, pr_number, repo_name, branch, base_branch, ... |
:pr_merged |
PR merged to default branch | card_number, pr_url, project_key, ... |
:pr_merged_to_branch |
Any merge of a fizzy-<n>-… branch (incl. epic branches) |
card_number, branch, base_branch, pr_url, ... |
:pr_review_received |
Review submitted | card_number, reviewer, agent_name, ... |
:pr_synchronized |
New commits pushed to a PR | card_number, worktree, branch, ... |
:production_deployed |
Deploy to Production workflow succeeds |
project_key, project_config |
Development
git clone https://github.com/stowzilla/brainiac-github.git
cd brainiac-github
bundle install
bundle exec rake test
bundle exec rubocopLicense
MIT