Skip to content

Commit 4d16a2a

Browse files
authored
feat(gator): improve review output and launch compatibility (#2896)
* feat(gator): render human-readable review findings Signed-off-by: John Myers <johntmyers@users.noreply.github.com> * feat(gator): collapse operational review metadata Signed-off-by: John Myers <johntmyers@users.noreply.github.com> * fix(gator): support canonical sandbox startup Signed-off-by: John Myers <johntmyers@users.noreply.github.com> * fix(gator): preserve credential placeholder identity Signed-off-by: John Myers <johntmyers@users.noreply.github.com> * feat(gator): resolve addressed review threads Signed-off-by: John Myers <johntmyers@users.noreply.github.com> * fix(agents): preserve provider profile revisions Signed-off-by: John Myers <johntmyers@users.noreply.github.com> --------- Signed-off-by: John Myers <johntmyers@users.noreply.github.com> Co-authored-by: John Myers <johntmyers@users.noreply.github.com>
1 parent 0e79653 commit 4d16a2a

16 files changed

Lines changed: 566 additions & 92 deletions

File tree

‎.agents/skills/launch-openshell-gator/SKILL.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ For gator's PR/issue validation policy, load `gator-gate` inside the launched sa
2828
| `scripts/agents/gator/policy.yaml` | Sandbox policy for the gator agent. |
2929
| `scripts/agents/gator/bin/gh` | Gator-specific `gh` wrapper and same-SHA duplicate-post guard. |
3030
| `scripts/agents/gator/bin/review-feedback-ledger` | Builds tree-aware review scope, durable findings, convergence telemetry, and review-budget state. |
31+
| `scripts/agents/gator/bin/resolve-gator-review-threads` | Resolves addressed Gator-owned inline review threads by ledger finding ID. |
3132
| `scripts/agents/gator/bin/validate-review-findings` | Enforces the blocker evidence schema and downgrades unsupported hypotheses. |
3233
| `scripts/agents/gator/prompts/gator.md` | Rendered top-level prompt template baked into the payload. |
3334
| `scripts/agents/gator/skills/gator-gate/SKILL.md` | In-sandbox gator state-machine skill. |
@@ -157,7 +158,7 @@ sandbox_name="gator-pr-${pr_number}-supervised"
157158
"Review and monitor PR #${pr_number} through the gator-gate workflow. Scope this invocation only to PR #${pr_number}."
158159
```
159160

160-
The launcher builds the gator sandbox image when needed, stages the immutable payload, imports provider profiles, configures provider credentials and refresh, creates the sandbox, and writes a background log under `scripts/agents/gator/logs/`.
161+
The launcher builds the gator sandbox image when needed, stages the immutable payload, imports provider profiles, configures provider credentials and refresh, creates and uploads the sandbox payload, then starts the agent supervisor with `sandbox exec`. It writes a background log under `scripts/agents/gator/logs/`.
161162

162163
### Launch An Issue Or Issue/PR Pair
163164

@@ -317,10 +318,10 @@ Restart when the payload must change, the sandbox is wedged without a sentinel,
317318

318319
Increment `payload_version` in `scripts/agents/gator/agent.yaml` whenever a
319320
merged change alters the Gator prompt, gate skill, reviewer contract, write
320-
guard, ledger, or bundled validator. Existing immutable watchers cannot replace
321-
their own payload. New-version watchers detect later published versions and
322-
stop with `stale_gator_payload`; relaunch every still-active older watcher after
323-
the version bump is published.
321+
guard, ledger, thread resolver, or bundled validator. Existing immutable
322+
watchers cannot replace their own payload. New-version watchers detect later
323+
published versions and stop with `stale_gator_payload`; relaunch every
324+
still-active older watcher after the version bump is published.
324325

325326
Before deleting, check that the sandbox is truly stale or that the operator asked for a restart. If a bounded review cycle is actively running and still producing useful output, prefer leaving it alone.
326327

@@ -368,7 +369,9 @@ Symptoms: host `gh` auth fails, Codex refresh fails, in-sandbox GitHub calls rep
368369
Actions:
369370

370371
- Re-run the GitHub and Codex preflight checks.
372+
- Existing refresh-managed providers are reused without an ordinary credential update; the launcher rotates their gateway-managed credential instead.
371373
- If host Codex auth changed, relaunch with `--reset-refresh` once.
374+
- `--reset-refresh` removes the old refresh ownership before rediscovering host credentials, then configures and rotates the replacement refresh state.
372375
- If Entra or Microsoft auth is involved in a future provider, use the relevant auth skill. Gator's default providers are GitHub and Codex.
373376

374377
### Unsupported `gh pr view --json` Field

‎scripts/agents/gator/Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ RUN mkdir -p /etc/openshell
8585
COPY policy.yaml /etc/openshell/policy.yaml
8686
COPY bin/gh /usr/local/bin/gh-gator
8787
COPY bin/review-feedback-ledger /usr/local/bin/review-feedback-ledger
88+
COPY bin/resolve-gator-review-threads /usr/local/bin/resolve-gator-review-threads
8889
COPY bin/validate-review-findings /usr/local/bin/validate-review-findings
8990
RUN rm -f /usr/local/bin/gh && \
9091
cp /usr/local/bin/gh-gator /usr/local/bin/gh && \
9192
chmod 755 /usr/local/bin/gh /usr/local/bin/review-feedback-ledger \
93+
/usr/local/bin/resolve-gator-review-threads \
9294
/usr/local/bin/validate-review-findings
9395

9496
RUN printf 'export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"\nexport PS1="\\u@\\h:\\w\\$ "\n' \

‎scripts/agents/gator/README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The manifest-driven launcher at `scripts/agents/run.sh` reads `agent.yaml`, whic
2929

3030
The launcher:
3131

32-
- Scans `profile_paths` in manifest order and imports `providers/github-gator.yaml`.
32+
- Scans `profile_paths` in manifest order and imports or updates `providers/github-gator.yaml`.
3333
- Creates or updates the `github-gator` provider from `gh auth token`.
3434
- Selects the requested harness and bakes the common runtime into the immutable sandbox payload.
3535
- 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.
@@ -38,14 +38,18 @@ The launcher:
3838
- Uses the gator image policy copied to `/etc/openshell/policy.yaml`.
3939
- 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.
4040
- 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.
41+
- Installs `gator/bin/resolve-gator-review-threads` so a follow-up commit that
42+
demonstrably fixes a Gator inline finding can resolve the corresponding
43+
Gator-owned GitHub review thread without touching human review threads.
4144
- Installs `gator/bin/validate-review-findings` to downgrade blockers that lack the required reachability, ownership, base-vs-head, impact, and reproducer evidence.
45+
- 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.
4246
- Bakes `scripts/agents/gator/skills/gator-gate/SKILL.md` into `/etc/openshell/agent-payload`.
4347
- Bakes `.claude/agents/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`.
4448
- For `--harness codex`, optionally bakes a host Codex executable as `/etc/openshell/agent-payload/runtime/harnesses/codex/codex`.
4549
- Starts the selected harness without a TTY.
4650
- 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.
4751
- Makes each watch cycle compare its immutable payload version with the version published on the default branch. A stale watcher stops without GitHub writes and must be relaunched.
48-
The GitHub provider profile allows read-only GraphQL queries on `api.github.com/graphql` so `gh` read paths can use GraphQL when needed. Write operations remain REST-only and scoped to the two allowed repositories.
52+
The GitHub provider profile allows read-only GraphQL queries on `api.github.com/graphql` so `gh` read paths can use GraphQL when needed. Its only GraphQL mutation is the named `ResolveGatorReviewThread` operation, restricted to the `resolveReviewThread` root field. All other writes remain REST-only and scoped to the two allowed repositories.
4953

5054
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.
5155

@@ -58,4 +62,6 @@ The launcher preserves existing gateway-owned Codex refresh material by default
5862
```shell
5963
bash scripts/agents/gator/bin/gh_guard_test.sh
6064
bash scripts/agents/gator/bin/review_feedback_ledger_test.sh
65+
bash scripts/agents/gator/bin/resolve_gator_review_threads_test.sh
66+
bash scripts/agents/runtime/harnesses/codex/exec_test.sh
6167
```

‎scripts/agents/gator/agent.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
id: gator
5-
payload_version: 4
5+
payload_version: 7
66
display_name: Gator Gate Agent
77
description: Validate and monitor OpenShell GitHub issues and pull requests through the gator state machine.
88

‎scripts/agents/gator/bin/gh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -euo pipefail
77

88
REAL_GH="${OPENSHELL_REAL_GH:-/usr/bin/gh}"
99
GATOR_MARKER='> **gator-agent**'
10-
GATOR_PAYLOAD_VERSION="${OPENSHELL_AGENT_PAYLOAD_VERSION:-4}"
10+
GATOR_PAYLOAD_VERSION="${OPENSHELL_AGENT_PAYLOAD_VERSION:-5}"
1111

1212
if [[ $# -lt 1 || "$1" != "api" ]]; then
1313
exec "$REAL_GH" "$@"

‎scripts/agents/gator/bin/gh_guard_test.sh‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,15 @@ run_review_case() {
111111
112112
## PR Review Status
113113
114-
Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`' \
115-
--arg payload 'Gator payload: `4`' \
114+
The review is ready for author follow-up.
115+
116+
<details>
117+
<summary>Gator metadata</summary>
118+
119+
- Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`' \
120+
--arg payload '- Gator payload: `5`
121+
122+
</details>' \
116123
--arg inline_body '> **gator-agent**
117124
118125
**Warning:** Keep this validation bound to the accepted value.' \
@@ -142,7 +149,7 @@ same_sha_body='> **gator-agent**
142149
## PR Review Status
143150
144151
Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`
145-
Gator payload: `4`'
152+
Gator payload: `5`'
146153

147154
run_case "blocks duplicate marked comment" \
148155
"$same_sha_body" \
@@ -169,7 +176,7 @@ run_case "allows first versioned review disposition" \
169176
## PR Review Status
170177
171178
Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`
172-
Gator payload: `4`' \
179+
Gator payload: `5`' \
173180
0
174181

175182
run_case "allows unmarked comment" \
@@ -224,7 +231,7 @@ Gator is blocked from completing the required independent re-review for current
224231
## PR Review Status
225232
226233
Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`
227-
Gator payload: `4`' \
234+
Gator payload: `5`' \
228235
0
229236

230237
draft_blocked_body='> **gator-agent**
@@ -244,7 +251,7 @@ run_case "ignores draft blocker after PR is ready" \
244251
## PR Review Status
245252
246253
Head SHA: `0e4d7af7722fbedce2307d571b0c937a1eb3250f`
247-
Gator payload: `4`' \
254+
Gator payload: `5`' \
248255
0 \
249256
false
250257

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -euo pipefail
7+
8+
usage() {
9+
cat >&2 <<'EOF'
10+
Usage:
11+
resolve-gator-review-threads LEDGER.json FINDING_ID [FINDING_ID ...]
12+
EOF
13+
}
14+
15+
[[ "$#" -ge 2 && -r "$1" ]] || {
16+
usage
17+
exit 2
18+
}
19+
20+
ledger="$1"
21+
shift
22+
23+
jq -e '
24+
.schema_version == 4 and
25+
(.threads | type == "array")
26+
' "$ledger" >/dev/null || {
27+
echo "invalid gator review feedback ledger" >&2
28+
exit 2
29+
}
30+
31+
mutation='mutation ResolveGatorReviewThread($threadId: ID!) {
32+
resolveReviewThread(input: {threadId: $threadId}) {
33+
thread {
34+
id
35+
isResolved
36+
}
37+
}
38+
}'
39+
40+
finding_ids=("$@")
41+
thread_ids=()
42+
resolution_states=()
43+
declare -A seen_finding_ids=()
44+
45+
# Validate the complete request before performing the first GitHub write so a
46+
# malformed or ambiguous later ID cannot leave a partially resolved batch.
47+
for finding_id in "${finding_ids[@]}"; do
48+
[[ "$finding_id" =~ ^(GATOR-[0-9A-Fa-f]{8}-[0-9]{2}|gator-inline-[0-9]+)$ ]] || {
49+
echo "invalid gator finding ID: $finding_id" >&2
50+
exit 2
51+
}
52+
[[ -z "${seen_finding_ids[$finding_id]:-}" ]] || {
53+
echo "duplicate gator finding ID: $finding_id" >&2
54+
exit 2
55+
}
56+
seen_finding_ids["$finding_id"]=1
57+
58+
matching_threads="$(jq -c --arg finding_id "$finding_id" '
59+
[
60+
.threads[]
61+
| select(.finding_id == $finding_id)
62+
]
63+
' "$ledger")"
64+
match_count="$(jq 'length' <<< "$matching_threads")"
65+
[[ "$match_count" -eq 1 ]] || {
66+
echo "expected exactly one Gator thread for $finding_id; found $match_count" >&2
67+
exit 1
68+
}
69+
70+
first_body="$(jq -r '.[0].comments[0].body // empty' <<< "$matching_threads")"
71+
[[ "$first_body" == '> **gator-agent**'* ]] || {
72+
echo "refusing to resolve non-Gator thread for $finding_id" >&2
73+
exit 1
74+
}
75+
76+
thread_id="$(jq -r '.[0].thread_id // empty' <<< "$matching_threads")"
77+
[[ -n "$thread_id" ]] || {
78+
echo "Gator thread ID missing for $finding_id" >&2
79+
exit 1
80+
}
81+
82+
thread_ids+=("$thread_id")
83+
resolution_states+=("$(jq -r '.[0].is_resolved' <<< "$matching_threads")")
84+
done
85+
86+
for ((i = 0; i < ${#finding_ids[@]}; i++)); do
87+
finding_id="${finding_ids[$i]}"
88+
thread_id="${thread_ids[$i]}"
89+
if [[ "${resolution_states[$i]}" == "true" ]]; then
90+
echo "Gator review thread already resolved: $finding_id"
91+
continue
92+
fi
93+
94+
response="$(gh api graphql \
95+
-f query="$mutation" \
96+
-f threadId="$thread_id")"
97+
jq -e --arg thread_id "$thread_id" '
98+
.data.resolveReviewThread.thread
99+
| .id == $thread_id and .isResolved == true
100+
' <<< "$response" >/dev/null || {
101+
echo "GitHub did not confirm resolution for $finding_id ($thread_id)" >&2
102+
exit 1
103+
}
104+
105+
echo "Resolved Gator review thread: $finding_id"
106+
done
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -euo pipefail
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
GATOR_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
10+
RESOLVER="$SCRIPT_DIR/resolve-gator-review-threads"
11+
12+
tmp="$(mktemp -d)"
13+
trap 'rm -rf "$tmp"' EXIT
14+
mkdir -p "$tmp/bin"
15+
16+
cat > "$tmp/bin/gh" <<'SH'
17+
#!/usr/bin/env bash
18+
set -euo pipefail
19+
20+
thread_id=""
21+
previous=""
22+
for arg in "$@"; do
23+
if [[ "$previous" == "-f" && "$arg" == threadId=* ]]; then
24+
thread_id="${arg#threadId=}"
25+
fi
26+
previous="$arg"
27+
done
28+
29+
printf '%s\n' "$*" >> "${MOCK_GH_LOG:?}"
30+
if [[ "$thread_id" == "${MOCK_FAIL_THREAD:-}" ]]; then
31+
jq -n --arg id "$thread_id" '{data: {resolveReviewThread: {thread: {id: $id, isResolved: false}}}}'
32+
else
33+
jq -n --arg id "$thread_id" '{data: {resolveReviewThread: {thread: {id: $id, isResolved: true}}}}'
34+
fi
35+
SH
36+
chmod +x "$tmp/bin/gh"
37+
38+
cat > "$tmp/ledger.json" <<'JSON'
39+
{
40+
"schema_version": 4,
41+
"threads": [
42+
{
43+
"thread_id": "thread-open",
44+
"finding_id": "GATOR-11111111-01",
45+
"is_resolved": false,
46+
"comments": [{"body": "> **gator-agent**\n\nOpen finding"}]
47+
},
48+
{
49+
"thread_id": "thread-resolved",
50+
"finding_id": "GATOR-11111111-02",
51+
"is_resolved": true,
52+
"comments": [{"body": "> **gator-agent**\n\nResolved finding"}]
53+
},
54+
{
55+
"thread_id": "thread-legacy",
56+
"finding_id": "gator-inline-1234",
57+
"is_resolved": false,
58+
"comments": [{"body": "> **gator-agent**\n\nLegacy finding"}]
59+
},
60+
{
61+
"thread_id": "thread-human",
62+
"finding_id": "GATOR-22222222-01",
63+
"is_resolved": false,
64+
"comments": [{"body": "Human review thread"}]
65+
}
66+
]
67+
}
68+
JSON
69+
70+
export MOCK_GH_LOG="$tmp/gh.log"
71+
PATH="$tmp/bin:$PATH" "$RESOLVER" "$tmp/ledger.json" \
72+
GATOR-11111111-01 GATOR-11111111-02 gator-inline-1234 \
73+
> "$tmp/success.out"
74+
75+
[[ "$(grep -c 'threadId=thread-' "$tmp/gh.log")" -eq 2 ]]
76+
grep -q 'ResolveGatorReviewThread' "$tmp/gh.log"
77+
grep -q 'threadId=thread-open' "$tmp/gh.log"
78+
grep -q 'threadId=thread-legacy' "$tmp/gh.log"
79+
grep -q 'already resolved: GATOR-11111111-02' "$tmp/success.out"
80+
81+
if PATH="$tmp/bin:$PATH" "$RESOLVER" "$tmp/ledger.json" GATOR-33333333-01 >/dev/null 2>&1; then
82+
echo "expected unknown finding ID to fail" >&2
83+
exit 1
84+
fi
85+
86+
if PATH="$tmp/bin:$PATH" "$RESOLVER" "$tmp/ledger.json" GATOR-22222222-01 >/dev/null 2>&1; then
87+
echo "expected human-owned thread resolution to fail" >&2
88+
exit 1
89+
fi
90+
91+
if MOCK_FAIL_THREAD=thread-open PATH="$tmp/bin:$PATH" \
92+
"$RESOLVER" "$tmp/ledger.json" GATOR-11111111-01 >/dev/null 2>&1; then
93+
echo "expected unconfirmed GitHub resolution to fail" >&2
94+
exit 1
95+
fi
96+
97+
ruby -ryaml -e '
98+
profile = YAML.load_file(ARGV.fetch(0))
99+
endpoint = profile.fetch("endpoints").find {
100+
|entry| entry["path"] == "/graphql"
101+
}
102+
abort unless endpoint.fetch("rules").any? {
103+
|rule|
104+
allow = rule["allow"]
105+
allow &&
106+
allow["operation_type"] == "mutation" &&
107+
allow["operation_name"] == "ResolveGatorReviewThread" &&
108+
allow["fields"] == ["resolveReviewThread"]
109+
}
110+
' "$GATOR_DIR/providers/github-gator.yaml"
111+
112+
echo "resolve-gator-review-threads tests passed"

0 commit comments

Comments
 (0)