Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agents/agents/gator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ENV PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"

RUN mkdir -p /etc/openshell
COPY policy.yaml /etc/openshell/policy.yaml
COPY repos.json /etc/openshell/gator-repos.json
COPY bin/gh /usr/local/bin/gh-gator
COPY bin/review-feedback-ledger /usr/local/bin/review-feedback-ledger
COPY bin/resolve-gator-review-threads /usr/local/bin/resolve-gator-review-threads
Expand Down
27 changes: 27 additions & 0 deletions .agents/agents/gator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ Before enabling this flow, require `OpenShell / Maintainer Approval` from
GitHub Actions in the `main` ruleset and verify that GitHub counts the App
review toward its native approving-review requirement.

## Supported repositories

`repos.json` registers every repository gator may work in. It ships in the image
at `/etc/openshell/gator-repos.json`. Each run targets exactly one registered
repository. Per repository it sets:

- `approval`: `enabled`, `maintainers_file`, `required_check`, and
`required_check_integration_id`. Approval is off unless `enabled` is true, so
gator reviews, labels, and comments in a new repository but never approves.
- `note`: why the repository is configured this way, and what must change
before approval is enabled. JSON has no comments, so keep the reason here.
- `workflow_approval`: the workflow paths `approve-gator-workflow` may approve.
An empty list approves nothing.

To add a repository:

1. Add it to `repos.json`, leaving approval disabled.
2. Copy its rules in `providers/github-gator.yaml` and
`providers/github-app-gator.yaml`, and add its repository ID to the App
installation's `repository_ids` in `agent.yaml`.
3. Bump `payload_version` in `agent.yaml` and the version check in
`tests/review_feedback_ledger_test.sh`.
4. To allow approval, add the maintainer roster file and a required check from
GitHub Actions to the repository, then set `approval.enabled`.

`ai-openshell/desktop` is registered with approval disabled.

## Tests

The test suite requires Bash, Ruby, Node.js, jq, and ripgrep on the host. It mocks image, gateway, credential, and GitHub operations.
Expand Down
2 changes: 1 addition & 1 deletion .agents/agents/gator/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

id: gator
payload_version: 24
payload_version: 26
display_name: Gator Gate Agent
description: Validate and monitor OpenShell GitHub issues and pull requests through the gator state machine.

