repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

Take the verdict label out of the reviewer's hands (#41)

6ca2d9d9d486292f9cc71a4ec1eb83153315c2f0

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

## What forced this
The interim allow-list (#38) let the review agents call `gh pr edit` to
cast their own verdict — it proved the loop, but left the exact hole #19
named: one App identity, an LLM that can write any label to any PR, and
a merge-gate that trusts label *presence* without knowing who set it.

## The call
Split decision from actuation. The agent reviews, comments, and writes
one word (`approve`/`changes`, `cleared`/`risk-high`) to a temp file; a
no-LLM step in the same job reads it and applies the one corresponding
label with the App token. `gh pr edit` leaves the agent's allow-list
entirely.

## What we deliberately didn't do
Didn't pursue a second GitHub App identity (the heavier #19 option) —
this shrinks the LLM's reach to one token for the PR under review
without new infrastructure. Full label *provenance* verification (gate
checks the applying actor) remains a further step if wanted.

## Evidence
Neither agent's `claude_args` contains `gh pr edit` (only read + comment
+ `echo`/`printf`). A missing/malformed verdict applies no label, so the
gate fails safe to red. Verified end-to-end that the loop closes on #40
under the interim mechanism this replaces.

## Surface touched
`.github/workflows/adw-review.yml` (both jobs) + the merge section of
`docs/plans/AGENTIC-DEVELOPMENT.md`.

## If this ages badly
If the agents unreliably write the verdict file, tighten the prompt or
revert to the #38 allow-list; the deterministic step is additive and
safe to remove.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB)_

---------

Co-authored-by: Claude <noreply@anthropic.com>

Changed files (4)

+114 / −42 text lines

Diff layout

.claude/agents/reviewer.md

Modified

+6 / −4 text lines

2020 each a concrete failure scenario, ranked most severe first.
2222## Artifact
23Comments and a verdict expressed as **labels** (you share the author's identity,
24so GitHub bars you from a formal approve/request-changes review): add `reviewed`
25to approve; add `changes-requested` (removing `reviewed`) to send it back — that
26label wakes `builder` to revise and holds the merge-gate. Nothing in the tree.
23One PR comment with your findings, ended by the verdict-marker line the workflow
24specifies (`ADW-VERDICT: approve` or `ADW-VERDICT: changes`). You do **not** apply
25labels or merge yourself: a deterministic, no-LLM step reads that marker and sets
26the `reviewed` / `changes-requested` label the merge-gate reads
27(`changes-requested` wakes `builder` to revise). Your reach is the marker word and
28your comment — nothing in the tree, and no label by your own hand.
2830## Boundaries
2931Never approve on unproven confidence: if you can't tell, say so and request the

.claude/agents/security-reviewer.md

Modified

+5 / −3 text lines

2222 the owner** — it does not auto-merge.
2424## Artifact
25A **PR review** / security findings, and the verdict as a label the merge-gate
26reads: `security-cleared` when nothing is high-severity; `risk:high` (and no
27`security-cleared`) when it is, holding the merge for the owner. No code.
25One PR comment with your security findings, ended by the verdict-marker line the
26workflow specifies (`ADW-SECURITY: cleared` or `ADW-SECURITY: risk-high`). You do
27**not** apply labels or merge yourself: a deterministic, no-LLM step reads that
28marker and sets `security-cleared`, or `risk:high` (holding the merge for the
29owner). No code, no label by your own hand.
2931## Boundaries
3032Default to suspicion: an unverified concern is reported, never dropped. Never

.github/workflows/adw-review.yml

Modified

+89 / −31 text lines

