Skip to content
Open
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
4 changes: 3 additions & 1 deletion .agents/agents/gator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ COPY bin/review-feedback-ledger /usr/local/bin/review-feedback-ledger
COPY bin/resolve-gator-review-threads /usr/local/bin/resolve-gator-review-threads
COPY bin/validate-review-findings /usr/local/bin/validate-review-findings
COPY bin/approve-gator-workflow /usr/local/bin/approve-gator-workflow
COPY bin/review-team /usr/local/bin/review-team
RUN rm -f /usr/local/bin/gh && \
cp /usr/local/bin/gh-gator /usr/local/bin/gh && \
chmod 755 /usr/local/bin/gh /usr/local/bin/review-feedback-ledger \
/usr/local/bin/resolve-gator-review-threads \
/usr/local/bin/validate-review-findings /usr/local/bin/approve-gator-workflow
/usr/local/bin/validate-review-findings /usr/local/bin/approve-gator-workflow \
/usr/local/bin/review-team

RUN printf 'export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"\nexport PS1="\\u@\\h:\\w\\$ "\n' \
> /sandbox/.bashrc && \
Expand Down
24 changes: 21 additions & 3 deletions .agents/agents/gator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ The manifest-driven launcher at `scripts/agents/run.sh` reads `agent.yaml`, whic
The launcher:

