fix(ci): use opencode-go plan model for AI review #5

Merged
Noel merged 14 commits from fix/ai_pr_review into main 2026-10-18 16:24:58 +00:00
Showing only changes of commit 3e68e630df - Show all commits
+34 -13
View File
@@ -109,8 +109,9 @@ jobs:
- name: Audit dependencies for known vulnerabilities
working-directory: ${{ env.APP_DIR }}
run: pnpm audit --prod --audit-level moderate
# blocks the PR on vulnerabilities - flip to true only if a CVE fix
# is genuinely blocked, never to make red pipelines "go away"
# blocks the PR on vulnerabilities - re-add `continue-on-error: true`
# here only if a CVE fix is genuinely blocked upstream, never to
# make a red pipeline green
# ------------------------------------------------------- dockerfile lint --
dockerfile-lint:
@@ -164,7 +165,13 @@ jobs:
run: |
# --no-roast = technical output for CI; --min-severity warning so
# info-level findings don't block the PR
droast --no-roast --min-severity warning .
# lint exactly the tree the discovery step sees: prune node_modules
# and .git so vendored Dockerfiles in dependencies cannot produce
# findings on third-party code
find . \
-path ./.git -prune -o -path ./node_modules -prune -o \
-type f \( -iname 'Dockerfile*' -o -iname '*dockerfile' -o -iname 'Containerfile*' \) \
-print0 | xargs -0 -r droast --no-roast --min-severity warning
# ------------------------------------------------------- snyk security ----
# DISABLED: Snyk free plan only includes ~100 test credits/month, which the
@@ -257,17 +264,19 @@ jobs:
# prompt-inject the agent into quoting the key in the review
# comment (publicly visible). Env vars are invisible to file reads.
# Permissions live in a global config OUTSIDE the checkout (no
# secrets in it, so nothing can leak): denying edit/bash/webfetch
# means no headless permission prompts can hang or kill the run,
# and the reviewer physically cannot modify the repo.
mkdir -p "$HOME/.config/opencode"
# OpenCode v2 permission schema: ordered array of
# secrets in it, so nothing can leak). OpenCode v2 schema: the
# field is "permissions" (plural) - an ordered array of
# {action, resource, effect}; "bash" was renamed "shell" in v2.
# websearch is a distinct action from webfetch - deny both, plus
# external directories.
# The singular v1 "permission" object is ignored by the v2 CLI
# (verified empirically: shell commands executed despite deny).
# Denying shell/edit/webfetch/websearch/external_directory means
# no headless permission prompts can hang or kill the run, and
# the reviewer physically cannot modify the repo or browse
# attacker-controlled URLs.
mkdir -p "$HOME/.config/opencode"
printf '{
"$schema": "https://opencode.ai/config.json",
"permission": [
"permissions": [
{ "action": "edit", "resource": "*", "effect": "deny" },
{ "action": "shell", "resource": "*", "effect": "deny" },
{ "action": "webfetch", "resource": "*", "effect": "deny" },
@@ -355,12 +364,18 @@ jobs:
# dumps never do. opencode can exit 1 on benign tool denials
# even after a full review, so a present verdict means post;
# anything else means the review did not complete.
if grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)' /tmp/review.md; then
# Anchored to the tail: the prompt itself contains VERDICT
# lines, so scanning the whole file could pass on echoed
# prompt text or injected quotes - only the last lines count.
if tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
[ "$EXIT_CODE" -ne 0 ] && echo "::warning::opencode exited ${EXIT_CODE} but produced a valid verdict - posting review"
echo "Review completed with verdict."
else
# fail closed: no verdict = no review. exit 1 unconditionally -
# falling back to EXIT_CODE would exit 0 when opencode succeeded
# but produced no review, and the job would go green.
echo "::error::opencode produced no valid review (exit ${EXIT_CODE:-1}) - NOT posting this output as a review comment"
exit "${EXIT_CODE:-1}"
exit 1
fi
- name: Post review as PR comment
@@ -371,6 +386,12 @@ jobs:
REPO: ${{ github.repository }}
# Gitea sets GITHUB_API_URL, e.g. https://gitea.example.com/api/v1
run: |
# re-verify the output contract here: never post anything that is
# not a completed review, regardless of how the previous step ended
if ! tail -n 5 /tmp/review.md | grep -qE '^VERDICT: (APPROVE|REQUEST_CHANGES)'; then
echo "::error::no verdict in review output - nothing to post"
exit 1
fi
# jq is not in the node image - use node for JSON encoding
BODY=$(node -e 'process.stdout.write(JSON.stringify(require("fs").readFileSync("/tmp/review.md","utf8")))')
HTTP_CODE=$(curl -s -o /tmp/comment-response.json -w "%{http_code}" \