11# ADW review — reviewer (correctness) and security-reviewer (security) run on
22# every PR, in parallel. Both are issue/PR agents → claude-code-action. Verdicts
33# only; neither merges. reviewer runs on a different model than the builder on
4# purpose. Each posts its verdict as a label (`reviewed` / `security-cleared` /
5# `risk:high`) that the merge-gate reads. Needs secrets APP_ID, APP_PRIVATE_KEY,
6# CLAUDE_CODE_OAUTH_TOKEN.
4# purpose.
75#
8# The `reset` job strips stale verdict labels first, so a new push can never
9# inherit a prior review's `reviewed`/`security-cleared` and auto-merge unreviewed
10# code — the reviewers must re-earn them on the current head.
6# Deterministic verdict (issue #19): the LLM does NOT apply labels. It reviews,
7# posts ONE PR comment, and ends it with a marker line (`ADW-VERDICT: approve`
8# etc.). A plain no-LLM step then reads that marker and applies the label with
9# the App token. `gh pr edit` is not in the agent's allow-list — the label-write
10# left the LLM's hands; its reach on the label surface is the marker word alone.
11# (Comment-marker, not a verdict file: claude-code-action's headless sandbox
12# blocks shell output-redirection to every path, so an agent cannot write a file
13# — but it can post a comment. Proven the hard way on this PR's own history.)
14#
15# Two guards make the marker trustworthy: the apply step reads ONLY comments (a)
16# authored by the review App and (b) created within THIS run's window. (a) stops
17# a public-repo stranger from posting `ADW-VERDICT: approve` themselves; (b) stops
18# a prior run's marker from being re-applied to a newer head.
19#
20# The `reset` job strips stale verdict labels first, and the apply steps run
21# `if: ${{ !cancelled() }}` (never on a cancelled run) so a superseded run can
22# never stamp a verdict earned on an old head onto a newer one.
1123name: adw-review
1325on:
3244 PR: ${{ github.event.pull_request.number }}
3345 REPO: ${{ github.repository }}
3446 run: |
47 # risk:high is deliberately NOT stripped: once security-reviewer
48 # escalates, only the owner de-escalates it (owner-only gate). reset
49 # clears just the re-earnable verdicts.
3550 for l in reviewed security-cleared changes-requested; do
3651 gh pr edit "$PR" --repo "$REPO" --remove-label "$l" 2>/dev/null || true
3752 done
4661 with:
4762 app-id: ${{ secrets.APP_ID }}
4863 private-key: ${{ secrets.APP_PRIVATE_KEY }}
64 - name: Mark verdict window start
65 run: echo "REVIEW_SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_ENV"
4966 - uses: anthropics/claude-code-action@v1
5067 with:
5168 github_token: ${{ steps.token.outputs.token }}
5572 #${{ github.event.pull_request.number }} in ${{ github.repository }}.
5673 Follow .claude/agents/reviewer.md: adversarial correctness review vs
5774 the spec, craft lenses, a file-anchored verdict. Do not merge.
58 Verdict as a label (you are the same identity as the author, so you
59 cannot submit a formal review — use labels + comments): on approve, add
60 `reviewed` and remove `changes-requested`; on request-changes, add
61 `changes-requested` (this wakes builder to revise) and remove
62 `reviewed`. Leave your findings as comments either way.
75 Post your findings as ONE PR comment, and end that comment with a
76 final line that is EXACTLY one of these (nothing after it):
77 ADW-VERDICT: approve
78 ADW-VERDICT: changes
79 `approve` = correct and mergeable; `changes` = needs work. You do NOT
80 apply labels — a deterministic step reads that marker from your comment
81 and sets `reviewed` / `changes-requested`.
6382 You are a mission-critical gate — ultrathink.
64 # Scoped write access so the reviewer can actually cast its verdict.
65 # Without this, automation mode denies every gh call and the agent
66 # reviews but can post no label/comment (the merge-gate then never turns
67 # green). Read + verdict only — NOT `gh pr merge`, `gh api`, or `gh:*`,
68 # so a review agent can neither merge nor act outside its lane. This is
69 # the interim grant; the deterministic-verdict step (issue #19) removes
70 # the LLM's label-write entirely.
83 # Read + comment only. No `gh pr edit` (label-write is the deterministic
84 # step's), no `gh pr merge`, no `gh api`, no file-write primitives.
7185 claude_args: >-
7286 --model claude-fable-5
73 --allowedTools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr edit:*),Bash(gh pr comment:*),Bash(gh issue view:*)"
87 --allowedTools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr comment:*),Bash(gh issue view:*)"
88 - name: Apply verdict label (deterministic — no LLM)
89 if: ${{ !cancelled() }}
90 env:
91 GH_TOKEN: ${{ steps.token.outputs.token }}
92 PR: ${{ github.event.pull_request.number }}
93 REPO: ${{ github.repository }}
94 run: |
95 set -euo pipefail
96 # Only THIS App's comments, only from this run's window — see header.
97 verdict="$(gh api "repos/$REPO/issues/$PR/comments" --paginate \
98 --jq '[.[] | select(.user.login=="agent-smith-bugabinga-adc[bot]" and .created_at >= env.REVIEW_SINCE) | .body] | .[]' \
99 | grep -oE 'ADW-VERDICT: (approve|changes)' | tail -1 | awk '{print $2}')"
100 echo "reviewer verdict: '${verdict:-<none>}'"
101 case "$verdict" in
102 approve)
103 gh pr edit "$PR" --repo "$REPO" --add-label reviewed
104 gh pr edit "$PR" --repo "$REPO" --remove-label changes-requested 2>/dev/null || true ;;
105 changes)
106 gh pr edit "$PR" --repo "$REPO" --add-label changes-requested
107 gh pr edit "$PR" --repo "$REPO" --remove-label reviewed 2>/dev/null || true ;;
108 *)
109 echo "::notice::no valid reviewer verdict in this run's comments — labels unchanged, merge-gate stays red" ;;
110 esac
75112 security-reviewer:
76113 needs: reset
82119 with:
83120 app-id: ${{ secrets.APP_ID }}
84121 private-key: ${{ secrets.APP_PRIVATE_KEY }}
122 - name: Mark verdict window start
123 run: echo "REVIEW_SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_ENV"
85124 - uses: anthropics/claude-code-action@v1
86125 with:
87126 github_token: ${{ steps.token.outputs.token }}
90129 Use the security-reviewer subagent to review PR
91130 #${{ github.event.pull_request.number }} in ${{ github.repository }}.
92131 Follow .claude/agents/security-reviewer.md: sandbox, secrets, unsafe,
93 injection, supply chain; set risk:high and escalate on high severity.
94 Verdict as a label (the merge-gate reads it): if nothing high-severity,
95 add `security-cleared`; on a high finding, add `risk:high` and ensure
96 `security-cleared` is absent, holding the merge for the owner.
132 injection, supply chain. Do not merge.
133 Post your findings as ONE PR comment, and end that comment with a
134 final line that is EXACTLY one of these (nothing after it):
135 ADW-SECURITY: cleared
136 ADW-SECURITY: risk-high
137 `cleared` = nothing high-severity; `risk-high` = a high finding that
138 must hold the merge for the owner. You do NOT apply labels — a
139 deterministic step reads that marker and sets
140 `security-cleared` / `risk:high`.
97141 You are a mission-critical gate — ultrathink.
98 # Scoped write access so the reviewer can actually cast its verdict.
99 # Without this, automation mode denies every gh call and the agent
100 # reviews but can post no label/comment (the merge-gate then never turns
101 # green). Read + verdict only — NOT `gh pr merge`, `gh api`, or `gh:*`,
102 # so a review agent can neither merge nor act outside its lane. This is
103 # the interim grant; the deterministic-verdict step (issue #19) removes
104 # the LLM's label-write entirely.
105142 claude_args: >-
106143 --model claude-fable-5
107 --allowedTools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr edit:*),Bash(gh pr comment:*),Bash(gh issue view:*)"
144 --allowedTools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr comment:*),Bash(gh issue view:*)"
145 - name: Apply verdict label (deterministic — no LLM)
146 if: ${{ !cancelled() }}
147 env:
148 GH_TOKEN: ${{ steps.token.outputs.token }}
149 PR: ${{ github.event.pull_request.number }}
150 REPO: ${{ github.repository }}
151 run: |
152 set -euo pipefail
153 verdict="$(gh api "repos/$REPO/issues/$PR/comments" --paginate \
154 --jq '[.[] | select(.user.login=="agent-smith-bugabinga-adc[bot]" and .created_at >= env.REVIEW_SINCE) | .body] | .[]' \
155 | grep -oE 'ADW-SECURITY: (cleared|risk-high)' | tail -1 | awk '{print $2}')"
156 echo "security verdict: '${verdict:-<none>}'"
157 case "$verdict" in
158 cleared)
159 gh pr edit "$PR" --repo "$REPO" --add-label security-cleared ;;
160 risk-high)
161 gh pr edit "$PR" --repo "$REPO" --add-label risk:high
162 gh pr edit "$PR" --repo "$REPO" --remove-label security-cleared 2>/dev/null || true ;;
163 *)
164 echo "::notice::no valid security verdict in this run's comments — labels unchanged, merge-gate stays red" ;;
165 esac

