Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b84d353dcb | ||
|
|
f5810960a8 | ||
|
|
679c0b4858 | ||
|
|
efb73378e9 | ||
|
|
a8355d976b | ||
|
|
214ec46fed | ||
|
|
c332c195a9 | ||
|
|
c626cc9c1d | ||
|
|
a129e89aec | ||
|
|
2497d91cf7 | ||
|
|
9ecf504843 |
No files matched your search
@@ -229,229 +229,3 @@ jobs:
|
|||||||
# Dockerfile/base image checks are covered by the droast job
|
# Dockerfile/base image checks are covered by the droast job
|
||||||
snyk code test \
|
snyk code test \
|
||||||
--severity-threshold=high
|
--severity-threshold=high
|
||||||
|
|
||||||
# -------------------------------------------------------- ai code review --
|
|
||||||
review:
|
|
||||||
name: AI code review (opencode)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: node:22-bookworm
|
|
||||||
# Draft PRs don't get a (paid) review yet. The event_name check is
|
|
||||||
# load-bearing: manual (workflow_dispatch) triggers - which exist to
|
|
||||||
# run the paused snyk job - must NOT launch a paid review, which on
|
|
||||||
# a dispatch event has no PR to post to.
|
|
||||||
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Restore opencode binary
|
|
||||||
id: opencode-cache
|
|
||||||
# The installer writes to $HOME/.opencode/bin. Caching it saves the
|
|
||||||
# ~4s download+extract per run - small next to the model call, but
|
|
||||||
# free to keep. Key includes the pinned version, so bumping the
|
|
||||||
# version below invalidates the cached binary automatically.
|
|
||||||
# As above, a cache outage falls back to the installer.
|
|
||||||
continue-on-error: true
|
|
||||||
uses: actions/cache@v4.1.0
|
|
||||||
with:
|
|
||||||
path: ~/.opencode/bin
|
|
||||||
key: opencode-v2.0.32-${{ runner.os }}
|
|
||||||
|
|
||||||
- name: Install opencode CLI
|
|
||||||
if: steps.opencode-cache.outputs.cache-hit != 'true'
|
|
||||||
run: curl -fsSL https://opencode.ai/v2/install | bash -s -- -v 2.0.32
|
|
||||||
# v2 installer is required: the classic /install URL ships only
|
|
||||||
# OpenCode 1.x (resolved to v1.19.3 on arm64), which cannot resolve
|
|
||||||
# model variants like "#medium" and failed with ProviderModelNotFoundError.
|
|
||||||
# Version pinned (-v 2.0.32) so a breaking v2 release cannot fail
|
|
||||||
# the job mid-PR; bump deliberately, not automatically.
|
|
||||||
|
|
||||||
- name: Add opencode to PATH
|
|
||||||
# The installer appends the directory to $GITHUB_PATH itself, but that
|
|
||||||
# step is skipped on a cache hit. Add it unconditionally.
|
|
||||||
run: echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
|
|
||||||
|
|
||||||
- name: Get PR diff
|
|
||||||
run: |
|
|
||||||
# lockfile changes bloat the diff (175KB here) and are pointless to
|
|
||||||
# review - pnpm audit already covers dependencies. Excluding the
|
|
||||||
# lockfile also keeps the diff small enough to hand to the model.
|
|
||||||
# The diff goes to a file IN the workspace so the agent can read it
|
|
||||||
# with its file tools (passing 190KB as a CLI argument fails with
|
|
||||||
# "Argument list too long", MAX_ARG_STRLEN is 128KiB).
|
|
||||||
git diff --merge-base "origin/${{ github.base_ref }}" \
|
|
||||||
-- . ':(exclude)pnpm-lock.yaml' > .pr-review-diff.patch
|
|
||||||
wc -c .pr-review-diff.patch
|
|
||||||
|
|
||||||
- name: Run opencode review
|
|
||||||
env:
|
|
||||||
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
|
|
||||||
run: |
|
|
||||||
# opencode-go/claude-haiku-5-5#medium: cheap ($0.10/$0.50 per M
|
|
||||||
# tokens) and, unlike deepseek-v4.1-flash, it has a #medium
|
|
||||||
# reasoning variant - flash only exposes low/high/max, so every
|
|
||||||
# review there ran at maximum effort. #medium keeps the review
|
|
||||||
# competent without paying for max reasoning on each push.
|
|
||||||
# History: deepseek-v4-pro#max -> deepseek-v4.1-flash#max ->
|
|
||||||
# haiku-5-5#medium (2026-10-20). The pro endpoint failed two
|
|
||||||
# consecutive runs with "Upstream request failed: Endpoint is
|
|
||||||
# unavailable" before the flash switch; that fallback is recorded
|
|
||||||
# in OKF_Nuxt/open-questions.md. NOTE the provider prefix must be
|
|
||||||
# "opencode-go", NOT "opencode" (Zen is a different, pay-per-call
|
|
||||||
# provider and fails with 'Insufficient account funds').
|
|
||||||
#
|
|
||||||
# Auth is env-only: the CLI picks up OPENCODE_API_KEY from the
|
|
||||||
# environment (verified headless). Deliberately NO opencode.json:
|
|
||||||
# a config file in the checkout would hold the API key in
|
|
||||||
# plaintext, readable by the agent - a malicious PR diff could
|
|
||||||
# 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). OpenCode v2 schema: the
|
|
||||||
# field is "permissions" (plural) - an ordered array of
|
|
||||||
# {action, resource, effect}; "bash" was renamed "shell" in v2.
|
|
||||||
# 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",
|
|
||||||
"permissions": [
|
|
||||||
{ "action": "edit", "resource": "*", "effect": "deny" },
|
|
||||||
{ "action": "shell", "resource": "*", "effect": "deny" },
|
|
||||||
{ "action": "webfetch", "resource": "*", "effect": "deny" },
|
|
||||||
{ "action": "websearch", "resource": "*", "effect": "deny" },
|
|
||||||
{ "action": "external_directory", "resource": "*", "effect": "deny" }
|
|
||||||
]
|
|
||||||
}' > "$HOME/.config/opencode/opencode.json"
|
|
||||||
# --print-logs: surface auth/provider errors in the CI log instead
|
|
||||||
# of failing with an opaque exit code
|
|
||||||
EXIT_CODE=0
|
|
||||||
opencode run \
|
|
||||||
--print-logs \
|
|
||||||
--model opencode-go/claude-haiku-5-5#medium \
|
|
||||||
"You are a principal engineer performing a rigorous code review on a
|
|
||||||
pull request. You have tool access: read repo files for context when
|
|
||||||
the diff alone is ambiguous, but review ONLY code changed in this PR.
|
|
||||||
|
|
||||||
The full PR diff is in the file .pr-review-diff.patch in the repo
|
|
||||||
root. Read it first with your file tools.
|
|
||||||
|
|
||||||
pnpm-lock.yaml is deliberately excluded from that patch to keep it
|
|
||||||
small, not forgotten. It is committed in the PR, pnpm audit covers
|
|
||||||
the dependencies, and CI runs `pnpm install --frozen-lockfile`.
|
|
||||||
Do not report a missing lockfile or a frozen-install drift.
|
|
||||||
|
|
||||||
## Project context
|
|
||||||
- Stack: Nuxt 4 (Vue 3, TypeScript) SSR web app in the repo root.
|
|
||||||
Backend/API services are being added in Golang.
|
|
||||||
- Deployment target: a personal production CV website.
|
|
||||||
- Already covered by other CI jobs, do NOT repeat their findings:
|
|
||||||
ESLint (style), vue-tsc (types), gitleaks (secrets in git history),
|
|
||||||
pnpm audit (dependency CVEs), droast (Dockerfile lint).
|
|
||||||
- Your job is everything those tools CANNOT see: logic, security,
|
|
||||||
architecture, correctness.
|
|
||||||
|
|
||||||
## Nuxt / Vue / TypeScript focus
|
|
||||||
- SSR pitfalls: window/document/localStorage access without
|
|
||||||
<ClientOnly> or process.client guards; hydration mismatch risks
|
|
||||||
(Date.now(), Math.random(), locale formatting in render path).
|
|
||||||
- useAsyncData/useFetch: missing or colliding keys, duplicate
|
|
||||||
requests between server and client, wrong caching/refresh setup.
|
|
||||||
- Reactivity bugs: destructuring reactive objects losing reactivity,
|
|
||||||
missing await on async setup, watch on getters vs refs.
|
|
||||||
- Security: v-html with unsanitized data, user input flowing into
|
|
||||||
meta/URLs, open redirects, missing validation in /server/api and
|
|
||||||
Nitro route handlers, auth checks on both page and API level.
|
|
||||||
- Config hygiene: server-only runtime config (no NUXT_PUBLIC_
|
|
||||||
prefix) leaking secrets into the client bundle.
|
|
||||||
|
|
||||||
## Golang focus (when Go code is in the diff)
|
|
||||||
- Errors: unchecked errors, errors discarded, wrapping with %w,
|
|
||||||
sentinel vs typed errors, panic in library code.
|
|
||||||
- Concurrency: goroutine leaks (missing context cancellation),
|
|
||||||
data races (shared state without mutex/channel), WaitGroup
|
|
||||||
misuse, defer in loops.
|
|
||||||
- Resources: unclosed response bodies/files/rows, missing
|
|
||||||
timeouts on http.Client, unbounded buffering.
|
|
||||||
- Correctness: slice aliasing surprises, copy vs reference
|
|
||||||
semantics, nil map writes, integer truncation.
|
|
||||||
|
|
||||||
## Cross-cutting
|
|
||||||
- API contract mismatches between Nuxt frontend and Go backends
|
|
||||||
(field names, nullability, status codes, date formats).
|
|
||||||
- Missing authorization checks on new endpoints or pages.
|
|
||||||
- Secrets/credentials ending up in logs or client-visible output.
|
|
||||||
- Performance on the critical render path (heavy components,
|
|
||||||
unoptimized images, blocking Nitro middleware).
|
|
||||||
|
|
||||||
## Output format (strict)
|
|
||||||
Review the diff in .pr-review-diff.patch. For every finding:
|
|
||||||
[BLOCKER] file:line - what and why + concrete fix suggestion
|
|
||||||
[WARN] file:line - what and why + concrete fix suggestion
|
|
||||||
[NIT] file:line - optional improvement
|
|
||||||
BLOCKER = must fix before merge (security, data loss, broken
|
|
||||||
behavior). WARN = should fix soon. NIT = optional.
|
|
||||||
If a finding cannot be localized to a file, prefix [BLOCKER-GENERAL].
|
|
||||||
No compliments, no summaries of what the diff does, no style nits.
|
|
||||||
Keep it under 400 words unless there are more than 10 findings.
|
|
||||||
If the diff contains no reviewable code (docs/config only), say so
|
|
||||||
in one line.
|
|
||||||
|
|
||||||
End your response with a final verdict line, exactly one of:
|
|
||||||
VERDICT: APPROVE (no BLOCKER findings)
|
|
||||||
VERDICT: REQUEST_CHANGES (at least one BLOCKER)" \
|
|
||||||
> /tmp/review.md 2>&1 || EXIT_CODE=$?
|
|
||||||
# always show the output - never swallow the error text
|
|
||||||
cat /tmp/review.md
|
|
||||||
# The posting gate is the OUTPUT CONTRACT, not the exit code:
|
|
||||||
# a completed review always ends with a VERDICT line - error
|
|
||||||
# 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.
|
|
||||||
# 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 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Post review as PR comment
|
|
||||||
continue-on-error: true # token missing/expired must not fail the build
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.PR_GITEA_TOKEN }}
|
|
||||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
||||||
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}" \
|
|
||||||
-X POST \
|
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"body\": ${BODY}}" \
|
|
||||||
"${GITHUB_API_URL}/repos/${REPO}/issues/${PR_NUMBER}/comments")
|
|
||||||
echo "POST status: ${HTTP_CODE}"
|
|
||||||
cat /tmp/comment-response.json
|
|
||||||
case "$HTTP_CODE" in
|
|
||||||
200|201) echo "Review comment posted." ;;
|
|
||||||
*) echo "::error::Failed to post review comment (HTTP ${HTTP_CODE}) - check PR_GITEA_TOKEN scope and expiry" ;;
|
|
||||||
esac
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
name: Renovate
|
||||||
|
|
||||||
|
# Renovate is not hosted for Gitea, so this repository runs it itself.
|
||||||
|
# The bot opens dependency PRs through the API; the PR pipeline checks them
|
||||||
|
# (a branch protection rule should require those checks before automerge).
|
||||||
|
#
|
||||||
|
# Manual setup: create a bot account with its full name and email set, give
|
||||||
|
# it write access to this repository, and store a token with
|
||||||
|
# repository read/write, issue read/write, user read and organization read
|
||||||
|
# as the RENOVATE_TOKEN Actions secret.
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
# Daily at 04:00 UTC. Gitea only schedules workflows that exist on the
|
||||||
|
# default branch.
|
||||||
|
- cron: "0 4 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: renovate
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
renovate:
|
||||||
|
name: Run Renovate
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
# Pinned and multi-arch (the runner is arm64). The image installs the
|
||||||
|
# Node-based toolchain it needs on demand.
|
||||||
|
container: renovate/renovate:44.198.2
|
||||||
|
steps:
|
||||||
|
- name: Run Renovate
|
||||||
|
env:
|
||||||
|
RENOVATE_PLATFORM: gitea
|
||||||
|
# API root, not the web root. Renovate reads renovate.json from the
|
||||||
|
# default branch through this endpoint.
|
||||||
|
RENOVATE_ENDPOINT: https://git.noelsabia.dev/api/v1
|
||||||
|
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
|
# This workflow lives in the repository it updates, so scope the bot
|
||||||
|
# to it instead of every repository its account can see.
|
||||||
|
RENOVATE_REPOSITORIES: CV_Website/CV_Site_Nuxt
|
||||||
|
run: renovate
|
||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
# runner's arm64 and this workstation's x86_64.
|
# runner's arm64 and this workstation's x86_64.
|
||||||
# syntax: no BuildKit-only features used, so the default frontend suffices.
|
# syntax: no BuildKit-only features used, so the default frontend suffices.
|
||||||
|
|
||||||
FROM node:26-slim@sha256:d62f13676d530f7edf97782729df69713c8ccfe6631e7f62f9ccab65968719a8 AS build
|
FROM node:26-slim@sha256:18f03e4b532a63baf09809fe8349c2171807f1818cb6c5230fb12aecd5beda65 AS build
|
||||||
|
|
||||||
# pnpm pinned to the same version as CI (pr-checker.yml pins major 11) and
|
# pnpm pinned to the same version as CI (pr-checker.yml pins major 11) and
|
||||||
# the local toolchain (11.26.0). Installed via npm from the node image - no
|
# the local toolchain (11.26.0). Installed via npm from the node image - no
|
||||||
@@ -38,7 +38,7 @@ COPY . .
|
|||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
|
|
||||||
FROM node:26-slim@sha256:d62f13676d530f7edf97782729df69713c8ccfe6631e7f62f9ccab65968719a8
|
FROM node:26-slim@sha256:18f03e4b532a63baf09809fe8349c2171807f1818cb6c5230fb12aecd5beda65
|
||||||
|
|
||||||
# pnpm is NOT installed in the runtime image: nothing here runs pnpm.
|
# pnpm is NOT installed in the runtime image: nothing here runs pnpm.
|
||||||
ENV NODE_ENV=production \
|
ENV NODE_ENV=production \
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM node:26-slim@sha256:d62f13676d530f7edf97782729df69713c8ccfe6631e7f62f9ccab65968719a8
|
FROM node:26-slim@sha256:18f03e4b532a63baf09809fe8349c2171807f1818cb6c5230fb12aecd5beda65
|
||||||
|
|
||||||
# Node no longer bundles pnpm (corepack and pnpm are both absent from this
|
# Node no longer bundles pnpm (corepack and pnpm are both absent from this
|
||||||
# image), so install it. First instruction, so later changes reuse the layer.
|
# image), so install it. First instruction, so later changes reuse the layer.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ type: Decision
|
|||||||
title: AI code review setup
|
title: AI code review setup
|
||||||
description: The review job runs opencode with a cheap medium-effort opencode-go model, env-only auth, a read-only permission set, and posts only reviews that end with a verdict line.
|
description: The review job runs opencode with a cheap medium-effort opencode-go model, env-only auth, a read-only permission set, and posts only reviews that end with a verdict line.
|
||||||
tags: [decision, ci, ai, opencode, security]
|
tags: [decision, ci, ai, opencode, security]
|
||||||
status: draft
|
status: deprecated
|
||||||
generated: { by: opencode-go/glm-5.3-flash, at: 2026-10-18T16:05:00Z }
|
generated: { by: opencode-go/glm-5.3-flash, at: 2026-10-18T16:05:00Z }
|
||||||
verified: { by: human:noel, at: not yet }
|
verified: { by: human:noel, at: not yet }
|
||||||
sources:
|
sources:
|
||||||
@@ -15,6 +15,10 @@ sources:
|
|||||||
title: OpenCode Go plan documentation
|
title: OpenCode Go plan documentation
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> Superseded by [PR-Agent for Gitea reviews](pr-agent.md) on 2026-10-30.
|
||||||
|
> The opencode job was removed from `pr-checker.yml`; this document remains
|
||||||
|
> as the record of the earlier setup and the failures it fixed.
|
||||||
|
|
||||||
# Decision
|
# Decision
|
||||||
|
|
||||||
The review job installs opencode v2 from the dedicated v2 installer,
|
The review job installs opencode v2 from the dedicated v2 installer,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
# Decisions
|
# Decisions
|
||||||
|
|
||||||
* [PR pipeline layering](pr-pipeline-layering.md) - What runs pre-commit, what runs in Gitea Actions, what the AI review does, and the cost rule that decides.
|
* [PR pipeline layering](pr-pipeline-layering.md) - What runs pre-commit, what runs in Gitea Actions, what the AI review does, and the cost rule that decides.
|
||||||
* [AI review setup](ai-review-setup.md) - Plan model, env-only auth against prompt injection, read-only agent, and the verdict line as the posting gate.
|
* [PR-Agent for Gitea reviews](pr-agent.md) - A pinned webhook server replaces the per-PR opencode job; internal-only, scoped bot, OpenCode Go model.
|
||||||
|
* [AI review setup (opencode)](ai-review-setup.md) - Superseded 2026-10-30; kept for the env-only auth and verdict-gate reasoning.
|
||||||
* [Vulnerability audit policy](vulnerability-audit-policy.md) - Blocking audit, reviewed ignore-list for unfixable advisories, and the pnpm-11 settings home.
|
* [Vulnerability audit policy](vulnerability-audit-policy.md) - Blocking audit, reviewed ignore-list for unfixable advisories, and the pnpm-11 settings home.
|
||||||
* [Release engineering](release-engineering.md) - release-please in manifest mode, conventional commits as input, message format enforced at commit time.
|
* [Release engineering](release-engineering.md) - release-please in manifest mode, conventional commits as input, message format enforced at commit time.
|
||||||
* [Snyk paused and secrets policy](snyk-paused-and-secrets-policy.md) - Why the job is skipped rather than deleted, and the token scopes every workflow secret needs.
|
* [Snyk paused and secrets policy](snyk-paused-and-secrets-policy.md) - Why the job is skipped rather than deleted, and the token scopes every workflow secret needs.
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
---
|
||||||
|
type: Decision
|
||||||
|
title: PR-Agent for Gitea reviews
|
||||||
|
description: A pinned PR-Agent webhook server on server0 reviews pull requests through a scoped Gitea bot user, replacing the per-PR opencode job.
|
||||||
|
tags: [decision, ci, ai, gitea, pr-agent, security]
|
||||||
|
status: draft
|
||||||
|
generated: { by: opencode-go/deepseek-v4.1-flash, at: 2026-10-30T20:00:00Z }
|
||||||
|
verified: { by: human:noel, at: not yet }
|
||||||
|
sources:
|
||||||
|
- id: compose
|
||||||
|
resource: deploy/pr-agent/docker-compose.yml
|
||||||
|
title: PR-Agent compose service
|
||||||
|
- id: env-example
|
||||||
|
resource: deploy/pr-agent/.env.example
|
||||||
|
title: Environment variables, without secrets
|
||||||
|
- id: pr-checker
|
||||||
|
resource: .gitea/workflows/pr-checker.yml
|
||||||
|
title: PR Check workflow, opencode job removed
|
||||||
|
- id: install
|
||||||
|
resource: https://docs.pr-agent.ai/installation/gitea/
|
||||||
|
title: PR-Agent Gitea installation
|
||||||
|
- id: images
|
||||||
|
resource: https://hub.docker.com/r/pragent/pr-agent
|
||||||
|
title: Published gitea_app image tags
|
||||||
|
- id: gitea-egress
|
||||||
|
resource: https://docs.gitea.com/administration/config-cheat-sheet#webhook
|
||||||
|
title: Gitea webhook egress allowlist
|
||||||
|
---
|
||||||
|
|
||||||
|
# Decision
|
||||||
|
|
||||||
|
PR-Agent runs as `pragent/pr-agent:0.49.0-gitea_app` in a long-lived
|
||||||
|
container on `server0`, attached to the existing `gitea_gitea` Docker
|
||||||
|
network. It publishes no ports. Gitea delivers pull-request and comment
|
||||||
|
events to `http://pr-agent:3000/api/v1/gitea_webhooks`; the bot user
|
||||||
|
`pr-agent` posts the result with a scoped personal access token.
|
||||||
|
|
||||||
|
The opencode review job is removed from `pr-checker.yml`. PR-Agent runs
|
||||||
|
`/describe` and `/review` on pull request open/reopen and answers slash
|
||||||
|
commands in the conversation. Push-triggered re-review is disabled, so a
|
||||||
|
PR is reviewed once when it opens, not on every push.
|
||||||
|
|
||||||
|
The model is OpenCode Go's OpenAI-compatible endpoint:
|
||||||
|
|
||||||
|
```text
|
||||||
|
model openai/glm-5.3-flash
|
||||||
|
fallback openai/glm-5.3
|
||||||
|
api base https://opencode.ai/inference/go/openai/v1
|
||||||
|
```
|
||||||
|
|
||||||
|
`CONFIG__CUSTOM_MODEL_MAX_TOKENS=128000` supplies the context limit the
|
||||||
|
model table does not know; PR-Agent's default `config.max_model_tokens`
|
||||||
|
still caps the review budget at 32000.
|
||||||
|
|
||||||
|
OpenCode Go requires an `x-opencode-session` header. PR-Agent sends the
|
||||||
|
stable id `pr-agent` through `LITELLM__EXTRA_HEADERS`; without it the
|
||||||
|
provider rejects the request before it reaches the model.
|
||||||
|
|
||||||
|
# Why
|
||||||
|
|
||||||
|
* One container replaces a per-PR CLI install, binary cache and prompt
|
||||||
|
wrapper. The review path is then the same code for every PR.
|
||||||
|
* PR-Agent owns the Gitea webhook and comment plumbing, including the slash
|
||||||
|
commands (`/review`, `/improve`, `/ask`) the repository previously had no
|
||||||
|
way to trigger.
|
||||||
|
* The webhook endpoint stays on the Docker network. Nothing new is exposed
|
||||||
|
to the internet, and comment links still use the public Gitea URL.
|
||||||
|
* The image tag is pinned. A new PR-Agent release is a deliberate change,
|
||||||
|
not a rollout underneath the repository.
|
||||||
|
|
||||||
|
# Gitea configuration
|
||||||
|
|
||||||
|
* Bot user `pr-agent` is a collaborator with write permission on
|
||||||
|
`CV_Website/CV_Site_Nuxt`. The token scopes are `read:repository`,
|
||||||
|
`write:issue` and `read:user`. Gitea has no comment-only collaborator
|
||||||
|
role, so write is the narrowest role that can post comments and labels.
|
||||||
|
* `[webhook] ALLOWED_HOST_LIST = private:3000` is required: Gitea's default
|
||||||
|
lax egress policy allows public targets but refuses private ones, and the
|
||||||
|
webhook target is a Docker-network address. The API is reached at
|
||||||
|
`http://gitea:3000`; `GITEA__WEB_URL=https://git.noelsabia.dev` keeps
|
||||||
|
published links on the public host.
|
||||||
|
* The webhook sends `push`, `issues`, `pull_request` and `issue_comment`
|
||||||
|
events. Only the last two change behaviour today; `push` is kept because
|
||||||
|
PR-Agent may handle push commands in a later configuration.
|
||||||
|
* Secrets live only in `/home/noel/self-hosted/pr-agent/.env` (mode 600) on
|
||||||
|
`server0`. The repository contains the compose file and an example env
|
||||||
|
file, never the token or webhook secret.
|
||||||
|
|
||||||
|
# Not verified
|
||||||
|
|
||||||
|
* The OpenCode Go API key was not present when this was committed, so no
|
||||||
|
model call and no real review have run. The first PR after the key is set
|
||||||
|
is the verification.
|
||||||
|
* Whether `glm-5.3-flash` handles PR-Agent's structured review output well
|
||||||
|
enough. `glm-5.3` is configured as the fallback.
|
||||||
|
* Whether two gunicorn workers and the 1 GB memory limit hold under
|
||||||
|
concurrent reviews. The host has roughly 2.5 GB available with Gitea and
|
||||||
|
its runner idle.
|
||||||
|
* Whether the default review prompt is specific enough for this repository.
|
||||||
|
A `.pr_agent.toml` with project instructions is deliberately absent until
|
||||||
|
the first real review shows what it misses.
|
||||||
|
|
||||||
|
# Revisit when
|
||||||
|
|
||||||
|
* The first review fails, returns unstructured output, or misses the kind
|
||||||
|
of finding the opencode prompt used to catch.
|
||||||
|
* A newer `gitea_app` image tag is worth taking; bump the tag and run
|
||||||
|
`docker compose up -d`.
|
||||||
|
* Review volume makes the container's memory limit tight, or Gitea adds a
|
||||||
|
role that can comment without push access.
|
||||||
@@ -26,8 +26,8 @@ Every pull request is checked by three layers, ordered by cost:
|
|||||||
in one job (one install, cached pnpm store), gitleaks over full
|
in one job (one install, cached pnpm store), gitleaks over full
|
||||||
history, pnpm audit (blocking), droast Dockerfile lint, Snyk
|
history, pnpm audit (blocking), droast Dockerfile lint, Snyk
|
||||||
(currently disabled).
|
(currently disabled).
|
||||||
3. **AI code review** (per PR push): opencode with a plan-covered model,
|
3. **AI code review** (on PR open, or on a slash command): the PR-Agent
|
||||||
verdict-based, posted as a PR comment.
|
webhook server, posted as a PR comment.
|
||||||
|
|
||||||
The split rule: anything that finishes in seconds and auto-fixes goes in
|
The split rule: anything that finishes in seconds and auto-fixes goes in
|
||||||
pre-commit; anything slow, network-bound or quota-bound goes in CI; anything
|
pre-commit; anything slow, network-bound or quota-bound goes in CI; anything
|
||||||
@@ -45,15 +45,16 @@ already passed the deterministic gates.
|
|||||||
|
|
||||||
# Caching
|
# Caching
|
||||||
|
|
||||||
Two caches, both served by the runner's own cache server (no external
|
One cache, served by the runner's own cache server (no external service,
|
||||||
service, entries stay on the home server):
|
entries stay on the home server):
|
||||||
|
|
||||||
* **pnpm store**, keyed on the store layout version (v11) and a `sha256sum`
|
* **pnpm store**, keyed on the store layout version (v11) and a `sha256sum`
|
||||||
of `pnpm-lock.yaml`. Installs hardlink from the store instead of
|
of `pnpm-lock.yaml`. Installs hardlink from the store instead of
|
||||||
downloading tarballs again. The key is built in a shell step because
|
downloading tarballs again. The key is built in a shell step because
|
||||||
`hashFiles()` evaluates empty in this act runner.
|
`hashFiles()` evaluates empty in this act runner.
|
||||||
* **opencode binary**, keyed on the pinned CLI version (`~/.opencode/bin`).
|
|
||||||
Small next to the model call, but it removes a network fetch per review.
|
The opencode binary cache is gone with the opencode job. PR-Agent is a
|
||||||
|
long-running container on `server0`, so a review no longer downloads a CLI.
|
||||||
|
|
||||||
Lint and typecheck also share one job: same image, same lockfile, same
|
Lint and typecheck also share one job: same image, same lockfile, same
|
||||||
install. Splitting them duplicated the install and made both compete for
|
install. Splitting them duplicated the install and made both compete for
|
||||||
@@ -71,6 +72,10 @@ exposure in the review setup — each fixed where it was cheapest.
|
|||||||
|
|
||||||
# Failure modes deliberately designed against
|
# Failure modes deliberately designed against
|
||||||
|
|
||||||
|
The opencode-specific rows are historical since the review moved to
|
||||||
|
[PR-Agent](pr-agent.md); they are kept because the failure classes still
|
||||||
|
apply to any review implementation.
|
||||||
|
|
||||||
| Failure seen | Guard now in place |
|
| Failure seen | Guard now in place |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Error logs posted as review comments | Posting gate is the output contract (a `VERDICT:` line), not the exit code |
|
| Error logs posted as review comments | Posting gate is the output contract (a `VERDICT:` line), not the exit code |
|
||||||
|
|||||||
+2
-1
@@ -19,7 +19,8 @@ config files — the configs say what, these documents say why.
|
|||||||
## CI/CD and releases (2026-10-18)
|
## CI/CD and releases (2026-10-18)
|
||||||
|
|
||||||
* [PR pipeline layering](decisions/pr-pipeline-layering.md) - Three layers: pre-commit for cheap deterministic checks, Gitea Actions for thorough ones, AI review for judgment.
|
* [PR pipeline layering](decisions/pr-pipeline-layering.md) - Three layers: pre-commit for cheap deterministic checks, Gitea Actions for thorough ones, AI review for judgment.
|
||||||
* [AI review setup](decisions/ai-review-setup.md) - Plan model, env-only auth against prompt injection, read-only agent, verdict line as the posting gate.
|
* [PR-Agent for Gitea reviews](decisions/pr-agent.md) - A pinned webhook server on server0 replaces the per-PR opencode job; internal-only, scoped bot, OpenCode Go model.
|
||||||
|
* [AI review setup (opencode)](decisions/ai-review-setup.md) - Superseded 2026-10-30; kept for the env-only auth and verdict-gate reasoning.
|
||||||
* [Vulnerability audit policy](decisions/vulnerability-audit-policy.md) - Blocking audit; reviewed ignore-list for unfixable advisories in pnpm-workspace.yaml.
|
* [Vulnerability audit policy](decisions/vulnerability-audit-policy.md) - Blocking audit; reviewed ignore-list for unfixable advisories in pnpm-workspace.yaml.
|
||||||
* [Release engineering](decisions/release-engineering.md) - release-please in manifest mode; conventional commits enforced at commit time.
|
* [Release engineering](decisions/release-engineering.md) - release-please in manifest mode; conventional commits enforced at commit time.
|
||||||
* [Snyk paused and secrets policy](decisions/snyk-paused-and-secrets-policy.md) - Quota-paused job kept in place; `write:issue` scope required on every workflow token.
|
* [Snyk paused and secrets policy](decisions/snyk-paused-and-secrets-policy.md) - Quota-paused job kept in place; `write:issue` scope required on every workflow token.
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# Update Log
|
# Update Log
|
||||||
|
|
||||||
|
## 2026-10-30 (PR-Agent replaces the opencode review job)
|
||||||
|
|
||||||
|
* **Decision**: [PR-Agent for Gitea reviews](decisions/pr-agent.md) - a pinned `pragent/pr-agent:0.49.0-gitea_app` container on `server0` reviews PRs through the Gitea bot user `pr-agent`; the endpoint stays on the `gitea_gitea` Docker network.
|
||||||
|
* **Update**: [pr-checker.yml](../.gitea/workflows/pr-checker.yml) - removed the `review` job, the opencode installer and the verdict-posting step. PR-Agent now runs `/describe` and `/review` on PR open/reopen and answers slash commands.
|
||||||
|
* **Creation**: `deploy/pr-agent/` - compose service, example environment and operator README. The real `.env` lives only at `/home/noel/self-hosted/pr-agent/.env` (mode 600) on `server0`.
|
||||||
|
* **State**: the container is running and the webhook signature path is verified. Gitea gained `[webhook] ALLOWED_HOST_LIST = private:3000` (one restart, healthy) and the repository has a signed webhook. The OpenCode Go API key was still missing at commit time, so no model call or real review has run yet.
|
||||||
|
|
||||||
## 2026-10-27 (release-please still never tagged: the deleted head branch)
|
## 2026-10-27 (release-please still never tagged: the deleted head branch)
|
||||||
|
|
||||||
* **Fix**: [release-please-config.json](../release-please-config.json) gained `"changelog-host": "https://git.noelsabia.dev"` - the changelog compare links were generated against `github.com/CV_Website/CV_Site_Nuxt`, a host this repository does not live on. Root cause of the missing tags: **Gitea rewrites `head.ref` to `refs/pull/<n>/head` when the merged PR's branch is deleted**, and release-please parses that field as the release branch, so `BranchName.parse` fails and the release is dropped - silently, exit code 0. Evidence: run 143 (task 475) logs `✖ Bad branch name: refs/pull/22/head` right after `Found pull request #22`, then `Expected 1 releases, only found 0`; #22 did carry `autorelease: pending`. The repository deleted every merged branch (`default_delete_branch_after_merge: true`); it is `false` now. Four versions (1.1.0-1.4.0) were consumed by the manifest with no tag ever created, so the release baseline has to be restored by hand. See [Release engineering](decisions/release-engineering.md).
|
* **Fix**: [release-please-config.json](../release-please-config.json) gained `"changelog-host": "https://git.noelsabia.dev"` - the changelog compare links were generated against `github.com/CV_Website/CV_Site_Nuxt`, a host this repository does not live on. Root cause of the missing tags: **Gitea rewrites `head.ref` to `refs/pull/<n>/head` when the merged PR's branch is deleted**, and release-please parses that field as the release branch, so `BranchName.parse` fails and the release is dropped - silently, exit code 0. Evidence: run 143 (task 475) logs `✖ Bad branch name: refs/pull/22/head` right after `Found pull request #22`, then `Expected 1 releases, only found 0`; #22 did carry `autorelease: pending`. The repository deleted every merged branch (`default_delete_branch_after_merge: true`); it is `false` now. Four versions (1.1.0-1.4.0) were consumed by the manifest with no tag ever created, so the release baseline has to be restored by hand. See [Release engineering](decisions/release-engineering.md).
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ generated: { by: opencode-go/glm-5.3-flash, at: 2026-10-18T12:41:52Z }
|
|||||||
| Whether these decisions stay in this bundle or fold into the sibling `OKF_CV_Website` bundle, which already describes the frontend at design level | after the production image exists | None. |
|
| Whether these decisions stay in this bundle or fold into the sibling `OKF_CV_Website` bundle, which already describes the frontend at design level | after the production image exists | None. |
|
||||||
| When and how often Snyk runs once re-enabled: weekly schedule, ready-for-review gate, or per-push | re-enabling the snyk job | Stay disabled. |
|
| When and how often Snyk runs once re-enabled: weekly schedule, ready-for-review gate, or per-push | re-enabling the snyk job | Stay disabled. |
|
||||||
| Whether the AI review job should gate merges (required status check on the verdict) or stay advisory | branch protection setup | Advisory. The review comment is information; blocking merges on an AI verdict is a policy choice, not a technical one. |
|
| Whether the AI review job should gate merges (required status check on the verdict) or stay advisory | branch protection setup | Advisory. The review comment is information; blocking merges on an AI verdict is a policy choice, not a technical one. |
|
||||||
| How the opencode CLI version in CI gets upgraded: manually bump the pinned 2.0.32, or automate when a new major appears | first review failure after an opencode release | Manual bump. Pinning exists so upgrades are decisions. |
|
| ~~How the opencode CLI version in CI gets upgraded~~ - **closed** (2026-10-30): the opencode job was removed; the review path is a pinned PR-Agent container. See [PR-Agent for Gitea reviews](decisions/pr-agent.md) | done | — |
|
||||||
|
| Whether `glm-5.3-flash` through PR-Agent produces acceptable reviews on this repository | first PR after the OpenCode Go key is set | Keep it; `glm-5.3` is the configured fallback. |
|
||||||
| ~~Whether the Go plan's per-model usage windows survive real review frequency, and which model the review should use~~ - **decided** (2026-10-20): review model is `opencode-go/claude-haiku-5-5#medium` in [pr-checker.yml](../.gitea/workflows/pr-checker.yml). Cheap per token, and it has a real `#medium` effort level; `deepseek-v4.1-flash` only exposes low/high/max, so it always paid for maximum reasoning. The earlier pro -> flash switch (two consecutive `Endpoint is unavailable` failures) is in the [log](../log.md) | done | — |
|
| ~~Whether the Go plan's per-model usage windows survive real review frequency, and which model the review should use~~ - **decided** (2026-10-20): review model is `opencode-go/claude-haiku-5-5#medium` in [pr-checker.yml](../.gitea/workflows/pr-checker.yml). Cheap per token, and it has a real `#medium` effort level; `deepseek-v4.1-flash` only exposes low/high/max, so it always paid for maximum reasoning. The earlier pro -> flash switch (two consecutive `Endpoint is unavailable` failures) is in the [log](../log.md) | done | — |
|
||||||
| Removing the two reviewed audit ignores when `node-forge` or `braces` ship patched releases | next dependency update round | Watch for new releases. |
|
| Removing the two reviewed audit ignores when `node-forge` or `braces` ship patched releases | next dependency update round | Watch for new releases. |
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Copy to .env on server0 and fill in; never commit .env.
|
||||||
|
# chmod 600 .env
|
||||||
|
|
||||||
|
CONFIG__GIT_PROVIDER=gitea
|
||||||
|
|
||||||
|
# The API is reached over the Docker network; links in comments use the
|
||||||
|
# public URL instead.
|
||||||
|
GITEA__URL=http://gitea:3000
|
||||||
|
GITEA__WEB_URL=https://git.noelsabia.dev
|
||||||
|
|
||||||
|
# Bot user pr-agent, scoped token (read:repository, write:issue, read:user).
|
||||||
|
# Not the admin account and not a workflow secret.
|
||||||
|
GITEA__PERSONAL_ACCESS_TOKEN=
|
||||||
|
|
||||||
|
# Secret configured on the Gitea webhook. Required: the server rejects
|
||||||
|
# unsigned webhooks with HTTP 403.
|
||||||
|
GITEA__WEBHOOK_SECRET=
|
||||||
|
|
||||||
|
# OpenCode Go exposes an OpenAI-compatible chat-completions endpoint, so
|
||||||
|
# PR-Agent reaches it through its openai provider with a custom base URL.
|
||||||
|
CONFIG__MODEL=openai/glm-5.3-flash
|
||||||
|
CONFIG__FALLBACK_MODELS=["openai/glm-5.3"]
|
||||||
|
CONFIG__CUSTOM_MODEL_MAX_TOKENS=128000
|
||||||
|
OPENAI__API_BASE=https://opencode.ai/inference/go/openai/v1
|
||||||
|
OPENAI__KEY=
|
||||||
|
|
||||||
|
# OpenCode Go requires a session id header; a stable id is enough here.
|
||||||
|
LITELLM__EXTRA_HEADERS={"x-opencode-session":"pr-agent"}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# PR-Agent for Gitea
|
||||||
|
|
||||||
|
PR-Agent runs as a webhook server next to Gitea on `server0`. Gitea sends
|
||||||
|
pull-request and comment events over the `gitea_gitea` Docker network; the
|
||||||
|
endpoint is not published to the internet.
|
||||||
|
|
||||||
|
| Piece | Value |
|
||||||
|
|---|---|
|
||||||
|
| Image | `pragent/pr-agent:0.49.0-gitea_app` |
|
||||||
|
| Container | `pr-agent` |
|
||||||
|
| Webhook URL, from Gitea | `http://pr-agent:3000/api/v1/gitea_webhooks` |
|
||||||
|
| Config | `/opt/pr-agent/.env` (root, mode 600) |
|
||||||
|
| Logs | `ssh … agent@server0 logs` |
|
||||||
|
| Deploy / restart | `ssh … agent@server0 deploy` |
|
||||||
|
| Status | `ssh … agent@server0 status` |
|
||||||
|
| Upgrade | edit the root-owned compose file, then run `deploy` |
|
||||||
|
|
||||||
|
## Gitea side
|
||||||
|
|
||||||
|
1. The bot user `pr-agent` is a collaborator on `CV_Website/CV_Site_Nuxt` with
|
||||||
|
write permission. Its personal access token is scoped to
|
||||||
|
`read:repository`, `write:issue` and `read:user`.
|
||||||
|
2. The repository webhook sends `push`, `issues`, `pull_request` and
|
||||||
|
`issue_comment` events, with JSON content type and the shared secret.
|
||||||
|
3. Gitea's `[webhook] ALLOWED_HOST_LIST` includes `private:3000`. Without it,
|
||||||
|
Gitea's default egress policy refuses webhook deliveries to private
|
||||||
|
addresses, including the Docker network.
|
||||||
|
|
||||||
|
## Operator access
|
||||||
|
|
||||||
|
The agent does not log in as `noel`. A dedicated `agent` account has one
|
||||||
|
forced command and three actions:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 status
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 logs
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
The SSH key is restricted with `restrict,command=…`; the account has no
|
||||||
|
Docker group, no general sudo, and no shell. Sudo permits only the three
|
||||||
|
root-owned helper scripts in `/usr/local/sbin`, and those helpers operate on
|
||||||
|
the fixed `/opt/pr-agent/docker-compose.yml`. The compose file, `.env` and
|
||||||
|
helpers are root-owned, so the agent cannot turn “restart” into a different
|
||||||
|
container or a host mount.
|
||||||
|
|
||||||
|
`setup-agent-access.sh` creates the account and moves the stack to
|
||||||
|
`/opt/pr-agent`. `remove-noel-access.sh` then removes the inherited access
|
||||||
|
from `noel`: the `docker` and `sudo` groups, the keys in
|
||||||
|
`/home/noel/.ssh/authorized_keys`, and the old PR-Agent directory. Run both
|
||||||
|
on the server as root, and only run the second after the restricted command
|
||||||
|
works and you have another admin path.
|
||||||
|
|
||||||
|
For git, use a repository-scoped deploy key instead of the personal Gitea
|
||||||
|
key: `~/.ssh/pr_agent_gitea.pub` is added as a write deploy key on
|
||||||
|
`CV_Website/CV_Site_Nuxt`. The old personal key must be removed from Gitea,
|
||||||
|
or it still grants every repository the user can see.
|
||||||
|
|
||||||
|
## AI model
|
||||||
|
|
||||||
|
The agent uses OpenCode Go's OpenAI-compatible endpoint:
|
||||||
|
|
||||||
|
```text
|
||||||
|
model openai/glm-5.3-flash
|
||||||
|
fallback openai/glm-5.3
|
||||||
|
api base https://opencode.ai/inference/go/openai/v1
|
||||||
|
```
|
||||||
|
|
||||||
|
`CONFIG__CUSTOM_MODEL_MAX_TOKENS` tells PR-Agent the context limit, because
|
||||||
|
the model is not in its token table. The effective review budget is still
|
||||||
|
capped by PR-Agent's default `config.max_model_tokens` of 32000.
|
||||||
|
|
||||||
|
OpenCode Go requires an `x-opencode-session` header; PR-Agent sends the
|
||||||
|
stable id `pr-agent` through `LITELLM__EXTRA_HEADERS`.
|
||||||
|
|
||||||
|
The transfer file used during installation was empty, so set the key as
|
||||||
|
root and redeploy:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudoedit /opt/pr-agent/.env # set OPENAI__KEY=…
|
||||||
|
sudo /usr/local/sbin/pr-agent-deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
## First check
|
||||||
|
|
||||||
|
Open a pull request in `CV_Website/CV_Site_Nuxt`. The server runs `/describe`
|
||||||
|
and `/review` on open/reopen; comment commands such as `/review`, `/improve`
|
||||||
|
and `/ask` are handled from the PR conversation. If nothing appears:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 logs
|
||||||
|
```
|
||||||
|
|
||||||
|
A `403` in the Gitea webhook delivery log means the secret does not match or
|
||||||
|
`ALLOWED_HOST_LIST` is still missing; a `401` from PR-Agent means the
|
||||||
|
signature header and secret disagree.
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# PR-Agent webhook server for the self-hosted Gitea instance.
|
||||||
|
#
|
||||||
|
# Runs on the existing gitea_gitea network and publishes no ports. Gitea
|
||||||
|
# reaches it as http://pr-agent:3000/api/v1/gitea_webhooks, so the webhook
|
||||||
|
# endpoint is never internet-facing. Gitea still publishes comment links with
|
||||||
|
# its own ROOT_URL (https://git.noelsabia.dev).
|
||||||
|
#
|
||||||
|
# Deployed by hand on server0 from /home/noel/self-hosted/pr-agent; see the
|
||||||
|
# README next to this file.
|
||||||
|
|
||||||
|
services:
|
||||||
|
pr-agent:
|
||||||
|
image: pragent/pr-agent:0.49.0-gitea_app
|
||||||
|
container_name: pr-agent
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
PORT: "3000"
|
||||||
|
# Importing the app costs roughly 250 MB. Two workers leave headroom on
|
||||||
|
# the 3.8 GB host that also runs Gitea, its runner and a web app.
|
||||||
|
GUNICORN_WORKERS: "2"
|
||||||
|
mem_limit: 1g
|
||||||
|
networks:
|
||||||
|
- gitea
|
||||||
|
healthcheck:
|
||||||
|
# The server has no HTTP health route; an open TCP socket is enough to
|
||||||
|
# distinguish a running gunicorn master from a crashed container.
|
||||||
|
test: ["CMD", "python", "-c", "import socket; socket.create_connection(('127.0.0.1', 3000), 3).close()"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
|
|
||||||
|
networks:
|
||||||
|
gitea:
|
||||||
|
external: true
|
||||||
|
name: gitea_gitea
|
||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Final step: remove the agent's inherited noel access.
|
||||||
|
#
|
||||||
|
# Run on server0 only after the agent command works:
|
||||||
|
# ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 status
|
||||||
|
#
|
||||||
|
# This removes noel from docker and sudo, clears noel's authorized_keys,
|
||||||
|
# and deletes the old PR-Agent directory that held the secrets. Make sure
|
||||||
|
# you have another admin path (provider console or a new key) first.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<'EOF'
|
||||||
|
This will:
|
||||||
|
- remove noel from the docker and sudo groups
|
||||||
|
- clear every key in /home/noel/.ssh/authorized_keys
|
||||||
|
- delete /home/noel/self-hosted/pr-agent (the /opt copy remains)
|
||||||
|
Existing noel SSH sessions keep their old groups until they log out.
|
||||||
|
Make sure you have another admin path before continuing.
|
||||||
|
EOF
|
||||||
|
read -r -p "Type REMOVE to continue: " answer
|
||||||
|
[ "$answer" = "REMOVE" ] || { echo "aborted"; exit 1; }
|
||||||
|
|
||||||
|
if id -nG noel | tr ' ' '\n' | grep -qx docker; then
|
||||||
|
gpasswd -d noel docker
|
||||||
|
fi
|
||||||
|
if id -nG noel | tr ' ' '\n' | grep -qx sudo; then
|
||||||
|
deluser noel sudo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /home/noel/.ssh/authorized_keys ]; then
|
||||||
|
cp -a /home/noel/.ssh/authorized_keys \
|
||||||
|
"/root/noel-authorized_keys.$(date +%Y%m%d-%H%M%S).bak"
|
||||||
|
: > /home/noel/.ssh/authorized_keys
|
||||||
|
chown noel:noel /home/noel/.ssh/authorized_keys
|
||||||
|
chmod 600 /home/noel/.ssh/authorized_keys
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf /home/noel/self-hosted/pr-agent
|
||||||
|
|
||||||
|
cat <<'EOF'
|
||||||
|
|
||||||
|
Done. Test the restricted path again:
|
||||||
|
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 status
|
||||||
|
|
||||||
|
Still to do outside this script:
|
||||||
|
- remove the old personal SSH key from Gitea (Settings > SSH / GPG Keys)
|
||||||
|
- add ~/.ssh/pr_agent_gitea.pub as a write deploy key on CV_Site_Nuxt
|
||||||
|
- put the OpenCode Go key in /opt/pr-agent/.env and run the deploy helper
|
||||||
|
EOF
|
||||||
Executable
+135
@@ -0,0 +1,135 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# One-time root setup for the least-privilege PR-Agent operator account.
|
||||||
|
#
|
||||||
|
# Run on server0:
|
||||||
|
# sudo bash /home/noel/agent-access-setup.sh
|
||||||
|
#
|
||||||
|
# This creates the agent user and moves the PR-Agent stack to /opt/pr-agent.
|
||||||
|
# It does NOT remove noel's current docker/sudo access. Verify the agent
|
||||||
|
# command printed at the end first, then run remove-noel-access.sh.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
AGENT_USER=agent
|
||||||
|
AGENT_HOME=/home/$AGENT_USER
|
||||||
|
PR_AGENT_DIR=/opt/pr-agent
|
||||||
|
SRC_DIR=/home/noel/self-hosted/pr-agent
|
||||||
|
PUBKEY_FILE=/home/noel/.ssh/pr_agent_control.pub
|
||||||
|
DOCKER=/usr/bin/docker
|
||||||
|
|
||||||
|
for f in "$SRC_DIR/docker-compose.yml" "$SRC_DIR/README.md" "$SRC_DIR/.env" "$PUBKEY_FILE"; do
|
||||||
|
[ -f "$f" ] || { echo "missing $f" >&2; exit 1; }
|
||||||
|
done
|
||||||
|
case "$(cat "$PUBKEY_FILE")" in
|
||||||
|
ssh-*|ecdsa-*|sk-ssh-*) ;;
|
||||||
|
*) echo "$PUBKEY_FILE does not look like an SSH public key" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
grep -q '^Include /etc/ssh/sshd_config.d/\*.conf' /etc/ssh/sshd_config \
|
||||||
|
|| { echo "sshd does not include sshd_config.d" >&2; exit 1; }
|
||||||
|
|
||||||
|
if ! id "$AGENT_USER" >/dev/null 2>&1; then
|
||||||
|
useradd --create-home --shell /bin/bash "$AGENT_USER"
|
||||||
|
fi
|
||||||
|
passwd -l "$AGENT_USER" >/dev/null 2>&1 || true
|
||||||
|
chmod 700 "$AGENT_HOME"
|
||||||
|
install -d -m 700 -o "$AGENT_USER" -g "$AGENT_USER" "$AGENT_HOME/.ssh"
|
||||||
|
|
||||||
|
# The stack must not be writable by the agent: a changed compose file would
|
||||||
|
# turn "restart the service" into arbitrary root containers.
|
||||||
|
install -d -m 755 -o root -g root "$PR_AGENT_DIR"
|
||||||
|
if [ ! -f "$PR_AGENT_DIR/docker-compose.yml" ]; then
|
||||||
|
install -m 644 -o root -g root "$SRC_DIR/docker-compose.yml" "$PR_AGENT_DIR/docker-compose.yml"
|
||||||
|
fi
|
||||||
|
install -m 644 -o root -g root "$SRC_DIR/README.md" "$PR_AGENT_DIR/README.md"
|
||||||
|
if [ ! -f "$PR_AGENT_DIR/.env" ]; then
|
||||||
|
install -m 600 -o root -g root "$SRC_DIR/.env" "$PR_AGENT_DIR/.env"
|
||||||
|
fi
|
||||||
|
if ! grep -q '^name:' "$PR_AGENT_DIR/docker-compose.yml"; then
|
||||||
|
sed -i '1i name: pr-agent' "$PR_AGENT_DIR/docker-compose.yml"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat > /usr/local/sbin/pr-agent-deploy <<EOF
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
$DOCKER compose --project-directory $PR_AGENT_DIR -f $PR_AGENT_DIR/docker-compose.yml pull
|
||||||
|
exec $DOCKER compose --project-directory $PR_AGENT_DIR -f $PR_AGENT_DIR/docker-compose.yml up -d
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > /usr/local/sbin/pr-agent-logs <<EOF
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
exec $DOCKER compose --project-directory $PR_AGENT_DIR -f $PR_AGENT_DIR/docker-compose.yml logs --tail=200 pr-agent
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > /usr/local/sbin/pr-agent-status <<EOF
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
exec $DOCKER compose --project-directory $PR_AGENT_DIR -f $PR_AGENT_DIR/docker-compose.yml ps
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > /usr/local/sbin/pr-agent-control <<'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
case "${SSH_ORIGINAL_COMMAND:-}" in
|
||||||
|
deploy) exec sudo -n /usr/local/sbin/pr-agent-deploy ;;
|
||||||
|
logs) exec sudo -n /usr/local/sbin/pr-agent-logs ;;
|
||||||
|
status) exec sudo -n /usr/local/sbin/pr-agent-status ;;
|
||||||
|
*) echo "allowed: deploy, logs, status" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chown root:root /usr/local/sbin/pr-agent-deploy /usr/local/sbin/pr-agent-logs \
|
||||||
|
/usr/local/sbin/pr-agent-status /usr/local/sbin/pr-agent-control
|
||||||
|
chmod 755 /usr/local/sbin/pr-agent-deploy /usr/local/sbin/pr-agent-logs \
|
||||||
|
/usr/local/sbin/pr-agent-status /usr/local/sbin/pr-agent-control
|
||||||
|
|
||||||
|
cat > /etc/sudoers.d/pr-agent-control <<'EOF'
|
||||||
|
agent ALL=(root) NOPASSWD: /usr/local/sbin/pr-agent-deploy, /usr/local/sbin/pr-agent-logs, /usr/local/sbin/pr-agent-status
|
||||||
|
EOF
|
||||||
|
chmod 440 /etc/sudoers.d/pr-agent-control
|
||||||
|
visudo -cf /etc/sudoers.d/pr-agent-control >/dev/null
|
||||||
|
|
||||||
|
PUB=$(cat "$PUBKEY_FILE")
|
||||||
|
printf 'restrict,command="/usr/local/sbin/pr-agent-control" %s\n' "$PUB" \
|
||||||
|
> "$AGENT_HOME/.ssh/authorized_keys"
|
||||||
|
chown "$AGENT_USER:$AGENT_USER" "$AGENT_HOME/.ssh/authorized_keys"
|
||||||
|
chmod 600 "$AGENT_HOME/.ssh/authorized_keys"
|
||||||
|
|
||||||
|
cat > /etc/ssh/sshd_config.d/60-pr-agent-agent.conf <<'EOF'
|
||||||
|
Match User agent
|
||||||
|
ForceCommand /usr/local/sbin/pr-agent-control
|
||||||
|
PermitTTY no
|
||||||
|
AllowTcpForwarding no
|
||||||
|
X11Forwarding no
|
||||||
|
PermitTunnel no
|
||||||
|
AllowAgentForwarding no
|
||||||
|
EOF
|
||||||
|
chmod 644 /etc/ssh/sshd_config.d/60-pr-agent-agent.conf
|
||||||
|
if ! sshd -t; then
|
||||||
|
rm -f /etc/ssh/sshd_config.d/60-pr-agent-agent.conf
|
||||||
|
echo "sshd config test failed; removed the new file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
systemctl reload ssh
|
||||||
|
|
||||||
|
cd "$PR_AGENT_DIR"
|
||||||
|
"$DOCKER" compose pull
|
||||||
|
"$DOCKER" compose up -d
|
||||||
|
sleep 5
|
||||||
|
"$DOCKER" compose ps
|
||||||
|
|
||||||
|
cat <<'EOF'
|
||||||
|
|
||||||
|
Agent access is ready. Test from the laptop:
|
||||||
|
|
||||||
|
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 status
|
||||||
|
|
||||||
|
Old access is still in place. Only after that command works, run:
|
||||||
|
|
||||||
|
sudo bash /home/noel/agent-access-remove.sh
|
||||||
|
EOF
|
||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify-json/material-symbols": "^1.2.95",
|
"@iconify-json/material-symbols": "^1.2.95",
|
||||||
"@nuxt/icon": "2.6.0",
|
"@nuxt/icon": "2.6.2",
|
||||||
"@nuxtjs/i18n": "10.6.0",
|
"@nuxtjs/i18n": "10.6.0",
|
||||||
"@nuxtjs/seo": "6.0.1",
|
"@nuxtjs/seo": "6.0.1",
|
||||||
"@nuxtjs/tailwindcss": "6.14.0",
|
"@nuxtjs/tailwindcss": "6.14.0",
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
Reference in new issue
Block a user