Skip to content

feat: add security consensus design for bounty #104 (0.42 BTC) #29

feat: add security consensus design for bounty #104 (0.42 BTC)

feat: add security consensus design for bounty #104 (0.42 BTC) #29

Workflow file for this run

name: Review PR
# Mirrors the Inspector "review" workflow, but fires on freshly OPENED pull
# requests authored by a real (non-bot) human, and posts an automated review in
# the voice of Cookie Monster trapped in a duck's body. The automated, src/-only
# PRs from the self-improvement bot are deliberately skipped here — those are the
# Inspector's beat (.github/workflows/review.yaml), which is left unchanged.
#
# We use `pull_request_target` so the GITHUB_TOKEN has write access (to post the
# review) even for fork PRs. This is safe because we NEVER check out or execute
# the PR's code: we only read its diff text via `gh pr diff` and feed that text
# to a local model. The checkout below is the BASE repo (our trusted script).
on:
pull_request_target:
types: [opened]
# Manual trigger: run the duck against a specific PR on demand. Handy for
# re-reviewing, or reviewing a PR that predates this workflow.
workflow_dispatch:
inputs:
pr_number:
description: "PR number to review (e.g. 42)"
required: true
type: string
permissions:
contents: read
pull-requests: write
# One review per PR; don't stack duck reviews on top of each other. (Falls back
# to the dispatch input when there is no pull_request event.)
concurrency:
group: cookie-duck-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
cancel-in-progress: false
jobs:
review:
# On `pull_request_target`, only review PRs opened by a non-github-actions-bot
# user (this also keeps us off the self-improvement bot's PRs, which the
# Inspector handles). A manual `workflow_dispatch` always runs.
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.user.login != 'github-actions[bot]' }}
runs-on: ubuntu-latest
# Run-level guard against an infinite re-prompt loop (the script has no static
# fallbacks; a stage that never produces usable output just retries).
timeout-minutes: 10
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REVIEW_MODEL: "qwen3.5:0.8b"
# Resolve the target PR from the manual input, else the triggering PR.
PR_NUMBER: ${{ github.event.inputs.pr_number || github.event.pull_request.number }}
steps:
- name: Checkout (base repo — our trusted scripts only)
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install and start Ollama
run: |
curl -fsSL https://ollama.com/install.sh | sh
nohup ollama serve >/tmp/ollama.log 2>&1 &
# Wait for the server to accept connections.
for i in $(seq 1 30); do
if curl -fsS http://127.0.0.1:11434/api/version >/dev/null 2>&1; then
echo "ollama is up"; break
fi
sleep 2
done
- name: Pull model (qwen)
run: ollama pull "$REVIEW_MODEL"
- name: Generate the review
env:
REVIEW_PAYLOAD_FILE: ${{ runner.temp }}/review_payload.json
REVIEW_BODY_FILE: ${{ runner.temp }}/review_body.md
run: python .github/scripts/human_review.py
- name: Post the review
env:
REVIEW_PAYLOAD_FILE: ${{ runner.temp }}/review_payload.json
REVIEW_BODY_FILE: ${{ runner.temp }}/review_body.md
run: |
set -euo pipefail
# Preferred: a formal review with inline comments + the suggested change.
if gh api --method POST \
"repos/${{ github.repository }}/pulls/${PR_NUMBER}/reviews" \
--input "$REVIEW_PAYLOAD_FILE"; then
echo "Posted the review on PR #$PR_NUMBER. 🦆🍪"
else
# GitHub can reject inline anchors (line mapping is finicky). Fall back
# to the same content as a plain PR comment so the review is never lost.
echo "::warning::Formal review rejected; falling back to a plain comment."
gh pr comment "$PR_NUMBER" --body-file "$REVIEW_BODY_FILE"
echo "Commented the review on PR #$PR_NUMBER. 🦆🍪"
fi