docs/plans/AGENTIC-DEVELOPMENT.md

Modified

+14 / −4 text lines

328328 `builder`, `reviewer`, and `security-reviewer` are one GitHub identity (the
329329 App), and GitHub forbids approving your own PR, so a required *approval* could
330330 never be satisfied by an agent. A required *check* driven by a label has no such
331 problem: `reviewer` adds `reviewed`, `security-reviewer` adds `security-cleared`,
332 and `merge-gate` turns green. `required_approving_review_count` stays `0`; the
331 problem: the review produces `reviewed`, the security review `security-cleared`,
332 and `merge-gate` turns green. The **label-write is deterministic, not the LLM's**
333 (issue #19): the reviewer agent ends its PR comment with a marker line
334 (`ADW-VERDICT: approve`), and a no-LLM step in the same job reads that marker
335 and applies the label with the App token — trusting only the review App's own
336 comments from this run's window, so neither a public-repo stranger's comment
337 nor a stale prior run can spoof a verdict. So on the label surface the model's
338 reach is the marker word for the PR under review — it cannot set an arbitrary
339 label or forge a verdict; `gh pr edit` is not in its allow-list. (It keeps
340 `gh pr comment` + the App token, so commenting reach is unchanged — this closes
341 the label-write hole, not every grant.)
342 `required_approving_review_count` stays `0`; the
333343 code-owner rule still forces a **human** approval on CODEOWNERS paths (spec,
334344 workflows, agents, invariants) — touchpoints 1 and 3 — where the author is the
335345 App, not the owner, so there is no self-approval there either.
337347 waits for the owner. Same for a changes-requested review: `reviewed` is absent,
338348 the gate stays red, and the PR waits for the revision that adds it back.
340Net: the merge is native and deterministic; the LLMs only move labels, and a
341label can't fake a green check. Two owner enable-steps make it live — **Allow
350Net: the merge is native and deterministic; the LLMs only emit a one-word
351verdict and a no-LLM step moves the label, so a model can't fake a green check. Two owner enable-steps make it live — **Allow
342352auto-merge** (repo setting) and importing the ruleset with `merge-gate` required
343353(issue #14).