- Scans `profile_paths` in manifest order and imports or updates `providers/github-gator.yaml`.
- Creates or updates the `github-gator` provider from `gh auth token`.
- Creates or updates the `github-gator` provider from `gh auth token`. With `--option github=app`, it instead imports `providers/github-app-gator.yaml`, creates the `github-gator-app` provider, and configures gateway refresh for the `gator-review-bot` GitHub App installation token.
- Selects the requested harness and bakes the common runtime into the immutable sandbox payload.
- Builds with the latest Codex CLI by default. Docker can reuse the cached install layer; rebuild with that layer's cache disabled to fetch a newer release.
- For `--harness codex`, imports `providers/codex-gator.yaml`, creates or updates the `codex-gator` provider from `$HOME/.codex/auth.json`, and stores the refresh token as gateway-only refresh material.
- For `--harness codex`, reuses gateway-managed refresh for `CODEX_AUTH_ACCESS_TOKEN`. Initial setup and explicit resets configure and rotate it once.
- Passes the non-secret Codex account ID from host auth as `CODEX_ACCOUNT_ID`. The harness writes it literally into `auth.json` for local workspace discovery; access tokens remain opaque provider placeholders and refresh tokens remain gateway-only.
- Enables `agent_policy_proposals_enabled` and `proposal_approval_mode=auto` on the gator sandbox only. Gateway-global values for these keys take precedence; the launcher does not change them.
- Uses the gator image policy copied to `/etc/openshell/policy.yaml`.
- Installs the gator-specific `gh` wrapper from `gator/bin/gh` as `/usr/local/bin/gh` to fail closed when same-head-SHA history cannot be checked, prevent duplicate dispositions, and require versioned review payloads.
- Installs the Gator `gh` wrapper to check same-head history, prevent duplicate dispositions, and require versioned review payloads. It deduplicates App approvals separately from code-review comments.
- Installs `gator/bin/review-feedback-ledger` as `/usr/local/bin/review-feedback-ledger` so reviews receive tree- and patch-aware scope, prior summaries and findings, resolution state, convergence telemetry, and the three-round Warning budget.
Patch identity uses fetched merge-base/head trees in a temporary bare Git
repository, avoiding GitHub's full-diff size limit without checking out PR
Expand All @@ -125,6 +125,7 @@ The launcher:
- Keeps that normalized evidence as Gator's internal review contract, then renders validated blockers for people as a read-aloud `Summary`, an actionable `Fix`, and a deterministic `Verify`. Exact paths and only the additional provenance an implementation agent needs appear in collapsed `Agent context`; raw evidence headings such as `Base` and `Head` are not posted publicly. Review-process provenance, docs and E2E disposition, SHAs, and state codes appear at the end of the summary in collapsed `Gator metadata`, while required human actions remain visible.
- Bakes `.agents/agents/gator/skills/gator-gate/SKILL.md` into `/etc/openshell/agent-payload`.
- Bakes `.agents/agents/principal-engineer-reviewer/prompts/principal-engineer-reviewer.md` so the selected harness can run a deterministic independent reviewer execution through `/etc/openshell/agent-payload/runtime/subagent.sh principal-engineer-reviewer < task.md`.
- Bakes the review team: `bin/review-team`, the `prompts/review-*.md` members, and `skills/gator-gate/references/review-team.json`.
- For `--harness codex`, optionally bakes a host Codex executable as `/etc/openshell/agent-payload/runtime/harnesses/codex/codex`.
- Starts the selected harness without a TTY.
- Runs gator in `watch` mode by default. The sandbox stays alive while the supervisor sleeps between bounded Codex cycles, so Codex is not connected during passive PR waits. The supervisor prints periodic heartbeat lines during active cycles and passive sleeps.
Expand All @@ -133,7 +134,11 @@ The GitHub provider profile allows read-only GraphQL queries on `api.github.com/

Set `GATOR_CODEX_ACCESS_CREDENTIAL_KEY` or pass `--codex-access-key` if the gator Codex profile uses a credential key other than `CODEX_AUTH_ACCESS_TOKEN` for the short-lived access token.

Use `--once` for a single reconciliation cycle. Use `--poll-interval <seconds>` to change the default 15-minute watch cadence.
To run Gator as the `gator-review-bot` GitHub App, point `GATOR_GITHUB_APP_PRIVATE_KEY_FILE` at the App PEM and pass `--option github=app`. The gateway mints installation tokens scoped to `ai-openshell/openshell` with the permissions in `agent.yaml`; the sandbox sees only a placeholder. App launches cannot reach private advisory forks.

To replace the PEM, launch with the new key and a new `--github-provider NAME`. The previous provider keeps serving while the replacement mints its first token. Use the new provider name on subsequent launches after it succeeds. `--reset-refresh` does not replace App keys.

Use `--once` for a single reconciliation cycle. Use `--poll-interval <seconds>` to change the default 15-minute watch cadence. Use `--option reviewer=team` to review with the review team instead of the single `principal-engineer-reviewer` (`--option reviewer=single`, the default).

The launcher preserves gateway-owned Codex refresh material without reading host refresh material or forcing rotation on subsequent launches. Lookup, configuration, and rotation errors fail the launch rather than triggering an automatic reset. After reauthenticating Codex locally, pass `--reset-refresh` only when you intend to replace the shared provider's refresh ownership; this affects other sandboxes using that provider.

Expand All @@ -145,10 +150,23 @@ Test labels select CI suites. Gator can approve current-head workflow runs only
with explicit launch authorization. PRs changing `.github/` require manual
approval. PR approval, merging, reruns, and dispatch require separate authorization.

With `--option github=app`, Gator directly approves the reviewed head of a
maintainer-authored PR once it has cleared review and CI. The
`OpenShell / Maintainer Approval` check independently verifies the App review,
author, and head. Required CI and CODEOWNER reviews still apply. The PR author
merges in GitHub.

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.

## Tests

The test suite requires Bash, Ruby, Node.js, jq, and ripgrep on the host. It mocks image, gateway, credential, and GitHub operations.

```shell
mise run test:gator
```

To measure reviewer changes against past review misses, see
[`evals/README.md`](evals/README.md).
66 changes: 64 additions & 2 deletions .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: 16
payload_version: 18
display_name: Gator Gate Agent
description: Validate and monitor OpenShell GitHub issues and pull requests through the gator state machine.

Expand All @@ -15,13 +15,23 @@ harness:
default: codex
supported:
codex:
model: gpt-6.1-sol
model: gpt-6.2-sol
reasoning: medium

runtime:
mode: watch
poll_interval_seconds: 900
max_transient_failures: 5
options:
# single: the principal-engineer-reviewer alone. team: bin/review-team.
reviewer:
values: [single, team]
default: single
# user: the operator's `gh auth token`. app: the gator-review-bot GitHub App,
# with the private key path in GATOR_GITHUB_APP_PRIVATE_KEY_FILE.
github:
values: [user, app]
default: user

profile_paths:
- providers
Expand All @@ -36,6 +46,7 @@ providers:
- id: github
name: github-gator
profile: github-gator
option: {github: user}
credential_mode: explicit
credentials:
- env: GITHUB_TOKEN
Expand All @@ -44,6 +55,30 @@ providers:
command: gh auth token
export: true

- id: github-app
name: github-gator-app
profile: github-app-gator
option: {github: app}
credential_mode: runtime
refresh:
credential_key: GITHUB_TOKEN
strategy: github-app-installation
materials:
- name: client_id
value: Iv23liXeS0Vd5XOUzVgN
- name: installation_id
value: "187638323"
# ai-openshell/openshell
- name: repository_ids
value: "[1166129534]"
- name: permissions
value: '{"actions":"write","checks":"read","contents":"read","issues":"write","members":"read","pull_requests":"write","statuses":"write"}'
- name: private_key
secret: true
source:
kind: file
path_env: GATOR_GITHUB_APP_PRIVATE_KEY_FILE

- id: codex
name: codex-gator
profile: codex-gator
Expand Down Expand Up @@ -84,11 +119,38 @@ resources:
- id: gator-review-findings-schema
source: agent://skills/gator-gate/references/review-findings-schema.md
destination: skills/gator-gate/references/review-findings-schema.md
- id: gator-review-team-config
source: agent://skills/gator-gate/references/review-team.json
destination: skills/gator-gate/references/review-team.json
- id: gator-review-team-member-rules
source: agent://skills/gator-gate/references/review-team-member.md
destination: skills/gator-gate/references/review-team-member.md
- id: gator-networking-checklist
source: agent://skills/gator-gate/references/networking-checklist.md
destination: skills/gator-gate/references/networking-checklist.md

subagents:
- id: principal-engineer-reviewer
source: repo://.agents/agents/principal-engineer-reviewer/prompts/principal-engineer-reviewer.md
destination: subagents/principal-engineer-reviewer.md
expose_as: REVIEWER_COMMAND
- id: review-correctness
source: agent://prompts/review-correctness.md
destination: subagents/review-correctness.md
- id: review-security
source: agent://prompts/review-security.md
destination: subagents/review-security.md
- id: review-contracts
source: agent://prompts/review-contracts.md
destination: subagents/review-contracts.md
- id: review-compatibility
source: agent://prompts/review-compatibility.md
destination: subagents/review-compatibility.md
- id: review-networking
source: agent://prompts/review-networking.md
destination: subagents/review-networking.md
- id: review-merge
source: agent://prompts/review-merge.md
destination: subagents/review-merge.md

prompt_template: prompts/gator.md
10 changes: 7 additions & 3 deletions .agents/agents/gator/bin/approve-gator-workflow
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ fi
repo=ai-openshell/openshell
pr="$2" run="$3"
deny() { echo "Workflow not approved: $*" >&2; exit 1; }
actor="$(gh api user --jq .login)"
permission="$(gh api "repos/$repo/collaborators/$actor/permission" --jq .permission)"
case "$permission" in admin|maintain|write) ;; *) deny 'repository write permission is required' ;; esac
# 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
actor="$(gh api user --jq .login)"
permission="$(gh api "repos/$repo/collaborators/$actor/permission" --jq .permission)"
case "$permission" in admin|maintain|write) ;; *) deny 'repository write permission is required' ;; esac
fi
pull="$(gh api "repos/$repo/pulls/$pr")"
head="$(jq -er '.head.sha' <<< "$pull")"
jq -e --arg repo "$repo" '.state == "open" and .draft == false and (.base.repo.full_name | ascii_downcase) == ($repo | ascii_downcase)' <<< "$pull" >/dev/null || deny 'PR is not open and ready in the target repository'
Expand Down
76 changes: 73 additions & 3 deletions .agents/agents/gator/bin/gh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fi
method="GET"
input_file=""
body_field=""
event_field=""
commit_id_field=""
endpoint=""
args=("$@")

Expand Down Expand Up @@ -50,9 +52,11 @@ for ((i = 1; i < ${#args[@]}; i++)); do
-f|--field|-F|--raw-field)
if (( i + 1 < ${#args[@]} )); then
field="${args[$((i + 1))]}"
if [[ "$field" == body=* ]]; then
body_field="${field#body=}"
fi
case "$field" in
body=*) body_field="${field#body=}" ;;
event=*) event_field="${field#event=}" ;;
commit_id=*) commit_id_field="${field#commit_id=}" ;;
esac
consume_next=true
fi
;;
Expand All @@ -69,6 +73,15 @@ for ((i = 1; i < ${#args[@]}; i++)); do
esac
done

read_field() {
local name="$1" fallback="$2"
if [[ -n "$input_file" && -f "$input_file" ]]; then
jq -r --arg name "$name" '.[$name] // empty' "$input_file" 2>/dev/null || true
return
fi
printf '%s' "$fallback"
}

read_body() {
if [[ -n "$input_file" && -f "$input_file" ]]; then
jq -r '.body // empty' "$input_file" 2>/dev/null || true
Expand Down Expand Up @@ -218,6 +231,63 @@ guard_duplicate_gator_disposition() {
fi
}

guard_gator_approval() {
local repo="$1" number="$2" body="$3" commit="$4"
local pull default_branch author maintainers required reviews seen
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
return 23
fi
pull="$("$REAL_GH" api "repos/$repo/pulls/$number")" || return 21
if ! jq -e --arg commit "$commit" '
($commit | test("^[0-9a-f]{40}$")) and
.state == "open" and .draft == false and .head.sha == $commit
' <<< "$pull" >/dev/null; then
echo "openshell-agent: Gator approval requires the current head of an open, ready PR" >&2
return 23
fi
author="$(jq -er '.user.login' <<< "$pull")" || return 21
default_branch="$(jq -er '.base.repo.default_branch' <<< "$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
if ! jq -ne --arg roster "$maintainers" --arg author "${author,,}" '
any($roster | scan("\\[@([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)\\]\\(https://github\\.com/")[];
ascii_downcase == $author)
' >/dev/null; then
echo "openshell-agent: Gator approval requires a maintainer-authored PR" >&2
return 23
fi
required="$("$REAL_GH" pr checks "$number" --repo "$repo" --required --json name)" || return 21
if ! jq -e 'any(.[]; .name == "OpenShell / Maintainer Approval")' <<< "$required" >/dev/null; then
echo "openshell-agent: OpenShell / Maintainer Approval must be required before Gator submits an approval" >&2
return 23
fi
reviews="$("$REAL_GH" api --paginate --slurp "repos/$repo/pulls/$number/reviews")" || return 21
# An approval is independent of the code-review disposition. GitHub ties
# it to commit_id, including when a maintainer later dismisses the review.
seen="$(jq -ser --arg commit "$commit" '
if length != 1 or (.[0] | type != "array") then error("invalid review list") else .[0] end |
any(.[][]; .user.id == 363243726 and .commit_id == $commit and
(.state | IN("APPROVED", "DISMISSED", "CHANGES_REQUESTED")))
| tostring
' <<< "$reviews")" || return 21
if [[ "$seen" == true ]]; then
echo "openshell-agent: Gator already submitted a decisive review for this head" >&2
return 20
fi
}

if [[ "${method^^}" == "POST" && "$endpoint" =~ ^repos/([^/]+/[^/]+)/pulls/([0-9]+)/reviews$ ]]; then
review_event="$(read_field event "$event_field")"
if [[ "${review_event^^}" == APPROVE ]]; then
guard_gator_approval "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" \
"$(read_body)" "$(read_field commit_id "$commit_id_field")"
exec "$REAL_GH" "$@"
fi
fi

if [[ "${OPENSHELL_GATOR_ALLOW_SAME_SHA_COMMENT:-}" != "1" && "${method^^}" == "POST" ]]; then
request_body="$(read_body)"
if [[ "$endpoint" =~ ^repos/([^/]+)/([^/]+)/issues/([0-9]+)/comments$ ]]; then
Expand Down
Loading
Loading