Expand Down
19 changes: 10 additions & 9 deletions .agents/agents/gator/bin/approve-gator-workflow
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ if [[ $# != 3 || "$1" != --operator-authorized || ! "$2" =~ ^[0-9]+$ || ! "$3" =
echo 'Usage: approve-gator-workflow --operator-authorized PR_NUMBER RUN_ID' >&2
exit 2
fi
repo=ai-openshell/openshell
repo="${OPENSHELL_GATOR_REPO:-ai-openshell/openshell}"
pr="$2" run="$3"
deny() { echo "Workflow not approved: $*" >&2; exit 1; }
repos_file="${OPENSHELL_GATOR_REPOS_FILE:-/etc/openshell/gator-repos.json}"
# Only workflows listed for the repo in repos.json may be approved; an
# unregistered repo or an empty list denies every run.
allowed_workflows="$(jq -c --arg repo "${repo,,}" '
(.repos | with_entries(.key |= ascii_downcase))[$repo].workflow_approval // []
' "$repos_file")" || deny 'cannot read repos.json'
[[ "$allowed_workflows" != '[]' ]] || deny "workflow approval is not enabled for $repo in repos.json"
# A user identity must have write access. A GitHub App installation token has
# no user; GitHub enforces the installation's actions permission instead.
if [[ "${OPENSHELL_AGENT_OPTION_GITHUB:-user}" != app ]]; then
Expand All @@ -25,17 +32,11 @@ jq -e --arg repo "$repo" '.state == "open" and .draft == false and (.base.repo.f
check_run() {
local metadata
metadata="$(gh api "repos/$repo/actions/runs/$run")"
jq -e --arg repo "$repo" --arg head "$head" --argjson pr "$pr" '
jq -e --arg repo "$repo" --arg head "$head" --argjson pr "$pr" --argjson allowed "$allowed_workflows" '
(.repository.full_name | ascii_downcase) == ($repo | ascii_downcase) and .event == "pull_request" and
.head_sha == $head and .conclusion == "action_required" and
any(.pull_requests[]; .number == $pr) and
(.path == ".github/workflows/branch-checks.yml" or
.path == ".github/workflows/branch-e2e.yml" or
.path == ".github/workflows/helm-lint.yml" or
.path == ".github/workflows/trivy-changes.yml" or
.path == ".github/workflows/dependency-review.yml" or
.path == ".github/workflows/workflow-security.yml" or
.path == ".github/workflows/windows-msvc.yml")
(.path as $path | $allowed | index($path) != null)
' <<< "$metadata" >/dev/null || deny 'run is not a recognized pending PR-head workflow'
}
check_run
Expand Down
40 changes: 28 additions & 12 deletions .agents/agents/gator/bin/gh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -euo pipefail
REAL_GH="${OPENSHELL_REAL_GH:-/usr/bin/gh}"
GATOR_MARKER='> **gator-agent**'
GATOR_APP_ID=363243726
GATOR_REPOS_FILE="${OPENSHELL_GATOR_REPOS_FILE:-/etc/openshell/gator-repos.json}"
GATOR_PAYLOAD_VERSION="${OPENSHELL_AGENT_PAYLOAD_VERSION:-5}"

if [[ "${OPENSHELL_AGENT_OPTION_GITHUB:-user}" == app && "${1:-}" == pr && "${2:-}" == review ]]; then
Expand Down Expand Up @@ -320,37 +321,52 @@ guard_gator_approval_checks() {
type == "array" and
any(.[]; .type == "required_status_checks" and
any(.parameters.required_status_checks[]?;
.context == "OpenShell / Maintainer Approval" and .integration_id == 15368))
' <<< "$rules" >/dev/null; then
echo "openshell-agent: the base branch must require OpenShell / Maintainer Approval from GitHub Actions" >&2
.context == $check and .integration_id == $integration))
' --arg check "$GATOR_REQUIRED_CHECK" --argjson integration "$GATOR_REQUIRED_CHECK_INTEGRATION" <<< "$rules" >/dev/null; then
echo "openshell-agent: the base branch must require $GATOR_REQUIRED_CHECK from GitHub Actions" >&2
return 23
fi
required="$(jq -c '
[ .[] | select(.type == "required_status_checks") |
.parameters.required_status_checks[].context |
select(. != "OpenShell / Maintainer Approval") ] | unique
' <<< "$rules")" || return 21
select(. != $check) ] | unique
' --arg check "$GATOR_REQUIRED_CHECK" <<< "$rules")" || return 21
[[ "$required" != "[]" ]] || return 0
checks="$("$REAL_GH" pr checks "$number" --repo "$repo" --required --json name,bucket)" || return 21
if ! jq -e --argjson required "$required" '
if ! jq -e --argjson required "$required" --arg check "$GATOR_REQUIRED_CHECK" '
. as $checks |
all($required[]; . as $name | any($checks[]; .name == $name)) and
all($checks[] | select(.name != "OpenShell / Maintainer Approval"); .bucket | IN("pass", "skipping"))
all($checks[] | select(.name != $check); .bucket | IN("pass", "skipping"))
' <<< "$checks" >/dev/null; then
echo "openshell-agent: Gator approval requires passing required CI checks other than Maintainer Approval" >&2
echo "openshell-agent: Gator approval requires passing required CI checks other than $GATOR_REQUIRED_CHECK" >&2
return 23
fi
}

# Print the repo's approval config from repos.json, or fail when the repo is
# unregistered or has approval disabled. Never fall back to a default.
gator_approval_config() {
jq -ce --arg repo "${1,,}" '
(.repos | with_entries(.key |= ascii_downcase))[$repo].approval
| select(. != null and .enabled == true)
' "$GATOR_REPOS_FILE"
}

