From 4f6db7841fa22b1dae63b4a9833b2f0cde8f636d Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 4 Dec 2026 11:27:59 +0100 Subject: [PATCH] feat(gator): add per-repo registry and register ai-openshell/desktop Move the approval guard's repo, roster, required check, and approvable workflows into repos.json. Approval is opt-in per repo: desktop is registered review-only, and unregistered repos are denied. Extend the provider policies to cover desktop. Read the stale-payload version from ai-openshell/openshell so the agent definition is not duplicated in each target repo. Signed-off-by: Evan Lezar --- .agents/agents/gator/Dockerfile | 1 + .agents/agents/gator/README.md | 27 +++++++++++++ .agents/agents/gator/agent.yaml | 2 +- .../agents/gator/bin/approve-gator-workflow | 19 ++++----- .agents/agents/gator/bin/gh | 40 +++++++++++++------ .agents/agents/gator/prompts/gator.md | 8 ++-- .../gator/providers/github-app-gator.yaml | 21 ++++++++++ .../agents/gator/providers/github-gator.yaml | 22 ++++++++++ .agents/agents/gator/repos.json | 27 +++++++++++++ .../agents/gator/skills/gator-gate/SKILL.md | 33 +++++++-------- .../tests/approve_gator_workflow_test.sh | 5 +++ .agents/agents/gator/tests/gh_guard_test.sh | 14 +++++++ .../tests/review_feedback_ledger_test.sh | 2 +- .../skills/launch-openshell-gator/SKILL.md | 8 ++-- 14 files changed, 184 insertions(+), 45 deletions(-) create mode 100644 .agents/agents/gator/repos.json diff --git a/.agents/agents/gator/Dockerfile b/.agents/agents/gator/Dockerfile index 592d5af588..1f80e676eb 100644 --- a/.agents/agents/gator/Dockerfile +++ b/.agents/agents/gator/Dockerfile @@ -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 diff --git a/.agents/agents/gator/README.md b/.agents/agents/gator/README.md index aa89338c86..a84ff42b59 100644 --- a/.agents/agents/gator/README.md +++ b/.agents/agents/gator/README.md @@ -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. diff --git a/.agents/agents/gator/agent.yaml b/.agents/agents/gator/agent.yaml index 82af770465..e73f371554 100644 --- a/.agents/agents/gator/agent.yaml +++ b/.agents/agents/gator/agent.yaml @@ -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. diff --git a/.agents/agents/gator/bin/approve-gator-workflow b/.agents/agents/gator/bin/approve-gator-workflow index bd9b722e0a..37fba421e3 100755 --- a/.agents/agents/gator/bin/approve-gator-workflow +++ b/.agents/agents/gator/bin/approve-gator-workflow @@ -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 @@ -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 diff --git a/.agents/agents/gator/bin/gh b/.agents/agents/gator/bin/gh index 12e2b9820f..1a4825cee9 100755 --- a/.agents/agents/gator/bin/gh +++ b/.agents/agents/gator/bin/gh @@ -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 @@ -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 @@ -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 diff --git a/.agents/agents/gator/prompts/gator.md b/.agents/agents/gator/prompts/gator.md index 20020e4ff9..87c68576f3 100644 --- a/.agents/agents/gator/prompts/gator.md +++ b/.agents/agents/gator/prompts/gator.md @@ -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 @@ -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. diff --git a/.agents/agents/gator/providers/github-app-gator.yaml b/.agents/agents/gator/providers/github-app-gator.yaml index 24422b807d..22e666c336 100644 --- a/.agents/agents/gator/providers/github-app-gator.yaml +++ b/.agents/agents/gator/providers/github-app-gator.yaml @@ -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 @@ -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 diff --git a/.agents/agents/gator/providers/github-gator.yaml b/.agents/agents/gator/providers/github-gator.yaml index e30b71fe80..3e57d00b68 100644 --- a/.agents/agents/gator/providers/github-gator.yaml +++ b/.agents/agents/gator/providers/github-gator.yaml @@ -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 @@ -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 diff --git a/.agents/agents/gator/repos.json b/.agents/agents/gator/repos.json new file mode 100644 index 0000000000..aa5b2e5529 --- /dev/null +++ b/.agents/agents/gator/repos.json @@ -0,0 +1,27 @@ +{ + "repos": { + "ai-openshell/openshell": { + "note": "Approval requires MAINTAINERS.md and the OpenShell / Maintainer Approval check required on the base branch.", + "approval": { + "enabled": true, + "maintainers_file": "MAINTAINERS.md", + "required_check": "OpenShell / Maintainer Approval", + "required_check_integration_id": 15368 + }, + "workflow_approval": [ + ".github/workflows/branch-checks.yml", + ".github/workflows/branch-e2e.yml", + ".github/workflows/helm-lint.yml", + ".github/workflows/trivy-changes.yml", + ".github/workflows/dependency-review.yml", + ".github/workflows/workflow-security.yml", + ".github/workflows/windows-msvc.yml" + ] + }, + "ai-openshell/desktop": { + "note": "Review only. Enable approval after the repo has a maintainer roster file and a required Maintainer Approval check from GitHub Actions, then fill in the approval fields.", + "approval": {"enabled": false}, + "workflow_approval": [] + } + } +} diff --git a/.agents/agents/gator/skills/gator-gate/SKILL.md b/.agents/agents/gator/skills/gator-gate/SKILL.md index c5450a689d..0c4e0fe8f5 100644 --- a/.agents/agents/gator/skills/gator-gate/SKILL.md +++ b/.agents/agents/gator/skills/gator-gate/SKILL.md @@ -15,7 +15,8 @@ Load this skill from `.agents/agents/gator/skills/gator-gate/SKILL.md`, or its [ ## Prerequisites -- The `gh` CLI must be able to call GitHub APIs (`gh api repos/ai-openshell/openshell --jq .full_name`) +- The `gh` CLI must be able to call GitHub APIs (`gh api repos/ --jq .full_name`) +- `` is the single repository the operator scoped this run to, defaulting to `ai-openshell/openshell`. It must be registered in `repos.json`. Approval and workflow approval are opt-in per repo there; the guards deny a repo that is unregistered or not enabled, so review, label and comment without approving. - You must be in the OpenShell repository root - GitHub write permissions are required to apply labels, comment, close issues/PRs, or approve workflow runs @@ -29,16 +30,16 @@ The sandbox prompt names Gator's GitHub identity: that login. - `app`: Gator acts as the `gator-review-bot` GitHub App installation and posts as `gator-review-bot[bot]`. Installation tokens cannot call `gh api user`; - do not use it. The token covers only `ai-openshell/openshell`, so private + do not use it. The token covers only the registered repositories, so private advisory forks need a `user` launch. Use REST-backed `gh api` for GitHub write actions inside gator sandboxes. Do not rely on `gh issue edit`, `gh pr edit`, or other high-level write commands when a REST path is available, because some of them use GraphQL mutations and gator policy allows GraphQL reads only. Do not fall back to `curl` for credentialed GitHub writes unless the active provider policy explicitly allows the `curl` binary for the same scoped endpoint. Preferred write shapes: ```bash jq -Rs '{body:.}' comment.md > /tmp/comment.json -gh api --method POST repos/ai-openshell/openshell/issues//comments --input /tmp/comment.json --jq .html_url -gh api --method POST repos/ai-openshell/openshell/issues//labels -f labels[]="gator:" -gh api --method DELETE repos/ai-openshell/openshell/issues//labels/gator%3Ablocked --silent || true +gh api --method POST repos//issues//comments --input /tmp/comment.json --jq .html_url +gh api --method POST repos//issues//labels -f labels[]="gator:" +gh api --method DELETE repos//issues//labels/gator%3Ablocked --silent || true ``` If a required GitHub REST read or write fails with `EOF`, `Empty reply from server`, or a sandbox `NET:FAIL` after the current policy shows the endpoint was allowed, treat it as a transient transport or provider failure. Do not convert the PR or issue to `gator:blocked`, do not report it as a rate-limit/auth failure, and do not keep probing optional endpoints such as `/rate_limit`. In supervised watch mode, finish with `OPENSHELL_AGENT_RESULT {"status":"transient_failure","next_poll_seconds":120,"reason":"github_transport_eof","notes":"GitHub transport failed after policy allowed the request. The supervisor should retry without changing the PR state."}` so the supervisor retries soon. @@ -70,7 +71,7 @@ Use these checks where needed: ```bash gh api user --jq '.login' -gh api repos/ai-openshell/openshell/collaborators//permission --jq '{permission,role_name}' +gh api repos//collaborators//permission --jq '{permission,role_name}' gh api orgs/ai-openshell/teams/maintainers/members --jq '.[].login' ``` @@ -271,9 +272,9 @@ When changing state, remove all existing `gator:*` labels first, then add the ne ```bash for label in gator%3Afollow-up-needed gator%3Ablocked gator%3Avalidated gator%3Ain-review gator%3Awatch-pipeline gator%3Aapproval-needed gator%3Amerge-ready; do - gh api --method DELETE repos/ai-openshell/openshell/issues//labels/$label --silent || true + gh api --method DELETE repos//issues//labels/$label --silent || true done -gh api --method POST repos/ai-openshell/openshell/issues//labels -f labels[]="gator:" +gh api --method POST repos//issues//labels -f labels[]="gator:" ``` Pull requests are also GitHub issues for label operations, so the REST issue label endpoints are valid for PR labels. @@ -319,7 +320,7 @@ for label in \ gator:watch-pipeline \ gator:approval-needed \ gator:merge-ready; do - gh pr list --repo ai-openshell/openshell --author "$author" --state closed \ + gh pr list --repo --author "$author" --state closed \ --search "label:$label" \ --json number,title,state,mergedAt,closedAt,labels,url,updatedAt done | jq -s 'add | unique_by(.number)' @@ -506,10 +507,10 @@ For newer issues and PRs, check for duplicates before deciding validity. Duplica Search for existing issues and PRs using the title, subsystem labels, changed files, key error strings, and important feature terms: ```bash -gh search issues --repo ai-openshell/openshell "" --state open --json number,title,state,url,labels,updatedAt -gh search issues --repo ai-openshell/openshell "" --state closed --json number,title,state,url,labels,updatedAt -gh search prs --repo ai-openshell/openshell "" --state open --json number,title,state,url,labels,updatedAt -gh search prs --repo ai-openshell/openshell "" --state closed --json number,title,state,url,labels,updatedAt +gh search issues --repo "" --state open --json number,title,state,url,labels,updatedAt +gh search issues --repo "" --state closed --json number,title,state,url,labels,updatedAt +gh search prs --repo "" --state open --json number,title,state,url,labels,updatedAt +gh search prs --repo "" --state closed --json number,title,state,url,labels,updatedAt ``` Treat items as duplicate candidates when they share the same user-visible problem, requested capability, affected subsystem, or implementation approach. Do not rely on title similarity alone. @@ -959,7 +960,7 @@ Build the batch as one REST request. Verify every requested line appears in the ```bash gh api --method POST \ - repos/ai-openshell/openshell/pulls//reviews \ + repos//pulls//reviews \ --input review.json ``` @@ -1026,7 +1027,7 @@ Applying `test:e2e`, `test:e2e-kubernetes`, `test:e2e:continuity`, or `test:wind operator authorization, approve a pending run using: ```bash -approve-gator-workflow --operator-authorized +OPENSHELL_GATOR_REPO= approve-gator-workflow --operator-authorized ``` The helper checks repository write permission, the PR's current head, the run's @@ -1124,7 +1125,7 @@ Use the exact reviewed head SHA for the approval: jq -n --arg head "" \ '{event:"APPROVE", commit_id:$head, body:"> **gator-agent**\n\n## Gator Approval\n\nGator review is complete and required CI has passed."}' \ > approval.json -gh api --method POST repos/ai-openshell/openshell/pulls//reviews --input approval.json +gh api --method POST repos//pulls//reviews --input approval.json ``` The App approval is separate from the code-review disposition. If the App diff --git a/.agents/agents/gator/tests/approve_gator_workflow_test.sh b/.agents/agents/gator/tests/approve_gator_workflow_test.sh index 4aadb94acb..b6d1ab14ae 100755 --- a/.agents/agents/gator/tests/approve_gator_workflow_test.sh +++ b/.agents/agents/gator/tests/approve_gator_workflow_test.sh @@ -23,6 +23,7 @@ esac SH chmod +x "$tmp/gh" export PATH="$tmp:$PATH" +export OPENSHELL_GATOR_REPOS_FILE="$dir/../repos.json" check() { bash "$dir/approve-gator-workflow" "$@"; } reject() { : > "$CALLS" @@ -39,6 +40,10 @@ PR_REPO=other/openshell reject --operator-authorized 42 123 RUN_REPO=other/openshell reject --operator-authorized 42 123 RUN_HEAD=stale reject --operator-authorized 42 123 CURRENT_HEAD=changed reject --operator-authorized 42 123 +# Registered repos with no approvable workflows, and unregistered repos, fail closed. +for denied in ai-openshell/desktop ai-openshell/unregistered; do + OPENSHELL_GATOR_REPO=$denied PR_REPO=$denied RUN_REPO=$denied reject --operator-authorized 42 123 +done RUN_PR=43 reject --operator-authorized 42 123 EVENT=push reject --operator-authorized 42 123 CONCLUSION=success reject --operator-authorized 42 123 diff --git a/.agents/agents/gator/tests/gh_guard_test.sh b/.agents/agents/gator/tests/gh_guard_test.sh index 3a394d9f0b..e2f4cdd778 100755 --- a/.agents/agents/gator/tests/gh_guard_test.sh +++ b/.agents/agents/gator/tests/gh_guard_test.sh @@ -8,6 +8,7 @@ set -euo pipefail GATOR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SCRIPT_DIR="$GATOR_DIR/bin" WRAPPER="$SCRIPT_DIR/gh" +export OPENSHELL_GATOR_REPOS_FILE="$SCRIPT_DIR/../repos.json" assert_status() { local expected="$1" @@ -508,6 +509,17 @@ for arg in --approve -a; do exit 1 fi done +# Approval is opt-in per repo: desktop is registered with approval disabled and +# an unregistered repo is denied the same way. +for denied_repo in ai-openshell/desktop ai-openshell/unregistered; do + jq -n --arg commit "$head77" '{event:"APPROVE",commit_id:$commit,body:"> **gator-agent**\n\n## Gator Approval"}' > "$approval_dir/review.json" + if PATH="$(dirname "$WRAPPER"):$PATH" APPROVAL_LOG="$approval_dir/log" APPROVAL_AUTHOR=maint-one \ + OPENSHELL_AGENT_OPTION_GITHUB=app OPENSHELL_REAL_GH="$approval_dir/mock-gh" "$WRAPPER" api --method POST \ + "repos/$denied_repo/pulls/77/reviews" --input "$approval_dir/review.json" >/dev/null 2>&1; then + echo "FAIL: Gator approved a PR in $denied_repo without repos.json approval" >&2 + exit 1 + fi +done # The App and user identities can both submit a COMMENT review. jq -n '{event:"COMMENT",body:"note"}' > "$approval_dir/review.json" for identity in user app; do @@ -520,6 +532,8 @@ ruby -ryaml -e ' endpoints = YAML.safe_load_file(ARGV.fetch(0)).fetch("endpoints") writes = endpoints.flat_map { |e| e.fetch("rules", []) } .filter_map { |rule| rule["allow"] }.select { |rule| rule["method"] == "POST" } + desktop = "/repos/ai-openshell/desktop/pulls/*/reviews" + abort "App cannot submit COMMENT reviews to desktop" unless writes.any? { |rule| rule.fetch("path") == desktop } abort "App cannot submit reviews to OpenShell" unless writes.any? { |rule| rule.fetch("path") == "/repos/ai-openshell/openshell/pulls/*/reviews" } ' "$profile" rm -rf "$approval_dir" diff --git a/.agents/agents/gator/tests/review_feedback_ledger_test.sh b/.agents/agents/gator/tests/review_feedback_ledger_test.sh index 71740b22cc..6dfe9bfe61 100755 --- a/.agents/agents/gator/tests/review_feedback_ledger_test.sh +++ b/.agents/agents/gator/tests/review_feedback_ledger_test.sh @@ -485,7 +485,7 @@ rg -q 'COPY bin/review-team /usr/local/bin/review-team' \ "$GATOR_DIR/Dockerfile" ruby -ryaml -e ' manifest = YAML.load_file(ARGV.fetch(0)) - abort unless manifest.fetch("payload_version") == 24 + abort unless manifest.fetch("payload_version") == 26 resource = manifest.fetch("resources").find { |entry| entry.fetch("id") == "gator-review-findings-schema" } diff --git a/.agents/skills/launch-openshell-gator/SKILL.md b/.agents/skills/launch-openshell-gator/SKILL.md index dbbbc6b0ef..4a6775c6fc 100644 --- a/.agents/skills/launch-openshell-gator/SKILL.md +++ b/.agents/skills/launch-openshell-gator/SKILL.md @@ -65,9 +65,11 @@ Use `gh api user` as the health check. It works with provider-scoped tokens and ```bash gh api user --jq '.login' -gh api repos/ai-openshell/openshell --jq '{full_name,default_branch}' +gh api repos/ --jq '{full_name,default_branch}' ``` +`` is `ai-openshell/openshell` unless the operator names another repository registered in `.agents/agents/gator/repos.json`. Set `repo` to it before the launch commands below; each gator targets one repository. + If this fails, refresh host `gh` auth before launching. Do not rely on `gh auth status` alone inside provider-backed sandboxes. ### Step 4: Verify Codex Auth For Codex Harness @@ -234,7 +236,7 @@ sandbox_name="gtr-pr-${pr_number}-watch" --gateway "$gateway_name" \ --name "$sandbox_name" \ --watch \ - "Review and monitor PR #${pr_number} in ai-openshell/openshell through the gator-gate workflow. Scope this invocation only to PR #${pr_number}. The operator explicitly authorizes applying relevant test labels and approving current-head GitHub Actions workflow runs through approve-gator-workflow." + "Review and monitor PR #${pr_number} in ${repo:-ai-openshell/openshell} through the gator-gate workflow. Scope this invocation only to PR #${pr_number}. The operator explicitly authorizes applying relevant test labels and approving current-head GitHub Actions workflow runs through approve-gator-workflow." ``` Native GitHub Actions approval replaces `/ok to test`; a test label selects the @@ -289,7 +291,7 @@ new `--github-provider NAME`. This keeps the old provider serving while the replacement mints its first token. After the new launch succeeds, use the new provider name on subsequent launches. `--reset-refresh` does not reset the App provider. App launches cover only -`ai-openshell/openshell`; use the default identity for private advisory forks. +the repositories in the App installation; use the default identity for private advisory forks. ### Review With The Team