GitHub
GitHub is a code platform: kōjō takes requests there from mentions and from the events you map to skills, answers in comments, and opens pull requests. kōjō acts on GitHub as a GitHub App. It works with github.com and with GitHub Enterprise Server (forges.github.base_url).
See Surfaces for how GitHub compares with GitLab and Forgejo, and Who may trigger what for whose requests may change code.
Set up
-
Run the setup command with kōjō’s public URL:
kojo setup github --public-url https://kojo.example.com -
The command serves a page on localhost and prints its address (
http://127.0.0.1:<port>/). It does not open a browser. Open the address yourself and choose “Continue to GitHub”. The page posts the App manifest to GitHub, where you review and confirm it. -
GitHub redirects back to the local page with a one-time code. The command exchanges it for the App’s credentials and writes two files that only you can read (mode
0600) into the--outdirectory. It waits up to 10 minutes.File Content github-app.pemThe App’s private key github-app.envGITHUB_APP_IDandGITHUB_WEBHOOK_SECRET -
Add the App to
kojo.yaml. The command prints this block with the absolute path of the key file, so the path does not depend on the directory kōjō starts in:forges: github: app_id: ${GITHUB_APP_ID} private_key_file: /etc/kojo/secrets/github-app.pem webhook_secret: ${GITHUB_WEBHOOK_SECRET} -
Install the App on the repositories kōjō should work on. The command prints the link (
<app page>/installations/new). -
Enable those repositories in the dashboard under Settings → Repositories.
-
Run
kojo doctor. It checks that the App authenticates, that it has every permission and event below, and that each installation has accepted them.
No secret is printed, and the command talks only to github.com or your Enterprise Server.
| Flag | Default | Meaning |
|---|---|---|
--public-url |
none, required | kōjō’s public URL (server.public_url). GitHub sends webhooks to <public-url>/webhooks/github. |
--org |
your user account | Create the App in this organization. |
--base-url |
github.com | API root of a GitHub Enterprise Server, for example https://ghe.example.com/api/v3. |
--name |
kojo |
Name of the App. It becomes the App’s slug and the login people mention. App names are unique on a GitHub instance. |
--public |
off | Let other accounts install the App. By default only its owner can. |
--out |
secrets |
Directory the private key and the env file are written to. The paths the command prints are absolute. |
forges.github takes exactly one of private_key_file (a path) and private_key (the PEM itself, for an environment variable). For Enterprise Server, add base_url.
Permissions
The manifest asks for these repository permissions and nothing else:
| Permission | Level | Used for |
|---|---|---|
metadata |
read | Repositories, collaborators, rulesets |
contents |
write | Read files, commit to kojo/* branches and to the branch of a person’s pull request when they ask |
issues |
write | Read issues, comment |
pull_requests |
write | List, read, open, edit, comment on and merge pull requests, and read their reviews |
checks |
read | Check runs of a commit, with their output |
statuses |
read | Commit statuses of a commit, with their descriptions |
administration |
read | Classic branch protection |
The App has no workflows permission, so GitHub rejects a commit from kōjō that changes a file under .github/workflows.
Events
The manifest subscribes to these webhook events:
| Event | Becomes |
|---|---|
issue_comment, pull_request_review_comment (action created) |
A mention, when the comment mentions the App. On a pull request, any other comment is pr_comment or pr_review_comment: feedback |
pull_request_review (action submitted, with a body) |
pr_review: feedback, or a mention when the body mentions the App |
issues (action opened) |
issue_opened, or a mention when the body mentions the App |
pull_request (opened, reopened, ready_for_review) |
pr_opened, or a mention when a newly opened pull request’s body mentions the App |
pull_request (synchronize) |
pr_updated |
pull_request (closed) |
pr_closed: the pull request was merged, or closed without merging |
check_run, check_suite (action completed, conclusion failure, timed_out or startup_failure) |
check_failed |
push to a branch |
A reload of the repository’s .factory/ files, when the branch is the default branch |
A failed check produces both a check_run and a check_suite delivery. Both are reported as check_failed.
An App created before kōjō subscribed to pull_request_review does not receive it: add the event under the App’s “Permissions & events”. kojo doctor names an event the App is not subscribed to.
Webhook
GitHub delivers to POST /webhooks/github. kōjō computes the HMAC-SHA256 of the raw body with forges.github.webhook_secret and compares it in constant time with X-Hub-Signature-256 before it decodes anything. An App without a webhook secret rejects every delivery.
The status codes kōjō answers a delivery with are the same for every forge: see webhook responses.
What triggers a session
- A mention. Write
@kojo(the App’s slug; yours differs if you chose another--name) in an issue comment, a pull request comment, a review comment, or in the body of a new issue or pull request. The rest of the text is the request, in plain words. The orchestrator decides which skills to run. Matching is case-insensitive.@kojoinside quoted text or a code block also counts. - An automatic trigger. A new issue, a new or updated pull request, or a failed check runs the skill you configured for that event on that repository. See automatic triggers.
A mention on an issue or pull request that a session is already working on goes to that session as a message instead of starting another one, when its author has trigger_permission. See Talking to a session at work.
There are no slash commands and no label triggers. kōjō ignores its own comments, its own checks and its own pushes to kojo/* branches.
Follow-ups
On a pull request kōjō opened, a mention, or a failed check where the repository opts in, starts a follow-up that commits to the pull request’s branch. What it uses on GitHub:
- The review, for
get_review_comments: the comments on lines of the diff (GET /pulls/{n}/comments), each with its file, line and diff hunk, marked outdated when a later push moved its line out of the diff; and the text of each submitted review (GET /pulls/{n}/reviews) with its verdict. A review without text, a pending one and a dismissed one are left out. At most the newest 300 entries. - The checks, for
get_check_runs: the check runs of the commit with their output’s title, summary and text, then its commit statuses with their descriptions, each cut to its last 16 KiB. - Which pull request a failed check is about: the pull request the
check_runorcheck_suitedelivery names, or else its head branch among the open pull requests kōjō recorded. - The commit: written like any other, on top of the commit the session cloned. The branch is read first and must point there, and it is moved without force, so a push that lands in between makes GitHub refuse the move and nothing is overwritten.
- A person’s pull request (commits on a person’s pull request): who added the
kojo:commitlabel is the latestlabeledevent of the pull request’s issue timeline (GET /issues/{n}/timeline) that nounlabeledevent follows, read from at most 10 pages of 100 events; a longer timeline counts as no adder, with a warning. On GitHub triage access is enough to add a label, so it counts only when the person who added it hastrigger_permission. A pull request whose head repository is another one (a fork) is never written to. A failed check on such a pull request is matched by the pull request the delivery names, or else by its branch among the repository’s open pull requests whose head is in the repository itself.
Clone credentials
Installation tokens last about an hour and are renewed five minutes before they expire. For each clone, kōjō asks GitHub for a separate token limited to the one repository with contents: read and metadata: read. That token goes to the proxy, never into the sandbox, and it cannot push. kojo-proxy also sets it only on requests that cannot write, as it does for every forge.
Limits
kōjō commits through the Git Data API, to branches named kojo/* and to the branch of a person’s open pull request in the same repository when its author asked or someone with trigger_permission added the kojo:commit label; for that one the adapter reads the pull request before writing and refuses a closed one, a fork’s, another branch or the default branch. It accepts regular files only (modes 100644 and 100755) and no path inside .git.