guard_gator_approval() {
local repo="$1" number="$2" body="$3" commit="$4"
local pull default_branch base_ref author maintainers maintainer_logins
local pull default_branch base_ref author maintainers maintainer_logins config roster
if [[ "${OPENSHELL_AGENT_OPTION_GITHUB:-user}" != app ||
"${repo,,}" != ai-openshell/openshell ||
"$body" != "$GATOR_MARKER"* ]]; then
echo "openshell-agent: Gator approval requires the App identity and a marked review in ai-openshell/openshell" >&2
echo "openshell-agent: Gator approval requires the App identity and a marked review" >&2
return 23
fi
if ! config="$(gator_approval_config "$repo")" || [[ -z "$config" ]]; then
echo "openshell-agent: Gator approval is not enabled for $repo in repos.json" >&2
return 23
fi
roster="$(jq -er '.maintainers_file' <<< "$config")" || return 21
GATOR_REQUIRED_CHECK="$(jq -er '.required_check' <<< "$config")" || return 21
GATOR_REQUIRED_CHECK_INTEGRATION="$(jq -er '.required_check_integration_id' <<< "$config")" || return 21
pull="$("$REAL_GH" api "repos/$repo/pulls/$number")" || return 21
if ! jq -e --arg commit "$commit" '
($commit | test("^[0-9a-f]{40}$")) and
Expand All @@ -363,7 +379,7 @@ guard_gator_approval() {
default_branch="$(jq -er '.base.repo.default_branch' <<< "$pull")" || return 21
base_ref="$(jq -er '.base.ref | strings | select(length > 0)' <<< "$pull")" || return 21
maintainers="$("$REAL_GH" api -X GET -H 'Accept: application/vnd.github.raw' \
"repos/$repo/contents/MAINTAINERS.md" --raw-field "ref=$default_branch")" || return 21
"repos/$repo/contents/$roster" --raw-field "ref=$default_branch")" || return 21
maintainer_logins="$(jq -nc --arg roster "$maintainers" '
[$roster | scan("\\[@([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)\\]\\(https://github\\.com/")[] |
ascii_downcase] | unique
Expand Down
8 changes: 5 additions & 3 deletions .agents/agents/gator/prompts/gator.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Important sandbox constraints:
skill's first-review exception. Non-required check statuses never block
progression; inspect required checks separately from the full rollup.

- Target ai-openshell/openshell unless the operator explicitly scopes this run
to a private advisory fork. Never substitute the public repository for a
- Target the single repository the operator names (default ai-openshell/openshell;
it must appear in `/etc/openshell/gator-repos.json`), or a private advisory
fork when the operator explicitly scopes the run to one. Never work across repos in one run. Never substitute the public repository for a
private target. GitHub writes remain subject to the provider policy.
- `/ok to test` comments no longer start CI. Test labels select suites;
external-contributor runs need native GitHub Actions approval. Only approve
Expand All @@ -36,7 +37,8 @@ Important sandbox constraints:
actions and use GraphQL-backed `gh` reads when useful.
- Keep watching active PRs until they close, merge, or the operator stops the sandbox.
- At the start of every watch cycle, read `payload_version` from
`.agents/agents/gator/agent.yaml` on the default branch through the GitHub
`.agents/agents/gator/agent.yaml` on the default branch of ai-openshell/openshell
(the canonical agent definition, whichever repository this run targets) through the GitHub
contents API. If the published integer is greater than
`{{PAYLOAD_VERSION}}`, do not write to GitHub or run the reviewer. Finish with
`OPENSHELL_AGENT_RESULT {"status":"terminal_failure","reason":"stale_gator_payload","notes":"This sandbox is using an outdated Gator payload. Relaunch it before monitoring continues."}` so the operator relaunches the immutable watcher.
Expand Down
21 changes: 21 additions & 0 deletions .agents/agents/gator/providers/github-app-gator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,35 @@ endpoints:
q:
any:
- "*repo:ai-openshell/openshell*"
- "*repo:ai-openshell/desktop*"
- allow: { method: GET, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}" }
- allow: { method: GET, path: "/repos/ai-openshell/desktop" }
- allow: { method: GET, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/repos/ai-openshell/desktop/**" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/issues/*/comments" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/comments/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/issues/comments/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/issues/*/labels" }
- allow: { method: PUT, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels" }
- allow: { method: PUT, path: "/repos/ai-openshell/desktop/issues/*/labels" }
- allow: { method: DELETE, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels/*" }
- allow: { method: DELETE, path: "/repos/ai-openshell/desktop/issues/*/labels/*" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/issues/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/labels" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/labels" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/labels/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/labels/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/pulls/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/pulls/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/openshell/pulls/*/reviews" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/pulls/*/reviews" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/statuses/*" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/statuses/*" }
- allow: { method: POST, path: "/repos/ai-openshell/openshell/actions/runs/*/approve" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/actions/runs/*/approve" }
- host: api.github.com
port: 443
path: /graphql
Expand All @@ -82,16 +97,22 @@ endpoints:
enforcement: enforce
rules:
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}" }
- allow: { method: GET, path: "/ai-openshell/desktop" }
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/ai-openshell/desktop/**" }
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}.git/**" }
- allow: { method: GET, path: "/ai-openshell/desktop.git/**" }
- allow: { method: POST, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**/git-upload-pack" }
- allow: { method: POST, path: "/ai-openshell/desktop/**/git-upload-pack" }
- allow: { method: POST, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}.git/**/git-upload-pack" }
- allow: { method: POST, path: "/ai-openshell/desktop.git/**/git-upload-pack" }
- host: codeload.github.com
port: 443
protocol: rest
enforcement: enforce
rules:
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/ai-openshell/desktop/**" }
- host: results-receiver.actions.githubusercontent.com
port: 443
protocol: rest
Expand Down
22 changes: 22 additions & 0 deletions .agents/agents/gator/providers/github-gator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,37 @@ endpoints:
q:
any:
- "*repo:ai-openshell/openshell*"
- "*repo:ai-openshell/desktop*"
- allow: { method: GET, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}" }
- allow: { method: GET, path: "/repos/ai-openshell/desktop" }
- allow: { method: GET, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/repos/ai-openshell/desktop/**" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/issues/*/comments" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/comments/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/issues/comments/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/issues/*/labels" }
- allow: { method: PUT, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels" }
- allow: { method: PUT, path: "/repos/ai-openshell/desktop/issues/*/labels" }
- allow: { method: DELETE, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*/labels/*" }
- allow: { method: DELETE, path: "/repos/ai-openshell/desktop/issues/*/labels/*" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/issues/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/issues/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/labels" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/labels" }
- allow: { method: PATCH, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/labels/*" }
- allow: { method: PATCH, path: "/repos/ai-openshell/desktop/labels/*" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/pulls/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/pulls/*/comments" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/pulls/*/reviews" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/pulls/*/reviews" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/pulls/*/reviews/*/comments" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/pulls/*/reviews/*/comments" }
- allow: { method: POST, path: "/repos/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/statuses/*" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/statuses/*" }
- allow: { method: POST, path: "/repos/ai-openshell/openshell/actions/runs/*/approve" }
- allow: { method: POST, path: "/repos/ai-openshell/desktop/actions/runs/*/approve" }
- host: api.github.com
port: 443
path: /graphql
Expand All @@ -61,16 +77,22 @@ endpoints:
enforcement: enforce
rules:
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}" }
- allow: { method: GET, path: "/ai-openshell/desktop" }
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/ai-openshell/desktop/**" }
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}.git/**" }
- allow: { method: GET, path: "/ai-openshell/desktop.git/**" }
- allow: { method: POST, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**/git-upload-pack" }
- allow: { method: POST, path: "/ai-openshell/desktop/**/git-upload-pack" }
- allow: { method: POST, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}.git/**/git-upload-pack" }
- allow: { method: POST, path: "/ai-openshell/desktop.git/**/git-upload-pack" }
- host: codeload.github.com
port: 443
protocol: rest
enforcement: enforce
rules:
- allow: { method: GET, path: "/{NVIDIA,ai-openshell}/{openshell,OpenShell-ghsa-*}/**" }
- allow: { method: GET, path: "/ai-openshell/desktop/**" }
- host: results-receiver.actions.githubusercontent.com
port: 443
protocol: rest
Expand Down
Loading
Loading